@open-pencil/scene-graph 0.18.0-beta.1 → 0.18.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/arrow-caps.d.ts +14 -17
- package/dist/arrow-caps.d.ts.map +1 -1
- package/dist/arrow-caps.js +1 -2
- package/dist/asset-keys.d.ts +5 -8
- package/dist/asset-keys.d.ts.map +1 -1
- package/dist/asset-keys.js +2 -3
- package/dist/behaviours/index.d.ts +4 -3
- package/dist/behaviours/index.js +6 -5
- package/dist/behaviours/kinds.d.ts +38 -15
- package/dist/behaviours/kinds.d.ts.map +1 -1
- package/dist/behaviours/kinds.js +119 -4
- package/dist/behaviours/kinds.js.map +1 -1
- package/dist/behaviours/layers.d.ts +3 -6
- package/dist/behaviours/layers.d.ts.map +1 -1
- package/dist/behaviours/layers.js +1 -2
- package/dist/behaviours/listing.d.ts +58 -0
- package/dist/behaviours/listing.d.ts.map +1 -0
- package/dist/behaviours/listing.js +98 -0
- package/dist/behaviours/listing.js.map +1 -0
- package/dist/behaviours/model.d.ts +19 -16
- package/dist/behaviours/model.d.ts.map +1 -1
- package/dist/behaviours/model.js +14 -6
- package/dist/behaviours/model.js.map +1 -1
- package/dist/behaviours/schema.d.ts +16 -18
- package/dist/behaviours/schema.d.ts.map +1 -1
- package/dist/behaviours/schema.js +2 -3
- package/dist/behaviours/spec.d.ts +3 -6
- package/dist/behaviours/spec.d.ts.map +1 -1
- package/dist/behaviours/spec.js +4 -5
- package/dist/behaviours/transition.d.ts +6 -9
- package/dist/behaviours/transition.d.ts.map +1 -1
- package/dist/behaviours/transition.js +1 -2
- package/dist/bindings.js +2 -3
- package/dist/blur.d.ts +35 -0
- package/dist/blur.d.ts.map +1 -0
- package/dist/blur.js +69 -0
- package/dist/blur.js.map +1 -0
- package/dist/buffered-events.d.ts +3 -6
- package/dist/buffered-events.d.ts.map +1 -1
- package/dist/buffered-events.js +1 -2
- package/dist/buffered-events.js.map +1 -1
- package/dist/checkpoint.d.ts +3 -6
- package/dist/checkpoint.d.ts.map +1 -1
- package/dist/checkpoint.js +2 -3
- package/dist/clipping.d.ts +4 -7
- package/dist/clipping.d.ts.map +1 -1
- package/dist/clipping.js +4 -16
- package/dist/clipping.js.map +1 -1
- package/dist/color/contrast.d.ts +4 -7
- package/dist/color/contrast.d.ts.map +1 -1
- package/dist/color/contrast.js +2 -3
- package/dist/color/index.d.ts +13 -15
- package/dist/color/index.d.ts.map +1 -1
- package/dist/color/index.js +3 -4
- package/dist/color/management.d.ts +11 -14
- package/dist/color/management.d.ts.map +1 -1
- package/dist/color/management.js +2 -3
- package/dist/color/normalize.d.ts +1 -4
- package/dist/color/normalize.d.ts.map +1 -1
- package/dist/color/normalize.js +1 -2
- package/dist/color/okhcl.d.ts +16 -19
- package/dist/color/okhcl.d.ts.map +1 -1
- package/dist/color/okhcl.js +3 -4
- package/dist/color/schema.d.ts +4 -7
- package/dist/color/schema.d.ts.map +1 -1
- package/dist/color/schema.js +2 -3
- package/dist/comments/document.d.ts +3 -6
- package/dist/comments/document.d.ts.map +1 -1
- package/dist/comments/document.js +1 -2
- package/dist/comments/index.js +2 -2
- package/dist/comments/list.d.ts +5 -8
- package/dist/comments/list.d.ts.map +1 -1
- package/dist/comments/list.js +1 -2
- package/dist/comments/merge.d.ts +2 -5
- package/dist/comments/merge.d.ts.map +1 -1
- package/dist/comments/merge.js +1 -2
- package/dist/comments/schema.d.ts +2 -5
- package/dist/comments/schema.d.ts.map +1 -1
- package/dist/comments/schema.js +1 -2
- package/dist/comments/threads.d.ts +16 -19
- package/dist/comments/threads.d.ts.map +1 -1
- package/dist/comments/threads.js +8 -3
- package/dist/comments/threads.js.map +1 -1
- package/dist/components/exposure.d.ts +4 -7
- package/dist/components/exposure.d.ts.map +1 -1
- package/dist/components/exposure.js +1 -2
- package/dist/components/properties.d.ts +13 -16
- package/dist/components/properties.d.ts.map +1 -1
- package/dist/components/properties.js +3 -4
- package/dist/components/variants.d.ts +5 -8
- package/dist/components/variants.d.ts.map +1 -1
- package/dist/components/variants.js +1 -2
- package/dist/connectors/controls.d.ts +6 -9
- package/dist/connectors/controls.d.ts.map +1 -1
- package/dist/connectors/controls.js +2 -3
- package/dist/connectors/create.d.ts +3 -6
- package/dist/connectors/create.d.ts.map +1 -1
- package/dist/connectors/create.js +2 -3
- package/dist/connectors/elbow.js +0 -1
- package/dist/connectors/gaps.d.ts +1 -4
- package/dist/connectors/gaps.d.ts.map +1 -1
- package/dist/connectors/gaps.js +1 -2
- package/dist/connectors/hit.d.ts +1 -4
- package/dist/connectors/hit.d.ts.map +1 -1
- package/dist/connectors/hit.js +3 -4
- package/dist/connectors/index.d.ts +3 -3
- package/dist/connectors/index.js +6 -6
- package/dist/connectors/label.d.ts +4 -7
- package/dist/connectors/label.d.ts.map +1 -1
- package/dist/connectors/label.js +1 -2
- package/dist/connectors/layout.d.ts +8 -10
- package/dist/connectors/layout.d.ts.map +1 -1
- package/dist/connectors/layout.js +12 -10
- package/dist/connectors/layout.js.map +1 -1
- package/dist/connectors/pieces.d.ts +2 -5
- package/dist/connectors/pieces.d.ts.map +1 -1
- package/dist/connectors/pieces.js +3 -4
- package/dist/connectors/pieces.js.map +1 -1
- package/dist/connectors/route.d.ts +2 -5
- package/dist/connectors/route.d.ts.map +1 -1
- package/dist/connectors/route.js +4 -5
- package/dist/connectors/sides.d.ts +3 -6
- package/dist/connectors/sides.d.ts.map +1 -1
- package/dist/connectors/sides.js +2 -3
- package/dist/connectors/sublayers.d.ts +21 -24
- package/dist/connectors/sublayers.d.ts.map +1 -1
- package/dist/connectors/sublayers.js +3 -3
- package/dist/connectors/sublayers.js.map +1 -1
- package/dist/constants.d.ts +13 -16
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +1 -2
- package/dist/constraints.d.ts +6 -8
- package/dist/constraints.d.ts.map +1 -1
- package/dist/constraints.js +1 -2
- package/dist/coordinate.d.ts +27 -29
- package/dist/coordinate.d.ts.map +1 -1
- package/dist/coordinate.js +19 -38
- package/dist/coordinate.js.map +1 -1
- package/dist/copy.d.ts +31 -25
- package/dist/copy.d.ts.map +1 -1
- package/dist/copy.js +13 -5
- package/dist/copy.js.map +1 -1
- package/dist/corners.d.ts +8 -10
- package/dist/corners.d.ts.map +1 -1
- package/dist/corners.js +1 -2
- package/dist/css/blend.d.ts +1 -4
- package/dist/css/blend.d.ts.map +1 -1
- package/dist/css/blend.js +1 -2
- package/dist/css/grid.d.ts +1 -4
- package/dist/css/grid.d.ts.map +1 -1
- package/dist/css/grid.js +4 -5
- package/dist/css/index.js +2 -2
- package/dist/css/layout.d.ts +7 -10
- package/dist/css/layout.d.ts.map +1 -1
- package/dist/css/layout.js +2 -3
- package/dist/css/motion.d.ts +2 -5
- package/dist/css/motion.d.ts.map +1 -1
- package/dist/css/motion.js +2 -3
- package/dist/css/shadows.d.ts +1 -4
- package/dist/css/shadows.d.ts.map +1 -1
- package/dist/css/shadows.js +3 -4
- package/dist/css/text.d.ts +8 -11
- package/dist/css/text.d.ts.map +1 -1
- package/dist/css/text.js +1 -2
- package/dist/css/transform.d.ts +6 -9
- package/dist/css/transform.d.ts.map +1 -1
- package/dist/css/transform.js +2 -3
- package/dist/css/values.d.ts +9 -12
- package/dist/css/values.d.ts.map +1 -1
- package/dist/css/values.js +2 -3
- package/dist/cubic.d.ts +11 -5
- package/dist/cubic.d.ts.map +1 -1
- package/dist/cubic.js +71 -3
- package/dist/cubic.js.map +1 -1
- package/dist/events.js +1 -2
- package/dist/export-format.d.ts +5 -8
- package/dist/export-format.d.ts.map +1 -1
- package/dist/export-format.js +4 -3
- package/dist/export-format.js.map +1 -1
- package/dist/export-scale.d.ts +4 -7
- package/dist/export-scale.d.ts.map +1 -1
- package/dist/export-scale.js +1 -2
- package/dist/fields/appearance.d.ts +3 -6
- package/dist/fields/appearance.d.ts.map +1 -1
- package/dist/fields/appearance.js +1 -2
- package/dist/fields/geometry.d.ts +2 -5
- package/dist/fields/geometry.d.ts.map +1 -1
- package/dist/fields/geometry.js +1 -2
- package/dist/fields/index.js +1 -1
- package/dist/fields/layout.d.ts +4 -7
- package/dist/fields/layout.d.ts.map +1 -1
- package/dist/fields/layout.js +1 -2
- package/dist/fields/text.d.ts +5 -8
- package/dist/fields/text.d.ts.map +1 -1
- package/dist/fields/text.js +1 -2
- package/dist/fig-compression.d.ts +3 -6
- package/dist/fig-compression.d.ts.map +1 -1
- package/dist/fig-compression.js +1 -2
- package/dist/figjam/index.js +1 -1
- package/dist/figjam/palette.d.ts +21 -23
- package/dist/figjam/palette.d.ts.map +1 -1
- package/dist/figjam/palette.js +3 -4
- package/dist/figjam/text.d.ts +10 -13
- package/dist/figjam/text.d.ts.map +1 -1
- package/dist/figjam/text.js +1 -2
- package/dist/font-style.d.ts +18 -18
- package/dist/font-style.d.ts.map +1 -1
- package/dist/font-style.js +5 -5
- package/dist/font-style.js.map +1 -1
- package/dist/generated/index.d.ts +32 -16
- package/dist/generated/index.d.ts.map +1 -1
- package/dist/generated/index.js +37 -9
- package/dist/generated/index.js.map +1 -1
- package/dist/generated/kind.d.ts +17 -6
- package/dist/generated/kind.d.ts.map +1 -1
- package/dist/generated/shape-with-text.d.ts +10 -13
- package/dist/generated/shape-with-text.d.ts.map +1 -1
- package/dist/generated/shape-with-text.js +3 -3
- package/dist/generated/shape-with-text.js.map +1 -1
- package/dist/generated/spec.d.ts +45 -0
- package/dist/generated/spec.d.ts.map +1 -0
- package/dist/generated/spec.js +281 -0
- package/dist/generated/spec.js.map +1 -0
- package/dist/generated/sticky.d.ts +23 -26
- package/dist/generated/sticky.d.ts.map +1 -1
- package/dist/generated/sticky.js +4 -4
- package/dist/generated/sticky.js.map +1 -1
- package/dist/geometry.d.ts +43 -69
- package/dist/geometry.d.ts.map +1 -1
- package/dist/geometry.js +44 -76
- package/dist/geometry.js.map +1 -1
- package/dist/gradient.d.ts +15 -18
- package/dist/gradient.d.ts.map +1 -1
- package/dist/gradient.js +1 -2
- package/dist/graph.d.ts +4 -7
- package/dist/graph.d.ts.map +1 -1
- package/dist/graph.js +26 -19
- package/dist/graph.js.map +1 -1
- package/dist/group-bounds.d.ts +10 -12
- package/dist/group-bounds.d.ts.map +1 -1
- package/dist/group-bounds.js +5 -6
- package/dist/guides.d.ts +5 -8
- package/dist/guides.d.ts.map +1 -1
- package/dist/guides.js +2 -3
- package/dist/hit-test.d.ts +20 -12
- package/dist/hit-test.d.ts.map +1 -1
- package/dist/hit-test.js +51 -31
- package/dist/hit-test.js.map +1 -1
- package/dist/icons/fit.d.ts +2 -4
- package/dist/icons/fit.d.ts.map +1 -1
- package/dist/icons/fit.js +1 -2
- package/dist/icons/glyph.d.ts +3 -5
- package/dist/icons/glyph.d.ts.map +1 -1
- package/dist/icons/glyph.js +3 -4
- package/dist/icons/index.d.ts +1 -1
- package/dist/icons/index.js +2 -2
- package/dist/icons/model.d.ts +8 -11
- package/dist/icons/model.d.ts.map +1 -1
- package/dist/icons/model.js +1 -2
- package/dist/icons/schema.d.ts +8 -11
- package/dist/icons/schema.d.ts.map +1 -1
- package/dist/icons/schema.js +1 -2
- package/dist/ids.d.ts +2 -5
- package/dist/ids.d.ts.map +1 -1
- package/dist/ids.js +3 -4
- package/dist/images.d.ts +20 -21
- package/dist/images.d.ts.map +1 -1
- package/dist/images.js +7 -6
- package/dist/images.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -3
- package/dist/instances/assignments.js +1 -2
- package/dist/instances/content-marks.js +98 -0
- package/dist/instances/content-marks.js.map +1 -0
- package/dist/instances/content-size.js +3 -4
- package/dist/instances/copies.js +2 -3
- package/dist/instances/cycles.d.ts +3 -6
- package/dist/instances/cycles.d.ts.map +1 -1
- package/dist/instances/cycles.js +1 -2
- package/dist/instances/deleted.d.ts +23 -0
- package/dist/instances/deleted.d.ts.map +1 -0
- package/dist/instances/deleted.js +82 -0
- package/dist/instances/deleted.js.map +1 -0
- package/dist/instances/fields.d.ts +5 -8
- package/dist/instances/fields.d.ts.map +1 -1
- package/dist/instances/fields.js +9 -7
- package/dist/instances/fields.js.map +1 -1
- package/dist/instances/index.d.ts +21 -20
- package/dist/instances/index.d.ts.map +1 -1
- package/dist/instances/index.js +69 -12
- package/dist/instances/index.js.map +1 -1
- package/dist/instances/kept-overrides.js +4 -5
- package/dist/instances/lookup.d.ts +17 -0
- package/dist/instances/lookup.d.ts.map +1 -0
- package/dist/instances/lookup.js +48 -0
- package/dist/instances/lookup.js.map +1 -0
- package/dist/instances/main-component.d.ts +2 -5
- package/dist/instances/main-component.d.ts.map +1 -1
- package/dist/instances/main-component.js +1 -2
- package/dist/instances/matching.js +1 -2
- package/dist/instances/overrides.d.ts +23 -26
- package/dist/instances/overrides.d.ts.map +1 -1
- package/dist/instances/overrides.js +1 -2
- package/dist/instances/placement.js +3 -4
- package/dist/instances/protection.js +3 -4
- package/dist/instances/source-walk.js +1 -2
- package/dist/instances/swap.js +7 -8
- package/dist/instances/sync.js +27 -14
- package/dist/instances/sync.js.map +1 -1
- package/dist/instances/vector-geometry.js +2 -3
- package/dist/layout/aspect-ratio.d.ts +7 -9
- package/dist/layout/aspect-ratio.d.ts.map +1 -1
- package/dist/layout/aspect-ratio.js +1 -2
- package/dist/layout/flow.d.ts +3 -6
- package/dist/layout/flow.d.ts.map +1 -1
- package/dist/layout/flow.js +6 -5
- package/dist/layout/flow.js.map +1 -1
- package/dist/layout/guides.d.ts +13 -16
- package/dist/layout/guides.d.ts.map +1 -1
- package/dist/layout/guides.js +4 -5
- package/dist/layout/guides.js.map +1 -1
- package/dist/layout/index.d.ts +3 -2
- package/dist/layout/index.js +6 -5
- package/dist/layout/keywords.d.ts +7 -9
- package/dist/layout/keywords.d.ts.map +1 -1
- package/dist/layout/keywords.js +1 -2
- package/dist/layout/limits.d.ts +13 -16
- package/dist/layout/limits.d.ts.map +1 -1
- package/dist/layout/limits.js +1 -2
- package/dist/layout/sizing.d.ts +11 -13
- package/dist/layout/sizing.d.ts.map +1 -1
- package/dist/layout/sizing.js +1 -2
- package/dist/layout/spacing.d.ts +2 -5
- package/dist/layout/spacing.d.ts.map +1 -1
- package/dist/layout/spacing.js +1 -2
- package/dist/layout/stacking.d.ts +8 -0
- package/dist/layout/stacking.d.ts.map +1 -0
- package/dist/layout/stacking.js +12 -0
- package/dist/layout/stacking.js.map +1 -0
- package/dist/layout/strokes.d.ts +1 -4
- package/dist/layout/strokes.d.ts.map +1 -1
- package/dist/layout/strokes.js +1 -2
- package/dist/layout/writes.js +1 -2
- package/dist/layout/writes.js.map +1 -1
- package/dist/masks.d.ts +4 -7
- package/dist/masks.d.ts.map +1 -1
- package/dist/masks.js +1 -2
- package/dist/matrix.d.ts +3 -4
- package/dist/matrix.d.ts.map +1 -1
- package/dist/matrix.js +11 -3
- package/dist/matrix.js.map +1 -1
- package/dist/mesh/geometry.d.ts +21 -24
- package/dist/mesh/geometry.d.ts.map +1 -1
- package/dist/mesh/geometry.js +3 -14
- package/dist/mesh/geometry.js.map +1 -1
- package/dist/mesh/index.d.ts +1 -1
- package/dist/mesh/index.js +1 -1
- package/dist/mesh/model.d.ts +5 -8
- package/dist/mesh/model.d.ts.map +1 -1
- package/dist/mesh/model.js +2 -3
- package/dist/mesh/schema.d.ts +10 -13
- package/dist/mesh/schema.d.ts.map +1 -1
- package/dist/mesh/schema.js +3 -4
- package/dist/motion/apply.d.ts +42 -0
- package/dist/motion/apply.d.ts.map +1 -0
- package/dist/motion/apply.js +98 -0
- package/dist/motion/apply.js.map +1 -0
- package/dist/motion/edit.d.ts +53 -0
- package/dist/motion/edit.d.ts.map +1 -0
- package/dist/motion/edit.js +125 -0
- package/dist/motion/edit.js.map +1 -0
- package/dist/motion/effects.js +86 -0
- package/dist/motion/effects.js.map +1 -0
- package/dist/motion/evaluate.d.ts +33 -0
- package/dist/motion/evaluate.d.ts.map +1 -0
- package/dist/motion/evaluate.js +160 -0
- package/dist/motion/evaluate.js.map +1 -0
- package/dist/motion/fields.d.ts +69 -0
- package/dist/motion/fields.d.ts.map +1 -0
- package/dist/motion/fields.js +132 -0
- package/dist/motion/fields.js.map +1 -0
- package/dist/motion/index.d.ts +16 -0
- package/dist/motion/index.js +15 -0
- package/dist/motion/keyable.d.ts +32 -0
- package/dist/motion/keyable.d.ts.map +1 -0
- package/dist/motion/keyable.js +120 -0
- package/dist/motion/keyable.js.map +1 -0
- package/dist/motion/outline.d.ts +35 -0
- package/dist/motion/outline.d.ts.map +1 -0
- package/dist/motion/outline.js +59 -0
- package/dist/motion/outline.js.map +1 -0
- package/dist/motion/presets/index.d.ts +20 -0
- package/dist/motion/presets/index.d.ts.map +1 -0
- package/dist/motion/presets/index.js +166 -0
- package/dist/motion/presets/index.js.map +1 -0
- package/dist/motion/presets/settings.d.ts +43 -0
- package/dist/motion/presets/settings.d.ts.map +1 -0
- package/dist/motion/presets/settings.js +254 -0
- package/dist/motion/presets/settings.js.map +1 -0
- package/dist/motion/presets/stagger.d.ts +69 -0
- package/dist/motion/presets/stagger.d.ts.map +1 -0
- package/dist/motion/presets/stagger.js +185 -0
- package/dist/motion/presets/stagger.js.map +1 -0
- package/dist/motion/schema.d.ts +185 -0
- package/dist/motion/schema.d.ts.map +1 -0
- package/dist/motion/schema.js +62 -0
- package/dist/motion/schema.js.map +1 -0
- package/dist/motion/segment.d.ts +25 -0
- package/dist/motion/segment.d.ts.map +1 -0
- package/dist/motion/segment.js +73 -0
- package/dist/motion/segment.js.map +1 -0
- package/dist/motion/spec.d.ts +26 -0
- package/dist/motion/spec.d.ts.map +1 -0
- package/dist/motion/spec.js +175 -0
- package/dist/motion/spec.js.map +1 -0
- package/dist/motion/timeline.d.ts +16 -0
- package/dist/motion/timeline.d.ts.map +1 -0
- package/dist/motion/timeline.js +53 -0
- package/dist/motion/timeline.js.map +1 -0
- package/dist/motion/types.d.ts +49 -0
- package/dist/motion/types.d.ts.map +1 -0
- package/dist/motion/variables.d.ts +9 -0
- package/dist/motion/variables.d.ts.map +1 -0
- package/dist/motion/variables.js +25 -0
- package/dist/motion/variables.js.map +1 -0
- package/dist/mutation-impact.d.ts +7 -10
- package/dist/mutation-impact.d.ts.map +1 -1
- package/dist/mutation-impact.js +2 -3
- package/dist/node-defaults.d.ts +14 -15
- package/dist/node-defaults.d.ts.map +1 -1
- package/dist/node-defaults.js +133 -51
- package/dist/node-defaults.js.map +1 -1
- package/dist/order-keys.d.ts +8 -9
- package/dist/order-keys.d.ts.map +1 -1
- package/dist/order-keys.js +10 -2
- package/dist/order-keys.js.map +1 -1
- package/dist/outline/flatten.d.ts +3 -6
- package/dist/outline/flatten.d.ts.map +1 -1
- package/dist/outline/flatten.js +3 -4
- package/dist/outline/heads.js +1 -2
- package/dist/outline/hit.d.ts +2 -5
- package/dist/outline/hit.d.ts.map +1 -1
- package/dist/outline/hit.js +5 -6
- package/dist/outline/index.js +3 -3
- package/dist/outline/point.d.ts +4 -7
- package/dist/outline/point.d.ts.map +1 -1
- package/dist/outline/point.js +2 -3
- package/dist/outline/shapes.d.ts +4 -7
- package/dist/outline/shapes.d.ts.map +1 -1
- package/dist/outline/shapes.js +2 -3
- package/dist/paints/index.d.ts +2 -2
- package/dist/paints/index.js +4 -4
- package/dist/paints/pattern.d.ts +6 -9
- package/dist/paints/pattern.d.ts.map +1 -1
- package/dist/paints/pattern.js +1 -2
- package/dist/paints/schema.d.ts +4 -7
- package/dist/paints/schema.d.ts.map +1 -1
- package/dist/paints/schema.js +3 -4
- package/dist/paints/shows.d.ts +3 -6
- package/dist/paints/shows.d.ts.map +1 -1
- package/dist/paints/shows.js +1 -2
- package/dist/paints/solid.d.ts +1 -4
- package/dist/paints/solid.d.ts.map +1 -1
- package/dist/paints/solid.js +1 -2
- package/dist/paints/stills.d.ts +17 -17
- package/dist/paints/stills.d.ts.map +1 -1
- package/dist/paints/stills.js +22 -18
- package/dist/paints/stills.js.map +1 -1
- package/dist/parse-path.d.ts +12 -9
- package/dist/parse-path.d.ts.map +1 -1
- package/dist/parse-path.js +13 -3
- package/dist/parse-path.js.map +1 -1
- package/dist/paths/arc.d.ts +6 -9
- package/dist/paths/arc.d.ts.map +1 -1
- package/dist/paths/arc.js +1 -2
- package/dist/paths/index.d.ts +1 -1
- package/dist/paths/index.js +1 -1
- package/dist/paths/network.d.ts +13 -16
- package/dist/paths/network.d.ts.map +1 -1
- package/dist/paths/network.js +1 -2
- package/dist/paths/sink.d.ts +5 -8
- package/dist/paths/sink.d.ts.map +1 -1
- package/dist/paths/sink.js +1 -2
- package/dist/paths/smooth-corners.d.ts +3 -6
- package/dist/paths/smooth-corners.d.ts.map +1 -1
- package/dist/paths/smooth-corners.js +1 -2
- package/dist/plugin-data/field.d.ts +15 -18
- package/dist/plugin-data/field.d.ts.map +1 -1
- package/dist/plugin-data/field.js +1 -2
- package/dist/plugin-data/fields.d.ts +37 -11
- package/dist/plugin-data/fields.d.ts.map +1 -1
- package/dist/plugin-data/fields.js +35 -10
- package/dist/plugin-data/fields.js.map +1 -1
- package/dist/plugin-data/index.d.ts +2 -2
- package/dist/plugin-data/index.js +2 -2
- package/dist/polygon.d.ts +8 -8
- package/dist/polygon.d.ts.map +1 -1
- package/dist/polygon.js +7 -7
- package/dist/polygon.js.map +1 -1
- package/dist/preview.d.ts +3 -5
- package/dist/preview.d.ts.map +1 -1
- package/dist/preview.js +2 -3
- package/dist/primitives/index.d.ts +7 -9
- package/dist/primitives/index.d.ts.map +1 -1
- package/dist/primitives/index.js +1 -2
- package/dist/primitives/schema.d.ts +3 -6
- package/dist/primitives/schema.d.ts.map +1 -1
- package/dist/primitives/schema.js +1 -2
- package/dist/resize.d.ts +13 -15
- package/dist/resize.d.ts.map +1 -1
- package/dist/resize.js +5 -6
- package/dist/scaling/node.d.ts +2 -5
- package/dist/scaling/node.d.ts.map +1 -1
- package/dist/scaling/node.js +4 -5
- package/dist/scaling/snapshot.d.ts +5 -8
- package/dist/scaling/snapshot.d.ts.map +1 -1
- package/dist/scaling/snapshot.js +1 -2
- package/dist/scaling/tree.d.ts +6 -9
- package/dist/scaling/tree.d.ts.map +1 -1
- package/dist/scaling/tree.js +2 -3
- package/dist/shaders/index.d.ts +2 -2
- package/dist/shaders/index.js +2 -2
- package/dist/shaders/model.d.ts +54 -13
- package/dist/shaders/model.d.ts.map +1 -1
- package/dist/shaders/model.js +98 -7
- package/dist/shaders/model.js.map +1 -1
- package/dist/shaders/schema.d.ts +15 -8
- package/dist/shaders/schema.d.ts.map +1 -1
- package/dist/shaders/schema.js +11 -2
- package/dist/shaders/schema.js.map +1 -1
- package/dist/shape-with-text/document.js +9 -21
- package/dist/shape-with-text/document.js.map +1 -1
- package/dist/shape-with-text/fit.d.ts +6 -9
- package/dist/shape-with-text/fit.d.ts.map +1 -1
- package/dist/shape-with-text/fit.js +1 -2
- package/dist/shape-with-text/geometry.d.ts +7 -10
- package/dist/shape-with-text/geometry.d.ts.map +1 -1
- package/dist/shape-with-text/geometry.js +4 -7
- package/dist/shape-with-text/geometry.js.map +1 -1
- package/dist/shape-with-text/index.js +1 -1
- package/dist/shape-with-text/kinds.d.ts +4 -7
- package/dist/shape-with-text/kinds.d.ts.map +1 -1
- package/dist/shape-with-text/kinds.js +1 -2
- package/dist/shared-style-index.d.ts +2 -4
- package/dist/shared-style-index.d.ts.map +1 -1
- package/dist/shared-style-index.js +1 -2
- package/dist/shared-style-index.js.map +1 -1
- package/dist/shared-styles.d.ts +17 -19
- package/dist/shared-styles.d.ts.map +1 -1
- package/dist/shared-styles.js +5 -6
- package/dist/slides/drop.d.ts +5 -8
- package/dist/slides/drop.d.ts.map +1 -1
- package/dist/slides/drop.js +1 -2
- package/dist/slides/index.d.ts +19 -19
- package/dist/slides/index.d.ts.map +1 -1
- package/dist/slides/index.js +8 -5
- package/dist/slides/index.js.map +1 -1
- package/dist/slides/motion.d.ts +32 -16
- package/dist/slides/motion.d.ts.map +1 -1
- package/dist/slides/motion.js +30 -5
- package/dist/slides/motion.js.map +1 -1
- package/dist/slides/playback.d.ts +24 -21
- package/dist/slides/playback.d.ts.map +1 -1
- package/dist/slides/playback.js +45 -13
- package/dist/slides/playback.js.map +1 -1
- package/dist/slides/types.d.ts +8 -11
- package/dist/slides/types.d.ts.map +1 -1
- package/dist/slides/types.js +1 -2
- package/dist/slots/authoring.d.ts +6 -9
- package/dist/slots/authoring.d.ts.map +1 -1
- package/dist/slots/authoring.js +2 -3
- package/dist/slots/content.d.ts +5 -8
- package/dist/slots/content.d.ts.map +1 -1
- package/dist/slots/content.js +4 -5
- package/dist/slots/frames.d.ts +7 -9
- package/dist/slots/frames.d.ts.map +1 -1
- package/dist/slots/frames.js +3 -4
- package/dist/slots/frames.js.map +1 -1
- package/dist/slots/index.js +1 -1
- package/dist/slots/limits.d.ts +4 -7
- package/dist/slots/limits.d.ts.map +1 -1
- package/dist/slots/limits.js +1 -2
- package/dist/snap.d.ts +4 -7
- package/dist/snap.d.ts.map +1 -1
- package/dist/snap.js +7 -8
- package/dist/source-metadata.d.ts +1 -4
- package/dist/source-metadata.d.ts.map +1 -1
- package/dist/source-metadata.js +1 -2
- package/dist/specs/index.d.ts +3 -0
- package/dist/specs/index.js +3 -0
- package/dist/specs/model.d.ts +20 -0
- package/dist/specs/model.d.ts.map +1 -0
- package/dist/specs/model.js +32 -0
- package/dist/specs/model.js.map +1 -0
- package/dist/specs/schema.d.ts +24 -0
- package/dist/specs/schema.d.ts.map +1 -0
- package/dist/specs/schema.js +32 -0
- package/dist/specs/schema.js.map +1 -0
- package/dist/statuses/impact.d.ts +2 -5
- package/dist/statuses/impact.d.ts.map +1 -1
- package/dist/statuses/impact.js +2 -3
- package/dist/statuses/index.d.ts +1 -1
- package/dist/statuses/index.js +2 -2
- package/dist/statuses/node.d.ts +4 -7
- package/dist/statuses/node.d.ts.map +1 -1
- package/dist/statuses/node.js +1 -2
- package/dist/statuses/schema.d.ts +7 -9
- package/dist/statuses/schema.d.ts.map +1 -1
- package/dist/statuses/schema.js +1 -2
- package/dist/statuses/workflow.d.ts +9 -12
- package/dist/statuses/workflow.d.ts.map +1 -1
- package/dist/statuses/workflow.js +1 -2
- package/dist/strokes.d.ts +8 -10
- package/dist/strokes.d.ts.map +1 -1
- package/dist/strokes.js +2 -3
- package/dist/text/auto-resize.d.ts +4 -6
- package/dist/text/auto-resize.d.ts.map +1 -1
- package/dist/text/auto-resize.js +1 -2
- package/dist/text/direction.d.ts +5 -8
- package/dist/text/direction.d.ts.map +1 -1
- package/dist/text/direction.js +1 -2
- package/dist/text/index.d.ts +2 -2
- package/dist/text/index.js +5 -5
- package/dist/text/lengths.d.ts +9 -12
- package/dist/text/lengths.d.ts.map +1 -1
- package/dist/text/lengths.js +1 -2
- package/dist/text/lists.d.ts +17 -13
- package/dist/text/lists.d.ts.map +1 -1
- package/dist/text/lists.js +15 -4
- package/dist/text/lists.js.map +1 -1
- package/dist/text/name.d.ts +4 -7
- package/dist/text/name.d.ts.map +1 -1
- package/dist/text/name.js +1 -2
- package/dist/text/overflow.d.ts +5 -7
- package/dist/text/overflow.d.ts.map +1 -1
- package/dist/text/overflow.js +1 -2
- package/dist/text/paragraphs.d.ts +20 -23
- package/dist/text/paragraphs.d.ts.map +1 -1
- package/dist/text/paragraphs.js +8 -5
- package/dist/text/paragraphs.js.map +1 -1
- package/dist/text/path.js +1 -2
- package/dist/text/picture.d.ts +3 -6
- package/dist/text/picture.d.ts.map +1 -1
- package/dist/text/picture.js +2 -3
- package/dist/text/references.d.ts +3 -6
- package/dist/text/references.d.ts.map +1 -1
- package/dist/text/references.js +1 -2
- package/dist/text/runs.d.ts +6 -9
- package/dist/text/runs.d.ts.map +1 -1
- package/dist/text/runs.js +1 -2
- package/dist/text/schema.d.ts +1 -4
- package/dist/text/schema.d.ts.map +1 -1
- package/dist/text/schema.js +1 -2
- package/dist/thumbnail.d.ts +4 -7
- package/dist/thumbnail.d.ts.map +1 -1
- package/dist/thumbnail.js +1 -2
- package/dist/transfer/apply.d.ts +2 -5
- package/dist/transfer/apply.d.ts.map +1 -1
- package/dist/transfer/apply.js +2 -3
- package/dist/transfer/copied.d.ts +5 -8
- package/dist/transfer/copied.d.ts.map +1 -1
- package/dist/transfer/copied.js +3 -4
- package/dist/transfer/dependencies.d.ts +6 -9
- package/dist/transfer/dependencies.d.ts.map +1 -1
- package/dist/transfer/dependencies.js +13 -11
- package/dist/transfer/dependencies.js.map +1 -1
- package/dist/transfer/history.d.ts +1 -4
- package/dist/transfer/history.d.ts.map +1 -1
- package/dist/transfer/history.js +1 -2
- package/dist/transfer/identity.js +1 -2
- package/dist/transfer/index.d.ts +3 -3
- package/dist/transfer/index.js +6 -6
- package/dist/transfer/library.d.ts +5 -7
- package/dist/transfer/library.d.ts.map +1 -1
- package/dist/transfer/library.js +32 -12
- package/dist/transfer/library.js.map +1 -1
- package/dist/transfer/nodes.d.ts +2 -5
- package/dist/transfer/nodes.d.ts.map +1 -1
- package/dist/transfer/nodes.js +8 -6
- package/dist/transfer/nodes.js.map +1 -1
- package/dist/transfer/plan.d.ts +2 -5
- package/dist/transfer/plan.d.ts.map +1 -1
- package/dist/transfer/plan.js +2 -3
- package/dist/transfer/references.js +1 -2
- package/dist/transfer/remove.d.ts +1 -4
- package/dist/transfer/remove.d.ts.map +1 -1
- package/dist/transfer/remove.js +2 -3
- package/dist/transfer/resources.d.ts +2 -5
- package/dist/transfer/resources.d.ts.map +1 -1
- package/dist/transfer/resources.js +3 -4
- package/dist/transfer/validation.js +1 -2
- package/dist/transfer/variables.d.ts +3 -6
- package/dist/transfer/variables.d.ts.map +1 -1
- package/dist/transfer/variables.js +2 -3
- package/dist/types.d.ts +191 -142
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +15 -3
- package/dist/types.js.map +1 -1
- package/dist/undo.d.ts +5 -8
- package/dist/undo.d.ts.map +1 -1
- package/dist/undo.js +9 -3
- package/dist/undo.js.map +1 -1
- package/dist/variables/bindings.d.ts +24 -25
- package/dist/variables/bindings.d.ts.map +1 -1
- package/dist/variables/bindings.js +28 -23
- package/dist/variables/bindings.js.map +1 -1
- package/dist/variables/corners.d.ts +1 -4
- package/dist/variables/corners.d.ts.map +1 -1
- package/dist/variables/corners.js +1 -2
- package/dist/variables/easing.d.ts +24 -19
- package/dist/variables/easing.d.ts.map +1 -1
- package/dist/variables/easing.js +17 -17
- package/dist/variables/easing.js.map +1 -1
- package/dist/variables/fields.d.ts +21 -14
- package/dist/variables/fields.d.ts.map +1 -1
- package/dist/variables/fields.js +24 -6
- package/dist/variables/fields.js.map +1 -1
- package/dist/variables/formula/check.d.ts +2 -5
- package/dist/variables/formula/check.d.ts.map +1 -1
- package/dist/variables/formula/check.js +2 -3
- package/dist/variables/formula/evaluate.d.ts +1 -4
- package/dist/variables/formula/evaluate.d.ts.map +1 -1
- package/dist/variables/formula/evaluate.js +3 -4
- package/dist/variables/formula/index.d.ts +6 -8
- package/dist/variables/formula/index.d.ts.map +1 -1
- package/dist/variables/formula/index.js +4 -5
- package/dist/variables/formula/parse.js +5 -6
- package/dist/variables/formula/print.d.ts +2 -5
- package/dist/variables/formula/print.d.ts.map +1 -1
- package/dist/variables/formula/print.js +4 -5
- package/dist/variables/formula/schema.d.ts +2 -5
- package/dist/variables/formula/schema.d.ts.map +1 -1
- package/dist/variables/formula/schema.js +5 -6
- package/dist/variables/formula/signatures.d.ts +3 -6
- package/dist/variables/formula/signatures.d.ts.map +1 -1
- package/dist/variables/formula/signatures.js +1 -2
- package/dist/variables/formula/tokens.d.ts +5 -8
- package/dist/variables/formula/tokens.d.ts.map +1 -1
- package/dist/variables/formula/tokens.js +1 -2
- package/dist/variables/formula/tree.d.ts +6 -9
- package/dist/variables/formula/tree.d.ts.map +1 -1
- package/dist/variables/formula/tree.js +1 -2
- package/dist/variables/formula/tree.js.map +1 -1
- package/dist/variables/index.d.ts +30 -32
- package/dist/variables/index.d.ts.map +1 -1
- package/dist/variables/index.js +17 -18
- package/dist/variables/lookup.d.ts +11 -7
- package/dist/variables/lookup.d.ts.map +1 -1
- package/dist/variables/lookup.js +24 -3
- package/dist/variables/lookup.js.map +1 -1
- package/dist/variables/motion.d.ts +9 -12
- package/dist/variables/motion.d.ts.map +1 -1
- package/dist/variables/motion.js +3 -4
- package/dist/variables/paints.d.ts +18 -20
- package/dist/variables/paints.d.ts.map +1 -1
- package/dist/variables/paints.js +4 -5
- package/dist/variables/resolution.d.ts +22 -19
- package/dist/variables/resolution.d.ts.map +1 -1
- package/dist/variables/resolution.js +13 -5
- package/dist/variables/resolution.js.map +1 -1
- package/dist/variables/schema.d.ts +9 -12
- package/dist/variables/schema.d.ts.map +1 -1
- package/dist/variables/schema.js +3 -4
- package/dist/variables/style-bindings.d.ts +11 -13
- package/dist/variables/style-bindings.d.ts.map +1 -1
- package/dist/variables/style-bindings.js +2 -3
- package/dist/variables/subtree.js +1 -2
- package/dist/variables/text.d.ts +2 -5
- package/dist/variables/text.d.ts.map +1 -1
- package/dist/variables/text.js +3 -4
- package/dist/variables/token.d.ts +5 -8
- package/dist/variables/token.d.ts.map +1 -1
- package/dist/variables/token.js +1 -2
- package/dist/variables/units.js +3 -5
- package/dist/variables/units.js.map +1 -1
- package/dist/variables/value.d.ts +4 -7
- package/dist/variables/value.d.ts.map +1 -1
- package/dist/variables/value.js +4 -5
- package/dist/variant-name.d.ts +2 -5
- package/dist/variant-name.d.ts.map +1 -1
- package/dist/variant-name.js +1 -2
- package/dist/variant-properties.d.ts +4 -7
- package/dist/variant-properties.d.ts.map +1 -1
- package/dist/variant-properties.js +2 -3
- package/dist/vector-network.d.ts +17 -20
- package/dist/vector-network.d.ts.map +1 -1
- package/dist/vector-network.js +4 -5
- package/package.json +23 -5
- package/src/behaviours/index.ts +1 -0
- package/src/behaviours/kinds.ts +103 -1
- package/src/behaviours/listing.ts +142 -0
- package/src/behaviours/model.ts +21 -0
- package/src/blur.ts +88 -0
- package/src/clipping.ts +3 -4
- package/src/comments/threads.ts +8 -1
- package/src/connectors/layout.ts +10 -3
- package/src/connectors/sublayers.ts +2 -1
- package/src/coordinate.ts +17 -25
- package/src/copy.ts +15 -6
- package/src/cubic.ts +57 -1
- package/src/export-format.ts +11 -1
- package/src/font-style.ts +12 -4
- package/src/generated/index.ts +43 -6
- package/src/generated/kind.ts +16 -2
- package/src/generated/shape-with-text.ts +1 -0
- package/src/generated/spec.ts +243 -0
- package/src/generated/sticky.ts +2 -1
- package/src/geometry.ts +39 -88
- package/src/graph.ts +21 -6
- package/src/hit-test.ts +66 -26
- package/src/images.ts +4 -1
- package/src/instances/content-marks.ts +124 -0
- package/src/instances/deleted.ts +115 -0
- package/src/instances/fields.ts +7 -3
- package/src/instances/index.ts +94 -5
- package/src/instances/lookup.ts +61 -0
- package/src/instances/sync.ts +15 -0
- package/src/layout/flow.ts +5 -3
- package/src/layout/index.ts +1 -0
- package/src/layout/stacking.ts +14 -0
- package/src/matrix.ts +11 -1
- package/src/mesh/geometry.ts +2 -13
- package/src/motion/apply.ts +156 -0
- package/src/motion/edit.ts +148 -0
- package/src/motion/effects.ts +166 -0
- package/src/motion/evaluate.ts +181 -0
- package/src/motion/fields.ts +136 -0
- package/src/motion/index.ts +13 -0
- package/src/motion/keyable.ts +141 -0
- package/src/motion/outline.ts +72 -0
- package/src/motion/presets/index.ts +257 -0
- package/src/motion/presets/settings.ts +221 -0
- package/src/motion/presets/stagger.ts +242 -0
- package/src/motion/schema.ts +66 -0
- package/src/motion/segment.ts +83 -0
- package/src/motion/spec.ts +225 -0
- package/src/motion/timeline.ts +48 -0
- package/src/motion/types.ts +45 -0
- package/src/motion/variables.ts +33 -0
- package/src/node-defaults.ts +131 -49
- package/src/order-keys.ts +16 -2
- package/src/paints/stills.ts +16 -12
- package/src/parse-path.ts +15 -0
- package/src/plugin-data/fields.ts +40 -3
- package/src/polygon.ts +6 -4
- package/src/shaders/model.ts +124 -6
- package/src/shaders/schema.ts +12 -0
- package/src/shape-with-text/document.ts +7 -12
- package/src/shape-with-text/geometry.ts +1 -4
- package/src/slides/index.ts +8 -0
- package/src/slides/motion.ts +35 -1
- package/src/slides/playback.ts +51 -9
- package/src/slots/frames.ts +2 -3
- package/src/specs/index.ts +2 -0
- package/src/specs/model.ts +40 -0
- package/src/specs/schema.ts +43 -0
- package/src/text/lists.ts +20 -7
- package/src/text/paragraphs.ts +10 -3
- package/src/transfer/dependencies.ts +17 -11
- package/src/transfer/library.ts +36 -12
- package/src/transfer/nodes.ts +8 -0
- package/src/types.ts +71 -8
- package/src/undo.ts +10 -1
- package/src/variables/bindings.ts +33 -16
- package/src/variables/easing.ts +16 -17
- package/src/variables/fields.ts +30 -3
- package/src/variables/lookup.ts +24 -1
- package/src/variables/resolution.ts +15 -1
- package/src/variables/units.ts +2 -3
package/dist/ids.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { randomIndex } from "@open-pencil/std/random";
|
|
2
|
-
|
|
2
|
+
// src/ids.ts
|
|
3
3
|
/** Figma reads both parts of a GUID as signed 32-bit integers and drops records beyond them. */
|
|
4
|
-
const MAX_ID_SESSION =
|
|
4
|
+
const MAX_ID_SESSION = 0x7fffffff;
|
|
5
5
|
/** Sessions 0 and 1 hold FIG's document and internal-resource records and counter GUIDs. */
|
|
6
6
|
const FIRST_RANDOM_SESSION = 2;
|
|
7
7
|
/** A random session, as Yjs picks each document's `clientID`, so processes never share IDs. */
|
|
8
8
|
function randomIdSession() {
|
|
9
|
-
return FIRST_RANDOM_SESSION + randomIndex(
|
|
9
|
+
return FIRST_RANDOM_SESSION + randomIndex(0x7ffffffe);
|
|
10
10
|
}
|
|
11
11
|
let idSession = randomIdSession();
|
|
12
12
|
let nextLocalID = 1;
|
|
@@ -25,7 +25,6 @@ function setIdSession(sessionId) {
|
|
|
25
25
|
function generateId() {
|
|
26
26
|
return `${idSession}:${nextLocalID++}`;
|
|
27
27
|
}
|
|
28
|
-
//#endregion
|
|
29
28
|
export { generateId, setIdSession };
|
|
30
29
|
|
|
31
30
|
//# sourceMappingURL=ids.js.map
|
package/dist/images.d.ts
CHANGED
|
@@ -1,36 +1,37 @@
|
|
|
1
|
+
import { Mat3 } from "./matrix.js";
|
|
1
2
|
import { Matrix, Size } from "./primitives/index.js";
|
|
2
3
|
import { Fill, SceneNode } from "./types.js";
|
|
3
|
-
import { Mat3 } from "./matrix.js";
|
|
4
|
-
//#region src/images.d.ts
|
|
5
4
|
/**
|
|
6
5
|
* The name an image's bytes are stored under: the hex SHA-1 of the bytes, as Figma names images,
|
|
7
6
|
* so `.fig` files and the Figma clipboard can carry the name as it is. Documents saved before may
|
|
8
7
|
* hold images under other names; anything that hands images to Figma still checks. Each array is
|
|
9
8
|
* hashed once, as image bytes are never written into once read or stored.
|
|
10
9
|
*/
|
|
11
|
-
declare function computeImageHash(data: Uint8Array): string;
|
|
12
|
-
type ImageMimeType = 'image/png' | 'image/jpeg' | 'image/gif' | 'image/webp' | 'image/avif';
|
|
10
|
+
export declare function computeImageHash(data: Uint8Array): string;
|
|
11
|
+
export type ImageMimeType = 'image/png' | 'image/jpeg' | 'image/gif' | 'image/webp' | 'image/avif';
|
|
13
12
|
/** The raster types a dropped or pasted file can be imported as an image fill from. */
|
|
14
|
-
declare const IMPORTABLE_RASTER_TYPES: ReadonlySet<string>;
|
|
13
|
+
export declare const IMPORTABLE_RASTER_TYPES: ReadonlySet<string>;
|
|
15
14
|
/** Whether a file is an SVG image, which some systems report without a media type. */
|
|
16
|
-
declare function isSVGFile(file: {
|
|
15
|
+
export declare function isSVGFile(file: {
|
|
17
16
|
name: string;
|
|
18
17
|
type: string;
|
|
19
18
|
}): boolean;
|
|
20
|
-
interface ImageHeader extends Size {
|
|
19
|
+
export interface ImageHeader extends Size {
|
|
21
20
|
type: ImageMimeType;
|
|
21
|
+
/** A JPEG's Exif orientation, 1–8, when it names one; the size is as stored, before it. */
|
|
22
|
+
orientation?: number;
|
|
22
23
|
}
|
|
23
24
|
/**
|
|
24
25
|
* The type and size of a PNG, JPEG, GIF, WebP, or AVIF, read from its header by `image-size`; null for
|
|
25
26
|
* bytes it cannot read and for other formats.
|
|
26
27
|
*/
|
|
27
|
-
declare function imageHeader(data: Uint8Array): ImageHeader | null;
|
|
28
|
+
export declare function imageHeader(data: Uint8Array): ImageHeader | null;
|
|
28
29
|
/**
|
|
29
30
|
* The media type of encoded image bytes, read from their header, for writing them out as a data
|
|
30
31
|
* URL or file. Bytes it cannot read are reported as PNG, as image fills began.
|
|
31
32
|
*/
|
|
32
|
-
declare function imageMimeType(data: Uint8Array): ImageMimeType;
|
|
33
|
-
interface DataURL {
|
|
33
|
+
export declare function imageMimeType(data: Uint8Array): ImageMimeType;
|
|
34
|
+
export interface DataURL {
|
|
34
35
|
/** The media type in lowercase, without parameters; `text/plain` when the URL names none. */
|
|
35
36
|
mimeType: string;
|
|
36
37
|
bytes: Uint8Array;
|
|
@@ -41,33 +42,31 @@ interface DataURL {
|
|
|
41
42
|
* cut short in transit, and escapes that are not UTF-8, such as a binary image escaped byte by
|
|
42
43
|
* byte, which a reader that must take any data URL, such as `.pen` loading, gets from `fetch`.
|
|
43
44
|
*/
|
|
44
|
-
declare function parseDataURL(url: string): DataURL | null;
|
|
45
|
+
export declare function parseDataURL(url: string): DataURL | null;
|
|
45
46
|
/** Encoded image bytes as a Base64 data URL of the type their header names. */
|
|
46
|
-
declare function imageDataURL(data: Uint8Array): string;
|
|
47
|
+
export declare function imageDataURL(data: Uint8Array): string;
|
|
47
48
|
/** SVG markup as a percent-encoded data URL, as CSS `url()` and `<img src>` take one. */
|
|
48
|
-
declare function svgDataURL(svg: string): string;
|
|
49
|
+
export declare function svgDataURL(svg: string): string;
|
|
49
50
|
/** An image's size in pixels, read from its header; null for bytes it cannot read. */
|
|
50
|
-
declare function imageSize(data: Uint8Array): Size | null;
|
|
51
|
+
export declare function imageSize(data: Uint8Array): Size | null;
|
|
51
52
|
/**
|
|
52
53
|
* The crop that shows an image as Fill does: scaled to cover a `width` × `height` layer and
|
|
53
54
|
* centred. Figma starts a crop from it, as the image-space window a crop's transform holds.
|
|
54
55
|
*/
|
|
55
|
-
declare function coverImageTransform(width: number, height: number, imageWidth: number, imageHeight: number): Matrix;
|
|
56
|
+
export declare function coverImageTransform(width: number, height: number, imageWidth: number, imageHeight: number): Matrix;
|
|
56
57
|
/**
|
|
57
58
|
* Maps `img`'s pixels onto `node` as `fill` places them. `size` is the image's own size when `img`
|
|
58
59
|
* is a downscaled preview, so a tile keeps its size. A crop places the image by its transform;
|
|
59
60
|
* Fill, Fit and Tile ignore it, as Figma does, and turn the image by `imageRotation` first.
|
|
60
61
|
*/
|
|
61
|
-
declare function imageFillMatrix(fill: Fill, node: Pick<SceneNode, 'width' | 'height'>, imgW: number, imgH: number, size?: Size): Mat3;
|
|
62
|
+
export declare function imageFillMatrix(fill: Fill, node: Pick<SceneNode, 'width' | 'height'>, imgW: number, imgH: number, size?: Size): Mat3;
|
|
62
63
|
/** The image a paint draws: an IMAGE paint's own, or the poster frame of a VIDEO paint. */
|
|
63
|
-
declare function drawnImageHash(paint: Pick<Fill, 'type' | 'imageHash'>): string | undefined;
|
|
64
|
+
export declare function drawnImageHash(paint: Pick<Fill, 'type' | 'imageHash'>): string | undefined;
|
|
64
65
|
/** The images `paints` show, by their hashes: a VIDEO paint shows its poster frame. */
|
|
65
|
-
declare function imagePaintHashes(paints: Iterable<Fill>): string[];
|
|
66
|
+
export declare function imagePaintHashes(paints: Iterable<Fill>): string[];
|
|
66
67
|
/**
|
|
67
68
|
* Copies the images `hashes` name from `from` into `to`, each as bytes of its own. An image is
|
|
68
69
|
* named by its content, so one `to` already holds stays.
|
|
69
70
|
*/
|
|
70
|
-
declare function copyImages(from: ReadonlyMap<string, Uint8Array>, to: Map<string, Uint8Array>, hashes: Iterable<string>): void;
|
|
71
|
-
//#endregion
|
|
72
|
-
export { DataURL, IMPORTABLE_RASTER_TYPES, ImageHeader, ImageMimeType, computeImageHash, copyImages, coverImageTransform, drawnImageHash, imageDataURL, imageFillMatrix, imageHeader, imageMimeType, imagePaintHashes, imageSize, isSVGFile, parseDataURL, svgDataURL };
|
|
71
|
+
export declare function copyImages(from: ReadonlyMap<string, Uint8Array>, to: Map<string, Uint8Array>, hashes: Iterable<string>): void;
|
|
73
72
|
//# sourceMappingURL=images.d.ts.map
|
package/dist/images.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"images.d.ts","names":[],"sources":["../src/images.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"images.d.ts","names":[],"sources":["../src/images.ts"],"mappings":";;;;;;;;;wBAkBgB,iBAAiB,MAAM;YAQ3B;;qBAYC,yBAAyB;;wBAStB,UAAU;EAAQ;EAAc;;iBAM/B,oBAAoB;EACnC,MAAM;;EAEN;;;;;;wBAOc,YAAY,MAAM,aAAa;;;;;wBAgB/B,cAAc,MAAM,aAAa;iBAIhC;;EAEf;EACA,OAAO;;;;;;;;wBASO,aAAa,cAAc;;wBAsB3B,aAAa,MAAM;;wBAKnB,WAAW;;wBAKX,UAAU,MAAM,aAAa;;;;;wBAS7B,oBACd,eACA,gBACA,oBACA,sBACC;;;;;;wBAYa,gBACd,MAAM,MACN,MAAM,KAAK,gCACX,cACA,cACA,OAAM,OACL;;wBAsCa,eAAe,OAAO,KAAK;;wBAK3B,iBAAiB,QAAQ,SAAS;;;;;wBAQlC,WACd,MAAM,oBAAoB,aAC1B,IAAI,YAAY,aAChB,QAAQ"}
|
package/dist/images.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import Matrix from "./matrix.js";
|
|
2
1
|
import { sha1 } from "@noble/hashes/legacy.js";
|
|
3
2
|
import { bytesToHex } from "@noble/hashes/utils.js";
|
|
4
3
|
import { imageSize as imageSize$1 } from "image-size";
|
|
5
4
|
import { fromUint8Array, isValid, toUint8Array } from "js-base64";
|
|
6
|
-
|
|
5
|
+
import Matrix from "./matrix.js";
|
|
6
|
+
// src/images.ts
|
|
7
7
|
/** Hashes already computed, by the bytes hashed: a save would otherwise hash every image again. */
|
|
8
8
|
const imageHashes = /* @__PURE__ */ new WeakMap();
|
|
9
9
|
/**
|
|
@@ -51,11 +51,13 @@ function imageHeader(data) {
|
|
|
51
51
|
return null;
|
|
52
52
|
}
|
|
53
53
|
const type = header.type === void 0 ? void 0 : IMAGE_MIME_TYPES[header.type];
|
|
54
|
-
|
|
54
|
+
if (!type) return null;
|
|
55
|
+
return {
|
|
55
56
|
type,
|
|
56
57
|
width: header.width,
|
|
57
|
-
height: header.height
|
|
58
|
-
|
|
58
|
+
height: header.height,
|
|
59
|
+
orientation: header.orientation
|
|
60
|
+
};
|
|
59
61
|
}
|
|
60
62
|
/**
|
|
61
63
|
* The media type of encoded image bytes, read from their header, for writing them out as a data
|
|
@@ -173,7 +175,6 @@ function copyImages(from, to, hashes) {
|
|
|
173
175
|
if (bytes && !to.has(hash)) to.set(hash, new Uint8Array(bytes));
|
|
174
176
|
}
|
|
175
177
|
}
|
|
176
|
-
//#endregion
|
|
177
178
|
export { IMPORTABLE_RASTER_TYPES, computeImageHash, copyImages, coverImageTransform, drawnImageHash, imageDataURL, imageFillMatrix, imageHeader, imageMimeType, imagePaintHashes, imageSize, isSVGFile, parseDataURL, svgDataURL };
|
|
178
179
|
|
|
179
180
|
//# sourceMappingURL=images.js.map
|
package/dist/images.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"images.js","names":["readImageHeader","MatrixMath"],"sources":["../src/images.ts"],"sourcesContent":["import { sha1 } from '@noble/hashes/legacy.js'\nimport { bytesToHex } from '@noble/hashes/utils.js'\nimport { imageSize as readImageHeader } from 'image-size'\nimport { fromUint8Array, isValid, toUint8Array } from 'js-base64'\n\nimport MatrixMath, { type Mat3 } from './matrix'\nimport type { Matrix, Size } from './primitives'\nimport type { Fill, SceneNode } from './types'\n\n/** Hashes already computed, by the bytes hashed: a save would otherwise hash every image again. */\nconst imageHashes = new WeakMap<Uint8Array, string>()\n\n/**\n * The name an image's bytes are stored under: the hex SHA-1 of the bytes, as Figma names images,\n * so `.fig` files and the Figma clipboard can carry the name as it is. Documents saved before may\n * hold images under other names; anything that hands images to Figma still checks. Each array is\n * hashed once, as image bytes are never written into once read or stored.\n */\nexport function computeImageHash(data: Uint8Array): string {\n const known = imageHashes.get(data)\n if (known) return known\n const hash = bytesToHex(sha1(data))\n imageHashes.set(data, hash)\n return hash\n}\n\nexport type ImageMimeType = 'image/png' | 'image/jpeg' | 'image/gif' | 'image/webp' | 'image/avif'\n\n/** The image types documents store, by the name `image-size` gives each format. */\nconst IMAGE_MIME_TYPES: Partial<Record<string, ImageMimeType>> = {\n png: 'image/png',\n jpg: 'image/jpeg',\n gif: 'image/gif',\n webp: 'image/webp',\n avif: 'image/avif'\n}\n\n/** The raster types a dropped or pasted file can be imported as an image fill from. */\nexport const IMPORTABLE_RASTER_TYPES: ReadonlySet<string> = new Set([\n 'image/png',\n 'image/jpeg',\n 'image/webp',\n 'image/gif',\n 'image/avif'\n])\n\n/** Whether a file is an SVG image, which some systems report without a media type. */\nexport function isSVGFile(file: { name: string; type: string }): boolean {\n return (\n file.type === 'image/svg+xml' || (file.type === '' && file.name.toLowerCase().endsWith('.svg'))\n )\n}\n\nexport interface ImageHeader extends Size {\n type: ImageMimeType\n}\n\n/**\n * The type and size of a PNG, JPEG, GIF, WebP, or AVIF, read from its header by `image-size`; null for\n * bytes it cannot read and for other formats.\n */\nexport function imageHeader(data: Uint8Array): ImageHeader | null {\n let header: ReturnType<typeof readImageHeader>\n try {\n header = readImageHeader(data)\n } catch {\n return null\n }\n const type = header.type === undefined ? undefined : IMAGE_MIME_TYPES[header.type]\n return type ? { type, width: header.width, height: header.height } : null\n}\n\n/**\n * The media type of encoded image bytes, read from their header, for writing them out as a data\n * URL or file. Bytes it cannot read are reported as PNG, as image fills began.\n */\nexport function imageMimeType(data: Uint8Array): ImageMimeType {\n return imageHeader(data)?.type ?? 'image/png'\n}\n\nexport interface DataURL {\n /** The media type in lowercase, without parameters; `text/plain` when the URL names none. */\n mimeType: string\n bytes: Uint8Array\n}\n\n/**\n * The media type and bytes a `data:` URL carries: a Base64 body decoded, and a percent-encoded\n * one unescaped as UTF-8 text, as SVG and other markup are written. Null for anything else: Base64\n * cut short in transit, and escapes that are not UTF-8, such as a binary image escaped byte by\n * byte, which a reader that must take any data URL, such as `.pen` loading, gets from `fetch`.\n */\nexport function parseDataURL(url: string): DataURL | null {\n const match = /^\\s*data:([^,]*),(.*?)\\s*$/is.exec(url)\n if (!match) return null\n const [, header = '', body = ''] = match\n const params = header.split(';').map((param) => param.trim())\n const base64 = params.length > 1 && params.at(-1)?.toLowerCase() === 'base64'\n const mimeType = params[0]?.toLowerCase() || 'text/plain'\n let text: string\n try {\n // A `%` that starts no escape is a literal percent sign, as in `width=\"100%\"`.\n text = decodeURIComponent(body.replace(/%(?![\\da-f]{2})/gi, '%25'))\n } catch {\n return null\n }\n if (!base64) return { mimeType, bytes: new TextEncoder().encode(text) }\n const compact = text.replace(/\\s+/g, '')\n // Base64 one character past a whole group of four cannot be bytes: it was cut short.\n if (compact.replace(/={1,2}$/, '').length % 4 === 1 || !isValid(compact)) return null\n return { mimeType, bytes: toUint8Array(compact) }\n}\n\n/** Encoded image bytes as a Base64 data URL of the type their header names. */\nexport function imageDataURL(data: Uint8Array): string {\n return `data:${imageMimeType(data)};base64,${fromUint8Array(data)}`\n}\n\n/** SVG markup as a percent-encoded data URL, as CSS `url()` and `<img src>` take one. */\nexport function svgDataURL(svg: string): string {\n return `data:image/svg+xml,${encodeURIComponent(svg)}`\n}\n\n/** An image's size in pixels, read from its header; null for bytes it cannot read. */\nexport function imageSize(data: Uint8Array): Size | null {\n const header = imageHeader(data)\n return header && { width: header.width, height: header.height }\n}\n\n/**\n * The crop that shows an image as Fill does: scaled to cover a `width` × `height` layer and\n * centred. Figma starts a crop from it, as the image-space window a crop's transform holds.\n */\nexport function coverImageTransform(\n width: number,\n height: number,\n imageWidth: number,\n imageHeight: number\n): Matrix {\n const scale = Math.max(width / imageWidth, height / imageHeight)\n const m00 = width / scale / imageWidth\n const m11 = height / scale / imageHeight\n return { m00, m01: 0, m02: (1 - m00) / 2, m10: 0, m11, m12: (1 - m11) / 2 }\n}\n\n/**\n * Maps `img`'s pixels onto `node` as `fill` places them. `size` is the image's own size when `img`\n * is a downscaled preview, so a tile keeps its size. A crop places the image by its transform;\n * Fill, Fit and Tile ignore it, as Figma does, and turn the image by `imageRotation` first.\n */\nexport function imageFillMatrix(\n fill: Fill,\n node: Pick<SceneNode, 'width' | 'height'>,\n imgW: number,\n imgH: number,\n size: Size = { width: imgW, height: imgH }\n): Mat3 {\n const scaleMode = fill.imageScaleMode ?? 'FILL'\n if (scaleMode === 'CROP' && fill.imageTransform) {\n const t = fill.imageTransform\n const inverse = MatrixMath.invert(MatrixMath.fromAffine(t))\n if (inverse)\n return MatrixMath.multiply(\n MatrixMath.scaled(node.width, node.height),\n inverse,\n MatrixMath.scaled(1 / imgW, 1 / imgH)\n )\n }\n\n const radians = ((fill.imageRotation ?? 0) * Math.PI) / 180\n const cos = Math.abs(Math.cos(radians))\n const sin = Math.abs(Math.sin(radians))\n const turnedW = size.width * cos + size.height * sin\n const turnedH = size.width * sin + size.height * cos\n const turned = MatrixMath.multiply(\n MatrixMath.translated(turnedW / 2, turnedH / 2),\n MatrixMath.rotated(radians),\n MatrixMath.translated(-size.width / 2, -size.height / 2),\n MatrixMath.scaled(size.width / imgW, size.height / imgH)\n )\n if (scaleMode === 'TILE') {\n const scale = fill.scale && fill.scale > 0 ? fill.scale : 1\n return MatrixMath.multiply(MatrixMath.scaled(scale, scale), turned)\n }\n const fit = scaleMode === 'FIT'\n const scale = (fit ? Math.min : Math.max)(node.width / turnedW, node.height / turnedH)\n return MatrixMath.multiply(\n MatrixMath.translated((node.width - turnedW * scale) / 2, (node.height - turnedH * scale) / 2),\n MatrixMath.scaled(scale, scale),\n turned\n )\n}\n\n/** The image a paint draws: an IMAGE paint's own, or the poster frame of a VIDEO paint. */\nexport function drawnImageHash(paint: Pick<Fill, 'type' | 'imageHash'>): string | undefined {\n return paint.type === 'IMAGE' || paint.type === 'VIDEO' ? paint.imageHash : undefined\n}\n\n/** The images `paints` show, by their hashes: a VIDEO paint shows its poster frame. */\nexport function imagePaintHashes(paints: Iterable<Fill>): string[] {\n return [...paints].flatMap((paint) => drawnImageHash(paint) ?? [])\n}\n\n/**\n * Copies the images `hashes` name from `from` into `to`, each as bytes of its own. An image is\n * named by its content, so one `to` already holds stays.\n */\nexport function copyImages(\n from: ReadonlyMap<string, Uint8Array>,\n to: Map<string, Uint8Array>,\n hashes: Iterable<string>\n): void {\n for (const hash of hashes) {\n const bytes = from.get(hash)\n if (bytes && !to.has(hash)) to.set(hash, new Uint8Array(bytes))\n }\n}\n"],"mappings":";;;;;;;AAUA,MAAM,8BAAc,IAAI,QAA4B;;;;;;;AAQpD,SAAgB,iBAAiB,MAA0B;CACzD,MAAM,QAAQ,YAAY,IAAI,IAAI;CAClC,IAAI,OAAO,OAAO;CAClB,MAAM,OAAO,WAAW,KAAK,IAAI,CAAC;CAClC,YAAY,IAAI,MAAM,IAAI;CAC1B,OAAO;AACT;;AAKA,MAAM,mBAA2D;CAC/D,KAAK;CACL,KAAK;CACL,KAAK;CACL,MAAM;CACN,MAAM;AACR;;AAGA,MAAa,0CAA+C,IAAI,IAAI;CAClE;CACA;CACA;CACA;CACA;AACF,CAAC;;AAGD,SAAgB,UAAU,MAA+C;CACvE,OACE,KAAK,SAAS,mBAAoB,KAAK,SAAS,MAAM,KAAK,KAAK,YAAY,CAAC,CAAC,SAAS,MAAM;AAEjG;;;;;AAUA,SAAgB,YAAY,MAAsC;CAChE,IAAI;CACJ,IAAI;EACF,SAASA,YAAgB,IAAI;CAC/B,QAAQ;EACN,OAAO;CACT;CACA,MAAM,OAAO,OAAO,SAAS,KAAA,IAAY,KAAA,IAAY,iBAAiB,OAAO;CAC7E,OAAO,OAAO;EAAE;EAAM,OAAO,OAAO;EAAO,QAAQ,OAAO;CAAO,IAAI;AACvE;;;;;AAMA,SAAgB,cAAc,MAAiC;CAC7D,OAAO,YAAY,IAAI,CAAC,EAAE,QAAQ;AACpC;;;;;;;AAcA,SAAgB,aAAa,KAA6B;CACxD,MAAM,QAAQ,+BAA+B,KAAK,GAAG;CACrD,IAAI,CAAC,OAAO,OAAO;CAC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;AAGA,SAAgB,eAAe,OAA6D;CAC1F,OAAO,MAAM,SAAS,WAAW,MAAM,SAAS,UAAU,MAAM,YAAY,KAAA;AAC9E;;AAGA,SAAgB,iBAAiB,QAAkC;CACjE,OAAO,CAAC,GAAG,MAAM,CAAC,CAAC,SAAS,UAAU,eAAe,KAAK,KAAK,CAAC,CAAC;AACnE;;;;;AAMA,SAAgB,WACd,MACA,IACA,QACM;CACN,KAAK,MAAM,QAAQ,QAAQ;EACzB,MAAM,QAAQ,KAAK,IAAI,IAAI;EAC3B,IAAI,SAAS,CAAC,GAAG,IAAI,IAAI,GAAG,GAAG,IAAI,MAAM,IAAI,WAAW,KAAK,CAAC;CAChE;AACF"}
|
|
1
|
+
{"version":3,"file":"images.js","names":["readImageHeader","MatrixMath"],"sources":["../src/images.ts"],"sourcesContent":["import { sha1 } from '@noble/hashes/legacy.js'\nimport { bytesToHex } from '@noble/hashes/utils.js'\nimport { imageSize as readImageHeader } from 'image-size'\nimport { fromUint8Array, isValid, toUint8Array } from 'js-base64'\n\nimport MatrixMath, { type Mat3 } from './matrix'\nimport type { Matrix, Size } from './primitives'\nimport type { Fill, SceneNode } from './types'\n\n/** Hashes already computed, by the bytes hashed: a save would otherwise hash every image again. */\nconst imageHashes = new WeakMap<Uint8Array, string>()\n\n/**\n * The name an image's bytes are stored under: the hex SHA-1 of the bytes, as Figma names images,\n * so `.fig` files and the Figma clipboard can carry the name as it is. Documents saved before may\n * hold images under other names; anything that hands images to Figma still checks. Each array is\n * hashed once, as image bytes are never written into once read or stored.\n */\nexport function computeImageHash(data: Uint8Array): string {\n const known = imageHashes.get(data)\n if (known) return known\n const hash = bytesToHex(sha1(data))\n imageHashes.set(data, hash)\n return hash\n}\n\nexport type ImageMimeType = 'image/png' | 'image/jpeg' | 'image/gif' | 'image/webp' | 'image/avif'\n\n/** The image types documents store, by the name `image-size` gives each format. */\nconst IMAGE_MIME_TYPES: Partial<Record<string, ImageMimeType>> = {\n png: 'image/png',\n jpg: 'image/jpeg',\n gif: 'image/gif',\n webp: 'image/webp',\n avif: 'image/avif'\n}\n\n/** The raster types a dropped or pasted file can be imported as an image fill from. */\nexport const IMPORTABLE_RASTER_TYPES: ReadonlySet<string> = new Set([\n 'image/png',\n 'image/jpeg',\n 'image/webp',\n 'image/gif',\n 'image/avif'\n])\n\n/** Whether a file is an SVG image, which some systems report without a media type. */\nexport function isSVGFile(file: { name: string; type: string }): boolean {\n return (\n file.type === 'image/svg+xml' || (file.type === '' && file.name.toLowerCase().endsWith('.svg'))\n )\n}\n\nexport interface ImageHeader extends Size {\n type: ImageMimeType\n /** A JPEG's Exif orientation, 1–8, when it names one; the size is as stored, before it. */\n orientation?: number\n}\n\n/**\n * The type and size of a PNG, JPEG, GIF, WebP, or AVIF, read from its header by `image-size`; null for\n * bytes it cannot read and for other formats.\n */\nexport function imageHeader(data: Uint8Array): ImageHeader | null {\n let header: ReturnType<typeof readImageHeader>\n try {\n header = readImageHeader(data)\n } catch {\n return null\n }\n const type = header.type === undefined ? undefined : IMAGE_MIME_TYPES[header.type]\n if (!type) return null\n return { type, width: header.width, height: header.height, orientation: header.orientation }\n}\n\n/**\n * The media type of encoded image bytes, read from their header, for writing them out as a data\n * URL or file. Bytes it cannot read are reported as PNG, as image fills began.\n */\nexport function imageMimeType(data: Uint8Array): ImageMimeType {\n return imageHeader(data)?.type ?? 'image/png'\n}\n\nexport interface DataURL {\n /** The media type in lowercase, without parameters; `text/plain` when the URL names none. */\n mimeType: string\n bytes: Uint8Array\n}\n\n/**\n * The media type and bytes a `data:` URL carries: a Base64 body decoded, and a percent-encoded\n * one unescaped as UTF-8 text, as SVG and other markup are written. Null for anything else: Base64\n * cut short in transit, and escapes that are not UTF-8, such as a binary image escaped byte by\n * byte, which a reader that must take any data URL, such as `.pen` loading, gets from `fetch`.\n */\nexport function parseDataURL(url: string): DataURL | null {\n const match = /^\\s*data:([^,]*),(.*?)\\s*$/is.exec(url)\n if (!match) return null\n const [, header = '', body = ''] = match\n const params = header.split(';').map((param) => param.trim())\n const base64 = params.length > 1 && params.at(-1)?.toLowerCase() === 'base64'\n const mimeType = params[0]?.toLowerCase() || 'text/plain'\n let text: string\n try {\n // A `%` that starts no escape is a literal percent sign, as in `width=\"100%\"`.\n text = decodeURIComponent(body.replace(/%(?![\\da-f]{2})/gi, '%25'))\n } catch {\n return null\n }\n if (!base64) return { mimeType, bytes: new TextEncoder().encode(text) }\n const compact = text.replace(/\\s+/g, '')\n // Base64 one character past a whole group of four cannot be bytes: it was cut short.\n if (compact.replace(/={1,2}$/, '').length % 4 === 1 || !isValid(compact)) return null\n return { mimeType, bytes: toUint8Array(compact) }\n}\n\n/** Encoded image bytes as a Base64 data URL of the type their header names. */\nexport function imageDataURL(data: Uint8Array): string {\n return `data:${imageMimeType(data)};base64,${fromUint8Array(data)}`\n}\n\n/** SVG markup as a percent-encoded data URL, as CSS `url()` and `<img src>` take one. */\nexport function svgDataURL(svg: string): string {\n return `data:image/svg+xml,${encodeURIComponent(svg)}`\n}\n\n/** An image's size in pixels, read from its header; null for bytes it cannot read. */\nexport function imageSize(data: Uint8Array): Size | null {\n const header = imageHeader(data)\n return header && { width: header.width, height: header.height }\n}\n\n/**\n * The crop that shows an image as Fill does: scaled to cover a `width` × `height` layer and\n * centred. Figma starts a crop from it, as the image-space window a crop's transform holds.\n */\nexport function coverImageTransform(\n width: number,\n height: number,\n imageWidth: number,\n imageHeight: number\n): Matrix {\n const scale = Math.max(width / imageWidth, height / imageHeight)\n const m00 = width / scale / imageWidth\n const m11 = height / scale / imageHeight\n return { m00, m01: 0, m02: (1 - m00) / 2, m10: 0, m11, m12: (1 - m11) / 2 }\n}\n\n/**\n * Maps `img`'s pixels onto `node` as `fill` places them. `size` is the image's own size when `img`\n * is a downscaled preview, so a tile keeps its size. A crop places the image by its transform;\n * Fill, Fit and Tile ignore it, as Figma does, and turn the image by `imageRotation` first.\n */\nexport function imageFillMatrix(\n fill: Fill,\n node: Pick<SceneNode, 'width' | 'height'>,\n imgW: number,\n imgH: number,\n size: Size = { width: imgW, height: imgH }\n): Mat3 {\n const scaleMode = fill.imageScaleMode ?? 'FILL'\n if (scaleMode === 'CROP' && fill.imageTransform) {\n const t = fill.imageTransform\n const inverse = MatrixMath.invert(MatrixMath.fromAffine(t))\n if (inverse)\n return MatrixMath.multiply(\n MatrixMath.scaled(node.width, node.height),\n inverse,\n MatrixMath.scaled(1 / imgW, 1 / imgH)\n )\n }\n\n const radians = ((fill.imageRotation ?? 0) * Math.PI) / 180\n const cos = Math.abs(Math.cos(radians))\n const sin = Math.abs(Math.sin(radians))\n const turnedW = size.width * cos + size.height * sin\n const turnedH = size.width * sin + size.height * cos\n const turned = MatrixMath.multiply(\n MatrixMath.translated(turnedW / 2, turnedH / 2),\n MatrixMath.rotated(radians),\n MatrixMath.translated(-size.width / 2, -size.height / 2),\n MatrixMath.scaled(size.width / imgW, size.height / imgH)\n )\n if (scaleMode === 'TILE') {\n const scale = fill.scale && fill.scale > 0 ? fill.scale : 1\n return MatrixMath.multiply(MatrixMath.scaled(scale, scale), turned)\n }\n const fit = scaleMode === 'FIT'\n const scale = (fit ? Math.min : Math.max)(node.width / turnedW, node.height / turnedH)\n return MatrixMath.multiply(\n MatrixMath.translated((node.width - turnedW * scale) / 2, (node.height - turnedH * scale) / 2),\n MatrixMath.scaled(scale, scale),\n turned\n )\n}\n\n/** The image a paint draws: an IMAGE paint's own, or the poster frame of a VIDEO paint. */\nexport function drawnImageHash(paint: Pick<Fill, 'type' | 'imageHash'>): string | undefined {\n return paint.type === 'IMAGE' || paint.type === 'VIDEO' ? paint.imageHash : undefined\n}\n\n/** The images `paints` show, by their hashes: a VIDEO paint shows its poster frame. */\nexport function imagePaintHashes(paints: Iterable<Fill>): string[] {\n return [...paints].flatMap((paint) => drawnImageHash(paint) ?? [])\n}\n\n/**\n * Copies the images `hashes` name from `from` into `to`, each as bytes of its own. An image is\n * named by its content, so one `to` already holds stays.\n */\nexport function copyImages(\n from: ReadonlyMap<string, Uint8Array>,\n to: Map<string, Uint8Array>,\n hashes: Iterable<string>\n): void {\n for (const hash of hashes) {\n const bytes = from.get(hash)\n if (bytes && !to.has(hash)) to.set(hash, new Uint8Array(bytes))\n }\n}\n"],"mappings":";;;;;;;AAUA,MAAM,8BAAc,IAAI,QAA4B;;;;;;;AAQpD,SAAgB,iBAAiB,MAA0B;CACzD,MAAM,QAAQ,YAAY,IAAI,IAAI;CAClC,IAAI,OAAO,OAAO;CAClB,MAAM,OAAO,WAAW,KAAK,IAAI,CAAC;CAClC,YAAY,IAAI,MAAM,IAAI;CAC1B,OAAO;AACT;;AAKA,MAAM,mBAA2D;CAC/D,KAAK;CACL,KAAK;CACL,KAAK;CACL,MAAM;CACN,MAAM;AACR;;AAGA,MAAa,0CAA+C,IAAI,IAAI;CAClE;CACA;CACA;CACA;CACA;AACF,CAAC;;AAGD,SAAgB,UAAU,MAA+C;CACvE,OACE,KAAK,SAAS,mBAAoB,KAAK,SAAS,MAAM,KAAK,KAAK,YAAY,CAAC,CAAC,SAAS,MAAM;AAEjG;;;;;AAYA,SAAgB,YAAY,MAAsC;CAChE,IAAI;CACJ,IAAI;EACF,SAASA,YAAgB,IAAI;CAC/B,QAAQ;EACN,OAAO;CACT;CACA,MAAM,OAAO,OAAO,SAAS,KAAA,IAAY,KAAA,IAAY,iBAAiB,OAAO;CAC7E,IAAI,CAAC,MAAM,OAAO;CAClB,OAAO;EAAE;EAAM,OAAO,OAAO;EAAO,QAAQ,OAAO;EAAQ,aAAa,OAAO;CAAY;AAC7F;;;;;AAMA,SAAgB,cAAc,MAAiC;CAC7D,OAAO,YAAY,IAAI,CAAC,EAAE,QAAQ;AACpC;;;;;;;AAcA,SAAgB,aAAa,KAA6B;CACxD,MAAM,QAAQ,+BAA+B,KAAK,GAAG;CACrD,IAAI,CAAC,OAAO,OAAO;CACnB,MAAM,GAAG,SAAS,IAAI,OAAO,MAAM;CACnC,MAAM,SAAS,OAAO,MAAM,GAAG,CAAC,CAAC,KAAK,UAAU,MAAM,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GA,SAAgB,iBAAiB,QAAkC;CACjE,OAAO,CAAC,GAAG,MAAM,CAAC,CAAC,SAAS,UAAU,eAAe,KAAK,KAAK,CAAC,CAAC;AACnE;;;;;AAMA,SAAgB,WACd,MACA,IACA,QACM;CACN,KAAK,MAAM,QAAQ,QAAQ;EACzB,MAAM,QAAQ,KAAK,IAAI,IAAI;EAC3B,IAAI,SAAS,CAAC,GAAG,IAAI,IAAI,GAAG,GAAG,IAAI,MAAM,IAAI,WAAW,KAAK,CAAC;CAChE;AACF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CommittedGraphEventError } from "./buffered-events.js";
|
|
2
2
|
import { SceneGraph } from "./graph.js";
|
|
3
|
-
import { ArcData, AxisSizingMode, BlendMode, CODE_SYNTAX_PLATFORMS, CharacterStyleOverride, CodeSyntaxPlatform, ColorProfile, CommentReply, CommentThread, ComponentPropertyDefinition, ComponentPropertyReference, ComponentPropertyReferenceField, ComponentPropertyType, ConnectorControlPoint, ConnectorEndpoint, ConnectorLabelPosition, ConnectorLineType, ConnectorMagnet, ConstraintType, CubicBezier, DerivedTextGlyph, DocumentKind, DocumentRecordKind, EASING_CURVES, Easing, EasingCurve, Effect, EnabledLibraryBinding, ExportColorProfile, ExportSetting, ExportSize, FigmaLayoutMetadata, FigmaSourcePayload, Fill, FillType, FontFeature, FontVariation, GeometryPath, GlassEffectParams, GradientStop, GradientTransform, GridPosition, GridTrack, GridTrackSizing, HandleMirroring, HyperlinkTarget, ImageFilters, ImageScaleMode, LayoutAlign, LayoutAlignSelf, LayoutCounterAlign, LayoutDirection, LayoutGrid, LayoutMode, LayoutSizing, LayoutWrap, LeadingTrim, LibraryAssetIdentity, LibraryAssetRef, LibraryAssetSource, MODE_ATTRIBUTE_PATTERN, MaskType, NodeChangeObserver, NodeType, NoiseEffectParams, NoiseType, NumericNodeProperty, PatternAlignment, PatternTileType, PluginDataEntry, PluginRelaunchDataEntry, ProgressiveBlur, SceneGraphEventHandlers, SceneGraphEvents, SceneNode, SharedStyle, SharedStyleKind, SharedStyleType, SlotSettings, SourceLibraryPublication, SourceMetadata, Spring, Stroke, StrokeCap, StrokeJoin, StyleRun, SymbolLink, TEXT_BINDABLE_FIELDS, TOKEN_UNITS, TextAlignVertical, TextAutoResize, TextBindableField, TextBoundVariables, TextCase, TextDecoration, TextDecorationStyle, TextDirection, TextLength, TextListType, TextParagraphSpacingField, TextParagraphStyle, TextPathData, TextureEffectParams, TokenExpression, TokenUnit, VARIABLE_FORMULA_OPERATORS, VARIABLE_SCOPES, VARIABLE_TYPES, Variable, VariableAlias, VariableCollection, VariableCollectionMode, VariableColorExpression, VariableFormula, VariableFormulaLiteral, VariableFormulaNode, VariableFormulaOperation, VariableFormulaOperator, VariableFormulaType, VariableLiteral, VariableModeMap, VariableScope, VariableType, VariableUnsupportedExpression, VariableValue, VariantPropSpec, VectorNetwork, VectorRegion, VectorSegment, VectorVertex, WindingRule, isLibraryCollection, isModeAttributeName } from "./types.js";
|
|
4
3
|
import { generateId, setIdSession } from "./ids.js";
|
|
5
|
-
|
|
4
|
+
import { ArcData, AxisSizingMode, BlendMode, CODE_SYNTAX_PLATFORMS, CharacterStyleOverride, CodeSyntaxPlatform, ColorProfile, CommentReply, CommentThread, ComponentPropertyDefinition, ComponentPropertyReference, ComponentPropertyReferenceField, ComponentPropertyType, ConnectorControlPoint, ConnectorEndpoint, ConnectorLabelPosition, ConnectorLineType, ConnectorMagnet, ConstraintType, CubicBezier, DOCUMENT_KINDS, DerivedTextGlyph, DocumentKind, DocumentRecordKind, EASING_CURVES, Easing, EasingCurve, Effect, EnabledLibraryBinding, ExportColorProfile, ExportSetting, ExportSize, FigmaLayoutMetadata, FigmaShaderFields, FigmaSourcePayload, Fill, FillType, FontFeature, FontVariation, GeometryPath, GlassEffectParams, GradientStop, GradientTransform, GridPosition, GridTrack, GridTrackSizing, HandleMirroring, HyperlinkTarget, ImageFilters, ImageScaleMode, LayoutAlign, LayoutAlignSelf, LayoutCounterAlign, LayoutDirection, LayoutGrid, LayoutMode, LayoutSizing, LayoutWrap, LeadingTrim, LibraryAssetIdentity, LibraryAssetRef, LibraryAssetSource, MODE_ATTRIBUTE_PATTERN, MaskType, NodeChangeObserver, NodeType, NoiseEffectParams, NoiseType, NumericNodeProperty, PatternAlignment, PatternTileType, PluginDataEntry, PluginRelaunchDataEntry, ProgressiveBlur, SceneGraphEventHandlers, SceneGraphEvents, SceneNode, ShaderEffectParams, SharedStyle, SharedStyleKind, SharedStyleType, SlotSettings, SourceLibraryPublication, SourceMetadata, Spring, Stroke, StrokeCap, StrokeJoin, StyleRun, SymbolLink, TEXT_BINDABLE_FIELDS, TOKEN_UNITS, TextAlignVertical, TextAutoResize, TextBindableField, TextBoundVariables, TextCase, TextDecoration, TextDecorationStyle, TextDirection, TextLength, TextListType, TextParagraphSpacingField, TextParagraphStyle, TextPathData, TextureEffectParams, TokenExpression, TokenUnit, VARIABLE_FORMULA_OPERATORS, VARIABLE_SCOPES, VARIABLE_TYPES, Variable, VariableAlias, VariableCollection, VariableCollectionMode, VariableColorExpression, VariableFormula, VariableFormulaLiteral, VariableFormulaNode, VariableFormulaOperation, VariableFormulaOperator, VariableFormulaType, VariableLiteral, VariableModeMap, VariableScope, VariableType, VariableUnsupportedExpression, VariableValue, VariantPropSpec, VectorNetwork, VectorRegion, VectorSegment, VectorVertex, WindingRule, isHiddenFromPublishing, isLibraryCollection, isLibraryVariable, isModeAttributeName } from "./types.js";
|
|
5
|
+
export { ArcData, AxisSizingMode, BlendMode, CODE_SYNTAX_PLATFORMS, CharacterStyleOverride, CodeSyntaxPlatform, ColorProfile, CommentReply, CommentThread, CommittedGraphEventError, ComponentPropertyDefinition, ComponentPropertyReference, ComponentPropertyReferenceField, ComponentPropertyType, ConnectorControlPoint, ConnectorEndpoint, ConnectorLabelPosition, ConnectorLineType, ConnectorMagnet, ConstraintType, CubicBezier, DOCUMENT_KINDS, DerivedTextGlyph, DocumentKind, DocumentRecordKind, EASING_CURVES, Easing, EasingCurve, Effect, EnabledLibraryBinding, ExportColorProfile, ExportSetting, ExportSize, FigmaLayoutMetadata, FigmaShaderFields, FigmaSourcePayload, Fill, FillType, FontFeature, FontVariation, GeometryPath, GlassEffectParams, GradientStop, GradientTransform, GridPosition, GridTrack, GridTrackSizing, HandleMirroring, HyperlinkTarget, ImageFilters, ImageScaleMode, LayoutAlign, LayoutAlignSelf, LayoutCounterAlign, LayoutDirection, LayoutGrid, LayoutMode, LayoutSizing, LayoutWrap, LeadingTrim, LibraryAssetIdentity, LibraryAssetRef, LibraryAssetSource, MODE_ATTRIBUTE_PATTERN, MaskType, NodeChangeObserver, NodeType, NoiseEffectParams, NoiseType, NumericNodeProperty, PatternAlignment, PatternTileType, PluginDataEntry, PluginRelaunchDataEntry, ProgressiveBlur, SceneGraph, SceneGraphEventHandlers, SceneGraphEvents, SceneNode, ShaderEffectParams, SharedStyle, SharedStyleKind, SharedStyleType, SlotSettings, SourceLibraryPublication, SourceMetadata, Spring, Stroke, StrokeCap, StrokeJoin, StyleRun, SymbolLink, TEXT_BINDABLE_FIELDS, TOKEN_UNITS, TextAlignVertical, TextAutoResize, TextBindableField, TextBoundVariables, TextCase, TextDecoration, TextDecorationStyle, TextDirection, TextLength, TextListType, TextParagraphSpacingField, TextParagraphStyle, TextPathData, TextureEffectParams, TokenExpression, TokenUnit, VARIABLE_FORMULA_OPERATORS, VARIABLE_SCOPES, VARIABLE_TYPES, Variable, VariableAlias, VariableCollection, VariableCollectionMode, VariableColorExpression, VariableFormula, VariableFormulaLiteral, VariableFormulaNode, VariableFormulaOperation, VariableFormulaOperator, VariableFormulaType, VariableLiteral, VariableModeMap, VariableScope, VariableType, VariableUnsupportedExpression, VariableValue, VariantPropSpec, VectorNetwork, VectorRegion, VectorSegment, VectorVertex, WindingRule, generateId, isHiddenFromPublishing, isLibraryCollection, isLibraryVariable, isModeAttributeName, setIdSession };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CommittedGraphEventError } from "./buffered-events.js";
|
|
2
|
-
import { generateId, setIdSession } from "./ids.js";
|
|
3
|
-
import { CODE_SYNTAX_PLATFORMS, EASING_CURVES, MODE_ATTRIBUTE_PATTERN, TEXT_BINDABLE_FIELDS, TOKEN_UNITS, VARIABLE_FORMULA_OPERATORS, VARIABLE_SCOPES, VARIABLE_TYPES, isLibraryCollection, isModeAttributeName } from "./types.js";
|
|
4
2
|
import { SceneGraph } from "./graph.js";
|
|
5
|
-
|
|
3
|
+
import { generateId, setIdSession } from "./ids.js";
|
|
4
|
+
import { CODE_SYNTAX_PLATFORMS, DOCUMENT_KINDS, EASING_CURVES, MODE_ATTRIBUTE_PATTERN, TEXT_BINDABLE_FIELDS, TOKEN_UNITS, VARIABLE_FORMULA_OPERATORS, VARIABLE_SCOPES, VARIABLE_TYPES, isHiddenFromPublishing, isLibraryCollection, isLibraryVariable, isModeAttributeName } from "./types.js";
|
|
5
|
+
export { CODE_SYNTAX_PLATFORMS, CommittedGraphEventError, DOCUMENT_KINDS, EASING_CURVES, MODE_ATTRIBUTE_PATTERN, SceneGraph, TEXT_BINDABLE_FIELDS, TOKEN_UNITS, VARIABLE_FORMULA_OPERATORS, VARIABLE_SCOPES, VARIABLE_TYPES, generateId, isHiddenFromPublishing, isLibraryCollection, isLibraryVariable, isModeAttributeName, setIdSession };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { assignmentOverrideField } from "./overrides.js";
|
|
2
|
-
|
|
2
|
+
// src/instances/assignments.ts
|
|
3
3
|
/** SLOT_CONTENT is absent because it drives children, which `ownsSlotContent` keeps instead. */
|
|
4
4
|
const PROPERTY_REFERENCE_FIELDS = {
|
|
5
5
|
VISIBLE: "visible",
|
|
@@ -116,7 +116,6 @@ function assignedFieldValues(graph, instChild, compChild) {
|
|
|
116
116
|
}
|
|
117
117
|
return values;
|
|
118
118
|
}
|
|
119
|
-
//#endregion
|
|
120
119
|
export { applyEnclosingAssignments, assignedFieldValues, propertyDrivenFields };
|
|
121
120
|
|
|
122
121
|
//# sourceMappingURL=assignments.js.map
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { isEqual } from "es-toolkit/predicate";
|
|
2
|
+
import { imagePaintHashes } from "../images.js";
|
|
3
|
+
import { isPluginDataEntry, pluginDataEntry, readPluginData, withoutPluginData } from "../plugin-data/field.js";
|
|
4
|
+
import { CONTENT_PLUGIN_DATA, OPEN_PENCIL_PLUGIN_DATA } from "../plugin-data/fields.js";
|
|
5
|
+
import { shaderEffectImages } from "../shaders/model.js";
|
|
6
|
+
// src/instances/content-marks.ts
|
|
7
|
+
/** A paint list by the kind OkHCL colors and icon tints name it. */
|
|
8
|
+
const PAINT_LISTS = {
|
|
9
|
+
fill: "fills",
|
|
10
|
+
stroke: "strokes"
|
|
11
|
+
};
|
|
12
|
+
const PAINT_KINDS = ["fill", "stroke"];
|
|
13
|
+
function entriesOf(node, field) {
|
|
14
|
+
return node.pluginData.filter((entry) => isPluginDataEntry(entry, field));
|
|
15
|
+
}
|
|
16
|
+
/** The layer's entries: a mark no instance override reaches. */
|
|
17
|
+
const followLayer = (field) => ({ layer }) => entriesOf(layer, field);
|
|
18
|
+
/**
|
|
19
|
+
* One entry per paint, as an OkHCL color is: a fill's from whichever of the copy and the layer
|
|
20
|
+
* the copy's fills come from, a stroke's likewise.
|
|
21
|
+
*/
|
|
22
|
+
const okhclColors = ({ copy, layer, kept }) => {
|
|
23
|
+
const field = OPEN_PENCIL_PLUGIN_DATA.okhcl;
|
|
24
|
+
return PAINT_KINDS.flatMap((kind) => entriesOf(kept(PAINT_LISTS[kind]) ? copy : layer, field).filter((entry) => field.decode(entry.value)?.kind === kind));
|
|
25
|
+
};
|
|
26
|
+
/** Which paint lists an icon path's color sets, each as its list is synced. */
|
|
27
|
+
const iconTint = ({ copy, layer, kept }) => {
|
|
28
|
+
const field = OPEN_PENCIL_PLUGIN_DATA.iconTint;
|
|
29
|
+
const tint = PAINT_KINDS.filter((kind) => {
|
|
30
|
+
const from = kept(PAINT_LISTS[kind]) ? copy : layer;
|
|
31
|
+
return readPluginData(from.pluginData, field)?.includes(kind) ?? false;
|
|
32
|
+
});
|
|
33
|
+
return tint.length > 0 ? [pluginDataEntry(field, tint)] : [];
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Entries matched to a paint or Shader effect by its frame's image: each image the copy's
|
|
37
|
+
* synced lists show takes the entry of whichever of the copy and the layer that list comes from.
|
|
38
|
+
*/
|
|
39
|
+
function stillPaints(field, withEffects) {
|
|
40
|
+
return ({ copy, layer, synced, kept }) => {
|
|
41
|
+
const lists = [
|
|
42
|
+
{
|
|
43
|
+
list: "fills",
|
|
44
|
+
images: imagePaintHashes(synced.fills)
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
list: "strokes",
|
|
48
|
+
images: imagePaintHashes(synced.strokes)
|
|
49
|
+
},
|
|
50
|
+
...withEffects ? [{
|
|
51
|
+
list: "effects",
|
|
52
|
+
images: shaderEffectImages(synced.effects)
|
|
53
|
+
}] : []
|
|
54
|
+
];
|
|
55
|
+
const byImage = /* @__PURE__ */ new Map();
|
|
56
|
+
for (const { list, images } of lists) {
|
|
57
|
+
const entries = entriesOf(kept(list) ? copy : layer, field);
|
|
58
|
+
for (const image of images) {
|
|
59
|
+
const entry = entries.find((item) => field.decode(item.value)?.image === image);
|
|
60
|
+
if (entry && !byImage.has(image)) byImage.set(image, entry);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return [...byImage.values()];
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Content fields whose value belongs to a property an instance can override; every other one
|
|
68
|
+
* follows the layer. A new content field follows unless it is listed here.
|
|
69
|
+
*/
|
|
70
|
+
const PROPERTY_MARKS = /* @__PURE__ */ new Map([
|
|
71
|
+
[OPEN_PENCIL_PLUGIN_DATA.okhcl.key, okhclColors],
|
|
72
|
+
[OPEN_PENCIL_PLUGIN_DATA.iconTint.key, iconTint],
|
|
73
|
+
[OPEN_PENCIL_PLUGIN_DATA.shader.key, stillPaints(OPEN_PENCIL_PLUGIN_DATA.shader, true)],
|
|
74
|
+
[OPEN_PENCIL_PLUGIN_DATA.mesh.key, stillPaints(OPEN_PENCIL_PLUGIN_DATA.mesh, false)]
|
|
75
|
+
]);
|
|
76
|
+
/**
|
|
77
|
+
* What the copy is in its parent's listing, which stays the component's even in a copy that
|
|
78
|
+
* shows another component.
|
|
79
|
+
*/
|
|
80
|
+
const PLACE_MARKS = /* @__PURE__ */ new Set([OPEN_PENCIL_PLUGIN_DATA.listingPart.key]);
|
|
81
|
+
/**
|
|
82
|
+
* The plugin data a copy has once it takes its component layer's content marks, or undefined
|
|
83
|
+
* when they already match. A mark tied to paints follows as those paints do; a copy that shows
|
|
84
|
+
* another component (`swapped`) keeps every mark of what it shows but its place in a listing.
|
|
85
|
+
*/
|
|
86
|
+
function syncedContentMarks(sync) {
|
|
87
|
+
let entries;
|
|
88
|
+
for (const field of CONTENT_PLUGIN_DATA) {
|
|
89
|
+
if (sync.swapped && !PLACE_MARKS.has(field.key)) continue;
|
|
90
|
+
const next = (PROPERTY_MARKS.get(field.key) ?? followLayer(field))(sync);
|
|
91
|
+
if (isEqual(entriesOf(sync.copy, field), next)) continue;
|
|
92
|
+
entries = [...withoutPluginData(entries ?? sync.copy.pluginData, [field]), ...next];
|
|
93
|
+
}
|
|
94
|
+
return entries;
|
|
95
|
+
}
|
|
96
|
+
export { syncedContentMarks };
|
|
97
|
+
|
|
98
|
+
//# sourceMappingURL=content-marks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-marks.js","names":[],"sources":["../../src/instances/content-marks.ts"],"sourcesContent":["// The content plugin data a copy takes from its component's layer when an instance syncs.\nimport { isEqual } from 'es-toolkit/predicate'\n\nimport { imagePaintHashes } from '../images'\nimport {\n isPluginDataEntry,\n pluginDataEntry,\n readPluginData,\n withoutPluginData,\n type PluginDataKey\n} from '../plugin-data/field'\nimport { CONTENT_PLUGIN_DATA, OPEN_PENCIL_PLUGIN_DATA } from '../plugin-data/fields'\nimport { shaderEffectImages } from '../shaders/model'\nimport type { PluginDataEntry, SceneNode } from '../types'\n\ninterface MarkSync {\n copy: SceneNode\n layer: SceneNode\n /** The paints and effects the copy has once the sync writes them. */\n synced: Pick<SceneNode, 'fills' | 'strokes' | 'effects'>\n /** A field the copy keeps as its own: overridden, bound, or driven by a property. */\n kept: (field: string) => boolean\n}\n\n/** The entries a copy ends up with under one key. */\ntype MarkRule = (sync: MarkSync) => PluginDataEntry[]\n\n/** A paint list by the kind OkHCL colors and icon tints name it. */\nconst PAINT_LISTS = { fill: 'fills', stroke: 'strokes' } as const\nconst PAINT_KINDS = ['fill', 'stroke'] as const\n\nfunction entriesOf(node: SceneNode, field: PluginDataKey): PluginDataEntry[] {\n return node.pluginData.filter((entry) => isPluginDataEntry(entry, field))\n}\n\n/** The layer's entries: a mark no instance override reaches. */\nconst followLayer =\n (field: PluginDataKey): MarkRule =>\n ({ layer }) =>\n entriesOf(layer, field)\n\n/**\n * One entry per paint, as an OkHCL color is: a fill's from whichever of the copy and the layer\n * the copy's fills come from, a stroke's likewise.\n */\nconst okhclColors: MarkRule = ({ copy, layer, kept }) => {\n const field = OPEN_PENCIL_PLUGIN_DATA.okhcl\n return PAINT_KINDS.flatMap((kind) =>\n entriesOf(kept(PAINT_LISTS[kind]) ? copy : layer, field).filter(\n (entry) => field.decode(entry.value)?.kind === kind\n )\n )\n}\n\n/** Which paint lists an icon path's color sets, each as its list is synced. */\nconst iconTint: MarkRule = ({ copy, layer, kept }) => {\n const field = OPEN_PENCIL_PLUGIN_DATA.iconTint\n const tint = PAINT_KINDS.filter((kind) => {\n const from = kept(PAINT_LISTS[kind]) ? copy : layer\n return readPluginData(from.pluginData, field)?.includes(kind) ?? false\n })\n return tint.length > 0 ? [pluginDataEntry(field, tint)] : []\n}\n\n/**\n * Entries matched to a paint or Shader effect by its frame's image: each image the copy's\n * synced lists show takes the entry of whichever of the copy and the layer that list comes from.\n */\nfunction stillPaints(\n field: typeof OPEN_PENCIL_PLUGIN_DATA.shader | typeof OPEN_PENCIL_PLUGIN_DATA.mesh,\n withEffects: boolean\n): MarkRule {\n return ({ copy, layer, synced, kept }) => {\n const lists = [\n { list: 'fills', images: imagePaintHashes(synced.fills) },\n { list: 'strokes', images: imagePaintHashes(synced.strokes) },\n ...(withEffects ? [{ list: 'effects', images: shaderEffectImages(synced.effects) }] : [])\n ]\n const byImage = new Map<string, PluginDataEntry>()\n for (const { list, images } of lists) {\n const entries = entriesOf(kept(list) ? copy : layer, field)\n for (const image of images) {\n const entry = entries.find((item) => field.decode(item.value)?.image === image)\n if (entry && !byImage.has(image)) byImage.set(image, entry)\n }\n }\n return [...byImage.values()]\n }\n}\n\n/**\n * Content fields whose value belongs to a property an instance can override; every other one\n * follows the layer. A new content field follows unless it is listed here.\n */\nconst PROPERTY_MARKS: ReadonlyMap<string, MarkRule> = new Map([\n [OPEN_PENCIL_PLUGIN_DATA.okhcl.key, okhclColors],\n [OPEN_PENCIL_PLUGIN_DATA.iconTint.key, iconTint],\n [OPEN_PENCIL_PLUGIN_DATA.shader.key, stillPaints(OPEN_PENCIL_PLUGIN_DATA.shader, true)],\n [OPEN_PENCIL_PLUGIN_DATA.mesh.key, stillPaints(OPEN_PENCIL_PLUGIN_DATA.mesh, false)]\n])\n\n/**\n * What the copy is in its parent's listing, which stays the component's even in a copy that\n * shows another component.\n */\nconst PLACE_MARKS: ReadonlySet<string> = new Set([OPEN_PENCIL_PLUGIN_DATA.listingPart.key])\n\n/**\n * The plugin data a copy has once it takes its component layer's content marks, or undefined\n * when they already match. A mark tied to paints follows as those paints do; a copy that shows\n * another component (`swapped`) keeps every mark of what it shows but its place in a listing.\n */\nexport function syncedContentMarks(\n sync: MarkSync & { swapped: boolean }\n): PluginDataEntry[] | undefined {\n let entries: PluginDataEntry[] | undefined\n for (const field of CONTENT_PLUGIN_DATA) {\n if (sync.swapped && !PLACE_MARKS.has(field.key)) continue\n const next = (PROPERTY_MARKS.get(field.key) ?? followLayer(field))(sync)\n if (isEqual(entriesOf(sync.copy, field), next)) continue\n entries = [...withoutPluginData(entries ?? sync.copy.pluginData, [field]), ...next]\n }\n return entries\n}\n"],"mappings":";;;;;;;AA4BA,MAAM,cAAc;CAAE,MAAM;CAAS,QAAQ;AAAU;AACvD,MAAM,cAAc,CAAC,QAAQ,QAAQ;AAErC,SAAS,UAAU,MAAiB,OAAyC;CAC3E,OAAO,KAAK,WAAW,QAAQ,UAAU,kBAAkB,OAAO,KAAK,CAAC;AAC1E;;AAGA,MAAM,eACH,WACA,EAAE,YACD,UAAU,OAAO,KAAK;;;;;AAM1B,MAAM,eAAyB,EAAE,MAAM,OAAO,WAAW;CACvD,MAAM,QAAQ,wBAAwB;CACtC,OAAO,YAAY,SAAS,SAC1B,UAAU,KAAK,YAAY,KAAK,IAAI,OAAO,OAAO,KAAK,CAAC,CAAC,QACtD,UAAU,MAAM,OAAO,MAAM,KAAK,CAAC,EAAE,SAAS,IACjD,CACF;AACF;;AAGA,MAAM,YAAsB,EAAE,MAAM,OAAO,WAAW;CACpD,MAAM,QAAQ,wBAAwB;CACtC,MAAM,OAAO,YAAY,QAAQ,SAAS;EACxC,MAAM,OAAO,KAAK,YAAY,KAAK,IAAI,OAAO;EAC9C,OAAO,eAAe,KAAK,YAAY,KAAK,CAAC,EAAE,SAAS,IAAI,KAAK;CACnE,CAAC;CACD,OAAO,KAAK,SAAS,IAAI,CAAC,gBAAgB,OAAO,IAAI,CAAC,IAAI,CAAC;AAC7D;;;;;AAMA,SAAS,YACP,OACA,aACU;CACV,QAAQ,EAAE,MAAM,OAAO,QAAQ,WAAW;EACxC,MAAM,QAAQ;GACZ;IAAE,MAAM;IAAS,QAAQ,iBAAiB,OAAO,KAAK;GAAE;GACxD;IAAE,MAAM;IAAW,QAAQ,iBAAiB,OAAO,OAAO;GAAE;GAC5D,GAAI,cAAc,CAAC;IAAE,MAAM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|
|
1
|
+
import { isEqual } from "es-toolkit/predicate";
|
|
2
2
|
import { TEXT_METRIC_FIELDS, TEXT_SHAPING_FIELDS } from "../fields/text.js";
|
|
3
3
|
import { layoutSizing } from "../layout/sizing.js";
|
|
4
|
-
import {
|
|
5
|
-
|
|
4
|
+
import { resizedChildRect } from "../resize.js";
|
|
5
|
+
// src/instances/content-size.ts
|
|
6
6
|
const METRIC_FIELDS = new Set(TEXT_METRIC_FIELDS);
|
|
7
7
|
/**
|
|
8
8
|
* The axes along which a copy sizes itself to its own content rather than to its component,
|
|
@@ -54,7 +54,6 @@ function remeasureChangedText(updates, copy) {
|
|
|
54
54
|
if (copy.type !== "TEXT" || !copy.derivedLayout) return;
|
|
55
55
|
if (Object.keys(updates).some((key) => METRIC_FIELDS.has(key))) updates.derivedLayout = null;
|
|
56
56
|
}
|
|
57
|
-
//#endregion
|
|
58
57
|
export { keepOwnContentSize, remeasureChangedText };
|
|
59
58
|
|
|
60
59
|
//# sourceMappingURL=content-size.js.map
|
package/dist/instances/copies.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { copiedComponentLayerId, hasInstanceOverride } from "./overrides.js";
|
|
2
1
|
import { ownsSlotContent, slotPropertyId } from "../slots/frames.js";
|
|
3
2
|
import "../undo.js";
|
|
4
|
-
|
|
3
|
+
import { copiedComponentLayerId, hasInstanceOverride } from "./overrides.js";
|
|
4
|
+
// src/instances/copies.ts
|
|
5
5
|
function createInstanceSyncContext(instanceId, overrides) {
|
|
6
6
|
return {
|
|
7
7
|
instanceId,
|
|
@@ -155,7 +155,6 @@ function removeLeftoverCopies(graph, context, removals) {
|
|
|
155
155
|
}
|
|
156
156
|
context.leftovers.clear();
|
|
157
157
|
}
|
|
158
|
-
//#endregion
|
|
159
158
|
export { createInstanceSyncContext, groupCopyRemovals, hasUnplacedCopiesBelow, removeLeftoverCopies, restoreRemovedCopy, unplacedCopy };
|
|
160
159
|
|
|
161
160
|
//# sourceMappingURL=copies.js.map
|
|
@@ -1,20 +1,17 @@
|
|
|
1
1
|
import { SceneGraph } from "../graph.js";
|
|
2
|
-
//#region src/instances/cycles.d.ts
|
|
3
2
|
/**
|
|
4
3
|
* Whether moving `nodeId` under `parentId` would make a component contain itself: its layers,
|
|
5
4
|
* followed through instances into their components, reach a component at or above the parent.
|
|
6
5
|
* Both components and instances above the parent count: an instance's layers are its
|
|
7
6
|
* component's, so a swap inside one may not bring that component back in.
|
|
8
7
|
*/
|
|
9
|
-
declare function createsComponentCycle(graph: SceneGraph, nodeId: string, parentId: string): boolean;
|
|
8
|
+
export declare function createsComponentCycle(graph: SceneGraph, nodeId: string, parentId: string): boolean;
|
|
10
9
|
/** Whether placing this definition's instance under `parentId` would make a component contain itself. */
|
|
11
|
-
declare function canCreateInstance(graph: SceneGraph, componentId: string, parentId: string): boolean;
|
|
10
|
+
export declare function canCreateInstance(graph: SceneGraph, componentId: string, parentId: string): boolean;
|
|
12
11
|
/**
|
|
13
12
|
* `parentId`, or its nearest ancestor that can hold these layers or instances of these
|
|
14
13
|
* components without a component containing itself. Figma pastes an instance next to its own
|
|
15
14
|
* component, not in it.
|
|
16
15
|
*/
|
|
17
|
-
declare function cycleSafeParent(graph: SceneGraph, parentId: string, nodeIds: readonly string[]): string;
|
|
18
|
-
//#endregion
|
|
19
|
-
export { canCreateInstance, createsComponentCycle, cycleSafeParent };
|
|
16
|
+
export declare function cycleSafeParent(graph: SceneGraph, parentId: string, nodeIds: readonly string[]): string;
|
|
20
17
|
//# sourceMappingURL=cycles.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cycles.d.ts","names":[],"sources":["../../src/instances/cycles.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"cycles.d.ts","names":[],"sources":["../../src/instances/cycles.ts"],"mappings":";;;;;;;wBAuBgB,sBACd,OAAO,YACP,gBACA;;wBAmBc,kBACd,OAAO,YACP,qBACA;;;;;;wBAWc,gBACd,OAAO,YACP,kBACA"}
|
package/dist/instances/cycles.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { instanceMainComponent } from "./main-component.js";
|
|
2
|
-
|
|
2
|
+
// src/instances/cycles.ts
|
|
3
3
|
/** Components at or above `parentId`, counting the component each enclosing instance shows. */
|
|
4
4
|
function enclosingComponents(graph, parentId) {
|
|
5
5
|
const ancestors = /* @__PURE__ */ new Set();
|
|
@@ -47,7 +47,6 @@ function canCreateInstance(graph, componentId, parentId) {
|
|
|
47
47
|
function cycleSafeParent(graph, parentId, nodeIds) {
|
|
48
48
|
return graph.closest(parentId, (node) => (node.id === parentId || node.type !== "COMPONENT_SET") && nodeIds.every((id) => !createsComponentCycle(graph, id, node.id)))?.id ?? parentId;
|
|
49
49
|
}
|
|
50
|
-
//#endregion
|
|
51
50
|
export { canCreateInstance, createsComponentCycle, cycleSafeParent };
|
|
52
51
|
|
|
53
52
|
//# sourceMappingURL=cycles.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { SceneGraph } from "../graph.js";
|
|
2
|
+
import { SceneNode } from "../types.js";
|
|
3
|
+
/**
|
|
4
|
+
* The main components and sets inside layers about to be deleted that an instance outside them
|
|
5
|
+
* still uses, and so stay as Figma keeps them. A set counts whole.
|
|
6
|
+
*/
|
|
7
|
+
export declare function usedMainComponents(graph: SceneGraph, rootIds: readonly string[]): SceneNode[];
|
|
8
|
+
/**
|
|
9
|
+
* The main components a delete kept on the internal page that no instance uses any more, counted
|
|
10
|
+
* together: one used only from inside another unused one is unused too. A save leaves them out,
|
|
11
|
+
* as Figma's does, and writes the others whole, so every instance inside one it writes counts.
|
|
12
|
+
* `usedElsewhere` names kept components instances outside the graph use, as on pages not loaded.
|
|
13
|
+
*/
|
|
14
|
+
export declare function unusedKeptComponents(graph: SceneGraph, usedElsewhere?: ReadonlySet<string>): ReadonlySet<string>;
|
|
15
|
+
/**
|
|
16
|
+
* Readies layers for deletion as Figma deletes a main component: each of `usedMainComponents`
|
|
17
|
+
* moves to the internal page with `deletedFrom` naming the page and layers it sat in. Its
|
|
18
|
+
* instances keep their contents and overrides, and a `.fig` save writes it as Figma does. One
|
|
19
|
+
* kept already, deleted again, keeps where it was first deleted from. Returns the layers moved
|
|
20
|
+
* and every layer inside them, which the caller must not delete.
|
|
21
|
+
*/
|
|
22
|
+
export declare function keepUsedMainComponents(graph: SceneGraph, rootIds: readonly string[]): ReadonlySet<string>;
|
|
23
|
+
//# sourceMappingURL=deleted.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deleted.d.ts","names":[],"sources":["../../src/instances/deleted.ts"],"mappings":";;;;;;wBAQgB,mBAAmB,OAAO,YAAY,6BAA6B;;;;;;;wBAiDnE,qBACd,OAAO,YACP,gBAAe,sBACd;;;;;;;;wBA0Ba,uBACd,OAAO,YACP,6BACC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { internalCanvas } from "../shared-styles.js";
|
|
2
|
+
// src/instances/deleted.ts
|
|
3
|
+
/**
|
|
4
|
+
* The main components and sets inside layers about to be deleted that an instance outside them
|
|
5
|
+
* still uses, and so stay as Figma keeps them. A set counts whole.
|
|
6
|
+
*/
|
|
7
|
+
function usedMainComponents(graph, rootIds) {
|
|
8
|
+
const deleted = /* @__PURE__ */ new Set();
|
|
9
|
+
const subtree = (id) => subtreeIds(graph, id);
|
|
10
|
+
for (const id of rootIds) for (const each of subtree(id)) deleted.add(each);
|
|
11
|
+
const usedOutside = (component) => [...graph.instanceIndex.get(component.id) ?? []].some((id) => graph.getNode(id) !== void 0 && !deleted.has(id));
|
|
12
|
+
const isUsed = (node) => node.type === "COMPONENT_SET" ? graph.getChildren(node.id).some((variant) => usedOutside(variant)) : node.type === "COMPONENT" && usedOutside(node);
|
|
13
|
+
const kept = [];
|
|
14
|
+
const keptIds = /* @__PURE__ */ new Set();
|
|
15
|
+
/** Keeps the used components under `node`; returns whether it kept any. */
|
|
16
|
+
const keepUnder = (node) => {
|
|
17
|
+
if (keptIds.has(node.id)) return false;
|
|
18
|
+
if (!isUsed(node)) return graph.getChildren(node.id).reduce((found, child) => keepUnder(child) || found, false);
|
|
19
|
+
kept.push(node);
|
|
20
|
+
keptIds.add(node.id);
|
|
21
|
+
for (const id of subtree(node.id)) deleted.delete(id);
|
|
22
|
+
return true;
|
|
23
|
+
};
|
|
24
|
+
const requested = new Set(rootIds);
|
|
25
|
+
const roots = rootIds.flatMap((id) => {
|
|
26
|
+
const node = graph.getNode(id);
|
|
27
|
+
if (!node?.parentId) return node ? [node] : [];
|
|
28
|
+
return graph.closest(node.parentId, (parent) => requested.has(parent.id)) ? [] : [node];
|
|
29
|
+
});
|
|
30
|
+
let found = true;
|
|
31
|
+
while (found) found = roots.reduce((any, root) => keepUnder(root) || any, false);
|
|
32
|
+
return kept.filter((node) => !node.parentId || !graph.closest(node.parentId, (parent) => keptIds.has(parent.id)));
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The main components a delete kept on the internal page that no instance uses any more, counted
|
|
36
|
+
* together: one used only from inside another unused one is unused too. A save leaves them out,
|
|
37
|
+
* as Figma's does, and writes the others whole, so every instance inside one it writes counts.
|
|
38
|
+
* `usedElsewhere` names kept components instances outside the graph use, as on pages not loaded.
|
|
39
|
+
*/
|
|
40
|
+
function unusedKeptComponents(graph, usedElsewhere = /* @__PURE__ */ new Set()) {
|
|
41
|
+
const internal = graph.getPages(true).find((page) => page.internalOnly);
|
|
42
|
+
if (!internal) return /* @__PURE__ */ new Set();
|
|
43
|
+
const unused = new Set(graph.getChildren(internal.id).filter((child) => child.deletedFrom.length > 0 && !usedElsewhere.has(child.id)).map((node) => node.id));
|
|
44
|
+
for (;;) {
|
|
45
|
+
const used = usedMainComponents(graph, [...unused]).flatMap((node) => graph.closest(node.id, (each) => unused.has(each.id))?.id ?? []);
|
|
46
|
+
if (used.length === 0) return unused;
|
|
47
|
+
for (const id of used) unused.delete(id);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Readies layers for deletion as Figma deletes a main component: each of `usedMainComponents`
|
|
52
|
+
* moves to the internal page with `deletedFrom` naming the page and layers it sat in. Its
|
|
53
|
+
* instances keep their contents and overrides, and a `.fig` save writes it as Figma does. One
|
|
54
|
+
* kept already, deleted again, keeps where it was first deleted from. Returns the layers moved
|
|
55
|
+
* and every layer inside them, which the caller must not delete.
|
|
56
|
+
*/
|
|
57
|
+
function keepUsedMainComponents(graph, rootIds) {
|
|
58
|
+
const kept = usedMainComponents(graph, rootIds);
|
|
59
|
+
if (kept.length === 0) return /* @__PURE__ */ new Set();
|
|
60
|
+
const internal = internalCanvas(graph);
|
|
61
|
+
for (const node of kept) {
|
|
62
|
+
const deletedFrom = node.deletedFrom.length > 0 ? node.deletedFrom : ancestorIds(graph, node);
|
|
63
|
+
graph.reparentNode(node.id, internal.id);
|
|
64
|
+
graph.updateNode(node.id, { deletedFrom });
|
|
65
|
+
}
|
|
66
|
+
return new Set(kept.flatMap((node) => subtreeIds(graph, node.id)));
|
|
67
|
+
}
|
|
68
|
+
function subtreeIds(graph, id) {
|
|
69
|
+
return [id, ...(graph.getNode(id)?.childIds ?? []).flatMap((child) => subtreeIds(graph, child))];
|
|
70
|
+
}
|
|
71
|
+
/** The page and layers above a layer, outermost first. */
|
|
72
|
+
function ancestorIds(graph, node) {
|
|
73
|
+
const ids = [];
|
|
74
|
+
graph.closest(node.parentId ?? graph.rootId, (parent) => {
|
|
75
|
+
if (parent.id !== graph.rootId) ids.unshift(parent.id);
|
|
76
|
+
return parent.id === graph.rootId;
|
|
77
|
+
});
|
|
78
|
+
return ids;
|
|
79
|
+
}
|
|
80
|
+
export { keepUsedMainComponents, unusedKeptComponents, usedMainComponents };
|
|
81
|
+
|
|
82
|
+
//# sourceMappingURL=deleted.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deleted.js","names":[],"sources":["../../src/instances/deleted.ts"],"sourcesContent":["import type { SceneGraph } from '../graph'\nimport { internalCanvas } from '../shared-styles'\nimport type { SceneNode } from '../types'\n\n/**\n * The main components and sets inside layers about to be deleted that an instance outside them\n * still uses, and so stay as Figma keeps them. A set counts whole.\n */\nexport function usedMainComponents(graph: SceneGraph, rootIds: readonly string[]): SceneNode[] {\n const deleted = new Set<string>()\n const subtree = (id: string): string[] => subtreeIds(graph, id)\n for (const id of rootIds) for (const each of subtree(id)) deleted.add(each)\n const usedOutside = (component: SceneNode): boolean =>\n [...(graph.instanceIndex.get(component.id) ?? [])].some(\n (id) => graph.getNode(id) !== undefined && !deleted.has(id)\n )\n const isUsed = (node: SceneNode): boolean =>\n node.type === 'COMPONENT_SET'\n ? graph.getChildren(node.id).some((variant) => usedOutside(variant))\n : node.type === 'COMPONENT' && usedOutside(node)\n const kept: SceneNode[] = []\n const keptIds = new Set<string>()\n /** Keeps the used components under `node`; returns whether it kept any. */\n const keepUnder = (node: SceneNode): boolean => {\n if (keptIds.has(node.id)) return false\n if (!isUsed(node)) {\n return graph.getChildren(node.id).reduce((found, child) => keepUnder(child) || found, false)\n }\n kept.push(node)\n keptIds.add(node.id)\n for (const id of subtree(node.id)) deleted.delete(id)\n return true\n }\n // A layer inside another one being deleted is reached through it, so it is no root of its own:\n // scanned again, a variant of a kept set would leave the set.\n const requested = new Set(rootIds)\n const roots = rootIds.flatMap((id) => {\n const node = graph.getNode(id)\n if (!node?.parentId) return node ? [node] : []\n const nested = graph.closest(node.parentId, (parent) => requested.has(parent.id))\n return nested ? [] : [node]\n })\n // A kept component keeps the instances inside it, which may keep other components in turn.\n let found = true\n while (found) found = roots.reduce((any, root) => keepUnder(root) || any, false)\n // One kept first can turn out to sit inside one a later pass keeps, and stays in it.\n return kept.filter(\n (node) => !node.parentId || !graph.closest(node.parentId, (parent) => keptIds.has(parent.id))\n )\n}\n\n/**\n * The main components a delete kept on the internal page that no instance uses any more, counted\n * together: one used only from inside another unused one is unused too. A save leaves them out,\n * as Figma's does, and writes the others whole, so every instance inside one it writes counts.\n * `usedElsewhere` names kept components instances outside the graph use, as on pages not loaded.\n */\nexport function unusedKeptComponents(\n graph: SceneGraph,\n usedElsewhere: ReadonlySet<string> = new Set()\n): ReadonlySet<string> {\n const internal = graph.getPages(true).find((page) => page.internalOnly)\n if (!internal) return new Set()\n const unused = new Set(\n graph\n .getChildren(internal.id)\n .filter((child) => child.deletedFrom.length > 0 && !usedElsewhere.has(child.id))\n .map((node) => node.id)\n )\n // A component used by a layer nested in it is written whole, instances of others among it.\n for (;;) {\n const used = usedMainComponents(graph, [...unused]).flatMap(\n (node) => graph.closest(node.id, (each) => unused.has(each.id))?.id ?? []\n )\n if (used.length === 0) return unused\n for (const id of used) unused.delete(id)\n }\n}\n\n/**\n * Readies layers for deletion as Figma deletes a main component: each of `usedMainComponents`\n * moves to the internal page with `deletedFrom` naming the page and layers it sat in. Its\n * instances keep their contents and overrides, and a `.fig` save writes it as Figma does. One\n * kept already, deleted again, keeps where it was first deleted from. Returns the layers moved\n * and every layer inside them, which the caller must not delete.\n */\nexport function keepUsedMainComponents(\n graph: SceneGraph,\n rootIds: readonly string[]\n): ReadonlySet<string> {\n const kept = usedMainComponents(graph, rootIds)\n if (kept.length === 0) return new Set()\n const internal = internalCanvas(graph)\n for (const node of kept) {\n const deletedFrom = node.deletedFrom.length > 0 ? node.deletedFrom : ancestorIds(graph, node)\n graph.reparentNode(node.id, internal.id)\n graph.updateNode(node.id, { deletedFrom })\n }\n return new Set(kept.flatMap((node) => subtreeIds(graph, node.id)))\n}\n\nfunction subtreeIds(graph: SceneGraph, id: string): string[] {\n return [id, ...(graph.getNode(id)?.childIds ?? []).flatMap((child) => subtreeIds(graph, child))]\n}\n\n/** The page and layers above a layer, outermost first. */\nfunction ancestorIds(graph: SceneGraph, node: SceneNode): string[] {\n const ids: string[] = []\n // `closest` stops on a parent cycle in bad data.\n graph.closest(node.parentId ?? graph.rootId, (parent) => {\n if (parent.id !== graph.rootId) ids.unshift(parent.id)\n return parent.id === graph.rootId\n })\n return ids\n}\n"],"mappings":";;;;;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