@open-pencil/scene-graph 0.17.0-beta.1 → 0.17.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/arrow-caps.d.ts.map +1 -1
- package/dist/arrow-caps.js +2 -5
- package/dist/arrow-caps.js.map +1 -1
- 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/behaviours/index.d.ts +2 -2
- package/dist/behaviours/index.js +2 -2
- package/dist/behaviours/kinds.d.ts +11 -5
- package/dist/behaviours/kinds.d.ts.map +1 -1
- package/dist/behaviours/kinds.js +76 -75
- package/dist/behaviours/kinds.js.map +1 -1
- package/dist/behaviours/layers.d.ts.map +1 -1
- package/dist/behaviours/layers.js +3 -2
- package/dist/behaviours/layers.js.map +1 -1
- package/dist/behaviours/model.d.ts +7 -4
- package/dist/behaviours/model.d.ts.map +1 -1
- package/dist/behaviours/model.js +16 -9
- package/dist/behaviours/model.js.map +1 -1
- package/dist/behaviours/schema.d.ts +118 -4
- package/dist/behaviours/schema.d.ts.map +1 -1
- package/dist/behaviours/schema.js +18 -3
- package/dist/behaviours/schema.js.map +1 -1
- package/dist/behaviours/spec.d.ts.map +1 -1
- package/dist/behaviours/spec.js +3 -2
- package/dist/behaviours/spec.js.map +1 -1
- package/dist/bindings.js +9 -1
- package/dist/bindings.js.map +1 -1
- package/dist/checkpoint.d.ts +31 -2
- package/dist/checkpoint.d.ts.map +1 -1
- package/dist/checkpoint.js +211 -10
- package/dist/checkpoint.js.map +1 -1
- package/dist/components/index.d.ts +3 -3
- package/dist/components/index.js +3 -3
- package/dist/components/properties.d.ts +18 -1
- package/dist/components/properties.d.ts.map +1 -1
- package/dist/components/properties.js +66 -3
- package/dist/components/properties.js.map +1 -1
- package/dist/components/variants.d.ts +16 -10
- package/dist/components/variants.d.ts.map +1 -1
- package/dist/components/variants.js +39 -13
- package/dist/components/variants.js.map +1 -1
- package/dist/connectors/hit.d.ts.map +1 -1
- package/dist/connectors/hit.js +1 -7
- package/dist/connectors/hit.js.map +1 -1
- package/dist/connectors/pieces.d.ts.map +1 -1
- package/dist/connectors/pieces.js +2 -5
- package/dist/connectors/pieces.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 +17 -16
- package/dist/copy.js.map +1 -1
- package/dist/css/blend.d.ts +11 -0
- package/dist/css/blend.d.ts.map +1 -0
- package/dist/css/blend.js +30 -0
- package/dist/css/blend.js.map +1 -0
- package/dist/css/index.d.ts +4 -2
- package/dist/css/index.js +4 -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/cubic.d.ts +7 -0
- package/dist/cubic.d.ts.map +1 -0
- package/dist/cubic.js +17 -0
- package/dist/cubic.js.map +1 -0
- package/dist/export-format.d.ts +14 -1
- package/dist/export-format.d.ts.map +1 -1
- package/dist/export-format.js +26 -1
- package/dist/export-format.js.map +1 -1
- package/dist/fields/text.d.ts +2 -2
- package/dist/fields/text.d.ts.map +1 -1
- package/dist/fields/text.js +2 -1
- package/dist/fields/text.js.map +1 -1
- package/dist/figjam/index.d.ts +2 -2
- package/dist/figjam/index.js +2 -2
- package/dist/figjam/palette.d.ts +13 -2
- package/dist/figjam/palette.d.ts.map +1 -1
- package/dist/figjam/palette.js +30 -2
- package/dist/figjam/palette.js.map +1 -1
- package/dist/generated/index.d.ts +2 -2
- package/dist/generated/index.js +2 -2
- package/dist/generated/shape-with-text.d.ts +7 -2
- package/dist/generated/shape-with-text.d.ts.map +1 -1
- package/dist/generated/shape-with-text.js +20 -3
- package/dist/generated/shape-with-text.js.map +1 -1
- package/dist/geometry.d.ts +37 -46
- package/dist/geometry.d.ts.map +1 -1
- package/dist/geometry.js +80 -137
- package/dist/geometry.js.map +1 -1
- package/dist/graph.d.ts +49 -12
- package/dist/graph.d.ts.map +1 -1
- package/dist/graph.js +125 -27
- 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/guides.d.ts +3 -1
- package/dist/guides.d.ts.map +1 -1
- package/dist/guides.js +5 -1
- package/dist/guides.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 +57 -38
- 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/fields.d.ts +2 -2
- package/dist/instances/fields.d.ts.map +1 -1
- package/dist/instances/fields.js +8 -0
- package/dist/instances/fields.js.map +1 -1
- package/dist/instances/index.d.ts +1 -3
- package/dist/instances/index.d.ts.map +1 -1
- package/dist/instances/index.js +39 -30
- package/dist/instances/index.js.map +1 -1
- package/dist/instances/kept-overrides.js +204 -0
- package/dist/instances/kept-overrides.js.map +1 -0
- package/dist/instances/main-component.d.ts +3 -1
- package/dist/instances/main-component.d.ts.map +1 -1
- package/dist/instances/main-component.js +10 -2
- package/dist/instances/main-component.js.map +1 -1
- package/dist/instances/overrides.d.ts +4 -1
- package/dist/instances/overrides.d.ts.map +1 -1
- package/dist/instances/overrides.js +18 -2
- package/dist/instances/overrides.js.map +1 -1
- package/dist/instances/placement.js +55 -12
- package/dist/instances/placement.js.map +1 -1
- package/dist/instances/swap.js +291 -0
- package/dist/instances/swap.js.map +1 -0
- package/dist/instances/sync.js +112 -39
- package/dist/instances/sync.js.map +1 -1
- package/dist/node-defaults.d.ts.map +1 -1
- package/dist/node-defaults.js +2 -1
- 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/outline/flatten.d.ts +15 -0
- package/dist/outline/flatten.d.ts.map +1 -0
- package/dist/outline/flatten.js +189 -0
- package/dist/outline/flatten.js.map +1 -0
- package/dist/outline/heads.js +34 -0
- package/dist/outline/heads.js.map +1 -0
- package/dist/outline/hit.d.ts +21 -0
- package/dist/outline/hit.d.ts.map +1 -0
- package/dist/outline/hit.js +276 -0
- package/dist/outline/hit.js.map +1 -0
- package/dist/outline/index.d.ts +5 -0
- package/dist/outline/index.js +5 -0
- package/dist/outline/point.d.ts +16 -0
- package/dist/outline/point.d.ts.map +1 -0
- package/dist/outline/point.js +42 -0
- package/dist/outline/point.js.map +1 -0
- package/dist/outline/shapes.d.ts +35 -0
- package/dist/outline/shapes.d.ts.map +1 -0
- package/dist/outline/shapes.js +181 -0
- package/dist/outline/shapes.js.map +1 -0
- package/dist/plugin-data/fields.d.ts +4 -1
- package/dist/plugin-data/fields.d.ts.map +1 -1
- package/dist/plugin-data/fields.js +21 -4
- 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 +38 -15
- 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 +16 -1
- package/dist/shared-styles.d.ts.map +1 -1
- package/dist/shared-styles.js +69 -2
- 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 +6 -1
- package/dist/slots/content.js.map +1 -1
- package/dist/slots/frames.d.ts +2 -0
- package/dist/slots/frames.d.ts.map +1 -1
- package/dist/slots/frames.js +7 -2
- package/dist/slots/frames.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/text/index.d.ts +2 -2
- package/dist/text/index.js +3 -3
- package/dist/text/lengths.d.ts +6 -1
- package/dist/text/lengths.d.ts.map +1 -1
- package/dist/text/lengths.js +10 -1
- package/dist/text/lengths.js.map +1 -1
- package/dist/text/overflow.d.ts +2 -2
- package/dist/text/overflow.js.map +1 -1
- package/dist/text/picture.d.ts +1 -2
- package/dist/text/picture.d.ts.map +1 -1
- package/dist/text/picture.js +1 -4
- package/dist/text/picture.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 +16 -19
- 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 +73 -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 +37 -11
- package/dist/variables/bindings.d.ts.map +1 -1
- package/dist/variables/bindings.js +122 -74
- package/dist/variables/bindings.js.map +1 -1
- package/dist/variables/fields.d.ts +19 -1
- package/dist/variables/fields.d.ts.map +1 -1
- package/dist/variables/fields.js +36 -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 +7 -7
- package/dist/variables/index.d.ts.map +1 -1
- package/dist/variables/index.js +57 -26
- 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 +14 -1
- package/src/arrow-caps.ts +2 -5
- package/src/asset-keys.ts +20 -0
- package/src/behaviours/kinds.ts +51 -34
- package/src/behaviours/layers.ts +4 -2
- package/src/behaviours/model.ts +22 -11
- package/src/behaviours/schema.ts +20 -4
- package/src/behaviours/spec.ts +8 -2
- package/src/bindings.ts +11 -2
- package/src/checkpoint.ts +319 -17
- package/src/components/properties.ts +101 -2
- package/src/components/variants.ts +51 -30
- package/src/connectors/hit.ts +1 -12
- package/src/connectors/pieces.ts +2 -5
- package/src/constants.ts +17 -0
- package/src/constraints.ts +60 -0
- package/src/coordinate.ts +220 -0
- package/src/copy.ts +18 -19
- package/src/css/blend.ts +27 -0
- package/src/css/index.ts +18 -1
- package/src/css/text.ts +85 -17
- package/src/css/transform.ts +266 -0
- package/src/css/values.ts +8 -0
- package/src/cubic.ts +14 -0
- package/src/export-format.ts +29 -0
- package/src/fields/text.ts +3 -1
- package/src/figjam/palette.ts +29 -1
- package/src/generated/shape-with-text.ts +28 -2
- package/src/geometry.ts +97 -206
- package/src/graph.ts +155 -45
- package/src/group-bounds.ts +84 -17
- package/src/guides.ts +5 -0
- package/src/hit-test.ts +93 -64
- package/src/images.ts +71 -3
- package/src/instances/fields.ts +8 -0
- package/src/instances/index.ts +62 -31
- package/src/instances/kept-overrides.ts +280 -0
- package/src/instances/main-component.ts +12 -0
- package/src/instances/overrides.ts +27 -1
- package/src/instances/placement.ts +63 -10
- package/src/instances/swap.ts +456 -0
- package/src/instances/sync.ts +176 -50
- package/src/node-defaults.ts +3 -1
- package/src/order-keys.ts +6 -0
- package/src/outline/flatten.ts +190 -0
- package/src/outline/heads.ts +52 -0
- package/src/outline/hit.ts +369 -0
- package/src/outline/index.ts +4 -0
- package/src/outline/point.ts +59 -0
- package/src/outline/shapes.ts +207 -0
- package/src/plugin-data/fields.ts +21 -2
- 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 +90 -1
- package/src/slots/authoring.ts +5 -3
- package/src/slots/content.ts +6 -1
- package/src/slots/frames.ts +9 -7
- package/src/text/direction.ts +5 -0
- package/src/text/lengths.ts +10 -0
- package/src/text/overflow.ts +2 -2
- package/src/text/picture.ts +0 -4
- 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 +17 -31
- 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 +83 -1
- package/src/undo.ts +48 -10
- package/src/variables/bindings.ts +152 -88
- package/src/variables/fields.ts +46 -1
- package/src/variables/formula/index.ts +3 -1
- package/src/variables/index.ts +90 -39
- 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
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Effect } from "../types.js";
|
|
1
2
|
//#region src/variables/fields.d.ts
|
|
2
3
|
declare function isNumericVariableBindingField(field: string): boolean;
|
|
3
4
|
/**
|
|
@@ -20,6 +21,23 @@ declare function paintBindingTarget(field: string): {
|
|
|
20
21
|
list: PaintBindingList;
|
|
21
22
|
index: number;
|
|
22
23
|
} | null;
|
|
24
|
+
/** The effect fields that bind to variables, in the order Figma's messages list them. */
|
|
25
|
+
declare const EFFECT_BINDING_PROPERTIES: readonly ["color", "radius", "spread", "offsetX", "offsetY"];
|
|
26
|
+
type EffectBindingProperty = (typeof EFFECT_BINDING_PROPERTIES)[number];
|
|
27
|
+
/** The node binding field for one property of the effect at `index`, such as `effects/0/radius`. */
|
|
28
|
+
declare function effectBindingField(index: number, property: EffectBindingProperty): string;
|
|
29
|
+
/**
|
|
30
|
+
* The effect and property a binding field names, such as the second effect's blur for
|
|
31
|
+
* `effects/1/radius`, or null for a field that binds anything else.
|
|
32
|
+
*/
|
|
33
|
+
declare function effectBindingTarget(field: string): {
|
|
34
|
+
index: number;
|
|
35
|
+
property: EffectBindingProperty;
|
|
36
|
+
} | null;
|
|
37
|
+
/** The properties of an effect that bind: every shadow property, else only the radius. */
|
|
38
|
+
declare function effectBindableProperties(type: Effect['type']): readonly EffectBindingProperty[];
|
|
39
|
+
/** The variable type an effect property binds to: colour to COLOR, lengths to FLOAT. */
|
|
40
|
+
declare function effectBindingVariableType(property: EffectBindingProperty): 'COLOR' | 'FLOAT';
|
|
23
41
|
//#endregion
|
|
24
|
-
export { PaintBindingList, TEXT_CONTENT_VARIABLE_TYPES, VISIBILITY_VARIABLE_TYPES, isNumericVariableBindingField, paintBindingTarget };
|
|
42
|
+
export { EFFECT_BINDING_PROPERTIES, EffectBindingProperty, PaintBindingList, TEXT_CONTENT_VARIABLE_TYPES, VISIBILITY_VARIABLE_TYPES, effectBindableProperties, effectBindingField, effectBindingTarget, effectBindingVariableType, isNumericVariableBindingField, paintBindingTarget };
|
|
25
43
|
//# sourceMappingURL=fields.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fields.d.ts","names":[],"sources":["../../src/variables/fields.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"fields.d.ts","names":[],"sources":["../../src/variables/fields.ts"],"mappings":";;iBAoCgB,8BAA8B;;;;;cAWjC;;;;;cAYA;;KAMD;;;;;iBAQI,mBACd;EACG,MAAM;EAAkB;;;cAQhB;KAQD,gCAAgC;;iBAO5B,mBAAmB,eAAe,UAAU;;;;;iBAQ5C,oBACd;EACG;EAAe,UAAU;;;iBAQd,yBAAyB,MAAM,0BAA0B;;iBAOzD,0BAA0B,UAAU"}
|
package/dist/variables/fields.js
CHANGED
|
@@ -63,7 +63,42 @@ function paintBindingTarget(field) {
|
|
|
63
63
|
index: Number(match[2])
|
|
64
64
|
};
|
|
65
65
|
}
|
|
66
|
+
/** The effect fields that bind to variables, in the order Figma's messages list them. */
|
|
67
|
+
const EFFECT_BINDING_PROPERTIES = [
|
|
68
|
+
"color",
|
|
69
|
+
"radius",
|
|
70
|
+
"spread",
|
|
71
|
+
"offsetX",
|
|
72
|
+
"offsetY"
|
|
73
|
+
];
|
|
74
|
+
const EFFECT_BINDING_FIELD = /^effects\/(\d+)\/(color|radius|spread|offsetX|offsetY)$/;
|
|
75
|
+
const BLUR_BINDING_PROPERTIES = ["radius"];
|
|
76
|
+
/** The node binding field for one property of the effect at `index`, such as `effects/0/radius`. */
|
|
77
|
+
function effectBindingField(index, property) {
|
|
78
|
+
return `effects/${index}/${property}`;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The effect and property a binding field names, such as the second effect's blur for
|
|
82
|
+
* `effects/1/radius`, or null for a field that binds anything else.
|
|
83
|
+
*/
|
|
84
|
+
function effectBindingTarget(field) {
|
|
85
|
+
if (!field.startsWith("effects/")) return null;
|
|
86
|
+
const match = EFFECT_BINDING_FIELD.exec(field);
|
|
87
|
+
if (!match) return null;
|
|
88
|
+
return {
|
|
89
|
+
index: Number(match[1]),
|
|
90
|
+
property: match[2]
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/** The properties of an effect that bind: every shadow property, else only the radius. */
|
|
94
|
+
function effectBindableProperties(type) {
|
|
95
|
+
return type === "DROP_SHADOW" || type === "INNER_SHADOW" ? EFFECT_BINDING_PROPERTIES : BLUR_BINDING_PROPERTIES;
|
|
96
|
+
}
|
|
97
|
+
/** The variable type an effect property binds to: colour to COLOR, lengths to FLOAT. */
|
|
98
|
+
function effectBindingVariableType(property) {
|
|
99
|
+
return property === "color" ? "COLOR" : "FLOAT";
|
|
100
|
+
}
|
|
66
101
|
//#endregion
|
|
67
|
-
export { BOOLEAN_BINDING_FIELDS, NUMERIC_FIELDS, STRING_BINDING_FIELDS, TEXT_CONTENT_VARIABLE_TYPES, VISIBILITY_VARIABLE_TYPES, isNumericVariableBindingField, paintBindingTarget };
|
|
102
|
+
export { BOOLEAN_BINDING_FIELDS, EFFECT_BINDING_PROPERTIES, NUMERIC_FIELDS, STRING_BINDING_FIELDS, TEXT_CONTENT_VARIABLE_TYPES, VISIBILITY_VARIABLE_TYPES, effectBindableProperties, effectBindingField, effectBindingTarget, effectBindingVariableType, isNumericVariableBindingField, paintBindingTarget };
|
|
68
103
|
|
|
69
104
|
//# sourceMappingURL=fields.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fields.js","names":[],"sources":["../../src/variables/fields.ts"],"sourcesContent":["import type { 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"],"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"}
|
|
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;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
+
import { SceneGraph } from "../../graph.js";
|
|
2
|
+
import { VariableLiteral, VariableValue } from "../../types.js";
|
|
1
3
|
import { FormulaFold, MAX_FORMULA_DEPTH, VariableFormulaError, foldFormula, isFormulaOperation, isFormulaReference } from "./tree.js";
|
|
2
4
|
import { FormulaValueType, formulaArity, formulaSymbol } from "./signatures.js";
|
|
3
5
|
import { PrintFormulaOptions, printFormula } from "./print.js";
|
|
4
6
|
import { FormulaToken, FormulaTokenKind, formulaTokenName, formulaTokens, readFormulaToken } from "./tokens.js";
|
|
5
7
|
import { evaluateVariableFormula } from "./evaluate.js";
|
|
6
8
|
import { formulaValueType, inferFormulaType } from "./check.js";
|
|
7
|
-
import { SceneGraph } from "../../graph.js";
|
|
8
|
-
import { VariableLiteral, VariableValue } from "../../types.js";
|
|
9
9
|
//#region src/variables/formula/index.d.ts
|
|
10
10
|
/** Qualified names disambiguate references; the stored formula uses stable IDs. */
|
|
11
11
|
declare function variableFormulaReference(graph: SceneGraph, id: string): string;
|
|
@@ -68,7 +68,7 @@ function parseVariableFormula(graph, variableId, modeId, source) {
|
|
|
68
68
|
} : node;
|
|
69
69
|
return {
|
|
70
70
|
value,
|
|
71
|
-
resolved: resolveVariableInModes(graph, variableId, (collectionId) => collectionId === variable.collectionId ? modeId : graph.
|
|
71
|
+
resolved: resolveVariableInModes(graph, variableId, (collectionId) => collectionId === variable.collectionId ? modeId : graph.variableCollections.get(collectionId)?.defaultModeId ?? "", /* @__PURE__ */ new Set(), /* @__PURE__ */ new Map(), /* @__PURE__ */ new Map([[variableId, value]]))
|
|
72
72
|
};
|
|
73
73
|
}
|
|
74
74
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/variables/formula/index.ts"],"sourcesContent":["import type { SceneGraph } from '#scene-graph/graph'\nimport type { VariableLiteral, VariableValue } from '#scene-graph/types'\n\nimport { resolveVariableInModes } from '../resolution'\nimport { parseFormulaSyntax, type FormulaReference } from './parse'\nimport { printFormula, type PrintFormulaOptions } from './print'\nimport type { FormulaValueType } from './signatures'\nimport { isFormulaOperation, VariableFormulaError } from './tree'\n\nexport { printFormula, type PrintFormulaOptions } from './print'\nexport {\n formulaTokenName,\n formulaTokens,\n readFormulaToken,\n type FormulaToken,\n type FormulaTokenKind\n} from './tokens'\n\nexport { evaluateVariableFormula } from './evaluate'\nexport { formulaValueType, inferFormulaType } from './check'\nexport { formulaArity, formulaSymbol, type FormulaValueType } from './signatures'\nexport {\n foldFormula,\n isFormulaOperation,\n isFormulaReference,\n MAX_FORMULA_DEPTH,\n VariableFormulaError,\n type FormulaFold\n} from './tree'\n\nfunction qualifiedName(graph: SceneGraph, id: string) {\n const variable = graph.variables.get(id)\n if (!variable) return undefined\n const collection = graph.variableCollections.get(variable.collectionId)\n return `${collection?.name ?? variable.collectionId}::${variable.name}`\n}\n\n/** Qualified names disambiguate references; the stored formula uses stable IDs. */\nexport function variableFormulaReference(graph: SceneGraph, id: string): string {\n const variable = graph.variables.get(id)\n if (!variable) return `{#${id}}`\n const unique = (name: string, of: (id: string) => string | undefined) =>\n [...graph.variables.keys()].filter((other) => of(other) === name).length === 1\n const plain = variable.name\n if (\n !/[{}]/.test(plain) &&\n plain.trim() === plain &&\n unique(plain, (other) => graph.variables.get(other)?.name)\n )\n return `{${plain}}`\n const qualified = qualifiedName(graph, id) ?? ''\n return /[{}]/.test(qualified) || !unique(qualified, (other) => qualifiedName(graph, other))\n ? `{#${id}}`\n : `{${qualified}}`\n}\n\n/** The formula's source text, with `{name}` for each reference, as the clipboard and scripts write it; text is quoted. */\nexport function formatVariableFormula(\n graph: SceneGraph,\n value: VariableValue,\n options?: PrintFormulaOptions\n): string {\n const reference = (id: string) => variableFormulaReference(graph, id)\n const typed = { type: (id: string) => graph.variables.get(id)?.type, ...options }\n if (typeof value !== 'object' || !('expression' in value))\n return printFormula(value, reference, typed)\n return value.expression === 'FORMULA' ? printFormula(value.value, reference, typed) : ''\n}\n\n/**\n * Find the variable a reference names: `#id`, `Collection::name`, or a name, preferring the\n * edited variable's own collection when a name appears in several.\n */\nfunction resolveReference(graph: SceneGraph, collectionId: string, name: string): FormulaReference {\n const candidates = [...graph.variables.values()].filter(\n (candidate) =>\n name === `#${candidate.id}` ||\n name === qualifiedName(graph, candidate.id) ||\n name === candidate.name\n )\n const local = candidates.filter((candidate) => candidate.collectionId === collectionId)\n const matches = local.length === 1 ? local : candidates\n const match = matches.at(0)\n if (!match) throw new VariableFormulaError(`No variable named ${name}`)\n if (matches.length !== 1)\n throw new VariableFormulaError(`More than one variable is named ${name}`)\n return { id: match.id, type: match.type }\n}\n\nconst TYPE_NAMES: Record<FormulaValueType, string> = {\n FLOAT: 'a number',\n BOOLEAN: 'true or false',\n STRING: 'text',\n COLOR: 'a color'\n}\n\n/** Validate a draft without changing the document. Formulas operate on stored units. */\nexport function parseVariableFormula(\n graph: SceneGraph,\n variableId: string,\n modeId: string,\n source: string\n): { value: VariableValue; resolved: VariableLiteral } {\n const variable = graph.variables.get(variableId)\n if (!variable) throw new VariableFormulaError('Select a variable')\n const collection = graph.variableCollections.get(variable.collectionId)\n if (!collection?.modes.some((mode) => mode.modeId === modeId))\n throw new VariableFormulaError('Unknown variable mode')\n const { node, type } = parseFormulaSyntax(source, (name) =>\n resolveReference(graph, variable.collectionId, name)\n )\n if (type !== variable.type)\n throw new VariableFormulaError(\n `This gives ${TYPE_NAMES[type]}, but ${variable.name} holds ${TYPE_NAMES[variable.type]}`\n )\n const value: VariableValue = isFormulaOperation(node)\n ? { expression: 'FORMULA', type: variable.type, value: node }\n : node\n const resolved = resolveVariableInModes(\n graph,\n variableId,\n (collectionId) =>\n collectionId === variable.collectionId
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/variables/formula/index.ts"],"sourcesContent":["import type { SceneGraph } from '#scene-graph/graph'\nimport type { VariableLiteral, VariableValue } from '#scene-graph/types'\n\nimport { resolveVariableInModes } from '../resolution'\nimport { parseFormulaSyntax, type FormulaReference } from './parse'\nimport { printFormula, type PrintFormulaOptions } from './print'\nimport type { FormulaValueType } from './signatures'\nimport { isFormulaOperation, VariableFormulaError } from './tree'\n\nexport { printFormula, type PrintFormulaOptions } from './print'\nexport {\n formulaTokenName,\n formulaTokens,\n readFormulaToken,\n type FormulaToken,\n type FormulaTokenKind\n} from './tokens'\n\nexport { evaluateVariableFormula } from './evaluate'\nexport { formulaValueType, inferFormulaType } from './check'\nexport { formulaArity, formulaSymbol, type FormulaValueType } from './signatures'\nexport {\n foldFormula,\n isFormulaOperation,\n isFormulaReference,\n MAX_FORMULA_DEPTH,\n VariableFormulaError,\n type FormulaFold\n} from './tree'\n\nfunction qualifiedName(graph: SceneGraph, id: string) {\n const variable = graph.variables.get(id)\n if (!variable) return undefined\n const collection = graph.variableCollections.get(variable.collectionId)\n return `${collection?.name ?? variable.collectionId}::${variable.name}`\n}\n\n/** Qualified names disambiguate references; the stored formula uses stable IDs. */\nexport function variableFormulaReference(graph: SceneGraph, id: string): string {\n const variable = graph.variables.get(id)\n if (!variable) return `{#${id}}`\n const unique = (name: string, of: (id: string) => string | undefined) =>\n [...graph.variables.keys()].filter((other) => of(other) === name).length === 1\n const plain = variable.name\n if (\n !/[{}]/.test(plain) &&\n plain.trim() === plain &&\n unique(plain, (other) => graph.variables.get(other)?.name)\n )\n return `{${plain}}`\n const qualified = qualifiedName(graph, id) ?? ''\n return /[{}]/.test(qualified) || !unique(qualified, (other) => qualifiedName(graph, other))\n ? `{#${id}}`\n : `{${qualified}}`\n}\n\n/** The formula's source text, with `{name}` for each reference, as the clipboard and scripts write it; text is quoted. */\nexport function formatVariableFormula(\n graph: SceneGraph,\n value: VariableValue,\n options?: PrintFormulaOptions\n): string {\n const reference = (id: string) => variableFormulaReference(graph, id)\n const typed = { type: (id: string) => graph.variables.get(id)?.type, ...options }\n if (typeof value !== 'object' || !('expression' in value))\n return printFormula(value, reference, typed)\n return value.expression === 'FORMULA' ? printFormula(value.value, reference, typed) : ''\n}\n\n/**\n * Find the variable a reference names: `#id`, `Collection::name`, or a name, preferring the\n * edited variable's own collection when a name appears in several.\n */\nfunction resolveReference(graph: SceneGraph, collectionId: string, name: string): FormulaReference {\n const candidates = [...graph.variables.values()].filter(\n (candidate) =>\n name === `#${candidate.id}` ||\n name === qualifiedName(graph, candidate.id) ||\n name === candidate.name\n )\n const local = candidates.filter((candidate) => candidate.collectionId === collectionId)\n const matches = local.length === 1 ? local : candidates\n const match = matches.at(0)\n if (!match) throw new VariableFormulaError(`No variable named ${name}`)\n if (matches.length !== 1)\n throw new VariableFormulaError(`More than one variable is named ${name}`)\n return { id: match.id, type: match.type }\n}\n\nconst TYPE_NAMES: Record<FormulaValueType, string> = {\n FLOAT: 'a number',\n BOOLEAN: 'true or false',\n STRING: 'text',\n COLOR: 'a color'\n}\n\n/** Validate a draft without changing the document. Formulas operate on stored units. */\nexport function parseVariableFormula(\n graph: SceneGraph,\n variableId: string,\n modeId: string,\n source: string\n): { value: VariableValue; resolved: VariableLiteral } {\n const variable = graph.variables.get(variableId)\n if (!variable) throw new VariableFormulaError('Select a variable')\n const collection = graph.variableCollections.get(variable.collectionId)\n if (!collection?.modes.some((mode) => mode.modeId === modeId))\n throw new VariableFormulaError('Unknown variable mode')\n const { node, type } = parseFormulaSyntax(source, (name) =>\n resolveReference(graph, variable.collectionId, name)\n )\n if (type !== variable.type)\n throw new VariableFormulaError(\n `This gives ${TYPE_NAMES[type]}, but ${variable.name} holds ${TYPE_NAMES[variable.type]}`\n )\n const value: VariableValue = isFormulaOperation(node)\n ? { expression: 'FORMULA', type: variable.type, value: node }\n : node\n const resolved = resolveVariableInModes(\n graph,\n variableId,\n (collectionId) =>\n collectionId === variable.collectionId\n ? modeId\n : (graph.variableCollections.get(collectionId)?.defaultModeId ?? ''),\n new Set(),\n new Map(),\n new Map([[variableId, value]])\n )\n return { value, resolved }\n}\n"],"mappings":";;;;;;;;;AA8BA,SAAS,cAAc,OAAmB,IAAY;CACpD,MAAM,WAAW,MAAM,UAAU,IAAI,EAAE;CACvC,IAAI,CAAC,UAAU,OAAO,KAAA;CAEtB,OAAO,GADY,MAAM,oBAAoB,IAAI,SAAS,YACvC,CAAC,EAAE,QAAQ,SAAS,aAAa,IAAI,SAAS;AACnE;;AAGA,SAAgB,yBAAyB,OAAmB,IAAoB;CAC9E,MAAM,WAAW,MAAM,UAAU,IAAI,EAAE;CACvC,IAAI,CAAC,UAAU,OAAO,KAAK,GAAG;CAC9B,MAAM,UAAU,MAAc,OAC5B,CAAC,GAAG,MAAM,UAAU,KAAK,CAAC,CAAC,CAAC,QAAQ,UAAU,GAAG,KAAK,MAAM,IAAI,CAAC,CAAC,WAAW;CAC/E,MAAM,QAAQ,SAAS;CACvB,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,OAAO;AACT;;AAGA,SAAgB,qBACd,OACA,YACA,QACA,QACqD;CACrD,MAAM,WAAW,MAAM,UAAU,IAAI,UAAU;CAC/C,IAAI,CAAC,UAAU,MAAM,IAAI,qBAAqB,mBAAmB;CAEjE,IAAI,CADe,MAAM,oBAAoB,IAAI,SAAS,YAC5C,CAAC,EAAE,MAAM,MAAM,SAAS,KAAK,WAAW,MAAM,GAC1D,MAAM,IAAI,qBAAqB,uBAAuB;CACxD,MAAM,EAAE,MAAM,SAAS,mBAAmB,SAAS,SACjD,iBAAiB,OAAO,SAAS,cAAc,IAAI,CACrD;CACA,IAAI,SAAS,SAAS,MACpB,MAAM,IAAI,qBACR,cAAc,WAAW,MAAM,QAAQ,SAAS,KAAK,SAAS,WAAW,SAAS,OACpF;CACF,MAAM,QAAuB,mBAAmB,IAAI,IAChD;EAAE,YAAY;EAAW,MAAM,SAAS;EAAM,OAAO;CAAK,IAC1D;CAYJ,OAAO;EAAE;EAAO,UAXC,uBACf,OACA,aACC,iBACC,iBAAiB,SAAS,eACtB,SACC,MAAM,oBAAoB,IAAI,YAAY,CAAC,EAAE,iBAAiB,oBACrE,IAAI,IAAI,mBACR,IAAI,IAAI,mBACR,IAAI,IAAI,CAAC,CAAC,YAAY,KAAK,CAAC,CAAC,CAER;CAAE;AAC3B"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { SceneGraph } from "../graph.js";
|
|
2
|
+
import { Variable, VariableCollection, VariableCollectionMode, VariableType, VariableValue } from "../types.js";
|
|
1
3
|
import { FormulaFold, MAX_FORMULA_DEPTH, VariableFormulaError, foldFormula, isFormulaOperation, isFormulaReference } from "./formula/tree.js";
|
|
2
|
-
import { NodeVariableResolver,
|
|
3
|
-
import { PaintBindingList, TEXT_CONTENT_VARIABLE_TYPES, VISIBILITY_VARIABLE_TYPES, isNumericVariableBindingField, paintBindingTarget } from "./fields.js";
|
|
4
|
-
import { BindingScope, assignVariableBindingUnits, boundNumberValue, collectionsBoundIn, layersUsingVariables, reconcileVariableBindings,
|
|
4
|
+
import { NodeVariableResolver, VariableResolutionError, collectionsResolving, createBatchVariableResolver, getNodeVariableModeId, resolveColorVariable, resolveColorVariableForNode, resolveNumberVariable, resolveNumberVariableForNode, resolveStringVariableForNode, resolveVariable, resolveVariableForNode, resolveVariableInModes, variableValueInMode } from "./resolution.js";
|
|
5
|
+
import { EFFECT_BINDING_PROPERTIES, EffectBindingProperty, PaintBindingList, TEXT_CONTENT_VARIABLE_TYPES, VISIBILITY_VARIABLE_TYPES, effectBindableProperties, effectBindingField, effectBindingTarget, effectBindingVariableType, isNumericVariableBindingField, paintBindingTarget } from "./fields.js";
|
|
6
|
+
import { BindingScope, BoundLayerList, assignVariableBindingUnits, boundNumberValue, collectionsBoundIn, layersResolvingCollections, layersUsingVariables, listBindingsAfterEdit, reconcileVariableBindingUpdates, reconcileVariableBindings, resolvedEffectBindings, resolvedNumericBindings, resolvedRunBindings, resolvedValueBindings, variableBindingOwner, variablesResolvingThrough } from "./bindings.js";
|
|
5
7
|
import { independentCornerChanges } from "./corners.js";
|
|
6
8
|
import { FormulaValueType, formulaArity, formulaSymbol } from "./formula/signatures.js";
|
|
7
9
|
import { PrintFormulaOptions, printFormula } from "./formula/print.js";
|
|
@@ -10,12 +12,11 @@ import { evaluateVariableFormula } from "./formula/evaluate.js";
|
|
|
10
12
|
import { formulaValueType, inferFormulaType } from "./formula/check.js";
|
|
11
13
|
import { formatVariableFormula, parseVariableFormula, variableFormulaReference } from "./formula/index.js";
|
|
12
14
|
import { variableFormulaSchema } from "./formula/schema.js";
|
|
15
|
+
import { applyBoundPaintColor, applyBoundPaintColorsIn, copiesComponentPaints, copyAppliedBoundPaints, hasBoundPaints, keepCopyBoundPaints, recordWrittenBoundPaints, refreshBoundPaints, refreshBoundPaintsIn, refreshMovedBoundPaints } from "./paints.js";
|
|
13
16
|
import { variableAliasSchema, variableCollectionSchema, variableColorExpressionSchema, variableSchema } from "./schema.js";
|
|
14
17
|
import { variableText, variableTruthy } from "./text.js";
|
|
15
18
|
import { ROOT_FONT_SIZE_PX, tokenExpressionForValue, tokenNumberFromUnit, tokenNumberInUnit, updateTokenExpression } from "./token.js";
|
|
16
19
|
import { isUnsupportedVariableValue, mapVariableValueReferences, resolveVariableValue, variableValueReferences } from "./value.js";
|
|
17
|
-
import { SceneGraph } from "../graph.js";
|
|
18
|
-
import { Variable, VariableCollection, VariableCollectionMode, VariableType, VariableValue } from "../types.js";
|
|
19
20
|
//#region src/variables/index.d.ts
|
|
20
21
|
declare function addVariable(graph: SceneGraph, variable: Variable): void;
|
|
21
22
|
declare function removeVariable(graph: SceneGraph, id: string): void;
|
|
@@ -23,7 +24,6 @@ declare function addCollection(graph: SceneGraph, collection: VariableCollection
|
|
|
23
24
|
declare function createVariable(graph: SceneGraph, generateId: () => string, name: string, type: VariableType, collectionId: string, value?: VariableValue): Variable;
|
|
24
25
|
declare function createCollection(graph: SceneGraph, generateId: () => string, name: string): VariableCollection;
|
|
25
26
|
declare function removeCollection(graph: SceneGraph, id: string): void;
|
|
26
|
-
declare function setActiveMode(graph: SceneGraph, collectionId: string, modeId: string): void;
|
|
27
27
|
declare function addMode(graph: SceneGraph, collectionId: string, modeId: string, name: string, sourceMode?: string): void;
|
|
28
28
|
/** Add a mode with a new ID from `generateId`; undo and redo replay it with `addMode`. */
|
|
29
29
|
declare function createMode(graph: SceneGraph, generateId: () => string, collectionId: string, name: string, sourceMode?: string): string | undefined;
|
|
@@ -37,5 +37,5 @@ declare function getVariablesByType(graph: SceneGraph, type: VariableType): Vari
|
|
|
37
37
|
declare function bindVariable(graph: SceneGraph, nodeId: string, field: string, variableId: string): void;
|
|
38
38
|
declare function unbindVariable(graph: SceneGraph, nodeId: string, field: string): void;
|
|
39
39
|
//#endregion
|
|
40
|
-
export { BindingScope, type FormulaFold, type FormulaToken, type FormulaTokenKind, type FormulaValueType, MAX_FORMULA_DEPTH, NodeVariableResolver, type PaintBindingList, type PrintFormulaOptions, ROOT_FONT_SIZE_PX, TEXT_CONTENT_VARIABLE_TYPES, VISIBILITY_VARIABLE_TYPES, VariableFormulaError,
|
|
40
|
+
export { BindingScope, BoundLayerList, EFFECT_BINDING_PROPERTIES, type EffectBindingProperty, type FormulaFold, type FormulaToken, type FormulaTokenKind, type FormulaValueType, MAX_FORMULA_DEPTH, NodeVariableResolver, type PaintBindingList, type PrintFormulaOptions, ROOT_FONT_SIZE_PX, TEXT_CONTENT_VARIABLE_TYPES, VISIBILITY_VARIABLE_TYPES, VariableFormulaError, VariableResolutionError, addCollection, addMode, addVariable, applyBoundPaintColor, applyBoundPaintColorsIn, assignVariableBindingUnits, bindVariable, boundNumberValue, collectionsBoundIn, collectionsResolving, copiesComponentPaints, copyAppliedBoundPaints, createBatchVariableResolver, createCollection, createMode, createVariable, effectBindableProperties, effectBindingField, effectBindingTarget, effectBindingVariableType, evaluateVariableFormula, foldFormula, formatVariableFormula, formulaArity, formulaSymbol, formulaTokenName, formulaTokens, formulaValueType, getNodeVariableModeId, getVariablesByType, getVariablesForCollection, hasBoundPaints, independentCornerChanges, inferFormulaType, isFormulaOperation, isFormulaReference, isNumericVariableBindingField, isUnsupportedVariableValue, keepCopyBoundPaints, layersResolvingCollections, layersUsingVariables, listBindingsAfterEdit, mapVariableValueReferences, modesDefaultFirst, paintBindingTarget, parseVariableFormula, printFormula, readFormulaToken, reconcileVariableBindingUpdates, reconcileVariableBindings, recordWrittenBoundPaints, refreshBoundPaints, refreshBoundPaintsIn, refreshMovedBoundPaints, removeCollection, removeMode, removeVariable, renameMode, resolveColorVariable, resolveColorVariableForNode, resolveNumberVariable, resolveNumberVariableForNode, resolveStringVariableForNode, resolveVariable, resolveVariableForNode, resolveVariableInModes, resolveVariableValue, resolvedEffectBindings, resolvedNumericBindings, resolvedRunBindings, resolvedValueBindings, setDefaultMode, tokenExpressionForValue, tokenNumberFromUnit, tokenNumberInUnit, unbindVariable, updateTokenExpression, variableAliasSchema, variableBindingOwner, variableCollectionSchema, variableColorExpressionSchema, variableFormulaReference, variableFormulaSchema, variableSchema, variableText, variableTruthy, variableValueInMode, variableValueReferences, variablesResolvingThrough };
|
|
41
41
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/variables/index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/variables/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;iBAqCgB,YAAY,OAAO,YAAY,UAAU;iBAUzC,eAAe,OAAO,YAAY;iBA8BlC,cAAc,OAAO,YAAY,YAAY;iBAa7C,eACd,OAAO,YACP,0BACA,cACA,MAAM,cACN,sBACA,QAAQ,gBACP;iBAsBa,iBACd,OAAO,YACP,0BACA,eACC;iBAca,iBAAiB,OAAO,YAAY;iBAWpC,QACd,OAAO,YACP,sBACA,gBACA,cACA;;iBAkBc,WACd,OAAO,YACP,0BACA,sBACA,cACA;iBAQc,WAAW,OAAO,YAAY,sBAAsB;iBAgBpD,WACd,OAAO,YACP,sBACA,gBACA;iBAUc,eAAe,OAAO,YAAY,sBAAsB;;iBAkBxD,kBAAkB,YAAY,qBAAqB;iBAKnD,0BAA0B,OAAO,YAAY,uBAAuB;iBAQpE,mBAAmB,OAAO,YAAY,MAAM,eAAe;iBA+C3D,aACd,OAAO,YACP,gBACA,eACA;iBAyDc,eAAe,OAAO,YAAY,gBAAgB"}
|
package/dist/variables/index.js
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
|
+
import { BOOLEAN_BINDING_FIELDS, EFFECT_BINDING_PROPERTIES, STRING_BINDING_FIELDS, TEXT_CONTENT_VARIABLE_TYPES, VISIBILITY_VARIABLE_TYPES, effectBindableProperties, effectBindingField, effectBindingTarget, effectBindingVariableType, isNumericVariableBindingField, paintBindingTarget } from "./fields.js";
|
|
1
2
|
import { BLACK } from "../constants.js";
|
|
2
3
|
import { bindingOverrideField, setInstanceOverride } from "../instances/overrides.js";
|
|
3
|
-
import {
|
|
4
|
-
import { findInstanceAncestor } from "../instances/index.js";
|
|
5
|
-
import { siblingOrderKeys } from "../order-keys.js";
|
|
6
|
-
import { variableText, variableTruthy } from "./text.js";
|
|
4
|
+
import { findInstanceAncestor } from "../instances/main-component.js";
|
|
7
5
|
import { MAX_FORMULA_DEPTH, VariableFormulaError, foldFormula, isFormulaOperation, isFormulaReference } from "./formula/tree.js";
|
|
6
|
+
import { variableText, variableTruthy } from "./text.js";
|
|
8
7
|
import { formulaArity, formulaSymbol } from "./formula/signatures.js";
|
|
9
8
|
import { formulaValueType, inferFormulaType } from "./formula/check.js";
|
|
10
9
|
import { evaluateVariableFormula } from "./formula/evaluate.js";
|
|
11
10
|
import { variableAliasSchema, variableCollectionSchema, variableColorExpressionSchema, variableSchema } from "./schema.js";
|
|
12
11
|
import { isUnsupportedVariableValue, mapVariableValueReferences, resolveVariableValue, variableValueReferences } from "./value.js";
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
12
|
+
import { VariableResolutionError, collectionsResolving, createBatchVariableResolver, getNodeVariableModeId, resolveColorVariable, resolveColorVariableForNode, resolveNumberVariable, resolveNumberVariableForNode, resolveStringVariableForNode, resolveVariable, resolveVariableForNode, resolveVariableInModes, variableValueInMode } from "./resolution.js";
|
|
13
|
+
import { applyBoundPaintColor, applyBoundPaintColorsIn, copiesComponentPaints, copyAppliedBoundPaints, hasBoundPaints, keepCopyBoundPaints, recordWrittenBoundPaints, refreshBoundPaints, refreshBoundPaintsIn, refreshMovedBoundPaints } from "./paints.js";
|
|
14
|
+
import { assignVariableBindingUnits, boundNumberValue, collectionsBoundIn, layersResolvingCollections, layersUsingVariables, listBindingsAfterEdit, reconcileVariableBindingUpdates, reconcileVariableBindings, resolvedEffectBindings, resolvedNumericBindings, resolvedRunBindings, resolvedValueBindings, variableBindingOwner, variablesResolvingThrough } from "./bindings.js";
|
|
15
|
+
import { siblingOrderKeys } from "../order-keys.js";
|
|
15
16
|
import { independentCornerChanges } from "./corners.js";
|
|
16
17
|
import { formulaTokenName, formulaTokens, readFormulaToken } from "./formula/tokens.js";
|
|
17
18
|
import { printFormula } from "./formula/print.js";
|
|
@@ -19,19 +20,27 @@ import { formatVariableFormula, parseVariableFormula, variableFormulaReference }
|
|
|
19
20
|
import { variableFormulaSchema } from "./formula/schema.js";
|
|
20
21
|
import { ROOT_FONT_SIZE_PX, tokenExpressionForValue, tokenNumberFromUnit, tokenNumberInUnit, updateTokenExpression } from "./token.js";
|
|
21
22
|
import { omit, omitBy } from "es-toolkit/object";
|
|
22
|
-
import { partition } from "es-toolkit/array";
|
|
23
|
+
import { compact, partition, uniq } from "es-toolkit/array";
|
|
23
24
|
//#region src/variables/index.ts
|
|
24
25
|
function addVariable(graph, variable) {
|
|
26
|
+
graph.willChangeVariable(variable.id);
|
|
25
27
|
graph.variables.set(variable.id, variable);
|
|
26
28
|
const collection = graph.variableCollections.get(variable.collectionId);
|
|
27
|
-
if (collection && !collection.variableIds.includes(variable.id))
|
|
29
|
+
if (collection && !collection.variableIds.includes(variable.id)) {
|
|
30
|
+
graph.willChangeCollection(collection.id);
|
|
31
|
+
collection.variableIds.push(variable.id);
|
|
32
|
+
}
|
|
28
33
|
}
|
|
29
34
|
function removeVariable(graph, id) {
|
|
30
35
|
const variable = graph.variables.get(id);
|
|
31
36
|
if (!variable) return;
|
|
37
|
+
graph.willChangeVariable(id);
|
|
32
38
|
graph.variables.delete(id);
|
|
33
39
|
const collection = graph.variableCollections.get(variable.collectionId);
|
|
34
|
-
if (collection)
|
|
40
|
+
if (collection) {
|
|
41
|
+
graph.willChangeCollection(collection.id);
|
|
42
|
+
collection.variableIds = collection.variableIds.filter((vid) => vid !== id);
|
|
43
|
+
}
|
|
35
44
|
for (const node of graph.nodes.values()) {
|
|
36
45
|
if (!Object.values(node.boundVariables).includes(id)) continue;
|
|
37
46
|
graph.willChangeNode(node);
|
|
@@ -45,8 +54,8 @@ function removeVariable(graph, id) {
|
|
|
45
54
|
}
|
|
46
55
|
}
|
|
47
56
|
function addCollection(graph, collection) {
|
|
57
|
+
graph.willChangeCollection(collection.id);
|
|
48
58
|
graph.variableCollections.set(collection.id, collection);
|
|
49
|
-
if (!graph.activeMode.has(collection.id)) graph.activeMode.set(collection.id, collection.defaultModeId);
|
|
50
59
|
}
|
|
51
60
|
function defaultVariableValue(type, value) {
|
|
52
61
|
if (value !== void 0) return value;
|
|
@@ -93,15 +102,13 @@ function createCollection(graph, generateId, name) {
|
|
|
93
102
|
function removeCollection(graph, id) {
|
|
94
103
|
const collection = graph.variableCollections.get(id);
|
|
95
104
|
if (collection) for (const varId of Array.from(collection.variableIds)) removeVariable(graph, varId);
|
|
105
|
+
graph.willChangeCollection(id);
|
|
96
106
|
graph.variableCollections.delete(id);
|
|
97
|
-
graph.activeMode.delete(id);
|
|
98
|
-
}
|
|
99
|
-
function setActiveMode(graph, collectionId, modeId) {
|
|
100
|
-
graph.activeMode.set(collectionId, modeId);
|
|
101
107
|
}
|
|
102
108
|
function addMode(graph, collectionId, modeId, name, sourceMode) {
|
|
103
109
|
const collection = graph.variableCollections.get(collectionId);
|
|
104
110
|
if (!collection) return;
|
|
111
|
+
graph.willChangeCollection(collectionId);
|
|
105
112
|
collection.modes.push({
|
|
106
113
|
modeId,
|
|
107
114
|
name
|
|
@@ -110,6 +117,7 @@ function addMode(graph, collectionId, modeId, name, sourceMode) {
|
|
|
110
117
|
for (const varId of collection.variableIds) {
|
|
111
118
|
const variable = graph.variables.get(varId);
|
|
112
119
|
if (!variable) continue;
|
|
120
|
+
graph.willChangeVariable(varId);
|
|
113
121
|
variable.valuesByMode[modeId] = structuredClone(variable.valuesByMode[sourceModeId] ?? Object.values(variable.valuesByMode)[0]);
|
|
114
122
|
}
|
|
115
123
|
}
|
|
@@ -123,24 +131,29 @@ function createMode(graph, generateId, collectionId, name, sourceMode) {
|
|
|
123
131
|
function removeMode(graph, collectionId, modeId) {
|
|
124
132
|
const collection = graph.variableCollections.get(collectionId);
|
|
125
133
|
if (!collection || collection.modes.length <= 1) return;
|
|
134
|
+
graph.willChangeCollection(collectionId);
|
|
126
135
|
collection.modes = collection.modes.filter((m) => m.modeId !== modeId);
|
|
127
136
|
if (collection.defaultModeId === modeId) collection.defaultModeId = collection.modes[0].modeId;
|
|
128
137
|
for (const varId of collection.variableIds) {
|
|
129
138
|
const variable = graph.variables.get(varId);
|
|
130
|
-
if (variable)
|
|
139
|
+
if (!variable) continue;
|
|
140
|
+
graph.willChangeVariable(varId);
|
|
141
|
+
variable.valuesByMode = omit(variable.valuesByMode, [modeId]);
|
|
131
142
|
}
|
|
132
|
-
if (graph.activeMode.get(collectionId) === modeId) graph.activeMode.set(collectionId, collection.defaultModeId);
|
|
133
143
|
}
|
|
134
144
|
function renameMode(graph, collectionId, modeId, name) {
|
|
135
145
|
const collection = graph.variableCollections.get(collectionId);
|
|
136
146
|
if (!collection) return;
|
|
137
147
|
const mode = collection.modes.find((m) => m.modeId === modeId);
|
|
138
|
-
if (mode)
|
|
148
|
+
if (!mode) return;
|
|
149
|
+
graph.willChangeCollection(collectionId);
|
|
150
|
+
mode.name = name;
|
|
139
151
|
}
|
|
140
152
|
function setDefaultMode(graph, collectionId, modeId) {
|
|
141
153
|
const collection = graph.variableCollections.get(collectionId);
|
|
142
154
|
if (!collection) return;
|
|
143
155
|
if (!collection.modes.some((m) => m.modeId === modeId)) return;
|
|
156
|
+
graph.willChangeCollection(collectionId);
|
|
144
157
|
collection.defaultModeId = modeId;
|
|
145
158
|
collection.modes = withSortPositionsInOrder(modesDefaultFirst(collection));
|
|
146
159
|
}
|
|
@@ -165,23 +178,37 @@ function getVariablesForCollection(graph, collectionId) {
|
|
|
165
178
|
function getVariablesByType(graph, type) {
|
|
166
179
|
return [...graph.variables.values()].filter((v) => v.type === type);
|
|
167
180
|
}
|
|
181
|
+
/** Checks that an effect binding names an effect the node has, a property it binds, and its type. */
|
|
182
|
+
function assertEffectBinding(effects, target, type, field) {
|
|
183
|
+
const effect = effects.at(target.index);
|
|
184
|
+
if (!effect) throw new Error(`Index ${target.index} out of range for effects (length ${effects.length})`);
|
|
185
|
+
if (!effectBindableProperties(effect.type).includes(target.property)) throw new Error(`A ${effect.type} effect has no bindable ${target.property} ("${field}")`);
|
|
186
|
+
if (type !== effectBindingVariableType(target.property)) throw new Error(`Cannot bind ${type} variable to effect field "${field}"`);
|
|
187
|
+
}
|
|
188
|
+
/** Checks a paint binding and drops the list's dead top-level binding it replaces. */
|
|
189
|
+
function preparePaintBinding(graph, node, paint, variable, field) {
|
|
190
|
+
if (variable.type !== "COLOR") throw new Error(`Cannot bind ${variable.type} variable to color field "${field}"`);
|
|
191
|
+
const currentLength = node[paint.list].length;
|
|
192
|
+
if (paint.index >= currentLength) throw new Error(`Index ${paint.index} out of range for ${paint.list} (length ${currentLength})`);
|
|
193
|
+
if (paint.list in node.boundVariables) {
|
|
194
|
+
graph.willChangeNode(node);
|
|
195
|
+
node.boundVariables = omit(node.boundVariables, [paint.list]);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
168
198
|
function bindVariable(graph, nodeId, field, variableId) {
|
|
169
199
|
const node = graph.nodes.get(nodeId);
|
|
170
200
|
if (!node) return;
|
|
171
201
|
const variable = graph.variables.get(variableId);
|
|
172
202
|
if (!variable) throw new Error(`Variable "${variableId}" not found`);
|
|
173
203
|
const paint = paintBindingTarget(field);
|
|
174
|
-
if (paint)
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
if (paint.index >= currentLength) throw new Error(`Index ${paint.index} out of range for ${paint.list} (length ${currentLength})`);
|
|
178
|
-
if (paint.list in node.boundVariables) node.boundVariables = omit(node.boundVariables, [paint.list]);
|
|
179
|
-
}
|
|
204
|
+
if (paint) preparePaintBinding(graph, node, paint, variable, field);
|
|
205
|
+
const effect = effectBindingTarget(field);
|
|
206
|
+
if (effect) assertEffectBinding(node.effects, effect, variable.type, field);
|
|
180
207
|
if (isNumericVariableBindingField(field) && variable.type !== "FLOAT") throw new Error(`Cannot bind ${variable.type} variable to scalar field "${field}"`);
|
|
181
208
|
const textTypes = field === "text" ? TEXT_CONTENT_VARIABLE_TYPES : ["STRING"];
|
|
182
209
|
if (STRING_BINDING_FIELDS.has(field) && !textTypes.includes(variable.type)) throw new Error(`Cannot bind ${variable.type} variable to string field "${field}"`);
|
|
183
210
|
if (BOOLEAN_BINDING_FIELDS.has(field) && !VISIBILITY_VARIABLE_TYPES.some((type) => type === variable.type)) throw new Error(`Cannot bind ${variable.type} variable to boolean field "${field}"`);
|
|
184
|
-
if (!(isNumericVariableBindingField(field) || STRING_BINDING_FIELDS.has(field) || BOOLEAN_BINDING_FIELDS.has(field) || paint !== null)) throw new Error(`Unknown binding field "${field}"`);
|
|
211
|
+
if (!(isNumericVariableBindingField(field) || STRING_BINDING_FIELDS.has(field) || BOOLEAN_BINDING_FIELDS.has(field) || paint !== null || effect !== null)) throw new Error(`Unknown binding field "${field}"`);
|
|
185
212
|
graph.willChangeNode(node);
|
|
186
213
|
node.boundVariables = {
|
|
187
214
|
...node.boundVariables,
|
|
@@ -193,6 +220,7 @@ function bindVariable(graph, nodeId, field, variableId) {
|
|
|
193
220
|
boundVariables: { ...node.boundVariables },
|
|
194
221
|
variableBindingScales: { ...node.variableBindingScales }
|
|
195
222
|
});
|
|
223
|
+
if (paint) applyBoundPaintColor(graph, node, field);
|
|
196
224
|
}
|
|
197
225
|
function unbindVariable(graph, nodeId, field) {
|
|
198
226
|
const node = graph.nodes.get(nodeId);
|
|
@@ -213,11 +241,14 @@ function markBoundVariablesOverrideOnInstance(graph, nodeId, field) {
|
|
|
213
241
|
const owner = variableBindingOwner(graph, node);
|
|
214
242
|
if (owner.type !== "INSTANCE") return;
|
|
215
243
|
const nearest = findInstanceAncestor(graph, nodeId);
|
|
244
|
+
const instances = uniq(compact([nearest, owner])).filter((x) => x.id !== nodeId);
|
|
245
|
+
for (const instance of instances) graph.willChangeNode(instance);
|
|
216
246
|
if (nearest) setInstanceOverride(nearest.instanceOverrides, nearest.id, nodeId, "boundVariables");
|
|
217
247
|
setInstanceOverride(owner.instanceOverrides, owner.id, nodeId, "boundVariables");
|
|
218
|
-
if (field) setInstanceOverride(
|
|
248
|
+
if (field) for (const instance of uniq(compact([nearest, owner]))) setInstanceOverride(instance.instanceOverrides, instance.id, nodeId, bindingOverrideField(field), node.boundVariables[field] ?? null);
|
|
249
|
+
for (const instance of instances) graph.updateNode(instance.id, { instanceOverrides: instance.instanceOverrides });
|
|
219
250
|
}
|
|
220
251
|
//#endregion
|
|
221
|
-
export { MAX_FORMULA_DEPTH, ROOT_FONT_SIZE_PX, TEXT_CONTENT_VARIABLE_TYPES, VISIBILITY_VARIABLE_TYPES, VariableFormulaError, VariableResolutionError, addCollection, addMode, addVariable, assignVariableBindingUnits, bindVariable, boundNumberValue, collectionsBoundIn, createBatchVariableResolver, createCollection, createMode, createVariable, evaluateVariableFormula, foldFormula, formatVariableFormula, formulaArity, formulaSymbol, formulaTokenName, formulaTokens, formulaValueType,
|
|
252
|
+
export { EFFECT_BINDING_PROPERTIES, MAX_FORMULA_DEPTH, ROOT_FONT_SIZE_PX, TEXT_CONTENT_VARIABLE_TYPES, VISIBILITY_VARIABLE_TYPES, VariableFormulaError, VariableResolutionError, addCollection, addMode, addVariable, applyBoundPaintColor, applyBoundPaintColorsIn, assignVariableBindingUnits, bindVariable, boundNumberValue, collectionsBoundIn, collectionsResolving, copiesComponentPaints, copyAppliedBoundPaints, createBatchVariableResolver, createCollection, createMode, createVariable, effectBindableProperties, effectBindingField, effectBindingTarget, effectBindingVariableType, evaluateVariableFormula, foldFormula, formatVariableFormula, formulaArity, formulaSymbol, formulaTokenName, formulaTokens, formulaValueType, getNodeVariableModeId, getVariablesByType, getVariablesForCollection, hasBoundPaints, independentCornerChanges, inferFormulaType, isFormulaOperation, isFormulaReference, isNumericVariableBindingField, isUnsupportedVariableValue, keepCopyBoundPaints, layersResolvingCollections, layersUsingVariables, listBindingsAfterEdit, mapVariableValueReferences, modesDefaultFirst, paintBindingTarget, parseVariableFormula, printFormula, readFormulaToken, reconcileVariableBindingUpdates, reconcileVariableBindings, recordWrittenBoundPaints, refreshBoundPaints, refreshBoundPaintsIn, refreshMovedBoundPaints, removeCollection, removeMode, removeVariable, renameMode, resolveColorVariable, resolveColorVariableForNode, resolveNumberVariable, resolveNumberVariableForNode, resolveStringVariableForNode, resolveVariable, resolveVariableForNode, resolveVariableInModes, resolveVariableValue, resolvedEffectBindings, resolvedNumericBindings, resolvedRunBindings, resolvedValueBindings, setDefaultMode, tokenExpressionForValue, tokenNumberFromUnit, tokenNumberInUnit, unbindVariable, updateTokenExpression, variableAliasSchema, variableBindingOwner, variableCollectionSchema, variableColorExpressionSchema, variableFormulaReference, variableFormulaSchema, variableSchema, variableText, variableTruthy, variableValueInMode, variableValueReferences, variablesResolvingThrough };
|
|
222
253
|
|
|
223
254
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/variables/index.ts"],"sourcesContent":["import { partition } from 'es-toolkit/array'\nimport { omit, omitBy } from 'es-toolkit/object'\n\nimport { BLACK } from '../constants'\nimport type { SceneGraph } from '../graph'\nimport { findInstanceAncestor } from '../instances'\nimport { bindingOverrideField, setInstanceOverride } from '../instances/overrides'\nimport { siblingOrderKeys } from '../order-keys'\nimport type {\n Variable,\n VariableCollection,\n VariableCollectionMode,\n VariableType,\n VariableValue\n} from '../types'\nimport {\n isNumericVariableBindingField,\n variableBindingOwner,\n assignVariableBindingUnits\n} from './bindings'\nimport {\n BOOLEAN_BINDING_FIELDS,\n paintBindingTarget,\n STRING_BINDING_FIELDS,\n TEXT_CONTENT_VARIABLE_TYPES,\n VISIBILITY_VARIABLE_TYPES\n} from './fields'\n\nexport * from './resolution'\n\nexport function addVariable(graph: SceneGraph, variable: Variable): void {\n graph.variables.set(variable.id, variable)\n const collection = graph.variableCollections.get(variable.collectionId)\n if (collection && !collection.variableIds.includes(variable.id)) {\n collection.variableIds.push(variable.id)\n }\n}\n\nexport function removeVariable(graph: SceneGraph, id: string): void {\n const variable = graph.variables.get(id)\n if (!variable) return\n graph.variables.delete(id)\n const collection = graph.variableCollections.get(variable.collectionId)\n if (collection) {\n collection.variableIds = collection.variableIds.filter((vid) => vid !== id)\n }\n for (const node of graph.nodes.values()) {\n const hadBinding = Object.values(node.boundVariables).includes(id)\n if (!hadBinding) continue\n graph.willChangeNode(node)\n node.boundVariables = omitBy(node.boundVariables, (varId) => varId === id) as Record<\n string,\n string\n >\n node.variableBindingScales = omitBy(\n node.variableBindingScales,\n (_, field) => !(field in node.boundVariables)\n )\n graph.emitter.emit('node:updated', node.id, {\n boundVariables: { ...node.boundVariables },\n variableBindingScales: { ...node.variableBindingScales }\n })\n markBoundVariablesOverrideOnInstance(graph, node.id)\n }\n}\n\nexport function addCollection(graph: SceneGraph, collection: VariableCollection): void {\n graph.variableCollections.set(collection.id, collection)\n if (!graph.activeMode.has(collection.id)) {\n graph.activeMode.set(collection.id, collection.defaultModeId)\n }\n}\n\nfunction defaultVariableValue(type: VariableType, value?: VariableValue): VariableValue {\n if (value !== undefined) return value\n if (type === 'COLOR') return { ...BLACK }\n if (type === 'FLOAT') return 0\n if (type === 'BOOLEAN') return false\n return ''\n}\n\nexport function createVariable(\n graph: SceneGraph,\n generateId: () => string,\n name: string,\n type: VariableType,\n collectionId: string,\n value?: VariableValue\n): Variable {\n const collection = graph.variableCollections.get(collectionId)\n if (!collection) throw new Error(`Collection \"${collectionId}\" not found`)\n const id = generateId()\n const defaultValue = defaultVariableValue(type, value)\n const valuesByMode: Record<string, VariableValue> = {}\n for (const mode of collection.modes) {\n valuesByMode[mode.modeId] = structuredClone(defaultValue)\n }\n const variable: Variable = {\n id,\n name,\n type,\n collectionId,\n valuesByMode,\n description: '',\n hiddenFromPublishing: false\n }\n addVariable(graph, variable)\n return variable\n}\n\nexport function createCollection(\n graph: SceneGraph,\n generateId: () => string,\n name: string\n): VariableCollection {\n const id = generateId()\n const modeId = generateId()\n const collection: VariableCollection = {\n id,\n name,\n modes: [{ modeId, name: 'Mode 1' }],\n defaultModeId: modeId,\n variableIds: []\n }\n addCollection(graph, collection)\n return collection\n}\n\nexport function removeCollection(graph: SceneGraph, id: string): void {\n const collection = graph.variableCollections.get(id)\n if (collection) {\n for (const varId of Array.from(collection.variableIds)) {\n removeVariable(graph, varId)\n }\n }\n graph.variableCollections.delete(id)\n graph.activeMode.delete(id)\n}\n\nexport function setActiveMode(graph: SceneGraph, collectionId: string, modeId: string): void {\n graph.activeMode.set(collectionId, modeId)\n}\n\nexport function addMode(\n graph: SceneGraph,\n collectionId: string,\n modeId: string,\n name: string,\n sourceMode?: string\n): void {\n const collection = graph.variableCollections.get(collectionId)\n if (!collection) return\n collection.modes.push({ modeId, name })\n const sourceModeId = sourceMode ?? collection.defaultModeId\n for (const varId of collection.variableIds) {\n const variable = graph.variables.get(varId)\n if (!variable) continue\n variable.valuesByMode[modeId] = structuredClone(\n variable.valuesByMode[sourceModeId] ?? Object.values(variable.valuesByMode)[0]\n )\n }\n}\n\n/** Add a mode with a new ID from `generateId`; undo and redo replay it with `addMode`. */\nexport function createMode(\n graph: SceneGraph,\n generateId: () => string,\n collectionId: string,\n name: string,\n sourceMode?: string\n): string | undefined {\n if (!graph.variableCollections.has(collectionId)) return undefined\n const modeId = generateId()\n addMode(graph, collectionId, modeId, name, sourceMode)\n return modeId\n}\n\nexport function removeMode(graph: SceneGraph, collectionId: string, modeId: string): void {\n const collection = graph.variableCollections.get(collectionId)\n if (!collection || collection.modes.length <= 1) return\n collection.modes = collection.modes.filter((m) => m.modeId !== modeId)\n if (collection.defaultModeId === modeId) {\n collection.defaultModeId = collection.modes[0].modeId\n }\n for (const varId of collection.variableIds) {\n const variable = graph.variables.get(varId)\n if (variable) variable.valuesByMode = omit(variable.valuesByMode, [modeId])\n }\n if (graph.activeMode.get(collectionId) === modeId) {\n graph.activeMode.set(collectionId, collection.defaultModeId)\n }\n}\n\nexport function renameMode(\n graph: SceneGraph,\n collectionId: string,\n modeId: string,\n name: string\n): void {\n const collection = graph.variableCollections.get(collectionId)\n if (!collection) return\n const mode = collection.modes.find((m) => m.modeId === modeId)\n if (mode) mode.name = name\n}\n\nexport function setDefaultMode(graph: SceneGraph, collectionId: string, modeId: string): void {\n const collection = graph.variableCollections.get(collectionId)\n if (!collection) return\n if (!collection.modes.some((m) => m.modeId === modeId)) return\n collection.defaultModeId = modeId\n collection.modes = withSortPositionsInOrder(modesDefaultFirst(collection))\n}\n\nfunction withSortPositionsInOrder(modes: VariableCollectionMode[]): VariableCollectionMode[] {\n if (modes.every((mode) => !mode.sortPosition)) {\n return modes\n }\n const positions = siblingOrderKeys(modes.map((mode) => mode.sortPosition))\n return modes.map((mode, index) => ({ ...mode, sortPosition: positions[index] }))\n}\n\n/** Figma has no default-mode field: the first mode is the default. */\nexport function modesDefaultFirst(collection: VariableCollection): VariableCollectionMode[] {\n const [defaults, rest] = partition(collection.modes, (m) => m.modeId === collection.defaultModeId)\n return [...defaults, ...rest]\n}\n\nexport function getVariablesForCollection(graph: SceneGraph, collectionId: string): Variable[] {\n const collection = graph.variableCollections.get(collectionId)\n if (!collection) return []\n return collection.variableIds\n .map((id) => graph.variables.get(id))\n .filter((v): v is Variable => v !== undefined)\n}\n\nexport function getVariablesByType(graph: SceneGraph, type: VariableType): Variable[] {\n return [...graph.variables.values()].filter((v) => v.type === type)\n}\n\nexport function bindVariable(\n graph: SceneGraph,\n nodeId: string,\n field: string,\n variableId: string\n): void {\n const node = graph.nodes.get(nodeId)\n if (!node) return\n\n // Validate variable exists\n const variable = graph.variables.get(variableId)\n if (!variable) {\n throw new Error(`Variable \"${variableId}\" not found`)\n }\n\n // Color fields require COLOR variable type\n const paint = paintBindingTarget(field)\n if (paint) {\n if (variable.type !== 'COLOR') {\n throw new Error(`Cannot bind ${variable.type} variable to color field \"${field}\"`)\n }\n // Validate index is within current array bounds\n const currentLength = node[paint.list].length\n if (paint.index >= currentLength) {\n throw new Error(\n `Index ${paint.index} out of range for ${paint.list} (length ${currentLength})`\n )\n }\n // Auto-remove top-level dead binding (e.g. 'fills') when setting indexed binding\n if (paint.list in node.boundVariables) {\n node.boundVariables = omit(node.boundVariables, [paint.list])\n }\n }\n\n if (isNumericVariableBindingField(field) && variable.type !== 'FLOAT') {\n throw new Error(`Cannot bind ${variable.type} variable to scalar field \"${field}\"`)\n }\n\n const textTypes: readonly VariableType[] =\n field === 'text' ? TEXT_CONTENT_VARIABLE_TYPES : ['STRING']\n if (STRING_BINDING_FIELDS.has(field) && !textTypes.includes(variable.type)) {\n throw new Error(`Cannot bind ${variable.type} variable to string field \"${field}\"`)\n }\n\n if (\n BOOLEAN_BINDING_FIELDS.has(field) &&\n !VISIBILITY_VARIABLE_TYPES.some((type) => type === variable.type)\n ) {\n throw new Error(`Cannot bind ${variable.type} variable to boolean field \"${field}\"`)\n }\n\n const isKnownField =\n isNumericVariableBindingField(field) ||\n STRING_BINDING_FIELDS.has(field) ||\n BOOLEAN_BINDING_FIELDS.has(field) ||\n paint !== null\n\n if (!isKnownField) {\n throw new Error(`Unknown binding field \"${field}\"`)\n }\n\n graph.willChangeNode(node)\n node.boundVariables = { ...node.boundVariables, [field]: variableId }\n assignVariableBindingUnits(graph, node, field)\n markBoundVariablesOverrideOnInstance(graph, nodeId, field)\n graph.emitter.emit('node:updated', nodeId, {\n boundVariables: { ...node.boundVariables },\n variableBindingScales: { ...node.variableBindingScales }\n })\n}\n\nexport function unbindVariable(graph: SceneGraph, nodeId: string, field: string): void {\n const node = graph.nodes.get(nodeId)\n if (!node) return\n if (!(field in node.boundVariables)) return\n graph.willChangeNode(node)\n node.boundVariables = omit(node.boundVariables, [field])\n node.variableBindingScales = omit(node.variableBindingScales, [field])\n markBoundVariablesOverrideOnInstance(graph, nodeId, field)\n graph.emitter.emit('node:updated', nodeId, {\n boundVariables: { ...node.boundVariables },\n variableBindingScales: { ...node.variableBindingScales }\n })\n}\n\nfunction markBoundVariablesOverrideOnInstance(\n graph: SceneGraph,\n nodeId: string,\n field?: string\n): void {\n const node = graph.nodes.get(nodeId)\n if (!node) return\n\n const owner = variableBindingOwner(graph, node)\n if (owner.type !== 'INSTANCE') return\n const nearest = findInstanceAncestor(graph, nodeId)\n if (nearest) setInstanceOverride(nearest.instanceOverrides, nearest.id, nodeId, 'boundVariables')\n setInstanceOverride(owner.instanceOverrides, owner.id, nodeId, 'boundVariables')\n if (field)\n setInstanceOverride(\n owner.instanceOverrides,\n owner.id,\n nodeId,\n bindingOverrideField(field),\n node.boundVariables[field] ?? null\n )\n}\n\nexport * from './bindings'\nexport * from './corners'\nexport * from './formula'\nexport * from './formula/schema'\nexport * from './schema'\nexport * from './text'\nexport * from './token'\nexport * from './value'\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA8BA,SAAgB,YAAY,OAAmB,UAA0B;CACvE,MAAM,UAAU,IAAI,SAAS,IAAI,QAAQ;CACzC,MAAM,aAAa,MAAM,oBAAoB,IAAI,SAAS,YAAY;CACtE,IAAI,cAAc,CAAC,WAAW,YAAY,SAAS,SAAS,EAAE,GAC5D,WAAW,YAAY,KAAK,SAAS,EAAE;AAE3C;AAEA,SAAgB,eAAe,OAAmB,IAAkB;CAClE,MAAM,WAAW,MAAM,UAAU,IAAI,EAAE;CACvC,IAAI,CAAC,UAAU;CACf,MAAM,UAAU,OAAO,EAAE;CACzB,MAAM,aAAa,MAAM,oBAAoB,IAAI,SAAS,YAAY;CACtE,IAAI,YACF,WAAW,cAAc,WAAW,YAAY,QAAQ,QAAQ,QAAQ,EAAE;CAE5E,KAAK,MAAM,QAAQ,MAAM,MAAM,OAAO,GAAG;EAEvC,IAAI,CADe,OAAO,OAAO,KAAK,cAAc,CAAC,CAAC,SAAS,EACjD,GAAG;EACjB,MAAM,eAAe,IAAI;EACzB,KAAK,iBAAiB,OAAO,KAAK,iBAAiB,UAAU,UAAU,EAAE;EAIzE,KAAK,wBAAwB,OAC3B,KAAK,wBACJ,GAAG,UAAU,EAAE,SAAS,KAAK,eAChC;EACA,MAAM,QAAQ,KAAK,gBAA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A,qBAAqB,KAAK,GAC1B,KAAK,eAAe,UAAU,IAChC;AACJ"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/variables/index.ts"],"sourcesContent":["import { compact, partition, uniq } from 'es-toolkit/array'\nimport { omit, omitBy } from 'es-toolkit/object'\n\nimport { BLACK } from '../constants'\nimport type { SceneGraph } from '../graph'\nimport { findInstanceAncestor } from '../instances'\nimport { bindingOverrideField, setInstanceOverride } from '../instances/overrides'\nimport { siblingOrderKeys } from '../order-keys'\nimport type {\n Effect,\n SceneNode,\n Variable,\n VariableCollection,\n VariableCollectionMode,\n VariableType,\n VariableValue\n} from '../types'\nimport {\n isNumericVariableBindingField,\n variableBindingOwner,\n assignVariableBindingUnits\n} from './bindings'\nimport {\n BOOLEAN_BINDING_FIELDS,\n effectBindableProperties,\n effectBindingTarget,\n effectBindingVariableType,\n type EffectBindingProperty,\n paintBindingTarget,\n STRING_BINDING_FIELDS,\n TEXT_CONTENT_VARIABLE_TYPES,\n VISIBILITY_VARIABLE_TYPES\n} from './fields'\nimport { applyBoundPaintColor } from './paints'\n\nexport * from './resolution'\n\nexport function addVariable(graph: SceneGraph, variable: Variable): void {\n graph.willChangeVariable(variable.id)\n graph.variables.set(variable.id, variable)\n const collection = graph.variableCollections.get(variable.collectionId)\n if (collection && !collection.variableIds.includes(variable.id)) {\n graph.willChangeCollection(collection.id)\n collection.variableIds.push(variable.id)\n }\n}\n\nexport function removeVariable(graph: SceneGraph, id: string): void {\n const variable = graph.variables.get(id)\n if (!variable) return\n graph.willChangeVariable(id)\n graph.variables.delete(id)\n const collection = graph.variableCollections.get(variable.collectionId)\n if (collection) {\n graph.willChangeCollection(collection.id)\n collection.variableIds = collection.variableIds.filter((vid) => vid !== id)\n }\n for (const node of graph.nodes.values()) {\n const hadBinding = Object.values(node.boundVariables).includes(id)\n if (!hadBinding) continue\n graph.willChangeNode(node)\n node.boundVariables = omitBy(node.boundVariables, (varId) => varId === id) as Record<\n string,\n string\n >\n node.variableBindingScales = omitBy(\n node.variableBindingScales,\n (_, field) => !(field in node.boundVariables)\n )\n graph.emitter.emit('node:updated', node.id, {\n boundVariables: { ...node.boundVariables },\n variableBindingScales: { ...node.variableBindingScales }\n })\n markBoundVariablesOverrideOnInstance(graph, node.id)\n }\n}\n\nexport function addCollection(graph: SceneGraph, collection: VariableCollection): void {\n graph.willChangeCollection(collection.id)\n graph.variableCollections.set(collection.id, collection)\n}\n\nfunction defaultVariableValue(type: VariableType, value?: VariableValue): VariableValue {\n if (value !== undefined) return value\n if (type === 'COLOR') return { ...BLACK }\n if (type === 'FLOAT') return 0\n if (type === 'BOOLEAN') return false\n return ''\n}\n\nexport function createVariable(\n graph: SceneGraph,\n generateId: () => string,\n name: string,\n type: VariableType,\n collectionId: string,\n value?: VariableValue\n): Variable {\n const collection = graph.variableCollections.get(collectionId)\n if (!collection) throw new Error(`Collection \"${collectionId}\" not found`)\n const id = generateId()\n const defaultValue = defaultVariableValue(type, value)\n const valuesByMode: Record<string, VariableValue> = {}\n for (const mode of collection.modes) {\n valuesByMode[mode.modeId] = structuredClone(defaultValue)\n }\n const variable: Variable = {\n id,\n name,\n type,\n collectionId,\n valuesByMode,\n description: '',\n hiddenFromPublishing: false\n }\n addVariable(graph, variable)\n return variable\n}\n\nexport function createCollection(\n graph: SceneGraph,\n generateId: () => string,\n name: string\n): VariableCollection {\n const id = generateId()\n const modeId = generateId()\n const collection: VariableCollection = {\n id,\n name,\n modes: [{ modeId, name: 'Mode 1' }],\n defaultModeId: modeId,\n variableIds: []\n }\n addCollection(graph, collection)\n return collection\n}\n\nexport function removeCollection(graph: SceneGraph, id: string): void {\n const collection = graph.variableCollections.get(id)\n if (collection) {\n for (const varId of Array.from(collection.variableIds)) {\n removeVariable(graph, varId)\n }\n }\n graph.willChangeCollection(id)\n graph.variableCollections.delete(id)\n}\n\nexport function addMode(\n graph: SceneGraph,\n collectionId: string,\n modeId: string,\n name: string,\n sourceMode?: string\n): void {\n const collection = graph.variableCollections.get(collectionId)\n if (!collection) return\n graph.willChangeCollection(collectionId)\n collection.modes.push({ modeId, name })\n const sourceModeId = sourceMode ?? collection.defaultModeId\n for (const varId of collection.variableIds) {\n const variable = graph.variables.get(varId)\n if (!variable) continue\n graph.willChangeVariable(varId)\n variable.valuesByMode[modeId] = structuredClone(\n variable.valuesByMode[sourceModeId] ?? Object.values(variable.valuesByMode)[0]\n )\n }\n}\n\n/** Add a mode with a new ID from `generateId`; undo and redo replay it with `addMode`. */\nexport function createMode(\n graph: SceneGraph,\n generateId: () => string,\n collectionId: string,\n name: string,\n sourceMode?: string\n): string | undefined {\n if (!graph.variableCollections.has(collectionId)) return undefined\n const modeId = generateId()\n addMode(graph, collectionId, modeId, name, sourceMode)\n return modeId\n}\n\nexport function removeMode(graph: SceneGraph, collectionId: string, modeId: string): void {\n const collection = graph.variableCollections.get(collectionId)\n if (!collection || collection.modes.length <= 1) return\n graph.willChangeCollection(collectionId)\n collection.modes = collection.modes.filter((m) => m.modeId !== modeId)\n if (collection.defaultModeId === modeId) {\n collection.defaultModeId = collection.modes[0].modeId\n }\n for (const varId of collection.variableIds) {\n const variable = graph.variables.get(varId)\n if (!variable) continue\n graph.willChangeVariable(varId)\n variable.valuesByMode = omit(variable.valuesByMode, [modeId])\n }\n}\n\nexport function renameMode(\n graph: SceneGraph,\n collectionId: string,\n modeId: string,\n name: string\n): void {\n const collection = graph.variableCollections.get(collectionId)\n if (!collection) return\n const mode = collection.modes.find((m) => m.modeId === modeId)\n if (!mode) return\n graph.willChangeCollection(collectionId)\n mode.name = name\n}\n\nexport function setDefaultMode(graph: SceneGraph, collectionId: string, modeId: string): void {\n const collection = graph.variableCollections.get(collectionId)\n if (!collection) return\n if (!collection.modes.some((m) => m.modeId === modeId)) return\n graph.willChangeCollection(collectionId)\n collection.defaultModeId = modeId\n collection.modes = withSortPositionsInOrder(modesDefaultFirst(collection))\n}\n\nfunction withSortPositionsInOrder(modes: VariableCollectionMode[]): VariableCollectionMode[] {\n if (modes.every((mode) => !mode.sortPosition)) {\n return modes\n }\n const positions = siblingOrderKeys(modes.map((mode) => mode.sortPosition))\n return modes.map((mode, index) => ({ ...mode, sortPosition: positions[index] }))\n}\n\n/** Figma has no default-mode field: the first mode is the default. */\nexport function modesDefaultFirst(collection: VariableCollection): VariableCollectionMode[] {\n const [defaults, rest] = partition(collection.modes, (m) => m.modeId === collection.defaultModeId)\n return [...defaults, ...rest]\n}\n\nexport function getVariablesForCollection(graph: SceneGraph, collectionId: string): Variable[] {\n const collection = graph.variableCollections.get(collectionId)\n if (!collection) return []\n return collection.variableIds\n .map((id) => graph.variables.get(id))\n .filter((v): v is Variable => v !== undefined)\n}\n\nexport function getVariablesByType(graph: SceneGraph, type: VariableType): Variable[] {\n return [...graph.variables.values()].filter((v) => v.type === type)\n}\n\n/** Checks that an effect binding names an effect the node has, a property it binds, and its type. */\nfunction assertEffectBinding(\n effects: readonly Effect[],\n target: { index: number; property: EffectBindingProperty },\n type: VariableType,\n field: string\n): void {\n const effect = effects.at(target.index)\n if (!effect) {\n throw new Error(`Index ${target.index} out of range for effects (length ${effects.length})`)\n }\n if (!effectBindableProperties(effect.type).includes(target.property)) {\n throw new Error(`A ${effect.type} effect has no bindable ${target.property} (\"${field}\")`)\n }\n if (type !== effectBindingVariableType(target.property)) {\n throw new Error(`Cannot bind ${type} variable to effect field \"${field}\"`)\n }\n}\n\n/** Checks a paint binding and drops the list's dead top-level binding it replaces. */\nfunction preparePaintBinding(\n graph: SceneGraph,\n node: SceneNode,\n paint: { list: 'fills' | 'strokes'; index: number },\n variable: Variable,\n field: string\n): void {\n // Color fields require COLOR variable type\n if (variable.type !== 'COLOR') {\n throw new Error(`Cannot bind ${variable.type} variable to color field \"${field}\"`)\n }\n // Validate index is within current array bounds\n const currentLength = node[paint.list].length\n if (paint.index >= currentLength) {\n throw new Error(`Index ${paint.index} out of range for ${paint.list} (length ${currentLength})`)\n }\n // Auto-remove top-level dead binding (e.g. 'fills') when setting indexed binding\n if (paint.list in node.boundVariables) {\n graph.willChangeNode(node)\n node.boundVariables = omit(node.boundVariables, [paint.list])\n }\n}\n\nexport function bindVariable(\n graph: SceneGraph,\n nodeId: string,\n field: string,\n variableId: string\n): void {\n const node = graph.nodes.get(nodeId)\n if (!node) return\n\n // Validate variable exists\n const variable = graph.variables.get(variableId)\n if (!variable) {\n throw new Error(`Variable \"${variableId}\" not found`)\n }\n\n const paint = paintBindingTarget(field)\n if (paint) preparePaintBinding(graph, node, paint, variable, field)\n\n const effect = effectBindingTarget(field)\n if (effect) assertEffectBinding(node.effects, effect, variable.type, field)\n\n if (isNumericVariableBindingField(field) && variable.type !== 'FLOAT') {\n throw new Error(`Cannot bind ${variable.type} variable to scalar field \"${field}\"`)\n }\n\n const textTypes: readonly VariableType[] =\n field === 'text' ? TEXT_CONTENT_VARIABLE_TYPES : ['STRING']\n if (STRING_BINDING_FIELDS.has(field) && !textTypes.includes(variable.type)) {\n throw new Error(`Cannot bind ${variable.type} variable to string field \"${field}\"`)\n }\n\n if (\n BOOLEAN_BINDING_FIELDS.has(field) &&\n !VISIBILITY_VARIABLE_TYPES.some((type) => type === variable.type)\n ) {\n throw new Error(`Cannot bind ${variable.type} variable to boolean field \"${field}\"`)\n }\n\n const isKnownField =\n isNumericVariableBindingField(field) ||\n STRING_BINDING_FIELDS.has(field) ||\n BOOLEAN_BINDING_FIELDS.has(field) ||\n paint !== null ||\n effect !== null\n\n if (!isKnownField) {\n throw new Error(`Unknown binding field \"${field}\"`)\n }\n\n graph.willChangeNode(node)\n node.boundVariables = { ...node.boundVariables, [field]: variableId }\n assignVariableBindingUnits(graph, node, field)\n markBoundVariablesOverrideOnInstance(graph, nodeId, field)\n graph.emitter.emit('node:updated', nodeId, {\n boundVariables: { ...node.boundVariables },\n variableBindingScales: { ...node.variableBindingScales }\n })\n // A paint takes its variable's color, alpha as opacity, when it binds, as Figma's does.\n if (paint) applyBoundPaintColor(graph, node, field)\n}\n\nexport function unbindVariable(graph: SceneGraph, nodeId: string, field: string): void {\n const node = graph.nodes.get(nodeId)\n if (!node) return\n if (!(field in node.boundVariables)) return\n graph.willChangeNode(node)\n node.boundVariables = omit(node.boundVariables, [field])\n node.variableBindingScales = omit(node.variableBindingScales, [field])\n markBoundVariablesOverrideOnInstance(graph, nodeId, field)\n graph.emitter.emit('node:updated', nodeId, {\n boundVariables: { ...node.boundVariables },\n variableBindingScales: { ...node.variableBindingScales }\n })\n}\n\nfunction markBoundVariablesOverrideOnInstance(\n graph: SceneGraph,\n nodeId: string,\n field?: string\n): void {\n const node = graph.nodes.get(nodeId)\n if (!node) return\n\n const owner = variableBindingOwner(graph, node)\n if (owner.type !== 'INSTANCE') return\n const nearest = findInstanceAncestor(graph, nodeId)\n const instances = uniq(compact([nearest, owner])).filter((x) => x.id !== nodeId)\n for (const instance of instances) graph.willChangeNode(instance)\n if (nearest) setInstanceOverride(nearest.instanceOverrides, nearest.id, nodeId, 'boundVariables')\n setInstanceOverride(owner.instanceOverrides, owner.id, nodeId, 'boundVariables')\n // Each instance claims the binding it changed alone, so the layer's other bindings keep\n // following their components, as Figma claims only the paint or effect a script edits.\n if (field)\n for (const instance of uniq(compact([nearest, owner])))\n setInstanceOverride(\n instance.instanceOverrides,\n instance.id,\n nodeId,\n bindingOverrideField(field),\n node.boundVariables[field] ?? null\n )\n for (const instance of instances)\n graph.updateNode(instance.id, { instanceOverrides: instance.instanceOverrides })\n}\n\nexport * from './bindings'\nexport * from './corners'\nexport * from './formula'\nexport * from './formula/schema'\nexport * from './paints'\nexport * from './schema'\nexport * from './text'\nexport * from './token'\nexport * from './value'\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAqCA,SAAgB,YAAY,OAAmB,UAA0B;CACvE,MAAM,mBAAmB,SAAS,EAAE;CACpC,MAAM,UAAU,IAAI,SAAS,IAAI,QAAQ;CACzC,MAAM,aAAa,MAAM,oBAAoB,IAAI,SAAS,YAAY;CACtE,IAAI,cAAc,CAAC,WAAW,YAAY,SAAS,SAAS,EAAE,GA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