@pairdraw/scene-graph 0.20.0 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/color/index.d.ts +28 -7
- package/dist/color/index.d.ts.map +1 -1
- package/dist/color/index.js +40 -15
- package/dist/color/index.js.map +1 -1
- package/dist/color/management.d.ts +19 -6
- package/dist/color/management.d.ts.map +1 -1
- package/dist/color/management.js +56 -1
- package/dist/color/management.js.map +1 -1
- package/dist/color/profile.d.ts +32 -0
- package/dist/color/profile.d.ts.map +1 -0
- package/dist/color/profile.js +140 -0
- package/dist/color/profile.js.map +1 -0
- package/dist/comments/index.d.ts +2 -2
- package/dist/comments/index.js +2 -2
- package/dist/comments/merge.d.ts.map +1 -1
- package/dist/comments/merge.js +1 -0
- package/dist/comments/merge.js.map +1 -1
- package/dist/comments/schema.d.ts +3 -1
- package/dist/comments/schema.d.ts.map +1 -1
- package/dist/comments/schema.js +19 -2
- package/dist/comments/schema.js.map +1 -1
- package/dist/comments/threads.d.ts +3 -1
- package/dist/comments/threads.d.ts.map +1 -1
- package/dist/comments/threads.js +2 -1
- package/dist/comments/threads.js.map +1 -1
- package/dist/components/properties.d.ts.map +1 -1
- package/dist/components/properties.js +7 -7
- package/dist/components/properties.js.map +1 -1
- package/dist/css/shadows.d.ts +2 -2
- package/dist/css/shadows.d.ts.map +1 -1
- package/dist/css/shadows.js +4 -4
- package/dist/css/shadows.js.map +1 -1
- package/dist/css/values.d.ts +7 -2
- package/dist/css/values.d.ts.map +1 -1
- package/dist/css/values.js +8 -4
- package/dist/css/values.js.map +1 -1
- package/dist/empty-values.js +9 -0
- package/dist/empty-values.js.map +1 -1
- package/dist/graph.d.ts +4 -0
- package/dist/graph.d.ts.map +1 -1
- package/dist/graph.js +11 -2
- package/dist/graph.js.map +1 -1
- package/dist/images.d.ts +3 -2
- package/dist/images.d.ts.map +1 -1
- package/dist/images.js +18 -2
- package/dist/images.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/instances/copies.js +2 -1
- package/dist/instances/copies.js.map +1 -1
- package/dist/instances/index.d.ts.map +1 -1
- package/dist/instances/index.js +12 -11
- package/dist/instances/index.js.map +1 -1
- package/dist/instances/overrides.d.ts +15 -1
- package/dist/instances/overrides.d.ts.map +1 -1
- package/dist/instances/overrides.js +37 -1
- package/dist/instances/overrides.js.map +1 -1
- package/dist/instances/swap-overrides.js +3 -3
- package/dist/instances/swap-overrides.js.map +1 -1
- package/dist/instances/sync.js +9 -7
- package/dist/instances/sync.js.map +1 -1
- package/dist/node-defaults.js +2 -2
- package/dist/node-defaults.js.map +1 -1
- package/dist/plugin-data/fields.d.ts +15 -0
- package/dist/plugin-data/fields.d.ts.map +1 -1
- package/dist/plugin-data/fields.js +15 -23
- package/dist/plugin-data/fields.js.map +1 -1
- package/dist/plugin-data/index.d.ts +2 -2
- package/dist/plugin-data/index.js +2 -2
- package/dist/plugin-data/schema.d.ts +6 -1
- package/dist/plugin-data/schema.d.ts.map +1 -1
- package/dist/plugin-data/schema.js +24 -1
- package/dist/plugin-data/schema.js.map +1 -1
- package/dist/shaders/animation.d.ts +21 -0
- package/dist/shaders/animation.d.ts.map +1 -0
- package/dist/shaders/animation.js +25 -0
- package/dist/shaders/animation.js.map +1 -0
- package/dist/shaders/index.d.ts +2 -1
- package/dist/shaders/index.js +2 -1
- package/dist/slots/content.d.ts.map +1 -1
- package/dist/slots/content.js +4 -4
- package/dist/slots/content.js.map +1 -1
- package/dist/statuses/index.d.ts +2 -2
- package/dist/statuses/index.js +2 -2
- package/dist/statuses/workflow.d.ts +3 -1
- package/dist/statuses/workflow.d.ts.map +1 -1
- package/dist/statuses/workflow.js +6 -2
- package/dist/statuses/workflow.js.map +1 -1
- package/dist/transfer/variables.d.ts.map +1 -1
- package/dist/transfer/variables.js +1 -1
- package/dist/transfer/variables.js.map +1 -1
- package/dist/types.d.ts +34 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/variables/bindings.d.ts +6 -5
- package/dist/variables/bindings.d.ts.map +1 -1
- package/dist/variables/bindings.js +24 -16
- package/dist/variables/bindings.js.map +1 -1
- package/dist/variables/formula/index.d.ts.map +1 -1
- package/dist/variables/formula/index.js +12 -6
- package/dist/variables/formula/index.js.map +1 -1
- package/dist/variables/index.d.ts +14 -1
- package/dist/variables/index.d.ts.map +1 -1
- package/dist/variables/index.js +38 -10
- package/dist/variables/index.js.map +1 -1
- package/dist/variables/paints.d.ts +9 -8
- package/dist/variables/paints.d.ts.map +1 -1
- package/dist/variables/paints.js +35 -26
- package/dist/variables/paints.js.map +1 -1
- package/dist/variables/resolver.d.ts +45 -0
- package/dist/variables/resolver.d.ts.map +1 -0
- package/dist/variables/resolver.js +106 -0
- package/dist/variables/resolver.js.map +1 -0
- package/package.json +1 -1
- package/src/color/index.ts +43 -9
- package/src/color/management.ts +54 -1
- package/src/color/profile.ts +131 -0
- package/src/comments/merge.ts +3 -0
- package/src/comments/schema.ts +32 -2
- package/src/comments/threads.ts +5 -2
- package/src/components/properties.ts +13 -7
- package/src/css/shadows.ts +8 -5
- package/src/css/values.ts +12 -5
- package/src/empty-values.ts +16 -0
- package/src/graph.ts +13 -1
- package/src/images.ts +27 -3
- package/src/instances/copies.ts +2 -1
- package/src/instances/index.ts +19 -11
- package/src/instances/overrides.ts +49 -0
- package/src/instances/swap-overrides.ts +3 -2
- package/src/instances/sync.ts +11 -7
- package/src/node-defaults.ts +2 -2
- package/src/plugin-data/fields.ts +16 -31
- package/src/plugin-data/index.ts +1 -0
- package/src/plugin-data/schema.ts +30 -0
- package/src/shaders/animation.ts +39 -0
- package/src/shaders/index.ts +1 -0
- package/src/slots/content.ts +8 -4
- package/src/statuses/workflow.ts +6 -4
- package/src/transfer/variables.ts +2 -1
- package/src/types.ts +30 -1
- package/src/variables/bindings.ts +35 -18
- package/src/variables/formula/index.ts +19 -18
- package/src/variables/index.ts +49 -10
- package/src/variables/paints.ts +64 -29
- package/src/variables/resolver.ts +178 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { FormulaFold, MAX_FORMULA_DEPTH, VariableFormulaError, foldFormula, isFormulaOperation, isFormulaReference } from "./formula/tree.js";
|
|
2
2
|
import { NodeVariableResolver, VariableModeFallback, VariableResolutionError, collectionsResolving, createBatchVariableResolver, getActiveModeId, getNodeExplicitVariableModeId, getNodeVariableModeId, resolveColorVariable, resolveColorVariableForNode, resolveNumberVariable, resolveNumberVariableForNode, resolveStringVariableForNode, resolveVariable, resolveVariableForNode, resolveVariableInModes, resolvedVariableModes, variableValueInMode } from "./resolution.js";
|
|
3
|
+
import { VariableReader, VariableResolver, VariableResolverOptions, createVariableResolver } from "./resolver.js";
|
|
3
4
|
import { ICON_BINDING_FIELDS, PaintBindingList, TEXT_CONTENT_VARIABLE_TYPES, VISIBILITY_VARIABLE_TYPES, isNumericVariableBindingField, paintBindingTarget } from "./fields.js";
|
|
4
5
|
import { BindingScope, BoundLayerList, assignVariableBindingUnits, boundNumberValue, collectionsBoundIn, layersUsingVariables, listBindingsAfterEdit, reconcileVariableBindings, resolvedIconBinding, resolvedNumericBindings, resolvedRunBindings, resolvedValueBindings, variableBindingOwner, variablesResolvingThrough } from "./bindings.js";
|
|
5
6
|
import { independentCornerChanges } from "./corners.js";
|
|
@@ -19,6 +20,18 @@ import { isUnsupportedVariableValue, mapVariableValueReferences, resolveVariable
|
|
|
19
20
|
import { SceneGraph } from "../graph.js";
|
|
20
21
|
import { Variable, VariableCollection, VariableCollectionMode, VariableType, VariableValue } from "../types.js";
|
|
21
22
|
//#region src/variables/index.d.ts
|
|
23
|
+
/**
|
|
24
|
+
* Variables a list shows: every one but those deleted, on their own or with their collection,
|
|
25
|
+
* which only their bindings still reach.
|
|
26
|
+
*/
|
|
27
|
+
declare function liveVariables(graph: SceneGraph): Variable[];
|
|
28
|
+
/** Collections a list shows: every one but those deleted. */
|
|
29
|
+
declare function liveCollections(graph: SceneGraph): VariableCollection[];
|
|
30
|
+
/**
|
|
31
|
+
* A collection's deleted variables, which its `variableIds` leave out. A deleted collection's
|
|
32
|
+
* variables are all deleted.
|
|
33
|
+
*/
|
|
34
|
+
declare function deletedVariablesOf(graph: SceneGraph, collectionId: string): Variable[];
|
|
22
35
|
declare function addVariable(graph: SceneGraph, variable: Variable): void;
|
|
23
36
|
declare function removeVariable(graph: SceneGraph, id: string): void;
|
|
24
37
|
declare function addCollection(graph: SceneGraph, collection: VariableCollection): void;
|
|
@@ -44,5 +57,5 @@ declare function getVariablesByType(graph: SceneGraph, type: VariableType): Vari
|
|
|
44
57
|
declare function bindVariable(graph: SceneGraph, nodeId: string, field: string, variableId: string): void;
|
|
45
58
|
declare function unbindVariable(graph: SceneGraph, nodeId: string, field: string): void;
|
|
46
59
|
//#endregion
|
|
47
|
-
export { AppliedBoundPaints, AppliedColor, BindingScope, BoundLayerList, type FormulaFold, type FormulaToken, type FormulaTokenKind, type FormulaValueType, ICON_BINDING_FIELDS, MAX_FORMULA_DEPTH, NodeVariableResolver, type PaintBindingList, type PrintFormulaOptions, ROOT_FONT_SIZE_PX, SCALED_RUN_BINDING_FIELDS, ScaledRunBindingField, TEXT_CONTENT_VARIABLE_TYPES, VISIBILITY_VARIABLE_TYPES, VariableFormulaError, VariableModeFallback, VariableResolutionError, addCollection, addMode, addVariable, applyBoundPaintColor, applyBoundPaintColorsIn, assignVariableBindingUnits, bindVariable, boundNumberValue, captureAppliedBoundPaints, collectionsBoundIn, collectionsResolving, copiesComponentPaints, copyAppliedBoundPaints, createBatchVariableResolver, createCollection, createMode, createVariable, evaluateVariableFormula, foldFormula, formatVariableFormula, formulaArity, formulaSymbol, formulaTokenName, formulaTokens, formulaValueType, getActiveModeId, getNodeExplicitVariableModeId, getNodeVariableModeId, getVariablesByType, getVariablesForCollection, hasBoundPaints, independentCornerChanges, inferFormulaType, isFormulaOperation, isFormulaReference, isNumericVariableBindingField, isUnsupportedVariableValue, keepCopyBoundPaints, keepPastedBoundPaints, layersUsingVariables, listBindingsAfterEdit, mapVariableValueReferences, modesDefaultFirst, modesInListedOrder, paintBindingTarget, paintColorApplied, parseVariableFormula, pinnedRunBindingScales, printFormula, readFormulaToken, reconcileVariableBindings, recordWrittenBoundPaints, refreshBoundPaints, refreshBoundPaintsIn, refreshMovedBoundPaints, removeCollection, removeMode, removeVariable, renameMode, resolveColorVariable, resolveColorVariableForNode, resolveNumberVariable, resolveNumberVariableForNode, resolveStringVariableForNode, resolveVariable, resolveVariableForNode, resolveVariableInModes, resolveVariableValue, resolvedIconBinding, resolvedNumericBindings, resolvedRunBindings, resolvedValueBindings, resolvedVariableModes, runBindingScale, scaleVariableBindingUnits, setActiveMode, setDefaultMode, shownPaintBindings, tokenExpressionForValue, tokenNumberFromUnit, tokenNumberInUnit, unbindVariable, updateTokenExpression, variableAliasSchema, variableBindingOwner, variableCollectionSchema, variableColorExpressionSchema, variableFontFamily, variableFormulaReference, variableFormulaSchema, variableSchema, variableText, variableTruthy, variableValueInMode, variableValueReferences, variablesResolvingThrough, withBoundBindingScales };
|
|
60
|
+
export { AppliedBoundPaints, AppliedColor, BindingScope, BoundLayerList, type FormulaFold, type FormulaToken, type FormulaTokenKind, type FormulaValueType, ICON_BINDING_FIELDS, MAX_FORMULA_DEPTH, NodeVariableResolver, type PaintBindingList, type PrintFormulaOptions, ROOT_FONT_SIZE_PX, SCALED_RUN_BINDING_FIELDS, ScaledRunBindingField, TEXT_CONTENT_VARIABLE_TYPES, VISIBILITY_VARIABLE_TYPES, VariableFormulaError, VariableModeFallback, VariableReader, VariableResolutionError, VariableResolver, VariableResolverOptions, addCollection, addMode, addVariable, applyBoundPaintColor, applyBoundPaintColorsIn, assignVariableBindingUnits, bindVariable, boundNumberValue, captureAppliedBoundPaints, collectionsBoundIn, collectionsResolving, copiesComponentPaints, copyAppliedBoundPaints, createBatchVariableResolver, createCollection, createMode, createVariable, createVariableResolver, deletedVariablesOf, evaluateVariableFormula, foldFormula, formatVariableFormula, formulaArity, formulaSymbol, formulaTokenName, formulaTokens, formulaValueType, getActiveModeId, getNodeExplicitVariableModeId, getNodeVariableModeId, getVariablesByType, getVariablesForCollection, hasBoundPaints, independentCornerChanges, inferFormulaType, isFormulaOperation, isFormulaReference, isNumericVariableBindingField, isUnsupportedVariableValue, keepCopyBoundPaints, keepPastedBoundPaints, layersUsingVariables, listBindingsAfterEdit, liveCollections, liveVariables, mapVariableValueReferences, modesDefaultFirst, modesInListedOrder, paintBindingTarget, paintColorApplied, parseVariableFormula, pinnedRunBindingScales, printFormula, readFormulaToken, reconcileVariableBindings, recordWrittenBoundPaints, refreshBoundPaints, refreshBoundPaintsIn, refreshMovedBoundPaints, removeCollection, removeMode, removeVariable, renameMode, resolveColorVariable, resolveColorVariableForNode, resolveNumberVariable, resolveNumberVariableForNode, resolveStringVariableForNode, resolveVariable, resolveVariableForNode, resolveVariableInModes, resolveVariableValue, resolvedIconBinding, resolvedNumericBindings, resolvedRunBindings, resolvedValueBindings, resolvedVariableModes, runBindingScale, scaleVariableBindingUnits, setActiveMode, setDefaultMode, shownPaintBindings, tokenExpressionForValue, tokenNumberFromUnit, tokenNumberInUnit, unbindVariable, updateTokenExpression, variableAliasSchema, variableBindingOwner, variableCollectionSchema, variableColorExpressionSchema, variableFontFamily, variableFormulaReference, variableFormulaSchema, variableSchema, variableText, variableTruthy, variableValueInMode, variableValueReferences, variablesResolvingThrough, withBoundBindingScales };
|
|
48
61
|
//# 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":";;;;;;;;;;;;;;;;;;;;;;;;;;iBAgDgB,cAAc,OAAO,aAAa;;iBAQlC,gBAAgB,OAAO,aAAa;;;;;iBAQpC,mBAAmB,OAAO,YAAY,uBAAuB;iBAoB7D,YAAY,OAAO,YAAY,UAAU;iBAWzC,eAAe,OAAO,YAAY;iBA8BlC,cAAc,OAAO,YAAY,YAAY;iBAe7C,eACd,OAAO,YACP,0BACA,cACA,MAAM,cACN,sBACA,QAAQ,gBACP;iBAsBa,iBACd,OAAO,YACP,0BACA,eACC;iBAca,iBAAiB,OAAO,YAAY;iBAoBpC,cAAc,OAAO,YAAY,sBAAsB;iBAIvD,QACd,OAAO,YACP,sBACA,gBACA,cACA;;iBAgBc,WACd,OAAO,YACP,0BACA,sBACA,cACA;iBAQc,WAAW,OAAO,YAAY,sBAAsB;iBAoCpD,WACd,OAAO,YACP,sBACA,gBACA;iBAQc,eAAe,OAAO,YAAY,sBAAsB;;iBAuBxD,kBAAkB,YAAY,qBAAqB;;;;;iBAYnD,mBAAmB,YAAY,qBAAqB;iBAIpD,0BAA0B,OAAO,YAAY,uBAAuB;iBAQpE,mBAAmB,OAAO,YAAY,MAAM,eAAe;iBAgE3D,aACd,OAAO,YACP,gBACA,eACA;iBA8Ec,eAAe,OAAO,YAAY,gBAAgB"}
|
package/dist/variables/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BLACK } from "../constants.js";
|
|
2
|
-
import { bindingOverrideField, setInstanceOverride, variableModeOverrideField } from "../instances/overrides.js";
|
|
2
|
+
import { bindingOverrideField, ownInstanceOverrides, setInstanceOverride, variableModeOverrideField } from "../instances/overrides.js";
|
|
3
3
|
import { BOOLEAN_BINDING_FIELDS, ICON_BINDING_FIELDS, NUMERIC_FIELDS, STRING_BINDING_FIELDS, TEXT_CONTENT_VARIABLE_TYPES, VISIBILITY_VARIABLE_TYPES, isNumericVariableBindingField, paintBindingTarget, uniformBindingTarget } from "./fields.js";
|
|
4
4
|
import { MAX_FORMULA_DEPTH, VariableFormulaError, foldFormula, isFormulaOperation, isFormulaReference } from "./formula/tree.js";
|
|
5
5
|
import { variableFontFamily, variableText, variableTruthy } from "./text.js";
|
|
@@ -9,6 +9,7 @@ import { evaluateVariableFormula } from "./formula/evaluate.js";
|
|
|
9
9
|
import { variableAliasSchema, variableCollectionSchema, variableColorExpressionSchema, variableSchema } from "./schema.js";
|
|
10
10
|
import { isUnsupportedVariableValue, mapVariableValueReferences, resolveVariableValue, variableValueReferences } from "./value.js";
|
|
11
11
|
import { VariableResolutionError, collectionsResolving, createBatchVariableResolver, getActiveModeId, getNodeExplicitVariableModeId, getNodeVariableModeId, resolveColorVariable, resolveColorVariableForNode, resolveNumberVariable, resolveNumberVariableForNode, resolveStringVariableForNode, resolveVariable, resolveVariableForNode, resolveVariableInModes, resolvedVariableModes, variableValueInMode } from "./resolution.js";
|
|
12
|
+
import { createVariableResolver } from "./resolver.js";
|
|
12
13
|
import { applyBoundPaintColor, applyBoundPaintColorsIn, captureAppliedBoundPaints, copiesComponentPaints, copyAppliedBoundPaints, hasBoundPaints, keepCopyBoundPaints, keepPastedBoundPaints, paintColorApplied, recordWrittenBoundPaints, refreshBoundPaints, refreshBoundPaintsIn, refreshMovedBoundPaints, shownPaintBindings } from "./paints.js";
|
|
13
14
|
import { SCALED_RUN_BINDING_FIELDS, pinnedRunBindingScales, runBindingScale, scaleVariableBindingUnits, withBoundBindingScales } from "./units.js";
|
|
14
15
|
import { assignVariableBindingUnits, boundNumberValue, collectionsBoundIn, layersUsingVariables, listBindingsAfterEdit, reconcileVariableBindings, resolvedIconBinding, resolvedNumericBindings, resolvedRunBindings, resolvedValueBindings, variableBindingOwner, variablesResolvingThrough } from "./bindings.js";
|
|
@@ -25,6 +26,24 @@ import { omit, omitBy } from "es-toolkit/object";
|
|
|
25
26
|
import { compact, partition, sortBy, uniq } from "es-toolkit/array";
|
|
26
27
|
//#region src/variables/index.ts
|
|
27
28
|
/**
|
|
29
|
+
* Variables a list shows: every one but those deleted, on their own or with their collection,
|
|
30
|
+
* which only their bindings still reach.
|
|
31
|
+
*/
|
|
32
|
+
function liveVariables(graph) {
|
|
33
|
+
return [...graph.variables.values()].filter((variable) => !variable.deleted && !graph.variableCollections.get(variable.collectionId)?.deleted);
|
|
34
|
+
}
|
|
35
|
+
/** Collections a list shows: every one but those deleted. */
|
|
36
|
+
function liveCollections(graph) {
|
|
37
|
+
return [...graph.variableCollections.values()].filter((collection) => !collection.deleted);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* A collection's deleted variables, which its `variableIds` leave out. A deleted collection's
|
|
41
|
+
* variables are all deleted.
|
|
42
|
+
*/
|
|
43
|
+
function deletedVariablesOf(graph, collectionId) {
|
|
44
|
+
return [...graph.variables.values()].filter((variable) => variable.collectionId === collectionId && variable.deleted);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
28
47
|
* Gives the runs that bind `fields` the scale they resolve with as their own, before the layer's
|
|
29
48
|
* scale for those fields changes or goes, and the change to announce.
|
|
30
49
|
*/
|
|
@@ -37,7 +56,9 @@ function pinRunBindingScales(node, fields) {
|
|
|
37
56
|
function addVariable(graph, variable) {
|
|
38
57
|
graph.variables.set(variable.id, variable);
|
|
39
58
|
const collection = graph.variableCollections.get(variable.collectionId);
|
|
40
|
-
if (
|
|
59
|
+
if (!collection) return;
|
|
60
|
+
if (collection.variableIds.includes(variable.id) === !variable.deleted) return;
|
|
61
|
+
collection.variableIds = variable.deleted ? collection.variableIds.filter((id) => id !== variable.id) : [...collection.variableIds, variable.id];
|
|
41
62
|
}
|
|
42
63
|
function removeVariable(graph, id) {
|
|
43
64
|
const variable = graph.variables.get(id);
|
|
@@ -108,7 +129,10 @@ function createCollection(graph, generateId, name) {
|
|
|
108
129
|
}
|
|
109
130
|
function removeCollection(graph, id) {
|
|
110
131
|
const collection = graph.variableCollections.get(id);
|
|
111
|
-
if (collection)
|
|
132
|
+
if (collection) {
|
|
133
|
+
for (const varId of Array.from(collection.variableIds)) removeVariable(graph, varId);
|
|
134
|
+
for (const variable of deletedVariablesOf(graph, id)) removeVariable(graph, variable.id);
|
|
135
|
+
}
|
|
112
136
|
graph.variableCollections.delete(id);
|
|
113
137
|
graph.activeMode.delete(id);
|
|
114
138
|
for (const node of graph.nodes.values()) {
|
|
@@ -158,8 +182,12 @@ function removeMode(graph, collectionId, modeId) {
|
|
|
158
182
|
const variableModes = omit(node.variableModes, [collectionId]);
|
|
159
183
|
graph.willChangeNode(node);
|
|
160
184
|
node.variableModes = variableModes;
|
|
161
|
-
node.instanceOverrides
|
|
162
|
-
|
|
185
|
+
const state = node.instanceOverrides;
|
|
186
|
+
if (state.self.has(overrideField) || [...state.descendants.values()].some((fields) => fields.has(overrideField))) {
|
|
187
|
+
const owned = ownInstanceOverrides(node);
|
|
188
|
+
owned.self.delete(overrideField);
|
|
189
|
+
for (const overrides of owned.descendants.values()) overrides.delete(overrideField);
|
|
190
|
+
}
|
|
163
191
|
graph.emitter.emit("node:updated", node.id, { variableModes });
|
|
164
192
|
}
|
|
165
193
|
if (graph.activeMode.get(collectionId) === modeId) graph.activeMode.set(collectionId, collection.defaultModeId);
|
|
@@ -205,7 +233,7 @@ function getVariablesForCollection(graph, collectionId) {
|
|
|
205
233
|
return collection.variableIds.map((id) => graph.variables.get(id)).filter((v) => v !== void 0);
|
|
206
234
|
}
|
|
207
235
|
function getVariablesByType(graph, type) {
|
|
208
|
-
return
|
|
236
|
+
return liveVariables(graph).filter((v) => v.type === type);
|
|
209
237
|
}
|
|
210
238
|
const PAINT_BINDING_LISTS = ["fills", "strokes"];
|
|
211
239
|
/**
|
|
@@ -308,12 +336,12 @@ function markBoundVariablesOverrideOnInstance(graph, nodeId, field) {
|
|
|
308
336
|
const nearest = findInstanceAncestor(graph, nodeId);
|
|
309
337
|
const instances = uniq(compact([nearest, owner])).filter((x) => x.id !== nodeId);
|
|
310
338
|
for (const instance of instances) graph.willChangeNode(instance);
|
|
311
|
-
if (nearest) setInstanceOverride(nearest
|
|
312
|
-
setInstanceOverride(owner
|
|
313
|
-
if (field) for (const instance of instances) setInstanceOverride(instance
|
|
339
|
+
if (nearest) setInstanceOverride(ownInstanceOverrides(nearest), nearest.id, nodeId, "boundVariables");
|
|
340
|
+
setInstanceOverride(ownInstanceOverrides(owner), owner.id, nodeId, "boundVariables");
|
|
341
|
+
if (field) for (const instance of instances) setInstanceOverride(ownInstanceOverrides(instance), instance.id, nodeId, bindingOverrideField(field), node.boundVariables[field] ?? null);
|
|
314
342
|
for (const instance of instances) graph.updateNode(instance.id, { instanceOverrides: instance.instanceOverrides });
|
|
315
343
|
}
|
|
316
344
|
//#endregion
|
|
317
|
-
export { ICON_BINDING_FIELDS, MAX_FORMULA_DEPTH, ROOT_FONT_SIZE_PX, SCALED_RUN_BINDING_FIELDS, TEXT_CONTENT_VARIABLE_TYPES, VISIBILITY_VARIABLE_TYPES, VariableFormulaError, VariableResolutionError, addCollection, addMode, addVariable, applyBoundPaintColor, applyBoundPaintColorsIn, assignVariableBindingUnits, bindVariable, boundNumberValue, captureAppliedBoundPaints, collectionsBoundIn, collectionsResolving, copiesComponentPaints, copyAppliedBoundPaints, createBatchVariableResolver, createCollection, createMode, createVariable, evaluateVariableFormula, foldFormula, formatVariableFormula, formulaArity, formulaSymbol, formulaTokenName, formulaTokens, formulaValueType, getActiveModeId, getNodeExplicitVariableModeId, getNodeVariableModeId, getVariablesByType, getVariablesForCollection, hasBoundPaints, independentCornerChanges, inferFormulaType, isFormulaOperation, isFormulaReference, isNumericVariableBindingField, isUnsupportedVariableValue, keepCopyBoundPaints, keepPastedBoundPaints, layersUsingVariables, listBindingsAfterEdit, mapVariableValueReferences, modesDefaultFirst, modesInListedOrder, paintBindingTarget, paintColorApplied, parseVariableFormula, pinnedRunBindingScales, printFormula, readFormulaToken, reconcileVariableBindings, recordWrittenBoundPaints, refreshBoundPaints, refreshBoundPaintsIn, refreshMovedBoundPaints, removeCollection, removeMode, removeVariable, renameMode, resolveColorVariable, resolveColorVariableForNode, resolveNumberVariable, resolveNumberVariableForNode, resolveStringVariableForNode, resolveVariable, resolveVariableForNode, resolveVariableInModes, resolveVariableValue, resolvedIconBinding, resolvedNumericBindings, resolvedRunBindings, resolvedValueBindings, resolvedVariableModes, runBindingScale, scaleVariableBindingUnits, setActiveMode, setDefaultMode, shownPaintBindings, tokenExpressionForValue, tokenNumberFromUnit, tokenNumberInUnit, unbindVariable, updateTokenExpression, variableAliasSchema, variableBindingOwner, variableCollectionSchema, variableColorExpressionSchema, variableFontFamily, variableFormulaReference, variableFormulaSchema, variableSchema, variableText, variableTruthy, variableValueInMode, variableValueReferences, variablesResolvingThrough, withBoundBindingScales };
|
|
345
|
+
export { ICON_BINDING_FIELDS, MAX_FORMULA_DEPTH, ROOT_FONT_SIZE_PX, SCALED_RUN_BINDING_FIELDS, TEXT_CONTENT_VARIABLE_TYPES, VISIBILITY_VARIABLE_TYPES, VariableFormulaError, VariableResolutionError, addCollection, addMode, addVariable, applyBoundPaintColor, applyBoundPaintColorsIn, assignVariableBindingUnits, bindVariable, boundNumberValue, captureAppliedBoundPaints, collectionsBoundIn, collectionsResolving, copiesComponentPaints, copyAppliedBoundPaints, createBatchVariableResolver, createCollection, createMode, createVariable, createVariableResolver, deletedVariablesOf, evaluateVariableFormula, foldFormula, formatVariableFormula, formulaArity, formulaSymbol, formulaTokenName, formulaTokens, formulaValueType, getActiveModeId, getNodeExplicitVariableModeId, getNodeVariableModeId, getVariablesByType, getVariablesForCollection, hasBoundPaints, independentCornerChanges, inferFormulaType, isFormulaOperation, isFormulaReference, isNumericVariableBindingField, isUnsupportedVariableValue, keepCopyBoundPaints, keepPastedBoundPaints, layersUsingVariables, listBindingsAfterEdit, liveCollections, liveVariables, mapVariableValueReferences, modesDefaultFirst, modesInListedOrder, paintBindingTarget, paintColorApplied, parseVariableFormula, pinnedRunBindingScales, printFormula, readFormulaToken, reconcileVariableBindings, recordWrittenBoundPaints, refreshBoundPaints, refreshBoundPaintsIn, refreshMovedBoundPaints, removeCollection, removeMode, removeVariable, renameMode, resolveColorVariable, resolveColorVariableForNode, resolveNumberVariable, resolveNumberVariableForNode, resolveStringVariableForNode, resolveVariable, resolveVariableForNode, resolveVariableInModes, resolveVariableValue, resolvedIconBinding, resolvedNumericBindings, resolvedRunBindings, resolvedValueBindings, resolvedVariableModes, runBindingScale, scaleVariableBindingUnits, setActiveMode, setDefaultMode, shownPaintBindings, tokenExpressionForValue, tokenNumberFromUnit, tokenNumberInUnit, unbindVariable, updateTokenExpression, variableAliasSchema, variableBindingOwner, variableCollectionSchema, variableColorExpressionSchema, variableFontFamily, variableFormulaReference, variableFormulaSchema, variableSchema, variableText, variableTruthy, variableValueInMode, variableValueReferences, variablesResolvingThrough, withBoundBindingScales };
|
|
318
346
|
|
|
319
347
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/variables/index.ts"],"sourcesContent":["import { compact, partition, sortBy, 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 {\n bindingOverrideField,\n setInstanceOverride,\n variableModeOverrideField\n} from '../instances/overrides'\nimport { siblingOrderKeys } from '../order-keys'\nimport { isShaderSourcePaint, shaderOfPaint, withShaderPaints } from '../shaders/model'\nimport type {\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 ICON_BINDING_FIELDS,\n NUMERIC_FIELDS,\n paintBindingTarget,\n STRING_BINDING_FIELDS,\n TEXT_CONTENT_VARIABLE_TYPES,\n uniformBindingTarget,\n VISIBILITY_VARIABLE_TYPES,\n type PaintBindingList\n} from './fields'\nimport { applyBoundPaintColor } from './paints'\nimport { pinnedRunBindingScales } from './units'\n\nexport * from './resolution'\n\n/**\n * Gives the runs that bind `fields` the scale they resolve with as their own, before the layer's\n * scale for those fields changes or goes, and the change to announce.\n */\nfunction pinRunBindingScales(\n node: SceneNode,\n fields: readonly string[]\n): Pick<Partial<SceneNode>, 'styleRuns'> {\n const styleRuns = pinnedRunBindingScales(node, fields)\n if (!styleRuns) return {}\n node.styleRuns = styleRuns\n return { styleRuns }\n}\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 const pruned = Object.keys(node.variableBindingScales).filter(\n (field) => !(field in node.boundVariables)\n )\n const runs = pinRunBindingScales(node, pruned)\n node.variableBindingScales = omit(node.variableBindingScales, pruned)\n graph.emitter.emit('node:updated', node.id, {\n boundVariables: { ...node.boundVariables },\n variableBindingScales: { ...node.variableBindingScales },\n ...runs\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 // A layer that chose one of its modes has nothing left to choose from.\n for (const node of graph.nodes.values()) {\n if (!(id in node.variableModes)) continue\n const variableModes = omit(node.variableModes, [id])\n graph.willChangeNode(node)\n node.variableModes = variableModes\n graph.emitter.emit('node:updated', node.id, { variableModes })\n }\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 // The next default is the next listed mode, as Figma picks it, not the next saved entry.\n collection.defaultModeId = modesInListedOrder(collection)[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 // A layer that chose the mode goes back to the collection's default, and an instance keeps no\n // override naming a mode that is gone, which would otherwise come back on a later sync.\n const overrideField = variableModeOverrideField(collectionId)\n for (const node of graph.nodes.values()) {\n if (node.variableModes[collectionId] !== modeId) continue\n const variableModes = omit(node.variableModes, [collectionId])\n graph.willChangeNode(node)\n node.variableModes = variableModes\n node.instanceOverrides.self.delete(overrideField)\n for (const overrides of node.instanceOverrides.descendants.values())\n overrides.delete(overrideField)\n graph.emitter.emit('node:updated', node.id, { variableModes })\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 if (collection.modes.every((mode) => !mode.sortPosition)) {\n // No sort positions carry an order of their own: the array is the order, so the new\n // default moves first in it, as a collection created here has always done.\n collection.modes = modesDefaultFirst(collection)\n return\n }\n // The saved array order stays the file's own; the new default sorts first by its sort\n // position, so the listed order shows it first and a re-import reads it as the default.\n const listed = modesDefaultFirst(collection)\n const positions = siblingOrderKeys(listed.map((mode) => mode.sortPosition))\n const byId = new Map(listed.map((mode, index) => [mode.modeId, positions[index]]))\n collection.modes = collection.modes.map((mode) => ({\n ...mode,\n sortPosition: byId.get(mode.modeId) ?? mode.sortPosition\n }))\n}\n\n/** Figma has no default-mode field: the first listed mode is the default. */\nexport function modesDefaultFirst(collection: VariableCollection): VariableCollectionMode[] {\n const [defaults, rest] = partition(\n modesInListedOrder(collection),\n (m) => m.modeId === collection.defaultModeId\n )\n return [...defaults, ...rest]\n}\n\n/**\n * The modes as Figma lists them: by `sortPosition`, modes without one following in saved order.\n * The collection's own array keeps the file's saved order, which an export writes back as it was.\n */\nexport function modesInListedOrder(collection: VariableCollection): VariableCollectionMode[] {\n return sortBy(collection.modes, [(mode) => !mode.sortPosition, (mode) => mode.sortPosition ?? ''])\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\nconst PAINT_BINDING_LISTS = ['fills', 'strokes'] as const satisfies readonly PaintBindingList[]\n\n/**\n * Every field a binding takes, from the same sets `checkBindingFieldType` reads, so a refusal for\n * an unknown one names what the caller can send instead of leaving them to guess.\n */\nconst ACCEPTED_BINDING_FIELDS: readonly string[] = [\n ...NUMERIC_FIELDS,\n ...STRING_BINDING_FIELDS,\n ...BOOLEAN_BINDING_FIELDS,\n ...ICON_BINDING_FIELDS,\n ...PAINT_BINDING_LISTS.flatMap((list) => [`${list}/<n>/color`, `${list}/<n>/uniforms/<name>`])\n]\n\n/**\n * Throws when a variable of `type` cannot bind to `field`, or for a field no binding takes. A\n * paint target is checked by its caller, which also validates its index.\n */\nfunction checkBindingFieldType(field: string, type: VariableType): void {\n if (isNumericVariableBindingField(field) && type !== 'FLOAT') {\n throw new Error(`Cannot bind ${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(type)) {\n throw new Error(`Cannot bind ${type} variable to string field \"${field}\"`)\n }\n\n if (\n BOOLEAN_BINDING_FIELDS.has(field) &&\n !VISIBILITY_VARIABLE_TYPES.some((kind) => kind === type)\n ) {\n throw new Error(`Cannot bind ${type} variable to boolean field \"${field}\"`)\n }\n\n if (ICON_BINDING_FIELDS.has(field) && type !== 'STRING') {\n throw new Error(`Cannot bind ${type} variable to icon field \"${field}\"`)\n }\n\n // A shader uniform takes a number, a colour, or a boolean; its shader declares which.\n const uniform = uniformBindingTarget(field)\n if (uniform && type !== 'FLOAT' && type !== 'COLOR' && type !== 'BOOLEAN') {\n throw new Error(`Cannot bind ${type} variable to shader input \"${field}\"`)\n }\n\n const isKnownField =\n isNumericVariableBindingField(field) ||\n STRING_BINDING_FIELDS.has(field) ||\n BOOLEAN_BINDING_FIELDS.has(field) ||\n ICON_BINDING_FIELDS.has(field) ||\n paintBindingTarget(field) !== null ||\n uniform !== null\n\n if (!isKnownField) {\n throw new Error(\n `Unknown binding field \"${field}\". Accepted: ${ACCEPTED_BINDING_FIELDS.join(', ')}`\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) {\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 graph.willChangeNode(node)\n node.boundVariables = omit(node.boundVariables, [paint.list])\n }\n }\n\n checkBindingFieldType(field, variable.type)\n\n // A shader input belongs to one paint, so its index must exist on the layer.\n const uniform = uniformBindingTarget(field)\n if (uniform && uniform.index >= node[uniform.list].length) {\n throw new Error(\n `Index ${uniform.index} out of range for ${uniform.list} (length ${node[uniform.list].length})`\n )\n }\n if (uniform) {\n // The binding lives with the shader entry, next to the value it resolves, so any renderer\n // that draws the paint resolves it the same way.\n const paints = node[uniform.list]\n const paint = paints.at(uniform.index)\n const shader = paint ? shaderOfPaint(node, paint) : null\n if (paint && shader && isShaderSourcePaint(shader)) {\n node.pluginData = withShaderPaints(node, paints, [\n {\n ...shader,\n uniformBindings: {\n ...shader.uniformBindings,\n [uniform.name]: variableId\n }\n }\n ])\n }\n graph.willChangeNode(node)\n graph.emitter.emit('node:updated', nodeId, {\n pluginData: node.pluginData,\n boundVariables: { ...node.boundVariables },\n variableBindingScales: { ...node.variableBindingScales }\n })\n return\n }\n graph.willChangeNode(node)\n node.boundVariables = { ...node.boundVariables, [field]: variableId }\n const runs = pinRunBindingScales(node, [field])\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 ...runs\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 const runs = pinRunBindingScales(node, [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 ...runs\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 instances)\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 './units'\nexport * from './value'\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8CA,SAAS,oBACP,MACA,QACuC;CACvC,MAAM,YAAY,uBAAuB,MAAM,MAAM;CACrD,IAAI,CAAC,WAAW,OAAO,CAAC;CACxB,KAAK,YAAY;CACjB,OAAO,EAAE,UAAU;AACrB;AAEA,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,WA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MAAM,OAAO,oBAAoB,MAAM,CAAC,KAAK,CAAC;CAC9C,KAAK,wBAAwB,KAAK,KAAK,uBAAuB,CAAC,KAAK,CAAC;CACrE,qCAAqC,OAAO,QAAQ,KAAK;CACzD,MAAM,QAAQ,KAAK,gBAAgB,QAAQ;EACzC,gBAAgB,EAAE,GAAG,KAAK,eAAe;EACzC,uBAAuB,EAAE,GAAG,KAAK,sBAAsB;EACvD,GAAG;CACL,CAAC;AACH;AAEA,SAAS,qCACP,OACA,QACA,OACM;CACN,MAAM,OAAO,MAAM,MAAM,IAAI,MAAM;CACnC,IAAI,CAAC,MAAM;CAEX,MAAM,QAAQ,qBAAqB,OAAO,IAAI;CAC9C,IAAI,MAAM,SAAS,YAAY;CAC/B,MAAM,UAAU,qBAAqB,OAAO,MAAM;CAClD,MAAM,YAAY,KAAK,QAAQ,CAAC,SAAS,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,MAAM,EAAE,OAAO,MAAM;CAC/E,KAAK,MAAM,YAAY,WAAW,MAAM,eAAe,QAAQ;CAC/D,IAAI,SAAS,oBAAoB,QAAQ,mBAAmB,QAAQ,IAAI,QAAQ,gBAAgB;CAChG,oBAAoB,MAAM,mBAAmB,MAAM,IAAI,QAAQ,gBAAgB;CAG/E,IAAI,OACF,KAAK,MAAM,YAAY,WACrB,oBACE,SAAS,mBACT,SAAS,IACT,QACA,qBAAqB,KAAK,GAC1B,KAAK,eAAe,UAAU,IAChC;CACJ,KAAK,MAAM,YAAY,WACrB,MAAM,WAAW,SAAS,IAAI,EAAE,mBAAmB,SAAS,kBAAkB,CAAC;AACnF"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/variables/index.ts"],"sourcesContent":["import { compact, partition, sortBy, 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 {\n bindingOverrideField,\n ownInstanceOverrides,\n setInstanceOverride,\n variableModeOverrideField\n} from '../instances/overrides'\nimport { siblingOrderKeys } from '../order-keys'\nimport { isShaderSourcePaint, shaderOfPaint, withShaderPaints } from '../shaders/model'\nimport type {\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 ICON_BINDING_FIELDS,\n NUMERIC_FIELDS,\n paintBindingTarget,\n STRING_BINDING_FIELDS,\n TEXT_CONTENT_VARIABLE_TYPES,\n uniformBindingTarget,\n VISIBILITY_VARIABLE_TYPES,\n type PaintBindingList\n} from './fields'\nimport { applyBoundPaintColor } from './paints'\nimport { pinnedRunBindingScales } from './units'\n\nexport * from './resolution'\nexport * from './resolver'\n\n/**\n * Variables a list shows: every one but those deleted, on their own or with their collection,\n * which only their bindings still reach.\n */\nexport function liveVariables(graph: SceneGraph): Variable[] {\n return [...graph.variables.values()].filter(\n (variable) =>\n !variable.deleted && !graph.variableCollections.get(variable.collectionId)?.deleted\n )\n}\n\n/** Collections a list shows: every one but those deleted. */\nexport function liveCollections(graph: SceneGraph): VariableCollection[] {\n return [...graph.variableCollections.values()].filter((collection) => !collection.deleted)\n}\n\n/**\n * A collection's deleted variables, which its `variableIds` leave out. A deleted collection's\n * variables are all deleted.\n */\nexport function deletedVariablesOf(graph: SceneGraph, collectionId: string): Variable[] {\n return [...graph.variables.values()].filter(\n (variable) => variable.collectionId === collectionId && variable.deleted\n )\n}\n\n/**\n * Gives the runs that bind `fields` the scale they resolve with as their own, before the layer's\n * scale for those fields changes or goes, and the change to announce.\n */\nfunction pinRunBindingScales(\n node: SceneNode,\n fields: readonly string[]\n): Pick<Partial<SceneNode>, 'styleRuns'> {\n const styleRuns = pinnedRunBindingScales(node, fields)\n if (!styleRuns) return {}\n node.styleRuns = styleRuns\n return { styleRuns }\n}\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) return\n // A collection lists its live variables, so one replaced by its deleted record leaves the list.\n if (collection.variableIds.includes(variable.id) === !variable.deleted) return\n collection.variableIds = variable.deleted\n ? collection.variableIds.filter((id) => id !== variable.id)\n : [...collection.variableIds, variable.id]\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 const pruned = Object.keys(node.variableBindingScales).filter(\n (field) => !(field in node.boundVariables)\n )\n const runs = pinRunBindingScales(node, pruned)\n node.variableBindingScales = omit(node.variableBindingScales, pruned)\n graph.emitter.emit('node:updated', node.id, {\n boundVariables: { ...node.boundVariables },\n variableBindingScales: { ...node.variableBindingScales },\n ...runs\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 for (const variable of deletedVariablesOf(graph, id)) removeVariable(graph, variable.id)\n }\n graph.variableCollections.delete(id)\n graph.activeMode.delete(id)\n // A layer that chose one of its modes has nothing left to choose from.\n for (const node of graph.nodes.values()) {\n if (!(id in node.variableModes)) continue\n const variableModes = omit(node.variableModes, [id])\n graph.willChangeNode(node)\n node.variableModes = variableModes\n graph.emitter.emit('node:updated', node.id, { variableModes })\n }\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 // The next default is the next listed mode, as Figma picks it, not the next saved entry.\n collection.defaultModeId = modesInListedOrder(collection)[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 // A layer that chose the mode goes back to the collection's default, and an instance keeps no\n // override naming a mode that is gone, which would otherwise come back on a later sync.\n const overrideField = variableModeOverrideField(collectionId)\n for (const node of graph.nodes.values()) {\n if (node.variableModes[collectionId] !== modeId) continue\n const variableModes = omit(node.variableModes, [collectionId])\n graph.willChangeNode(node)\n node.variableModes = variableModes\n const state = node.instanceOverrides\n const claimsMode =\n state.self.has(overrideField) ||\n [...state.descendants.values()].some((fields) => fields.has(overrideField))\n if (claimsMode) {\n const owned = ownInstanceOverrides(node)\n owned.self.delete(overrideField)\n for (const overrides of owned.descendants.values()) overrides.delete(overrideField)\n }\n graph.emitter.emit('node:updated', node.id, { variableModes })\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 if (collection.modes.every((mode) => !mode.sortPosition)) {\n // No sort positions carry an order of their own: the array is the order, so the new\n // default moves first in it, as a collection created here has always done.\n collection.modes = modesDefaultFirst(collection)\n return\n }\n // The saved array order stays the file's own; the new default sorts first by its sort\n // position, so the listed order shows it first and a re-import reads it as the default.\n const listed = modesDefaultFirst(collection)\n const positions = siblingOrderKeys(listed.map((mode) => mode.sortPosition))\n const byId = new Map(listed.map((mode, index) => [mode.modeId, positions[index]]))\n collection.modes = collection.modes.map((mode) => ({\n ...mode,\n sortPosition: byId.get(mode.modeId) ?? mode.sortPosition\n }))\n}\n\n/** Figma has no default-mode field: the first listed mode is the default. */\nexport function modesDefaultFirst(collection: VariableCollection): VariableCollectionMode[] {\n const [defaults, rest] = partition(\n modesInListedOrder(collection),\n (m) => m.modeId === collection.defaultModeId\n )\n return [...defaults, ...rest]\n}\n\n/**\n * The modes as Figma lists them: by `sortPosition`, modes without one following in saved order.\n * The collection's own array keeps the file's saved order, which an export writes back as it was.\n */\nexport function modesInListedOrder(collection: VariableCollection): VariableCollectionMode[] {\n return sortBy(collection.modes, [(mode) => !mode.sortPosition, (mode) => mode.sortPosition ?? ''])\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 liveVariables(graph).filter((v) => v.type === type)\n}\n\nconst PAINT_BINDING_LISTS = ['fills', 'strokes'] as const satisfies readonly PaintBindingList[]\n\n/**\n * Every field a binding takes, from the same sets `checkBindingFieldType` reads, so a refusal for\n * an unknown one names what the caller can send instead of leaving them to guess.\n */\nconst ACCEPTED_BINDING_FIELDS: readonly string[] = [\n ...NUMERIC_FIELDS,\n ...STRING_BINDING_FIELDS,\n ...BOOLEAN_BINDING_FIELDS,\n ...ICON_BINDING_FIELDS,\n ...PAINT_BINDING_LISTS.flatMap((list) => [`${list}/<n>/color`, `${list}/<n>/uniforms/<name>`])\n]\n\n/**\n * Throws when a variable of `type` cannot bind to `field`, or for a field no binding takes. A\n * paint target is checked by its caller, which also validates its index.\n */\nfunction checkBindingFieldType(field: string, type: VariableType): void {\n if (isNumericVariableBindingField(field) && type !== 'FLOAT') {\n throw new Error(`Cannot bind ${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(type)) {\n throw new Error(`Cannot bind ${type} variable to string field \"${field}\"`)\n }\n\n if (\n BOOLEAN_BINDING_FIELDS.has(field) &&\n !VISIBILITY_VARIABLE_TYPES.some((kind) => kind === type)\n ) {\n throw new Error(`Cannot bind ${type} variable to boolean field \"${field}\"`)\n }\n\n if (ICON_BINDING_FIELDS.has(field) && type !== 'STRING') {\n throw new Error(`Cannot bind ${type} variable to icon field \"${field}\"`)\n }\n\n // A shader uniform takes a number, a colour, or a boolean; its shader declares which.\n const uniform = uniformBindingTarget(field)\n if (uniform && type !== 'FLOAT' && type !== 'COLOR' && type !== 'BOOLEAN') {\n throw new Error(`Cannot bind ${type} variable to shader input \"${field}\"`)\n }\n\n const isKnownField =\n isNumericVariableBindingField(field) ||\n STRING_BINDING_FIELDS.has(field) ||\n BOOLEAN_BINDING_FIELDS.has(field) ||\n ICON_BINDING_FIELDS.has(field) ||\n paintBindingTarget(field) !== null ||\n uniform !== null\n\n if (!isKnownField) {\n throw new Error(\n `Unknown binding field \"${field}\". Accepted: ${ACCEPTED_BINDING_FIELDS.join(', ')}`\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) {\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 graph.willChangeNode(node)\n node.boundVariables = omit(node.boundVariables, [paint.list])\n }\n }\n\n checkBindingFieldType(field, variable.type)\n\n // A shader input belongs to one paint, so its index must exist on the layer.\n const uniform = uniformBindingTarget(field)\n if (uniform && uniform.index >= node[uniform.list].length) {\n throw new Error(\n `Index ${uniform.index} out of range for ${uniform.list} (length ${node[uniform.list].length})`\n )\n }\n if (uniform) {\n // The binding lives with the shader entry, next to the value it resolves, so any renderer\n // that draws the paint resolves it the same way.\n const paints = node[uniform.list]\n const paint = paints.at(uniform.index)\n const shader = paint ? shaderOfPaint(node, paint) : null\n if (paint && shader && isShaderSourcePaint(shader)) {\n node.pluginData = withShaderPaints(node, paints, [\n {\n ...shader,\n uniformBindings: {\n ...shader.uniformBindings,\n [uniform.name]: variableId\n }\n }\n ])\n }\n graph.willChangeNode(node)\n graph.emitter.emit('node:updated', nodeId, {\n pluginData: node.pluginData,\n boundVariables: { ...node.boundVariables },\n variableBindingScales: { ...node.variableBindingScales }\n })\n return\n }\n graph.willChangeNode(node)\n node.boundVariables = { ...node.boundVariables, [field]: variableId }\n const runs = pinRunBindingScales(node, [field])\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 ...runs\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 const runs = pinRunBindingScales(node, [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 ...runs\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)\n setInstanceOverride(ownInstanceOverrides(nearest), nearest.id, nodeId, 'boundVariables')\n setInstanceOverride(ownInstanceOverrides(owner), 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 instances)\n setInstanceOverride(\n ownInstanceOverrides(instance),\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 './units'\nexport * from './value'\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDA,SAAgB,cAAc,OAA+B;CAC3D,OAAO,CAAC,GAAG,MAAM,UAAU,OAAO,CAAC,CAAC,CAAC,QAClC,aACC,CAAC,SAAS,WAAW,CAAC,MAAM,oBAAoB,IAAI,SAAS,YAAY,CAAC,EAAE,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uB,EAAE,GAAG,KAAK,sBAAsB;EACvD,GAAG;CACL,CAAC;AACH;AAEA,SAAS,qCACP,OACA,QACA,OACM;CACN,MAAM,OAAO,MAAM,MAAM,IAAI,MAAM;CACnC,IAAI,CAAC,MAAM;CAEX,MAAM,QAAQ,qBAAqB,OAAO,IAAI;CAC9C,IAAI,MAAM,SAAS,YAAY;CAC/B,MAAM,UAAU,qBAAqB,OAAO,MAAM;CAClD,MAAM,YAAY,KAAK,QAAQ,CAAC,SAAS,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,MAAM,EAAE,OAAO,MAAM;CAC/E,KAAK,MAAM,YAAY,WAAW,MAAM,eAAe,QAAQ;CAC/D,IAAI,SACF,oBAAoB,qBAAqB,OAAO,GAAG,QAAQ,IAAI,QAAQ,gBAAgB;CACzF,oBAAoB,qBAAqB,KAAK,GAAG,MAAM,IAAI,QAAQ,gBAAgB;CAGnF,IAAI,OACF,KAAK,MAAM,YAAY,WACrB,oBACE,qBAAqB,QAAQ,GAC7B,SAAS,IACT,QACA,qBAAqB,KAAK,GAC1B,KAAK,eAAe,UAAU,IAChC;CACJ,KAAK,MAAM,YAAY,WACrB,MAAM,WAAW,SAAS,IAAI,EAAE,mBAAmB,SAAS,kBAAkB,CAAC;AACnF"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Color } from "../primitives/index.js";
|
|
2
|
+
import { VariableResolver } from "./resolver.js";
|
|
2
3
|
import { PaintBindingList } from "./fields.js";
|
|
3
4
|
import { SceneGraph } from "../graph.js";
|
|
4
5
|
import { SceneNode } from "../types.js";
|
|
@@ -58,36 +59,36 @@ declare function copiesComponentPaints(graph: SceneGraph, node: SceneNode, list:
|
|
|
58
59
|
* opacity, once that color differs from the one last applied, discarding edits made since, as
|
|
59
60
|
* Figma refreshes them when a variable's value or a layer's mode changes.
|
|
60
61
|
*/
|
|
61
|
-
declare function refreshBoundPaints(graph: SceneGraph, node: SceneNode): void;
|
|
62
|
+
declare function refreshBoundPaints(graph: SceneGraph, node: SceneNode, resolver?: VariableResolver): void;
|
|
62
63
|
/** Gives one bound paint its variable's color for the layer, as binding it does in Figma. */
|
|
63
|
-
declare function applyBoundPaintColor(graph: SceneGraph, node: SceneNode, field: string): void;
|
|
64
|
+
declare function applyBoundPaintColor(graph: SceneGraph, node: SceneNode, field: string, resolver?: VariableResolver): void;
|
|
64
65
|
/**
|
|
65
66
|
* Gives every bound paint in this subtree its variable's color where it sits. A new instance
|
|
66
67
|
* or a layer an instance sync adds is a copy, which shows its variables in its own context rather
|
|
67
68
|
* than whatever its component's paints hold.
|
|
68
69
|
*/
|
|
69
|
-
declare function applyBoundPaintColorsIn(graph: SceneGraph, rootId: string): void;
|
|
70
|
+
declare function applyBoundPaintColorsIn(graph: SceneGraph, rootId: string, resolver?: VariableResolver): void;
|
|
70
71
|
/** Refreshes the bound paints in this subtree whose variables now give their layers another color. */
|
|
71
|
-
declare function refreshBoundPaintsIn(graph: SceneGraph, rootId: string): void;
|
|
72
|
+
declare function refreshBoundPaintsIn(graph: SceneGraph, rootId: string, resolver?: VariableResolver): void;
|
|
72
73
|
/**
|
|
73
74
|
* Records, for the paint lists a write sets, the colors their variables give the layer now, so a
|
|
74
75
|
* paint written with another color or opacity keeps it until that color changes.
|
|
75
76
|
*/
|
|
76
|
-
declare function recordWrittenBoundPaints(graph: SceneGraph, node: SceneNode, written: PaintLists): void;
|
|
77
|
+
declare function recordWrittenBoundPaints(graph: SceneGraph, node: SceneNode, written: PaintLists, resolver?: VariableResolver): void;
|
|
77
78
|
/**
|
|
78
79
|
* The fills and strokes a layer shows: its stored paints, except a bound paint no applied color
|
|
79
80
|
* vouches for takes its variable's color for the layer, alpha as opacity, as Figma shows a layer
|
|
80
81
|
* whose saved cache is stale on import. Nothing is written or recorded; a copy pasted unlinked
|
|
81
82
|
* keeps the colors it showed.
|
|
82
83
|
*/
|
|
83
|
-
declare function shownPaintBindings(graph: SceneGraph, node: SceneNode): Pick<Partial<SceneNode>, 'fills' | 'strokes'>;
|
|
84
|
+
declare function shownPaintBindings(graph: SceneGraph, node: SceneNode, resolver?: VariableResolver): Pick<Partial<SceneNode>, 'fills' | 'strokes'>;
|
|
84
85
|
/**
|
|
85
86
|
* Refreshes the bound paints in a moved layer's subtree that resolve through a collection whose
|
|
86
87
|
* mode set the move changed, as Figma does when a layer enters a frame or page that sets another
|
|
87
88
|
* mode, or one where none was. A move between parents setting the same modes, or of layers that
|
|
88
89
|
* bind no paint, costs no more than comparing those modes.
|
|
89
90
|
*/
|
|
90
|
-
declare function refreshMovedBoundPaints(graph: SceneGraph, nodeId: string, previousParentId: string | null | undefined): void;
|
|
91
|
+
declare function refreshMovedBoundPaints(graph: SceneGraph, nodeId: string, previousParentId: string | null | undefined, resolver?: VariableResolver): void;
|
|
91
92
|
/**
|
|
92
93
|
* A copy's bound paints are its own cache, as Figma keeps them per layer, so a component's edit
|
|
93
94
|
* to its paint's color or opacity does not reach them. An instance sync writing a copy's paints
|
|
@@ -95,7 +96,7 @@ declare function refreshMovedBoundPaints(graph: SceneGraph, nodeId: string, prev
|
|
|
95
96
|
* variable's color for the copy once that differs from the one last applied, or when it binds
|
|
96
97
|
* anew. `updates` holds what the sync writes, whose paints this sets in place.
|
|
97
98
|
*/
|
|
98
|
-
declare function keepCopyBoundPaints(graph: SceneGraph, target: SceneNode, updates: Partial<SceneNode
|
|
99
|
+
declare function keepCopyBoundPaints(graph: SceneGraph, target: SceneNode, updates: Partial<SceneNode>, resolver?: VariableResolver): void;
|
|
99
100
|
//#endregion
|
|
100
101
|
export { AppliedBoundPaints, AppliedColor, applyBoundPaintColor, applyBoundPaintColorsIn, captureAppliedBoundPaints, copiesComponentPaints, copyAppliedBoundPaints, hasBoundPaints, keepCopyBoundPaints, keepPastedBoundPaints, paintColorApplied, recordWrittenBoundPaints, refreshBoundPaints, refreshBoundPaintsIn, refreshMovedBoundPaints, shownPaintBindings };
|
|
101
102
|
//# sourceMappingURL=paints.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paints.d.ts","names":[],"sources":["../../src/variables/paints.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"paints.d.ts","names":[],"sources":["../../src/variables/paints.ts"],"mappings":";;;;;;;;;;;;;;;UAoBiB;WACN;WACA,OAAO;;WAEP,OAAO,SAAS;;;iBAyBX,eAAe,MAAM;;;;;;iBAUrB,kBAAkB,MAAM,WAAW;;;;;iBAuDnC,uBAAuB,QAAQ,WAAW,MAAM;;KAMpD,qBAAqB,oBAAoB,oBAAoB;;;;;iBAMzD,0BACd,OAAO,YACP,SAAS,mBACR;;;;;;;;iBAiBa,sBACd,OAAO,YACP,QAAQ,6BACR,SAAS;KAwCN,aAAa,KAAK,QAAQ;;;;;;iBAOf,sBACd,OAAO,YACP,MAAM,WACN,MAAM;;;;;;iBAmEQ,mBACd,OAAO,YACP,MAAM,WACN,WAAW;;iBAMG,qBACd,OAAO,YACP,MAAM,WACN,eACA,WAAW;;;;;;iBAUG,wBACd,OAAO,YACP,gBACA,WAAW;;iBAQG,qBACd,OAAO,YACP,gBACA,WAAW;;;;;iBAUG,yBACd,OAAO,YACP,MAAM,WACN,SAAS,YACT,WAAW;;;;;;;iBAiBG,mBACd,OAAO,YACP,MAAM,WACN,WAAW,mBACV,KAAK,QAAQ;;;;;;;iBAyBA,wBACd,OAAO,YACP,gBACA,6CACA,WAAW;;;;;;;;iBA+CG,oBACd,OAAO,YACP,QAAQ,WACR,SAAS,QAAQ,YACjB,WAAW"}
|
package/dist/variables/paints.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { hasInstanceOverride } from "../instances/overrides.js";
|
|
2
2
|
import { copyFills, copyStrokes } from "../copy.js";
|
|
3
3
|
import { paintBindingTarget } from "./fields.js";
|
|
4
|
-
import {
|
|
4
|
+
import { createVariableResolver } from "./resolver.js";
|
|
5
5
|
import { subtreeNodes } from "./subtree.js";
|
|
6
6
|
import { isEqual } from "es-toolkit/predicate";
|
|
7
7
|
//#region src/variables/paints.ts
|
|
@@ -51,9 +51,10 @@ function sameColor(a, b) {
|
|
|
51
51
|
* The modes set for a layer, or null, in the collections a variable resolves through. Figma
|
|
52
52
|
* refreshes a bound paint whenever one of them changes, even to a mode giving the same color.
|
|
53
53
|
*/
|
|
54
|
-
function explicitModes(graph, node, variableId) {
|
|
54
|
+
function explicitModes(graph, node, variableId, resolver) {
|
|
55
55
|
const modes = {};
|
|
56
|
-
|
|
56
|
+
const shared = resolver ?? createVariableResolver(graph);
|
|
57
|
+
for (const collectionId of shared.dependencies([variableId])) modes[collectionId] = shared.explicitModeFor(node.id, collectionId);
|
|
57
58
|
return modes;
|
|
58
59
|
}
|
|
59
60
|
/** Whether the color a binding last applied is stale: another color, or set in other modes. */
|
|
@@ -158,14 +159,15 @@ function writePaints(graph, node, changes) {
|
|
|
158
159
|
* Writes into each bound paint the color its variable gives the layer now, where that differs
|
|
159
160
|
* from the color last applied, or wherever `forced` says, and records what each binding gives.
|
|
160
161
|
*/
|
|
161
|
-
function refresh(graph, node, forced) {
|
|
162
|
+
function refresh(graph, node, forced, resolver) {
|
|
162
163
|
let fills;
|
|
163
164
|
let strokes;
|
|
165
|
+
const reader = (resolver ?? createVariableResolver(graph)).forNode(node.id);
|
|
164
166
|
for (const bound of boundPaints(node)) {
|
|
165
|
-
const color =
|
|
167
|
+
const color = reader.color(bound.variableId);
|
|
166
168
|
const paint = node[bound.list].at(bound.index);
|
|
167
169
|
if (!color || !paint) continue;
|
|
168
|
-
const modes = explicitModes(graph, node, bound.variableId);
|
|
170
|
+
const modes = explicitModes(graph, node, bound.variableId, resolver);
|
|
169
171
|
const stale = staleApplied(node, bound, paint, color, modes);
|
|
170
172
|
recordApplied(node, bound, color, modes);
|
|
171
173
|
if (!forced(bound.field) && !stale || showsColor(paint, color)) continue;
|
|
@@ -189,34 +191,37 @@ const ALL_FORCED = () => true;
|
|
|
189
191
|
* opacity, once that color differs from the one last applied, discarding edits made since, as
|
|
190
192
|
* Figma refreshes them when a variable's value or a layer's mode changes.
|
|
191
193
|
*/
|
|
192
|
-
function refreshBoundPaints(graph, node) {
|
|
193
|
-
if (hasBoundPaints(node)) refresh(graph, node, NONE_FORCED);
|
|
194
|
+
function refreshBoundPaints(graph, node, resolver) {
|
|
195
|
+
if (hasBoundPaints(node)) refresh(graph, node, NONE_FORCED, resolver);
|
|
194
196
|
}
|
|
195
197
|
/** Gives one bound paint its variable's color for the layer, as binding it does in Figma. */
|
|
196
|
-
function applyBoundPaintColor(graph, node, field) {
|
|
197
|
-
if (paintBindingTarget(field)) refresh(graph, node, (bound) => bound === field);
|
|
198
|
+
function applyBoundPaintColor(graph, node, field, resolver) {
|
|
199
|
+
if (paintBindingTarget(field)) refresh(graph, node, (bound) => bound === field, resolver);
|
|
198
200
|
}
|
|
199
201
|
/**
|
|
200
202
|
* Gives every bound paint in this subtree its variable's color where it sits. A new instance
|
|
201
203
|
* or a layer an instance sync adds is a copy, which shows its variables in its own context rather
|
|
202
204
|
* than whatever its component's paints hold.
|
|
203
205
|
*/
|
|
204
|
-
function applyBoundPaintColorsIn(graph, rootId) {
|
|
205
|
-
|
|
206
|
+
function applyBoundPaintColorsIn(graph, rootId, resolver) {
|
|
207
|
+
const shared = resolver ?? createVariableResolver(graph);
|
|
208
|
+
for (const node of subtreeNodes(graph, [rootId])) if (hasBoundPaints(node)) refresh(graph, node, ALL_FORCED, shared);
|
|
206
209
|
}
|
|
207
210
|
/** Refreshes the bound paints in this subtree whose variables now give their layers another color. */
|
|
208
|
-
function refreshBoundPaintsIn(graph, rootId) {
|
|
209
|
-
|
|
211
|
+
function refreshBoundPaintsIn(graph, rootId, resolver) {
|
|
212
|
+
const shared = resolver ?? createVariableResolver(graph);
|
|
213
|
+
for (const node of subtreeNodes(graph, [rootId])) refreshBoundPaints(graph, node, shared);
|
|
210
214
|
}
|
|
211
215
|
/**
|
|
212
216
|
* Records, for the paint lists a write sets, the colors their variables give the layer now, so a
|
|
213
217
|
* paint written with another color or opacity keeps it until that color changes.
|
|
214
218
|
*/
|
|
215
|
-
function recordWrittenBoundPaints(graph, node, written) {
|
|
219
|
+
function recordWrittenBoundPaints(graph, node, written, resolver) {
|
|
220
|
+
const reader = (resolver ?? createVariableResolver(graph)).forNode(node.id);
|
|
216
221
|
for (const bound of boundPaints(node)) {
|
|
217
222
|
if (!written[bound.list]) continue;
|
|
218
|
-
const color =
|
|
219
|
-
if (color) recordApplied(node, bound, color, explicitModes(graph, node, bound.variableId));
|
|
223
|
+
const color = reader.color(bound.variableId);
|
|
224
|
+
if (color) recordApplied(node, bound, color, explicitModes(graph, node, bound.variableId, resolver));
|
|
220
225
|
}
|
|
221
226
|
}
|
|
222
227
|
/**
|
|
@@ -225,11 +230,12 @@ function recordWrittenBoundPaints(graph, node, written) {
|
|
|
225
230
|
* whose saved cache is stale on import. Nothing is written or recorded; a copy pasted unlinked
|
|
226
231
|
* keeps the colors it showed.
|
|
227
232
|
*/
|
|
228
|
-
function shownPaintBindings(graph, node) {
|
|
233
|
+
function shownPaintBindings(graph, node, resolver) {
|
|
229
234
|
const changes = {};
|
|
235
|
+
const reader = (resolver ?? createVariableResolver(graph)).forNode(node.id);
|
|
230
236
|
for (const bound of boundPaints(node)) {
|
|
231
237
|
if (paintColorApplied(node, bound.field)) continue;
|
|
232
|
-
const color =
|
|
238
|
+
const color = reader.color(bound.variableId);
|
|
233
239
|
const paint = node[bound.list].at(bound.index);
|
|
234
240
|
if (!color || !paint || showsColor(paint, color)) continue;
|
|
235
241
|
if (bound.list === "fills") {
|
|
@@ -248,23 +254,24 @@ function shownPaintBindings(graph, node) {
|
|
|
248
254
|
* mode, or one where none was. A move between parents setting the same modes, or of layers that
|
|
249
255
|
* bind no paint, costs no more than comparing those modes.
|
|
250
256
|
*/
|
|
251
|
-
function refreshMovedBoundPaints(graph, nodeId, previousParentId) {
|
|
257
|
+
function refreshMovedBoundPaints(graph, nodeId, previousParentId, resolver) {
|
|
252
258
|
if (graph.isApplyingImportedState || graph.variableCollections.size === 0) return;
|
|
253
259
|
const parentId = graph.nodes.get(nodeId)?.parentId;
|
|
254
260
|
if (!parentId) return;
|
|
255
261
|
const previous = previousParentId && graph.nodes.has(previousParentId) ? previousParentId : null;
|
|
256
|
-
const
|
|
262
|
+
const shared = resolver ?? createVariableResolver(graph);
|
|
263
|
+
const changed = new Set([...graph.variableCollections.keys()].filter((id) => !previous || shared.explicitModeFor(previous, id) !== shared.explicitModeFor(parentId, id)));
|
|
257
264
|
if (changed.size === 0) return;
|
|
258
265
|
const reaches = /* @__PURE__ */ new Map();
|
|
259
266
|
const reachesChanged = (variableId) => {
|
|
260
267
|
let found = reaches.get(variableId);
|
|
261
268
|
if (found === void 0) {
|
|
262
|
-
found = [...
|
|
269
|
+
found = [...shared.dependencies([variableId])].some((id) => changed.has(id));
|
|
263
270
|
reaches.set(variableId, found);
|
|
264
271
|
}
|
|
265
272
|
return found;
|
|
266
273
|
};
|
|
267
|
-
for (const node of subtreeNodes(graph, [nodeId])) if (boundPaints(node).some((bound) => reachesChanged(bound.variableId))) refresh(graph, node, NONE_FORCED);
|
|
274
|
+
for (const node of subtreeNodes(graph, [nodeId])) if (boundPaints(node).some((bound) => reachesChanged(bound.variableId))) refresh(graph, node, NONE_FORCED, shared);
|
|
268
275
|
}
|
|
269
276
|
function reboundPaint(target, bindings, list) {
|
|
270
277
|
return target[list].some((_, index) => {
|
|
@@ -279,8 +286,10 @@ function reboundPaint(target, bindings, list) {
|
|
|
279
286
|
* variable's color for the copy once that differs from the one last applied, or when it binds
|
|
280
287
|
* anew. `updates` holds what the sync writes, whose paints this sets in place.
|
|
281
288
|
*/
|
|
282
|
-
function keepCopyBoundPaints(graph, target, updates) {
|
|
289
|
+
function keepCopyBoundPaints(graph, target, updates, resolver) {
|
|
283
290
|
const bindings = updates.boundVariables ?? target.boundVariables;
|
|
291
|
+
const shared = resolver ?? createVariableResolver(graph);
|
|
292
|
+
const reader = shared.forNode(target.id);
|
|
284
293
|
for (const list of PAINT_LISTS) {
|
|
285
294
|
if (!updates[list] && reboundPaint(target, bindings, list)) Object.assign(updates, { [list]: list === "fills" ? copyFills(target.fills) : copyStrokes(target.strokes) });
|
|
286
295
|
updates[list]?.forEach((paint, index) => {
|
|
@@ -299,9 +308,9 @@ function keepCopyBoundPaints(graph, target, updates) {
|
|
|
299
308
|
paint.color = { ...own.color };
|
|
300
309
|
paint.opacity = own.opacity;
|
|
301
310
|
}
|
|
302
|
-
const color =
|
|
311
|
+
const color = reader.color(variableId);
|
|
303
312
|
if (!color) return;
|
|
304
|
-
const modes = explicitModes(graph, target, variableId);
|
|
313
|
+
const modes = explicitModes(graph, target, variableId, shared);
|
|
305
314
|
if (!keeps || staleApplied(target, bound, own, color, modes)) applyColor(paint, color);
|
|
306
315
|
recordApplied(target, bound, color, modes);
|
|
307
316
|
});
|