Unverified Commit 4ae5b539 authored by Hong Minhee's avatar Hong Minhee
Browse files

Add width/height props to Document class

parent c47b7e4d
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -66,6 +66,16 @@ To be released.
     -  The type of the third parameter of `doesActorOwnKey()` function became
        `DoesActorOwnKeyOptions` (was `DocumentLoader`).

 -  Added `width` and `height` properties to `Document` class for better
    compatibility with Mastodon.  [[#47]]

     -  Added `Document.width` property.
     -  Added `Document.height` property.
     -  `new Document()` constructor now accepts `width` option.
     -  `new Document()` constructor now accepts `height` option.
     -  `Document.clone()` method now accepts `width` option.
     -  `Document.clone()` method now accepts `height` option.

 -  Removed the dependency on *@js-temporal/polyfill* on Deno, and Fedify now
    requires `--unstable-temporal` flag.  On other runtime, it still depends
    on *@js-temporal/polyfill*.
@@ -88,6 +98,7 @@ To be released.
[@fedify/cli]: https://jsr.io/@fedify/cli
[releases]: https://github.com/dahlia/fedify/releases
[FEP-8fcf]: https://codeberg.org/fediverse/fep/src/branch/main/fep/8fcf/fep-8fcf.md
[#47]: https://github.com/dahlia/fedify/issues/47


Version 0.7.0
+125 −13
Original line number Diff line number Diff line
@@ -7736,6 +7736,8 @@ export class Document extends Object {
    static get typeId(): URL {
      return new URL(\\"https://www.w3.org/ns/activitystreams#Document\\");
    }
  #_2e9AP7WdHBJYAgXG6GEyq7nSkNMe: number[] = [];
#_2cGKFeFJMmiNpGZFEF75mCwFQsKb: number[] = [];
  /**
   * Constructs a new instance of Document with the given values.
@@ -7761,7 +7763,7 @@ urls?: (URL | Link)[];to?: Object | URL | null;
tos?: (Object | URL)[];bto?: Object | URL | null;
btos?: (Object | URL)[];cc?: Object | URL | null;
ccs?: (Object | URL)[];bcc?: Object | URL | null;
bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;}
bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;width?: number | null;height?: number | null;}
,
    {
      documentLoader,
@@ -7771,7 +7773,15 @@ bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration |
      contextLoader?: DocumentLoader,
    } = {},
  ) {
  super(values, { documentLoader, contextLoader });}
  super(values, { documentLoader, contextLoader });
        if (\\"width\\" in values &&             values.width != null) {
          this.#_2e9AP7WdHBJYAgXG6GEyq7nSkNMe = [values.width];
        }
      
        if (\\"height\\" in values &&             values.height != null) {
          this.#_2cGKFeFJMmiNpGZFEF75mCwFQsKb = [values.height];
        }
      }
  /**
   * Clones this instance, optionally updating it with the given values.
@@ -7798,7 +7808,7 @@ urls?: (URL | Link)[];to?: Object | URL | null;
tos?: (Object | URL)[];bto?: Object | URL | null;
btos?: (Object | URL)[];cc?: Object | URL | null;
ccs?: (Object | URL)[];bcc?: Object | URL | null;
bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;}
bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;width?: number | null;height?: number | null;}
    = {},
    options: {
@@ -7806,10 +7816,36 @@ bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration |
      contextLoader?: DocumentLoader,
    } = {}
  ): Document {
  const clone = super.clone(values, options) as unknown as Document;
  const clone = super.clone(values, options) as unknown as Document;clone.#_2e9AP7WdHBJYAgXG6GEyq7nSkNMe = this.#_2e9AP7WdHBJYAgXG6GEyq7nSkNMe;
        if (\\"width\\" in values &&             values.width != null) {
          clone.#_2e9AP7WdHBJYAgXG6GEyq7nSkNMe = [values.width];
        }
      clone.#_2cGKFeFJMmiNpGZFEF75mCwFQsKb = this.#_2cGKFeFJMmiNpGZFEF75mCwFQsKb;
        if (\\"height\\" in values &&             values.height != null) {
          clone.#_2cGKFeFJMmiNpGZFEF75mCwFQsKb = [values.height];
        }
      
    return clone;
  }
  
/** Specifies a hint as to the rendering width in
 * device-independent pixels of the linked resource.
 * 
 */
get width(): (number | null) {
        if (this.#_2e9AP7WdHBJYAgXG6GEyq7nSkNMe.length < 1) return null;
        return this.#_2e9AP7WdHBJYAgXG6GEyq7nSkNMe[0];
      }
      
/** Specifies a hint as to the rendering height in
 * device-independent pixels of the linked resource. 
 * 
 */
get height(): (number | null) {
        if (this.#_2cGKFeFJMmiNpGZFEF75mCwFQsKb.length < 1) return null;
        return this.#_2cGKFeFJMmiNpGZFEF75mCwFQsKb[0];
      }
      
  /**
   * Converts this object to a JSON-LD structure.
   * @returns The JSON-LD representation of this object.
@@ -7831,6 +7867,28 @@ bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration |
    }) as unknown[];
    const values = baseValues[0] as Record<string, unknown[] | string>;
    
    array = [];
    for (const v of this.#_2e9AP7WdHBJYAgXG6GEyq7nSkNMe) {
      array.push(
    {
        \\"@type\\": \\"http://www.w3.org/2001/XMLSchema#nonNegativeInteger\\",
        \\"@value\\": v,
      }
      );
    }
    if (array.length > 0) values[\\"https://www.w3.org/ns/activitystreams#width\\"] = array;
    
    array = [];
    for (const v of this.#_2cGKFeFJMmiNpGZFEF75mCwFQsKb) {
      array.push(
    {
        \\"@type\\": \\"http://www.w3.org/2001/XMLSchema#nonNegativeInteger\\",
        \\"@value\\": v,
      }
      );
    }
    if (array.length > 0) values[\\"https://www.w3.org/ns/activitystreams#height\\"] = array;
    
    values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Document\\"];
    if (this.id) values[\\"@id\\"] = this.id.href;
    if (options.expand) {
@@ -7912,12 +7970,66 @@ bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration |
    if (!(instance instanceof Document)) {
      throw new TypeError(\\"Unexpected type: \\" + instance.constructor.name);
    }
    const _2e9AP7WdHBJYAgXG6GEyq7nSkNMe: number[] = [];
    for (const v of values[\\"https://www.w3.org/ns/activitystreams#width\\"] ?? []) {
      if (v == null) continue;
    _2e9AP7WdHBJYAgXG6GEyq7nSkNMe.push(v[\\"@value\\"])
    }
    instance.#_2e9AP7WdHBJYAgXG6GEyq7nSkNMe = _2e9AP7WdHBJYAgXG6GEyq7nSkNMe;
    const _2cGKFeFJMmiNpGZFEF75mCwFQsKb: number[] = [];
    for (const v of values[\\"https://www.w3.org/ns/activitystreams#height\\"] ?? []) {
      if (v == null) continue;
    _2cGKFeFJMmiNpGZFEF75mCwFQsKb.push(v[\\"@value\\"])
    }
    instance.#_2cGKFeFJMmiNpGZFEF75mCwFQsKb = _2cGKFeFJMmiNpGZFEF75mCwFQsKb;
    
    return instance;
  }
  
  protected _getCustomInspectProxy(): Record<string, unknown> {
  const proxy: Record<string, unknown> = super._getCustomInspectProxy();
      const _2e9AP7WdHBJYAgXG6GEyq7nSkNMe = this.#_2e9AP7WdHBJYAgXG6GEyq7nSkNMe
        // deno-lint-ignore no-explicit-any
        .map((v: any) => v instanceof URL
          ? {
              [Symbol.for(\\"Deno.customInspect\\")]: (
                inspect: typeof Deno.inspect,
                options: Deno.InspectOptions,
              ): string => \\"URL \\" + inspect(v.href, options),
              [Symbol.for(\\"nodejs.util.inspect.custom\\")]: (
                _depth: number,
                options: unknown,
                inspect: (value: unknown, options: unknown) => string,
              ): string => \\"URL \\" + inspect(v.href, options),
            }
          : v);
    
      if (_2e9AP7WdHBJYAgXG6GEyq7nSkNMe.length == 1) {
        proxy.width = _2e9AP7WdHBJYAgXG6GEyq7nSkNMe[0];
      }
      
      const _2cGKFeFJMmiNpGZFEF75mCwFQsKb = this.#_2cGKFeFJMmiNpGZFEF75mCwFQsKb
        // deno-lint-ignore no-explicit-any
        .map((v: any) => v instanceof URL
          ? {
              [Symbol.for(\\"Deno.customInspect\\")]: (
                inspect: typeof Deno.inspect,
                options: Deno.InspectOptions,
              ): string => \\"URL \\" + inspect(v.href, options),
              [Symbol.for(\\"nodejs.util.inspect.custom\\")]: (
                _depth: number,
                options: unknown,
                inspect: (value: unknown, options: unknown) => string,
              ): string => \\"URL \\" + inspect(v.href, options),
            }
          : v);
    
      if (_2cGKFeFJMmiNpGZFEF75mCwFQsKb.length == 1) {
        proxy.height = _2cGKFeFJMmiNpGZFEF75mCwFQsKb[0];
      }
      
    return proxy;
  }
@@ -7974,7 +8086,7 @@ urls?: (URL | Link)[];to?: Object | URL | null;
tos?: (Object | URL)[];bto?: Object | URL | null;
btos?: (Object | URL)[];cc?: Object | URL | null;
ccs?: (Object | URL)[];bcc?: Object | URL | null;
bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;}
bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;width?: number | null;height?: number | null;}
,
    {
      documentLoader,
@@ -8011,7 +8123,7 @@ urls?: (URL | Link)[];to?: Object | URL | null;
tos?: (Object | URL)[];bto?: Object | URL | null;
btos?: (Object | URL)[];cc?: Object | URL | null;
ccs?: (Object | URL)[];bcc?: Object | URL | null;
bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;}
bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;width?: number | null;height?: number | null;}
    = {},
    options: {
@@ -13182,7 +13294,7 @@ urls?: (URL | Link)[];to?: Object | URL | null;
tos?: (Object | URL)[];bto?: Object | URL | null;
btos?: (Object | URL)[];cc?: Object | URL | null;
ccs?: (Object | URL)[];bcc?: Object | URL | null;
bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;}
bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;width?: number | null;height?: number | null;}
,
    {
      documentLoader,
@@ -13219,7 +13331,7 @@ urls?: (URL | Link)[];to?: Object | URL | null;
tos?: (Object | URL)[];bto?: Object | URL | null;
btos?: (Object | URL)[];cc?: Object | URL | null;
ccs?: (Object | URL)[];bcc?: Object | URL | null;
bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;}
bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;width?: number | null;height?: number | null;}
    = {},
    options: {
@@ -16909,7 +17021,7 @@ urls?: (URL | Link)[];to?: Object | URL | null;
tos?: (Object | URL)[];bto?: Object | URL | null;
btos?: (Object | URL)[];cc?: Object | URL | null;
ccs?: (Object | URL)[];bcc?: Object | URL | null;
bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;}
bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;width?: number | null;height?: number | null;}
,
    {
      documentLoader,
@@ -16946,7 +17058,7 @@ urls?: (URL | Link)[];to?: Object | URL | null;
tos?: (Object | URL)[];bto?: Object | URL | null;
btos?: (Object | URL)[];cc?: Object | URL | null;
ccs?: (Object | URL)[];bcc?: Object | URL | null;
bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;}
bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;width?: number | null;height?: number | null;}
    = {},
    options: {
@@ -22439,7 +22551,7 @@ urls?: (URL | Link)[];to?: Object | URL | null;
tos?: (Object | URL)[];bto?: Object | URL | null;
btos?: (Object | URL)[];cc?: Object | URL | null;
ccs?: (Object | URL)[];bcc?: Object | URL | null;
bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;}
bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;width?: number | null;height?: number | null;}
,
    {
      documentLoader,
@@ -22476,7 +22588,7 @@ urls?: (URL | Link)[];to?: Object | URL | null;
tos?: (Object | URL)[];bto?: Object | URL | null;
btos?: (Object | URL)[];cc?: Object | URL | null;
ccs?: (Object | URL)[];bcc?: Object | URL | null;
bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;}
bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;width?: number | null;height?: number | null;}
    = {},
    options: {
+45 −15
Original line number Diff line number Diff line
@@ -735,7 +735,9 @@ snapshot[`Deno.inspect(Audio) [auto] 1`] = `
  bcc: Object {},
  mediaType: "hello",
  duration: PT1H,
  sensitive: true
  sensitive: true,
  width: 123,
  height: 123
}'
`;

@@ -767,7 +769,9 @@ snapshot[`Deno.inspect(Audio) [auto] 2`] = `
  bcc: URL "https://example.com/",
  mediaType: "hello",
  duration: PT1H,
  sensitive: true
  sensitive: true,
  width: 123,
  height: 123
}'
`;

@@ -799,7 +803,9 @@ snapshot[`Deno.inspect(Audio) [auto] 3`] = `
  bccs: [ Object {}, Object {} ],
  mediaType: "hello",
  duration: PT1H,
  sensitive: true
  sensitive: true,
  width: 123,
  height: 123
}'
`;

@@ -1477,7 +1483,9 @@ snapshot[`Deno.inspect(Document) [auto] 1`] = `
  bcc: Object {},
  mediaType: "hello",
  duration: PT1H,
  sensitive: true
  sensitive: true,
  width: 123,
  height: 123
}'
`;

@@ -1509,7 +1517,9 @@ snapshot[`Deno.inspect(Document) [auto] 2`] = `
  bcc: URL "https://example.com/",
  mediaType: "hello",
  duration: PT1H,
  sensitive: true
  sensitive: true,
  width: 123,
  height: 123
}'
`;

@@ -1541,7 +1551,9 @@ snapshot[`Deno.inspect(Document) [auto] 3`] = `
  bccs: [ Object {}, Object {} ],
  mediaType: "hello",
  duration: PT1H,
  sensitive: true
  sensitive: true,
  width: 123,
  height: 123
}'
`;

@@ -2153,7 +2165,9 @@ snapshot[`Deno.inspect(Image) [auto] 1`] = `
  bcc: Object {},
  mediaType: "hello",
  duration: PT1H,
  sensitive: true
  sensitive: true,
  width: 123,
  height: 123
}'
`;

@@ -2185,7 +2199,9 @@ snapshot[`Deno.inspect(Image) [auto] 2`] = `
  bcc: URL "https://example.com/",
  mediaType: "hello",
  duration: PT1H,
  sensitive: true
  sensitive: true,
  width: 123,
  height: 123
}'
`;

@@ -2217,7 +2233,9 @@ snapshot[`Deno.inspect(Image) [auto] 3`] = `
  bccs: [ Object {}, Object {} ],
  mediaType: "hello",
  duration: PT1H,
  sensitive: true
  sensitive: true,
  width: 123,
  height: 123
}'
`;

@@ -3141,7 +3159,9 @@ snapshot[`Deno.inspect(Page) [auto] 1`] = `
  bcc: Object {},
  mediaType: "hello",
  duration: PT1H,
  sensitive: true
  sensitive: true,
  width: 123,
  height: 123
}'
`;

@@ -3173,7 +3193,9 @@ snapshot[`Deno.inspect(Page) [auto] 2`] = `
  bcc: URL "https://example.com/",
  mediaType: "hello",
  duration: PT1H,
  sensitive: true
  sensitive: true,
  width: 123,
  height: 123
}'
`;

@@ -3205,7 +3227,9 @@ snapshot[`Deno.inspect(Page) [auto] 3`] = `
  bccs: [ Object {}, Object {} ],
  mediaType: "hello",
  duration: PT1H,
  sensitive: true
  sensitive: true,
  width: 123,
  height: 123
}'
`;

@@ -4249,7 +4273,9 @@ snapshot[`Deno.inspect(Video) [auto] 1`] = `
  bcc: Object {},
  mediaType: "hello",
  duration: PT1H,
  sensitive: true
  sensitive: true,
  width: 123,
  height: 123
}'
`;

@@ -4281,7 +4307,9 @@ snapshot[`Deno.inspect(Video) [auto] 2`] = `
  bcc: URL "https://example.com/",
  mediaType: "hello",
  duration: PT1H,
  sensitive: true
  sensitive: true,
  width: 123,
  height: 123
}'
`;

@@ -4313,6 +4341,8 @@ snapshot[`Deno.inspect(Video) [auto] 3`] = `
  bccs: [ Object {}, Object {} ],
  mediaType: "hello",
  duration: PT1H,
  sensitive: true
  sensitive: true,
  width: 123,
  height: 123
}'
`;
+19 −1
Original line number Diff line number Diff line
@@ -5,4 +5,22 @@ extends: "https://www.w3.org/ns/activitystreams#Object"
entity: true
description: Represents a document of any kind.
defaultContext: "https://www.w3.org/ns/activitystreams"
properties: []

properties:
- singularName: width
  functional: true
  uri: "https://www.w3.org/ns/activitystreams#width"
  description: |
    Specifies a hint as to the rendering width in
    device-independent pixels of the linked resource.
  range:
  - "http://www.w3.org/2001/XMLSchema#nonNegativeInteger"

- singularName: height
  functional: true
  uri: "https://www.w3.org/ns/activitystreams#height"
  description: |
    Specifies a hint as to the rendering height in
    device-independent pixels of the linked resource. 
  range:
  - "http://www.w3.org/2001/XMLSchema#nonNegativeInteger"