@open-pencil/scene-graph 0.17.0 → 0.18.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/behaviours/index.d.ts +3 -2
- package/dist/behaviours/index.js +2 -1
- package/dist/behaviours/kinds.d.ts.map +1 -1
- package/dist/behaviours/kinds.js +15 -8
- package/dist/behaviours/kinds.js.map +1 -1
- package/dist/behaviours/model.d.ts +2 -2
- package/dist/behaviours/model.d.ts.map +1 -1
- package/dist/behaviours/model.js.map +1 -1
- package/dist/behaviours/schema.d.ts +136 -1
- package/dist/behaviours/schema.d.ts.map +1 -1
- package/dist/behaviours/schema.js +17 -2
- package/dist/behaviours/schema.js.map +1 -1
- package/dist/behaviours/spec.d.ts.map +1 -1
- package/dist/behaviours/spec.js +4 -0
- package/dist/behaviours/spec.js.map +1 -1
- package/dist/behaviours/transition.d.ts +23 -0
- package/dist/behaviours/transition.d.ts.map +1 -0
- package/dist/behaviours/transition.js +36 -0
- package/dist/behaviours/transition.js.map +1 -0
- package/dist/checkpoint.d.ts.map +1 -1
- package/dist/checkpoint.js +2 -0
- package/dist/checkpoint.js.map +1 -1
- package/dist/color/index.d.ts +12 -9
- package/dist/color/index.d.ts.map +1 -1
- package/dist/color/index.js +15 -25
- package/dist/color/index.js.map +1 -1
- package/dist/color/management.d.ts +51 -23
- package/dist/color/management.d.ts.map +1 -1
- package/dist/color/management.js +154 -149
- package/dist/color/management.js.map +1 -1
- package/dist/color/okhcl.d.ts +28 -10
- package/dist/color/okhcl.d.ts.map +1 -1
- package/dist/color/okhcl.js +56 -40
- package/dist/color/okhcl.js.map +1 -1
- package/dist/color/schema.d.ts +6 -1
- package/dist/color/schema.d.ts.map +1 -1
- package/dist/color/schema.js +10 -1
- package/dist/color/schema.js.map +1 -1
- package/dist/constraints.d.ts.map +1 -1
- package/dist/constraints.js +2 -1
- package/dist/constraints.js.map +1 -1
- package/dist/copy.d.ts +7 -1
- package/dist/copy.d.ts.map +1 -1
- package/dist/copy.js +22 -1
- package/dist/copy.js.map +1 -1
- package/dist/corners.d.ts +3 -1
- package/dist/corners.d.ts.map +1 -1
- package/dist/corners.js +3 -1
- package/dist/corners.js.map +1 -1
- package/dist/css/grid.js +1 -1
- package/dist/css/index.d.ts +2 -1
- package/dist/css/index.js +3 -2
- package/dist/css/motion.d.ts +12 -0
- package/dist/css/motion.d.ts.map +1 -0
- package/dist/css/motion.js +60 -0
- package/dist/css/motion.js.map +1 -0
- package/dist/css/shadows.d.ts +4 -3
- package/dist/css/shadows.d.ts.map +1 -1
- package/dist/css/shadows.js +7 -6
- package/dist/css/shadows.js.map +1 -1
- package/dist/css/values.d.ts +3 -2
- package/dist/css/values.d.ts.map +1 -1
- package/dist/css/values.js +4 -4
- package/dist/css/values.js.map +1 -1
- package/dist/fields/index.d.ts +2 -2
- package/dist/fields/index.js +2 -2
- package/dist/fields/layout.d.ts +3 -1
- package/dist/fields/layout.d.ts.map +1 -1
- package/dist/fields/layout.js +9 -1
- package/dist/fields/layout.js.map +1 -1
- package/dist/figjam/palette.js +1 -1
- package/dist/font-style.d.ts.map +1 -1
- package/dist/font-style.js +7 -3
- package/dist/font-style.js.map +1 -1
- package/dist/generated/index.d.ts +6 -2
- package/dist/generated/index.d.ts.map +1 -1
- package/dist/generated/index.js +14 -4
- package/dist/generated/index.js.map +1 -1
- package/dist/geometry.d.ts +6 -1
- package/dist/geometry.d.ts.map +1 -1
- package/dist/geometry.js +10 -2
- package/dist/geometry.js.map +1 -1
- package/dist/graph.d.ts +29 -4
- package/dist/graph.d.ts.map +1 -1
- package/dist/graph.js +59 -9
- package/dist/graph.js.map +1 -1
- package/dist/group-bounds.d.ts +5 -2
- package/dist/group-bounds.d.ts.map +1 -1
- package/dist/group-bounds.js +38 -8
- package/dist/group-bounds.js.map +1 -1
- package/dist/hit-test.d.ts.map +1 -1
- package/dist/hit-test.js +19 -8
- package/dist/hit-test.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/instances/content-size.js +1 -1
- package/dist/instances/fields.d.ts +2 -2
- package/dist/instances/fields.d.ts.map +1 -1
- package/dist/instances/fields.js +2 -0
- package/dist/instances/fields.js.map +1 -1
- package/dist/instances/index.d.ts.map +1 -1
- package/dist/instances/index.js +50 -11
- package/dist/instances/index.js.map +1 -1
- package/dist/instances/sync.js +67 -7
- package/dist/instances/sync.js.map +1 -1
- package/dist/layout/flow.d.ts +16 -0
- package/dist/layout/flow.d.ts.map +1 -0
- package/dist/layout/flow.js +34 -0
- package/dist/layout/flow.js.map +1 -0
- package/dist/layout/index.d.ts +4 -3
- package/dist/layout/index.js +4 -3
- package/dist/layout/keywords.d.ts.map +1 -1
- package/dist/layout/keywords.js +7 -1
- package/dist/layout/keywords.js.map +1 -1
- package/dist/layout/sizing.d.ts +9 -1
- package/dist/layout/sizing.d.ts.map +1 -1
- package/dist/layout/sizing.js +17 -1
- package/dist/layout/sizing.js.map +1 -1
- package/dist/layout/spacing.d.ts +7 -1
- package/dist/layout/spacing.d.ts.map +1 -1
- package/dist/layout/spacing.js +10 -1
- package/dist/layout/spacing.js.map +1 -1
- package/dist/mesh/geometry.d.ts +83 -0
- package/dist/mesh/geometry.d.ts.map +1 -0
- package/dist/mesh/geometry.js +441 -0
- package/dist/mesh/geometry.js.map +1 -0
- package/dist/mesh/index.d.ts +4 -0
- package/dist/mesh/index.js +4 -0
- package/dist/mesh/model.d.ts +28 -0
- package/dist/mesh/model.d.ts.map +1 -0
- package/dist/mesh/model.js +40 -0
- package/dist/mesh/model.js.map +1 -0
- package/dist/mesh/schema.d.ts +191 -0
- package/dist/mesh/schema.d.ts.map +1 -0
- package/dist/mesh/schema.js +56 -0
- package/dist/mesh/schema.js.map +1 -0
- package/dist/mutation-impact.d.ts +2 -0
- package/dist/mutation-impact.d.ts.map +1 -1
- package/dist/mutation-impact.js +18 -7
- package/dist/mutation-impact.js.map +1 -1
- package/dist/node-defaults.d.ts +3 -1
- package/dist/node-defaults.d.ts.map +1 -1
- package/dist/node-defaults.js +22 -6
- package/dist/node-defaults.js.map +1 -1
- package/dist/paints/index.d.ts +5 -3
- package/dist/paints/index.js +5 -3
- package/dist/paints/pattern.d.ts +5 -1
- package/dist/paints/pattern.d.ts.map +1 -1
- package/dist/paints/pattern.js +33 -1
- package/dist/paints/pattern.js.map +1 -1
- package/dist/paints/shows.d.ts +4 -1
- package/dist/paints/shows.d.ts.map +1 -1
- package/dist/paints/shows.js +8 -1
- package/dist/paints/shows.js.map +1 -1
- package/dist/paints/solid.d.ts +11 -0
- package/dist/paints/solid.d.ts.map +1 -0
- package/dist/paints/solid.js +18 -0
- package/dist/paints/solid.js.map +1 -0
- package/dist/paints/stills.d.ts +74 -0
- package/dist/paints/stills.d.ts.map +1 -0
- package/dist/paints/stills.js +113 -0
- package/dist/paints/stills.js.map +1 -0
- package/dist/plugin-data/field.d.ts.map +1 -1
- package/dist/plugin-data/field.js +2 -0
- package/dist/plugin-data/field.js.map +1 -1
- package/dist/plugin-data/fields.d.ts +67 -0
- package/dist/plugin-data/fields.d.ts.map +1 -1
- package/dist/plugin-data/fields.js +12 -7
- package/dist/plugin-data/fields.js.map +1 -1
- package/dist/resize.d.ts +10 -3
- package/dist/resize.d.ts.map +1 -1
- package/dist/resize.js +34 -3
- package/dist/resize.js.map +1 -1
- package/dist/scaling/index.d.ts +2 -2
- package/dist/scaling/index.js +2 -2
- package/dist/scaling/node.d.ts +2 -1
- package/dist/scaling/node.d.ts.map +1 -1
- package/dist/scaling/node.js +27 -7
- package/dist/scaling/node.js.map +1 -1
- package/dist/shaders/index.d.ts +2 -3
- package/dist/shaders/index.js +2 -3
- package/dist/shaders/model.d.ts +3 -11
- package/dist/shaders/model.d.ts.map +1 -1
- package/dist/shaders/model.js +13 -36
- package/dist/shaders/model.js.map +1 -1
- package/dist/shaders/schema.d.ts +1 -1
- package/dist/shaders/schema.js +1 -1
- package/dist/shaders/schema.js.map +1 -1
- package/dist/shape-with-text/document.js +276 -0
- package/dist/shape-with-text/document.js.map +1 -0
- package/dist/shape-with-text/geometry.d.ts +13 -1
- package/dist/shape-with-text/geometry.d.ts.map +1 -1
- package/dist/shape-with-text/geometry.js +103 -41
- package/dist/shape-with-text/geometry.js.map +1 -1
- package/dist/shape-with-text/index.d.ts +2 -2
- package/dist/shape-with-text/index.js +2 -2
- package/dist/shared-style-index.d.ts +21 -0
- package/dist/shared-style-index.d.ts.map +1 -0
- package/dist/shared-style-index.js +72 -0
- package/dist/shared-style-index.js.map +1 -0
- package/dist/shared-styles.d.ts +3 -3
- package/dist/shared-styles.d.ts.map +1 -1
- package/dist/shared-styles.js +16 -7
- package/dist/shared-styles.js.map +1 -1
- package/dist/slides/drop.d.ts +32 -0
- package/dist/slides/drop.d.ts.map +1 -0
- package/dist/slides/drop.js +81 -0
- package/dist/slides/drop.js.map +1 -0
- package/dist/slides/index.d.ts +56 -0
- package/dist/slides/index.d.ts.map +1 -0
- package/dist/slides/index.js +134 -0
- package/dist/slides/index.js.map +1 -0
- package/dist/slides/motion.d.ts +55 -0
- package/dist/slides/motion.d.ts.map +1 -0
- package/dist/slides/motion.js +142 -0
- package/dist/slides/motion.js.map +1 -0
- package/dist/slides/playback.d.ts +59 -0
- package/dist/slides/playback.d.ts.map +1 -0
- package/dist/slides/playback.js +188 -0
- package/dist/slides/playback.js.map +1 -0
- package/dist/slides/types.d.ts +62 -0
- package/dist/slides/types.d.ts.map +1 -0
- package/dist/slides/types.js +39 -0
- package/dist/slides/types.js.map +1 -0
- package/dist/statuses/workflow.js +1 -1
- package/dist/text/direction.d.ts +6 -3
- package/dist/text/direction.d.ts.map +1 -1
- package/dist/text/direction.js +12 -12
- package/dist/text/direction.js.map +1 -1
- package/dist/text/index.d.ts +2 -1
- package/dist/text/index.js +3 -2
- package/dist/text/name.d.ts +22 -0
- package/dist/text/name.d.ts.map +1 -0
- package/dist/text/name.js +38 -0
- package/dist/text/name.js.map +1 -0
- package/dist/text/references.d.ts.map +1 -1
- package/dist/text/references.js +1 -2
- package/dist/text/references.js.map +1 -1
- package/dist/thumbnail.d.ts +23 -0
- package/dist/thumbnail.d.ts.map +1 -0
- package/dist/thumbnail.js +47 -0
- package/dist/thumbnail.js.map +1 -0
- package/dist/transfer/apply.d.ts.map +1 -1
- package/dist/transfer/apply.js +14 -3
- package/dist/transfer/apply.js.map +1 -1
- package/dist/transfer/copied.d.ts +6 -1
- package/dist/transfer/copied.d.ts.map +1 -1
- package/dist/transfer/copied.js +2 -2
- package/dist/transfer/copied.js.map +1 -1
- package/dist/transfer/dependencies.d.ts +4 -1
- package/dist/transfer/dependencies.d.ts.map +1 -1
- package/dist/transfer/dependencies.js +10 -1
- package/dist/transfer/dependencies.js.map +1 -1
- package/dist/transfer/history.js +2 -0
- package/dist/transfer/history.js.map +1 -1
- package/dist/transfer/identity.js +18 -3
- package/dist/transfer/identity.js.map +1 -1
- package/dist/transfer/index.d.ts +2 -1
- package/dist/transfer/index.js +4 -3
- package/dist/transfer/library.d.ts +45 -0
- package/dist/transfer/library.d.ts.map +1 -0
- package/dist/transfer/library.js +102 -0
- package/dist/transfer/library.js.map +1 -0
- package/dist/transfer/nodes.d.ts.map +1 -1
- package/dist/transfer/nodes.js +9 -0
- package/dist/transfer/nodes.js.map +1 -1
- package/dist/transfer/plan.d.ts +9 -0
- package/dist/transfer/plan.d.ts.map +1 -1
- package/dist/transfer/plan.js +51 -6
- package/dist/transfer/plan.js.map +1 -1
- package/dist/transfer/remove.js +7 -1
- package/dist/transfer/remove.js.map +1 -1
- package/dist/transfer/validation.js +8 -4
- package/dist/transfer/validation.js.map +1 -1
- package/dist/transfer/variables.d.ts.map +1 -1
- package/dist/transfer/variables.js +2 -1
- package/dist/transfer/variables.js.map +1 -1
- package/dist/types.d.ts +90 -12
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +33 -1
- package/dist/types.js.map +1 -1
- package/dist/variables/bindings.d.ts +11 -6
- package/dist/variables/bindings.d.ts.map +1 -1
- package/dist/variables/bindings.js +162 -38
- package/dist/variables/bindings.js.map +1 -1
- package/dist/variables/easing.d.ts +48 -0
- package/dist/variables/easing.d.ts.map +1 -0
- package/dist/variables/easing.js +321 -0
- package/dist/variables/easing.js.map +1 -0
- package/dist/variables/formula/index.d.ts +4 -2
- package/dist/variables/formula/index.d.ts.map +1 -1
- package/dist/variables/formula/index.js +26 -9
- package/dist/variables/formula/index.js.map +1 -1
- package/dist/variables/formula/parse.js +1 -1
- package/dist/variables/formula/schema.js +1 -1
- package/dist/variables/formula/signatures.d.ts +2 -2
- package/dist/variables/formula/signatures.d.ts.map +1 -1
- package/dist/variables/formula/signatures.js.map +1 -1
- package/dist/variables/formula/tree.d.ts +2 -2
- package/dist/variables/formula/tree.d.ts.map +1 -1
- package/dist/variables/formula/tree.js.map +1 -1
- package/dist/variables/index.d.ts +22 -5
- package/dist/variables/index.d.ts.map +1 -1
- package/dist/variables/index.js +67 -17
- package/dist/variables/index.js.map +1 -1
- package/dist/variables/lookup.js +1 -1
- package/dist/variables/lookup.js.map +1 -1
- package/dist/variables/motion.d.ts +46 -0
- package/dist/variables/motion.d.ts.map +1 -0
- package/dist/variables/motion.js +107 -0
- package/dist/variables/motion.js.map +1 -0
- package/dist/variables/paints.d.ts +10 -2
- package/dist/variables/paints.d.ts.map +1 -1
- package/dist/variables/paints.js +24 -10
- package/dist/variables/paints.js.map +1 -1
- package/dist/variables/resolution.d.ts.map +1 -1
- package/dist/variables/resolution.js +10 -9
- package/dist/variables/resolution.js.map +1 -1
- package/dist/variables/schema.d.ts +59 -1
- package/dist/variables/schema.d.ts.map +1 -1
- package/dist/variables/schema.js +36 -1
- package/dist/variables/schema.js.map +1 -1
- package/dist/variables/style-bindings.d.ts +23 -0
- package/dist/variables/style-bindings.d.ts.map +1 -0
- package/dist/variables/style-bindings.js +83 -0
- package/dist/variables/style-bindings.js.map +1 -0
- package/package.json +21 -2
- package/src/behaviours/index.ts +1 -0
- package/src/behaviours/kinds.ts +5 -1
- package/src/behaviours/model.ts +2 -2
- package/src/behaviours/schema.ts +19 -2
- package/src/behaviours/spec.ts +5 -0
- package/src/behaviours/transition.ts +46 -0
- package/src/checkpoint.ts +2 -0
- package/src/color/index.ts +15 -24
- package/src/color/management.ts +144 -168
- package/src/color/okhcl.ts +62 -43
- package/src/color/schema.ts +13 -0
- package/src/constraints.ts +2 -1
- package/src/copy.ts +29 -0
- package/src/corners.ts +3 -0
- package/src/css/index.ts +1 -0
- package/src/css/motion.ts +51 -0
- package/src/css/shadows.ts +7 -6
- package/src/css/values.ts +7 -3
- package/src/fields/layout.ts +9 -0
- package/src/font-style.ts +8 -3
- package/src/generated/index.ts +15 -3
- package/src/geometry.ts +13 -1
- package/src/graph.ts +72 -9
- package/src/group-bounds.ts +54 -13
- package/src/hit-test.ts +13 -8
- package/src/instances/fields.ts +2 -0
- package/src/instances/index.ts +71 -12
- package/src/instances/sync.ts +93 -11
- package/src/layout/flow.ts +34 -0
- package/src/layout/index.ts +1 -0
- package/src/layout/keywords.ts +7 -1
- package/src/layout/sizing.ts +30 -0
- package/src/layout/spacing.ts +12 -0
- package/src/mesh/geometry.ts +433 -0
- package/src/mesh/index.ts +3 -0
- package/src/mesh/model.ts +50 -0
- package/src/mesh/schema.ts +81 -0
- package/src/mutation-impact.ts +23 -7
- package/src/node-defaults.ts +22 -5
- package/src/paints/index.ts +2 -0
- package/src/paints/pattern.ts +55 -0
- package/src/paints/shows.ts +9 -0
- package/src/paints/solid.ts +10 -0
- package/src/paints/stills.ts +182 -0
- package/src/plugin-data/field.ts +3 -0
- package/src/plugin-data/fields.ts +15 -2
- package/src/resize.ts +32 -20
- package/src/scaling/index.ts +1 -1
- package/src/scaling/node.ts +43 -6
- package/src/shaders/index.ts +0 -1
- package/src/shaders/model.ts +19 -49
- package/src/shaders/schema.ts +1 -1
- package/src/shape-with-text/document.ts +175 -0
- package/src/shape-with-text/geometry.ts +99 -27
- package/src/shared-style-index.ts +106 -0
- package/src/shared-styles.ts +21 -14
- package/src/slides/drop.ts +94 -0
- package/src/slides/index.ts +125 -0
- package/src/slides/motion.ts +169 -0
- package/src/slides/playback.ts +200 -0
- package/src/slides/types.ts +94 -0
- package/src/text/direction.ts +13 -23
- package/src/text/index.ts +1 -0
- package/src/text/name.ts +39 -0
- package/src/text/references.ts +3 -3
- package/src/thumbnail.ts +52 -0
- package/src/transfer/apply.ts +16 -3
- package/src/transfer/copied.ts +7 -2
- package/src/transfer/dependencies.ts +10 -1
- package/src/transfer/history.ts +2 -0
- package/src/transfer/identity.ts +34 -2
- package/src/transfer/index.ts +6 -0
- package/src/transfer/library.ts +153 -0
- package/src/transfer/nodes.ts +20 -0
- package/src/transfer/plan.ts +96 -10
- package/src/transfer/remove.ts +6 -2
- package/src/transfer/validation.ts +15 -7
- package/src/transfer/variables.ts +8 -2
- package/src/types.ts +114 -10
- package/src/variables/bindings.ts +260 -36
- package/src/variables/easing.ts +282 -0
- package/src/variables/formula/index.ts +33 -14
- package/src/variables/formula/signatures.ts +6 -2
- package/src/variables/formula/tree.ts +3 -3
- package/src/variables/index.ts +90 -37
- package/src/variables/lookup.ts +1 -1
- package/src/variables/motion.ts +151 -0
- package/src/variables/paints.ts +29 -7
- package/src/variables/resolution.ts +11 -5
- package/src/variables/schema.ts +41 -0
- package/src/variables/style-bindings.ts +137 -0
- package/dist/shaders/still.d.ts +0 -18
- package/dist/shaders/still.d.ts.map +0 -1
- package/dist/shaders/still.js +0 -36
- package/dist/shaders/still.js.map +0 -1
- package/src/shaders/still.ts +0 -41
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Easing } from "../types.js";
|
|
2
|
+
//#region src/slides/types.d.ts
|
|
3
|
+
/** How a slide gives way to the next, by Figma's names for its slide transitions. */
|
|
4
|
+
declare const SLIDE_TRANSITION_STYLES: readonly ["NONE", "DISSOLVE", "SLIDE_FROM_LEFT", "SLIDE_FROM_RIGHT", "SLIDE_FROM_BOTTOM", "SLIDE_FROM_TOP", "PUSH_FROM_LEFT", "PUSH_FROM_RIGHT", "PUSH_FROM_BOTTOM", "PUSH_FROM_TOP", "MOVE_FROM_LEFT", "MOVE_FROM_RIGHT", "MOVE_FROM_TOP", "MOVE_FROM_BOTTOM", "SLIDE_OUT_TO_LEFT", "SLIDE_OUT_TO_RIGHT", "SLIDE_OUT_TO_TOP", "SLIDE_OUT_TO_BOTTOM", "MOVE_OUT_TO_LEFT", "MOVE_OUT_TO_RIGHT", "MOVE_OUT_TO_TOP", "MOVE_OUT_TO_BOTTOM", "SMART_ANIMATE"];
|
|
5
|
+
type SlideTransitionStyle = (typeof SLIDE_TRANSITION_STYLES)[number];
|
|
6
|
+
/** What moves the deck on from a slide: a click, or `delay` seconds passing. */
|
|
7
|
+
type SlideTransitionTiming = {
|
|
8
|
+
type: 'ON_CLICK';
|
|
9
|
+
} | {
|
|
10
|
+
type: 'AFTER_DELAY';
|
|
11
|
+
delay: number;
|
|
12
|
+
/** The TIMING variable the delay follows while it exists; `delay` is kept beside it. */
|
|
13
|
+
delayVariableId?: string;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* How a deck moves on from a slide. It names no slide: the next one is the next in the grid. The
|
|
17
|
+
* duration and easing may follow TIMING and EASING variables, keeping their values beside them
|
|
18
|
+
* for when the variables are gone, as a behaviour's transition does.
|
|
19
|
+
*/
|
|
20
|
+
interface SlideTransition {
|
|
21
|
+
style: SlideTransitionStyle;
|
|
22
|
+
/** In seconds; a spring easing settles in its own time instead. */
|
|
23
|
+
duration: number;
|
|
24
|
+
easing: Easing;
|
|
25
|
+
durationVariableId?: string;
|
|
26
|
+
easingVariableId?: string;
|
|
27
|
+
timing: SlideTransitionTiming;
|
|
28
|
+
}
|
|
29
|
+
/** How a layer comes onto or leaves its slide, by Figma's names: a slide moves from that side. */
|
|
30
|
+
declare const LAYER_ANIMATION_STYLES: readonly ["FADE", "SLIDE_FROM_LEFT", "SLIDE_FROM_RIGHT", "SLIDE_FROM_TOP", "SLIDE_FROM_BOTTOM"];
|
|
31
|
+
type LayerAnimationStyle = (typeof LAYER_ANIMATION_STYLES)[number];
|
|
32
|
+
/**
|
|
33
|
+
* A layer's animation on its slide: a step of the slide's build. Steps play in `order`; one that
|
|
34
|
+
* plays `ON_CLICK` waits for the presenter, one that plays `AFTER_PREVIOUS` follows the step before
|
|
35
|
+
* it. It lives on the layer so a copied layer or slide keeps it, and a layer has one at most, as in
|
|
36
|
+
* Figma.
|
|
37
|
+
*/
|
|
38
|
+
interface LayerAnimation {
|
|
39
|
+
style: LayerAnimationStyle;
|
|
40
|
+
/** `IN` brings the layer on, so it is hidden until its step; `OUT` takes it away. */
|
|
41
|
+
phase: 'IN' | 'OUT';
|
|
42
|
+
trigger: 'ON_CLICK' | 'AFTER_PREVIOUS';
|
|
43
|
+
/** In seconds. */
|
|
44
|
+
duration: number;
|
|
45
|
+
easing: Easing;
|
|
46
|
+
durationVariableId?: string;
|
|
47
|
+
easingVariableId?: string;
|
|
48
|
+
/** Where the step plays among the slide's; ties play in layer order. */
|
|
49
|
+
order: number;
|
|
50
|
+
}
|
|
51
|
+
/** What a slide keeps besides its layers. */
|
|
52
|
+
interface SlideSettings {
|
|
53
|
+
/** Whether presenting passes the slide by; a skipped slide has no number either. */
|
|
54
|
+
skipped: boolean;
|
|
55
|
+
/** The presenter's notes as plain text, a paragraph per line. */
|
|
56
|
+
notes: string;
|
|
57
|
+
/** How the deck moves on from the slide, or null when it was never set. */
|
|
58
|
+
transition: SlideTransition | null;
|
|
59
|
+
}
|
|
60
|
+
//#endregion
|
|
61
|
+
export { LAYER_ANIMATION_STYLES, LayerAnimation, LayerAnimationStyle, SLIDE_TRANSITION_STYLES, SlideSettings, SlideTransition, SlideTransitionStyle, SlideTransitionTiming };
|
|
62
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","names":[],"sources":["../../src/slides/types.ts"],"mappings":";;;cAGa;KAyBD,+BAA+B;;KAG/B;EACN;;EAEA;EACA;;EAEA;;;;;;;UAQW;EACf,OAAO;;EAEP;EACA,QAAQ;EACR;EACA;EACA,QAAQ;;;cAIG;KAOD,8BAA8B;;;;;;;UAQzB;EACf,OAAO;;EAEP;EACA;;EAEA;EACA,QAAQ;EACR;EACA;;EAEA;;;UAIe;;EAEf;;EAEA;;EAEA,YAAY"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
//#region src/slides/types.ts
|
|
2
|
+
/** How a slide gives way to the next, by Figma's names for its slide transitions. */
|
|
3
|
+
const SLIDE_TRANSITION_STYLES = [
|
|
4
|
+
"NONE",
|
|
5
|
+
"DISSOLVE",
|
|
6
|
+
"SLIDE_FROM_LEFT",
|
|
7
|
+
"SLIDE_FROM_RIGHT",
|
|
8
|
+
"SLIDE_FROM_BOTTOM",
|
|
9
|
+
"SLIDE_FROM_TOP",
|
|
10
|
+
"PUSH_FROM_LEFT",
|
|
11
|
+
"PUSH_FROM_RIGHT",
|
|
12
|
+
"PUSH_FROM_BOTTOM",
|
|
13
|
+
"PUSH_FROM_TOP",
|
|
14
|
+
"MOVE_FROM_LEFT",
|
|
15
|
+
"MOVE_FROM_RIGHT",
|
|
16
|
+
"MOVE_FROM_TOP",
|
|
17
|
+
"MOVE_FROM_BOTTOM",
|
|
18
|
+
"SLIDE_OUT_TO_LEFT",
|
|
19
|
+
"SLIDE_OUT_TO_RIGHT",
|
|
20
|
+
"SLIDE_OUT_TO_TOP",
|
|
21
|
+
"SLIDE_OUT_TO_BOTTOM",
|
|
22
|
+
"MOVE_OUT_TO_LEFT",
|
|
23
|
+
"MOVE_OUT_TO_RIGHT",
|
|
24
|
+
"MOVE_OUT_TO_TOP",
|
|
25
|
+
"MOVE_OUT_TO_BOTTOM",
|
|
26
|
+
"SMART_ANIMATE"
|
|
27
|
+
];
|
|
28
|
+
/** How a layer comes onto or leaves its slide, by Figma's names: a slide moves from that side. */
|
|
29
|
+
const LAYER_ANIMATION_STYLES = [
|
|
30
|
+
"FADE",
|
|
31
|
+
"SLIDE_FROM_LEFT",
|
|
32
|
+
"SLIDE_FROM_RIGHT",
|
|
33
|
+
"SLIDE_FROM_TOP",
|
|
34
|
+
"SLIDE_FROM_BOTTOM"
|
|
35
|
+
];
|
|
36
|
+
//#endregion
|
|
37
|
+
export { LAYER_ANIMATION_STYLES, SLIDE_TRANSITION_STYLES };
|
|
38
|
+
|
|
39
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../src/slides/types.ts"],"sourcesContent":["import type { Easing } from '../types'\n\n/** How a slide gives way to the next, by Figma's names for its slide transitions. */\nexport const SLIDE_TRANSITION_STYLES = [\n 'NONE',\n 'DISSOLVE',\n 'SLIDE_FROM_LEFT',\n 'SLIDE_FROM_RIGHT',\n 'SLIDE_FROM_BOTTOM',\n 'SLIDE_FROM_TOP',\n 'PUSH_FROM_LEFT',\n 'PUSH_FROM_RIGHT',\n 'PUSH_FROM_BOTTOM',\n 'PUSH_FROM_TOP',\n 'MOVE_FROM_LEFT',\n 'MOVE_FROM_RIGHT',\n 'MOVE_FROM_TOP',\n 'MOVE_FROM_BOTTOM',\n 'SLIDE_OUT_TO_LEFT',\n 'SLIDE_OUT_TO_RIGHT',\n 'SLIDE_OUT_TO_TOP',\n 'SLIDE_OUT_TO_BOTTOM',\n 'MOVE_OUT_TO_LEFT',\n 'MOVE_OUT_TO_RIGHT',\n 'MOVE_OUT_TO_TOP',\n 'MOVE_OUT_TO_BOTTOM',\n 'SMART_ANIMATE'\n] as const\nexport type SlideTransitionStyle = (typeof SLIDE_TRANSITION_STYLES)[number]\n\n/** What moves the deck on from a slide: a click, or `delay` seconds passing. */\nexport type SlideTransitionTiming =\n | { type: 'ON_CLICK' }\n | {\n type: 'AFTER_DELAY'\n delay: number\n /** The TIMING variable the delay follows while it exists; `delay` is kept beside it. */\n delayVariableId?: string\n }\n\n/**\n * How a deck moves on from a slide. It names no slide: the next one is the next in the grid. The\n * duration and easing may follow TIMING and EASING variables, keeping their values beside them\n * for when the variables are gone, as a behaviour's transition does.\n */\nexport interface SlideTransition {\n style: SlideTransitionStyle\n /** In seconds; a spring easing settles in its own time instead. */\n duration: number\n easing: Easing\n durationVariableId?: string\n easingVariableId?: string\n timing: SlideTransitionTiming\n}\n\n/** How a layer comes onto or leaves its slide, by Figma's names: a slide moves from that side. */\nexport const LAYER_ANIMATION_STYLES = [\n 'FADE',\n 'SLIDE_FROM_LEFT',\n 'SLIDE_FROM_RIGHT',\n 'SLIDE_FROM_TOP',\n 'SLIDE_FROM_BOTTOM'\n] as const\nexport type LayerAnimationStyle = (typeof LAYER_ANIMATION_STYLES)[number]\n\n/**\n * A layer's animation on its slide: a step of the slide's build. Steps play in `order`; one that\n * plays `ON_CLICK` waits for the presenter, one that plays `AFTER_PREVIOUS` follows the step before\n * it. It lives on the layer so a copied layer or slide keeps it, and a layer has one at most, as in\n * Figma.\n */\nexport interface LayerAnimation {\n style: LayerAnimationStyle\n /** `IN` brings the layer on, so it is hidden until its step; `OUT` takes it away. */\n phase: 'IN' | 'OUT'\n trigger: 'ON_CLICK' | 'AFTER_PREVIOUS'\n /** In seconds. */\n duration: number\n easing: Easing\n durationVariableId?: string\n easingVariableId?: string\n /** Where the step plays among the slide's; ties play in layer order. */\n order: number\n}\n\n/** What a slide keeps besides its layers. */\nexport interface SlideSettings {\n /** Whether presenting passes the slide by; a skipped slide has no number either. */\n skipped: boolean\n /** The presenter's notes as plain text, a paragraph per line. */\n notes: string\n /** How the deck moves on from the slide, or null when it was never set. */\n transition: SlideTransition | null\n}\n"],"mappings":";;AAGA,MAAa,0BAA0B;CACrC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;AA6BA,MAAa,yBAAyB;CACpC;CACA;CACA;CACA;CACA;AACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { parseColor } from "../color/management.js";
|
|
1
2
|
import { readPluginData, withPluginData } from "../plugin-data/field.js";
|
|
2
3
|
import { OPEN_PENCIL_PLUGIN_DATA } from "../plugin-data/fields.js";
|
|
3
|
-
import { parseColor } from "../color/index.js";
|
|
4
4
|
import { effectiveStatus } from "./node.js";
|
|
5
5
|
//#region src/statuses/workflow.ts
|
|
6
6
|
const { statuses } = OPEN_PENCIL_PLUGIN_DATA;
|
package/dist/text/direction.d.ts
CHANGED
|
@@ -2,14 +2,17 @@ import { LayoutDirection, SceneNode, TextDirection } from "../types.js";
|
|
|
2
2
|
//#region src/text/direction.d.ts
|
|
3
3
|
/** Whether the text has a letter of a right-to-left script, such as Arabic or Hebrew. */
|
|
4
4
|
declare function containsRTLText(text: string): boolean;
|
|
5
|
+
/**
|
|
6
|
+
* The direction of the text's first strongly directional character, as the Unicode bidi
|
|
7
|
+
* algorithm and Figma pick a paragraph's: digits, number signs, marks, and punctuation before
|
|
8
|
+
* it do not count.
|
|
9
|
+
*/
|
|
5
10
|
declare function detectTextDirection(text: string): Exclude<TextDirection, 'AUTO'>;
|
|
6
11
|
declare function resolveTextDirection(direction: TextDirection, text: string): Exclude<TextDirection, 'AUTO'>;
|
|
7
12
|
declare function resolveNodeTextDirection(node: Pick<SceneNode, 'textDirection' | 'text'>): 'LTR' | 'RTL';
|
|
8
13
|
declare function resolveNodeLayoutDirection(node: {
|
|
9
14
|
layoutDirection?: LayoutDirection;
|
|
10
15
|
}, inheritedDirection?: Exclude<LayoutDirection, 'AUTO'>): Exclude<LayoutDirection, 'AUTO'>;
|
|
11
|
-
declare function isLogicalTextAlignStart(node: Pick<SceneNode, 'textAlignHorizontal' | 'textDirection' | 'text'>): boolean;
|
|
12
|
-
declare function isLogicalTextAlignEnd(node: Pick<SceneNode, 'textAlignHorizontal' | 'textDirection' | 'text'>): boolean;
|
|
13
16
|
//#endregion
|
|
14
|
-
export { containsRTLText, detectTextDirection,
|
|
17
|
+
export { containsRTLText, detectTextDirection, resolveNodeLayoutDirection, resolveNodeTextDirection, resolveTextDirection };
|
|
15
18
|
//# sourceMappingURL=direction.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"direction.d.ts","names":[],"sources":["../../src/text/direction.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"direction.d.ts","names":[],"sources":["../../src/text/direction.ts"],"mappings":";;;iBAQgB,gBAAgB;;;;;;iBAWhB,oBAAoB,eAAe,QAAQ;iBAU3C,qBACd,WAAW,eACX,eACC,QAAQ;iBAIK,yBACd,MAAM,KAAK;iBAKG,2BACd;EAAQ,kBAAkB;GAC1B,qBAAoB,QAAQ,2BAC3B,QAAQ"}
|
package/dist/text/direction.js
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
|
+
import bidiFactory from "bidi-js";
|
|
1
2
|
//#region src/text/direction.ts
|
|
2
3
|
const RTL_CHAR_RE = /\p{Script=Arabic}|\p{Script=Hebrew}|\p{Script=Syriac}|\p{Script=Thaana}|\p{Script=Nko}|\p{Script=Adlam}/u;
|
|
3
|
-
const LTR_CHAR_RE = /\p{Script=Latin}|\p{Script=Cyrillic}|\p{Script=Greek}/u;
|
|
4
4
|
/** Whether the text has a letter of a right-to-left script, such as Arabic or Hebrew. */
|
|
5
5
|
function containsRTLText(text) {
|
|
6
6
|
return RTL_CHAR_RE.test(text);
|
|
7
7
|
}
|
|
8
|
+
let bidi;
|
|
9
|
+
/**
|
|
10
|
+
* The direction of the text's first strongly directional character, as the Unicode bidi
|
|
11
|
+
* algorithm and Figma pick a paragraph's: digits, number signs, marks, and punctuation before
|
|
12
|
+
* it do not count.
|
|
13
|
+
*/
|
|
8
14
|
function detectTextDirection(text) {
|
|
15
|
+
bidi ??= bidiFactory();
|
|
9
16
|
for (const char of text) {
|
|
10
|
-
|
|
11
|
-
if (
|
|
17
|
+
const type = bidi.getBidiCharTypeName(char);
|
|
18
|
+
if (type === "L") return "LTR";
|
|
19
|
+
if (type === "R" || type === "AL") return "RTL";
|
|
12
20
|
}
|
|
13
21
|
return "LTR";
|
|
14
22
|
}
|
|
@@ -21,15 +29,7 @@ function resolveNodeTextDirection(node) {
|
|
|
21
29
|
function resolveNodeLayoutDirection(node, inheritedDirection = "LTR") {
|
|
22
30
|
return !node.layoutDirection || node.layoutDirection === "AUTO" ? inheritedDirection : node.layoutDirection;
|
|
23
31
|
}
|
|
24
|
-
function isLogicalTextAlignStart(node) {
|
|
25
|
-
const direction = resolveNodeTextDirection(node);
|
|
26
|
-
return direction === "LTR" && node.textAlignHorizontal === "LEFT" || direction === "RTL" && node.textAlignHorizontal === "RIGHT";
|
|
27
|
-
}
|
|
28
|
-
function isLogicalTextAlignEnd(node) {
|
|
29
|
-
const direction = resolveNodeTextDirection(node);
|
|
30
|
-
return direction === "LTR" && node.textAlignHorizontal === "RIGHT" || direction === "RTL" && node.textAlignHorizontal === "LEFT";
|
|
31
|
-
}
|
|
32
32
|
//#endregion
|
|
33
|
-
export { containsRTLText, detectTextDirection,
|
|
33
|
+
export { containsRTLText, detectTextDirection, resolveNodeLayoutDirection, resolveNodeTextDirection, resolveTextDirection };
|
|
34
34
|
|
|
35
35
|
//# sourceMappingURL=direction.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"direction.js","names":[],"sources":["../../src/text/direction.ts"],"sourcesContent":["import type { LayoutDirection, SceneNode, TextDirection } from '../types'\n\nconst RTL_CHAR_RE =\n /\\p{Script=Arabic}|\\p{Script=Hebrew}|\\p{Script=Syriac}|\\p{Script=Thaana}|\\p{Script=Nko}|\\p{Script=Adlam}/u\
|
|
1
|
+
{"version":3,"file":"direction.js","names":[],"sources":["../../src/text/direction.ts"],"sourcesContent":["import bidiFactory from 'bidi-js'\n\nimport type { LayoutDirection, SceneNode, TextDirection } from '../types'\n\nconst RTL_CHAR_RE =\n /\\p{Script=Arabic}|\\p{Script=Hebrew}|\\p{Script=Syriac}|\\p{Script=Thaana}|\\p{Script=Nko}|\\p{Script=Adlam}/u\n\n/** Whether the text has a letter of a right-to-left script, such as Arabic or Hebrew. */\nexport function containsRTLText(text: string): boolean {\n return RTL_CHAR_RE.test(text)\n}\n\nlet bidi: ReturnType<typeof bidiFactory> | undefined\n\n/**\n * The direction of the text's first strongly directional character, as the Unicode bidi\n * algorithm and Figma pick a paragraph's: digits, number signs, marks, and punctuation before\n * it do not count.\n */\nexport function detectTextDirection(text: string): Exclude<TextDirection, 'AUTO'> {\n bidi ??= bidiFactory()\n for (const char of text) {\n const type = bidi.getBidiCharTypeName(char)\n if (type === 'L') return 'LTR'\n if (type === 'R' || type === 'AL') return 'RTL'\n }\n return 'LTR'\n}\n\nexport function resolveTextDirection(\n direction: TextDirection,\n text: string\n): Exclude<TextDirection, 'AUTO'> {\n return direction === 'AUTO' ? detectTextDirection(text) : direction\n}\n\nexport function resolveNodeTextDirection(\n node: Pick<SceneNode, 'textDirection' | 'text'>\n): 'LTR' | 'RTL' {\n return resolveTextDirection(node.textDirection, node.text)\n}\n\nexport function resolveNodeLayoutDirection(\n node: { layoutDirection?: LayoutDirection },\n inheritedDirection: Exclude<LayoutDirection, 'AUTO'> = 'LTR'\n): Exclude<LayoutDirection, 'AUTO'> {\n return !node.layoutDirection || node.layoutDirection === 'AUTO'\n ? inheritedDirection\n : node.layoutDirection\n}\n"],"mappings":";;AAIA,MAAM,cACJ;;AAGF,SAAgB,gBAAgB,MAAuB;CACrD,OAAO,YAAY,KAAK,IAAI;AAC9B;AAEA,IAAI;;;;;;AAOJ,SAAgB,oBAAoB,MAA8C;CAChF,SAAS,YAAY;CACrB,KAAK,MAAM,QAAQ,MAAM;EACvB,MAAM,OAAO,KAAK,oBAAoB,IAAI;EAC1C,IAAI,SAAS,KAAK,OAAO;EACzB,IAAI,SAAS,OAAO,SAAS,MAAM,OAAO;CAC5C;CACA,OAAO;AACT;AAEA,SAAgB,qBACd,WACA,MACgC;CAChC,OAAO,cAAc,SAAS,oBAAoB,IAAI,IAAI;AAC5D;AAEA,SAAgB,yBACd,MACe;CACf,OAAO,qBAAqB,KAAK,eAAe,KAAK,IAAI;AAC3D;AAEA,SAAgB,2BACd,MACA,qBAAuD,OACrB;CAClC,OAAO,CAAC,KAAK,mBAAmB,KAAK,oBAAoB,SACrD,qBACA,KAAK;AACX"}
|
package/dist/text/index.d.ts
CHANGED
|
@@ -6,4 +6,5 @@ import { NO_LETTER_SPACING, estimatedLineStep, formatTextLength, lineHeightPixel
|
|
|
6
6
|
import { TextLinesReach, textLinesReach, textVerticalOffset } from "./overflow.js";
|
|
7
7
|
import { textLengthSchema } from "./schema.js";
|
|
8
8
|
import { StyleRunPiece, appendStyleRun, characterOverrides, styleRunAt, styleRunPieces, textLanguageAt } from "./runs.js";
|
|
9
|
-
|
|
9
|
+
import { newTextNameChanges, renameChanges, textLayerName, textNameChanges } from "./name.js";
|
|
10
|
+
export { FigmaTextAutoResize, LIST_BULLET, ListNumberFormat, MAX_LIST_INDENTATION, NO_LETTER_SPACING, PLAIN_PARAGRAPH, StyleRunPiece, StyleRunReferences, TEXT_PARAGRAPH_SPACING_FIELDS, TextLinesReach, TextListItem, TextParagraphRange, appendStyleRun, characterOverrides, estimatedLineStep, figmaTextAutoResize, formatListNumber, formatTextLength, hasParagraphSpacing, hasTextList, lineHeightPixels, lineStepPixels, listNumberFormat, newTextNameChanges, paragraphCount, paragraphIndexAt, paragraphSpacingAt, paragraphStyleAt, paragraphStylesAfterEdit, paragraphStylesAfterTextChange, paragraphStylesInRange, paragraphStylesWithoutSpacing, percentLength, pixelLength, remapStyleRunReferences, renameChanges, scaledTextLength, sharedParagraphSpacing, styleRunAt, styleRunPieces, styleRunReferences, textAutoResizeFields, textLanguageAt, textLayerName, textLengthPixels, textLengthSchema, textLinesReach, textListItems, textNameChanges, textParagraphRanges, textVerticalOffset, topLevelNumberDigits, trimParagraphStyles, withIndentation, withListType, withParagraphSpacing };
|
package/dist/text/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { NO_LETTER_SPACING, estimatedLineStep, formatTextLength, lineHeightPixels, lineStepPixels, percentLength, pixelLength, scaledTextLength, textLengthPixels } from "./lengths.js";
|
|
2
|
-
import { remapStyleRunReferences, styleRunReferences } from "./references.js";
|
|
3
2
|
import { MAX_LIST_INDENTATION, PLAIN_PARAGRAPH, TEXT_PARAGRAPH_SPACING_FIELDS, hasParagraphSpacing, hasTextList, paragraphCount, paragraphIndexAt, paragraphSpacingAt, paragraphStyleAt, paragraphStylesAfterEdit, paragraphStylesAfterTextChange, paragraphStylesInRange, paragraphStylesWithoutSpacing, sharedParagraphSpacing, textParagraphRanges, trimParagraphStyles, withIndentation, withListType, withParagraphSpacing } from "./paragraphs.js";
|
|
3
|
+
import { remapStyleRunReferences, styleRunReferences } from "./references.js";
|
|
4
|
+
import { newTextNameChanges, renameChanges, textLayerName, textNameChanges } from "./name.js";
|
|
4
5
|
import { figmaTextAutoResize, textAutoResizeFields } from "./auto-resize.js";
|
|
5
6
|
import { LIST_BULLET, formatListNumber, listNumberFormat, textListItems, topLevelNumberDigits } from "./lists.js";
|
|
6
7
|
import { textLinesReach, textVerticalOffset } from "./overflow.js";
|
|
7
8
|
import { textLengthSchema } from "./schema.js";
|
|
8
9
|
import { appendStyleRun, characterOverrides, styleRunAt, styleRunPieces, textLanguageAt } from "./runs.js";
|
|
9
|
-
export { LIST_BULLET, MAX_LIST_INDENTATION, NO_LETTER_SPACING, PLAIN_PARAGRAPH, TEXT_PARAGRAPH_SPACING_FIELDS, appendStyleRun, characterOverrides, estimatedLineStep, figmaTextAutoResize, formatListNumber, formatTextLength, hasParagraphSpacing, hasTextList, lineHeightPixels, lineStepPixels, listNumberFormat, paragraphCount, paragraphIndexAt, paragraphSpacingAt, paragraphStyleAt, paragraphStylesAfterEdit, paragraphStylesAfterTextChange, paragraphStylesInRange, paragraphStylesWithoutSpacing, percentLength, pixelLength, remapStyleRunReferences, scaledTextLength, sharedParagraphSpacing, styleRunAt, styleRunPieces, styleRunReferences, textAutoResizeFields, textLanguageAt, textLengthPixels, textLengthSchema, textLinesReach, textListItems, textParagraphRanges, textVerticalOffset, topLevelNumberDigits, trimParagraphStyles, withIndentation, withListType, withParagraphSpacing };
|
|
10
|
+
export { LIST_BULLET, MAX_LIST_INDENTATION, NO_LETTER_SPACING, PLAIN_PARAGRAPH, TEXT_PARAGRAPH_SPACING_FIELDS, appendStyleRun, characterOverrides, estimatedLineStep, figmaTextAutoResize, formatListNumber, formatTextLength, hasParagraphSpacing, hasTextList, lineHeightPixels, lineStepPixels, listNumberFormat, newTextNameChanges, paragraphCount, paragraphIndexAt, paragraphSpacingAt, paragraphStyleAt, paragraphStylesAfterEdit, paragraphStylesAfterTextChange, paragraphStylesInRange, paragraphStylesWithoutSpacing, percentLength, pixelLength, remapStyleRunReferences, renameChanges, scaledTextLength, sharedParagraphSpacing, styleRunAt, styleRunPieces, styleRunReferences, textAutoResizeFields, textLanguageAt, textLayerName, textLengthPixels, textLengthSchema, textLinesReach, textListItems, textNameChanges, textParagraphRanges, textVerticalOffset, topLevelNumberDigits, trimParagraphStyles, withIndentation, withListType, withParagraphSpacing };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { SceneNode } from "../types.js";
|
|
2
|
+
//#region src/text/name.d.ts
|
|
3
|
+
/** The name a text layer that follows its text takes: its characters on one line, as Figma names it. */
|
|
4
|
+
declare function textLayerName(text: string): string;
|
|
5
|
+
/**
|
|
6
|
+
* The name `changes` also sets on a text layer that follows its text (`autoRename`): its new text
|
|
7
|
+
* written, or following turned back on. A name the write gives itself wins, so a rename, or undo
|
|
8
|
+
* putting one back, is kept; setting the name alone does not stop the layer following its text,
|
|
9
|
+
* which a rename does by setting `autoRename` to false with it.
|
|
10
|
+
*/
|
|
11
|
+
declare function textNameChanges(node: SceneNode, changes: Partial<SceneNode>): Partial<SceneNode>;
|
|
12
|
+
/** What renaming a layer writes: the name, and on a text layer an end to following its text. */
|
|
13
|
+
declare function renameChanges(node: SceneNode, name: string): Partial<SceneNode>;
|
|
14
|
+
/**
|
|
15
|
+
* What making a text layer from `overrides` also sets: the name of its text, as an edit sets it,
|
|
16
|
+
* or, given a name other than its text's, an end to following it, as a rename makes. A follow
|
|
17
|
+
* flag the overrides give, as a file or a copy gives, is kept.
|
|
18
|
+
*/
|
|
19
|
+
declare function newTextNameChanges(node: SceneNode, overrides: Partial<SceneNode>): Partial<SceneNode>;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { newTextNameChanges, renameChanges, textLayerName, textNameChanges };
|
|
22
|
+
//# sourceMappingURL=name.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"name.d.ts","names":[],"sources":["../../src/text/name.ts"],"mappings":";;;iBAGgB,cAAc;;;;;;;iBAUd,gBAAgB,MAAM,WAAW,SAAS,QAAQ,aAAa,QAAQ;;iBASvE,cAAc,MAAM,WAAW,eAAe,QAAQ;;;;;;iBAStD,mBACd,MAAM,WACN,WAAW,QAAQ,aAClB,QAAQ"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
//#region src/text/name.ts
|
|
2
|
+
/** The name a text layer that follows its text takes: its characters on one line, as Figma names it. */
|
|
3
|
+
function textLayerName(text) {
|
|
4
|
+
return text.replace(/\s+/g, " ").trim() || "Text";
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* The name `changes` also sets on a text layer that follows its text (`autoRename`): its new text
|
|
8
|
+
* written, or following turned back on. A name the write gives itself wins, so a rename, or undo
|
|
9
|
+
* putting one back, is kept; setting the name alone does not stop the layer following its text,
|
|
10
|
+
* which a rename does by setting `autoRename` to false with it.
|
|
11
|
+
*/
|
|
12
|
+
function textNameChanges(node, changes) {
|
|
13
|
+
if (node.type !== "TEXT" || "name" in changes) return {};
|
|
14
|
+
if (!("text" in changes) && changes.autoRename !== true) return {};
|
|
15
|
+
if (!(changes.autoRename ?? node.autoRename)) return {};
|
|
16
|
+
const name = textLayerName(changes.text ?? node.text);
|
|
17
|
+
return name === node.name ? {} : { name };
|
|
18
|
+
}
|
|
19
|
+
/** What renaming a layer writes: the name, and on a text layer an end to following its text. */
|
|
20
|
+
function renameChanges(node, name) {
|
|
21
|
+
return node.type === "TEXT" ? {
|
|
22
|
+
name,
|
|
23
|
+
autoRename: false
|
|
24
|
+
} : { name };
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* What making a text layer from `overrides` also sets: the name of its text, as an edit sets it,
|
|
28
|
+
* or, given a name other than its text's, an end to following it, as a rename makes. A follow
|
|
29
|
+
* flag the overrides give, as a file or a copy gives, is kept.
|
|
30
|
+
*/
|
|
31
|
+
function newTextNameChanges(node, overrides) {
|
|
32
|
+
if (node.type !== "TEXT" || !("name" in overrides) || "autoRename" in overrides) return textNameChanges(node, overrides);
|
|
33
|
+
return node.name === textLayerName(node.text) ? {} : { autoRename: false };
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
export { newTextNameChanges, renameChanges, textLayerName, textNameChanges };
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=name.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"name.js","names":[],"sources":["../../src/text/name.ts"],"sourcesContent":["import type { SceneNode } from '../types'\n\n/** The name a text layer that follows its text takes: its characters on one line, as Figma names it. */\nexport function textLayerName(text: string): string {\n return text.replace(/\\s+/g, ' ').trim() || 'Text'\n}\n\n/**\n * The name `changes` also sets on a text layer that follows its text (`autoRename`): its new text\n * written, or following turned back on. A name the write gives itself wins, so a rename, or undo\n * putting one back, is kept; setting the name alone does not stop the layer following its text,\n * which a rename does by setting `autoRename` to false with it.\n */\nexport function textNameChanges(node: SceneNode, changes: Partial<SceneNode>): Partial<SceneNode> {\n if (node.type !== 'TEXT' || 'name' in changes) return {}\n if (!('text' in changes) && changes.autoRename !== true) return {}\n if (!(changes.autoRename ?? node.autoRename)) return {}\n const name = textLayerName(changes.text ?? node.text)\n return name === node.name ? {} : { name }\n}\n\n/** What renaming a layer writes: the name, and on a text layer an end to following its text. */\nexport function renameChanges(node: SceneNode, name: string): Partial<SceneNode> {\n return node.type === 'TEXT' ? { name, autoRename: false } : { name }\n}\n\n/**\n * What making a text layer from `overrides` also sets: the name of its text, as an edit sets it,\n * or, given a name other than its text's, an end to following it, as a rename makes. A follow\n * flag the overrides give, as a file or a copy gives, is kept.\n */\nexport function newTextNameChanges(\n node: SceneNode,\n overrides: Partial<SceneNode>\n): Partial<SceneNode> {\n if (node.type !== 'TEXT' || !('name' in overrides) || 'autoRename' in overrides)\n return textNameChanges(node, overrides)\n return node.name === textLayerName(node.text) ? {} : { autoRename: false }\n}\n"],"mappings":";;AAGA,SAAgB,cAAc,MAAsB;CAClD,OAAO,KAAK,QAAQ,QAAQ,GAAG,CAAC,CAAC,KAAK,KAAK;AAC7C;;;;;;;AAQA,SAAgB,gBAAgB,MAAiB,SAAiD;CAChG,IAAI,KAAK,SAAS,UAAU,UAAU,SAAS,OAAO,CAAC;CACvD,IAAI,EAAE,UAAU,YAAY,QAAQ,eAAe,MAAM,OAAO,CAAC;CACjE,IAAI,EAAE,QAAQ,cAAc,KAAK,aAAa,OAAO,CAAC;CACtD,MAAM,OAAO,cAAc,QAAQ,QAAQ,KAAK,IAAI;CACpD,OAAO,SAAS,KAAK,OAAO,CAAC,IAAI,EAAE,KAAK;AAC1C;;AAGA,SAAgB,cAAc,MAAiB,MAAkC;CAC/E,OAAO,KAAK,SAAS,SAAS;EAAE;EAAM,YAAY;CAAM,IAAI,EAAE,KAAK;AACrE;;;;;;AAOA,SAAgB,mBACd,MACA,WACoB;CACpB,IAAI,KAAK,SAAS,UAAU,EAAE,UAAU,cAAc,gBAAgB,WACpE,OAAO,gBAAgB,MAAM,SAAS;CACxC,OAAO,KAAK,SAAS,cAAc,KAAK,IAAI,IAAI,CAAC,IAAI,EAAE,YAAY,MAAM;AAC3E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"references.d.ts","names":[],"sources":["../../src/text/references.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"references.d.ts","names":[],"sources":["../../src/text/references.ts"],"mappings":";;;UAGiB;EACf;EACA;;;iBAIc,mBAAmB,eAAe,aAAa;;;;;iBAe/C,wBACd,eAAe,YACf;EACE,WAAW;EACX,QAAQ;EACR,QAAQ;IAET"}
|
package/dist/text/references.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { mapValues } from "es-toolkit/object";
|
|
2
1
|
//#region src/text/references.ts
|
|
3
2
|
/** The variables and styles a text's runs refer to, which copies and transfers carry with it. */
|
|
4
3
|
function styleRunReferences(runs) {
|
|
@@ -28,7 +27,7 @@ function remapStyleRunReferences(runs, rename) {
|
|
|
28
27
|
type: "NODE",
|
|
29
28
|
value: rename.node(hyperlink.value)
|
|
30
29
|
};
|
|
31
|
-
if (boundVariables) style.boundVariables =
|
|
30
|
+
if (boundVariables) style.boundVariables = Object.fromEntries(Object.entries(boundVariables).map(([field, id]) => [field, rename.variable(id)]));
|
|
32
31
|
if (textStyleId) style.textStyleId = rename.style(textStyleId);
|
|
33
32
|
if (fillStyleId) style.fillStyleId = rename.style(fillStyleId);
|
|
34
33
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"references.js","names":[],"sources":["../../src/text/references.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"references.js","names":[],"sources":["../../src/text/references.ts"],"sourcesContent":["import type { StyleRun } from '../types'\n\n/** What a text's runs refer to outside the text: the variables they bind and the styles they use. */\nexport interface StyleRunReferences {\n variables: string[]\n styles: string[]\n}\n\n/** The variables and styles a text's runs refer to, which copies and transfers carry with it. */\nexport function styleRunReferences(runs: readonly StyleRun[]): StyleRunReferences {\n const variables = new Set<string>()\n const styles = new Set<string>()\n for (const { style } of runs) {\n for (const id of Object.values(style.boundVariables ?? {})) if (id) variables.add(id)\n if (style.textStyleId) styles.add(style.textStyleId)\n if (style.fillStyleId) styles.add(style.fillStyleId)\n }\n return { variables: [...variables], styles: [...styles] }\n}\n\n/**\n * Runs whose variables, styles, and linked layers are renamed, as a copy into another document\n * renames them. Layers are renamed only when given, since a link may name a layer left behind.\n */\nexport function remapStyleRunReferences(\n runs: readonly StyleRun[],\n rename: {\n variable: (id: string) => string\n style: (id: string) => string\n node?: (id: string) => string\n }\n): StyleRun[] {\n return runs.map((run) => {\n const { boundVariables, textStyleId, fillStyleId, hyperlink } = run.style\n const linksLayer = hyperlink?.type === 'NODE' && rename.node !== undefined\n if (!boundVariables && !textStyleId && !fillStyleId && !linksLayer) return run\n const style = { ...run.style }\n if (hyperlink?.type === 'NODE' && rename.node) {\n style.hyperlink = { type: 'NODE', value: rename.node(hyperlink.value) }\n }\n if (boundVariables) {\n style.boundVariables = Object.fromEntries(\n Object.entries(boundVariables).map(([field, id]) => [field, rename.variable(id)])\n )\n }\n if (textStyleId) style.textStyleId = rename.style(textStyleId)\n if (fillStyleId) style.fillStyleId = rename.style(fillStyleId)\n return { ...run, style }\n })\n}\n"],"mappings":";;AASA,SAAgB,mBAAmB,MAA+C;CAChF,MAAM,4BAAY,IAAI,IAAY;CAClC,MAAM,yBAAS,IAAI,IAAY;CAC/B,KAAK,MAAM,EAAE,WAAW,MAAM;EAC5B,KAAK,MAAM,MAAM,OAAO,OAAO,MAAM,kBAAkB,CAAC,CAAC,GAAG,IAAI,IAAI,UAAU,IAAI,EAAE;EACpF,IAAI,MAAM,aAAa,OAAO,IAAI,MAAM,WAAW;EACnD,IAAI,MAAM,aAAa,OAAO,IAAI,MAAM,WAAW;CACrD;CACA,OAAO;EAAE,WAAW,CAAC,GAAG,SAAS;EAAG,QAAQ,CAAC,GAAG,MAAM;CAAE;AAC1D;;;;;AAMA,SAAgB,wBACd,MACA,QAKY;CACZ,OAAO,KAAK,KAAK,QAAQ;EACvB,MAAM,EAAE,gBAAgB,aAAa,aAAa,cAAc,IAAI;EACpE,MAAM,aAAa,WAAW,SAAS,UAAU,OAAO,SAAS,KAAA;EACjE,IAAI,CAAC,kBAAkB,CAAC,eAAe,CAAC,eAAe,CAAC,YAAY,OAAO;EAC3E,MAAM,QAAQ,EAAE,GAAG,IAAI,MAAM;EAC7B,IAAI,WAAW,SAAS,UAAU,OAAO,MACvC,MAAM,YAAY;GAAE,MAAM;GAAQ,OAAO,OAAO,KAAK,UAAU,KAAK;EAAE;EAExE,IAAI,gBACF,MAAM,iBAAiB,OAAO,YAC5B,OAAO,QAAQ,cAAc,CAAC,CAAC,KAAK,CAAC,OAAO,QAAQ,CAAC,OAAO,OAAO,SAAS,EAAE,CAAC,CAAC,CAClF;EAEF,IAAI,aAAa,MAAM,cAAc,OAAO,MAAM,WAAW;EAC7D,IAAI,aAAa,MAAM,cAAc,OAAO,MAAM,WAAW;EAC7D,OAAO;GAAE,GAAG;GAAK;EAAM;CACzB,CAAC;AACH"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { SceneGraph } from "./graph.js";
|
|
2
|
+
import { SceneNode } from "./types.js";
|
|
3
|
+
//#region src/thumbnail.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Whether `node` can be the document's thumbnail: a frame, section, or component placed straight
|
|
6
|
+
* on a page people see, or a slide.
|
|
7
|
+
*/
|
|
8
|
+
declare function canBeDocumentThumbnail(graph: SceneGraph, node: SceneNode): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* The id stored as the document's thumbnail, whether or not that layer is loaded or can still be
|
|
11
|
+
* one: what undo restores.
|
|
12
|
+
*/
|
|
13
|
+
declare function documentThumbnailId(graph: SceneGraph): string | null;
|
|
14
|
+
/**
|
|
15
|
+
* The layer chosen as the document's thumbnail, or null when there is none or it can no longer
|
|
16
|
+
* be one, such as after it was deleted or moved into another frame.
|
|
17
|
+
*/
|
|
18
|
+
declare function documentThumbnail(graph: SceneGraph): SceneNode | null;
|
|
19
|
+
/** Chooses `nodeId` as the document's thumbnail, or goes back to the default with null. */
|
|
20
|
+
declare function setDocumentThumbnail(graph: SceneGraph, nodeId: string | null): void;
|
|
21
|
+
//#endregion
|
|
22
|
+
export { canBeDocumentThumbnail, documentThumbnail, documentThumbnailId, setDocumentThumbnail };
|
|
23
|
+
//# sourceMappingURL=thumbnail.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"thumbnail.d.ts","names":[],"sources":["../src/thumbnail.ts"],"mappings":";;;;;;;iBAmBgB,uBAAuB,OAAO,YAAY,MAAM;;;;;iBAWhD,oBAAoB,OAAO;;;;;iBAQ3B,kBAAkB,OAAO,aAAa;;iBAOtC,qBAAqB,OAAO,YAAY"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { readPluginData, withPluginData } from "./plugin-data/field.js";
|
|
2
|
+
import { OPEN_PENCIL_PLUGIN_DATA } from "./plugin-data/fields.js";
|
|
3
|
+
//#region src/thumbnail.ts
|
|
4
|
+
const { thumbnail } = OPEN_PENCIL_PLUGIN_DATA;
|
|
5
|
+
/** Layers that frame a picture of their own, as Figma lets frames and sections be thumbnails. */
|
|
6
|
+
const THUMBNAIL_TYPES = /* @__PURE__ */ new Set([
|
|
7
|
+
"FRAME",
|
|
8
|
+
"SECTION",
|
|
9
|
+
"COMPONENT",
|
|
10
|
+
"SLIDE"
|
|
11
|
+
]);
|
|
12
|
+
/**
|
|
13
|
+
* Whether `node` can be the document's thumbnail: a frame, section, or component placed straight
|
|
14
|
+
* on a page people see, or a slide.
|
|
15
|
+
*/
|
|
16
|
+
function canBeDocumentThumbnail(graph, node) {
|
|
17
|
+
if (!THUMBNAIL_TYPES.has(node.type)) return false;
|
|
18
|
+
if (node.type === "SLIDE") return true;
|
|
19
|
+
const parent = node.parentId ? graph.getNode(node.parentId) : void 0;
|
|
20
|
+
return parent?.type === "CANVAS" && !parent.internalOnly;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The id stored as the document's thumbnail, whether or not that layer is loaded or can still be
|
|
24
|
+
* one: what undo restores.
|
|
25
|
+
*/
|
|
26
|
+
function documentThumbnailId(graph) {
|
|
27
|
+
return readPluginData(graph.getNode(graph.rootId)?.pluginData, thumbnail) ?? null;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The layer chosen as the document's thumbnail, or null when there is none or it can no longer
|
|
31
|
+
* be one, such as after it was deleted or moved into another frame.
|
|
32
|
+
*/
|
|
33
|
+
function documentThumbnail(graph) {
|
|
34
|
+
const id = documentThumbnailId(graph);
|
|
35
|
+
const node = id ? graph.getNode(id) : void 0;
|
|
36
|
+
return node && canBeDocumentThumbnail(graph, node) ? node : null;
|
|
37
|
+
}
|
|
38
|
+
/** Chooses `nodeId` as the document's thumbnail, or goes back to the default with null. */
|
|
39
|
+
function setDocumentThumbnail(graph, nodeId) {
|
|
40
|
+
const root = graph.getNode(graph.rootId);
|
|
41
|
+
if (!root) return;
|
|
42
|
+
graph.updateNode(root.id, { pluginData: withPluginData(root.pluginData, thumbnail, nodeId ?? void 0) });
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
export { canBeDocumentThumbnail, documentThumbnail, documentThumbnailId, setDocumentThumbnail };
|
|
46
|
+
|
|
47
|
+
//# sourceMappingURL=thumbnail.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"thumbnail.js","names":[],"sources":["../src/thumbnail.ts"],"sourcesContent":["import type { SceneGraph } from './graph'\nimport { readPluginData, withPluginData } from './plugin-data/field'\nimport { OPEN_PENCIL_PLUGIN_DATA } from './plugin-data/fields'\nimport type { SceneNode } from './types'\n\nconst { thumbnail } = OPEN_PENCIL_PLUGIN_DATA\n\n/** Layers that frame a picture of their own, as Figma lets frames and sections be thumbnails. */\nconst THUMBNAIL_TYPES: ReadonlySet<SceneNode['type']> = new Set([\n 'FRAME',\n 'SECTION',\n 'COMPONENT',\n 'SLIDE'\n])\n\n/**\n * Whether `node` can be the document's thumbnail: a frame, section, or component placed straight\n * on a page people see, or a slide.\n */\nexport function canBeDocumentThumbnail(graph: SceneGraph, node: SceneNode): boolean {\n if (!THUMBNAIL_TYPES.has(node.type)) return false\n if (node.type === 'SLIDE') return true\n const parent = node.parentId ? graph.getNode(node.parentId) : undefined\n return parent?.type === 'CANVAS' && !parent.internalOnly\n}\n\n/**\n * The id stored as the document's thumbnail, whether or not that layer is loaded or can still be\n * one: what undo restores.\n */\nexport function documentThumbnailId(graph: SceneGraph): string | null {\n return readPluginData(graph.getNode(graph.rootId)?.pluginData, thumbnail) ?? null\n}\n\n/**\n * The layer chosen as the document's thumbnail, or null when there is none or it can no longer\n * be one, such as after it was deleted or moved into another frame.\n */\nexport function documentThumbnail(graph: SceneGraph): SceneNode | null {\n const id = documentThumbnailId(graph)\n const node = id ? graph.getNode(id) : undefined\n return node && canBeDocumentThumbnail(graph, node) ? node : null\n}\n\n/** Chooses `nodeId` as the document's thumbnail, or goes back to the default with null. */\nexport function setDocumentThumbnail(graph: SceneGraph, nodeId: string | null): void {\n const root = graph.getNode(graph.rootId)\n if (!root) return\n graph.updateNode(root.id, {\n pluginData: withPluginData(root.pluginData, thumbnail, nodeId ?? undefined)\n })\n}\n"],"mappings":";;;AAKA,MAAM,EAAE,cAAc;;AAGtB,MAAM,kCAAkD,IAAI,IAAI;CAC9D;CACA;CACA;CACA;AACF,CAAC;;;;;AAMD,SAAgB,uBAAuB,OAAmB,MAA0B;CAClF,IAAI,CAAC,gBAAgB,IAAI,KAAK,IAAI,GAAG,OAAO;CAC5C,IAAI,KAAK,SAAS,SAAS,OAAO;CAClC,MAAM,SAAS,KAAK,WAAW,MAAM,QAAQ,KAAK,QAAQ,IAAI,KAAA;CAC9D,OAAO,QAAQ,SAAS,YAAY,CAAC,OAAO;AAC9C;;;;;AAMA,SAAgB,oBAAoB,OAAkC;CACpE,OAAO,eAAe,MAAM,QAAQ,MAAM,MAAM,CAAC,EAAE,YAAY,SAAS,KAAK;AAC/E;;;;;AAMA,SAAgB,kBAAkB,OAAqC;CACrE,MAAM,KAAK,oBAAoB,KAAK;CACpC,MAAM,OAAO,KAAK,MAAM,QAAQ,EAAE,IAAI,KAAA;CACtC,OAAO,QAAQ,uBAAuB,OAAO,IAAI,IAAI,OAAO;AAC9D;;AAGA,SAAgB,qBAAqB,OAAmB,QAA6B;CACnF,MAAM,OAAO,MAAM,QAAQ,MAAM,MAAM;CACvC,IAAI,CAAC,MAAM;CACX,MAAM,WAAW,KAAK,IAAI,EACxB,YAAY,eAAe,KAAK,YAAY,WAAW,UAAU,KAAA,CAAS,EAC5E,CAAC;AACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apply.d.ts","names":[],"sources":["../../src/transfer/apply.ts"],"mappings":";;;KAQY,oBAAoB,kBAAkB;;
|
|
1
|
+
{"version":3,"file":"apply.d.ts","names":[],"sources":["../../src/transfer/apply.ts"],"mappings":";;;KAQY,oBAAoB,kBAAkB;;iBAqDlC,mBAAmB,QAAQ,YAAY,OAAO"}
|
package/dist/transfer/apply.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { variableIdentityReferences } from "./identity.js";
|
|
1
|
+
import { heldTransferCollections, variableIdentityReferences } from "./identity.js";
|
|
2
2
|
import { validateTransferReferences } from "./validation.js";
|
|
3
3
|
import { prepareVariableTransfer } from "./variables.js";
|
|
4
4
|
import { isEqual } from "es-toolkit/predicate";
|
|
@@ -14,7 +14,8 @@ function validate(target, plan) {
|
|
|
14
14
|
if (reserved.has(id)) throw new Error(`Transfer identity collision ${id}`);
|
|
15
15
|
reserved.add(id);
|
|
16
16
|
};
|
|
17
|
-
|
|
17
|
+
const collections = [...plan.collections, ...heldTransferCollections(target, plan)];
|
|
18
|
+
prepareVariableTransfer(plan.variables, collections, variableIdentityReferences(plan.variables, collections, plan.reused.variables));
|
|
18
19
|
for (const collection of plan.collections) claim(collection.id);
|
|
19
20
|
for (const variable of plan.variables) claim(variable.id);
|
|
20
21
|
const parents = new Set(target.nodes.keys());
|
|
@@ -31,6 +32,15 @@ function validate(target, plan) {
|
|
|
31
32
|
if (existing && !isEqual(existing, bytes)) throw new Error(`Transfer image collision ${hash}`);
|
|
32
33
|
}
|
|
33
34
|
}
|
|
35
|
+
/** Takes the variables a plan added out of the target's library collections again. */
|
|
36
|
+
function leaveHeldCollections(target, plan) {
|
|
37
|
+
for (const { collectionId, variableId } of plan.joined) {
|
|
38
|
+
const collection = target.variableCollections.get(collectionId);
|
|
39
|
+
if (!collection?.variableIds.includes(variableId)) continue;
|
|
40
|
+
target.willChangeCollection(collectionId);
|
|
41
|
+
collection.variableIds = collection.variableIds.filter((id) => id !== variableId);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
34
44
|
/** Revalidate at insertion time. Event-delivery failures after commit are not rollback failures. */
|
|
35
45
|
function applyGraphTransfer(target, input) {
|
|
36
46
|
const plan = structuredClone(input);
|
|
@@ -47,6 +57,7 @@ function applyGraphTransfer(target, input) {
|
|
|
47
57
|
});
|
|
48
58
|
} catch (error) {
|
|
49
59
|
for (const node of plan.nodes.toReversed()) if (target.getNode(node.id)) target.deleteNode(node.id);
|
|
60
|
+
leaveHeldCollections(target, plan);
|
|
50
61
|
for (const variable of plan.variables) target.variables.delete(variable.id);
|
|
51
62
|
for (const collection of plan.collections) target.variableCollections.delete(collection.id);
|
|
52
63
|
for (const hash of imageIds) target.images.delete(hash);
|
|
@@ -55,6 +66,6 @@ function applyGraphTransfer(target, input) {
|
|
|
55
66
|
});
|
|
56
67
|
}
|
|
57
68
|
//#endregion
|
|
58
|
-
export { applyGraphTransfer };
|
|
69
|
+
export { applyGraphTransfer, leaveHeldCollections };
|
|
59
70
|
|
|
60
71
|
//# sourceMappingURL=apply.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apply.js","names":[],"sources":["../../src/transfer/apply.ts"],"sourcesContent":["import { isEqual } from 'es-toolkit/predicate'\n\nimport type { SceneGraph } from '../graph'\nimport { variableIdentityReferences } from './identity'\nimport type { prepareGraphTransfer } from './plan'\nimport { validateTransferReferences } from './validation'\nimport { prepareVariableTransfer } from './variables'\n\nexport type GraphTransferPlan = ReturnType<typeof prepareGraphTransfer>\n\nfunction validate(target: SceneGraph, plan: GraphTransferPlan): void {\n validateTransferReferences(target, plan)\n const reserved = new Set([\n ...target.nodes.keys(),\n ...target.variables.keys(),\n ...target.variableCollections.keys()\n ])\n const claim = (id: string): void => {\n if (reserved.has(id)) throw new Error(`Transfer identity collision ${id}`)\n reserved.add(id)\n }\n prepareVariableTransfer(\n plan.variables,\n
|
|
1
|
+
{"version":3,"file":"apply.js","names":[],"sources":["../../src/transfer/apply.ts"],"sourcesContent":["import { isEqual } from 'es-toolkit/predicate'\n\nimport type { SceneGraph } from '../graph'\nimport { heldTransferCollections, variableIdentityReferences } from './identity'\nimport type { prepareGraphTransfer } from './plan'\nimport { validateTransferReferences } from './validation'\nimport { prepareVariableTransfer } from './variables'\n\nexport type GraphTransferPlan = ReturnType<typeof prepareGraphTransfer>\n\nfunction validate(target: SceneGraph, plan: GraphTransferPlan): void {\n validateTransferReferences(target, plan)\n const reserved = new Set([\n ...target.nodes.keys(),\n ...target.variables.keys(),\n ...target.variableCollections.keys()\n ])\n const claim = (id: string): void => {\n if (reserved.has(id)) throw new Error(`Transfer identity collision ${id}`)\n reserved.add(id)\n }\n const collections = [...plan.collections, ...heldTransferCollections(target, plan)]\n prepareVariableTransfer(\n plan.variables,\n collections,\n variableIdentityReferences(plan.variables, collections, plan.reused.variables)\n )\n for (const collection of plan.collections) claim(collection.id)\n for (const variable of plan.variables) claim(variable.id)\n const parents = new Set(target.nodes.keys())\n for (const node of plan.nodes) {\n claim(node.id)\n if ('id' in node.props || 'parentId' in node.props || 'childIds' in node.props)\n throw new Error('Transfer props cannot override hierarchy identity')\n if (!parents.has(node.parentId)) throw new Error(`Missing transfer parent ${node.parentId}`)\n parents.add(node.id)\n }\n for (const id of [...plan.rootIds, ...plan.dependencyPageIds]) {\n if (!plan.nodes.some((node) => node.id === id)) throw new Error(`Missing transfer root ${id}`)\n }\n for (const node of plan.nodes) {\n if (node.props.componentId && !parents.has(node.props.componentId))\n throw new Error(`Missing transfer component ${node.props.componentId}`)\n }\n for (const [hash, bytes] of plan.images) {\n const existing = target.images.get(hash)\n if (existing && !isEqual(existing, bytes)) throw new Error(`Transfer image collision ${hash}`)\n }\n}\n\n/** Takes the variables a plan added out of the target's library collections again. */\nexport function leaveHeldCollections(target: SceneGraph, plan: GraphTransferPlan): void {\n for (const { collectionId, variableId } of plan.joined) {\n const collection = target.variableCollections.get(collectionId)\n if (!collection?.variableIds.includes(variableId)) continue\n target.willChangeCollection(collectionId)\n collection.variableIds = collection.variableIds.filter((id) => id !== variableId)\n }\n}\n\n/** Revalidate at insertion time. Event-delivery failures after commit are not rollback failures. */\nexport function applyGraphTransfer(target: SceneGraph, input: GraphTransferPlan): void {\n const plan = structuredClone(input)\n validate(target, plan)\n const imageIds = [...plan.images.keys()].filter((hash) => !target.images.has(hash))\n target.withBufferedEvents(() => {\n try {\n for (const collection of plan.collections) target.addCollection(collection)\n // Adding a variable lists it in its collection, the target's own included.\n for (const variable of plan.variables) target.addVariable(variable)\n for (const [hash, bytes] of plan.images)\n if (!target.images.has(hash)) target.images.set(hash, bytes)\n for (const node of plan.nodes)\n target.createNodeWithId(node.id, node.type, node.parentId, { ...node.props, childIds: [] })\n } catch (error) {\n for (const node of plan.nodes.toReversed())\n if (target.getNode(node.id)) target.deleteNode(node.id)\n leaveHeldCollections(target, plan)\n for (const variable of plan.variables) target.variables.delete(variable.id)\n for (const collection of plan.collections) target.variableCollections.delete(collection.id)\n for (const hash of imageIds) target.images.delete(hash)\n throw error\n }\n })\n}\n"],"mappings":";;;;;AAUA,SAAS,SAAS,QAAoB,MAA+B;CACnE,2BAA2B,QAAQ,IAAI;CACvC,MAAM,2BAAW,IAAI,IAAI;EACvB,GAAG,OAAO,MAAM,KAAK;EACrB,GAAG,OAAO,UAAU,KAAK;EACzB,GAAG,OAAO,oBAAoB,KAAK;CACrC,CAAC;CACD,MAAM,SAAS,OAAqB;EAClC,IAAI,SAAS,IAAI,EAAE,GAAG,MAAM,IAAI,MAAM,+BAA+B,IAAI;EACzE,SAAS,IAAI,EAAE;CACjB;CACA,MAAM,cAAc,CAAC,GAAG,KAAK,aAAa,GAAG,wBAAwB,QAAQ,IAAI,CAAC;CAClF,wBACE,KAAK,WACL,aACA,2BAA2B,KAAK,WAAW,aAAa,KAAK,OAAO,SAAS,CAC/E;CACA,KAAK,MAAM,cAAc,KAAK,aAAa,MAAM,WAAW,EAAE;CAC9D,KAAK,MAAM,YAAY,KAAK,WAAW,MAAM,SAAS,EAAE;CACxD,MAAM,UAAU,IAAI,IAAI,OAAO,MAAM,KAAK,CAAC;CAC3C,KAAK,MAAM,QAAQ,KAAK,OAAO;EAC7B,MAAM,KAAK,EAAE;EACb,IAAI,QAAQ,KAAK,SAAS,cAAc,KAAK,SAAS,cAAc,KAAK,OACvE,MAAM,IAAI,MAAM,mDAAmD;EACrE,IAAI,CAAC,QAAQ,IAAI,KAAK,QAAQ,GAAG,MAAM,IAAI,MAAM,2BAA2B,KAAK,UAAU;EAC3F,QAAQ,IAAI,KAAK,EAAE;CACrB;CACA,KAAK,MAAM,MAAM,CAAC,GAAG,KAAK,SAAS,GAAG,KAAK,iBAAiB,GAC1D,IAAI,CAAC,KAAK,MAAM,MAAM,SAAS,KAAK,OAAO,EAAE,GAAG,MAAM,IAAI,MAAM,yBAAyB,IAAI;CAE/F,KAAK,MAAM,QAAQ,KAAK,OACtB,IAAI,KAAK,MAAM,eAAe,CAAC,QAAQ,IAAI,KAAK,MAAM,WAAW,GAC/D,MAAM,IAAI,MAAM,8BAA8B,KAAK,MAAM,aAAa;CAE1E,KAAK,MAAM,CAAC,MAAM,UAAU,KAAK,QAAQ;EACvC,MAAM,WAAW,OAAO,OAAO,IAAI,IAAI;EACvC,IAAI,YAAY,CAAC,QAAQ,UAAU,KAAK,GAAG,MAAM,IAAI,MAAM,4BAA4B,MAAM;CAC/F;AACF;;AAGA,SAAgB,qBAAqB,QAAoB,MAA+B;CACtF,KAAK,MAAM,EAAE,cAAc,gBAAgB,KAAK,QAAQ;EACtD,MAAM,aAAa,OAAO,oBAAoB,IAAI,YAAY;EAC9D,IAAI,CAAC,YAAY,YAAY,SAAS,UAAU,GAAG;EACnD,OAAO,qBAAqB,YAAY;EACxC,WAAW,cAAc,WAAW,YAAY,QAAQ,OAAO,OAAO,UAAU;CAClF;AACF;;AAGA,SAAgB,mBAAmB,QAAoB,OAAgC;CACrF,MAAM,OAAO,gBAAgB,KAAK;CAClC,SAAS,QAAQ,IAAI;CACrB,MAAM,WAAW,CAAC,GAAG,KAAK,OAAO,KAAK,CAAC,CAAC,CAAC,QAAQ,SAAS,CAAC,OAAO,OAAO,IAAI,IAAI,CAAC;CAClF,OAAO,yBAAyB;EAC9B,IAAI;GACF,KAAK,MAAM,cAAc,KAAK,aAAa,OAAO,cAAc,UAAU;GAE1E,KAAK,MAAM,YAAY,KAAK,WAAW,OAAO,YAAY,QAAQ;GAClE,KAAK,MAAM,CAAC,MAAM,UAAU,KAAK,QAC/B,IAAI,CAAC,OAAO,OAAO,IAAI,IAAI,GAAG,OAAO,OAAO,IAAI,MAAM,KAAK;GAC7D,KAAK,MAAM,QAAQ,KAAK,OACtB,OAAO,iBAAiB,KAAK,IAAI,KAAK,MAAM,KAAK,UAAU;IAAE,GAAG,KAAK;IAAO,UAAU,CAAC;GAAE,CAAC;EAC9F,SAAS,OAAO;GACd,KAAK,MAAM,QAAQ,KAAK,MAAM,WAAW,GACvC,IAAI,OAAO,QAAQ,KAAK,EAAE,GAAG,OAAO,WAAW,KAAK,EAAE;GACxD,qBAAqB,QAAQ,IAAI;GACjC,KAAK,MAAM,YAAY,KAAK,WAAW,OAAO,UAAU,OAAO,SAAS,EAAE;GAC1E,KAAK,MAAM,cAAc,KAAK,aAAa,OAAO,oBAAoB,OAAO,WAAW,EAAE;GAC1F,KAAK,MAAM,QAAQ,UAAU,OAAO,OAAO,OAAO,IAAI;GACtD,MAAM;EACR;CACF,CAAC;AACH"}
|
|
@@ -20,6 +20,11 @@ interface ReferenceResolvers {
|
|
|
20
20
|
/** Copies placed in another document, whose text links must follow the copy. */
|
|
21
21
|
interface CopiedReferenceOptions {
|
|
22
22
|
followTextLinks?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Layers the target already holds in place of ones left out of the copy, by the ID each stands
|
|
25
|
+
* for. References to them point there; the layers themselves are not copies and stay as they are.
|
|
26
|
+
*/
|
|
27
|
+
aliases?: ReadonlyMap<string, string>;
|
|
23
28
|
}
|
|
24
29
|
/** The instance-swap properties `nodes` define, whose values name components. */
|
|
25
30
|
declare function instanceSwapPropertyIds(nodes: Iterable<SceneNode>): Set<string>;
|
|
@@ -38,7 +43,7 @@ declare function resolvedReferences(node: SceneNode, previous: SceneNode, resolv
|
|
|
38
43
|
* ends follow. `mappedIds` maps each copied layer to its copy, such as a library copy or a design
|
|
39
44
|
* JSX render folded into the layers it replaces; a reference outside the copy stays as it is, and
|
|
40
45
|
* so do variable IDs, since the copies keep their source's variables. Text links follow the copy
|
|
41
|
-
* only with `followTextLinks
|
|
46
|
+
* only with `followTextLinks`, and `aliases` points references at layers already there.
|
|
42
47
|
*/
|
|
43
48
|
declare function remapCopiedReferences(graph: SceneGraph, mappedIds: ReadonlyMap<string, string>, options?: CopiedReferenceOptions): void;
|
|
44
49
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"copied.d.ts","names":[],"sources":["../../src/transfer/copied.ts"],"mappings":";;;;UASiB;;EAEf,YAAY,YAAY;;EAExB,QAAQ,YAAY;;EAEpB,WAAW;;;;;;EAMX,QAAQ;EACR,WAAW;;;UAII;EACf;;;
|
|
1
|
+
{"version":3,"file":"copied.d.ts","names":[],"sources":["../../src/transfer/copied.ts"],"mappings":";;;;UASiB;;EAEf,YAAY,YAAY;;EAExB,QAAQ,YAAY;;EAEpB,WAAW;;;;;;EAMX,QAAQ;EACR,WAAW;;;UAII;EACf;;;;;EAKA,UAAU;;;iBAUI,wBAAwB,OAAO,SAAS,aAAa;;;;;;;;iBAWrD,mBACd,MAAM,WACN,UAAU,WACV,SAAS,oBACT,gBAAgB,sBACf,QAAQ;;;;;;;;;;iBA8DK,sBACd,OAAO,YACP,WAAW,6BACX,UAAS"}
|
package/dist/transfer/copied.js
CHANGED
|
@@ -59,10 +59,10 @@ function resolvedReferences(node, previous, resolve, swapProperties) {
|
|
|
59
59
|
* ends follow. `mappedIds` maps each copied layer to its copy, such as a library copy or a design
|
|
60
60
|
* JSX render folded into the layers it replaces; a reference outside the copy stays as it is, and
|
|
61
61
|
* so do variable IDs, since the copies keep their source's variables. Text links follow the copy
|
|
62
|
-
* only with `followTextLinks
|
|
62
|
+
* only with `followTextLinks`, and `aliases` points references at layers already there.
|
|
63
63
|
*/
|
|
64
64
|
function remapCopiedReferences(graph, mappedIds, options = {}) {
|
|
65
|
-
const mapped = (id) => mappedIds.get(id) ?? id;
|
|
65
|
+
const mapped = (id) => mappedIds.get(id) ?? options.aliases?.get(id) ?? id;
|
|
66
66
|
const resolve = {
|
|
67
67
|
component: mapped,
|
|
68
68
|
layer: mapped,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"copied.js","names":[],"sources":["../../src/transfer/copied.ts"],"sourcesContent":["import { isEqual, mapValues } from 'es-toolkit'\n\nimport { componentPropertyDefinitions } from '../components/properties'\nimport type { SceneGraph } from '../graph'\nimport { remapInstanceOverrideState } from '../instances/overrides'\nimport { remapStyleRunReferences } from '../text/references'\nimport type { ComponentPropertyDefinition, SceneNode } from '../types'\n\n/** How a layer's references to other layers are resolved anew. */\nexport interface ReferenceResolvers {\n /** The component a reference names now; `previous` is the one the layer named, if any. */\n component: (id: string, previous: string | null) => string\n /** The layer an override names now; `component` is the one its instance now draws. */\n layer: (id: string, component: string | null) => string\n /** The layer a connector's end follows now. */\n endpoint: (id: string) => string\n /**\n * The layer a text link names now. Without it links keep naming their layers, as Figma's\n * duplicate and paste do (desktop 126); copies into another document, which lacks those\n * layers, pass it.\n */\n link?: (id: string) => string\n variable: (id: string) => string\n}\n\n/** Copies placed in another document, whose text links must follow the copy. */\nexport interface CopiedReferenceOptions {\n followTextLinks?: boolean\n}\n\nfunction swapPropertyIds(definitions: readonly ComponentPropertyDefinition[]): string[] {\n return definitions\n .filter((definition) => definition.type === 'INSTANCE_SWAP')\n .map((definition) => definition.id)\n}\n\n/** The instance-swap properties `nodes` define, whose values name components. */\nexport function instanceSwapPropertyIds(nodes: Iterable<SceneNode>): Set<string> {\n return new Set([...nodes].flatMap((node) => swapPropertyIds(node.componentPropertyDefinitions)))\n}\n\n/**\n * `node`'s references to other layers, resolved anew: its main component, the layers its\n * overrides change and the components they swap in, the components its instance-swap properties\n * default to or are set to, and the layers its connector ends follow. `previous` is the layer\n * whose references these replace, so a resolver can keep what it already pointed at. Only the\n * fields whose references change are returned: every write is an update collaboration sends.\n */\nexport function resolvedReferences(\n node: SceneNode,\n previous: SceneNode,\n resolve: ReferenceResolvers,\n swapProperties: ReadonlySet<string>\n): Partial<SceneNode> {\n const changes: Partial<SceneNode> = {}\n const componentId = node.componentId\n ? resolve.component(node.componentId, previous.componentId)\n : null\n if (componentId !== node.componentId) changes.componentId = componentId\n const overrides = remapInstanceOverrideState(node.instanceOverrides, {\n node: (id) => resolve.layer(id, componentId),\n variable: resolve.variable\n })\n if (!isEqual(overrides, node.instanceOverrides)) changes.instanceOverrides = overrides\n const previousDefaults = new Map(\n previous.componentPropertyDefinitions.map((definition) => [\n definition.id,\n definition.defaultValue\n ])\n )\n const definitions = node.componentPropertyDefinitions.map((definition) =>\n definition.type === 'INSTANCE_SWAP' && definition.defaultValue\n ? {\n ...definition,\n defaultValue: resolve.component(\n definition.defaultValue,\n previousDefaults.get(definition.id) ?? null\n )\n }\n : definition\n )\n if (!isEqual(definitions, node.componentPropertyDefinitions))\n changes.componentPropertyDefinitions = definitions\n const assignments = mapValues(node.componentPropertyAssignments, (value, id) =>\n swapProperties.has(id)\n ? resolve.component(value, previous.componentPropertyAssignments[id] ?? null)\n : value\n )\n if (!isEqual(assignments, node.componentPropertyAssignments))\n changes.componentPropertyAssignments = assignments\n for (const field of ['connectorStart', 'connectorEnd'] as const) {\n const endpoint = node[field]\n const nodeId = endpoint?.nodeId ? resolve.endpoint(endpoint.nodeId) : null\n if (endpoint && nodeId && nodeId !== endpoint.nodeId) changes[field] = { ...endpoint, nodeId }\n }\n if (resolve.link) {\n const styleRuns = remapStyleRunReferences(node.styleRuns, {\n variable: (id) => id,\n style: (id) => id,\n node: resolve.link\n })\n if (!isEqual(styleRuns, node.styleRuns)) changes.styleRuns = styleRuns\n }\n return changes\n}\n\n/**\n * Points copied layers at one another, as `prepareNodeTransfer` does for a paste: an instance's\n * main component, the layers its overrides change and the components they swap in, the\n * components an instance-swap property defaults to or is set to, and the layers a connector's\n * ends follow. `mappedIds` maps each copied layer to its copy, such as a library copy or a design\n * JSX render folded into the layers it replaces; a reference outside the copy stays as it is, and\n * so do variable IDs, since the copies keep their source's variables. Text links follow the copy\n * only with `followTextLinks
|
|
1
|
+
{"version":3,"file":"copied.js","names":[],"sources":["../../src/transfer/copied.ts"],"sourcesContent":["import { isEqual, mapValues } from 'es-toolkit'\n\nimport { componentPropertyDefinitions } from '../components/properties'\nimport type { SceneGraph } from '../graph'\nimport { remapInstanceOverrideState } from '../instances/overrides'\nimport { remapStyleRunReferences } from '../text/references'\nimport type { ComponentPropertyDefinition, SceneNode } from '../types'\n\n/** How a layer's references to other layers are resolved anew. */\nexport interface ReferenceResolvers {\n /** The component a reference names now; `previous` is the one the layer named, if any. */\n component: (id: string, previous: string | null) => string\n /** The layer an override names now; `component` is the one its instance now draws. */\n layer: (id: string, component: string | null) => string\n /** The layer a connector's end follows now. */\n endpoint: (id: string) => string\n /**\n * The layer a text link names now. Without it links keep naming their layers, as Figma's\n * duplicate and paste do (desktop 126); copies into another document, which lacks those\n * layers, pass it.\n */\n link?: (id: string) => string\n variable: (id: string) => string\n}\n\n/** Copies placed in another document, whose text links must follow the copy. */\nexport interface CopiedReferenceOptions {\n followTextLinks?: boolean\n /**\n * Layers the target already holds in place of ones left out of the copy, by the ID each stands\n * for. References to them point there; the layers themselves are not copies and stay as they are.\n */\n aliases?: ReadonlyMap<string, string>\n}\n\nfunction swapPropertyIds(definitions: readonly ComponentPropertyDefinition[]): string[] {\n return definitions\n .filter((definition) => definition.type === 'INSTANCE_SWAP')\n .map((definition) => definition.id)\n}\n\n/** The instance-swap properties `nodes` define, whose values name components. */\nexport function instanceSwapPropertyIds(nodes: Iterable<SceneNode>): Set<string> {\n return new Set([...nodes].flatMap((node) => swapPropertyIds(node.componentPropertyDefinitions)))\n}\n\n/**\n * `node`'s references to other layers, resolved anew: its main component, the layers its\n * overrides change and the components they swap in, the components its instance-swap properties\n * default to or are set to, and the layers its connector ends follow. `previous` is the layer\n * whose references these replace, so a resolver can keep what it already pointed at. Only the\n * fields whose references change are returned: every write is an update collaboration sends.\n */\nexport function resolvedReferences(\n node: SceneNode,\n previous: SceneNode,\n resolve: ReferenceResolvers,\n swapProperties: ReadonlySet<string>\n): Partial<SceneNode> {\n const changes: Partial<SceneNode> = {}\n const componentId = node.componentId\n ? resolve.component(node.componentId, previous.componentId)\n : null\n if (componentId !== node.componentId) changes.componentId = componentId\n const overrides = remapInstanceOverrideState(node.instanceOverrides, {\n node: (id) => resolve.layer(id, componentId),\n variable: resolve.variable\n })\n if (!isEqual(overrides, node.instanceOverrides)) changes.instanceOverrides = overrides\n const previousDefaults = new Map(\n previous.componentPropertyDefinitions.map((definition) => [\n definition.id,\n definition.defaultValue\n ])\n )\n const definitions = node.componentPropertyDefinitions.map((definition) =>\n definition.type === 'INSTANCE_SWAP' && definition.defaultValue\n ? {\n ...definition,\n defaultValue: resolve.component(\n definition.defaultValue,\n previousDefaults.get(definition.id) ?? null\n )\n }\n : definition\n )\n if (!isEqual(definitions, node.componentPropertyDefinitions))\n changes.componentPropertyDefinitions = definitions\n const assignments = mapValues(node.componentPropertyAssignments, (value, id) =>\n swapProperties.has(id)\n ? resolve.component(value, previous.componentPropertyAssignments[id] ?? null)\n : value\n )\n if (!isEqual(assignments, node.componentPropertyAssignments))\n changes.componentPropertyAssignments = assignments\n for (const field of ['connectorStart', 'connectorEnd'] as const) {\n const endpoint = node[field]\n const nodeId = endpoint?.nodeId ? resolve.endpoint(endpoint.nodeId) : null\n if (endpoint && nodeId && nodeId !== endpoint.nodeId) changes[field] = { ...endpoint, nodeId }\n }\n if (resolve.link) {\n const styleRuns = remapStyleRunReferences(node.styleRuns, {\n variable: (id) => id,\n style: (id) => id,\n node: resolve.link\n })\n if (!isEqual(styleRuns, node.styleRuns)) changes.styleRuns = styleRuns\n }\n return changes\n}\n\n/**\n * Points copied layers at one another, as `prepareNodeTransfer` does for a paste: an instance's\n * main component, the layers its overrides change and the components they swap in, the\n * components an instance-swap property defaults to or is set to, and the layers a connector's\n * ends follow. `mappedIds` maps each copied layer to its copy, such as a library copy or a design\n * JSX render folded into the layers it replaces; a reference outside the copy stays as it is, and\n * so do variable IDs, since the copies keep their source's variables. Text links follow the copy\n * only with `followTextLinks`, and `aliases` points references at layers already there.\n */\nexport function remapCopiedReferences(\n graph: SceneGraph,\n mappedIds: ReadonlyMap<string, string>,\n options: CopiedReferenceOptions = {}\n): void {\n const mapped = (id: string) => mappedIds.get(id) ?? options.aliases?.get(id) ?? id\n const resolve: ReferenceResolvers = {\n component: mapped,\n layer: mapped,\n endpoint: mapped,\n link: options.followTextLinks ? mapped : undefined,\n variable: (id) => id\n }\n const copies = [...mappedIds.values()].flatMap((id) => graph.getNode(id) ?? [])\n const copiedSwaps = instanceSwapPropertyIds(copies)\n for (const node of copies) {\n // An instance's swap property may be defined on a component the copy leaves behind.\n const swapProperties = new Set([\n ...copiedSwaps,\n ...swapPropertyIds(componentPropertyDefinitions(graph, node))\n ])\n const changes = resolvedReferences(node, node, resolve, swapProperties)\n if (Object.keys(changes).length > 0) graph.updateNode(node.id, changes)\n }\n}\n"],"mappings":";;;;;AAmCA,SAAS,gBAAgB,aAA+D;CACtF,OAAO,YACJ,QAAQ,eAAe,WAAW,SAAS,eAAe,CAAC,CAC3D,KAAK,eAAe,WAAW,EAAE;AACtC;;AAGA,SAAgB,wBAAwB,OAAyC;CAC/E,OAAO,IAAI,IAAI,CAAC,GAAG,KAAK,CAAC,CAAC,SAAS,SAAS,gBAAgB,KAAK,4BAA4B,CAAC,CAAC;AACjG;;;;;;;;AASA,SAAgB,mBACd,MACA,UACA,SACA,gBACoB;CACpB,MAAM,UAA8B,CAAC;CACrC,MAAM,cAAc,KAAK,cACrB,QAAQ,UAAU,KAAK,aAAa,SAAS,WAAW,IACxD;CACJ,IAAI,gBAAgB,KAAK,aAAa,QAAQ,cAAc;CAC5D,MAAM,YAAY,2BAA2B,KAAK,mBAAmB;EACnE,OAAO,OAAO,QAAQ,MAAM,IAAI,WAAW;EAC3C,UAAU,QAAQ;CACpB,CAAC;CACD,IAAI,CAAC,QAAQ,WAAW,KAAK,iBAAiB,GAAG,QAAQ,oBAAoB;CAC7E,MAAM,mBAAmB,IAAI,IAC3B,SAAS,6BAA6B,KAAK,eAAe,CACxD,WAAW,IACX,WAAW,YACb,CAAC,CACH;CACA,MAAM,cAAc,KAAK,6BAA6B,KAAK,eACzD,WAAW,SAAS,mBAAmB,WAAW,eAC9C;EACE,GAAG;EACH,cAAc,QAAQ,UACpB,WAAW,cACX,iBAAiB,IAAI,WAAW,EAAE,KAAK,IACzC;CACF,IACA,UACN;CACA,IAAI,CAAC,QAAQ,aAAa,KAAK,4BAA4B,GACzD,QAAQ,+BAA+B;CACzC,MAAM,cAAc,UAAU,KAAK,+BAA+B,OAAO,OACvE,eAAe,IAAI,EAAE,IACjB,QAAQ,UAAU,OAAO,SAAS,6BAA6B,OAAO,IAAI,IAC1E,KACN;CACA,IAAI,CAAC,QAAQ,aAAa,KAAK,4BAA4B,GACzD,QAAQ,+BAA+B;CACzC,KAAK,MAAM,SAAS,CAAC,kBAAkB,cAAc,GAAY;EAC/D,MAAM,WAAW,KAAK;EACtB,MAAM,SAAS,UAAU,SAAS,QAAQ,SAAS,SAAS,MAAM,IAAI;EACtE,IAAI,YAAY,UAAU,WAAW,SAAS,QAAQ,QAAQ,SAAS;GAAE,GAAG;GAAU;EAAO;CAC/F;CACA,IAAI,QAAQ,MAAM;EAChB,MAAM,YAAY,wBAAwB,KAAK,WAAW;GACxD,WAAW,OAAO;GAClB,QAAQ,OAAO;GACf,MAAM,QAAQ;EAChB,CAAC;EACD,IAAI,CAAC,QAAQ,WAAW,KAAK,SAAS,GAAG,QAAQ,YAAY;CAC/D;CACA,OAAO;AACT;;;;;;;;;;AAWA,SAAgB,sBACd,OACA,WACA,UAAkC,CAAC,GAC7B;CACN,MAAM,UAAU,OAAe,UAAU,IAAI,EAAE,KAAK,QAAQ,SAAS,IAAI,EAAE,KAAK;CAChF,MAAM,UAA8B;EAClC,WAAW;EACX,OAAO;EACP,UAAU;EACV,MAAM,QAAQ,kBAAkB,SAAS,KAAA;EACzC,WAAW,OAAO;CACpB;CACA,MAAM,SAAS,CAAC,GAAG,UAAU,OAAO,CAAC,CAAC,CAAC,SAAS,OAAO,MAAM,QAAQ,EAAE,KAAK,CAAC,CAAC;CAC9E,MAAM,cAAc,wBAAwB,MAAM;CAClD,KAAK,MAAM,QAAQ,QAAQ;EAMzB,MAAM,UAAU,mBAAmB,MAAM,MAAM,yBAAS,IAJ7B,IAAI,CAC7B,GAAG,aACH,GAAG,gBAAgB,6BAA6B,OAAO,IAAI,CAAC,CAC9D,CACqE,CAAC;EACtE,IAAI,OAAO,KAAK,OAAO,CAAC,CAAC,SAAS,GAAG,MAAM,WAAW,KAAK,IAAI,OAAO;CACxE;AACF"}
|