@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/node-defaults.ts
CHANGED
|
@@ -8,6 +8,12 @@ import { createInstanceOverrideState } from './instances/overrides'
|
|
|
8
8
|
import { NO_LETTER_SPACING } from './text/lengths'
|
|
9
9
|
import type { NodeType, SceneNode, SourceMetadata } from './types'
|
|
10
10
|
|
|
11
|
+
/** The name a layer of `type` starts with: its type in words, as Figma names a new layer. */
|
|
12
|
+
export function defaultNodeName(type: NodeType): string {
|
|
13
|
+
const words = type.toLowerCase().replaceAll('_', ' ')
|
|
14
|
+
return words.charAt(0).toUpperCase() + words.slice(1)
|
|
15
|
+
}
|
|
16
|
+
|
|
11
17
|
export function createDefaultSourceMetadata(): SourceMetadata {
|
|
12
18
|
return {
|
|
13
19
|
format: null,
|
|
@@ -21,6 +27,7 @@ export function createDefaultSourceMetadata(): SourceMetadata {
|
|
|
21
27
|
layout: null,
|
|
22
28
|
symbolOverrides: [],
|
|
23
29
|
componentPropAssignments: [],
|
|
30
|
+
hiddenSlotAssignments: [],
|
|
24
31
|
derivedSymbolData: [],
|
|
25
32
|
derivedSymbolDataLayoutVersion: null,
|
|
26
33
|
uniformScaleFactor: null
|
|
@@ -79,7 +86,7 @@ export function createDefaultNode(
|
|
|
79
86
|
const defaults = {
|
|
80
87
|
id: generateId(),
|
|
81
88
|
type,
|
|
82
|
-
name:
|
|
89
|
+
name: defaultNodeName(type),
|
|
83
90
|
parentId: null,
|
|
84
91
|
childIds: ownList(overrides.childIds),
|
|
85
92
|
x: 0,
|
|
@@ -208,6 +215,8 @@ export function createDefaultNode(
|
|
|
208
215
|
// Figma's: the golden-ratio star, whose inner points line up with its outer ones.
|
|
209
216
|
starInnerRadius: (3 - Math.sqrt(5)) / 2,
|
|
210
217
|
shapeWithTextType: 'SQUARE',
|
|
218
|
+
slide: null,
|
|
219
|
+
animation: null,
|
|
211
220
|
shapeUserHeight: 0,
|
|
212
221
|
shapeTruncates: false,
|
|
213
222
|
componentId: null,
|
|
@@ -264,7 +273,8 @@ export const SIDE_STROKE_TYPES: ReadonlySet<NodeType> = new Set<NodeType>([
|
|
|
264
273
|
'FRAME',
|
|
265
274
|
'COMPONENT',
|
|
266
275
|
'COMPONENT_SET',
|
|
267
|
-
'INSTANCE'
|
|
276
|
+
'INSTANCE',
|
|
277
|
+
'SLIDE'
|
|
268
278
|
])
|
|
269
279
|
|
|
270
280
|
/** The kinds that hold layers of their own on the canvas: what a shadow or a clip encloses. */
|
|
@@ -274,7 +284,10 @@ export const LAYER_CONTAINER_TYPES: ReadonlySet<NodeType> = new Set<NodeType>([
|
|
|
274
284
|
'SECTION',
|
|
275
285
|
'COMPONENT',
|
|
276
286
|
'COMPONENT_SET',
|
|
277
|
-
'INSTANCE'
|
|
287
|
+
'INSTANCE',
|
|
288
|
+
'SLIDE',
|
|
289
|
+
'SLIDE_ROW',
|
|
290
|
+
'SLIDE_GRID'
|
|
278
291
|
])
|
|
279
292
|
|
|
280
293
|
export function isLayerContainer(node: Pick<SceneNode, 'type'>): boolean {
|
|
@@ -286,7 +299,8 @@ export const CLIPPING_TYPES: ReadonlySet<NodeType> = new Set<NodeType>([
|
|
|
286
299
|
'FRAME',
|
|
287
300
|
'COMPONENT',
|
|
288
301
|
'COMPONENT_SET',
|
|
289
|
-
'INSTANCE'
|
|
302
|
+
'INSTANCE',
|
|
303
|
+
'SLIDE'
|
|
290
304
|
])
|
|
291
305
|
|
|
292
306
|
/**
|
|
@@ -306,5 +320,8 @@ export const CONTAINER_TYPES = new Set<NodeType>([
|
|
|
306
320
|
'SECTION',
|
|
307
321
|
'COMPONENT',
|
|
308
322
|
'COMPONENT_SET',
|
|
309
|
-
'INSTANCE'
|
|
323
|
+
'INSTANCE',
|
|
324
|
+
'SLIDE',
|
|
325
|
+
'SLIDE_ROW',
|
|
326
|
+
'SLIDE_GRID'
|
|
310
327
|
])
|
package/src/paints/index.ts
CHANGED
package/src/paints/pattern.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { SceneGraph } from '../graph'
|
|
1
2
|
import type { Rect, Vector } from '../primitives'
|
|
2
3
|
import type { Fill, SceneNode } from '../types'
|
|
3
4
|
|
|
@@ -43,3 +44,57 @@ export function patternTileLayout(
|
|
|
43
44
|
|
|
44
45
|
return { rect: { x: 0, y: 0, width, height }, scale, positions }
|
|
45
46
|
}
|
|
47
|
+
|
|
48
|
+
function addPatternSourceIds(paints: readonly Fill[], ids: string[]) {
|
|
49
|
+
for (const paint of paints) {
|
|
50
|
+
if (paint.type === 'PATTERN' && paint.sourceNodeId) {
|
|
51
|
+
ids.push(paint.sourceNodeId)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function patternSourceIds(node: SceneNode): string[] {
|
|
57
|
+
const ids: string[] = []
|
|
58
|
+
addPatternSourceIds(node.fills, ids)
|
|
59
|
+
addPatternSourceIds(node.strokes, ids)
|
|
60
|
+
addPatternSourceIds(node.textDecorationFills, ids)
|
|
61
|
+
for (const region of node.vectorNetwork?.regions ?? []) {
|
|
62
|
+
addPatternSourceIds(region.fills ?? [], ids)
|
|
63
|
+
}
|
|
64
|
+
for (const run of node.styleRuns) {
|
|
65
|
+
addPatternSourceIds(run.style.fills ?? [], ids)
|
|
66
|
+
addPatternSourceIds(run.style.textDecorationFills ?? [], ids)
|
|
67
|
+
}
|
|
68
|
+
return ids
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function indexBySourceId(graph: SceneGraph): Map<string, SceneNode> {
|
|
72
|
+
const index = new Map<string, SceneNode>()
|
|
73
|
+
for (const node of graph.getAllNodes()) {
|
|
74
|
+
if (node.source.id && !index.has(node.source.id)) {
|
|
75
|
+
index.set(node.source.id, node)
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return index
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function createPatternSourceLookup(
|
|
82
|
+
graph: SceneGraph
|
|
83
|
+
): (sourceId: string) => SceneNode | null {
|
|
84
|
+
let bySourceId: Map<string, SceneNode> | null = null
|
|
85
|
+
return (sourceId) => {
|
|
86
|
+
const direct = graph.getNode(sourceId)
|
|
87
|
+
if (direct) {
|
|
88
|
+
return direct
|
|
89
|
+
}
|
|
90
|
+
bySourceId ??= indexBySourceId(graph)
|
|
91
|
+
return bySourceId.get(sourceId) ?? null
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function resolvedPatternSourceIds(
|
|
96
|
+
node: SceneNode,
|
|
97
|
+
findSource: (sourceId: string) => SceneNode | null
|
|
98
|
+
): string[] {
|
|
99
|
+
return patternSourceIds(node).flatMap((sourceId) => findSource(sourceId)?.id ?? [])
|
|
100
|
+
}
|
package/src/paints/shows.ts
CHANGED
|
@@ -11,3 +11,12 @@ export function paintShows(paint: Fill): boolean {
|
|
|
11
11
|
if (paint.type === 'SOLID') return paint.color.a > 0
|
|
12
12
|
return true
|
|
13
13
|
}
|
|
14
|
+
|
|
15
|
+
/** A Figma shader paint, which OpenPencil cannot draw: Figma keeps the program outside the file. */
|
|
16
|
+
export function isFigmaShaderPaint(paint: Fill): boolean {
|
|
17
|
+
return paint.type === 'CUSTOM'
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function isDrawnPaint(paint: Fill): boolean {
|
|
21
|
+
return paint.visible && !isFigmaShaderPaint(paint)
|
|
22
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Color } from '../primitives'
|
|
2
|
+
import type { Fill } from '../types'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A color as a solid paint holds it: its channels at full alpha, and its alpha as the paint's
|
|
6
|
+
* opacity, which shapes draw at alone and text draws at times its color's alpha.
|
|
7
|
+
*/
|
|
8
|
+
export function solidPaintColor(color: Color): Pick<Fill, 'color' | 'opacity'> {
|
|
9
|
+
return { color: { ...color, a: 1 }, opacity: color.a }
|
|
10
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { sha1 } from '@noble/hashes/legacy.js'
|
|
2
|
+
import { bytesToHex, utf8ToBytes } from '@noble/hashes/utils.js'
|
|
3
|
+
|
|
4
|
+
import { randomHex } from '@open-pencil/std/random'
|
|
5
|
+
|
|
6
|
+
import { TRANSPARENT } from '../constants'
|
|
7
|
+
import { imagePaintHashes } from '../images'
|
|
8
|
+
import { readAllPluginData, withAllPluginData, type PluginDataField } from '../plugin-data/field'
|
|
9
|
+
import { OPEN_PENCIL_PLUGIN_DATA } from '../plugin-data/fields'
|
|
10
|
+
import type { Size } from '../primitives'
|
|
11
|
+
import type { Fill, SceneNode } from '../types'
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Paints OpenPencil draws itself, such as shaders and mesh gradients, kept as an image fill of
|
|
15
|
+
* their still frame, so `.fig` files, the Figma clipboard, and every format that reads images
|
|
16
|
+
* show them. What draws the frame is plugin data on the layer, one entry per paint, matched to
|
|
17
|
+
* the paint by the frame's image hash. A paint whose image is replaced, as in Figma, then draws
|
|
18
|
+
* as the image it holds.
|
|
19
|
+
*
|
|
20
|
+
* Frames are drawn and stored the same way for every renderer that draws one: the editor's
|
|
21
|
+
* canvas and the tools that prebuild documents. Figma must be able to read them, which rules out
|
|
22
|
+
* WebP.
|
|
23
|
+
*/
|
|
24
|
+
export interface StillPaint {
|
|
25
|
+
/** The hash of the paint's image: the still frame. */
|
|
26
|
+
image: string
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Every entry a node keeps under `field`, whether or not a paint still shows it. */
|
|
30
|
+
export function readStillPaints<T extends StillPaint>(
|
|
31
|
+
node: Pick<SceneNode, 'pluginData'>,
|
|
32
|
+
field: PluginDataField<T>
|
|
33
|
+
): T[] {
|
|
34
|
+
return readAllPluginData(node.pluginData, field)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The entry under `field` that `paint` of `node` shows: an image paint whose image is that
|
|
39
|
+
* entry's frame. Null for any other paint, including one whose image was replaced.
|
|
40
|
+
*/
|
|
41
|
+
export function stillPaintOf<T extends StillPaint>(
|
|
42
|
+
node: Pick<SceneNode, 'pluginData'>,
|
|
43
|
+
paint: Fill,
|
|
44
|
+
field: PluginDataField<T>
|
|
45
|
+
): T | null {
|
|
46
|
+
if (paint.type !== 'IMAGE' || !paint.imageHash) return null
|
|
47
|
+
return readStillPaints(node, field).find((entry) => entry.image === paint.imageHash) ?? null
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The node's plugin data with `field`'s entries set by their image, keeping only entries a fill
|
|
52
|
+
* or stroke of `paints` still shows, so removing or replacing a paint leaves no entry behind.
|
|
53
|
+
*/
|
|
54
|
+
export function withStillPaints<T extends StillPaint>(
|
|
55
|
+
node: Pick<SceneNode, 'pluginData'>,
|
|
56
|
+
paints: readonly Fill[],
|
|
57
|
+
field: PluginDataField<T>,
|
|
58
|
+
entries: readonly T[] = []
|
|
59
|
+
): SceneNode['pluginData'] {
|
|
60
|
+
const shown = new Set(imagePaintHashes(paints))
|
|
61
|
+
const byImage = new Map(readStillPaints(node, field).map((entry) => [entry.image, entry]))
|
|
62
|
+
for (const entry of entries) byImage.set(entry.image, entry)
|
|
63
|
+
return withAllPluginData(
|
|
64
|
+
node.pluginData,
|
|
65
|
+
field,
|
|
66
|
+
[...byImage.values()].filter((entry) => shown.has(entry.image))
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* A new image paint for a still frame not yet drawn. Its image is unique to this paint, so no
|
|
72
|
+
* other paint's entry claims it until the frame is drawn.
|
|
73
|
+
*/
|
|
74
|
+
export function createStillPaint(): { paint: Fill; image: string } {
|
|
75
|
+
const image = randomHex(20)
|
|
76
|
+
return {
|
|
77
|
+
paint: {
|
|
78
|
+
type: 'IMAGE',
|
|
79
|
+
color: TRANSPARENT,
|
|
80
|
+
opacity: 1,
|
|
81
|
+
visible: true,
|
|
82
|
+
imageHash: image,
|
|
83
|
+
imageScaleMode: 'FILL'
|
|
84
|
+
},
|
|
85
|
+
image
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** A short key that tells one drawn value from another, which a drawn frame records. */
|
|
90
|
+
export function stillContentKey(value: unknown): string {
|
|
91
|
+
return bytesToHex(sha1(utf8ToBytes(JSON.stringify(value))))
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** The layer size and content key a frame was drawn for. */
|
|
95
|
+
export interface StillFrame {
|
|
96
|
+
width: number
|
|
97
|
+
height: number
|
|
98
|
+
key: string
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Whether a frame was drawn for the content `key` names at the layer's size now, so undoing a
|
|
103
|
+
* change after reopening the document does not keep a frame of the newer content.
|
|
104
|
+
*/
|
|
105
|
+
export function isStillFrameCurrent(
|
|
106
|
+
frame: StillFrame | undefined,
|
|
107
|
+
key: string,
|
|
108
|
+
size: Size
|
|
109
|
+
): boolean {
|
|
110
|
+
return (
|
|
111
|
+
frame?.key === key &&
|
|
112
|
+
Math.round(frame.width) === Math.round(size.width) &&
|
|
113
|
+
Math.round(frame.height) === Math.round(size.height)
|
|
114
|
+
)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** Renames the image a stored entry of `field` names, or says it names none. */
|
|
118
|
+
function stillPaintRenamer<T extends StillPaint>(field: PluginDataField<T>) {
|
|
119
|
+
return {
|
|
120
|
+
key: field.key,
|
|
121
|
+
rename(value: string, rename: (image: string) => string | null): string | null {
|
|
122
|
+
const paint = field.decode(value)
|
|
123
|
+
const renamed = paint ? rename(paint.image) : null
|
|
124
|
+
return paint && renamed && renamed !== paint.image
|
|
125
|
+
? field.encode({ ...paint, image: renamed })
|
|
126
|
+
: null
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** The plugin-data fields whose entries name a paint's still frame: shaders and meshes. */
|
|
132
|
+
const STILL_PAINT_RENAMERS = [
|
|
133
|
+
stillPaintRenamer(OPEN_PENCIL_PLUGIN_DATA.shader),
|
|
134
|
+
stillPaintRenamer(OPEN_PENCIL_PLUGIN_DATA.mesh)
|
|
135
|
+
]
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* The stored value of OpenPencil plugin-data entry `key` with the still frame it names renamed by
|
|
139
|
+
* `rename`, so the paint is found under its image's new name; null when the entry names no still
|
|
140
|
+
* frame or its name stays.
|
|
141
|
+
*/
|
|
142
|
+
export function renameStillPaintImage(
|
|
143
|
+
key: string,
|
|
144
|
+
value: string,
|
|
145
|
+
rename: (image: string) => string | null
|
|
146
|
+
): string | null {
|
|
147
|
+
return STILL_PAINT_RENAMERS.find((renamer) => renamer.key === key)?.rename(value, rename) ?? null
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** Frames are drawn at twice the layer's size, for sharp high-density displays. */
|
|
151
|
+
const FRAME_SCALE = 2
|
|
152
|
+
/** The longest side a frame is drawn at, however large the layer. */
|
|
153
|
+
const MAX_FRAME_EDGE = 2048
|
|
154
|
+
/** JPEG quality for opaque frames: no visible difference from PNG at a fraction of the size. */
|
|
155
|
+
const JPEG_QUALITY = 0.9
|
|
156
|
+
|
|
157
|
+
/** The pixels a frame for a layer of `size` is drawn at. */
|
|
158
|
+
export function stillFramePixels(size: Size): Size {
|
|
159
|
+
const scale = Math.min(FRAME_SCALE, MAX_FRAME_EDGE / Math.max(size.width, size.height, 1))
|
|
160
|
+
return {
|
|
161
|
+
width: Math.max(1, Math.round(size.width * scale)),
|
|
162
|
+
height: Math.max(1, Math.round(size.height * scale))
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export interface StillFrameEncoding {
|
|
167
|
+
type: 'image/jpeg' | 'image/png'
|
|
168
|
+
/** For `canvas.toBlob` and `toDataURL`; PNG takes none. */
|
|
169
|
+
quality?: number
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* The encoding a frame with these RGBA pixels is stored in: JPEG when every pixel is opaque, which
|
|
174
|
+
* is about 25 times smaller than PNG for a shader, and PNG when any pixel lets the layer behind
|
|
175
|
+
* show through, which JPEG cannot keep.
|
|
176
|
+
*/
|
|
177
|
+
export function stillFrameEncoding(rgba: ArrayLike<number>): StillFrameEncoding {
|
|
178
|
+
for (let alpha = 3; alpha < rgba.length; alpha += 4) {
|
|
179
|
+
if (rgba[alpha] !== 255) return { type: 'image/png' }
|
|
180
|
+
}
|
|
181
|
+
return { type: 'image/jpeg', quality: JPEG_QUALITY }
|
|
182
|
+
}
|
package/src/plugin-data/field.ts
CHANGED
|
@@ -42,6 +42,8 @@ export function jsonPluginDataField<T>(
|
|
|
42
42
|
key,
|
|
43
43
|
role,
|
|
44
44
|
decode(value) {
|
|
45
|
+
// Most layers carry no entry at all; validating that absence builds an issue per read.
|
|
46
|
+
if (value == null) return undefined
|
|
45
47
|
const parsed = v.safeParse(stored, value)
|
|
46
48
|
return parsed.success ? parsed.output : undefined
|
|
47
49
|
},
|
|
@@ -60,6 +62,7 @@ export function textPluginDataField<const T extends string>(
|
|
|
60
62
|
key,
|
|
61
63
|
role,
|
|
62
64
|
decode(value) {
|
|
65
|
+
if (value == null) return undefined
|
|
63
66
|
const parsed = v.safeParse(schema, value)
|
|
64
67
|
return parsed.success ? parsed.output : undefined
|
|
65
68
|
},
|
|
@@ -2,11 +2,13 @@ import * as v from 'valibot'
|
|
|
2
2
|
|
|
3
3
|
import { behaviourSchema } from '../behaviours/schema'
|
|
4
4
|
import type { OkHCLPayload } from '../color/okhcl'
|
|
5
|
+
import { exportColorProfileSchema } from '../color/schema'
|
|
5
6
|
import { commentThreadsSchema } from '../comments/schema'
|
|
6
7
|
import { isExportFormatId, type ExportFormatId } from '../export-format'
|
|
7
8
|
import { clampExportScale } from '../export-scale'
|
|
8
9
|
import { FIG_COMPRESSIONS } from '../fig-compression'
|
|
9
10
|
import { iconSchema, iconTintSchema } from '../icons/schema'
|
|
11
|
+
import { meshPaintSchema } from '../mesh/schema'
|
|
10
12
|
import type { Rect } from '../primitives'
|
|
11
13
|
import { shaderPaintSchema } from '../shaders/schema'
|
|
12
14
|
import { nodeStatusSchema, statusWorkflowSchema } from '../statuses/schema'
|
|
@@ -70,7 +72,7 @@ const exportSettingsSchema: v.GenericSchema<unknown, ExportSetting[]> = v.array(
|
|
|
70
72
|
),
|
|
71
73
|
contentsOnly: v.optional(v.boolean()),
|
|
72
74
|
useAbsoluteBounds: v.optional(v.boolean()),
|
|
73
|
-
colorProfile: v.optional(
|
|
75
|
+
colorProfile: v.optional(exportColorProfileSchema),
|
|
74
76
|
svgOutlineText: v.optional(v.boolean()),
|
|
75
77
|
svgIdAttribute: v.optional(v.boolean()),
|
|
76
78
|
svgSimplifyStroke: v.optional(v.boolean())
|
|
@@ -194,6 +196,15 @@ export const OPEN_PENCIL_PLUGIN_DATA = {
|
|
|
194
196
|
'bookkeeping',
|
|
195
197
|
sourceLibraryPublicationSchema
|
|
196
198
|
),
|
|
199
|
+
/**
|
|
200
|
+
* The layer chosen as the document's thumbnail, on the DOCUMENT node. Figma keeps its own
|
|
201
|
+
* choice outside the file, so a `.fig` carries only this one.
|
|
202
|
+
*/
|
|
203
|
+
thumbnail: jsonPluginDataField(
|
|
204
|
+
'thumbnail',
|
|
205
|
+
'bookkeeping',
|
|
206
|
+
v.pipe(v.string(), v.nonEmpty(), v.maxLength(64))
|
|
207
|
+
),
|
|
197
208
|
/** Canvas comment threads, deleted ones included, on the DOCUMENT node. */
|
|
198
209
|
comments: jsonPluginDataField('comments', 'bookkeeping', commentThreadsSchema),
|
|
199
210
|
/** The statuses layers can be in, on the DOCUMENT node. */
|
|
@@ -227,7 +238,9 @@ export const OPEN_PENCIL_PLUGIN_DATA = {
|
|
|
227
238
|
/** Which of an icon path's paints its icon's color sets, on each path the source drew in it. */
|
|
228
239
|
iconTint: jsonPluginDataField('iconTint', 'content', iconTintSchema),
|
|
229
240
|
/** One entry per paint that draws a shader, matched to its image paint by the frame's hash. */
|
|
230
|
-
shader: jsonPluginDataField('shader', 'content', shaderPaintSchema)
|
|
241
|
+
shader: jsonPluginDataField('shader', 'content', shaderPaintSchema),
|
|
242
|
+
/** One entry per paint that draws a mesh gradient, matched to its image paint by the frame's hash. */
|
|
243
|
+
mesh: jsonPluginDataField('mesh', 'content', meshPaintSchema)
|
|
231
244
|
} satisfies Record<string, PluginDataKey>
|
|
232
245
|
|
|
233
246
|
const NOT_CONTENT = Object.values(OPEN_PENCIL_PLUGIN_DATA).filter(
|
package/src/resize.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { pick } from 'es-toolkit/object'
|
|
2
|
+
|
|
1
3
|
import { CONSTRAINT_PARENT_TYPES } from './constraints'
|
|
2
4
|
import { getNodeLocalMatrix } from './coordinate'
|
|
3
5
|
import {
|
|
@@ -22,24 +24,24 @@ import type { ConstraintType, DerivedTextGlyph, SceneNode, Stroke, VectorNetwork
|
|
|
22
24
|
* geometry that must scale with the node, and textPathBox is the layout box the
|
|
23
25
|
* glyphs were reflowed against.
|
|
24
26
|
*/
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
27
|
+
const RESIZE_SNAPSHOT_FIELDS = [
|
|
28
|
+
'type',
|
|
29
|
+
'x',
|
|
30
|
+
'y',
|
|
31
|
+
'width',
|
|
32
|
+
'height',
|
|
33
|
+
'flipX',
|
|
34
|
+
'flipY',
|
|
35
|
+
'vectorNetwork',
|
|
36
|
+
'fillGeometry',
|
|
37
|
+
'strokeGeometry',
|
|
38
|
+
'derivedTextGlyphs',
|
|
39
|
+
'strokes',
|
|
40
|
+
'textPathData',
|
|
41
|
+
'textPathBox'
|
|
42
|
+
] as const satisfies readonly (keyof SceneNode)[]
|
|
43
|
+
|
|
44
|
+
export type ResizeSnapshot = Pick<SceneNode, (typeof RESIZE_SNAPSHOT_FIELDS)[number]>
|
|
43
45
|
interface ResizeGraph {
|
|
44
46
|
readonly rootId: string
|
|
45
47
|
getNode(id: string): SceneNode | undefined
|
|
@@ -361,9 +363,19 @@ function constrainedGeometryChanges(
|
|
|
361
363
|
return scalesGeometry(orig, current) ? snapshotGeometry(orig) : {}
|
|
362
364
|
}
|
|
363
365
|
|
|
366
|
+
/**
|
|
367
|
+
* A node's resize state holding its own geometry rather than copies of it. It stays the state the
|
|
368
|
+
* resize began from only while nothing edits that geometry in place, as a resize plan does not:
|
|
369
|
+
* it writes new paths and outlines.
|
|
370
|
+
*/
|
|
371
|
+
export function sharedResizeSnapshot(node: SceneNode): ResizeSnapshot {
|
|
372
|
+
return pick(node, RESIZE_SNAPSHOT_FIELDS)
|
|
373
|
+
}
|
|
374
|
+
|
|
364
375
|
export function collectResizeDescendants(
|
|
365
376
|
graph: ResizeGraph,
|
|
366
|
-
rootId: string
|
|
377
|
+
rootId: string,
|
|
378
|
+
snapshot: (node: SceneNode) => ResizeSnapshot = createResizeSnapshot
|
|
367
379
|
): Map<string, ResizeSnapshot> | null {
|
|
368
380
|
const root = graph.getNode(rootId)
|
|
369
381
|
if (!root || !CONSTRAINT_CONTAINER_TYPES.has(root.type)) return null
|
|
@@ -375,7 +387,7 @@ export function collectResizeDescendants(
|
|
|
375
387
|
for (const childId of parent.childIds) {
|
|
376
388
|
const child = graph.getNode(childId)
|
|
377
389
|
if (!child) continue
|
|
378
|
-
snapshots.set(childId,
|
|
390
|
+
snapshots.set(childId, snapshot(child))
|
|
379
391
|
collect(childId)
|
|
380
392
|
}
|
|
381
393
|
}
|
package/src/scaling/index.ts
CHANGED
package/src/scaling/node.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { pick } from 'es-toolkit/object'
|
|
2
|
+
|
|
1
3
|
import { cloneVectorNetwork, copyDerivedGlyphs, scaleGeometryPaths } from '../copy'
|
|
2
4
|
import { scaledTextLength } from '../text/lengths'
|
|
3
5
|
import { TEXT_PARAGRAPH_SPACING_FIELDS } from '../text/paragraphs'
|
|
@@ -10,6 +12,7 @@ import {
|
|
|
10
12
|
type SceneNode,
|
|
11
13
|
type Stroke,
|
|
12
14
|
type StyleRun,
|
|
15
|
+
type TextLength,
|
|
13
16
|
type TextParagraphStyle
|
|
14
17
|
} from '../types'
|
|
15
18
|
|
|
@@ -56,6 +59,45 @@ function scaledFills(fills: readonly Fill[], scale: number): Fill[] {
|
|
|
56
59
|
}))
|
|
57
60
|
}
|
|
58
61
|
|
|
62
|
+
const TEXT_STYLE_LENGTH_FIELDS = [
|
|
63
|
+
'fontSize',
|
|
64
|
+
'lineHeight',
|
|
65
|
+
'letterSpacing',
|
|
66
|
+
'paragraphSpacing',
|
|
67
|
+
'paragraphIndent',
|
|
68
|
+
'listSpacing'
|
|
69
|
+
] as const satisfies readonly (keyof SceneNode)[]
|
|
70
|
+
|
|
71
|
+
const TEXT_STYLE_LENGTHS: ReadonlySet<string> = new Set(TEXT_STYLE_LENGTH_FIELDS)
|
|
72
|
+
|
|
73
|
+
export function isTextStyleLength(field: string): boolean {
|
|
74
|
+
return TEXT_STYLE_LENGTHS.has(field)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function isTextLength(value: unknown): value is TextLength {
|
|
78
|
+
return typeof value === 'object' && value !== null && 'unit' in value && 'value' in value
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function lengthAtScale(value: unknown, scale: number): unknown {
|
|
82
|
+
if (typeof value === 'number') {
|
|
83
|
+
return value * scale
|
|
84
|
+
}
|
|
85
|
+
return isTextLength(value) ? scaledTextLength(value, scale) : value
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function scaledTextStyleLengths<Values extends object>(
|
|
89
|
+
values: Values,
|
|
90
|
+
scale: number
|
|
91
|
+
): Values {
|
|
92
|
+
const scaled = { ...values }
|
|
93
|
+
for (const [field, value] of Object.entries(values)) {
|
|
94
|
+
if (isTextStyleLength(field)) {
|
|
95
|
+
Object.assign(scaled, { [field]: lengthAtScale(value, scale) })
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return scaled
|
|
99
|
+
}
|
|
100
|
+
|
|
59
101
|
function scaledStyleRuns(styleRuns: readonly StyleRun[], scale: number): StyleRun[] {
|
|
60
102
|
return styleRuns.map((run) => ({
|
|
61
103
|
...structuredClone(run),
|
|
@@ -162,15 +204,10 @@ export function scaleNodeChanges(
|
|
|
162
204
|
topRightRadius: node.topRightRadius * scale,
|
|
163
205
|
bottomRightRadius: node.bottomRightRadius * scale,
|
|
164
206
|
bottomLeftRadius: node.bottomLeftRadius * scale,
|
|
165
|
-
|
|
166
|
-
letterSpacing: scaledTextLength(node.letterSpacing, scale),
|
|
167
|
-
lineHeight: node.lineHeight && scaledTextLength(node.lineHeight, scale),
|
|
207
|
+
...scaledTextStyleLengths(pick(node, TEXT_STYLE_LENGTH_FIELDS), scale),
|
|
168
208
|
textDecorationThickness: scaledOptional(node.textDecorationThickness, scale),
|
|
169
209
|
textUnderlineOffset: scaledOptional(node.textUnderlineOffset, scale),
|
|
170
210
|
styleRuns: scaledStyleRuns(node.styleRuns, scale),
|
|
171
|
-
listSpacing: node.listSpacing * scale,
|
|
172
|
-
paragraphSpacing: node.paragraphSpacing * scale,
|
|
173
|
-
paragraphIndent: node.paragraphIndent * scale,
|
|
174
211
|
textParagraphs: scaledParagraphStyles(node.textParagraphs, scale),
|
|
175
212
|
derivedTextHeight: scaledOptional(node.derivedTextHeight, scale),
|
|
176
213
|
itemSpacing: node.itemSpacing * scale,
|
package/src/shaders/index.ts
CHANGED