@open-pencil/scene-graph 0.17.0-beta.2 → 0.17.0-beta.4
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/undo.js
CHANGED
|
@@ -10,9 +10,13 @@ var UndoManager = class {
|
|
|
10
10
|
settlers = /* @__PURE__ */ new Set();
|
|
11
11
|
limit;
|
|
12
12
|
onChange;
|
|
13
|
+
onDiscard;
|
|
14
|
+
runReplay;
|
|
13
15
|
constructor(options = {}) {
|
|
14
16
|
this.limit = options.limit ?? 200;
|
|
15
17
|
this.onChange = options.onChange;
|
|
18
|
+
this.onDiscard = options.onDiscard;
|
|
19
|
+
this.runReplay = options.runReplay ?? ((replay) => replay());
|
|
16
20
|
}
|
|
17
21
|
apply(entry) {
|
|
18
22
|
this.execute(entry);
|
|
@@ -58,7 +62,7 @@ var UndoManager = class {
|
|
|
58
62
|
if (!entry) return null;
|
|
59
63
|
this.replay(() => entry.inverse());
|
|
60
64
|
this.redoStack.push(entry);
|
|
61
|
-
this.onChange?.();
|
|
65
|
+
this.onChange?.("undo");
|
|
62
66
|
return entry.label;
|
|
63
67
|
}
|
|
64
68
|
redo() {
|
|
@@ -67,7 +71,7 @@ var UndoManager = class {
|
|
|
67
71
|
if (!entry) return null;
|
|
68
72
|
this.replay(() => entry.forward());
|
|
69
73
|
this.undoStack.push(entry);
|
|
70
|
-
this.onChange?.();
|
|
74
|
+
this.onChange?.("redo");
|
|
71
75
|
return entry.label;
|
|
72
76
|
}
|
|
73
77
|
beginBatch(label, coalesceKey) {
|
|
@@ -97,9 +101,21 @@ var UndoManager = class {
|
|
|
97
101
|
}
|
|
98
102
|
}
|
|
99
103
|
rollbackBatch() {
|
|
100
|
-
const batch = this.batches.
|
|
104
|
+
const batch = this.batches.at(-1);
|
|
101
105
|
if (!batch) return;
|
|
102
|
-
|
|
106
|
+
try {
|
|
107
|
+
for (const entry of batch.entries.toReversed()) entry.inverse();
|
|
108
|
+
} finally {
|
|
109
|
+
this.batches.pop();
|
|
110
|
+
}
|
|
111
|
+
this.onDiscard?.();
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Reports an edit that ended without a step, rolled back or changing nothing, as a rolled-back
|
|
115
|
+
* batch does. Called once the edit has closed, so `isRecording` tells whether another is open.
|
|
116
|
+
*/
|
|
117
|
+
discardEdit() {
|
|
118
|
+
this.onDiscard?.();
|
|
103
119
|
}
|
|
104
120
|
/** Abandon provisional history without replaying it or changing committed undo/redo entries. */
|
|
105
121
|
discardBatches() {
|
|
@@ -109,7 +125,7 @@ var UndoManager = class {
|
|
|
109
125
|
this.undoStack = [];
|
|
110
126
|
this.redoStack = [];
|
|
111
127
|
this.discardBatches();
|
|
112
|
-
this.onChange?.();
|
|
128
|
+
this.onChange?.("clear");
|
|
113
129
|
}
|
|
114
130
|
/** Whether undo or redo is replaying a step, whose changes are history rather than new edits. */
|
|
115
131
|
get isReplaying() {
|
|
@@ -135,12 +151,13 @@ var UndoManager = class {
|
|
|
135
151
|
entry.inverse();
|
|
136
152
|
inverse();
|
|
137
153
|
};
|
|
154
|
+
this.onChange?.("join", last);
|
|
138
155
|
return true;
|
|
139
156
|
}
|
|
140
157
|
replay(step) {
|
|
141
158
|
this.replaying++;
|
|
142
159
|
try {
|
|
143
|
-
step
|
|
160
|
+
this.runReplay(step);
|
|
144
161
|
} finally {
|
|
145
162
|
this.replaying--;
|
|
146
163
|
}
|
|
@@ -222,7 +239,7 @@ var UndoManager = class {
|
|
|
222
239
|
else this.undoStack.push(entry);
|
|
223
240
|
this.redoStack = [];
|
|
224
241
|
this.trimUndoStack();
|
|
225
|
-
this.onChange?.();
|
|
242
|
+
this.onChange?.("record", this.undoStack.at(-1));
|
|
226
243
|
}
|
|
227
244
|
trimUndoStack() {
|
|
228
245
|
if (!Number.isFinite(this.limit) || this.limit <= 0) return;
|
package/dist/undo.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"undo.js","names":[],"sources":["../src/undo.ts"],"sourcesContent":["export interface UndoEntry {\n label: string\n forward: () => void\n inverse: () => void\n coalesceKey?: string\n}\n\nexport interface UndoManagerOptions {\n limit?: number\n /** Called after recording, undoing, redoing, or clearing committed history. */\n onChange?: () => void\n}\n\ninterface UndoBatch {\n label: string\n entries: UndoEntry[]\n coalesceKey?: string\n}\n\n/** How many edits undo keeps by default. */\nexport const DEFAULT_HISTORY_LIMIT = 200\n\nexport class UndoManager {\n private undoStack: UndoEntry[] = []\n private redoStack: UndoEntry[] = []\n private batches: UndoBatch[] = []\n private replaying = 0\n private openEdits = 0\n private readonly settlers = new Set<() => void>()\n private readonly limit: number\n private readonly onChange: (() => void) | undefined\n\n constructor(options: UndoManagerOptions = {}) {\n this.limit = options.limit ?? DEFAULT_HISTORY_LIMIT\n this.onChange = options.onChange\n }\n\n apply(entry: UndoEntry): void {\n this.execute(entry)\n }\n\n execute(entry: UndoEntry): void {\n entry.forward()\n this.record(entry)\n }\n\n push(entry: UndoEntry): void {\n this.record(entry)\n }\n\n record(entry: UndoEntry): void {\n const batch = this.currentBatch\n if (batch) {\n batch.entries.push(entry)\n return\n }\n this.pushUndoEntry(entry)\n }\n\n /**\n * Records an entry as a step of its own, outside the batches being built, such as an agent's\n * edit made while a colour picker is open. Batches settle first, so the step follows the\n * changes they hold so far.\n */\n pushStep(entry: UndoEntry): void {\n this.settle()\n this.pushUndoEntry(entry)\n }\n\n /**\n * Registers a hook that commits an edit still being coalesced, such as a run of picker changes.\n * Undo and redo run every hook first, so they act on the newest change.\n */\n onBeforeHistory(settle: () => void): () => void {\n this.settlers.add(settle)\n return () => this.settlers.delete(settle)\n }\n\n private settle() {\n for (const settle of this.settlers) settle()\n }\n\n undo(): string | null {\n this.settle()\n const entry = this.undoStack.pop()\n if (!entry) return null\n this.replay(() => entry.inverse())\n this.redoStack.push(entry)\n this.onChange?.()\n return entry.label\n }\n\n redo(): string | null {\n this.settle()\n const entry = this.redoStack.pop()\n if (!entry) return null\n this.replay(() => entry.forward())\n this.undoStack.push(entry)\n this.onChange?.()\n return entry.label\n }\n\n beginBatch(label: string, coalesceKey?: string): void {\n this.batches.push({ label, entries: [], coalesceKey })\n }\n\n commitBatch(): void {\n const batch = this.batches.pop()\n if (!batch || batch.entries.length === 0) return\n\n const entry = this.createBatchEntry(batch)\n const parentBatch = this.currentBatch\n if (parentBatch) parentBatch.entries.push(entry)\n else this.pushUndoEntry(entry)\n }\n\n runBatch<T>(label: string, fn: () => T, coalesceKey?: string): T {\n this.beginBatch(label, coalesceKey)\n try {\n const result = fn()\n this.commitBatch()\n return result\n } catch (error) {\n this.rollbackBatch()\n throw error\n }\n }\n\n rollbackBatch(): void {\n const batch = this.batches.pop()\n if (!batch) return\n for (const entry of batch.entries.toReversed()) entry.inverse()\n }\n\n /** Abandon provisional history without replaying it or changing committed undo/redo entries. */\n discardBatches(): void {\n this.batches = []\n }\n\n clear(): void {\n this.undoStack = []\n this.redoStack = []\n this.discardBatches()\n this.onChange?.()\n }\n\n /** Whether undo or redo is replaying a step, whose changes are history rather than new edits. */\n get isReplaying(): boolean {\n return this.replaying > 0\n }\n\n /**\n * Adds a change that the newest step caused, as one an editor makes in response to it, so undo\n * and redo apply them together. Inside a batch it joins the batch. False with no step to join.\n */\n extendLastStep(entry: UndoEntry): boolean {\n if (this.currentBatch) {\n this.currentBatch.entries.push(entry)\n return true\n }\n const last = this.undoStack.at(-1)\n if (!last) return false\n // The step keeps its identity, so callers that hold it still find it in the history.\n const { forward, inverse } = last\n last.forward = () => {\n forward()\n entry.forward()\n }\n last.inverse = () => {\n entry.inverse()\n inverse()\n }\n return true\n }\n\n private replay(step: () => void) {\n this.replaying++\n try {\n step()\n } finally {\n this.replaying--\n }\n }\n\n get isBatching(): boolean {\n return this.batches.length > 0\n }\n\n /**\n * Marks an edit whose step is recorded when it ends, such as an agent's call that awaits fonts\n * or a layout before it finishes. Returns the function that ends it; ending it twice is a no-op.\n */\n openEdit(): () => void {\n this.openEdits++\n let open = true\n return () => {\n if (!open) return\n open = false\n this.openEdits--\n }\n }\n\n /**\n * Whether a batch or an edit opened with `openEdit` will record a step for the changes made now,\n * so they are not edits outside the history.\n */\n get isRecording(): boolean {\n return this.isBatching || this.openEdits > 0\n }\n\n /** Committed history, or changes in an open batch that a settling hook commits first. */\n get canUndo(): boolean {\n if (this.undoStack.length > 0) return true\n return this.settlers.size > 0 && this.batches.some((batch) => batch.entries.length > 0)\n }\n\n get canRedo(): boolean {\n return this.redoStack.length > 0\n }\n\n /**\n * The entry `depth` steps below the top of the undo stack, so a caller that pushed entries\n * can tell whether they are still the most recent ones.\n */\n peekUndo(depth = 0): UndoEntry | undefined {\n return this.undoStack.at(-1 - depth)\n }\n\n /** The entry `depth` steps below the top of the redo stack, the next one Redo applies at 0. */\n peekRedo(depth = 0): UndoEntry | undefined {\n return this.redoStack.at(-1 - depth)\n }\n\n /**\n * Whether `entry` is applied (on the undo stack) or undone (on the redo stack); null once it\n * left the history, trimmed or dropped when an edit cleared Redo.\n */\n stateOf(entry: UndoEntry): 'applied' | 'undone' | null {\n if (this.undoStack.includes(entry)) return 'applied'\n if (this.redoStack.includes(entry)) return 'undone'\n return null\n }\n\n get undoLabel(): string | null {\n return this.undoStack.at(-1)?.label ?? null\n }\n\n get redoLabel(): string | null {\n return this.redoStack.at(-1)?.label ?? null\n }\n\n private get currentBatch(): UndoBatch | null {\n return this.batches.at(-1) ?? null\n }\n\n private createBatchEntry(batch: UndoBatch): UndoEntry {\n return {\n label: batch.label,\n forward: () => batch.entries.forEach((entry) => entry.forward()),\n inverse: () => batch.entries.toReversed().forEach((entry) => entry.inverse()),\n coalesceKey: batch.coalesceKey\n }\n }\n\n private pushUndoEntry(entry: UndoEntry): void {\n const previous = this.undoStack.at(-1)\n if (entry.coalesceKey && previous?.coalesceKey === entry.coalesceKey) {\n this.undoStack[this.undoStack.length - 1] = {\n ...entry,\n inverse: previous.inverse\n }\n } else {\n this.undoStack.push(entry)\n }\n this.redoStack = []\n this.trimUndoStack()\n this.onChange?.()\n }\n\n private trimUndoStack(): void {\n if (!Number.isFinite(this.limit) || this.limit <= 0) return\n const overflow = this.undoStack.length - this.limit\n if (overflow > 0) this.undoStack.splice(0, overflow)\n }\n}\n"],"mappings":";;AAoBA,MAAa,wBAAwB;AAErC,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AC5C,MAAM,WAAW,KAAK,UAAU,GAAG,EAAE;EACrC,IAAI,MAAM,eAAe,UAAU,gBAAgB,MAAM,aACvD,KAAK,UAAU,KAAK,UAAU,SAAS,KAAK;GAC1C,GAAG;GACH,SAAS,SAAS;EACpB;OAEA,KAAK,UAAU,KAAK,KAAK;EAE3B,KAAK,YAAY,CAAC;EAClB,KAAK,cAAc;EACnB,KAAK,WAAW;CAClB;CAEA,gBAA8B;EAC5B,IAAI,CAAC,OAAO,SAAS,KAAK,KAAK,KAAK,KAAK,SAAS,GAAG;EACrD,MAAM,WAAW,KAAK,UAAU,SAAS,KAAK;EAC9C,IAAI,WAAW,GAAG,KAAK,UAAU,OAAO,GAAG,QAAQ;CACrD;AACF"}
|
|
1
|
+
{"version":3,"file":"undo.js","names":[],"sources":["../src/undo.ts"],"sourcesContent":["export interface UndoEntry {\n label: string\n forward: () => void\n inverse: () => void\n coalesceKey?: string\n}\n\n/**\n * Why committed history changed: a new step, a change joining the newest step, undo, redo, or\n * clearing it.\n */\nexport type HistoryChange = 'record' | 'join' | 'undo' | 'redo' | 'clear'\n\nexport interface UndoManagerOptions {\n limit?: number\n /**\n * Called after recording, joining, undoing, redoing, or clearing committed history, with which,\n * and with the step recorded or joined for `'record'` and `'join'`.\n */\n onChange?: (change: HistoryChange, step?: UndoEntry) => void\n /**\n * Called when an edit ends without a step, its changes undone or amounting to nothing: a batch\n * rolled back, or an edit reported with `discardEdit`. History is unchanged, so `onChange` is not.\n */\n onDiscard?: () => void\n /**\n * Runs an undo or a redo, which the editor runs outside edits in progress\n * (`SceneGraph.runOutsideEdits`), so an agent's edit open meanwhile does not record it.\n */\n runReplay?: (replay: () => void) => void\n}\n\ninterface UndoBatch {\n label: string\n entries: UndoEntry[]\n coalesceKey?: string\n}\n\n/** How many edits undo keeps by default. */\nexport const DEFAULT_HISTORY_LIMIT = 200\n\nexport class UndoManager {\n private undoStack: UndoEntry[] = []\n private redoStack: UndoEntry[] = []\n private batches: UndoBatch[] = []\n private replaying = 0\n private openEdits = 0\n private readonly settlers = new Set<() => void>()\n private readonly limit: number\n private readonly onChange: ((change: HistoryChange, step?: UndoEntry) => void) | undefined\n private readonly onDiscard: (() => void) | undefined\n private readonly runReplay: (replay: () => void) => void\n\n constructor(options: UndoManagerOptions = {}) {\n this.limit = options.limit ?? DEFAULT_HISTORY_LIMIT\n this.onChange = options.onChange\n this.onDiscard = options.onDiscard\n this.runReplay = options.runReplay ?? ((replay) => replay())\n }\n\n apply(entry: UndoEntry): void {\n this.execute(entry)\n }\n\n execute(entry: UndoEntry): void {\n entry.forward()\n this.record(entry)\n }\n\n push(entry: UndoEntry): void {\n this.record(entry)\n }\n\n record(entry: UndoEntry): void {\n const batch = this.currentBatch\n if (batch) {\n batch.entries.push(entry)\n return\n }\n this.pushUndoEntry(entry)\n }\n\n /**\n * Records an entry as a step of its own, outside the batches being built, such as an agent's\n * edit made while a colour picker is open. Batches settle first, so the step follows the\n * changes they hold so far.\n */\n pushStep(entry: UndoEntry): void {\n this.settle()\n this.pushUndoEntry(entry)\n }\n\n /**\n * Registers a hook that commits an edit still being coalesced, such as a run of picker changes.\n * Undo and redo run every hook first, so they act on the newest change.\n */\n onBeforeHistory(settle: () => void): () => void {\n this.settlers.add(settle)\n return () => this.settlers.delete(settle)\n }\n\n private settle() {\n for (const settle of this.settlers) settle()\n }\n\n undo(): string | null {\n this.settle()\n const entry = this.undoStack.pop()\n if (!entry) return null\n this.replay(() => entry.inverse())\n this.redoStack.push(entry)\n this.onChange?.('undo')\n return entry.label\n }\n\n redo(): string | null {\n this.settle()\n const entry = this.redoStack.pop()\n if (!entry) return null\n this.replay(() => entry.forward())\n this.undoStack.push(entry)\n this.onChange?.('redo')\n return entry.label\n }\n\n beginBatch(label: string, coalesceKey?: string): void {\n this.batches.push({ label, entries: [], coalesceKey })\n }\n\n commitBatch(): void {\n const batch = this.batches.pop()\n if (!batch || batch.entries.length === 0) return\n\n const entry = this.createBatchEntry(batch)\n const parentBatch = this.currentBatch\n if (parentBatch) parentBatch.entries.push(entry)\n else this.pushUndoEntry(entry)\n }\n\n runBatch<T>(label: string, fn: () => T, coalesceKey?: string): T {\n this.beginBatch(label, coalesceKey)\n try {\n const result = fn()\n this.commitBatch()\n return result\n } catch (error) {\n this.rollbackBatch()\n throw error\n }\n }\n\n rollbackBatch(): void {\n const batch = this.batches.at(-1)\n if (!batch) return\n // Still open while it rolls back, so what the rollback changes belongs to the batch.\n try {\n for (const entry of batch.entries.toReversed()) entry.inverse()\n } finally {\n this.batches.pop()\n }\n this.onDiscard?.()\n }\n\n /**\n * Reports an edit that ended without a step, rolled back or changing nothing, as a rolled-back\n * batch does. Called once the edit has closed, so `isRecording` tells whether another is open.\n */\n discardEdit(): void {\n this.onDiscard?.()\n }\n\n /** Abandon provisional history without replaying it or changing committed undo/redo entries. */\n discardBatches(): void {\n this.batches = []\n }\n\n clear(): void {\n this.undoStack = []\n this.redoStack = []\n this.discardBatches()\n this.onChange?.('clear')\n }\n\n /** Whether undo or redo is replaying a step, whose changes are history rather than new edits. */\n get isReplaying(): boolean {\n return this.replaying > 0\n }\n\n /**\n * Adds a change that the newest step caused, as one an editor makes in response to it, so undo\n * and redo apply them together. Inside a batch it joins the batch. False with no step to join.\n */\n extendLastStep(entry: UndoEntry): boolean {\n if (this.currentBatch) {\n this.currentBatch.entries.push(entry)\n return true\n }\n const last = this.undoStack.at(-1)\n if (!last) return false\n // The step keeps its identity, so callers that hold it still find it in the history.\n const { forward, inverse } = last\n last.forward = () => {\n forward()\n entry.forward()\n }\n last.inverse = () => {\n entry.inverse()\n inverse()\n }\n this.onChange?.('join', last)\n return true\n }\n\n private replay(step: () => void) {\n this.replaying++\n try {\n this.runReplay(step)\n } finally {\n this.replaying--\n }\n }\n\n get isBatching(): boolean {\n return this.batches.length > 0\n }\n\n /**\n * Marks an edit whose step is recorded when it ends, such as an agent's call that awaits fonts\n * or a layout before it finishes. Returns the function that ends it; ending it twice is a no-op.\n */\n openEdit(): () => void {\n this.openEdits++\n let open = true\n return () => {\n if (!open) return\n open = false\n this.openEdits--\n }\n }\n\n /**\n * Whether a batch or an edit opened with `openEdit` will record a step for the changes made now,\n * so they are not edits outside the history.\n */\n get isRecording(): boolean {\n return this.isBatching || this.openEdits > 0\n }\n\n /** Committed history, or changes in an open batch that a settling hook commits first. */\n get canUndo(): boolean {\n if (this.undoStack.length > 0) return true\n return this.settlers.size > 0 && this.batches.some((batch) => batch.entries.length > 0)\n }\n\n get canRedo(): boolean {\n return this.redoStack.length > 0\n }\n\n /**\n * The entry `depth` steps below the top of the undo stack, so a caller that pushed entries\n * can tell whether they are still the most recent ones.\n */\n peekUndo(depth = 0): UndoEntry | undefined {\n return this.undoStack.at(-1 - depth)\n }\n\n /** The entry `depth` steps below the top of the redo stack, the next one Redo applies at 0. */\n peekRedo(depth = 0): UndoEntry | undefined {\n return this.redoStack.at(-1 - depth)\n }\n\n /**\n * Whether `entry` is applied (on the undo stack) or undone (on the redo stack); null once it\n * left the history, trimmed or dropped when an edit cleared Redo.\n */\n stateOf(entry: UndoEntry): 'applied' | 'undone' | null {\n if (this.undoStack.includes(entry)) return 'applied'\n if (this.redoStack.includes(entry)) return 'undone'\n return null\n }\n\n get undoLabel(): string | null {\n return this.undoStack.at(-1)?.label ?? null\n }\n\n get redoLabel(): string | null {\n return this.redoStack.at(-1)?.label ?? null\n }\n\n private get currentBatch(): UndoBatch | null {\n return this.batches.at(-1) ?? null\n }\n\n private createBatchEntry(batch: UndoBatch): UndoEntry {\n return {\n label: batch.label,\n forward: () => batch.entries.forEach((entry) => entry.forward()),\n inverse: () => batch.entries.toReversed().forEach((entry) => entry.inverse()),\n coalesceKey: batch.coalesceKey\n }\n }\n\n private pushUndoEntry(entry: UndoEntry): void {\n const previous = this.undoStack.at(-1)\n if (entry.coalesceKey && previous?.coalesceKey === entry.coalesceKey) {\n this.undoStack[this.undoStack.length - 1] = {\n ...entry,\n inverse: previous.inverse\n }\n } else {\n this.undoStack.push(entry)\n }\n this.redoStack = []\n this.trimUndoStack()\n this.onChange?.('record', this.undoStack.at(-1))\n }\n\n private trimUndoStack(): void {\n if (!Number.isFinite(this.limit) || this.limit <= 0) return\n const overflow = this.undoStack.length - this.limit\n if (overflow > 0) this.undoStack.splice(0, overflow)\n }\n}\n"],"mappings":";;AAuCA,MAAa,wBAAwB;AAErC,IAAa,cAAb,MAAyB;CACvB,YAAiC,CAAC;CAClC,YAAiC,CAAC;CAClC,UAA+B,CAAC;CAChC,YAAoB;CACpB,YAAoB;CACpB,2BAA4B,IAAI,IAAgB;CAChD;CACA;CACA;CACA;CAEA,YAAY,UAA8B,CAAC,GAAG;EAC5C,KAAK,QAAQ,QAAQ,SAAA;EACrB,KAAK,WAAW,QAAQ;EACxB,KAAK,YAAY,QAAQ;EACzB,KAAK,YAAY,QAAQ,eAAe,WAAW,OAAO;CAC5D;CAEA,MAAM,OAAwB;EAC5B,KAAK,QAAQ,KAAK;CACpB;CAEA,QAAQ,OAAwB;EAC9B,MAAM,QAAQ;EACd,KAAK,OAAO,KAAK;CACnB;CAEA,KAAK,OAAwB;EAC3B,KAAK,OAAO,KAAK;CACnB;CAEA,OAAO,OAAwB;EAC7B,MAAM,QAAQ,KAAK;EACnB,IAAI,OAAO;GACT,MAAM,QAAQ,KAAK,KAAK;GACxB;EACF;EACA,KAAK,cAAc,KAAK;CAC1B;;;;;;CAOA,SAAS,OAAwB;EAC/B,KAAK,OAAO;EACZ,KAAK,cAAc,KAAK;CAC1B;;;;;CAMA,gBAAgB,QAAgC;EAC9C,KAAK,SAAS,IAAI,MAAM;EACxB,aAAa,KAAK,SAAS,OAAO,MAAM;CAC1C;CAEA,SAAiB;EACf,KAAK,MAAM,UAAU,KAAK,UAAU,OAAO;CAC7C;CAEA,OAAsB;EACpB,KAAK,OAAO;EACZ,MAAM,QAAQ,KAAK,UAAU,IAAI;EACjC,IAAI,CAAC,OAAO,OAAO;EACnB,KAAK,aAAa,MAAM,QAAQ,CAAC;EACjC,KAAK,UAAU,KAAK,KAA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;CAEA,IAAI,YAA2B;EAC7B,OAAO,KAAK,UAAU,GAAG,EAAE,CAAC,EAAE,SAAS;CACzC;CAEA,IAAI,YAA2B;EAC7B,OAAO,KAAK,UAAU,GAAG,EAAE,CAAC,EAAE,SAAS;CACzC;CAEA,IAAY,eAAiC;EAC3C,OAAO,KAAK,QAAQ,GAAG,EAAE,KAAK;CAChC;CAEA,iBAAyB,OAA6B;EACpD,OAAO;GACL,OAAO,MAAM;GACb,eAAe,MAAM,QAAQ,SAAS,UAAU,MAAM,QAAQ,CAAC;GAC/D,eAAe,MAAM,QAAQ,WAAW,CAAC,CAAC,SAAS,UAAU,MAAM,QAAQ,CAAC;GAC5E,aAAa,MAAM;EACrB;CACF;CAEA,cAAsB,OAAwB;EAC5C,MAAM,WAAW,KAAK,UAAU,GAAG,EAAE;EACrC,IAAI,MAAM,eAAe,UAAU,gBAAgB,MAAM,aACvD,KAAK,UAAU,KAAK,UAAU,SAAS,KAAK;GAC1C,GAAG;GACH,SAAS,SAAS;EACpB;OAEA,KAAK,UAAU,KAAK,KAAK;EAE3B,KAAK,YAAY,CAAC;EAClB,KAAK,cAAc;EACnB,KAAK,WAAW,UAAU,KAAK,UAAU,GAAG,EAAE,CAAC;CACjD;CAEA,gBAA8B;EAC5B,IAAI,CAAC,OAAO,SAAS,KAAK,KAAK,KAAK,KAAK,SAAS,GAAG;EACrD,MAAM,WAAW,KAAK,UAAU,SAAS,KAAK;EAC9C,IAAI,WAAW,GAAG,KAAK,UAAU,OAAO,GAAG,QAAQ;CACrD;AACF"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { VariableModeFallback } from "./resolution.js";
|
|
2
|
-
import { EFFECT_BINDING_PROPERTIES, EffectBindingProperty, PaintBindingList, TEXT_CONTENT_VARIABLE_TYPES, VISIBILITY_VARIABLE_TYPES, effectBindableProperties, effectBindingField, effectBindingTarget, effectBindingVariableType, isNumericVariableBindingField, paintBindingTarget } from "./fields.js";
|
|
3
1
|
import { SceneGraph } from "../graph.js";
|
|
4
2
|
import { SceneNode, TextLength } from "../types.js";
|
|
3
|
+
import { EFFECT_BINDING_PROPERTIES, EffectBindingProperty, PaintBindingList, TEXT_CONTENT_VARIABLE_TYPES, VISIBILITY_VARIABLE_TYPES, effectBindableProperties, effectBindingField, effectBindingTarget, effectBindingVariableType, isNumericVariableBindingField, paintBindingTarget } from "./fields.js";
|
|
5
4
|
//#region src/variables/bindings.d.ts
|
|
6
5
|
/** New declarations belong to the outermost occurrence, bounded by a component definition. */
|
|
7
6
|
declare function variableBindingOwner(graph: SceneGraph, node: SceneNode): SceneNode;
|
|
@@ -12,7 +11,7 @@ declare function boundNumberValue(field: string, value: number): number | TextLe
|
|
|
12
11
|
* The values a node's numeric bindings resolve to in its mode, in scene units, for the fields
|
|
13
12
|
* whose stored value differs. A width or height an instance overrides keeps its own value.
|
|
14
13
|
*/
|
|
15
|
-
declare function resolvedNumericBindings(graph: SceneGraph, node: SceneNode
|
|
14
|
+
declare function resolvedNumericBindings(graph: SceneGraph, node: SceneNode): Partial<SceneNode>;
|
|
16
15
|
/**
|
|
17
16
|
* The text and visibility a node's string and boolean bindings resolve to in its mode, for the
|
|
18
17
|
* fields whose stored value differs. Text or visibility an instance overrides, which typing in a
|
|
@@ -20,14 +19,12 @@ declare function resolvedNumericBindings(graph: SceneGraph, node: SceneNode, fal
|
|
|
20
19
|
* A bound font family is left as stored: changing it needs the font loaded, which resolving a
|
|
21
20
|
* binding cannot do.
|
|
22
21
|
*/
|
|
23
|
-
declare function resolvedValueBindings(graph: SceneGraph, node: SceneNode
|
|
22
|
+
declare function resolvedValueBindings(graph: SceneGraph, node: SceneNode): Partial<SceneNode>;
|
|
24
23
|
/**
|
|
25
24
|
* The runs a text's character bindings resolve to in its mode, when a bound number differs from
|
|
26
25
|
* what its characters hold. Bound font families and styles are left as stored, as the text's own.
|
|
27
26
|
*/
|
|
28
|
-
declare function resolvedRunBindings(graph: SceneGraph, node: SceneNode
|
|
29
|
-
/** The fills and strokes a node's color bindings resolve to in its mode, when it has any. */
|
|
30
|
-
declare function resolvedPaintBindings(graph: SceneGraph, node: SceneNode, fallback?: VariableModeFallback): Pick<Partial<SceneNode>, 'fills' | 'strokes'>;
|
|
27
|
+
declare function resolvedRunBindings(graph: SceneGraph, node: SceneNode): Pick<Partial<SceneNode>, 'styleRuns'>;
|
|
31
28
|
/**
|
|
32
29
|
* The effects a node's effect bindings resolve to in its mode, when one differs from what the node
|
|
33
30
|
* holds. Lengths stay as the variables give them, negative ones included, as Figma keeps them;
|
|
@@ -35,7 +32,7 @@ declare function resolvedPaintBindings(graph: SceneGraph, node: SceneNode, fallb
|
|
|
35
32
|
* component, whenever they were bound, as Figma scales them; a layer scaled outside an instance
|
|
36
33
|
* goes back to the variable's own value.
|
|
37
34
|
*/
|
|
38
|
-
declare function resolvedEffectBindings(graph: SceneGraph, node: SceneNode
|
|
35
|
+
declare function resolvedEffectBindings(graph: SceneGraph, node: SceneNode): Pick<Partial<SceneNode>, 'effects'>;
|
|
39
36
|
/**
|
|
40
37
|
* The layers a reconcile looks at: those bound to these variables, directly or through a variable
|
|
41
38
|
* aliasing them, or the layers in these subtrees. Without a scope, every layer.
|
|
@@ -58,16 +55,22 @@ declare function collectionsBoundIn(graph: SceneGraph, roots: Iterable<string>):
|
|
|
58
55
|
*/
|
|
59
56
|
declare function layersUsingVariables(graph: SceneGraph, ids: Iterable<string>): SceneNode[];
|
|
60
57
|
/**
|
|
61
|
-
*
|
|
58
|
+
* The layers in these subtrees that resolve a variable of these collections, binding it or a
|
|
59
|
+
* variable that aliases it, so a mode change for the collections can change what they show.
|
|
60
|
+
*/
|
|
61
|
+
declare function layersResolvingCollections(graph: SceneGraph, roots: Iterable<string>, collectionIds: ReadonlySet<string>): SceneNode[];
|
|
62
|
+
/**
|
|
63
|
+
* Resolve live numeric, text, visibility, and effect bindings, numbers in scene units, and refresh
|
|
64
|
+
* bound paints whose variable's color for the layer changed (`refreshBoundPaints`), without
|
|
62
65
|
* authoring instance overrides. A scope limits it to the layers a change can reach, so layers whose
|
|
63
66
|
* saved values differ from their bindings elsewhere in the document are left as saved. Returns the
|
|
64
|
-
* layers whose change needs a layout pass; effects are not a layout input, so
|
|
65
|
-
* is written but not returned.
|
|
67
|
+
* layers whose change needs a layout pass; effects and paints are not a layout input, so a change
|
|
68
|
+
* to them alone is written but not returned.
|
|
66
69
|
*/
|
|
67
70
|
declare function reconcileVariableBindings(graph: SceneGraph, scope?: BindingScope): string[];
|
|
68
71
|
/**
|
|
69
|
-
* As `reconcileVariableBindings`, with the layout fields each relaid layer received. Effects
|
|
70
|
-
* are written too, but draw without layout, so a layer whose only change is
|
|
72
|
+
* As `reconcileVariableBindings`, with the layout fields each relaid layer received. Effects and
|
|
73
|
+
* paints are written too, but draw without layout, so a layer whose only change is one is left out.
|
|
71
74
|
*/
|
|
72
75
|
declare function reconcileVariableBindingUpdates(graph: SceneGraph, scope?: BindingScope): Map<string, Partial<SceneNode>>;
|
|
73
76
|
/** A layer list whose items carry their own bindings, keyed by position such as `fills/1/color`. */
|
|
@@ -79,5 +82,5 @@ type BoundLayerList = 'fills' | 'strokes' | 'effects';
|
|
|
79
82
|
*/
|
|
80
83
|
declare function listBindingsAfterEdit(boundVariables: Readonly<Record<string, string>>, list: BoundLayerList, sources: readonly (number | null)[]): Record<string, string>;
|
|
81
84
|
//#endregion
|
|
82
|
-
export { BindingScope, BoundLayerList, EFFECT_BINDING_PROPERTIES, type EffectBindingProperty, type PaintBindingList, TEXT_CONTENT_VARIABLE_TYPES, VISIBILITY_VARIABLE_TYPES, assignVariableBindingUnits, boundNumberValue, collectionsBoundIn, effectBindableProperties, effectBindingField, effectBindingTarget, effectBindingVariableType, isNumericVariableBindingField, layersUsingVariables, listBindingsAfterEdit, paintBindingTarget, reconcileVariableBindingUpdates, reconcileVariableBindings, resolvedEffectBindings, resolvedNumericBindings,
|
|
85
|
+
export { BindingScope, BoundLayerList, EFFECT_BINDING_PROPERTIES, type EffectBindingProperty, type PaintBindingList, TEXT_CONTENT_VARIABLE_TYPES, VISIBILITY_VARIABLE_TYPES, assignVariableBindingUnits, boundNumberValue, collectionsBoundIn, effectBindableProperties, effectBindingField, effectBindingTarget, effectBindingVariableType, isNumericVariableBindingField, layersResolvingCollections, layersUsingVariables, listBindingsAfterEdit, paintBindingTarget, reconcileVariableBindingUpdates, reconcileVariableBindings, resolvedEffectBindings, resolvedNumericBindings, resolvedRunBindings, resolvedValueBindings, variableBindingOwner, variablesResolvingThrough };
|
|
83
86
|
//# sourceMappingURL=bindings.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bindings.d.ts","names":[],"sources":["../../src/variables/bindings.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"bindings.d.ts","names":[],"sources":["../../src/variables/bindings.ts"],"mappings":";;;;;iBAkCgB,qBAAqB,OAAO,YAAY,MAAM,YAAY;iBAW1D,2BACd,OAAO,YACP,MAAM,WACN;;iBAoBc,iBAAiB,eAAe,yBAAyB;;;;;iBAQzD,wBAAwB,OAAO,YAAY,MAAM,YAAY,QAAQ;;;;;;;;iBA2BrE,sBAAsB,OAAO,YAAY,MAAM,YAAY,QAAQ;;;;;iBAsBnE,oBACd,OAAO,YACP,MAAM,YACL,KAAK,QAAQ;;;;;;;;iBAqDA,uBACd,OAAO,YACP,MAAM,YACL,KAAK,QAAQ;;;;;KAyBJ;EAAiB,WAAW;;EAAuB,UAAU;;;iBAGzD,0BAA0B,OAAO,YAAY,KAAK,mBAAmB;;;;;iBAuBrE,mBAAmB,OAAO,YAAY,OAAO,mBAAmB;;;;;iBAQhE,qBAAqB,OAAO,YAAY,KAAK,mBAAmB;;;;;iBAWhE,2BACd,OAAO,YACP,OAAO,kBACP,eAAe,sBACd;;;;;;;;;iBA2Ba,0BAA0B,OAAO,YAAY,QAAQ;;;;;iBAQrD,gCACd,OAAO,YACP,QAAQ,eACP,YAAY,QAAQ;;KAmBX;;;;;;iBAOI,sBACd,gBAAgB,SAAS,yBACzB,MAAM,gBACN,sCACC"}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { EFFECT_BINDING_PROPERTIES, NUMERIC_FIELDS, TEXT_CONTENT_VARIABLE_TYPES, VISIBILITY_VARIABLE_TYPES, effectBindableProperties, effectBindingField, effectBindingTarget, effectBindingVariableType, isNumericVariableBindingField, paintBindingTarget } from "./fields.js";
|
|
2
2
|
import { hasInstanceOverride } from "../instances/overrides.js";
|
|
3
3
|
import { pixelLength } from "../text/lengths.js";
|
|
4
|
-
import { copyFills, copyStrokes } from "../copy.js";
|
|
5
4
|
import { variableText, variableTruthy } from "./text.js";
|
|
6
5
|
import { variableValueReferences } from "./value.js";
|
|
6
|
+
import { collectionsResolving } from "./resolution.js";
|
|
7
|
+
import { subtreeNodes } from "./subtree.js";
|
|
8
|
+
import { refreshBoundPaints } from "./paints.js";
|
|
7
9
|
import { isEmptyObject, isEqual } from "es-toolkit/predicate";
|
|
8
10
|
//#region src/variables/bindings.ts
|
|
9
11
|
/** New declarations belong to the outermost occurrence, bounded by a component definition. */
|
|
@@ -40,12 +42,12 @@ function boundNumberValue(field, value) {
|
|
|
40
42
|
* The values a node's numeric bindings resolve to in its mode, in scene units, for the fields
|
|
41
43
|
* whose stored value differs. A width or height an instance overrides keeps its own value.
|
|
42
44
|
*/
|
|
43
|
-
function resolvedNumericBindings(graph, node
|
|
45
|
+
function resolvedNumericBindings(graph, node) {
|
|
44
46
|
const updates = {};
|
|
45
47
|
for (const [field, variableId] of Object.entries(node.boundVariables)) {
|
|
46
48
|
if (!NUMERIC_FIELDS.has(field)) continue;
|
|
47
49
|
if ((field === "width" || field === "height") && overriddenInInstance(graph, node.id, field)) continue;
|
|
48
|
-
const value = graph.resolveNumberVariableForNode(node.id, variableId
|
|
50
|
+
const value = graph.resolveNumberVariableForNode(node.id, variableId);
|
|
49
51
|
if (value === void 0 || !Number.isFinite(value)) continue;
|
|
50
52
|
const effective = value * (node.variableBindingScales[field] ?? 1);
|
|
51
53
|
if (!Number.isFinite(effective)) continue;
|
|
@@ -61,12 +63,12 @@ function resolvedNumericBindings(graph, node, fallback = "active") {
|
|
|
61
63
|
* A bound font family is left as stored: changing it needs the font loaded, which resolving a
|
|
62
64
|
* binding cannot do.
|
|
63
65
|
*/
|
|
64
|
-
function resolvedValueBindings(graph, node
|
|
66
|
+
function resolvedValueBindings(graph, node) {
|
|
65
67
|
const updates = {};
|
|
66
68
|
const resolve = (field) => {
|
|
67
69
|
const variableId = node.boundVariables[field];
|
|
68
70
|
if (!variableId || overriddenInInstance(graph, node.id, field)) return void 0;
|
|
69
|
-
return graph.resolveVariableForNode(node.id, variableId
|
|
71
|
+
return graph.resolveVariableForNode(node.id, variableId);
|
|
70
72
|
};
|
|
71
73
|
const text = node.type === "TEXT" ? variableText(resolve("text")) : void 0;
|
|
72
74
|
if (text !== void 0 && text !== node.text) updates.text = text;
|
|
@@ -85,7 +87,7 @@ const NUMERIC_RUN_FIELDS = [
|
|
|
85
87
|
* The runs a text's character bindings resolve to in its mode, when a bound number differs from
|
|
86
88
|
* what its characters hold. Bound font families and styles are left as stored, as the text's own.
|
|
87
89
|
*/
|
|
88
|
-
function resolvedRunBindings(graph, node
|
|
90
|
+
function resolvedRunBindings(graph, node) {
|
|
89
91
|
const styleRuns = node.styleRuns.map((run) => {
|
|
90
92
|
const bound = run.style.boundVariables;
|
|
91
93
|
if (!bound) return run;
|
|
@@ -93,7 +95,7 @@ function resolvedRunBindings(graph, node, fallback = "active") {
|
|
|
93
95
|
for (const field of NUMERIC_RUN_FIELDS) {
|
|
94
96
|
const variableId = bound[field];
|
|
95
97
|
if (!variableId) continue;
|
|
96
|
-
const value = graph.resolveNumberVariableForNode(node.id, variableId
|
|
98
|
+
const value = graph.resolveNumberVariableForNode(node.id, variableId);
|
|
97
99
|
if (value === void 0 || !Number.isFinite(value)) continue;
|
|
98
100
|
const next = boundNumberValue(field, value);
|
|
99
101
|
if (isEqual(style[field], next)) continue;
|
|
@@ -113,39 +115,6 @@ function resolvedRunBindings(graph, node, fallback = "active") {
|
|
|
113
115
|
function boundVariableIds(node) {
|
|
114
116
|
return [...Object.values(node.boundVariables), ...node.styleRuns.flatMap((run) => Object.values(run.style.boundVariables ?? {}))].filter((id) => typeof id === "string");
|
|
115
117
|
}
|
|
116
|
-
/**
|
|
117
|
-
* A bound paint takes its whole color from the variable, alpha included, the way Figma stores
|
|
118
|
-
* it: the variable's RGB at full alpha, and its alpha as the paint's opacity.
|
|
119
|
-
*/
|
|
120
|
-
function applyBoundColor(paint, color) {
|
|
121
|
-
paint.color = {
|
|
122
|
-
...color,
|
|
123
|
-
a: 1
|
|
124
|
-
};
|
|
125
|
-
paint.opacity = color.a;
|
|
126
|
-
}
|
|
127
|
-
/** The fills and strokes a node's color bindings resolve to in its mode, when it has any. */
|
|
128
|
-
function resolvedPaintBindings(graph, node, fallback = "active") {
|
|
129
|
-
const changes = {};
|
|
130
|
-
for (const field in node.boundVariables) {
|
|
131
|
-
if (!field.endsWith("/color")) continue;
|
|
132
|
-
const paint = paintBindingTarget(field);
|
|
133
|
-
if (!paint) continue;
|
|
134
|
-
const color = graph.resolveColorVariableForNode(node.id, node.boundVariables[field], fallback);
|
|
135
|
-
const { index } = paint;
|
|
136
|
-
if (!color) continue;
|
|
137
|
-
if (paint.list === "fills") {
|
|
138
|
-
if (!node.fills[index]) continue;
|
|
139
|
-
changes.fills ??= copyFills(node.fills);
|
|
140
|
-
applyBoundColor(changes.fills[index], color);
|
|
141
|
-
} else {
|
|
142
|
-
if (!node.strokes[index]) continue;
|
|
143
|
-
changes.strokes ??= copyStrokes(node.strokes);
|
|
144
|
-
applyBoundColor(changes.strokes[index], color);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
return changes;
|
|
148
|
-
}
|
|
149
118
|
/** `effect` with one bound property set to its variable's value; a colour keeps its alpha. */
|
|
150
119
|
function withBoundEffectValue(effect, property, value) {
|
|
151
120
|
if (typeof value !== "number") return property === "color" ? {
|
|
@@ -183,14 +152,14 @@ function scaledLength(length, node) {
|
|
|
183
152
|
* component, whenever they were bound, as Figma scales them; a layer scaled outside an instance
|
|
184
153
|
* goes back to the variable's own value.
|
|
185
154
|
*/
|
|
186
|
-
function resolvedEffectBindings(graph, node
|
|
155
|
+
function resolvedEffectBindings(graph, node) {
|
|
187
156
|
let effects;
|
|
188
157
|
for (const [field, variableId] of Object.entries(node.boundVariables)) {
|
|
189
158
|
const target = effectBindingTarget(field);
|
|
190
159
|
if (!target) continue;
|
|
191
160
|
const effect = (effects ?? node.effects).at(target.index);
|
|
192
161
|
if (!effect || !effectBindableProperties(effect.type).includes(target.property)) continue;
|
|
193
|
-
const value = target.property === "color" ? graph.resolveColorVariableForNode(node.id, variableId
|
|
162
|
+
const value = target.property === "color" ? graph.resolveColorVariableForNode(node.id, variableId) : scaledLength(graph.resolveNumberVariableForNode(node.id, variableId), node);
|
|
194
163
|
if (value == null || typeof value === "number" && !Number.isFinite(value)) continue;
|
|
195
164
|
const next = withBoundEffectValue(effect, target.property, value);
|
|
196
165
|
if (isEqual(next, effect)) continue;
|
|
@@ -215,34 +184,12 @@ function variablesResolvingThrough(graph, ids) {
|
|
|
215
184
|
}
|
|
216
185
|
return found;
|
|
217
186
|
}
|
|
218
|
-
function subtreeNodes(graph, roots) {
|
|
219
|
-
const nodes = [];
|
|
220
|
-
const pending = [...roots];
|
|
221
|
-
for (let id = pending.pop(); id !== void 0; id = pending.pop()) {
|
|
222
|
-
const node = graph.getNode(id);
|
|
223
|
-
if (!node) continue;
|
|
224
|
-
nodes.push(node);
|
|
225
|
-
pending.push(...node.childIds);
|
|
226
|
-
}
|
|
227
|
-
return nodes;
|
|
228
|
-
}
|
|
229
187
|
/**
|
|
230
188
|
* The collections whose variables the layers in these subtrees resolve: those they bind, and
|
|
231
189
|
* those the bound variables alias, so a mode set on the subtrees can change what they show.
|
|
232
190
|
*/
|
|
233
191
|
function collectionsBoundIn(graph, roots) {
|
|
234
|
-
|
|
235
|
-
const seen = /* @__PURE__ */ new Set();
|
|
236
|
-
const collections = /* @__PURE__ */ new Set();
|
|
237
|
-
for (let id = pending.pop(); id !== void 0; id = pending.pop()) {
|
|
238
|
-
if (seen.has(id)) continue;
|
|
239
|
-
seen.add(id);
|
|
240
|
-
const variable = graph.variables.get(id);
|
|
241
|
-
if (!variable) continue;
|
|
242
|
-
collections.add(variable.collectionId);
|
|
243
|
-
for (const value of Object.values(variable.valuesByMode)) pending.push(...variableValueReferences(value));
|
|
244
|
-
}
|
|
245
|
-
return collections;
|
|
192
|
+
return collectionsResolving(graph, subtreeNodes(graph, roots).flatMap(boundVariableIds));
|
|
246
193
|
}
|
|
247
194
|
/**
|
|
248
195
|
* The layers a change to these variables reaches: those binding one of them, or a variable that
|
|
@@ -252,28 +199,39 @@ function layersUsingVariables(graph, ids) {
|
|
|
252
199
|
const variables = variablesResolvingThrough(graph, ids);
|
|
253
200
|
return [...graph.getAllNodes()].filter((node) => boundVariableIds(node).some((id) => variables.has(id)));
|
|
254
201
|
}
|
|
202
|
+
/**
|
|
203
|
+
* The layers in these subtrees that resolve a variable of these collections, binding it or a
|
|
204
|
+
* variable that aliases it, so a mode change for the collections can change what they show.
|
|
205
|
+
*/
|
|
206
|
+
function layersResolvingCollections(graph, roots, collectionIds) {
|
|
207
|
+
const variables = variablesResolvingThrough(graph, [...graph.variables.values()].filter((variable) => collectionIds.has(variable.collectionId)).map((variable) => variable.id));
|
|
208
|
+
return subtreeNodes(graph, roots).filter((node) => boundVariableIds(node).some((id) => variables.has(id)));
|
|
209
|
+
}
|
|
255
210
|
function scopedNodes(graph, scope) {
|
|
256
211
|
if (!scope) return graph.getAllNodes();
|
|
257
212
|
if ("subtrees" in scope) return subtreeNodes(graph, scope.subtrees);
|
|
258
213
|
return layersUsingVariables(graph, scope.variables);
|
|
259
214
|
}
|
|
260
215
|
/**
|
|
261
|
-
* Resolve live numeric, text, visibility, and effect bindings, numbers in scene units,
|
|
216
|
+
* Resolve live numeric, text, visibility, and effect bindings, numbers in scene units, and refresh
|
|
217
|
+
* bound paints whose variable's color for the layer changed (`refreshBoundPaints`), without
|
|
262
218
|
* authoring instance overrides. A scope limits it to the layers a change can reach, so layers whose
|
|
263
219
|
* saved values differ from their bindings elsewhere in the document are left as saved. Returns the
|
|
264
|
-
* layers whose change needs a layout pass; effects are not a layout input, so
|
|
265
|
-
* is written but not returned.
|
|
220
|
+
* layers whose change needs a layout pass; effects and paints are not a layout input, so a change
|
|
221
|
+
* to them alone is written but not returned.
|
|
266
222
|
*/
|
|
267
223
|
function reconcileVariableBindings(graph, scope) {
|
|
268
224
|
return [...reconcileVariableBindingUpdates(graph, scope).keys()];
|
|
269
225
|
}
|
|
270
226
|
/**
|
|
271
|
-
* As `reconcileVariableBindings`, with the layout fields each relaid layer received. Effects
|
|
272
|
-
* are written too, but draw without layout, so a layer whose only change is
|
|
227
|
+
* As `reconcileVariableBindings`, with the layout fields each relaid layer received. Effects and
|
|
228
|
+
* paints are written too, but draw without layout, so a layer whose only change is one is left out.
|
|
273
229
|
*/
|
|
274
230
|
function reconcileVariableBindingUpdates(graph, scope) {
|
|
275
231
|
const relaid = /* @__PURE__ */ new Map();
|
|
276
|
-
|
|
232
|
+
const nodes = [...scopedNodes(graph, scope)];
|
|
233
|
+
for (const node of nodes) refreshBoundPaints(graph, node);
|
|
234
|
+
for (const node of nodes) {
|
|
277
235
|
const layoutUpdates = {
|
|
278
236
|
...resolvedNumericBindings(graph, node),
|
|
279
237
|
...resolvedValueBindings(graph, node),
|
|
@@ -309,6 +267,6 @@ function listBindingsAfterEdit(boundVariables, list, sources) {
|
|
|
309
267
|
return moved;
|
|
310
268
|
}
|
|
311
269
|
//#endregion
|
|
312
|
-
export { EFFECT_BINDING_PROPERTIES, TEXT_CONTENT_VARIABLE_TYPES, VISIBILITY_VARIABLE_TYPES, assignVariableBindingUnits, boundNumberValue, collectionsBoundIn, effectBindableProperties, effectBindingField, effectBindingTarget, effectBindingVariableType, isNumericVariableBindingField, layersUsingVariables, listBindingsAfterEdit, paintBindingTarget, reconcileVariableBindingUpdates, reconcileVariableBindings, resolvedEffectBindings, resolvedNumericBindings,
|
|
270
|
+
export { EFFECT_BINDING_PROPERTIES, TEXT_CONTENT_VARIABLE_TYPES, VISIBILITY_VARIABLE_TYPES, assignVariableBindingUnits, boundNumberValue, collectionsBoundIn, effectBindableProperties, effectBindingField, effectBindingTarget, effectBindingVariableType, isNumericVariableBindingField, layersResolvingCollections, layersUsingVariables, listBindingsAfterEdit, paintBindingTarget, reconcileVariableBindingUpdates, reconcileVariableBindings, resolvedEffectBindings, resolvedNumericBindings, resolvedRunBindings, resolvedValueBindings, variableBindingOwner, variablesResolvingThrough };
|
|
313
271
|
|
|
314
272
|
//# sourceMappingURL=bindings.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bindings.js","names":[],"sources":["../../src/variables/bindings.ts"],"sourcesContent":["import { isEmptyObject, isEqual } from 'es-toolkit/predicate'\n\nimport type { VariableModeFallback } from '.'\nimport { copyFills, copyStrokes } from '../copy'\nimport type { SceneGraph } from '../graph'\nimport { hasInstanceOverride } from '../instances/overrides'\nimport type { Color } from '../primitives'\nimport { pixelLength } from '../text/lengths'\nimport type { Effect, Fill, SceneNode, Stroke, StyleRun, TextLength } from '../types'\nimport {\n effectBindableProperties,\n effectBindingTarget,\n NUMERIC_FIELDS,\n isNumericVariableBindingField,\n paintBindingTarget,\n type EffectBindingProperty\n} from './fields'\nimport { variableText, variableTruthy } from './text'\nimport { variableValueReferences } from './value'\nexport {\n EFFECT_BINDING_PROPERTIES,\n effectBindableProperties,\n effectBindingField,\n effectBindingTarget,\n effectBindingVariableType,\n isNumericVariableBindingField,\n paintBindingTarget,\n type EffectBindingProperty,\n TEXT_CONTENT_VARIABLE_TYPES,\n VISIBILITY_VARIABLE_TYPES,\n type PaintBindingList\n} from './fields'\n\n/** New declarations belong to the outermost occurrence, bounded by a component definition. */\nexport function variableBindingOwner(graph: SceneGraph, node: SceneNode): SceneNode {\n let owner = node\n let current: SceneNode | undefined = node\n while (current) {\n if (current.type === 'COMPONENT' || current.type === 'COMPONENT_SET') break\n if (current.type === 'INSTANCE') owner = current\n current = current.parentId ? graph.getNode(current.parentId) : undefined\n }\n return owner\n}\n\nexport function assignVariableBindingUnits(\n graph: SceneGraph,\n node: SceneNode,\n field: string\n): void {\n if (!isNumericVariableBindingField(field)) return\n const owner = variableBindingOwner(graph, node)\n node.variableBindingScales = {\n ...node.variableBindingScales,\n [field]: owner.variableAssignmentScales[field] ?? 1\n }\n}\n\n/** Fields a bound number sets as a length in pixels, as Figma's do, whatever unit they held. */\nconst TEXT_LENGTH_FIELDS: ReadonlySet<string> = new Set(['lineHeight', 'letterSpacing'])\n\n/** Whether the instance a layer sits in, or the instance itself, overrides one of its fields. */\nfunction overriddenInInstance(graph: SceneGraph, nodeId: string, field: string): boolean {\n const instance = graph.closest(nodeId, (node) => node.type === 'INSTANCE')\n return !!instance && hasInstanceOverride(instance.instanceOverrides, instance.id, nodeId, field)\n}\n\n/** A bound number as the field stores it. */\nexport function boundNumberValue(field: string, value: number): number | TextLength {\n return TEXT_LENGTH_FIELDS.has(field) ? pixelLength(value) : value\n}\n\n/**\n * The values a node's numeric bindings resolve to in its mode, in scene units, for the fields\n * whose stored value differs. A width or height an instance overrides keeps its own value.\n */\nexport function resolvedNumericBindings(\n graph: SceneGraph,\n node: SceneNode,\n fallback: VariableModeFallback = 'active'\n): Partial<SceneNode> {\n const updates: Partial<SceneNode> = {}\n for (const [field, variableId] of Object.entries(node.boundVariables)) {\n if (!NUMERIC_FIELDS.has(field)) continue\n if ((field === 'width' || field === 'height') && overriddenInInstance(graph, node.id, field))\n continue\n const value = graph.resolveNumberVariableForNode(node.id, variableId, fallback)\n if (value === undefined || !Number.isFinite(value)) continue\n const scale = node.variableBindingScales[field] ?? 1\n const effective = value * scale\n if (!Number.isFinite(effective)) continue\n const next = boundNumberValue(\n field,\n field === 'opacity' ? Math.max(0, Math.min(1, effective)) : effective\n )\n if (!isEqual(node[field as keyof SceneNode], next)) Object.assign(updates, { [field]: next })\n }\n return updates\n}\n\n/**\n * The text and visibility a node's string and boolean bindings resolve to in its mode, for the\n * fields whose stored value differs. Text or visibility an instance overrides, which typing in a\n * layer or toggling its eye records, keeps its own value, as an overridden width or height does.\n * A bound font family is left as stored: changing it needs the font loaded, which resolving a\n * binding cannot do.\n */\nexport function resolvedValueBindings(\n graph: SceneGraph,\n node: SceneNode,\n fallback: VariableModeFallback = 'active'\n): Partial<SceneNode> {\n const updates: Partial<SceneNode> = {}\n const resolve = (field: 'text' | 'visible') => {\n const variableId = node.boundVariables[field]\n if (!variableId || overriddenInInstance(graph, node.id, field)) return undefined\n return graph.resolveVariableForNode(node.id, variableId, fallback)\n }\n const text = node.type === 'TEXT' ? variableText(resolve('text')) : undefined\n if (text !== undefined && text !== node.text) updates.text = text\n // Figma binds visibility to text too, and shows the layer when the text reads as true.\n const visible = variableTruthy(resolve('visible'))\n if (visible !== undefined && visible !== node.visible) updates.visible = visible\n return updates\n}\n\n/** Fields of a range of characters a bound number gives its value; the rest need fonts loaded. */\nconst NUMERIC_RUN_FIELDS = ['fontSize', 'fontWeight', 'letterSpacing', 'lineHeight'] as const\n\n/**\n * The runs a text's character bindings resolve to in its mode, when a bound number differs from\n * what its characters hold. Bound font families and styles are left as stored, as the text's own.\n */\nexport function resolvedRunBindings(\n graph: SceneGraph,\n node: SceneNode,\n fallback: VariableModeFallback = 'active'\n): Pick<Partial<SceneNode>, 'styleRuns'> {\n const styleRuns = node.styleRuns.map((run): StyleRun => {\n const bound = run.style.boundVariables\n if (!bound) return run\n let style = run.style\n for (const field of NUMERIC_RUN_FIELDS) {\n const variableId = bound[field]\n if (!variableId) continue\n const value = graph.resolveNumberVariableForNode(node.id, variableId, fallback)\n if (value === undefined || !Number.isFinite(value)) continue\n const next = boundNumberValue(field, value)\n if (isEqual(style[field], next)) continue\n style = { ...style, [field]: next }\n }\n return style === run.style ? run : { ...run, style }\n })\n const changed = styleRuns.some((run, index) => run !== node.styleRuns[index])\n return changed ? { styleRuns } : {}\n}\n\n/** The variables a node binds, its own and its characters'. */\nfunction boundVariableIds(node: SceneNode): string[] {\n return [\n ...Object.values(node.boundVariables),\n ...node.styleRuns.flatMap((run) => Object.values(run.style.boundVariables ?? {}))\n ].filter((id): id is string => typeof id === 'string')\n}\n\n/**\n * A bound paint takes its whole color from the variable, alpha included, the way Figma stores\n * it: the variable's RGB at full alpha, and its alpha as the paint's opacity.\n */\nfunction applyBoundColor(paint: Fill | Stroke, color: Color): void {\n paint.color = { ...color, a: 1 }\n paint.opacity = color.a\n}\n\n/** The fills and strokes a node's color bindings resolve to in its mode, when it has any. */\nexport function resolvedPaintBindings(\n graph: SceneGraph,\n node: SceneNode,\n fallback: VariableModeFallback = 'active'\n): Pick<Partial<SceneNode>, 'fills' | 'strokes'> {\n // Most nodes bind nothing, so no copy is made until a paint binding is actually found.\n const changes: Pick<Partial<SceneNode>, 'fills' | 'strokes'> = {}\n for (const field in node.boundVariables) {\n if (!field.endsWith('/color')) continue\n const paint = paintBindingTarget(field)\n if (!paint) continue\n const color = graph.resolveColorVariableForNode(node.id, node.boundVariables[field], fallback)\n const { index } = paint\n if (!color) continue\n if (paint.list === 'fills') {\n if (!node.fills[index]) continue\n changes.fills ??= copyFills(node.fills)\n applyBoundColor(changes.fills[index], color)\n } else {\n if (!node.strokes[index]) continue\n changes.strokes ??= copyStrokes(node.strokes)\n applyBoundColor(changes.strokes[index], color)\n }\n }\n return changes\n}\n\n/** `effect` with one bound property set to its variable's value; a colour keeps its alpha. */\nfunction withBoundEffectValue(\n effect: Effect,\n property: EffectBindingProperty,\n value: number | Color\n): Effect {\n if (typeof value !== 'number') return property === 'color' ? { ...effect, color: value } : effect\n if (property === 'offsetX') return { ...effect, offset: { ...effect.offset, x: value } }\n if (property === 'offsetY') return { ...effect, offset: { ...effect.offset, y: value } }\n if (property === 'radius' || property === 'spread') return { ...effect, [property]: value }\n return effect\n}\n\n/** A bound effect length in an occurrence's coordinates, which are 1:1 outside instances. */\nfunction scaledLength(length: number | undefined, node: SceneNode): number | undefined {\n return length === undefined ? undefined : length * node.componentScale\n}\n\n/**\n * The effects a node's effect bindings resolve to in its mode, when one differs from what the node\n * holds. Lengths stay as the variables give them, negative ones included, as Figma keeps them;\n * drawing treats a negative blur as none. In an instance they take its scale against its\n * component, whenever they were bound, as Figma scales them; a layer scaled outside an instance\n * goes back to the variable's own value.\n */\nexport function resolvedEffectBindings(\n graph: SceneGraph,\n node: SceneNode,\n fallback: VariableModeFallback = 'active'\n): Pick<Partial<SceneNode>, 'effects'> {\n // Most nodes bind nothing, so no copy is made until a value actually changes.\n let effects: Effect[] | undefined\n for (const [field, variableId] of Object.entries(node.boundVariables)) {\n const target = effectBindingTarget(field)\n if (!target) continue\n const effect = (effects ?? node.effects).at(target.index)\n if (!effect || !effectBindableProperties(effect.type).includes(target.property)) continue\n const value =\n target.property === 'color'\n ? graph.resolveColorVariableForNode(node.id, variableId, fallback)\n : scaledLength(graph.resolveNumberVariableForNode(node.id, variableId, fallback), node)\n if (value == null || (typeof value === 'number' && !Number.isFinite(value))) continue\n const next = withBoundEffectValue(effect, target.property, value)\n if (isEqual(next, effect)) continue\n effects ??= [...node.effects]\n effects[target.index] = next\n }\n return effects ? { effects } : {}\n}\n\n/**\n * The layers a reconcile looks at: those bound to these variables, directly or through a variable\n * aliasing them, or the layers in these subtrees. Without a scope, every layer.\n */\nexport type BindingScope = { variables: Iterable<string> } | { subtrees: Iterable<string> }\n\n/** These variables and every variable that aliases one of them, at any depth and in any mode. */\nexport function variablesResolvingThrough(graph: SceneGraph, ids: Iterable<string>): Set<string> {\n const found = new Set(ids)\n let grew = true\n while (grew) {\n grew = false\n for (const variable of graph.variables.values()) {\n if (found.has(variable.id)) continue\n const aliases = Object.values(variable.valuesByMode).some((value) =>\n variableValueReferences(value).some((id) => found.has(id))\n )\n if (aliases) {\n found.add(variable.id)\n grew = true\n }\n }\n }\n return found\n}\n\nfunction subtreeNodes(graph: SceneGraph, roots: Iterable<string>): SceneNode[] {\n const nodes: SceneNode[] = []\n const pending = [...roots]\n for (let id = pending.pop(); id !== undefined; id = pending.pop()) {\n const node = graph.getNode(id)\n if (!node) continue\n nodes.push(node)\n pending.push(...node.childIds)\n }\n return nodes\n}\n\n/**\n * The collections whose variables the layers in these subtrees resolve: those they bind, and\n * those the bound variables alias, so a mode set on the subtrees can change what they show.\n */\nexport function collectionsBoundIn(graph: SceneGraph, roots: Iterable<string>): Set<string> {\n const pending = subtreeNodes(graph, roots).flatMap(boundVariableIds)\n const seen = new Set<string>()\n const collections = new Set<string>()\n for (let id = pending.pop(); id !== undefined; id = pending.pop()) {\n if (seen.has(id)) continue\n seen.add(id)\n const variable = graph.variables.get(id)\n if (!variable) continue\n collections.add(variable.collectionId)\n for (const value of Object.values(variable.valuesByMode))\n pending.push(...variableValueReferences(value))\n }\n return collections\n}\n\n/**\n * The layers a change to these variables reaches: those binding one of them, or a variable that\n * aliases one, on the layer itself or on its characters.\n */\nexport function layersUsingVariables(graph: SceneGraph, ids: Iterable<string>): SceneNode[] {\n const variables = variablesResolvingThrough(graph, ids)\n return [...graph.getAllNodes()].filter((node) =>\n boundVariableIds(node).some((id) => variables.has(id))\n )\n}\n\nfunction scopedNodes(graph: SceneGraph, scope: BindingScope | undefined): Iterable<SceneNode> {\n if (!scope) return graph.getAllNodes()\n if ('subtrees' in scope) return subtreeNodes(graph, scope.subtrees)\n return layersUsingVariables(graph, scope.variables)\n}\n\n/**\n * Resolve live numeric, text, visibility, and effect bindings, numbers in scene units, without\n * authoring instance overrides. A scope limits it to the layers a change can reach, so layers whose\n * saved values differ from their bindings elsewhere in the document are left as saved. Returns the\n * layers whose change needs a layout pass; effects are not a layout input, so an effect-only change\n * is written but not returned.\n */\nexport function reconcileVariableBindings(graph: SceneGraph, scope?: BindingScope): string[] {\n return [...reconcileVariableBindingUpdates(graph, scope).keys()]\n}\n\n/**\n * As `reconcileVariableBindings`, with the layout fields each relaid layer received. Effects\n * are written too, but draw without layout, so a layer whose only change is an effect is left out.\n */\nexport function reconcileVariableBindingUpdates(\n graph: SceneGraph,\n scope?: BindingScope\n): Map<string, Partial<SceneNode>> {\n const relaid = new Map<string, Partial<SceneNode>>()\n for (const node of scopedNodes(graph, scope)) {\n const layoutUpdates = {\n ...resolvedNumericBindings(graph, node),\n ...resolvedValueBindings(graph, node),\n ...resolvedRunBindings(graph, node)\n }\n const updates = { ...layoutUpdates, ...resolvedEffectBindings(graph, node) }\n if (isEmptyObject(updates)) continue\n graph.updateNode(node.id, updates)\n if (!isEmptyObject(layoutUpdates)) relaid.set(node.id, layoutUpdates)\n }\n return relaid\n}\n\n/** A layer list whose items carry their own bindings, keyed by position such as `fills/1/color`. */\nexport type BoundLayerList = 'fills' | 'strokes' | 'effects'\n\n/**\n * `boundVariables` once the `list` items are rebuilt from `sources`, where `sources[i]` is the\n * position the new item `i` had before, or null for an added item. A binding moves with its item\n * and goes with a removed one, as Figma keeps a binding on its paint or effect.\n */\nexport function listBindingsAfterEdit(\n boundVariables: Readonly<Record<string, string>>,\n list: BoundLayerList,\n sources: readonly (number | null)[]\n): Record<string, string> {\n const prefix = `${list}/`\n const moved: Record<string, string> = {}\n for (const [field, variableId] of Object.entries(boundVariables)) {\n if (!field.startsWith(prefix)) {\n moved[field] = variableId\n continue\n }\n const [index, ...property] = field.slice(prefix.length).split('/')\n const next = sources.indexOf(Number(index))\n if (next !== -1 && property.length > 0)\n moved[`${prefix}${next}/${property.join('/')}`] = variableId\n }\n return moved\n}\n"],"mappings":";;;;;;;;;AAkCA,SAAgB,qBAAqB,OAAmB,MAA4B;CAClF,IAAI,QAAQ;CACZ,IAAI,UAAiC;CACrC,OAAO,SAAS;EACd,IAAI,QAAQ,SAAS,eAAe,QAAQ,SAAS,iBAAiB;EACtE,IAAI,QAAQ,SAAS,YAAY,QAAQ;EACzC,UAAU,QAAQ,WAAW,MAAM,QAAQ,QAAQ,QAAQ,IAAI,KAAA;CACjE;CACA,OAAO;AACT;AAEA,SA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AAK,GAAG,SAAS,KAAK,GAAG,OAAO;CACtD;CACA,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"bindings.js","names":[],"sources":["../../src/variables/bindings.ts"],"sourcesContent":["import { isEmptyObject, isEqual } from 'es-toolkit/predicate'\n\nimport type { SceneGraph } from '../graph'\nimport { hasInstanceOverride } from '../instances/overrides'\nimport type { Color } from '../primitives'\nimport { pixelLength } from '../text/lengths'\nimport type { Effect, SceneNode, StyleRun, TextLength } from '../types'\nimport {\n effectBindableProperties,\n effectBindingTarget,\n NUMERIC_FIELDS,\n isNumericVariableBindingField,\n type EffectBindingProperty\n} from './fields'\nimport { refreshBoundPaints } from './paints'\nimport { collectionsResolving } from './resolution'\nimport { subtreeNodes } from './subtree'\nimport { variableText, variableTruthy } from './text'\nimport { variableValueReferences } from './value'\nexport {\n EFFECT_BINDING_PROPERTIES,\n effectBindableProperties,\n effectBindingField,\n effectBindingTarget,\n effectBindingVariableType,\n isNumericVariableBindingField,\n paintBindingTarget,\n type EffectBindingProperty,\n TEXT_CONTENT_VARIABLE_TYPES,\n VISIBILITY_VARIABLE_TYPES,\n type PaintBindingList\n} from './fields'\n\n/** New declarations belong to the outermost occurrence, bounded by a component definition. */\nexport function variableBindingOwner(graph: SceneGraph, node: SceneNode): SceneNode {\n let owner = node\n let current: SceneNode | undefined = node\n while (current) {\n if (current.type === 'COMPONENT' || current.type === 'COMPONENT_SET') break\n if (current.type === 'INSTANCE') owner = current\n current = current.parentId ? graph.getNode(current.parentId) : undefined\n }\n return owner\n}\n\nexport function assignVariableBindingUnits(\n graph: SceneGraph,\n node: SceneNode,\n field: string\n): void {\n if (!isNumericVariableBindingField(field)) return\n const owner = variableBindingOwner(graph, node)\n node.variableBindingScales = {\n ...node.variableBindingScales,\n [field]: owner.variableAssignmentScales[field] ?? 1\n }\n}\n\n/** Fields a bound number sets as a length in pixels, as Figma's do, whatever unit they held. */\nconst TEXT_LENGTH_FIELDS: ReadonlySet<string> = new Set(['lineHeight', 'letterSpacing'])\n\n/** Whether the instance a layer sits in, or the instance itself, overrides one of its fields. */\nfunction overriddenInInstance(graph: SceneGraph, nodeId: string, field: string): boolean {\n const instance = graph.closest(nodeId, (node) => node.type === 'INSTANCE')\n return !!instance && hasInstanceOverride(instance.instanceOverrides, instance.id, nodeId, field)\n}\n\n/** A bound number as the field stores it. */\nexport function boundNumberValue(field: string, value: number): number | TextLength {\n return TEXT_LENGTH_FIELDS.has(field) ? pixelLength(value) : value\n}\n\n/**\n * The values a node's numeric bindings resolve to in its mode, in scene units, for the fields\n * whose stored value differs. A width or height an instance overrides keeps its own value.\n */\nexport function resolvedNumericBindings(graph: SceneGraph, node: SceneNode): Partial<SceneNode> {\n const updates: Partial<SceneNode> = {}\n for (const [field, variableId] of Object.entries(node.boundVariables)) {\n if (!NUMERIC_FIELDS.has(field)) continue\n if ((field === 'width' || field === 'height') && overriddenInInstance(graph, node.id, field))\n continue\n const value = graph.resolveNumberVariableForNode(node.id, variableId)\n if (value === undefined || !Number.isFinite(value)) continue\n const scale = node.variableBindingScales[field] ?? 1\n const effective = value * scale\n if (!Number.isFinite(effective)) continue\n const next = boundNumberValue(\n field,\n field === 'opacity' ? Math.max(0, Math.min(1, effective)) : effective\n )\n if (!isEqual(node[field as keyof SceneNode], next)) Object.assign(updates, { [field]: next })\n }\n return updates\n}\n\n/**\n * The text and visibility a node's string and boolean bindings resolve to in its mode, for the\n * fields whose stored value differs. Text or visibility an instance overrides, which typing in a\n * layer or toggling its eye records, keeps its own value, as an overridden width or height does.\n * A bound font family is left as stored: changing it needs the font loaded, which resolving a\n * binding cannot do.\n */\nexport function resolvedValueBindings(graph: SceneGraph, node: SceneNode): Partial<SceneNode> {\n const updates: Partial<SceneNode> = {}\n const resolve = (field: 'text' | 'visible') => {\n const variableId = node.boundVariables[field]\n if (!variableId || overriddenInInstance(graph, node.id, field)) return undefined\n return graph.resolveVariableForNode(node.id, variableId)\n }\n const text = node.type === 'TEXT' ? variableText(resolve('text')) : undefined\n if (text !== undefined && text !== node.text) updates.text = text\n // Figma binds visibility to text too, and shows the layer when the text reads as true.\n const visible = variableTruthy(resolve('visible'))\n if (visible !== undefined && visible !== node.visible) updates.visible = visible\n return updates\n}\n\n/** Fields of a range of characters a bound number gives its value; the rest need fonts loaded. */\nconst NUMERIC_RUN_FIELDS = ['fontSize', 'fontWeight', 'letterSpacing', 'lineHeight'] as const\n\n/**\n * The runs a text's character bindings resolve to in its mode, when a bound number differs from\n * what its characters hold. Bound font families and styles are left as stored, as the text's own.\n */\nexport function resolvedRunBindings(\n graph: SceneGraph,\n node: SceneNode\n): Pick<Partial<SceneNode>, 'styleRuns'> {\n const styleRuns = node.styleRuns.map((run): StyleRun => {\n const bound = run.style.boundVariables\n if (!bound) return run\n let style = run.style\n for (const field of NUMERIC_RUN_FIELDS) {\n const variableId = bound[field]\n if (!variableId) continue\n const value = graph.resolveNumberVariableForNode(node.id, variableId)\n if (value === undefined || !Number.isFinite(value)) continue\n const next = boundNumberValue(field, value)\n if (isEqual(style[field], next)) continue\n style = { ...style, [field]: next }\n }\n return style === run.style ? run : { ...run, style }\n })\n const changed = styleRuns.some((run, index) => run !== node.styleRuns[index])\n return changed ? { styleRuns } : {}\n}\n\n/** The variables a node binds, its own and its characters'. */\nfunction boundVariableIds(node: SceneNode): string[] {\n return [\n ...Object.values(node.boundVariables),\n ...node.styleRuns.flatMap((run) => Object.values(run.style.boundVariables ?? {}))\n ].filter((id): id is string => typeof id === 'string')\n}\n\n/** `effect` with one bound property set to its variable's value; a colour keeps its alpha. */\nfunction withBoundEffectValue(\n effect: Effect,\n property: EffectBindingProperty,\n value: number | Color\n): Effect {\n if (typeof value !== 'number') return property === 'color' ? { ...effect, color: value } : effect\n if (property === 'offsetX') return { ...effect, offset: { ...effect.offset, x: value } }\n if (property === 'offsetY') return { ...effect, offset: { ...effect.offset, y: value } }\n if (property === 'radius' || property === 'spread') return { ...effect, [property]: value }\n return effect\n}\n\n/** A bound effect length in an occurrence's coordinates, which are 1:1 outside instances. */\nfunction scaledLength(length: number | undefined, node: SceneNode): number | undefined {\n return length === undefined ? undefined : length * node.componentScale\n}\n\n/**\n * The effects a node's effect bindings resolve to in its mode, when one differs from what the node\n * holds. Lengths stay as the variables give them, negative ones included, as Figma keeps them;\n * drawing treats a negative blur as none. In an instance they take its scale against its\n * component, whenever they were bound, as Figma scales them; a layer scaled outside an instance\n * goes back to the variable's own value.\n */\nexport function resolvedEffectBindings(\n graph: SceneGraph,\n node: SceneNode\n): Pick<Partial<SceneNode>, 'effects'> {\n // Most nodes bind nothing, so no copy is made until a value actually changes.\n let effects: Effect[] | undefined\n for (const [field, variableId] of Object.entries(node.boundVariables)) {\n const target = effectBindingTarget(field)\n if (!target) continue\n const effect = (effects ?? node.effects).at(target.index)\n if (!effect || !effectBindableProperties(effect.type).includes(target.property)) continue\n const value =\n target.property === 'color'\n ? graph.resolveColorVariableForNode(node.id, variableId)\n : scaledLength(graph.resolveNumberVariableForNode(node.id, variableId), node)\n if (value == null || (typeof value === 'number' && !Number.isFinite(value))) continue\n const next = withBoundEffectValue(effect, target.property, value)\n if (isEqual(next, effect)) continue\n effects ??= [...node.effects]\n effects[target.index] = next\n }\n return effects ? { effects } : {}\n}\n\n/**\n * The layers a reconcile looks at: those bound to these variables, directly or through a variable\n * aliasing them, or the layers in these subtrees. Without a scope, every layer.\n */\nexport type BindingScope = { variables: Iterable<string> } | { subtrees: Iterable<string> }\n\n/** These variables and every variable that aliases one of them, at any depth and in any mode. */\nexport function variablesResolvingThrough(graph: SceneGraph, ids: Iterable<string>): Set<string> {\n const found = new Set(ids)\n let grew = true\n while (grew) {\n grew = false\n for (const variable of graph.variables.values()) {\n if (found.has(variable.id)) continue\n const aliases = Object.values(variable.valuesByMode).some((value) =>\n variableValueReferences(value).some((id) => found.has(id))\n )\n if (aliases) {\n found.add(variable.id)\n grew = true\n }\n }\n }\n return found\n}\n\n/**\n * The collections whose variables the layers in these subtrees resolve: those they bind, and\n * those the bound variables alias, so a mode set on the subtrees can change what they show.\n */\nexport function collectionsBoundIn(graph: SceneGraph, roots: Iterable<string>): Set<string> {\n return collectionsResolving(graph, subtreeNodes(graph, roots).flatMap(boundVariableIds))\n}\n\n/**\n * The layers a change to these variables reaches: those binding one of them, or a variable that\n * aliases one, on the layer itself or on its characters.\n */\nexport function layersUsingVariables(graph: SceneGraph, ids: Iterable<string>): SceneNode[] {\n const variables = variablesResolvingThrough(graph, ids)\n return [...graph.getAllNodes()].filter((node) =>\n boundVariableIds(node).some((id) => variables.has(id))\n )\n}\n\n/**\n * The layers in these subtrees that resolve a variable of these collections, binding it or a\n * variable that aliases it, so a mode change for the collections can change what they show.\n */\nexport function layersResolvingCollections(\n graph: SceneGraph,\n roots: Iterable<string>,\n collectionIds: ReadonlySet<string>\n): SceneNode[] {\n const inCollections = [...graph.variables.values()].filter((variable) =>\n collectionIds.has(variable.collectionId)\n )\n const variables = variablesResolvingThrough(\n graph,\n inCollections.map((variable) => variable.id)\n )\n return subtreeNodes(graph, roots).filter((node) =>\n boundVariableIds(node).some((id) => variables.has(id))\n )\n}\n\nfunction scopedNodes(graph: SceneGraph, scope: BindingScope | undefined): Iterable<SceneNode> {\n if (!scope) return graph.getAllNodes()\n if ('subtrees' in scope) return subtreeNodes(graph, scope.subtrees)\n return layersUsingVariables(graph, scope.variables)\n}\n\n/**\n * Resolve live numeric, text, visibility, and effect bindings, numbers in scene units, and refresh\n * bound paints whose variable's color for the layer changed (`refreshBoundPaints`), without\n * authoring instance overrides. A scope limits it to the layers a change can reach, so layers whose\n * saved values differ from their bindings elsewhere in the document are left as saved. Returns the\n * layers whose change needs a layout pass; effects and paints are not a layout input, so a change\n * to them alone is written but not returned.\n */\nexport function reconcileVariableBindings(graph: SceneGraph, scope?: BindingScope): string[] {\n return [...reconcileVariableBindingUpdates(graph, scope).keys()]\n}\n\n/**\n * As `reconcileVariableBindings`, with the layout fields each relaid layer received. Effects and\n * paints are written too, but draw without layout, so a layer whose only change is one is left out.\n */\nexport function reconcileVariableBindingUpdates(\n graph: SceneGraph,\n scope?: BindingScope\n): Map<string, Partial<SceneNode>> {\n const relaid = new Map<string, Partial<SceneNode>>()\n const nodes = [...scopedNodes(graph, scope)]\n for (const node of nodes) refreshBoundPaints(graph, node)\n for (const node of nodes) {\n const layoutUpdates = {\n ...resolvedNumericBindings(graph, node),\n ...resolvedValueBindings(graph, node),\n ...resolvedRunBindings(graph, node)\n }\n const updates = { ...layoutUpdates, ...resolvedEffectBindings(graph, node) }\n if (isEmptyObject(updates)) continue\n graph.updateNode(node.id, updates)\n if (!isEmptyObject(layoutUpdates)) relaid.set(node.id, layoutUpdates)\n }\n return relaid\n}\n\n/** A layer list whose items carry their own bindings, keyed by position such as `fills/1/color`. */\nexport type BoundLayerList = 'fills' | 'strokes' | 'effects'\n\n/**\n * `boundVariables` once the `list` items are rebuilt from `sources`, where `sources[i]` is the\n * position the new item `i` had before, or null for an added item. A binding moves with its item\n * and goes with a removed one, as Figma keeps a binding on its paint or effect.\n */\nexport function listBindingsAfterEdit(\n boundVariables: Readonly<Record<string, string>>,\n list: BoundLayerList,\n sources: readonly (number | null)[]\n): Record<string, string> {\n const prefix = `${list}/`\n const moved: Record<string, string> = {}\n for (const [field, variableId] of Object.entries(boundVariables)) {\n if (!field.startsWith(prefix)) {\n moved[field] = variableId\n continue\n }\n const [index, ...property] = field.slice(prefix.length).split('/')\n const next = sources.indexOf(Number(index))\n if (next !== -1 && property.length > 0)\n moved[`${prefix}${next}/${property.join('/')}`] = variableId\n }\n return moved\n}\n"],"mappings":";;;;;;;;;;;AAkCA,SAAgB,qBAAqB,OAAmB,MAA4B;CAClF,IAAI,QAAQ;CACZ,IAAI,UAAiC;CACrC,OAAO,SAAS;EACd,IAAI,QAAQ,SAAS,eAAe,QAAQ,SAAS,iBAAiB;EACtE,IAAI,QAAQ,SAAS,YAAY,QAAQ;EACzC,UAAU,QAAQ,WAAW,MAAM,QAAQ,QAAQ,QAAQ,IAAI,KAAA;CACjE;CACA,OAAO;AACT;A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jE,MAAM,OAAO,QAAQ,QAAQ,OAAO,KAAK,CAAC;EAC1C,IAAI,SAAS,MAAM,SAAS,SAAS,GACnC,MAAM,GAAG,SAAS,KAAK,GAAG,SAAS,KAAK,GAAG,OAAO;CACtD;CACA,OAAO;AACT"}
|
|
@@ -34,7 +34,7 @@ declare function effectBindingTarget(field: string): {
|
|
|
34
34
|
index: number;
|
|
35
35
|
property: EffectBindingProperty;
|
|
36
36
|
} | null;
|
|
37
|
-
/** The properties of an effect that bind: every shadow property,
|
|
37
|
+
/** The properties of an effect that bind: every shadow property, else only the radius. */
|
|
38
38
|
declare function effectBindableProperties(type: Effect['type']): readonly EffectBindingProperty[];
|
|
39
39
|
/** The variable type an effect property binds to: colour to COLOR, lengths to FLOAT. */
|
|
40
40
|
declare function effectBindingVariableType(property: EffectBindingProperty): 'COLOR' | 'FLOAT';
|
package/dist/variables/fields.js
CHANGED
|
@@ -90,7 +90,7 @@ function effectBindingTarget(field) {
|
|
|
90
90
|
property: match[2]
|
|
91
91
|
};
|
|
92
92
|
}
|
|
93
|
-
/** The properties of an effect that bind: every shadow property,
|
|
93
|
+
/** The properties of an effect that bind: every shadow property, else only the radius. */
|
|
94
94
|
function effectBindableProperties(type) {
|
|
95
95
|
return type === "DROP_SHADOW" || type === "INNER_SHADOW" ? EFFECT_BINDING_PROPERTIES : BLUR_BINDING_PROPERTIES;
|
|
96
96
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fields.js","names":[],"sources":["../../src/variables/fields.ts"],"sourcesContent":["import type { Effect, VariableType } from '../types'\n\nexport const NUMERIC_FIELDS = new Set([\n 'opacity',\n 'width',\n 'height',\n 'minWidth',\n 'maxWidth',\n 'minHeight',\n 'maxHeight',\n 'x',\n 'y',\n 'rotation',\n 'cornerRadius',\n 'topLeftRadius',\n 'topRightRadius',\n 'bottomLeftRadius',\n 'bottomRightRadius',\n 'strokeWeight',\n 'borderTopWeight',\n 'borderBottomWeight',\n 'borderLeftWeight',\n 'borderRightWeight',\n 'fontSize',\n 'letterSpacing',\n 'lineHeight',\n 'paddingLeft',\n 'paddingRight',\n 'paddingTop',\n 'paddingBottom',\n 'itemSpacing',\n 'counterAxisSpacing',\n 'gridRowGap',\n 'gridColumnGap'\n])\n\nexport function isNumericVariableBindingField(field: string): boolean {\n return NUMERIC_FIELDS.has(field)\n}\n\n/** Text content and font family are the string-valued bindings a node accepts. */\nexport const STRING_BINDING_FIELDS: ReadonlySet<string> = new Set(['text', 'fontFamily'])\n\n/**\n * The variable types text content binds to: text, or a number shown as text, as Figma's layer\n * panel offers. Figma's plugin API takes text alone; font family stays text-only.\n */\nexport const TEXT_CONTENT_VARIABLE_TYPES = [\n 'STRING',\n 'FLOAT'\n] as const satisfies readonly VariableType[]\n\n/** Visibility is the only boolean-valued binding a node accepts. */\nexport const BOOLEAN_BINDING_FIELDS: ReadonlySet<string> = new Set(['visible'])\n\n/**\n * The variable types visibility binds to: a boolean, or text that shows the layer unless it reads\n * as false, as Figma's layer panel offers. Figma's plugin API takes booleans alone.\n */\nexport const VISIBILITY_VARIABLE_TYPES = [\n 'BOOLEAN',\n 'STRING'\n] as const satisfies readonly VariableType[]\n\n/** The paint lists whose colours bind to variables, one binding field per paint. */\nexport type PaintBindingList = 'fills' | 'strokes'\n\nconst PAINT_BINDING_FIELD = /^(fills|strokes)\\/(\\d+)\\/color$/\n\n/**\n * The paint a binding field names the colour of, such as the second fill for `fills/1/color`, or\n * null for a field that binds anything else.\n */\nexport function paintBindingTarget(\n field: string\n): { list: PaintBindingList; index: number } | null {\n if (!field.endsWith('/color')) return null\n const match = PAINT_BINDING_FIELD.exec(field)\n if (!match) return null\n return { list: match[1] === 'fills' ? 'fills' : 'strokes', index: Number(match[2]) }\n}\n\n/** The effect fields that bind to variables, in the order Figma's messages list them. */\nexport const EFFECT_BINDING_PROPERTIES = [\n 'color',\n 'radius',\n 'spread',\n 'offsetX',\n 'offsetY'\n] as const\n\nexport type EffectBindingProperty = (typeof EFFECT_BINDING_PROPERTIES)[number]\n\nconst EFFECT_BINDING_FIELD = /^effects\\/(\\d+)\\/(color|radius|spread|offsetX|offsetY)$/\n\nconst BLUR_BINDING_PROPERTIES = ['radius'] as const satisfies readonly EffectBindingProperty[]\n\n/** The node binding field for one property of the effect at `index`, such as `effects/0/radius`. */\nexport function effectBindingField(index: number, property: EffectBindingProperty): string {\n return `effects/${index}/${property}`\n}\n\n/**\n * The effect and property a binding field names, such as the second effect's blur for\n * `effects/1/radius`, or null for a field that binds anything else.\n */\nexport function effectBindingTarget(\n field: string\n): { index: number; property: EffectBindingProperty } | null {\n if (!field.startsWith('effects/')) return null\n const match = EFFECT_BINDING_FIELD.exec(field)\n if (!match) return null\n return { index: Number(match[1]), property: match[2] as EffectBindingProperty }\n}\n\n/** The properties of an effect that bind: every shadow property,
|
|
1
|
+
{"version":3,"file":"fields.js","names":[],"sources":["../../src/variables/fields.ts"],"sourcesContent":["import type { Effect, VariableType } from '../types'\n\nexport const NUMERIC_FIELDS = new Set([\n 'opacity',\n 'width',\n 'height',\n 'minWidth',\n 'maxWidth',\n 'minHeight',\n 'maxHeight',\n 'x',\n 'y',\n 'rotation',\n 'cornerRadius',\n 'topLeftRadius',\n 'topRightRadius',\n 'bottomLeftRadius',\n 'bottomRightRadius',\n 'strokeWeight',\n 'borderTopWeight',\n 'borderBottomWeight',\n 'borderLeftWeight',\n 'borderRightWeight',\n 'fontSize',\n 'letterSpacing',\n 'lineHeight',\n 'paddingLeft',\n 'paddingRight',\n 'paddingTop',\n 'paddingBottom',\n 'itemSpacing',\n 'counterAxisSpacing',\n 'gridRowGap',\n 'gridColumnGap'\n])\n\nexport function isNumericVariableBindingField(field: string): boolean {\n return NUMERIC_FIELDS.has(field)\n}\n\n/** Text content and font family are the string-valued bindings a node accepts. */\nexport const STRING_BINDING_FIELDS: ReadonlySet<string> = new Set(['text', 'fontFamily'])\n\n/**\n * The variable types text content binds to: text, or a number shown as text, as Figma's layer\n * panel offers. Figma's plugin API takes text alone; font family stays text-only.\n */\nexport const TEXT_CONTENT_VARIABLE_TYPES = [\n 'STRING',\n 'FLOAT'\n] as const satisfies readonly VariableType[]\n\n/** Visibility is the only boolean-valued binding a node accepts. */\nexport const BOOLEAN_BINDING_FIELDS: ReadonlySet<string> = new Set(['visible'])\n\n/**\n * The variable types visibility binds to: a boolean, or text that shows the layer unless it reads\n * as false, as Figma's layer panel offers. Figma's plugin API takes booleans alone.\n */\nexport const VISIBILITY_VARIABLE_TYPES = [\n 'BOOLEAN',\n 'STRING'\n] as const satisfies readonly VariableType[]\n\n/** The paint lists whose colours bind to variables, one binding field per paint. */\nexport type PaintBindingList = 'fills' | 'strokes'\n\nconst PAINT_BINDING_FIELD = /^(fills|strokes)\\/(\\d+)\\/color$/\n\n/**\n * The paint a binding field names the colour of, such as the second fill for `fills/1/color`, or\n * null for a field that binds anything else.\n */\nexport function paintBindingTarget(\n field: string\n): { list: PaintBindingList; index: number } | null {\n if (!field.endsWith('/color')) return null\n const match = PAINT_BINDING_FIELD.exec(field)\n if (!match) return null\n return { list: match[1] === 'fills' ? 'fills' : 'strokes', index: Number(match[2]) }\n}\n\n/** The effect fields that bind to variables, in the order Figma's messages list them. */\nexport const EFFECT_BINDING_PROPERTIES = [\n 'color',\n 'radius',\n 'spread',\n 'offsetX',\n 'offsetY'\n] as const\n\nexport type EffectBindingProperty = (typeof EFFECT_BINDING_PROPERTIES)[number]\n\nconst EFFECT_BINDING_FIELD = /^effects\\/(\\d+)\\/(color|radius|spread|offsetX|offsetY)$/\n\nconst BLUR_BINDING_PROPERTIES = ['radius'] as const satisfies readonly EffectBindingProperty[]\n\n/** The node binding field for one property of the effect at `index`, such as `effects/0/radius`. */\nexport function effectBindingField(index: number, property: EffectBindingProperty): string {\n return `effects/${index}/${property}`\n}\n\n/**\n * The effect and property a binding field names, such as the second effect's blur for\n * `effects/1/radius`, or null for a field that binds anything else.\n */\nexport function effectBindingTarget(\n field: string\n): { index: number; property: EffectBindingProperty } | null {\n if (!field.startsWith('effects/')) return null\n const match = EFFECT_BINDING_FIELD.exec(field)\n if (!match) return null\n return { index: Number(match[1]), property: match[2] as EffectBindingProperty }\n}\n\n/** The properties of an effect that bind: every shadow property, else only the radius. */\nexport function effectBindableProperties(type: Effect['type']): readonly EffectBindingProperty[] {\n return type === 'DROP_SHADOW' || type === 'INNER_SHADOW'\n ? EFFECT_BINDING_PROPERTIES\n : BLUR_BINDING_PROPERTIES\n}\n\n/** The variable type an effect property binds to: colour to COLOR, lengths to FLOAT. */\nexport function effectBindingVariableType(property: EffectBindingProperty): 'COLOR' | 'FLOAT' {\n return property === 'color' ? 'COLOR' : 'FLOAT'\n}\n"],"mappings":";AAEA,MAAa,iCAAiB,IAAI,IAAI;CACpC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,SAAgB,8BAA8B,OAAwB;CACpE,OAAO,eAAe,IAAI,KAAK;AACjC;;AAGA,MAAa,wCAA6C,IAAI,IAAI,CAAC,QAAQ,YAAY,CAAC;;;;;AAMxF,MAAa,8BAA8B,CACzC,UACA,OACF;;AAGA,MAAa,yCAA8C,IAAI,IAAI,CAAC,SAAS,CAAC;;;;;AAM9E,MAAa,4BAA4B,CACvC,WACA,QACF;AAKA,MAAM,sBAAsB;;;;;AAM5B,SAAgB,mBACd,OACkD;CAClD,IAAI,CAAC,MAAM,SAAS,QAAQ,GAAG,OAAO;CACtC,MAAM,QAAQ,oBAAoB,KAAK,KAAK;CAC5C,IAAI,CAAC,OAAO,OAAO;CACnB,OAAO;EAAE,MAAM,MAAM,OAAO,UAAU,UAAU;EAAW,OAAO,OAAO,MAAM,EAAE;CAAE;AACrF;;AAGA,MAAa,4BAA4B;CACvC;CACA;CACA;CACA;CACA;AACF;AAIA,MAAM,uBAAuB;AAE7B,MAAM,0BAA0B,CAAC,QAAQ;;AAGzC,SAAgB,mBAAmB,OAAe,UAAyC;CACzF,OAAO,WAAW,MAAM,GAAG;AAC7B;;;;;AAMA,SAAgB,oBACd,OAC2D;CAC3D,IAAI,CAAC,MAAM,WAAW,UAAU,GAAG,OAAO;CAC1C,MAAM,QAAQ,qBAAqB,KAAK,KAAK;CAC7C,IAAI,CAAC,OAAO,OAAO;CACnB,OAAO;EAAE,OAAO,OAAO,MAAM,EAAE;EAAG,UAAU,MAAM;CAA4B;AAChF;;AAGA,SAAgB,yBAAyB,MAAwD;CAC/F,OAAO,SAAS,iBAAiB,SAAS,iBACtC,4BACA;AACN;;AAGA,SAAgB,0BAA0B,UAAoD;CAC5F,OAAO,aAAa,UAAU,UAAU;AAC1C"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FormulaValueType } from "./signatures.js";
|
|
2
1
|
import { VariableFormulaNode, VariableLiteral } from "../../types.js";
|
|
2
|
+
import { FormulaValueType } from "./signatures.js";
|
|
3
3
|
//#region src/variables/formula/check.d.ts
|
|
4
4
|
/** The type of a value a formula holds or a variable gives. */
|
|
5
5
|
declare function formulaValueType(value: VariableLiteral): FormulaValueType;
|