@open-pencil/scene-graph 0.17.0-beta.7 → 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 +3 -2
- 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 +8 -18
- package/dist/css/shadows.js.map +1 -1
- package/dist/css/values.d.ts +6 -3
- package/dist/css/values.d.ts.map +1 -1
- package/dist/css/values.js +23 -5
- 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 +91 -13
- 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 +2 -0
- package/src/css/motion.ts +51 -0
- package/src/css/shadows.ts +8 -23
- package/src/css/values.ts +34 -4
- 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 +115 -11
- 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
package/src/text/direction.ts
CHANGED
|
@@ -1,18 +1,28 @@
|
|
|
1
|
+
import bidiFactory from 'bidi-js'
|
|
2
|
+
|
|
1
3
|
import type { LayoutDirection, SceneNode, TextDirection } from '../types'
|
|
2
4
|
|
|
3
5
|
const RTL_CHAR_RE =
|
|
4
6
|
/\p{Script=Arabic}|\p{Script=Hebrew}|\p{Script=Syriac}|\p{Script=Thaana}|\p{Script=Nko}|\p{Script=Adlam}/u
|
|
5
|
-
const LTR_CHAR_RE = /\p{Script=Latin}|\p{Script=Cyrillic}|\p{Script=Greek}/u
|
|
6
7
|
|
|
7
8
|
/** Whether the text has a letter of a right-to-left script, such as Arabic or Hebrew. */
|
|
8
9
|
export function containsRTLText(text: string): boolean {
|
|
9
10
|
return RTL_CHAR_RE.test(text)
|
|
10
11
|
}
|
|
11
12
|
|
|
13
|
+
let bidi: ReturnType<typeof bidiFactory> | undefined
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The direction of the text's first strongly directional character, as the Unicode bidi
|
|
17
|
+
* algorithm and Figma pick a paragraph's: digits, number signs, marks, and punctuation before
|
|
18
|
+
* it do not count.
|
|
19
|
+
*/
|
|
12
20
|
export function detectTextDirection(text: string): Exclude<TextDirection, 'AUTO'> {
|
|
21
|
+
bidi ??= bidiFactory()
|
|
13
22
|
for (const char of text) {
|
|
14
|
-
|
|
15
|
-
if (
|
|
23
|
+
const type = bidi.getBidiCharTypeName(char)
|
|
24
|
+
if (type === 'L') return 'LTR'
|
|
25
|
+
if (type === 'R' || type === 'AL') return 'RTL'
|
|
16
26
|
}
|
|
17
27
|
return 'LTR'
|
|
18
28
|
}
|
|
@@ -38,23 +48,3 @@ export function resolveNodeLayoutDirection(
|
|
|
38
48
|
? inheritedDirection
|
|
39
49
|
: node.layoutDirection
|
|
40
50
|
}
|
|
41
|
-
|
|
42
|
-
export function isLogicalTextAlignStart(
|
|
43
|
-
node: Pick<SceneNode, 'textAlignHorizontal' | 'textDirection' | 'text'>
|
|
44
|
-
): boolean {
|
|
45
|
-
const direction = resolveNodeTextDirection(node)
|
|
46
|
-
return (
|
|
47
|
-
(direction === 'LTR' && node.textAlignHorizontal === 'LEFT') ||
|
|
48
|
-
(direction === 'RTL' && node.textAlignHorizontal === 'RIGHT')
|
|
49
|
-
)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export function isLogicalTextAlignEnd(
|
|
53
|
-
node: Pick<SceneNode, 'textAlignHorizontal' | 'textDirection' | 'text'>
|
|
54
|
-
): boolean {
|
|
55
|
-
const direction = resolveNodeTextDirection(node)
|
|
56
|
-
return (
|
|
57
|
-
(direction === 'LTR' && node.textAlignHorizontal === 'RIGHT') ||
|
|
58
|
-
(direction === 'RTL' && node.textAlignHorizontal === 'LEFT')
|
|
59
|
-
)
|
|
60
|
-
}
|
package/src/text/index.ts
CHANGED
package/src/text/name.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { SceneNode } from '../types'
|
|
2
|
+
|
|
3
|
+
/** The name a text layer that follows its text takes: its characters on one line, as Figma names it. */
|
|
4
|
+
export function textLayerName(text: string): string {
|
|
5
|
+
return text.replace(/\s+/g, ' ').trim() || 'Text'
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The name `changes` also sets on a text layer that follows its text (`autoRename`): its new text
|
|
10
|
+
* written, or following turned back on. A name the write gives itself wins, so a rename, or undo
|
|
11
|
+
* putting one back, is kept; setting the name alone does not stop the layer following its text,
|
|
12
|
+
* which a rename does by setting `autoRename` to false with it.
|
|
13
|
+
*/
|
|
14
|
+
export function textNameChanges(node: SceneNode, changes: Partial<SceneNode>): Partial<SceneNode> {
|
|
15
|
+
if (node.type !== 'TEXT' || 'name' in changes) return {}
|
|
16
|
+
if (!('text' in changes) && changes.autoRename !== true) return {}
|
|
17
|
+
if (!(changes.autoRename ?? node.autoRename)) return {}
|
|
18
|
+
const name = textLayerName(changes.text ?? node.text)
|
|
19
|
+
return name === node.name ? {} : { name }
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** What renaming a layer writes: the name, and on a text layer an end to following its text. */
|
|
23
|
+
export function renameChanges(node: SceneNode, name: string): Partial<SceneNode> {
|
|
24
|
+
return node.type === 'TEXT' ? { name, autoRename: false } : { name }
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* What making a text layer from `overrides` also sets: the name of its text, as an edit sets it,
|
|
29
|
+
* or, given a name other than its text's, an end to following it, as a rename makes. A follow
|
|
30
|
+
* flag the overrides give, as a file or a copy gives, is kept.
|
|
31
|
+
*/
|
|
32
|
+
export function newTextNameChanges(
|
|
33
|
+
node: SceneNode,
|
|
34
|
+
overrides: Partial<SceneNode>
|
|
35
|
+
): Partial<SceneNode> {
|
|
36
|
+
if (node.type !== 'TEXT' || !('name' in overrides) || 'autoRename' in overrides)
|
|
37
|
+
return textNameChanges(node, overrides)
|
|
38
|
+
return node.name === textLayerName(node.text) ? {} : { autoRename: false }
|
|
39
|
+
}
|
package/src/text/references.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { mapValues } from 'es-toolkit/object'
|
|
2
|
-
|
|
3
1
|
import type { StyleRun } from '../types'
|
|
4
2
|
|
|
5
3
|
/** What a text's runs refer to outside the text: the variables they bind and the styles they use. */
|
|
@@ -41,7 +39,9 @@ export function remapStyleRunReferences(
|
|
|
41
39
|
style.hyperlink = { type: 'NODE', value: rename.node(hyperlink.value) }
|
|
42
40
|
}
|
|
43
41
|
if (boundVariables) {
|
|
44
|
-
style.boundVariables =
|
|
42
|
+
style.boundVariables = Object.fromEntries(
|
|
43
|
+
Object.entries(boundVariables).map(([field, id]) => [field, rename.variable(id)])
|
|
44
|
+
)
|
|
45
45
|
}
|
|
46
46
|
if (textStyleId) style.textStyleId = rename.style(textStyleId)
|
|
47
47
|
if (fillStyleId) style.fillStyleId = rename.style(fillStyleId)
|
package/src/thumbnail.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { SceneGraph } from './graph'
|
|
2
|
+
import { readPluginData, withPluginData } from './plugin-data/field'
|
|
3
|
+
import { OPEN_PENCIL_PLUGIN_DATA } from './plugin-data/fields'
|
|
4
|
+
import type { SceneNode } from './types'
|
|
5
|
+
|
|
6
|
+
const { thumbnail } = OPEN_PENCIL_PLUGIN_DATA
|
|
7
|
+
|
|
8
|
+
/** Layers that frame a picture of their own, as Figma lets frames and sections be thumbnails. */
|
|
9
|
+
const THUMBNAIL_TYPES: ReadonlySet<SceneNode['type']> = new Set([
|
|
10
|
+
'FRAME',
|
|
11
|
+
'SECTION',
|
|
12
|
+
'COMPONENT',
|
|
13
|
+
'SLIDE'
|
|
14
|
+
])
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Whether `node` can be the document's thumbnail: a frame, section, or component placed straight
|
|
18
|
+
* on a page people see, or a slide.
|
|
19
|
+
*/
|
|
20
|
+
export function canBeDocumentThumbnail(graph: SceneGraph, node: SceneNode): boolean {
|
|
21
|
+
if (!THUMBNAIL_TYPES.has(node.type)) return false
|
|
22
|
+
if (node.type === 'SLIDE') return true
|
|
23
|
+
const parent = node.parentId ? graph.getNode(node.parentId) : undefined
|
|
24
|
+
return parent?.type === 'CANVAS' && !parent.internalOnly
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The id stored as the document's thumbnail, whether or not that layer is loaded or can still be
|
|
29
|
+
* one: what undo restores.
|
|
30
|
+
*/
|
|
31
|
+
export function documentThumbnailId(graph: SceneGraph): string | null {
|
|
32
|
+
return readPluginData(graph.getNode(graph.rootId)?.pluginData, thumbnail) ?? null
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The layer chosen as the document's thumbnail, or null when there is none or it can no longer
|
|
37
|
+
* be one, such as after it was deleted or moved into another frame.
|
|
38
|
+
*/
|
|
39
|
+
export function documentThumbnail(graph: SceneGraph): SceneNode | null {
|
|
40
|
+
const id = documentThumbnailId(graph)
|
|
41
|
+
const node = id ? graph.getNode(id) : undefined
|
|
42
|
+
return node && canBeDocumentThumbnail(graph, node) ? node : null
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Chooses `nodeId` as the document's thumbnail, or goes back to the default with null. */
|
|
46
|
+
export function setDocumentThumbnail(graph: SceneGraph, nodeId: string | null): void {
|
|
47
|
+
const root = graph.getNode(graph.rootId)
|
|
48
|
+
if (!root) return
|
|
49
|
+
graph.updateNode(root.id, {
|
|
50
|
+
pluginData: withPluginData(root.pluginData, thumbnail, nodeId ?? undefined)
|
|
51
|
+
})
|
|
52
|
+
}
|
package/src/transfer/apply.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isEqual } from 'es-toolkit/predicate'
|
|
2
2
|
|
|
3
3
|
import type { SceneGraph } from '../graph'
|
|
4
|
-
import { variableIdentityReferences } from './identity'
|
|
4
|
+
import { heldTransferCollections, variableIdentityReferences } from './identity'
|
|
5
5
|
import type { prepareGraphTransfer } from './plan'
|
|
6
6
|
import { validateTransferReferences } from './validation'
|
|
7
7
|
import { prepareVariableTransfer } from './variables'
|
|
@@ -19,10 +19,11 @@ function validate(target: SceneGraph, plan: GraphTransferPlan): void {
|
|
|
19
19
|
if (reserved.has(id)) throw new Error(`Transfer identity collision ${id}`)
|
|
20
20
|
reserved.add(id)
|
|
21
21
|
}
|
|
22
|
+
const collections = [...plan.collections, ...heldTransferCollections(target, plan)]
|
|
22
23
|
prepareVariableTransfer(
|
|
23
24
|
plan.variables,
|
|
24
|
-
|
|
25
|
-
variableIdentityReferences(plan.variables, plan.
|
|
25
|
+
collections,
|
|
26
|
+
variableIdentityReferences(plan.variables, collections, plan.reused.variables)
|
|
26
27
|
)
|
|
27
28
|
for (const collection of plan.collections) claim(collection.id)
|
|
28
29
|
for (const variable of plan.variables) claim(variable.id)
|
|
@@ -47,6 +48,16 @@ function validate(target: SceneGraph, plan: GraphTransferPlan): void {
|
|
|
47
48
|
}
|
|
48
49
|
}
|
|
49
50
|
|
|
51
|
+
/** Takes the variables a plan added out of the target's library collections again. */
|
|
52
|
+
export function leaveHeldCollections(target: SceneGraph, plan: GraphTransferPlan): void {
|
|
53
|
+
for (const { collectionId, variableId } of plan.joined) {
|
|
54
|
+
const collection = target.variableCollections.get(collectionId)
|
|
55
|
+
if (!collection?.variableIds.includes(variableId)) continue
|
|
56
|
+
target.willChangeCollection(collectionId)
|
|
57
|
+
collection.variableIds = collection.variableIds.filter((id) => id !== variableId)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
50
61
|
/** Revalidate at insertion time. Event-delivery failures after commit are not rollback failures. */
|
|
51
62
|
export function applyGraphTransfer(target: SceneGraph, input: GraphTransferPlan): void {
|
|
52
63
|
const plan = structuredClone(input)
|
|
@@ -55,6 +66,7 @@ export function applyGraphTransfer(target: SceneGraph, input: GraphTransferPlan)
|
|
|
55
66
|
target.withBufferedEvents(() => {
|
|
56
67
|
try {
|
|
57
68
|
for (const collection of plan.collections) target.addCollection(collection)
|
|
69
|
+
// Adding a variable lists it in its collection, the target's own included.
|
|
58
70
|
for (const variable of plan.variables) target.addVariable(variable)
|
|
59
71
|
for (const [hash, bytes] of plan.images)
|
|
60
72
|
if (!target.images.has(hash)) target.images.set(hash, bytes)
|
|
@@ -63,6 +75,7 @@ export function applyGraphTransfer(target: SceneGraph, input: GraphTransferPlan)
|
|
|
63
75
|
} catch (error) {
|
|
64
76
|
for (const node of plan.nodes.toReversed())
|
|
65
77
|
if (target.getNode(node.id)) target.deleteNode(node.id)
|
|
78
|
+
leaveHeldCollections(target, plan)
|
|
66
79
|
for (const variable of plan.variables) target.variables.delete(variable.id)
|
|
67
80
|
for (const collection of plan.collections) target.variableCollections.delete(collection.id)
|
|
68
81
|
for (const hash of imageIds) target.images.delete(hash)
|
package/src/transfer/copied.ts
CHANGED
|
@@ -26,6 +26,11 @@ export interface ReferenceResolvers {
|
|
|
26
26
|
/** Copies placed in another document, whose text links must follow the copy. */
|
|
27
27
|
export interface CopiedReferenceOptions {
|
|
28
28
|
followTextLinks?: boolean
|
|
29
|
+
/**
|
|
30
|
+
* Layers the target already holds in place of ones left out of the copy, by the ID each stands
|
|
31
|
+
* for. References to them point there; the layers themselves are not copies and stay as they are.
|
|
32
|
+
*/
|
|
33
|
+
aliases?: ReadonlyMap<string, string>
|
|
29
34
|
}
|
|
30
35
|
|
|
31
36
|
function swapPropertyIds(definitions: readonly ComponentPropertyDefinition[]): string[] {
|
|
@@ -111,14 +116,14 @@ export function resolvedReferences(
|
|
|
111
116
|
* ends follow. `mappedIds` maps each copied layer to its copy, such as a library copy or a design
|
|
112
117
|
* JSX render folded into the layers it replaces; a reference outside the copy stays as it is, and
|
|
113
118
|
* so do variable IDs, since the copies keep their source's variables. Text links follow the copy
|
|
114
|
-
* only with `followTextLinks
|
|
119
|
+
* only with `followTextLinks`, and `aliases` points references at layers already there.
|
|
115
120
|
*/
|
|
116
121
|
export function remapCopiedReferences(
|
|
117
122
|
graph: SceneGraph,
|
|
118
123
|
mappedIds: ReadonlyMap<string, string>,
|
|
119
124
|
options: CopiedReferenceOptions = {}
|
|
120
125
|
): void {
|
|
121
|
-
const mapped = (id: string) => mappedIds.get(id) ?? id
|
|
126
|
+
const mapped = (id: string) => mappedIds.get(id) ?? options.aliases?.get(id) ?? id
|
|
122
127
|
const resolve: ReferenceResolvers = {
|
|
123
128
|
component: mapped,
|
|
124
129
|
layer: mapped,
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { appendAll } from '@open-pencil/std/arrays'
|
|
2
2
|
|
|
3
|
+
import { readBehaviour } from '../behaviours/model'
|
|
4
|
+
import { transitionVariableIds } from '../behaviours/transition'
|
|
3
5
|
import type { SceneGraph } from '../graph'
|
|
4
6
|
import { imagePaintHashes } from '../images'
|
|
5
7
|
import { overriddenBindingField } from '../instances/overrides'
|
|
6
8
|
import { referencedStyleIds, sharedStyleLayers } from '../shared-styles'
|
|
9
|
+
import { slideVariableIds } from '../slides/motion'
|
|
7
10
|
import { styleRunReferences } from '../text/references'
|
|
8
11
|
import type { SceneNode } from '../types'
|
|
9
12
|
import { isUnsupportedVariableValue, variableValueReferences } from '../variables/value'
|
|
@@ -24,12 +27,18 @@ export interface LayerDependencies {
|
|
|
24
27
|
images: Set<string>
|
|
25
28
|
}
|
|
26
29
|
|
|
27
|
-
/**
|
|
30
|
+
/**
|
|
31
|
+
* The variables a layer names: its own bindings, its characters', its overrides', and those its
|
|
32
|
+
* behaviour's transition, slide transition and animation follow.
|
|
33
|
+
*/
|
|
28
34
|
export function layerVariableIds(node: SceneNode): string[] {
|
|
29
35
|
const { self, descendants } = node.instanceOverrides
|
|
30
36
|
const overridden = [...self, ...[...descendants.values()].flatMap((fields) => [...fields])]
|
|
37
|
+
const behaviour = readBehaviour(node)
|
|
31
38
|
return [
|
|
32
39
|
...Object.values(node.boundVariables),
|
|
40
|
+
...(behaviour ? transitionVariableIds(behaviour) : []),
|
|
41
|
+
...slideVariableIds(node),
|
|
33
42
|
...styleRunReferences(node.styleRuns).variables,
|
|
34
43
|
...overridden.flatMap(([field, value]) =>
|
|
35
44
|
typeof value === 'string' && overriddenBindingField(field) !== null ? [value] : []
|
package/src/transfer/history.ts
CHANGED
|
@@ -15,6 +15,8 @@ export function captureTransferredState(
|
|
|
15
15
|
nodeIds: new Map(original.nodeIds),
|
|
16
16
|
rootIds: [...original.rootIds],
|
|
17
17
|
dependencyPageIds: [...original.dependencyPageIds],
|
|
18
|
+
reused: structuredClone(original.reused),
|
|
19
|
+
joined: structuredClone(original.joined),
|
|
18
20
|
nodes: original.nodes.map((entry) => {
|
|
19
21
|
const node = requireValue(graph.getNode(entry.id), 'node', entry.id)
|
|
20
22
|
if (!node.parentId) throw new Error(`Missing transferred parent ${entry.id}`)
|
package/src/transfer/identity.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
+
import type { SceneGraph } from '../graph'
|
|
1
2
|
import type { Variable, VariableCollection } from '../types'
|
|
2
3
|
|
|
3
4
|
export function variableIdentityReferences(
|
|
4
5
|
variables: readonly Variable[],
|
|
5
|
-
collections: readonly VariableCollection[]
|
|
6
|
+
collections: readonly VariableCollection[],
|
|
7
|
+
heldVariableIds: readonly string[] = []
|
|
6
8
|
) {
|
|
7
9
|
return {
|
|
8
|
-
variables: new Map(
|
|
10
|
+
variables: new Map(
|
|
11
|
+
[...variables.map((variable) => variable.id), ...heldVariableIds].map((id) => [id, id])
|
|
12
|
+
),
|
|
9
13
|
collections: new Map(collections.map((collection) => [collection.id, collection.id])),
|
|
10
14
|
modes: new Map(
|
|
11
15
|
collections.flatMap((collection) =>
|
|
@@ -14,3 +18,31 @@ export function variableIdentityReferences(
|
|
|
14
18
|
)
|
|
15
19
|
}
|
|
16
20
|
}
|
|
21
|
+
|
|
22
|
+
/** The target's library resources a transfer reuses, and the variables it adds to them. */
|
|
23
|
+
export interface HeldTransferResources {
|
|
24
|
+
reused: { collections: string[]; variables: string[]; styles: string[] }
|
|
25
|
+
joined: Array<{ collectionId: string; variableId: string }>
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The target's collections a plan reuses, each listing only the variables the plan adds to it,
|
|
30
|
+
* as a plan's own collections list theirs, so the plan validates as one self-contained fragment.
|
|
31
|
+
*/
|
|
32
|
+
export function heldTransferCollections(
|
|
33
|
+
target: SceneGraph,
|
|
34
|
+
plan: HeldTransferResources
|
|
35
|
+
): VariableCollection[] {
|
|
36
|
+
for (const id of plan.reused.variables)
|
|
37
|
+
if (!target.variables.has(id)) throw new Error(`Missing reused transfer variable ${id}`)
|
|
38
|
+
return plan.reused.collections.map((id) => {
|
|
39
|
+
const collection = target.variableCollections.get(id)
|
|
40
|
+
if (!collection) throw new Error(`Missing reused transfer collection ${id}`)
|
|
41
|
+
return {
|
|
42
|
+
...structuredClone(collection),
|
|
43
|
+
variableIds: plan.joined
|
|
44
|
+
.filter((entry) => entry.collectionId === id)
|
|
45
|
+
.map((entry) => entry.variableId)
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
}
|
package/src/transfer/index.ts
CHANGED
|
@@ -23,3 +23,9 @@ export {
|
|
|
23
23
|
type LayerDependencies
|
|
24
24
|
} from './dependencies'
|
|
25
25
|
export { remappedResourceReferences, type ResourceReferences } from './resources'
|
|
26
|
+
export {
|
|
27
|
+
libraryModeOf,
|
|
28
|
+
matchLibraryResources,
|
|
29
|
+
withoutLibraryKey,
|
|
30
|
+
type LibraryReuse
|
|
31
|
+
} from './library'
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import type { SceneGraph } from '../graph'
|
|
2
|
+
import { sharedStyleLayers } from '../shared-styles'
|
|
3
|
+
import type { SceneNode, Variable, VariableCollection, VariableCollectionMode } from '../types'
|
|
4
|
+
|
|
5
|
+
/** A library asset's identity: its key and the version references by key carry with it. */
|
|
6
|
+
interface LibraryIdentity {
|
|
7
|
+
key?: string
|
|
8
|
+
version?: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function sameAsset(a: LibraryIdentity, b: LibraryIdentity): boolean {
|
|
12
|
+
return !!a.key && a.key === b.key && a.version === b.version
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** A copy without the library key and version it came with: the document's own. */
|
|
16
|
+
export function withoutLibraryKey<T extends LibraryIdentity>(item: T): T {
|
|
17
|
+
const copy = { ...item }
|
|
18
|
+
delete copy.key
|
|
19
|
+
delete copy.version
|
|
20
|
+
return copy
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** The library key and version a style taken from a library keeps from its file. */
|
|
24
|
+
function styleLibraryIdentity(style: SceneNode): LibraryIdentity {
|
|
25
|
+
const { key, version } = style.source.fig.rawNodeFields
|
|
26
|
+
return {
|
|
27
|
+
key: typeof key === 'string' ? key : undefined,
|
|
28
|
+
version: typeof version === 'string' ? version : undefined
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** The library mode a mode stands for: the one it came from, or else itself. */
|
|
33
|
+
export function libraryModeOf(mode: VariableCollectionMode): string {
|
|
34
|
+
return mode.libraryModeId ?? mode.modeId
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Which of `copy`'s modes each of `collection`'s stands for, or undefined when one has none. A mode
|
|
39
|
+
* takes the copy's mode that came from the same library mode; where there is none, as in a copy
|
|
40
|
+
* made before modes kept that link, an unpaired mode with its name, as `pairModes` in Core's
|
|
41
|
+
* library import pairs them.
|
|
42
|
+
*/
|
|
43
|
+
function pairedModes(
|
|
44
|
+
collection: VariableCollection,
|
|
45
|
+
copy: VariableCollection
|
|
46
|
+
): Map<string, string> | undefined {
|
|
47
|
+
const unpaired = new Map(copy.modes.map((mode) => [mode.modeId, mode]))
|
|
48
|
+
const paired = new Map<string, string>()
|
|
49
|
+
const pair = (
|
|
50
|
+
mode: VariableCollectionMode,
|
|
51
|
+
match: (candidate: VariableCollectionMode) => boolean
|
|
52
|
+
) => {
|
|
53
|
+
const found = [...unpaired.values()].find(match)
|
|
54
|
+
if (!found) return
|
|
55
|
+
unpaired.delete(found.modeId)
|
|
56
|
+
paired.set(mode.modeId, found.modeId)
|
|
57
|
+
}
|
|
58
|
+
for (const mode of collection.modes)
|
|
59
|
+
pair(mode, (candidate) => candidate.libraryModeId === libraryModeOf(mode))
|
|
60
|
+
for (const mode of collection.modes)
|
|
61
|
+
if (!paired.has(mode.modeId)) pair(mode, (candidate) => candidate.name === mode.name)
|
|
62
|
+
return paired.size === collection.modes.length ? paired : undefined
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* How a transfer meets the copies the target already holds of the library resources it brings,
|
|
67
|
+
* so that a document keeps one copy of each library asset, as Figma does: a pasted layer binds
|
|
68
|
+
* to the copy the document has, which the reader would otherwise find twice under one key.
|
|
69
|
+
*/
|
|
70
|
+
export interface LibraryReuse {
|
|
71
|
+
/** Source collections the target holds, by the target collection holding them. */
|
|
72
|
+
collections: Map<string, string>
|
|
73
|
+
/** Modes of those collections, by the target mode each stands for. */
|
|
74
|
+
modes: Map<string, string>
|
|
75
|
+
/** Source variables the target holds, by the target variable. */
|
|
76
|
+
variables: Map<string, string>
|
|
77
|
+
/** Source styles the target holds, by the style ID layers name the target's copy with. */
|
|
78
|
+
styles: Map<string, string>
|
|
79
|
+
/**
|
|
80
|
+
* Library resources the target holds a copy of that cannot take this one's place, such as a
|
|
81
|
+
* collection whose modes do not pair: the transfer makes them its own, without their key.
|
|
82
|
+
*/
|
|
83
|
+
local: Set<string>
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Matches the library resources a transfer brings against the copies the target holds.
|
|
88
|
+
* `targetStyles` is the target's `sharedStyleLayers` when the caller has it already; the target
|
|
89
|
+
* is searched for styles only when the transfer brings one.
|
|
90
|
+
*/
|
|
91
|
+
export function matchLibraryResources(
|
|
92
|
+
target: SceneGraph,
|
|
93
|
+
source: {
|
|
94
|
+
collections: Iterable<VariableCollection>
|
|
95
|
+
variables: Iterable<Variable>
|
|
96
|
+
styles: Iterable<SceneNode>
|
|
97
|
+
},
|
|
98
|
+
targetStyles?: ReadonlyMap<string, SceneNode>
|
|
99
|
+
): LibraryReuse {
|
|
100
|
+
const reuse: LibraryReuse = {
|
|
101
|
+
collections: new Map(),
|
|
102
|
+
modes: new Map(),
|
|
103
|
+
variables: new Map(),
|
|
104
|
+
styles: new Map(),
|
|
105
|
+
local: new Set()
|
|
106
|
+
}
|
|
107
|
+
// A transfer can bring one library asset twice, as a file 0.17 saved can hold it: the first
|
|
108
|
+
// copy is the library's, and the others become the document's own.
|
|
109
|
+
const claimed = new Set<string>()
|
|
110
|
+
const firstCopy = (item: LibraryIdentity & { id: string }): boolean => {
|
|
111
|
+
if (!item.key) return true
|
|
112
|
+
const identity = `${item.key}\u0000${item.version ?? ''}`
|
|
113
|
+
if (claimed.has(identity)) {
|
|
114
|
+
reuse.local.add(item.id)
|
|
115
|
+
return false
|
|
116
|
+
}
|
|
117
|
+
claimed.add(identity)
|
|
118
|
+
return true
|
|
119
|
+
}
|
|
120
|
+
const collections = [...target.variableCollections.values()]
|
|
121
|
+
for (const collection of source.collections) {
|
|
122
|
+
if (!firstCopy(collection)) continue
|
|
123
|
+
const copy = collections.find((candidate) => sameAsset(candidate, collection))
|
|
124
|
+
if (!copy) continue
|
|
125
|
+
const modes = copy.deleted ? undefined : pairedModes(collection, copy)
|
|
126
|
+
if (!modes) {
|
|
127
|
+
reuse.local.add(collection.id)
|
|
128
|
+
continue
|
|
129
|
+
}
|
|
130
|
+
reuse.collections.set(collection.id, copy.id)
|
|
131
|
+
for (const [mode, targetMode] of modes) reuse.modes.set(mode, targetMode)
|
|
132
|
+
}
|
|
133
|
+
const variables = [...target.variables.values()]
|
|
134
|
+
for (const variable of source.variables) {
|
|
135
|
+
if (!firstCopy(variable)) continue
|
|
136
|
+
const copy = variables.find((candidate) => sameAsset(candidate, variable))
|
|
137
|
+
if (!copy) continue
|
|
138
|
+
if (reuse.collections.get(variable.collectionId) === copy.collectionId && !copy.deleted)
|
|
139
|
+
reuse.variables.set(variable.id, copy.id)
|
|
140
|
+
else reuse.local.add(variable.id)
|
|
141
|
+
}
|
|
142
|
+
const incoming = [...source.styles]
|
|
143
|
+
if (incoming.length === 0) return reuse
|
|
144
|
+
const styles = [...(targetStyles ?? sharedStyleLayers(target)).values()].filter(
|
|
145
|
+
(style) => styleLibraryIdentity(style).key
|
|
146
|
+
)
|
|
147
|
+
for (const style of incoming) {
|
|
148
|
+
const identity = styleLibraryIdentity(style)
|
|
149
|
+
const copy = styles.find((candidate) => sameAsset(styleLibraryIdentity(candidate), identity))
|
|
150
|
+
if (style.source.id && copy?.source.id) reuse.styles.set(style.source.id, copy.source.id)
|
|
151
|
+
}
|
|
152
|
+
return reuse
|
|
153
|
+
}
|
package/src/transfer/nodes.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import { readBehaviour, withBehaviour } from '../behaviours/model'
|
|
2
|
+
import { mapTransitionVariables, transitionVariableIds } from '../behaviours/transition'
|
|
1
3
|
import { cloneNodeProps } from '../copy'
|
|
2
4
|
import { overriddenBindingField, remapInstanceOverrideState } from '../instances/overrides'
|
|
3
5
|
import { referencedStyleIds } from '../shared-styles'
|
|
6
|
+
import { mapSlideVariables, slideVariableIds } from '../slides/motion'
|
|
4
7
|
import { styleRunReferences } from '../text/references'
|
|
5
8
|
import type { ComponentPropertyType, SceneNode } from '../types'
|
|
6
9
|
import { requireTransferReference as required } from './references'
|
|
@@ -9,9 +12,12 @@ import type { VariableTransferReferences } from './variables'
|
|
|
9
12
|
|
|
10
13
|
export function semanticTransferReferences(node: SceneNode): string[] {
|
|
11
14
|
const runs = styleRunReferences(node.styleRuns)
|
|
15
|
+
const behaviour = readBehaviour(node)
|
|
12
16
|
return [
|
|
13
17
|
...(node.componentId ? [node.componentId] : []),
|
|
14
18
|
...Object.values(node.boundVariables),
|
|
19
|
+
...(behaviour ? transitionVariableIds(behaviour) : []),
|
|
20
|
+
...slideVariableIds(node),
|
|
15
21
|
...runs.variables,
|
|
16
22
|
...referencedStyleIds(node),
|
|
17
23
|
...Object.entries(node.componentPropertyAssignments).flatMap(([id, value]) => [id, value]),
|
|
@@ -98,6 +104,20 @@ export function prepareNodeTransfer(
|
|
|
98
104
|
return propertyId ? [{ ...reference, propertyId }] : []
|
|
99
105
|
})
|
|
100
106
|
result.componentPropertyAssignments = values(source.componentPropertyAssignments)
|
|
107
|
+
// A behaviour's transition follows the variables the copy brings; one it left behind is let go,
|
|
108
|
+
// and the transition keeps its own value.
|
|
109
|
+
const behaviour = readBehaviour(source)
|
|
110
|
+
if (behaviour && transitionVariableIds(behaviour).length > 0)
|
|
111
|
+
result.pluginData = withBehaviour(
|
|
112
|
+
source,
|
|
113
|
+
mapTransitionVariables(behaviour, (id) => refs.variables.get(id))
|
|
114
|
+
)
|
|
115
|
+
// So do a slide's transition and a layer's animation.
|
|
116
|
+
if (slideVariableIds(source).length > 0)
|
|
117
|
+
Object.assign(
|
|
118
|
+
result,
|
|
119
|
+
mapSlideVariables(source, (id) => refs.variables.get(id))
|
|
120
|
+
)
|
|
101
121
|
// Variant values are keyed by display names, unlike definition-ID assignments.
|
|
102
122
|
result.componentPropertyValues = { ...source.componentPropertyValues }
|
|
103
123
|
return result
|