@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,86 @@
|
|
|
1
|
+
//#region src/shape-with-text/kinds.ts
|
|
2
|
+
/**
|
|
3
|
+
* FigJam's shape-with-text kinds, as Figma names them in `.fig` files and in its plugin API
|
|
4
|
+
* (`ShapeWithTextNode.shapeType`). Each kind is drawn from its size here, so rendering, hit
|
|
5
|
+
* testing, export and connectors share one outline.
|
|
6
|
+
*/
|
|
7
|
+
const SHAPE_WITH_TEXT_TYPES = [
|
|
8
|
+
"SQUARE",
|
|
9
|
+
"ELLIPSE",
|
|
10
|
+
"DIAMOND",
|
|
11
|
+
"TRIANGLE_UP",
|
|
12
|
+
"TRIANGLE_DOWN",
|
|
13
|
+
"ROUNDED_RECTANGLE",
|
|
14
|
+
"PARALLELOGRAM_RIGHT",
|
|
15
|
+
"PARALLELOGRAM_LEFT",
|
|
16
|
+
"ENG_DATABASE",
|
|
17
|
+
"ENG_QUEUE",
|
|
18
|
+
"ENG_FILE",
|
|
19
|
+
"ENG_FOLDER",
|
|
20
|
+
"TRAPEZOID",
|
|
21
|
+
"PREDEFINED_PROCESS",
|
|
22
|
+
"SHIELD",
|
|
23
|
+
"DOCUMENT_SINGLE",
|
|
24
|
+
"DOCUMENT_MULTIPLE",
|
|
25
|
+
"MANUAL_INPUT",
|
|
26
|
+
"HEXAGON",
|
|
27
|
+
"CHEVRON",
|
|
28
|
+
"PENTAGON",
|
|
29
|
+
"OCTAGON",
|
|
30
|
+
"STAR",
|
|
31
|
+
"PLUS",
|
|
32
|
+
"ARROW_LEFT",
|
|
33
|
+
"ARROW_RIGHT",
|
|
34
|
+
"SUMMING_JUNCTION",
|
|
35
|
+
"OR",
|
|
36
|
+
"SPEECH_BUBBLE",
|
|
37
|
+
"INTERNAL_STORAGE"
|
|
38
|
+
];
|
|
39
|
+
const KNOWN = new Set(SHAPE_WITH_TEXT_TYPES);
|
|
40
|
+
function isShapeWithTextType(value) {
|
|
41
|
+
return typeof value === "string" && KNOWN.has(value);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The kinds as FigJam's Shapes panel offers them, in its order: Basic, then Flowchart. Together
|
|
45
|
+
* they are every kind.
|
|
46
|
+
*/
|
|
47
|
+
const SHAPE_WITH_TEXT_GROUPS = {
|
|
48
|
+
basic: [
|
|
49
|
+
"SQUARE",
|
|
50
|
+
"ELLIPSE",
|
|
51
|
+
"DIAMOND",
|
|
52
|
+
"TRIANGLE_UP",
|
|
53
|
+
"TRIANGLE_DOWN",
|
|
54
|
+
"ROUNDED_RECTANGLE",
|
|
55
|
+
"PENTAGON",
|
|
56
|
+
"OCTAGON",
|
|
57
|
+
"PLUS",
|
|
58
|
+
"ARROW_LEFT",
|
|
59
|
+
"ARROW_RIGHT",
|
|
60
|
+
"CHEVRON",
|
|
61
|
+
"STAR",
|
|
62
|
+
"SPEECH_BUBBLE"
|
|
63
|
+
],
|
|
64
|
+
flowchart: [
|
|
65
|
+
"PARALLELOGRAM_RIGHT",
|
|
66
|
+
"PARALLELOGRAM_LEFT",
|
|
67
|
+
"ENG_DATABASE",
|
|
68
|
+
"ENG_QUEUE",
|
|
69
|
+
"ENG_FILE",
|
|
70
|
+
"ENG_FOLDER",
|
|
71
|
+
"DOCUMENT_SINGLE",
|
|
72
|
+
"DOCUMENT_MULTIPLE",
|
|
73
|
+
"PREDEFINED_PROCESS",
|
|
74
|
+
"SHIELD",
|
|
75
|
+
"TRAPEZOID",
|
|
76
|
+
"MANUAL_INPUT",
|
|
77
|
+
"HEXAGON",
|
|
78
|
+
"INTERNAL_STORAGE",
|
|
79
|
+
"OR",
|
|
80
|
+
"SUMMING_JUNCTION"
|
|
81
|
+
]
|
|
82
|
+
};
|
|
83
|
+
//#endregion
|
|
84
|
+
export { SHAPE_WITH_TEXT_GROUPS, SHAPE_WITH_TEXT_TYPES, isShapeWithTextType };
|
|
85
|
+
|
|
86
|
+
//# sourceMappingURL=kinds.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kinds.js","names":[],"sources":["../../src/shape-with-text/kinds.ts"],"sourcesContent":["/**\n * FigJam's shape-with-text kinds, as Figma names them in `.fig` files and in its plugin API\n * (`ShapeWithTextNode.shapeType`). Each kind is drawn from its size here, so rendering, hit\n * testing, export and connectors share one outline.\n */\nexport const SHAPE_WITH_TEXT_TYPES = [\n 'SQUARE',\n 'ELLIPSE',\n 'DIAMOND',\n 'TRIANGLE_UP',\n 'TRIANGLE_DOWN',\n 'ROUNDED_RECTANGLE',\n 'PARALLELOGRAM_RIGHT',\n 'PARALLELOGRAM_LEFT',\n 'ENG_DATABASE',\n 'ENG_QUEUE',\n 'ENG_FILE',\n 'ENG_FOLDER',\n 'TRAPEZOID',\n 'PREDEFINED_PROCESS',\n 'SHIELD',\n 'DOCUMENT_SINGLE',\n 'DOCUMENT_MULTIPLE',\n 'MANUAL_INPUT',\n 'HEXAGON',\n 'CHEVRON',\n 'PENTAGON',\n 'OCTAGON',\n 'STAR',\n 'PLUS',\n 'ARROW_LEFT',\n 'ARROW_RIGHT',\n 'SUMMING_JUNCTION',\n 'OR',\n 'SPEECH_BUBBLE',\n 'INTERNAL_STORAGE'\n] as const\n\nexport type ShapeWithTextType = (typeof SHAPE_WITH_TEXT_TYPES)[number]\n\nconst KNOWN = new Set<string>(SHAPE_WITH_TEXT_TYPES)\n\nexport function isShapeWithTextType(value: unknown): value is ShapeWithTextType {\n return typeof value === 'string' && KNOWN.has(value)\n}\n\n/**\n * The kinds as FigJam's Shapes panel offers them, in its order: Basic, then Flowchart. Together\n * they are every kind.\n */\nexport const SHAPE_WITH_TEXT_GROUPS = {\n basic: [\n 'SQUARE',\n 'ELLIPSE',\n 'DIAMOND',\n 'TRIANGLE_UP',\n 'TRIANGLE_DOWN',\n 'ROUNDED_RECTANGLE',\n 'PENTAGON',\n 'OCTAGON',\n 'PLUS',\n 'ARROW_LEFT',\n 'ARROW_RIGHT',\n 'CHEVRON',\n 'STAR',\n 'SPEECH_BUBBLE'\n ],\n flowchart: [\n 'PARALLELOGRAM_RIGHT',\n 'PARALLELOGRAM_LEFT',\n 'ENG_DATABASE',\n 'ENG_QUEUE',\n 'ENG_FILE',\n 'ENG_FOLDER',\n 'DOCUMENT_SINGLE',\n 'DOCUMENT_MULTIPLE',\n 'PREDEFINED_PROCESS',\n 'SHIELD',\n 'TRAPEZOID',\n 'MANUAL_INPUT',\n 'HEXAGON',\n 'INTERNAL_STORAGE',\n 'OR',\n 'SUMMING_JUNCTION'\n ]\n} as const satisfies Record<string, readonly ShapeWithTextType[]>\n"],"mappings":";;;;;;AAKA,MAAa,wBAAwB;CACnC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAIA,MAAM,QAAQ,IAAI,IAAY,qBAAqB;AAEnD,SAAgB,oBAAoB,OAA4C;CAC9E,OAAO,OAAO,UAAU,YAAY,MAAM,IAAI,KAAK;AACrD;;;;;AAMA,MAAa,yBAAyB;CACpC,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;CACA,WAAW;EACT;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { SceneGraph } from "./graph.js";
|
|
2
|
+
import { CharacterStyleOverride, SceneNode, SharedStyle, SharedStyleKind, SharedStyleType } from "./types.js";
|
|
3
|
+
//#region src/shared-styles.d.ts
|
|
4
|
+
declare const STYLE_REF_KEYS: {
|
|
5
|
+
readonly fill: "fillStyleId";
|
|
6
|
+
readonly stroke: "strokeStyleId";
|
|
7
|
+
readonly text: "textStyleId";
|
|
8
|
+
readonly effect: "effectStyleId";
|
|
9
|
+
readonly grid: "gridStyleId";
|
|
10
|
+
};
|
|
11
|
+
/** The fields that link a layer to its shared styles. */
|
|
12
|
+
declare const STYLE_LINK_FIELDS: ("fillStyleId" | "strokeStyleId" | "textStyleId" | "effectStyleId" | "gridStyleId")[];
|
|
13
|
+
/** The shared styles a layer uses: its own, its text ranges', and its vector regions'. */
|
|
14
|
+
declare function referencedStyleIds(node: SceneNode): string[];
|
|
15
|
+
/** The fields a text style gives what uses it; changing one leaves the style. */
|
|
16
|
+
declare const SHARED_TEXT_STYLE_FIELDS: readonly ["fontFamily", "fontWeight", "italic", "fontStyle", "fontSize", "lineHeight", "letterSpacing", "textDecoration", "textCase", "fontFeatures"];
|
|
17
|
+
/** The fields each kind of shared style gives what uses it; changing one leaves the style. */
|
|
18
|
+
declare const SHARED_STYLE_FIELDS: {
|
|
19
|
+
readonly fill: readonly ["fills"];
|
|
20
|
+
readonly stroke: readonly ["strokes"];
|
|
21
|
+
readonly text: readonly ["fontFamily", "fontWeight", "italic", "fontStyle", "fontSize", "lineHeight", "letterSpacing", "textDecoration", "textCase", "fontFeatures", "paragraphSpacing", "paragraphIndent", "listSpacing"];
|
|
22
|
+
readonly effect: readonly ["effects"];
|
|
23
|
+
readonly grid: readonly ["layoutGrids"];
|
|
24
|
+
};
|
|
25
|
+
/** The fields that pick a text's face, which its style name names. */
|
|
26
|
+
declare const FACE_KEYS: readonly ["fontFamily", "fontWeight", "italic"];
|
|
27
|
+
/**
|
|
28
|
+
* The face name of characters with `style` over the text: their own, none where they set another
|
|
29
|
+
* face without one (as ranges from HTML or `.pen` do), else the text's.
|
|
30
|
+
*/
|
|
31
|
+
declare function rangeFontStyle(node: Pick<SceneNode, 'fontStyle'>, style: CharacterStyleOverride): string | null;
|
|
32
|
+
declare function sharedStyleRefKey(kind: SharedStyleKind): (typeof STYLE_REF_KEYS)[SharedStyleKind];
|
|
33
|
+
declare function sharedStyleTypeForKind(kind: SharedStyleKind): SharedStyleType;
|
|
34
|
+
declare function getSharedStyles(graph: SceneGraph, kind: SharedStyleKind): SharedStyle[];
|
|
35
|
+
declare function styleDetachmentChanges(node: SceneNode, changes: Partial<SceneNode>): Partial<SceneNode>;
|
|
36
|
+
/** The node of the shared style with `id`, when the document holds one of `type`. */
|
|
37
|
+
declare function findSharedStyle(graph: SceneGraph, id: string, type: SharedStyleType): SceneNode | undefined;
|
|
38
|
+
/** A new local style's ID, in the shape Figma gives one: `S:` and a 40-digit hex key. */
|
|
39
|
+
declare function newSharedStyleId(): string;
|
|
40
|
+
/** The page that holds the document's styles out of view, as a `.fig` file keeps them; made once. */
|
|
41
|
+
declare function internalCanvas(graph: SceneGraph): SceneNode;
|
|
42
|
+
/**
|
|
43
|
+
* What a layer takes from a shared style it starts using: the style's fields and the reference
|
|
44
|
+
* that keeps it attached. Without the style's node, the reference alone.
|
|
45
|
+
*/
|
|
46
|
+
declare function sharedStylePatch(kind: SharedStyleKind, target: SceneNode, styleId: string, style: SceneNode | null): Partial<SceneNode>;
|
|
47
|
+
/** A layer leaving a shared style: it keeps the style's values, without the reference. */
|
|
48
|
+
declare function sharedStyleDetachPatch(kind: SharedStyleKind): Partial<SceneNode>;
|
|
49
|
+
//#endregion
|
|
50
|
+
export { FACE_KEYS, SHARED_STYLE_FIELDS, SHARED_TEXT_STYLE_FIELDS, STYLE_LINK_FIELDS, findSharedStyle, getSharedStyles, internalCanvas, newSharedStyleId, rangeFontStyle, referencedStyleIds, sharedStyleDetachPatch, sharedStylePatch, sharedStyleRefKey, sharedStyleTypeForKind, styleDetachmentChanges };
|
|
51
|
+
//# sourceMappingURL=shared-styles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared-styles.d.ts","names":[],"sources":["../src/shared-styles.ts"],"mappings":";;;cAiBM;;;;;;;;cASO;;iBAGG,mBAAmB,MAAM;;cAiB5B;;cAwBA;;;;;;;;cASA;;;;;iBAUG,eACd,MAAM,KAAK,yBACX,OAAO;iBAMO,kBAAkB,MAAM,0BAA0B,gBAAgB;iBAIlE,uBAAuB,MAAM,kBAAkB;iBAI/C,gBAAgB,OAAO,YAAY,MAAM,kBAAkB;iBA0B3D,uBACd,MAAM,WACN,SAAS,QAAQ,aAChB,QAAQ;;iBAmBK,gBACd,OAAO,YACP,YACA,MAAM,kBACL;;iBASa;;iBAOA,eAAe,OAAO,aAAa;;;;;iBAmCnC,iBACd,MAAM,iBACN,QAAQ,WACR,iBACA,OAAO,mBACN,QAAQ;;iBAYK,uBAAuB,MAAM,kBAAkB,QAAQ"}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { BLACK } from "./constants.js";
|
|
2
|
+
import { newStrokeGeometry } from "./node-defaults.js";
|
|
3
|
+
import { copyEffects, copyFills, copyLayoutGrids } from "./copy.js";
|
|
4
|
+
import { randomHex } from "./random.js";
|
|
5
|
+
import { styleRunReferences } from "./text/references.js";
|
|
6
|
+
import { compact, isEqual, omit, pick } from "es-toolkit";
|
|
7
|
+
//#region src/shared-styles.ts
|
|
8
|
+
const STYLE_REF_KEYS = {
|
|
9
|
+
fill: "fillStyleId",
|
|
10
|
+
stroke: "strokeStyleId",
|
|
11
|
+
text: "textStyleId",
|
|
12
|
+
effect: "effectStyleId",
|
|
13
|
+
grid: "gridStyleId"
|
|
14
|
+
};
|
|
15
|
+
/** The fields that link a layer to its shared styles. */
|
|
16
|
+
const STYLE_LINK_FIELDS = Object.values(STYLE_REF_KEYS);
|
|
17
|
+
/** The shared styles a layer uses: its own, its text ranges', and its vector regions'. */
|
|
18
|
+
function referencedStyleIds(node) {
|
|
19
|
+
return compact([
|
|
20
|
+
...STYLE_LINK_FIELDS.map((field) => node[field]),
|
|
21
|
+
...styleRunReferences(node.styleRuns).styles,
|
|
22
|
+
...(node.vectorNetwork?.regions ?? []).map((region) => region.fillStyleId)
|
|
23
|
+
]);
|
|
24
|
+
}
|
|
25
|
+
const STYLE_TYPES = {
|
|
26
|
+
fill: "FILL",
|
|
27
|
+
stroke: "FILL",
|
|
28
|
+
text: "TEXT",
|
|
29
|
+
effect: "EFFECT",
|
|
30
|
+
grid: "GRID"
|
|
31
|
+
};
|
|
32
|
+
/** The fields a text style gives what uses it; changing one leaves the style. */
|
|
33
|
+
const SHARED_TEXT_STYLE_FIELDS = [
|
|
34
|
+
"fontFamily",
|
|
35
|
+
"fontWeight",
|
|
36
|
+
"italic",
|
|
37
|
+
"fontStyle",
|
|
38
|
+
"fontSize",
|
|
39
|
+
"lineHeight",
|
|
40
|
+
"letterSpacing",
|
|
41
|
+
"textDecoration",
|
|
42
|
+
"textCase",
|
|
43
|
+
"fontFeatures"
|
|
44
|
+
];
|
|
45
|
+
/**
|
|
46
|
+
* The paragraph fields a text style also gives the whole text; a range takes only the character
|
|
47
|
+
* ones. Changing one leaves the style, and a cleared style resets them (live-verified).
|
|
48
|
+
*/
|
|
49
|
+
const TEXT_STYLE_PARAGRAPH_FIELDS = [
|
|
50
|
+
"paragraphSpacing",
|
|
51
|
+
"paragraphIndent",
|
|
52
|
+
"listSpacing"
|
|
53
|
+
];
|
|
54
|
+
/** The fields each kind of shared style gives what uses it; changing one leaves the style. */
|
|
55
|
+
const SHARED_STYLE_FIELDS = {
|
|
56
|
+
fill: ["fills"],
|
|
57
|
+
stroke: ["strokes"],
|
|
58
|
+
text: [...SHARED_TEXT_STYLE_FIELDS, ...TEXT_STYLE_PARAGRAPH_FIELDS],
|
|
59
|
+
effect: ["effects"],
|
|
60
|
+
grid: ["layoutGrids"]
|
|
61
|
+
};
|
|
62
|
+
/** The fields that pick a text's face, which its style name names. */
|
|
63
|
+
const FACE_KEYS = [
|
|
64
|
+
"fontFamily",
|
|
65
|
+
"fontWeight",
|
|
66
|
+
"italic"
|
|
67
|
+
];
|
|
68
|
+
/**
|
|
69
|
+
* The face name of characters with `style` over the text: their own, none where they set another
|
|
70
|
+
* face without one (as ranges from HTML or `.pen` do), else the text's.
|
|
71
|
+
*/
|
|
72
|
+
function rangeFontStyle(node, style) {
|
|
73
|
+
if (style.fontStyle !== void 0) return style.fontStyle;
|
|
74
|
+
return FACE_KEYS.some((key) => style[key] !== void 0) ? null : node.fontStyle;
|
|
75
|
+
}
|
|
76
|
+
function sharedStyleRefKey(kind) {
|
|
77
|
+
return STYLE_REF_KEYS[kind];
|
|
78
|
+
}
|
|
79
|
+
function sharedStyleTypeForKind(kind) {
|
|
80
|
+
return STYLE_TYPES[kind];
|
|
81
|
+
}
|
|
82
|
+
function getSharedStyles(graph, kind) {
|
|
83
|
+
const type = sharedStyleTypeForKind(kind);
|
|
84
|
+
const styles = [];
|
|
85
|
+
for (const node of graph.getAllNodes()) {
|
|
86
|
+
if (node.sharedStyleType !== type || !node.source.id) continue;
|
|
87
|
+
styles.push({
|
|
88
|
+
id: node.source.id,
|
|
89
|
+
nodeId: node.id,
|
|
90
|
+
name: node.name,
|
|
91
|
+
type
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
return styles.sort((left, right) => left.name.localeCompare(right.name));
|
|
95
|
+
}
|
|
96
|
+
/** What a stroke draws along beside its paint: the layer's, not its stroke style's. */
|
|
97
|
+
const STROKE_LINE_KEYS = [
|
|
98
|
+
"weight",
|
|
99
|
+
"align",
|
|
100
|
+
"cap",
|
|
101
|
+
"join",
|
|
102
|
+
"dashPattern"
|
|
103
|
+
];
|
|
104
|
+
/**
|
|
105
|
+
* Whether new strokes only change how their lines run, keeping every paint. A stroke style gives
|
|
106
|
+
* paints only, so such a write keeps it; any other strokes write leaves it, as setting even the
|
|
107
|
+
* same paints does in Figma (live-verified).
|
|
108
|
+
*/
|
|
109
|
+
function restylesStrokeLines(current, next) {
|
|
110
|
+
const paints = (strokes) => strokes.map((stroke) => omit(stroke, STROKE_LINE_KEYS));
|
|
111
|
+
const lines = (strokes) => strokes.map((stroke) => STROKE_LINE_KEYS.map((key) => stroke[key]));
|
|
112
|
+
return isEqual(paints(current), paints(next)) && !isEqual(lines(current), lines(next));
|
|
113
|
+
}
|
|
114
|
+
function styleDetachmentChanges(node, changes) {
|
|
115
|
+
const next = { ...changes };
|
|
116
|
+
for (const [kind, fields] of Object.entries(SHARED_STYLE_FIELDS)) {
|
|
117
|
+
const reference = STYLE_REF_KEYS[kind];
|
|
118
|
+
if (reference in changes || !node[reference]) continue;
|
|
119
|
+
if (!fields.some((field) => field in changes)) continue;
|
|
120
|
+
if (kind === "stroke" && changes.strokes && restylesStrokeLines(node.strokes, changes.strokes)) continue;
|
|
121
|
+
next[reference] = null;
|
|
122
|
+
}
|
|
123
|
+
if (FACE_KEYS.some((key) => key in changes && changes[key] !== node[key]) && !("fontStyle" in changes) && node.fontStyle) next.fontStyle = null;
|
|
124
|
+
return next;
|
|
125
|
+
}
|
|
126
|
+
/** The node of the shared style with `id`, when the document holds one of `type`. */
|
|
127
|
+
function findSharedStyle(graph, id, type) {
|
|
128
|
+
if (!id) return void 0;
|
|
129
|
+
for (const node of graph.getAllNodes()) if (node.sharedStyleType === type && node.source.id === id) return node;
|
|
130
|
+
}
|
|
131
|
+
/** A new local style's ID, in the shape Figma gives one: `S:` and a 40-digit hex key. */
|
|
132
|
+
function newSharedStyleId() {
|
|
133
|
+
return `S:${randomHex(20)},`;
|
|
134
|
+
}
|
|
135
|
+
const INTERNAL_CANVAS_NAME = "Internal Only Canvas";
|
|
136
|
+
/** The page that holds the document's styles out of view, as a `.fig` file keeps them; made once. */
|
|
137
|
+
function internalCanvas(graph) {
|
|
138
|
+
const existing = graph.getPages(true).find((page) => page.internalOnly);
|
|
139
|
+
if (existing) return existing;
|
|
140
|
+
return graph.createNode("CANVAS", graph.rootId, {
|
|
141
|
+
name: INTERNAL_CANVAS_NAME,
|
|
142
|
+
width: 0,
|
|
143
|
+
height: 0,
|
|
144
|
+
internalOnly: true
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* A paint style's paints as a layer's strokes: every paint, each keeping the weight, alignment,
|
|
149
|
+
* and line style of the stroke it replaces, or of the layer's first; no paints clear the strokes
|
|
150
|
+
* (Figma desktop 126).
|
|
151
|
+
*/
|
|
152
|
+
function strokesFromStyle(target, style) {
|
|
153
|
+
const fallback = target.strokes[0] ?? {
|
|
154
|
+
type: "SOLID",
|
|
155
|
+
color: BLACK,
|
|
156
|
+
opacity: 1,
|
|
157
|
+
visible: true,
|
|
158
|
+
...newStrokeGeometry(target)
|
|
159
|
+
};
|
|
160
|
+
return copyFills(style.fills).map((paint, index) => ({
|
|
161
|
+
...paint,
|
|
162
|
+
...pick(target.strokes[index] ?? fallback, STROKE_LINE_KEYS)
|
|
163
|
+
}));
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* What a layer takes from a shared style it starts using: the style's fields and the reference
|
|
167
|
+
* that keeps it attached. Without the style's node, the reference alone.
|
|
168
|
+
*/
|
|
169
|
+
function sharedStylePatch(kind, target, styleId, style) {
|
|
170
|
+
const patch = { [STYLE_REF_KEYS[kind]]: styleId };
|
|
171
|
+
if (!style) return patch;
|
|
172
|
+
if (kind === "fill") patch.fills = copyFills(style.fills);
|
|
173
|
+
else if (kind === "stroke") patch.strokes = strokesFromStyle(target, style);
|
|
174
|
+
else if (kind === "effect") patch.effects = copyEffects(style.effects);
|
|
175
|
+
else if (kind === "grid") patch.layoutGrids = copyLayoutGrids(style.layoutGrids);
|
|
176
|
+
else Object.assign(patch, structuredClone(pick(style, SHARED_STYLE_FIELDS.text)));
|
|
177
|
+
return patch;
|
|
178
|
+
}
|
|
179
|
+
/** A layer leaving a shared style: it keeps the style's values, without the reference. */
|
|
180
|
+
function sharedStyleDetachPatch(kind) {
|
|
181
|
+
return { [STYLE_REF_KEYS[kind]]: null };
|
|
182
|
+
}
|
|
183
|
+
//#endregion
|
|
184
|
+
export { FACE_KEYS, SHARED_STYLE_FIELDS, SHARED_TEXT_STYLE_FIELDS, STYLE_LINK_FIELDS, findSharedStyle, getSharedStyles, internalCanvas, newSharedStyleId, rangeFontStyle, referencedStyleIds, sharedStyleDetachPatch, sharedStylePatch, sharedStyleRefKey, sharedStyleTypeForKind, styleDetachmentChanges };
|
|
185
|
+
|
|
186
|
+
//# sourceMappingURL=shared-styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared-styles.js","names":[],"sources":["../src/shared-styles.ts"],"sourcesContent":["import { compact, isEqual, omit, pick } from 'es-toolkit'\n\nimport { BLACK } from './constants'\nimport { copyEffects, copyFills, copyLayoutGrids } from './copy'\nimport type { SceneGraph } from './graph'\nimport { newStrokeGeometry } from './node-defaults'\nimport { randomHex } from './random'\nimport { styleRunReferences } from './text/references'\nimport type {\n CharacterStyleOverride,\n SceneNode,\n SharedStyle,\n SharedStyleKind,\n SharedStyleType,\n Stroke\n} from './types'\n\nconst STYLE_REF_KEYS = {\n fill: 'fillStyleId',\n stroke: 'strokeStyleId',\n text: 'textStyleId',\n effect: 'effectStyleId',\n grid: 'gridStyleId'\n} as const satisfies Record<SharedStyleKind, keyof SceneNode>\n\n/** The fields that link a layer to its shared styles. */\nexport const STYLE_LINK_FIELDS = Object.values(STYLE_REF_KEYS)\n\n/** The shared styles a layer uses: its own, its text ranges', and its vector regions'. */\nexport function referencedStyleIds(node: SceneNode): string[] {\n return compact([\n ...STYLE_LINK_FIELDS.map((field) => node[field]),\n ...styleRunReferences(node.styleRuns).styles,\n ...(node.vectorNetwork?.regions ?? []).map((region) => region.fillStyleId)\n ])\n}\n\nconst STYLE_TYPES = {\n fill: 'FILL',\n stroke: 'FILL',\n text: 'TEXT',\n effect: 'EFFECT',\n grid: 'GRID'\n} as const satisfies Record<SharedStyleKind, SharedStyleType>\n\n/** The fields a text style gives what uses it; changing one leaves the style. */\nexport const SHARED_TEXT_STYLE_FIELDS = [\n 'fontFamily',\n 'fontWeight',\n 'italic',\n 'fontStyle',\n 'fontSize',\n 'lineHeight',\n 'letterSpacing',\n 'textDecoration',\n 'textCase',\n 'fontFeatures'\n] as const satisfies readonly (keyof SceneNode)[]\n\n/**\n * The paragraph fields a text style also gives the whole text; a range takes only the character\n * ones. Changing one leaves the style, and a cleared style resets them (live-verified).\n */\nconst TEXT_STYLE_PARAGRAPH_FIELDS = [\n 'paragraphSpacing',\n 'paragraphIndent',\n 'listSpacing'\n] as const satisfies readonly (keyof SceneNode)[]\n\n/** The fields each kind of shared style gives what uses it; changing one leaves the style. */\nexport const SHARED_STYLE_FIELDS = {\n fill: ['fills'],\n stroke: ['strokes'],\n text: [...SHARED_TEXT_STYLE_FIELDS, ...TEXT_STYLE_PARAGRAPH_FIELDS],\n effect: ['effects'],\n grid: ['layoutGrids']\n} as const satisfies Record<SharedStyleKind, readonly (keyof SceneNode)[]>\n\n/** The fields that pick a text's face, which its style name names. */\nexport const FACE_KEYS = [\n 'fontFamily',\n 'fontWeight',\n 'italic'\n] as const satisfies readonly (keyof SceneNode)[]\n\n/**\n * The face name of characters with `style` over the text: their own, none where they set another\n * face without one (as ranges from HTML or `.pen` do), else the text's.\n */\nexport function rangeFontStyle(\n node: Pick<SceneNode, 'fontStyle'>,\n style: CharacterStyleOverride\n): string | null {\n if (style.fontStyle !== undefined) return style.fontStyle\n return FACE_KEYS.some((key) => style[key] !== undefined) ? null : node.fontStyle\n}\n\nexport function sharedStyleRefKey(kind: SharedStyleKind): (typeof STYLE_REF_KEYS)[SharedStyleKind] {\n return STYLE_REF_KEYS[kind]\n}\n\nexport function sharedStyleTypeForKind(kind: SharedStyleKind): SharedStyleType {\n return STYLE_TYPES[kind]\n}\n\nexport function getSharedStyles(graph: SceneGraph, kind: SharedStyleKind): SharedStyle[] {\n const type = sharedStyleTypeForKind(kind)\n const styles: SharedStyle[] = []\n for (const node of graph.getAllNodes()) {\n if (node.sharedStyleType !== type || !node.source.id) continue\n styles.push({ id: node.source.id, nodeId: node.id, name: node.name, type })\n }\n return styles.sort((left, right) => left.name.localeCompare(right.name))\n}\n\n/** What a stroke draws along beside its paint: the layer's, not its stroke style's. */\nconst STROKE_LINE_KEYS = ['weight', 'align', 'cap', 'join', 'dashPattern'] as const\n\n/**\n * Whether new strokes only change how their lines run, keeping every paint. A stroke style gives\n * paints only, so such a write keeps it; any other strokes write leaves it, as setting even the\n * same paints does in Figma (live-verified).\n */\nfunction restylesStrokeLines(current: readonly Stroke[], next: readonly Stroke[]): boolean {\n const paints = (strokes: readonly Stroke[]) =>\n strokes.map((stroke) => omit(stroke, STROKE_LINE_KEYS))\n const lines = (strokes: readonly Stroke[]) =>\n strokes.map((stroke) => STROKE_LINE_KEYS.map((key) => stroke[key]))\n return isEqual(paints(current), paints(next)) && !isEqual(lines(current), lines(next))\n}\n\nexport function styleDetachmentChanges(\n node: SceneNode,\n changes: Partial<SceneNode>\n): Partial<SceneNode> {\n const next = { ...changes }\n for (const [kind, fields] of Object.entries(SHARED_STYLE_FIELDS)) {\n const reference = STYLE_REF_KEYS[kind as SharedStyleKind]\n if (reference in changes || !node[reference]) continue\n if (!fields.some((field) => field in changes)) continue\n if (kind === 'stroke' && changes.strokes && restylesStrokeLines(node.strokes, changes.strokes))\n continue\n next[reference] = null\n }\n // A face named for another family, weight, or slant names none; the new one takes its own name.\n const changesFace = FACE_KEYS.some((key) => key in changes && changes[key] !== node[key])\n if (changesFace && !('fontStyle' in changes) && node.fontStyle) {\n next.fontStyle = null\n }\n return next\n}\n\n/** The node of the shared style with `id`, when the document holds one of `type`. */\nexport function findSharedStyle(\n graph: SceneGraph,\n id: string,\n type: SharedStyleType\n): SceneNode | undefined {\n if (!id) return undefined\n for (const node of graph.getAllNodes()) {\n if (node.sharedStyleType === type && node.source.id === id) return node\n }\n return undefined\n}\n\n/** A new local style's ID, in the shape Figma gives one: `S:` and a 40-digit hex key. */\nexport function newSharedStyleId(): string {\n return `S:${randomHex(20)},`\n}\n\nconst INTERNAL_CANVAS_NAME = 'Internal Only Canvas'\n\n/** The page that holds the document's styles out of view, as a `.fig` file keeps them; made once. */\nexport function internalCanvas(graph: SceneGraph): SceneNode {\n const existing = graph.getPages(true).find((page) => page.internalOnly)\n if (existing) return existing\n return graph.createNode('CANVAS', graph.rootId, {\n name: INTERNAL_CANVAS_NAME,\n width: 0,\n height: 0,\n internalOnly: true\n })\n}\n\n/**\n * A paint style's paints as a layer's strokes: every paint, each keeping the weight, alignment,\n * and line style of the stroke it replaces, or of the layer's first; no paints clear the strokes\n * (Figma desktop 126).\n */\nfunction strokesFromStyle(target: SceneNode, style: SceneNode): SceneNode['strokes'] {\n // Without strokes, the layer keeps the weight and alignment a new stroke takes.\n const fallback: Stroke = target.strokes[0] ?? {\n type: 'SOLID',\n color: BLACK,\n opacity: 1,\n visible: true,\n ...newStrokeGeometry(target)\n }\n return copyFills(style.fills).map((paint, index) => ({\n ...paint,\n ...pick(target.strokes[index] ?? fallback, STROKE_LINE_KEYS)\n }))\n}\n\n/**\n * What a layer takes from a shared style it starts using: the style's fields and the reference\n * that keeps it attached. Without the style's node, the reference alone.\n */\nexport function sharedStylePatch(\n kind: SharedStyleKind,\n target: SceneNode,\n styleId: string,\n style: SceneNode | null\n): Partial<SceneNode> {\n const patch: Partial<SceneNode> = { [STYLE_REF_KEYS[kind]]: styleId }\n if (!style) return patch\n if (kind === 'fill') patch.fills = copyFills(style.fills)\n else if (kind === 'stroke') patch.strokes = strokesFromStyle(target, style)\n else if (kind === 'effect') patch.effects = copyEffects(style.effects)\n else if (kind === 'grid') patch.layoutGrids = copyLayoutGrids(style.layoutGrids)\n else Object.assign(patch, structuredClone(pick(style, SHARED_STYLE_FIELDS.text)))\n return patch\n}\n\n/** A layer leaving a shared style: it keeps the style's values, without the reference. */\nexport function sharedStyleDetachPatch(kind: SharedStyleKind): Partial<SceneNode> {\n return { [STYLE_REF_KEYS[kind]]: null }\n}\n"],"mappings":";;;;;;;AAiBA,MAAM,iBAAiB;CACrB,MAAM;CACN,QAAQ;CACR,MAAM;CACN,QAAQ;CACR,MAAM;AACR;;AAGA,MAAa,oBAAoB,OAAO,OAAO,cAAc;;AAG7D,SAAgB,mBAAmB,MAA2B;CAC5D,OAAO,QAAQ;EACb,GAAG,kBAAkB,KAAK,UAAU,KAAK,MAAM;EAC/C,GAAG,mBAAmB,KAAK,SAAS,CAAC,CAAC;EACtC,IAAI,KAAK,eAAe,WAAW,CAAC,EAAA,CAAG,KAAK,WAAW,OAAO,WAAW;CAC3E,CAAC;AACH;AAEA,MAAM,cAAc;CAClB,MAAM;CACN,QAAQ;CACR,MAAM;CACN,QAAQ;CACR,MAAM;AACR;;AAGA,MAAa,2BAA2B;CACtC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;;;;AAMA,MAAM,8BAA8B;CAClC;CACA;CACA;AACF;;AAGA,MAAa,sBAAsB;CACjC,MAAM,CAAC,OAAO;CACd,QAAQ,CAAC,SAAS;CAClB,MAAM,CAAC,GAAG,0BAA0B,GAAG,2BAA2B;CAClE,QAAQ,CAAC,SAAS;CAClB,MAAM,CAAC,aAAa;AACtB;;AAGA,MAAa,YAAY;CACvB;CACA;CACA;AACF;;;;;AAMA,SAAgB,eACd,MACA,OACe;CACf,IAAI,MAAM,cAAc,KAAA,GAAW,OAAO,MAAM;CAChD,OAAO,UAAU,MAAM,QAAQ,MAAM,SAAS,KAAA,CAAS,IAAI,OAAO,KAAK;AACzE;AAEA,SAAgB,kBAAkB,MAAiE;CACjG,OAAO,eAAe;AACxB;AAEA,SAAgB,uBAAuB,MAAwC;CAC7E,OAAO,YAAY;AACrB;AAEA,SAAgB,gBAAgB,OAAmB,MAAsC;CACvF,MAAM,OAAO,uBAAuB,IAAI;CACxC,MAAM,SAAwB,CAAC;CAC/B,KAAK,MAAM,QAAQ,MAAM,YAAY,GAAG;EACtC,IAAI,KAAK,oBAAoB,QAAQ,CAAC,KAAK,OAAO,IAAI;EACtD,OAAO,KAAK;GAAE,IAAI,KAAK,OAAO;GAAI,QAAQ,KAAK;GAAI,MAAM,KAAK;GAAM;EAAK,CAAC;CAC5E;CACA,OAAO,OAAO,MAAM,MAAM,UAAU,KAAK,KAAK,cAAc,MAAM,IAAI,CAAC;AACzE;;AAGA,MAAM,mBAAmB;CAAC;CAAU;CAAS;CAAO;CAAQ;AAAa;;;;;;AAOzE,SAAS,oBAAoB,SAA4B,MAAkC;CACzF,MAAM,UAAU,YACd,QAAQ,KAAK,WAAW,KAAK,QAAQ,gBAAgB,CAAC;CACxD,MAAM,SAAS,YACb,QAAQ,KAAK,WAAW,iBAAiB,KAAK,QAAQ,OAAO,IAAI,CAAC;CACpE,OAAO,QAAQ,OAAO,OAAO,GAAG,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC;AACvF;AAEA,SAAgB,uBACd,MACA,SACoB;CACpB,MAAM,OAAO,EAAE,GAAG,QAAQ;CAC1B,KAAK,MAAM,CAAC,MAAM,WAAW,OAAO,QAAQ,mBAAmB,GAAG;EAChE,MAAM,YAAY,eAAe;EACjC,IAAI,aAAa,WAAW,CAAC,KAAK,YAAY;EAC9C,IAAI,CAAC,OAAO,MAAM,UAAU,SAAS,OAAO,GAAG;EAC/C,IAAI,SAAS,YAAY,QAAQ,WAAW,oBAAoB,KAAK,SAAS,QAAQ,OAAO,GAC3F;EACF,KAAK,aAAa;CACpB;CAGA,IADoB,UAAU,MAAM,QAAQ,OAAO,WAAW,QAAQ,SAAS,KAAK,IACtE,KAAK,EAAE,eAAe,YAAY,KAAK,WACnD,KAAK,YAAY;CAEnB,OAAO;AACT;;AAGA,SAAgB,gBACd,OACA,IACA,MACuB;CACvB,IAAI,CAAC,IAAI,OAAO,KAAA;CAChB,KAAK,MAAM,QAAQ,MAAM,YAAY,GACnC,IAAI,KAAK,oBAAoB,QAAQ,KAAK,OAAO,OAAO,IAAI,OAAO;AAGvE;;AAGA,SAAgB,mBAA2B;CACzC,OAAO,KAAK,UAAU,EAAE,EAAE;AAC5B;AAEA,MAAM,uBAAuB;;AAG7B,SAAgB,eAAe,OAA8B;CAC3D,MAAM,WAAW,MAAM,SAAS,IAAI,CAAC,CAAC,MAAM,SAAS,KAAK,YAAY;CACtE,IAAI,UAAU,OAAO;CACrB,OAAO,MAAM,WAAW,UAAU,MAAM,QAAQ;EAC9C,MAAM;EACN,OAAO;EACP,QAAQ;EACR,cAAc;CAChB,CAAC;AACH;;;;;;AAOA,SAAS,iBAAiB,QAAmB,OAAwC;CAEnF,MAAM,WAAmB,OAAO,QAAQ,MAAM;EAC5C,MAAM;EACN,OAAO;EACP,SAAS;EACT,SAAS;EACT,GAAG,kBAAkB,MAAM;CAC7B;CACA,OAAO,UAAU,MAAM,KAAK,CAAC,CAAC,KAAK,OAAO,WAAW;EACnD,GAAG;EACH,GAAG,KAAK,OAAO,QAAQ,UAAU,UAAU,gBAAgB;CAC7D,EAAE;AACJ;;;;;AAMA,SAAgB,iBACd,MACA,QACA,SACA,OACoB;CACpB,MAAM,QAA4B,GAAG,eAAe,QAAQ,QAAQ;CACpE,IAAI,CAAC,OAAO,OAAO;CACnB,IAAI,SAAS,QAAQ,MAAM,QAAQ,UAAU,MAAM,KAAK;MACnD,IAAI,SAAS,UAAU,MAAM,UAAU,iBAAiB,QAAQ,KAAK;MACrE,IAAI,SAAS,UAAU,MAAM,UAAU,YAAY,MAAM,OAAO;MAChE,IAAI,SAAS,QAAQ,MAAM,cAAc,gBAAgB,MAAM,WAAW;MAC1E,OAAO,OAAO,OAAO,gBAAgB,KAAK,OAAO,oBAAoB,IAAI,CAAC,CAAC;CAChF,OAAO;AACT;;AAGA,SAAgB,uBAAuB,MAA2C;CAChF,OAAO,GAAG,eAAe,QAAQ,KAAK;AACxC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { SceneGraph } from "../graph.js";
|
|
2
|
+
import { ComponentPropertyDefinition, SceneNode, SlotSettings } from "../types.js";
|
|
3
|
+
//#region src/slots/authoring.d.ts
|
|
4
|
+
/** The settings a new slot starts with: no limits, any layer allowed. */
|
|
5
|
+
declare const DEFAULT_SLOT_SETTINGS: SlotSettings;
|
|
6
|
+
/**
|
|
7
|
+
* The main component a layer belongs to, which defines the slots inside it. Layers of an
|
|
8
|
+
* instance are not authored there, so a layer under an instance has none.
|
|
9
|
+
*/
|
|
10
|
+
declare function slotOwner(graph: SceneGraph, node: SceneNode): SceneNode | undefined;
|
|
11
|
+
/** Whether a frame inside a main component can become a slot. */
|
|
12
|
+
declare function canCreateSlot(graph: SceneGraph, node: SceneNode): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Make a frame of a main component a slot: define a SLOT property, named after the frame, on
|
|
15
|
+
* the component and bind the frame's children to it. Instances pick up the slot on their next
|
|
16
|
+
* sync.
|
|
17
|
+
*/
|
|
18
|
+
declare function createSlotProperty(graph: SceneGraph, frameId: string, id: string): ComponentPropertyDefinition | null;
|
|
19
|
+
/** What a slot's settings panel can change. */
|
|
20
|
+
type SlotPropertyPatch = Partial<Pick<ComponentPropertyDefinition, 'name' | 'description' | 'preferredValues'>> & {
|
|
21
|
+
slotSettings?: Partial<SlotSettings>;
|
|
22
|
+
};
|
|
23
|
+
/** Change a slot property's name, description, preferred components, or limits. */
|
|
24
|
+
declare function updateSlotProperty(graph: SceneGraph, ownerId: string, propertyId: string, patch: SlotPropertyPatch): boolean;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { DEFAULT_SLOT_SETTINGS, SlotPropertyPatch, canCreateSlot, createSlotProperty, slotOwner, updateSlotProperty };
|
|
27
|
+
//# sourceMappingURL=authoring.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authoring.d.ts","names":[],"sources":["../../src/slots/authoring.ts"],"mappings":";;;;cAKa,uBAAuB;;;;;iBAUpB,UAAU,OAAO,YAAY,MAAM,YAAY;;iBAW/C,cAAc,OAAO,YAAY,MAAM;;;;;;iBAiBvC,mBACd,OAAO,YACP,iBACA,aACC;;KAyBS,oBAAoB,QAC9B,KAAK;EACD,eAAe,QAAQ;;;iBAGb,mBACd,OAAO,YACP,iBACA,oBACA,OAAO"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { slotPropertyId } from "./frames.js";
|
|
2
|
+
//#region src/slots/authoring.ts
|
|
3
|
+
/** The settings a new slot starts with: no limits, any layer allowed. */
|
|
4
|
+
const DEFAULT_SLOT_SETTINGS = {
|
|
5
|
+
allowPreferredValuesOnly: false,
|
|
6
|
+
displayEmptyByDefault: false,
|
|
7
|
+
stretchChildOnInsert: false
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* The main component a layer belongs to, which defines the slots inside it. Layers of an
|
|
11
|
+
* instance are not authored there, so a layer under an instance has none.
|
|
12
|
+
*/
|
|
13
|
+
function slotOwner(graph, node) {
|
|
14
|
+
let current = node.parentId ? graph.getNode(node.parentId) : void 0;
|
|
15
|
+
while (current && current.type !== "CANVAS") {
|
|
16
|
+
if (current.type === "COMPONENT") return current;
|
|
17
|
+
if (current.type === "INSTANCE") return void 0;
|
|
18
|
+
current = current.parentId ? graph.getNode(current.parentId) : void 0;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/** Whether a frame inside a main component can become a slot. */
|
|
22
|
+
function canCreateSlot(graph, node) {
|
|
23
|
+
return node.type === "FRAME" && !slotPropertyId(node) && !!slotOwner(graph, node);
|
|
24
|
+
}
|
|
25
|
+
function uniqueSlotName(owner, base) {
|
|
26
|
+
const taken = new Set(owner.componentPropertyDefinitions.map((definition) => definition.name));
|
|
27
|
+
if (!taken.has(base)) return base;
|
|
28
|
+
let index = 2;
|
|
29
|
+
while (taken.has(`${base} ${index}`)) index++;
|
|
30
|
+
return `${base} ${index}`;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Make a frame of a main component a slot: define a SLOT property, named after the frame, on
|
|
34
|
+
* the component and bind the frame's children to it. Instances pick up the slot on their next
|
|
35
|
+
* sync.
|
|
36
|
+
*/
|
|
37
|
+
function createSlotProperty(graph, frameId, id) {
|
|
38
|
+
const frame = graph.getNode(frameId);
|
|
39
|
+
const owner = frame && canCreateSlot(graph, frame) ? slotOwner(graph, frame) : void 0;
|
|
40
|
+
if (!frame || !owner) return null;
|
|
41
|
+
const definition = {
|
|
42
|
+
id,
|
|
43
|
+
name: uniqueSlotName(owner, frame.name.trim() || "Slot"),
|
|
44
|
+
type: "SLOT",
|
|
45
|
+
defaultValue: "",
|
|
46
|
+
preferredValues: [],
|
|
47
|
+
slotSettings: { ...DEFAULT_SLOT_SETTINGS }
|
|
48
|
+
};
|
|
49
|
+
graph.updateNode(owner.id, { componentPropertyDefinitions: [...owner.componentPropertyDefinitions, definition] });
|
|
50
|
+
graph.updateNode(frame.id, { componentPropertyReferences: [...frame.componentPropertyReferences, {
|
|
51
|
+
propertyId: id,
|
|
52
|
+
field: "SLOT_CONTENT"
|
|
53
|
+
}] });
|
|
54
|
+
return definition;
|
|
55
|
+
}
|
|
56
|
+
/** Change a slot property's name, description, preferred components, or limits. */
|
|
57
|
+
function updateSlotProperty(graph, ownerId, propertyId, patch) {
|
|
58
|
+
const owner = graph.getNode(ownerId);
|
|
59
|
+
const current = owner?.componentPropertyDefinitions.find((definition) => definition.id === propertyId && definition.type === "SLOT");
|
|
60
|
+
if (!owner || !current) return false;
|
|
61
|
+
const { slotSettings, ...fields } = patch;
|
|
62
|
+
const next = {
|
|
63
|
+
...current,
|
|
64
|
+
...fields,
|
|
65
|
+
slotSettings: {
|
|
66
|
+
...DEFAULT_SLOT_SETTINGS,
|
|
67
|
+
...current.slotSettings,
|
|
68
|
+
...slotSettings
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
graph.updateNode(owner.id, { componentPropertyDefinitions: owner.componentPropertyDefinitions.map((definition) => definition.id === propertyId ? next : definition) });
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
//#endregion
|
|
75
|
+
export { DEFAULT_SLOT_SETTINGS, canCreateSlot, createSlotProperty, slotOwner, updateSlotProperty };
|
|
76
|
+
|
|
77
|
+
//# sourceMappingURL=authoring.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authoring.js","names":[],"sources":["../../src/slots/authoring.ts"],"sourcesContent":["import type { SceneGraph } from '../graph'\nimport type { ComponentPropertyDefinition, SceneNode, SlotSettings } from '../types'\nimport { slotPropertyId } from './frames'\n\n/** The settings a new slot starts with: no limits, any layer allowed. */\nexport const DEFAULT_SLOT_SETTINGS: SlotSettings = {\n allowPreferredValuesOnly: false,\n displayEmptyByDefault: false,\n stretchChildOnInsert: false\n}\n\n/**\n * The main component a layer belongs to, which defines the slots inside it. Layers of an\n * instance are not authored there, so a layer under an instance has none.\n */\nexport function slotOwner(graph: SceneGraph, node: SceneNode): SceneNode | undefined {\n let current = node.parentId ? graph.getNode(node.parentId) : undefined\n while (current && current.type !== 'CANVAS') {\n if (current.type === 'COMPONENT') return current\n if (current.type === 'INSTANCE') return undefined\n current = current.parentId ? graph.getNode(current.parentId) : undefined\n }\n return undefined\n}\n\n/** Whether a frame inside a main component can become a slot. */\nexport function canCreateSlot(graph: SceneGraph, node: SceneNode): boolean {\n return node.type === 'FRAME' && !slotPropertyId(node) && !!slotOwner(graph, node)\n}\n\nfunction uniqueSlotName(owner: SceneNode, base: string): string {\n const taken = new Set(owner.componentPropertyDefinitions.map((definition) => definition.name))\n if (!taken.has(base)) return base\n let index = 2\n while (taken.has(`${base} ${index}`)) index++\n return `${base} ${index}`\n}\n\n/**\n * Make a frame of a main component a slot: define a SLOT property, named after the frame, on\n * the component and bind the frame's children to it. Instances pick up the slot on their next\n * sync.\n */\nexport function createSlotProperty(\n graph: SceneGraph,\n frameId: string,\n id: string\n): ComponentPropertyDefinition | null {\n const frame = graph.getNode(frameId)\n const owner = frame && canCreateSlot(graph, frame) ? slotOwner(graph, frame) : undefined\n if (!frame || !owner) return null\n const definition: ComponentPropertyDefinition = {\n id,\n name: uniqueSlotName(owner, frame.name.trim() || 'Slot'),\n type: 'SLOT',\n defaultValue: '',\n preferredValues: [],\n slotSettings: { ...DEFAULT_SLOT_SETTINGS }\n }\n graph.updateNode(owner.id, {\n componentPropertyDefinitions: [...owner.componentPropertyDefinitions, definition]\n })\n graph.updateNode(frame.id, {\n componentPropertyReferences: [\n ...frame.componentPropertyReferences,\n { propertyId: id, field: 'SLOT_CONTENT' }\n ]\n })\n return definition\n}\n\n/** What a slot's settings panel can change. */\nexport type SlotPropertyPatch = Partial<\n Pick<ComponentPropertyDefinition, 'name' | 'description' | 'preferredValues'>\n> & { slotSettings?: Partial<SlotSettings> }\n\n/** Change a slot property's name, description, preferred components, or limits. */\nexport function updateSlotProperty(\n graph: SceneGraph,\n ownerId: string,\n propertyId: string,\n patch: SlotPropertyPatch\n): boolean {\n const owner = graph.getNode(ownerId)\n const current = owner?.componentPropertyDefinitions.find(\n (definition) => definition.id === propertyId && definition.type === 'SLOT'\n )\n if (!owner || !current) return false\n const { slotSettings, ...fields } = patch\n const next: ComponentPropertyDefinition = {\n ...current,\n ...fields,\n slotSettings: { ...DEFAULT_SLOT_SETTINGS, ...current.slotSettings, ...slotSettings }\n }\n graph.updateNode(owner.id, {\n componentPropertyDefinitions: owner.componentPropertyDefinitions.map((definition) =>\n definition.id === propertyId ? next : definition\n )\n })\n return true\n}\n"],"mappings":";;;AAKA,MAAa,wBAAsC;CACjD,0BAA0B;CAC1B,uBAAuB;CACvB,sBAAsB;AACxB;;;;;AAMA,SAAgB,UAAU,OAAmB,MAAwC;CACnF,IAAI,UAAU,KAAK,WAAW,MAAM,QAAQ,KAAK,QAAQ,IAAI,KAAA;CAC7D,OAAO,WAAW,QAAQ,SAAS,UAAU;EAC3C,IAAI,QAAQ,SAAS,aAAa,OAAO;EACzC,IAAI,QAAQ,SAAS,YAAY,OAAO,KAAA;EACxC,UAAU,QAAQ,WAAW,MAAM,QAAQ,QAAQ,QAAQ,IAAI,KAAA;CACjE;AAEF;;AAGA,SAAgB,cAAc,OAAmB,MAA0B;CACzE,OAAO,KAAK,SAAS,WAAW,CAAC,eAAe,IAAI,KAAK,CAAC,CAAC,UAAU,OAAO,IAAI;AAClF;AAEA,SAAS,eAAe,OAAkB,MAAsB;CAC9D,MAAM,QAAQ,IAAI,IAAI,MAAM,6BAA6B,KAAK,eAAe,WAAW,IAAI,CAAC;CAC7F,IAAI,CAAC,MAAM,IAAI,IAAI,GAAG,OAAO;CAC7B,IAAI,QAAQ;CACZ,OAAO,MAAM,IAAI,GAAG,KAAK,GAAG,OAAO,GAAG;CACtC,OAAO,GAAG,KAAK,GAAG;AACpB;;;;;;AAOA,SAAgB,mBACd,OACA,SACA,IACoC;CACpC,MAAM,QAAQ,MAAM,QAAQ,OAAO;CACnC,MAAM,QAAQ,SAAS,cAAc,OAAO,KAAK,IAAI,UAAU,OAAO,KAAK,IAAI,KAAA;CAC/E,IAAI,CAAC,SAAS,CAAC,OAAO,OAAO;CAC7B,MAAM,aAA0C;EAC9C;EACA,MAAM,eAAe,OAAO,MAAM,KAAK,KAAK,KAAK,MAAM;EACvD,MAAM;EACN,cAAc;EACd,iBAAiB,CAAC;EAClB,cAAc,EAAE,GAAG,sBAAsB;CAC3C;CACA,MAAM,WAAW,MAAM,IAAI,EACzB,8BAA8B,CAAC,GAAG,MAAM,8BAA8B,UAAU,EAClF,CAAC;CACD,MAAM,WAAW,MAAM,IAAI,EACzB,6BAA6B,CAC3B,GAAG,MAAM,6BACT;EAAE,YAAY;EAAI,OAAO;CAAe,CAC1C,EACF,CAAC;CACD,OAAO;AACT;;AAQA,SAAgB,mBACd,OACA,SACA,YACA,OACS;CACT,MAAM,QAAQ,MAAM,QAAQ,OAAO;CACnC,MAAM,UAAU,OAAO,6BAA6B,MACjD,eAAe,WAAW,OAAO,cAAc,WAAW,SAAS,MACtE;CACA,IAAI,CAAC,SAAS,CAAC,SAAS,OAAO;CAC/B,MAAM,EAAE,cAAc,GAAG,WAAW;CACpC,MAAM,OAAoC;EACxC,GAAG;EACH,GAAG;EACH,cAAc;GAAE,GAAG;GAAuB,GAAG,QAAQ;GAAc,GAAG;EAAa;CACrF;CACA,MAAM,WAAW,MAAM,IAAI,EACzB,8BAA8B,MAAM,6BAA6B,KAAK,eACpE,WAAW,OAAO,aAAa,OAAO,UACxC,EACF,CAAC;CACD,OAAO;AACT"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { SceneGraph } from "../graph.js";
|
|
2
|
+
import { SceneNode } from "../types.js";
|
|
3
|
+
//#region src/slots/content.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Where layers may be added, moved, or removed under a parent:
|
|
6
|
+
* - `free`: outside any instance, or inside a component definition;
|
|
7
|
+
* - `slot`: inside a slot of an instance, whose content the instance owns or can claim;
|
|
8
|
+
* - `locked`: anywhere else inside an instance, whose layers come from its component, or inside a
|
|
9
|
+
* generated frame such as a sticky note, whose layers come from its template.
|
|
10
|
+
*/
|
|
11
|
+
type SlotScope = {
|
|
12
|
+
kind: 'free';
|
|
13
|
+
} | {
|
|
14
|
+
kind: 'slot';
|
|
15
|
+
frame: SceneNode;
|
|
16
|
+
instance: SceneNode;
|
|
17
|
+
propertyId: string;
|
|
18
|
+
} | {
|
|
19
|
+
kind: 'locked';
|
|
20
|
+
owner: SceneNode;
|
|
21
|
+
};
|
|
22
|
+
declare function slotScope(graph: SceneGraph, parentId: string): SlotScope;
|
|
23
|
+
/**
|
|
24
|
+
* Make the instance own its slot's content, as Figma does on the first edit: the layers
|
|
25
|
+
* stay where they are, but stop following the component. Overrides the instance held for
|
|
26
|
+
* them become their own values, or move to the nested instance they belong to.
|
|
27
|
+
*/
|
|
28
|
+
declare function claimSlotContent(graph: SceneGraph, scope: Extract<SlotScope, {
|
|
29
|
+
kind: 'slot';
|
|
30
|
+
}>): void;
|
|
31
|
+
/** Return the slot to its component's content: the instance stops owning it. */
|
|
32
|
+
declare function resetSlotContent(graph: SceneGraph, scope: Extract<SlotScope, {
|
|
33
|
+
kind: 'slot';
|
|
34
|
+
}>): void;
|
|
35
|
+
/** Remove everything from the slot; the instance keeps owning it, now empty. */
|
|
36
|
+
declare function clearSlotContent(graph: SceneGraph, scope: Extract<SlotScope, {
|
|
37
|
+
kind: 'slot';
|
|
38
|
+
}>): void;
|
|
39
|
+
//#endregion
|
|
40
|
+
export { SlotScope, claimSlotContent, clearSlotContent, resetSlotContent, slotScope };
|
|
41
|
+
//# sourceMappingURL=content.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content.d.ts","names":[],"sources":["../../src/slots/content.ts"],"mappings":";;;;;;;;;;KAcY;EACN;;EACA;EAAc,OAAO;EAAW,UAAU;EAAW;;EACrD;EAAgB,OAAO;;iBAYb,UAAU,OAAO,YAAY,mBAAmB;;;;;;iBAmChD,iBACd,OAAO,YACP,OAAO,QAAQ;EAAa;;;iBA0Cd,iBACd,OAAO,YACP,OAAO,QAAQ;EAAa;;;iBAYd,iBACd,OAAO,YACP,OAAO,QAAQ;EAAa"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { getInstanceOverride, setInstanceOverride } from "../instances/overrides.js";
|
|
2
|
+
import { isGeneratedFrame } from "../generated/index.js";
|
|
3
|
+
import { ownsSlotContent, slotPropertyId } from "./frames.js";
|
|
4
|
+
import { cloneChildrenWithMapping } from "../instances/sync.js";
|
|
5
|
+
//#region src/slots/content.ts
|
|
6
|
+
function parentOf(graph, node) {
|
|
7
|
+
return node.parentId ? graph.nodes.get(node.parentId) : void 0;
|
|
8
|
+
}
|
|
9
|
+
function nearestInstance(graph, node) {
|
|
10
|
+
let current = parentOf(graph, node);
|
|
11
|
+
while (current && current.type !== "INSTANCE") current = parentOf(graph, current);
|
|
12
|
+
return current;
|
|
13
|
+
}
|
|
14
|
+
function slotScope(graph, parentId) {
|
|
15
|
+
let current = graph.nodes.get(parentId);
|
|
16
|
+
while (current) {
|
|
17
|
+
const propertyId = slotPropertyId(current);
|
|
18
|
+
if (propertyId) {
|
|
19
|
+
const instance = nearestInstance(graph, current);
|
|
20
|
+
return instance ? {
|
|
21
|
+
kind: "slot",
|
|
22
|
+
frame: current,
|
|
23
|
+
instance,
|
|
24
|
+
propertyId
|
|
25
|
+
} : { kind: "free" };
|
|
26
|
+
}
|
|
27
|
+
if (current.type === "INSTANCE" || isGeneratedFrame(current)) return {
|
|
28
|
+
kind: "locked",
|
|
29
|
+
owner: current
|
|
30
|
+
};
|
|
31
|
+
current = parentOf(graph, current);
|
|
32
|
+
}
|
|
33
|
+
return { kind: "free" };
|
|
34
|
+
}
|
|
35
|
+
/** Every layer below `node`; `enterInstances` also walks the layers of nested instances. */
|
|
36
|
+
function descendants(graph, node, enterInstances) {
|
|
37
|
+
const result = [];
|
|
38
|
+
const visit = (parent) => {
|
|
39
|
+
for (const childId of parent.childIds) {
|
|
40
|
+
const child = graph.nodes.get(childId);
|
|
41
|
+
if (!child) continue;
|
|
42
|
+
result.push(child);
|
|
43
|
+
if (enterInstances || child.type !== "INSTANCE") visit(child);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
visit(node);
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Make the instance own its slot's content, as Figma does on the first edit: the layers
|
|
51
|
+
* stay where they are, but stop following the component. Overrides the instance held for
|
|
52
|
+
* them become their own values, or move to the nested instance they belong to.
|
|
53
|
+
*/
|
|
54
|
+
function claimSlotContent(graph, scope) {
|
|
55
|
+
const { frame, instance, propertyId } = scope;
|
|
56
|
+
if (ownsSlotContent(graph, frame, propertyId)) return;
|
|
57
|
+
graph.willChangeNode(instance);
|
|
58
|
+
const overrides = instance.instanceOverrides;
|
|
59
|
+
for (const node of descendants(graph, frame, false)) {
|
|
60
|
+
overrides.descendants.delete(node.id);
|
|
61
|
+
if (node.type !== "INSTANCE") {
|
|
62
|
+
graph.updateNode(node.id, { componentId: null });
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
graph.willChangeNode(node);
|
|
66
|
+
for (const inner of descendants(graph, node, true)) {
|
|
67
|
+
const fields = overrides.descendants.get(inner.id);
|
|
68
|
+
if (!fields) continue;
|
|
69
|
+
for (const [field, value] of fields) if (field !== "sourceComponentId") setInstanceOverride(node.instanceOverrides, node.id, inner.id, field, value);
|
|
70
|
+
overrides.descendants.delete(inner.id);
|
|
71
|
+
}
|
|
72
|
+
graph.updateNode(node.id, { instanceOverrides: node.instanceOverrides });
|
|
73
|
+
}
|
|
74
|
+
graph.updateNode(instance.id, {
|
|
75
|
+
instanceOverrides: overrides,
|
|
76
|
+
componentPropertyAssignments: {
|
|
77
|
+
...instance.componentPropertyAssignments,
|
|
78
|
+
[propertyId]: ""
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
/** The component layer an instance layer was cloned from. */
|
|
83
|
+
function componentSource(instance, node) {
|
|
84
|
+
const mapped = getInstanceOverride(instance.instanceOverrides, instance.id, node.id, "sourceComponentId");
|
|
85
|
+
return typeof mapped === "string" ? mapped : node.componentId;
|
|
86
|
+
}
|
|
87
|
+
/** Return the slot to its component's content: the instance stops owning it. */
|
|
88
|
+
function resetSlotContent(graph, scope) {
|
|
89
|
+
const { frame, instance, propertyId } = scope;
|
|
90
|
+
for (const childId of Array.from(frame.childIds)) graph.deleteNode(childId);
|
|
91
|
+
const assignments = { ...instance.componentPropertyAssignments };
|
|
92
|
+
Reflect.deleteProperty(assignments, propertyId);
|
|
93
|
+
graph.updateNode(instance.id, { componentPropertyAssignments: assignments });
|
|
94
|
+
const source = componentSource(instance, frame);
|
|
95
|
+
if (source && graph.nodes.has(source)) cloneChildrenWithMapping(graph, source, frame.id);
|
|
96
|
+
}
|
|
97
|
+
/** Remove everything from the slot; the instance keeps owning it, now empty. */
|
|
98
|
+
function clearSlotContent(graph, scope) {
|
|
99
|
+
claimSlotContent(graph, scope);
|
|
100
|
+
for (const childId of Array.from(scope.frame.childIds)) graph.deleteNode(childId);
|
|
101
|
+
}
|
|
102
|
+
//#endregion
|
|
103
|
+
export { claimSlotContent, clearSlotContent, resetSlotContent, slotScope };
|
|
104
|
+
|
|
105
|
+
//# sourceMappingURL=content.js.map
|