@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
package/src/instances/index.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
|
+
import { omitBy } from 'es-toolkit/object'
|
|
2
|
+
import { isEmptyObject } from 'es-toolkit/predicate'
|
|
3
|
+
|
|
1
4
|
import type { NodeCloneMode } from '../copy'
|
|
2
5
|
import type { SceneGraph } from '../graph'
|
|
6
|
+
import {
|
|
7
|
+
collectResizeDescendants,
|
|
8
|
+
computeConstrainedResizeChanges,
|
|
9
|
+
sharedResizeSnapshot
|
|
10
|
+
} from '../resize'
|
|
3
11
|
import {
|
|
4
12
|
detachOwnedSlotContent,
|
|
5
13
|
restoreOwnedSlotContent,
|
|
@@ -34,7 +42,8 @@ import {
|
|
|
34
42
|
copyProp,
|
|
35
43
|
sourceInTargetCoordinates,
|
|
36
44
|
syncChildren,
|
|
37
|
-
updateSyncedProps
|
|
45
|
+
updateSyncedProps,
|
|
46
|
+
withSyncedStyleBindings
|
|
38
47
|
} from './sync'
|
|
39
48
|
|
|
40
49
|
export { canCreateInstance, createsComponentCycle, cycleSafeParent } from './cycles'
|
|
@@ -72,12 +81,60 @@ export function createInstance(
|
|
|
72
81
|
const instance = graph.createNode('INSTANCE', parentId, { ...props, ...overrides, componentId })
|
|
73
82
|
|
|
74
83
|
cloneChildrenWithMapping(graph, component.id, instance.id)
|
|
84
|
+
// The copies arrive at the component's size; an instance created at another one places them by
|
|
85
|
+
// their constraints, as resizing it afterwards does.
|
|
86
|
+
placeCopiedChildrenForSize(graph, component, instance)
|
|
75
87
|
// A copy shows its bound paints in its own context, not as its component's paints hold them.
|
|
76
88
|
applyBoundPaintColorsIn(graph, instance.id)
|
|
77
89
|
|
|
78
90
|
return instance
|
|
79
91
|
}
|
|
80
92
|
|
|
93
|
+
/**
|
|
94
|
+
* Places a new instance's copies as its own size asks, from the size the component gave them.
|
|
95
|
+
* Cloning writes them at the component's size, in the instance's coordinates, so an instance
|
|
96
|
+
* created straight at another size would otherwise keep every layer at the component's size and
|
|
97
|
+
* place, while resizing it to the same size scales them; Figma scales a copy's `scale` layers
|
|
98
|
+
* however it reaches that size.
|
|
99
|
+
*/
|
|
100
|
+
function placeCopiedChildrenForSize(
|
|
101
|
+
graph: SceneGraph,
|
|
102
|
+
component: SceneNode,
|
|
103
|
+
instance: SceneNode
|
|
104
|
+
): void {
|
|
105
|
+
if (instance.childIds.length === 0) return
|
|
106
|
+
// The component's size in the copies' coordinates, which a scaled instance holds apart.
|
|
107
|
+
const from = sourceInTargetCoordinates(component, instance.componentScale)
|
|
108
|
+
if (from.width === instance.width && from.height === instance.height) return
|
|
109
|
+
// The copies are new and every pass writes new geometry, so the snapshots need no copies of it.
|
|
110
|
+
const originals = collectResizeDescendants(graph, instance.id, sharedResizeSnapshot)
|
|
111
|
+
if (!originals) return
|
|
112
|
+
// An auto layout frame places its own constrained layers for the size it has, which a pass
|
|
113
|
+
// only gives it as it writes; each pass starts from the snapshots, so the placement repeats
|
|
114
|
+
// until no such frame changes size, one level deeper each time.
|
|
115
|
+
for (let pass = 0; pass <= originals.size; pass++) {
|
|
116
|
+
const changes = computeConstrainedResizeChanges(graph, instance.id, from, instance, originals)
|
|
117
|
+
const resizesLayout = [...changes].some(([id, change]) => resizesLayoutFrame(graph, id, change))
|
|
118
|
+
for (const [id, change] of changes) writeChanged(graph, id, change)
|
|
119
|
+
if (!resizesLayout) return
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Writes only what differs: the plan places every layer, most of them where they already are. */
|
|
124
|
+
function writeChanged(graph: SceneGraph, id: string, change: Partial<SceneNode>): void {
|
|
125
|
+
const node = graph.nodes.get(id)
|
|
126
|
+
if (!node) return
|
|
127
|
+
const changed = omitBy(change, (value, key) => node[key] === value)
|
|
128
|
+
if (!isEmptyObject(changed)) graph.updateNode(id, changed)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function resizesLayoutFrame(graph: SceneGraph, id: string, change: Partial<SceneNode>): boolean {
|
|
132
|
+
const node = graph.nodes.get(id)
|
|
133
|
+
if (!node || node.layoutMode === 'NONE') return false
|
|
134
|
+
const { width = node.width, height = node.height } = change
|
|
135
|
+
return width !== node.width || height !== node.height
|
|
136
|
+
}
|
|
137
|
+
|
|
81
138
|
export function populateInstanceChildren(
|
|
82
139
|
graph: SceneGraph,
|
|
83
140
|
instanceId: string,
|
|
@@ -234,17 +291,19 @@ function syncInstancesOf(
|
|
|
234
291
|
if (syncing.has(componentId)) return
|
|
235
292
|
syncing.add(componentId)
|
|
236
293
|
try {
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
const
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
294
|
+
withSyncedStyleBindings(graph, () => {
|
|
295
|
+
groupCopyRemovals(graph, (removals) => {
|
|
296
|
+
for (const instance of instances) {
|
|
297
|
+
const source = sourceInTargetCoordinates(component, instance.componentScale)
|
|
298
|
+
const { updates, kept } = ownSyncedProps(graph, instance, source)
|
|
299
|
+
// An instance that hugs its layers sizes to what it shows, not to the component.
|
|
300
|
+
keepOwnContentSize(graph, updates, instance, source)
|
|
301
|
+
updateSyncedProps(graph, instance, updates, kept)
|
|
302
|
+
const context = createInstanceSyncContext(instance.id, instance.instanceOverrides)
|
|
303
|
+
syncChildren(graph, component.id, instance.id, instance.instanceOverrides, context)
|
|
304
|
+
removeLeftoverCopies(graph, context, removals)
|
|
305
|
+
}
|
|
306
|
+
})
|
|
248
307
|
})
|
|
249
308
|
} finally {
|
|
250
309
|
syncing.delete(componentId)
|
package/src/instances/sync.ts
CHANGED
|
@@ -16,13 +16,22 @@ import {
|
|
|
16
16
|
withStrokeLines
|
|
17
17
|
} from '../strokes'
|
|
18
18
|
import type { SceneNode } from '../types'
|
|
19
|
-
import {
|
|
20
|
-
|
|
19
|
+
import {
|
|
20
|
+
resolvedNumericBindings,
|
|
21
|
+
resolvedRunBindings,
|
|
22
|
+
resolvesToNumber,
|
|
23
|
+
resolvedValueBindings
|
|
24
|
+
} from '../variables/bindings'
|
|
21
25
|
import {
|
|
22
26
|
applyBoundPaintColorsIn,
|
|
23
27
|
copyAppliedBoundPaints,
|
|
24
28
|
keepCopyBoundPaints
|
|
25
29
|
} from '../variables/paints'
|
|
30
|
+
import {
|
|
31
|
+
createStyleBindingLookup,
|
|
32
|
+
effectiveBoundVariables,
|
|
33
|
+
type TextStyleLookup
|
|
34
|
+
} from '../variables/style-bindings'
|
|
26
35
|
import { scaleVariableBindingUnits } from '../variables/units'
|
|
27
36
|
import { applyEnclosingAssignments, assignedFieldValues, propertyDrivenFields } from './assignments'
|
|
28
37
|
import { keepOwnContentSize, remeasureChangedText, type SyncedPlacement } from './content-size'
|
|
@@ -157,6 +166,7 @@ export function updateSyncedProps(
|
|
|
157
166
|
kept: (field: string) => boolean = () => false
|
|
158
167
|
): void {
|
|
159
168
|
resolveBoundNumbersInPlace(graph, target, updates, kept)
|
|
169
|
+
resolveBoundValuesInPlace(graph, target, updates, kept)
|
|
160
170
|
if (updates.fills || updates.strokes || updates.boundVariables) {
|
|
161
171
|
applySyncedModes(graph, target, updates)
|
|
162
172
|
keepCopyBoundPaints(graph, target, updates)
|
|
@@ -225,21 +235,93 @@ function resolveBoundNumbersInPlace(
|
|
|
225
235
|
updates: Partial<SceneNode>,
|
|
226
236
|
kept: (field: string) => boolean
|
|
227
237
|
): void {
|
|
228
|
-
const
|
|
229
|
-
// The fields the sync writes, and the ones it
|
|
230
|
-
// the component's mode.
|
|
231
|
-
const rebound = updates.boundVariables
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
const
|
|
235
|
-
|
|
238
|
+
const own = updates.boundVariables ?? target.boundVariables
|
|
239
|
+
// The fields the sync writes, and the ones whose binding it changes, which keep an equal value
|
|
240
|
+
// only in the component's mode.
|
|
241
|
+
const rebound = updates.boundVariables ? changedBindings(target.boundVariables, own) : []
|
|
242
|
+
const styles = styleBindingsOf(graph)
|
|
243
|
+
const textStyleId = updates.textStyleId === undefined ? target.textStyleId : updates.textStyleId
|
|
244
|
+
const bound = effectiveBoundVariables(
|
|
245
|
+
{ type: target.type, textStyleId, boundVariables: own },
|
|
246
|
+
styles
|
|
236
247
|
)
|
|
248
|
+
const restyled = textStyleId !== target.textStyleId ? Object.keys(bound) : []
|
|
249
|
+
const synced = uniq([...Object.keys(updates), ...rebound, ...restyled]).filter(
|
|
250
|
+
(field) => resolvesToNumber(field) && bound[field] && !kept(field)
|
|
251
|
+
)
|
|
252
|
+
resolveSyncedRunsInPlace(graph, target, updates, styles)
|
|
237
253
|
if (synced.length === 0) return
|
|
238
254
|
applySyncedModes(graph, target, updates)
|
|
239
|
-
const resolved = resolvedNumericBindings(graph, { ...target, ...updates })
|
|
255
|
+
const resolved = resolvedNumericBindings(graph, { ...target, ...updates }, styles)
|
|
240
256
|
Object.assign(updates, pick(resolved, synced as (keyof SceneNode)[]))
|
|
241
257
|
}
|
|
242
258
|
|
|
259
|
+
/**
|
|
260
|
+
* Bound text and visibility the sync writes, or whose binding it changes, take the value they
|
|
261
|
+
* resolve to where the copy sits, as bound numbers do, rather than the one the component holds
|
|
262
|
+
* in its own mode.
|
|
263
|
+
*/
|
|
264
|
+
function resolveBoundValuesInPlace(
|
|
265
|
+
graph: SceneGraph,
|
|
266
|
+
target: SceneNode,
|
|
267
|
+
updates: Partial<SceneNode>,
|
|
268
|
+
kept: (field: string) => boolean
|
|
269
|
+
): void {
|
|
270
|
+
const bound = updates.boundVariables ?? target.boundVariables
|
|
271
|
+
const rebound = updates.boundVariables ? changedBindings(target.boundVariables, bound) : []
|
|
272
|
+
const synced = (['text', 'visible'] as const).filter(
|
|
273
|
+
(field) =>
|
|
274
|
+
(updates[field] !== undefined || rebound.includes(field)) && bound[field] && !kept(field)
|
|
275
|
+
)
|
|
276
|
+
if (synced.length === 0) return
|
|
277
|
+
applySyncedModes(graph, target, updates)
|
|
278
|
+
const resolved = resolvedValueBindings(graph, { ...target, ...updates })
|
|
279
|
+
Object.assign(updates, pick(resolved, synced))
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function changedBindings(before: Record<string, string>, after: Record<string, string>): string[] {
|
|
283
|
+
return uniq([...Object.keys(before), ...Object.keys(after)]).filter(
|
|
284
|
+
(field) => before[field] !== after[field]
|
|
285
|
+
)
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function resolveSyncedRunsInPlace(
|
|
289
|
+
graph: SceneGraph,
|
|
290
|
+
target: SceneNode,
|
|
291
|
+
updates: Partial<SceneNode>,
|
|
292
|
+
styles: TextStyleLookup
|
|
293
|
+
): void {
|
|
294
|
+
if (!updates.styleRuns) {
|
|
295
|
+
return
|
|
296
|
+
}
|
|
297
|
+
applySyncedModes(graph, target, updates)
|
|
298
|
+
const copy = {
|
|
299
|
+
id: target.id,
|
|
300
|
+
styleRuns: updates.styleRuns,
|
|
301
|
+
componentScale: updates.componentScale ?? target.componentScale
|
|
302
|
+
}
|
|
303
|
+
Object.assign(updates, resolvedRunBindings(graph, copy, styles))
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
const styleBindingsDuringSync = new WeakMap<SceneGraph, TextStyleLookup>()
|
|
307
|
+
|
|
308
|
+
export function withSyncedStyleBindings(graph: SceneGraph, sync: () => void): void {
|
|
309
|
+
if (styleBindingsDuringSync.has(graph)) {
|
|
310
|
+
sync()
|
|
311
|
+
return
|
|
312
|
+
}
|
|
313
|
+
styleBindingsDuringSync.set(graph, createStyleBindingLookup(graph))
|
|
314
|
+
try {
|
|
315
|
+
sync()
|
|
316
|
+
} finally {
|
|
317
|
+
styleBindingsDuringSync.delete(graph)
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
function styleBindingsOf(graph: SceneGraph): TextStyleLookup {
|
|
322
|
+
return styleBindingsDuringSync.get(graph) ?? createStyleBindingLookup(graph)
|
|
323
|
+
}
|
|
324
|
+
|
|
243
325
|
/** The modes the copy takes in this sync decide what its bindings resolve to. */
|
|
244
326
|
function applySyncedModes(graph: SceneGraph, target: SceneNode, updates: Partial<SceneNode>): void {
|
|
245
327
|
if (updates.variableModes && !isEqual(updates.variableModes, target.variableModes))
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { geometryBlobBounds } from '../geometry'
|
|
2
|
+
import type { SceneGraph } from '../graph'
|
|
3
|
+
import type { SceneNode } from '../types'
|
|
4
|
+
|
|
5
|
+
function hasFiniteSavedFill(node: SceneNode): boolean {
|
|
6
|
+
const box = geometryBlobBounds(node.fillGeometry)
|
|
7
|
+
return box !== null && [box.x, box.y, box.width, box.height].every(Number.isFinite)
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Whether `node` is a boolean with no operands and so no box: Figma keeps one whose operands are
|
|
12
|
+
* all removed as a layer of no size, and neither a group's box nor an auto layout flow counts it.
|
|
13
|
+
* One read from a file with a finite saved fill and a size to match still has its box.
|
|
14
|
+
*/
|
|
15
|
+
export function isEmptyBoolean(node: SceneNode): boolean {
|
|
16
|
+
return (
|
|
17
|
+
node.type === 'BOOLEAN_OPERATION' &&
|
|
18
|
+
node.childIds.length === 0 &&
|
|
19
|
+
!((node.width > 0 || node.height > 0) && hasFiniteSavedFill(node))
|
|
20
|
+
)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Whether auto layout places `child` in its flow: shown, not placed absolutely, and not an empty boolean. */
|
|
24
|
+
export function inLayoutFlow(child: SceneNode): boolean {
|
|
25
|
+
return child.visible && child.layoutPositioning !== 'ABSOLUTE' && !isEmptyBoolean(child)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** The children an auto layout frame places in its flow, in order. */
|
|
29
|
+
export function flowChildren(graph: SceneGraph, frame: SceneNode): SceneNode[] {
|
|
30
|
+
return frame.childIds.flatMap((id) => {
|
|
31
|
+
const child = graph.getNode(id)
|
|
32
|
+
return child && inLayoutFlow(child) ? [child] : []
|
|
33
|
+
})
|
|
34
|
+
}
|
package/src/layout/index.ts
CHANGED
package/src/layout/keywords.ts
CHANGED
|
@@ -16,12 +16,18 @@ const DIRECTIONS = new Map<string, AutoLayoutDirection>([
|
|
|
16
16
|
['vertical', 'VERTICAL']
|
|
17
17
|
])
|
|
18
18
|
|
|
19
|
+
/**
|
|
20
|
+
* `flow-start` and `flow-end` are what `flex-start` and `flex-end` compute to, as CSS Box
|
|
21
|
+
* Alignment now defines them and the HTML engine reports them.
|
|
22
|
+
*/
|
|
19
23
|
const POSITIONS = new Map<string, 'MIN' | 'CENTER' | 'MAX'>([
|
|
20
24
|
['start', 'MIN'],
|
|
21
25
|
['flex-start', 'MIN'],
|
|
26
|
+
['flow-start', 'MIN'],
|
|
22
27
|
['center', 'CENTER'],
|
|
23
28
|
['end', 'MAX'],
|
|
24
|
-
['flex-end', 'MAX']
|
|
29
|
+
['flex-end', 'MAX'],
|
|
30
|
+
['flow-end', 'MAX']
|
|
25
31
|
])
|
|
26
32
|
|
|
27
33
|
function keyword(value: string | undefined): string | undefined {
|
package/src/layout/sizing.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { SceneGraph } from '../graph'
|
|
2
2
|
import type { LayoutSizing, SceneNode, TextAutoResize } from '../types'
|
|
3
|
+
import { flowChildren } from './flow'
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* How a node sizes along one screen axis, as Figma's `layoutSizingHorizontal` and
|
|
@@ -192,3 +193,32 @@ export function autoLayoutSizingFields(
|
|
|
192
193
|
counterAxisSizing: horizontal ? height : width
|
|
193
194
|
}
|
|
194
195
|
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* The axes a frame hugs but keeps its size on, as Figma keeps them. With nothing in its flow,
|
|
199
|
+
* no visible layer that is not placed absolutely, it keeps every axis it hugs: a new frame keeps
|
|
200
|
+
* the size it was made at, and one that loses its last layer keeps the size it hugged to. On the
|
|
201
|
+
* counter axis it also keeps its size when every child in its flow fills that axis and none has
|
|
202
|
+
* content of its own to hug.
|
|
203
|
+
*/
|
|
204
|
+
export function heldHugAxes(graph: SceneGraph, frame: SceneNode): ('width' | 'height')[] {
|
|
205
|
+
if (frame.layoutMode !== 'HORIZONTAL' && frame.layoutMode !== 'VERTICAL') return []
|
|
206
|
+
const [primary, counter] =
|
|
207
|
+
frame.layoutMode === 'HORIZONTAL'
|
|
208
|
+
? (['width', 'height'] as const)
|
|
209
|
+
: (['height', 'width'] as const)
|
|
210
|
+
const hugged = [
|
|
211
|
+
...(frame.primaryAxisSizing === 'HUG' ? [primary] : []),
|
|
212
|
+
...(frame.counterAxisSizing === 'HUG' ? [counter] : [])
|
|
213
|
+
]
|
|
214
|
+
const flow = flowChildren(graph, frame)
|
|
215
|
+
if (flow.length === 0) return hugged
|
|
216
|
+
const filled = flow.every(
|
|
217
|
+
(child) =>
|
|
218
|
+
child.layoutMode === 'NONE' &&
|
|
219
|
+
child.type !== 'TEXT' &&
|
|
220
|
+
(child.layoutAlignSelf === 'STRETCH' ||
|
|
221
|
+
(child.layoutAlignSelf === 'AUTO' && frame.counterAxisAlign === 'STRETCH'))
|
|
222
|
+
)
|
|
223
|
+
return filled && frame.counterAxisSizing === 'HUG' ? [counter] : []
|
|
224
|
+
}
|
package/src/layout/spacing.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isGeneratedFrame } from '../generated'
|
|
1
2
|
import type { SceneNode } from '../types'
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -9,3 +10,14 @@ export function counterAxisSpacingOf(
|
|
|
9
10
|
): number {
|
|
10
11
|
return node.counterAxisSpacing ?? node.itemSpacing
|
|
11
12
|
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The space an auto layout keeps between its items along its axis. Space between takes the place
|
|
16
|
+
* of the gap, as in Figma. A generated frame keeps it as the least space between its sublayers,
|
|
17
|
+
* as a sticky note keeps its author clear of a long body.
|
|
18
|
+
*/
|
|
19
|
+
export function primaryAxisSpacingOf(
|
|
20
|
+
node: Pick<SceneNode, 'type' | 'primaryAxisAlign' | 'itemSpacing'>
|
|
21
|
+
): number {
|
|
22
|
+
return node.primaryAxisAlign === 'SPACE_BETWEEN' && !isGeneratedFrame(node) ? 0 : node.itemSpacing
|
|
23
|
+
}
|