@open-pencil/scene-graph 0.16.0-beta.3 → 0.17.0-beta.1
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 +289 -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 +56 -0
- package/dist/behaviours/kinds.d.ts.map +1 -0
- package/dist/behaviours/kinds.js.map +1 -0
- package/dist/behaviours/layers.d.ts +16 -0
- package/dist/behaviours/layers.d.ts.map +1 -0
- package/dist/behaviours/layers.js +42 -0
- package/dist/behaviours/layers.js.map +1 -0
- package/dist/behaviours/model.d.ts +45 -0
- package/dist/behaviours/model.d.ts.map +1 -0
- package/dist/behaviours/model.js +149 -0
- package/dist/behaviours/model.js.map +1 -0
- package/dist/behaviours/schema.d.ts +114 -0
- package/dist/behaviours/schema.d.ts.map +1 -0
- package/dist/behaviours/schema.js +71 -0
- package/dist/behaviours/schema.js.map +1 -0
- package/dist/behaviours/spec.d.ts +26 -0
- package/dist/behaviours/spec.d.ts.map +1 -0
- package/dist/{chunks/behaviours → behaviours}/spec.js +4 -28
- package/dist/behaviours/spec.js.map +1 -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 +13 -0
- package/dist/checkpoint.d.ts.map +1 -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 +20 -0
- package/dist/components/properties.d.ts.map +1 -0
- package/dist/components/properties.js +125 -0
- package/dist/components/properties.js.map +1 -0
- package/dist/components/variants.d.ts +27 -0
- package/dist/components/variants.d.ts.map +1 -0
- package/dist/components/variants.js.map +1 -0
- package/dist/connectors/controls.d.ts +34 -0
- package/dist/connectors/controls.d.ts.map +1 -0
- package/dist/connectors/controls.js +196 -0
- package/dist/connectors/controls.js.map +1 -0
- package/dist/connectors/create.d.ts +23 -0
- package/dist/connectors/create.d.ts.map +1 -0
- package/dist/connectors/create.js +33 -0
- package/dist/connectors/create.js.map +1 -0
- package/dist/connectors/elbow.js +191 -0
- package/dist/connectors/elbow.js.map +1 -0
- package/dist/connectors/gaps.d.ts +10 -0
- package/dist/connectors/gaps.d.ts.map +1 -0
- package/dist/connectors/gaps.js +86 -0
- package/dist/connectors/gaps.js.map +1 -0
- package/dist/connectors/hit.d.ts +11 -0
- package/dist/connectors/hit.d.ts.map +1 -0
- package/dist/connectors/hit.js +53 -0
- package/dist/connectors/hit.js.map +1 -0
- package/dist/connectors/index.d.ts +11 -0
- package/dist/connectors/index.js +11 -0
- package/dist/connectors/label.d.ts +32 -0
- package/dist/connectors/label.d.ts.map +1 -0
- package/dist/connectors/label.js +213 -0
- package/dist/connectors/label.js.map +1 -0
- package/dist/connectors/layout.d.ts +46 -0
- package/dist/connectors/layout.d.ts.map +1 -0
- package/dist/connectors/layout.js +234 -0
- package/dist/connectors/layout.js.map +1 -0
- package/dist/connectors/pieces.d.ts +22 -0
- package/dist/connectors/pieces.d.ts.map +1 -0
- package/dist/connectors/pieces.js +159 -0
- package/dist/connectors/pieces.js.map +1 -0
- package/dist/connectors/route.d.ts +23 -0
- package/dist/connectors/route.d.ts.map +1 -0
- package/dist/connectors/route.js +107 -0
- package/dist/connectors/route.js.map +1 -0
- package/dist/connectors/sides.d.ts +23 -0
- package/dist/connectors/sides.d.ts.map +1 -0
- package/dist/connectors/sides.js +98 -0
- package/dist/connectors/sides.js.map +1 -0
- package/dist/connectors/sublayers.d.ts +76 -0
- package/dist/connectors/sublayers.d.ts.map +1 -0
- package/dist/connectors/sublayers.js +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 +270 -2
- package/dist/copy.js.map +1 -0
- package/dist/css/grid.d.ts +7 -0
- package/dist/css/grid.d.ts.map +1 -0
- package/dist/{chunks/css → css}/grid.js +2 -33
- package/dist/css/grid.js.map +1 -0
- package/dist/css/index.d.ts +6 -0
- package/dist/css/index.js +6 -0
- package/dist/css/layout.d.ts +17 -0
- package/dist/css/layout.d.ts.map +1 -0
- package/dist/css/layout.js +45 -0
- package/dist/css/layout.js.map +1 -0
- package/dist/css/shadows.d.ts +10 -0
- package/dist/css/shadows.d.ts.map +1 -0
- package/dist/css/shadows.js +64 -0
- package/dist/css/shadows.js.map +1 -0
- package/dist/css/text.d.ts +22 -0
- package/dist/css/text.d.ts.map +1 -0
- package/dist/css/text.js +76 -0
- package/dist/css/text.js.map +1 -0
- package/dist/css/values.d.ts +14 -0
- package/dist/css/values.d.ts.map +1 -0
- package/dist/css/values.js +36 -0
- package/dist/css/values.js.map +1 -0
- package/dist/events.js.map +1 -0
- package/dist/export-format.d.ts +12 -0
- package/dist/export-format.d.ts.map +1 -0
- package/dist/export-format.js +22 -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 +63 -0
- package/dist/fields/text.js.map +1 -0
- package/dist/fig-compression.d.ts +11 -0
- package/dist/fig-compression.d.ts.map +1 -0
- package/dist/fig-compression.js +15 -0
- package/dist/fig-compression.js.map +1 -0
- package/dist/figjam/index.d.ts +3 -0
- package/dist/figjam/index.js +3 -0
- package/dist/figjam/palette.d.ts +259 -0
- package/dist/figjam/palette.d.ts.map +1 -0
- package/dist/figjam/palette.js +411 -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 +38 -0
- package/dist/generated/shape-with-text.d.ts.map +1 -0
- package/dist/generated/shape-with-text.js +118 -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 +105 -2
- package/dist/geometry.d.ts.map +1 -0
- package/dist/geometry.js +374 -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 +177 -0
- package/dist/graph.d.ts.map +1 -0
- package/dist/graph.js +613 -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 +19 -2
- package/dist/guides.d.ts.map +1 -0
- 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 +34 -29
- 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 +82 -0
- package/dist/instances/fields.js.map +1 -0
- package/dist/instances/index.d.ts +40 -0
- package/dist/instances/index.d.ts.map +1 -0
- package/dist/instances/index.js +174 -0
- package/dist/instances/index.js.map +1 -0
- package/dist/instances/main-component.d.ts +11 -0
- package/dist/instances/main-component.d.ts.map +1 -0
- package/dist/instances/main-component.js +42 -0
- package/dist/instances/main-component.js.map +1 -0
- package/dist/instances/overrides.d.ts +48 -0
- package/dist/instances/overrides.d.ts.map +1 -0
- package/dist/instances/overrides.js +142 -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/sync.js +275 -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/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 +142 -0
- package/dist/plugin-data/fields.d.ts.map +1 -0
- package/dist/plugin-data/fields.js +153 -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 +38 -0
- package/dist/shared-styles.d.ts.map +1 -0
- package/dist/shared-styles.js +125 -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 +103 -0
- package/dist/slots/content.js.map +1 -0
- package/dist/slots/frames.d.ts +38 -0
- package/dist/slots/frames.d.ts.map +1 -0
- package/dist/slots/frames.js +113 -0
- package/dist/slots/frames.js.map +1 -0
- package/dist/slots/index.d.ts +5 -0
- package/dist/slots/index.js +5 -0
- package/dist/slots/limits.d.ts +14 -0
- package/dist/slots/limits.d.ts.map +1 -0
- package/dist/slots/limits.js +28 -0
- package/dist/slots/limits.js.map +1 -0
- package/dist/snap.d.ts +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 +19 -0
- package/dist/text/lengths.d.ts.map +1 -0
- package/dist/text/lengths.js +40 -0
- package/dist/text/lengths.js.map +1 -0
- package/dist/text/lists.d.ts +44 -0
- package/dist/text/lists.d.ts.map +1 -0
- package/dist/text/lists.js +100 -0
- package/dist/text/lists.js.map +1 -0
- package/dist/text/overflow.d.ts +11 -0
- package/dist/text/overflow.d.ts.map +1 -0
- package/dist/text/overflow.js +13 -0
- package/dist/text/overflow.js.map +1 -0
- package/dist/text/paragraphs.d.ts +62 -0
- package/dist/text/paragraphs.d.ts.map +1 -0
- package/dist/text/paragraphs.js +166 -0
- package/dist/text/paragraphs.js.map +1 -0
- package/dist/{text-picture.d.ts → text/picture.d.ts} +2 -2
- package/dist/text/picture.d.ts.map +1 -0
- package/dist/text/picture.js +41 -0
- package/dist/text/picture.js.map +1 -0
- package/dist/text/references.d.ts +21 -0
- package/dist/text/references.d.ts.map +1 -0
- package/dist/text/references.js +43 -0
- package/dist/text/references.js.map +1 -0
- package/dist/text/schema.d.ts +10 -0
- package/dist/text/schema.d.ts.map +1 -0
- package/dist/text/schema.js +11 -0
- package/dist/text/schema.js.map +1 -0
- package/dist/transfer/apply.d.ts +9 -0
- package/dist/transfer/apply.d.ts.map +1 -0
- package/dist/transfer/apply.js +65 -0
- package/dist/transfer/apply.js.map +1 -0
- package/dist/transfer/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 +74 -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 +169 -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 +60 -0
- package/dist/variables/bindings.d.ts.map +1 -0
- package/dist/variables/bindings.js +224 -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 +25 -0
- package/dist/variables/fields.d.ts.map +1 -0
- package/dist/variables/fields.js +69 -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 +223 -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 +297 -137
- package/src/arrow-caps.ts +282 -62
- package/src/behaviours/index.ts +5 -0
- package/src/behaviours/layers.ts +1 -1
- package/src/behaviours/model.ts +3 -11
- package/src/behaviours/schema.ts +44 -9
- package/src/behaviours/spec.ts +4 -49
- package/src/checkpoint.ts +1 -1
- 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 +2 -2
- package/src/components/variants.ts +1 -1
- package/src/connectors/controls.ts +229 -0
- package/src/connectors/create.ts +48 -0
- package/src/connectors/elbow.ts +235 -0
- package/src/connectors/gaps.ts +72 -0
- package/src/connectors/hit.ts +60 -0
- package/src/connectors/index.ts +28 -0
- package/src/connectors/label.ts +238 -0
- package/src/connectors/layout.ts +280 -0
- package/src/connectors/pieces.ts +144 -0
- package/src/connectors/route.ts +148 -0
- package/src/connectors/sides.ts +94 -0
- package/src/connectors/sublayers.ts +203 -0
- package/src/coordinate.ts +10 -3
- package/src/copy.ts +63 -17
- package/src/css/index.ts +1 -0
- package/src/css/text.ts +84 -0
- package/src/export-format.ts +1 -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 +29 -0
- package/src/fig-compression.ts +9 -0
- package/src/figjam/index.ts +2 -0
- package/src/figjam/palette.ts +445 -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 +131 -0
- package/src/generated/sticky.ts +213 -0
- package/src/geometry.ts +40 -130
- package/src/gradient.ts +14 -0
- package/src/graph.ts +825 -0
- package/src/group-bounds.ts +59 -12
- package/src/guides.ts +1 -1
- package/src/hit-test.ts +52 -21
- 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 +39 -92
- package/src/{instances.ts → instances/index.ts} +13 -15
- package/src/instances/main-component.ts +43 -1
- package/src/{instance-overrides.ts → instances/overrides.ts} +31 -1
- package/src/instances/placement.ts +1 -1
- package/src/instances/source-walk.ts +3 -9
- package/src/instances/sync.ts +30 -140
- 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 +41 -2
- 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 +54 -75
- 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 +89 -18
- package/src/slots/authoring.ts +1 -1
- package/src/slots/content.ts +8 -5
- package/src/slots/frames.ts +3 -3
- 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 +34 -0
- package/src/text/overflow.ts +12 -0
- 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 +11 -14
- 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 +218 -13
- package/src/undo.ts +64 -2
- package/src/variables/bindings.ts +44 -55
- package/src/variables/corners.ts +39 -0
- package/src/variables/fields.ts +38 -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} +52 -145
- 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.map +0 -1
- package/dist/chunks/buffered-events.js.map +0 -1
- 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.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/behaviours → behaviours}/kinds.js +0 -0
- /package/dist/{chunks/bindings.js → bindings.js} +0 -0
- /package/dist/{chunks/buffered-events.js → buffered-events.js} +0 -0
- /package/dist/{chunks/checkpoint.js → checkpoint.js} +0 -0
- /package/dist/{chunks/components → components}/variants.js +0 -0
- /package/dist/{chunks/events.js → events.js} +0 -0
- /package/dist/{chunks/fields → fields}/geometry.js +0 -0
package/dist/resize.js
CHANGED
|
@@ -1,2 +1,287 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { cloneVectorNetwork, copyDerivedGlyphs, copyGeometryPaths, copyStroke, copyStrokes, scaleGeometryPaths } from "./copy.js";
|
|
2
|
+
import { enforcedAspectRatio } from "./layout/aspect-ratio.js";
|
|
3
|
+
//#region src/resize.ts
|
|
4
|
+
const CONSTRAINT_CONTAINER_TYPES = /* @__PURE__ */ new Set([
|
|
5
|
+
"FRAME",
|
|
6
|
+
"COMPONENT",
|
|
7
|
+
"COMPONENT_SET",
|
|
8
|
+
"INSTANCE",
|
|
9
|
+
"GROUP",
|
|
10
|
+
"BOOLEAN_OPERATION"
|
|
11
|
+
]);
|
|
12
|
+
function constrainedAxis(position, size, parentBefore, parentAfter, constraint) {
|
|
13
|
+
const delta = parentAfter - parentBefore;
|
|
14
|
+
if (constraint === "MAX") return {
|
|
15
|
+
position: position + delta,
|
|
16
|
+
size
|
|
17
|
+
};
|
|
18
|
+
if (constraint === "CENTER") return {
|
|
19
|
+
position: position + delta / 2,
|
|
20
|
+
size
|
|
21
|
+
};
|
|
22
|
+
if (constraint === "STRETCH") return {
|
|
23
|
+
position,
|
|
24
|
+
size: Math.max(1, size + delta)
|
|
25
|
+
};
|
|
26
|
+
if (constraint === "SCALE" && parentBefore > 0) {
|
|
27
|
+
const scale = parentAfter / parentBefore;
|
|
28
|
+
return {
|
|
29
|
+
position: position * scale,
|
|
30
|
+
size: Math.max(1, size * scale)
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
position,
|
|
35
|
+
size
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
const FLEXIBLE_CONSTRAINTS = /* @__PURE__ */ new Set(["STRETCH", "SCALE"]);
|
|
39
|
+
/** The axis at `size`, keeping the edge or centre its constraint pins where it was placed. */
|
|
40
|
+
function resizedInPlace(placed, size, constraint) {
|
|
41
|
+
if (constraint === "MAX") return {
|
|
42
|
+
position: placed.position + placed.size - size,
|
|
43
|
+
size
|
|
44
|
+
};
|
|
45
|
+
if (constraint === "CENTER") return {
|
|
46
|
+
position: placed.position + (placed.size - size) / 2,
|
|
47
|
+
size
|
|
48
|
+
};
|
|
49
|
+
return {
|
|
50
|
+
position: placed.position,
|
|
51
|
+
size
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/** Keep a placed box's constrained edges or center when its content determines its size. */
|
|
55
|
+
function resizedChildRect(placed, size, horizontal, vertical) {
|
|
56
|
+
const x = resizedInPlace({
|
|
57
|
+
position: placed.x,
|
|
58
|
+
size: placed.width
|
|
59
|
+
}, size.width, horizontal);
|
|
60
|
+
const y = resizedInPlace({
|
|
61
|
+
position: placed.y,
|
|
62
|
+
size: placed.height
|
|
63
|
+
}, size.height, vertical);
|
|
64
|
+
return {
|
|
65
|
+
x: x.position,
|
|
66
|
+
y: y.position,
|
|
67
|
+
width: x.size,
|
|
68
|
+
height: y.size
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* A locked aspect ratio holds when exactly one axis follows the parent, as in Figma: that axis
|
|
73
|
+
* sizes the other. With both axes following the parent, or neither, the ratio gives way.
|
|
74
|
+
*/
|
|
75
|
+
function keepLockedRatio(x, y, horizontal, vertical, aspectRatio) {
|
|
76
|
+
const flexibleX = FLEXIBLE_CONSTRAINTS.has(horizontal);
|
|
77
|
+
if (aspectRatio === null || flexibleX === FLEXIBLE_CONSTRAINTS.has(vertical)) return {
|
|
78
|
+
x,
|
|
79
|
+
y
|
|
80
|
+
};
|
|
81
|
+
return flexibleX ? {
|
|
82
|
+
x,
|
|
83
|
+
y: resizedInPlace(y, x.size / aspectRatio, vertical)
|
|
84
|
+
} : {
|
|
85
|
+
x: resizedInPlace(x, y.size * aspectRatio, horizontal),
|
|
86
|
+
y
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/** A child's box after its parent resizes, keeping a locked aspect ratio as Figma does. */
|
|
90
|
+
function constrainedChildRect(child, parentBefore, parentAfter, horizontal, vertical, aspectRatio = null) {
|
|
91
|
+
let x = constrainedAxis(child.x, child.width, parentBefore.width, parentAfter.width, horizontal);
|
|
92
|
+
let y = constrainedAxis(child.y, child.height, parentBefore.height, parentAfter.height, vertical);
|
|
93
|
+
({x, y} = keepLockedRatio(x, y, horizontal, vertical, aspectRatio));
|
|
94
|
+
return {
|
|
95
|
+
x: Math.round(x.position),
|
|
96
|
+
y: Math.round(y.position),
|
|
97
|
+
width: Math.round(x.size),
|
|
98
|
+
height: Math.round(y.size)
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
function layoutConstrainedAxis(position, size, parentBefore, parentAfter, constraint) {
|
|
102
|
+
const delta = Math.round(parentAfter) - Math.round(parentBefore);
|
|
103
|
+
if (constraint === "MAX") return {
|
|
104
|
+
position: position + delta,
|
|
105
|
+
size
|
|
106
|
+
};
|
|
107
|
+
if (constraint === "CENTER") return {
|
|
108
|
+
position: position + Math.round(parentAfter / 2) - Math.round(parentBefore / 2),
|
|
109
|
+
size
|
|
110
|
+
};
|
|
111
|
+
if (constraint === "STRETCH") return {
|
|
112
|
+
position,
|
|
113
|
+
size: Math.abs(size + delta)
|
|
114
|
+
};
|
|
115
|
+
if (constraint === "SCALE" && parentBefore > 0) {
|
|
116
|
+
const scale = parentAfter / parentBefore;
|
|
117
|
+
return {
|
|
118
|
+
position: Math.round(position * scale * 128) / 128,
|
|
119
|
+
size: size * scale
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
position,
|
|
124
|
+
size
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Where a child goes when layout resizes its parent, as Figma places a layer that ignores auto
|
|
129
|
+
* layout when its Hug frame grows (measured on desktop 126): Right and Left & right move or grow
|
|
130
|
+
* it by the change in the parent's size rounded to whole pixels, Center by the change in its
|
|
131
|
+
* rounded half, and Scale by the exact ratio, its position to 1/128 of a pixel. Sizes are not
|
|
132
|
+
* rounded, so applying a run of changes one at a time lands where applying them at once does.
|
|
133
|
+
*/
|
|
134
|
+
function layoutConstrainedChildRect(child, parentBefore, parentAfter, horizontal, vertical, aspectRatio = null) {
|
|
135
|
+
const placed = keepLockedRatio(layoutConstrainedAxis(child.x, child.width, parentBefore.width, parentAfter.width, horizontal), layoutConstrainedAxis(child.y, child.height, parentBefore.height, parentAfter.height, vertical), horizontal, vertical, aspectRatio);
|
|
136
|
+
return {
|
|
137
|
+
x: placed.x.position,
|
|
138
|
+
y: placed.y.position,
|
|
139
|
+
width: placed.x.size,
|
|
140
|
+
height: placed.y.size
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
function scaledChildRect(child, parentBefore, parentAfter) {
|
|
144
|
+
return constrainedChildRect(child, parentBefore, parentAfter, "SCALE", "SCALE");
|
|
145
|
+
}
|
|
146
|
+
function scaleVectorNetworkForResize(vectorNetwork, originalWidth, originalHeight, width, height) {
|
|
147
|
+
if (!vectorNetwork || originalWidth <= 0 && originalHeight <= 0) return null;
|
|
148
|
+
const scaleX = originalWidth > 0 ? width / originalWidth : 1;
|
|
149
|
+
const scaleY = originalHeight > 0 ? height / originalHeight : 1;
|
|
150
|
+
if (scaleX === 1 && scaleY === 1) return null;
|
|
151
|
+
return {
|
|
152
|
+
vertices: vectorNetwork.vertices.map((vertex) => ({
|
|
153
|
+
...vertex,
|
|
154
|
+
x: vertex.x * scaleX,
|
|
155
|
+
y: vertex.y * scaleY
|
|
156
|
+
})),
|
|
157
|
+
segments: vectorNetwork.segments.map((segment) => ({
|
|
158
|
+
...segment,
|
|
159
|
+
tangentStart: {
|
|
160
|
+
x: segment.tangentStart.x * scaleX,
|
|
161
|
+
y: segment.tangentStart.y * scaleY
|
|
162
|
+
},
|
|
163
|
+
tangentEnd: {
|
|
164
|
+
x: segment.tangentEnd.x * scaleX,
|
|
165
|
+
y: segment.tangentEnd.y * scaleY
|
|
166
|
+
}
|
|
167
|
+
})),
|
|
168
|
+
regions: vectorNetwork.regions
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
/** Snapshot one node's resize-relevant state (rect + geometry that must scale with it). */
|
|
172
|
+
function createResizeSnapshot(node) {
|
|
173
|
+
return {
|
|
174
|
+
type: node.type,
|
|
175
|
+
x: node.x,
|
|
176
|
+
y: node.y,
|
|
177
|
+
width: node.width,
|
|
178
|
+
height: node.height,
|
|
179
|
+
vectorNetwork: node.vectorNetwork ? cloneVectorNetwork(node.vectorNetwork) : null,
|
|
180
|
+
fillGeometry: copyGeometryPaths(node.fillGeometry),
|
|
181
|
+
strokeGeometry: copyGeometryPaths(node.strokeGeometry),
|
|
182
|
+
derivedTextGlyphs: copyDerivedGlyphs(node.derivedTextGlyphs),
|
|
183
|
+
strokes: copyStrokes(node.strokes),
|
|
184
|
+
textPathData: node.textPathData ? structuredClone(node.textPathData) : null,
|
|
185
|
+
textPathBox: node.textPathBox ? { ...node.textPathBox } : null
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
function scaleDerivedGlyphs(glyphs, sx, sy) {
|
|
189
|
+
if (!glyphs?.length) return glyphs;
|
|
190
|
+
return glyphs.map((g) => ({
|
|
191
|
+
...g,
|
|
192
|
+
x: g.x * sx,
|
|
193
|
+
y: g.y * sy,
|
|
194
|
+
scaleX: (g.scaleX ?? 1) * sx,
|
|
195
|
+
scaleY: (g.scaleY ?? 1) * sy,
|
|
196
|
+
commandsBlob: new Uint8Array(g.commandsBlob)
|
|
197
|
+
}));
|
|
198
|
+
}
|
|
199
|
+
function hasPath(orig) {
|
|
200
|
+
return (orig.vectorNetwork?.segments.length ?? 0) > 0;
|
|
201
|
+
}
|
|
202
|
+
function scaleStrokes(strokes, sx, sy) {
|
|
203
|
+
if (strokes.length === 0) return strokes;
|
|
204
|
+
const weightScale = (Math.abs(sx) + Math.abs(sy)) / 2;
|
|
205
|
+
return strokes.map((s) => ({
|
|
206
|
+
...copyStroke(s),
|
|
207
|
+
weight: s.weight * weightScale
|
|
208
|
+
}));
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* All geometry that must track a width/height change. Historically only
|
|
212
|
+
* vectorNetwork + fillGeometry were updated — path-text strokeGeometry and
|
|
213
|
+
* glyphs stayed at the pre-resize size, so shrinking a sticker made the white
|
|
214
|
+
* OUTSIDE outlines look massively thick (DomeSticker resize bug).
|
|
215
|
+
*/
|
|
216
|
+
function scaledGeometryChanges(orig, origWidth, origHeight, width, height) {
|
|
217
|
+
if (origWidth <= 0 || origHeight <= 0) return {};
|
|
218
|
+
const sx = width / origWidth;
|
|
219
|
+
const sy = height / origHeight;
|
|
220
|
+
if (sx === 1 && sy === 1) return {};
|
|
221
|
+
const changes = {};
|
|
222
|
+
const resizedVN = scaleVectorNetworkForResize(orig.vectorNetwork, origWidth, origHeight, width, height);
|
|
223
|
+
if (resizedVN) changes.vectorNetwork = resizedVN;
|
|
224
|
+
if (orig.fillGeometry.length > 0) changes.fillGeometry = scaleGeometryPaths(orig.fillGeometry, sx, sy);
|
|
225
|
+
const outlineOnly = orig.type === "TEXT" || orig.type === "VECTOR" && !hasPath(orig);
|
|
226
|
+
if (orig.strokeGeometry.length > 0) changes.strokeGeometry = outlineOnly ? scaleGeometryPaths(orig.strokeGeometry, sx, sy) : [];
|
|
227
|
+
const glyphs = orig.derivedTextGlyphs ?? [];
|
|
228
|
+
const pathText = !!orig.textPathData || !!orig.textPathBox || glyphs.some((glyph) => (glyph.rotation ?? 0) !== 0);
|
|
229
|
+
if (glyphs.length > 0 && pathText) {
|
|
230
|
+
changes.derivedTextGlyphs = scaleDerivedGlyphs(glyphs, sx, sy);
|
|
231
|
+
if (orig.textPathBox) changes.textPathBox = {
|
|
232
|
+
x: orig.textPathBox.x * sx,
|
|
233
|
+
y: orig.textPathBox.y * sy,
|
|
234
|
+
width: orig.textPathBox.width * sx,
|
|
235
|
+
height: orig.textPathBox.height * sy
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
if (orig.strokes.length > 0 && glyphs.length > 0 && pathText) changes.strokes = scaleStrokes(orig.strokes, sx, sy);
|
|
239
|
+
return changes;
|
|
240
|
+
}
|
|
241
|
+
function collectResizeDescendants(graph, rootId) {
|
|
242
|
+
const root = graph.getNode(rootId);
|
|
243
|
+
if (!root || !CONSTRAINT_CONTAINER_TYPES.has(root.type)) return null;
|
|
244
|
+
const snapshots = /* @__PURE__ */ new Map();
|
|
245
|
+
const collect = (parentId) => {
|
|
246
|
+
const parent = graph.getNode(parentId);
|
|
247
|
+
if (!parent) return;
|
|
248
|
+
for (const childId of parent.childIds) {
|
|
249
|
+
const child = graph.getNode(childId);
|
|
250
|
+
if (!child) continue;
|
|
251
|
+
snapshots.set(childId, createResizeSnapshot(child));
|
|
252
|
+
collect(childId);
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
collect(rootId);
|
|
256
|
+
return snapshots.size > 0 ? snapshots : null;
|
|
257
|
+
}
|
|
258
|
+
function computeConstrainedResizeChanges(graph, rootId, rootBefore, rootAfter, originals) {
|
|
259
|
+
const changes = /* @__PURE__ */ new Map();
|
|
260
|
+
const compute = (parentId, parentBefore, parentAfter) => {
|
|
261
|
+
const parent = graph.getNode(parentId);
|
|
262
|
+
if (!parent) return;
|
|
263
|
+
const scalesChildren = parent.type === "GROUP" || parent.type === "BOOLEAN_OPERATION";
|
|
264
|
+
for (const childId of parent.childIds) {
|
|
265
|
+
const original = originals.get(childId);
|
|
266
|
+
const child = graph.getNode(childId);
|
|
267
|
+
if (!original || !child) continue;
|
|
268
|
+
if (parent.layoutMode !== "NONE" && child.layoutPositioning !== "ABSOLUTE") {
|
|
269
|
+
compute(childId, original, child);
|
|
270
|
+
continue;
|
|
271
|
+
}
|
|
272
|
+
const rect = scalesChildren ? scaledChildRect(original, parentBefore, parentAfter) : constrainedChildRect(original, parentBefore, parentAfter, child.horizontalConstraint, child.verticalConstraint, enforcedAspectRatio(child));
|
|
273
|
+
const childChanges = {
|
|
274
|
+
...rect,
|
|
275
|
+
...scaledGeometryChanges(original, original.width, original.height, rect.width, rect.height)
|
|
276
|
+
};
|
|
277
|
+
changes.set(childId, childChanges);
|
|
278
|
+
compute(childId, original, child.layoutMode === "NONE" ? rect : child);
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
compute(rootId, rootBefore, rootAfter);
|
|
282
|
+
return changes;
|
|
283
|
+
}
|
|
284
|
+
//#endregion
|
|
285
|
+
export { collectResizeDescendants, computeConstrainedResizeChanges, constrainedChildRect, createResizeSnapshot, layoutConstrainedChildRect, resizedChildRect, scaleVectorNetworkForResize, scaledChildRect, scaledGeometryChanges };
|
|
286
|
+
|
|
287
|
+
//# sourceMappingURL=resize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resize.js","names":[],"sources":["../src/resize.ts"],"sourcesContent":["import {\n cloneVectorNetwork,\n copyDerivedGlyphs,\n copyGeometryPaths,\n copyStroke,\n copyStrokes,\n scaleGeometryPaths\n} from './copy'\nimport { enforcedAspectRatio } from './layout/aspect-ratio'\nimport type { Rect } from './primitives'\nimport type { ConstraintType, DerivedTextGlyph, SceneNode, Stroke, VectorNetwork } from './types'\n\n/**\n * Drag-start state a live resize re-scales from. Path text needs more than the\n * layout rect: its OUTSIDE stroke silhouettes and glyph outlines are baked\n * geometry that must scale with the node, and textPathBox is the layout box the\n * glyphs were reflowed against.\n */\nexport type ResizeSnapshot = Pick<\n SceneNode,\n | 'type'\n | 'x'\n | 'y'\n | 'width'\n | 'height'\n | 'vectorNetwork'\n | 'fillGeometry'\n | 'strokeGeometry'\n | 'derivedTextGlyphs'\n | 'strokes'\n | 'textPathData'\n | 'textPathBox'\n>\n\ninterface ResizeGraph {\n getNode(id: string): SceneNode | undefined\n}\n\nconst CONSTRAINT_CONTAINER_TYPES = new Set([\n 'FRAME',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE',\n 'GROUP',\n 'BOOLEAN_OPERATION'\n])\n\nfunction constrainedAxis(\n position: number,\n size: number,\n parentBefore: number,\n parentAfter: number,\n constraint: ConstraintType\n): { position: number; size: number } {\n const delta = parentAfter - parentBefore\n if (constraint === 'MAX') return { position: position + delta, size }\n if (constraint === 'CENTER') return { position: position + delta / 2, size }\n if (constraint === 'STRETCH') return { position, size: Math.max(1, size + delta) }\n if (constraint === 'SCALE' && parentBefore > 0) {\n const scale = parentAfter / parentBefore\n return { position: position * scale, size: Math.max(1, size * scale) }\n }\n return { position, size }\n}\n\ntype AxisPlacement = { position: number; size: number }\n\nconst FLEXIBLE_CONSTRAINTS: ReadonlySet<ConstraintType> = new Set(['STRETCH', 'SCALE'])\n\n/** The axis at `size`, keeping the edge or centre its constraint pins where it was placed. */\nfunction resizedInPlace(\n placed: AxisPlacement,\n size: number,\n constraint: ConstraintType\n): AxisPlacement {\n if (constraint === 'MAX') return { position: placed.position + placed.size - size, size }\n if (constraint === 'CENTER') return { position: placed.position + (placed.size - size) / 2, size }\n return { position: placed.position, size }\n}\n\n/** Keep a placed box's constrained edges or center when its content determines its size. */\nexport function resizedChildRect(\n placed: Rect,\n size: Pick<Rect, 'width' | 'height'>,\n horizontal: ConstraintType,\n vertical: ConstraintType\n): Rect {\n const x = resizedInPlace({ position: placed.x, size: placed.width }, size.width, horizontal)\n const y = resizedInPlace({ position: placed.y, size: placed.height }, size.height, vertical)\n return { x: x.position, y: y.position, width: x.size, height: y.size }\n}\n\n/**\n * A locked aspect ratio holds when exactly one axis follows the parent, as in Figma: that axis\n * sizes the other. With both axes following the parent, or neither, the ratio gives way.\n */\nfunction keepLockedRatio(\n x: AxisPlacement,\n y: AxisPlacement,\n horizontal: ConstraintType,\n vertical: ConstraintType,\n aspectRatio: number | null\n): { x: AxisPlacement; y: AxisPlacement } {\n const flexibleX = FLEXIBLE_CONSTRAINTS.has(horizontal)\n if (aspectRatio === null || flexibleX === FLEXIBLE_CONSTRAINTS.has(vertical)) return { x, y }\n return flexibleX\n ? { x, y: resizedInPlace(y, x.size / aspectRatio, vertical) }\n : { x: resizedInPlace(x, y.size * aspectRatio, horizontal), y }\n}\n\n/** A child's box after its parent resizes, keeping a locked aspect ratio as Figma does. */\nexport function constrainedChildRect(\n child: Rect,\n parentBefore: Pick<Rect, 'width' | 'height'>,\n parentAfter: Pick<Rect, 'width' | 'height'>,\n horizontal: ConstraintType,\n vertical: ConstraintType,\n aspectRatio: number | null = null\n): Rect {\n let x = constrainedAxis(child.x, child.width, parentBefore.width, parentAfter.width, horizontal)\n let y = constrainedAxis(child.y, child.height, parentBefore.height, parentAfter.height, vertical)\n ;({ x, y } = keepLockedRatio(x, y, horizontal, vertical, aspectRatio))\n return {\n x: Math.round(x.position),\n y: Math.round(y.position),\n width: Math.round(x.size),\n height: Math.round(y.size)\n }\n}\n\nfunction layoutConstrainedAxis(\n position: number,\n size: number,\n parentBefore: number,\n parentAfter: number,\n constraint: ConstraintType\n): { position: number; size: number } {\n const delta = Math.round(parentAfter) - Math.round(parentBefore)\n if (constraint === 'MAX') return { position: position + delta, size }\n if (constraint === 'CENTER') {\n return { position: position + Math.round(parentAfter / 2) - Math.round(parentBefore / 2), size }\n }\n if (constraint === 'STRETCH') return { position, size: Math.abs(size + delta) }\n if (constraint === 'SCALE' && parentBefore > 0) {\n const scale = parentAfter / parentBefore\n return { position: Math.round(position * scale * 128) / 128, size: size * scale }\n }\n return { position, size }\n}\n\n/**\n * Where a child goes when layout resizes its parent, as Figma places a layer that ignores auto\n * layout when its Hug frame grows (measured on desktop 126): Right and Left & right move or grow\n * it by the change in the parent's size rounded to whole pixels, Center by the change in its\n * rounded half, and Scale by the exact ratio, its position to 1/128 of a pixel. Sizes are not\n * rounded, so applying a run of changes one at a time lands where applying them at once does.\n */\nexport function layoutConstrainedChildRect(\n child: Rect,\n parentBefore: Pick<Rect, 'width' | 'height'>,\n parentAfter: Pick<Rect, 'width' | 'height'>,\n horizontal: ConstraintType,\n vertical: ConstraintType,\n aspectRatio: number | null = null\n): Rect {\n const placed = keepLockedRatio(\n layoutConstrainedAxis(child.x, child.width, parentBefore.width, parentAfter.width, horizontal),\n layoutConstrainedAxis(child.y, child.height, parentBefore.height, parentAfter.height, vertical),\n horizontal,\n vertical,\n aspectRatio\n )\n return {\n x: placed.x.position,\n y: placed.y.position,\n width: placed.x.size,\n height: placed.y.size\n }\n}\n\nexport function scaledChildRect(\n child: Rect,\n parentBefore: Pick<Rect, 'width' | 'height'>,\n parentAfter: Pick<Rect, 'width' | 'height'>\n): Rect {\n return constrainedChildRect(child, parentBefore, parentAfter, 'SCALE', 'SCALE')\n}\n\nexport function scaleVectorNetworkForResize(\n vectorNetwork: VectorNetwork | null,\n originalWidth: number,\n originalHeight: number,\n width: number,\n height: number\n): VectorNetwork | null {\n if (!vectorNetwork || (originalWidth <= 0 && originalHeight <= 0)) return null\n\n // A flat side, as a straight line's, has nothing to scale along it.\n const scaleX = originalWidth > 0 ? width / originalWidth : 1\n const scaleY = originalHeight > 0 ? height / originalHeight : 1\n if (scaleX === 1 && scaleY === 1) return null\n\n return {\n vertices: vectorNetwork.vertices.map((vertex) => ({\n ...vertex,\n x: vertex.x * scaleX,\n y: vertex.y * scaleY\n })),\n segments: vectorNetwork.segments.map((segment) => ({\n ...segment,\n tangentStart: {\n x: segment.tangentStart.x * scaleX,\n y: segment.tangentStart.y * scaleY\n },\n tangentEnd: {\n x: segment.tangentEnd.x * scaleX,\n y: segment.tangentEnd.y * scaleY\n }\n })),\n regions: vectorNetwork.regions\n }\n}\n\n/** Snapshot one node's resize-relevant state (rect + geometry that must scale with it). */\nexport function createResizeSnapshot(node: SceneNode): ResizeSnapshot {\n return {\n type: node.type,\n x: node.x,\n y: node.y,\n width: node.width,\n height: node.height,\n vectorNetwork: node.vectorNetwork ? cloneVectorNetwork(node.vectorNetwork) : null,\n fillGeometry: copyGeometryPaths(node.fillGeometry),\n strokeGeometry: copyGeometryPaths(node.strokeGeometry),\n derivedTextGlyphs: copyDerivedGlyphs(node.derivedTextGlyphs),\n strokes: copyStrokes(node.strokes),\n textPathData: node.textPathData ? structuredClone(node.textPathData) : null,\n textPathBox: node.textPathBox ? { ...node.textPathBox } : null\n }\n}\n\nfunction scaleDerivedGlyphs(\n glyphs: DerivedTextGlyph[] | null,\n sx: number,\n sy: number\n): DerivedTextGlyph[] | null {\n if (!glyphs?.length) return glyphs\n return glyphs.map((g) => ({\n ...g,\n x: g.x * sx,\n y: g.y * sy,\n scaleX: (g.scaleX ?? 1) * sx,\n scaleY: (g.scaleY ?? 1) * sy,\n commandsBlob: new Uint8Array(g.commandsBlob)\n }))\n}\n\nfunction hasPath(orig: Pick<ResizeSnapshot, 'vectorNetwork'>): boolean {\n return (orig.vectorNetwork?.segments.length ?? 0) > 0\n}\n\nfunction scaleStrokes(strokes: Stroke[], sx: number, sy: number): Stroke[] {\n if (strokes.length === 0) return strokes\n // Weight is a scalar; average scale is the usual 2D → 1D compromise.\n const weightScale = (Math.abs(sx) + Math.abs(sy)) / 2\n return strokes.map((s) => ({ ...copyStroke(s), weight: s.weight * weightScale }))\n}\n\n/**\n * All geometry that must track a width/height change. Historically only\n * vectorNetwork + fillGeometry were updated — path-text strokeGeometry and\n * glyphs stayed at the pre-resize size, so shrinking a sticker made the white\n * OUTSIDE outlines look massively thick (DomeSticker resize bug).\n */\nexport function scaledGeometryChanges(\n orig: Pick<\n ResizeSnapshot,\n | 'type'\n | 'vectorNetwork'\n | 'fillGeometry'\n | 'strokeGeometry'\n | 'derivedTextGlyphs'\n | 'strokes'\n | 'textPathData'\n | 'textPathBox'\n >,\n origWidth: number,\n origHeight: number,\n width: number,\n height: number\n): Partial<SceneNode> {\n if (origWidth <= 0 || origHeight <= 0) return {}\n const sx = width / origWidth\n const sy = height / origHeight\n if (sx === 1 && sy === 1) return {}\n\n const changes: Partial<SceneNode> = {}\n const resizedVN = scaleVectorNetworkForResize(\n orig.vectorNetwork,\n origWidth,\n origHeight,\n width,\n height\n )\n if (resizedVN) changes.vectorNetwork = resizedVN\n\n if (orig.fillGeometry.length > 0) {\n changes.fillGeometry = scaleGeometryPaths(orig.fillGeometry, sx, sy)\n }\n // A stroke keeps its weight through a resize, as in Figma, so a saved stroke outline goes where\n // the stroke can be drawn again at its weight: from a path, or from a shape's own outline.\n // Text and a vector with only its outline keep scaling the outline, which is all they have.\n const outlineOnly = orig.type === 'TEXT' || (orig.type === 'VECTOR' && !hasPath(orig))\n if (orig.strokeGeometry.length > 0) {\n changes.strokeGeometry = outlineOnly ? scaleGeometryPaths(orig.strokeGeometry, sx, sy) : []\n }\n // Path text scales with its path, including baked path text that kept only rotated glyphs;\n // other text reflows in the new box, so its glyphs are dropped.\n const glyphs = orig.derivedTextGlyphs ?? []\n const pathText =\n !!orig.textPathData || !!orig.textPathBox || glyphs.some((glyph) => (glyph.rotation ?? 0) !== 0)\n if (glyphs.length > 0 && pathText) {\n changes.derivedTextGlyphs = scaleDerivedGlyphs(glyphs, sx, sy)\n // Keep the layout/selection box in sync with the scaled glyphs. reflow\n // overrides this when it applies; this covers the fallback where reflow\n // returns null (no path data) so the box doesn't carry a stale size.\n if (orig.textPathBox) {\n changes.textPathBox = {\n x: orig.textPathBox.x * sx,\n y: orig.textPathBox.y * sy,\n width: orig.textPathBox.width * sx,\n height: orig.textPathBox.height * sy\n }\n }\n }\n // Glyphs scaled as a picture take their strokes along; any other stroke keeps its weight, as\n // Figma reports it, even where only a scaled outline can draw it.\n if (orig.strokes.length > 0 && glyphs.length > 0 && pathText) {\n changes.strokes = scaleStrokes(orig.strokes, sx, sy)\n }\n return changes\n}\n\nexport function collectResizeDescendants(\n graph: ResizeGraph,\n rootId: string\n): Map<string, ResizeSnapshot> | null {\n const root = graph.getNode(rootId)\n if (!root || !CONSTRAINT_CONTAINER_TYPES.has(root.type)) return null\n const snapshots = new Map<string, ResizeSnapshot>()\n\n const collect = (parentId: string) => {\n const parent = graph.getNode(parentId)\n if (!parent) return\n for (const childId of parent.childIds) {\n const child = graph.getNode(childId)\n if (!child) continue\n snapshots.set(childId, createResizeSnapshot(child))\n collect(childId)\n }\n }\n\n collect(rootId)\n return snapshots.size > 0 ? snapshots : null\n}\n\nexport function computeConstrainedResizeChanges(\n graph: ResizeGraph,\n rootId: string,\n rootBefore: Pick<Rect, 'width' | 'height'>,\n rootAfter: Pick<Rect, 'width' | 'height'>,\n originals: ReadonlyMap<string, ResizeSnapshot>\n): Map<string, Partial<SceneNode>> {\n const changes = new Map<string, Partial<SceneNode>>()\n\n const compute = (\n parentId: string,\n parentBefore: Pick<Rect, 'width' | 'height'>,\n parentAfter: Pick<Rect, 'width' | 'height'>\n ) => {\n const parent = graph.getNode(parentId)\n if (!parent) return\n const scalesChildren = parent.type === 'GROUP' || parent.type === 'BOOLEAN_OPERATION'\n for (const childId of parent.childIds) {\n const original = originals.get(childId)\n const child = graph.getNode(childId)\n if (!original || !child) continue\n const isInFlow = parent.layoutMode !== 'NONE' && child.layoutPositioning !== 'ABSOLUTE'\n if (isInFlow) {\n compute(childId, original, child)\n continue\n }\n const rect = scalesChildren\n ? scaledChildRect(original, parentBefore, parentAfter)\n : constrainedChildRect(\n original,\n parentBefore,\n parentAfter,\n child.horizontalConstraint,\n child.verticalConstraint,\n enforcedAspectRatio(child)\n )\n const childChanges: Partial<SceneNode> = {\n ...rect,\n ...scaledGeometryChanges(original, original.width, original.height, rect.width, rect.height)\n }\n changes.set(childId, childChanges)\n // The final pass sees layout containers after Yoga has resolved HUG/FILL sizing.\n compute(childId, original, child.layoutMode === 'NONE' ? rect : child)\n }\n }\n\n compute(rootId, rootBefore, rootAfter)\n return changes\n}\n"],"mappings":";;;AAsCA,MAAM,6CAA6B,IAAI,IAAI;CACzC;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,SAAS,gBACP,UACA,MACA,cACA,aACA,YACoC;CACpC,MAAM,QAAQ,cAAc;CAC5B,IAAI,eAAe,OAAO,OAAO;EAAE,UAAU,WAAW;EAAO;CAAK;CACpE,IAAI,eAAe,UAAU,OAAO;EAAE,UAAU,WAAW,QAAQ;EAAG;CAAK;CAC3E,IAAI,eAAe,WAAW,OAAO;EAAE;EAAU,MAAM,KAAK,IAAI,GAAG,OAAO,KAAK;CAAE;CACjF,IAAI,eAAe,WAAW,eAAe,GAAG;EAC9C,MAAM,QAAQ,cAAc;EAC5B,OAAO;GAAE,UAAU,WAAW;GAAO,MAAM,KAAK,IAAI,GAAG,OAAO,KAAK;EAAE;CACvE;CACA,OAAO;EAAE;EAAU;CAAK;AAC1B;AAIA,MAAM,uCAAoD,IAAI,IAAI,CAAC,WAAW,OAAO,CAAC;;AAGtF,SAAS,eACP,QACA,MACA,YACe;CACf,IAAI,eAAe,OAAO,OAAO;EAAE,UAAU,OAAO,WAAW,OAAO,OAAO;EAAM;CAAK;CACxF,IAAI,eAAe,UAAU,OAAO;EAAE,UAAU,OAAO,YAAY,OAAO,OAAO,QAAQ;EAAG;CAAK;CACjG,OAA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AAM,eAAe,SAAS,OAAO,KAAK;EACvE;CACF;CAEA,QAAQ,QAAQ,YAAY,SAAS;CACrC,OAAO;AACT"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { SceneNode } from "../types.js";
|
|
2
|
+
//#region src/scaling/node.d.ts
|
|
3
|
+
declare function scaleNodeChanges(node: SceneNode, scale: number, scalePosition: boolean): Partial<SceneNode>;
|
|
4
|
+
//#endregion
|
|
5
|
+
export { scaleNodeChanges };
|
|
6
|
+
//# sourceMappingURL=node.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.d.ts","names":[],"sources":["../../src/scaling/node.ts"],"mappings":";;iBAiHgB,iBACd,MAAM,WACN,eACA,yBACC,QAAQ"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { scaledTextLength } from "../text/lengths.js";
|
|
2
|
+
import { cloneVectorNetwork, scaleGeometryPaths } from "../copy.js";
|
|
3
|
+
import { TEXT_PARAGRAPH_SPACING_FIELDS } from "../text/paragraphs.js";
|
|
4
|
+
//#region src/scaling/node.ts
|
|
5
|
+
function scaledOptional(value, scale) {
|
|
6
|
+
return value == null ? null : value * scale;
|
|
7
|
+
}
|
|
8
|
+
function scaledStrokes(strokes, scale) {
|
|
9
|
+
return strokes.map((stroke) => ({
|
|
10
|
+
...structuredClone(stroke),
|
|
11
|
+
weight: stroke.weight * scale,
|
|
12
|
+
dashPattern: stroke.dashPattern?.map((value) => value * scale)
|
|
13
|
+
}));
|
|
14
|
+
}
|
|
15
|
+
function scaledEffects(effects, scale) {
|
|
16
|
+
return effects.map((effect) => ({
|
|
17
|
+
...structuredClone(effect),
|
|
18
|
+
offset: {
|
|
19
|
+
x: effect.offset.x * scale,
|
|
20
|
+
y: effect.offset.y * scale
|
|
21
|
+
},
|
|
22
|
+
radius: effect.radius * scale,
|
|
23
|
+
spread: effect.spread * scale
|
|
24
|
+
}));
|
|
25
|
+
}
|
|
26
|
+
function scaledFills(fills, scale) {
|
|
27
|
+
return fills.map((fill) => ({
|
|
28
|
+
...structuredClone(fill),
|
|
29
|
+
scale: fill.scale == null ? void 0 : fill.scale * scale,
|
|
30
|
+
spacing: fill.spacing == null ? void 0 : fill.spacing * scale,
|
|
31
|
+
patternSpacing: fill.patternSpacing ? {
|
|
32
|
+
x: fill.patternSpacing.x * scale,
|
|
33
|
+
y: fill.patternSpacing.y * scale
|
|
34
|
+
} : void 0,
|
|
35
|
+
noiseSize: fill.noiseSize ? {
|
|
36
|
+
x: fill.noiseSize.x * scale,
|
|
37
|
+
y: fill.noiseSize.y * scale
|
|
38
|
+
} : void 0
|
|
39
|
+
}));
|
|
40
|
+
}
|
|
41
|
+
function scaledStyleRuns(styleRuns, scale) {
|
|
42
|
+
return styleRuns.map((run) => ({
|
|
43
|
+
...structuredClone(run),
|
|
44
|
+
style: {
|
|
45
|
+
...structuredClone(run.style),
|
|
46
|
+
fontSize: run.style.fontSize == null ? void 0 : run.style.fontSize * scale,
|
|
47
|
+
letterSpacing: run.style.letterSpacing && scaledTextLength(run.style.letterSpacing, scale),
|
|
48
|
+
lineHeight: run.style.lineHeight && scaledTextLength(run.style.lineHeight, scale),
|
|
49
|
+
textDecorationThickness: scaledOptional(run.style.textDecorationThickness ?? null, scale),
|
|
50
|
+
textUnderlineOffset: scaledOptional(run.style.textUnderlineOffset ?? null, scale)
|
|
51
|
+
}
|
|
52
|
+
}));
|
|
53
|
+
}
|
|
54
|
+
function scaledParagraphStyles(paragraphs, scale) {
|
|
55
|
+
return paragraphs.map((style) => {
|
|
56
|
+
const scaled = { ...style };
|
|
57
|
+
for (const field of TEXT_PARAGRAPH_SPACING_FIELDS) {
|
|
58
|
+
const value = style[field];
|
|
59
|
+
if (value !== void 0) scaled[field] = value * scale;
|
|
60
|
+
}
|
|
61
|
+
return scaled;
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
function scaledLayoutGrids(grids, scale) {
|
|
65
|
+
return grids.map((grid) => ({
|
|
66
|
+
...structuredClone(grid),
|
|
67
|
+
offset: grid.offset == null ? void 0 : grid.offset * scale,
|
|
68
|
+
sectionSize: grid.sectionSize == null ? void 0 : grid.sectionSize * scale,
|
|
69
|
+
gutterSize: grid.gutterSize == null ? void 0 : grid.gutterSize * scale
|
|
70
|
+
}));
|
|
71
|
+
}
|
|
72
|
+
function scaledGridTracks(tracks, scale) {
|
|
73
|
+
return tracks.map((track) => ({
|
|
74
|
+
...track,
|
|
75
|
+
value: track.sizing === "FIXED" ? track.value * scale : track.value
|
|
76
|
+
}));
|
|
77
|
+
}
|
|
78
|
+
function scaledVectorNetwork(node, scale) {
|
|
79
|
+
if (!node.vectorNetwork) return null;
|
|
80
|
+
const network = cloneVectorNetwork(node.vectorNetwork);
|
|
81
|
+
for (const vertex of network.vertices) {
|
|
82
|
+
vertex.x *= scale;
|
|
83
|
+
vertex.y *= scale;
|
|
84
|
+
}
|
|
85
|
+
for (const segment of network.segments) {
|
|
86
|
+
segment.tangentStart.x *= scale;
|
|
87
|
+
segment.tangentStart.y *= scale;
|
|
88
|
+
segment.tangentEnd.x *= scale;
|
|
89
|
+
segment.tangentEnd.y *= scale;
|
|
90
|
+
}
|
|
91
|
+
for (const region of network.regions) if (region.fills) region.fills = scaledFills(region.fills, scale);
|
|
92
|
+
return network;
|
|
93
|
+
}
|
|
94
|
+
function scaleNodeChanges(node, scale, scalePosition) {
|
|
95
|
+
return {
|
|
96
|
+
x: scalePosition ? node.x * scale : node.x,
|
|
97
|
+
y: scalePosition ? node.y * scale : node.y,
|
|
98
|
+
width: node.width * scale,
|
|
99
|
+
height: node.height * scale,
|
|
100
|
+
minWidth: scaledOptional(node.minWidth, scale),
|
|
101
|
+
maxWidth: scaledOptional(node.maxWidth, scale),
|
|
102
|
+
minHeight: scaledOptional(node.minHeight, scale),
|
|
103
|
+
maxHeight: scaledOptional(node.maxHeight, scale),
|
|
104
|
+
cornerRadius: node.cornerRadius * scale,
|
|
105
|
+
topLeftRadius: node.topLeftRadius * scale,
|
|
106
|
+
topRightRadius: node.topRightRadius * scale,
|
|
107
|
+
bottomRightRadius: node.bottomRightRadius * scale,
|
|
108
|
+
bottomLeftRadius: node.bottomLeftRadius * scale,
|
|
109
|
+
fontSize: node.fontSize * scale,
|
|
110
|
+
letterSpacing: scaledTextLength(node.letterSpacing, scale),
|
|
111
|
+
lineHeight: node.lineHeight && scaledTextLength(node.lineHeight, scale),
|
|
112
|
+
textDecorationThickness: scaledOptional(node.textDecorationThickness, scale),
|
|
113
|
+
textUnderlineOffset: scaledOptional(node.textUnderlineOffset, scale),
|
|
114
|
+
styleRuns: scaledStyleRuns(node.styleRuns, scale),
|
|
115
|
+
listSpacing: node.listSpacing * scale,
|
|
116
|
+
paragraphSpacing: node.paragraphSpacing * scale,
|
|
117
|
+
paragraphIndent: node.paragraphIndent * scale,
|
|
118
|
+
textParagraphs: scaledParagraphStyles(node.textParagraphs, scale),
|
|
119
|
+
itemSpacing: node.itemSpacing * scale,
|
|
120
|
+
counterAxisSpacing: node.counterAxisSpacing * scale,
|
|
121
|
+
paddingTop: node.paddingTop * scale,
|
|
122
|
+
paddingRight: node.paddingRight * scale,
|
|
123
|
+
paddingBottom: node.paddingBottom * scale,
|
|
124
|
+
paddingLeft: node.paddingLeft * scale,
|
|
125
|
+
gridColumnGap: node.gridColumnGap * scale,
|
|
126
|
+
gridRowGap: node.gridRowGap * scale,
|
|
127
|
+
gridTemplateColumns: scaledGridTracks(node.gridTemplateColumns, scale),
|
|
128
|
+
gridTemplateRows: scaledGridTracks(node.gridTemplateRows, scale),
|
|
129
|
+
strokes: scaledStrokes(node.strokes, scale),
|
|
130
|
+
strokeWeight: node.strokeWeight * scale,
|
|
131
|
+
dashPattern: node.dashPattern.map((value) => value * scale),
|
|
132
|
+
borderTopWeight: node.borderTopWeight * scale,
|
|
133
|
+
borderRightWeight: node.borderRightWeight * scale,
|
|
134
|
+
borderBottomWeight: node.borderBottomWeight * scale,
|
|
135
|
+
borderLeftWeight: node.borderLeftWeight * scale,
|
|
136
|
+
strokeMiterLimit: node.strokeMiterLimit,
|
|
137
|
+
effects: scaledEffects(node.effects, scale),
|
|
138
|
+
fills: scaledFills(node.fills, scale),
|
|
139
|
+
layoutGrids: scaledLayoutGrids(node.layoutGrids, scale),
|
|
140
|
+
vectorNetwork: scaledVectorNetwork(node, scale),
|
|
141
|
+
fillGeometry: scaleGeometryPaths(node.fillGeometry, scale, scale),
|
|
142
|
+
strokeGeometry: scaleGeometryPaths(node.strokeGeometry, scale, scale)
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
//#endregion
|
|
146
|
+
export { scaleNodeChanges };
|
|
147
|
+
|
|
148
|
+
//# sourceMappingURL=node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.js","names":[],"sources":["../../src/scaling/node.ts"],"sourcesContent":["import { cloneVectorNetwork, scaleGeometryPaths } from '../copy'\nimport { scaledTextLength } from '../text/lengths'\nimport { TEXT_PARAGRAPH_SPACING_FIELDS } from '../text/paragraphs'\nimport {\n type Effect,\n type Fill,\n type GridTrack,\n type LayoutGrid,\n type SceneNode,\n type Stroke,\n type StyleRun,\n type TextParagraphStyle\n} from '../types'\n\nfunction scaledOptional(value: number | null, scale: number): number | null {\n return value == null ? null : value * scale\n}\n\nfunction scaledStrokes(strokes: readonly Stroke[], scale: number): Stroke[] {\n return strokes.map((stroke) => ({\n ...structuredClone(stroke),\n weight: stroke.weight * scale,\n dashPattern: stroke.dashPattern?.map((value) => value * scale)\n }))\n}\n\nfunction scaledEffects(effects: readonly Effect[], scale: number): Effect[] {\n return effects.map((effect) => ({\n ...structuredClone(effect),\n offset: { x: effect.offset.x * scale, y: effect.offset.y * scale },\n radius: effect.radius * scale,\n spread: effect.spread * scale\n }))\n}\n\nfunction scaledFills(fills: readonly Fill[], scale: number): Fill[] {\n return fills.map((fill) => ({\n ...structuredClone(fill),\n scale: fill.scale == null ? undefined : fill.scale * scale,\n spacing: fill.spacing == null ? undefined : fill.spacing * scale,\n patternSpacing: fill.patternSpacing\n ? { x: fill.patternSpacing.x * scale, y: fill.patternSpacing.y * scale }\n : undefined,\n noiseSize: fill.noiseSize\n ? { x: fill.noiseSize.x * scale, y: fill.noiseSize.y * scale }\n : undefined\n }))\n}\n\nfunction scaledStyleRuns(styleRuns: readonly StyleRun[], scale: number): StyleRun[] {\n return styleRuns.map((run) => ({\n ...structuredClone(run),\n style: {\n ...structuredClone(run.style),\n fontSize: run.style.fontSize == null ? undefined : run.style.fontSize * scale,\n letterSpacing: run.style.letterSpacing && scaledTextLength(run.style.letterSpacing, scale),\n lineHeight: run.style.lineHeight && scaledTextLength(run.style.lineHeight, scale),\n textDecorationThickness: scaledOptional(run.style.textDecorationThickness ?? null, scale),\n textUnderlineOffset: scaledOptional(run.style.textUnderlineOffset ?? null, scale)\n }\n }))\n}\n\nfunction scaledParagraphStyles(\n paragraphs: readonly TextParagraphStyle[],\n scale: number\n): TextParagraphStyle[] {\n return paragraphs.map((style) => {\n const scaled = { ...style }\n for (const field of TEXT_PARAGRAPH_SPACING_FIELDS) {\n const value = style[field]\n if (value !== undefined) scaled[field] = value * scale\n }\n return scaled\n })\n}\n\nfunction scaledLayoutGrids(grids: readonly LayoutGrid[], scale: number): LayoutGrid[] {\n return grids.map((grid) => ({\n ...structuredClone(grid),\n offset: grid.offset == null ? undefined : grid.offset * scale,\n sectionSize: grid.sectionSize == null ? undefined : grid.sectionSize * scale,\n gutterSize: grid.gutterSize == null ? undefined : grid.gutterSize * scale\n }))\n}\n\nfunction scaledGridTracks(tracks: readonly GridTrack[], scale: number): GridTrack[] {\n return tracks.map((track) => ({\n ...track,\n value: track.sizing === 'FIXED' ? track.value * scale : track.value\n }))\n}\n\nfunction scaledVectorNetwork(node: SceneNode, scale: number): SceneNode['vectorNetwork'] {\n if (!node.vectorNetwork) return null\n const network = cloneVectorNetwork(node.vectorNetwork)\n for (const vertex of network.vertices) {\n vertex.x *= scale\n vertex.y *= scale\n }\n for (const segment of network.segments) {\n segment.tangentStart.x *= scale\n segment.tangentStart.y *= scale\n segment.tangentEnd.x *= scale\n segment.tangentEnd.y *= scale\n }\n // A region's own paints scale as the layer's do.\n for (const region of network.regions) {\n if (region.fills) region.fills = scaledFills(region.fills, scale)\n }\n return network\n}\n\nexport function scaleNodeChanges(\n node: SceneNode,\n scale: number,\n scalePosition: boolean\n): Partial<SceneNode> {\n return {\n x: scalePosition ? node.x * scale : node.x,\n y: scalePosition ? node.y * scale : node.y,\n width: node.width * scale,\n height: node.height * scale,\n minWidth: scaledOptional(node.minWidth, scale),\n maxWidth: scaledOptional(node.maxWidth, scale),\n minHeight: scaledOptional(node.minHeight, scale),\n maxHeight: scaledOptional(node.maxHeight, scale),\n cornerRadius: node.cornerRadius * scale,\n topLeftRadius: node.topLeftRadius * scale,\n topRightRadius: node.topRightRadius * scale,\n bottomRightRadius: node.bottomRightRadius * scale,\n bottomLeftRadius: node.bottomLeftRadius * scale,\n fontSize: node.fontSize * scale,\n letterSpacing: scaledTextLength(node.letterSpacing, scale),\n lineHeight: node.lineHeight && scaledTextLength(node.lineHeight, scale),\n textDecorationThickness: scaledOptional(node.textDecorationThickness, scale),\n textUnderlineOffset: scaledOptional(node.textUnderlineOffset, scale),\n styleRuns: scaledStyleRuns(node.styleRuns, scale),\n listSpacing: node.listSpacing * scale,\n paragraphSpacing: node.paragraphSpacing * scale,\n paragraphIndent: node.paragraphIndent * scale,\n textParagraphs: scaledParagraphStyles(node.textParagraphs, scale),\n itemSpacing: node.itemSpacing * scale,\n counterAxisSpacing: node.counterAxisSpacing * scale,\n paddingTop: node.paddingTop * scale,\n paddingRight: node.paddingRight * scale,\n paddingBottom: node.paddingBottom * scale,\n paddingLeft: node.paddingLeft * scale,\n gridColumnGap: node.gridColumnGap * scale,\n gridRowGap: node.gridRowGap * scale,\n gridTemplateColumns: scaledGridTracks(node.gridTemplateColumns, scale),\n gridTemplateRows: scaledGridTracks(node.gridTemplateRows, scale),\n strokes: scaledStrokes(node.strokes, scale),\n strokeWeight: node.strokeWeight * scale,\n dashPattern: node.dashPattern.map((value) => value * scale),\n borderTopWeight: node.borderTopWeight * scale,\n borderRightWeight: node.borderRightWeight * scale,\n borderBottomWeight: node.borderBottomWeight * scale,\n borderLeftWeight: node.borderLeftWeight * scale,\n strokeMiterLimit: node.strokeMiterLimit,\n effects: scaledEffects(node.effects, scale),\n fills: scaledFills(node.fills, scale),\n layoutGrids: scaledLayoutGrids(node.layoutGrids, scale),\n vectorNetwork: scaledVectorNetwork(node, scale),\n fillGeometry: scaleGeometryPaths(node.fillGeometry, scale, scale),\n strokeGeometry: scaleGeometryPaths(node.strokeGeometry, scale, scale)\n }\n}\n"],"mappings":";;;;AAcA,SAAS,eAAe,OAAsB,OAA8B;CAC1E,OAAO,SAAS,OAAO,OAAO,QAAQ;AACxC;AAEA,SAAS,cAAc,SAA4B,OAAyB;CAC1E,OAAO,QAAQ,KAAK,YAAY;EAC9B,GAAG,gBAAgB,MAAM;EACzB,QAAQ,OAAO,SAAS;EACxB,aAAa,OAAO,aAAa,KAAK,UAAU,QAAQ,KAAK;CAC/D,EAAE;AACJ;AAEA,SAAS,cAAc,SAA4B,OAAyB;CAC1E,OAAO,QAAQ,KAAK,YAAY;EAC9B,GAAG,gBAAgB,MAAM;EACzB,QAAQ;GAAE,GAAG,OAAO,OAAO,IAAI;GAAO,GAAG,OAAO,OAAO,IAAI;EAAM;EACjE,QAAQ,OAAO,SAAS;EACxB,QAAQ,OAAO,SAAS;CAC1B,EAAE;AACJ;AAEA,SAAS,YAAY,OAAwB,OAAuB;CAClE,OAAO,MAAM,KAAK,UAAU;EAC1B,GAAG,gBAAgB,IAAI;EACvB,OAAO,KAAK,SAAS,OAAO,KAAA,IAAY,KAAK,QAAQ;EACrD,SAAS,KAAK,WAAW,OAAO,KAAA,IAAY,KAAK,UAAU;EAC3D,gBAAgB,KAAK,iBACjB;GAAE,GAAG,KAAK,eAAe,IAAI;GAAO,GAAG,KAAK,eAAe,IAAI;EAAM,IACrE,KAAA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AAiB,KAAK,kBAAkB;EACxC,gBAAgB,sBAAsB,KAAK,gBAAgB,KAAK;EAChE,aAAa,KAAK,cAAc;EAChC,oBAAoB,KAAK,qBAAqB;EAC9C,YAAY,KAAK,aAAa;EAC9B,cAAc,KAAK,eAAe;EAClC,eAAe,KAAK,gBAAgB;EACpC,aAAa,KAAK,cAAc;EAChC,eAAe,KAAK,gBAAgB;EACpC,YAAY,KAAK,aAAa;EAC9B,qBAAqB,iBAAiB,KAAK,qBAAqB,KAAK;EACrE,kBAAkB,iBAAiB,KAAK,kBAAkB,KAAK;EAC/D,SAAS,cAAc,KAAK,SAAS,KAAK;EAC1C,cAAc,KAAK,eAAe;EAClC,aAAa,KAAK,YAAY,KAAK,UAAU,QAAQ,KAAK;EAC1D,iBAAiB,KAAK,kBAAkB;EACxC,mBAAmB,KAAK,oBAAoB;EAC5C,oBAAoB,KAAK,qBAAqB;EAC9C,kBAAkB,KAAK,mBAAmB;EAC1C,kBAAkB,KAAK;EACvB,SAAS,cAAc,KAAK,SAAS,KAAK;EAC1C,OAAO,YAAY,KAAK,OAAO,KAAK;EACpC,aAAa,kBAAkB,KAAK,aAAa,KAAK;EACtD,eAAe,oBAAoB,MAAM,KAAK;EAC9C,cAAc,mBAAmB,KAAK,cAAc,OAAO,KAAK;EAChE,gBAAgB,mBAAmB,KAAK,gBAAgB,OAAO,KAAK;CACtE;AACF"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { SceneGraph } from "../graph.js";
|
|
2
|
+
//#region src/scaling/tree.d.ts
|
|
3
|
+
/** Scale a node tree from the root node's top-left, matching Figma's Scale tool. */
|
|
4
|
+
declare function rescaleNodeTree(graph: SceneGraph, rootId: string, scale: number): void;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { rescaleNodeTree };
|
|
7
|
+
//# sourceMappingURL=tree.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tree.d.ts","names":[],"sources":["../../src/scaling/tree.ts"],"mappings":";;;iBAyBgB,gBAAgB,OAAO,YAAY,gBAAgB"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { scaleNodeChanges } from "./node.js";
|
|
2
|
+
import { scaleVariableBindingUnits } from "../variables/units.js";
|
|
3
|
+
import { findInstanceAncestor } from "../instances/index.js";
|
|
4
|
+
//#region src/scaling/tree.ts
|
|
5
|
+
const MIN_SCALE = .01;
|
|
6
|
+
const RESCALABLE_NODE_TYPES = /* @__PURE__ */ new Set([
|
|
7
|
+
"BOOLEAN_OPERATION",
|
|
8
|
+
"COMPONENT",
|
|
9
|
+
"COMPONENT_SET",
|
|
10
|
+
"ELLIPSE",
|
|
11
|
+
"FRAME",
|
|
12
|
+
"GROUP",
|
|
13
|
+
"INSTANCE",
|
|
14
|
+
"LINE",
|
|
15
|
+
"POLYGON",
|
|
16
|
+
"RECTANGLE",
|
|
17
|
+
"STAR",
|
|
18
|
+
"STICKY",
|
|
19
|
+
"TEXT",
|
|
20
|
+
"VECTOR"
|
|
21
|
+
]);
|
|
22
|
+
/** Scale a node tree from the root node's top-left, matching Figma's Scale tool. */
|
|
23
|
+
function rescaleNodeTree(graph, rootId, scale) {
|
|
24
|
+
if (!Number.isFinite(scale)) throw new TypeError("Scale must be a finite number");
|
|
25
|
+
if (scale < MIN_SCALE) throw new RangeError(`Scale must be at least ${MIN_SCALE}`);
|
|
26
|
+
const root = graph.getNode(rootId);
|
|
27
|
+
if (!root || !RESCALABLE_NODE_TYPES.has(root.type)) throw new Error("rescale() is not supported on this node");
|
|
28
|
+
const nodes = [root];
|
|
29
|
+
const collect = (node) => {
|
|
30
|
+
for (const childId of node.childIds) {
|
|
31
|
+
const child = graph.getNode(childId);
|
|
32
|
+
if (!child) continue;
|
|
33
|
+
nodes.push(child);
|
|
34
|
+
collect(child);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
collect(root);
|
|
38
|
+
for (const node of nodes) graph.updateNode(node.id, {
|
|
39
|
+
...scaleNodeChanges(node, scale, node.id !== rootId),
|
|
40
|
+
...scaleVariableBindingUnits(node, scale),
|
|
41
|
+
componentScale: findInstanceAncestor(graph, node.id) ? node.componentScale * scale : node.componentScale
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
export { rescaleNodeTree };
|
|
46
|
+
|
|
47
|
+
//# sourceMappingURL=tree.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tree.js","names":[],"sources":["../../src/scaling/tree.ts"],"sourcesContent":["import type { SceneGraph } from '../graph'\nimport { findInstanceAncestor } from '../instances'\nimport type { SceneNode } from '../types'\nimport { scaleVariableBindingUnits } from '../variables/units'\nimport { scaleNodeChanges } from './node'\n\nconst MIN_SCALE = 0.01\nconst RESCALABLE_NODE_TYPES = new Set<SceneNode['type']>([\n 'BOOLEAN_OPERATION',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'ELLIPSE',\n 'FRAME',\n 'GROUP',\n 'INSTANCE',\n 'LINE',\n 'POLYGON',\n 'RECTANGLE',\n 'STAR',\n 'STICKY',\n 'TEXT',\n 'VECTOR'\n])\n\n/** Scale a node tree from the root node's top-left, matching Figma's Scale tool. */\nexport function rescaleNodeTree(graph: SceneGraph, rootId: string, scale: number): void {\n if (!Number.isFinite(scale)) throw new TypeError('Scale must be a finite number')\n if (scale < MIN_SCALE) throw new RangeError(`Scale must be at least ${MIN_SCALE}`)\n const root = graph.getNode(rootId)\n if (!root || !RESCALABLE_NODE_TYPES.has(root.type))\n throw new Error('rescale() is not supported on this node')\n const nodes: SceneNode[] = [root]\n const collect = (node: SceneNode): void => {\n for (const childId of node.childIds) {\n const child = graph.getNode(childId)\n if (!child) continue\n nodes.push(child)\n collect(child)\n }\n }\n collect(root)\n for (const node of nodes) {\n graph.updateNode(node.id, {\n ...scaleNodeChanges(node, scale, node.id !== rootId),\n ...scaleVariableBindingUnits(node, scale),\n componentScale: findInstanceAncestor(graph, node.id)\n ? node.componentScale * scale\n : node.componentScale\n })\n }\n}\n"],"mappings":";;;;AAMA,MAAM,YAAY;AAClB,MAAM,wCAAwB,IAAI,IAAuB;CACvD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;;AAGD,SAAgB,gBAAgB,OAAmB,QAAgB,OAAqB;CACtF,IAAI,CAAC,OAAO,SAAS,KAAK,GAAG,MAAM,IAAI,UAAU,+BAA+B;CAChF,IAAI,QAAQ,WAAW,MAAM,IAAI,WAAW,0BAA0B,WAAW;CACjF,MAAM,OAAO,MAAM,QAAQ,MAAM;CACjC,IAAI,CAAC,QAAQ,CAAC,sBAAsB,IAAI,KAAK,IAAI,GAC/C,MAAM,IAAI,MAAM,yCAAyC;CAC3D,MAAM,QAAqB,CAAC,IAAI;CAChC,MAAM,WAAW,SAA0B;EACzC,KAAK,MAAM,WAAW,KAAK,UAAU;GACnC,MAAM,QAAQ,MAAM,QAAQ,OAAO;GACnC,IAAI,CAAC,OAAO;GACZ,MAAM,KAAK,KAAK;GAChB,QAAQ,KAAK;EACf;CACF;CACA,QAAQ,IAAI;CACZ,KAAK,MAAM,QAAQ,OACjB,MAAM,WAAW,KAAK,IAAI;EACxB,GAAG,iBAAiB,MAAM,OAAO,KAAK,OAAO,MAAM;EACnD,GAAG,0BAA0B,MAAM,KAAK;EACxC,gBAAgB,qBAAqB,OAAO,KAAK,EAAE,IAC/C,KAAK,iBAAiB,QACtB,KAAK;CACX,CAAC;AAEL"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ShaderComponent, ShaderPaint, ShaderPreset, shaderPaintSchema, shaderPresetSchema } from "./schema.js";
|
|
2
|
+
import { createShaderPaint, hasShaderPaint, isShaderFrameCurrent, readShaderPaints, shaderOfPaint, shaderPresetKey, withShaderPaints } from "./model.js";
|
|
3
|
+
import { ShaderFrameEncoding, shaderFrameEncoding, shaderFramePixels } from "./still.js";
|
|
4
|
+
export { ShaderComponent, ShaderFrameEncoding, ShaderPaint, ShaderPreset, createShaderPaint, hasShaderPaint, isShaderFrameCurrent, readShaderPaints, shaderFrameEncoding, shaderFramePixels, shaderOfPaint, shaderPaintSchema, shaderPresetKey, shaderPresetSchema, withShaderPaints };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { shaderPaintSchema, shaderPresetSchema } from "./schema.js";
|
|
2
|
+
import { createShaderPaint, hasShaderPaint, isShaderFrameCurrent, readShaderPaints, shaderOfPaint, shaderPresetKey, withShaderPaints } from "./model.js";
|
|
3
|
+
import { shaderFrameEncoding, shaderFramePixels } from "./still.js";
|
|
4
|
+
export { createShaderPaint, hasShaderPaint, isShaderFrameCurrent, readShaderPaints, shaderFrameEncoding, shaderFramePixels, shaderOfPaint, shaderPaintSchema, shaderPresetKey, shaderPresetSchema, withShaderPaints };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Fill, SceneNode } from "../types.js";
|
|
2
|
+
import { ShaderPaint, ShaderPreset } from "./schema.js";
|
|
3
|
+
//#region src/shaders/model.d.ts
|
|
4
|
+
/** What shader paints read of a node. */
|
|
5
|
+
type ShaderNode = Pick<SceneNode, 'fills' | 'strokes' | 'pluginData'>;
|
|
6
|
+
/** Every shader a node's fills and strokes draw, whether or not a paint still shows it. */
|
|
7
|
+
declare function readShaderPaints(node: Pick<SceneNode, 'pluginData'>): ShaderPaint[];
|
|
8
|
+
/**
|
|
9
|
+
* The shader a fill or stroke of `node` draws: an image paint whose image is a shader's frame.
|
|
10
|
+
* Null for any other paint, including one whose image was replaced, which then draws as the
|
|
11
|
+
* image it holds.
|
|
12
|
+
*/
|
|
13
|
+
declare function shaderOfPaint(node: Pick<SceneNode, 'pluginData'>, paint: Fill): ShaderPaint | null;
|
|
14
|
+
/** Whether any paint of `node` draws a shader. */
|
|
15
|
+
declare function hasShaderPaint(node: ShaderNode): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* The node's plugin data with `shaders` set by their image, keeping only shaders a fill or
|
|
18
|
+
* stroke of `paints` still shows, so removing or replacing a paint leaves no entry behind.
|
|
19
|
+
*/
|
|
20
|
+
declare function withShaderPaints(node: Pick<SceneNode, 'pluginData'>, paints: readonly Fill[], shaders?: readonly ShaderPaint[]): SceneNode['pluginData'];
|
|
21
|
+
/**
|
|
22
|
+
* A new paint that draws `preset`, and the shader entry it shows. Its image names a frame not yet
|
|
23
|
+
* rendered, unique to this paint, so no other paint's entry claims it until the frame is drawn.
|
|
24
|
+
*/
|
|
25
|
+
declare function createShaderPaint(preset: ShaderPreset): {
|
|
26
|
+
paint: Fill;
|
|
27
|
+
shader: ShaderPaint;
|
|
28
|
+
};
|
|
29
|
+
/** A short key that tells one preset from another, which a rendered frame records. */
|
|
30
|
+
declare function shaderPresetKey(preset: ShaderPreset): string;
|
|
31
|
+
/**
|
|
32
|
+
* Whether a shader's frame was rendered for its preset at the size `node` has now, so undoing a
|
|
33
|
+
* preset change after reopening the document does not keep a frame of the newer preset.
|
|
34
|
+
*/
|
|
35
|
+
declare function isShaderFrameCurrent(shader: ShaderPaint, size: {
|
|
36
|
+
width: number;
|
|
37
|
+
height: number;
|
|
38
|
+
}): boolean;
|
|
39
|
+
//#endregion
|
|
40
|
+
export { createShaderPaint, hasShaderPaint, isShaderFrameCurrent, readShaderPaints, shaderOfPaint, shaderPresetKey, withShaderPaints };
|
|
41
|
+
//# sourceMappingURL=model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.d.ts","names":[],"sources":["../../src/shaders/model.ts"],"mappings":";;;;KAWK,aAAa,KAAK;;iBAGP,iBAAiB,MAAM,KAAK,2BAA2B;;;;;;iBASvD,cACd,MAAM,KAAK,0BACX,OAAO,OACN;;iBAMa,eAAe,MAAM;;;;;iBAQrB,iBACd,MAAM,KAAK,0BACX,iBAAiB,QACjB,mBAAkB,gBACjB;;;;;iBAiBa,kBAAkB,QAAQ;EACxC,OAAO;EACP,QAAQ;;;iBAiBM,gBAAgB,QAAQ;;;;;iBAQxB,qBACd,QAAQ,aACR;EAAQ;EAAe"}
|