@open-pencil/scene-graph 0.17.0-beta.2 → 0.17.0-beta.3
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/asset-keys.d.ts +11 -1
- package/dist/asset-keys.d.ts.map +1 -1
- package/dist/asset-keys.js +16 -1
- package/dist/asset-keys.js.map +1 -1
- package/dist/checkpoint.d.ts +3 -3
- package/dist/checkpoint.d.ts.map +1 -1
- package/dist/checkpoint.js +53 -23
- package/dist/checkpoint.js.map +1 -1
- package/dist/components/index.d.ts +2 -2
- package/dist/components/index.js +2 -2
- package/dist/components/properties.d.ts +6 -1
- package/dist/components/properties.d.ts.map +1 -1
- package/dist/components/properties.js +9 -1
- package/dist/components/properties.js.map +1 -1
- package/dist/constants.d.ts +6 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +17 -1
- package/dist/constants.js.map +1 -1
- package/dist/constraints.d.ts +25 -0
- package/dist/constraints.d.ts.map +1 -0
- package/dist/constraints.js +51 -0
- package/dist/constraints.js.map +1 -0
- package/dist/coordinate.d.ts +64 -1
- package/dist/coordinate.d.ts.map +1 -1
- package/dist/coordinate.js +217 -1
- package/dist/coordinate.js.map +1 -1
- package/dist/copy.d.ts.map +1 -1
- package/dist/copy.js +8 -1
- package/dist/copy.js.map +1 -1
- package/dist/css/index.d.ts +3 -2
- package/dist/css/index.js +3 -2
- package/dist/css/text.d.ts +28 -1
- package/dist/css/text.d.ts.map +1 -1
- package/dist/css/text.js +84 -17
- package/dist/css/text.js.map +1 -1
- package/dist/css/transform.d.ts +34 -0
- package/dist/css/transform.d.ts.map +1 -0
- package/dist/css/transform.js +320 -0
- package/dist/css/transform.js.map +1 -0
- package/dist/css/values.d.ts.map +1 -1
- package/dist/css/values.js +11 -1
- package/dist/css/values.js.map +1 -1
- package/dist/figjam/palette.d.ts +1 -1
- package/dist/figjam/palette.js +1 -1
- package/dist/figjam/palette.js.map +1 -1
- package/dist/geometry.d.ts +8 -1
- package/dist/geometry.d.ts.map +1 -1
- package/dist/geometry.js +19 -8
- package/dist/geometry.js.map +1 -1
- package/dist/graph.d.ts +48 -12
- package/dist/graph.d.ts.map +1 -1
- package/dist/graph.js +110 -24
- package/dist/graph.js.map +1 -1
- package/dist/group-bounds.d.ts +14 -4
- package/dist/group-bounds.d.ts.map +1 -1
- package/dist/group-bounds.js +76 -11
- package/dist/group-bounds.js.map +1 -1
- package/dist/hit-test.d.ts +5 -0
- package/dist/hit-test.d.ts.map +1 -1
- package/dist/hit-test.js +18 -12
- package/dist/hit-test.js.map +1 -1
- package/dist/images.d.ts +27 -3
- package/dist/images.d.ts.map +1 -1
- package/dist/images.js +57 -3
- package/dist/images.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/instances/index.d.ts.map +1 -1
- package/dist/instances/index.js +3 -0
- package/dist/instances/index.js.map +1 -1
- package/dist/instances/placement.js +55 -12
- package/dist/instances/placement.js.map +1 -1
- package/dist/instances/swap.js +3 -0
- package/dist/instances/swap.js.map +1 -1
- package/dist/instances/sync.js +34 -13
- package/dist/instances/sync.js.map +1 -1
- package/dist/node-defaults.d.ts.map +1 -1
- package/dist/node-defaults.js +1 -0
- package/dist/node-defaults.js.map +1 -1
- package/dist/order-keys.d.ts +3 -1
- package/dist/order-keys.d.ts.map +1 -1
- package/dist/order-keys.js +6 -1
- package/dist/order-keys.js.map +1 -1
- package/dist/plugin-data/fields.d.ts +2 -0
- package/dist/plugin-data/fields.d.ts.map +1 -1
- package/dist/plugin-data/fields.js +2 -0
- package/dist/plugin-data/fields.js.map +1 -1
- package/dist/resize.d.ts +22 -11
- package/dist/resize.d.ts.map +1 -1
- package/dist/resize.js +227 -93
- package/dist/resize.js.map +1 -1
- package/dist/scaling/index.d.ts +3 -2
- package/dist/scaling/index.js +3 -2
- package/dist/scaling/node.d.ts.map +1 -1
- package/dist/scaling/node.js +5 -1
- package/dist/scaling/node.js.map +1 -1
- package/dist/scaling/snapshot.d.ts +25 -0
- package/dist/scaling/snapshot.d.ts.map +1 -0
- package/dist/scaling/snapshot.js +39 -0
- package/dist/scaling/snapshot.js.map +1 -0
- package/dist/scaling/tree.d.ts +24 -2
- package/dist/scaling/tree.d.ts.map +1 -1
- package/dist/scaling/tree.js +37 -14
- package/dist/scaling/tree.js.map +1 -1
- package/dist/shaders/model.d.ts.map +1 -1
- package/dist/shaders/model.js +2 -1
- package/dist/shaders/model.js.map +1 -1
- package/dist/shared-styles.d.ts +3 -1
- package/dist/shared-styles.d.ts.map +1 -1
- package/dist/shared-styles.js +7 -1
- package/dist/shared-styles.js.map +1 -1
- package/dist/slots/authoring.d.ts +3 -2
- package/dist/slots/authoring.d.ts.map +1 -1
- package/dist/slots/authoring.js +5 -3
- package/dist/slots/authoring.js.map +1 -1
- package/dist/slots/content.d.ts.map +1 -1
- package/dist/slots/content.js +4 -1
- package/dist/slots/content.js.map +1 -1
- package/dist/text/direction.d.ts +3 -1
- package/dist/text/direction.d.ts.map +1 -1
- package/dist/text/direction.js +5 -1
- package/dist/text/direction.js.map +1 -1
- package/dist/transfer/apply.d.ts.map +1 -1
- package/dist/transfer/apply.js +1 -6
- package/dist/transfer/apply.js.map +1 -1
- package/dist/transfer/copied.d.ts +35 -3
- package/dist/transfer/copied.d.ts.map +1 -1
- package/dist/transfer/copied.js +44 -13
- package/dist/transfer/copied.js.map +1 -1
- package/dist/transfer/dependencies.d.ts +38 -0
- package/dist/transfer/dependencies.d.ts.map +1 -0
- package/dist/transfer/dependencies.js +100 -0
- package/dist/transfer/dependencies.js.map +1 -0
- package/dist/transfer/history.js +0 -1
- package/dist/transfer/history.js.map +1 -1
- package/dist/transfer/index.d.ts +5 -3
- package/dist/transfer/index.js +5 -3
- package/dist/transfer/nodes.d.ts.map +1 -1
- package/dist/transfer/nodes.js +7 -14
- package/dist/transfer/nodes.js.map +1 -1
- package/dist/transfer/plan.d.ts +0 -1
- package/dist/transfer/plan.js +3 -5
- package/dist/transfer/plan.js.map +1 -1
- package/dist/transfer/remove.js +5 -2
- package/dist/transfer/remove.js.map +1 -1
- package/dist/transfer/resources.d.ts +21 -0
- package/dist/transfer/resources.d.ts.map +1 -0
- package/dist/transfer/resources.js +38 -0
- package/dist/transfer/resources.js.map +1 -0
- package/dist/transfer/variables.d.ts +8 -1
- package/dist/transfer/variables.d.ts.map +1 -1
- package/dist/transfer/variables.js +24 -1
- package/dist/transfer/variables.js.map +1 -1
- package/dist/types.d.ts +47 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/undo.d.ts +28 -3
- package/dist/undo.d.ts.map +1 -1
- package/dist/undo.js +24 -7
- package/dist/undo.js.map +1 -1
- package/dist/variables/bindings.d.ts +17 -14
- package/dist/variables/bindings.d.ts.map +1 -1
- package/dist/variables/bindings.js +30 -72
- package/dist/variables/bindings.js.map +1 -1
- package/dist/variables/fields.d.ts +1 -1
- package/dist/variables/fields.js +1 -1
- package/dist/variables/fields.js.map +1 -1
- package/dist/variables/formula/check.d.ts +1 -1
- package/dist/variables/formula/index.d.ts +2 -2
- package/dist/variables/formula/index.js +1 -1
- package/dist/variables/formula/index.js.map +1 -1
- package/dist/variables/formula/print.d.ts +1 -1
- package/dist/variables/formula/signatures.js +1 -1
- package/dist/variables/index.d.ts +6 -6
- package/dist/variables/index.d.ts.map +1 -1
- package/dist/variables/index.js +40 -24
- package/dist/variables/index.js.map +1 -1
- package/dist/variables/paints.d.ts +57 -0
- package/dist/variables/paints.d.ts.map +1 -0
- package/dist/variables/paints.js +231 -0
- package/dist/variables/paints.js.map +1 -0
- package/dist/variables/resolution.d.ts +14 -11
- package/dist/variables/resolution.d.ts.map +1 -1
- package/dist/variables/resolution.js +36 -17
- package/dist/variables/resolution.js.map +1 -1
- package/dist/variables/subtree.js +17 -0
- package/dist/variables/subtree.js.map +1 -0
- package/dist/vector-network.d.ts.map +1 -1
- package/dist/vector-network.js +2 -8
- package/dist/vector-network.js.map +1 -1
- package/package.json +8 -1
- package/src/asset-keys.ts +20 -0
- package/src/checkpoint.ts +87 -32
- package/src/components/properties.ts +9 -0
- package/src/constants.ts +17 -0
- package/src/constraints.ts +60 -0
- package/src/coordinate.ts +220 -0
- package/src/copy.ts +9 -4
- package/src/css/index.ts +17 -1
- package/src/css/text.ts +85 -17
- package/src/css/transform.ts +266 -0
- package/src/css/values.ts +8 -0
- package/src/figjam/palette.ts +1 -1
- package/src/geometry.ts +20 -9
- package/src/graph.ts +128 -42
- package/src/group-bounds.ts +84 -17
- package/src/hit-test.ts +30 -14
- package/src/images.ts +71 -3
- package/src/instances/index.ts +4 -0
- package/src/instances/placement.ts +63 -10
- package/src/instances/swap.ts +5 -0
- package/src/instances/sync.ts +48 -21
- package/src/node-defaults.ts +1 -0
- package/src/order-keys.ts +6 -0
- package/src/plugin-data/fields.ts +6 -0
- package/src/resize.ts +267 -119
- package/src/scaling/index.ts +9 -1
- package/src/scaling/node.ts +9 -1
- package/src/scaling/snapshot.ts +51 -0
- package/src/scaling/tree.ts +63 -19
- package/src/shaders/model.ts +2 -3
- package/src/shared-styles.ts +8 -0
- package/src/slots/authoring.ts +5 -3
- package/src/slots/content.ts +4 -1
- package/src/text/direction.ts +5 -0
- package/src/transfer/apply.ts +1 -13
- package/src/transfer/copied.ts +83 -15
- package/src/transfer/dependencies.ts +126 -0
- package/src/transfer/history.ts +0 -6
- package/src/transfer/index.ts +20 -2
- package/src/transfer/nodes.ts +10 -26
- package/src/transfer/plan.ts +3 -11
- package/src/transfer/remove.ts +5 -2
- package/src/transfer/resources.ts +54 -0
- package/src/transfer/variables.ts +34 -0
- package/src/types.ts +55 -1
- package/src/undo.ts +48 -10
- package/src/variables/bindings.ts +44 -91
- package/src/variables/fields.ts +1 -1
- package/src/variables/formula/index.ts +3 -1
- package/src/variables/index.ts +56 -38
- package/src/variables/paints.ts +296 -0
- package/src/variables/resolution.ts +39 -28
- package/src/variables/subtree.ts +15 -0
- package/src/vector-network.ts +4 -2
package/dist/asset-keys.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SceneNode, Variable, VariableCollection } from "./types.js";
|
|
1
2
|
//#region src/asset-keys.d.ts
|
|
2
3
|
/**
|
|
3
4
|
* A key shaped as Figma's asset keys, 40 hex digits, derived from `seed` so the same seed always
|
|
@@ -12,6 +13,15 @@ declare function derivedAssetKey(seed: string): string;
|
|
|
12
13
|
* across an edit would bring the old value back.
|
|
13
14
|
*/
|
|
14
15
|
declare function derivedAssetVersion(content: string): string;
|
|
16
|
+
/** A collection's asset key: its library key, or else one derived from its ID. */
|
|
17
|
+
declare function collectionAssetKey(collection: Pick<VariableCollection, 'id' | 'key'>): string;
|
|
18
|
+
/** A variable's asset key: its library key, or else one derived from its ID. */
|
|
19
|
+
declare function variableAssetKey(variable: Pick<Variable, 'id' | 'key'>): string;
|
|
20
|
+
/**
|
|
21
|
+
* A shared style's asset key: its library key, or else one derived from its ID, which layers name
|
|
22
|
+
* it by but which can hold characters a key cannot (`S:…,`).
|
|
23
|
+
*/
|
|
24
|
+
declare function styleAssetKey(style: Pick<SceneNode, 'id' | 'componentKey' | 'source'>): string;
|
|
15
25
|
//#endregion
|
|
16
|
-
export { derivedAssetKey, derivedAssetVersion };
|
|
26
|
+
export { collectionAssetKey, derivedAssetKey, derivedAssetVersion, styleAssetKey, variableAssetKey };
|
|
17
27
|
//# sourceMappingURL=asset-keys.d.ts.map
|
package/dist/asset-keys.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asset-keys.d.ts","names":[],"sources":["../src/asset-keys.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"asset-keys.d.ts","names":[],"sources":["../src/asset-keys.ts"],"mappings":";;;;;;;iBAUgB,gBAAgB;;;;;;;iBAahB,oBAAoB;;iBAMpB,mBAAmB,YAAY,KAAK;;iBAKpC,iBAAiB,UAAU,KAAK;;;;;iBAQhC,cAAc,OAAO,KAAK"}
|
package/dist/asset-keys.js
CHANGED
|
@@ -21,7 +21,22 @@ function derivedAssetVersion(content) {
|
|
|
21
21
|
const view = new DataView(sha1(utf8ToBytes(content)).buffer);
|
|
22
22
|
return `${view.getUint32(0) & MAX_GUID_PART}:${view.getUint32(4) & MAX_GUID_PART}`;
|
|
23
23
|
}
|
|
24
|
+
/** A collection's asset key: its library key, or else one derived from its ID. */
|
|
25
|
+
function collectionAssetKey(collection) {
|
|
26
|
+
return collection.key ?? derivedAssetKey(`collection:${collection.id}`);
|
|
27
|
+
}
|
|
28
|
+
/** A variable's asset key: its library key, or else one derived from its ID. */
|
|
29
|
+
function variableAssetKey(variable) {
|
|
30
|
+
return variable.key ?? derivedAssetKey(`variable:${variable.id}`);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* A shared style's asset key: its library key, or else one derived from its ID, which layers name
|
|
34
|
+
* it by but which can hold characters a key cannot (`S:…,`).
|
|
35
|
+
*/
|
|
36
|
+
function styleAssetKey(style) {
|
|
37
|
+
return style.componentKey ?? derivedAssetKey(`style:${style.source.id ?? style.id}`);
|
|
38
|
+
}
|
|
24
39
|
//#endregion
|
|
25
|
-
export { derivedAssetKey, derivedAssetVersion };
|
|
40
|
+
export { collectionAssetKey, derivedAssetKey, derivedAssetVersion, styleAssetKey, variableAssetKey };
|
|
26
41
|
|
|
27
42
|
//# sourceMappingURL=asset-keys.js.map
|
package/dist/asset-keys.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asset-keys.js","names":[],"sources":["../src/asset-keys.ts"],"sourcesContent":["import { sha1 } from '@noble/hashes/legacy.js'\nimport { bytesToHex, utf8ToBytes } from '@noble/hashes/utils.js'\n\n/**\n * A key shaped as Figma's asset keys, 40 hex digits, derived from `seed` so the same seed always\n * gives the same key. The Figma clipboard names variables and collections by key; one made in\n * OpenPencil has none, so copying it gives it this one, and copying it again gives the same.\n */\nexport function derivedAssetKey(seed: string): string {\n return bytesToHex(sha1(utf8ToBytes(seed)))\n}\n\n/** Largest part of a Figma GUID, which Figma reads as a signed 32-bit integer. */\nconst MAX_GUID_PART = 0x7fffffff\n\n/**\n * A version shaped as Figma's asset versions, `session:local`, derived from `content` so that\n * copying an unchanged asset again gives the same version and copying a changed one gives another.\n * Figma keeps the first value it pasted for a key and version, so a version that stayed the same\n * across an edit would bring the old value back.\n */\nexport function derivedAssetVersion(content: string): string {\n const view = new DataView(sha1(utf8ToBytes(content)).buffer)\n return `${view.getUint32(0) & MAX_GUID_PART}:${view.getUint32(4) & MAX_GUID_PART}`\n}\n"],"mappings":";;;;;;;;
|
|
1
|
+
{"version":3,"file":"asset-keys.js","names":[],"sources":["../src/asset-keys.ts"],"sourcesContent":["import { sha1 } from '@noble/hashes/legacy.js'\nimport { bytesToHex, utf8ToBytes } from '@noble/hashes/utils.js'\n\nimport type { SceneNode, Variable, VariableCollection } from './types'\n\n/**\n * A key shaped as Figma's asset keys, 40 hex digits, derived from `seed` so the same seed always\n * gives the same key. The Figma clipboard names variables and collections by key; one made in\n * OpenPencil has none, so copying it gives it this one, and copying it again gives the same.\n */\nexport function derivedAssetKey(seed: string): string {\n return bytesToHex(sha1(utf8ToBytes(seed)))\n}\n\n/** Largest part of a Figma GUID, which Figma reads as a signed 32-bit integer. */\nconst MAX_GUID_PART = 0x7fffffff\n\n/**\n * A version shaped as Figma's asset versions, `session:local`, derived from `content` so that\n * copying an unchanged asset again gives the same version and copying a changed one gives another.\n * Figma keeps the first value it pasted for a key and version, so a version that stayed the same\n * across an edit would bring the old value back.\n */\nexport function derivedAssetVersion(content: string): string {\n const view = new DataView(sha1(utf8ToBytes(content)).buffer)\n return `${view.getUint32(0) & MAX_GUID_PART}:${view.getUint32(4) & MAX_GUID_PART}`\n}\n\n/** A collection's asset key: its library key, or else one derived from its ID. */\nexport function collectionAssetKey(collection: Pick<VariableCollection, 'id' | 'key'>): string {\n return collection.key ?? derivedAssetKey(`collection:${collection.id}`)\n}\n\n/** A variable's asset key: its library key, or else one derived from its ID. */\nexport function variableAssetKey(variable: Pick<Variable, 'id' | 'key'>): string {\n return variable.key ?? derivedAssetKey(`variable:${variable.id}`)\n}\n\n/**\n * A shared style's asset key: its library key, or else one derived from its ID, which layers name\n * it by but which can hold characters a key cannot (`S:…,`).\n */\nexport function styleAssetKey(style: Pick<SceneNode, 'id' | 'componentKey' | 'source'>): string {\n return style.componentKey ?? derivedAssetKey(`style:${style.source.id ?? style.id}`)\n}\n"],"mappings":";;;;;;;;AAUA,SAAgB,gBAAgB,MAAsB;CACpD,OAAO,WAAW,KAAK,YAAY,IAAI,CAAC,CAAC;AAC3C;;AAGA,MAAM,gBAAgB;;;;;;;AAQtB,SAAgB,oBAAoB,SAAyB;CAC3D,MAAM,OAAO,IAAI,SAAS,KAAK,YAAY,OAAO,CAAC,CAAC,CAAC,MAAM;CAC3D,OAAO,GAAG,KAAK,UAAU,CAAC,IAAI,cAAc,GAAG,KAAK,UAAU,CAAC,IAAI;AACrE;;AAGA,SAAgB,mBAAmB,YAA4D;CAC7F,OAAO,WAAW,OAAO,gBAAgB,cAAc,WAAW,IAAI;AACxE;;AAGA,SAAgB,iBAAiB,UAAgD;CAC/E,OAAO,SAAS,OAAO,gBAAgB,YAAY,SAAS,IAAI;AAClE;;;;;AAMA,SAAgB,cAAc,OAAkE;CAC9F,OAAO,MAAM,gBAAgB,gBAAgB,SAAS,MAAM,OAAO,MAAM,MAAM,IAAI;AACrF"}
|
package/dist/checkpoint.d.ts
CHANGED
|
@@ -19,9 +19,9 @@ interface TouchedCheckpoint {
|
|
|
19
19
|
readonly nodes: ReadonlyMap<string, SceneNode>;
|
|
20
20
|
/** Nodes the graph reported changing or creating. */
|
|
21
21
|
readonly reported: ReadonlySet<string>;
|
|
22
|
-
/** Copies of
|
|
23
|
-
readonly variables: ReadonlyMap<string, Variable>;
|
|
24
|
-
readonly variableCollections: ReadonlyMap<string, VariableCollection>;
|
|
22
|
+
/** Copies of the variables reported changing (`SceneGraph.willChangeVariable`), as they were. */
|
|
23
|
+
readonly variables: ReadonlyMap<string, Variable | null>;
|
|
24
|
+
readonly variableCollections: ReadonlyMap<string, VariableCollection | null>;
|
|
25
25
|
/** Throws unless the edit only changed properties of existing nodes and variables. */
|
|
26
26
|
assertPropertiesOnly(): void;
|
|
27
27
|
/** Stops observing and puts back everything the edit changed, keeping object identities. */
|
package/dist/checkpoint.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkpoint.d.ts","names":[],"sources":["../src/checkpoint.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"checkpoint.d.ts","names":[],"sources":["../src/checkpoint.ts"],"mappings":";;;;iBA+BgB,uBAAuB,OAAO;;;;;;;;;;;;UAqJ7B;;WAEN,OAAO,oBAAoB;;WAE3B,UAAU;;WAEV,WAAW,oBAAoB;WAC/B,qBAAqB,oBAAoB;;EAElD;;EAEA;;EAEA;;;;;;;;;iBAUc,yBAAyB,OAAO,aAAa"}
|
package/dist/checkpoint.js
CHANGED
|
@@ -5,6 +5,13 @@ const NODE_COUNT_ERROR = "Atomic tools must not create or remove nodes or variab
|
|
|
5
5
|
const NODE_IDENTITY_ERROR = "Atomic tools must not change node hierarchy or identity";
|
|
6
6
|
const VARIABLE_IDENTITY_ERROR = "Atomic tools must not change variable identity";
|
|
7
7
|
const DOCUMENT_ERROR = "Atomic tools must not change collections, assets or document metadata";
|
|
8
|
+
/** Throws when an edit replaced a variable or changed its identity, collection, or type. */
|
|
9
|
+
function assertVariableIdentity(graph, saved, refs) {
|
|
10
|
+
for (const [id, before] of saved) {
|
|
11
|
+
const after = graph.variables.get(id);
|
|
12
|
+
if (!after || after !== refs.get(id) || before.id !== after.id || before.collectionId !== after.collectionId || before.type !== after.type) throw new Error(VARIABLE_IDENTITY_ERROR);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
8
15
|
/** Capture rollback state without changing graph or surviving object identities. */
|
|
9
16
|
function captureGraphCheckpoint(graph) {
|
|
10
17
|
const nodeRefs = new Map(graph.nodes);
|
|
@@ -14,7 +21,6 @@ function captureGraphCheckpoint(graph) {
|
|
|
14
21
|
nodes: graph.nodes,
|
|
15
22
|
variables: graph.variables,
|
|
16
23
|
variableCollections: graph.variableCollections,
|
|
17
|
-
activeMode: graph.activeMode,
|
|
18
24
|
instanceIndex: graph.instanceIndex,
|
|
19
25
|
enabledLibraries: graph.enabledLibraries,
|
|
20
26
|
rootId: graph.rootId,
|
|
@@ -29,24 +35,22 @@ function captureGraphCheckpoint(graph) {
|
|
|
29
35
|
const after = graph.nodes.get(id);
|
|
30
36
|
if (!after || after !== nodeRefs.get(id) || before.id !== after.id || before.type !== after.type || before.parentId !== after.parentId || before.componentId !== after.componentId || !isEqual(before.childIds, after.childIds)) throw new Error(NODE_IDENTITY_ERROR);
|
|
31
37
|
}
|
|
32
|
-
|
|
33
|
-
const after = graph.variables.get(id);
|
|
34
|
-
if (!after || after !== variableRefs.get(id) || before.id !== after.id || before.collectionId !== after.collectionId || before.type !== after.type) throw new Error(VARIABLE_IDENTITY_ERROR);
|
|
35
|
-
}
|
|
38
|
+
assertVariableIdentity(graph, snapshot.variables, variableRefs);
|
|
36
39
|
assertDocumentUnchanged();
|
|
37
40
|
}
|
|
38
41
|
function assertDocumentUnchanged() {
|
|
39
|
-
if (!isEqual(snapshot.variableCollections, graph.variableCollections) || !isEqual(snapshot.
|
|
42
|
+
if (!isEqual(snapshot.variableCollections, graph.variableCollections) || !isEqual(snapshot.instanceIndex, graph.instanceIndex) || !isEqual(snapshot.enabledLibraries, graph.enabledLibraries) || images.size !== graph.images.size || [...images].some(([id, bytes]) => graph.images.get(id) !== bytes) || graph.rootId !== snapshot.rootId || graph.documentColorSpace !== snapshot.documentColorSpace || graph.figKiwiVersion !== snapshot.figKiwiVersion || !isEqual(graph.figSchemaDeflated, snapshot.figSchemaDeflated)) throw new Error(DOCUMENT_ERROR);
|
|
40
43
|
}
|
|
41
44
|
function restore() {
|
|
42
45
|
const failedNodes = new Map(graph.nodes);
|
|
43
46
|
restoreObjects(graph.nodes, snapshot.nodes, nodeRefs);
|
|
44
47
|
restoreObjects(graph.variables, snapshot.variables, variableRefs);
|
|
45
48
|
restoreObjects(graph.variableCollections, snapshot.variableCollections, collectionRefs);
|
|
46
|
-
restoreMap(graph.activeMode, structuredClone(snapshot.activeMode));
|
|
47
49
|
restoreMap(graph.instanceIndex, structuredClone(snapshot.instanceIndex));
|
|
48
50
|
restoreMap(graph.enabledLibraries, structuredClone(snapshot.enabledLibraries));
|
|
49
51
|
restoreMap(graph.images, images);
|
|
52
|
+
graph.connectorIds.clear();
|
|
53
|
+
for (const node of graph.nodes.values()) if (node.type === "CONNECTOR") graph.connectorIds.add(node.id);
|
|
50
54
|
graph.rootId = snapshot.rootId;
|
|
51
55
|
graph.figKiwiVersion = snapshot.figKiwiVersion;
|
|
52
56
|
graph.figSchemaDeflated = structuredClone(snapshot.figSchemaDeflated);
|
|
@@ -73,6 +77,31 @@ function restoreObjects(target, snapshot, refs) {
|
|
|
73
77
|
target.set(id, original);
|
|
74
78
|
}
|
|
75
79
|
}
|
|
80
|
+
/** Copies `id`'s record the first time it is reported: `null` for one about to be added. */
|
|
81
|
+
function copyRecord(copies, live, id) {
|
|
82
|
+
if (!copies.has(id)) copies.set(id, structuredClone(live.get(id) ?? null));
|
|
83
|
+
}
|
|
84
|
+
/** Whether `target` holds exactly the objects `refs` held, in any order. */
|
|
85
|
+
function sameEntries(target, refs) {
|
|
86
|
+
if (target.size !== refs.size) return false;
|
|
87
|
+
for (const [id, ref] of refs) if (target.get(id) !== ref) return false;
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Puts back the records `refs` held, in their order, with the copied ones rewritten in place to
|
|
92
|
+
* their copies, as views may hold them.
|
|
93
|
+
*/
|
|
94
|
+
function restoreCopied(target, copies, refs) {
|
|
95
|
+
target.clear();
|
|
96
|
+
for (const [id, original] of refs) {
|
|
97
|
+
const saved = copies.get(id);
|
|
98
|
+
if (saved) {
|
|
99
|
+
for (const key of Object.keys(original)) if (!(key in saved)) Reflect.deleteProperty(original, key);
|
|
100
|
+
Object.assign(original, structuredClone(saved));
|
|
101
|
+
}
|
|
102
|
+
target.set(id, original);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
76
105
|
function restoreMap(target, saved) {
|
|
77
106
|
target.clear();
|
|
78
107
|
for (const [key, value] of saved) target.set(key, value);
|
|
@@ -88,13 +117,10 @@ function captureTouchedCheckpoint(graph) {
|
|
|
88
117
|
const nodeRefs = new Map(graph.nodes);
|
|
89
118
|
const variableRefs = new Map(graph.variables);
|
|
90
119
|
const collectionRefs = new Map(graph.variableCollections);
|
|
91
|
-
const saved = structuredClone({
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
instanceIndex: graph.instanceIndex,
|
|
96
|
-
enabledLibraries: graph.enabledLibraries
|
|
97
|
-
});
|
|
120
|
+
const saved = structuredClone({ enabledLibraries: graph.enabledLibraries });
|
|
121
|
+
const instanceIndex = new Map([...graph.instanceIndex].map(([id, instances]) => [id, new Set(instances)]));
|
|
122
|
+
const variables = /* @__PURE__ */ new Map();
|
|
123
|
+
const variableCollections = /* @__PURE__ */ new Map();
|
|
98
124
|
const images = new Map(graph.images);
|
|
99
125
|
const { rootId, figKiwiVersion, figSchemaDeflated, documentColorSpace } = graph;
|
|
100
126
|
const nodes = /* @__PURE__ */ new Map();
|
|
@@ -128,6 +154,10 @@ function captureTouchedCheckpoint(graph) {
|
|
|
128
154
|
before: (node) => {
|
|
129
155
|
reported.add(node.id);
|
|
130
156
|
copyLineage(node);
|
|
157
|
+
},
|
|
158
|
+
beforeRecord: (kind, id) => {
|
|
159
|
+
if (kind === "variable") copyRecord(variables, graph.variables, id);
|
|
160
|
+
else copyRecord(variableCollections, graph.variableCollections, id);
|
|
131
161
|
}
|
|
132
162
|
});
|
|
133
163
|
const unbindEvents = recordSceneMutations(graph, impact);
|
|
@@ -157,11 +187,12 @@ function captureTouchedCheckpoint(graph) {
|
|
|
157
187
|
}
|
|
158
188
|
function assertPropertiesOnly() {
|
|
159
189
|
assertNodes();
|
|
160
|
-
|
|
190
|
+
if (!sameEntries(graph.variables, variableRefs)) throw new Error(VARIABLE_IDENTITY_ERROR);
|
|
191
|
+
for (const [id, before] of variables) {
|
|
161
192
|
const after = graph.variables.get(id);
|
|
162
|
-
if (!
|
|
193
|
+
if (!before || !after || before.id !== after.id || before.collectionId !== after.collectionId || before.type !== after.type) throw new Error(VARIABLE_IDENTITY_ERROR);
|
|
163
194
|
}
|
|
164
|
-
if (!
|
|
195
|
+
if (!sameEntries(graph.variableCollections, collectionRefs) || [...variableCollections].some(([id, before]) => !isEqual(before, graph.variableCollections.get(id) ?? null)) || !isEqual(instanceIndex, graph.instanceIndex) || !isEqual(saved.enabledLibraries, graph.enabledLibraries) || images.size !== graph.images.size || [...images].some(([id, bytes]) => graph.images.get(id) !== bytes) || graph.rootId !== rootId || graph.documentColorSpace !== documentColorSpace || graph.figKiwiVersion !== figKiwiVersion || graph.figSchemaDeflated !== figSchemaDeflated) throw new Error(DOCUMENT_ERROR);
|
|
165
196
|
}
|
|
166
197
|
/** Puts the node map back as it was, in its order, if the edit changed its entries. */
|
|
167
198
|
function restoreNodeMap() {
|
|
@@ -203,10 +234,9 @@ function captureTouchedCheckpoint(graph) {
|
|
|
203
234
|
for (const key of Object.keys(original)) if (!Object.hasOwn(copy, key)) Reflect.deleteProperty(original, key);
|
|
204
235
|
Object.assign(original, structuredClone(copy));
|
|
205
236
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
restoreMap(graph.
|
|
209
|
-
restoreMap(graph.instanceIndex, structuredClone(saved.instanceIndex));
|
|
237
|
+
restoreCopied(graph.variables, variables, variableRefs);
|
|
238
|
+
restoreCopied(graph.variableCollections, variableCollections, collectionRefs);
|
|
239
|
+
restoreMap(graph.instanceIndex, new Map([...instanceIndex].map(([id, instances]) => [id, new Set(instances)])));
|
|
210
240
|
restoreMap(graph.enabledLibraries, structuredClone(saved.enabledLibraries));
|
|
211
241
|
restoreMap(graph.images, images);
|
|
212
242
|
graph.rootId = rootId;
|
|
@@ -236,8 +266,8 @@ function captureTouchedCheckpoint(graph) {
|
|
|
236
266
|
return {
|
|
237
267
|
nodes,
|
|
238
268
|
reported,
|
|
239
|
-
variables
|
|
240
|
-
variableCollections
|
|
269
|
+
variables,
|
|
270
|
+
variableCollections,
|
|
241
271
|
assertPropertiesOnly,
|
|
242
272
|
restore,
|
|
243
273
|
stop
|
package/dist/checkpoint.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkpoint.js","names":[],"sources":["../src/checkpoint.ts"],"sourcesContent":["import { isEqual } from 'es-toolkit'\n\nimport type { SceneGraph } from './graph'\nimport { createSceneMutationImpact, recordSceneMutations } from './mutation-impact'\nimport type { SceneNode, Variable, VariableCollection } from './types'\n\nconst NODE_COUNT_ERROR = 'Atomic tools must not create or remove nodes or variables'\nconst NODE_IDENTITY_ERROR = 'Atomic tools must not change node hierarchy or identity'\nconst VARIABLE_IDENTITY_ERROR = 'Atomic tools must not change variable identity'\nconst DOCUMENT_ERROR = 'Atomic tools must not change collections, assets or document metadata'\n\n/** Capture rollback state without changing graph or surviving object identities. */\nexport function captureGraphCheckpoint(graph: SceneGraph) {\n const nodeRefs = new Map(graph.nodes)\n const variableRefs = new Map(graph.variables)\n const collectionRefs = new Map(graph.variableCollections)\n const snapshot = structuredClone({\n nodes: graph.nodes,\n variables: graph.variables,\n variableCollections: graph.variableCollections,\n activeMode: graph.activeMode,\n instanceIndex: graph.instanceIndex,\n enabledLibraries: graph.enabledLibraries,\n rootId: graph.rootId,\n figKiwiVersion: graph.figKiwiVersion,\n figSchemaDeflated: graph.figSchemaDeflated,\n documentColorSpace: graph.documentColorSpace\n })\n // Atomic property tools cannot edit assets. Retain existing buffers, not copies of every bitmap.\n const images = new Map(graph.images)\n\n function assertPropertiesOnly() {\n if (\n snapshot.nodes.size !== graph.nodes.size ||\n snapshot.variables.size !== graph.variables.size\n )\n throw new Error(NODE_COUNT_ERROR)\n for (const [id, before] of snapshot.nodes) {\n const after = graph.nodes.get(id)\n if (\n !after ||\n after !== nodeRefs.get(id) ||\n before.id !== after.id ||\n before.type !== after.type ||\n before.parentId !== after.parentId ||\n before.componentId !== after.componentId ||\n !isEqual(before.childIds, after.childIds)\n ) {\n throw new Error(NODE_IDENTITY_ERROR)\n }\n }\n for (const [id, before] of snapshot.variables) {\n const after = graph.variables.get(id)\n if (\n !after ||\n after !== variableRefs.get(id) ||\n before.id !== after.id ||\n before.collectionId !== after.collectionId ||\n before.type !== after.type\n )\n throw new Error(VARIABLE_IDENTITY_ERROR)\n }\n assertDocumentUnchanged()\n }\n\n function assertDocumentUnchanged() {\n if (\n !isEqual(snapshot.variableCollections, graph.variableCollections) ||\n !isEqual(snapshot.activeMode, graph.activeMode) ||\n !isEqual(snapshot.instanceIndex, graph.instanceIndex) ||\n !isEqual(snapshot.enabledLibraries, graph.enabledLibraries) ||\n images.size !== graph.images.size ||\n [...images].some(([id, bytes]) => graph.images.get(id) !== bytes) ||\n graph.rootId !== snapshot.rootId ||\n graph.documentColorSpace !== snapshot.documentColorSpace ||\n graph.figKiwiVersion !== snapshot.figKiwiVersion ||\n !isEqual(graph.figSchemaDeflated, snapshot.figSchemaDeflated)\n ) {\n throw new Error(DOCUMENT_ERROR)\n }\n }\n\n function restore() {\n const failedNodes = new Map(graph.nodes)\n restoreObjects(graph.nodes, snapshot.nodes, nodeRefs)\n restoreObjects(graph.variables, snapshot.variables, variableRefs)\n restoreObjects(graph.variableCollections, snapshot.variableCollections, collectionRefs)\n restoreMap(graph.activeMode, structuredClone(snapshot.activeMode))\n restoreMap(graph.instanceIndex, structuredClone(snapshot.instanceIndex))\n restoreMap(graph.enabledLibraries, structuredClone(snapshot.enabledLibraries))\n restoreMap(graph.images, images)\n graph.rootId = snapshot.rootId\n graph.figKiwiVersion = snapshot.figKiwiVersion\n graph.figSchemaDeflated = structuredClone(snapshot.figSchemaDeflated)\n graph.documentColorSpace = snapshot.documentColorSpace\n graph.clearAbsPosCache()\n // Notify consumers only after the complete hierarchy and indexes have been restored.\n for (const [id, node] of failedNodes) {\n if (!graph.nodes.has(id)) graph.emitter.emit('node:deleted', id, node.parentId)\n }\n for (const [id, node] of graph.nodes) {\n if (failedNodes.has(id)) graph.emitter.emit('node:updated', id, node)\n else graph.emitter.emit('node:created', node)\n }\n }\n\n return { nodes: snapshot.nodes, variables: snapshot.variables, assertPropertiesOnly, restore }\n}\n\nfunction restoreObjects<T extends object>(\n target: Map<string, T>,\n snapshot: Map<string, T>,\n refs: Map<string, T>\n) {\n target.clear()\n for (const [id, saved] of snapshot) {\n const original = refs.get(id)\n if (!original) throw new Error(`Missing checkpoint reference: ${id}`)\n for (const key of Object.keys(original) as (keyof T)[]) {\n if (!(key in saved)) Reflect.deleteProperty(original, key)\n }\n Object.assign(original, structuredClone(saved))\n target.set(id, original)\n }\n}\n\nfunction restoreMap<K, V>(target: Map<K, V>, saved: Map<K, V>) {\n target.clear()\n for (const [key, value] of saved) target.set(key, value)\n}\n\n/**\n * Rollback state for an edit that may only change properties, which costs what the edit touches\n * rather than a copy of the document: a node is copied the first time the graph reports it about\n * to change (`SceneGraph.observeNodeChanges`), together with its ancestors below the page, which\n * keep instance override maps the graph writes into in place.\n */\nexport interface TouchedCheckpoint {\n /** Copies of the reported nodes and their ancestors below the page, as they were before. */\n readonly nodes: ReadonlyMap<string, SceneNode>\n /** Nodes the graph reported changing or creating. */\n readonly reported: ReadonlySet<string>\n /** Copies of every variable, as variables have no change report. */\n readonly variables: ReadonlyMap<string, Variable>\n readonly variableCollections: ReadonlyMap<string, VariableCollection>\n /** Throws unless the edit only changed properties of existing nodes and variables. */\n assertPropertiesOnly(): void\n /** Stops observing and puts back everything the edit changed, keeping object identities. */\n restore(): void\n /** Stops observing the graph. */\n stop(): void\n}\n\n/**\n * Starts observing `graph` for an edit that may only change properties. Node identities are\n * kept as pointers, so replacing, adding, or removing a node anywhere is found; a node's fields\n * are compared and restored only where the graph reported it, so code that writes into a node\n * directly calls `SceneGraph.willChangeNode` first, and a node event without such a report fails\n * the edit.\n */\nexport function captureTouchedCheckpoint(graph: SceneGraph): TouchedCheckpoint {\n const nodeRefs = new Map(graph.nodes)\n const variableRefs = new Map(graph.variables)\n const collectionRefs = new Map(graph.variableCollections)\n const saved = structuredClone({\n variables: graph.variables,\n variableCollections: graph.variableCollections,\n activeMode: graph.activeMode,\n instanceIndex: graph.instanceIndex,\n enabledLibraries: graph.enabledLibraries\n })\n // Property edits cannot edit assets. Retain existing buffers, not copies of every bitmap.\n const images = new Map(graph.images)\n const { rootId, figKiwiVersion, figSchemaDeflated, documentColorSpace } = graph\n const nodes = new Map<string, SceneNode>()\n const reported = new Set<string>()\n const created = new Set<string>()\n const impact = createSceneMutationImpact()\n\n /** Copies a node as the edit found it: the original object, should the edit have replaced it. */\n function copy(node: SceneNode) {\n nodes.set(node.id, structuredClone(nodeRefs.get(node.id) ?? node))\n }\n\n const skipped = (node: SceneNode) => nodes.has(node.id) || created.has(node.id)\n\n /**\n * Copies `node` and each ancestor not copied yet, up to but excluding its page. An ancestor\n * copied already had its own ancestors copied with it, so the walk stops there.\n */\n function copyLineage(node: SceneNode) {\n if (skipped(node)) return\n copy(node)\n if (!node.parentId) return\n graph.closest(node.parentId, (ancestor) => {\n if (ancestor.type === 'CANVAS' || ancestor.id === rootId || skipped(ancestor)) return true\n copy(ancestor)\n return false\n })\n }\n\n const unobserve = graph.observeNodeChanges({\n created: (node) => {\n created.add(node.id)\n reported.add(node.id)\n },\n before: (node) => {\n reported.add(node.id)\n copyLineage(node)\n }\n })\n const unbindEvents = recordSceneMutations(graph, impact)\n let observing = true\n\n function stop() {\n if (!observing) return\n observing = false\n unobserve()\n unbindEvents()\n }\n\n function assertNodes() {\n if (\n created.size > 0 ||\n impact.deletedNodeIds.size > 0 ||\n graph.nodes.size !== nodeRefs.size ||\n graph.variables.size !== variableRefs.size\n )\n throw new Error(NODE_COUNT_ERROR)\n for (const [id, node] of graph.nodes) {\n const original = nodeRefs.get(id)\n if (!original) throw new Error(NODE_COUNT_ERROR)\n if (original !== node) throw new Error(NODE_IDENTITY_ERROR)\n }\n for (const [id, before] of nodes) {\n const after = graph.nodes.get(id)\n if (\n !after ||\n before.id !== after.id ||\n before.type !== after.type ||\n before.parentId !== after.parentId ||\n before.componentId !== after.componentId ||\n !isEqual(before.childIds, after.childIds)\n )\n throw new Error(NODE_IDENTITY_ERROR)\n }\n for (const id of [\n ...impact.changedNodeIds,\n ...impact.previousParentIds,\n ...impact.currentParentIds\n ]) {\n if (!nodes.has(id) && !created.has(id)) {\n throw new Error(\n `Atomic tools must report layer changes to the scene graph (SceneGraph.willChangeNode): ${id}`\n )\n }\n }\n }\n\n function assertPropertiesOnly() {\n assertNodes()\n for (const [id, before] of saved.variables) {\n const after = graph.variables.get(id)\n if (\n !after ||\n after !== variableRefs.get(id) ||\n before.id !== after.id ||\n before.collectionId !== after.collectionId ||\n before.type !== after.type\n )\n throw new Error(VARIABLE_IDENTITY_ERROR)\n }\n if (\n !isEqual(saved.variableCollections, graph.variableCollections) ||\n !isEqual(saved.activeMode, graph.activeMode) ||\n !isEqual(saved.instanceIndex, graph.instanceIndex) ||\n !isEqual(saved.enabledLibraries, graph.enabledLibraries) ||\n images.size !== graph.images.size ||\n [...images].some(([id, bytes]) => graph.images.get(id) !== bytes) ||\n graph.rootId !== rootId ||\n graph.documentColorSpace !== documentColorSpace ||\n graph.figKiwiVersion !== figKiwiVersion ||\n // Every writer assigns a new schema rather than writing into it.\n graph.figSchemaDeflated !== figSchemaDeflated\n )\n throw new Error(DOCUMENT_ERROR)\n }\n\n /** Puts the node map back as it was, in its order, if the edit changed its entries. */\n function restoreNodeMap(): { removed: Map<string, SceneNode>; readded: Set<string> } {\n const removed = new Map<string, SceneNode>()\n const readded = new Set<string>()\n let changed = graph.nodes.size !== nodeRefs.size\n if (!changed) {\n // In lockstep, so a node removed and set again, which moves to the end, is put back too.\n const live = graph.nodes.entries()\n for (const [id, node] of nodeRefs) {\n const next = live.next()\n if (next.done || next.value[0] !== id || next.value[1] !== node) {\n changed = true\n break\n }\n }\n }\n if (!changed) return { removed, readded }\n const failed = new Map(graph.nodes)\n graph.nodes.clear()\n for (const [id, node] of nodeRefs) {\n graph.nodes.set(id, node)\n if (!failed.has(id)) readded.add(id)\n }\n for (const [id, node] of failed) if (!nodeRefs.has(id)) removed.set(id, node)\n return { removed, readded }\n }\n\n function restore() {\n stop()\n const { removed, readded } = restoreNodeMap()\n for (const [id, copy] of nodes) {\n const original = nodeRefs.get(id)\n if (!original) continue\n for (const key of Object.keys(original)) {\n if (!Object.hasOwn(copy, key)) Reflect.deleteProperty(original, key)\n }\n Object.assign(original, structuredClone(copy))\n }\n restoreObjects(graph.variables, saved.variables, variableRefs)\n restoreObjects(graph.variableCollections, saved.variableCollections, collectionRefs)\n restoreMap(graph.activeMode, structuredClone(saved.activeMode))\n restoreMap(graph.instanceIndex, structuredClone(saved.instanceIndex))\n restoreMap(graph.enabledLibraries, structuredClone(saved.enabledLibraries))\n restoreMap(graph.images, images)\n graph.rootId = rootId\n graph.figKiwiVersion = figKiwiVersion\n graph.figSchemaDeflated = figSchemaDeflated\n graph.documentColorSpace = documentColorSpace\n graph.clearAbsPosCache()\n const touched = new Set([\n ...nodes.keys(),\n ...created,\n ...readded,\n ...removed.keys(),\n ...impact.changedNodeIds,\n ...impact.previousParentIds,\n ...impact.currentParentIds\n ])\n for (const id of touched) {\n if (graph.nodes.get(id)?.type === 'CONNECTOR') graph.connectorIds.add(id)\n else graph.connectorIds.delete(id)\n }\n // Notify consumers only after the complete hierarchy and indexes have been restored.\n for (const [id, node] of removed) graph.emitter.emit('node:deleted', id, node.parentId)\n for (const id of touched) {\n const node = graph.nodes.get(id)\n if (!node) continue\n if (readded.has(id)) graph.emitter.emit('node:created', node)\n else graph.emitter.emit('node:updated', id, node)\n }\n }\n\n return {\n nodes,\n reported,\n variables: saved.variables,\n variableCollections: saved.variableCollections,\n assertPropertiesOnly,\n restore,\n stop\n }\n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AAM,gBAAgB,CAAC;EAC1E,WAAW,MAAM,QAAQ,MAAM;EAC/B,MAAM,SAAS;EACf,MAAM,iBAAiB;EACvB,MAAM,oBAAoB;EAC1B,MAAM,qBAAqB;EAC3B,MAAM,iBAAiB;EACvB,MAAM,0BAAU,IAAI,IAAI;GACtB,GAAG,MAAM,KAAK;GACd,GAAG;GACH,GAAG;GACH,GAAG,QAAQ,KAAK;GAChB,GAAG,OAAO;GACV,GAAG,OAAO;GACV,GAAG,OAAO;EACZ,CAAC;EACD,KAAK,MAAM,MAAM,SACf,IAAI,MAAM,MAAM,IAAI,EAAE,CAAC,EAAE,SAAS,aAAa,MAAM,aAAa,IAAI,EAAE;OACnE,MAAM,aAAa,OAAO,EAAE;EAGnC,KAAK,MAAM,CAAC,IAAI,SAAS,SAAS,MAAM,QAAQ,KAAK,gBAAgB,IAAI,KAAK,QAAQ;EACtF,KAAK,MAAM,MAAM,SAAS;GACxB,MAAM,OAAO,MAAM,MAAM,IAAI,EAAE;GAC/B,IAAI,CAAC,MAAM;GACX,IAAI,QAAQ,IAAI,EAAE,GAAG,MAAM,QAAQ,KAAK,gBAAgB,IAAI;QACvD,MAAM,QAAQ,KAAK,gBAAgB,IAAI,IAAI;EAClD;CACF;CAEA,OAAO;EACL;EACA;EACA,WAAW,MAAM;EACjB,qBAAqB,MAAM;EAC3B;EACA;EACA;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"checkpoint.js","names":[],"sources":["../src/checkpoint.ts"],"sourcesContent":["import { isEqual } from 'es-toolkit'\n\nimport type { SceneGraph } from './graph'\nimport { createSceneMutationImpact, recordSceneMutations } from './mutation-impact'\nimport type { SceneNode, Variable, VariableCollection } from './types'\n\nconst NODE_COUNT_ERROR = 'Atomic tools must not create or remove nodes or variables'\nconst NODE_IDENTITY_ERROR = 'Atomic tools must not change node hierarchy or identity'\nconst VARIABLE_IDENTITY_ERROR = 'Atomic tools must not change variable identity'\nconst DOCUMENT_ERROR = 'Atomic tools must not change collections, assets or document metadata'\n\n/** Throws when an edit replaced a variable or changed its identity, collection, or type. */\nfunction assertVariableIdentity(\n graph: SceneGraph,\n saved: ReadonlyMap<string, Variable>,\n refs: ReadonlyMap<string, Variable>\n): void {\n for (const [id, before] of saved) {\n const after = graph.variables.get(id)\n if (\n !after ||\n after !== refs.get(id) ||\n before.id !== after.id ||\n before.collectionId !== after.collectionId ||\n before.type !== after.type\n )\n throw new Error(VARIABLE_IDENTITY_ERROR)\n }\n}\n\n/** Capture rollback state without changing graph or surviving object identities. */\nexport function captureGraphCheckpoint(graph: SceneGraph) {\n const nodeRefs = new Map(graph.nodes)\n const variableRefs = new Map(graph.variables)\n const collectionRefs = new Map(graph.variableCollections)\n const snapshot = structuredClone({\n nodes: graph.nodes,\n variables: graph.variables,\n variableCollections: graph.variableCollections,\n instanceIndex: graph.instanceIndex,\n enabledLibraries: graph.enabledLibraries,\n rootId: graph.rootId,\n figKiwiVersion: graph.figKiwiVersion,\n figSchemaDeflated: graph.figSchemaDeflated,\n documentColorSpace: graph.documentColorSpace\n })\n // Atomic property tools cannot edit assets. Retain existing buffers, not copies of every bitmap.\n const images = new Map(graph.images)\n\n function assertPropertiesOnly() {\n if (\n snapshot.nodes.size !== graph.nodes.size ||\n snapshot.variables.size !== graph.variables.size\n )\n throw new Error(NODE_COUNT_ERROR)\n for (const [id, before] of snapshot.nodes) {\n const after = graph.nodes.get(id)\n if (\n !after ||\n after !== nodeRefs.get(id) ||\n before.id !== after.id ||\n before.type !== after.type ||\n before.parentId !== after.parentId ||\n before.componentId !== after.componentId ||\n !isEqual(before.childIds, after.childIds)\n ) {\n throw new Error(NODE_IDENTITY_ERROR)\n }\n }\n assertVariableIdentity(graph, snapshot.variables, variableRefs)\n assertDocumentUnchanged()\n }\n\n function assertDocumentUnchanged() {\n if (\n !isEqual(snapshot.variableCollections, graph.variableCollections) ||\n !isEqual(snapshot.instanceIndex, graph.instanceIndex) ||\n !isEqual(snapshot.enabledLibraries, graph.enabledLibraries) ||\n images.size !== graph.images.size ||\n [...images].some(([id, bytes]) => graph.images.get(id) !== bytes) ||\n graph.rootId !== snapshot.rootId ||\n graph.documentColorSpace !== snapshot.documentColorSpace ||\n graph.figKiwiVersion !== snapshot.figKiwiVersion ||\n !isEqual(graph.figSchemaDeflated, snapshot.figSchemaDeflated)\n ) {\n throw new Error(DOCUMENT_ERROR)\n }\n }\n\n function restore() {\n const failedNodes = new Map(graph.nodes)\n restoreObjects(graph.nodes, snapshot.nodes, nodeRefs)\n restoreObjects(graph.variables, snapshot.variables, variableRefs)\n restoreObjects(graph.variableCollections, snapshot.variableCollections, collectionRefs)\n restoreMap(graph.instanceIndex, structuredClone(snapshot.instanceIndex))\n restoreMap(graph.enabledLibraries, structuredClone(snapshot.enabledLibraries))\n restoreMap(graph.images, images)\n graph.connectorIds.clear()\n for (const node of graph.nodes.values())\n if (node.type === 'CONNECTOR') graph.connectorIds.add(node.id)\n graph.rootId = snapshot.rootId\n graph.figKiwiVersion = snapshot.figKiwiVersion\n graph.figSchemaDeflated = structuredClone(snapshot.figSchemaDeflated)\n graph.documentColorSpace = snapshot.documentColorSpace\n graph.clearAbsPosCache()\n // Notify consumers only after the complete hierarchy and indexes have been restored.\n for (const [id, node] of failedNodes) {\n if (!graph.nodes.has(id)) graph.emitter.emit('node:deleted', id, node.parentId)\n }\n for (const [id, node] of graph.nodes) {\n if (failedNodes.has(id)) graph.emitter.emit('node:updated', id, node)\n else graph.emitter.emit('node:created', node)\n }\n }\n\n return { nodes: snapshot.nodes, variables: snapshot.variables, assertPropertiesOnly, restore }\n}\n\nfunction restoreObjects<T extends object>(\n target: Map<string, T>,\n snapshot: Map<string, T>,\n refs: Map<string, T>\n) {\n target.clear()\n for (const [id, saved] of snapshot) {\n const original = refs.get(id)\n if (!original) throw new Error(`Missing checkpoint reference: ${id}`)\n for (const key of Object.keys(original) as (keyof T)[]) {\n if (!(key in saved)) Reflect.deleteProperty(original, key)\n }\n Object.assign(original, structuredClone(saved))\n target.set(id, original)\n }\n}\n\n/** Copies `id`'s record the first time it is reported: `null` for one about to be added. */\nfunction copyRecord<T>(copies: Map<string, T | null>, live: ReadonlyMap<string, T>, id: string) {\n if (!copies.has(id)) copies.set(id, structuredClone(live.get(id) ?? null))\n}\n\n/** Whether `target` holds exactly the objects `refs` held, in any order. */\nfunction sameEntries<T>(target: ReadonlyMap<string, T>, refs: ReadonlyMap<string, T>): boolean {\n if (target.size !== refs.size) return false\n for (const [id, ref] of refs) if (target.get(id) !== ref) return false\n return true\n}\n\n/**\n * Puts back the records `refs` held, in their order, with the copied ones rewritten in place to\n * their copies, as views may hold them.\n */\nfunction restoreCopied<T extends object>(\n target: Map<string, T>,\n copies: ReadonlyMap<string, T | null>,\n refs: ReadonlyMap<string, T>\n) {\n target.clear()\n for (const [id, original] of refs) {\n const saved = copies.get(id)\n if (saved) {\n for (const key of Object.keys(original) as (keyof T)[]) {\n if (!(key in saved)) Reflect.deleteProperty(original, key)\n }\n Object.assign(original, structuredClone(saved))\n }\n target.set(id, original)\n }\n}\n\nfunction restoreMap<K, V>(target: Map<K, V>, saved: Map<K, V>) {\n target.clear()\n for (const [key, value] of saved) target.set(key, value)\n}\n\n/**\n * Rollback state for an edit that may only change properties, which costs what the edit touches\n * rather than a copy of the document: a node is copied the first time the graph reports it about\n * to change (`SceneGraph.observeNodeChanges`), together with its ancestors below the page, which\n * keep instance override maps the graph writes into in place.\n */\nexport interface TouchedCheckpoint {\n /** Copies of the reported nodes and their ancestors below the page, as they were before. */\n readonly nodes: ReadonlyMap<string, SceneNode>\n /** Nodes the graph reported changing or creating. */\n readonly reported: ReadonlySet<string>\n /** Copies of the variables reported changing (`SceneGraph.willChangeVariable`), as they were. */\n readonly variables: ReadonlyMap<string, Variable | null>\n readonly variableCollections: ReadonlyMap<string, VariableCollection | null>\n /** Throws unless the edit only changed properties of existing nodes and variables. */\n assertPropertiesOnly(): void\n /** Stops observing and puts back everything the edit changed, keeping object identities. */\n restore(): void\n /** Stops observing the graph. */\n stop(): void\n}\n\n/**\n * Starts observing `graph` for an edit that may only change properties. Node identities are\n * kept as pointers, so replacing, adding, or removing a node anywhere is found; a node's fields\n * are compared and restored only where the graph reported it, so code that writes into a node\n * directly calls `SceneGraph.willChangeNode` first, and a node event without such a report fails\n * the edit.\n */\nexport function captureTouchedCheckpoint(graph: SceneGraph): TouchedCheckpoint {\n const nodeRefs = new Map(graph.nodes)\n const variableRefs = new Map(graph.variables)\n const collectionRefs = new Map(graph.variableCollections)\n const saved = structuredClone({\n enabledLibraries: graph.enabledLibraries\n })\n // Instances follow their nodes' components, which a property edit cannot change, so the sets\n // are kept rather than their ids copied deeply.\n const instanceIndex = new Map(\n [...graph.instanceIndex].map(([id, instances]) => [id, new Set(instances)])\n )\n const variables = new Map<string, Variable | null>()\n const variableCollections = new Map<string, VariableCollection | null>()\n // Property edits cannot edit assets. Retain existing buffers, not copies of every bitmap.\n const images = new Map(graph.images)\n const { rootId, figKiwiVersion, figSchemaDeflated, documentColorSpace } = graph\n const nodes = new Map<string, SceneNode>()\n const reported = new Set<string>()\n const created = new Set<string>()\n const impact = createSceneMutationImpact()\n\n /** Copies a node as the edit found it: the original object, should the edit have replaced it. */\n function copy(node: SceneNode) {\n nodes.set(node.id, structuredClone(nodeRefs.get(node.id) ?? node))\n }\n\n const skipped = (node: SceneNode) => nodes.has(node.id) || created.has(node.id)\n\n /**\n * Copies `node` and each ancestor not copied yet, up to but excluding its page. An ancestor\n * copied already had its own ancestors copied with it, so the walk stops there.\n */\n function copyLineage(node: SceneNode) {\n if (skipped(node)) return\n copy(node)\n if (!node.parentId) return\n graph.closest(node.parentId, (ancestor) => {\n if (ancestor.type === 'CANVAS' || ancestor.id === rootId || skipped(ancestor)) return true\n copy(ancestor)\n return false\n })\n }\n\n const unobserve = graph.observeNodeChanges({\n created: (node) => {\n created.add(node.id)\n reported.add(node.id)\n },\n before: (node) => {\n reported.add(node.id)\n copyLineage(node)\n },\n beforeRecord: (kind, id) => {\n if (kind === 'variable') copyRecord(variables, graph.variables, id)\n else copyRecord(variableCollections, graph.variableCollections, id)\n }\n })\n const unbindEvents = recordSceneMutations(graph, impact)\n let observing = true\n\n function stop() {\n if (!observing) return\n observing = false\n unobserve()\n unbindEvents()\n }\n\n function assertNodes() {\n if (\n created.size > 0 ||\n impact.deletedNodeIds.size > 0 ||\n graph.nodes.size !== nodeRefs.size ||\n graph.variables.size !== variableRefs.size\n )\n throw new Error(NODE_COUNT_ERROR)\n for (const [id, node] of graph.nodes) {\n const original = nodeRefs.get(id)\n if (!original) throw new Error(NODE_COUNT_ERROR)\n if (original !== node) throw new Error(NODE_IDENTITY_ERROR)\n }\n for (const [id, before] of nodes) {\n const after = graph.nodes.get(id)\n if (\n !after ||\n before.id !== after.id ||\n before.type !== after.type ||\n before.parentId !== after.parentId ||\n before.componentId !== after.componentId ||\n !isEqual(before.childIds, after.childIds)\n )\n throw new Error(NODE_IDENTITY_ERROR)\n }\n for (const id of [\n ...impact.changedNodeIds,\n ...impact.previousParentIds,\n ...impact.currentParentIds\n ]) {\n if (!nodes.has(id) && !created.has(id)) {\n throw new Error(\n `Atomic tools must report layer changes to the scene graph (SceneGraph.willChangeNode): ${id}`\n )\n }\n }\n }\n\n function assertPropertiesOnly() {\n assertNodes()\n if (!sameEntries(graph.variables, variableRefs)) throw new Error(VARIABLE_IDENTITY_ERROR)\n for (const [id, before] of variables) {\n const after = graph.variables.get(id)\n if (\n !before ||\n !after ||\n before.id !== after.id ||\n before.collectionId !== after.collectionId ||\n before.type !== after.type\n )\n throw new Error(VARIABLE_IDENTITY_ERROR)\n }\n if (\n !sameEntries(graph.variableCollections, collectionRefs) ||\n [...variableCollections].some(\n ([id, before]) => !isEqual(before, graph.variableCollections.get(id) ?? null)\n ) ||\n !isEqual(instanceIndex, graph.instanceIndex) ||\n !isEqual(saved.enabledLibraries, graph.enabledLibraries) ||\n images.size !== graph.images.size ||\n [...images].some(([id, bytes]) => graph.images.get(id) !== bytes) ||\n graph.rootId !== rootId ||\n graph.documentColorSpace !== documentColorSpace ||\n graph.figKiwiVersion !== figKiwiVersion ||\n // Every writer assigns a new schema rather than writing into it.\n graph.figSchemaDeflated !== figSchemaDeflated\n )\n throw new Error(DOCUMENT_ERROR)\n }\n\n /** Puts the node map back as it was, in its order, if the edit changed its entries. */\n function restoreNodeMap(): { removed: Map<string, SceneNode>; readded: Set<string> } {\n const removed = new Map<string, SceneNode>()\n const readded = new Set<string>()\n let changed = graph.nodes.size !== nodeRefs.size\n if (!changed) {\n // In lockstep, so a node removed and set again, which moves to the end, is put back too.\n const live = graph.nodes.entries()\n for (const [id, node] of nodeRefs) {\n const next = live.next()\n if (next.done || next.value[0] !== id || next.value[1] !== node) {\n changed = true\n break\n }\n }\n }\n if (!changed) return { removed, readded }\n const failed = new Map(graph.nodes)\n graph.nodes.clear()\n for (const [id, node] of nodeRefs) {\n graph.nodes.set(id, node)\n if (!failed.has(id)) readded.add(id)\n }\n for (const [id, node] of failed) if (!nodeRefs.has(id)) removed.set(id, node)\n return { removed, readded }\n }\n\n function restore() {\n stop()\n const { removed, readded } = restoreNodeMap()\n for (const [id, copy] of nodes) {\n const original = nodeRefs.get(id)\n if (!original) continue\n for (const key of Object.keys(original)) {\n if (!Object.hasOwn(copy, key)) Reflect.deleteProperty(original, key)\n }\n Object.assign(original, structuredClone(copy))\n }\n restoreCopied(graph.variables, variables, variableRefs)\n restoreCopied(graph.variableCollections, variableCollections, collectionRefs)\n restoreMap(\n graph.instanceIndex,\n new Map([...instanceIndex].map(([id, instances]) => [id, new Set(instances)]))\n )\n restoreMap(graph.enabledLibraries, structuredClone(saved.enabledLibraries))\n restoreMap(graph.images, images)\n graph.rootId = rootId\n graph.figKiwiVersion = figKiwiVersion\n graph.figSchemaDeflated = figSchemaDeflated\n graph.documentColorSpace = documentColorSpace\n graph.clearAbsPosCache()\n const touched = new Set([\n ...nodes.keys(),\n ...created,\n ...readded,\n ...removed.keys(),\n ...impact.changedNodeIds,\n ...impact.previousParentIds,\n ...impact.currentParentIds\n ])\n for (const id of touched) {\n if (graph.nodes.get(id)?.type === 'CONNECTOR') graph.connectorIds.add(id)\n else graph.connectorIds.delete(id)\n }\n // Notify consumers only after the complete hierarchy and indexes have been restored.\n for (const [id, node] of removed) graph.emitter.emit('node:deleted', id, node.parentId)\n for (const id of touched) {\n const node = graph.nodes.get(id)\n if (!node) continue\n if (readded.has(id)) graph.emitter.emit('node:created', node)\n else graph.emitter.emit('node:updated', id, node)\n }\n }\n\n return {\n nodes,\n reported,\n variables,\n variableCollections,\n assertPropertiesOnly,\n restore,\n stop\n }\n}\n"],"mappings":";;;AAMA,MAAM,mBAAmB;AACzB,MAAM,sBAAsB;AAC5B,MAAM,0BAA0B;AAChC,MAAM,iBAAiB;;AAGvB,SAAS,uBACP,OACA,OACA,MACM;CACN,KAAK,MAAM,CAAC,IAAI,WAAW,OAAO;EAChC,MAAM,QAAQ,MAAM,UAAU,IAAI,EAAE;EACpC,IACE,CAAC,SACD,UAAU,KAAK,IAAI,EAAE,KACrB,OAAO,OAAO,MAAM,MACpB,OAAO,iBAAiB,MAAM,gBAC9B,OAAO,SAAS,MAAM,MAEtB,MAAM,IAAI,MAAM,uBAAuB;CAC3C;AACF;;AAGA,SAAgB,uBAAuB,OAAmB;CACxD,MAAM,WAAW,IAAI,IAAI,MAAM,KAAK;CACpC,MAAM,eAAe,IAAI,IAAI,MAAM,SAAS;CAC5C,MAAM,iBAAiB,IAAI,IAAI,MAAM,mBAAmB;CACxD,MAAM,WAAW,gBAAgB;EAC/B,OAAO,MAAM;EACb,WAAW,MAAM;EACjB,qBAAqB,MAAM;EAC3B,eAAe,MAAM;EACrB,kBAAkB,MAAM;EACxB,QAAQ,MAAM;EACd,gBAAgB,MAAM;EACtB,mBAAmB,MAAM;EACzB,oBAAoB,MAAM;CAC5B,CAAC;CAED,MAAM,SAAS,IAAI,IAAI,MAAM,MAAM;CAEnC,SAAS,uBAAuB;EAC9B,IACE,SAAS,MAAM,SAAS,MAAM,MAAM,QACpC,SAAS,UAAU,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,IAAI,CAAC;EAC/C;EACA,cAAc,MAAM,WAAW,WAAW,YAAY;EACtD,cAAc,MAAM,qBAAqB,qBAAqB,cAAc;EAC5E,WACE,MAAM,eACN,IAAI,IAAI,CAAC,GAAG,aAAa,CAAC,CAAC,KAAK,CAAC,IAAI,eAAe,CAAC,IAAI,IAAI,IAAI,SAAS,CAAC,CAAC,CAAC,CAC/E;EACA,WAAW,MAAM,kBAAkB,gBAAgB,MAAM,gBAAgB,CAAC;EAC1E,WAAW,MAAM,QAAQ,MAAM;EAC/B,MAAM,SAAS;EACf,MAAM,iBAAiB;EACvB,MAAM,oBAAoB;EAC1B,MAAM,qBAAqB;EAC3B,MAAM,iBAAiB;EACvB,MAAM,0BAAU,IAAI,IAAI;GACtB,GAAG,MAAM,KAAK;GACd,GAAG;GACH,GAAG;GACH,GAAG,QAAQ,KAAK;GAChB,GAAG,OAAO;GACV,GAAG,OAAO;GACV,GAAG,OAAO;EACZ,CAAC;EACD,KAAK,MAAM,MAAM,SACf,IAAI,MAAM,MAAM,IAAI,EAAE,CAAC,EAAE,SAAS,aAAa,MAAM,aAAa,IAAI,EAAE;OACnE,MAAM,aAAa,OAAO,EAAE;EAGnC,KAAK,MAAM,CAAC,IAAI,SAAS,SAAS,MAAM,QAAQ,KAAK,gBAAgB,IAAI,KAAK,QAAQ;EACtF,KAAK,MAAM,MAAM,SAAS;GACxB,MAAM,OAAO,MAAM,MAAM,IAAI,EAAE;GAC/B,IAAI,CAAC,MAAM;GACX,IAAI,QAAQ,IAAI,EAAE,GAAG,MAAM,QAAQ,KAAK,gBAAgB,IAAI;QACvD,MAAM,QAAQ,KAAK,gBAAgB,IAAI,IAAI;EAClD;CACF;CAEA,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ComponentPropertyTarget, applyComponentPropertyValue, assignmentOverrideField, componentPropertyDefinitions, componentPropertyOwners, createComponentPropertyId, findComponentPropertyTarget, findComponentPropertyTargets, moveVariantPropertiesToSet, overriddenAssignmentId, reapplyComponentPropertyAssignments, recordAssignmentOverride, removeComponentProperty, resolveComponentPropertyValue } from "./properties.js";
|
|
1
|
+
import { ComponentPropertyTarget, applyComponentPropertyValue, assignmentOverrideField, componentPropertyDefinitions, componentPropertyOwners, createComponentPropertyId, findComponentPropertyTarget, findComponentPropertyTargets, moveVariantPropertiesToSet, overriddenAssignmentId, propertyOwner, reapplyComponentPropertyAssignments, recordAssignmentOverride, removeComponentProperty, resolveComponentPropertyValue } from "./properties.js";
|
|
2
2
|
import { compareCanvasPosition, defaultVariant, resolvedVariantDefinition, variantDefaultValue, variantOptions } from "./variants.js";
|
|
3
3
|
import { InstanceExposureIssue, exposableInstances, exposedInstances, instanceExposureIssue } from "./exposure.js";
|
|
4
|
-
export { ComponentPropertyTarget, type InstanceExposureIssue, applyComponentPropertyValue, assignmentOverrideField, compareCanvasPosition, componentPropertyDefinitions, componentPropertyOwners, createComponentPropertyId, defaultVariant, exposableInstances, exposedInstances, findComponentPropertyTarget, findComponentPropertyTargets, instanceExposureIssue, moveVariantPropertiesToSet, overriddenAssignmentId, reapplyComponentPropertyAssignments, recordAssignmentOverride, removeComponentProperty, resolveComponentPropertyValue, resolvedVariantDefinition, variantDefaultValue, variantOptions };
|
|
4
|
+
export { ComponentPropertyTarget, type InstanceExposureIssue, applyComponentPropertyValue, assignmentOverrideField, compareCanvasPosition, componentPropertyDefinitions, componentPropertyOwners, createComponentPropertyId, defaultVariant, exposableInstances, exposedInstances, findComponentPropertyTarget, findComponentPropertyTargets, instanceExposureIssue, moveVariantPropertiesToSet, overriddenAssignmentId, propertyOwner, reapplyComponentPropertyAssignments, recordAssignmentOverride, removeComponentProperty, resolveComponentPropertyValue, resolvedVariantDefinition, variantDefaultValue, variantOptions };
|
package/dist/components/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { applyComponentPropertyValue, assignmentOverrideField, componentPropertyDefinitions, componentPropertyOwners, createComponentPropertyId, findComponentPropertyTarget, findComponentPropertyTargets, moveVariantPropertiesToSet, overriddenAssignmentId, reapplyComponentPropertyAssignments, recordAssignmentOverride, removeComponentProperty, resolveComponentPropertyValue } from "./properties.js";
|
|
1
|
+
import { applyComponentPropertyValue, assignmentOverrideField, componentPropertyDefinitions, componentPropertyOwners, createComponentPropertyId, findComponentPropertyTarget, findComponentPropertyTargets, moveVariantPropertiesToSet, overriddenAssignmentId, propertyOwner, reapplyComponentPropertyAssignments, recordAssignmentOverride, removeComponentProperty, resolveComponentPropertyValue } from "./properties.js";
|
|
2
2
|
import { compareCanvasPosition, defaultVariant, resolvedVariantDefinition, variantDefaultValue, variantOptions } from "./variants.js";
|
|
3
3
|
import { exposableInstances, exposedInstances, instanceExposureIssue } from "./exposure.js";
|
|
4
|
-
export { applyComponentPropertyValue, assignmentOverrideField, compareCanvasPosition, componentPropertyDefinitions, componentPropertyOwners, createComponentPropertyId, defaultVariant, exposableInstances, exposedInstances, findComponentPropertyTarget, findComponentPropertyTargets, instanceExposureIssue, moveVariantPropertiesToSet, overriddenAssignmentId, reapplyComponentPropertyAssignments, recordAssignmentOverride, removeComponentProperty, resolveComponentPropertyValue, resolvedVariantDefinition, variantDefaultValue, variantOptions };
|
|
4
|
+
export { applyComponentPropertyValue, assignmentOverrideField, compareCanvasPosition, componentPropertyDefinitions, componentPropertyOwners, createComponentPropertyId, defaultVariant, exposableInstances, exposedInstances, findComponentPropertyTarget, findComponentPropertyTargets, instanceExposureIssue, moveVariantPropertiesToSet, overriddenAssignmentId, propertyOwner, reapplyComponentPropertyAssignments, recordAssignmentOverride, removeComponentProperty, resolveComponentPropertyValue, resolvedVariantDefinition, variantDefaultValue, variantOptions };
|
|
@@ -6,6 +6,11 @@ interface ComponentPropertyTarget {
|
|
|
6
6
|
field: ComponentPropertyReferenceField;
|
|
7
7
|
source: SceneNode;
|
|
8
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* The component that defines a main component's properties: its set when it is a variant,
|
|
11
|
+
* since variants own no properties of their own (desktop 126), else the component itself.
|
|
12
|
+
*/
|
|
13
|
+
declare function propertyOwner(graph: SceneGraph, component: SceneNode): SceneNode;
|
|
9
14
|
declare function componentPropertyOwners(graph: SceneGraph, instance: SceneNode): SceneNode[];
|
|
10
15
|
declare function componentPropertyDefinitions(graph: SceneGraph, instance: SceneNode): ComponentPropertyDefinition[];
|
|
11
16
|
declare function resolveComponentPropertyValue(graph: SceneGraph, value: string): SceneNode | null;
|
|
@@ -28,5 +33,5 @@ declare function moveVariantPropertiesToSet(graph: SceneGraph, setId: string): s
|
|
|
28
33
|
/** A new component property ID, in the `prop:` form the editor, plugin API, and design JSX share. */
|
|
29
34
|
declare function createComponentPropertyId(): string;
|
|
30
35
|
//#endregion
|
|
31
|
-
export { ComponentPropertyTarget, applyComponentPropertyValue, assignmentOverrideField, componentPropertyDefinitions, componentPropertyOwners, createComponentPropertyId, findComponentPropertyTarget, findComponentPropertyTargets, moveVariantPropertiesToSet, overriddenAssignmentId, reapplyComponentPropertyAssignments, recordAssignmentOverride, removeComponentProperty, resolveComponentPropertyValue };
|
|
36
|
+
export { ComponentPropertyTarget, applyComponentPropertyValue, assignmentOverrideField, componentPropertyDefinitions, componentPropertyOwners, createComponentPropertyId, findComponentPropertyTarget, findComponentPropertyTargets, moveVariantPropertiesToSet, overriddenAssignmentId, propertyOwner, reapplyComponentPropertyAssignments, recordAssignmentOverride, removeComponentProperty, resolveComponentPropertyValue };
|
|
32
37
|
//# sourceMappingURL=properties.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"properties.d.ts","names":[],"sources":["../../src/components/properties.ts"],"mappings":";;;UAWiB;EACf,MAAM;EACN,OAAO;EACP,QAAQ
|
|
1
|
+
{"version":3,"file":"properties.d.ts","names":[],"sources":["../../src/components/properties.ts"],"mappings":";;;UAWiB;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;iBA4Ea,4BACd,OAAO,YACP,oBACA,YAAY,6BACZ,gBACC;iBAwBa,oCACd,OAAO,YACP,qBACC;iBAqBa,wBAAwB;iBAIxB,uBAAuB;iBAMvB,yBACd,OAAO,YACP,oBACA;iBAsDc,wBACd,OAAO,YACP,iBACA;;;;;;;;iBA8Bc,2BAA2B,OAAO,YAAY;;iBA+B9C"}
|
|
@@ -3,6 +3,14 @@ import { randomHex } from "../random.js";
|
|
|
3
3
|
import { findInstanceAncestor, instanceMainComponent } from "../instances/main-component.js";
|
|
4
4
|
import { walkInstanceSources } from "../instances/source-walk.js";
|
|
5
5
|
//#region src/components/properties.ts
|
|
6
|
+
/**
|
|
7
|
+
* The component that defines a main component's properties: its set when it is a variant,
|
|
8
|
+
* since variants own no properties of their own (desktop 126), else the component itself.
|
|
9
|
+
*/
|
|
10
|
+
function propertyOwner(graph, component) {
|
|
11
|
+
const parent = component.parentId ? graph.getNode(component.parentId) : void 0;
|
|
12
|
+
return component.type === "COMPONENT" && parent?.type === "COMPONENT_SET" ? parent : component;
|
|
13
|
+
}
|
|
6
14
|
function componentPropertyOwners(graph, instance) {
|
|
7
15
|
if (instance.type !== "INSTANCE") return [];
|
|
8
16
|
const component = instanceMainComponent(graph, instance);
|
|
@@ -175,6 +183,6 @@ function createComponentPropertyId() {
|
|
|
175
183
|
return `prop:${randomHex(8)}`;
|
|
176
184
|
}
|
|
177
185
|
//#endregion
|
|
178
|
-
export { applyComponentPropertyValue, assignmentOverrideField, componentPropertyDefinitions, componentPropertyOwners, createComponentPropertyId, findComponentPropertyTarget, findComponentPropertyTargets, moveVariantPropertiesToSet, overriddenAssignmentId, reapplyComponentPropertyAssignments, recordAssignmentOverride, removeComponentProperty, resolveComponentPropertyValue };
|
|
186
|
+
export { applyComponentPropertyValue, assignmentOverrideField, componentPropertyDefinitions, componentPropertyOwners, createComponentPropertyId, findComponentPropertyTarget, findComponentPropertyTargets, moveVariantPropertiesToSet, overriddenAssignmentId, propertyOwner, reapplyComponentPropertyAssignments, recordAssignmentOverride, removeComponentProperty, resolveComponentPropertyValue };
|
|
179
187
|
|
|
180
188
|
//# sourceMappingURL=properties.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"properties.js","names":[],"sources":["../../src/components/properties.ts"],"sourcesContent":["import type { SceneGraph } from '../graph'\nimport { findInstanceAncestor, 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\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 graph.updateNode(instance.id, {\n componentPropertyAssignments: {\n ...instance.componentPropertyAssignments,\n [definition.id]: definition.type === 'INSTANCE_SWAP' && target ? target.id : value\n }\n })\n return definition.type === 'INSTANCE_SWAP' ? target : instance\n}\n\nexport function reapplyComponentPropertyAssignments(\n graph: SceneGraph,\n instanceId: string\n): ComponentPropertyDefinition[] {\n const instance = graph.getNode(instanceId)\n if (instance?.type !== 'INSTANCE') {\n return []\n }\n const definitions = new Map(\n componentPropertyDefinitions(graph, instance).map((definition) => [definition.id, definition])\n )\n const applied: ComponentPropertyDefinition[] = []\n for (const [propertyId, value] of Object.entries(instance.componentPropertyAssignments)) {\n const definition = definitions.get(propertyId)\n if (definition && definition.type !== 'VARIANT') {\n applyComponentPropertyValue(graph, instanceId, definition, value)\n applied.push(definition)\n }\n }\n return applied\n}\n\nconst ASSIGNMENT_OVERRIDE_PREFIX = 'componentPropertyAssignments/'\n\nexport function assignmentOverrideField(propertyId: string): string {\n return `${ASSIGNMENT_OVERRIDE_PREFIX}${propertyId}`\n}\n\nexport function overriddenAssignmentId(field: string): string | undefined {\n return field.startsWith(ASSIGNMENT_OVERRIDE_PREFIX)\n ? field.slice(ASSIGNMENT_OVERRIDE_PREFIX.length)\n : undefined\n}\n\nexport function recordAssignmentOverride(\n graph: SceneGraph,\n instanceId: string,\n propertyId: string\n): void {\n const instance = graph.getNode(instanceId)\n const owner = instance?.parentId ? findInstanceAncestor(graph, instance.parentId) : undefined\n if (!instance || !owner) {\n return\n }\n setInstanceOverride(\n owner.instanceOverrides,\n owner.id,\n instance.id,\n assignmentOverrideField(propertyId),\n instance.componentPropertyAssignments[propertyId]\n )\n graph.updateNode(owner.id, { instanceOverrides: owner.instanceOverrides })\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/**\n * Moves the boolean, text, instance swap, and slot properties a set's variants define themselves\n * onto the set, under their IDs, so the layers and instances naming them still do: a variant's\n * properties are its set's, as Figma keeps them, and combining components moves theirs to the\n * set (desktop 126). A property the set already has under that ID is not added again. Returns\n * the IDs of the set and the variants it changed.\n */\nexport function moveVariantPropertiesToSet(graph: SceneGraph, setId: string): string[] {\n const set = graph.getNode(setId)\n if (set?.type !== 'COMPONENT_SET') return []\n const changed: string[] = []\n const known = new Set(set.componentPropertyDefinitions.map((definition) => definition.id))\n const moved: ComponentPropertyDefinition[] = []\n for (const variant of graph.getChildren(setId)) {\n const own = variant.componentPropertyDefinitions.filter(\n (definition) => definition.type !== 'VARIANT'\n )\n if (variant.type !== 'COMPONENT' || own.length === 0) continue\n for (const definition of own) {\n if (known.has(definition.id)) continue\n known.add(definition.id)\n moved.push(definition)\n }\n graph.updateNode(variant.id, {\n componentPropertyDefinitions: variant.componentPropertyDefinitions.filter(\n (definition) => definition.type === 'VARIANT'\n )\n })\n changed.push(variant.id)\n }\n if (moved.length === 0) return changed\n graph.updateNode(setId, {\n componentPropertyDefinitions: [...moved, ...set.componentPropertyDefinitions]\n })\n return [setId, ...changed]\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":";;;;;AAiBA,SAAgB,wBAAwB,OAAmB,UAAkC;CAC3F,IAAI,SAAS,SAAS,YAAY,O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AW,SAAS,SACtC,EACF,CAAC;EACD,QAAQ,KAAK,QAAQ,EAAE;CACzB;CACA,IAAI,MAAM,WAAW,GAAG,OAAO;CAC/B,MAAM,WAAW,OAAO,EACtB,8BAA8B,CAAC,GAAG,OAAO,GAAG,IAAI,4BAA4B,EAC9E,CAAC;CACD,OAAO,CAAC,OAAO,GAAG,OAAO;AAC3B;;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, 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 graph.updateNode(instance.id, {\n componentPropertyAssignments: {\n ...instance.componentPropertyAssignments,\n [definition.id]: definition.type === 'INSTANCE_SWAP' && target ? target.id : value\n }\n })\n return definition.type === 'INSTANCE_SWAP' ? target : instance\n}\n\nexport function reapplyComponentPropertyAssignments(\n graph: SceneGraph,\n instanceId: string\n): ComponentPropertyDefinition[] {\n const instance = graph.getNode(instanceId)\n if (instance?.type !== 'INSTANCE') {\n return []\n }\n const definitions = new Map(\n componentPropertyDefinitions(graph, instance).map((definition) => [definition.id, definition])\n )\n const applied: ComponentPropertyDefinition[] = []\n for (const [propertyId, value] of Object.entries(instance.componentPropertyAssignments)) {\n const definition = definitions.get(propertyId)\n if (definition && definition.type !== 'VARIANT') {\n applyComponentPropertyValue(graph, instanceId, definition, value)\n applied.push(definition)\n }\n }\n return applied\n}\n\nconst ASSIGNMENT_OVERRIDE_PREFIX = 'componentPropertyAssignments/'\n\nexport function assignmentOverrideField(propertyId: string): string {\n return `${ASSIGNMENT_OVERRIDE_PREFIX}${propertyId}`\n}\n\nexport function overriddenAssignmentId(field: string): string | undefined {\n return field.startsWith(ASSIGNMENT_OVERRIDE_PREFIX)\n ? field.slice(ASSIGNMENT_OVERRIDE_PREFIX.length)\n : undefined\n}\n\nexport function recordAssignmentOverride(\n graph: SceneGraph,\n instanceId: string,\n propertyId: string\n): void {\n const instance = graph.getNode(instanceId)\n const owner = instance?.parentId ? findInstanceAncestor(graph, instance.parentId) : undefined\n if (!instance || !owner) {\n return\n }\n setInstanceOverride(\n owner.instanceOverrides,\n owner.id,\n instance.id,\n assignmentOverrideField(propertyId),\n instance.componentPropertyAssignments[propertyId]\n )\n graph.updateNode(owner.id, { instanceOverrides: owner.instanceOverrides })\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/**\n * Moves the boolean, text, instance swap, and slot properties a set's variants define themselves\n * onto the set, under their IDs, so the layers and instances naming them still do: a variant's\n * properties are its set's, as Figma keeps them, and combining components moves theirs to the\n * set (desktop 126). A property the set already has under that ID is not added again. Returns\n * the IDs of the set and the variants it changed.\n */\nexport function moveVariantPropertiesToSet(graph: SceneGraph, setId: string): string[] {\n const set = graph.getNode(setId)\n if (set?.type !== 'COMPONENT_SET') return []\n const changed: string[] = []\n const known = new Set(set.componentPropertyDefinitions.map((definition) => definition.id))\n const moved: ComponentPropertyDefinition[] = []\n for (const variant of graph.getChildren(setId)) {\n const own = variant.componentPropertyDefinitions.filter(\n (definition) => definition.type !== 'VARIANT'\n )\n if (variant.type !== 'COMPONENT' || own.length === 0) continue\n for (const definition of own) {\n if (known.has(definition.id)) continue\n known.add(definition.id)\n moved.push(definition)\n }\n graph.updateNode(variant.id, {\n componentPropertyDefinitions: variant.componentPropertyDefinitions.filter(\n (definition) => definition.type === 'VARIANT'\n )\n })\n changed.push(variant.id)\n }\n if (moved.length === 0) return changed\n graph.updateNode(setId, {\n componentPropertyDefinitions: [...moved, ...set.componentPropertyDefinitions]\n })\n return [setId, ...changed]\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":";;;;;;;;;AAqBA,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,IAAI,QAAQ,SAAS,aAAa,OAAO;CACzC,IAAI,QAAQ,SAAS,iBAAiB;EACpC,MAAM,cAAc,OAAO,SAAS,MAAM,OAAO,MAAM,QAAQ,EAAE,CAAC,EAAE,SAAS,WAAW;EACxF,OAAO,cAAe,MAAM,QAAQ,WAAW,KAAK,OAAQ;CAC9D;CACA,KAAK,MAAM,QAAQ,MAAM,YAAY,GACnC,IACE,KAAK,SAAS,gBACb,KAAK,iBAAiB,SAAS,KAAK,qBA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,MAAM,YAAY,KAAK,GAAG;EAC9C,MAAM,MAAM,QAAQ,6BAA6B,QAC9C,eAAe,WAAW,SAAS,SACtC;EACA,IAAI,QAAQ,SAAS,eAAe,IAAI,WAAW,GAAG;EACtD,KAAK,MAAM,cAAc,KAAK;GAC5B,IAAI,MAAM,IAAI,WAAW,EAAE,GAAG;GAC9B,MAAM,IAAI,WAAW,EAAE;GACvB,MAAM,KAAK,UAAU;EACvB;EACA,MAAM,WAAW,QAAQ,IAAI,EAC3B,8BAA8B,QAAQ,6BAA6B,QAChE,eAAe,WAAW,SAAS,SACtC,EACF,CAAC;EACD,QAAQ,KAAK,QAAQ,EAAE;CACzB;CACA,IAAI,MAAM,WAAW,GAAG,OAAO;CAC/B,MAAM,WAAW,OAAO,EACtB,8BAA8B,CAAC,GAAG,OAAO,GAAG,IAAI,4BAA4B,EAC9E,CAAC;CACD,OAAO,CAAC,OAAO,GAAG,OAAO;AAC3B;;AAGA,SAAgB,4BAAoC;CAClD,OAAO,QAAQ,UAAU,CAAC;AAC5B"}
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { Color } from "./primitives/index.js";
|
|
2
|
+
import { GlassEffectParams } from "./types.js";
|
|
2
3
|
//#region src/constants.d.ts
|
|
3
4
|
declare const BLACK: Color;
|
|
4
5
|
declare const WHITE: Color;
|
|
5
6
|
declare const TRANSPARENT: Color;
|
|
7
|
+
/** The lens of a glass effect whose values are missing: the least it can be, so it bends nothing. */
|
|
8
|
+
declare const UNSET_GLASS: Readonly<GlassEffectParams>;
|
|
9
|
+
/** The lens a new glass effect starts with when nothing sets its values. */
|
|
10
|
+
declare const DEFAULT_GLASS: Readonly<GlassEffectParams>;
|
|
6
11
|
declare const DEFAULT_FONT_FAMILY = "Inter";
|
|
7
12
|
declare const DEFAULT_STROKE_MITER_LIMIT = 4;
|
|
8
13
|
declare const DEFAULT_STROKE_WEIGHT = 1;
|
|
9
14
|
//#endregion
|
|
10
|
-
export { BLACK, DEFAULT_FONT_FAMILY, DEFAULT_STROKE_MITER_LIMIT, DEFAULT_STROKE_WEIGHT, TRANSPARENT, WHITE };
|
|
15
|
+
export { BLACK, DEFAULT_FONT_FAMILY, DEFAULT_GLASS, DEFAULT_STROKE_MITER_LIMIT, DEFAULT_STROKE_WEIGHT, TRANSPARENT, UNSET_GLASS, WHITE };
|
|
11
16
|
//# sourceMappingURL=constants.d.ts.map
|
package/dist/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","names":[],"sources":["../src/constants.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"constants.d.ts","names":[],"sources":["../src/constants.ts"],"mappings":";;;cAGa,OAAO;cACP,OAAO;cACP,aAAa;;cAEb,aAAa,SAAS;;cAQtB,eAAe,SAAS;cAOxB;cACA;cACA"}
|
package/dist/constants.js
CHANGED
|
@@ -17,10 +17,26 @@ const TRANSPARENT = {
|
|
|
17
17
|
b: 0,
|
|
18
18
|
a: 0
|
|
19
19
|
};
|
|
20
|
+
/** The lens of a glass effect whose values are missing: the least it can be, so it bends nothing. */
|
|
21
|
+
const UNSET_GLASS = {
|
|
22
|
+
refraction: 0,
|
|
23
|
+
depth: 1,
|
|
24
|
+
lightAngle: 0,
|
|
25
|
+
lightIntensity: 0,
|
|
26
|
+
dispersion: 0
|
|
27
|
+
};
|
|
28
|
+
/** The lens a new glass effect starts with when nothing sets its values. */
|
|
29
|
+
const DEFAULT_GLASS = {
|
|
30
|
+
refraction: .5,
|
|
31
|
+
depth: 20,
|
|
32
|
+
lightAngle: -45,
|
|
33
|
+
lightIntensity: .5,
|
|
34
|
+
dispersion: 0
|
|
35
|
+
};
|
|
20
36
|
const DEFAULT_FONT_FAMILY = "Inter";
|
|
21
37
|
const DEFAULT_STROKE_MITER_LIMIT = 4;
|
|
22
38
|
const DEFAULT_STROKE_WEIGHT = 1;
|
|
23
39
|
//#endregion
|
|
24
|
-
export { BLACK, DEFAULT_FONT_FAMILY, DEFAULT_STROKE_MITER_LIMIT, DEFAULT_STROKE_WEIGHT, TRANSPARENT, WHITE };
|
|
40
|
+
export { BLACK, DEFAULT_FONT_FAMILY, DEFAULT_GLASS, DEFAULT_STROKE_MITER_LIMIT, DEFAULT_STROKE_WEIGHT, TRANSPARENT, UNSET_GLASS, WHITE };
|
|
25
41
|
|
|
26
42
|
//# sourceMappingURL=constants.js.map
|
package/dist/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","names":[],"sources":["../src/constants.ts"],"sourcesContent":["import type { Color } from './primitives'\n\nexport const BLACK: Color = { r: 0, g: 0, b: 0, a: 1 }\nexport const WHITE: Color = { r: 1, g: 1, b: 1, a: 1 }\nexport const TRANSPARENT: Color = { r: 0, g: 0, b: 0, a: 0 }\nexport const DEFAULT_FONT_FAMILY = 'Inter'\nexport const DEFAULT_STROKE_MITER_LIMIT = 4\nexport const DEFAULT_STROKE_WEIGHT = 1\n"],"mappings":";
|
|
1
|
+
{"version":3,"file":"constants.js","names":[],"sources":["../src/constants.ts"],"sourcesContent":["import type { Color } from './primitives'\nimport type { GlassEffectParams } from './types'\n\nexport const BLACK: Color = { r: 0, g: 0, b: 0, a: 1 }\nexport const WHITE: Color = { r: 1, g: 1, b: 1, a: 1 }\nexport const TRANSPARENT: Color = { r: 0, g: 0, b: 0, a: 0 }\n/** The lens of a glass effect whose values are missing: the least it can be, so it bends nothing. */\nexport const UNSET_GLASS: Readonly<GlassEffectParams> = {\n refraction: 0,\n depth: 1,\n lightAngle: 0,\n lightIntensity: 0,\n dispersion: 0\n}\n/** The lens a new glass effect starts with when nothing sets its values. */\nexport const DEFAULT_GLASS: Readonly<GlassEffectParams> = {\n refraction: 0.5,\n depth: 20,\n lightAngle: -45,\n lightIntensity: 0.5,\n dispersion: 0\n}\nexport const DEFAULT_FONT_FAMILY = 'Inter'\nexport const DEFAULT_STROKE_MITER_LIMIT = 4\nexport const DEFAULT_STROKE_WEIGHT = 1\n"],"mappings":";AAGA,MAAa,QAAe;CAAE,GAAG;CAAG,GAAG;CAAG,GAAG;CAAG,GAAG;AAAE;AACrD,MAAa,QAAe;CAAE,GAAG;CAAG,GAAG;CAAG,GAAG;CAAG,GAAG;AAAE;AACrD,MAAa,cAAqB;CAAE,GAAG;CAAG,GAAG;CAAG,GAAG;CAAG,GAAG;AAAE;;AAE3D,MAAa,cAA2C;CACtD,YAAY;CACZ,OAAO;CACP,YAAY;CACZ,gBAAgB;CAChB,YAAY;AACd;;AAEA,MAAa,gBAA6C;CACxD,YAAY;CACZ,OAAO;CACP,YAAY;CACZ,gBAAgB;CAChB,YAAY;AACd;AACA,MAAa,sBAAsB;AACnC,MAAa,6BAA6B;AAC1C,MAAa,wBAAwB"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { SceneGraph } from "./graph.js";
|
|
2
|
+
import { ConstraintType, SceneNode } from "./types.js";
|
|
3
|
+
//#region src/constraints.d.ts
|
|
4
|
+
type ConstraintGraph = Pick<SceneGraph, 'getNode' | 'closest'>;
|
|
5
|
+
/** Containers whose children keep their place by their own constraints when they resize. */
|
|
6
|
+
declare const CONSTRAINT_PARENT_TYPES: ReadonlySet<SceneNode['type']>;
|
|
7
|
+
/**
|
|
8
|
+
* The frame, component, or instance whose resize moves `node` by its constraints: its parent, or,
|
|
9
|
+
* for a layer in groups and booleans, the frame around the outermost of them, as in Figma (live,
|
|
10
|
+
* #1835). Null when nothing places it by constraints: on a page or in a section, or in an auto
|
|
11
|
+
* layout flow.
|
|
12
|
+
*/
|
|
13
|
+
declare function constraintFrame(graph: ConstraintGraph, node: SceneNode): SceneNode | null;
|
|
14
|
+
/** Whether `node` has constraints the Design panel offers and the canvas shows. */
|
|
15
|
+
declare function isConstraintEligible(graph: ConstraintGraph, node: SceneNode): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* The layers whose constraints `node` stands for. A group or boolean has none of its own: it shows
|
|
18
|
+
* and sets those of the layers in it, through nested groups and booleans, as in Figma.
|
|
19
|
+
*/
|
|
20
|
+
declare function constraintLayers(graph: ConstraintGraph, node: SceneNode): SceneNode[];
|
|
21
|
+
/** The constraint the layers share on one axis, or null when they differ or there are none. */
|
|
22
|
+
declare function sharedConstraint(layers: readonly SceneNode[], key: 'horizontalConstraint' | 'verticalConstraint'): ConstraintType | null;
|
|
23
|
+
//#endregion
|
|
24
|
+
export { CONSTRAINT_PARENT_TYPES, constraintFrame, constraintLayers, isConstraintEligible, sharedConstraint };
|
|
25
|
+
//# sourceMappingURL=constraints.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constraints.d.ts","names":[],"sources":["../src/constraints.ts"],"mappings":";;;KAIK,kBAAkB,KAAK;;cAGf,yBAAyB,YAAY;;;;;;;iBAalC,gBAAgB,OAAO,iBAAiB,MAAM,YAAY;;iBAe1D,qBAAqB,OAAO,iBAAiB,MAAM;;;;;iBAQnD,iBAAiB,OAAO,iBAAiB,MAAM,YAAY;;iBAS3D,iBACd,iBAAiB,aACjB,qDACC"}
|