Skip to content

Commit 4ae5b53

Browse files
committed
Add width/height props to Document class
Close #47
1 parent c47b7e4 commit 4ae5b53

File tree

4 files changed

+200
-29
lines changed

4 files changed

+200
-29
lines changed

CHANGES.md

+11
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@ To be released.
6666
- The type of the third parameter of `doesActorOwnKey()` function became
6767
`DoesActorOwnKeyOptions` (was `DocumentLoader`).
6868

69+
- Added `width` and `height` properties to `Document` class for better
70+
compatibility with Mastodon. [[#47]]
71+
72+
- Added `Document.width` property.
73+
- Added `Document.height` property.
74+
- `new Document()` constructor now accepts `width` option.
75+
- `new Document()` constructor now accepts `height` option.
76+
- `Document.clone()` method now accepts `width` option.
77+
- `Document.clone()` method now accepts `height` option.
78+
6979
- Removed the dependency on *@js-temporal/polyfill* on Deno, and Fedify now
7080
requires `--unstable-temporal` flag. On other runtime, it still depends
7181
on *@js-temporal/polyfill*.
@@ -88,6 +98,7 @@ To be released.
8898
[@fedify/cli]: https://jsr.io/@fedify/cli
8999
[releases]: https://github.com/dahlia/fedify/releases
90100
[FEP-8fcf]: https://codeberg.org/fediverse/fep/src/branch/main/fep/8fcf/fep-8fcf.md
101+
[#47]: https://github.com/dahlia/fedify/issues/47
91102

92103

93104
Version 0.7.0

codegen/__snapshots__/class.test.ts.snap

+125-13
Original file line numberDiff line numberDiff line change
@@ -7736,7 +7736,9 @@ export class Document extends Object {
77367736
static get typeId(): URL {
77377737
return new URL(\\"https://www.w3.org/ns/activitystreams#Document\\");
77387738
}
7739-
7739+
#_2e9AP7WdHBJYAgXG6GEyq7nSkNMe: number[] = [];
7740+
#_2cGKFeFJMmiNpGZFEF75mCwFQsKb: number[] = [];
7741+
77407742
/**
77417743
* Constructs a new instance of Document with the given values.
77427744
* @param values The values to initialize the instance with.
@@ -7761,7 +7763,7 @@ urls?: (URL | Link)[];to?: Object | URL | null;
77617763
tos?: (Object | URL)[];bto?: Object | URL | null;
77627764
btos?: (Object | URL)[];cc?: Object | URL | null;
77637765
ccs?: (Object | URL)[];bcc?: Object | URL | null;
7764-
bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;}
7766+
bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;width?: number | null;height?: number | null;}
77657767
,
77667768
{
77677769
documentLoader,
@@ -7771,7 +7773,15 @@ bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration |
77717773
contextLoader?: DocumentLoader,
77727774
} = {},
77737775
) {
7774-
super(values, { documentLoader, contextLoader });}
7776+
super(values, { documentLoader, contextLoader });
7777+
if (\\"width\\" in values && values.width != null) {
7778+
this.#_2e9AP7WdHBJYAgXG6GEyq7nSkNMe = [values.width];
7779+
}
7780+
7781+
if (\\"height\\" in values && values.height != null) {
7782+
this.#_2cGKFeFJMmiNpGZFEF75mCwFQsKb = [values.height];
7783+
}
7784+
}
77757785

77767786
/**
77777787
* Clones this instance, optionally updating it with the given values.
@@ -7798,18 +7808,44 @@ urls?: (URL | Link)[];to?: Object | URL | null;
77987808
tos?: (Object | URL)[];bto?: Object | URL | null;
77997809
btos?: (Object | URL)[];cc?: Object | URL | null;
78007810
ccs?: (Object | URL)[];bcc?: Object | URL | null;
7801-
bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;}
7811+
bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;width?: number | null;height?: number | null;}
78027812

78037813
= {},
78047814
options: {
78057815
documentLoader?: DocumentLoader,
78067816
contextLoader?: DocumentLoader,
78077817
} = {}
78087818
): Document {
7809-
const clone = super.clone(values, options) as unknown as Document;
7819+
const clone = super.clone(values, options) as unknown as Document;clone.#_2e9AP7WdHBJYAgXG6GEyq7nSkNMe = this.#_2e9AP7WdHBJYAgXG6GEyq7nSkNMe;
7820+
if (\\"width\\" in values && values.width != null) {
7821+
clone.#_2e9AP7WdHBJYAgXG6GEyq7nSkNMe = [values.width];
7822+
}
7823+
clone.#_2cGKFeFJMmiNpGZFEF75mCwFQsKb = this.#_2cGKFeFJMmiNpGZFEF75mCwFQsKb;
7824+
if (\\"height\\" in values && values.height != null) {
7825+
clone.#_2cGKFeFJMmiNpGZFEF75mCwFQsKb = [values.height];
7826+
}
7827+
78107828
return clone;
78117829
}
78127830

7831+
/** Specifies a hint as to the rendering width in
7832+
* device-independent pixels of the linked resource.
7833+
*
7834+
*/
7835+
get width(): (number | null) {
7836+
if (this.#_2e9AP7WdHBJYAgXG6GEyq7nSkNMe.length < 1) return null;
7837+
return this.#_2e9AP7WdHBJYAgXG6GEyq7nSkNMe[0];
7838+
}
7839+
7840+
/** Specifies a hint as to the rendering height in
7841+
* device-independent pixels of the linked resource.
7842+
*
7843+
*/
7844+
get height(): (number | null) {
7845+
if (this.#_2cGKFeFJMmiNpGZFEF75mCwFQsKb.length < 1) return null;
7846+
return this.#_2cGKFeFJMmiNpGZFEF75mCwFQsKb[0];
7847+
}
7848+
78137849
/**
78147850
* Converts this object to a JSON-LD structure.
78157851
* @returns The JSON-LD representation of this object.
@@ -7831,6 +7867,28 @@ bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration |
78317867
}) as unknown[];
78327868
const values = baseValues[0] as Record<string, unknown[] | string>;
78337869

7870+
array = [];
7871+
for (const v of this.#_2e9AP7WdHBJYAgXG6GEyq7nSkNMe) {
7872+
array.push(
7873+
{
7874+
\\"@type\\": \\"http://www.w3.org/2001/XMLSchema#nonNegativeInteger\\",
7875+
\\"@value\\": v,
7876+
}
7877+
);
7878+
}
7879+
if (array.length > 0) values[\\"https://www.w3.org/ns/activitystreams#width\\"] = array;
7880+
7881+
array = [];
7882+
for (const v of this.#_2cGKFeFJMmiNpGZFEF75mCwFQsKb) {
7883+
array.push(
7884+
{
7885+
\\"@type\\": \\"http://www.w3.org/2001/XMLSchema#nonNegativeInteger\\",
7886+
\\"@value\\": v,
7887+
}
7888+
);
7889+
}
7890+
if (array.length > 0) values[\\"https://www.w3.org/ns/activitystreams#height\\"] = array;
7891+
78347892
values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Document\\"];
78357893
if (this.id) values[\\"@id\\"] = this.id.href;
78367894
if (options.expand) {
@@ -7912,12 +7970,66 @@ bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration |
79127970
if (!(instance instanceof Document)) {
79137971
throw new TypeError(\\"Unexpected type: \\" + instance.constructor.name);
79147972
}
7973+
const _2e9AP7WdHBJYAgXG6GEyq7nSkNMe: number[] = [];
7974+
7975+
for (const v of values[\\"https://www.w3.org/ns/activitystreams#width\\"] ?? []) {
7976+
if (v == null) continue;
7977+
_2e9AP7WdHBJYAgXG6GEyq7nSkNMe.push(v[\\"@value\\"])
7978+
}
7979+
instance.#_2e9AP7WdHBJYAgXG6GEyq7nSkNMe = _2e9AP7WdHBJYAgXG6GEyq7nSkNMe;
7980+
const _2cGKFeFJMmiNpGZFEF75mCwFQsKb: number[] = [];
7981+
7982+
for (const v of values[\\"https://www.w3.org/ns/activitystreams#height\\"] ?? []) {
7983+
if (v == null) continue;
7984+
_2cGKFeFJMmiNpGZFEF75mCwFQsKb.push(v[\\"@value\\"])
7985+
}
7986+
instance.#_2cGKFeFJMmiNpGZFEF75mCwFQsKb = _2cGKFeFJMmiNpGZFEF75mCwFQsKb;
79157987

79167988
return instance;
79177989
}
79187990

79197991
protected _getCustomInspectProxy(): Record<string, unknown> {
79207992
const proxy: Record<string, unknown> = super._getCustomInspectProxy();
7993+
const _2e9AP7WdHBJYAgXG6GEyq7nSkNMe = this.#_2e9AP7WdHBJYAgXG6GEyq7nSkNMe
7994+
// deno-lint-ignore no-explicit-any
7995+
.map((v: any) => v instanceof URL
7996+
? {
7997+
[Symbol.for(\\"Deno.customInspect\\")]: (
7998+
inspect: typeof Deno.inspect,
7999+
options: Deno.InspectOptions,
8000+
): string => \\"URL \\" + inspect(v.href, options),
8001+
[Symbol.for(\\"nodejs.util.inspect.custom\\")]: (
8002+
_depth: number,
8003+
options: unknown,
8004+
inspect: (value: unknown, options: unknown) => string,
8005+
): string => \\"URL \\" + inspect(v.href, options),
8006+
}
8007+
: v);
8008+
8009+
if (_2e9AP7WdHBJYAgXG6GEyq7nSkNMe.length == 1) {
8010+
proxy.width = _2e9AP7WdHBJYAgXG6GEyq7nSkNMe[0];
8011+
}
8012+
8013+
const _2cGKFeFJMmiNpGZFEF75mCwFQsKb = this.#_2cGKFeFJMmiNpGZFEF75mCwFQsKb
8014+
// deno-lint-ignore no-explicit-any
8015+
.map((v: any) => v instanceof URL
8016+
? {
8017+
[Symbol.for(\\"Deno.customInspect\\")]: (
8018+
inspect: typeof Deno.inspect,
8019+
options: Deno.InspectOptions,
8020+
): string => \\"URL \\" + inspect(v.href, options),
8021+
[Symbol.for(\\"nodejs.util.inspect.custom\\")]: (
8022+
_depth: number,
8023+
options: unknown,
8024+
inspect: (value: unknown, options: unknown) => string,
8025+
): string => \\"URL \\" + inspect(v.href, options),
8026+
}
8027+
: v);
8028+
8029+
if (_2cGKFeFJMmiNpGZFEF75mCwFQsKb.length == 1) {
8030+
proxy.height = _2cGKFeFJMmiNpGZFEF75mCwFQsKb[0];
8031+
}
8032+
79218033
return proxy;
79228034
}
79238035

@@ -7974,7 +8086,7 @@ urls?: (URL | Link)[];to?: Object | URL | null;
79748086
tos?: (Object | URL)[];bto?: Object | URL | null;
79758087
btos?: (Object | URL)[];cc?: Object | URL | null;
79768088
ccs?: (Object | URL)[];bcc?: Object | URL | null;
7977-
bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;}
8089+
bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;width?: number | null;height?: number | null;}
79788090
,
79798091
{
79808092
documentLoader,
@@ -8011,7 +8123,7 @@ urls?: (URL | Link)[];to?: Object | URL | null;
80118123
tos?: (Object | URL)[];bto?: Object | URL | null;
80128124
btos?: (Object | URL)[];cc?: Object | URL | null;
80138125
ccs?: (Object | URL)[];bcc?: Object | URL | null;
8014-
bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;}
8126+
bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;width?: number | null;height?: number | null;}
80158127

80168128
= {},
80178129
options: {
@@ -13182,7 +13294,7 @@ urls?: (URL | Link)[];to?: Object | URL | null;
1318213294
tos?: (Object | URL)[];bto?: Object | URL | null;
1318313295
btos?: (Object | URL)[];cc?: Object | URL | null;
1318413296
ccs?: (Object | URL)[];bcc?: Object | URL | null;
13185-
bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;}
13297+
bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;width?: number | null;height?: number | null;}
1318613298
,
1318713299
{
1318813300
documentLoader,
@@ -13219,7 +13331,7 @@ urls?: (URL | Link)[];to?: Object | URL | null;
1321913331
tos?: (Object | URL)[];bto?: Object | URL | null;
1322013332
btos?: (Object | URL)[];cc?: Object | URL | null;
1322113333
ccs?: (Object | URL)[];bcc?: Object | URL | null;
13222-
bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;}
13334+
bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;width?: number | null;height?: number | null;}
1322313335

1322413336
= {},
1322513337
options: {
@@ -16909,7 +17021,7 @@ urls?: (URL | Link)[];to?: Object | URL | null;
1690917021
tos?: (Object | URL)[];bto?: Object | URL | null;
1691017022
btos?: (Object | URL)[];cc?: Object | URL | null;
1691117023
ccs?: (Object | URL)[];bcc?: Object | URL | null;
16912-
bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;}
17024+
bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;width?: number | null;height?: number | null;}
1691317025
,
1691417026
{
1691517027
documentLoader,
@@ -16946,7 +17058,7 @@ urls?: (URL | Link)[];to?: Object | URL | null;
1694617058
tos?: (Object | URL)[];bto?: Object | URL | null;
1694717059
btos?: (Object | URL)[];cc?: Object | URL | null;
1694817060
ccs?: (Object | URL)[];bcc?: Object | URL | null;
16949-
bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;}
17061+
bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;width?: number | null;height?: number | null;}
1695017062

1695117063
= {},
1695217064
options: {
@@ -22439,7 +22551,7 @@ urls?: (URL | Link)[];to?: Object | URL | null;
2243922551
tos?: (Object | URL)[];bto?: Object | URL | null;
2244022552
btos?: (Object | URL)[];cc?: Object | URL | null;
2244122553
ccs?: (Object | URL)[];bcc?: Object | URL | null;
22442-
bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;}
22554+
bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;width?: number | null;height?: number | null;}
2244322555
,
2244422556
{
2244522557
documentLoader,
@@ -22476,7 +22588,7 @@ urls?: (URL | Link)[];to?: Object | URL | null;
2247622588
tos?: (Object | URL)[];bto?: Object | URL | null;
2247722589
btos?: (Object | URL)[];cc?: Object | URL | null;
2247822590
ccs?: (Object | URL)[];bcc?: Object | URL | null;
22479-
bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;}
22591+
bccs?: (Object | URL)[];mediaType?: string | null;duration?: Temporal.Duration | null;sensitive?: boolean | null;width?: number | null;height?: number | null;}
2248022592

2248122593
= {},
2248222594
options: {

0 commit comments

Comments
 (0)