@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,238 @@
|
|
|
1
|
+
import { variableText, variableTruthy } from "../text.js";
|
|
2
|
+
import { VariableFormulaError } from "./tree.js";
|
|
3
|
+
const FLOAT_FLOAT = ["FLOAT", "FLOAT"];
|
|
4
|
+
const TEXT_TYPES = [
|
|
5
|
+
"FLOAT",
|
|
6
|
+
"BOOLEAN",
|
|
7
|
+
"STRING"
|
|
8
|
+
];
|
|
9
|
+
const SIGNATURES = {
|
|
10
|
+
add: {
|
|
11
|
+
spellings: ["+"],
|
|
12
|
+
arity: 2,
|
|
13
|
+
precedence: 5,
|
|
14
|
+
associative: true,
|
|
15
|
+
overloads: [
|
|
16
|
+
{
|
|
17
|
+
operands: FLOAT_FLOAT,
|
|
18
|
+
result: "FLOAT"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
operands: ["STRING", "STRING"],
|
|
22
|
+
result: "STRING"
|
|
23
|
+
},
|
|
24
|
+
...["FLOAT", "BOOLEAN"].flatMap((other) => [{
|
|
25
|
+
operands: ["STRING", other],
|
|
26
|
+
result: "STRING"
|
|
27
|
+
}, {
|
|
28
|
+
operands: [other, "STRING"],
|
|
29
|
+
result: "STRING"
|
|
30
|
+
}])
|
|
31
|
+
],
|
|
32
|
+
needs: "adds numbers or joins text",
|
|
33
|
+
apply: ([a, b]) => typeof a === "number" && typeof b === "number" ? a + b : `${variableText(a) ?? ""}${variableText(b) ?? ""}`
|
|
34
|
+
},
|
|
35
|
+
subtract: arithmetic("-", 5, (a, b) => a - b),
|
|
36
|
+
multiply: {
|
|
37
|
+
...arithmetic("*", 6, (a, b) => a * b),
|
|
38
|
+
associative: true
|
|
39
|
+
},
|
|
40
|
+
divide: arithmetic("/", 6, (a, b) => {
|
|
41
|
+
if (b === 0) throw new VariableFormulaError("Cannot divide by zero");
|
|
42
|
+
return a / b;
|
|
43
|
+
}),
|
|
44
|
+
negate: {
|
|
45
|
+
spellings: ["-"],
|
|
46
|
+
arity: 1,
|
|
47
|
+
precedence: 7,
|
|
48
|
+
overloads: [{
|
|
49
|
+
operands: ["FLOAT"],
|
|
50
|
+
result: "FLOAT"
|
|
51
|
+
}],
|
|
52
|
+
needs: "needs numbers",
|
|
53
|
+
apply: ([a]) => -Number(a)
|
|
54
|
+
},
|
|
55
|
+
equal: equality("==", (a, b) => a === b),
|
|
56
|
+
notEqual: equality("!=", (a, b) => a !== b),
|
|
57
|
+
less: comparison("<", (a, b) => a < b),
|
|
58
|
+
lessOrEqual: comparison("<=", (a, b) => a <= b),
|
|
59
|
+
greater: comparison(">", (a, b) => a > b),
|
|
60
|
+
greaterOrEqual: comparison(">=", (a, b) => a >= b),
|
|
61
|
+
and: logic(["and", "&&"], 2, (a, b) => a && b),
|
|
62
|
+
or: logic(["or", "||"], 1, (a, b) => a || b),
|
|
63
|
+
not: {
|
|
64
|
+
spellings: ["not", "!"],
|
|
65
|
+
arity: 1,
|
|
66
|
+
precedence: 7,
|
|
67
|
+
overloads: [{
|
|
68
|
+
operands: ["BOOLEAN"],
|
|
69
|
+
result: "BOOLEAN"
|
|
70
|
+
}],
|
|
71
|
+
needs: "needs true or false",
|
|
72
|
+
apply: ([a]) => a !== true
|
|
73
|
+
},
|
|
74
|
+
text: {
|
|
75
|
+
spellings: ["text"],
|
|
76
|
+
call: true,
|
|
77
|
+
arity: 1,
|
|
78
|
+
overloads: TEXT_TYPES.map((type) => ({
|
|
79
|
+
operands: [type],
|
|
80
|
+
result: "STRING"
|
|
81
|
+
})),
|
|
82
|
+
needs: "needs a number, text, or true or false",
|
|
83
|
+
apply: ([a]) => variableText(a) ?? ""
|
|
84
|
+
},
|
|
85
|
+
truthy: {
|
|
86
|
+
spellings: ["truthy"],
|
|
87
|
+
call: true,
|
|
88
|
+
arity: 1,
|
|
89
|
+
overloads: TEXT_TYPES.map((type) => ({
|
|
90
|
+
operands: [type],
|
|
91
|
+
result: "BOOLEAN"
|
|
92
|
+
})),
|
|
93
|
+
needs: "needs a number, text, or true or false",
|
|
94
|
+
apply: ([a]) => variableTruthy(a) ?? false
|
|
95
|
+
},
|
|
96
|
+
if: {
|
|
97
|
+
spellings: ["if"],
|
|
98
|
+
call: true,
|
|
99
|
+
arity: 3,
|
|
100
|
+
overloads: [
|
|
101
|
+
"FLOAT",
|
|
102
|
+
"BOOLEAN",
|
|
103
|
+
"STRING",
|
|
104
|
+
"COLOR"
|
|
105
|
+
].map((type) => ({
|
|
106
|
+
operands: [
|
|
107
|
+
"BOOLEAN",
|
|
108
|
+
type,
|
|
109
|
+
type
|
|
110
|
+
],
|
|
111
|
+
result: type
|
|
112
|
+
})),
|
|
113
|
+
needs: "needs true or false, then two values of the same type",
|
|
114
|
+
apply: ([condition, then, otherwise]) => condition === true ? then : otherwise
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
function arithmetic(symbol, precedence, apply) {
|
|
118
|
+
return {
|
|
119
|
+
spellings: [symbol],
|
|
120
|
+
arity: 2,
|
|
121
|
+
precedence,
|
|
122
|
+
overloads: [{
|
|
123
|
+
operands: FLOAT_FLOAT,
|
|
124
|
+
result: "FLOAT"
|
|
125
|
+
}],
|
|
126
|
+
needs: "needs numbers",
|
|
127
|
+
apply: ([a, b]) => apply(Number(a), Number(b))
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
function comparison(symbol, apply) {
|
|
131
|
+
return {
|
|
132
|
+
spellings: [symbol],
|
|
133
|
+
arity: 2,
|
|
134
|
+
precedence: 4,
|
|
135
|
+
nonAssociative: true,
|
|
136
|
+
overloads: [{
|
|
137
|
+
operands: FLOAT_FLOAT,
|
|
138
|
+
result: "BOOLEAN"
|
|
139
|
+
}],
|
|
140
|
+
needs: "needs numbers",
|
|
141
|
+
apply: ([a, b]) => apply(Number(a), Number(b))
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
function equality(symbol, apply) {
|
|
145
|
+
return {
|
|
146
|
+
spellings: [symbol],
|
|
147
|
+
arity: 2,
|
|
148
|
+
precedence: 3,
|
|
149
|
+
nonAssociative: true,
|
|
150
|
+
overloads: TEXT_TYPES.map((type) => ({
|
|
151
|
+
operands: [type, type],
|
|
152
|
+
result: "BOOLEAN"
|
|
153
|
+
})),
|
|
154
|
+
needs: "compares two numbers, two texts, or two true or false values",
|
|
155
|
+
apply: ([a, b]) => apply(a, b)
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
function logic(spellings, precedence, apply) {
|
|
159
|
+
return {
|
|
160
|
+
spellings,
|
|
161
|
+
arity: 2,
|
|
162
|
+
precedence,
|
|
163
|
+
associative: true,
|
|
164
|
+
overloads: [{
|
|
165
|
+
operands: ["BOOLEAN", "BOOLEAN"],
|
|
166
|
+
result: "BOOLEAN"
|
|
167
|
+
}],
|
|
168
|
+
needs: "needs true or false",
|
|
169
|
+
apply: ([a, b]) => apply(a === true, b === true)
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
const OPERATORS = Object.keys(SIGNATURES);
|
|
173
|
+
/** Each spelling written between operands, or before one, and the operator it reads as. */
|
|
174
|
+
function spellingIndex(written) {
|
|
175
|
+
return new Map(OPERATORS.filter((operator) => written(SIGNATURES[operator])).flatMap((operator) => SIGNATURES[operator].spellings.map((spelling) => [spelling, operator])));
|
|
176
|
+
}
|
|
177
|
+
const BINARY = spellingIndex(({ arity, call }) => arity === 2 && !call);
|
|
178
|
+
const PREFIX = spellingIndex(({ arity, call }) => arity === 1 && !call);
|
|
179
|
+
const CALLS = spellingIndex(({ call }) => call === true);
|
|
180
|
+
/** Operators spelled as words, such as `and` and `not`, which read as keywords, not names. */
|
|
181
|
+
const FORMULA_KEYWORDS = new Set([...BINARY.keys(), ...PREFIX.keys()].filter((spelling) => /^\p{L}+$/u.test(spelling)));
|
|
182
|
+
function isFormulaOperator(name) {
|
|
183
|
+
return Object.hasOwn(SIGNATURES, name);
|
|
184
|
+
}
|
|
185
|
+
function formulaArity(operator) {
|
|
186
|
+
return SIGNATURES[operator].arity;
|
|
187
|
+
}
|
|
188
|
+
/** How the operator is printed: its first spelling. */
|
|
189
|
+
function formulaSymbol(operator) {
|
|
190
|
+
return SIGNATURES[operator].spellings[0];
|
|
191
|
+
}
|
|
192
|
+
function formulaPrecedence(operator) {
|
|
193
|
+
return SIGNATURES[operator].precedence;
|
|
194
|
+
}
|
|
195
|
+
/** Written as a function call, such as `if(a, b, c)`, rather than around its operands. */
|
|
196
|
+
function isFormulaCall(operator) {
|
|
197
|
+
return SIGNATURES[operator].call === true;
|
|
198
|
+
}
|
|
199
|
+
function isFormulaAssociative(operator) {
|
|
200
|
+
return SIGNATURES[operator].associative === true;
|
|
201
|
+
}
|
|
202
|
+
/** Precedence levels whose operations do not chain, such as the comparisons. */
|
|
203
|
+
const FORMULA_NON_ASSOCIATIVE = new Set(OPERATORS.flatMap((operator) => {
|
|
204
|
+
const { nonAssociative, precedence } = SIGNATURES[operator];
|
|
205
|
+
return nonAssociative && precedence !== void 0 ? [precedence] : [];
|
|
206
|
+
}));
|
|
207
|
+
/** The operator written between operands as `spelling`, such as `AND` for `&&`. */
|
|
208
|
+
function binaryFormulaOperator(spelling) {
|
|
209
|
+
return BINARY.get(spelling.toLowerCase());
|
|
210
|
+
}
|
|
211
|
+
/** The operator written before an operand as `spelling`, such as `NOT` for `!`. */
|
|
212
|
+
function prefixFormulaOperator(spelling) {
|
|
213
|
+
return PREFIX.get(spelling.toLowerCase());
|
|
214
|
+
}
|
|
215
|
+
/** The operator a function call names, such as `TERNARY` for `if`. */
|
|
216
|
+
function formulaCallOperator(name) {
|
|
217
|
+
return CALLS.get(name.toLowerCase());
|
|
218
|
+
}
|
|
219
|
+
function formulaOverloads(operator) {
|
|
220
|
+
return SIGNATURES[operator].overloads;
|
|
221
|
+
}
|
|
222
|
+
/** The name an error gives the operator, `if()` for a call, and what it needs. */
|
|
223
|
+
function formulaNeeds(operator) {
|
|
224
|
+
const { call, needs } = SIGNATURES[operator];
|
|
225
|
+
const symbol = formulaSymbol(operator);
|
|
226
|
+
return {
|
|
227
|
+
name: call ? `${symbol}()` : symbol,
|
|
228
|
+
needs
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
/** Compute an operation whose operands have been checked against its overloads. */
|
|
232
|
+
function applyFormulaOperator(operator, operands) {
|
|
233
|
+
return SIGNATURES[operator].apply(operands);
|
|
234
|
+
}
|
|
235
|
+
//#endregion
|
|
236
|
+
export { FORMULA_KEYWORDS, FORMULA_NON_ASSOCIATIVE, applyFormulaOperator, binaryFormulaOperator, formulaArity, formulaCallOperator, formulaNeeds, formulaOverloads, formulaPrecedence, formulaSymbol, isFormulaAssociative, isFormulaCall, isFormulaOperator, prefixFormulaOperator };
|
|
237
|
+
|
|
238
|
+
//# sourceMappingURL=signatures.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signatures.js","names":[],"sources":["../../../src/variables/formula/signatures.ts"],"sourcesContent":["import type { VariableFormulaOperator, VariableLiteral, VariableType } from '#scene-graph/types'\n\nimport { variableText, variableTruthy } from '../text'\nimport { VariableFormulaError } from './tree'\n\nexport type FormulaValueType = VariableType\n\n/** One set of operand types an operator takes, and the type it then gives. */\nexport interface FormulaOverload {\n operands: readonly FormulaValueType[]\n result: FormulaValueType\n}\n\n/**\n * Everything about one operator: how it is written and binds, which operand types it takes as\n * Figma's expression signatures list them, and what it computes. The parser, printer, tokenizer,\n * type checker and evaluator all read this table.\n */\ninterface OperatorSignature {\n /** How the operator is written; the parser reads every spelling, the printer the first. */\n spellings: readonly [string, ...string[]]\n /** Written as a function call, `name(operands)`, rather than around its operands. */\n call?: boolean\n arity: 1 | 2 | 3\n /** How tightly an operator written around its operands binds; calls need none. */\n precedence?: number\n /** Grouping it differently gives the same value, so `a + (b + c)` may print as `a + b + c`. */\n associative?: boolean\n /** Its operations do not chain: `a < b < c` reads as a mistake, not as `(a < b) < c`. */\n nonAssociative?: boolean\n overloads: readonly FormulaOverload[]\n /** What the error says when no overload takes the operands. */\n needs: string\n /** Operands are checked against `overloads` before this runs. */\n apply: (operands: VariableLiteral[]) => VariableLiteral\n}\n\n/** Prefix operators bind tighter than every operator written between two operands. */\nexport const FORMULA_PREFIX_PRECEDENCE = 7\n\nconst FLOAT_FLOAT = ['FLOAT', 'FLOAT'] as const\nconst TEXT_TYPES = ['FLOAT', 'BOOLEAN', 'STRING'] as const\n\nconst SIGNATURES: Record<VariableFormulaOperator, OperatorSignature> = {\n add: {\n spellings: ['+'],\n arity: 2,\n precedence: 5,\n associative: true,\n overloads: [\n { operands: FLOAT_FLOAT, result: 'FLOAT' },\n { operands: ['STRING', 'STRING'], result: 'STRING' },\n ...(['FLOAT', 'BOOLEAN'] as const).flatMap((other) => [\n { operands: ['STRING', other], result: 'STRING' } as const,\n { operands: [other, 'STRING'], result: 'STRING' } as const\n ])\n ],\n needs: 'adds numbers or joins text',\n apply: ([a, b]) =>\n typeof a === 'number' && typeof b === 'number'\n ? a + b\n : `${variableText(a) ?? ''}${variableText(b) ?? ''}`\n },\n subtract: arithmetic('-', 5, (a, b) => a - b),\n multiply: { ...arithmetic('*', 6, (a, b) => a * b), associative: true },\n divide: arithmetic('/', 6, (a, b) => {\n if (b === 0) throw new VariableFormulaError('Cannot divide by zero')\n return a / b\n }),\n negate: {\n spellings: ['-'],\n arity: 1,\n precedence: FORMULA_PREFIX_PRECEDENCE,\n overloads: [{ operands: ['FLOAT'], result: 'FLOAT' }],\n needs: 'needs numbers',\n apply: ([a]) => -Number(a)\n },\n equal: equality('==', (a, b) => a === b),\n notEqual: equality('!=', (a, b) => a !== b),\n less: comparison('<', (a, b) => a < b),\n lessOrEqual: comparison('<=', (a, b) => a <= b),\n greater: comparison('>', (a, b) => a > b),\n greaterOrEqual: comparison('>=', (a, b) => a >= b),\n and: logic(['and', '&&'], 2, (a, b) => a && b),\n or: logic(['or', '||'], 1, (a, b) => a || b),\n not: {\n spellings: ['not', '!'],\n arity: 1,\n precedence: FORMULA_PREFIX_PRECEDENCE,\n overloads: [{ operands: ['BOOLEAN'], result: 'BOOLEAN' }],\n needs: 'needs true or false',\n apply: ([a]) => a !== true\n },\n text: {\n spellings: ['text'],\n call: true,\n arity: 1,\n overloads: TEXT_TYPES.map((type) => ({ operands: [type], result: 'STRING' })),\n needs: 'needs a number, text, or true or false',\n apply: ([a]) => variableText(a) ?? ''\n },\n truthy: {\n spellings: ['truthy'],\n call: true,\n arity: 1,\n overloads: TEXT_TYPES.map((type) => ({ operands: [type], result: 'BOOLEAN' })),\n needs: 'needs a number, text, or true or false',\n apply: ([a]) => variableTruthy(a) ?? false\n },\n if: {\n spellings: ['if'],\n call: true,\n arity: 3,\n overloads: (['FLOAT', 'BOOLEAN', 'STRING', 'COLOR'] as const).map((type) => ({\n operands: ['BOOLEAN', type, type],\n result: type\n })),\n needs: 'needs true or false, then two values of the same type',\n apply: ([condition, then, otherwise]) => (condition === true ? then : otherwise)\n }\n}\n\nfunction arithmetic(\n symbol: string,\n precedence: number,\n apply: (a: number, b: number) => number\n): OperatorSignature {\n return {\n spellings: [symbol],\n arity: 2,\n precedence,\n overloads: [{ operands: FLOAT_FLOAT, result: 'FLOAT' }],\n needs: 'needs numbers',\n apply: ([a, b]) => apply(Number(a), Number(b))\n }\n}\n\nfunction comparison(symbol: string, apply: (a: number, b: number) => boolean): OperatorSignature {\n return {\n spellings: [symbol],\n arity: 2,\n precedence: 4,\n nonAssociative: true,\n overloads: [{ operands: FLOAT_FLOAT, result: 'BOOLEAN' }],\n needs: 'needs numbers',\n apply: ([a, b]) => apply(Number(a), Number(b))\n }\n}\n\nfunction equality(\n symbol: string,\n apply: (a: VariableLiteral, b: VariableLiteral) => boolean\n): OperatorSignature {\n return {\n spellings: [symbol],\n arity: 2,\n precedence: 3,\n nonAssociative: true,\n overloads: TEXT_TYPES.map((type) => ({ operands: [type, type], result: 'BOOLEAN' })),\n needs: 'compares two numbers, two texts, or two true or false values',\n apply: ([a, b]) => apply(a, b)\n }\n}\n\nfunction logic(\n spellings: readonly [string, ...string[]],\n precedence: number,\n apply: (a: boolean, b: boolean) => boolean\n): OperatorSignature {\n return {\n spellings,\n arity: 2,\n precedence,\n associative: true,\n overloads: [{ operands: ['BOOLEAN', 'BOOLEAN'], result: 'BOOLEAN' }],\n needs: 'needs true or false',\n apply: ([a, b]) => apply(a === true, b === true)\n }\n}\n\nconst OPERATORS = Object.keys(SIGNATURES) as VariableFormulaOperator[]\n\n/** Each spelling written between operands, or before one, and the operator it reads as. */\nfunction spellingIndex(written: (signature: OperatorSignature) => boolean) {\n return new Map(\n OPERATORS.filter((operator) => written(SIGNATURES[operator])).flatMap((operator) =>\n SIGNATURES[operator].spellings.map((spelling) => [spelling, operator] as const)\n )\n )\n}\nconst BINARY = spellingIndex(({ arity, call }) => arity === 2 && !call)\nconst PREFIX = spellingIndex(({ arity, call }) => arity === 1 && !call)\nconst CALLS = spellingIndex(({ call }) => call === true)\n\n/** Operators spelled as words, such as `and` and `not`, which read as keywords, not names. */\nexport const FORMULA_KEYWORDS: ReadonlySet<string> = new Set(\n [...BINARY.keys(), ...PREFIX.keys()].filter((spelling) => /^\\p{L}+$/u.test(spelling))\n)\n\nexport function isFormulaOperator(name: string): name is VariableFormulaOperator {\n return Object.hasOwn(SIGNATURES, name)\n}\n\nexport function formulaArity(operator: VariableFormulaOperator): number {\n return SIGNATURES[operator].arity\n}\n\n/** How the operator is printed: its first spelling. */\nexport function formulaSymbol(operator: VariableFormulaOperator): string {\n return SIGNATURES[operator].spellings[0]\n}\n\nexport function formulaPrecedence(operator: VariableFormulaOperator): number | undefined {\n return SIGNATURES[operator].precedence\n}\n\n/** Written as a function call, such as `if(a, b, c)`, rather than around its operands. */\nexport function isFormulaCall(operator: VariableFormulaOperator): boolean {\n return SIGNATURES[operator].call === true\n}\n\nexport function isFormulaAssociative(operator: VariableFormulaOperator): boolean {\n return SIGNATURES[operator].associative === true\n}\n\n/** Precedence levels whose operations do not chain, such as the comparisons. */\nexport const FORMULA_NON_ASSOCIATIVE: ReadonlySet<number> = new Set(\n OPERATORS.flatMap((operator) => {\n const { nonAssociative, precedence } = SIGNATURES[operator]\n return nonAssociative && precedence !== undefined ? [precedence] : []\n })\n)\n\n/** The operator written between operands as `spelling`, such as `AND` for `&&`. */\nexport function binaryFormulaOperator(spelling: string): VariableFormulaOperator | undefined {\n return BINARY.get(spelling.toLowerCase())\n}\n\n/** The operator written before an operand as `spelling`, such as `NOT` for `!`. */\nexport function prefixFormulaOperator(spelling: string): VariableFormulaOperator | undefined {\n return PREFIX.get(spelling.toLowerCase())\n}\n\n/** The operator a function call names, such as `TERNARY` for `if`. */\nexport function formulaCallOperator(name: string): VariableFormulaOperator | undefined {\n return CALLS.get(name.toLowerCase())\n}\n\nexport function formulaOverloads(operator: VariableFormulaOperator): readonly FormulaOverload[] {\n return SIGNATURES[operator].overloads\n}\n\n/** The name an error gives the operator, `if()` for a call, and what it needs. */\nexport function formulaNeeds(operator: VariableFormulaOperator): { name: string; needs: string } {\n const { call, needs } = SIGNATURES[operator]\n const symbol = formulaSymbol(operator)\n return { name: call ? `${symbol}()` : symbol, needs }\n}\n\n/** Compute an operation whose operands have been checked against its overloads. */\nexport function applyFormulaOperator(\n operator: V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,QAAQ;CACrC,OAAO;EAAE,MAAM,OAAO,GAAG,OAAO,MAAM;EAAQ;CAAM;AACtD;;AAGA,SAAgB,qBACd,UACA,UACiB;CACjB,OAAO,WAAW,SAAS,CAAC,MAAM,QAAQ;AAC5C"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//#region src/variables/formula/tokens.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* What a piece of formula text is. `reference` is a braced `{name}` and `string` a quoted
|
|
4
|
+
* `"text"`, either of which may still be open while it is typed; `name` is a bare word that
|
|
5
|
+
* names a variable; `function` is a call's name, such as `if`; `invalid` is any character the
|
|
6
|
+
* syntax has no place for.
|
|
7
|
+
*/
|
|
8
|
+
type FormulaTokenKind = 'number' | 'string' | 'color' | 'reference' | 'name' | 'function' | 'keyword' | 'bool' | 'operator' | 'paren' | 'comma' | 'invalid';
|
|
9
|
+
interface FormulaToken {
|
|
10
|
+
kind: FormulaTokenKind;
|
|
11
|
+
text: string;
|
|
12
|
+
from: number;
|
|
13
|
+
to: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The token that starts at `at`, which must not be whitespace. Reading never fails: text the
|
|
17
|
+
* syntax has no place for is an `invalid` token, so an editor can highlight what a parser rejects.
|
|
18
|
+
*/
|
|
19
|
+
declare function readFormulaToken(source: string, at: number): FormulaToken;
|
|
20
|
+
/** Every token of a formula, in order, without the whitespace between them. */
|
|
21
|
+
declare function formulaTokens(source: string): FormulaToken[];
|
|
22
|
+
/** The variable a reference or bare name gives, without braces or surrounding spaces. */
|
|
23
|
+
declare function formulaTokenName(token: FormulaToken): string;
|
|
24
|
+
//#endregion
|
|
25
|
+
export { FormulaToken, FormulaTokenKind, formulaTokenName, formulaTokens, readFormulaToken };
|
|
26
|
+
//# sourceMappingURL=tokens.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokens.d.ts","names":[],"sources":["../../../src/variables/formula/tokens.ts"],"mappings":";;;;;;;KAQY;UAcK;EACf,MAAM;EACN;EACA;EACA;;;;;;iBA4Cc,iBAAiB,gBAAgB,aAAa;;iBAuB9C,cAAc,iBAAiB;;iBAiB/B,iBAAiB,OAAO"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { FORMULA_KEYWORDS, formulaCallOperator } from "./signatures.js";
|
|
2
|
+
//#region src/variables/formula/tokens.ts
|
|
3
|
+
const NUMBER = /(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?/y;
|
|
4
|
+
const WORD = /[\p{L}_$][\p{L}\p{N}_$]*/uy;
|
|
5
|
+
const OPERATOR = /<=|>=|==|!=|&&|\|\||[-+*/<>!]/y;
|
|
6
|
+
const SPACE = /\s+/y;
|
|
7
|
+
const COLOR = /#(?:[0-9a-fA-F]{8}|[0-9a-fA-F]{6})(?![\p{L}\p{N}_$])/uy;
|
|
8
|
+
const BOOLEANS = /* @__PURE__ */ new Set(["true", "false"]);
|
|
9
|
+
function matchAt(pattern, source, at) {
|
|
10
|
+
pattern.lastIndex = at;
|
|
11
|
+
return pattern.exec(source)?.[0];
|
|
12
|
+
}
|
|
13
|
+
/** A string runs to its unescaped closing quote, or, while it is still being typed, to the end. */
|
|
14
|
+
function stringEnd(source, at) {
|
|
15
|
+
for (let index = at + 1; index < source.length; index++) if (source[index] === "\\") index++;
|
|
16
|
+
else if (source[index] === "\"") return index + 1;
|
|
17
|
+
return source.length;
|
|
18
|
+
}
|
|
19
|
+
/** A reference runs to its `}`, or, while it is still being typed, to the next `{` or the end. */
|
|
20
|
+
function referenceEnd(source, at) {
|
|
21
|
+
for (let index = at + 1; index < source.length; index++) {
|
|
22
|
+
if (source[index] === "}") return index + 1;
|
|
23
|
+
if (source[index] === "{") return index;
|
|
24
|
+
}
|
|
25
|
+
return source.length;
|
|
26
|
+
}
|
|
27
|
+
function wordKind(word) {
|
|
28
|
+
const lower = word.toLowerCase();
|
|
29
|
+
if (FORMULA_KEYWORDS.has(lower)) return "keyword";
|
|
30
|
+
if (formulaCallOperator(lower)) return "function";
|
|
31
|
+
return BOOLEANS.has(lower) ? "bool" : "name";
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The token that starts at `at`, which must not be whitespace. Reading never fails: text the
|
|
35
|
+
* syntax has no place for is an `invalid` token, so an editor can highlight what a parser rejects.
|
|
36
|
+
*/
|
|
37
|
+
function readFormulaToken(source, at) {
|
|
38
|
+
const token = (kind, length) => ({
|
|
39
|
+
kind,
|
|
40
|
+
text: source.slice(at, at + length),
|
|
41
|
+
from: at,
|
|
42
|
+
to: at + length
|
|
43
|
+
});
|
|
44
|
+
const char = source[at] ?? "";
|
|
45
|
+
if (char === "{") return token("reference", referenceEnd(source, at) - at);
|
|
46
|
+
if (char === "\"") return token("string", stringEnd(source, at) - at);
|
|
47
|
+
if (char === "(" || char === ")") return token("paren", 1);
|
|
48
|
+
if (char === ",") return token("comma", 1);
|
|
49
|
+
const color = matchAt(COLOR, source, at);
|
|
50
|
+
if (color) return token("color", color.length);
|
|
51
|
+
const number = matchAt(NUMBER, source, at);
|
|
52
|
+
if (number) return token("number", number.length);
|
|
53
|
+
const word = matchAt(WORD, source, at);
|
|
54
|
+
if (word) return token(wordKind(word), word.length);
|
|
55
|
+
const operator = matchAt(OPERATOR, source, at);
|
|
56
|
+
return operator ? token("operator", operator.length) : token("invalid", 1);
|
|
57
|
+
}
|
|
58
|
+
/** Every token of a formula, in order, without the whitespace between them. */
|
|
59
|
+
function formulaTokens(source) {
|
|
60
|
+
const tokens = [];
|
|
61
|
+
let at = 0;
|
|
62
|
+
while (at < source.length) {
|
|
63
|
+
const space = matchAt(SPACE, source, at);
|
|
64
|
+
if (space) {
|
|
65
|
+
at += space.length;
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
const token = readFormulaToken(source, at);
|
|
69
|
+
tokens.push(token);
|
|
70
|
+
at = token.to;
|
|
71
|
+
}
|
|
72
|
+
return tokens;
|
|
73
|
+
}
|
|
74
|
+
/** The variable a reference or bare name gives, without braces or surrounding spaces. */
|
|
75
|
+
function formulaTokenName(token) {
|
|
76
|
+
if (token.kind !== "reference") return token.text;
|
|
77
|
+
return token.text.slice(1, token.text.endsWith("}") ? -1 : void 0).trim();
|
|
78
|
+
}
|
|
79
|
+
//#endregion
|
|
80
|
+
export { formulaTokenName, formulaTokens, readFormulaToken };
|
|
81
|
+
|
|
82
|
+
//# sourceMappingURL=tokens.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokens.js","names":[],"sources":["../../../src/variables/formula/tokens.ts"],"sourcesContent":["import { formulaCallOperator, FORMULA_KEYWORDS } from './signatures'\n\n/**\n * What a piece of formula text is. `reference` is a braced `{name}` and `string` a quoted\n * `\"text\"`, either of which may still be open while it is typed; `name` is a bare word that\n * names a variable; `function` is a call's name, such as `if`; `invalid` is any character the\n * syntax has no place for.\n */\nexport type FormulaTokenKind =\n | 'number'\n | 'string'\n | 'color'\n | 'reference'\n | 'name'\n | 'function'\n | 'keyword'\n | 'bool'\n | 'operator'\n | 'paren'\n | 'comma'\n | 'invalid'\n\nexport interface FormulaToken {\n kind: FormulaTokenKind\n text: string\n from: number\n to: number\n}\n\nconst NUMBER = /(?:\\d+(?:\\.\\d*)?|\\.\\d+)(?:[eE][+-]?\\d+)?/y\nconst WORD = /[\\p{L}_$][\\p{L}\\p{N}_$]*/uy\nconst OPERATOR = /<=|>=|==|!=|&&|\\|\\||[-+*/<>!]/y\nconst SPACE = /\\s+/y\nconst COLOR = /#(?:[0-9a-fA-F]{8}|[0-9a-fA-F]{6})(?![\\p{L}\\p{N}_$])/uy\nconst BOOLEANS = new Set(['true', 'false'])\n\nfunction matchAt(pattern: RegExp, source: string, at: number) {\n pattern.lastIndex = at\n return pattern.exec(source)?.[0]\n}\n\n/** A string runs to its unescaped closing quote, or, while it is still being typed, to the end. */\nfunction stringEnd(source: string, at: number) {\n for (let index = at + 1; index < source.length; index++) {\n if (source[index] === '\\\\') index++\n else if (source[index] === '\"') return index + 1\n }\n return source.length\n}\n\n/** A reference runs to its `}`, or, while it is still being typed, to the next `{` or the end. */\nfunction referenceEnd(source: string, at: number) {\n for (let index = at + 1; index < source.length; index++) {\n if (source[index] === '}') return index + 1\n if (source[index] === '{') return index\n }\n return source.length\n}\n\nfunction wordKind(word: string): FormulaTokenKind {\n const lower = word.toLowerCase()\n if (FORMULA_KEYWORDS.has(lower)) return 'keyword'\n if (formulaCallOperator(lower)) return 'function'\n return BOOLEANS.has(lower) ? 'bool' : 'name'\n}\n\n/**\n * The token that starts at `at`, which must not be whitespace. Reading never fails: text the\n * syntax has no place for is an `invalid` token, so an editor can highlight what a parser rejects.\n */\nexport function readFormulaToken(source: string, at: number): FormulaToken {\n const token = (kind: FormulaTokenKind, length: number): FormulaToken => ({\n kind,\n text: source.slice(at, at + length),\n from: at,\n to: at + length\n })\n const char = source[at] ?? ''\n if (char === '{') return token('reference', referenceEnd(source, at) - at)\n if (char === '\"') return token('string', stringEnd(source, at) - at)\n if (char === '(' || char === ')') return token('paren', 1)\n if (char === ',') return token('comma', 1)\n const color = matchAt(COLOR, source, at)\n if (color) return token('color', color.length)\n const number = matchAt(NUMBER, source, at)\n if (number) return token('number', number.length)\n const word = matchAt(WORD, source, at)\n if (word) return token(wordKind(word), word.length)\n const operator = matchAt(OPERATOR, source, at)\n return operator ? token('operator', operator.length) : token('invalid', 1)\n}\n\n/** Every token of a formula, in order, without the whitespace between them. */\nexport function formulaTokens(source: string): FormulaToken[] {\n const tokens: FormulaToken[] = []\n let at = 0\n while (at < source.length) {\n const space = matchAt(SPACE, source, at)\n if (space) {\n at += space.length\n continue\n }\n const token = readFormulaToken(source, at)\n tokens.push(token)\n at = token.to\n }\n return tokens\n}\n\n/** The variable a reference or bare name gives, without braces or surrounding spaces. */\nexport function formulaTokenName(token: FormulaToken) {\n if (token.kind !== 'reference') return token.text\n return token.text.slice(1, token.text.endsWith('}') ? -1 : undefined).trim()\n}\n"],"mappings":";;AA6BA,MAAM,S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AAS,KAAK,OAAO,MAAM,SAAS,CAAC;CACzC,MAAM,QAAQ,QAAQ,OAAO,QAAQ,EAAE;CACvC,IAAI,OAAO,OAAO,MAAM,SAAS,MAAM,MAAM;CAC7C,MAAM,SAAS,QAAQ,QAAQ,QAAQ,EAAE;CACzC,IAAI,QAAQ,OAAO,MAAM,UAAU,OAAO,MAAM;CAChD,MAAM,OAAO,QAAQ,MAAM,QAAQ,EAAE;CACrC,IAAI,MAAM,OAAO,MAAM,SAAS,IAAI,GAAG,KAAK,MAAM;CAClD,MAAM,WAAW,QAAQ,UAAU,QAAQ,EAAE;CAC7C,OAAO,WAAW,MAAM,YAAY,SAAS,MAAM,IAAI,MAAM,WAAW,CAAC;AAC3E;;AAGA,SAAgB,cAAc,QAAgC;CAC5D,MAAM,SAAyB,CAAC;CAChC,IAAI,KAAK;CACT,OAAO,KAAK,OAAO,QAAQ;EACzB,MAAM,QAAQ,QAAQ,OAAO,QAAQ,EAAE;EACvC,IAAI,OAAO;GACT,MAAM,MAAM;GACZ;EACF;EACA,MAAM,QAAQ,iBAAiB,QAAQ,EAAE;EACzC,OAAO,KAAK,KAAK;EACjB,KAAK,MAAM;CACb;CACA,OAAO;AACT;;AAGA,SAAgB,iBAAiB,OAAqB;CACpD,IAAI,MAAM,SAAS,aAAa,OAAO,MAAM;CAC7C,OAAO,MAAM,KAAK,MAAM,GAAG,MAAM,KAAK,SAAS,GAAG,IAAI,KAAK,KAAA,CAAS,CAAC,CAAC,KAAK;AAC7E"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { VariableAlias, VariableFormulaNode, VariableFormulaOperation, VariableLiteral } from "../../types.js";
|
|
2
|
+
//#region src/variables/formula/tree.d.ts
|
|
3
|
+
declare const MAX_FORMULA_DEPTH = 64;
|
|
4
|
+
declare class VariableFormulaError extends Error {
|
|
5
|
+
name: string;
|
|
6
|
+
}
|
|
7
|
+
declare function isFormulaOperation(node: VariableFormulaNode): node is VariableFormulaOperation;
|
|
8
|
+
declare function isFormulaReference(node: VariableFormulaNode): node is VariableAlias;
|
|
9
|
+
/** What a fold makes of each kind of node; an operation gets its operands' results. */
|
|
10
|
+
interface FormulaFold<T> {
|
|
11
|
+
literal: (value: VariableLiteral) => T;
|
|
12
|
+
reference: (id: string) => T;
|
|
13
|
+
operation: (node: VariableFormulaOperation, operands: T[]) => T;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Walk a formula bottom-up, as evaluating, type checking, remapping and writing it to another
|
|
17
|
+
* format all do. A tree deeper than `MAX_FORMULA_DEPTH` is refused rather than walked.
|
|
18
|
+
*/
|
|
19
|
+
declare function foldFormula<T>(node: VariableFormulaNode, fold: FormulaFold<T>, depth?: number): T;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { FormulaFold, MAX_FORMULA_DEPTH, VariableFormulaError, foldFormula, isFormulaOperation, isFormulaReference };
|
|
22
|
+
//# sourceMappingURL=tree.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tree.d.ts","names":[],"sources":["../../../src/variables/formula/tree.ts"],"mappings":";;cAOa;cAGA,6BAA6B;EAC/B;;iBAGK,mBAAmB,MAAM,sBAAsB,QAAQ;iBAIvD,mBAAmB,MAAM,sBAAsB,QAAQ;;UAKtD,YAAY;EAC3B,UAAU,OAAO,oBAAoB;EACrC,YAAY,eAAe;EAC3B,YAAY,MAAM,0BAA0B,UAAU,QAAQ;;;;;;iBAOhD,YAAY,GAAG,MAAM,qBAAqB,MAAM,YAAY,IAAI,iBAAY"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
//#region src/variables/formula/tree.ts
|
|
2
|
+
const MAX_FORMULA_DEPTH = 64;
|
|
3
|
+
const MAX_FORMULA_LENGTH = 4096;
|
|
4
|
+
var VariableFormulaError = class extends Error {
|
|
5
|
+
name = "VariableFormulaError";
|
|
6
|
+
};
|
|
7
|
+
function isFormulaOperation(node) {
|
|
8
|
+
return typeof node === "object" && "operator" in node;
|
|
9
|
+
}
|
|
10
|
+
function isFormulaReference(node) {
|
|
11
|
+
return typeof node === "object" && "aliasId" in node;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Walk a formula bottom-up, as evaluating, type checking, remapping and writing it to another
|
|
15
|
+
* format all do. A tree deeper than `MAX_FORMULA_DEPTH` is refused rather than walked.
|
|
16
|
+
*/
|
|
17
|
+
function foldFormula(node, fold, depth = 0) {
|
|
18
|
+
if (depth > 64) throw new VariableFormulaError("Formula is too deeply nested");
|
|
19
|
+
if (isFormulaOperation(node)) return fold.operation(node, node.operands.map((operand) => foldFormula(operand, fold, depth + 1)));
|
|
20
|
+
return isFormulaReference(node) ? fold.reference(node.aliasId) : fold.literal(node);
|
|
21
|
+
}
|
|
22
|
+
function mapFormulaReferences(node, map) {
|
|
23
|
+
return foldFormula(node, {
|
|
24
|
+
literal: (value) => typeof value === "object" ? { ...value } : value,
|
|
25
|
+
reference: (id) => ({ aliasId: map(id) }),
|
|
26
|
+
operation: ({ operator }, operands) => ({
|
|
27
|
+
operator,
|
|
28
|
+
operands
|
|
29
|
+
})
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
export { MAX_FORMULA_DEPTH, MAX_FORMULA_LENGTH, VariableFormulaError, foldFormula, isFormulaOperation, isFormulaReference, mapFormulaReferences };
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=tree.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tree.js","names":[],"sources":["../../../src/variables/formula/tree.ts"],"sourcesContent":["import type {\n VariableAlias,\n VariableFormulaNode,\n VariableFormulaOperation,\n VariableLiteral\n} from '#scene-graph/types'\n\nexport const MAX_FORMULA_DEPTH = 64\nexport const MAX_FORMULA_LENGTH = 4096\n\nexport class VariableFormulaError extends Error {\n override name = 'VariableFormulaError'\n}\n\nexport function isFormulaOperation(node: VariableFormulaNode): node is VariableFormulaOperation {\n return typeof node === 'object' && 'operator' in node\n}\n\nexport function isFormulaReference(node: VariableFormulaNode): node is VariableAlias {\n return typeof node === 'object' && 'aliasId' in node\n}\n\n/** What a fold makes of each kind of node; an operation gets its operands' results. */\nexport interface FormulaFold<T> {\n literal: (value: VariableLiteral) => T\n reference: (id: string) => T\n operation: (node: VariableFormulaOperation, operands: T[]) => T\n}\n\n/**\n * Walk a formula bottom-up, as evaluating, type checking, remapping and writing it to another\n * format all do. A tree deeper than `MAX_FORMULA_DEPTH` is refused rather than walked.\n */\nexport function foldFormula<T>(node: VariableFormulaNode, fold: FormulaFold<T>, depth = 0): T {\n if (depth > MAX_FORMULA_DEPTH) throw new VariableFormulaError('Formula is too deeply nested')\n if (isFormulaOperation(node))\n return fold.operation(\n node,\n node.operands.map((operand) => foldFormula(operand, fold, depth + 1))\n )\n return isFormulaReference(node) ? fold.reference(node.aliasId) : fold.literal(node)\n}\n\nexport function mapFormulaReferences(\n node: VariableFormulaNode,\n map: (id: string) => string\n): VariableFormulaNode {\n return foldFormula<VariableFormulaNode>(node, {\n literal: (value) => (typeof value === 'object' ? { ...value } : value),\n reference: (id) => ({ aliasId: map(id) }),\n operation: ({ operator }, operands) => ({ operator, operands })\n })\n}\n"],"mappings":";AAOA,MAAa,oBAAoB;AACjC,MAAa,qBAAqB;AAElC,IAAa,uBAAb,cAA0C,MAAM;CAC9C,OAAgB;AAClB;AAEA,SAAgB,mBAAmB,MAA6D;CAC9F,OAAO,OAAO,SAAS,YAAY,cAAc;AACnD;AAEA,SAAgB,mBAAmB,MAAkD;CACnF,OAAO,OAAO,SAAS,YAAY,aAAa;AAClD;;;;;AAaA,SAAgB,YAAe,MAA2B,MAAsB,QAAQ,GAAM;CAC5F,IAAI,QAAA,IAA2B,MAAM,IAAI,qBAAqB,8BAA8B;CAC5F,IAAI,mBAAmB,IAAI,GACzB,OAAO,KAAK,UACV,MACA,KAAK,SAAS,KAAK,YAAY,YAAY,SAAS,MAAM,QAAQ,CAAC,CAAC,CACtE;CACF,OAAO,mBAAmB,IAAI,IAAI,KAAK,UAAU,KAAK,OAAO,IAAI,KAAK,QAAQ,IAAI;AACpF;AAEA,SAAgB,qBACd,MACA,KACqB;CACrB,OAAO,YAAiC,MAAM;EAC5C,UAAU,UAAW,OAAO,UAAU,WAAW,EAAE,GAAG,MAAM,IAAI;EAChE,YAAY,QAAQ,EAAE,SAAS,IAAI,EAAE,EAAE;EACvC,YAAY,EAAE,YAAY,cAAc;GAAE;GAAU;EAAS;CAC/D,CAAC;AACH"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { FormulaFold, MAX_FORMULA_DEPTH, VariableFormulaError, foldFormula, isFormulaOperation, isFormulaReference } from "./formula/tree.js";
|
|
2
|
+
import { NodeVariableResolver, VariableModeFallback, VariableResolutionError, createBatchVariableResolver, getActiveModeId, getNodeVariableModeId, resolveColorVariable, resolveColorVariableForNode, resolveNumberVariable, resolveNumberVariableForNode, resolveStringVariableForNode, resolveVariable, resolveVariableForNode, resolveVariableInModes, variableValueInMode } from "./resolution.js";
|
|
3
|
+
import { ICON_BINDING_FIELDS, PaintBindingList, TEXT_CONTENT_VARIABLE_TYPES, VISIBILITY_VARIABLE_TYPES, isNumericVariableBindingField, paintBindingTarget } from "./fields.js";
|
|
4
|
+
import { BindingScope, assignVariableBindingUnits, boundNumberValue, collectionsBoundIn, layersUsingVariables, reconcileVariableBindings, resolvedIconBinding, resolvedNumericBindings, resolvedPaintBindings, resolvedRunBindings, resolvedValueBindings, variableBindingOwner, variablesResolvingThrough } from "./bindings.js";
|
|
5
|
+
import { independentCornerChanges } from "./corners.js";
|
|
6
|
+
import { FormulaValueType, formulaArity, formulaSymbol } from "./formula/signatures.js";
|
|
7
|
+
import { PrintFormulaOptions, printFormula } from "./formula/print.js";
|
|
8
|
+
import { FormulaToken, FormulaTokenKind, formulaTokenName, formulaTokens, readFormulaToken } from "./formula/tokens.js";
|
|
9
|
+
import { evaluateVariableFormula } from "./formula/evaluate.js";
|
|
10
|
+
import { formulaValueType, inferFormulaType } from "./formula/check.js";
|
|
11
|
+
import { formatVariableFormula, parseVariableFormula, variableFormulaReference } from "./formula/index.js";
|
|
12
|
+
import { variableFormulaSchema } from "./formula/schema.js";
|
|
13
|
+
import { variableAliasSchema, variableCollectionSchema, variableColorExpressionSchema, variableSchema } from "./schema.js";
|
|
14
|
+
import { variableFontFamily, variableText, variableTruthy } from "./text.js";
|
|
15
|
+
import { ROOT_FONT_SIZE_PX, tokenExpressionForValue, tokenNumberFromUnit, tokenNumberInUnit, updateTokenExpression } from "./token.js";
|
|
16
|
+
import { isUnsupportedVariableValue, mapVariableValueReferences, resolveVariableValue, variableValueReferences } from "./value.js";
|
|
17
|
+
import { SceneGraph } from "../graph.js";
|
|
18
|
+
import { Variable, VariableCollection, VariableCollectionMode, VariableType, VariableValue } from "../types.js";
|
|
19
|
+
//#region src/variables/index.d.ts
|
|
20
|
+
declare function addVariable(graph: SceneGraph, variable: Variable): void;
|
|
21
|
+
declare function removeVariable(graph: SceneGraph, id: string): void;
|
|
22
|
+
declare function addCollection(graph: SceneGraph, collection: VariableCollection): void;
|
|
23
|
+
declare function createVariable(graph: SceneGraph, generateId: () => string, name: string, type: VariableType, collectionId: string, value?: VariableValue): Variable;
|
|
24
|
+
declare function createCollection(graph: SceneGraph, generateId: () => string, name: string): VariableCollection;
|
|
25
|
+
declare function removeCollection(graph: SceneGraph, id: string): void;
|
|
26
|
+
declare function setActiveMode(graph: SceneGraph, collectionId: string, modeId: string): void;
|
|
27
|
+
declare function addMode(graph: SceneGraph, collectionId: string, modeId: string, name: string, sourceMode?: string): void;
|
|
28
|
+
/** Add a mode with a new ID from `generateId`; undo and redo replay it with `addMode`. */
|
|
29
|
+
declare function createMode(graph: SceneGraph, generateId: () => string, collectionId: string, name: string, sourceMode?: string): string | undefined;
|
|
30
|
+
declare function removeMode(graph: SceneGraph, collectionId: string, modeId: string): void;
|
|
31
|
+
declare function renameMode(graph: SceneGraph, collectionId: string, modeId: string, name: string): void;
|
|
32
|
+
declare function setDefaultMode(graph: SceneGraph, collectionId: string, modeId: string): void;
|
|
33
|
+
/** Figma has no default-mode field: the first mode is the default. */
|
|
34
|
+
declare function modesDefaultFirst(collection: VariableCollection): VariableCollectionMode[];
|
|
35
|
+
declare function getVariablesForCollection(graph: SceneGraph, collectionId: string): Variable[];
|
|
36
|
+
declare function getVariablesByType(graph: SceneGraph, type: VariableType): Variable[];
|
|
37
|
+
declare function bindVariable(graph: SceneGraph, nodeId: string, field: string, variableId: string): void;
|
|
38
|
+
declare function unbindVariable(graph: SceneGraph, nodeId: string, field: string): void;
|
|
39
|
+
//#endregion
|
|
40
|
+
export { BindingScope, type FormulaFold, type FormulaToken, type FormulaTokenKind, type FormulaValueType, ICON_BINDING_FIELDS, MAX_FORMULA_DEPTH, NodeVariableResolver, type PaintBindingList, type PrintFormulaOptions, ROOT_FONT_SIZE_PX, TEXT_CONTENT_VARIABLE_TYPES, VISIBILITY_VARIABLE_TYPES, VariableFormulaError, VariableModeFallback, VariableResolutionError, addCollection, addMode, addVariable, assignVariableBindingUnits, bindVariable, boundNumberValue, collectionsBoundIn, createBatchVariableResolver, createCollection, createMode, createVariable, evaluateVariableFormula, foldFormula, formatVariableFormula, formulaArity, formulaSymbol, formulaTokenName, formulaTokens, formulaValueType, getActiveModeId, getNodeVariableModeId, getVariablesByType, getVariablesForCollection, independentCornerChanges, inferFormulaType, isFormulaOperation, isFormulaReference, isNumericVariableBindingField, isUnsupportedVariableValue, layersUsingVariables, mapVariableValueReferences, modesDefaultFirst, paintBindingTarget, parseVariableFormula, printFormula, readFormulaToken, reconcileVariableBindings, removeCollection, removeMode, removeVariable, renameMode, resolveColorVariable, resolveColorVariableForNode, resolveNumberVariable, resolveNumberVariableForNode, resolveStringVariableForNode, resolveVariable, resolveVariableForNode, resolveVariableInModes, resolveVariableValue, resolvedIconBinding, resolvedNumericBindings, resolvedPaintBindings, resolvedRunBindings, resolvedValueBindings, setActiveMode, setDefaultMode, tokenExpressionForValue, tokenNumberFromUnit, tokenNumberInUnit, unbindVariable, updateTokenExpression, variableAliasSchema, variableBindingOwner, variableCollectionSchema, variableColorExpressionSchema, variableFontFamily, variableFormulaReference, variableFormulaSchema, variableSchema, variableText, variableTruthy, variableValueInMode, variableValueReferences, variablesResolvingThrough };
|
|
41
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/variables/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;iBAgCgB,YAAY,OAAO,YAAY,UAAU;iBAQzC,eAAe,OAAO,YAAY;iBA4BlC,cAAc,OAAO,YAAY,YAAY;iBAe7C,eACd,OAAO,YACP,0BACA,cACA,MAAM,cACN,sBACA,QAAQ,gBACP;iBAsBa,iBACd,OAAO,YACP,0BACA,eACC;iBAca,iBAAiB,OAAO,YAAY;iBAWpC,cAAc,OAAO,YAAY,sBAAsB;iBAIvD,QACd,OAAO,YACP,sBACA,gBACA,cACA;;iBAgBc,WACd,OAAO,YACP,0BACA,sBACA,cACA;iBAQc,WAAW,OAAO,YAAY,sBAAsB;iBAgBpD,WACd,OAAO,YACP,sBACA,gBACA;iBAQc,eAAe,OAAO,YAAY,sBAAsB;;iBASxD,kBAAkB,YAAY,qBAAqB;iBAKnD,0BAA0B,OAAO,YAAY,uBAAuB;iBAQpE,mBAAmB,OAAO,YAAY,MAAM,eAAe;iBAgD3D,aACd,OAAO,YACP,gBACA,eACA;iBA0Ec,eAAe,OAAO,YAAY,gBAAgB"}
|