@pairdraw/scene-graph 0.0.0-stage → 0.16.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/LICENSE +21 -0
- package/README.md +4 -2
- package/dist/agent-notes/index.d.ts +3 -0
- package/dist/agent-notes/index.js +3 -0
- package/dist/agent-notes/model.d.ts +23 -0
- package/dist/agent-notes/model.d.ts.map +1 -0
- package/dist/agent-notes/model.js +36 -0
- package/dist/agent-notes/model.js.map +1 -0
- package/dist/agent-notes/schema.d.ts +19 -0
- package/dist/agent-notes/schema.d.ts.map +1 -0
- package/dist/agent-notes/schema.js +17 -0
- package/dist/agent-notes/schema.js.map +1 -0
- package/dist/arrow-caps.d.ts +65 -0
- package/dist/arrow-caps.d.ts.map +1 -0
- package/dist/arrow-caps.js +365 -0
- package/dist/arrow-caps.js.map +1 -0
- package/dist/asset-keys.d.ts +17 -0
- package/dist/asset-keys.d.ts.map +1 -0
- package/dist/asset-keys.js +27 -0
- package/dist/asset-keys.js.map +1 -0
- package/dist/behaviours/index.d.ts +6 -0
- package/dist/behaviours/index.js +6 -0
- package/dist/behaviours/kinds.d.ts +56 -0
- package/dist/behaviours/kinds.d.ts.map +1 -0
- package/dist/behaviours/kinds.js +273 -0
- package/dist/behaviours/kinds.js.map +1 -0
- package/dist/behaviours/layers.d.ts +16 -0
- package/dist/behaviours/layers.d.ts.map +1 -0
- package/dist/behaviours/layers.js +42 -0
- package/dist/behaviours/layers.js.map +1 -0
- package/dist/behaviours/model.d.ts +45 -0
- package/dist/behaviours/model.d.ts.map +1 -0
- package/dist/behaviours/model.js +149 -0
- package/dist/behaviours/model.js.map +1 -0
- package/dist/behaviours/schema.d.ts +114 -0
- package/dist/behaviours/schema.d.ts.map +1 -0
- package/dist/behaviours/schema.js +71 -0
- package/dist/behaviours/schema.js.map +1 -0
- package/dist/behaviours/spec.d.ts +26 -0
- package/dist/behaviours/spec.d.ts.map +1 -0
- package/dist/behaviours/spec.js +157 -0
- package/dist/behaviours/spec.js.map +1 -0
- package/dist/bindings.js +18 -0
- package/dist/bindings.js.map +1 -0
- package/dist/browser-node/index.d.ts +3 -0
- package/dist/browser-node/index.js +3 -0
- package/dist/browser-node/model.d.ts +18 -0
- package/dist/browser-node/model.d.ts.map +1 -0
- package/dist/browser-node/model.js +31 -0
- package/dist/browser-node/model.js.map +1 -0
- package/dist/browser-node/schema.d.ts +23 -0
- package/dist/browser-node/schema.d.ts.map +1 -0
- package/dist/browser-node/schema.js +44 -0
- package/dist/browser-node/schema.js.map +1 -0
- package/dist/buffered-events.d.ts +21 -0
- package/dist/buffered-events.d.ts.map +1 -0
- package/dist/buffered-events.js +57 -0
- package/dist/buffered-events.js.map +1 -0
- package/dist/checkpoint.d.ts +28 -0
- package/dist/checkpoint.d.ts.map +1 -0
- package/dist/checkpoint.js +246 -0
- package/dist/checkpoint.js.map +1 -0
- package/dist/clipping.d.ts +31 -0
- package/dist/clipping.d.ts.map +1 -0
- package/dist/clipping.js +125 -0
- package/dist/clipping.js.map +1 -0
- package/dist/color/contrast.d.ts +20 -0
- package/dist/color/contrast.d.ts.map +1 -0
- package/dist/color/contrast.js +69 -0
- package/dist/color/contrast.js.map +1 -0
- package/dist/color/index.d.ts +38 -0
- package/dist/color/index.d.ts.map +1 -0
- package/dist/color/index.js +110 -0
- package/dist/color/index.js.map +1 -0
- package/dist/color/management.d.ts +32 -0
- package/dist/color/management.d.ts.map +1 -0
- package/dist/color/management.js +187 -0
- package/dist/color/management.js.map +1 -0
- package/dist/color/normalize.d.ts +6 -0
- package/dist/color/normalize.d.ts.map +1 -0
- package/dist/color/normalize.js +15 -0
- package/dist/color/normalize.js.map +1 -0
- package/dist/color/okhcl.d.ts +33 -0
- package/dist/color/okhcl.d.ts.map +1 -0
- package/dist/color/okhcl.js +146 -0
- package/dist/color/okhcl.js.map +1 -0
- package/dist/color/schema.d.ts +11 -0
- package/dist/color/schema.d.ts.map +1 -0
- package/dist/color/schema.js +13 -0
- package/dist/color/schema.js.map +1 -0
- package/dist/comments/document.d.ts +23 -0
- package/dist/comments/document.d.ts.map +1 -0
- package/dist/comments/document.js +33 -0
- package/dist/comments/document.js.map +1 -0
- package/dist/comments/index.d.ts +6 -0
- package/dist/comments/index.js +6 -0
- package/dist/comments/list.d.ts +25 -0
- package/dist/comments/list.d.ts.map +1 -0
- package/dist/comments/list.js +33 -0
- package/dist/comments/list.js.map +1 -0
- package/dist/comments/merge.d.ts +16 -0
- package/dist/comments/merge.d.ts.map +1 -0
- package/dist/comments/merge.js +58 -0
- package/dist/comments/merge.js.map +1 -0
- package/dist/comments/schema.d.ts +8 -0
- package/dist/comments/schema.d.ts.map +1 -0
- package/dist/comments/schema.js +50 -0
- package/dist/comments/schema.js.map +1 -0
- package/dist/comments/threads.d.ts +59 -0
- package/dist/comments/threads.d.ts.map +1 -0
- package/dist/comments/threads.js +132 -0
- package/dist/comments/threads.js.map +1 -0
- package/dist/components/exposure.d.ts +24 -0
- package/dist/components/exposure.d.ts.map +1 -0
- package/dist/components/exposure.js +51 -0
- package/dist/components/exposure.js.map +1 -0
- package/dist/components/index.d.ts +5 -0
- package/dist/components/index.js +5 -0
- package/dist/components/library-page.d.ts +11 -0
- package/dist/components/library-page.d.ts.map +1 -0
- package/dist/components/library-page.js +21 -0
- package/dist/components/library-page.js.map +1 -0
- package/dist/components/properties.d.ts +20 -0
- package/dist/components/properties.d.ts.map +1 -0
- package/dist/components/properties.js +125 -0
- package/dist/components/properties.js.map +1 -0
- package/dist/components/variants.d.ts +27 -0
- package/dist/components/variants.d.ts.map +1 -0
- package/dist/components/variants.js +32 -0
- package/dist/components/variants.js.map +1 -0
- package/dist/connectors/controls.d.ts +34 -0
- package/dist/connectors/controls.d.ts.map +1 -0
- package/dist/connectors/controls.js +196 -0
- package/dist/connectors/controls.js.map +1 -0
- package/dist/connectors/create.d.ts +23 -0
- package/dist/connectors/create.d.ts.map +1 -0
- package/dist/connectors/create.js +33 -0
- package/dist/connectors/create.js.map +1 -0
- package/dist/connectors/elbow.js +191 -0
- package/dist/connectors/elbow.js.map +1 -0
- package/dist/connectors/gaps.d.ts +10 -0
- package/dist/connectors/gaps.d.ts.map +1 -0
- package/dist/connectors/gaps.js +86 -0
- package/dist/connectors/gaps.js.map +1 -0
- package/dist/connectors/hit.d.ts +11 -0
- package/dist/connectors/hit.d.ts.map +1 -0
- package/dist/connectors/hit.js +53 -0
- package/dist/connectors/hit.js.map +1 -0
- package/dist/connectors/index.d.ts +11 -0
- package/dist/connectors/index.js +11 -0
- package/dist/connectors/label.d.ts +32 -0
- package/dist/connectors/label.d.ts.map +1 -0
- package/dist/connectors/label.js +213 -0
- package/dist/connectors/label.js.map +1 -0
- package/dist/connectors/layout.d.ts +46 -0
- package/dist/connectors/layout.d.ts.map +1 -0
- package/dist/connectors/layout.js +234 -0
- package/dist/connectors/layout.js.map +1 -0
- package/dist/connectors/pieces.d.ts +22 -0
- package/dist/connectors/pieces.d.ts.map +1 -0
- package/dist/connectors/pieces.js +159 -0
- package/dist/connectors/pieces.js.map +1 -0
- package/dist/connectors/route.d.ts +23 -0
- package/dist/connectors/route.d.ts.map +1 -0
- package/dist/connectors/route.js +107 -0
- package/dist/connectors/route.js.map +1 -0
- package/dist/connectors/sides.d.ts +23 -0
- package/dist/connectors/sides.d.ts.map +1 -0
- package/dist/connectors/sides.js +98 -0
- package/dist/connectors/sides.js.map +1 -0
- package/dist/connectors/sublayers.d.ts +76 -0
- package/dist/connectors/sublayers.d.ts.map +1 -0
- package/dist/connectors/sublayers.js +209 -0
- package/dist/connectors/sublayers.js.map +1 -0
- package/dist/constants.d.ts +16 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +31 -0
- package/dist/constants.js.map +1 -0
- package/dist/coordinate.d.ts +99 -0
- package/dist/coordinate.d.ts.map +1 -0
- package/dist/coordinate.js +276 -0
- package/dist/coordinate.js.map +1 -0
- package/dist/copy.d.ts +45 -0
- package/dist/copy.d.ts.map +1 -0
- package/dist/copy.js +256 -0
- package/dist/copy.js.map +1 -0
- package/dist/css/grid.d.ts +7 -0
- package/dist/css/grid.d.ts.map +1 -0
- package/dist/css/grid.js +63 -0
- package/dist/css/grid.js.map +1 -0
- package/dist/css/index.d.ts +6 -0
- package/dist/css/index.js +6 -0
- package/dist/css/layout.d.ts +17 -0
- package/dist/css/layout.d.ts.map +1 -0
- package/dist/css/layout.js +45 -0
- package/dist/css/layout.js.map +1 -0
- package/dist/css/shadows.d.ts +10 -0
- package/dist/css/shadows.d.ts.map +1 -0
- package/dist/css/shadows.js +64 -0
- package/dist/css/shadows.js.map +1 -0
- package/dist/css/text.d.ts +22 -0
- package/dist/css/text.d.ts.map +1 -0
- package/dist/css/text.js +76 -0
- package/dist/css/text.js.map +1 -0
- package/dist/css/values.d.ts +14 -0
- package/dist/css/values.d.ts.map +1 -0
- package/dist/css/values.js +36 -0
- package/dist/css/values.js.map +1 -0
- package/dist/events.js +18 -0
- package/dist/events.js.map +1 -0
- package/dist/export-format.d.ts +19 -0
- package/dist/export-format.d.ts.map +1 -0
- package/dist/export-format.js +33 -0
- package/dist/export-format.js.map +1 -0
- package/dist/export-scale.d.ts +14 -0
- package/dist/export-scale.d.ts.map +1 -0
- package/dist/export-scale.js +19 -0
- package/dist/export-scale.js.map +1 -0
- package/dist/fields/appearance.d.ts +9 -0
- package/dist/fields/appearance.d.ts.map +1 -0
- package/dist/fields/appearance.js +36 -0
- package/dist/fields/appearance.js.map +1 -0
- package/dist/fields/geometry.d.ts +7 -0
- package/dist/fields/geometry.d.ts.map +1 -0
- package/dist/fields/geometry.js +14 -0
- package/dist/fields/geometry.js.map +1 -0
- package/dist/fields/index.d.ts +5 -0
- package/dist/fields/index.js +5 -0
- package/dist/fields/layout.d.ts +10 -0
- package/dist/fields/layout.d.ts.map +1 -0
- package/dist/fields/layout.js +49 -0
- package/dist/fields/layout.js.map +1 -0
- package/dist/fields/text.d.ts +11 -0
- package/dist/fields/text.d.ts.map +1 -0
- package/dist/fields/text.js +63 -0
- package/dist/fields/text.js.map +1 -0
- package/dist/fig-compression.d.ts +11 -0
- package/dist/fig-compression.d.ts.map +1 -0
- package/dist/fig-compression.js +15 -0
- package/dist/fig-compression.js.map +1 -0
- package/dist/figjam/index.d.ts +3 -0
- package/dist/figjam/index.js +3 -0
- package/dist/figjam/palette.d.ts +199 -0
- package/dist/figjam/palette.d.ts.map +1 -0
- package/dist/figjam/palette.js +277 -0
- package/dist/figjam/palette.js.map +1 -0
- package/dist/figjam/text.d.ts +68 -0
- package/dist/figjam/text.d.ts.map +1 -0
- package/dist/figjam/text.js +89 -0
- package/dist/figjam/text.js.map +1 -0
- package/dist/font-style.d.ts +46 -0
- package/dist/font-style.d.ts.map +1 -0
- package/dist/font-style.js +127 -0
- package/dist/font-style.js.map +1 -0
- package/dist/generated/index.d.ts +46 -0
- package/dist/generated/index.d.ts.map +1 -0
- package/dist/generated/index.js +62 -0
- package/dist/generated/index.js.map +1 -0
- package/dist/generated/kind.d.ts +29 -0
- package/dist/generated/kind.d.ts.map +1 -0
- package/dist/generated/shape-with-text.d.ts +38 -0
- package/dist/generated/shape-with-text.d.ts.map +1 -0
- package/dist/generated/shape-with-text.js +119 -0
- package/dist/generated/shape-with-text.js.map +1 -0
- package/dist/generated/sticky.d.ts +128 -0
- package/dist/generated/sticky.d.ts.map +1 -0
- package/dist/generated/sticky.js +234 -0
- package/dist/generated/sticky.js.map +1 -0
- package/dist/geometry.d.ts +105 -0
- package/dist/geometry.d.ts.map +1 -0
- package/dist/geometry.js +374 -0
- package/dist/geometry.js.map +1 -0
- package/dist/gradient.d.ts +74 -0
- package/dist/gradient.d.ts.map +1 -0
- package/dist/gradient.js +211 -0
- package/dist/gradient.js.map +1 -0
- package/dist/graph.d.ts +186 -0
- package/dist/graph.d.ts.map +1 -0
- package/dist/graph.js +630 -0
- package/dist/graph.js.map +1 -0
- package/dist/group-bounds.d.ts +42 -0
- package/dist/group-bounds.d.ts.map +1 -0
- package/dist/group-bounds.js +146 -0
- package/dist/group-bounds.js.map +1 -0
- package/dist/guides.d.ts +19 -0
- package/dist/guides.d.ts.map +1 -0
- package/dist/guides.js +39 -0
- package/dist/guides.js.map +1 -0
- package/dist/hit-test.d.ts +49 -0
- package/dist/hit-test.d.ts.map +1 -0
- package/dist/hit-test.js +315 -0
- package/dist/hit-test.js.map +1 -0
- package/dist/icons/glyph.d.ts +22 -0
- package/dist/icons/glyph.d.ts.map +1 -0
- package/dist/icons/glyph.js +109 -0
- package/dist/icons/glyph.js.map +1 -0
- package/dist/icons/index.d.ts +4 -0
- package/dist/icons/index.js +4 -0
- package/dist/icons/model.d.ts +29 -0
- package/dist/icons/model.d.ts.map +1 -0
- package/dist/icons/model.js +51 -0
- package/dist/icons/model.js.map +1 -0
- package/dist/icons/schema.d.ts +31 -0
- package/dist/icons/schema.d.ts.map +1 -0
- package/dist/icons/schema.js +28 -0
- package/dist/icons/schema.js.map +1 -0
- package/dist/ids.d.ts +12 -0
- package/dist/ids.d.ts.map +1 -0
- package/dist/ids.js +31 -0
- package/dist/ids.js.map +1 -0
- package/dist/images.d.ts +39 -0
- package/dist/images.d.ts.map +1 -0
- package/dist/images.js +85 -0
- package/dist/images.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/instances/assignments.js +89 -0
- package/dist/instances/assignments.js.map +1 -0
- package/dist/instances/content-size.js +60 -0
- package/dist/instances/content-size.js.map +1 -0
- package/dist/instances/copies.js +162 -0
- package/dist/instances/copies.js.map +1 -0
- package/dist/instances/cycles.d.ts +20 -0
- package/dist/instances/cycles.d.ts.map +1 -0
- package/dist/instances/cycles.js +53 -0
- package/dist/instances/cycles.js.map +1 -0
- package/dist/instances/fields.d.ts +18 -0
- package/dist/instances/fields.d.ts.map +1 -0
- package/dist/instances/fields.js +82 -0
- package/dist/instances/fields.js.map +1 -0
- package/dist/instances/index.d.ts +63 -0
- package/dist/instances/index.d.ts.map +1 -0
- package/dist/instances/index.js +305 -0
- package/dist/instances/index.js.map +1 -0
- package/dist/instances/main-component.d.ts +11 -0
- package/dist/instances/main-component.d.ts.map +1 -0
- package/dist/instances/main-component.js +42 -0
- package/dist/instances/main-component.js.map +1 -0
- package/dist/instances/modes.js +26 -0
- package/dist/instances/modes.js.map +1 -0
- package/dist/instances/overrides.d.ts +63 -0
- package/dist/instances/overrides.d.ts.map +1 -0
- package/dist/instances/overrides.js +164 -0
- package/dist/instances/overrides.js.map +1 -0
- package/dist/instances/placement.js +30 -0
- package/dist/instances/placement.js.map +1 -0
- package/dist/instances/replacements.d.ts +19 -0
- package/dist/instances/replacements.d.ts.map +1 -0
- package/dist/instances/replacements.js +67 -0
- package/dist/instances/replacements.js.map +1 -0
- package/dist/instances/source-walk.js +31 -0
- package/dist/instances/source-walk.js.map +1 -0
- package/dist/instances/sync.js +305 -0
- package/dist/instances/sync.js.map +1 -0
- package/dist/instances/vector-geometry.js +70 -0
- package/dist/instances/vector-geometry.js.map +1 -0
- package/dist/layout/aspect-ratio.d.ts +27 -0
- package/dist/layout/aspect-ratio.d.ts.map +1 -0
- package/dist/layout/aspect-ratio.js +45 -0
- package/dist/layout/aspect-ratio.js.map +1 -0
- package/dist/layout/guides.d.ts +25 -0
- package/dist/layout/guides.d.ts.map +1 -0
- package/dist/layout/guides.js +105 -0
- package/dist/layout/guides.js.map +1 -0
- package/dist/layout/index.d.ts +5 -0
- package/dist/layout/index.js +5 -0
- package/dist/layout/keywords.d.ts +26 -0
- package/dist/layout/keywords.d.ts.map +1 -0
- package/dist/layout/keywords.js +60 -0
- package/dist/layout/keywords.js.map +1 -0
- package/dist/layout/sizing.d.ts +40 -0
- package/dist/layout/sizing.d.ts.map +1 -0
- package/dist/layout/sizing.js +122 -0
- package/dist/layout/sizing.js.map +1 -0
- package/dist/layout/writes.js +55 -0
- package/dist/layout/writes.js.map +1 -0
- package/dist/matrix.d.ts +16 -0
- package/dist/matrix.d.ts.map +1 -0
- package/dist/matrix.js +120 -0
- package/dist/matrix.js.map +1 -0
- package/dist/mutation-impact.d.ts +23 -0
- package/dist/mutation-impact.d.ts.map +1 -0
- package/dist/mutation-impact.js +67 -0
- package/dist/mutation-impact.js.map +1 -0
- package/dist/naming.d.ts +9 -0
- package/dist/naming.d.ts.map +1 -0
- package/dist/naming.js +16 -0
- package/dist/naming.js.map +1 -0
- package/dist/node-defaults.d.ts +19 -0
- package/dist/node-defaults.d.ts.map +1 -0
- package/dist/node-defaults.js +243 -0
- package/dist/node-defaults.js.map +1 -0
- package/dist/order-keys.d.ts +39 -0
- package/dist/order-keys.d.ts.map +1 -0
- package/dist/order-keys.js +136 -0
- package/dist/order-keys.js.map +1 -0
- package/dist/paints/index.d.ts +2 -0
- package/dist/paints/index.js +2 -0
- package/dist/paints/schema.d.ts +103 -0
- package/dist/paints/schema.d.ts.map +1 -0
- package/dist/paints/schema.js +64 -0
- package/dist/paints/schema.js.map +1 -0
- package/dist/parse-path.d.ts +36 -0
- package/dist/parse-path.d.ts.map +1 -0
- package/dist/parse-path.js +200 -0
- package/dist/parse-path.js.map +1 -0
- package/dist/plugin-data/citation.d.ts +13 -0
- package/dist/plugin-data/citation.d.ts.map +1 -0
- package/dist/plugin-data/citation.js +23 -0
- package/dist/plugin-data/citation.js.map +1 -0
- package/dist/plugin-data/field.d.ts +47 -0
- package/dist/plugin-data/field.d.ts.map +1 -0
- package/dist/plugin-data/field.js +79 -0
- package/dist/plugin-data/field.js.map +1 -0
- package/dist/plugin-data/fields.d.ts +220 -0
- package/dist/plugin-data/fields.d.ts.map +1 -0
- package/dist/plugin-data/fields.js +214 -0
- package/dist/plugin-data/fields.js.map +1 -0
- package/dist/plugin-data/index.d.ts +5 -0
- package/dist/plugin-data/index.js +5 -0
- package/dist/plugin-data/schema.d.ts +18 -0
- package/dist/plugin-data/schema.d.ts.map +1 -0
- package/dist/plugin-data/schema.js +29 -0
- package/dist/plugin-data/schema.js.map +1 -0
- package/dist/polygon.d.ts +55 -0
- package/dist/polygon.d.ts.map +1 -0
- package/dist/polygon.js +220 -0
- package/dist/polygon.js.map +1 -0
- package/dist/preview.d.ts +12 -0
- package/dist/preview.d.ts.map +1 -0
- package/dist/preview.js +63 -0
- package/dist/preview.js.map +1 -0
- package/dist/primitives/index.d.ts +43 -0
- package/dist/primitives/index.d.ts.map +1 -0
- package/dist/primitives/index.js +2 -0
- package/dist/primitives/schema.d.ts +18 -0
- package/dist/primitives/schema.d.ts.map +1 -0
- package/dist/primitives/schema.js +19 -0
- package/dist/primitives/schema.js.map +1 -0
- package/dist/random.d.ts +7 -0
- package/dist/random.d.ts.map +1 -0
- package/dist/random.js +25 -0
- package/dist/random.js.map +1 -0
- package/dist/resize.d.ts +41 -0
- package/dist/resize.d.ts.map +1 -0
- package/dist/resize.js +288 -0
- package/dist/resize.js.map +1 -0
- package/dist/scaling/index.d.ts +3 -0
- package/dist/scaling/index.js +3 -0
- package/dist/scaling/node.d.ts +6 -0
- package/dist/scaling/node.d.ts.map +1 -0
- package/dist/scaling/node.js +150 -0
- package/dist/scaling/node.js.map +1 -0
- package/dist/scaling/tree.d.ts +22 -0
- package/dist/scaling/tree.d.ts.map +1 -0
- package/dist/scaling/tree.js +71 -0
- package/dist/scaling/tree.js.map +1 -0
- package/dist/script/index.d.ts +2 -0
- package/dist/script/index.js +2 -0
- package/dist/script/schema.d.ts +29 -0
- package/dist/script/schema.d.ts.map +1 -0
- package/dist/script/schema.js +51 -0
- package/dist/script/schema.js.map +1 -0
- package/dist/shaders/directives.d.ts +43 -0
- package/dist/shaders/directives.d.ts.map +1 -0
- package/dist/shaders/directives.js +293 -0
- package/dist/shaders/directives.js.map +1 -0
- package/dist/shaders/index.d.ts +5 -0
- package/dist/shaders/index.js +5 -0
- package/dist/shaders/model.d.ts +58 -0
- package/dist/shaders/model.d.ts.map +1 -0
- package/dist/shaders/model.js +109 -0
- package/dist/shaders/model.js.map +1 -0
- package/dist/shaders/schema.d.ts +86 -0
- package/dist/shaders/schema.d.ts.map +1 -0
- package/dist/shaders/schema.js +65 -0
- package/dist/shaders/schema.js.map +1 -0
- package/dist/shaders/still.d.ts +18 -0
- package/dist/shaders/still.d.ts.map +1 -0
- package/dist/shaders/still.js +36 -0
- package/dist/shaders/still.js.map +1 -0
- package/dist/shape-with-text/fit.d.ts +28 -0
- package/dist/shape-with-text/fit.d.ts.map +1 -0
- package/dist/shape-with-text/fit.js +271 -0
- package/dist/shape-with-text/fit.js.map +1 -0
- package/dist/shape-with-text/geometry.d.ts +20 -0
- package/dist/shape-with-text/geometry.d.ts.map +1 -0
- package/dist/shape-with-text/geometry.js +539 -0
- package/dist/shape-with-text/geometry.js.map +1 -0
- package/dist/shape-with-text/index.d.ts +4 -0
- package/dist/shape-with-text/index.js +4 -0
- package/dist/shape-with-text/kinds.d.ts +20 -0
- package/dist/shape-with-text/kinds.d.ts.map +1 -0
- package/dist/shape-with-text/kinds.js +86 -0
- package/dist/shape-with-text/kinds.js.map +1 -0
- package/dist/shared-styles.d.ts +36 -0
- package/dist/shared-styles.d.ts.map +1 -0
- package/dist/shared-styles.js +116 -0
- package/dist/shared-styles.js.map +1 -0
- package/dist/slots/authoring.d.ts +27 -0
- package/dist/slots/authoring.d.ts.map +1 -0
- package/dist/slots/authoring.js +74 -0
- package/dist/slots/authoring.js.map +1 -0
- package/dist/slots/content.d.ts +41 -0
- package/dist/slots/content.d.ts.map +1 -0
- package/dist/slots/content.js +103 -0
- package/dist/slots/content.js.map +1 -0
- package/dist/slots/frames.d.ts +38 -0
- package/dist/slots/frames.d.ts.map +1 -0
- package/dist/slots/frames.js +113 -0
- package/dist/slots/frames.js.map +1 -0
- package/dist/slots/index.d.ts +5 -0
- package/dist/slots/index.js +5 -0
- package/dist/slots/limits.d.ts +14 -0
- package/dist/slots/limits.d.ts.map +1 -0
- package/dist/slots/limits.js +28 -0
- package/dist/slots/limits.js.map +1 -0
- package/dist/snap.d.ts +61 -0
- package/dist/snap.d.ts.map +1 -0
- package/dist/snap.js +264 -0
- package/dist/snap.js.map +1 -0
- package/dist/source-metadata.d.ts +6 -0
- package/dist/source-metadata.d.ts.map +1 -0
- package/dist/source-metadata.js +11 -0
- package/dist/source-metadata.js.map +1 -0
- package/dist/statuses/impact.d.ts +18 -0
- package/dist/statuses/impact.d.ts.map +1 -0
- package/dist/statuses/impact.js +33 -0
- package/dist/statuses/impact.js.map +1 -0
- package/dist/statuses/index.d.ts +5 -0
- package/dist/statuses/index.js +5 -0
- package/dist/statuses/node.d.ts +22 -0
- package/dist/statuses/node.d.ts.map +1 -0
- package/dist/statuses/node.js +47 -0
- package/dist/statuses/node.js.map +1 -0
- package/dist/statuses/schema.d.ts +59 -0
- package/dist/statuses/schema.d.ts.map +1 -0
- package/dist/statuses/schema.js +27 -0
- package/dist/statuses/schema.js.map +1 -0
- package/dist/statuses/workflow.d.ts +120 -0
- package/dist/statuses/workflow.d.ts.map +1 -0
- package/dist/statuses/workflow.js +135 -0
- package/dist/statuses/workflow.js.map +1 -0
- package/dist/text/direction.d.ts +13 -0
- package/dist/text/direction.d.ts.map +1 -0
- package/dist/text/direction.js +31 -0
- package/dist/text/direction.js.map +1 -0
- package/dist/text/index.d.ts +7 -0
- package/dist/text/index.js +7 -0
- package/dist/text/lengths.d.ts +19 -0
- package/dist/text/lengths.d.ts.map +1 -0
- package/dist/text/lengths.js +40 -0
- package/dist/text/lengths.js.map +1 -0
- package/dist/text/lists.d.ts +44 -0
- package/dist/text/lists.d.ts.map +1 -0
- package/dist/text/lists.js +100 -0
- package/dist/text/lists.js.map +1 -0
- package/dist/text/overflow.d.ts +11 -0
- package/dist/text/overflow.d.ts.map +1 -0
- package/dist/text/overflow.js +13 -0
- package/dist/text/overflow.js.map +1 -0
- package/dist/text/paragraphs.d.ts +62 -0
- package/dist/text/paragraphs.d.ts.map +1 -0
- package/dist/text/paragraphs.js +166 -0
- package/dist/text/paragraphs.js.map +1 -0
- package/dist/text/picture.d.ts +18 -0
- package/dist/text/picture.d.ts.map +1 -0
- package/dist/text/picture.js +41 -0
- package/dist/text/picture.js.map +1 -0
- package/dist/text/references.d.ts +21 -0
- package/dist/text/references.d.ts.map +1 -0
- package/dist/text/references.js +43 -0
- package/dist/text/references.js.map +1 -0
- package/dist/text/schema.d.ts +10 -0
- package/dist/text/schema.d.ts.map +1 -0
- package/dist/text/schema.js +11 -0
- package/dist/text/schema.js.map +1 -0
- package/dist/transfer/apply.d.ts +9 -0
- package/dist/transfer/apply.d.ts.map +1 -0
- package/dist/transfer/apply.js +65 -0
- package/dist/transfer/apply.js.map +1 -0
- package/dist/transfer/history.d.ts +8 -0
- package/dist/transfer/history.d.ts.map +1 -0
- package/dist/transfer/history.js +32 -0
- package/dist/transfer/history.js.map +1 -0
- package/dist/transfer/identity.js +12 -0
- package/dist/transfer/identity.js.map +1 -0
- package/dist/transfer/index.d.ts +7 -0
- package/dist/transfer/index.js +7 -0
- package/dist/transfer/nodes.d.ts +14 -0
- package/dist/transfer/nodes.d.ts.map +1 -0
- package/dist/transfer/nodes.js +82 -0
- package/dist/transfer/nodes.js.map +1 -0
- package/dist/transfer/plan.d.ts +29 -0
- package/dist/transfer/plan.d.ts.map +1 -0
- package/dist/transfer/plan.js +106 -0
- package/dist/transfer/plan.js.map +1 -0
- package/dist/transfer/references.js +10 -0
- package/dist/transfer/references.js.map +1 -0
- package/dist/transfer/remove.d.ts +8 -0
- package/dist/transfer/remove.d.ts.map +1 -0
- package/dist/transfer/remove.js +34 -0
- package/dist/transfer/remove.js.map +1 -0
- package/dist/transfer/validation.js +39 -0
- package/dist/transfer/validation.js.map +1 -0
- package/dist/transfer/variables.d.ts +15 -0
- package/dist/transfer/variables.d.ts.map +1 -0
- package/dist/transfer/variables.js +52 -0
- package/dist/transfer/variables.js.map +1 -0
- package/dist/types.d.ts +910 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +89 -0
- package/dist/types.js.map +1 -0
- package/dist/undo.d.ts +93 -0
- package/dist/undo.d.ts.map +1 -0
- package/dist/undo.js +236 -0
- package/dist/undo.js.map +1 -0
- package/dist/variables/bindings.d.ts +66 -0
- package/dist/variables/bindings.d.ts.map +1 -0
- package/dist/variables/bindings.js +251 -0
- package/dist/variables/bindings.js.map +1 -0
- package/dist/variables/corners.d.ts +12 -0
- package/dist/variables/corners.d.ts.map +1 -0
- package/dist/variables/corners.js +38 -0
- package/dist/variables/corners.js.map +1 -0
- package/dist/variables/fields.d.ts +30 -0
- package/dist/variables/fields.d.ts.map +1 -0
- package/dist/variables/fields.js +89 -0
- package/dist/variables/fields.js.map +1 -0
- package/dist/variables/formula/check.d.ts +14 -0
- package/dist/variables/formula/check.d.ts.map +1 -0
- package/dist/variables/formula/check.js +73 -0
- package/dist/variables/formula/check.js.map +1 -0
- package/dist/variables/formula/evaluate.d.ts +7 -0
- package/dist/variables/formula/evaluate.d.ts.map +1 -0
- package/dist/variables/formula/evaluate.js +30 -0
- package/dist/variables/formula/evaluate.js.map +1 -0
- package/dist/variables/formula/index.d.ts +21 -0
- package/dist/variables/formula/index.d.ts.map +1 -0
- package/dist/variables/formula/index.js +77 -0
- package/dist/variables/formula/index.js.map +1 -0
- package/dist/variables/formula/parse.js +141 -0
- package/dist/variables/formula/parse.js.map +1 -0
- package/dist/variables/formula/print.d.ts +25 -0
- package/dist/variables/formula/print.d.ts.map +1 -0
- package/dist/variables/formula/print.js +105 -0
- package/dist/variables/formula/print.js.map +1 -0
- package/dist/variables/formula/schema.d.ts +7 -0
- package/dist/variables/formula/schema.d.ts.map +1 -0
- package/dist/variables/formula/schema.js +62 -0
- package/dist/variables/formula/schema.js.map +1 -0
- package/dist/variables/formula/signatures.d.ts +9 -0
- package/dist/variables/formula/signatures.d.ts.map +1 -0
- package/dist/variables/formula/signatures.js +238 -0
- package/dist/variables/formula/signatures.js.map +1 -0
- package/dist/variables/formula/tokens.d.ts +26 -0
- package/dist/variables/formula/tokens.d.ts.map +1 -0
- package/dist/variables/formula/tokens.js +82 -0
- package/dist/variables/formula/tokens.js.map +1 -0
- package/dist/variables/formula/tree.d.ts +22 -0
- package/dist/variables/formula/tree.d.ts.map +1 -0
- package/dist/variables/formula/tree.js +35 -0
- package/dist/variables/formula/tree.js.map +1 -0
- package/dist/variables/index.d.ts +41 -0
- package/dist/variables/index.d.ts.map +1 -0
- package/dist/variables/index.js +246 -0
- package/dist/variables/index.js.map +1 -0
- package/dist/variables/resolution.d.ts +39 -0
- package/dist/variables/resolution.d.ts.map +1 -0
- package/dist/variables/resolution.js +154 -0
- package/dist/variables/resolution.js.map +1 -0
- package/dist/variables/schema.d.ts +40 -0
- package/dist/variables/schema.d.ts.map +1 -0
- package/dist/variables/schema.js +32 -0
- package/dist/variables/schema.js.map +1 -0
- package/dist/variables/text.d.ts +21 -0
- package/dist/variables/text.d.ts.map +1 -0
- package/dist/variables/text.js +58 -0
- package/dist/variables/text.js.map +1 -0
- package/dist/variables/token.d.ts +18 -0
- package/dist/variables/token.d.ts.map +1 -0
- package/dist/variables/token.js +39 -0
- package/dist/variables/token.js.map +1 -0
- package/dist/variables/units.js +19 -0
- package/dist/variables/units.js.map +1 -0
- package/dist/variables/value.d.ts +12 -0
- package/dist/variables/value.d.ts.map +1 -0
- package/dist/variables/value.js +70 -0
- package/dist/variables/value.js.map +1 -0
- package/dist/variant-name.d.ts +6 -0
- package/dist/variant-name.d.ts.map +1 -0
- package/dist/variant-name.js +17 -0
- package/dist/variant-name.js.map +1 -0
- package/dist/variant-properties.d.ts +18 -0
- package/dist/variant-properties.d.ts.map +1 -0
- package/dist/variant-properties.js +74 -0
- package/dist/variant-properties.js.map +1 -0
- package/dist/vector-network.d.ts +48 -0
- package/dist/vector-network.d.ts.map +1 -0
- package/dist/vector-network.js +352 -0
- package/dist/vector-network.js.map +1 -0
- package/package.json +364 -4
- package/src/agent-notes/index.ts +2 -0
- package/src/agent-notes/model.ts +46 -0
- package/src/agent-notes/schema.ts +28 -0
- package/src/arrow-caps.ts +364 -0
- package/src/asset-keys.ts +25 -0
- package/src/behaviours/index.ts +5 -0
- package/src/behaviours/kinds.ts +185 -0
- package/src/behaviours/layers.ts +51 -0
- package/src/behaviours/model.ts +184 -0
- package/src/behaviours/schema.ts +93 -0
- package/src/behaviours/spec.ts +178 -0
- package/src/bindings.ts +20 -0
- package/src/browser-node/index.ts +2 -0
- package/src/browser-node/model.ts +35 -0
- package/src/browser-node/schema.ts +62 -0
- package/src/buffered-events.ts +64 -0
- package/src/checkpoint.ts +325 -0
- package/src/clipping.ts +112 -0
- package/src/color/contrast.ts +71 -0
- package/src/color/index.ts +89 -0
- package/src/color/management.ts +210 -0
- package/src/color/normalize.ts +7 -0
- package/src/color/okhcl.ts +201 -0
- package/src/color/schema.ts +10 -0
- package/src/comments/document.ts +51 -0
- package/src/comments/index.ts +5 -0
- package/src/comments/list.ts +52 -0
- package/src/comments/merge.ts +63 -0
- package/src/comments/schema.ts +51 -0
- package/src/comments/threads.ts +156 -0
- package/src/components/exposure.ts +61 -0
- package/src/components/index.ts +9 -0
- package/src/components/library-page.ts +17 -0
- package/src/components/properties.ts +241 -0
- package/src/components/variants.ts +53 -0
- package/src/connectors/controls.ts +229 -0
- package/src/connectors/create.ts +48 -0
- package/src/connectors/elbow.ts +235 -0
- package/src/connectors/gaps.ts +72 -0
- package/src/connectors/hit.ts +60 -0
- package/src/connectors/index.ts +28 -0
- package/src/connectors/label.ts +238 -0
- package/src/connectors/layout.ts +280 -0
- package/src/connectors/pieces.ts +144 -0
- package/src/connectors/route.ts +148 -0
- package/src/connectors/sides.ts +94 -0
- package/src/connectors/sublayers.ts +204 -0
- package/src/constants.ts +13 -0
- package/src/coordinate.ts +298 -0
- package/src/copy.ts +341 -0
- package/src/css/grid.ts +70 -0
- package/src/css/index.ts +10 -0
- package/src/css/layout.ts +53 -0
- package/src/css/shadows.ts +68 -0
- package/src/css/text.ts +84 -0
- package/src/css/values.ts +42 -0
- package/src/events.ts +21 -0
- package/src/export-format.ts +33 -0
- package/src/export-scale.ts +16 -0
- package/src/fields/appearance.ts +35 -0
- package/src/fields/geometry.ts +11 -0
- package/src/fields/index.ts +4 -0
- package/src/fields/layout.ts +48 -0
- package/src/fields/text.ts +64 -0
- package/src/fig-compression.ts +9 -0
- package/src/figjam/index.ts +2 -0
- package/src/figjam/palette.ts +308 -0
- package/src/figjam/text.ts +78 -0
- package/src/font-style.ts +121 -0
- package/src/generated/index.ts +81 -0
- package/src/generated/kind.ts +26 -0
- package/src/generated/shape-with-text.ts +132 -0
- package/src/generated/sticky.ts +214 -0
- package/src/geometry.ts +490 -0
- package/src/gradient.ts +275 -0
- package/src/graph.ts +842 -0
- package/src/group-bounds.ts +178 -0
- package/src/guides.ts +47 -0
- package/src/hit-test.ts +501 -0
- package/src/icons/glyph.ts +128 -0
- package/src/icons/index.ts +3 -0
- package/src/icons/model.ts +63 -0
- package/src/icons/schema.ts +34 -0
- package/src/ids.ts +34 -0
- package/src/images.ts +89 -0
- package/src/index.ts +4 -0
- package/src/instances/assignments.ts +116 -0
- package/src/instances/content-size.ts +84 -0
- package/src/instances/copies.ts +244 -0
- package/src/instances/cycles.ts +73 -0
- package/src/instances/fields.ts +90 -0
- package/src/instances/index.ts +467 -0
- package/src/instances/main-component.ts +61 -0
- package/src/instances/modes.ts +39 -0
- package/src/instances/overrides.ts +240 -0
- package/src/instances/placement.ts +29 -0
- package/src/instances/replacements.ts +80 -0
- package/src/instances/source-walk.ts +35 -0
- package/src/instances/sync.ts +556 -0
- package/src/instances/vector-geometry.ts +81 -0
- package/src/layout/aspect-ratio.ts +51 -0
- package/src/layout/guides.ts +132 -0
- package/src/layout/index.ts +4 -0
- package/src/layout/keywords.ts +74 -0
- package/src/layout/sizing.ts +196 -0
- package/src/layout/writes.ts +59 -0
- package/src/matrix.ts +116 -0
- package/src/mutation-impact.ts +85 -0
- package/src/naming.ts +11 -0
- package/src/node-defaults.ts +260 -0
- package/src/order-keys.ts +162 -0
- package/src/paints/index.ts +1 -0
- package/src/paints/schema.ts +72 -0
- package/src/parse-path.ts +244 -0
- package/src/plugin-data/citation.ts +27 -0
- package/src/plugin-data/field.ts +140 -0
- package/src/plugin-data/fields.ts +306 -0
- package/src/plugin-data/index.ts +3 -0
- package/src/plugin-data/schema.ts +35 -0
- package/src/polygon.ts +228 -0
- package/src/preview.ts +80 -0
- package/src/primitives/index.ts +44 -0
- package/src/primitives/schema.ts +14 -0
- package/src/random.ts +28 -0
- package/src/resize.ts +415 -0
- package/src/scaling/index.ts +9 -0
- package/src/scaling/node.ts +168 -0
- package/src/scaling/tree.ts +85 -0
- package/src/script/index.ts +1 -0
- package/src/script/schema.ts +65 -0
- package/src/shaders/directives.ts +366 -0
- package/src/shaders/index.ts +4 -0
- package/src/shaders/model.ts +147 -0
- package/src/shaders/schema.ts +84 -0
- package/src/shaders/still.ts +41 -0
- package/src/shape-with-text/fit.ts +154 -0
- package/src/shape-with-text/geometry.ts +496 -0
- package/src/shape-with-text/index.ts +10 -0
- package/src/shape-with-text/kinds.ts +86 -0
- package/src/shared-styles.ts +137 -0
- package/src/slots/authoring.ts +101 -0
- package/src/slots/content.ts +127 -0
- package/src/slots/frames.ts +160 -0
- package/src/slots/index.ts +4 -0
- package/src/slots/limits.ts +49 -0
- package/src/snap.ts +349 -0
- package/src/source-metadata.ts +8 -0
- package/src/statuses/impact.ts +38 -0
- package/src/statuses/index.ts +4 -0
- package/src/statuses/node.ts +63 -0
- package/src/statuses/schema.ts +39 -0
- package/src/statuses/workflow.ts +121 -0
- package/src/text/direction.ts +55 -0
- package/src/text/index.ts +6 -0
- package/src/text/lengths.ts +34 -0
- package/src/text/lists.ts +138 -0
- package/src/text/overflow.ts +12 -0
- package/src/text/paragraphs.ts +241 -0
- package/src/text/picture.ts +57 -0
- package/src/text/references.ts +50 -0
- package/src/text/schema.ts +7 -0
- package/src/transfer/apply.ts +84 -0
- package/src/transfer/history.ts +49 -0
- package/src/transfer/identity.ts +16 -0
- package/src/transfer/index.ts +6 -0
- package/src/transfer/nodes.ts +128 -0
- package/src/transfer/plan.ts +130 -0
- package/src/transfer/references.ts +9 -0
- package/src/transfer/remove.ts +39 -0
- package/src/transfer/validation.ts +59 -0
- package/src/transfer/variables.ts +83 -0
- package/src/types.ts +1205 -0
- package/src/undo.ts +285 -0
- package/src/variables/bindings.ts +310 -0
- package/src/variables/corners.ts +39 -0
- package/src/variables/fields.ts +109 -0
- package/src/variables/formula/check.ts +99 -0
- package/src/variables/formula/evaluate.ts +33 -0
- package/src/variables/formula/index.ts +129 -0
- package/src/variables/formula/parse.ts +160 -0
- package/src/variables/formula/print.ts +167 -0
- package/src/variables/formula/schema.ts +77 -0
- package/src/variables/formula/signatures.ts +266 -0
- package/src/variables/formula/tokens.ts +114 -0
- package/src/variables/formula/tree.ts +53 -0
- package/src/variables/index.ts +400 -0
- package/src/variables/resolution.ts +293 -0
- package/src/variables/schema.ts +31 -0
- package/src/variables/text.ts +61 -0
- package/src/variables/token.ts +40 -0
- package/src/variables/units.ts +15 -0
- package/src/variables/value.ts +92 -0
- package/src/variant-name.ts +15 -0
- package/src/variant-properties.ts +98 -0
- package/src/vector-network.ts +489 -0
package/dist/resize.js
ADDED
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import { cloneVectorNetwork } from "./vector-network.js";
|
|
2
|
+
import { copyDerivedGlyphs, copyGeometryPaths, copyStroke, copyStrokes, scaleGeometryPaths } from "./copy.js";
|
|
3
|
+
import { enforcedAspectRatio } from "./layout/aspect-ratio.js";
|
|
4
|
+
//#region src/resize.ts
|
|
5
|
+
const CONSTRAINT_CONTAINER_TYPES = /* @__PURE__ */ new Set([
|
|
6
|
+
"FRAME",
|
|
7
|
+
"COMPONENT",
|
|
8
|
+
"COMPONENT_SET",
|
|
9
|
+
"INSTANCE",
|
|
10
|
+
"GROUP",
|
|
11
|
+
"BOOLEAN_OPERATION"
|
|
12
|
+
]);
|
|
13
|
+
function constrainedAxis(position, size, parentBefore, parentAfter, constraint) {
|
|
14
|
+
const delta = parentAfter - parentBefore;
|
|
15
|
+
if (constraint === "MAX") return {
|
|
16
|
+
position: position + delta,
|
|
17
|
+
size
|
|
18
|
+
};
|
|
19
|
+
if (constraint === "CENTER") return {
|
|
20
|
+
position: position + delta / 2,
|
|
21
|
+
size
|
|
22
|
+
};
|
|
23
|
+
if (constraint === "STRETCH") return {
|
|
24
|
+
position,
|
|
25
|
+
size: Math.max(1, size + delta)
|
|
26
|
+
};
|
|
27
|
+
if (constraint === "SCALE" && parentBefore > 0) {
|
|
28
|
+
const scale = parentAfter / parentBefore;
|
|
29
|
+
return {
|
|
30
|
+
position: position * scale,
|
|
31
|
+
size: Math.max(1, size * scale)
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
position,
|
|
36
|
+
size
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
const FLEXIBLE_CONSTRAINTS = /* @__PURE__ */ new Set(["STRETCH", "SCALE"]);
|
|
40
|
+
/** The axis at `size`, keeping the edge or centre its constraint pins where it was placed. */
|
|
41
|
+
function resizedInPlace(placed, size, constraint) {
|
|
42
|
+
if (constraint === "MAX") return {
|
|
43
|
+
position: placed.position + placed.size - size,
|
|
44
|
+
size
|
|
45
|
+
};
|
|
46
|
+
if (constraint === "CENTER") return {
|
|
47
|
+
position: placed.position + (placed.size - size) / 2,
|
|
48
|
+
size
|
|
49
|
+
};
|
|
50
|
+
return {
|
|
51
|
+
position: placed.position,
|
|
52
|
+
size
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/** Keep a placed box's constrained edges or center when its content determines its size. */
|
|
56
|
+
function resizedChildRect(placed, size, horizontal, vertical) {
|
|
57
|
+
const x = resizedInPlace({
|
|
58
|
+
position: placed.x,
|
|
59
|
+
size: placed.width
|
|
60
|
+
}, size.width, horizontal);
|
|
61
|
+
const y = resizedInPlace({
|
|
62
|
+
position: placed.y,
|
|
63
|
+
size: placed.height
|
|
64
|
+
}, size.height, vertical);
|
|
65
|
+
return {
|
|
66
|
+
x: x.position,
|
|
67
|
+
y: y.position,
|
|
68
|
+
width: x.size,
|
|
69
|
+
height: y.size
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* A locked aspect ratio holds when exactly one axis follows the parent, as in Figma: that axis
|
|
74
|
+
* sizes the other. With both axes following the parent, or neither, the ratio gives way.
|
|
75
|
+
*/
|
|
76
|
+
function keepLockedRatio(x, y, horizontal, vertical, aspectRatio) {
|
|
77
|
+
const flexibleX = FLEXIBLE_CONSTRAINTS.has(horizontal);
|
|
78
|
+
if (aspectRatio === null || flexibleX === FLEXIBLE_CONSTRAINTS.has(vertical)) return {
|
|
79
|
+
x,
|
|
80
|
+
y
|
|
81
|
+
};
|
|
82
|
+
return flexibleX ? {
|
|
83
|
+
x,
|
|
84
|
+
y: resizedInPlace(y, x.size / aspectRatio, vertical)
|
|
85
|
+
} : {
|
|
86
|
+
x: resizedInPlace(x, y.size * aspectRatio, horizontal),
|
|
87
|
+
y
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/** A child's box after its parent resizes, keeping a locked aspect ratio as Figma does. */
|
|
91
|
+
function constrainedChildRect(child, parentBefore, parentAfter, horizontal, vertical, aspectRatio = null) {
|
|
92
|
+
let x = constrainedAxis(child.x, child.width, parentBefore.width, parentAfter.width, horizontal);
|
|
93
|
+
let y = constrainedAxis(child.y, child.height, parentBefore.height, parentAfter.height, vertical);
|
|
94
|
+
({x, y} = keepLockedRatio(x, y, horizontal, vertical, aspectRatio));
|
|
95
|
+
return {
|
|
96
|
+
x: Math.round(x.position),
|
|
97
|
+
y: Math.round(y.position),
|
|
98
|
+
width: Math.round(x.size),
|
|
99
|
+
height: Math.round(y.size)
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
function layoutConstrainedAxis(position, size, parentBefore, parentAfter, constraint) {
|
|
103
|
+
const delta = Math.round(parentAfter) - Math.round(parentBefore);
|
|
104
|
+
if (constraint === "MAX") return {
|
|
105
|
+
position: position + delta,
|
|
106
|
+
size
|
|
107
|
+
};
|
|
108
|
+
if (constraint === "CENTER") return {
|
|
109
|
+
position: position + Math.round(parentAfter / 2) - Math.round(parentBefore / 2),
|
|
110
|
+
size
|
|
111
|
+
};
|
|
112
|
+
if (constraint === "STRETCH") return {
|
|
113
|
+
position,
|
|
114
|
+
size: Math.abs(size + delta)
|
|
115
|
+
};
|
|
116
|
+
if (constraint === "SCALE" && parentBefore > 0) {
|
|
117
|
+
const scale = parentAfter / parentBefore;
|
|
118
|
+
return {
|
|
119
|
+
position: Math.round(position * scale * 128) / 128,
|
|
120
|
+
size: size * scale
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
position,
|
|
125
|
+
size
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Where a child goes when layout resizes its parent, as Figma places a layer that ignores auto
|
|
130
|
+
* layout when its Hug frame grows (measured on desktop 126): Right and Left & right move or grow
|
|
131
|
+
* it by the change in the parent's size rounded to whole pixels, Center by the change in its
|
|
132
|
+
* rounded half, and Scale by the exact ratio, its position to 1/128 of a pixel. Sizes are not
|
|
133
|
+
* rounded, so applying a run of changes one at a time lands where applying them at once does.
|
|
134
|
+
*/
|
|
135
|
+
function layoutConstrainedChildRect(child, parentBefore, parentAfter, horizontal, vertical, aspectRatio = null) {
|
|
136
|
+
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);
|
|
137
|
+
return {
|
|
138
|
+
x: placed.x.position,
|
|
139
|
+
y: placed.y.position,
|
|
140
|
+
width: placed.x.size,
|
|
141
|
+
height: placed.y.size
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
function scaledChildRect(child, parentBefore, parentAfter) {
|
|
145
|
+
return constrainedChildRect(child, parentBefore, parentAfter, "SCALE", "SCALE");
|
|
146
|
+
}
|
|
147
|
+
function scaleVectorNetworkForResize(vectorNetwork, originalWidth, originalHeight, width, height) {
|
|
148
|
+
if (!vectorNetwork || originalWidth <= 0 && originalHeight <= 0) return null;
|
|
149
|
+
const scaleX = originalWidth > 0 ? width / originalWidth : 1;
|
|
150
|
+
const scaleY = originalHeight > 0 ? height / originalHeight : 1;
|
|
151
|
+
if (scaleX === 1 && scaleY === 1) return null;
|
|
152
|
+
return {
|
|
153
|
+
vertices: vectorNetwork.vertices.map((vertex) => ({
|
|
154
|
+
...vertex,
|
|
155
|
+
x: vertex.x * scaleX,
|
|
156
|
+
y: vertex.y * scaleY
|
|
157
|
+
})),
|
|
158
|
+
segments: vectorNetwork.segments.map((segment) => ({
|
|
159
|
+
...segment,
|
|
160
|
+
tangentStart: {
|
|
161
|
+
x: segment.tangentStart.x * scaleX,
|
|
162
|
+
y: segment.tangentStart.y * scaleY
|
|
163
|
+
},
|
|
164
|
+
tangentEnd: {
|
|
165
|
+
x: segment.tangentEnd.x * scaleX,
|
|
166
|
+
y: segment.tangentEnd.y * scaleY
|
|
167
|
+
}
|
|
168
|
+
})),
|
|
169
|
+
regions: vectorNetwork.regions
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
/** Snapshot one node's resize-relevant state (rect + geometry that must scale with it). */
|
|
173
|
+
function createResizeSnapshot(node) {
|
|
174
|
+
return {
|
|
175
|
+
type: node.type,
|
|
176
|
+
x: node.x,
|
|
177
|
+
y: node.y,
|
|
178
|
+
width: node.width,
|
|
179
|
+
height: node.height,
|
|
180
|
+
vectorNetwork: node.vectorNetwork ? cloneVectorNetwork(node.vectorNetwork) : null,
|
|
181
|
+
fillGeometry: copyGeometryPaths(node.fillGeometry),
|
|
182
|
+
strokeGeometry: copyGeometryPaths(node.strokeGeometry),
|
|
183
|
+
derivedTextGlyphs: copyDerivedGlyphs(node.derivedTextGlyphs),
|
|
184
|
+
strokes: copyStrokes(node.strokes),
|
|
185
|
+
textPathData: node.textPathData ? structuredClone(node.textPathData) : null,
|
|
186
|
+
textPathBox: node.textPathBox ? { ...node.textPathBox } : null
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
function scaleDerivedGlyphs(glyphs, sx, sy) {
|
|
190
|
+
if (!glyphs?.length) return glyphs;
|
|
191
|
+
return glyphs.map((g) => ({
|
|
192
|
+
...g,
|
|
193
|
+
x: g.x * sx,
|
|
194
|
+
y: g.y * sy,
|
|
195
|
+
scaleX: (g.scaleX ?? 1) * sx,
|
|
196
|
+
scaleY: (g.scaleY ?? 1) * sy,
|
|
197
|
+
commandsBlob: new Uint8Array(g.commandsBlob)
|
|
198
|
+
}));
|
|
199
|
+
}
|
|
200
|
+
function hasPath(orig) {
|
|
201
|
+
return (orig.vectorNetwork?.segments.length ?? 0) > 0;
|
|
202
|
+
}
|
|
203
|
+
function scaleStrokes(strokes, sx, sy) {
|
|
204
|
+
if (strokes.length === 0) return strokes;
|
|
205
|
+
const weightScale = (Math.abs(sx) + Math.abs(sy)) / 2;
|
|
206
|
+
return strokes.map((s) => ({
|
|
207
|
+
...copyStroke(s),
|
|
208
|
+
weight: s.weight * weightScale
|
|
209
|
+
}));
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* All geometry that must track a width/height change. Historically only
|
|
213
|
+
* vectorNetwork + fillGeometry were updated — path-text strokeGeometry and
|
|
214
|
+
* glyphs stayed at the pre-resize size, so shrinking a sticker made the white
|
|
215
|
+
* OUTSIDE outlines look massively thick (DomeSticker resize bug).
|
|
216
|
+
*/
|
|
217
|
+
function scaledGeometryChanges(orig, origWidth, origHeight, width, height) {
|
|
218
|
+
if (origWidth <= 0 || origHeight <= 0) return {};
|
|
219
|
+
const sx = width / origWidth;
|
|
220
|
+
const sy = height / origHeight;
|
|
221
|
+
if (sx === 1 && sy === 1) return {};
|
|
222
|
+
const changes = {};
|
|
223
|
+
const resizedVN = scaleVectorNetworkForResize(orig.vectorNetwork, origWidth, origHeight, width, height);
|
|
224
|
+
if (resizedVN) changes.vectorNetwork = resizedVN;
|
|
225
|
+
if (orig.fillGeometry.length > 0) changes.fillGeometry = scaleGeometryPaths(orig.fillGeometry, sx, sy);
|
|
226
|
+
const outlineOnly = orig.type === "TEXT" || orig.type === "VECTOR" && !hasPath(orig);
|
|
227
|
+
if (orig.strokeGeometry.length > 0) changes.strokeGeometry = outlineOnly ? scaleGeometryPaths(orig.strokeGeometry, sx, sy) : [];
|
|
228
|
+
const glyphs = orig.derivedTextGlyphs ?? [];
|
|
229
|
+
const pathText = !!orig.textPathData || !!orig.textPathBox || glyphs.some((glyph) => (glyph.rotation ?? 0) !== 0);
|
|
230
|
+
if (glyphs.length > 0 && pathText) {
|
|
231
|
+
changes.derivedTextGlyphs = scaleDerivedGlyphs(glyphs, sx, sy);
|
|
232
|
+
if (orig.textPathBox) changes.textPathBox = {
|
|
233
|
+
x: orig.textPathBox.x * sx,
|
|
234
|
+
y: orig.textPathBox.y * sy,
|
|
235
|
+
width: orig.textPathBox.width * sx,
|
|
236
|
+
height: orig.textPathBox.height * sy
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
if (orig.strokes.length > 0 && glyphs.length > 0 && pathText) changes.strokes = scaleStrokes(orig.strokes, sx, sy);
|
|
240
|
+
return changes;
|
|
241
|
+
}
|
|
242
|
+
function collectResizeDescendants(graph, rootId) {
|
|
243
|
+
const root = graph.getNode(rootId);
|
|
244
|
+
if (!root || !CONSTRAINT_CONTAINER_TYPES.has(root.type)) return null;
|
|
245
|
+
const snapshots = /* @__PURE__ */ new Map();
|
|
246
|
+
const collect = (parentId) => {
|
|
247
|
+
const parent = graph.getNode(parentId);
|
|
248
|
+
if (!parent) return;
|
|
249
|
+
for (const childId of parent.childIds) {
|
|
250
|
+
const child = graph.getNode(childId);
|
|
251
|
+
if (!child) continue;
|
|
252
|
+
snapshots.set(childId, createResizeSnapshot(child));
|
|
253
|
+
collect(childId);
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
collect(rootId);
|
|
257
|
+
return snapshots.size > 0 ? snapshots : null;
|
|
258
|
+
}
|
|
259
|
+
function computeConstrainedResizeChanges(graph, rootId, rootBefore, rootAfter, originals) {
|
|
260
|
+
const changes = /* @__PURE__ */ new Map();
|
|
261
|
+
const compute = (parentId, parentBefore, parentAfter) => {
|
|
262
|
+
const parent = graph.getNode(parentId);
|
|
263
|
+
if (!parent) return;
|
|
264
|
+
const scalesChildren = parent.type === "GROUP" || parent.type === "BOOLEAN_OPERATION";
|
|
265
|
+
for (const childId of parent.childIds) {
|
|
266
|
+
const original = originals.get(childId);
|
|
267
|
+
const child = graph.getNode(childId);
|
|
268
|
+
if (!original || !child) continue;
|
|
269
|
+
if (parent.layoutMode !== "NONE" && child.layoutPositioning !== "ABSOLUTE") {
|
|
270
|
+
compute(childId, original, child);
|
|
271
|
+
continue;
|
|
272
|
+
}
|
|
273
|
+
const rect = scalesChildren ? scaledChildRect(original, parentBefore, parentAfter) : constrainedChildRect(original, parentBefore, parentAfter, child.horizontalConstraint, child.verticalConstraint, enforcedAspectRatio(child));
|
|
274
|
+
const childChanges = {
|
|
275
|
+
...rect,
|
|
276
|
+
...scaledGeometryChanges(original, original.width, original.height, rect.width, rect.height)
|
|
277
|
+
};
|
|
278
|
+
changes.set(childId, childChanges);
|
|
279
|
+
compute(childId, original, child.layoutMode === "NONE" ? rect : child);
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
compute(rootId, rootBefore, rootAfter);
|
|
283
|
+
return changes;
|
|
284
|
+
}
|
|
285
|
+
//#endregion
|
|
286
|
+
export { collectResizeDescendants, computeConstrainedResizeChanges, constrainedChildRect, createResizeSnapshot, layoutConstrainedChildRect, resizedChildRect, scaleVectorNetworkForResize, scaledChildRect, scaledGeometryChanges };
|
|
287
|
+
|
|
288
|
+
//# sourceMappingURL=resize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resize.js","names":[],"sources":["../src/resize.ts"],"sourcesContent":["import {\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'\nimport { cloneVectorNetwork } from './vector-network'\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,OAAO;EAAE,UAAU,OAAO;EAAU;CAAK;AAC3C;;AAGA,SAAgB,iBACd,QACA,MACA,YACA,UACM;CACN,MAAM,IAAI,eAAe;EAAE,UAAU,OAAO;EAAG,MAAM,OAAO;CAAM,GAA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node.js";
|
|
2
|
+
import { MIN_RESCALE, assertRescaleFactor, isRescalable, rescaleNodeTree, rescaleNodeTreeChanges, rescaleSubtree } from "./tree.js";
|
|
3
|
+
export { MIN_RESCALE, assertRescaleFactor, isRescalable, rescaleNodeTree, rescaleNodeTreeChanges, rescaleSubtree, scaleNodeChanges };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { scaleNodeChanges } from "./node.js";
|
|
2
|
+
import { MIN_RESCALE, assertRescaleFactor, isRescalable, rescaleNodeTree, rescaleNodeTreeChanges, rescaleSubtree } from "./tree.js";
|
|
3
|
+
export { MIN_RESCALE, assertRescaleFactor, isRescalable, rescaleNodeTree, rescaleNodeTreeChanges, rescaleSubtree, scaleNodeChanges };
|
|
@@ -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,150 @@
|
|
|
1
|
+
import { scaledTextLength } from "../text/lengths.js";
|
|
2
|
+
import { cloneVectorNetwork } from "../vector-network.js";
|
|
3
|
+
import { scaleGeometryPaths } from "../copy.js";
|
|
4
|
+
import { TEXT_PARAGRAPH_SPACING_FIELDS } from "../text/paragraphs.js";
|
|
5
|
+
//#region src/scaling/node.ts
|
|
6
|
+
function scaledOptional(value, scale) {
|
|
7
|
+
return value == null ? null : value * scale;
|
|
8
|
+
}
|
|
9
|
+
function scaledStrokes(strokes, scale) {
|
|
10
|
+
return strokes.map((stroke) => ({
|
|
11
|
+
...structuredClone(stroke),
|
|
12
|
+
weight: stroke.weight * scale,
|
|
13
|
+
dashPattern: stroke.dashPattern?.map((value) => value * scale)
|
|
14
|
+
}));
|
|
15
|
+
}
|
|
16
|
+
function scaledEffects(effects, scale) {
|
|
17
|
+
return effects.map((effect) => {
|
|
18
|
+
const copy = structuredClone(effect);
|
|
19
|
+
if (copy.type === "SHADER") return copy;
|
|
20
|
+
copy.offset = {
|
|
21
|
+
x: copy.offset.x * scale,
|
|
22
|
+
y: copy.offset.y * scale
|
|
23
|
+
};
|
|
24
|
+
copy.radius *= scale;
|
|
25
|
+
copy.spread *= scale;
|
|
26
|
+
return copy;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
function scaledFills(fills, scale) {
|
|
30
|
+
return fills.map((fill) => ({
|
|
31
|
+
...structuredClone(fill),
|
|
32
|
+
scale: fill.scale == null ? void 0 : fill.scale * scale,
|
|
33
|
+
spacing: fill.spacing == null ? void 0 : fill.spacing * scale,
|
|
34
|
+
patternSpacing: fill.patternSpacing ? {
|
|
35
|
+
x: fill.patternSpacing.x * scale,
|
|
36
|
+
y: fill.patternSpacing.y * scale
|
|
37
|
+
} : void 0,
|
|
38
|
+
noiseSize: fill.noiseSize ? {
|
|
39
|
+
x: fill.noiseSize.x * scale,
|
|
40
|
+
y: fill.noiseSize.y * scale
|
|
41
|
+
} : void 0
|
|
42
|
+
}));
|
|
43
|
+
}
|
|
44
|
+
function scaledStyleRuns(styleRuns, scale) {
|
|
45
|
+
return styleRuns.map((run) => ({
|
|
46
|
+
...structuredClone(run),
|
|
47
|
+
style: {
|
|
48
|
+
...structuredClone(run.style),
|
|
49
|
+
fontSize: run.style.fontSize == null ? void 0 : run.style.fontSize * scale,
|
|
50
|
+
letterSpacing: run.style.letterSpacing && scaledTextLength(run.style.letterSpacing, scale),
|
|
51
|
+
lineHeight: run.style.lineHeight && scaledTextLength(run.style.lineHeight, scale),
|
|
52
|
+
textDecorationThickness: scaledOptional(run.style.textDecorationThickness ?? null, scale),
|
|
53
|
+
textUnderlineOffset: scaledOptional(run.style.textUnderlineOffset ?? null, scale)
|
|
54
|
+
}
|
|
55
|
+
}));
|
|
56
|
+
}
|
|
57
|
+
function scaledParagraphStyles(paragraphs, scale) {
|
|
58
|
+
return paragraphs.map((style) => {
|
|
59
|
+
const scaled = { ...style };
|
|
60
|
+
for (const field of TEXT_PARAGRAPH_SPACING_FIELDS) {
|
|
61
|
+
const value = style[field];
|
|
62
|
+
if (value !== void 0) scaled[field] = value * scale;
|
|
63
|
+
}
|
|
64
|
+
return scaled;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
function scaledLayoutGrids(grids, scale) {
|
|
68
|
+
return grids.map((grid) => ({
|
|
69
|
+
...structuredClone(grid),
|
|
70
|
+
offset: grid.offset == null ? void 0 : grid.offset * scale,
|
|
71
|
+
sectionSize: grid.sectionSize == null ? void 0 : grid.sectionSize * scale,
|
|
72
|
+
gutterSize: grid.gutterSize == null ? void 0 : grid.gutterSize * scale
|
|
73
|
+
}));
|
|
74
|
+
}
|
|
75
|
+
function scaledGridTracks(tracks, scale) {
|
|
76
|
+
return tracks.map((track) => ({
|
|
77
|
+
...track,
|
|
78
|
+
value: track.sizing === "FIXED" ? track.value * scale : track.value
|
|
79
|
+
}));
|
|
80
|
+
}
|
|
81
|
+
function scaledVectorNetwork(node, scale) {
|
|
82
|
+
if (!node.vectorNetwork) return null;
|
|
83
|
+
const network = cloneVectorNetwork(node.vectorNetwork);
|
|
84
|
+
for (const vertex of network.vertices) {
|
|
85
|
+
vertex.x *= scale;
|
|
86
|
+
vertex.y *= scale;
|
|
87
|
+
}
|
|
88
|
+
for (const segment of network.segments) {
|
|
89
|
+
segment.tangentStart.x *= scale;
|
|
90
|
+
segment.tangentStart.y *= scale;
|
|
91
|
+
segment.tangentEnd.x *= scale;
|
|
92
|
+
segment.tangentEnd.y *= scale;
|
|
93
|
+
}
|
|
94
|
+
return network;
|
|
95
|
+
}
|
|
96
|
+
function scaleNodeChanges(node, scale, scalePosition) {
|
|
97
|
+
return {
|
|
98
|
+
x: scalePosition ? node.x * scale : node.x,
|
|
99
|
+
y: scalePosition ? node.y * scale : node.y,
|
|
100
|
+
width: node.width * scale,
|
|
101
|
+
height: node.height * scale,
|
|
102
|
+
minWidth: scaledOptional(node.minWidth, scale),
|
|
103
|
+
maxWidth: scaledOptional(node.maxWidth, scale),
|
|
104
|
+
minHeight: scaledOptional(node.minHeight, scale),
|
|
105
|
+
maxHeight: scaledOptional(node.maxHeight, scale),
|
|
106
|
+
cornerRadius: node.cornerRadius * scale,
|
|
107
|
+
topLeftRadius: node.topLeftRadius * scale,
|
|
108
|
+
topRightRadius: node.topRightRadius * scale,
|
|
109
|
+
bottomRightRadius: node.bottomRightRadius * scale,
|
|
110
|
+
bottomLeftRadius: node.bottomLeftRadius * scale,
|
|
111
|
+
fontSize: node.fontSize * scale,
|
|
112
|
+
letterSpacing: scaledTextLength(node.letterSpacing, scale),
|
|
113
|
+
lineHeight: node.lineHeight && scaledTextLength(node.lineHeight, scale),
|
|
114
|
+
textDecorationThickness: scaledOptional(node.textDecorationThickness, scale),
|
|
115
|
+
textUnderlineOffset: scaledOptional(node.textUnderlineOffset, scale),
|
|
116
|
+
styleRuns: scaledStyleRuns(node.styleRuns, scale),
|
|
117
|
+
listSpacing: node.listSpacing * scale,
|
|
118
|
+
paragraphSpacing: node.paragraphSpacing * scale,
|
|
119
|
+
paragraphIndent: node.paragraphIndent * scale,
|
|
120
|
+
textParagraphs: scaledParagraphStyles(node.textParagraphs, scale),
|
|
121
|
+
itemSpacing: node.itemSpacing * scale,
|
|
122
|
+
counterAxisSpacing: node.counterAxisSpacing * scale,
|
|
123
|
+
paddingTop: node.paddingTop * scale,
|
|
124
|
+
paddingRight: node.paddingRight * scale,
|
|
125
|
+
paddingBottom: node.paddingBottom * scale,
|
|
126
|
+
paddingLeft: node.paddingLeft * scale,
|
|
127
|
+
gridColumnGap: node.gridColumnGap * scale,
|
|
128
|
+
gridRowGap: node.gridRowGap * scale,
|
|
129
|
+
gridTemplateColumns: scaledGridTracks(node.gridTemplateColumns, scale),
|
|
130
|
+
gridTemplateRows: scaledGridTracks(node.gridTemplateRows, scale),
|
|
131
|
+
strokes: scaledStrokes(node.strokes, scale),
|
|
132
|
+
strokeWeight: node.strokeWeight * scale,
|
|
133
|
+
dashPattern: node.dashPattern.map((value) => value * scale),
|
|
134
|
+
borderTopWeight: node.borderTopWeight * scale,
|
|
135
|
+
borderRightWeight: node.borderRightWeight * scale,
|
|
136
|
+
borderBottomWeight: node.borderBottomWeight * scale,
|
|
137
|
+
borderLeftWeight: node.borderLeftWeight * scale,
|
|
138
|
+
strokeMiterLimit: node.strokeMiterLimit,
|
|
139
|
+
effects: scaledEffects(node.effects, scale),
|
|
140
|
+
fills: scaledFills(node.fills, scale),
|
|
141
|
+
layoutGrids: scaledLayoutGrids(node.layoutGrids, scale),
|
|
142
|
+
vectorNetwork: scaledVectorNetwork(node, scale),
|
|
143
|
+
fillGeometry: scaleGeometryPaths(node.fillGeometry, scale, scale),
|
|
144
|
+
strokeGeometry: scaleGeometryPaths(node.strokeGeometry, scale, scale)
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
//#endregion
|
|
148
|
+
export { scaleNodeChanges };
|
|
149
|
+
|
|
150
|
+
//# sourceMappingURL=node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.js","names":[],"sources":["../../src/scaling/node.ts"],"sourcesContent":["import { 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'\nimport { cloneVectorNetwork } from '../vector-network'\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 const copy = structuredClone(effect)\n // A shader effect has no geometry of its own; only a shadow's measures follow the layer.\n if (copy.type === 'SHADER') return copy\n copy.offset = { x: copy.offset.x * scale, y: copy.offset.y * scale }\n copy.radius *= scale\n copy.spread *= scale\n return copy\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 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":";;;;;AAeA,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,WAAW;EAC7B,MAAM,OAAO,gBAAgB,MAAM;EAEnC,IAAI,KAAK,SAAS,UAAU,OAAO;EACnC,KAAK,SA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|
1
|
+
import { SceneGraph } from "../graph.js";
|
|
2
|
+
import { SceneNode } from "../types.js";
|
|
3
|
+
//#region src/scaling/tree.d.ts
|
|
4
|
+
/** The smallest factor a layer scales by, so it never folds away. */
|
|
5
|
+
declare const MIN_RESCALE = 0.01;
|
|
6
|
+
/** Whether a layer scales with its contents, as Figma's Scale tool and `rescale()` allow. */
|
|
7
|
+
declare function isRescalable(node: Pick<SceneNode, 'type'>): boolean;
|
|
8
|
+
/** A layer and every layer below it, root first, as the graph holds them now. */
|
|
9
|
+
declare function rescaleSubtree(graph: SceneGraph, root: SceneNode): SceneNode[];
|
|
10
|
+
/**
|
|
11
|
+
* What scaling `nodes`, a subtree as `rescaleSubtree` lists it, by `scale` changes in each layer,
|
|
12
|
+
* keeping the root's top-left; read from the given copies, so a preview can scale again from the
|
|
13
|
+
* layers as they were.
|
|
14
|
+
*/
|
|
15
|
+
declare function rescaleNodeTreeChanges(graph: SceneGraph, nodes: readonly SceneNode[], rootId: string, scale: number): Map<string, Partial<SceneNode>>;
|
|
16
|
+
/** Throws unless `scale` is a factor a layer can be scaled by. */
|
|
17
|
+
declare function assertRescaleFactor(scale: number): void;
|
|
18
|
+
/** Scale a node tree from the root node's top-left, matching Figma's Scale tool. */
|
|
19
|
+
declare function rescaleNodeTree(graph: SceneGraph, rootId: string, scale: number): void;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { MIN_RESCALE, assertRescaleFactor, isRescalable, rescaleNodeTree, rescaleNodeTreeChanges, rescaleSubtree };
|
|
22
|
+
//# sourceMappingURL=tree.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tree.d.ts","names":[],"sources":["../../src/scaling/tree.ts"],"mappings":";;;;cAOa;;iBAmBG,aAAa,MAAM,KAAK;;iBAKxB,eAAe,OAAO,YAAY,MAAM,YAAY;;;;;;iBAmBpD,uBACd,OAAO,YACP,gBAAgB,aAChB,gBACA,gBACC,YAAY,QAAQ;;iBAeP,oBAAoB;;iBAMpB,gBAAgB,OAAO,YAAY,gBAAgB"}
|
|
@@ -0,0 +1,71 @@
|
|
|
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
|
+
/** The smallest factor a layer scales by, so it never folds away. */
|
|
6
|
+
const MIN_RESCALE = .01;
|
|
7
|
+
const RESCALABLE_NODE_TYPES = /* @__PURE__ */ new Set([
|
|
8
|
+
"BOOLEAN_OPERATION",
|
|
9
|
+
"COMPONENT",
|
|
10
|
+
"COMPONENT_SET",
|
|
11
|
+
"ELLIPSE",
|
|
12
|
+
"FRAME",
|
|
13
|
+
"GROUP",
|
|
14
|
+
"INSTANCE",
|
|
15
|
+
"LINE",
|
|
16
|
+
"POLYGON",
|
|
17
|
+
"RECTANGLE",
|
|
18
|
+
"STAR",
|
|
19
|
+
"STICKY",
|
|
20
|
+
"TEXT",
|
|
21
|
+
"VECTOR"
|
|
22
|
+
]);
|
|
23
|
+
/** Whether a layer scales with its contents, as Figma's Scale tool and `rescale()` allow. */
|
|
24
|
+
function isRescalable(node) {
|
|
25
|
+
return RESCALABLE_NODE_TYPES.has(node.type);
|
|
26
|
+
}
|
|
27
|
+
/** A layer and every layer below it, root first, as the graph holds them now. */
|
|
28
|
+
function rescaleSubtree(graph, root) {
|
|
29
|
+
const nodes = [root];
|
|
30
|
+
const collect = (node) => {
|
|
31
|
+
for (const childId of node.childIds) {
|
|
32
|
+
const child = graph.getNode(childId);
|
|
33
|
+
if (!child) continue;
|
|
34
|
+
nodes.push(child);
|
|
35
|
+
collect(child);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
collect(root);
|
|
39
|
+
return nodes;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* What scaling `nodes`, a subtree as `rescaleSubtree` lists it, by `scale` changes in each layer,
|
|
43
|
+
* keeping the root's top-left; read from the given copies, so a preview can scale again from the
|
|
44
|
+
* layers as they were.
|
|
45
|
+
*/
|
|
46
|
+
function rescaleNodeTreeChanges(graph, nodes, rootId, scale) {
|
|
47
|
+
const changes = /* @__PURE__ */ new Map();
|
|
48
|
+
for (const node of nodes) changes.set(node.id, {
|
|
49
|
+
...scaleNodeChanges(node, scale, node.id !== rootId),
|
|
50
|
+
...scaleVariableBindingUnits(node, scale),
|
|
51
|
+
componentScale: findInstanceAncestor(graph, node.id) ? node.componentScale * scale : node.componentScale
|
|
52
|
+
});
|
|
53
|
+
return changes;
|
|
54
|
+
}
|
|
55
|
+
/** Throws unless `scale` is a factor a layer can be scaled by. */
|
|
56
|
+
function assertRescaleFactor(scale) {
|
|
57
|
+
if (!Number.isFinite(scale)) throw new TypeError("Scale must be a finite number");
|
|
58
|
+
if (scale < .01) throw new RangeError(`Scale must be at least ${MIN_RESCALE}`);
|
|
59
|
+
}
|
|
60
|
+
/** Scale a node tree from the root node's top-left, matching Figma's Scale tool. */
|
|
61
|
+
function rescaleNodeTree(graph, rootId, scale) {
|
|
62
|
+
assertRescaleFactor(scale);
|
|
63
|
+
const root = graph.getNode(rootId);
|
|
64
|
+
if (!root || !isRescalable(root)) throw new Error("rescale() is not supported on this node");
|
|
65
|
+
const nodes = rescaleSubtree(graph, root);
|
|
66
|
+
for (const [id, changes] of rescaleNodeTreeChanges(graph, nodes, rootId, scale)) graph.updateNode(id, changes);
|
|
67
|
+
}
|
|
68
|
+
//#endregion
|
|
69
|
+
export { MIN_RESCALE, assertRescaleFactor, isRescalable, rescaleNodeTree, rescaleNodeTreeChanges, rescaleSubtree };
|
|
70
|
+
|
|
71
|
+
//# 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\n/** The smallest factor a layer scales by, so it never folds away. */\nexport const MIN_RESCALE = 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/** Whether a layer scales with its contents, as Figma's Scale tool and `rescale()` allow. */\nexport function isRescalable(node: Pick<SceneNode, 'type'>): boolean {\n return RESCALABLE_NODE_TYPES.has(node.type)\n}\n\n/** A layer and every layer below it, root first, as the graph holds them now. */\nexport function rescaleSubtree(graph: SceneGraph, root: SceneNode): SceneNode[] {\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 return nodes\n}\n\n/**\n * What scaling `nodes`, a subtree as `rescaleSubtree` lists it, by `scale` changes in each layer,\n * keeping the root's top-left; read from the given copies, so a preview can scale again from the\n * layers as they were.\n */\nexport function rescaleNodeTreeChanges(\n graph: SceneGraph,\n nodes: readonly SceneNode[],\n rootId: string,\n scale: number\n): Map<string, Partial<SceneNode>> {\n const changes = new Map<string, Partial<SceneNode>>()\n for (const node of nodes) {\n changes.set(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 return changes\n}\n\n/** Throws unless `scale` is a factor a layer can be scaled by. */\nexport function assertRescaleFactor(scale: number): void {\n if (!Number.isFinite(scale)) throw new TypeError('Scale must be a finite number')\n if (scale < MIN_RESCALE) throw new RangeError(`Scale must be at least ${MIN_RESCALE}`)\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 assertRescaleFactor(scale)\n const root = graph.getNode(rootId)\n if (!root || !isRescalable(root)) throw new Error('rescale() is not supported on this node')\n const nodes = rescaleSubtree(graph, root)\n for (const [id, changes] of rescaleNodeTreeChanges(graph, nodes, rootId, scale)) {\n graph.updateNode(id, changes)\n }\n}\n"],"mappings":";;;;;AAOA,MAAa,cAAc;AAC3B,MAAM,wCAAwB,IAAI,IAAuB;CACvD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;;AAGD,SAAgB,aAAa,MAAwC;CACnE,OAAO,sBAAsB,IAAI,KAAK,IAAI;AAC5C;;AAGA,SAAgB,eAAe,OAAmB,MAA8B;CAC9E,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,OAAO;AACT;;;;;;AAOA,SAAgB,uBACd,OACA,OACA,QACA,OACiC;CACjC,MAAM,0BAAU,IAAI,IAAgC;CACpD,KAAK,MAAM,QAAQ,OACjB,QAAQ,IAAI,KAAK,IAAI;EACnB,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;CAEH,OAAO;AACT;;AAGA,SAAgB,oBAAoB,OAAqB;CACvD,IAAI,CAAC,OAAO,SAAS,KAAK,GAAG,MAAM,IAAI,UAAU,+BAA+B;CAChF,IAAI,QAAA,KAAqB,MAAM,IAAI,WAAW,0BAA0B,aAAa;AACvF;;AAGA,SAAgB,gBAAgB,OAAmB,QAAgB,OAAqB;CACtF,oBAAoB,KAAK;CACzB,MAAM,OAAO,MAAM,QAAQ,MAAM;CACjC,IAAI,CAAC,QAAQ,CAAC,aAAa,IAAI,GAAG,MAAM,IAAI,MAAM,yCAAyC;CAC3F,MAAM,QAAQ,eAAe,OAAO,IAAI;CACxC,KAAK,MAAM,CAAC,IAAI,YAAY,uBAAuB,OAAO,OAAO,QAAQ,KAAK,GAC5E,MAAM,WAAW,IAAI,OAAO;AAEhC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { SCRIPT_MAX_SOURCE_LENGTH, ScriptInputKind, ScriptInputValue, ScriptNodeData, resolveScriptInputs, scriptInputAccepts, scriptNodeSchema } from "./schema.js";
|
|
2
|
+
export { SCRIPT_MAX_SOURCE_LENGTH, ScriptInputKind, ScriptInputValue, ScriptNodeData, resolveScriptInputs, scriptInputAccepts, scriptNodeSchema };
|