@pairdraw/scene-graph 0.20.0 → 0.21.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/color/index.d.ts +28 -7
- package/dist/color/index.d.ts.map +1 -1
- package/dist/color/index.js +40 -15
- package/dist/color/index.js.map +1 -1
- package/dist/color/management.d.ts +19 -6
- package/dist/color/management.d.ts.map +1 -1
- package/dist/color/management.js +56 -1
- package/dist/color/management.js.map +1 -1
- package/dist/color/profile.d.ts +32 -0
- package/dist/color/profile.d.ts.map +1 -0
- package/dist/color/profile.js +140 -0
- package/dist/color/profile.js.map +1 -0
- package/dist/comments/index.d.ts +2 -2
- package/dist/comments/index.js +2 -2
- package/dist/comments/merge.d.ts.map +1 -1
- package/dist/comments/merge.js +1 -0
- package/dist/comments/merge.js.map +1 -1
- package/dist/comments/schema.d.ts +3 -1
- package/dist/comments/schema.d.ts.map +1 -1
- package/dist/comments/schema.js +19 -2
- package/dist/comments/schema.js.map +1 -1
- package/dist/comments/threads.d.ts +3 -1
- package/dist/comments/threads.d.ts.map +1 -1
- package/dist/comments/threads.js +2 -1
- package/dist/comments/threads.js.map +1 -1
- package/dist/components/properties.d.ts.map +1 -1
- package/dist/components/properties.js +7 -7
- package/dist/components/properties.js.map +1 -1
- package/dist/css/shadows.d.ts +2 -2
- package/dist/css/shadows.d.ts.map +1 -1
- package/dist/css/shadows.js +4 -4
- package/dist/css/shadows.js.map +1 -1
- package/dist/css/values.d.ts +7 -2
- package/dist/css/values.d.ts.map +1 -1
- package/dist/css/values.js +8 -4
- package/dist/css/values.js.map +1 -1
- package/dist/empty-values.js +9 -0
- package/dist/empty-values.js.map +1 -1
- package/dist/graph.d.ts +4 -0
- package/dist/graph.d.ts.map +1 -1
- package/dist/graph.js +11 -2
- package/dist/graph.js.map +1 -1
- package/dist/images.d.ts +3 -2
- package/dist/images.d.ts.map +1 -1
- package/dist/images.js +18 -2
- package/dist/images.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/instances/copies.js +2 -1
- package/dist/instances/copies.js.map +1 -1
- package/dist/instances/index.d.ts.map +1 -1
- package/dist/instances/index.js +12 -11
- package/dist/instances/index.js.map +1 -1
- package/dist/instances/overrides.d.ts +15 -1
- package/dist/instances/overrides.d.ts.map +1 -1
- package/dist/instances/overrides.js +37 -1
- package/dist/instances/overrides.js.map +1 -1
- package/dist/instances/swap-overrides.js +3 -3
- package/dist/instances/swap-overrides.js.map +1 -1
- package/dist/instances/sync.js +9 -7
- package/dist/instances/sync.js.map +1 -1
- package/dist/node-defaults.js +2 -2
- package/dist/node-defaults.js.map +1 -1
- package/dist/plugin-data/fields.d.ts +15 -0
- package/dist/plugin-data/fields.d.ts.map +1 -1
- package/dist/plugin-data/fields.js +15 -23
- package/dist/plugin-data/fields.js.map +1 -1
- package/dist/plugin-data/index.d.ts +2 -2
- package/dist/plugin-data/index.js +2 -2
- package/dist/plugin-data/schema.d.ts +6 -1
- package/dist/plugin-data/schema.d.ts.map +1 -1
- package/dist/plugin-data/schema.js +24 -1
- package/dist/plugin-data/schema.js.map +1 -1
- package/dist/shaders/animation.d.ts +21 -0
- package/dist/shaders/animation.d.ts.map +1 -0
- package/dist/shaders/animation.js +25 -0
- package/dist/shaders/animation.js.map +1 -0
- package/dist/shaders/index.d.ts +2 -1
- package/dist/shaders/index.js +2 -1
- package/dist/slots/content.d.ts.map +1 -1
- package/dist/slots/content.js +4 -4
- package/dist/slots/content.js.map +1 -1
- package/dist/statuses/index.d.ts +2 -2
- package/dist/statuses/index.js +2 -2
- package/dist/statuses/workflow.d.ts +3 -1
- package/dist/statuses/workflow.d.ts.map +1 -1
- package/dist/statuses/workflow.js +6 -2
- package/dist/statuses/workflow.js.map +1 -1
- package/dist/transfer/variables.d.ts.map +1 -1
- package/dist/transfer/variables.js +1 -1
- package/dist/transfer/variables.js.map +1 -1
- package/dist/types.d.ts +34 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/variables/bindings.d.ts +6 -5
- package/dist/variables/bindings.d.ts.map +1 -1
- package/dist/variables/bindings.js +24 -16
- package/dist/variables/bindings.js.map +1 -1
- package/dist/variables/formula/index.d.ts.map +1 -1
- package/dist/variables/formula/index.js +12 -6
- package/dist/variables/formula/index.js.map +1 -1
- package/dist/variables/index.d.ts +14 -1
- package/dist/variables/index.d.ts.map +1 -1
- package/dist/variables/index.js +38 -10
- package/dist/variables/index.js.map +1 -1
- package/dist/variables/paints.d.ts +9 -8
- package/dist/variables/paints.d.ts.map +1 -1
- package/dist/variables/paints.js +35 -26
- package/dist/variables/paints.js.map +1 -1
- package/dist/variables/resolver.d.ts +45 -0
- package/dist/variables/resolver.d.ts.map +1 -0
- package/dist/variables/resolver.js +106 -0
- package/dist/variables/resolver.js.map +1 -0
- package/package.json +1 -1
- package/src/color/index.ts +43 -9
- package/src/color/management.ts +54 -1
- package/src/color/profile.ts +131 -0
- package/src/comments/merge.ts +3 -0
- package/src/comments/schema.ts +32 -2
- package/src/comments/threads.ts +5 -2
- package/src/components/properties.ts +13 -7
- package/src/css/shadows.ts +8 -5
- package/src/css/values.ts +12 -5
- package/src/empty-values.ts +16 -0
- package/src/graph.ts +13 -1
- package/src/images.ts +27 -3
- package/src/instances/copies.ts +2 -1
- package/src/instances/index.ts +19 -11
- package/src/instances/overrides.ts +49 -0
- package/src/instances/swap-overrides.ts +3 -2
- package/src/instances/sync.ts +11 -7
- package/src/node-defaults.ts +2 -2
- package/src/plugin-data/fields.ts +16 -31
- package/src/plugin-data/index.ts +1 -0
- package/src/plugin-data/schema.ts +30 -0
- package/src/shaders/animation.ts +39 -0
- package/src/shaders/index.ts +1 -0
- package/src/slots/content.ts +8 -4
- package/src/statuses/workflow.ts +6 -4
- package/src/transfer/variables.ts +2 -1
- package/src/types.ts +30 -1
- package/src/variables/bindings.ts +35 -18
- package/src/variables/formula/index.ts +19 -18
- package/src/variables/index.ts +49 -10
- package/src/variables/paints.ts +64 -29
- package/src/variables/resolver.ts +178 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"merge.js","names":[],"sources":["../../src/comments/merge.ts"],"sourcesContent":["import type { CommentReply, CommentThread } from '../types'\nimport { byCreatedAt } from './threads'\n\nfunction mergeReplies(first: CommentReply[], second: CommentReply[]): CommentReply[] {\n const byId = new Map<string, CommentReply>()\n for (const reply of [...first, ...second]) {\n const existing = byId.get(reply.id)\n // A deletion is never undone by an older copy of the same reply.\n byId.set(\n reply.id,\n existing ? { ...existing, ...reply, deleted: existing.deleted || reply.deleted } : reply\n )\n }\n return [...byId.values()].sort(byCreatedAt)\n}\n\n/**\n * Two copies of a document's comments become one. Nothing is lost: threads and replies are\n * joined by id, and for a thread both copies changed, the newer edit wins while replies from\n * both are kept. Deleted threads and replies stay deleted.\n */\nexport function mergeCommentThreads(\n local: readonly CommentThread[],\n remote: readonly CommentThread[]\n): CommentThread[] {\n const byId = new Map<string, CommentThread>()\n for (const thread of remote) byId.set(thread.id, thread)\n for (const thread of local) {\n const other = byId.get(thread.id)\n if (!other) {\n byId.set(thread.id, thread)\n continue\n }\n const newer = thread.updatedAt >= other.updatedAt ? thread : other\n byId.set(thread.id, {\n ...newer,\n deleted: thread.deleted || other.deleted,\n replies: mergeReplies(other.replies, thread.replies)\n })\n }\n return [...byId.values()].sort(byCreatedAt)\n}\n\n/**\n * Whether `local` holds anything `remote` lacks: a thread or reply it does not have, a newer edit,\n * or a deletion. Merging is then needed; otherwise `remote` already says everything.\n */\nexport function hasNewerComments(\n local: readonly CommentThread[],\n remote: readonly CommentThread[]\n): boolean {\n const remoteById = new Map(remote.map((thread) => [thread.id, thread]))\n return local.some((thread) => {\n const other = remoteById.get(thread.id)\n if (!other) return true\n if (thread.updatedAt > other.updatedAt || (thread.deleted && !other.deleted)) return true\n const replies = new Map(other.replies.map((entry) => [entry.id, entry]))\n return thread.replies.some((entry) => {\n const known = replies.get(entry.id)\n return !known || (!!entry.deleted && !known.deleted)\n })\n })\n}\n"],"mappings":";;AAGA,SAAS,aAAa,OAAuB,QAAwC;CACnF,MAAM,uBAAO,IAAI,IAA0B;CAC3C,KAAK,MAAM,SAAS,CAAC,GAAG,OAAO,GAAG,MAAM,GAAG;EACzC,MAAM,WAAW,KAAK,IAAI,MAAM,EAAE;EAElC,KAAK,IACH,MAAM,IACN,WAAW;GAAE,GAAG;GAAU,GAAG;GAAO,SAAS,SAAS,WAAW,MAAM;EAAQ,IAAI,KACrF;CACF;CACA,OAAO,CAAC,GAAG,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,WAAW;AAC5C;;;;;;AAOA,SAAgB,oBACd,OACA,QACiB;CACjB,MAAM,uBAAO,IAAI,IAA2B;CAC5C,KAAK,MAAM,UAAU,QAAQ,KAAK,IAAI,OAAO,IAAI,MAAM;CACvD,KAAK,MAAM,UAAU,OAAO;EAC1B,MAAM,QAAQ,KAAK,IAAI,OAAO,EAAE;EAChC,IAAI,CAAC,OAAO;GACV,KAAK,IAAI,OAAO,IAAI,MAAM;GAC1B;EACF;EACA,MAAM,QAAQ,OAAO,aAAa,MAAM,YAAY,SAAS;EAC7D,KAAK,IAAI,OAAO,IAAI;GAClB,GAAG;
|
|
1
|
+
{"version":3,"file":"merge.js","names":[],"sources":["../../src/comments/merge.ts"],"sourcesContent":["import type { CommentReply, CommentThread } from '../types'\nimport { byCreatedAt } from './threads'\n\nfunction mergeReplies(first: CommentReply[], second: CommentReply[]): CommentReply[] {\n const byId = new Map<string, CommentReply>()\n for (const reply of [...first, ...second]) {\n const existing = byId.get(reply.id)\n // A deletion is never undone by an older copy of the same reply.\n byId.set(\n reply.id,\n existing ? { ...existing, ...reply, deleted: existing.deleted || reply.deleted } : reply\n )\n }\n return [...byId.values()].sort(byCreatedAt)\n}\n\n/**\n * Two copies of a document's comments become one. Nothing is lost: threads and replies are\n * joined by id, and for a thread both copies changed, the newer edit wins while replies from\n * both are kept. Deleted threads and replies stay deleted.\n */\nexport function mergeCommentThreads(\n local: readonly CommentThread[],\n remote: readonly CommentThread[]\n): CommentThread[] {\n const byId = new Map<string, CommentThread>()\n for (const thread of remote) byId.set(thread.id, thread)\n for (const thread of local) {\n const other = byId.get(thread.id)\n if (!other) {\n byId.set(thread.id, thread)\n continue\n }\n const newer = thread.updatedAt >= other.updatedAt ? thread : other\n byId.set(thread.id, {\n ...newer,\n // A region is only ever set together with its thread, so a copy that lacks one — written by\n // an older build or read before the person drew — does not erase it.\n region: newer.region ?? thread.region ?? other.region,\n deleted: thread.deleted || other.deleted,\n replies: mergeReplies(other.replies, thread.replies)\n })\n }\n return [...byId.values()].sort(byCreatedAt)\n}\n\n/**\n * Whether `local` holds anything `remote` lacks: a thread or reply it does not have, a newer edit,\n * or a deletion. Merging is then needed; otherwise `remote` already says everything.\n */\nexport function hasNewerComments(\n local: readonly CommentThread[],\n remote: readonly CommentThread[]\n): boolean {\n const remoteById = new Map(remote.map((thread) => [thread.id, thread]))\n return local.some((thread) => {\n const other = remoteById.get(thread.id)\n if (!other) return true\n if (thread.updatedAt > other.updatedAt || (thread.deleted && !other.deleted)) return true\n const replies = new Map(other.replies.map((entry) => [entry.id, entry]))\n return thread.replies.some((entry) => {\n const known = replies.get(entry.id)\n return !known || (!!entry.deleted && !known.deleted)\n })\n })\n}\n"],"mappings":";;AAGA,SAAS,aAAa,OAAuB,QAAwC;CACnF,MAAM,uBAAO,IAAI,IAA0B;CAC3C,KAAK,MAAM,SAAS,CAAC,GAAG,OAAO,GAAG,MAAM,GAAG;EACzC,MAAM,WAAW,KAAK,IAAI,MAAM,EAAE;EAElC,KAAK,IACH,MAAM,IACN,WAAW;GAAE,GAAG;GAAU,GAAG;GAAO,SAAS,SAAS,WAAW,MAAM;EAAQ,IAAI,KACrF;CACF;CACA,OAAO,CAAC,GAAG,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,WAAW;AAC5C;;;;;;AAOA,SAAgB,oBACd,OACA,QACiB;CACjB,MAAM,uBAAO,IAAI,IAA2B;CAC5C,KAAK,MAAM,UAAU,QAAQ,KAAK,IAAI,OAAO,IAAI,MAAM;CACvD,KAAK,MAAM,UAAU,OAAO;EAC1B,MAAM,QAAQ,KAAK,IAAI,OAAO,EAAE;EAChC,IAAI,CAAC,OAAO;GACV,KAAK,IAAI,OAAO,IAAI,MAAM;GAC1B;EACF;EACA,MAAM,QAAQ,OAAO,aAAa,MAAM,YAAY,SAAS;EAC7D,KAAK,IAAI,OAAO,IAAI;GAClB,GAAG;GAGH,QAAQ,MAAM,UAAU,OAAO,UAAU,MAAM;GAC/C,SAAS,OAAO,WAAW,MAAM;GACjC,SAAS,aAAa,MAAM,SAAS,OAAO,OAAO;EACrD,CAAC;CACH;CACA,OAAO,CAAC,GAAG,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,WAAW;AAC5C;;;;;AAMA,SAAgB,iBACd,OACA,QACS;CACT,MAAM,aAAa,IAAI,IAAI,OAAO,KAAK,WAAW,CAAC,OAAO,IAAI,MAAM,CAAC,CAAC;CACtE,OAAO,MAAM,MAAM,WAAW;EAC5B,MAAM,QAAQ,WAAW,IAAI,OAAO,EAAE;EACtC,IAAI,CAAC,OAAO,OAAO;EACnB,IAAI,OAAO,YAAY,MAAM,aAAc,OAAO,WAAW,CAAC,MAAM,SAAU,OAAO;EACrF,MAAM,UAAU,IAAI,IAAI,MAAM,QAAQ,KAAK,UAAU,CAAC,MAAM,IAAI,KAAK,CAAC,CAAC;EACvE,OAAO,OAAO,QAAQ,MAAM,UAAU;GACpC,MAAM,QAAQ,QAAQ,IAAI,MAAM,EAAE;GAClC,OAAO,CAAC,SAAU,CAAC,CAAC,MAAM,WAAW,CAAC,MAAM;EAC9C,CAAC;CACH,CAAC;AACH"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { CommentThread } from "../types.js";
|
|
2
2
|
import * as v from "valibot";
|
|
3
3
|
//#region src/comments/schema.d.ts
|
|
4
|
+
/** Points one thread's region may carry; a file asking for more is not a stroke a person drew. */
|
|
5
|
+
declare const MAX_COMMENT_REGION_POINTS = 512;
|
|
4
6
|
/** A list of comment threads as files and rooms hold them; threads that cannot be read are left out. */
|
|
5
7
|
declare const commentThreadsSchema: v.GenericSchema<unknown, CommentThread[]>;
|
|
6
8
|
//#endregion
|
|
7
|
-
export { commentThreadsSchema };
|
|
9
|
+
export { MAX_COMMENT_REGION_POINTS, commentThreadsSchema };
|
|
8
10
|
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","names":[],"sources":["../../src/comments/schema.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"schema.d.ts","names":[],"sources":["../../src/comments/schema.ts"],"mappings":";;;;cAuBa;;cAuCA,sBAAsB,EAAE,uBAAuB"}
|
package/dist/comments/schema.js
CHANGED
|
@@ -18,6 +18,21 @@ const commentReplySchema = v.object({
|
|
|
18
18
|
id: v.string(),
|
|
19
19
|
...commentEntry
|
|
20
20
|
});
|
|
21
|
+
/** Points one thread's region may carry; a file asking for more is not a stroke a person drew. */
|
|
22
|
+
const MAX_COMMENT_REGION_POINTS = 512;
|
|
23
|
+
const finiteSchema = v.pipe(v.number(), v.finite());
|
|
24
|
+
const commentPointSchema = v.tuple([finiteSchema, finiteSchema]);
|
|
25
|
+
/** The stroke a person circled with: its points and width, and the box they span. */
|
|
26
|
+
const commentRegionSchema = v.object({
|
|
27
|
+
points: v.pipe(v.array(commentPointSchema), v.minLength(2), v.maxLength(512)),
|
|
28
|
+
width: v.pipe(finiteSchema, v.minValue(0)),
|
|
29
|
+
bounds: v.object({
|
|
30
|
+
minX: finiteSchema,
|
|
31
|
+
minY: finiteSchema,
|
|
32
|
+
maxX: finiteSchema,
|
|
33
|
+
maxY: finiteSchema
|
|
34
|
+
})
|
|
35
|
+
});
|
|
21
36
|
const commentThreadSchema = v.object({
|
|
22
37
|
id: v.string(),
|
|
23
38
|
pageId: v.string(),
|
|
@@ -39,12 +54,14 @@ const commentThreadsSchema = v.pipe(v.array(v.unknown()), v.transform((items) =>
|
|
|
39
54
|
const parsed = v.safeParse(commentThreadSchema, item);
|
|
40
55
|
if (!parsed.success) return [];
|
|
41
56
|
const thread = parsed.output;
|
|
57
|
+
const region = v.safeParse(commentRegionSchema, item.region);
|
|
42
58
|
return [{
|
|
43
59
|
...thread,
|
|
44
|
-
updatedAt: thread.updatedAt || thread.createdAt
|
|
60
|
+
updatedAt: thread.updatedAt || thread.createdAt,
|
|
61
|
+
...region.success ? { region: region.output } : {}
|
|
45
62
|
}];
|
|
46
63
|
})));
|
|
47
64
|
//#endregion
|
|
48
|
-
export { commentThreadsSchema };
|
|
65
|
+
export { MAX_COMMENT_REGION_POINTS, commentThreadsSchema };
|
|
49
66
|
|
|
50
67
|
//# sourceMappingURL=schema.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","names":[],"sources":["../../src/comments/schema.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport type { CommentThread } from '../types'\n\n// Lenient on purpose: other tools may write comments, so missing fields get defaults and one\n// malformed thread is skipped instead of hiding every comment.\nconst commentAuthorColorSchema = v.fallback(\n v.optional(v.object({ r: v.number(), g: v.number(), b: v.number(), a: v.number() })),\n undefined\n)\n\n/** What a comment and each reply say, who wrote them and when, and whether they were deleted. */\nconst commentEntry = {\n author: v.fallback(v.string(), ''),\n authorColor: commentAuthorColorSchema,\n text: v.fallback(v.string(), ''),\n createdAt: v.fallback(v.string(), ''),\n deleted: v.optional(v.boolean())\n}\n\nconst commentReplySchema = v.object({ id: v.string(), ...commentEntry })\n\nconst commentThreadSchema = v.object({\n id: v.string(),\n pageId: v.string(),\n pageName: v.optional(v.string()),\n nodeId: v.optional(v.nullable(v.string())),\n nodeName: v.optional(v.nullable(v.string())),\n offsetX: v.optional(v.number()),\n offsetY: v.optional(v.number()),\n x: v.fallback(v.number(), 0),\n y: v.fallback(v.number(), 0),\n ...commentEntry,\n updatedAt: v.fallback(v.string(), ''),\n resolved: v.fallback(v.boolean(), false),\n resolvedAt: v.optional(v.nullable(v.string())),\n replies: v.fallback(v.array(commentReplySchema), [])\n})\n\n/** A list of comment threads as files and rooms hold them; threads that cannot be read are left out. */\nexport const commentThreadsSchema: v.GenericSchema<unknown, CommentThread[]> = v.pipe(\n v.array(v.unknown()),\n v.transform((items) =>\n items.flatMap((item) => {\n const parsed = v.safeParse(commentThreadSchema, item)\n if (!parsed.success) return []\n const thread = parsed.output\n return [{
|
|
1
|
+
{"version":3,"file":"schema.js","names":[],"sources":["../../src/comments/schema.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport type { CommentRegion, CommentThread } from '../types'\n\n// Lenient on purpose: other tools may write comments, so missing fields get defaults and one\n// malformed thread is skipped instead of hiding every comment.\nconst commentAuthorColorSchema = v.fallback(\n v.optional(v.object({ r: v.number(), g: v.number(), b: v.number(), a: v.number() })),\n undefined\n)\n\n/** What a comment and each reply say, who wrote them and when, and whether they were deleted. */\nconst commentEntry = {\n author: v.fallback(v.string(), ''),\n authorColor: commentAuthorColorSchema,\n text: v.fallback(v.string(), ''),\n createdAt: v.fallback(v.string(), ''),\n deleted: v.optional(v.boolean())\n}\n\nconst commentReplySchema = v.object({ id: v.string(), ...commentEntry })\n\n/** Points one thread's region may carry; a file asking for more is not a stroke a person drew. */\nexport const MAX_COMMENT_REGION_POINTS = 512\n\nconst finiteSchema = v.pipe(v.number(), v.finite())\nconst commentPointSchema = v.tuple([finiteSchema, finiteSchema])\n\n/** The stroke a person circled with: its points and width, and the box they span. */\nconst commentRegionSchema: v.GenericSchema<unknown, CommentRegion> = v.object({\n points: v.pipe(\n v.array(commentPointSchema),\n v.minLength(2),\n v.maxLength(MAX_COMMENT_REGION_POINTS)\n ),\n width: v.pipe(finiteSchema, v.minValue(0)),\n bounds: v.object({\n minX: finiteSchema,\n minY: finiteSchema,\n maxX: finiteSchema,\n maxY: finiteSchema\n })\n})\n\nconst commentThreadSchema = v.object({\n id: v.string(),\n pageId: v.string(),\n pageName: v.optional(v.string()),\n nodeId: v.optional(v.nullable(v.string())),\n nodeName: v.optional(v.nullable(v.string())),\n offsetX: v.optional(v.number()),\n offsetY: v.optional(v.number()),\n x: v.fallback(v.number(), 0),\n y: v.fallback(v.number(), 0),\n ...commentEntry,\n updatedAt: v.fallback(v.string(), ''),\n resolved: v.fallback(v.boolean(), false),\n resolvedAt: v.optional(v.nullable(v.string())),\n replies: v.fallback(v.array(commentReplySchema), [])\n})\n\n/** A list of comment threads as files and rooms hold them; threads that cannot be read are left out. */\nexport const commentThreadsSchema: v.GenericSchema<unknown, CommentThread[]> = v.pipe(\n v.array(v.unknown()),\n v.transform((items) =>\n items.flatMap((item) => {\n const parsed = v.safeParse(commentThreadSchema, item)\n if (!parsed.success) return []\n const thread = parsed.output\n // A stroke that cannot be read is dropped; the note it was drawn around is still worth keeping.\n const region = v.safeParse(commentRegionSchema, (item as { region?: unknown }).region)\n return [\n {\n ...thread,\n updatedAt: thread.updatedAt || thread.createdAt,\n ...(region.success ? { region: region.output } : {})\n }\n ]\n })\n )\n)\n"],"mappings":";;AAMA,MAAM,2BAA2B,EAAE,SACjC,EAAE,SAAS,EAAE,OAAO;CAAE,GAAG,EAAE,OAAO;CAAG,GAAG,EAAE,OAAO;CAAG,GAAG,EAAE,OAAO;CAAG,GAAG,EAAE,OAAO;AAAE,CAAC,CAAC,GACnF,KAAA,CACF;;AAGA,MAAM,eAAe;CACnB,QAAQ,EAAE,SAAS,EAAE,OAAO,GAAG,EAAE;CACjC,aAAa;CACb,MAAM,EAAE,SAAS,EAAE,OAAO,GAAG,EAAE;CAC/B,WAAW,EAAE,SAAS,EAAE,OAAO,GAAG,EAAE;CACpC,SAAS,EAAE,SAAS,EAAE,QAAQ,CAAC;AACjC;AAEA,MAAM,qBAAqB,EAAE,OAAO;CAAE,IAAI,EAAE,OAAO;CAAG,GAAG;AAAa,CAAC;;AAGvE,MAAa,4BAA4B;AAEzC,MAAM,eAAe,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,OAAO,CAAC;AAClD,MAAM,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AAS,EAAE,UAAU,qBAAsB,KAA8B,MAAM;CACrF,OAAO,CACL;EACE,GAAG;EACH,WAAW,OAAO,aAAa,OAAO;EACtC,GAAI,OAAO,UAAU,EAAE,QAAQ,OAAO,OAAO,IAAI,CAAC;CACpD,CACF;AACF,CAAC,CACH,CACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Color, Vector } from "../primitives/index.js";
|
|
2
2
|
import { SceneGraph } from "../graph.js";
|
|
3
|
-
import { CommentReply, CommentThread, SceneNode } from "../types.js";
|
|
3
|
+
import { CommentRegion, CommentReply, CommentThread, SceneNode } from "../types.js";
|
|
4
4
|
//#region src/comments/threads.d.ts
|
|
5
5
|
/** Who writes a comment: their name and, in a collaboration room, their color. */
|
|
6
6
|
interface CommentAuthor {
|
|
@@ -41,6 +41,8 @@ declare function createCommentThread(graph: SceneGraph, options: {
|
|
|
41
41
|
at: Vector;
|
|
42
42
|
/** Pin it on this layer's top-level layer rather than on whatever is at `at`. */
|
|
43
43
|
node?: SceneNode;
|
|
44
|
+
/** The area the person circled, when the comment was drawn rather than clicked. */
|
|
45
|
+
region?: CommentRegion | null;
|
|
44
46
|
author: CommentAuthor;
|
|
45
47
|
text: string;
|
|
46
48
|
now: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"threads.d.ts","names":[],"sources":["../../src/comments/threads.ts"],"mappings":";;;;;UAMiB;EACf;EACA,QAAQ;;;iBAQM;;iBAKA,YAAY;EAAK;GAAqB;EAAK;;;iBAK3C,YAAY,QAAQ,gBAAgB;;iBAKpC,kBAAkB,QAAQ,eAAe;;iBAKzC,sBACd,kBAAkB,iBAClB,aACC;;;;;iBAoBa,cAAc,OAAO,YAAY,gBAAgB,IAAI,QAAQ,OAAO;;;;;;;;;iBAepE,gBAAgB,OAAO,YAAY,QAAQ,gBAAgB;;iBAQ3D,oBACd,OAAO,YACP;EACE;EACA,IAAI;;EAEJ,OAAO;
|
|
1
|
+
{"version":3,"file":"threads.d.ts","names":[],"sources":["../../src/comments/threads.ts"],"mappings":";;;;;UAMiB;EACf;EACA,QAAQ;;;iBAQM;;iBAKA,YAAY;EAAK;GAAqB;EAAK;;;iBAK3C,YAAY,QAAQ,gBAAgB;;iBAKpC,kBAAkB,QAAQ,eAAe;;iBAKzC,sBACd,kBAAkB,iBAClB,aACC;;;;;iBAoBa,cAAc,OAAO,YAAY,gBAAgB,IAAI,QAAQ,OAAO;;;;;;;;;iBAepE,gBAAgB,OAAO,YAAY,QAAQ,gBAAgB;;iBAQ3D,oBACd,OAAO,YACP;EACE;EACA,IAAI;;EAEJ,OAAO;;EAEP,SAAS;EACT,QAAQ;EACR;EACA;IAED;iBAkBa,mBAAmB,QAAQ,eAAe,cAAc,cAAc;;iBAWtE,kBACd,kBAAkB,iBAClB,YACA,aACA,OAAO,QAAQ,kBAAkB,gBAChC;;iBAKa,qBAAqB,QAAQ,eAAe,OAAO,eAAe;iBAIlE,qBACd,QAAQ,eACR,mBACA,cACC;;iBAKa,oBAAoB,QAAQ,gBAAgB;iBAI5C,mBAAmB,QAAQ,eAAe,kBAAkB"}
|
package/dist/comments/threads.js
CHANGED
|
@@ -63,7 +63,7 @@ function commentPosition(graph, thread) {
|
|
|
63
63
|
}
|
|
64
64
|
/** A new thread pinned at a canvas point of a page. */
|
|
65
65
|
function createCommentThread(graph, options) {
|
|
66
|
-
const { pageId, at, node, author, text, now } = options;
|
|
66
|
+
const { pageId, at, node, region, author, text, now } = options;
|
|
67
67
|
return {
|
|
68
68
|
id: newCommentId("c"),
|
|
69
69
|
pageId,
|
|
@@ -75,6 +75,7 @@ function createCommentThread(graph, options) {
|
|
|
75
75
|
createdAt: now,
|
|
76
76
|
updatedAt: now,
|
|
77
77
|
resolved: false,
|
|
78
|
+
...region ? { region } : {},
|
|
78
79
|
replies: []
|
|
79
80
|
};
|
|
80
81
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"threads.js","names":[],"sources":["../../src/comments/threads.ts"],"sourcesContent":["import type { SceneGraph } from '../graph'\nimport type { Color, Vector } from '../primitives'\nimport { randomHex } from '../random'\nimport type { CommentReply, CommentThread, SceneNode } from '../types'\n\n/** Who writes a comment: their name and, in a collaboration room, their color. */\nexport interface CommentAuthor {\n name: string\n color?: Color\n}\n\nfunction newCommentId(prefix: 'c' | 'r'): string {\n return `${prefix}_${randomHex(8)}`\n}\n\n/** When a comment is written or changed, as stored: an ISO timestamp. */\nexport function commentTimestamp(): string {\n return new Date().toISOString()\n}\n\n/** Oldest first, the order threads and replies are shown and numbered in. */\nexport function byCreatedAt(a: { createdAt: string }, b: { createdAt: string }): number {\n return a.createdAt.localeCompare(b.createdAt)\n}\n\n/** A thread's replies, without the deleted ones kept as tombstones. */\nexport function liveReplies(thread: CommentThread): CommentReply[] {\n return thread.replies.filter((entry) => !entry.deleted)\n}\n\n/** Whether `author` started the thread or replied to it, as Figma's \"Only your threads\" counts. */\nexport function takesPartInThread(thread: CommentThread, author: string): boolean {\n return thread.author === author || liveReplies(thread).some((entry) => entry.author === author)\n}\n\n/** The thread with `id`, unless it is missing or deleted. */\nexport function findLiveCommentThread(\n threads: readonly CommentThread[],\n id: string\n): CommentThread | undefined {\n return threads.find((thread) => thread.id === id && !thread.deleted)\n}\n\n/**\n * The layer a comment on `node` is kept on: its top-level layer, as Figma attaches comments, or\n * within a section the section's own child, as frames move about inside it.\n */\nfunction commentLayer(graph: SceneGraph, node: SceneNode, pageId: string): SceneNode {\n const isSection = (id: string | null) => !!id && graph.getNode(id)?.type === 'SECTION'\n return (\n graph.closest(node.id, (layer) => layer.parentId === pageId || isSection(layer.parentId)) ??\n node\n )\n}\n\n/**\n * Where a pin at a canvas point is kept: on the top-level layer under it, or on `node`'s when\n * given, so it follows that layer; on the canvas when nothing is there.\n */\nexport function commentAnchor(graph: SceneGraph, pageId: string, at: Vector, node?: SceneNode) {\n const target = node ?? graph.hitTest(at.x, at.y, pageId)\n const layer = target ? commentLayer(graph, target, pageId) : null\n const abs = layer ? graph.getAbsolutePosition(layer.id) : null\n return {\n nodeId: layer?.id ?? null,\n nodeName: layer?.name ?? null,\n offsetX: abs ? at.x - abs.x : 0,\n offsetY: abs ? at.y - abs.y : 0,\n x: at.x,\n y: at.y\n }\n}\n\n/** Where a thread's pin is now: on its layer while that layer exists, else where it was left. */\nexport function commentPosition(graph: SceneGraph, thread: CommentThread): Vector {\n const node = thread.nodeId ? graph.getNode(thread.nodeId) : undefined\n if (!node) return { x: thread.x, y: thread.y }\n const abs = graph.getAbsolutePosition(node.id)\n return { x: abs.x + (thread.offsetX ?? 0), y: abs.y + (thread.offsetY ?? 0) }\n}\n\n/** A new thread pinned at a canvas point of a page. */\nexport function createCommentThread(\n graph: SceneGraph,\n options: {\n pageId: string\n at: Vector\n /** Pin it on this layer's top-level layer rather than on whatever is at `at`. */\n node?: SceneNode\n author: CommentAuthor\n text: string\n now: string\n }\n): CommentThread {\n const { pageId, at, node, author, text, now } = options\n return {\n id: newCommentId('c'),\n pageId,\n pageName: graph.getNode(pageId)?.name,\n ...commentAnchor(graph, pageId, at, node),\n author: author.name,\n authorColor: author.color,\n text,\n createdAt: now,\n updatedAt: now,\n resolved: false,\n replies: []\n }\n}\n\nexport function createCommentReply(author: CommentAuthor, text: string, now: string): CommentReply {\n return {\n id: newCommentId('r'),\n author: author.name,\n authorColor: author.color,\n text,\n createdAt: now\n }\n}\n\n/** The threads with one changed and marked as edited at `now`, for merging with other copies. */\nexport function editCommentThread(\n threads: readonly CommentThread[],\n id: string,\n now: string,\n edit: (thread: CommentThread) => CommentThread\n): CommentThread[] {\n return threads.map((thread) => (thread.id === id ? { ...edit(thread), updatedAt: now } : thread))\n}\n\n/** A reply ends up in the thread and reopens it, as answering a resolved comment does. */\nexport function replyToCommentThread(thread: CommentThread, reply: CommentReply): CommentThread {\n return { ...thread, resolved: false, resolvedAt: null, replies: [...thread.replies, reply] }\n}\n\nexport function resolveCommentThread(\n thread: CommentThread,\n resolved: boolean,\n now: string\n): CommentThread {\n return { ...thread, resolved, resolvedAt: resolved ? now : null }\n}\n\n/** Deleted threads and replies stay as tombstones, so a stale copy cannot bring them back. */\nexport function deleteCommentThread(thread: CommentThread): CommentThread {\n return { ...thread, deleted: true }\n}\n\nexport function deleteCommentReply(thread: CommentThread, replyId: string): CommentThread {\n return {\n ...thread,\n replies: thread.replies.map((entry) =>\n entry.id === replyId ? { ...entry, deleted: true } : entry\n )\n }\n}\n"],"mappings":";;AAWA,SAAS,aAAa,QAA2B;CAC/C,OAAO,GAAG,OAAO,GAAG,UAAU,CAAC;AACjC;;AAGA,SAAgB,mBAA2B;CACzC,wBAAO,IAAI,KAAK,EAAA,CAAE,YAAY;AAChC;;AAGA,SAAgB,YAAY,GAA0B,GAAkC;CACtF,OAAO,EAAE,UAAU,cAAc,EAAE,SAAS;AAC9C;;AAGA,SAAgB,YAAY,QAAuC;CACjE,OAAO,OAAO,QAAQ,QAAQ,UAAU,CAAC,MAAM,OAAO;AACxD;;AAGA,SAAgB,kBAAkB,QAAuB,QAAyB;CAChF,OAAO,OAAO,WAAW,UAAU,YAAY,MAAM,CAAC,CAAC,MAAM,UAAU,MAAM,WAAW,MAAM;AAChG;;AAGA,SAAgB,sBACd,SACA,IAC2B;CAC3B,OAAO,QAAQ,MAAM,WAAW,OAAO,OAAO,MAAM,CAAC,OAAO,OAAO;AACrE;;;;;AAMA,SAAS,aAAa,OAAmB,MAAiB,QAA2B;CACnF,MAAM,aAAa,OAAsB,CAAC,CAAC,MAAM,MAAM,QAAQ,EAAE,CAAC,EAAE,SAAS;CAC7E,OACE,MAAM,QAAQ,KAAK,KAAK,UAAU,MAAM,aAAa,UAAU,UAAU,MAAM,QAAQ,CAAC,KACxF;AAEJ;;;;;AAMA,SAAgB,cAAc,OAAmB,QAAgB,IAAY,MAAkB;CAC7F,MAAM,SAAS,QAAQ,MAAM,QAAQ,GAAG,GAAG,GAAG,GAAG,MAAM;CACvD,MAAM,QAAQ,SAAS,aAAa,OAAO,QAAQ,MAAM,IAAI;CAC7D,MAAM,MAAM,QAAQ,MAAM,oBAAoB,MAAM,EAAE,IAAI;CAC1D,OAAO;EACL,QAAQ,OAAO,MAAM;EACrB,UAAU,OAAO,QAAQ;EACzB,SAAS,MAAM,GAAG,IAAI,IAAI,IAAI;EAC9B,SAAS,MAAM,GAAG,IAAI,IAAI,IAAI;EAC9B,GAAG,GAAG;EACN,GAAG,GAAG;CACR;AACF;;AAGA,SAAgB,gBAAgB,OAAmB,QAA+B;CAChF,MAAM,OAAO,OAAO,SAAS,MAAM,QAAQ,OAAO,MAAM,IAAI,KAAA;CAC5D,IAAI,CAAC,MAAM,OAAO;EAAE,GAAG,OAAO;EAAG,GAAG,OAAO;CAAE;CAC7C,MAAM,MAAM,MAAM,oBAAoB,KAAK,EAAE;CAC7C,OAAO;EAAE,GAAG,IAAI,KAAK,OAAO,WAAW;EAAI,GAAG,IAAI,KAAK,OAAO,WAAW;CAAG;AAC9E;;AAGA,SAAgB,oBACd,OACA,
|
|
1
|
+
{"version":3,"file":"threads.js","names":[],"sources":["../../src/comments/threads.ts"],"sourcesContent":["import type { SceneGraph } from '../graph'\nimport type { Color, Vector } from '../primitives'\nimport { randomHex } from '../random'\nimport type { CommentRegion, CommentReply, CommentThread, SceneNode } from '../types'\n\n/** Who writes a comment: their name and, in a collaboration room, their color. */\nexport interface CommentAuthor {\n name: string\n color?: Color\n}\n\nfunction newCommentId(prefix: 'c' | 'r'): string {\n return `${prefix}_${randomHex(8)}`\n}\n\n/** When a comment is written or changed, as stored: an ISO timestamp. */\nexport function commentTimestamp(): string {\n return new Date().toISOString()\n}\n\n/** Oldest first, the order threads and replies are shown and numbered in. */\nexport function byCreatedAt(a: { createdAt: string }, b: { createdAt: string }): number {\n return a.createdAt.localeCompare(b.createdAt)\n}\n\n/** A thread's replies, without the deleted ones kept as tombstones. */\nexport function liveReplies(thread: CommentThread): CommentReply[] {\n return thread.replies.filter((entry) => !entry.deleted)\n}\n\n/** Whether `author` started the thread or replied to it, as Figma's \"Only your threads\" counts. */\nexport function takesPartInThread(thread: CommentThread, author: string): boolean {\n return thread.author === author || liveReplies(thread).some((entry) => entry.author === author)\n}\n\n/** The thread with `id`, unless it is missing or deleted. */\nexport function findLiveCommentThread(\n threads: readonly CommentThread[],\n id: string\n): CommentThread | undefined {\n return threads.find((thread) => thread.id === id && !thread.deleted)\n}\n\n/**\n * The layer a comment on `node` is kept on: its top-level layer, as Figma attaches comments, or\n * within a section the section's own child, as frames move about inside it.\n */\nfunction commentLayer(graph: SceneGraph, node: SceneNode, pageId: string): SceneNode {\n const isSection = (id: string | null) => !!id && graph.getNode(id)?.type === 'SECTION'\n return (\n graph.closest(node.id, (layer) => layer.parentId === pageId || isSection(layer.parentId)) ??\n node\n )\n}\n\n/**\n * Where a pin at a canvas point is kept: on the top-level layer under it, or on `node`'s when\n * given, so it follows that layer; on the canvas when nothing is there.\n */\nexport function commentAnchor(graph: SceneGraph, pageId: string, at: Vector, node?: SceneNode) {\n const target = node ?? graph.hitTest(at.x, at.y, pageId)\n const layer = target ? commentLayer(graph, target, pageId) : null\n const abs = layer ? graph.getAbsolutePosition(layer.id) : null\n return {\n nodeId: layer?.id ?? null,\n nodeName: layer?.name ?? null,\n offsetX: abs ? at.x - abs.x : 0,\n offsetY: abs ? at.y - abs.y : 0,\n x: at.x,\n y: at.y\n }\n}\n\n/** Where a thread's pin is now: on its layer while that layer exists, else where it was left. */\nexport function commentPosition(graph: SceneGraph, thread: CommentThread): Vector {\n const node = thread.nodeId ? graph.getNode(thread.nodeId) : undefined\n if (!node) return { x: thread.x, y: thread.y }\n const abs = graph.getAbsolutePosition(node.id)\n return { x: abs.x + (thread.offsetX ?? 0), y: abs.y + (thread.offsetY ?? 0) }\n}\n\n/** A new thread pinned at a canvas point of a page. */\nexport function createCommentThread(\n graph: SceneGraph,\n options: {\n pageId: string\n at: Vector\n /** Pin it on this layer's top-level layer rather than on whatever is at `at`. */\n node?: SceneNode\n /** The area the person circled, when the comment was drawn rather than clicked. */\n region?: CommentRegion | null\n author: CommentAuthor\n text: string\n now: string\n }\n): CommentThread {\n const { pageId, at, node, region, author, text, now } = options\n return {\n id: newCommentId('c'),\n pageId,\n pageName: graph.getNode(pageId)?.name,\n ...commentAnchor(graph, pageId, at, node),\n author: author.name,\n authorColor: author.color,\n text,\n createdAt: now,\n updatedAt: now,\n resolved: false,\n ...(region ? { region } : {}),\n replies: []\n }\n}\n\nexport function createCommentReply(author: CommentAuthor, text: string, now: string): CommentReply {\n return {\n id: newCommentId('r'),\n author: author.name,\n authorColor: author.color,\n text,\n createdAt: now\n }\n}\n\n/** The threads with one changed and marked as edited at `now`, for merging with other copies. */\nexport function editCommentThread(\n threads: readonly CommentThread[],\n id: string,\n now: string,\n edit: (thread: CommentThread) => CommentThread\n): CommentThread[] {\n return threads.map((thread) => (thread.id === id ? { ...edit(thread), updatedAt: now } : thread))\n}\n\n/** A reply ends up in the thread and reopens it, as answering a resolved comment does. */\nexport function replyToCommentThread(thread: CommentThread, reply: CommentReply): CommentThread {\n return { ...thread, resolved: false, resolvedAt: null, replies: [...thread.replies, reply] }\n}\n\nexport function resolveCommentThread(\n thread: CommentThread,\n resolved: boolean,\n now: string\n): CommentThread {\n return { ...thread, resolved, resolvedAt: resolved ? now : null }\n}\n\n/** Deleted threads and replies stay as tombstones, so a stale copy cannot bring them back. */\nexport function deleteCommentThread(thread: CommentThread): CommentThread {\n return { ...thread, deleted: true }\n}\n\nexport function deleteCommentReply(thread: CommentThread, replyId: string): CommentThread {\n return {\n ...thread,\n replies: thread.replies.map((entry) =>\n entry.id === replyId ? { ...entry, deleted: true } : entry\n )\n }\n}\n"],"mappings":";;AAWA,SAAS,aAAa,QAA2B;CAC/C,OAAO,GAAG,OAAO,GAAG,UAAU,CAAC;AACjC;;AAGA,SAAgB,mBAA2B;CACzC,wBAAO,IAAI,KAAK,EAAA,CAAE,YAAY;AAChC;;AAGA,SAAgB,YAAY,GAA0B,GAAkC;CACtF,OAAO,EAAE,UAAU,cAAc,EAAE,SAAS;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@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"properties.d.ts","names":[],"sources":["../../src/components/properties.ts"],"mappings":";;;UAYiB;EACf,MAAM;EACN,OAAO;EACP,QAAQ;;;;;;iBAOM,cAAc,OAAO,YAAY,WAAW,YAAY;iBAKxD,wBAAwB,OAAO,YAAY,UAAU,YAAY;iBAQjE,6BACd,OAAO,YACP,UAAU,YACT;iBAUa,8BAA8B,OAAO,YAAY,gBAAgB;iBAkBjE,4BACd,OAAO,YACP,UAAU,WACV,qBACC;iBAIa,6BACd,OAAO,YACP,UAAU,WACV,qBACC;
|
|
1
|
+
{"version":3,"file":"properties.d.ts","names":[],"sources":["../../src/components/properties.ts"],"mappings":";;;UAYiB;EACf,MAAM;EACN,OAAO;EACP,QAAQ;;;;;;iBAOM,cAAc,OAAO,YAAY,WAAW,YAAY;iBAKxD,wBAAwB,OAAO,YAAY,UAAU,YAAY;iBAQjE,6BACd,OAAO,YACP,UAAU,YACT;iBAUa,8BAA8B,OAAO,YAAY,gBAAgB;iBAkBjE,4BACd,OAAO,YACP,UAAU,WACV,qBACC;iBAIa,6BACd,OAAO,YACP,UAAU,WACV,qBACC;iBAkFa,4BACd,OAAO,YACP,oBACA,YAAY,6BACZ,gBACC;iBAmEa,wBACd,OAAO,YACP,iBACA;;iBAwBc"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { setInstanceOverride } from "../instances/overrides.js";
|
|
1
|
+
import { ownInstanceOverrides, setInstanceOverride } from "../instances/overrides.js";
|
|
2
2
|
import { randomHex } from "../random.js";
|
|
3
3
|
import { instanceMainComponent } from "../instances/main-component.js";
|
|
4
4
|
import { walkInstanceSources } from "../instances/source-walk.js";
|
|
@@ -54,7 +54,7 @@ function applyTextProperty(graph, owner, targets, value) {
|
|
|
54
54
|
for (const item of targets) {
|
|
55
55
|
if (item.field !== "TEXT" || item.node.type !== "TEXT") continue;
|
|
56
56
|
graph.updateNode(item.node.id, { text: value });
|
|
57
|
-
if (findInstanceAncestor(graph, item.node.id)) setInstanceOverride(owner
|
|
57
|
+
if (findInstanceAncestor(graph, item.node.id)) setInstanceOverride(ownInstanceOverrides(owner), owner.id, item.node.id, "text", value);
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
function applyBooleanProperty(graph, owner, targets, value) {
|
|
@@ -62,17 +62,17 @@ function applyBooleanProperty(graph, owner, targets, value) {
|
|
|
62
62
|
if (item.field !== "VISIBLE") continue;
|
|
63
63
|
const instance = findInstanceAncestor(graph, item.node.id);
|
|
64
64
|
graph.updateNode(item.node.id, { visible: value === "true" });
|
|
65
|
-
if (instance) setInstanceOverride(owner
|
|
65
|
+
if (instance) setInstanceOverride(ownInstanceOverrides(owner), owner.id, item.node.id, "visible", value === "true");
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
function applyInstanceSwapProperty(graph, owner, targets, target) {
|
|
69
69
|
for (const item of targets) {
|
|
70
70
|
if (item.field !== "INSTANCE_SWAP" || item.node.type !== "INSTANCE") continue;
|
|
71
71
|
graph.swapInstanceComponent(item.node.id, target.id);
|
|
72
|
-
setInstanceOverride(owner
|
|
73
|
-
setInstanceOverride(owner
|
|
74
|
-
setInstanceOverride(owner
|
|
75
|
-
graph.updateNode(owner.id, { instanceOverrides: owner
|
|
72
|
+
setInstanceOverride(ownInstanceOverrides(owner), owner.id, item.node.id, "name", target.name);
|
|
73
|
+
setInstanceOverride(ownInstanceOverrides(owner), owner.id, item.node.id, "componentId", target.id);
|
|
74
|
+
setInstanceOverride(ownInstanceOverrides(owner), owner.id, item.node.id, "sourceComponentId", item.source.id);
|
|
75
|
+
graph.updateNode(owner.id, { instanceOverrides: ownInstanceOverrides(owner) });
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
function applyComponentPropertyValue(graph, instanceId, definition, value) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"properties.js","names":[],"sources":["../../src/components/properties.ts"],"sourcesContent":["import type { SceneGraph } from '../graph'\nimport { findInstanceAncestor, recordAssignmentOverride } from '../instances'\nimport { instanceMainComponent } from '../instances/main-component'\nimport { setInstanceOverride } from '../instances/overrides'\nimport { walkInstanceSources } from '../instances/source-walk'\nimport { randomHex } from '../random'\nimport type {\n ComponentPropertyDefinition,\n ComponentPropertyReferenceField,\n SceneNode\n} from '../types'\n\nexport interface ComponentPropertyTarget {\n node: SceneNode\n field: ComponentPropertyReferenceField\n source: SceneNode\n}\n\n/**\n * The component that defines a main component's properties: its set when it is a variant,\n * since variants own no properties of their own (desktop 126), else the component itself.\n */\nexport function propertyOwner(graph: SceneGraph, component: SceneNode): SceneNode {\n const parent = component.parentId ? graph.getNode(component.parentId) : undefined\n return component.type === 'COMPONENT' && parent?.type === 'COMPONENT_SET' ? parent : component\n}\n\nexport function componentPropertyOwners(graph: SceneGraph, instance: SceneNode): SceneNode[] {\n if (instance.type !== 'INSTANCE') return []\n const component = instanceMainComponent(graph, instance)\n if (!component) return []\n const parent = component.parentId ? graph.getNode(component.parentId) : null\n return parent?.type === 'COMPONENT_SET' ? [parent, component] : [component]\n}\n\nexport function componentPropertyDefinitions(\n graph: SceneGraph,\n instance: SceneNode\n): ComponentPropertyDefinition[] {\n const definitions = new Map<string, ComponentPropertyDefinition>()\n for (const owner of componentPropertyOwners(graph, instance)) {\n for (const definition of owner.componentPropertyDefinitions) {\n if (!definitions.has(definition.id)) definitions.set(definition.id, definition)\n }\n }\n return [...definitions.values()]\n}\n\nexport function resolveComponentPropertyValue(graph: SceneGraph, value: string): SceneNode | null {\n const direct = graph.getNode(value)\n if (direct?.type === 'COMPONENT') return direct\n if (direct?.type === 'COMPONENT_SET') {\n const componentId = direct.childIds.find((id) => graph.getNode(id)?.type === 'COMPONENT')\n return componentId ? (graph.getNode(componentId) ?? null) : null\n }\n for (const node of graph.getAllNodes()) {\n if (\n node.type === 'COMPONENT' &&\n (node.componentKey === value || node.sourceLibraryKey === value || node.source.id === value)\n ) {\n return node\n }\n }\n return null\n}\n\nexport function findComponentPropertyTarget(\n graph: SceneGraph,\n instance: SceneNode,\n propertyId: string\n): ComponentPropertyTarget | null {\n return findComponentPropertyTargets(graph, instance, propertyId)[0] ?? null\n}\n\nexport function findComponentPropertyTargets(\n graph: SceneGraph,\n instance: SceneNode,\n propertyId: string\n): ComponentPropertyTarget[] {\n const targets: ComponentPropertyTarget[] = []\n walkInstanceSources(\n graph,\n instance,\n (source, target) => {\n const reference = source.componentPropertyReferences.find(\n (candidate) => candidate.propertyId === propertyId\n )\n if (reference) targets.push({ node: target, field: reference.field, source })\n return true\n },\n true\n )\n return targets\n}\n\nfunction applyTextProperty(\n graph: SceneGraph,\n owner: SceneNode,\n targets: ComponentPropertyTarget[],\n value: string\n): void {\n for (const item of targets) {\n if (item.field !== 'TEXT' || item.node.type !== 'TEXT') continue\n graph.updateNode(item.node.id, { text: value })\n if (findInstanceAncestor(graph, item.node.id)) {\n setInstanceOverride(owner.instanceOverrides, owner.id, item.node.id, 'text', value)\n }\n }\n}\n\nfunction applyBooleanProperty(\n graph: SceneGraph,\n owner: SceneNode,\n targets: ComponentPropertyTarget[],\n value: string\n): void {\n for (const item of targets) {\n if (item.field !== 'VISIBLE') continue\n const instance = findInstanceAncestor(graph, item.node.id)\n graph.updateNode(item.node.id, { visible: value === 'true' })\n if (instance) {\n setInstanceOverride(\n owner.instanceOverrides,\n owner.id,\n item.node.id,\n 'visible',\n value === 'true'\n )\n }\n }\n}\n\nfunction applyInstanceSwapProperty(\n graph: SceneGraph,\n owner: SceneNode,\n targets: ComponentPropertyTarget[],\n target: SceneNode\n): void {\n for (const item of targets) {\n if (item.field !== 'INSTANCE_SWAP' || item.node.type !== 'INSTANCE') continue\n graph.swapInstanceComponent(item.node.id, target.id)\n setInstanceOverride(owner.instanceOverrides, owner.id, item.node.id, 'name', target.name)\n setInstanceOverride(owner.instanceOverrides, owner.id, item.node.id, 'componentId', target.id)\n setInstanceOverride(\n owner.instanceOverrides,\n owner.id,\n item.node.id,\n 'sourceComponentId',\n item.source.id\n )\n graph.updateNode(owner.id, { instanceOverrides: owner.instanceOverrides })\n }\n}\n\nexport function applyComponentPropertyValue(\n graph: SceneGraph,\n instanceId: string,\n definition: ComponentPropertyDefinition,\n value: string\n): SceneNode | null {\n const instance = graph.getNode(instanceId)\n if (instance?.type !== 'INSTANCE') return null\n if (definition.type === 'VARIANT') return null\n const targets = findComponentPropertyTargets(graph, instance, definition.id)\n const target =\n definition.type === 'INSTANCE_SWAP' ? resolveComponentPropertyValue(graph, value) : null\n if (definition.type === 'INSTANCE_SWAP' && !target) return null\n if (definition.type === 'TEXT') {\n applyTextProperty(graph, instance, targets, value)\n } else if (definition.type === 'BOOLEAN') {\n applyBooleanProperty(graph, instance, targets, value)\n } else if (target) {\n applyInstanceSwapProperty(graph, instance, targets, target)\n }\n const previous = instance.componentPropertyAssignments[definition.id]\n const assigned = definition.type === 'INSTANCE_SWAP' && target ? target.id : value\n graph.updateNode(instance.id, {\n componentPropertyAssignments: {\n ...instance.componentPropertyAssignments,\n [definition.id]: assigned\n }\n })\n // Assigning a nested instance's property is an edit of the instance above it, so it outranks\n // a text override at that same level. Reapplying the value a property already has (a variant\n // swap, a reload) is not an edit and records nothing.\n if (previous !== assigned) recordAssignmentOverride(graph, instance.id, definition.id, value)\n return definition.type === 'INSTANCE_SWAP' ? target : instance\n}\n\nfunction componentSubtree(graph: SceneGraph, componentId: string): SceneNode[] {\n const component = graph.getNode(componentId)\n if (!component) return []\n const nodes = [component]\n const visit = (node: SceneNode): void => {\n for (const child of graph.getChildren(node.id)) {\n nodes.push(child)\n visit(child)\n }\n }\n visit(component)\n return nodes\n}\n\nfunction componentInstances(graph: SceneGraph, componentId: string): SceneNode[] {\n return [...graph.getAllNodes()].filter(\n (node) => node.type === 'INSTANCE' && node.componentId === componentId\n )\n}\n\nfunction removePropertyFromNode(graph: SceneGraph, node: SceneNode, propertyId: string): void {\n if (node.componentPropertyReferences.some((reference) => reference.propertyId === propertyId)) {\n graph.updateNode(node.id, {\n componentPropertyReferences: node.componentPropertyReferences.filter(\n (reference) => reference.propertyId !== propertyId\n )\n })\n }\n if (node.type === 'INSTANCE' && propertyId in node.componentPropertyAssignments) {\n graph.updateNode(node.id, {\n componentPropertyAssignments: Object.fromEntries(\n Object.entries(node.componentPropertyAssignments).filter(([id]) => id !== propertyId)\n )\n })\n }\n}\n\nexport function removeComponentProperty(\n graph: SceneGraph,\n ownerId: string,\n propertyId: string\n): boolean {\n const owner = graph.getNode(ownerId)\n if (!owner || (owner.type !== 'COMPONENT' && owner.type !== 'COMPONENT_SET')) return false\n graph.updateNode(owner.id, {\n componentPropertyDefinitions: owner.componentPropertyDefinitions.filter(\n (definition) => definition.id !== propertyId\n )\n })\n const nodes = [\n ...componentSubtree(graph, owner.id),\n ...componentInstances(graph, owner.id),\n ...(owner.type === 'COMPONENT_SET'\n ? owner.childIds.flatMap((id) => [\n ...componentSubtree(graph, id),\n ...componentInstances(graph, id)\n ])\n : [])\n ]\n for (const node of nodes) removePropertyFromNode(graph, node, propertyId)\n return true\n}\n\n/** A new component property ID, in the `prop:` form the editor, plugin API, and design JSX share. */\nexport function createComponentPropertyId(): string {\n return `prop:${randomHex(8)}`\n}\n"],"mappings":";;;;;;;;;;AAsBA,SAAgB,cAAc,OAAmB,WAAiC;CAChF,MAAM,SAAS,UAAU,WAAW,MAAM,QAAQ,UAAU,QAAQ,IAAI,KAAA;CACxE,OAAO,UAAU,SAAS,eAAe,QAAQ,SAAS,kBAAkB,SAAS;AACvF;AAEA,SAAgB,wBAAwB,OAAmB,UAAkC;CAC3F,IAAI,SAAS,SAAS,YAAY,OAAO,CAAC;CAC1C,MAAM,YAAY,sBAAsB,OAAO,QAAQ;CACvD,IAAI,CAAC,WAAW,OAAO,CAAC;CACxB,MAAM,SAAS,UAAU,WAAW,MAAM,QAAQ,UAAU,QAAQ,IAAI;CACxE,OAAO,QAAQ,SAAS,kBAAkB,CAAC,QAAQ,SAAS,IAAI,CAAC,SAAS;AAC5E;AAEA,SAAgB,6BACd,OACA,UA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,WAAW,KAAK,IAAI,EACxB,8BAA8B,OAAO,YACnC,OAAO,QAAQ,KAAK,4BAA4B,CAAC,CAAC,QAAQ,CAAC,QAAQ,OAAO,UAAU,CACtF,EACF,CAAC;AAEL;AAEA,SAAgB,wBACd,OACA,SACA,YACS;CACT,MAAM,QAAQ,MAAM,QAAQ,OAAO;CACnC,IAAI,CAAC,SAAU,MAAM,SAAS,eAAe,MAAM,SAAS,iBAAkB,OAAO;CACrF,MAAM,WAAW,MAAM,IAAI,EACzB,8BAA8B,MAAM,6BAA6B,QAC9D,eAAe,WAAW,OAAO,UACpC,EACF,CAAC;CACD,MAAM,QAAQ;EACZ,GAAG,iBAAiB,OAAO,MAAM,EAAE;EACnC,GAAG,mBAAmB,OAAO,MAAM,EAAE;EACrC,GAAI,MAAM,SAAS,kBACf,MAAM,SAAS,SAAS,OAAO,CAC7B,GAAG,iBAAiB,OAAO,EAAE,GAC7B,GAAG,mBAAmB,OAAO,EAAE,CACjC,CAAC,IACD,CAAC;CACP;CACA,KAAK,MAAM,QAAQ,OAAO,uBAAuB,OAAO,MAAM,UAAU;CACxE,OAAO;AACT;;AAGA,SAAgB,4BAAoC;CAClD,OAAO,QAAQ,UAAU,CAAC;AAC5B"}
|
|
1
|
+
{"version":3,"file":"properties.js","names":[],"sources":["../../src/components/properties.ts"],"sourcesContent":["import type { SceneGraph } from '../graph'\nimport { findInstanceAncestor, recordAssignmentOverride } from '../instances'\nimport { instanceMainComponent } from '../instances/main-component'\nimport { ownInstanceOverrides, setInstanceOverride } from '../instances/overrides'\nimport { walkInstanceSources } from '../instances/source-walk'\nimport { randomHex } from '../random'\nimport type {\n ComponentPropertyDefinition,\n ComponentPropertyReferenceField,\n SceneNode\n} from '../types'\n\nexport interface ComponentPropertyTarget {\n node: SceneNode\n field: ComponentPropertyReferenceField\n source: SceneNode\n}\n\n/**\n * The component that defines a main component's properties: its set when it is a variant,\n * since variants own no properties of their own (desktop 126), else the component itself.\n */\nexport function propertyOwner(graph: SceneGraph, component: SceneNode): SceneNode {\n const parent = component.parentId ? graph.getNode(component.parentId) : undefined\n return component.type === 'COMPONENT' && parent?.type === 'COMPONENT_SET' ? parent : component\n}\n\nexport function componentPropertyOwners(graph: SceneGraph, instance: SceneNode): SceneNode[] {\n if (instance.type !== 'INSTANCE') return []\n const component = instanceMainComponent(graph, instance)\n if (!component) return []\n const parent = component.parentId ? graph.getNode(component.parentId) : null\n return parent?.type === 'COMPONENT_SET' ? [parent, component] : [component]\n}\n\nexport function componentPropertyDefinitions(\n graph: SceneGraph,\n instance: SceneNode\n): ComponentPropertyDefinition[] {\n const definitions = new Map<string, ComponentPropertyDefinition>()\n for (const owner of componentPropertyOwners(graph, instance)) {\n for (const definition of owner.componentPropertyDefinitions) {\n if (!definitions.has(definition.id)) definitions.set(definition.id, definition)\n }\n }\n return [...definitions.values()]\n}\n\nexport function resolveComponentPropertyValue(graph: SceneGraph, value: string): SceneNode | null {\n const direct = graph.getNode(value)\n if (direct?.type === 'COMPONENT') return direct\n if (direct?.type === 'COMPONENT_SET') {\n const componentId = direct.childIds.find((id) => graph.getNode(id)?.type === 'COMPONENT')\n return componentId ? (graph.getNode(componentId) ?? null) : null\n }\n for (const node of graph.getAllNodes()) {\n if (\n node.type === 'COMPONENT' &&\n (node.componentKey === value || node.sourceLibraryKey === value || node.source.id === value)\n ) {\n return node\n }\n }\n return null\n}\n\nexport function findComponentPropertyTarget(\n graph: SceneGraph,\n instance: SceneNode,\n propertyId: string\n): ComponentPropertyTarget | null {\n return findComponentPropertyTargets(graph, instance, propertyId)[0] ?? null\n}\n\nexport function findComponentPropertyTargets(\n graph: SceneGraph,\n instance: SceneNode,\n propertyId: string\n): ComponentPropertyTarget[] {\n const targets: ComponentPropertyTarget[] = []\n walkInstanceSources(\n graph,\n instance,\n (source, target) => {\n const reference = source.componentPropertyReferences.find(\n (candidate) => candidate.propertyId === propertyId\n )\n if (reference) targets.push({ node: target, field: reference.field, source })\n return true\n },\n true\n )\n return targets\n}\n\nfunction applyTextProperty(\n graph: SceneGraph,\n owner: SceneNode,\n targets: ComponentPropertyTarget[],\n value: string\n): void {\n for (const item of targets) {\n if (item.field !== 'TEXT' || item.node.type !== 'TEXT') continue\n graph.updateNode(item.node.id, { text: value })\n if (findInstanceAncestor(graph, item.node.id)) {\n setInstanceOverride(ownInstanceOverrides(owner), owner.id, item.node.id, 'text', value)\n }\n }\n}\n\nfunction applyBooleanProperty(\n graph: SceneGraph,\n owner: SceneNode,\n targets: ComponentPropertyTarget[],\n value: string\n): void {\n for (const item of targets) {\n if (item.field !== 'VISIBLE') continue\n const instance = findInstanceAncestor(graph, item.node.id)\n graph.updateNode(item.node.id, { visible: value === 'true' })\n if (instance) {\n setInstanceOverride(\n ownInstanceOverrides(owner),\n owner.id,\n item.node.id,\n 'visible',\n value === 'true'\n )\n }\n }\n}\n\nfunction applyInstanceSwapProperty(\n graph: SceneGraph,\n owner: SceneNode,\n targets: ComponentPropertyTarget[],\n target: SceneNode\n): void {\n for (const item of targets) {\n if (item.field !== 'INSTANCE_SWAP' || item.node.type !== 'INSTANCE') continue\n graph.swapInstanceComponent(item.node.id, target.id)\n setInstanceOverride(ownInstanceOverrides(owner), owner.id, item.node.id, 'name', target.name)\n setInstanceOverride(\n ownInstanceOverrides(owner),\n owner.id,\n item.node.id,\n 'componentId',\n target.id\n )\n setInstanceOverride(\n ownInstanceOverrides(owner),\n owner.id,\n item.node.id,\n 'sourceComponentId',\n item.source.id\n )\n graph.updateNode(owner.id, { instanceOverrides: ownInstanceOverrides(owner) })\n }\n}\n\nexport function applyComponentPropertyValue(\n graph: SceneGraph,\n instanceId: string,\n definition: ComponentPropertyDefinition,\n value: string\n): SceneNode | null {\n const instance = graph.getNode(instanceId)\n if (instance?.type !== 'INSTANCE') return null\n if (definition.type === 'VARIANT') return null\n const targets = findComponentPropertyTargets(graph, instance, definition.id)\n const target =\n definition.type === 'INSTANCE_SWAP' ? resolveComponentPropertyValue(graph, value) : null\n if (definition.type === 'INSTANCE_SWAP' && !target) return null\n if (definition.type === 'TEXT') {\n applyTextProperty(graph, instance, targets, value)\n } else if (definition.type === 'BOOLEAN') {\n applyBooleanProperty(graph, instance, targets, value)\n } else if (target) {\n applyInstanceSwapProperty(graph, instance, targets, target)\n }\n const previous = instance.componentPropertyAssignments[definition.id]\n const assigned = definition.type === 'INSTANCE_SWAP' && target ? target.id : value\n graph.updateNode(instance.id, {\n componentPropertyAssignments: {\n ...instance.componentPropertyAssignments,\n [definition.id]: assigned\n }\n })\n // Assigning a nested instance's property is an edit of the instance above it, so it outranks\n // a text override at that same level. Reapplying the value a property already has (a variant\n // swap, a reload) is not an edit and records nothing.\n if (previous !== assigned) recordAssignmentOverride(graph, instance.id, definition.id, value)\n return definition.type === 'INSTANCE_SWAP' ? target : instance\n}\n\nfunction componentSubtree(graph: SceneGraph, componentId: string): SceneNode[] {\n const component = graph.getNode(componentId)\n if (!component) return []\n const nodes = [component]\n const visit = (node: SceneNode): void => {\n for (const child of graph.getChildren(node.id)) {\n nodes.push(child)\n visit(child)\n }\n }\n visit(component)\n return nodes\n}\n\nfunction componentInstances(graph: SceneGraph, componentId: string): SceneNode[] {\n return [...graph.getAllNodes()].filter(\n (node) => node.type === 'INSTANCE' && node.componentId === componentId\n )\n}\n\nfunction removePropertyFromNode(graph: SceneGraph, node: SceneNode, propertyId: string): void {\n if (node.componentPropertyReferences.some((reference) => reference.propertyId === propertyId)) {\n graph.updateNode(node.id, {\n componentPropertyReferences: node.componentPropertyReferences.filter(\n (reference) => reference.propertyId !== propertyId\n )\n })\n }\n if (node.type === 'INSTANCE' && propertyId in node.componentPropertyAssignments) {\n graph.updateNode(node.id, {\n componentPropertyAssignments: Object.fromEntries(\n Object.entries(node.componentPropertyAssignments).filter(([id]) => id !== propertyId)\n )\n })\n }\n}\n\nexport function removeComponentProperty(\n graph: SceneGraph,\n ownerId: string,\n propertyId: string\n): boolean {\n const owner = graph.getNode(ownerId)\n if (!owner || (owner.type !== 'COMPONENT' && owner.type !== 'COMPONENT_SET')) return false\n graph.updateNode(owner.id, {\n componentPropertyDefinitions: owner.componentPropertyDefinitions.filter(\n (definition) => definition.id !== propertyId\n )\n })\n const nodes = [\n ...componentSubtree(graph, owner.id),\n ...componentInstances(graph, owner.id),\n ...(owner.type === 'COMPONENT_SET'\n ? owner.childIds.flatMap((id) => [\n ...componentSubtree(graph, id),\n ...componentInstances(graph, id)\n ])\n : [])\n ]\n for (const node of nodes) removePropertyFromNode(graph, node, propertyId)\n return true\n}\n\n/** A new component property ID, in the `prop:` form the editor, plugin API, and design JSX share. */\nexport function createComponentPropertyId(): string {\n return `prop:${randomHex(8)}`\n}\n"],"mappings":";;;;;;;;;;AAsBA,SAAgB,cAAc,OAAmB,WAAiC;CAChF,MAAM,SAAS,UAAU,WAAW,MAAM,QAAQ,UAAU,QAAQ,IAAI,KAAA;CACxE,OAAO,UAAU,SAAS,eAAe,QAAQ,SAAS,kBAAkB,SAAS;AACvF;AAEA,SAAgB,wBAAwB,OAAmB,UAAkC;CAC3F,IAAI,SAAS,SAAS,YAAY,OAAO,CAAC;CAC1C,MAAM,YAAY,sBAAsB,OAAO,QAAQ;CACvD,IAAI,CAAC,WAAW,OAAO,CAAC;CACxB,MAAM,SAAS,UAAU,WAAW,MAAM,QAAQ,UAAU,QAAQ,IAAI;CACxE,OAAO,QAAQ,SAAS,kBAAkB,CAAC,QAAQ,SAAS,IAAI,CAAC,SAAS;AAC5E;AAEA,SAAgB,6BACd,OACA,UAC+B;CAC/B,MAAM,8BAAc,IAAI,IAAyC;CACjE,KAAK,MAAM,SAAS,wBAAwB,OAAO,QAAQ,GACzD,KAAK,MAAM,cAAc,MAAM,8BAC7B,IAAI,CAAC,YAAY,IAAI,WAAW,EAAE,GAAG,YAAY,IAAI,WAAW,IAAI,UAAU;CAGlF,OAAO,CAAC,GAAG,YAAY,OAAO,CAAC;AACjC;AAEA,SAAgB,8BAA8B,OAAmB,OAAiC;CAChG,MAAM,SAAS,MAAM,QAAQ,KAAK;CAClC,I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AM,WAAW,MAAM,IAAI,EACzB,8BAA8B,MAAM,6BAA6B,QAC9D,eAAe,WAAW,OAAO,UACpC,EACF,CAAC;CACD,MAAM,QAAQ;EACZ,GAAG,iBAAiB,OAAO,MAAM,EAAE;EACnC,GAAG,mBAAmB,OAAO,MAAM,EAAE;EACrC,GAAI,MAAM,SAAS,kBACf,MAAM,SAAS,SAAS,OAAO,CAC7B,GAAG,iBAAiB,OAAO,EAAE,GAC7B,GAAG,mBAAmB,OAAO,EAAE,CACjC,CAAC,IACD,CAAC;CACP;CACA,KAAK,MAAM,QAAQ,OAAO,uBAAuB,OAAO,MAAM,UAAU;CACxE,OAAO;AACT;;AAGA,SAAgB,4BAAoC;CAClD,OAAO,QAAQ,UAAU,CAAC;AAC5B"}
|
package/dist/css/shadows.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Effect } from "../types.js";
|
|
1
|
+
import { DocumentColorSpace, Effect } from "../types.js";
|
|
2
2
|
//#region src/css/shadows.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* The shadows of a CSS `box-shadow` or `text-shadow` list, such as
|
|
5
5
|
* `0 4px 8px rgb(0 0 0 / 0.2), inset 0 1px #fff`: drop shadows, and inner shadows for `inset`.
|
|
6
6
|
*/
|
|
7
|
-
declare function parseCSSShadows(value: string | undefined): Effect[];
|
|
7
|
+
declare function parseCSSShadows(value: string | undefined, profile?: DocumentColorSpace): Effect[];
|
|
8
8
|
//#endregion
|
|
9
9
|
export { parseCSSShadows };
|
|
10
10
|
//# sourceMappingURL=shadows.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shadows.d.ts","names":[],"sources":["../../src/css/shadows.ts"],"mappings":";;;;;;iBAgDgB,
|
|
1
|
+
{"version":3,"file":"shadows.d.ts","names":[],"sources":["../../src/css/shadows.ts"],"mappings":";;;;;;iBAgDgB,gBACd,2BACA,UAAS,qBACR"}
|
package/dist/css/shadows.js
CHANGED
|
@@ -7,7 +7,7 @@ import valueParser from "postcss-value-parser";
|
|
|
7
7
|
* One layer: `inset`, two to four lengths, and a color in any order. Without a color it is
|
|
8
8
|
* black, as `currentColor` usually is; a layer with anything else, such as `none`, is dropped.
|
|
9
9
|
*/
|
|
10
|
-
function shadowOf(nodes) {
|
|
10
|
+
function shadowOf(nodes, profile) {
|
|
11
11
|
let inset = false;
|
|
12
12
|
let color = null;
|
|
13
13
|
const lengths = [];
|
|
@@ -21,7 +21,7 @@ function shadowOf(nodes) {
|
|
|
21
21
|
lengths.push(length);
|
|
22
22
|
continue;
|
|
23
23
|
}
|
|
24
|
-
const parsed = tryParseColor(valueParser.stringify(node));
|
|
24
|
+
const parsed = tryParseColor(valueParser.stringify(node), profile);
|
|
25
25
|
if (!parsed || color) return [];
|
|
26
26
|
color = parsed;
|
|
27
27
|
}
|
|
@@ -43,9 +43,9 @@ function shadowOf(nodes) {
|
|
|
43
43
|
* The shadows of a CSS `box-shadow` or `text-shadow` list, such as
|
|
44
44
|
* `0 4px 8px rgb(0 0 0 / 0.2), inset 0 1px #fff`: drop shadows, and inner shadows for `inset`.
|
|
45
45
|
*/
|
|
46
|
-
function parseCSSShadows(value) {
|
|
46
|
+
function parseCSSShadows(value, profile = "srgb") {
|
|
47
47
|
if (!value) return [];
|
|
48
|
-
return cssLayers(valueParser(value).nodes).flatMap(shadowOf);
|
|
48
|
+
return cssLayers(valueParser(value).nodes).flatMap((nodes) => shadowOf(nodes, profile));
|
|
49
49
|
}
|
|
50
50
|
//#endregion
|
|
51
51
|
export { parseCSSShadows };
|
package/dist/css/shadows.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shadows.js","names":[],"sources":["../../src/css/shadows.ts"],"sourcesContent":["import valueParser, { type Node } from 'postcss-value-parser'\n\nimport { tryParseColor } from '../color'\nimport { BLACK } from '../constants'\nimport type { Color } from '../primitives'\nimport type { Effect } from '../types'\nimport { cssLayers, parseCSSNumber } from './values'\n\n/**\n * One layer: `inset`, two to four lengths, and a color in any order. Without a color it is\n * black, as `currentColor` usually is; a layer with anything else, such as `none`, is dropped.\n */\nfunction shadowOf(nodes: Node[]): Effect[] {\n let inset = false\n let color: Color | null = null\n const lengths: number[] = []\n for (const node of nodes) {\n if (node.type === 'word' && node.value.toLowerCase() === 'inset') {\n inset = true\n continue\n }\n const length = node.type === 'word' ? parseCSSNumber(node.value) : null\n if (length !== null) {\n lengths.push(length)\n continue\n }\n const parsed = tryParseColor(valueParser.stringify(node))\n if (!parsed || color) return []\n color = parsed\n }\n if (lengths.length < 2 || lengths.length > 4 || color?.a === 0) return []\n const [x = 0, y = 0, radius = 0, spread = 0] = lengths\n return [\n {\n type: inset ? 'INNER_SHADOW' : 'DROP_SHADOW',\n color: color ?? { ...BLACK },\n offset: { x, y },\n radius,\n spread,\n visible: true\n }\n ]\n}\n\n/**\n * The shadows of a CSS `box-shadow` or `text-shadow` list, such as\n * `0 4px 8px rgb(0 0 0 / 0.2), inset 0 1px #fff`: drop shadows, and inner shadows for `inset`.\n */\nexport function parseCSSShadows(value: string | undefined): Effect[] {\n if (!value) return []\n return cssLayers(valueParser(value).nodes).flatMap(shadowOf)\n}\n"],"mappings":";;;;;;;;;AAYA,SAAS,SAAS,
|
|
1
|
+
{"version":3,"file":"shadows.js","names":[],"sources":["../../src/css/shadows.ts"],"sourcesContent":["import valueParser, { type Node } from 'postcss-value-parser'\n\nimport { tryParseColor } from '../color'\nimport { BLACK } from '../constants'\nimport type { Color } from '../primitives'\nimport type { DocumentColorSpace, Effect } from '../types'\nimport { cssLayers, parseCSSNumber } from './values'\n\n/**\n * One layer: `inset`, two to four lengths, and a color in any order. Without a color it is\n * black, as `currentColor` usually is; a layer with anything else, such as `none`, is dropped.\n */\nfunction shadowOf(nodes: Node[], profile: DocumentColorSpace): Effect[] {\n let inset = false\n let color: Color | null = null\n const lengths: number[] = []\n for (const node of nodes) {\n if (node.type === 'word' && node.value.toLowerCase() === 'inset') {\n inset = true\n continue\n }\n const length = node.type === 'word' ? parseCSSNumber(node.value) : null\n if (length !== null) {\n lengths.push(length)\n continue\n }\n const parsed = tryParseColor(valueParser.stringify(node), profile)\n if (!parsed || color) return []\n color = parsed\n }\n if (lengths.length < 2 || lengths.length > 4 || color?.a === 0) return []\n const [x = 0, y = 0, radius = 0, spread = 0] = lengths\n return [\n {\n type: inset ? 'INNER_SHADOW' : 'DROP_SHADOW',\n color: color ?? { ...BLACK },\n offset: { x, y },\n radius,\n spread,\n visible: true\n }\n ]\n}\n\n/**\n * The shadows of a CSS `box-shadow` or `text-shadow` list, such as\n * `0 4px 8px rgb(0 0 0 / 0.2), inset 0 1px #fff`: drop shadows, and inner shadows for `inset`.\n */\nexport function parseCSSShadows(\n value: string | undefined,\n profile: DocumentColorSpace = 'srgb'\n): Effect[] {\n if (!value) return []\n return cssLayers(valueParser(value).nodes).flatMap((nodes) => shadowOf(nodes, profile))\n}\n"],"mappings":";;;;;;;;;AAYA,SAAS,SAAS,OAAe,SAAuC;CACtE,IAAI,QAAQ;CACZ,IAAI,QAAsB;CAC1B,MAAM,UAAoB,CAAC;CAC3B,KAAK,MAAM,QAAQ,OAAO;EACxB,IAAI,KAAK,SAAS,UAAU,KAAK,MAAM,YAAY,MAAM,SAAS;GAChE,QAAQ;GACR;EACF;EACA,MAAM,SAAS,KAAK,SAAS,SAAS,eAAe,KAAK,KAAK,IAAI;EACnE,IAAI,WAAW,MAAM;GACnB,QAAQ,KAAK,MAAM;GACnB;EACF;EACA,MAAM,SAAS,cAAc,YAAY,UAAU,IAAI,GAAG,OAAO;EACjE,IAAI,CAAC,UAAU,OAAO,OAAO,CAAC;EAC9B,QAAQ;CACV;CACA,IAAI,QAAQ,SAAS,KAAK,QAAQ,SAAS,KAAK,OAAO,MAAM,GAAG,OAAO,CAAC;CACxE,MAAM,CAAC,IAAI,GAAG,IAAI,GAAG,SAAS,GAAG,SAAS,KAAK;CAC/C,OAAO,CACL;EACE,MAAM,QAAQ,iBAAiB;EAC/B,OAAO,SAAS,EAAE,GAAG,MAAM;EAC3B,QAAQ;GAAE;GAAG;EAAE;EACf;EACA;EACA,SAAS;CACX,CACF;AACF;;;;;AAMA,SAAgB,gBACd,OACA,UAA8B,QACpB;CACV,IAAI,CAAC,OAAO,OAAO,CAAC;CACpB,OAAO,UAAU,YAAY,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,SAAS,UAAU,SAAS,OAAO,OAAO,CAAC;AACxF"}
|
package/dist/css/values.d.ts
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import { Color } from "../primitives/index.js";
|
|
2
|
+
import { DocumentColorSpace } from "../types.js";
|
|
2
3
|
//#region src/css/values.d.ts
|
|
3
4
|
/**
|
|
4
5
|
* A CSS number in pixels: unitless, `px`, or `rem`. Null for `auto`, for units that depend on
|
|
5
6
|
* what the value applies to (`%`, `em`, `vh`), and for anything that is not a number.
|
|
6
7
|
*/
|
|
7
8
|
declare function parseCSSNumber(value: string | undefined): number | null;
|
|
8
|
-
/**
|
|
9
|
-
|
|
9
|
+
/**
|
|
10
|
+
* A CSS color that paints something, as components in `profile`; null for an invalid or fully
|
|
11
|
+
* transparent one. A stylesheet's own declarations are read in sRGB, as CSS authors them; a caller
|
|
12
|
+
* reading markup into a document passes the document's profile.
|
|
13
|
+
*/
|
|
14
|
+
declare function parseCSSColor(value: string | undefined, profile?: DocumentColorSpace): Color | null;
|
|
10
15
|
/** The space-separated parts of a CSS value, keeping functions such as `rgb(0, 0, 0)` whole. */
|
|
11
16
|
declare function splitCSSValue(value: string): string[];
|
|
12
17
|
//#endregion
|
package/dist/css/values.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"values.d.ts","names":[],"sources":["../../src/css/values.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"values.d.ts","names":[],"sources":["../../src/css/values.ts"],"mappings":";;;;;;;iBAagB,eAAe;;;;;;iBAsBf,cACd,2BACA,UAAS,qBACR;;iBAOa,cAAc"}
|
package/dist/css/values.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { tryParseColor } from "../color/index.js";
|
|
2
2
|
import valueParser from "postcss-value-parser";
|
|
3
3
|
//#region src/css/values.ts
|
|
4
4
|
/** Pixels in a rem, as browsers use by default. */
|
|
@@ -20,10 +20,14 @@ function parseCSSNumber(value) {
|
|
|
20
20
|
default: return null;
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
-
/**
|
|
24
|
-
|
|
23
|
+
/**
|
|
24
|
+
* A CSS color that paints something, as components in `profile`; null for an invalid or fully
|
|
25
|
+
* transparent one. A stylesheet's own declarations are read in sRGB, as CSS authors them; a caller
|
|
26
|
+
* reading markup into a document passes the document's profile.
|
|
27
|
+
*/
|
|
28
|
+
function parseCSSColor(value, profile = "srgb") {
|
|
25
29
|
if (!value) return null;
|
|
26
|
-
const color =
|
|
30
|
+
const color = tryParseColor(value.trim(), profile);
|
|
27
31
|
return color && color.a > 0 ? color : null;
|
|
28
32
|
}
|
|
29
33
|
/** The space-separated parts of a CSS value, keeping functions such as `rgb(0, 0, 0)` whole. */
|
package/dist/css/values.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"values.js","names":[],"sources":["../../src/css/values.ts"],"sourcesContent":["import valueParser, { type Node } from 'postcss-value-parser'\n\nimport {
|
|
1
|
+
{"version":3,"file":"values.js","names":[],"sources":["../../src/css/values.ts"],"sourcesContent":["import valueParser, { type Node } from 'postcss-value-parser'\n\nimport { tryParseColor } from '../color'\nimport type { Color } from '../primitives'\nimport type { DocumentColorSpace } from '../types'\n\n/** Pixels in a rem, as browsers use by default. */\nconst ROOT_FONT_SIZE = 16\n\n/**\n * A CSS number in pixels: unitless, `px`, or `rem`. Null for `auto`, for units that depend on\n * what the value applies to (`%`, `em`, `vh`), and for anything that is not a number.\n */\nexport function parseCSSNumber(value: string | undefined): number | null {\n if (!value) return null\n const dimension = valueParser.unit(value.trim())\n if (!dimension) return null\n const number = Number(dimension.number)\n if (!Number.isFinite(number)) return null\n switch (dimension.unit.toLowerCase()) {\n case '':\n case 'px':\n return number\n case 'rem':\n return number * ROOT_FONT_SIZE\n default:\n return null\n }\n}\n\n/**\n * A CSS color that paints something, as components in `profile`; null for an invalid or fully\n * transparent one. A stylesheet's own declarations are read in sRGB, as CSS authors them; a caller\n * reading markup into a document passes the document's profile.\n */\nexport function parseCSSColor(\n value: string | undefined,\n profile: DocumentColorSpace = 'srgb'\n): Color | null {\n if (!value) return null\n const color = tryParseColor(value.trim(), profile)\n return color && color.a > 0 ? color : null\n}\n\n/** The space-separated parts of a CSS value, keeping functions such as `rgb(0, 0, 0)` whole. */\nexport function splitCSSValue(value: string): string[] {\n return valueParser(value)\n .nodes.filter((node) => node.type !== 'space' && node.type !== 'comment')\n .map((node) => valueParser.stringify(node))\n}\n\n/** The layers of a CSS value list, split at its top-level commas, spaces and comments dropped. */\nexport function cssLayers(nodes: Node[]): Node[][] {\n const layers: Node[][] = []\n let current: Node[] = []\n for (const node of nodes) {\n if (node.type === 'div' && node.value === ',') {\n layers.push(current)\n current = []\n } else if (node.type !== 'space' && node.type !== 'comment') {\n current.push(node)\n }\n }\n layers.push(current)\n return layers\n}\n\n/** A word's finite number and lowercased unit, or null for anything that is not a dimension. */\nexport function cssDimension(node: Node | undefined): { value: number; unit: string } | null {\n if (node?.type !== 'word') return null\n const dimension = valueParser.unit(node.value)\n if (!dimension) return null\n const value = Number(dimension.number)\n if (!Number.isFinite(value)) return null\n return { value, unit: dimension.unit.toLowerCase() }\n}\n"],"mappings":";;;;AAOA,MAAM,iBAAiB;;;;;AAMvB,SAAgB,eAAe,OAA0C;CACvE,IAAI,CAAC,OAAO,OAAO;CACnB,MAAM,YAAY,YAAY,KAAK,MAAM,KAAK,CAAC;CAC/C,IAAI,CAAC,WAAW,OAAO;CACvB,MAAM,SAAS,OAAO,UAAU,MAAM;CACtC,IAAI,CAAC,OAAO,SAAS,MAAM,GAAG,OAAO;CACrC,QAAQ,UAAU,KAAK,YAAY,GAAnC;EACE,KAAK;EACL,KAAK,MACH,OAAO;EACT,KAAK,OACH,OAAO,SAAS;EAClB,SACE,OAAO;CACX;AACF;;;;;;AAOA,SAAgB,cACd,OACA,UAA8B,QAChB;CACd,IAAI,CAAC,OAAO,OAAO;CACnB,MAAM,QAAQ,cAAc,MAAM,KAAK,GAAG,OAAO;CACjD,OAAO,SAAS,MAAM,IAAI,IAAI,QAAQ;AACxC;;AAGA,SAAgB,cAAc,OAAyB;CACrD,OAAO,YAAY,KAAK,CAAC,CACtB,MAAM,QAAQ,SAAS,KAAK,SAAS,WAAW,KAAK,SAAS,SAAS,CAAC,CACxE,KAAK,SAAS,YAAY,UAAU,IAAI,CAAC;AAC9C;;AAGA,SAAgB,UAAU,OAAyB;CACjD,MAAM,SAAmB,CAAC;CAC1B,IAAI,UAAkB,CAAC;CACvB,KAAK,MAAM,QAAQ,OACjB,IAAI,KAAK,SAAS,SAAS,KAAK,UAAU,KAAK;EAC7C,OAAO,KAAK,OAAO;EACnB,UAAU,CAAC;CACb,OAAO,IAAI,KAAK,SAAS,WAAW,KAAK,SAAS,WAChD,QAAQ,KAAK,IAAI;CAGrB,OAAO,KAAK,OAAO;CACnB,OAAO;AACT;;AAGA,SAAgB,aAAa,MAAgE;CAC3F,IAAI,MAAM,SAAS,QAAQ,OAAO;CAClC,MAAM,YAAY,YAAY,KAAK,KAAK,KAAK;CAC7C,IAAI,CAAC,WAAW,OAAO;CACvB,MAAM,QAAQ,OAAO,UAAU,MAAM;CACrC,IAAI,CAAC,OAAO,SAAS,KAAK,GAAG,OAAO;CACpC,OAAO;EAAE;EAAO,MAAM,UAAU,KAAK,YAAY;CAAE;AACrD"}
|
package/dist/empty-values.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { EMPTY_INSTANCE_OVERRIDES, isEmptyInstanceOverrideState } from "./instances/overrides.js";
|
|
1
2
|
import { isEmptyObject, isPlainObject } from "es-toolkit";
|
|
2
3
|
//#region src/empty-values.ts
|
|
3
4
|
/**
|
|
@@ -31,9 +32,17 @@ function sharedEmptyRecord(value) {
|
|
|
31
32
|
return isPlainObject(value) && isEmptyObject(value) ? EMPTY_RECORD : value;
|
|
32
33
|
}
|
|
33
34
|
function sharedEmptyValue(field, value) {
|
|
35
|
+
if (field === "instanceOverrides") return sharedEmptyOverrideState(value);
|
|
34
36
|
if (Array.isArray(value)) return OWN_LIST_FIELDS.has(field) ? value : sharedEmptyList(value);
|
|
35
37
|
return RECORD_FIELDS.has(field) ? sharedEmptyRecord(value) : value;
|
|
36
38
|
}
|
|
39
|
+
/** An override state with nothing in it, so a layer that cleared its overrides shares the empty one. */
|
|
40
|
+
function sharedEmptyOverrideState(value) {
|
|
41
|
+
if (!isPlainObject(value)) return value;
|
|
42
|
+
const { self, descendants } = value;
|
|
43
|
+
if (!(self instanceof Map) || !(descendants instanceof Map)) return value;
|
|
44
|
+
return isEmptyInstanceOverrideState(value) ? EMPTY_INSTANCE_OVERRIDES : value;
|
|
45
|
+
}
|
|
37
46
|
/**
|
|
38
47
|
* `record` with the empty lists among `lists` and the empty record at `recordField` swapped for
|
|
39
48
|
* the shared ones: a copy when anything changes, so the caller's object is never written into.
|
package/dist/empty-values.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"empty-values.js","names":[],"sources":["../src/empty-values.ts"],"sourcesContent":["import { isEmptyObject, isPlainObject } from 'es-toolkit'\n\nimport type { SceneNode, SourceMetadata } from './types'\n\n/**\n * The empty list and record every layer holds until a field gets a value of its own. All layers\n * share them, so they are frozen: a field is replaced, never written into, and a write into one\n * throws instead of reaching every layer of every document.\n */\nexport const EMPTY_LIST: never[] = Object.freeze<never[]>([]) as never[]\nexport const EMPTY_RECORD: Record<string, never> = Object.freeze({})\n\n/** The child list is the graph's to grow in place, so every layer keeps its own. */\nconst OWN_LIST_FIELDS: ReadonlySet<string> = new Set<keyof SceneNode>(['childIds'])\n\n/** Fields keyed by name, such as bindings and property values, that start empty. */\nconst RECORD_FIELDS: ReadonlySet<string> = new Set<keyof SceneNode>([\n 'componentPropertyAssignments',\n 'componentPropertyValues',\n 'boundVariables',\n 'variableBindingScales',\n 'variableAssignmentScales',\n 'variableModes'\n])\n\nconst SOURCE_LIST_FIELDS = ['editedFields'] as const\nconst FIG_SOURCE_LIST_FIELDS = [\n 'symbolOverrides',\n 'componentPropAssignments',\n 'derivedSymbolData'\n] as const\n\nfunction sharedEmptyList(value: unknown): unknown {\n return Array.isArray(value) && value.length === 0 ? EMPTY_LIST : value\n}\n\nfunction sharedEmptyRecord(value: unknown): unknown {\n return isPlainObject(value) && isEmptyObject(value) ? EMPTY_RECORD : value\n}\n\nfunction sharedEmptyValue(field: string, value: unknown): unknown {\n if (Array.isArray(value)) return OWN_LIST_FIELDS.has(field) ? value : sharedEmptyList(value)\n return RECORD_FIELDS.has(field) ? sharedEmptyRecord(value) : value\n}\n\n/**\n * `record` with the empty lists among `lists` and the empty record at `recordField` swapped for\n * the shared ones: a copy when anything changes, so the caller's object is never written into.\n * A field the record lacks stays absent.\n */\nfunction withSharedEmpties<T extends object>(\n record: T,\n lists: readonly string[],\n recordField?: string\n): T {\n const fields: [string, (value: unknown) => unknown][] = lists.map((field) => [\n field,\n sharedEmptyList\n ])\n if (recordField !== undefined) fields.push([recordField, sharedEmptyRecord])\n let copy: T | null = null\n for (const [field, shared] of fields) {\n if (!Object.hasOwn(record, field)) continue\n const value: unknown = Reflect.get(record, field)\n const next = shared(value)\n if (next === value) continue\n copy ??= { ...record }\n Reflect.set(copy, field, next)\n }\n return copy ?? record\n}\n\n/**\n * Source metadata with its empty lists and raw fields swapped for the shared ones. The metadata\n * object and its `fig` part stay the layer's own, since readers and edits write their scalars in\n * place; metadata missing parts, as libraries and plugins may give, is kept as given.\n */\nfunction withSharedEmptySource(source: SourceMetadata): SourceMetadata {\n const outer = withSharedEmpties(source, SOURCE_LIST_FIELDS)\n const fig: unknown = Reflect.get(source, 'fig')\n if (!isPlainObject(fig)) return outer\n const sharedFig = withSharedEmpties(fig, FIG_SOURCE_LIST_FIELDS, 'rawNodeFields')\n if (sharedFig === fig) return outer\n return { ...outer, fig: { ...source.fig, ...sharedFig } }\n}\n\n/**\n * Swap the `fields` of `node` that hold an empty list or record, its source metadata's included,\n * for the shared ones. Writing known keys keeps the shape every layer shares.\n */\nexport function shareEmptyNodeValues(node: SceneNode, fields: Iterable<string>): void {\n for (const field of fields) {\n const value: unknown = Reflect.get(node, field)\n if (field === 'source') {\n if (isPlainObject(value)) node.source = withSharedEmptySource(node.source)\n continue\n }\n const shared = sharedEmptyValue(field, value)\n if (shared !== value) Reflect.set(node, field, shared)\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"empty-values.js","names":[],"sources":["../src/empty-values.ts"],"sourcesContent":["import { isEmptyObject, isPlainObject } from 'es-toolkit'\n\nimport {\n EMPTY_INSTANCE_OVERRIDES,\n isEmptyInstanceOverrideState,\n type InstanceOverrideState\n} from './instances/overrides'\nimport type { SceneNode, SourceMetadata } from './types'\n\n/**\n * The empty list and record every layer holds until a field gets a value of its own. All layers\n * share them, so they are frozen: a field is replaced, never written into, and a write into one\n * throws instead of reaching every layer of every document.\n */\nexport const EMPTY_LIST: never[] = Object.freeze<never[]>([]) as never[]\nexport const EMPTY_RECORD: Record<string, never> = Object.freeze({})\n\n/** The child list is the graph's to grow in place, so every layer keeps its own. */\nconst OWN_LIST_FIELDS: ReadonlySet<string> = new Set<keyof SceneNode>(['childIds'])\n\n/** Fields keyed by name, such as bindings and property values, that start empty. */\nconst RECORD_FIELDS: ReadonlySet<string> = new Set<keyof SceneNode>([\n 'componentPropertyAssignments',\n 'componentPropertyValues',\n 'boundVariables',\n 'variableBindingScales',\n 'variableAssignmentScales',\n 'variableModes'\n])\n\nconst SOURCE_LIST_FIELDS = ['editedFields'] as const\nconst FIG_SOURCE_LIST_FIELDS = [\n 'symbolOverrides',\n 'componentPropAssignments',\n 'derivedSymbolData'\n] as const\n\nfunction sharedEmptyList(value: unknown): unknown {\n return Array.isArray(value) && value.length === 0 ? EMPTY_LIST : value\n}\n\nfunction sharedEmptyRecord(value: unknown): unknown {\n return isPlainObject(value) && isEmptyObject(value) ? EMPTY_RECORD : value\n}\n\nfunction sharedEmptyValue(field: string, value: unknown): unknown {\n if (field === 'instanceOverrides') return sharedEmptyOverrideState(value)\n if (Array.isArray(value)) return OWN_LIST_FIELDS.has(field) ? value : sharedEmptyList(value)\n return RECORD_FIELDS.has(field) ? sharedEmptyRecord(value) : value\n}\n\n/** An override state with nothing in it, so a layer that cleared its overrides shares the empty one. */\nfunction sharedEmptyOverrideState(value: unknown): unknown {\n if (!isPlainObject(value)) return value\n const { self, descendants } = value as Partial<InstanceOverrideState>\n if (!(self instanceof Map) || !(descendants instanceof Map)) return value\n return isEmptyInstanceOverrideState(value as InstanceOverrideState)\n ? EMPTY_INSTANCE_OVERRIDES\n : value\n}\n\n/**\n * `record` with the empty lists among `lists` and the empty record at `recordField` swapped for\n * the shared ones: a copy when anything changes, so the caller's object is never written into.\n * A field the record lacks stays absent.\n */\nfunction withSharedEmpties<T extends object>(\n record: T,\n lists: readonly string[],\n recordField?: string\n): T {\n const fields: [string, (value: unknown) => unknown][] = lists.map((field) => [\n field,\n sharedEmptyList\n ])\n if (recordField !== undefined) fields.push([recordField, sharedEmptyRecord])\n let copy: T | null = null\n for (const [field, shared] of fields) {\n if (!Object.hasOwn(record, field)) continue\n const value: unknown = Reflect.get(record, field)\n const next = shared(value)\n if (next === value) continue\n copy ??= { ...record }\n Reflect.set(copy, field, next)\n }\n return copy ?? record\n}\n\n/**\n * Source metadata with its empty lists and raw fields swapped for the shared ones. The metadata\n * object and its `fig` part stay the layer's own, since readers and edits write their scalars in\n * place; metadata missing parts, as libraries and plugins may give, is kept as given.\n */\nfunction withSharedEmptySource(source: SourceMetadata): SourceMetadata {\n const outer = withSharedEmpties(source, SOURCE_LIST_FIELDS)\n const fig: unknown = Reflect.get(source, 'fig')\n if (!isPlainObject(fig)) return outer\n const sharedFig = withSharedEmpties(fig, FIG_SOURCE_LIST_FIELDS, 'rawNodeFields')\n if (sharedFig === fig) return outer\n return { ...outer, fig: { ...source.fig, ...sharedFig } }\n}\n\n/**\n * Swap the `fields` of `node` that hold an empty list or record, its source metadata's included,\n * for the shared ones. Writing known keys keeps the shape every layer shares.\n */\nexport function shareEmptyNodeValues(node: SceneNode, fields: Iterable<string>): void {\n for (const field of fields) {\n const value: unknown = Reflect.get(node, field)\n if (field === 'source') {\n if (isPlainObject(value)) node.source = withSharedEmptySource(node.source)\n continue\n }\n const shared = sharedEmptyValue(field, value)\n if (shared !== value) Reflect.set(node, field, shared)\n }\n}\n"],"mappings":";;;;;;;;AAcA,MAAa,aAAsB,OAAO,OAAgB,CAAC,CAAC;AAC5D,MAAa,eAAsC,OAAO,OAAO,CAAC,CAAC;;AAGnE,MAAM,kCAAuC,IAAI,IAAqB,CAAC,UAAU,CAAC;;AAGlF,MAAM,gCAAqC,IAAI,IAAqB;CAClE;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,MAAM,qBAAqB,CAAC,cAAc;AAC1C,MAAM,yBAAyB;CAC7B;CACA;CACA;AACF;AAEA,SAAS,gBAAgB,OAAyB;CAChD,OAAO,MAAM,QAAQ,KAAK,KAAK,MAAM,WAAW,IAAI,aAAa;AACnE;AAEA,SAAS,kBAAkB,OAAyB;CAClD,OAAO,cAAc,KAAK,KAAK,cAAc,KAAK,IAAI,eAAe;AACvE;AAEA,SAAS,iBAAiB,OAAe,OAAyB;CAChE,IAAI,UAAU,qBAAqB,OAAO,yBAAyB,KAAK;CACxE,IAAI,MAAM,QAAQ,KAAK,GAAG,OAAO,gBAAgB,IAAI,KAAK,IAAI,QAAQ,gBAAgB,KAAK;CAC3F,OAAO,cAAc,IAAI,KAAK,IAAI,kBAAkB,KAAK,IAAI;AAC/D;;AAGA,SAAS,yBAAyB,OAAyB;CACzD,IAAI,CAAC,cAAc,KAAK,GAAG,OAAO;C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,IAAI,MAAM,OAAO,MAAM;CACvD;AACF"}
|
package/dist/graph.d.ts
CHANGED
|
@@ -94,6 +94,10 @@ declare class SceneGraph {
|
|
|
94
94
|
resolveStringVariableForNode(nodeId: string, variableId: string, fallback?: VariableModeFallback): string | undefined;
|
|
95
95
|
getVariablesForCollection(collectionId: string): Variable[];
|
|
96
96
|
getVariablesByType(type: VariableType): Variable[];
|
|
97
|
+
/** Every variable but the deleted ones, which only their bindings still reach. */
|
|
98
|
+
getLiveVariables(): Variable[];
|
|
99
|
+
/** Every collection but the deleted ones. */
|
|
100
|
+
getLiveCollections(): VariableCollection[];
|
|
97
101
|
bindVariable(nodeId: string, field: string, variableId: string): void;
|
|
98
102
|
unbindVariable(nodeId: string, field: string): void;
|
|
99
103
|
getChildren(id: string): SceneNode[];
|
package/dist/graph.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graph.d.ts","names":[],"sources":["../src/graph.ts"],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"graph.d.ts","names":[],"sources":["../src/graph.ts"],"mappings":";;;;;;;;;cAiEa;mBAuCkB;EAtC7B,OAAK,YAAA;EACL,QAAM,YAAA,WAAA;EACN,WAAS,YAAA;EACT,qBAAmB,YAAA;EACnB,YAAU;EACV;EACA;;EAEA,mBAAmB;EACnB,oBAAoB;EACpB,cAAc;EACd,kBAAgB,YAAA;WACP,SAAO;UACR;mBACS;UAQT;;UAEA;mBACS;mBAGA;;mBAEA;UACT;UACA;EACR;EACA,eAAa,YAAA;;EAEb,cAAY;EAEiB,YAAA;EAW7B,QAAQ,eAAe;EAIvB,SAAS,4BAA0B;EAKnC,eAAe,SAAS;EAGxB,QAAQ,aAAa;EAGrB,aAAa,UAAU;;;;;;;EAUvB,mBAAmB,UAAU;;;;;;;EAW7B,gBAAgB,GAAG,aAAa,IAAI;;;;;;EAe9B,gBAAgB,GAAG,SAAS,QAAQ,KAAK,QAAQ;;EAyBvD,eAAe,MAAM;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U,GAAG,6BAA6B;MAUlE;;;;;EAQJ,yBAAyB;;;;;;EASzB,4BAA4B;MAIxB;MAIA;;;;;;EASJ,oBAAoB;UAeZ;MASJ;EAGJ,0BAA0B,YAAY,WAAW;EAGjD,kBAAkB,YAAY,SAAS,QAAQ;;;;;EAgB/C,WAAW,YAAY,SAAS,QAAQ;;;;;UAiBhC;;EAOR,sBACE,YACA,SAAS,QAAQ,YACjB,wBAAwB;UAMlB;;UA6CA;;UAOA;;UAKA;UAUA;EAgBR,aAAa,gBAAgB;;;;;;EA4D7B,cAAc,iBAAiB,kBAAkB;EAsBjD,WAAW;;;;;;;UAsBH;EAuBR,QAAQ,YAAY,YAAY,mBAAmB;;EAKnD,YAAY,YAAY,YAAY,kBAAkB,eAAU;;;;EAOhE,kBACE,YACA,YACA,iBACA,aAAa,qBACb,cACA,mBACC;EAIH,qBAAqB,YAAY,YAAY,kBAAkB;EAI/D,gBAAgB;EAIhB,cAAc,gBAAgB,YAAY;EAI1C,kBACE,YACA,YACA,YAAY,qBACZ,kBACA,UAAU,oBACT;EAIH,UACE,kBACA,kBACA,YAAW,QAAQ,aAClB;UAUK;EAkCR,eACE,qBACA,kBACA,YAAW,QAAQ,aAClB;EAIH,yBACE,oBACA,qBACA,OAAM;EAKR,sBACE,oBACA,qBACA,UAAU;EAKZ,cAAc;EAId,sBAAsB,cAAc;EAIpC,aAAa;EAIb,eAAe;EAIf,iBAAiB,qBAAqB;EAItC,aAAa,sBAAsB;;;;;EAQnC,YAAY,mBAAmB,iBAAY;IAAQ,MAAM;IAAW"}
|
package/dist/graph.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BufferedSceneEmitter } from "./buffered-events.js";
|
|
2
2
|
import { removeStaleBindings } from "./bindings.js";
|
|
3
3
|
import { normalizeEffects } from "./effects.js";
|
|
4
|
+
import { ownInstanceOverrides } from "./instances/overrides.js";
|
|
4
5
|
import { shareEmptyNodeValues } from "./empty-values.js";
|
|
5
6
|
import { CONTAINER_TYPES, createDefaultNode } from "./node-defaults.js";
|
|
6
7
|
import { assertPageLayout, finiteGeometry, pageLayoutOverrides } from "./canvas-layout.js";
|
|
@@ -27,7 +28,7 @@ import { LayoutWrites } from "./layout/writes.js";
|
|
|
27
28
|
import { invalidateTextCaches } from "./text/picture.js";
|
|
28
29
|
import { updateNodePreview } from "./preview.js";
|
|
29
30
|
import { markSourceFieldsEdited } from "./source-metadata.js";
|
|
30
|
-
import { addCollection, addMode, addVariable, bindVariable, createCollection, createMode, createVariable, getVariablesByType, getVariablesForCollection, removeCollection, removeMode, removeVariable, renameMode, setActiveMode, setDefaultMode, unbindVariable } from "./variables/index.js";
|
|
31
|
+
import { addCollection, addMode, addVariable, bindVariable, createCollection, createMode, createVariable, getVariablesByType, getVariablesForCollection, liveCollections, liveVariables, removeCollection, removeMode, removeVariable, renameMode, setActiveMode, setDefaultMode, unbindVariable } from "./variables/index.js";
|
|
31
32
|
import { omitBy, pick } from "es-toolkit/object";
|
|
32
33
|
import { isEmptyObject, isUndefined } from "es-toolkit/predicate";
|
|
33
34
|
//#region src/graph.ts
|
|
@@ -248,6 +249,14 @@ var SceneGraph = class {
|
|
|
248
249
|
getVariablesByType(type) {
|
|
249
250
|
return getVariablesByType(this, type);
|
|
250
251
|
}
|
|
252
|
+
/** Every variable but the deleted ones, which only their bindings still reach. */
|
|
253
|
+
getLiveVariables() {
|
|
254
|
+
return liveVariables(this);
|
|
255
|
+
}
|
|
256
|
+
/** Every collection but the deleted ones. */
|
|
257
|
+
getLiveCollections() {
|
|
258
|
+
return liveCollections(this);
|
|
259
|
+
}
|
|
251
260
|
bindVariable(nodeId, field, variableId) {
|
|
252
261
|
bindVariable(this, nodeId, field, variableId);
|
|
253
262
|
}
|
|
@@ -695,7 +704,7 @@ var SceneGraph = class {
|
|
|
695
704
|
}
|
|
696
705
|
if (node.type === "INSTANCE" && node.componentId) this.unindexInstance(node.componentId, id);
|
|
697
706
|
for (let owner = node.parentId ? this.nodes.get(node.parentId) : void 0; owner;) {
|
|
698
|
-
if (owner.type === "INSTANCE"
|
|
707
|
+
if (owner.type === "INSTANCE" && owner.instanceOverrides.descendants.has(id)) ownInstanceOverrides(owner).descendants.delete(id);
|
|
699
708
|
owner = owner.parentId ? this.nodes.get(owner.parentId) : void 0;
|
|
700
709
|
}
|
|
701
710
|
this.connectorIds.delete(id);
|