@open-pencil/scene-graph 0.16.0 → 0.17.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/arrow-caps.d.ts +35 -14
- package/dist/arrow-caps.d.ts.map +1 -1
- package/dist/arrow-caps.js +286 -55
- package/dist/arrow-caps.js.map +1 -1
- package/dist/asset-keys.d.ts +17 -0
- package/dist/asset-keys.d.ts.map +1 -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 +62 -0
- package/dist/behaviours/kinds.d.ts.map +1 -0
- package/dist/{chunks/behaviours → behaviours}/kinds.js +76 -75
- 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 +43 -0
- package/dist/behaviours/layers.js.map +1 -0
- package/dist/behaviours/model.d.ts +48 -0
- package/dist/behaviours/model.d.ts.map +1 -0
- package/dist/behaviours/model.js +156 -0
- package/dist/behaviours/model.js.map +1 -0
- package/dist/behaviours/schema.d.ts +228 -0
- package/dist/behaviours/schema.d.ts.map +1 -0
- package/dist/behaviours/schema.js +86 -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/{chunks/behaviours → behaviours}/spec.js +6 -29
- package/dist/behaviours/spec.js.map +1 -0
- package/dist/bindings.js +26 -0
- package/dist/bindings.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.map +1 -0
- package/dist/checkpoint.d.ts +42 -0
- package/dist/checkpoint.d.ts.map +1 -0
- package/dist/checkpoint.js +249 -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 +17 -0
- package/dist/color/contrast.d.ts.map +1 -0
- package/dist/{chunks/color → color}/contrast.js +2 -24
- 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/{chunks/comments → comments}/document.js +2 -1
- 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/{chunks/comments → comments}/merge.js +1 -1
- 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/{chunks/comments/list.js → comments/threads.js} +3 -53
- 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 +4 -0
- package/dist/components/index.js +4 -0
- package/dist/components/properties.d.ts +32 -0
- package/dist/components/properties.d.ts.map +1 -0
- package/dist/components/properties.js +180 -0
- package/dist/components/properties.js.map +1 -0
- package/dist/components/variants.d.ts +33 -0
- package/dist/components/variants.d.ts.map +1 -0
- package/dist/components/variants.js +58 -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 +47 -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 +156 -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 +208 -0
- package/dist/connectors/sublayers.js.map +1 -0
- package/dist/constants.d.ts +11 -2
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +25 -1
- package/dist/constants.js.map +1 -0
- package/dist/coordinate.d.ts +94 -2
- package/dist/coordinate.d.ts.map +1 -0
- package/dist/coordinate.js +268 -1
- package/dist/coordinate.js.map +1 -0
- package/dist/copy.d.ts +49 -2
- package/dist/copy.d.ts.map +1 -0
- package/dist/copy.js +264 -2
- package/dist/copy.js.map +1 -0
- package/dist/css/blend.d.ts +11 -0
- package/dist/css/blend.d.ts.map +1 -0
- package/dist/css/blend.js +30 -0
- package/dist/css/blend.js.map +1 -0
- package/dist/css/grid.d.ts +7 -0
- package/dist/css/grid.d.ts.map +1 -0
- package/dist/{chunks/css → css}/grid.js +2 -33
- package/dist/css/grid.js.map +1 -0
- package/dist/css/index.d.ts +7 -0
- package/dist/css/index.js +7 -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/cubic.d.ts +7 -0
- package/dist/cubic.d.ts.map +1 -0
- package/dist/cubic.js +17 -0
- package/dist/cubic.js.map +1 -0
- package/dist/events.js.map +1 -0
- package/dist/export-format.d.ts +25 -0
- package/dist/export-format.d.ts.map +1 -0
- package/dist/export-format.js +47 -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.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 +64 -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 +270 -0
- package/dist/figjam/palette.d.ts.map +1 -0
- package/dist/figjam/palette.js +439 -0
- package/dist/figjam/palette.js.map +1 -0
- package/dist/figjam/text.d.ts +70 -0
- package/dist/figjam/text.d.ts.map +1 -0
- package/dist/figjam/text.js +95 -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 +44 -0
- package/dist/generated/index.d.ts.map +1 -0
- package/dist/generated/index.js +58 -0
- package/dist/generated/index.js.map +1 -0
- package/dist/generated/kind.d.ts +27 -0
- package/dist/generated/kind.d.ts.map +1 -0
- package/dist/generated/shape-with-text.d.ts +43 -0
- package/dist/generated/shape-with-text.d.ts.map +1 -0
- package/dist/generated/shape-with-text.js +135 -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 +233 -0
- package/dist/generated/sticky.js.map +1 -0
- package/dist/geometry.d.ts +89 -2
- package/dist/geometry.d.ts.map +1 -0
- package/dist/geometry.js +306 -2
- package/dist/geometry.js.map +1 -0
- package/dist/gradient.d.ts +9 -2
- package/dist/gradient.d.ts.map +1 -1
- package/dist/gradient.js +13 -1
- package/dist/gradient.js.map +1 -1
- package/dist/graph.d.ts +178 -0
- package/dist/graph.d.ts.map +1 -0
- package/dist/graph.js +625 -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/{chunks/group-bounds.js → group-bounds.js} +56 -14
- package/dist/group-bounds.js.map +1 -0
- package/dist/guides.d.ts +21 -2
- package/dist/guides.d.ts.map +1 -0
- package/dist/guides.js +5 -1
- package/dist/guides.js.map +1 -1
- package/dist/hit-test.d.ts +48 -2
- package/dist/hit-test.d.ts.map +1 -0
- package/dist/hit-test.js +75 -57
- package/dist/hit-test.js.map +1 -1
- package/dist/icons/glyph.d.ts +22 -0
- package/dist/icons/glyph.d.ts.map +1 -0
- package/dist/{chunks/icons → icons}/glyph.js +2 -40
- 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 -2
- package/dist/images.d.ts.map +1 -0
- package/dist/images.js +67 -9
- package/dist/images.js.map +1 -1
- package/dist/index.d.ts +5 -7
- package/dist/index.js +5 -23
- 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 +161 -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 +90 -0
- package/dist/instances/fields.js.map +1 -0
- package/dist/instances/index.d.ts +38 -0
- package/dist/instances/index.d.ts.map +1 -0
- package/dist/instances/index.js +180 -0
- package/dist/instances/index.js.map +1 -0
- package/dist/instances/kept-overrides.js +204 -0
- package/dist/instances/kept-overrides.js.map +1 -0
- package/dist/instances/main-component.d.ts +13 -0
- package/dist/instances/main-component.d.ts.map +1 -0
- package/dist/instances/main-component.js +50 -0
- package/dist/instances/main-component.js.map +1 -0
- package/dist/instances/overrides.d.ts +51 -0
- package/dist/instances/overrides.d.ts.map +1 -0
- package/dist/instances/overrides.js +158 -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/source-walk.js +31 -0
- package/dist/instances/source-walk.js.map +1 -0
- package/dist/instances/swap.js +288 -0
- package/dist/instances/swap.js.map +1 -0
- package/dist/instances/sync.js +327 -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.js → layout/index.js} +4 -3
- package/dist/layout/keywords.d.ts +26 -0
- package/dist/layout/keywords.d.ts.map +1 -0
- package/dist/layout/keywords.js +59 -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 -2
- package/dist/matrix.d.ts.map +1 -0
- package/dist/matrix.js +119 -1
- 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/node-defaults.d.ts +22 -2
- package/dist/node-defaults.d.ts.map +1 -0
- package/dist/node-defaults.js +254 -2
- package/dist/node-defaults.js.map +1 -0
- package/dist/outline/flatten.d.ts +15 -0
- package/dist/outline/flatten.d.ts.map +1 -0
- package/dist/outline/flatten.js +189 -0
- package/dist/outline/flatten.js.map +1 -0
- package/dist/outline/heads.js +34 -0
- package/dist/outline/heads.js.map +1 -0
- package/dist/outline/hit.d.ts +21 -0
- package/dist/outline/hit.d.ts.map +1 -0
- package/dist/outline/hit.js +276 -0
- package/dist/outline/hit.js.map +1 -0
- package/dist/outline/index.d.ts +5 -0
- package/dist/outline/index.js +5 -0
- package/dist/outline/point.d.ts +16 -0
- package/dist/outline/point.d.ts.map +1 -0
- package/dist/outline/point.js +42 -0
- package/dist/outline/point.js.map +1 -0
- package/dist/outline/shapes.d.ts +35 -0
- package/dist/outline/shapes.d.ts.map +1 -0
- package/dist/outline/shapes.js +181 -0
- package/dist/outline/shapes.js.map +1 -0
- package/dist/paints/index.d.ts +2 -0
- package/dist/paints/index.js +2 -0
- package/dist/paints/schema.d.ts +77 -0
- package/dist/paints/schema.d.ts.map +1 -0
- package/dist/paints/schema.js +56 -0
- package/dist/paints/schema.js.map +1 -0
- package/dist/parse-path.d.ts +9 -1
- package/dist/parse-path.d.ts.map +1 -1
- package/dist/parse-path.js +39 -2
- package/dist/parse-path.js.map +1 -1
- 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 +73 -0
- package/dist/plugin-data/field.js.map +1 -0
- package/dist/plugin-data/fields.d.ts +143 -0
- package/dist/plugin-data/fields.d.ts.map +1 -0
- package/dist/plugin-data/fields.js +168 -0
- package/dist/plugin-data/fields.js.map +1 -0
- package/dist/plugin-data/index.d.ts +3 -0
- package/dist/plugin-data/index.js +3 -0
- package/dist/polygon.d.ts +4 -2
- package/dist/polygon.d.ts.map +1 -1
- package/dist/polygon.js +17 -2
- package/dist/polygon.js.map +1 -1
- package/dist/preview.d.ts +12 -2
- package/dist/preview.d.ts.map +1 -0
- package/dist/preview.js +62 -1
- package/dist/preview.js.map +1 -0
- package/dist/{primitives2.d.ts → primitives/index.d.ts} +4 -3
- 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.js +24 -1
- package/dist/random.js.map +1 -0
- package/dist/resize.d.ts +6 -4
- package/dist/resize.d.ts.map +1 -1
- package/dist/resize.js +287 -2
- 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 +148 -0
- package/dist/scaling/node.js.map +1 -0
- package/dist/scaling/tree.d.ts +7 -0
- package/dist/scaling/tree.d.ts.map +1 -0
- package/dist/scaling/tree.js +47 -0
- package/dist/scaling/tree.js.map +1 -0
- package/dist/shaders/index.d.ts +4 -0
- package/dist/shaders/index.js +4 -0
- package/dist/shaders/model.d.ts +41 -0
- package/dist/shaders/model.d.ts.map +1 -0
- package/dist/shaders/model.js +71 -0
- package/dist/shaders/model.js.map +1 -0
- package/dist/shaders/schema.d.ts +41 -0
- package/dist/shaders/schema.d.ts.map +1 -0
- package/dist/shaders/schema.js +36 -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 +51 -0
- package/dist/shared-styles.d.ts.map +1 -0
- package/dist/shared-styles.js +186 -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 +77 -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 +105 -0
- package/dist/slots/content.js.map +1 -0
- package/dist/slots/frames.d.ts +40 -0
- package/dist/slots/frames.d.ts.map +1 -0
- package/dist/slots/frames.js +118 -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 +21 -2
- package/dist/snap.d.ts.map +1 -0
- package/dist/snap.js +109 -1
- package/dist/snap.js.map +1 -0
- package/dist/source-metadata.js +10 -1
- 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 → text/direction.d.ts} +2 -2
- package/dist/text/direction.d.ts.map +1 -0
- package/dist/{text-direction.js → text/direction.js} +1 -1
- 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 +24 -0
- package/dist/text/lengths.d.ts.map +1 -0
- package/dist/text/lengths.js +49 -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 → text/picture.d.ts} +3 -4
- package/dist/text/picture.d.ts.map +1 -0
- package/dist/text/picture.js +38 -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/copied.d.ts +14 -0
- package/dist/transfer/copied.d.ts.map +1 -0
- package/dist/transfer/copied.js +52 -0
- package/dist/transfer/copied.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 +8 -0
- package/dist/transfer/index.js +8 -0
- package/dist/transfer/nodes.d.ts +14 -0
- package/dist/transfer/nodes.d.ts.map +1 -0
- package/dist/transfer/nodes.js +78 -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 +195 -2007
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +89 -2
- package/dist/types.js.map +1 -0
- package/dist/undo.d.ts +93 -2
- package/dist/undo.d.ts.map +1 -0
- package/dist/undo.js +235 -1
- package/dist/undo.js.map +1 -0
- package/dist/variables/bindings.d.ts +83 -0
- package/dist/variables/bindings.d.ts.map +1 -0
- package/dist/variables/bindings.js +314 -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 +43 -0
- package/dist/variables/fields.d.ts.map +1 -0
- package/dist/variables/fields.js +104 -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 +238 -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 +16 -0
- package/dist/variables/text.d.ts.map +1 -0
- package/dist/variables/text.js +49 -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/vector-network.d.ts +65 -2
- package/dist/vector-network.d.ts.map +1 -0
- package/dist/vector-network.js +375 -2
- package/dist/vector-network.js.map +1 -0
- package/package.json +303 -137
- package/src/arrow-caps.ts +279 -62
- package/src/behaviours/index.ts +5 -0
- package/src/behaviours/kinds.ts +51 -34
- package/src/behaviours/layers.ts +5 -3
- package/src/behaviours/model.ts +25 -22
- package/src/behaviours/schema.ts +64 -13
- package/src/behaviours/spec.ts +11 -50
- package/src/bindings.ts +11 -2
- package/src/checkpoint.ts +252 -5
- package/src/clipping.ts +112 -0
- package/src/color/index.ts +1 -0
- package/src/color/schema.ts +10 -0
- package/src/comments/document.ts +1 -1
- package/src/comments/index.ts +5 -0
- package/src/comments/schema.ts +51 -0
- package/src/comments/threads.ts +1 -1
- package/src/components/exposure.ts +1 -1
- package/src/components/index.ts +8 -0
- package/src/components/properties.ts +94 -4
- package/src/components/variants.ts +52 -31
- 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 +49 -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 +141 -0
- package/src/connectors/route.ts +148 -0
- package/src/connectors/sides.ts +94 -0
- package/src/connectors/sublayers.ts +203 -0
- package/src/coordinate.ts +10 -3
- package/src/copy.ts +71 -31
- package/src/css/blend.ts +27 -0
- package/src/css/index.ts +2 -0
- package/src/css/text.ts +84 -0
- package/src/cubic.ts +14 -0
- package/src/export-format.ts +30 -1
- package/src/fields/appearance.ts +35 -0
- package/src/fields/index.ts +4 -0
- package/src/fields/layout.ts +48 -0
- package/src/fields/text.ts +32 -1
- package/src/fig-compression.ts +9 -0
- package/src/figjam/index.ts +2 -0
- package/src/figjam/palette.ts +473 -0
- package/src/figjam/text.ts +83 -0
- package/src/font-style.ts +58 -14
- package/src/generated/index.ts +76 -0
- package/src/generated/kind.ts +24 -0
- package/src/generated/shape-with-text.ts +157 -0
- package/src/generated/sticky.ts +213 -0
- package/src/geometry.ts +102 -312
- package/src/gradient.ts +14 -0
- package/src/graph.ts +849 -0
- package/src/group-bounds.ts +59 -12
- package/src/guides.ts +6 -1
- package/src/hit-test.ts +118 -74
- package/src/icons/index.ts +3 -0
- package/src/icons/model.ts +9 -0
- package/src/icons/schema.ts +19 -3
- package/src/ids.ts +34 -0
- package/src/images.ts +71 -8
- package/src/index.ts +2 -976
- package/src/instances/assignments.ts +116 -0
- package/src/instances/content-size.ts +23 -2
- package/src/instances/copies.ts +7 -10
- package/src/instances/cycles.ts +1 -1
- package/src/instances/fields.ts +47 -92
- package/src/{instances.ts → instances/index.ts} +69 -44
- package/src/instances/kept-overrides.ts +280 -0
- package/src/instances/main-component.ts +55 -1
- package/src/{instance-overrides.ts → instances/overrides.ts} +58 -2
- package/src/instances/placement.ts +1 -1
- package/src/instances/source-walk.ts +3 -9
- package/src/instances/swap.ts +451 -0
- package/src/instances/sync.ts +166 -177
- package/src/instances/vector-geometry.ts +3 -3
- package/src/layout/aspect-ratio.ts +1 -1
- package/src/layout/sizing.ts +1 -1
- package/src/layout/writes.ts +59 -0
- package/src/matrix.ts +1 -1
- package/src/mutation-impact.ts +1 -1
- package/src/node-defaults.ts +43 -3
- package/src/outline/flatten.ts +190 -0
- package/src/outline/heads.ts +52 -0
- package/src/outline/hit.ts +369 -0
- package/src/outline/index.ts +4 -0
- package/src/outline/point.ts +59 -0
- package/src/outline/shapes.ts +207 -0
- package/src/paints/index.ts +1 -0
- package/src/paints/schema.ts +67 -0
- package/src/parse-path.ts +49 -4
- package/src/plugin-data/fields.ts +69 -77
- package/src/plugin-data/index.ts +2 -0
- package/src/polygon.ts +17 -0
- package/src/preview.ts +1 -1
- package/src/{primitives.ts → primitives/index.ts} +2 -0
- package/src/primitives/schema.ts +14 -0
- package/src/resize.ts +32 -6
- package/src/scaling/node.ts +10 -6
- package/src/scaling/tree.ts +2 -1
- package/src/shaders/index.ts +3 -0
- package/src/shaders/schema.ts +3 -3
- 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 +169 -17
- package/src/slots/authoring.ts +1 -1
- package/src/slots/content.ts +10 -5
- package/src/slots/frames.ts +12 -10
- package/src/slots/index.ts +4 -0
- package/src/slots/limits.ts +1 -1
- package/src/snap.ts +3 -1
- 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/index.ts +3 -0
- package/src/text/lengths.ts +44 -0
- package/src/text/overflow.ts +12 -0
- package/src/text/picture.ts +0 -4
- package/src/text/schema.ts +7 -0
- package/src/transfer/apply.ts +1 -1
- package/src/transfer/copied.ts +72 -0
- package/src/transfer/history.ts +1 -1
- package/src/transfer/index.ts +1 -0
- package/src/transfer/nodes.ts +18 -19
- package/src/transfer/plan.ts +1 -1
- package/src/transfer/remove.ts +1 -1
- package/src/transfer/validation.ts +1 -1
- package/src/transfer/variables.ts +7 -6
- package/src/types.ts +246 -13
- package/src/undo.ts +64 -2
- package/src/variables/bindings.ts +166 -66
- package/src/variables/corners.ts +39 -0
- package/src/variables/fields.ts +83 -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.ts → variables/index.ts} +86 -146
- package/src/variables/resolution.ts +293 -0
- package/src/variables/schema.ts +31 -0
- package/src/variables/text.ts +51 -0
- package/src/variables/token.ts +27 -1
- package/src/variables/value.ts +92 -0
- package/src/vector-network.ts +263 -22
- package/dist/chunks/asset-keys.js.map +0 -1
- package/dist/chunks/behaviours/kinds.js.map +0 -1
- package/dist/chunks/behaviours/layers.js +0 -611
- package/dist/chunks/behaviours/layers.js.map +0 -1
- package/dist/chunks/behaviours/spec.js.map +0 -1
- package/dist/chunks/bindings.js +0 -18
- package/dist/chunks/bindings.js.map +0 -1
- package/dist/chunks/buffered-events.js.map +0 -1
- package/dist/chunks/checkpoint.js +0 -78
- package/dist/chunks/checkpoint.js.map +0 -1
- package/dist/chunks/color/contrast.js.map +0 -1
- package/dist/chunks/color/index.js +0 -1662
- package/dist/chunks/color/index.js.map +0 -1
- package/dist/chunks/comments/document.js.map +0 -1
- package/dist/chunks/comments/list.js.map +0 -1
- package/dist/chunks/comments/merge.js.map +0 -1
- package/dist/chunks/components/exposure.js +0 -2291
- package/dist/chunks/components/exposure.js.map +0 -1
- package/dist/chunks/components/variants.js +0 -32
- package/dist/chunks/components/variants.js.map +0 -1
- package/dist/chunks/coordinate.js +0 -385
- package/dist/chunks/coordinate.js.map +0 -1
- package/dist/chunks/css/grid.js.map +0 -1
- package/dist/chunks/css/index.js +0 -160
- package/dist/chunks/css/index.js.map +0 -1
- package/dist/chunks/events.js.map +0 -1
- package/dist/chunks/fields/geometry.js.map +0 -1
- package/dist/chunks/font-style.js +0 -96
- package/dist/chunks/font-style.js.map +0 -1
- package/dist/chunks/group-bounds.js.map +0 -1
- package/dist/chunks/icons/glyph.js.map +0 -1
- package/dist/chunks/index.js +0 -2430
- package/dist/chunks/index.js.map +0 -1
- package/dist/color.d.ts +0 -78
- package/dist/color.d.ts.map +0 -1
- package/dist/color.js +0 -3
- package/dist/constants2.d.ts +0 -11
- package/dist/constants2.d.ts.map +0 -1
- package/dist/css.d.ts +0 -39
- package/dist/css.d.ts.map +0 -1
- package/dist/css.js +0 -3
- package/dist/images2.d.ts +0 -16
- package/dist/images2.d.ts.map +0 -1
- package/dist/instances.d.ts +0 -2
- package/dist/instances.js +0 -2
- package/dist/layout.d.ts +0 -2
- package/dist/matrix2.d.ts +0 -16
- package/dist/matrix2.d.ts.map +0 -1
- package/dist/primitives.d.ts +0 -2
- package/dist/primitives.js +0 -0
- package/dist/primitives2.d.ts.map +0 -1
- package/dist/text-direction.d.ts.map +0 -1
- package/dist/text-direction.js.map +0 -1
- package/dist/text-picture.d.ts.map +0 -1
- package/dist/text-picture.js +0 -2
- package/dist/text.d.ts +0 -2
- package/dist/text.js +0 -3
- package/dist/types2.d.ts +0 -2
- package/dist/undo2.d.ts +0 -73
- package/dist/undo2.d.ts.map +0 -1
- package/dist/variables.d.ts +0 -2
- package/dist/variables.js +0 -2
- /package/dist/{chunks/asset-keys.js → asset-keys.js} +0 -0
- /package/dist/{chunks/buffered-events.js → buffered-events.js} +0 -0
- /package/dist/{chunks/events.js → events.js} +0 -0
- /package/dist/{chunks/fields → fields}/geometry.js +0 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { isFormulaOperation, isFormulaReference } from "./tree.js";
|
|
2
|
+
import { FORMULA_NON_ASSOCIATIVE, formulaArity, formulaPrecedence, formulaSymbol, isFormulaAssociative, isFormulaCall } from "./signatures.js";
|
|
3
|
+
import { inferFormulaType } from "./check.js";
|
|
4
|
+
import { colorToHex8 } from "../../color/index.js";
|
|
5
|
+
//#region src/variables/formula/print.ts
|
|
6
|
+
const ATOM = 8;
|
|
7
|
+
/** A long formula breaks before these: `or`, `and`, and `+` and `-`. */
|
|
8
|
+
const BREAKABLE = new Set([
|
|
9
|
+
"or",
|
|
10
|
+
"and",
|
|
11
|
+
"add"
|
|
12
|
+
].map(formulaPrecedence));
|
|
13
|
+
const CONTINUATION = "\n ";
|
|
14
|
+
function nodePrecedence(node) {
|
|
15
|
+
if (!isFormulaOperation(node) || isFormulaCall(node.operator)) return ATOM;
|
|
16
|
+
if (formulaArity(node.operator) === 1) return 7;
|
|
17
|
+
return formulaPrecedence(node.operator) ?? 0;
|
|
18
|
+
}
|
|
19
|
+
const group = ({ text }) => `(${text})`;
|
|
20
|
+
function printCall(node, depth, print) {
|
|
21
|
+
const operands = node.operands.map((operand) => print(operand, depth + 1).text);
|
|
22
|
+
return {
|
|
23
|
+
text: `${formulaSymbol(node.operator)}(${operands.join(", ")})`,
|
|
24
|
+
precedence: ATOM
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function printUnary(node, depth, print) {
|
|
28
|
+
const [operandNode] = node.operands;
|
|
29
|
+
const operand = print(operandNode, depth + 1);
|
|
30
|
+
const text = operand.precedence < ATOM ? group(operand) : operand.text;
|
|
31
|
+
const symbol = formulaSymbol(node.operator);
|
|
32
|
+
return {
|
|
33
|
+
text: /^\p{L}/u.test(symbol) ? `${symbol} ${text}` : `${symbol}${text}`,
|
|
34
|
+
precedence: 7
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/** `breakAt` is the precedence of the outermost chain while it is printed on several lines. */
|
|
38
|
+
function printBinary(node, depth, print, regroups, breakAt) {
|
|
39
|
+
const precedence = formulaPrecedence(node.operator) ?? 0;
|
|
40
|
+
const chained = FORMULA_NON_ASSOCIATIVE.has(precedence);
|
|
41
|
+
const [leftNode, rightNode] = node.operands;
|
|
42
|
+
const sameAssociative = isFormulaAssociative(node.operator) && isFormulaOperation(rightNode) && rightNode.operator === node.operator && (node.operator !== "add" || regroups(node));
|
|
43
|
+
const breaking = breakAt === precedence;
|
|
44
|
+
const left = print(leftNode, depth + 1, breaking ? breakAt : void 0);
|
|
45
|
+
const right = print(rightNode, depth + 1, breaking && sameAssociative ? breakAt : void 0);
|
|
46
|
+
const nested = (operand) => chained && FORMULA_NON_ASSOCIATIVE.has(operand.precedence);
|
|
47
|
+
const leftText = left.precedence < precedence || nested(left) ? group(left) : left.text;
|
|
48
|
+
const rightText = right.precedence < precedence || nested(right) || right.precedence === precedence && !sameAssociative ? group(right) : right.text;
|
|
49
|
+
return {
|
|
50
|
+
text: `${leftText}${breaking ? CONTINUATION : " "}${formulaSymbol(node.operator)} ${rightText}`,
|
|
51
|
+
precedence
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/** Print a formula with only the parentheses its precedence needs; `reference` spells a variable. */
|
|
55
|
+
function printFormula(node, reference, { width, display, type } = {}) {
|
|
56
|
+
const typeOf = (of) => {
|
|
57
|
+
try {
|
|
58
|
+
return inferFormulaType(of, type);
|
|
59
|
+
} catch {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const chain = (of) => isFormulaOperation(of) && of.operator === "add" ? [...chain(of.operands[0]), of.operands[1]] : [of];
|
|
64
|
+
const regroups = (sum) => {
|
|
65
|
+
const result = typeOf(sum);
|
|
66
|
+
const [left, right] = sum.operands;
|
|
67
|
+
return result !== void 0 && [left, ...chain(right)].every((of) => typeOf(of) === result);
|
|
68
|
+
};
|
|
69
|
+
const line = printWith(reference, regroups, node);
|
|
70
|
+
const outer = nodePrecedence(node);
|
|
71
|
+
const shown = display ? printWith(display, regroups, node) : line;
|
|
72
|
+
if (width === void 0 || shown.length <= width || !BREAKABLE.has(outer)) return line;
|
|
73
|
+
return printWith(reference, regroups, node, outer);
|
|
74
|
+
}
|
|
75
|
+
function printWith(reference, regroups, root, rootBreak) {
|
|
76
|
+
const print = (node, depth, breakAt) => {
|
|
77
|
+
if (depth > 64) return {
|
|
78
|
+
text: "…",
|
|
79
|
+
precedence: ATOM
|
|
80
|
+
};
|
|
81
|
+
if (typeof node === "number") return {
|
|
82
|
+
text: String(node),
|
|
83
|
+
precedence: node < 0 ? 7 : ATOM
|
|
84
|
+
};
|
|
85
|
+
if (typeof node === "boolean") return {
|
|
86
|
+
text: String(node),
|
|
87
|
+
precedence: ATOM
|
|
88
|
+
};
|
|
89
|
+
if (typeof node === "string") return {
|
|
90
|
+
text: JSON.stringify(node),
|
|
91
|
+
precedence: ATOM
|
|
92
|
+
};
|
|
93
|
+
if (!isFormulaOperation(node)) return {
|
|
94
|
+
text: isFormulaReference(node) ? reference(node.aliasId) : colorToHex8(node),
|
|
95
|
+
precedence: ATOM
|
|
96
|
+
};
|
|
97
|
+
if (isFormulaCall(node.operator)) return printCall(node, depth, print);
|
|
98
|
+
return formulaArity(node.operator) === 1 ? printUnary(node, depth, print) : printBinary(node, depth, print, regroups, breakAt);
|
|
99
|
+
};
|
|
100
|
+
return print(root, 0, rootBreak).text;
|
|
101
|
+
}
|
|
102
|
+
//#endregion
|
|
103
|
+
export { printFormula };
|
|
104
|
+
|
|
105
|
+
//# sourceMappingURL=print.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"print.js","names":[],"sources":["../../../src/variables/formula/print.ts"],"sourcesContent":["import { colorToHex8 } from '#scene-graph/color/index'\nimport type {\n VariableFormulaNode,\n VariableFormulaOperation,\n VariableFormulaOperator\n} from '#scene-graph/types'\n\nimport { inferFormulaType } from './check'\nimport {\n formulaArity,\n formulaPrecedence,\n formulaSymbol,\n FORMULA_NON_ASSOCIATIVE,\n FORMULA_PREFIX_PRECEDENCE,\n isFormulaAssociative,\n isFormulaCall,\n type FormulaValueType\n} from './signatures'\nimport { isFormulaOperation, isFormulaReference, MAX_FORMULA_DEPTH } from './tree'\n\nconst ATOM = FORMULA_PREFIX_PRECEDENCE + 1\n/** A long formula breaks before these: `or`, `and`, and `+` and `-`. */\nconst BREAKABLE = new Set(\n (['or', 'and', 'add'] satisfies VariableFormulaOperator[]).map(formulaPrecedence)\n)\nconst CONTINUATION = '\\n '\n\ninterface Printed {\n text: string\n precedence: number\n}\n\nexport interface PrintFormulaOptions {\n /**\n * Past this many characters, a formula breaks before each operator of its outermost chain of\n * `or`, `and`, or `+` and `-`, with the lines after the first indented.\n */\n width?: number\n /**\n * How a reference reads where the formula is shown, such as a pill's name, which `width`\n * counts in place of the source spelling.\n */\n display?: (id: string) => string\n /**\n * A referenced variable's type. `+` adds numbers but joins text, so `a + (b + c)` drops its\n * parentheses only when both sides are known to be the same type.\n */\n type?: (id: string) => FormulaValueType | undefined\n}\n\nfunction nodePrecedence(node: VariableFormulaNode) {\n if (!isFormulaOperation(node) || isFormulaCall(node.operator)) return ATOM\n if (formulaArity(node.operator) === 1) return FORMULA_PREFIX_PRECEDENCE\n return formulaPrecedence(node.operator) ?? 0\n}\n\ntype Operation = VariableFormulaOperation\ntype Print = (node: VariableFormulaNode, depth: number, breakAt?: number) => Printed\n/** Whether `a + (b + c)` may print as `a + b + c` and still read back as the same value. */\ntype Regroups = (node: Operation) => boolean\n\nconst group = ({ text }: Printed) => `(${text})`\n\nfunction printCall(node: Operation, depth: number, print: Print): Printed {\n const operands = node.operands.map((operand) => print(operand, depth + 1).text)\n return { text: `${formulaSymbol(node.operator)}(${operands.join(', ')})`, precedence: ATOM }\n}\n\nfunction printUnary(node: Operation, depth: number, print: Print): Printed {\n const [operandNode] = node.operands\n const operand = print(operandNode, depth + 1)\n const text = operand.precedence < ATOM ? group(operand) : operand.text\n const symbol = formulaSymbol(node.operator)\n // A word, such as `not`, needs a space before its operand; a sign, such as `-`, does not.\n return {\n text: /^\\p{L}/u.test(symbol) ? `${symbol} ${text}` : `${symbol}${text}`,\n precedence: FORMULA_PREFIX_PRECEDENCE\n }\n}\n\n/** `breakAt` is the precedence of the outermost chain while it is printed on several lines. */\nfunction printBinary(\n node: Operation,\n depth: number,\n print: Print,\n regroups: Regroups,\n breakAt?: number\n): Printed {\n const precedence = formulaPrecedence(node.operator) ?? 0\n const chained = FORMULA_NON_ASSOCIATIVE.has(precedence)\n const [leftNode, rightNode] = node.operands\n const sameAssociative =\n isFormulaAssociative(node.operator) &&\n isFormulaOperation(rightNode) &&\n rightNode.operator === node.operator &&\n (node.operator !== 'add' || regroups(node))\n // The chain continues through a left operand and an unparenthesized right one of its level.\n const breaking = breakAt === precedence\n const left = print(leftNode, depth + 1, breaking ? breakAt : undefined)\n const right = print(rightNode, depth + 1, breaking && sameAssociative ? breakAt : undefined)\n // A comparison inside another, such as `(a > 1) == b`, keeps its parentheses to read clearly.\n const nested = (operand: Printed) => chained && FORMULA_NON_ASSOCIATIVE.has(operand.precedence)\n const leftText = left.precedence < precedence || nested(left) ? group(left) : left.text\n const rightGrouped =\n right.precedence < precedence ||\n nested(right) ||\n (right.precedence === precedence && !sameAssociative)\n const rightText = rightGrouped ? group(right) : right.text\n const separator = breaking ? CONTINUATION : ' '\n return { text: `${leftText}${separator}${formulaSymbol(node.operator)} ${rightText}`, precedence }\n}\n\n/** Print a formula with only the parentheses its precedence needs; `reference` spells a variable. */\nexport function printFormula(\n node: VariableFormulaNode,\n reference: (id: string) => string,\n { width, display, type }: PrintFormulaOptions = {}\n): string {\n const typeOf = (of: VariableFormulaNode) => {\n try {\n return inferFormulaType(of, type)\n } catch {\n return undefined\n }\n }\n // Text printed without parentheses reads left to right, so `\"a\" + (1 + 2)` would read as\n // `\"a\" + 1 + 2`: regroup only when every operand of the chain gives the sum's type.\n const chain = (of: VariableFormulaNode): VariableFormulaNode[] =>\n isFormulaOperation(of) && of.operator === 'add'\n ? [...chain(of.operands[0]), of.operands[1]]\n : [of]\n const regroups: Regroups = (sum) => {\n const result = typeOf(sum)\n const [left, right] = sum.operands\n return result !== undefined && [left, ...chain(right)].every((of) => typeOf(of) === result)\n }\n const line = printWith(reference, regroups, node)\n const outer = nodePrecedence(node)\n const shown = display ? printWith(display, regroups, node) : line\n if (width === undefined || shown.length <= width || !BREAKABLE.has(outer)) return line\n return printWith(reference, regroups, node, outer)\n}\n\nfunction printWith(\n reference: (id: string) => string,\n regroups: Regroups,\n root: VariableFormulaNode,\n rootBreak?: number\n): string {\n const print: Print = (node, depth, breakAt) => {\n if (depth > MAX_FORMULA_DEPTH) return { text: '…', precedence: ATOM }\n if (typeof node === 'number')\n return { text: String(node), precedence: node < 0 ? FORMULA_PREFIX_PRECEDENCE : ATOM }\n if (typeof node === 'boolean') return { text: String(node), precedence: ATOM }\n if (typeof node === 'string') return { text: JSON.stringify(node), precedence: ATOM }\n if (!isFormulaOperation(node))\n return {\n text: isFormulaReference(node) ? reference(node.aliasId) : colorToHex8(node),\n precedence: ATOM\n }\n if (isFormulaCall(node.operator)) return printCall(node, depth, print)\n return formulaArity(node.operator) === 1\n ? printUnary(node, depth, print)\n : printBinary(node, depth, print, regroups, breakAt)\n }\n return print(root, 0, rootBreak).text\n}\n"],"mappings":";;;;;AAoBA,MAAM,OAAA;;AAEN,MAAM,YAAY,IAAI,IACnB;CAAC;CAAM;CAAO;AAAK,CAAC,CAAsC,IAAI,iBAAiB,CAClF;AACA,MAAM,eAAe;AAyBrB,SAAS,eAAe,MAA2B;CACjD,IAAI,CAAC,mBAAmB,IAAI,KAAK,cAAc,KAAK,QAAQ,GAAG,OAAO;CACtE,IAAI,aAAa,KAAK,QAAQ,MAAM,GAAG,OAAA;CACvC,OAAO,kBAAkB,KAAK,QAAQ,KAAK;AAC7C;AAOA,MAAM,SAAS,EAAE,WAAoB,IAAI,KAAK;AAE9C,SAAS,UAAU,MAAiB,OAAe,OAAuB;CACxE,MAAM,WAAW,KAAK,SAAS,KAAK,YAAY,MAAM,SAAS,QAAQ,CAAC,CAAC,CAAC,IAAI;CAC9E,OAAO;EAAE,MAAM,GAAG,cAAc,KAAK,QAAQ,EAAE,GAAG,SAAS,KAAK,IAAI,EAAE;EAAI,YAAY;CAAK;AAC7F;AAEA,SAAS,WAAW,MAAiB,OAAe,OAAuB;CACzE,MAAM,CAAC,eAAe,KAAK;CAC3B,MAAM,UAAU,MAAM,aAAa,QAAQ,CAAC;CAC5C,MAAM,OAAO,QAAQ,aAAa,OAAO,MAAM,OAAO,IAAI,QAAQ;CAClE,MAAM,SAAS,cAAc,KAAK,QAAQ;CAE1C,OAAO;EACL,MAAM,UAAU,KAAK,MAAM,IAAI,GAAG,OAAO,GAAG,SAAS,GAAG,SAAS;EACjE,YAAA;CACF;AACF;;AAGA,SAAS,YACP,MACA,OACA,OACA,UACA,SACS;CACT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C,OAAO,OAAO,OAAO,EAAE,MAAM,MAAM;CAC5F;CACA,MAAM,OAAO,UAAU,WAAW,UAAU,IAAI;CAChD,MAAM,QAAQ,eAAe,IAAI;CACjC,MAAM,QAAQ,UAAU,UAAU,SAAS,UAAU,IAAI,IAAI;CAC7D,IAAI,UAAU,KAAA,KAAa,MAAM,UAAU,SAAS,CAAC,UAAU,IAAI,KAAK,GAAG,OAAO;CAClF,OAAO,UAAU,WAAW,UAAU,MAAM,KAAK;AACnD;AAEA,SAAS,UACP,WACA,UACA,MACA,WACQ;CACR,MAAM,SAAgB,MAAM,OAAO,YAAY;EAC7C,IAAI,QAAA,IAA2B,OAAO;GAAE,MAAM;GAAK,YAAY;EAAK;EACpE,IAAI,OAAO,SAAS,UAClB,OAAO;GAAE,MAAM,OAAO,IAAI;GAAG,YAAY,OAAO,IAAA,IAAgC;EAAK;EACvF,IAAI,OAAO,SAAS,WAAW,OAAO;GAAE,MAAM,OAAO,IAAI;GAAG,YAAY;EAAK;EAC7E,IAAI,OAAO,SAAS,UAAU,OAAO;GAAE,MAAM,KAAK,UAAU,IAAI;GAAG,YAAY;EAAK;EACpF,IAAI,CAAC,mBAAmB,IAAI,GAC1B,OAAO;GACL,MAAM,mBAAmB,IAAI,IAAI,UAAU,KAAK,OAAO,IAAI,YAAY,IAAI;GAC3E,YAAY;EACd;EACF,IAAI,cAAc,KAAK,QAAQ,GAAG,OAAO,UAAU,MAAM,OAAO,KAAK;EACrE,OAAO,aAAa,KAAK,QAAQ,MAAM,IACnC,WAAW,MAAM,OAAO,KAAK,IAC7B,YAAY,MAAM,OAAO,OAAO,UAAU,OAAO;CACvD;CACA,OAAO,MAAM,MAAM,GAAG,SAAS,CAAC,CAAC;AACnC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { VariableFormula } from "../../types.js";
|
|
2
|
+
import * as v from "valibot";
|
|
3
|
+
//#region src/variables/formula/schema.d.ts
|
|
4
|
+
declare const variableFormulaSchema: v.GenericSchema<unknown, VariableFormula>;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { variableFormulaSchema };
|
|
7
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","names":[],"sources":["../../../src/variables/formula/schema.ts"],"mappings":";;;cAqEa,uBAAuB,EAAE,uBAAuB"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import "./tree.js";
|
|
2
|
+
import { formulaArity } from "./signatures.js";
|
|
3
|
+
import { inferFormulaType } from "./check.js";
|
|
4
|
+
import { variableAliasSchema } from "../schema.js";
|
|
5
|
+
import { VARIABLE_FORMULA_OPERATORS } from "../../types.js";
|
|
6
|
+
import * as v from "valibot";
|
|
7
|
+
//#region src/variables/formula/schema.ts
|
|
8
|
+
const finiteNumberSchema = v.pipe(v.number(), v.finite());
|
|
9
|
+
const booleanSchema = v.boolean();
|
|
10
|
+
const stringSchema = v.string();
|
|
11
|
+
const colorSchema = v.object({
|
|
12
|
+
r: finiteNumberSchema,
|
|
13
|
+
g: finiteNumberSchema,
|
|
14
|
+
b: finiteNumberSchema,
|
|
15
|
+
a: finiteNumberSchema
|
|
16
|
+
});
|
|
17
|
+
/**
|
|
18
|
+
* A bounded recursive schema rejects excessively deep data before traversing it. Each node's
|
|
19
|
+
* schema is picked by its shape rather than tried in turn, which would build an issue for
|
|
20
|
+
* every literal kind an operation is not.
|
|
21
|
+
*/
|
|
22
|
+
function nodeSchema(depth, cache) {
|
|
23
|
+
const cached = cache.get(depth);
|
|
24
|
+
if (cached) return cached;
|
|
25
|
+
const operation = depth > 0 ? v.pipe(v.object({
|
|
26
|
+
operator: v.picklist(VARIABLE_FORMULA_OPERATORS),
|
|
27
|
+
operands: v.pipe(v.array(nodeSchema(depth - 1, cache)), v.minLength(1), v.maxLength(3))
|
|
28
|
+
}), v.check((node) => node.operands.length === formulaArity(node.operator), "Wrong number of operands")) : void 0;
|
|
29
|
+
const schema = v.lazy((input) => {
|
|
30
|
+
if (typeof input === "number") return finiteNumberSchema;
|
|
31
|
+
if (typeof input === "boolean") return booleanSchema;
|
|
32
|
+
if (typeof input === "string") return stringSchema;
|
|
33
|
+
if (typeof input === "object" && input !== null && "operator" in input && operation) return operation;
|
|
34
|
+
if (typeof input === "object" && input !== null && "aliasId" in input) return variableAliasSchema;
|
|
35
|
+
return colorSchema;
|
|
36
|
+
});
|
|
37
|
+
cache.set(depth, schema);
|
|
38
|
+
return schema;
|
|
39
|
+
}
|
|
40
|
+
/** Operand types are checked where the data shows them; a reference fits any operand. */
|
|
41
|
+
function fitsType(formula) {
|
|
42
|
+
try {
|
|
43
|
+
const type = inferFormulaType(formula.value);
|
|
44
|
+
return type === void 0 || type === formula.type;
|
|
45
|
+
} catch {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const variableFormulaSchema = v.pipe(v.object({
|
|
50
|
+
expression: v.literal("FORMULA"),
|
|
51
|
+
type: v.picklist([
|
|
52
|
+
"FLOAT",
|
|
53
|
+
"BOOLEAN",
|
|
54
|
+
"STRING",
|
|
55
|
+
"COLOR"
|
|
56
|
+
]),
|
|
57
|
+
value: nodeSchema(64, /* @__PURE__ */ new Map())
|
|
58
|
+
}), v.check(fitsType, "Formula operands do not fit their operators"));
|
|
59
|
+
//#endregion
|
|
60
|
+
export { variableFormulaSchema };
|
|
61
|
+
|
|
62
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","names":[],"sources":["../../../src/variables/formula/schema.ts"],"sourcesContent":["import {\n VARIABLE_FORMULA_OPERATORS,\n type VariableFormula,\n type VariableFormulaNode\n} from '#scene-graph/types'\nimport * as v from 'valibot'\n\nimport { variableAliasSchema } from '../schema'\nimport { inferFormulaType } from './check'\nimport { formulaArity } from './signatures'\nimport { MAX_FORMULA_DEPTH } from './tree'\n\ntype NodeSchema = v.GenericSchema<unknown, VariableFormulaNode>\n\nconst finiteNumberSchema = v.pipe(v.number(), v.finite())\nconst booleanSchema = v.boolean()\nconst stringSchema = v.string()\nconst colorSchema = v.object({\n r: finiteNumberSchema,\n g: finiteNumberSchema,\n b: finiteNumberSchema,\n a: finiteNumberSchema\n})\n\n/**\n * A bounded recursive schema rejects excessively deep data before traversing it. Each node's\n * schema is picked by its shape rather than tried in turn, which would build an issue for\n * every literal kind an operation is not.\n */\nfunction nodeSchema(depth: number, cache: Map<number, NodeSchema>): NodeSchema {\n const cached = cache.get(depth)\n if (cached) return cached\n const operation =\n depth > 0\n ? v.pipe(\n v.object({\n operator: v.picklist(VARIABLE_FORMULA_OPERATORS),\n operands: v.pipe(v.array(nodeSchema(depth - 1, cache)), v.minLength(1), v.maxLength(3))\n }),\n v.check(\n (node) => node.operands.length === formulaArity(node.operator),\n 'Wrong number of operands'\n )\n )\n : undefined\n const schema: NodeSchema = v.lazy((input) => {\n if (typeof input === 'number') return finiteNumberSchema\n if (typeof input === 'boolean') return booleanSchema\n if (typeof input === 'string') return stringSchema\n if (typeof input === 'object' && input !== null && 'operator' in input && operation)\n return operation\n if (typeof input === 'object' && input !== null && 'aliasId' in input)\n return variableAliasSchema\n return colorSchema\n })\n cache.set(depth, schema)\n return schema\n}\n\n/** Operand types are checked where the data shows them; a reference fits any operand. */\nfunction fitsType(formula: VariableFormula) {\n try {\n const type = inferFormulaType(formula.value)\n return type === undefined || type === formula.type\n } catch {\n return false\n }\n}\n\nexport const variableFormulaSchema: v.GenericSchema<unknown, VariableFormula> = v.pipe(\n v.object({\n expression: v.literal('FORMULA'),\n type: v.picklist(['FLOAT', 'BOOLEAN', 'STRING', 'COLOR']),\n value: nodeSchema(MAX_FORMULA_DEPTH, new Map())\n }),\n v.check(fitsType, 'Formula operands do not fit their operators')\n)\n"],"mappings":";;;;;;;AAcA,MAAM,qBAAqB,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,OAAO,CAAC;AACxD,MAAM,gBAAgB,EAAE,QAAQ;AAChC,MAAM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AA6C,CACjE"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { VariableFormulaOperator, VariableType } from "../../types.js";
|
|
2
|
+
//#region src/variables/formula/signatures.d.ts
|
|
3
|
+
type FormulaValueType = VariableType;
|
|
4
|
+
declare function formulaArity(operator: VariableFormulaOperator): number;
|
|
5
|
+
/** How the operator is printed: its first spelling. */
|
|
6
|
+
declare function formulaSymbol(operator: VariableFormulaOperator): string;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { FormulaValueType, formulaArity, formulaSymbol };
|
|
9
|
+
//# sourceMappingURL=signatures.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signatures.d.ts","names":[],"sources":["../../../src/variables/formula/signatures.ts"],"mappings":";;KAKY,mBAAmB;iBAsMf,aAAa,UAAU;;iBAKvB,cAAc,UAAU"}
|
|
@@ -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: VariableFormulaOperator,\n operands: VariableLiteral[]\n): VariableLite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AAG,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,SAAS;AACf,MAAM,OAAO;AACb,MAAM,WAAW;A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,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"}
|