@pairdraw/scene-graph 0.0.0-stage → 0.16.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/LICENSE +21 -0
- package/README.md +4 -2
- package/dist/agent-notes/index.d.ts +3 -0
- package/dist/agent-notes/index.js +3 -0
- package/dist/agent-notes/model.d.ts +23 -0
- package/dist/agent-notes/model.d.ts.map +1 -0
- package/dist/agent-notes/model.js +36 -0
- package/dist/agent-notes/model.js.map +1 -0
- package/dist/agent-notes/schema.d.ts +19 -0
- package/dist/agent-notes/schema.d.ts.map +1 -0
- package/dist/agent-notes/schema.js +17 -0
- package/dist/agent-notes/schema.js.map +1 -0
- package/dist/arrow-caps.d.ts +65 -0
- package/dist/arrow-caps.d.ts.map +1 -0
- package/dist/arrow-caps.js +365 -0
- package/dist/arrow-caps.js.map +1 -0
- package/dist/asset-keys.d.ts +17 -0
- package/dist/asset-keys.d.ts.map +1 -0
- package/dist/asset-keys.js +27 -0
- package/dist/asset-keys.js.map +1 -0
- package/dist/behaviours/index.d.ts +6 -0
- package/dist/behaviours/index.js +6 -0
- package/dist/behaviours/kinds.d.ts +56 -0
- package/dist/behaviours/kinds.d.ts.map +1 -0
- package/dist/behaviours/kinds.js +273 -0
- package/dist/behaviours/kinds.js.map +1 -0
- package/dist/behaviours/layers.d.ts +16 -0
- package/dist/behaviours/layers.d.ts.map +1 -0
- package/dist/behaviours/layers.js +42 -0
- package/dist/behaviours/layers.js.map +1 -0
- package/dist/behaviours/model.d.ts +45 -0
- package/dist/behaviours/model.d.ts.map +1 -0
- package/dist/behaviours/model.js +149 -0
- package/dist/behaviours/model.js.map +1 -0
- package/dist/behaviours/schema.d.ts +114 -0
- package/dist/behaviours/schema.d.ts.map +1 -0
- package/dist/behaviours/schema.js +71 -0
- package/dist/behaviours/schema.js.map +1 -0
- package/dist/behaviours/spec.d.ts +26 -0
- package/dist/behaviours/spec.d.ts.map +1 -0
- package/dist/behaviours/spec.js +157 -0
- package/dist/behaviours/spec.js.map +1 -0
- package/dist/bindings.js +18 -0
- package/dist/bindings.js.map +1 -0
- package/dist/browser-node/index.d.ts +3 -0
- package/dist/browser-node/index.js +3 -0
- package/dist/browser-node/model.d.ts +18 -0
- package/dist/browser-node/model.d.ts.map +1 -0
- package/dist/browser-node/model.js +31 -0
- package/dist/browser-node/model.js.map +1 -0
- package/dist/browser-node/schema.d.ts +23 -0
- package/dist/browser-node/schema.d.ts.map +1 -0
- package/dist/browser-node/schema.js +44 -0
- package/dist/browser-node/schema.js.map +1 -0
- package/dist/buffered-events.d.ts +21 -0
- package/dist/buffered-events.d.ts.map +1 -0
- package/dist/buffered-events.js +57 -0
- package/dist/buffered-events.js.map +1 -0
- package/dist/checkpoint.d.ts +13 -0
- package/dist/checkpoint.d.ts.map +1 -0
- package/dist/checkpoint.js +78 -0
- package/dist/checkpoint.js.map +1 -0
- package/dist/clipping.d.ts +31 -0
- package/dist/clipping.d.ts.map +1 -0
- package/dist/clipping.js +125 -0
- package/dist/clipping.js.map +1 -0
- package/dist/color/contrast.d.ts +20 -0
- package/dist/color/contrast.d.ts.map +1 -0
- package/dist/color/contrast.js +69 -0
- package/dist/color/contrast.js.map +1 -0
- package/dist/color/index.d.ts +38 -0
- package/dist/color/index.d.ts.map +1 -0
- package/dist/color/index.js +110 -0
- package/dist/color/index.js.map +1 -0
- package/dist/color/management.d.ts +32 -0
- package/dist/color/management.d.ts.map +1 -0
- package/dist/color/management.js +187 -0
- package/dist/color/management.js.map +1 -0
- package/dist/color/normalize.d.ts +6 -0
- package/dist/color/normalize.d.ts.map +1 -0
- package/dist/color/normalize.js +15 -0
- package/dist/color/normalize.js.map +1 -0
- package/dist/color/okhcl.d.ts +33 -0
- package/dist/color/okhcl.d.ts.map +1 -0
- package/dist/color/okhcl.js +146 -0
- package/dist/color/okhcl.js.map +1 -0
- package/dist/color/schema.d.ts +11 -0
- package/dist/color/schema.d.ts.map +1 -0
- package/dist/color/schema.js +13 -0
- package/dist/color/schema.js.map +1 -0
- package/dist/comments/document.d.ts +23 -0
- package/dist/comments/document.d.ts.map +1 -0
- package/dist/comments/document.js +33 -0
- package/dist/comments/document.js.map +1 -0
- package/dist/comments/index.d.ts +6 -0
- package/dist/comments/index.js +6 -0
- package/dist/comments/list.d.ts +25 -0
- package/dist/comments/list.d.ts.map +1 -0
- package/dist/comments/list.js +33 -0
- package/dist/comments/list.js.map +1 -0
- package/dist/comments/merge.d.ts +16 -0
- package/dist/comments/merge.d.ts.map +1 -0
- package/dist/comments/merge.js +58 -0
- package/dist/comments/merge.js.map +1 -0
- package/dist/comments/schema.d.ts +8 -0
- package/dist/comments/schema.d.ts.map +1 -0
- package/dist/comments/schema.js +50 -0
- package/dist/comments/schema.js.map +1 -0
- package/dist/comments/threads.d.ts +59 -0
- package/dist/comments/threads.d.ts.map +1 -0
- package/dist/comments/threads.js +132 -0
- package/dist/comments/threads.js.map +1 -0
- package/dist/components/exposure.d.ts +24 -0
- package/dist/components/exposure.d.ts.map +1 -0
- package/dist/components/exposure.js +51 -0
- package/dist/components/exposure.js.map +1 -0
- package/dist/components/index.d.ts +5 -0
- package/dist/components/index.js +5 -0
- package/dist/components/library-page.d.ts +11 -0
- package/dist/components/library-page.d.ts.map +1 -0
- package/dist/components/library-page.js +21 -0
- package/dist/components/library-page.js.map +1 -0
- package/dist/components/properties.d.ts +20 -0
- package/dist/components/properties.d.ts.map +1 -0
- package/dist/components/properties.js +125 -0
- package/dist/components/properties.js.map +1 -0
- package/dist/components/variants.d.ts +27 -0
- package/dist/components/variants.d.ts.map +1 -0
- package/dist/components/variants.js +32 -0
- package/dist/components/variants.js.map +1 -0
- package/dist/connectors/controls.d.ts +34 -0
- package/dist/connectors/controls.d.ts.map +1 -0
- package/dist/connectors/controls.js +196 -0
- package/dist/connectors/controls.js.map +1 -0
- package/dist/connectors/create.d.ts +23 -0
- package/dist/connectors/create.d.ts.map +1 -0
- package/dist/connectors/create.js +33 -0
- package/dist/connectors/create.js.map +1 -0
- package/dist/connectors/elbow.js +191 -0
- package/dist/connectors/elbow.js.map +1 -0
- package/dist/connectors/gaps.d.ts +10 -0
- package/dist/connectors/gaps.d.ts.map +1 -0
- package/dist/connectors/gaps.js +86 -0
- package/dist/connectors/gaps.js.map +1 -0
- package/dist/connectors/hit.d.ts +11 -0
- package/dist/connectors/hit.d.ts.map +1 -0
- package/dist/connectors/hit.js +53 -0
- package/dist/connectors/hit.js.map +1 -0
- package/dist/connectors/index.d.ts +11 -0
- package/dist/connectors/index.js +11 -0
- package/dist/connectors/label.d.ts +32 -0
- package/dist/connectors/label.d.ts.map +1 -0
- package/dist/connectors/label.js +213 -0
- package/dist/connectors/label.js.map +1 -0
- package/dist/connectors/layout.d.ts +46 -0
- package/dist/connectors/layout.d.ts.map +1 -0
- package/dist/connectors/layout.js +234 -0
- package/dist/connectors/layout.js.map +1 -0
- package/dist/connectors/pieces.d.ts +22 -0
- package/dist/connectors/pieces.d.ts.map +1 -0
- package/dist/connectors/pieces.js +159 -0
- package/dist/connectors/pieces.js.map +1 -0
- package/dist/connectors/route.d.ts +23 -0
- package/dist/connectors/route.d.ts.map +1 -0
- package/dist/connectors/route.js +107 -0
- package/dist/connectors/route.js.map +1 -0
- package/dist/connectors/sides.d.ts +23 -0
- package/dist/connectors/sides.d.ts.map +1 -0
- package/dist/connectors/sides.js +98 -0
- package/dist/connectors/sides.js.map +1 -0
- package/dist/connectors/sublayers.d.ts +76 -0
- package/dist/connectors/sublayers.d.ts.map +1 -0
- package/dist/connectors/sublayers.js +209 -0
- package/dist/connectors/sublayers.js.map +1 -0
- package/dist/constants.d.ts +16 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +31 -0
- package/dist/constants.js.map +1 -0
- package/dist/coordinate.d.ts +99 -0
- package/dist/coordinate.d.ts.map +1 -0
- package/dist/coordinate.js +276 -0
- package/dist/coordinate.js.map +1 -0
- package/dist/copy.d.ts +45 -0
- package/dist/copy.d.ts.map +1 -0
- package/dist/copy.js +256 -0
- package/dist/copy.js.map +1 -0
- package/dist/css/grid.d.ts +7 -0
- package/dist/css/grid.d.ts.map +1 -0
- package/dist/css/grid.js +63 -0
- package/dist/css/grid.js.map +1 -0
- package/dist/css/index.d.ts +6 -0
- package/dist/css/index.js +6 -0
- package/dist/css/layout.d.ts +17 -0
- package/dist/css/layout.d.ts.map +1 -0
- package/dist/css/layout.js +45 -0
- package/dist/css/layout.js.map +1 -0
- package/dist/css/shadows.d.ts +10 -0
- package/dist/css/shadows.d.ts.map +1 -0
- package/dist/css/shadows.js +64 -0
- package/dist/css/shadows.js.map +1 -0
- package/dist/css/text.d.ts +22 -0
- package/dist/css/text.d.ts.map +1 -0
- package/dist/css/text.js +76 -0
- package/dist/css/text.js.map +1 -0
- package/dist/css/values.d.ts +14 -0
- package/dist/css/values.d.ts.map +1 -0
- package/dist/css/values.js +36 -0
- package/dist/css/values.js.map +1 -0
- package/dist/events.js +18 -0
- package/dist/events.js.map +1 -0
- package/dist/export-format.d.ts +19 -0
- package/dist/export-format.d.ts.map +1 -0
- package/dist/export-format.js +33 -0
- package/dist/export-format.js.map +1 -0
- package/dist/export-scale.d.ts +14 -0
- package/dist/export-scale.d.ts.map +1 -0
- package/dist/export-scale.js +19 -0
- package/dist/export-scale.js.map +1 -0
- package/dist/fields/appearance.d.ts +9 -0
- package/dist/fields/appearance.d.ts.map +1 -0
- package/dist/fields/appearance.js +36 -0
- package/dist/fields/appearance.js.map +1 -0
- package/dist/fields/geometry.d.ts +7 -0
- package/dist/fields/geometry.d.ts.map +1 -0
- package/dist/fields/geometry.js +14 -0
- package/dist/fields/geometry.js.map +1 -0
- package/dist/fields/index.d.ts +5 -0
- package/dist/fields/index.js +5 -0
- package/dist/fields/layout.d.ts +10 -0
- package/dist/fields/layout.d.ts.map +1 -0
- package/dist/fields/layout.js +49 -0
- package/dist/fields/layout.js.map +1 -0
- package/dist/fields/text.d.ts +11 -0
- package/dist/fields/text.d.ts.map +1 -0
- package/dist/fields/text.js +63 -0
- package/dist/fields/text.js.map +1 -0
- package/dist/fig-compression.d.ts +11 -0
- package/dist/fig-compression.d.ts.map +1 -0
- package/dist/fig-compression.js +15 -0
- package/dist/fig-compression.js.map +1 -0
- package/dist/figjam/index.d.ts +3 -0
- package/dist/figjam/index.js +3 -0
- package/dist/figjam/palette.d.ts +199 -0
- package/dist/figjam/palette.d.ts.map +1 -0
- package/dist/figjam/palette.js +277 -0
- package/dist/figjam/palette.js.map +1 -0
- package/dist/figjam/text.d.ts +68 -0
- package/dist/figjam/text.d.ts.map +1 -0
- package/dist/figjam/text.js +89 -0
- package/dist/figjam/text.js.map +1 -0
- package/dist/font-style.d.ts +46 -0
- package/dist/font-style.d.ts.map +1 -0
- package/dist/font-style.js +127 -0
- package/dist/font-style.js.map +1 -0
- package/dist/generated/index.d.ts +46 -0
- package/dist/generated/index.d.ts.map +1 -0
- package/dist/generated/index.js +62 -0
- package/dist/generated/index.js.map +1 -0
- package/dist/generated/kind.d.ts +29 -0
- package/dist/generated/kind.d.ts.map +1 -0
- package/dist/generated/shape-with-text.d.ts +38 -0
- package/dist/generated/shape-with-text.d.ts.map +1 -0
- package/dist/generated/shape-with-text.js +119 -0
- package/dist/generated/shape-with-text.js.map +1 -0
- package/dist/generated/sticky.d.ts +128 -0
- package/dist/generated/sticky.d.ts.map +1 -0
- package/dist/generated/sticky.js +234 -0
- package/dist/generated/sticky.js.map +1 -0
- package/dist/geometry.d.ts +105 -0
- package/dist/geometry.d.ts.map +1 -0
- package/dist/geometry.js +374 -0
- package/dist/geometry.js.map +1 -0
- package/dist/gradient.d.ts +74 -0
- package/dist/gradient.d.ts.map +1 -0
- package/dist/gradient.js +211 -0
- package/dist/gradient.js.map +1 -0
- package/dist/graph.d.ts +186 -0
- package/dist/graph.d.ts.map +1 -0
- package/dist/graph.js +630 -0
- package/dist/graph.js.map +1 -0
- package/dist/group-bounds.d.ts +42 -0
- package/dist/group-bounds.d.ts.map +1 -0
- package/dist/group-bounds.js +146 -0
- package/dist/group-bounds.js.map +1 -0
- package/dist/guides.d.ts +19 -0
- package/dist/guides.d.ts.map +1 -0
- package/dist/guides.js +39 -0
- package/dist/guides.js.map +1 -0
- package/dist/hit-test.d.ts +49 -0
- package/dist/hit-test.d.ts.map +1 -0
- package/dist/hit-test.js +315 -0
- package/dist/hit-test.js.map +1 -0
- package/dist/icons/glyph.d.ts +22 -0
- package/dist/icons/glyph.d.ts.map +1 -0
- package/dist/icons/glyph.js +109 -0
- package/dist/icons/glyph.js.map +1 -0
- package/dist/icons/index.d.ts +4 -0
- package/dist/icons/index.js +4 -0
- package/dist/icons/model.d.ts +29 -0
- package/dist/icons/model.d.ts.map +1 -0
- package/dist/icons/model.js +51 -0
- package/dist/icons/model.js.map +1 -0
- package/dist/icons/schema.d.ts +31 -0
- package/dist/icons/schema.d.ts.map +1 -0
- package/dist/icons/schema.js +28 -0
- package/dist/icons/schema.js.map +1 -0
- package/dist/ids.d.ts +12 -0
- package/dist/ids.d.ts.map +1 -0
- package/dist/ids.js +31 -0
- package/dist/ids.js.map +1 -0
- package/dist/images.d.ts +39 -0
- package/dist/images.d.ts.map +1 -0
- package/dist/images.js +85 -0
- package/dist/images.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/instances/assignments.js +89 -0
- package/dist/instances/assignments.js.map +1 -0
- package/dist/instances/content-size.js +60 -0
- package/dist/instances/content-size.js.map +1 -0
- package/dist/instances/copies.js +162 -0
- package/dist/instances/copies.js.map +1 -0
- package/dist/instances/cycles.d.ts +20 -0
- package/dist/instances/cycles.d.ts.map +1 -0
- package/dist/instances/cycles.js +53 -0
- package/dist/instances/cycles.js.map +1 -0
- package/dist/instances/fields.d.ts +18 -0
- package/dist/instances/fields.d.ts.map +1 -0
- package/dist/instances/fields.js +82 -0
- package/dist/instances/fields.js.map +1 -0
- package/dist/instances/index.d.ts +63 -0
- package/dist/instances/index.d.ts.map +1 -0
- package/dist/instances/index.js +305 -0
- package/dist/instances/index.js.map +1 -0
- package/dist/instances/main-component.d.ts +11 -0
- package/dist/instances/main-component.d.ts.map +1 -0
- package/dist/instances/main-component.js +42 -0
- package/dist/instances/main-component.js.map +1 -0
- package/dist/instances/modes.js +26 -0
- package/dist/instances/modes.js.map +1 -0
- package/dist/instances/overrides.d.ts +63 -0
- package/dist/instances/overrides.d.ts.map +1 -0
- package/dist/instances/overrides.js +164 -0
- package/dist/instances/overrides.js.map +1 -0
- package/dist/instances/placement.js +30 -0
- package/dist/instances/placement.js.map +1 -0
- package/dist/instances/replacements.d.ts +19 -0
- package/dist/instances/replacements.d.ts.map +1 -0
- package/dist/instances/replacements.js +67 -0
- package/dist/instances/replacements.js.map +1 -0
- package/dist/instances/source-walk.js +31 -0
- package/dist/instances/source-walk.js.map +1 -0
- package/dist/instances/sync.js +305 -0
- package/dist/instances/sync.js.map +1 -0
- package/dist/instances/vector-geometry.js +70 -0
- package/dist/instances/vector-geometry.js.map +1 -0
- package/dist/layout/aspect-ratio.d.ts +27 -0
- package/dist/layout/aspect-ratio.d.ts.map +1 -0
- package/dist/layout/aspect-ratio.js +45 -0
- package/dist/layout/aspect-ratio.js.map +1 -0
- package/dist/layout/guides.d.ts +25 -0
- package/dist/layout/guides.d.ts.map +1 -0
- package/dist/layout/guides.js +105 -0
- package/dist/layout/guides.js.map +1 -0
- package/dist/layout/index.d.ts +5 -0
- package/dist/layout/index.js +5 -0
- package/dist/layout/keywords.d.ts +26 -0
- package/dist/layout/keywords.d.ts.map +1 -0
- package/dist/layout/keywords.js +60 -0
- package/dist/layout/keywords.js.map +1 -0
- package/dist/layout/sizing.d.ts +40 -0
- package/dist/layout/sizing.d.ts.map +1 -0
- package/dist/layout/sizing.js +122 -0
- package/dist/layout/sizing.js.map +1 -0
- package/dist/layout/writes.js +55 -0
- package/dist/layout/writes.js.map +1 -0
- package/dist/matrix.d.ts +16 -0
- package/dist/matrix.d.ts.map +1 -0
- package/dist/matrix.js +120 -0
- package/dist/matrix.js.map +1 -0
- package/dist/mutation-impact.d.ts +23 -0
- package/dist/mutation-impact.d.ts.map +1 -0
- package/dist/mutation-impact.js +67 -0
- package/dist/mutation-impact.js.map +1 -0
- package/dist/naming.d.ts +9 -0
- package/dist/naming.d.ts.map +1 -0
- package/dist/naming.js +16 -0
- package/dist/naming.js.map +1 -0
- package/dist/node-defaults.d.ts +19 -0
- package/dist/node-defaults.d.ts.map +1 -0
- package/dist/node-defaults.js +243 -0
- package/dist/node-defaults.js.map +1 -0
- package/dist/order-keys.d.ts +39 -0
- package/dist/order-keys.d.ts.map +1 -0
- package/dist/order-keys.js +136 -0
- package/dist/order-keys.js.map +1 -0
- package/dist/paints/index.d.ts +2 -0
- package/dist/paints/index.js +2 -0
- package/dist/paints/schema.d.ts +103 -0
- package/dist/paints/schema.d.ts.map +1 -0
- package/dist/paints/schema.js +64 -0
- package/dist/paints/schema.js.map +1 -0
- package/dist/parse-path.d.ts +36 -0
- package/dist/parse-path.d.ts.map +1 -0
- package/dist/parse-path.js +200 -0
- package/dist/parse-path.js.map +1 -0
- package/dist/plugin-data/citation.d.ts +13 -0
- package/dist/plugin-data/citation.d.ts.map +1 -0
- package/dist/plugin-data/citation.js +23 -0
- package/dist/plugin-data/citation.js.map +1 -0
- package/dist/plugin-data/field.d.ts +47 -0
- package/dist/plugin-data/field.d.ts.map +1 -0
- package/dist/plugin-data/field.js +79 -0
- package/dist/plugin-data/field.js.map +1 -0
- package/dist/plugin-data/fields.d.ts +220 -0
- package/dist/plugin-data/fields.d.ts.map +1 -0
- package/dist/plugin-data/fields.js +214 -0
- package/dist/plugin-data/fields.js.map +1 -0
- package/dist/plugin-data/index.d.ts +5 -0
- package/dist/plugin-data/index.js +5 -0
- package/dist/plugin-data/schema.d.ts +18 -0
- package/dist/plugin-data/schema.d.ts.map +1 -0
- package/dist/plugin-data/schema.js +29 -0
- package/dist/plugin-data/schema.js.map +1 -0
- package/dist/polygon.d.ts +55 -0
- package/dist/polygon.d.ts.map +1 -0
- package/dist/polygon.js +220 -0
- package/dist/polygon.js.map +1 -0
- package/dist/preview.d.ts +12 -0
- package/dist/preview.d.ts.map +1 -0
- package/dist/preview.js +63 -0
- package/dist/preview.js.map +1 -0
- package/dist/primitives/index.d.ts +43 -0
- package/dist/primitives/index.d.ts.map +1 -0
- package/dist/primitives/index.js +2 -0
- package/dist/primitives/schema.d.ts +18 -0
- package/dist/primitives/schema.d.ts.map +1 -0
- package/dist/primitives/schema.js +19 -0
- package/dist/primitives/schema.js.map +1 -0
- package/dist/random.d.ts +7 -0
- package/dist/random.d.ts.map +1 -0
- package/dist/random.js +25 -0
- package/dist/random.js.map +1 -0
- package/dist/resize.d.ts +41 -0
- package/dist/resize.d.ts.map +1 -0
- package/dist/resize.js +288 -0
- package/dist/resize.js.map +1 -0
- package/dist/scaling/index.d.ts +3 -0
- package/dist/scaling/index.js +3 -0
- package/dist/scaling/node.d.ts +6 -0
- package/dist/scaling/node.d.ts.map +1 -0
- package/dist/scaling/node.js +150 -0
- package/dist/scaling/node.js.map +1 -0
- package/dist/scaling/tree.d.ts +22 -0
- package/dist/scaling/tree.d.ts.map +1 -0
- package/dist/scaling/tree.js +71 -0
- package/dist/scaling/tree.js.map +1 -0
- package/dist/script/index.d.ts +2 -0
- package/dist/script/index.js +2 -0
- package/dist/script/schema.d.ts +29 -0
- package/dist/script/schema.d.ts.map +1 -0
- package/dist/script/schema.js +51 -0
- package/dist/script/schema.js.map +1 -0
- package/dist/shaders/directives.d.ts +43 -0
- package/dist/shaders/directives.d.ts.map +1 -0
- package/dist/shaders/directives.js +293 -0
- package/dist/shaders/directives.js.map +1 -0
- package/dist/shaders/index.d.ts +5 -0
- package/dist/shaders/index.js +5 -0
- package/dist/shaders/model.d.ts +58 -0
- package/dist/shaders/model.d.ts.map +1 -0
- package/dist/shaders/model.js +109 -0
- package/dist/shaders/model.js.map +1 -0
- package/dist/shaders/schema.d.ts +86 -0
- package/dist/shaders/schema.d.ts.map +1 -0
- package/dist/shaders/schema.js +65 -0
- package/dist/shaders/schema.js.map +1 -0
- package/dist/shaders/still.d.ts +18 -0
- package/dist/shaders/still.d.ts.map +1 -0
- package/dist/shaders/still.js +36 -0
- package/dist/shaders/still.js.map +1 -0
- package/dist/shape-with-text/fit.d.ts +28 -0
- package/dist/shape-with-text/fit.d.ts.map +1 -0
- package/dist/shape-with-text/fit.js +271 -0
- package/dist/shape-with-text/fit.js.map +1 -0
- package/dist/shape-with-text/geometry.d.ts +20 -0
- package/dist/shape-with-text/geometry.d.ts.map +1 -0
- package/dist/shape-with-text/geometry.js +539 -0
- package/dist/shape-with-text/geometry.js.map +1 -0
- package/dist/shape-with-text/index.d.ts +4 -0
- package/dist/shape-with-text/index.js +4 -0
- package/dist/shape-with-text/kinds.d.ts +20 -0
- package/dist/shape-with-text/kinds.d.ts.map +1 -0
- package/dist/shape-with-text/kinds.js +86 -0
- package/dist/shape-with-text/kinds.js.map +1 -0
- package/dist/shared-styles.d.ts +36 -0
- package/dist/shared-styles.d.ts.map +1 -0
- package/dist/shared-styles.js +116 -0
- package/dist/shared-styles.js.map +1 -0
- package/dist/slots/authoring.d.ts +27 -0
- package/dist/slots/authoring.d.ts.map +1 -0
- package/dist/slots/authoring.js +74 -0
- package/dist/slots/authoring.js.map +1 -0
- package/dist/slots/content.d.ts +41 -0
- package/dist/slots/content.d.ts.map +1 -0
- package/dist/slots/content.js +103 -0
- package/dist/slots/content.js.map +1 -0
- package/dist/slots/frames.d.ts +38 -0
- package/dist/slots/frames.d.ts.map +1 -0
- package/dist/slots/frames.js +113 -0
- package/dist/slots/frames.js.map +1 -0
- package/dist/slots/index.d.ts +5 -0
- package/dist/slots/index.js +5 -0
- package/dist/slots/limits.d.ts +14 -0
- package/dist/slots/limits.d.ts.map +1 -0
- package/dist/slots/limits.js +28 -0
- package/dist/slots/limits.js.map +1 -0
- package/dist/snap.d.ts +61 -0
- package/dist/snap.d.ts.map +1 -0
- package/dist/snap.js +264 -0
- package/dist/snap.js.map +1 -0
- package/dist/source-metadata.d.ts +6 -0
- package/dist/source-metadata.d.ts.map +1 -0
- package/dist/source-metadata.js +11 -0
- package/dist/source-metadata.js.map +1 -0
- package/dist/statuses/impact.d.ts +18 -0
- package/dist/statuses/impact.d.ts.map +1 -0
- package/dist/statuses/impact.js +33 -0
- package/dist/statuses/impact.js.map +1 -0
- package/dist/statuses/index.d.ts +5 -0
- package/dist/statuses/index.js +5 -0
- package/dist/statuses/node.d.ts +22 -0
- package/dist/statuses/node.d.ts.map +1 -0
- package/dist/statuses/node.js +47 -0
- package/dist/statuses/node.js.map +1 -0
- package/dist/statuses/schema.d.ts +59 -0
- package/dist/statuses/schema.d.ts.map +1 -0
- package/dist/statuses/schema.js +27 -0
- package/dist/statuses/schema.js.map +1 -0
- package/dist/statuses/workflow.d.ts +120 -0
- package/dist/statuses/workflow.d.ts.map +1 -0
- package/dist/statuses/workflow.js +135 -0
- package/dist/statuses/workflow.js.map +1 -0
- package/dist/text/direction.d.ts +13 -0
- package/dist/text/direction.d.ts.map +1 -0
- package/dist/text/direction.js +31 -0
- package/dist/text/direction.js.map +1 -0
- package/dist/text/index.d.ts +7 -0
- package/dist/text/index.js +7 -0
- package/dist/text/lengths.d.ts +19 -0
- package/dist/text/lengths.d.ts.map +1 -0
- package/dist/text/lengths.js +40 -0
- package/dist/text/lengths.js.map +1 -0
- package/dist/text/lists.d.ts +44 -0
- package/dist/text/lists.d.ts.map +1 -0
- package/dist/text/lists.js +100 -0
- package/dist/text/lists.js.map +1 -0
- package/dist/text/overflow.d.ts +11 -0
- package/dist/text/overflow.d.ts.map +1 -0
- package/dist/text/overflow.js +13 -0
- package/dist/text/overflow.js.map +1 -0
- package/dist/text/paragraphs.d.ts +62 -0
- package/dist/text/paragraphs.d.ts.map +1 -0
- package/dist/text/paragraphs.js +166 -0
- package/dist/text/paragraphs.js.map +1 -0
- package/dist/text/picture.d.ts +18 -0
- package/dist/text/picture.d.ts.map +1 -0
- package/dist/text/picture.js +41 -0
- package/dist/text/picture.js.map +1 -0
- package/dist/text/references.d.ts +21 -0
- package/dist/text/references.d.ts.map +1 -0
- package/dist/text/references.js +43 -0
- package/dist/text/references.js.map +1 -0
- package/dist/text/schema.d.ts +10 -0
- package/dist/text/schema.d.ts.map +1 -0
- package/dist/text/schema.js +11 -0
- package/dist/text/schema.js.map +1 -0
- package/dist/transfer/apply.d.ts +9 -0
- package/dist/transfer/apply.d.ts.map +1 -0
- package/dist/transfer/apply.js +65 -0
- package/dist/transfer/apply.js.map +1 -0
- package/dist/transfer/history.d.ts +8 -0
- package/dist/transfer/history.d.ts.map +1 -0
- package/dist/transfer/history.js +32 -0
- package/dist/transfer/history.js.map +1 -0
- package/dist/transfer/identity.js +12 -0
- package/dist/transfer/identity.js.map +1 -0
- package/dist/transfer/index.d.ts +7 -0
- package/dist/transfer/index.js +7 -0
- package/dist/transfer/nodes.d.ts +14 -0
- package/dist/transfer/nodes.d.ts.map +1 -0
- package/dist/transfer/nodes.js +82 -0
- package/dist/transfer/nodes.js.map +1 -0
- package/dist/transfer/plan.d.ts +29 -0
- package/dist/transfer/plan.d.ts.map +1 -0
- package/dist/transfer/plan.js +106 -0
- package/dist/transfer/plan.js.map +1 -0
- package/dist/transfer/references.js +10 -0
- package/dist/transfer/references.js.map +1 -0
- package/dist/transfer/remove.d.ts +8 -0
- package/dist/transfer/remove.d.ts.map +1 -0
- package/dist/transfer/remove.js +34 -0
- package/dist/transfer/remove.js.map +1 -0
- package/dist/transfer/validation.js +39 -0
- package/dist/transfer/validation.js.map +1 -0
- package/dist/transfer/variables.d.ts +15 -0
- package/dist/transfer/variables.d.ts.map +1 -0
- package/dist/transfer/variables.js +52 -0
- package/dist/transfer/variables.js.map +1 -0
- package/dist/types.d.ts +910 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +89 -0
- package/dist/types.js.map +1 -0
- package/dist/undo.d.ts +93 -0
- package/dist/undo.d.ts.map +1 -0
- package/dist/undo.js +236 -0
- package/dist/undo.js.map +1 -0
- package/dist/variables/bindings.d.ts +66 -0
- package/dist/variables/bindings.d.ts.map +1 -0
- package/dist/variables/bindings.js +251 -0
- package/dist/variables/bindings.js.map +1 -0
- package/dist/variables/corners.d.ts +12 -0
- package/dist/variables/corners.d.ts.map +1 -0
- package/dist/variables/corners.js +38 -0
- package/dist/variables/corners.js.map +1 -0
- package/dist/variables/fields.d.ts +30 -0
- package/dist/variables/fields.d.ts.map +1 -0
- package/dist/variables/fields.js +89 -0
- package/dist/variables/fields.js.map +1 -0
- package/dist/variables/formula/check.d.ts +14 -0
- package/dist/variables/formula/check.d.ts.map +1 -0
- package/dist/variables/formula/check.js +73 -0
- package/dist/variables/formula/check.js.map +1 -0
- package/dist/variables/formula/evaluate.d.ts +7 -0
- package/dist/variables/formula/evaluate.d.ts.map +1 -0
- package/dist/variables/formula/evaluate.js +30 -0
- package/dist/variables/formula/evaluate.js.map +1 -0
- package/dist/variables/formula/index.d.ts +21 -0
- package/dist/variables/formula/index.d.ts.map +1 -0
- package/dist/variables/formula/index.js +77 -0
- package/dist/variables/formula/index.js.map +1 -0
- package/dist/variables/formula/parse.js +141 -0
- package/dist/variables/formula/parse.js.map +1 -0
- package/dist/variables/formula/print.d.ts +25 -0
- package/dist/variables/formula/print.d.ts.map +1 -0
- package/dist/variables/formula/print.js +105 -0
- package/dist/variables/formula/print.js.map +1 -0
- package/dist/variables/formula/schema.d.ts +7 -0
- package/dist/variables/formula/schema.d.ts.map +1 -0
- package/dist/variables/formula/schema.js +62 -0
- package/dist/variables/formula/schema.js.map +1 -0
- package/dist/variables/formula/signatures.d.ts +9 -0
- package/dist/variables/formula/signatures.d.ts.map +1 -0
- package/dist/variables/formula/signatures.js +238 -0
- package/dist/variables/formula/signatures.js.map +1 -0
- package/dist/variables/formula/tokens.d.ts +26 -0
- package/dist/variables/formula/tokens.d.ts.map +1 -0
- package/dist/variables/formula/tokens.js +82 -0
- package/dist/variables/formula/tokens.js.map +1 -0
- package/dist/variables/formula/tree.d.ts +22 -0
- package/dist/variables/formula/tree.d.ts.map +1 -0
- package/dist/variables/formula/tree.js +35 -0
- package/dist/variables/formula/tree.js.map +1 -0
- package/dist/variables/index.d.ts +41 -0
- package/dist/variables/index.d.ts.map +1 -0
- package/dist/variables/index.js +246 -0
- package/dist/variables/index.js.map +1 -0
- package/dist/variables/resolution.d.ts +39 -0
- package/dist/variables/resolution.d.ts.map +1 -0
- package/dist/variables/resolution.js +154 -0
- package/dist/variables/resolution.js.map +1 -0
- package/dist/variables/schema.d.ts +40 -0
- package/dist/variables/schema.d.ts.map +1 -0
- package/dist/variables/schema.js +32 -0
- package/dist/variables/schema.js.map +1 -0
- package/dist/variables/text.d.ts +21 -0
- package/dist/variables/text.d.ts.map +1 -0
- package/dist/variables/text.js +58 -0
- package/dist/variables/text.js.map +1 -0
- package/dist/variables/token.d.ts +18 -0
- package/dist/variables/token.d.ts.map +1 -0
- package/dist/variables/token.js +39 -0
- package/dist/variables/token.js.map +1 -0
- package/dist/variables/units.js +19 -0
- package/dist/variables/units.js.map +1 -0
- package/dist/variables/value.d.ts +12 -0
- package/dist/variables/value.d.ts.map +1 -0
- package/dist/variables/value.js +70 -0
- package/dist/variables/value.js.map +1 -0
- package/dist/variant-name.d.ts +6 -0
- package/dist/variant-name.d.ts.map +1 -0
- package/dist/variant-name.js +17 -0
- package/dist/variant-name.js.map +1 -0
- package/dist/variant-properties.d.ts +18 -0
- package/dist/variant-properties.d.ts.map +1 -0
- package/dist/variant-properties.js +74 -0
- package/dist/variant-properties.js.map +1 -0
- package/dist/vector-network.d.ts +48 -0
- package/dist/vector-network.d.ts.map +1 -0
- package/dist/vector-network.js +352 -0
- package/dist/vector-network.js.map +1 -0
- package/package.json +352 -4
- package/src/agent-notes/index.ts +2 -0
- package/src/agent-notes/model.ts +46 -0
- package/src/agent-notes/schema.ts +28 -0
- package/src/arrow-caps.ts +364 -0
- package/src/asset-keys.ts +25 -0
- package/src/behaviours/index.ts +5 -0
- package/src/behaviours/kinds.ts +185 -0
- package/src/behaviours/layers.ts +51 -0
- package/src/behaviours/model.ts +184 -0
- package/src/behaviours/schema.ts +93 -0
- package/src/behaviours/spec.ts +178 -0
- package/src/bindings.ts +20 -0
- package/src/browser-node/index.ts +2 -0
- package/src/browser-node/model.ts +35 -0
- package/src/browser-node/schema.ts +62 -0
- package/src/buffered-events.ts +64 -0
- package/src/checkpoint.ts +123 -0
- package/src/clipping.ts +112 -0
- package/src/color/contrast.ts +71 -0
- package/src/color/index.ts +89 -0
- package/src/color/management.ts +210 -0
- package/src/color/normalize.ts +7 -0
- package/src/color/okhcl.ts +201 -0
- package/src/color/schema.ts +10 -0
- package/src/comments/document.ts +51 -0
- package/src/comments/index.ts +5 -0
- package/src/comments/list.ts +52 -0
- package/src/comments/merge.ts +63 -0
- package/src/comments/schema.ts +51 -0
- package/src/comments/threads.ts +156 -0
- package/src/components/exposure.ts +61 -0
- package/src/components/index.ts +9 -0
- package/src/components/library-page.ts +17 -0
- package/src/components/properties.ts +241 -0
- package/src/components/variants.ts +53 -0
- package/src/connectors/controls.ts +229 -0
- package/src/connectors/create.ts +48 -0
- package/src/connectors/elbow.ts +235 -0
- package/src/connectors/gaps.ts +72 -0
- package/src/connectors/hit.ts +60 -0
- package/src/connectors/index.ts +28 -0
- package/src/connectors/label.ts +238 -0
- package/src/connectors/layout.ts +280 -0
- package/src/connectors/pieces.ts +144 -0
- package/src/connectors/route.ts +148 -0
- package/src/connectors/sides.ts +94 -0
- package/src/connectors/sublayers.ts +204 -0
- package/src/constants.ts +13 -0
- package/src/coordinate.ts +298 -0
- package/src/copy.ts +341 -0
- package/src/css/grid.ts +70 -0
- package/src/css/index.ts +10 -0
- package/src/css/layout.ts +53 -0
- package/src/css/shadows.ts +68 -0
- package/src/css/text.ts +84 -0
- package/src/css/values.ts +42 -0
- package/src/events.ts +21 -0
- package/src/export-format.ts +33 -0
- package/src/export-scale.ts +16 -0
- package/src/fields/appearance.ts +35 -0
- package/src/fields/geometry.ts +11 -0
- package/src/fields/index.ts +4 -0
- package/src/fields/layout.ts +48 -0
- package/src/fields/text.ts +64 -0
- package/src/fig-compression.ts +9 -0
- package/src/figjam/index.ts +2 -0
- package/src/figjam/palette.ts +308 -0
- package/src/figjam/text.ts +78 -0
- package/src/font-style.ts +121 -0
- package/src/generated/index.ts +81 -0
- package/src/generated/kind.ts +26 -0
- package/src/generated/shape-with-text.ts +132 -0
- package/src/generated/sticky.ts +214 -0
- package/src/geometry.ts +490 -0
- package/src/gradient.ts +275 -0
- package/src/graph.ts +842 -0
- package/src/group-bounds.ts +178 -0
- package/src/guides.ts +47 -0
- package/src/hit-test.ts +501 -0
- package/src/icons/glyph.ts +128 -0
- package/src/icons/index.ts +3 -0
- package/src/icons/model.ts +63 -0
- package/src/icons/schema.ts +34 -0
- package/src/ids.ts +34 -0
- package/src/images.ts +89 -0
- package/src/index.ts +4 -0
- package/src/instances/assignments.ts +116 -0
- package/src/instances/content-size.ts +84 -0
- package/src/instances/copies.ts +244 -0
- package/src/instances/cycles.ts +73 -0
- package/src/instances/fields.ts +90 -0
- package/src/instances/index.ts +467 -0
- package/src/instances/main-component.ts +61 -0
- package/src/instances/modes.ts +39 -0
- package/src/instances/overrides.ts +240 -0
- package/src/instances/placement.ts +29 -0
- package/src/instances/replacements.ts +80 -0
- package/src/instances/source-walk.ts +35 -0
- package/src/instances/sync.ts +556 -0
- package/src/instances/vector-geometry.ts +81 -0
- package/src/layout/aspect-ratio.ts +51 -0
- package/src/layout/guides.ts +132 -0
- package/src/layout/index.ts +4 -0
- package/src/layout/keywords.ts +74 -0
- package/src/layout/sizing.ts +196 -0
- package/src/layout/writes.ts +59 -0
- package/src/matrix.ts +116 -0
- package/src/mutation-impact.ts +85 -0
- package/src/naming.ts +11 -0
- package/src/node-defaults.ts +260 -0
- package/src/order-keys.ts +162 -0
- package/src/paints/index.ts +1 -0
- package/src/paints/schema.ts +72 -0
- package/src/parse-path.ts +244 -0
- package/src/plugin-data/citation.ts +27 -0
- package/src/plugin-data/field.ts +140 -0
- package/src/plugin-data/fields.ts +306 -0
- package/src/plugin-data/index.ts +3 -0
- package/src/plugin-data/schema.ts +35 -0
- package/src/polygon.ts +228 -0
- package/src/preview.ts +80 -0
- package/src/primitives/index.ts +44 -0
- package/src/primitives/schema.ts +14 -0
- package/src/random.ts +28 -0
- package/src/resize.ts +415 -0
- package/src/scaling/index.ts +9 -0
- package/src/scaling/node.ts +168 -0
- package/src/scaling/tree.ts +85 -0
- package/src/script/index.ts +1 -0
- package/src/script/schema.ts +65 -0
- package/src/shaders/directives.ts +366 -0
- package/src/shaders/index.ts +4 -0
- package/src/shaders/model.ts +147 -0
- package/src/shaders/schema.ts +84 -0
- package/src/shaders/still.ts +41 -0
- package/src/shape-with-text/fit.ts +154 -0
- package/src/shape-with-text/geometry.ts +496 -0
- package/src/shape-with-text/index.ts +10 -0
- package/src/shape-with-text/kinds.ts +86 -0
- package/src/shared-styles.ts +137 -0
- package/src/slots/authoring.ts +101 -0
- package/src/slots/content.ts +127 -0
- package/src/slots/frames.ts +160 -0
- package/src/slots/index.ts +4 -0
- package/src/slots/limits.ts +49 -0
- package/src/snap.ts +349 -0
- package/src/source-metadata.ts +8 -0
- package/src/statuses/impact.ts +38 -0
- package/src/statuses/index.ts +4 -0
- package/src/statuses/node.ts +63 -0
- package/src/statuses/schema.ts +39 -0
- package/src/statuses/workflow.ts +121 -0
- package/src/text/direction.ts +55 -0
- package/src/text/index.ts +6 -0
- package/src/text/lengths.ts +34 -0
- package/src/text/lists.ts +138 -0
- package/src/text/overflow.ts +12 -0
- package/src/text/paragraphs.ts +241 -0
- package/src/text/picture.ts +57 -0
- package/src/text/references.ts +50 -0
- package/src/text/schema.ts +7 -0
- package/src/transfer/apply.ts +84 -0
- package/src/transfer/history.ts +49 -0
- package/src/transfer/identity.ts +16 -0
- package/src/transfer/index.ts +6 -0
- package/src/transfer/nodes.ts +128 -0
- package/src/transfer/plan.ts +130 -0
- package/src/transfer/references.ts +9 -0
- package/src/transfer/remove.ts +39 -0
- package/src/transfer/validation.ts +59 -0
- package/src/transfer/variables.ts +83 -0
- package/src/types.ts +1205 -0
- package/src/undo.ts +285 -0
- package/src/variables/bindings.ts +310 -0
- package/src/variables/corners.ts +39 -0
- package/src/variables/fields.ts +109 -0
- package/src/variables/formula/check.ts +99 -0
- package/src/variables/formula/evaluate.ts +33 -0
- package/src/variables/formula/index.ts +129 -0
- package/src/variables/formula/parse.ts +160 -0
- package/src/variables/formula/print.ts +167 -0
- package/src/variables/formula/schema.ts +77 -0
- package/src/variables/formula/signatures.ts +266 -0
- package/src/variables/formula/tokens.ts +114 -0
- package/src/variables/formula/tree.ts +53 -0
- package/src/variables/index.ts +400 -0
- package/src/variables/resolution.ts +293 -0
- package/src/variables/schema.ts +31 -0
- package/src/variables/text.ts +61 -0
- package/src/variables/token.ts +40 -0
- package/src/variables/units.ts +15 -0
- package/src/variables/value.ts +92 -0
- package/src/variant-name.ts +15 -0
- package/src/variant-properties.ts +98 -0
- package/src/vector-network.ts +489 -0
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import { pixelLength } from "../text/lengths.js";
|
|
2
|
+
import { copyFills, copyStrokes } from "../copy.js";
|
|
3
|
+
import { ICON_BINDING_FIELDS, NUMERIC_FIELDS, TEXT_CONTENT_VARIABLE_TYPES, VISIBILITY_VARIABLE_TYPES, isNumericVariableBindingField, paintBindingTarget } from "./fields.js";
|
|
4
|
+
import { hasInstanceOverride } from "../instances/index.js";
|
|
5
|
+
import { ICON_NAME } from "../icons/schema.js";
|
|
6
|
+
import { readIcon } from "../icons/model.js";
|
|
7
|
+
import { variableFontFamily, variableText, variableTruthy } from "./text.js";
|
|
8
|
+
import { variableValueReferences } from "./value.js";
|
|
9
|
+
import { isEqual } from "es-toolkit/predicate";
|
|
10
|
+
//#region src/variables/bindings.ts
|
|
11
|
+
/** New declarations belong to the outermost occurrence, bounded by a component definition. */
|
|
12
|
+
function variableBindingOwner(graph, node) {
|
|
13
|
+
let owner = node;
|
|
14
|
+
let current = node;
|
|
15
|
+
while (current) {
|
|
16
|
+
if (current.type === "COMPONENT" || current.type === "COMPONENT_SET") break;
|
|
17
|
+
if (current.type === "INSTANCE") owner = current;
|
|
18
|
+
current = current.parentId ? graph.getNode(current.parentId) : void 0;
|
|
19
|
+
}
|
|
20
|
+
return owner;
|
|
21
|
+
}
|
|
22
|
+
function assignVariableBindingUnits(graph, node, field) {
|
|
23
|
+
if (!isNumericVariableBindingField(field)) return;
|
|
24
|
+
const owner = variableBindingOwner(graph, node);
|
|
25
|
+
node.variableBindingScales = {
|
|
26
|
+
...node.variableBindingScales,
|
|
27
|
+
[field]: owner.variableAssignmentScales[field] ?? 1
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/** Fields a bound number sets as a length in pixels, as Figma's do, whatever unit they held. */
|
|
31
|
+
const TEXT_LENGTH_FIELDS = /* @__PURE__ */ new Set(["lineHeight", "letterSpacing"]);
|
|
32
|
+
/** A bound number as the field stores it. */
|
|
33
|
+
function boundNumberValue(field, value) {
|
|
34
|
+
return TEXT_LENGTH_FIELDS.has(field) ? pixelLength(value) : value;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The values a node's numeric bindings resolve to in its mode, in scene units, for the fields
|
|
38
|
+
* whose stored value differs. A width or height an instance overrides keeps its own value.
|
|
39
|
+
*/
|
|
40
|
+
function resolvedNumericBindings(graph, node, fallback = "active") {
|
|
41
|
+
const updates = {};
|
|
42
|
+
for (const [field, variableId] of Object.entries(node.boundVariables)) {
|
|
43
|
+
if (!NUMERIC_FIELDS.has(field)) continue;
|
|
44
|
+
if ((field === "width" || field === "height") && hasInstanceOverride(graph, node.id, field)) continue;
|
|
45
|
+
const value = graph.resolveNumberVariableForNode(node.id, variableId, fallback);
|
|
46
|
+
if (value === void 0 || !Number.isFinite(value)) continue;
|
|
47
|
+
const effective = value * (node.variableBindingScales[field] ?? 1);
|
|
48
|
+
if (!Number.isFinite(effective)) continue;
|
|
49
|
+
const next = boundNumberValue(field, field === "opacity" ? Math.max(0, Math.min(1, effective)) : effective);
|
|
50
|
+
if (!isEqual(node[field], next)) Object.assign(updates, { [field]: next });
|
|
51
|
+
}
|
|
52
|
+
return updates;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The text, font family, and visibility a node's string and boolean bindings resolve to in its
|
|
56
|
+
* mode, for the fields whose stored value differs. Text, a font family, or visibility an instance
|
|
57
|
+
* overrides, which typing in a layer or toggling its eye records, keeps its own value, as an
|
|
58
|
+
* overridden width or height does. A font family is only named here; the editor loads its faces
|
|
59
|
+
* after the reconcile (`loadBoundFonts` in Core), and the text draws in a fallback until they do.
|
|
60
|
+
*/
|
|
61
|
+
function resolvedValueBindings(graph, node, fallback = "active") {
|
|
62
|
+
const updates = {};
|
|
63
|
+
const resolve = (field) => {
|
|
64
|
+
const variableId = node.boundVariables[field];
|
|
65
|
+
if (!variableId || hasInstanceOverride(graph, node.id, field)) return void 0;
|
|
66
|
+
return graph.resolveVariableForNode(node.id, variableId, fallback);
|
|
67
|
+
};
|
|
68
|
+
const text = node.type === "TEXT" ? variableText(resolve("text")) : void 0;
|
|
69
|
+
if (text !== void 0 && text !== node.text) updates.text = text;
|
|
70
|
+
const fontFamily = node.type === "TEXT" ? variableFontFamily(resolve("fontFamily")) : void 0;
|
|
71
|
+
if (fontFamily !== void 0 && fontFamily !== node.fontFamily) updates.fontFamily = fontFamily;
|
|
72
|
+
const visible = variableTruthy(resolve("visible"));
|
|
73
|
+
if (visible !== void 0 && visible !== node.visible) updates.visible = visible;
|
|
74
|
+
return updates;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The icon an icon frame's `iconName` binding names in its mode, when it differs from the icon
|
|
78
|
+
* it draws. Only frames that are icons resolve it; other layers keep the binding inert. The
|
|
79
|
+
* caller redraws the frame, as resolving only names the icon.
|
|
80
|
+
*/
|
|
81
|
+
function resolvedIconBinding(graph, node, fallback = "active") {
|
|
82
|
+
if (node.type !== "FRAME") return void 0;
|
|
83
|
+
const icon = readIcon(node);
|
|
84
|
+
if (!icon) return void 0;
|
|
85
|
+
const variableId = node.boundVariables["iconName"];
|
|
86
|
+
if (!variableId || hasInstanceOverride(graph, node.id, "iconName")) return void 0;
|
|
87
|
+
const resolved = graph.resolveVariableForNode(node.id, variableId, fallback);
|
|
88
|
+
if (typeof resolved !== "string") return void 0;
|
|
89
|
+
const name = resolved.trim();
|
|
90
|
+
if (name === "" || name === icon.name || !ICON_NAME.test(name)) return void 0;
|
|
91
|
+
return name;
|
|
92
|
+
}
|
|
93
|
+
/** Fields of a range of characters a bound number gives its value. */
|
|
94
|
+
const NUMERIC_RUN_FIELDS = [
|
|
95
|
+
"fontSize",
|
|
96
|
+
"fontWeight",
|
|
97
|
+
"letterSpacing",
|
|
98
|
+
"lineHeight"
|
|
99
|
+
];
|
|
100
|
+
/**
|
|
101
|
+
* The runs a text's character bindings resolve to in its mode, when a bound number or font family
|
|
102
|
+
* differs from what its characters hold. Bound font styles are left as stored.
|
|
103
|
+
*/
|
|
104
|
+
function resolvedRunBindings(graph, node, fallback = "active") {
|
|
105
|
+
const styleRuns = node.styleRuns.map((run) => {
|
|
106
|
+
const bound = run.style.boundVariables;
|
|
107
|
+
if (!bound) return run;
|
|
108
|
+
let style = run.style;
|
|
109
|
+
for (const field of NUMERIC_RUN_FIELDS) {
|
|
110
|
+
const variableId = bound[field];
|
|
111
|
+
if (!variableId) continue;
|
|
112
|
+
const value = graph.resolveNumberVariableForNode(node.id, variableId, fallback);
|
|
113
|
+
if (value === void 0 || !Number.isFinite(value)) continue;
|
|
114
|
+
const next = boundNumberValue(field, value);
|
|
115
|
+
if (isEqual(style[field], next)) continue;
|
|
116
|
+
style = {
|
|
117
|
+
...style,
|
|
118
|
+
[field]: next
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
const familyId = bound.fontFamily;
|
|
122
|
+
const family = familyId ? variableFontFamily(graph.resolveVariableForNode(node.id, familyId, fallback)) : void 0;
|
|
123
|
+
if (family !== void 0 && family !== style.fontFamily) style = {
|
|
124
|
+
...style,
|
|
125
|
+
fontFamily: family
|
|
126
|
+
};
|
|
127
|
+
return style === run.style ? run : {
|
|
128
|
+
...run,
|
|
129
|
+
style
|
|
130
|
+
};
|
|
131
|
+
});
|
|
132
|
+
return styleRuns.some((run, index) => run !== node.styleRuns[index]) ? { styleRuns } : {};
|
|
133
|
+
}
|
|
134
|
+
/** The variables a node binds, its own and its characters'. */
|
|
135
|
+
function boundVariableIds(node) {
|
|
136
|
+
return [...Object.values(node.boundVariables), ...node.styleRuns.flatMap((run) => Object.values(run.style.boundVariables ?? {}))].filter((id) => typeof id === "string");
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* A bound paint takes its whole color from the variable, alpha included, the way Figma stores
|
|
140
|
+
* it: the variable's RGB at full alpha, and its alpha as the paint's opacity.
|
|
141
|
+
*/
|
|
142
|
+
function applyBoundColor(paint, color) {
|
|
143
|
+
paint.color = {
|
|
144
|
+
...color,
|
|
145
|
+
a: 1
|
|
146
|
+
};
|
|
147
|
+
paint.opacity = color.a;
|
|
148
|
+
}
|
|
149
|
+
/** The fills and strokes a node's color bindings resolve to in its mode, when it has any. */
|
|
150
|
+
function resolvedPaintBindings(graph, node, fallback = "active") {
|
|
151
|
+
const changes = {};
|
|
152
|
+
for (const field in node.boundVariables) {
|
|
153
|
+
if (!field.endsWith("/color")) continue;
|
|
154
|
+
const paint = paintBindingTarget(field);
|
|
155
|
+
if (!paint) continue;
|
|
156
|
+
const color = graph.resolveColorVariableForNode(node.id, node.boundVariables[field], fallback);
|
|
157
|
+
const { index } = paint;
|
|
158
|
+
if (!color) continue;
|
|
159
|
+
if (paint.list === "fills") {
|
|
160
|
+
if (!node.fills[index]) continue;
|
|
161
|
+
changes.fills ??= copyFills(node.fills);
|
|
162
|
+
applyBoundColor(changes.fills[index], color);
|
|
163
|
+
} else {
|
|
164
|
+
if (!node.strokes[index]) continue;
|
|
165
|
+
changes.strokes ??= copyStrokes(node.strokes);
|
|
166
|
+
applyBoundColor(changes.strokes[index], color);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return changes;
|
|
170
|
+
}
|
|
171
|
+
/** These variables and every variable that aliases one of them, at any depth and in any mode. */
|
|
172
|
+
function variablesResolvingThrough(graph, ids) {
|
|
173
|
+
const found = new Set(ids);
|
|
174
|
+
let grew = true;
|
|
175
|
+
while (grew) {
|
|
176
|
+
grew = false;
|
|
177
|
+
for (const variable of graph.variables.values()) {
|
|
178
|
+
if (found.has(variable.id)) continue;
|
|
179
|
+
if (Object.values(variable.valuesByMode).some((value) => variableValueReferences(value).some((id) => found.has(id)))) {
|
|
180
|
+
found.add(variable.id);
|
|
181
|
+
grew = true;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return found;
|
|
186
|
+
}
|
|
187
|
+
function subtreeNodes(graph, roots) {
|
|
188
|
+
const nodes = [];
|
|
189
|
+
const pending = [...roots];
|
|
190
|
+
for (let id = pending.pop(); id !== void 0; id = pending.pop()) {
|
|
191
|
+
const node = graph.getNode(id);
|
|
192
|
+
if (!node) continue;
|
|
193
|
+
nodes.push(node);
|
|
194
|
+
pending.push(...node.childIds);
|
|
195
|
+
}
|
|
196
|
+
return nodes;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* The collections whose variables the layers in these subtrees resolve: those they bind, and
|
|
200
|
+
* those the bound variables alias, so a mode set on the subtrees can change what they show.
|
|
201
|
+
*/
|
|
202
|
+
function collectionsBoundIn(graph, roots) {
|
|
203
|
+
const pending = subtreeNodes(graph, roots).flatMap(boundVariableIds);
|
|
204
|
+
const seen = /* @__PURE__ */ new Set();
|
|
205
|
+
const collections = /* @__PURE__ */ new Set();
|
|
206
|
+
for (let id = pending.pop(); id !== void 0; id = pending.pop()) {
|
|
207
|
+
if (seen.has(id)) continue;
|
|
208
|
+
seen.add(id);
|
|
209
|
+
const variable = graph.variables.get(id);
|
|
210
|
+
if (!variable) continue;
|
|
211
|
+
collections.add(variable.collectionId);
|
|
212
|
+
for (const value of Object.values(variable.valuesByMode)) pending.push(...variableValueReferences(value));
|
|
213
|
+
}
|
|
214
|
+
return collections;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* The layers a change to these variables reaches: those binding one of them, or a variable that
|
|
218
|
+
* aliases one, on the layer itself or on its characters.
|
|
219
|
+
*/
|
|
220
|
+
function layersUsingVariables(graph, ids) {
|
|
221
|
+
const variables = variablesResolvingThrough(graph, ids);
|
|
222
|
+
return [...graph.getAllNodes()].filter((node) => boundVariableIds(node).some((id) => variables.has(id)));
|
|
223
|
+
}
|
|
224
|
+
function scopedNodes(graph, scope) {
|
|
225
|
+
if (!scope) return graph.getAllNodes();
|
|
226
|
+
if ("subtrees" in scope) return subtreeNodes(graph, scope.subtrees);
|
|
227
|
+
return layersUsingVariables(graph, scope.variables);
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Resolve live numeric, text, font family, and visibility bindings, numbers in scene units, without authoring
|
|
231
|
+
* instance overrides. A scope limits it to the layers a change can reach, so layers whose saved
|
|
232
|
+
* values differ from their bindings elsewhere in the document are left as saved.
|
|
233
|
+
*/
|
|
234
|
+
function reconcileVariableBindings(graph, scope) {
|
|
235
|
+
const changed = [];
|
|
236
|
+
for (const node of scopedNodes(graph, scope)) {
|
|
237
|
+
const updates = {
|
|
238
|
+
...resolvedNumericBindings(graph, node),
|
|
239
|
+
...resolvedValueBindings(graph, node),
|
|
240
|
+
...resolvedRunBindings(graph, node)
|
|
241
|
+
};
|
|
242
|
+
if (Object.keys(updates).length === 0) continue;
|
|
243
|
+
graph.updateNode(node.id, updates);
|
|
244
|
+
changed.push(node.id);
|
|
245
|
+
}
|
|
246
|
+
return changed;
|
|
247
|
+
}
|
|
248
|
+
//#endregion
|
|
249
|
+
export { ICON_BINDING_FIELDS, TEXT_CONTENT_VARIABLE_TYPES, VISIBILITY_VARIABLE_TYPES, assignVariableBindingUnits, boundNumberValue, collectionsBoundIn, isNumericVariableBindingField, layersUsingVariables, paintBindingTarget, reconcileVariableBindings, resolvedIconBinding, resolvedNumericBindings, resolvedPaintBindings, resolvedRunBindings, resolvedValueBindings, variableBindingOwner, variablesResolvingThrough };
|
|
250
|
+
|
|
251
|
+
//# sourceMappingURL=bindings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bindings.js","names":[],"sources":["../../src/variables/bindings.ts"],"sourcesContent":["import { isEqual } from 'es-toolkit/predicate'\n\nimport type { VariableModeFallback } from '.'\nimport { copyFills, copyStrokes } from '../copy'\nimport type { SceneGraph } from '../graph'\nimport { readIcon } from '../icons/model'\nimport { ICON_NAME } from '../icons/schema'\nimport { hasInstanceOverride } from '../instances'\nimport type { Color } from '../primitives'\nimport { pixelLength } from '../text/lengths'\nimport type { Fill, SceneNode, Stroke, StyleRun, TextLength } from '../types'\nimport { NUMERIC_FIELDS, isNumericVariableBindingField, paintBindingTarget } from './fields'\nimport { variableFontFamily, variableText, variableTruthy } from './text'\nimport { variableValueReferences } from './value'\nexport {\n ICON_BINDING_FIELDS,\n isNumericVariableBindingField,\n paintBindingTarget,\n TEXT_CONTENT_VARIABLE_TYPES,\n VISIBILITY_VARIABLE_TYPES,\n type PaintBindingList\n} from './fields'\n\n/** New declarations belong to the outermost occurrence, bounded by a component definition. */\nexport function variableBindingOwner(graph: SceneGraph, node: SceneNode): SceneNode {\n let owner = node\n let current: SceneNode | undefined = node\n while (current) {\n if (current.type === 'COMPONENT' || current.type === 'COMPONENT_SET') break\n if (current.type === 'INSTANCE') owner = current\n current = current.parentId ? graph.getNode(current.parentId) : undefined\n }\n return owner\n}\n\nexport function assignVariableBindingUnits(\n graph: SceneGraph,\n node: SceneNode,\n field: string\n): void {\n if (!isNumericVariableBindingField(field)) return\n const owner = variableBindingOwner(graph, node)\n node.variableBindingScales = {\n ...node.variableBindingScales,\n [field]: owner.variableAssignmentScales[field] ?? 1\n }\n}\n\n/** Fields a bound number sets as a length in pixels, as Figma's do, whatever unit they held. */\nconst TEXT_LENGTH_FIELDS: ReadonlySet<string> = new Set(['lineHeight', 'letterSpacing'])\n\n/** A bound number as the field stores it. */\nexport function boundNumberValue(field: string, value: number): number | TextLength {\n return TEXT_LENGTH_FIELDS.has(field) ? pixelLength(value) : value\n}\n\n/**\n * The values a node's numeric bindings resolve to in its mode, in scene units, for the fields\n * whose stored value differs. A width or height an instance overrides keeps its own value.\n */\nexport function resolvedNumericBindings(\n graph: SceneGraph,\n node: SceneNode,\n fallback: VariableModeFallback = 'active'\n): Partial<SceneNode> {\n const updates: Partial<SceneNode> = {}\n for (const [field, variableId] of Object.entries(node.boundVariables)) {\n if (!NUMERIC_FIELDS.has(field)) continue\n if ((field === 'width' || field === 'height') && hasInstanceOverride(graph, node.id, field))\n continue\n const value = graph.resolveNumberVariableForNode(node.id, variableId, fallback)\n if (value === undefined || !Number.isFinite(value)) continue\n const scale = node.variableBindingScales[field] ?? 1\n const effective = value * scale\n if (!Number.isFinite(effective)) continue\n const next = boundNumberValue(\n field,\n field === 'opacity' ? Math.max(0, Math.min(1, effective)) : effective\n )\n if (!isEqual(node[field as keyof SceneNode], next)) Object.assign(updates, { [field]: next })\n }\n return updates\n}\n\n/**\n * The text, font family, and visibility a node's string and boolean bindings resolve to in its\n * mode, for the fields whose stored value differs. Text, a font family, or visibility an instance\n * overrides, which typing in a layer or toggling its eye records, keeps its own value, as an\n * overridden width or height does. A font family is only named here; the editor loads its faces\n * after the reconcile (`loadBoundFonts` in Core), and the text draws in a fallback until they do.\n */\nexport function resolvedValueBindings(\n graph: SceneGraph,\n node: SceneNode,\n fallback: VariableModeFallback = 'active'\n): Partial<SceneNode> {\n const updates: Partial<SceneNode> = {}\n const resolve = (field: 'text' | 'fontFamily' | 'visible') => {\n const variableId = node.boundVariables[field]\n if (!variableId || hasInstanceOverride(graph, node.id, field)) return undefined\n return graph.resolveVariableForNode(node.id, variableId, fallback)\n }\n const text = node.type === 'TEXT' ? variableText(resolve('text')) : undefined\n if (text !== undefined && text !== node.text) updates.text = text\n const fontFamily = node.type === 'TEXT' ? variableFontFamily(resolve('fontFamily')) : undefined\n if (fontFamily !== undefined && fontFamily !== node.fontFamily) updates.fontFamily = fontFamily\n // Figma binds visibility to text too, and shows the layer when the text reads as true.\n const visible = variableTruthy(resolve('visible'))\n if (visible !== undefined && visible !== node.visible) updates.visible = visible\n return updates\n}\n\n/**\n * The icon an icon frame's `iconName` binding names in its mode, when it differs from the icon\n * it draws. Only frames that are icons resolve it; other layers keep the binding inert. The\n * caller redraws the frame, as resolving only names the icon.\n */\nexport function resolvedIconBinding(\n graph: SceneGraph,\n node: SceneNode,\n fallback: VariableModeFallback = 'active'\n): string | undefined {\n if (node.type !== 'FRAME') return undefined\n const icon = readIcon(node)\n if (!icon) return undefined\n const variableId = node.boundVariables['iconName']\n if (!variableId || hasInstanceOverride(graph, node.id, 'iconName')) return undefined\n const resolved = graph.resolveVariableForNode(node.id, variableId, fallback)\n if (typeof resolved !== 'string') return undefined\n const name = resolved.trim()\n if (name === '' || name === icon.name || !ICON_NAME.test(name)) return undefined\n return name\n}\n\n/** Fields of a range of characters a bound number gives its value. */\nconst NUMERIC_RUN_FIELDS = ['fontSize', 'fontWeight', 'letterSpacing', 'lineHeight'] as const\n\n/**\n * The runs a text's character bindings resolve to in its mode, when a bound number or font family\n * differs from what its characters hold. Bound font styles are left as stored.\n */\nexport function resolvedRunBindings(\n graph: SceneGraph,\n node: SceneNode,\n fallback: VariableModeFallback = 'active'\n): Pick<Partial<SceneNode>, 'styleRuns'> {\n const styleRuns = node.styleRuns.map((run): StyleRun => {\n const bound = run.style.boundVariables\n if (!bound) return run\n let style = run.style\n for (const field of NUMERIC_RUN_FIELDS) {\n const variableId = bound[field]\n if (!variableId) continue\n const value = graph.resolveNumberVariableForNode(node.id, variableId, fallback)\n if (value === undefined || !Number.isFinite(value)) continue\n const next = boundNumberValue(field, value)\n if (isEqual(style[field], next)) continue\n style = { ...style, [field]: next }\n }\n const familyId = bound.fontFamily\n const family = familyId\n ? variableFontFamily(graph.resolveVariableForNode(node.id, familyId, fallback))\n : undefined\n if (family !== undefined && family !== style.fontFamily)\n style = { ...style, fontFamily: family }\n return style === run.style ? run : { ...run, style }\n })\n const changed = styleRuns.some((run, index) => run !== node.styleRuns[index])\n return changed ? { styleRuns } : {}\n}\n\n/** The variables a node binds, its own and its characters'. */\nfunction boundVariableIds(node: SceneNode): string[] {\n return [\n ...Object.values(node.boundVariables),\n ...node.styleRuns.flatMap((run) => Object.values(run.style.boundVariables ?? {}))\n ].filter((id): id is string => typeof id === 'string')\n}\n\n/**\n * A bound paint takes its whole color from the variable, alpha included, the way Figma stores\n * it: the variable's RGB at full alpha, and its alpha as the paint's opacity.\n */\nfunction applyBoundColor(paint: Fill | Stroke, color: Color): void {\n paint.color = { ...color, a: 1 }\n paint.opacity = color.a\n}\n\n/** The fills and strokes a node's color bindings resolve to in its mode, when it has any. */\nexport function resolvedPaintBindings(\n graph: SceneGraph,\n node: SceneNode,\n fallback: VariableModeFallback = 'active'\n): Pick<Partial<SceneNode>, 'fills' | 'strokes'> {\n // Most nodes bind nothing, so no copy is made until a paint binding is actually found.\n const changes: Pick<Partial<SceneNode>, 'fills' | 'strokes'> = {}\n for (const field in node.boundVariables) {\n if (!field.endsWith('/color')) continue\n const paint = paintBindingTarget(field)\n if (!paint) continue\n const color = graph.resolveColorVariableForNode(node.id, node.boundVariables[field], fallback)\n const { index } = paint\n if (!color) continue\n if (paint.list === 'fills') {\n if (!node.fills[index]) continue\n changes.fills ??= copyFills(node.fills)\n applyBoundColor(changes.fills[index], color)\n } else {\n if (!node.strokes[index]) continue\n changes.strokes ??= copyStrokes(node.strokes)\n applyBoundColor(changes.strokes[index], color)\n }\n }\n return changes\n}\n\n/**\n * The layers a reconcile looks at: those bound to these variables, directly or through a variable\n * aliasing them, or the layers in these subtrees. Without a scope, every layer.\n */\nexport type BindingScope = { variables: Iterable<string> } | { subtrees: Iterable<string> }\n\n/** These variables and every variable that aliases one of them, at any depth and in any mode. */\nexport function variablesResolvingThrough(graph: SceneGraph, ids: Iterable<string>): Set<string> {\n const found = new Set(ids)\n let grew = true\n while (grew) {\n grew = false\n for (const variable of graph.variables.values()) {\n if (found.has(variable.id)) continue\n const aliases = Object.values(variable.valuesByMode).some((value) =>\n variableValueReferences(value).some((id) => found.has(id))\n )\n if (aliases) {\n found.add(variable.id)\n grew = true\n }\n }\n }\n return found\n}\n\nfunction subtreeNodes(graph: SceneGraph, roots: Iterable<string>): SceneNode[] {\n const nodes: SceneNode[] = []\n const pending = [...roots]\n for (let id = pending.pop(); id !== undefined; id = pending.pop()) {\n const node = graph.getNode(id)\n if (!node) continue\n nodes.push(node)\n pending.push(...node.childIds)\n }\n return nodes\n}\n\n/**\n * The collections whose variables the layers in these subtrees resolve: those they bind, and\n * those the bound variables alias, so a mode set on the subtrees can change what they show.\n */\nexport function collectionsBoundIn(graph: SceneGraph, roots: Iterable<string>): Set<string> {\n const pending = subtreeNodes(graph, roots).flatMap(boundVariableIds)\n const seen = new Set<string>()\n const collections = new Set<string>()\n for (let id = pending.pop(); id !== undefined; id = pending.pop()) {\n if (seen.has(id)) continue\n seen.add(id)\n const variable = graph.variables.get(id)\n if (!variable) continue\n collections.add(variable.collectionId)\n for (const value of Object.values(variable.valuesByMode))\n pending.push(...variableValueReferences(value))\n }\n return collections\n}\n\n/**\n * The layers a change to these variables reaches: those binding one of them, or a variable that\n * aliases one, on the layer itself or on its characters.\n */\nexport function layersUsingVariables(graph: SceneGraph, ids: Iterable<string>): SceneNode[] {\n const variables = variablesResolvingThrough(graph, ids)\n return [...graph.getAllNodes()].filter((node) =>\n boundVariableIds(node).some((id) => variables.has(id))\n )\n}\n\nfunction scopedNodes(graph: SceneGraph, scope: BindingScope | undefined): Iterable<SceneNode> {\n if (!scope) return graph.getAllNodes()\n if ('subtrees' in scope) return subtreeNodes(graph, scope.subtrees)\n return layersUsingVariables(graph, scope.variables)\n}\n\n/**\n * Resolve live numeric, text, font family, and visibility bindings, numbers in scene units, without authoring\n * instance overrides. A scope limits it to the layers a change can reach, so layers whose saved\n * values differ from their bindings elsewhere in the document are left as saved.\n */\nexport function reconcileVariableBindings(graph: SceneGraph, scope?: BindingScope): string[] {\n const changed: string[] = []\n for (const node of scopedNodes(graph, scope)) {\n const updates = {\n ...resolvedNumericBindings(graph, node),\n ...resolvedValueBindings(graph, node),\n ...resolvedRunBindings(graph, node)\n }\n if (Object.keys(updates).length === 0) continue\n graph.updateNode(node.id, updates)\n changed.push(node.id)\n }\n return changed\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { SceneNode } from "../types.js";
|
|
2
|
+
//#region src/variables/corners.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* The changes that draw a layer's radius corner by corner, as Figma keeps it once corners can
|
|
5
|
+
* differ: each corner not bound on its own takes the radius the layer shows, and a binding of the
|
|
6
|
+
* whole radius, which a .fig or .pen file holds as one field, moves to those corners, so each
|
|
7
|
+
* corner can then change or be unbound alone.
|
|
8
|
+
*/
|
|
9
|
+
declare function independentCornerChanges(node: SceneNode): Partial<SceneNode>;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { independentCornerChanges };
|
|
12
|
+
//# sourceMappingURL=corners.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"corners.d.ts","names":[],"sources":["../../src/variables/corners.ts"],"mappings":";;;;;;;;iBAiBgB,yBAAyB,MAAM,YAAY,QAAQ"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { omit } from "es-toolkit/object";
|
|
2
|
+
//#region src/variables/corners.ts
|
|
3
|
+
const CORNERS = [
|
|
4
|
+
"topLeftRadius",
|
|
5
|
+
"topRightRadius",
|
|
6
|
+
"bottomLeftRadius",
|
|
7
|
+
"bottomRightRadius"
|
|
8
|
+
];
|
|
9
|
+
/**
|
|
10
|
+
* The changes that draw a layer's radius corner by corner, as Figma keeps it once corners can
|
|
11
|
+
* differ: each corner not bound on its own takes the radius the layer shows, and a binding of the
|
|
12
|
+
* whole radius, which a .fig or .pen file holds as one field, moves to those corners, so each
|
|
13
|
+
* corner can then change or be unbound alone.
|
|
14
|
+
*/
|
|
15
|
+
function independentCornerChanges(node) {
|
|
16
|
+
const changes = {};
|
|
17
|
+
if (!node.independentCorners) {
|
|
18
|
+
changes.independentCorners = true;
|
|
19
|
+
for (const corner of CORNERS) if (!node.boundVariables[corner]) changes[corner] = node.cornerRadius;
|
|
20
|
+
}
|
|
21
|
+
const variableId = node.boundVariables.cornerRadius;
|
|
22
|
+
if (!variableId) return changes;
|
|
23
|
+
const unbound = CORNERS.filter((corner) => !node.boundVariables[corner]);
|
|
24
|
+
const scale = node.variableBindingScales.cornerRadius;
|
|
25
|
+
changes.boundVariables = {
|
|
26
|
+
...omit(node.boundVariables, ["cornerRadius"]),
|
|
27
|
+
...Object.fromEntries(unbound.map((corner) => [corner, variableId]))
|
|
28
|
+
};
|
|
29
|
+
changes.variableBindingScales = {
|
|
30
|
+
...omit(node.variableBindingScales, ["cornerRadius"]),
|
|
31
|
+
...scale === void 0 ? {} : Object.fromEntries(unbound.map((corner) => [corner, scale]))
|
|
32
|
+
};
|
|
33
|
+
return changes;
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
export { independentCornerChanges };
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=corners.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"corners.js","names":[],"sources":["../../src/variables/corners.ts"],"sourcesContent":["import { omit } from 'es-toolkit/object'\n\nimport type { SceneNode } from '../types'\n\nconst CORNERS = [\n 'topLeftRadius',\n 'topRightRadius',\n 'bottomLeftRadius',\n 'bottomRightRadius'\n] as const\n\n/**\n * The changes that draw a layer's radius corner by corner, as Figma keeps it once corners can\n * differ: each corner not bound on its own takes the radius the layer shows, and a binding of the\n * whole radius, which a .fig or .pen file holds as one field, moves to those corners, so each\n * corner can then change or be unbound alone.\n */\nexport function independentCornerChanges(node: SceneNode): Partial<SceneNode> {\n const changes: Partial<SceneNode> = {}\n if (!node.independentCorners) {\n changes.independentCorners = true\n // A corner bound on its own keeps the value its variable gave it.\n for (const corner of CORNERS)\n if (!node.boundVariables[corner]) changes[corner] = node.cornerRadius\n }\n const variableId = node.boundVariables.cornerRadius\n if (!variableId) return changes\n const unbound = CORNERS.filter((corner) => !node.boundVariables[corner])\n const scale = node.variableBindingScales.cornerRadius\n changes.boundVariables = {\n ...omit(node.boundVariables, ['cornerRadius']),\n ...Object.fromEntries(unbound.map((corner) => [corner, variableId]))\n }\n changes.variableBindingScales = {\n ...omit(node.variableBindingScales, ['cornerRadius']),\n ...(scale === undefined ? {} : Object.fromEntries(unbound.map((corner) => [corner, scale])))\n }\n return changes\n}\n"],"mappings":";;AAIA,MAAM,UAAU;CACd;CACA;CACA;CACA;AACF;;;;;;;AAQA,SAAgB,yBAAyB,MAAqC;CAC5E,MAAM,UAA8B,CAAC;CACrC,IAAI,CAAC,KAAK,oBAAoB;EAC5B,QAAQ,qBAAqB;EAE7B,KAAK,MAAM,UAAU,SACnB,IAAI,CAAC,KAAK,eAAe,SAAS,QAAQ,UAAU,KAAK;CAC7D;CACA,MAAM,aAAa,KAAK,eAAe;CACvC,IAAI,CAAC,YAAY,OAAO;CACxB,MAAM,UAAU,QAAQ,QAAQ,WAAW,CAAC,KAAK,eAAe,OAAO;CACvE,MAAM,QAAQ,KAAK,sBAAsB;CACzC,QAAQ,iBAAiB;EACvB,GAAG,KAAK,KAAK,gBAAgB,CAAC,cAAc,CAAC;EAC7C,GAAG,OAAO,YAAY,QAAQ,KAAK,WAAW,CAAC,QAAQ,UAAU,CAAC,CAAC;CACrE;CACA,QAAQ,wBAAwB;EAC9B,GAAG,KAAK,KAAK,uBAAuB,CAAC,cAAc,CAAC;EACpD,GAAI,UAAU,KAAA,IAAY,CAAC,IAAI,OAAO,YAAY,QAAQ,KAAK,WAAW,CAAC,QAAQ,KAAK,CAAC,CAAC;CAC5F;CACA,OAAO;AACT"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//#region src/variables/fields.d.ts
|
|
2
|
+
declare function isNumericVariableBindingField(field: string): boolean;
|
|
3
|
+
/**
|
|
4
|
+
* The variable types text content binds to: text, or a number shown as text, as Figma's layer
|
|
5
|
+
* panel offers. Figma's plugin API takes text alone; font family stays text-only.
|
|
6
|
+
*/
|
|
7
|
+
declare const TEXT_CONTENT_VARIABLE_TYPES: readonly ["STRING", "FLOAT"];
|
|
8
|
+
/**
|
|
9
|
+
* The icon an icon frame draws, bound to a text variable holding its name: a mode change swaps
|
|
10
|
+
* the icon. Only icon frames resolve it; other layers keep it as an inert binding.
|
|
11
|
+
*/
|
|
12
|
+
declare const ICON_BINDING_FIELDS: ReadonlySet<string>;
|
|
13
|
+
/**
|
|
14
|
+
* The variable types visibility binds to: a boolean, or text that shows the layer unless it reads
|
|
15
|
+
* as false, as Figma's layer panel offers. Figma's plugin API takes booleans alone.
|
|
16
|
+
*/
|
|
17
|
+
declare const VISIBILITY_VARIABLE_TYPES: readonly ["BOOLEAN", "STRING"];
|
|
18
|
+
/** The paint lists whose colours bind to variables, one binding field per paint. */
|
|
19
|
+
type PaintBindingList = 'fills' | 'strokes';
|
|
20
|
+
/**
|
|
21
|
+
* The paint a binding field names the colour of, such as the second fill for `fills/1/color`, or
|
|
22
|
+
* null for a field that binds anything else.
|
|
23
|
+
*/
|
|
24
|
+
declare function paintBindingTarget(field: string): {
|
|
25
|
+
list: PaintBindingList;
|
|
26
|
+
index: number;
|
|
27
|
+
} | null;
|
|
28
|
+
//#endregion
|
|
29
|
+
export { ICON_BINDING_FIELDS, PaintBindingList, TEXT_CONTENT_VARIABLE_TYPES, VISIBILITY_VARIABLE_TYPES, isNumericVariableBindingField, paintBindingTarget };
|
|
30
|
+
//# sourceMappingURL=fields.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fields.d.ts","names":[],"sources":["../../src/variables/fields.ts"],"mappings":";iBAqCgB,8BAA8B;;;;;cAWjC;;;;;cAYA,qBAAqB;;;;;cAMrB;;KAMD;;;;;iBAQI,mBACd;EACG,MAAM;EAAkB"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
//#region src/variables/fields.ts
|
|
2
|
+
const NUMERIC_FIELDS = /* @__PURE__ */ new Set([
|
|
3
|
+
"opacity",
|
|
4
|
+
"width",
|
|
5
|
+
"height",
|
|
6
|
+
"minWidth",
|
|
7
|
+
"maxWidth",
|
|
8
|
+
"minHeight",
|
|
9
|
+
"maxHeight",
|
|
10
|
+
"x",
|
|
11
|
+
"y",
|
|
12
|
+
"rotation",
|
|
13
|
+
"cornerRadius",
|
|
14
|
+
"topLeftRadius",
|
|
15
|
+
"topRightRadius",
|
|
16
|
+
"bottomLeftRadius",
|
|
17
|
+
"bottomRightRadius",
|
|
18
|
+
"strokeWeight",
|
|
19
|
+
"borderTopWeight",
|
|
20
|
+
"borderBottomWeight",
|
|
21
|
+
"borderLeftWeight",
|
|
22
|
+
"borderRightWeight",
|
|
23
|
+
"fontSize",
|
|
24
|
+
"fontWeight",
|
|
25
|
+
"letterSpacing",
|
|
26
|
+
"lineHeight",
|
|
27
|
+
"paddingLeft",
|
|
28
|
+
"paddingRight",
|
|
29
|
+
"paddingTop",
|
|
30
|
+
"paddingBottom",
|
|
31
|
+
"itemSpacing",
|
|
32
|
+
"counterAxisSpacing",
|
|
33
|
+
"gridRowGap",
|
|
34
|
+
"gridColumnGap"
|
|
35
|
+
]);
|
|
36
|
+
function isNumericVariableBindingField(field) {
|
|
37
|
+
return NUMERIC_FIELDS.has(field);
|
|
38
|
+
}
|
|
39
|
+
/** Text content and font family are the string-valued bindings a node accepts. */
|
|
40
|
+
const STRING_BINDING_FIELDS = /* @__PURE__ */ new Set(["text", "fontFamily"]);
|
|
41
|
+
/**
|
|
42
|
+
* The variable types text content binds to: text, or a number shown as text, as Figma's layer
|
|
43
|
+
* panel offers. Figma's plugin API takes text alone; font family stays text-only.
|
|
44
|
+
*/
|
|
45
|
+
const TEXT_CONTENT_VARIABLE_TYPES = ["STRING", "FLOAT"];
|
|
46
|
+
/** Visibility is the only boolean-valued binding a node accepts. */
|
|
47
|
+
const BOOLEAN_BINDING_FIELDS = /* @__PURE__ */ new Set(["visible"]);
|
|
48
|
+
/**
|
|
49
|
+
* The icon an icon frame draws, bound to a text variable holding its name: a mode change swaps
|
|
50
|
+
* the icon. Only icon frames resolve it; other layers keep it as an inert binding.
|
|
51
|
+
*/
|
|
52
|
+
const ICON_BINDING_FIELDS = /* @__PURE__ */ new Set(["iconName"]);
|
|
53
|
+
/**
|
|
54
|
+
* The variable types visibility binds to: a boolean, or text that shows the layer unless it reads
|
|
55
|
+
* as false, as Figma's layer panel offers. Figma's plugin API takes booleans alone.
|
|
56
|
+
*/
|
|
57
|
+
const VISIBILITY_VARIABLE_TYPES = ["BOOLEAN", "STRING"];
|
|
58
|
+
const PAINT_BINDING_FIELD = /^(fills|strokes)\/(\d+)\/color$/;
|
|
59
|
+
/**
|
|
60
|
+
* The paint a binding field names the colour of, such as the second fill for `fills/1/color`, or
|
|
61
|
+
* null for a field that binds anything else.
|
|
62
|
+
*/
|
|
63
|
+
function paintBindingTarget(field) {
|
|
64
|
+
if (!field.endsWith("/color")) return null;
|
|
65
|
+
const match = PAINT_BINDING_FIELD.exec(field);
|
|
66
|
+
if (!match) return null;
|
|
67
|
+
return {
|
|
68
|
+
list: match[1] === "fills" ? "fills" : "strokes",
|
|
69
|
+
index: Number(match[2])
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
const UNIFORM_BINDING_FIELD = /^(fills|strokes)\/(\d+)\/uniforms\/([A-Za-z_]\w*)$/;
|
|
73
|
+
/**
|
|
74
|
+
* The shader uniform a binding field names, such as `fills/0/uniforms/speed`, or null for a field
|
|
75
|
+
* that binds anything else. The shader on the paint declares the uniform's type.
|
|
76
|
+
*/
|
|
77
|
+
function uniformBindingTarget(field) {
|
|
78
|
+
const match = UNIFORM_BINDING_FIELD.exec(field);
|
|
79
|
+
if (!match) return null;
|
|
80
|
+
return {
|
|
81
|
+
list: match[1] === "fills" ? "fills" : "strokes",
|
|
82
|
+
index: Number(match[2]),
|
|
83
|
+
name: match[3]
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
//#endregion
|
|
87
|
+
export { BOOLEAN_BINDING_FIELDS, ICON_BINDING_FIELDS, NUMERIC_FIELDS, STRING_BINDING_FIELDS, TEXT_CONTENT_VARIABLE_TYPES, VISIBILITY_VARIABLE_TYPES, isNumericVariableBindingField, paintBindingTarget, uniformBindingTarget };
|
|
88
|
+
|
|
89
|
+
//# sourceMappingURL=fields.js.map
|
|
@@ -0,0 +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 'fontWeight',\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 icon an icon frame draws, bound to a text variable holding its name: a mode change swaps\n * the icon. Only icon frames resolve it; other layers keep it as an inert binding.\n */\nexport const ICON_BINDING_FIELDS: ReadonlySet<string> = new Set(['iconName'])\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 {\n list: match[1] === 'fills' ? 'fills' : 'strokes',\n index: Number(match[2])\n }\n}\n\nconst UNIFORM_BINDING_FIELD = /^(fills|strokes)\\/(\\d+)\\/uniforms\\/([A-Za-z_]\\w*)$/\n\n/**\n * The shader uniform a binding field names, such as `fills/0/uniforms/speed`, or null for a field\n * that binds anything else. The shader on the paint declares the uniform's type.\n */\nexport function uniformBindingTarget(\n field: string\n): { list: PaintBindingList; index: number; name: string } | null {\n const match = UNIFORM_BINDING_FIELD.exec(field)\n if (!match) return null\n return {\n list: match[1] === 'fills' ? 'fills' : 'strokes',\n index: Number(match[2]),\n name: match[3]\n }\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;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,sCAA2C,IAAI,IAAI,CAAC,UAAU,CAAC;;;;;AAM5E,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;EACL,MAAM,MAAM,OAAO,UAAU,UAAU;EACvC,OAAO,OAAO,MAAM,EAAE;CACxB;AACF;AAEA,MAAM,wBAAwB;;;;;AAM9B,SAAgB,qBACd,OACgE;CAChE,MAAM,QAAQ,sBAAsB,KAAK,KAAK;CAC9C,IAAI,CAAC,OAAO,OAAO;CACnB,OAAO;EACL,MAAM,MAAM,OAAO,UAAU,UAAU;EACvC,OAAO,OAAO,MAAM,EAAE;EACtB,MAAM,MAAM;CACd;AACF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { FormulaValueType } from "./signatures.js";
|
|
2
|
+
import { VariableFormulaNode, VariableLiteral } from "../../types.js";
|
|
3
|
+
//#region src/variables/formula/check.d.ts
|
|
4
|
+
/** The type of a value a formula holds or a variable gives. */
|
|
5
|
+
declare function formulaValueType(value: VariableLiteral): FormulaValueType;
|
|
6
|
+
/**
|
|
7
|
+
* The type a formula gives, checking each operator's operands on the way. `reference` gives a
|
|
8
|
+
* variable's type, or nothing where it is not known, which any operand type then fits; the
|
|
9
|
+
* result is nothing when it depends on such a reference.
|
|
10
|
+
*/
|
|
11
|
+
declare function inferFormulaType(node: VariableFormulaNode, reference?: (id: string) => FormulaValueType | undefined): FormulaValueType | undefined;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { formulaValueType, inferFormulaType };
|
|
14
|
+
//# sourceMappingURL=check.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check.d.ts","names":[],"sources":["../../../src/variables/formula/check.ts"],"mappings":";;;;iBAmEgB,iBAAiB,OAAO,kBAAkB;;;;;;iBAa1C,iBACd,MAAM,qBACN,aAAY,eAAe,+BAC1B"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { VariableFormulaError, foldFormula } from "./tree.js";
|
|
2
|
+
import { formulaArity, formulaNeeds, formulaOverloads, isFormulaCall } from "./signatures.js";
|
|
3
|
+
//#region src/variables/formula/check.ts
|
|
4
|
+
/** The types an operator can give when some operand types are unknown, written as `undefined`. */
|
|
5
|
+
function formulaResultTypes(operator, types) {
|
|
6
|
+
const results = [];
|
|
7
|
+
if (types.length !== formulaArity(operator)) return results;
|
|
8
|
+
for (const { operands, result } of formulaOverloads(operator)) {
|
|
9
|
+
let fits = true;
|
|
10
|
+
for (let index = 0; fits && index < operands.length; index++) fits = types[index] === void 0 || types[index] === operands[index];
|
|
11
|
+
if (fits && !results.includes(result)) results.push(result);
|
|
12
|
+
}
|
|
13
|
+
return results;
|
|
14
|
+
}
|
|
15
|
+
/** The first overload whose operand types are `types`, checked on every operation evaluated. */
|
|
16
|
+
function matchingOverload(operator, types) {
|
|
17
|
+
for (const overload of formulaOverloads(operator)) {
|
|
18
|
+
const { operands } = overload;
|
|
19
|
+
let fits = operands.length === types.length;
|
|
20
|
+
for (let index = 0; fits && index < operands.length; index++) fits = operands[index] === types[index];
|
|
21
|
+
if (fits) return overload;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/** Check operand types against an operator's signatures; the message says what it needs. */
|
|
25
|
+
function checkFormulaOperands(operator, types) {
|
|
26
|
+
const match = matchingOverload(operator, types);
|
|
27
|
+
if (match) return match.result;
|
|
28
|
+
const arity = formulaArity(operator);
|
|
29
|
+
const { name, needs } = formulaNeeds(operator);
|
|
30
|
+
if (types.length !== arity) {
|
|
31
|
+
if (!isFormulaCall(operator)) throw new VariableFormulaError(`Wrong number of operands for ${operator}`);
|
|
32
|
+
throw new VariableFormulaError(`${name} takes ${arity} ${arity === 1 ? "value" : "values"}`);
|
|
33
|
+
}
|
|
34
|
+
throw new VariableFormulaError(`${name} ${needs}`);
|
|
35
|
+
}
|
|
36
|
+
function isColor(value) {
|
|
37
|
+
const channels = { ...value };
|
|
38
|
+
return [
|
|
39
|
+
"r",
|
|
40
|
+
"g",
|
|
41
|
+
"b",
|
|
42
|
+
"a"
|
|
43
|
+
].every((channel) => Number.isFinite(channels[channel]));
|
|
44
|
+
}
|
|
45
|
+
/** The type of a value a formula holds or a variable gives. */
|
|
46
|
+
function formulaValueType(value) {
|
|
47
|
+
if (typeof value === "number") return "FLOAT";
|
|
48
|
+
if (typeof value === "boolean") return "BOOLEAN";
|
|
49
|
+
if (typeof value === "string") return "STRING";
|
|
50
|
+
if (isColor(value)) return "COLOR";
|
|
51
|
+
throw new VariableFormulaError("Formulas use numbers, text, true or false, and colors");
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The type a formula gives, checking each operator's operands on the way. `reference` gives a
|
|
55
|
+
* variable's type, or nothing where it is not known, which any operand type then fits; the
|
|
56
|
+
* result is nothing when it depends on such a reference.
|
|
57
|
+
*/
|
|
58
|
+
function inferFormulaType(node, reference = () => void 0) {
|
|
59
|
+
return foldFormula(node, {
|
|
60
|
+
literal: formulaValueType,
|
|
61
|
+
reference,
|
|
62
|
+
operation: ({ operator }, types) => {
|
|
63
|
+
if (types.every((type) => type !== void 0)) return checkFormulaOperands(operator, types);
|
|
64
|
+
const results = formulaResultTypes(operator, types);
|
|
65
|
+
if (!results.length) checkFormulaOperands(operator, types.map((type) => type ?? "FLOAT"));
|
|
66
|
+
return results.length === 1 ? results[0] : void 0;
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
export { checkFormulaOperands, formulaValueType, inferFormulaType };
|
|
72
|
+
|
|
73
|
+
//# sourceMappingURL=check.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check.js","names":[],"sources":["../../../src/variables/formula/check.ts"],"sourcesContent":["import type { Color } from '#scene-graph/primitives'\nimport type {\n VariableFormulaNode,\n VariableFormulaOperator,\n VariableLiteral\n} from '#scene-graph/types'\n\nimport {\n formulaArity,\n formulaNeeds,\n formulaOverloads,\n isFormulaCall,\n type FormulaValueType\n} from './signatures'\nimport { foldFormula, VariableFormulaError } from './tree'\n\n/** The types an operator can give when some operand types are unknown, written as `undefined`. */\nfunction formulaResultTypes(\n operator: VariableFormulaOperator,\n types: readonly (FormulaValueType | undefined)[]\n): FormulaValueType[] {\n const results: FormulaValueType[] = []\n if (types.length !== formulaArity(operator)) return results\n for (const { operands, result } of formulaOverloads(operator)) {\n let fits = true\n for (let index = 0; fits && index < operands.length; index++)\n fits = types[index] === undefined || types[index] === operands[index]\n if (fits && !results.includes(result)) results.push(result)\n }\n return results\n}\n\n/** The first overload whose operand types are `types`, checked on every operation evaluated. */\nfunction matchingOverload(operator: VariableFormulaOperator, types: readonly FormulaValueType[]) {\n for (const overload of formulaOverloads(operator)) {\n const { operands } = overload\n let fits = operands.length === types.length\n for (let index = 0; fits && index < operands.length; index++)\n fits = operands[index] === types[index]\n if (fits) return overload\n }\n return undefined\n}\n\n/** Check operand types against an operator's signatures; the message says what it needs. */\nexport function checkFormulaOperands(\n operator: VariableFormulaOperator,\n types: readonly FormulaValueType[]\n): FormulaValueType {\n const match = matchingOverload(operator, types)\n if (match) return match.result\n const arity = formulaArity(operator)\n const { name, needs } = formulaNeeds(operator)\n if (types.length !== arity) {\n if (!isFormulaCall(operator))\n throw new VariableFormulaError(`Wrong number of operands for ${operator}`)\n throw new VariableFormulaError(`${name} takes ${arity} ${arity === 1 ? 'value' : 'values'}`)\n }\n throw new VariableFormulaError(`${name} ${needs}`)\n}\n\nfunction isColor(value: object): value is Color {\n const channels: Record<string, unknown> = { ...value }\n return ['r', 'g', 'b', 'a'].every((channel) => Number.isFinite(channels[channel]))\n}\n\n/** The type of a value a formula holds or a variable gives. */\nexport function formulaValueType(value: VariableLiteral): FormulaValueType {\n if (typeof value === 'number') return 'FLOAT'\n if (typeof value === 'boolean') return 'BOOLEAN'\n if (typeof value === 'string') return 'STRING'\n if (isColor(value)) return 'COLOR'\n throw new VariableFormulaError('Formulas use numbers, text, true or false, and colors')\n}\n\n/**\n * The type a formula gives, checking each operator's operands on the way. `reference` gives a\n * variable's type, or nothing where it is not known, which any operand type then fits; the\n * result is nothing when it depends on such a reference.\n */\nexport function inferFormulaType(\n node: VariableFormulaNode,\n reference: (id: string) => FormulaValueType | undefined = () => undefined\n): FormulaValueType | undefined {\n return foldFormula<FormulaValueType | undefined>(node, {\n literal: formulaValueType,\n reference,\n operation: ({ operator }, types) => {\n if (types.every((type) => type !== undefined)) return checkFormulaOperands(operator, types)\n const results = formulaResultTypes(operator, types)\n if (!results.length)\n checkFormulaOperands(\n operator,\n types.map((type) => type ?? 'FLOAT')\n )\n return results.length === 1 ? results[0] : undefined\n }\n })\n}\n"],"mappings":";;;;AAiBA,SAAS,mBACP,UACA,OACoB;CACpB,MAAM,UAA8B,CAAC;CACrC,IAAI,MAAM,WAAW,aAAa,QAAQ,GAAG,OAAO;CACpD,KAAK,MAAM,EAAE,UAAU,YAAY,iBAAiB,QAAQ,GAAG;EAC7D,IAAI,OAAO;EACX,KAAK,IAAI,QAAQ,GAAG,QAAQ,QAAQ,SAAS,QAAQ,SACnD,OAAO,MAAM,WAAW,KAAA,KAAa,MAAM,WAAW,SAAS;EACjE,IAAI,QAAQ,CAAC,QAAQ,SAAS,MAAM,GAAG,QAAQ,KAAK,MAAM;CAC5D;CACA,OAAO;AACT;;AAGA,SAAS,iBAAiB,UAAmC,OAAoC;CAC/F,KAAK,MAAM,YAAY,iBAAiB,QAAQ,GAAG;EACjD,MAAM,EAAE,aAAa;EACrB,IAAI,OAAO,SAAS,WAAW,MAAM;EACrC,KAAK,IAAI,QAAQ,GAAG,QAAQ,QAAQ,SAAS,QAAQ,SACnD,OAAO,SAAS,WAAW,MAAM;EACnC,IAAI,MAAM,OAAO;CACnB;AAEF;;AAGA,SAAgB,qBACd,UACA,OACkB;CAClB,MAAM,QAAQ,iBAAiB,UAAU,KAAK;CAC9C,IAAI,OAAO,OAAO,MAAM;CACxB,MAAM,QAAQ,aAAa,QAAQ;CACnC,MAAM,EAAE,MAAM,UAAU,aAAa,QAAQ;CAC7C,IAAI,MAAM,WAAW,OAAO;EAC1B,IAAI,CAAC,cAAc,QAAQ,GACzB,MAAM,IAAI,qBAAqB,gCAAgC,UAAU;EAC3E,MAAM,IAAI,qBAAqB,GAAG,KAAK,SAAS,MAAM,GAAG,UAAU,IAAI,UAAU,UAAU;CAC7F;CACA,MAAM,IAAI,qBAAqB,GAAG,KAAK,GAAG,OAAO;AACnD;AAEA,SAAS,QAAQ,OAA+B;CAC9C,MAAM,WAAoC,EAAE,GAAG,MAAM;CACrD,OAAO;EAAC;EAAK;EAAK;EAAK;CAAG,CAAC,CAAC,OAAO,YAAY,OAAO,SAAS,SAAS,QAAQ,CAAC;AACnF;;AAGA,SAAgB,iBAAiB,OAA0C;CACzE,IAAI,OAAO,UAAU,UAAU,OAAO;CACtC,IAAI,OAAO,UAAU,WAAW,OAAO;CACvC,IAAI,OAAO,UAAU,UAAU,OAAO;CACtC,IAAI,QAAQ,KAAK,GAAG,OAAO;CAC3B,MAAM,IAAI,qBAAqB,uDAAuD;AACxF;;;;;;AAOA,SAAgB,iBACd,MACA,kBAAgE,KAAA,GAClC;CAC9B,OAAO,YAA0C,MAAM;EACrD,SAAS;EACT;EACA,YAAY,EAAE,YAAY,UAAU;GAClC,IAAI,MAAM,OAAO,SAAS,SAAS,KAAA,CAAS,GAAG,OAAO,qBAAqB,UAAU,KAAK;GAC1F,MAAM,UAAU,mBAAmB,UAAU,KAAK;GAClD,IAAI,CAAC,QAAQ,QACX,qBACE,UACA,MAAM,KAAK,SAAS,QAAQ,OAAO,CACrC;GACF,OAAO,QAAQ,WAAW,IAAI,QAAQ,KAAK,KAAA;EAC7C;CACF,CAAC;AACH"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { VariableFormulaNode, VariableLiteral } from "../../types.js";
|
|
2
|
+
//#region src/variables/formula/evaluate.d.ts
|
|
3
|
+
/** Every operand is evaluated, so `false and` or `if()` with an invalid operand still fails. */
|
|
4
|
+
declare function evaluateVariableFormula(node: VariableFormulaNode, resolve: (id: string) => VariableLiteral | undefined): VariableLiteral;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { evaluateVariableFormula };
|
|
7
|
+
//# sourceMappingURL=evaluate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evaluate.d.ts","names":[],"sources":["../../../src/variables/formula/evaluate.ts"],"mappings":";;;iBAcgB,wBACd,MAAM,qBACN,UAAU,eAAe,8BACxB"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { VariableFormulaError, foldFormula } from "./tree.js";
|
|
2
|
+
import { applyFormulaOperator, isFormulaOperator } from "./signatures.js";
|
|
3
|
+
import { checkFormulaOperands, formulaValueType } from "./check.js";
|
|
4
|
+
//#region src/variables/formula/evaluate.ts
|
|
5
|
+
/** A finite number, or any other value a formula holds; anything else is refused. */
|
|
6
|
+
function checked(value) {
|
|
7
|
+
if (typeof value !== "number") formulaValueType(value);
|
|
8
|
+
else if (!Number.isFinite(value)) throw new VariableFormulaError("Formula result must be finite");
|
|
9
|
+
return value;
|
|
10
|
+
}
|
|
11
|
+
/** Every operand is evaluated, so `false and` or `if()` with an invalid operand still fails. */
|
|
12
|
+
function evaluateVariableFormula(node, resolve) {
|
|
13
|
+
return foldFormula(node, {
|
|
14
|
+
literal: checked,
|
|
15
|
+
reference: (id) => {
|
|
16
|
+
const value = resolve(id);
|
|
17
|
+
if (value === void 0) throw new VariableFormulaError(`Cannot resolve variable ${id}`);
|
|
18
|
+
return checked(value);
|
|
19
|
+
},
|
|
20
|
+
operation: ({ operator }, operands) => {
|
|
21
|
+
if (!isFormulaOperator(operator)) throw new VariableFormulaError(`Unknown formula operator ${String(operator)}`);
|
|
22
|
+
checkFormulaOperands(operator, operands.map(formulaValueType));
|
|
23
|
+
return checked(applyFormulaOperator(operator, operands));
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { evaluateVariableFormula };
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=evaluate.js.map
|