diff --git a/CHANGES.md b/CHANGES.md index 3c7f4ad..48c5c57 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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 diff --git a/codegen/__snapshots__/class.test.ts.snap b/codegen/__snapshots__/class.test.ts.snap index 29a5377..fd45f64 100644 --- a/codegen/__snapshots__/class.test.ts.snap +++ b/codegen/__snapshots__/class.test.ts.snap @@ -7736,7 +7736,9 @@ 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. * @param values The values to initialize the instance with. @@ -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; + 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 { const proxy: Record = 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: { diff --git a/vocab/__snapshots__/vocab.test.ts.snap b/vocab/__snapshots__/vocab.test.ts.snap index 9c8b85f..19776ad 100644 --- a/vocab/__snapshots__/vocab.test.ts.snap +++ b/vocab/__snapshots__/vocab.test.ts.snap @@ -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 }' `; diff --git a/vocab/document.yaml b/vocab/document.yaml index 4390ef6..f8949da 100644 --- a/vocab/document.yaml +++ b/vocab/document.yaml @@ -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"