@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/dist/group-bounds.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"group-bounds.js","names":[],"sources":["../src/group-bounds.ts"],"sourcesContent":["import { getAxisAlignedBoundsInParent, getNodeLocalMatrix } from './coordinate'\nimport type { SceneGraph } from './graph'\nimport { isVisibleMask, maskRuns } from './masks'\nimport Matrix from './matrix'\nimport { FITTED_CONTAINER_TYPES } from './node-defaults'\nimport type { Rect, Vector } from './primitives'\nimport type { SceneNode } from './types'\n\n/**\n * What fitting a group reads: its layers and their parents, as the graph has them or as a resize\n * plans them before writing.\n */\nexport type GroupFitGraph = Pick<SceneGraph, 'getNode' | 'rootId'>\n\n/** Where a layer sits, with a connector's ends, since a free end is in the parent's axes too. */\ntype Placement = Pick<SceneNode, 'x' | 'y' | 'width' | 'height'> &\n Partial<Pick<SceneNode, 'connectorStart' | 'connectorEnd'>>\n\n/** What `fitEnclosingGroups` changed, so a caller can undo and redo it. */\nexport interface GroupFit {\n before: Map<string, Placement>\n after: Map<string, Placement>\n /** Emptied groups, outermost last, with their index in their parent. */\n removed: Array<{ node: SceneNode; index: number }>\n}\n\nexport interface GroupFitOptions {\n /**\n * The box of a boolean operation's result in its parent's space, which Figma sizes a boolean to,\n * or null to fit its operands. Measuring needs path operations, so the renderer supplies it.\n */\n booleanBounds?: (node: SceneNode) => Rect | null\n}\n\nfunction placement(node: SceneNode): Placement {\n const box = { x: node.x, y: node.y, width: node.width, height: node.height }\n if (node.type !== 'CONNECTOR') return box\n return {\n ...box,\n connectorStart: structuredClone(node.connectorStart),\n connectorEnd: structuredClone(node.connectorEnd)\n }\n}\n\n/** A connector end moved by `dx`, `dy` when it is free, as its point is in the parent's axes. */\nfunction shiftedEnd(\n end: SceneNode['connectorStart'],\n dx: number,\n dy: number\n): SceneNode['connectorStart'] {\n if (end?.nodeId !== null) return end\n return { ...end, position: { x: end.position.x - dx, y: end.position.y - dy } }\n}\n\n/** Groups and booleans holding the parents, innermost first. */\nfunction fittedAncestors(graph: SceneGraph, parentIds: Iterable<string>): SceneNode[] {\n const found = new Map<string, { node: SceneNode; depth: number }>()\n for (const parentId of parentIds) {\n const chain: SceneNode[] = []\n for (let node = graph.getNode(parentId); node && FITTED_CONTAINER_TYPES.has(node.type);) {\n chain.push(node)\n node = node.parentId ? graph.getNode(node.parentId) : undefined\n }\n for (const [index, node] of chain.entries()) {\n found.set(node.id, {\n node,\n depth: Math.max(found.get(node.id)?.depth ?? 0, chain.length - index)\n })\n }\n }\n return [...found.values()].sort((a, b) => b.depth - a.depth).map(({ node }) => node)\n}\n\n/**\n * The layers a group's box covers, bottom to top. Hidden layers do not count, as in Figma. A mask\n * hides the layers above it outside its shape, so they count only through the mask: the box is\n * the layers below it and the masks.\n */\nfunction groupBoundingLayers(children: readonly SceneNode[]): SceneNode[] {\n const shown = children.filter((child) => child.visible)\n const runs = maskRuns(shown, isVisibleMask)\n if (runs.length === 0) return shown\n return [\n ...shown.slice(0, runs[0].start),\n ...runs.flatMap((run) => shown.slice(run.start, run.maskedStart))\n ]\n}\n\n/**\n * A group's box in its parent's space: around the layers it shows, or, with every layer hidden,\n * empty at `origin`, where Figma leaves it.\n */\nexport function groupBounds(\n graph: GroupFitGraph,\n children: readonly SceneNode[],\n parentId: string,\n origin: Vector\n): Rect {\n const layers = groupBoundingLayers(children)\n return layers.length > 0\n ? getAxisAlignedBoundsInParent(layers, parentId, graph)\n : { x: origin.x, y: origin.y, width: 0, height: 0 }\n}\n\n/** A child moved back by the group's shift, a connector's free ends with it. */\nfunction shiftedBack(child: SceneNode, dx: number, dy: number): Partial<SceneNode> {\n const moved = { x: child.x - dx, y: child.y - dy }\n if (child.type !== 'CONNECTOR') return moved\n return {\n ...moved,\n connectorStart: shiftedEnd(child.connectorStart, dx, dy),\n connectorEnd: shiftedEnd(child.connectorEnd, dx, dy)\n }\n}\n\nfunction isTransformed(node: SceneNode): boolean {\n return node.rotation !== 0 || node.flipX || node.flipY\n}\n\n/**\n * The group's new box in its parent's space and how far its children shift in its own frame, so\n * that the group holds its children while they stay put on the canvas. An unrotated group takes\n * their bounds in its parent's space. A rotated or flipped group keeps its angle: it takes their\n * bounds in its own frame, and its position is solved so its frame still maps every child to the\n * same canvas point, as its rotation and flips are unchanged. A rotated or flipped boolean, whose\n * box comes from its result's path, keeps its bounds.\n */\nfunction fittedBox(\n graph: GroupFitGraph,\n group: SceneNode,\n parentId: string,\n children: SceneNode[],\n options: GroupFitOptions\n): { box: Rect; shift: Vector } | null {\n if (!isTransformed(group)) {\n const box =\n (group.type === 'BOOLEAN_OPERATION' ? options.booleanBounds?.(group) : null) ??\n groupBounds(graph, children, parentId, group)\n return { box, shift: { x: box.x - group.x, y: box.y - group.y } }\n }\n if (group.type === 'BOOLEAN_OPERATION') return null\n const local = groupBounds(graph, children, group.id, { x: 0, y: 0 })\n const [px, py] = Matrix.mapPoints(getNodeLocalMatrix(group), [local.x, local.y])\n const sized = { ...group, width: local.width, height: local.height }\n const [qx, qy] = Matrix.mapPoints(getNodeLocalMatrix(sized, { x: 0, y: 0 }), [0, 0])\n return {\n box: { x: px - qx, y: py - qy, width: local.width, height: local.height },\n shift: { x: local.x, y: local.y }\n }\n}\n\nconst FIT_TOLERANCE = 1e-9\n\nfunction unchanged(value: number, previous: number): boolean {\n return Math.abs(value - previous) <= FIT_TOLERANCE * Math.max(1, Math.abs(previous))\n}\n\n/**\n * The changes that fit `group` to `children`: its box in its parent's space, and each child moved\n * back so it stays put on the canvas. Null when the fit changes nothing.\n */\nexport function groupFitChanges(\n graph: GroupFitGraph,\n group: SceneNode,\n children: SceneNode[],\n options: GroupFitOptions = {}\n): Map<string, Partial<SceneNode>> | null {\n if (!group.parentId) return null\n const fitted = fittedBox(graph, group, group.parentId, children, options)\n if (!fitted) return null\n const { box, shift } = fitted\n // A rotated group's frame leaves rounding residue; a fit within it changes nothing.\n if (\n unchanged(shift.x, 0) &&\n unchanged(shift.y, 0) &&\n unchanged(box.width, group.width) &&\n unchanged(box.height, group.height)\n ) {\n return null\n }\n const changes = new Map<string, Partial<SceneNode>>([[group.id, box]])\n for (const child of children) changes.set(child.id, shiftedBack(child, shift.x, shift.y))\n return changes\n}\n\n/** Moves the group to its children's bounds, shifting them back so they stay put. */\nfunction fitGroup(\n graph: SceneGraph,\n group: SceneNode,\n children: SceneNode[],\n fit: GroupFit,\n options: GroupFitOptions\n) {\n const changes = groupFitChanges(graph, group, children, options)\n if (!changes) return\n for (const node of [group, ...children]) {\n if (!fit.before.has(node.id)) fit.before.set(node.id, placement(node))\n }\n for (const [id, change] of changes) graph.updateNode(id, change)\n for (const node of [group, ...children]) {\n const current = graph.getNode(node.id)\n if (current) fit.after.set(node.id, placement(current))\n }\n}\n\n/** A group left without layers goes away; an empty boolean stays, as in Figma. */\nfunction removeEmptyGroup(graph: SceneGraph, group: SceneNode, fit: GroupFit) {\n if (group.type !== 'GROUP' || !group.parentId) return\n const index = graph.getNode(group.parentId)?.childIds.indexOf(group.id) ?? -1\n fit.removed.push({ node: structuredClone(group), index })\n graph.deleteNode(group.id)\n}\n\n/**\n * Refits the groups and booleans around these parents to their children, keeping every child where\n * it is on the canvas, and removes groups left empty, as Figma does after a layer inside one moves,\n * resizes, or leaves. Rotated or flipped groups keep their angle; a rotated or flipped boolean keeps\n * its bounds. Returns null when nothing changed.\n */\nexport function fitEnclosingGroups(\n graph: SceneGraph,\n parentIds: Iterable<string>,\n options: GroupFitOptions = {}\n): GroupFit | null {\n const fit: GroupFit = { before: new Map(), after: new Map(), removed: [] }\n for (const group of fittedAncestors(graph, parentIds)) {\n const children = graph.getChildren(group.id)\n if (children.length === 0) removeEmptyGroup(graph, group, fit)\n else fitGroup(graph, group, children, fit, options)\n }\n return fit.before.size === 0 && fit.removed.length === 0 ? null : fit\n}\n\n/** Reapplies a fit after `undoGroupFit`. */\nexport function redoGroupFit(graph: SceneGraph, fit: GroupFit): void {\n for (const [id, value] of fit.after) graph.updateNode(id, value)\n for (const { node } of fit.removed) graph.deleteNode(node.id)\n}\n\n/** Brings back the groups a fit removed and their earlier bounds. */\nexport function undoGroupFit(graph: SceneGraph, fit: GroupFit): void {\n // Outer groups were removed after inner ones, so they come back first.\n for (const { node, index } of fit.removed.toReversed()) {\n const parentId = node.parentId ?? graph.rootId\n graph.createNode(node.type, parentId, { ...structuredClone(node), childIds: [] })\n if (index >= 0) graph.insertChildAt(node.id, parentId, index)\n }\n for (const [id, value] of fit.before) graph.updateNode(id, value)\n}\n"],"mappings":";;;;;AAkCA,SAAS,UAAU,MAA4B;CAC7C,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;;AAGA,SAAgB,aAAa,OAAmB,KAAqB;CAEnE,KAAK,MAAM,EAAE,MAAM,WAAW,IAAI,QAAQ,WAAW,GAAG;EACtD,MAAM,WAAW,KAAK,YAAY,MAAM;EACxC,MAAM,WAAW,KAAK,MAAM,UAAU;GAAE,GAAG,gBAAgB,IAAI;GAAG,UAAU,CAAC;EAAE,CAAC;EAChF,IAAI,SAAS,GAAG,MAAM,cAAc,KAAK,IAAI,UAAU,KAAK;CAC9D;CACA,KAAK,MAAM,CAAC,IAAI,UAAU,IAAI,QAAQ,MAAM,WAAW,IAAI,KAAK;AAClE"}
|
|
1
|
+
{"version":3,"file":"group-bounds.js","names":[],"sources":["../src/group-bounds.ts"],"sourcesContent":["import { isEqual } from 'es-toolkit'\n\nimport { getAxisAlignedBoundsInParent, getNodeLocalMatrix } from './coordinate'\nimport { copyGeometryPaths } from './copy'\nimport type { SceneGraph } from './graph'\nimport { isEmptyBoolean } from './layout/flow'\nimport { isVisibleMask, maskRuns } from './masks'\nimport Matrix from './matrix'\nimport { FITTED_CONTAINER_TYPES } from './node-defaults'\nimport type { Rect, Vector } from './primitives'\nimport type { SceneNode } from './types'\n\n/**\n * What fitting a group reads: its layers and their parents, as the graph has them or as a resize\n * plans them before writing.\n */\nexport type GroupFitGraph = Pick<SceneGraph, 'getNode' | 'rootId'>\n\n/**\n * Where a layer sits, with a connector's ends, since a free end is in the parent's axes too, and\n * a boolean's saved geometry, which it drops when it loses its last operand.\n */\ntype Placement = Pick<SceneNode, 'x' | 'y' | 'width' | 'height'> &\n Partial<Pick<SceneNode, 'connectorStart' | 'connectorEnd' | 'fillGeometry' | 'strokeGeometry'>>\n\n/** What `fitEnclosingGroups` changed, so a caller can undo and redo it. */\nexport interface GroupFit {\n before: Map<string, Placement>\n after: Map<string, Placement>\n /** Emptied groups, outermost last, with their index in their parent. */\n removed: Array<{ node: SceneNode; index: number }>\n}\n\nexport interface GroupFitOptions {\n /**\n * The box of a boolean operation's result in its parent's space, which Figma sizes a boolean to,\n * or null to fit its operands. Measuring needs path operations, so the renderer supplies it.\n */\n booleanBounds?: (node: SceneNode) => Rect | null\n}\n\nfunction placement(node: SceneNode): Placement {\n const box = { x: node.x, y: node.y, width: node.width, height: node.height }\n if (node.type === 'BOOLEAN_OPERATION') {\n return {\n ...box,\n fillGeometry: copyGeometryPaths(node.fillGeometry),\n strokeGeometry: copyGeometryPaths(node.strokeGeometry)\n }\n }\n if (node.type !== 'CONNECTOR') return box\n return {\n ...box,\n connectorStart: structuredClone(node.connectorStart),\n connectorEnd: structuredClone(node.connectorEnd)\n }\n}\n\n/** A connector end moved by `dx`, `dy` when it is free, as its point is in the parent's axes. */\nfunction shiftedEnd(\n end: SceneNode['connectorStart'],\n dx: number,\n dy: number\n): SceneNode['connectorStart'] {\n if (end?.nodeId !== null) return end\n return { ...end, position: { x: end.position.x - dx, y: end.position.y - dy } }\n}\n\n/** Groups and booleans holding the parents, innermost first. */\nfunction fittedAncestors(graph: SceneGraph, parentIds: Iterable<string>): SceneNode[] {\n const found = new Map<string, { node: SceneNode; depth: number }>()\n for (const parentId of parentIds) {\n const chain: SceneNode[] = []\n for (let node = graph.getNode(parentId); node && FITTED_CONTAINER_TYPES.has(node.type);) {\n chain.push(node)\n node = node.parentId ? graph.getNode(node.parentId) : undefined\n }\n for (const [index, node] of chain.entries()) {\n found.set(node.id, {\n node,\n depth: Math.max(found.get(node.id)?.depth ?? 0, chain.length - index)\n })\n }\n }\n return [...found.values()].sort((a, b) => b.depth - a.depth).map(({ node }) => node)\n}\n\n/**\n * The layers a group's box covers, bottom to top. Hidden layers do not count, as in Figma, nor do\n * booleans with no operands unless they keep a finite saved fill and a box sized to it, since a\n * group counts a layer by its box. A mask hides the layers above it outside its shape, so they\n * count only through the mask: the box is the layers below it and the masks.\n */\nfunction groupBoundingLayers(children: readonly SceneNode[]): SceneNode[] {\n const shown = children.filter((child) => child.visible)\n const runs = maskRuns(shown, isVisibleMask)\n const covered =\n runs.length === 0\n ? shown\n : [\n ...shown.slice(0, runs[0].start),\n ...runs.flatMap((run) => shown.slice(run.start, run.maskedStart))\n ]\n return covered.filter((layer) => !isEmptyBoolean(layer))\n}\n\n/**\n * A group's box in its parent's space: around the layers it shows, or, with every layer hidden,\n * empty at `origin`, where Figma leaves it.\n */\nexport function groupBounds(\n graph: GroupFitGraph,\n children: readonly SceneNode[],\n parentId: string,\n origin: Vector\n): Rect {\n const layers = groupBoundingLayers(children)\n return layers.length > 0\n ? getAxisAlignedBoundsInParent(layers, parentId, graph)\n : { x: origin.x, y: origin.y, width: 0, height: 0 }\n}\n\n/** A child moved back by the group's shift, a connector's free ends with it. */\nfunction shiftedBack(child: SceneNode, dx: number, dy: number): Partial<SceneNode> {\n const moved = { x: child.x - dx, y: child.y - dy }\n if (child.type !== 'CONNECTOR') return moved\n return {\n ...moved,\n connectorStart: shiftedEnd(child.connectorStart, dx, dy),\n connectorEnd: shiftedEnd(child.connectorEnd, dx, dy)\n }\n}\n\nfunction isTransformed(node: SceneNode): boolean {\n return node.rotation !== 0 || node.flipX || node.flipY\n}\n\n/**\n * The group's new box in its parent's space and how far its children shift in its own frame, so\n * that the group holds its children while they stay put on the canvas. An unrotated group takes\n * their bounds in its parent's space. A rotated or flipped group keeps its angle: it takes their\n * bounds in its own frame, and its position is solved so its frame still maps every child to the\n * same canvas point, as its rotation and flips are unchanged. A rotated or flipped boolean, whose\n * box comes from its result's path, keeps its bounds.\n */\nfunction fittedBox(\n graph: GroupFitGraph,\n group: SceneNode,\n parentId: string,\n children: SceneNode[],\n options: GroupFitOptions\n): { box: Rect; shift: Vector } | null {\n if (!isTransformed(group)) {\n const box =\n (group.type === 'BOOLEAN_OPERATION' ? options.booleanBounds?.(group) : null) ??\n groupBounds(graph, children, parentId, group)\n return { box, shift: { x: box.x - group.x, y: box.y - group.y } }\n }\n if (group.type === 'BOOLEAN_OPERATION') return null\n const local = groupBounds(graph, children, group.id, { x: 0, y: 0 })\n const [px, py] = Matrix.mapPoints(getNodeLocalMatrix(group), [local.x, local.y])\n const sized = { ...group, width: local.width, height: local.height }\n const [qx, qy] = Matrix.mapPoints(getNodeLocalMatrix(sized, { x: 0, y: 0 }), [0, 0])\n return {\n box: { x: px - qx, y: py - qy, width: local.width, height: local.height },\n shift: { x: local.x, y: local.y }\n }\n}\n\nconst FIT_TOLERANCE = 1e-9\n\nfunction unchanged(value: number, previous: number): boolean {\n return Math.abs(value - previous) <= FIT_TOLERANCE * Math.max(1, Math.abs(previous))\n}\n\n/**\n * The changes that fit `group` to `children`: its box in its parent's space, and each child moved\n * back so it stays put on the canvas. Null when the fit changes nothing.\n */\nexport function groupFitChanges(\n graph: GroupFitGraph,\n group: SceneNode,\n children: SceneNode[],\n options: GroupFitOptions = {}\n): Map<string, Partial<SceneNode>> | null {\n if (!group.parentId) return null\n const fitted = fittedBox(graph, group, group.parentId, children, options)\n if (!fitted) return null\n const { box, shift } = fitted\n // A rotated group's frame leaves rounding residue; a fit within it changes nothing.\n if (\n unchanged(shift.x, 0) &&\n unchanged(shift.y, 0) &&\n unchanged(box.width, group.width) &&\n unchanged(box.height, group.height)\n ) {\n return null\n }\n const changes = new Map<string, Partial<SceneNode>>([[group.id, box]])\n for (const child of children) changes.set(child.id, shiftedBack(child, shift.x, shift.y))\n return changes\n}\n\n/** Moves the group to its children's bounds, shifting them back so they stay put. */\nfunction fitGroup(\n graph: SceneGraph,\n group: SceneNode,\n children: SceneNode[],\n fit: GroupFit,\n options: GroupFitOptions\n) {\n const changes = groupFitChanges(graph, group, children, options)\n if (!changes) return\n for (const node of [group, ...children]) {\n if (!fit.before.has(node.id)) fit.before.set(node.id, placement(node))\n }\n for (const [id, change] of changes) graph.updateNode(id, change)\n for (const node of [group, ...children]) {\n const current = graph.getNode(node.id)\n if (current) fit.after.set(node.id, placement(current))\n }\n}\n\n/**\n * A group left without layers goes away. A boolean stays, as in Figma, as a layer of no size at its\n * parent's origin, without the geometry its operands made.\n */\nfunction settleEmptyContainer(graph: SceneGraph, group: SceneNode, fit: GroupFit) {\n if (group.type === 'BOOLEAN_OPERATION') {\n collapseEmptyBoolean(graph, group, fit)\n return\n }\n if (group.type !== 'GROUP' || !group.parentId) return\n const index = graph.getNode(group.parentId)?.childIds.indexOf(group.id) ?? -1\n fit.removed.push({ node: structuredClone(group), index })\n graph.deleteNode(group.id)\n}\n\nfunction collapseEmptyBoolean(graph: SceneGraph, boolean: SceneNode, fit: GroupFit) {\n const before = placement(boolean)\n const collapsed: Placement = {\n x: 0,\n y: 0,\n width: 0,\n height: 0,\n fillGeometry: [],\n strokeGeometry: []\n }\n if (isEqual(before, collapsed)) return\n if (!fit.before.has(boolean.id)) fit.before.set(boolean.id, before)\n graph.updateNode(boolean.id, collapsed)\n fit.after.set(boolean.id, collapsed)\n}\n\n/**\n * Refits the groups and booleans around these parents to their children, keeping every child where\n * it is on the canvas, and removes groups left empty, as Figma does after a layer inside one moves,\n * resizes, or leaves. Rotated or flipped groups keep their angle; a rotated or flipped boolean keeps\n * its bounds. Returns null when nothing changed.\n */\nexport function fitEnclosingGroups(\n graph: SceneGraph,\n parentIds: Iterable<string>,\n options: GroupFitOptions = {}\n): GroupFit | null {\n const fit: GroupFit = { before: new Map(), after: new Map(), removed: [] }\n for (const group of fittedAncestors(graph, parentIds)) {\n const children = graph.getChildren(group.id)\n if (children.length === 0) settleEmptyContainer(graph, group, fit)\n else fitGroup(graph, group, children, fit, options)\n }\n return fit.before.size === 0 && fit.removed.length === 0 ? null : fit\n}\n\n/** Reapplies a fit after `undoGroupFit`. */\nexport function redoGroupFit(graph: SceneGraph, fit: GroupFit): void {\n for (const [id, value] of fit.after) graph.updateNode(id, value)\n for (const { node } of fit.removed) graph.deleteNode(node.id)\n}\n\n/** Brings back the groups a fit removed and their earlier bounds. */\nexport function undoGroupFit(graph: SceneGraph, fit: GroupFit): void {\n // Outer groups were removed after inner ones, so they come back first.\n for (const { node, index } of fit.removed.toReversed()) {\n const parentId = node.parentId ?? graph.rootId\n graph.createNode(node.type, parentId, { ...structuredClone(node), childIds: [] })\n if (index >= 0) graph.insertChildAt(node.id, parentId, index)\n }\n for (const [id, value] of fit.before) graph.updateNode(id, value)\n}\n"],"mappings":";;;;;;;;AAyCA,SAAS,UAAU,MAA4B;CAC7C,MAAM,MAAM;EAAE,GAAG,KAAK;EAAG,GAAG,KAAK;EAAG,OAAO,KAAK;EAAO,QAAQ,KAAK;CAAO;CAC3E,IAAI,KAAK,SAAS,qBAChB,OAAO;EACL,GAAG;EACH,cAAc,kBAAkB,KAAK,YAAY;EACjD,gBAAgB,kBAAkB,KAAK,cAAc;CACvD;CAEF,IAAI,KAAK,SAAS,aAAa,OAAO;CACtC,OAAO;EACL,GAAG;EACH,gBAAgB,gBAAgB,KAAK,cAAc;EACnD,cAAc,gBAAgB,KAAK,YAAY;CACjD;AACF;;AAGA,SAAS,WACP,KACA,IACA,IAC6B;CAC7B,IAAI,KAAK,WAAW,MAAM,OAAO;CACjC,OAAO;EAAE,GAAG;EAAK,UAAU;GAAE,GAAG,IAAI,SAAS,IAAI;GAAI,GAAG,IAAI,SAAS,IAAI;EAAG;CAAE;AAChF;;AAGA,SAAS,gBAAgB,OAAmB,WAA0C;CACpF,MAAM,wBAAQ,IAAI,IAAgD;CAClE,KAAK,MAAM,YAAY,WAAW;EAChC,MAAM,QAAqB,CAAC;EAC5B,KAAK,IAAI,OAAO,MAAM,QAAQ,QAAQ,GAAG,QAAQ,uBAAuB,IAAI,KAAK,IAAI,IAAI;GACvF,MAAM,KAAK,IAAI;GACf,OAAO,KAAK,WAAW,MAAM,QAAQ,KAAK,QAAQ,IAAI,KAAA;EACxD;EACA,KAAK,MAAM,CAAC,OAAO,SAAS,MAAM,QAAQ,GACxC,MAAM,IAAI,KAAK,IAAI;GACjB;GACA,OAAO,KAAK,IAAI,MAAM,IAAI,KAAK,EAAE,CAAC,EAAE,SAAS,GAAG,MAAM,SAAS,KAAK;EACtE,CAAC;CAEL;CACA,OAAO,CAAC,GAAG,MAAM,OAAO,CAAC,CAAC,CAAC,MAA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names":[],"sources":["../src/hit-test.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"hit-test.d.ts","names":[],"sources":["../src/hit-test.ts"],"mappings":";;;iBAoRgB,QACd,OAAO,YACP,YACA,YACA,mBACC;iBAKa,YACd,OAAO,YACP,YACA,YACA,kBACA,eACC;;;;;;;;;UA2Fc;;EAEf;;EAEA;;EAEA;;;;;EAKA;;iBAGc,kBACd,OAAO,YACP,YACA,YACA,iBACA,aAAa,qBACb,UAAS,uBACR;;iBA+Ba,gBAAgB,OAAO,YAAY,gBAAgB;;;;;iBASnD,qBACd,OAAO,YACP,YACA,YACA,kBACC;;iBAUa,cAAc,OAAO,YAAY,gBAAgB,YAAY;UA2D5D;;;;;EAKf,kBAAkB;;;;;;;;iBASJ,kBACd,OAAO,YACP,YACA,YACA,YAAY,qBACZ,kBACA,UAAS,oBACR"}
|
package/dist/hit-test.js
CHANGED
|
@@ -13,8 +13,13 @@ const CONTAINER_TYPES = /* @__PURE__ */ new Set([
|
|
|
13
13
|
"SECTION",
|
|
14
14
|
"COMPONENT",
|
|
15
15
|
"COMPONENT_SET",
|
|
16
|
-
"INSTANCE"
|
|
16
|
+
"INSTANCE",
|
|
17
|
+
"SLIDE",
|
|
18
|
+
"SLIDE_ROW",
|
|
19
|
+
"SLIDE_GRID"
|
|
17
20
|
]);
|
|
21
|
+
/** What holds a deck's slides: never selected from the canvas, and no target of a drop. */
|
|
22
|
+
const SLIDE_HOLDER_TYPES = /* @__PURE__ */ new Set(["SLIDE_ROW", "SLIDE_GRID"]);
|
|
18
23
|
const OPAQUE_CONTAINER_TYPES = /* @__PURE__ */ new Set(["COMPONENT", "INSTANCE"]);
|
|
19
24
|
/** Whether a container's own paints show, so its empty area is drawn (`paintShows`). */
|
|
20
25
|
function showsPaint(node) {
|
|
@@ -178,13 +183,13 @@ function hitTestDeep(graph, px, py, scopeId, pad = 0) {
|
|
|
178
183
|
}
|
|
179
184
|
/**
|
|
180
185
|
* A container a click looks into by itself, as in Figma: a top-level frame (on the page or in a
|
|
181
|
-
* section) or
|
|
186
|
+
* section), section, or slide that holds layers, a component set, and what holds a deck's slides. On a FigJam board frames stay
|
|
182
187
|
* closed (`framesOpen` false): a click inside one selects the frame.
|
|
183
188
|
*/
|
|
184
189
|
function opensByItself(graph, node, framesOpen = true) {
|
|
185
|
-
if (node.type === "COMPONENT_SET") return true;
|
|
190
|
+
if (node.type === "COMPONENT_SET" || SLIDE_HOLDER_TYPES.has(node.type)) return true;
|
|
186
191
|
if (node.childIds.length === 0) return false;
|
|
187
|
-
if (node.type === "SECTION") return true;
|
|
192
|
+
if (node.type === "SECTION" || node.type === "SLIDE") return true;
|
|
188
193
|
return framesOpen && node.type === "FRAME" && isTopLevel(graph, node);
|
|
189
194
|
}
|
|
190
195
|
/**
|
|
@@ -277,22 +282,28 @@ const LAYER_TARGETS = /* @__PURE__ */ new Set([
|
|
|
277
282
|
"FRAME",
|
|
278
283
|
"SECTION",
|
|
279
284
|
"COMPONENT",
|
|
280
|
-
"INSTANCE"
|
|
285
|
+
"INSTANCE",
|
|
286
|
+
"SLIDE"
|
|
281
287
|
]);
|
|
282
288
|
const COMPONENT_TARGETS = /* @__PURE__ */ new Set([
|
|
283
289
|
"FRAME",
|
|
284
290
|
"SECTION",
|
|
285
|
-
"INSTANCE"
|
|
291
|
+
"INSTANCE",
|
|
292
|
+
"SLIDE"
|
|
286
293
|
]);
|
|
287
294
|
function dropRules(options) {
|
|
288
295
|
const { componentSetIds } = options;
|
|
289
296
|
if (!componentSetIds) return {
|
|
290
297
|
takes: (node) => LAYER_TARGETS.has(node.type),
|
|
291
|
-
passThrough: /* @__PURE__ */ new Set([
|
|
298
|
+
passThrough: /* @__PURE__ */ new Set([
|
|
299
|
+
...SLIDE_HOLDER_TYPES,
|
|
300
|
+
"GROUP",
|
|
301
|
+
"COMPONENT_SET"
|
|
302
|
+
])
|
|
292
303
|
};
|
|
293
304
|
return {
|
|
294
305
|
takes: (node) => COMPONENT_TARGETS.has(node.type) || node.type === "COMPONENT_SET" && componentSetIds.has(node.id),
|
|
295
|
-
passThrough: /* @__PURE__ */ new Set(["GROUP"])
|
|
306
|
+
passThrough: /* @__PURE__ */ new Set([...SLIDE_HOLDER_TYPES, "GROUP"])
|
|
296
307
|
};
|
|
297
308
|
}
|
|
298
309
|
function dropTargetIn(graph, px, py, parent, excludeIds, rules, transformCache) {
|
package/dist/hit-test.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hit-test.js","names":[],"sources":["../src/hit-test.ts"],"sourcesContent":["import { hitsConnectorLine } from './connectors/hit'\nimport { getWorldMatrix } from './coordinate'\nimport type { SceneGraph } from './graph'\nimport { asMaskShape, isVisibleMask, maskRuns, type MaskRun } from './masks'\nimport Matrix from './matrix'\nimport { clipsChildren } from './node-defaults'\nimport { hitsShape, strokeReach } from './outline/hit'\nimport { paintShows } from './paints/shows'\nimport type { SceneNode, NodeType } from './types'\n\nconst CONTAINER_TYPES = new Set<NodeType>([\n 'CANVAS',\n 'FRAME',\n 'GROUP',\n 'SECTION',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE'\n])\nconst OPAQUE_CONTAINER_TYPES = new Set<NodeType>(['COMPONENT', 'INSTANCE'])\n\n/** Whether a container's own paints show, so its empty area is drawn (`paintShows`). */\nfunction showsPaint(node: SceneNode): boolean {\n return node.fills.some(paintShows) || node.strokes.some(paintShows)\n}\n\nfunction isTopLevel(graph: SceneGraph, node: SceneNode): boolean {\n const parent = node.parentId ? graph.nodes.get(node.parentId) : undefined\n return parent?.type === 'CANVAS' || parent?.type === 'SECTION'\n}\n\n/**\n * An open container whose empty area still belongs to it, as in Figma: a top-level frame with auto\n * layout is selected, hovered, and dragged by its gaps and padding, while its children stay one\n * click away, with or without a fill. A plain top-level frame's empty area is background, and a\n * nested frame's empty area belongs to it only as a click target (see `frameChildAt`).\n */\nfunction ownsItsEmptyArea(graph: SceneGraph, node: SceneNode): boolean {\n return node.type === 'FRAME' && node.layoutMode !== 'NONE' && isTopLevel(graph, node)\n}\n\nfunction hasTransformedAncestor(\n node: SceneNode,\n graph: SceneGraph,\n cache: Map<string, boolean>\n): boolean {\n const cached = cache.get(node.id)\n if (cached !== undefined) return cached\n const parent = node.parentId ? graph.getNode(node.parentId) : undefined\n const transformed =\n node.rotation !== 0 ||\n node.flipX ||\n node.flipY ||\n (parent ? hasTransformedAncestor(parent, graph, cache) : false)\n cache.set(node.id, transformed)\n return transformed\n}\n\n/** Whether the point lies in the node's box, grown by `pad` canvas units on every side. */\nfunction containsPoint(\n px: number,\n py: number,\n node: SceneNode,\n graph: SceneGraph,\n transformCache: Map<string, boolean>,\n pad = 0\n): boolean {\n if (!hasTransformedAncestor(node, graph, transformCache)) {\n const absolute = graph.getAbsolutePosition(node.id)\n return (\n px >= absolute.x - pad &&\n px <= absolute.x + node.width + pad &&\n py >= absolute.y - pad &&\n py <= absolute.y + node.height + pad\n )\n }\n\n const m = getWorldMatrix(node, graph)\n\n const inv = Matrix.invert(m)\n if (!inv) return false\n\n const [localX, localY] = Matrix.mapPoints(inv, [px, py])\n return (\n localX >= -pad && localX <= node.width + pad && localY >= -pad && localY <= node.height + pad\n )\n}\n\n/**\n * How a walk down the layers takes a click. `deep` reaches past containers to the deepest layer;\n * `pad`, in canvas units, grows each leaf layer's box, as Figma takes a click a few screen pixels\n * outside a shape; `instanceBodies` lets a deep walk take an instance's empty area whatever its\n * fill, as a plain click does, where a ⌘-click counts only a fill that shows.\n */\ninterface HitWalk {\n deep: boolean\n pad: number\n instanceBodies: boolean\n /** Whether locked layers are hit, as by a right-click; see `SelectableHitOptions.locked`. */\n locked: boolean\n transformCache: Map<string, boolean>\n}\n\nfunction walkOf(deep: boolean, pad = 0, instanceBodies = false, locked = false): HitWalk {\n return { deep, pad, instanceBodies, locked, transformCache: new Map() }\n}\n\n/** Whether a container's empty area under the point takes a click reaching past containers. */\nfunction takesEmptyArea(graph: SceneGraph, node: SceneNode, walk: HitWalk): boolean {\n // Figma counts an empty area only where a paint shows, except a main component's, which always\n // counts, and an instance's when the click is a plain one.\n if (node.type === 'COMPONENT' || showsPaint(node) || ownsItsEmptyArea(graph, node)) return true\n return walk.instanceBodies && node.type === 'INSTANCE'\n}\n\n/**\n * What a hit inside a container reports: the container itself when it is locked (a locked layer,\n * where one is hit at all, stands in for everything inside it) or the walk stops at containers.\n */\nfunction standIn(container: SceneNode, hit: SceneNode, deep: boolean): SceneNode {\n return container.locked || !deep ? container : hit\n}\n\nfunction hitTestTransparentContainer(\n graph: SceneGraph,\n px: number,\n py: number,\n child: SceneNode,\n walk: HitWalk\n): SceneNode | null {\n if (child.type === 'GROUP') {\n // A group fits its layers, so a padded click on one at its edge falls just outside it.\n if (!containsPoint(px, py, child, graph, walk.transformCache, walk.pad)) return null\n // A group has no area of its own, as in Figma: between its layers the click falls through to\n // whatever lies under the group.\n const childHit = hitTestChildren(graph, px, py, child.id, walk)\n return childHit ? standIn(child, childHit, walk.deep) : null\n }\n\n const childHit = hitTestChildren(graph, px, py, child.id, walk)\n if (childHit) return standIn(child, childHit, true)\n\n if (\n containsPoint(px, py, child, graph, walk.transformCache) &&\n takesEmptyArea(graph, child, walk)\n )\n return child\n return null\n}\n\n/**\n * The mask run holding each child, asked for from the top child down: the walk steps back through\n * the runs once rather than searching them for every child.\n */\nfunction maskRunCursor(\n graph: SceneGraph,\n childIds: readonly string[]\n): (index: number) => MaskRun | undefined {\n const runs = maskRuns(childIds, (id) => {\n const child = graph.nodes.get(id)\n return child !== undefined && isVisibleMask(child)\n })\n let runIndex = runs.length - 1\n return (index) => {\n while (runIndex >= 0 && runs[runIndex].start > index) runIndex--\n const run = runs.at(runIndex)\n return run && runIndex >= 0 && index >= run.maskedStart ? run : undefined\n }\n}\n\n/**\n * Whether the point lies on what a run's masks draw, or there is no run to hold it to. A container\n * mask draws its own paint and its layers, so a click between its layers is outside it.\n */\nfunction insideMasks(\n graph: SceneGraph,\n px: number,\n py: number,\n childIds: readonly string[],\n run: MaskRun | undefined,\n walk: HitWalk\n): boolean {\n if (!run) return true\n return childIds.slice(run.start, run.maskedStart).some((id) => {\n const mask = graph.nodes.get(id)\n if (!mask) return false\n if (!CONTAINER_TYPES.has(mask.type)) {\n return hitsLeaf(graph, px, py, asMaskShape(mask), walk.transformCache, 0)\n }\n if (showsPaint(mask) && containsPoint(px, py, mask, graph, walk.transformCache)) return true\n const drawn: HitWalk = { ...walk, deep: true, pad: 0, locked: true }\n return hitTestChildren(graph, px, py, mask.id, drawn) !== null\n })\n}\n\n/** The topmost layer under the point among a container's children. */\nfunction hitTestChildren(\n graph: SceneGraph,\n px: number,\n py: number,\n parentId: string,\n walk: HitWalk\n): SceneNode | null {\n const parent = graph.nodes.get(parentId)\n if (!parent) return null\n const { transformCache, pad } = walk\n\n if (clipsChildren(parent)) {\n if (!containsPoint(px, py, parent, graph, transformCache)) return null\n }\n\n const runAt = maskRunCursor(graph, parent.childIds)\n // Each run's masks are tested once per query, however many siblings they mask.\n const covered = new Map<MaskRun, boolean>()\n const inside = (run: MaskRun | undefined) => {\n if (!run) return true\n let hit = covered.get(run)\n if (hit === undefined) {\n hit = insideMasks(graph, px, py, parent.childIds, run, walk)\n covered.set(run, hit)\n }\n return hit\n }\n for (let i = parent.childIds.length - 1; i >= 0; i--) {\n const run = runAt(i)\n const child = graph.nodes.get(parent.childIds[i])\n // A locked layer and everything in it are invisible to a press and to hover, as in Figma: a\n // click falls through to what lies under it, and a drag from it draws a marquee.\n if (!child || child.internalOnly || !child.visible || (child.locked && !walk.locked)) continue\n // Where its masks cut a layer away, a click falls through to what lies under it (Figma, live).\n if (!inside(run)) continue\n if (CONTAINER_TYPES.has(child.type)) {\n if (OPAQUE_CONTAINER_TYPES.has(child.type) && !walk.deep) {\n // A plain click takes an instance or component anywhere in its box, with a fill or\n // without, as in Figma.\n if (containsPoint(px, py, child, graph, transformCache)) return child\n continue\n }\n const hit = hitTestTransparentContainer(graph, px, py, child, walk)\n if (hit) return hit\n continue\n }\n\n if (child.type === 'CONNECTOR') {\n if (hitsConnectorLine(graph, child, px, py, pad)) return child\n continue\n }\n if (hitsLeaf(graph, px, py, child, transformCache, pad)) return child\n }\n\n return null\n}\n\n/**\n * Whether a click lands on a leaf layer: on what its paints draw, as Figma tests shapes (see\n * `hitsShape`), or on its box for layers without an outline to test, such as text.\n */\nfunction hitsLeaf(\n graph: SceneGraph,\n px: number,\n py: number,\n node: SceneNode,\n transformCache: Map<string, boolean>,\n pad: number\n): boolean {\n if (!containsPoint(px, py, node, graph, transformCache, pad + strokeReach(node))) return false\n return (\n hitsShape(graph, node, px, py, pad) ?? containsPoint(px, py, node, graph, transformCache, pad)\n )\n}\n\nexport function hitTest(\n graph: SceneGraph,\n px: number,\n py: number,\n scopeId?: string\n): SceneNode | null {\n const scope = scopeId ?? graph.rootId\n return hitTestChildren(graph, px, py, scope, walkOf(false))\n}\n\nexport function hitTestDeep(\n graph: SceneGraph,\n px: number,\n py: number,\n scopeId?: string,\n pad = 0\n): SceneNode | null {\n const scope = scopeId ?? graph.rootId\n return hitTestChildren(graph, px, py, scope, walkOf(true, pad))\n}\n\n/**\n * A container a click looks into by itself, as in Figma: a top-level frame (on the page or in a\n * section) or a section that holds layers, and a component set. On a FigJam board frames stay\n * closed (`framesOpen` false): a click inside one selects the frame.\n */\nfunction opensByItself(graph: SceneGraph, node: SceneNode, framesOpen = true): boolean {\n if (node.type === 'COMPONENT_SET') return true\n if (node.childIds.length === 0) return false\n if (node.type === 'SECTION') return true\n return framesOpen && node.type === 'FRAME' && isTopLevel(graph, node)\n}\n\n/**\n * The topmost frame among a container's children whose bounds hold the point, filled or not: in\n * Figma a click on the empty area of a frame inside an open container, or of an empty frame on the\n * page or in a section, selects that frame, while a deep (⌘) click looks through it.\n */\nfunction frameChildAt(\n graph: SceneGraph,\n container: SceneNode,\n px: number,\n py: number,\n framesOpen = true,\n locked = false\n): SceneNode | null {\n const transformCache = new Map<string, boolean>()\n for (let i = container.childIds.length - 1; i >= 0; i--) {\n const child = graph.nodes.get(container.childIds[i])\n if (!child || child.internalOnly || !child.visible || child.type !== 'FRAME') continue\n if (child.locked && !locked) continue\n // A board, such as a top-level frame in a section, keeps its empty area as background.\n if (opensByItself(graph, child, framesOpen) && !ownsItsEmptyArea(graph, child)) continue\n if (containsPoint(px, py, child, graph, transformCache)) return child\n }\n return null\n}\n\n/**\n * The containers the selection opens: every ancestor of a selected layer inside the scope, so a\n * click reaches the siblings of selected layers, and a selected container itself, so hover and a\n * read-only click reach the layer under the point. A plain press inside a selected frame still\n * drags the frame, as in Figma, which `pressesSelection` in the Vue input decides. A selected group\n * or boolean stays closed: clicking inside it keeps it selected.\n */\nfunction openedBySelection(\n graph: SceneGraph,\n selectedIds: ReadonlySet<string>,\n scopeId: string,\n framesOpen: boolean,\n enteredId: string | null\n): Set<string> {\n const ancestors = new Set<string>()\n // An entered container is open whatever its kind, so a double-click into a board's frame\n // reaches its layers; its ancestors open with it.\n for (let id = enteredId; id && id !== scopeId && !ancestors.has(id);) {\n ancestors.add(id)\n id = graph.nodes.get(id)?.parentId ?? null\n }\n for (const id of selectedIds) {\n const node = graph.nodes.get(id)\n if (\n node &&\n node.childIds.length > 0 &&\n node.type !== 'GROUP' &&\n node.type !== 'BOOLEAN_OPERATION' &&\n // A board's frame stays closed when selected: a click inside keeps it selected.\n (framesOpen || node.type !== 'FRAME' || !isTopLevel(graph, node))\n )\n ancestors.add(id)\n let parentId = node?.parentId\n while (parentId && parentId !== scopeId && !ancestors.has(parentId)) {\n ancestors.add(parentId)\n parentId = graph.nodes.get(parentId)?.parentId\n }\n }\n return ancestors\n}\n\n/**\n * The layer a click selects, as in Figma. It walks from the scope down to the deepest layer under\n * the point and stops at the first layer that is not open. Top-level frames and sections with\n * layers and component sets are open, and so is every ancestor of the selection, so clicks reach\n * the siblings of selected layers. Where every layer under the point is open, a container opened\n * by the selection is selected, so is a top-level frame with auto layout, and a plain top-level\n * frame or a section is not.\n */\nexport interface SelectableHitOptions {\n /** Canvas units a leaf layer's box grows by, as Figma takes a click a few pixels outside. */\n pad?: number\n /** Whether top-level frames are looked into (a design) or selected whole (a board). */\n framesOpen?: boolean\n /** The container a double-click entered, open along with its ancestors. */\n enteredId?: string | null\n /**\n * Whether locked layers are hit, each standing in for everything inside it: a right-click\n * selects one, as in Figma, while a press and hover pass through it.\n */\n locked?: boolean\n}\n\nexport function hitTestSelectable(\n graph: SceneGraph,\n px: number,\n py: number,\n scopeId: string,\n selectedIds: ReadonlySet<string>,\n options: SelectableHitOptions = {}\n): SceneNode | null {\n const { pad = 0, framesOpen = true, enteredId = null, locked = false } = options\n // A plain click: the walk takes an instance's empty area whatever its fill.\n const deepest = hitTestChildren(graph, px, py, scopeId, walkOf(true, pad, true, locked))\n if (!deepest) {\n const scope = graph.nodes.get(scopeId)\n return scope ? frameChildAt(graph, scope, px, py, framesOpen, locked) : null\n }\n\n const chain: SceneNode[] = []\n for (let node: SceneNode | undefined = deepest; node && node.id !== scopeId;) {\n chain.unshift(node)\n node = node.parentId ? graph.nodes.get(node.parentId) : undefined\n }\n\n const opened = openedBySelection(graph, selectedIds, scopeId, framesOpen, enteredId)\n\n for (const node of chain) {\n // A locked layer, hit only with `locked`, stands in for everything inside it.\n if (node.locked) return node\n if (!opened.has(node.id) && !opensByItself(graph, node, framesOpen)) return node\n }\n const last = chain.at(-1)\n if (!last) return null\n const frame = frameChildAt(graph, last, px, py, framesOpen, locked)\n if (frame) return frame\n if (ownsItsEmptyArea(graph, last)) return last\n return opened.has(last.id) && !opensByItself(graph, last, framesOpen) ? last : null\n}\n\n/** Whether a click looks into this container rather than selecting it; see `hitTestSelectable`. */\nexport function isOpenContainer(graph: SceneGraph, nodeId: string, framesOpen = true): boolean {\n const node = graph.nodes.get(nodeId)\n return node !== undefined && opensByItself(graph, node, framesOpen)\n}\n\n/**\n * The innermost open container under the point when every layer there is open: a marquee starting\n * here selects that container's layers, as in Figma.\n */\nexport function hitTestOpenContainer(\n graph: SceneGraph,\n px: number,\n py: number,\n scopeId: string\n): SceneNode | null {\n const deepest = hitTestChildren(graph, px, py, scopeId, walkOf(true))\n for (let node: SceneNode | undefined = deepest ?? undefined; node && node.id !== scopeId;) {\n if (!opensByItself(graph, node) || ownsItsEmptyArea(graph, node)) return null\n node = node.parentId ? graph.nodes.get(node.parentId) : undefined\n }\n return deepest\n}\n\n/** Whether the point lies inside the node's rotated and flipped bounds. */\nexport function isPointInNode(graph: SceneGraph, nodeId: string, px: number, py: number): boolean {\n const node = graph.nodes.get(nodeId)\n return node !== undefined && containsPoint(px, py, node, graph, new Map())\n}\n\n/** Which layers take a drop, and which are only looked through, as in Figma. */\ninterface DropRules {\n takes: (node: SceneNode) => boolean\n passThrough: ReadonlySet<NodeType>\n}\n\nconst LAYER_TARGETS = new Set<NodeType>(['FRAME', 'SECTION', 'COMPONENT', 'INSTANCE'])\nconst COMPONENT_TARGETS = new Set<NodeType>(['FRAME', 'SECTION', 'INSTANCE'])\n\nfunction dropRules(options: DropTargetOptions): DropRules {\n const { componentSetIds } = options\n if (!componentSetIds) {\n return {\n takes: (node) => LAYER_TARGETS.has(node.type),\n passThrough: new Set(['GROUP', 'COMPONENT_SET'])\n }\n }\n // Components never go into other components, and a set only takes back its own variants.\n return {\n takes: (node) =>\n COMPONENT_TARGETS.has(node.type) ||\n (node.type === 'COMPONENT_SET' && componentSetIds.has(node.id)),\n passThrough: new Set(['GROUP'])\n }\n}\n\nfunction dropTargetIn(\n graph: SceneGraph,\n px: number,\n py: number,\n parent: SceneNode,\n excludeIds: ReadonlySet<string>,\n rules: DropRules,\n transformCache: Map<string, boolean>\n): SceneNode | null {\n // A clipped-away part of a child is not under the cursor.\n if (clipsChildren(parent) && !containsPoint(px, py, parent, graph, transformCache)) return null\n\n for (let i = parent.childIds.length - 1; i >= 0; i--) {\n const childId = parent.childIds[i]\n if (excludeIds.has(childId)) continue\n const child = graph.nodes.get(childId)\n if (!child || child.internalOnly || !child.visible || child.locked) continue\n const target = rules.takes(child)\n if (!target && !rules.passThrough.has(child.type)) continue\n\n const deeper = dropTargetIn(graph, px, py, child, excludeIds, rules, transformCache)\n if (deeper) return deeper\n if (target && containsPoint(px, py, child, graph, transformCache)) return child\n }\n\n return null\n}\n\nexport interface DropTargetOptions {\n /**\n * Set when the dropped layers are all main components: the component sets they come from.\n * Components then go only into frames, sections, instances, and those sets.\n */\n componentSetIds?: ReadonlySet<string>\n}\n\n/**\n * The topmost unlocked frame, section, component, or instance under the point, in its rotated\n * shape and inside its clipping ancestors. Groups and component sets are looked through but never\n * returned, except that a set takes dropped components; locked layers and their contents are\n * skipped.\n */\nexport function hitTestDropTarget(\n graph: SceneGraph,\n px: number,\n py: number,\n excludeIds: ReadonlySet<string>,\n scopeId?: string,\n options: DropTargetOptions = {}\n): SceneNode | null {\n const scope = graph.nodes.get(scopeId ?? graph.rootId)\n if (!scope) return null\n return dropTargetIn(graph, px, py, scope, excludeIds, dropRules(options), new Map())\n}\n"],"mappings":";;;;;;;;AAUA,MAAM,kCAAkB,IAAI,IAAc;CACxC;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AACD,MAAM,yCAAyB,IAAI,IAAc,CAAC,aAAa,UAAU,CAAC;;AAG1E,SAAS,WAAW,MAA0B;CAC5C,OAAO,KAAK,MAAM,KAAK,UAAU,KAAK,KAAK,QAAQ,KAAK,UAAU;AACpE;AAEA,SAAS,WAAW,OAAmB,MAA0B;CAC/D,MAAM,SAAS,KAAK,WAAW,MAAM,MAAM,IAAI,KAAK,QAAQ,IAAI,KAAA;CAChE,OAAO,QAAQ,SAAS,YAAY,QAAQ,SAAS;AACvD;;;;;;;AAQA,SAAS,iBAAiB,OAAmB,MAA0B;CACrE,OAAO,KAAK,SAAS,WAAW,KAAK,eAAe,UAAU,WAAW,OAAO,IAAI;AACtF;AAEA,SAAS,uBACP,MACA,OACA,OACS;CACT,MAAM,SAAS,MAAM,IAAI,KAAK,EAAE;CAChC,IAAI,WAAW,KAAA,GAAW,OAAO;CACjC,MAAM,SAAS,KAAK,WAAW,MAAM,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,IAAI,OAAO,OAAO,cAAc,GAAG,OAAO;CAC5E;CAEA,OAAO;AACT;;;;;;;AAgBA,SAAgB,kBACd,OACA,IACA,IACA,YACA,SACA,UAA6B,CAAC,GACZ;CAClB,MAAM,QAAQ,MAAM,MAAM,IAAI,WAAW,MAAM,MAAM;CACrD,IAAI,CAAC,OAAO,OAAO;CACnB,OAAO,aAAa,OAAO,IAAI,IAAI,OAAO,YAAY,UAAU,OAAO,mBAAG,IAAI,IAAI,CAAC;AACrF"}
|
|
1
|
+
{"version":3,"file":"hit-test.js","names":[],"sources":["../src/hit-test.ts"],"sourcesContent":["import { hitsConnectorLine } from './connectors/hit'\nimport { getWorldMatrix } from './coordinate'\nimport type { SceneGraph } from './graph'\nimport { asMaskShape, isVisibleMask, maskRuns, type MaskRun } from './masks'\nimport Matrix from './matrix'\nimport { clipsChildren } from './node-defaults'\nimport { hitsShape, strokeReach } from './outline/hit'\nimport { paintShows } from './paints/shows'\nimport type { SceneNode, NodeType } from './types'\n\nconst CONTAINER_TYPES = new Set<NodeType>([\n 'CANVAS',\n 'FRAME',\n 'GROUP',\n 'SECTION',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE',\n 'SLIDE',\n 'SLIDE_ROW',\n 'SLIDE_GRID'\n])\n/** What holds a deck's slides: never selected from the canvas, and no target of a drop. */\nconst SLIDE_HOLDER_TYPES = new Set<NodeType>(['SLIDE_ROW', 'SLIDE_GRID'])\nconst OPAQUE_CONTAINER_TYPES = new Set<NodeType>(['COMPONENT', 'INSTANCE'])\n\n/** Whether a container's own paints show, so its empty area is drawn (`paintShows`). */\nfunction showsPaint(node: SceneNode): boolean {\n return node.fills.some(paintShows) || node.strokes.some(paintShows)\n}\n\nfunction isTopLevel(graph: SceneGraph, node: SceneNode): boolean {\n const parent = node.parentId ? graph.nodes.get(node.parentId) : undefined\n return parent?.type === 'CANVAS' || parent?.type === 'SECTION'\n}\n\n/**\n * An open container whose empty area still belongs to it, as in Figma: a top-level frame with auto\n * layout is selected, hovered, and dragged by its gaps and padding, while its children stay one\n * click away, with or without a fill. A plain top-level frame's empty area is background, and a\n * nested frame's empty area belongs to it only as a click target (see `frameChildAt`).\n */\nfunction ownsItsEmptyArea(graph: SceneGraph, node: SceneNode): boolean {\n return node.type === 'FRAME' && node.layoutMode !== 'NONE' && isTopLevel(graph, node)\n}\n\nfunction hasTransformedAncestor(\n node: SceneNode,\n graph: SceneGraph,\n cache: Map<string, boolean>\n): boolean {\n const cached = cache.get(node.id)\n if (cached !== undefined) return cached\n const parent = node.parentId ? graph.getNode(node.parentId) : undefined\n const transformed =\n node.rotation !== 0 ||\n node.flipX ||\n node.flipY ||\n (parent ? hasTransformedAncestor(parent, graph, cache) : false)\n cache.set(node.id, transformed)\n return transformed\n}\n\n/** Whether the point lies in the node's box, grown by `pad` canvas units on every side. */\nfunction containsPoint(\n px: number,\n py: number,\n node: SceneNode,\n graph: SceneGraph,\n transformCache: Map<string, boolean>,\n pad = 0\n): boolean {\n if (!hasTransformedAncestor(node, graph, transformCache)) {\n const absolute = graph.getAbsolutePosition(node.id)\n return (\n px >= absolute.x - pad &&\n px <= absolute.x + node.width + pad &&\n py >= absolute.y - pad &&\n py <= absolute.y + node.height + pad\n )\n }\n\n const m = getWorldMatrix(node, graph)\n\n const inv = Matrix.invert(m)\n if (!inv) return false\n\n const [localX, localY] = Matrix.mapPoints(inv, [px, py])\n return (\n localX >= -pad && localX <= node.width + pad && localY >= -pad && localY <= node.height + pad\n )\n}\n\n/**\n * How a walk down the layers takes a click. `deep` reaches past containers to the deepest layer;\n * `pad`, in canvas units, grows each leaf layer's box, as Figma takes a click a few screen pixels\n * outside a shape; `instanceBodies` lets a deep walk take an instance's empty area whatever its\n * fill, as a plain click does, where a ⌘-click counts only a fill that shows.\n */\ninterface HitWalk {\n deep: boolean\n pad: number\n instanceBodies: boolean\n /** Whether locked layers are hit, as by a right-click; see `SelectableHitOptions.locked`. */\n locked: boolean\n transformCache: Map<string, boolean>\n}\n\nfunction walkOf(deep: boolean, pad = 0, instanceBodies = false, locked = false): HitWalk {\n return { deep, pad, instanceBodies, locked, transformCache: new Map() }\n}\n\n/** Whether a container's empty area under the point takes a click reaching past containers. */\nfunction takesEmptyArea(graph: SceneGraph, node: SceneNode, walk: HitWalk): boolean {\n // Figma counts an empty area only where a paint shows, except a main component's, which always\n // counts, and an instance's when the click is a plain one.\n if (node.type === 'COMPONENT' || showsPaint(node) || ownsItsEmptyArea(graph, node)) return true\n return walk.instanceBodies && node.type === 'INSTANCE'\n}\n\n/**\n * What a hit inside a container reports: the container itself when it is locked (a locked layer,\n * where one is hit at all, stands in for everything inside it) or the walk stops at containers.\n */\nfunction standIn(container: SceneNode, hit: SceneNode, deep: boolean): SceneNode {\n return container.locked || !deep ? container : hit\n}\n\nfunction hitTestTransparentContainer(\n graph: SceneGraph,\n px: number,\n py: number,\n child: SceneNode,\n walk: HitWalk\n): SceneNode | null {\n if (child.type === 'GROUP') {\n // A group fits its layers, so a padded click on one at its edge falls just outside it.\n if (!containsPoint(px, py, child, graph, walk.transformCache, walk.pad)) return null\n // A group has no area of its own, as in Figma: between its layers the click falls through to\n // whatever lies under the group.\n const childHit = hitTestChildren(graph, px, py, child.id, walk)\n return childHit ? standIn(child, childHit, walk.deep) : null\n }\n\n const childHit = hitTestChildren(graph, px, py, child.id, walk)\n if (childHit) return standIn(child, childHit, true)\n\n if (\n containsPoint(px, py, child, graph, walk.transformCache) &&\n takesEmptyArea(graph, child, walk)\n )\n return child\n return null\n}\n\n/**\n * The mask run holding each child, asked for from the top child down: the walk steps back through\n * the runs once rather than searching them for every child.\n */\nfunction maskRunCursor(\n graph: SceneGraph,\n childIds: readonly string[]\n): (index: number) => MaskRun | undefined {\n const runs = maskRuns(childIds, (id) => {\n const child = graph.nodes.get(id)\n return child !== undefined && isVisibleMask(child)\n })\n let runIndex = runs.length - 1\n return (index) => {\n while (runIndex >= 0 && runs[runIndex].start > index) runIndex--\n const run = runs.at(runIndex)\n return run && runIndex >= 0 && index >= run.maskedStart ? run : undefined\n }\n}\n\n/**\n * Whether the point lies on what a run's masks draw, or there is no run to hold it to. A container\n * mask draws its own paint and its layers, so a click between its layers is outside it.\n */\nfunction insideMasks(\n graph: SceneGraph,\n px: number,\n py: number,\n childIds: readonly string[],\n run: MaskRun | undefined,\n walk: HitWalk\n): boolean {\n if (!run) return true\n return childIds.slice(run.start, run.maskedStart).some((id) => {\n const mask = graph.nodes.get(id)\n if (!mask) return false\n if (!CONTAINER_TYPES.has(mask.type)) {\n return hitsLeaf(graph, px, py, asMaskShape(mask), walk.transformCache, 0)\n }\n if (showsPaint(mask) && containsPoint(px, py, mask, graph, walk.transformCache)) return true\n const drawn: HitWalk = { ...walk, deep: true, pad: 0, locked: true }\n return hitTestChildren(graph, px, py, mask.id, drawn) !== null\n })\n}\n\n/** The topmost layer under the point among a container's children. */\nfunction hitTestChildren(\n graph: SceneGraph,\n px: number,\n py: number,\n parentId: string,\n walk: HitWalk\n): SceneNode | null {\n const parent = graph.nodes.get(parentId)\n if (!parent) return null\n const { transformCache, pad } = walk\n\n if (clipsChildren(parent)) {\n if (!containsPoint(px, py, parent, graph, transformCache)) return null\n }\n\n const runAt = maskRunCursor(graph, parent.childIds)\n // Each run's masks are tested once per query, however many siblings they mask.\n const covered = new Map<MaskRun, boolean>()\n const inside = (run: MaskRun | undefined) => {\n if (!run) return true\n let hit = covered.get(run)\n if (hit === undefined) {\n hit = insideMasks(graph, px, py, parent.childIds, run, walk)\n covered.set(run, hit)\n }\n return hit\n }\n for (let i = parent.childIds.length - 1; i >= 0; i--) {\n const run = runAt(i)\n const child = graph.nodes.get(parent.childIds[i])\n // A locked layer and everything in it are invisible to a press and to hover, as in Figma: a\n // click falls through to what lies under it, and a drag from it draws a marquee.\n if (!child || child.internalOnly || !child.visible || (child.locked && !walk.locked)) continue\n // Where its masks cut a layer away, a click falls through to what lies under it (Figma, live).\n if (!inside(run)) continue\n if (CONTAINER_TYPES.has(child.type)) {\n if (OPAQUE_CONTAINER_TYPES.has(child.type) && !walk.deep) {\n // A plain click takes an instance or component anywhere in its box, with a fill or\n // without, as in Figma.\n if (containsPoint(px, py, child, graph, transformCache)) return child\n continue\n }\n const hit = hitTestTransparentContainer(graph, px, py, child, walk)\n if (hit) return hit\n continue\n }\n\n if (child.type === 'CONNECTOR') {\n if (hitsConnectorLine(graph, child, px, py, pad)) return child\n continue\n }\n if (hitsLeaf(graph, px, py, child, transformCache, pad)) return child\n }\n\n return null\n}\n\n/**\n * Whether a click lands on a leaf layer: on what its paints draw, as Figma tests shapes (see\n * `hitsShape`), or on its box for layers without an outline to test, such as text.\n */\nfunction hitsLeaf(\n graph: SceneGraph,\n px: number,\n py: number,\n node: SceneNode,\n transformCache: Map<string, boolean>,\n pad: number\n): boolean {\n if (!containsPoint(px, py, node, graph, transformCache, pad + strokeReach(node))) return false\n return (\n hitsShape(graph, node, px, py, pad) ?? containsPoint(px, py, node, graph, transformCache, pad)\n )\n}\n\nexport function hitTest(\n graph: SceneGraph,\n px: number,\n py: number,\n scopeId?: string\n): SceneNode | null {\n const scope = scopeId ?? graph.rootId\n return hitTestChildren(graph, px, py, scope, walkOf(false))\n}\n\nexport function hitTestDeep(\n graph: SceneGraph,\n px: number,\n py: number,\n scopeId?: string,\n pad = 0\n): SceneNode | null {\n const scope = scopeId ?? graph.rootId\n return hitTestChildren(graph, px, py, scope, walkOf(true, pad))\n}\n\n/**\n * A container a click looks into by itself, as in Figma: a top-level frame (on the page or in a\n * section), section, or slide that holds layers, a component set, and what holds a deck's slides. On a FigJam board frames stay\n * closed (`framesOpen` false): a click inside one selects the frame.\n */\nfunction opensByItself(graph: SceneGraph, node: SceneNode, framesOpen = true): boolean {\n if (node.type === 'COMPONENT_SET' || SLIDE_HOLDER_TYPES.has(node.type)) return true\n if (node.childIds.length === 0) return false\n if (node.type === 'SECTION' || node.type === 'SLIDE') return true\n return framesOpen && node.type === 'FRAME' && isTopLevel(graph, node)\n}\n\n/**\n * The topmost frame among a container's children whose bounds hold the point, filled or not: in\n * Figma a click on the empty area of a frame inside an open container, or of an empty frame on the\n * page or in a section, selects that frame, while a deep (⌘) click looks through it.\n */\nfunction frameChildAt(\n graph: SceneGraph,\n container: SceneNode,\n px: number,\n py: number,\n framesOpen = true,\n locked = false\n): SceneNode | null {\n const transformCache = new Map<string, boolean>()\n for (let i = container.childIds.length - 1; i >= 0; i--) {\n const child = graph.nodes.get(container.childIds[i])\n if (!child || child.internalOnly || !child.visible || child.type !== 'FRAME') continue\n if (child.locked && !locked) continue\n // A board, such as a top-level frame in a section, keeps its empty area as background.\n if (opensByItself(graph, child, framesOpen) && !ownsItsEmptyArea(graph, child)) continue\n if (containsPoint(px, py, child, graph, transformCache)) return child\n }\n return null\n}\n\n/**\n * The containers the selection opens: every ancestor of a selected layer inside the scope, so a\n * click reaches the siblings of selected layers, and a selected container itself, so hover and a\n * read-only click reach the layer under the point. A plain press inside a selected frame still\n * drags the frame, as in Figma, which `pressesSelection` in the Vue input decides. A selected group\n * or boolean stays closed: clicking inside it keeps it selected.\n */\nfunction openedBySelection(\n graph: SceneGraph,\n selectedIds: ReadonlySet<string>,\n scopeId: string,\n framesOpen: boolean,\n enteredId: string | null\n): Set<string> {\n const ancestors = new Set<string>()\n // An entered container is open whatever its kind, so a double-click into a board's frame\n // reaches its layers; its ancestors open with it.\n for (let id = enteredId; id && id !== scopeId && !ancestors.has(id);) {\n ancestors.add(id)\n id = graph.nodes.get(id)?.parentId ?? null\n }\n for (const id of selectedIds) {\n const node = graph.nodes.get(id)\n if (\n node &&\n node.childIds.length > 0 &&\n node.type !== 'GROUP' &&\n node.type !== 'BOOLEAN_OPERATION' &&\n // A board's frame stays closed when selected: a click inside keeps it selected.\n (framesOpen || node.type !== 'FRAME' || !isTopLevel(graph, node))\n )\n ancestors.add(id)\n let parentId = node?.parentId\n while (parentId && parentId !== scopeId && !ancestors.has(parentId)) {\n ancestors.add(parentId)\n parentId = graph.nodes.get(parentId)?.parentId\n }\n }\n return ancestors\n}\n\n/**\n * The layer a click selects, as in Figma. It walks from the scope down to the deepest layer under\n * the point and stops at the first layer that is not open. Top-level frames and sections with\n * layers and component sets are open, and so is every ancestor of the selection, so clicks reach\n * the siblings of selected layers. Where every layer under the point is open, a container opened\n * by the selection is selected, so is a top-level frame with auto layout, and a plain top-level\n * frame or a section is not.\n */\nexport interface SelectableHitOptions {\n /** Canvas units a leaf layer's box grows by, as Figma takes a click a few pixels outside. */\n pad?: number\n /** Whether top-level frames are looked into (a design) or selected whole (a board). */\n framesOpen?: boolean\n /** The container a double-click entered, open along with its ancestors. */\n enteredId?: string | null\n /**\n * Whether locked layers are hit, each standing in for everything inside it: a right-click\n * selects one, as in Figma, while a press and hover pass through it.\n */\n locked?: boolean\n}\n\nexport function hitTestSelectable(\n graph: SceneGraph,\n px: number,\n py: number,\n scopeId: string,\n selectedIds: ReadonlySet<string>,\n options: SelectableHitOptions = {}\n): SceneNode | null {\n const { pad = 0, framesOpen = true, enteredId = null, locked = false } = options\n // A plain click: the walk takes an instance's empty area whatever its fill.\n const deepest = hitTestChildren(graph, px, py, scopeId, walkOf(true, pad, true, locked))\n if (!deepest) {\n const scope = graph.nodes.get(scopeId)\n return scope ? frameChildAt(graph, scope, px, py, framesOpen, locked) : null\n }\n\n const chain: SceneNode[] = []\n for (let node: SceneNode | undefined = deepest; node && node.id !== scopeId;) {\n chain.unshift(node)\n node = node.parentId ? graph.nodes.get(node.parentId) : undefined\n }\n\n const opened = openedBySelection(graph, selectedIds, scopeId, framesOpen, enteredId)\n\n for (const node of chain) {\n // A locked layer, hit only with `locked`, stands in for everything inside it.\n if (node.locked) return node\n if (!opened.has(node.id) && !opensByItself(graph, node, framesOpen)) return node\n }\n const last = chain.at(-1)\n if (!last) return null\n const frame = frameChildAt(graph, last, px, py, framesOpen, locked)\n if (frame) return frame\n if (ownsItsEmptyArea(graph, last)) return last\n return opened.has(last.id) && !opensByItself(graph, last, framesOpen) ? last : null\n}\n\n/** Whether a click looks into this container rather than selecting it; see `hitTestSelectable`. */\nexport function isOpenContainer(graph: SceneGraph, nodeId: string, framesOpen = true): boolean {\n const node = graph.nodes.get(nodeId)\n return node !== undefined && opensByItself(graph, node, framesOpen)\n}\n\n/**\n * The innermost open container under the point when every layer there is open: a marquee starting\n * here selects that container's layers, as in Figma.\n */\nexport function hitTestOpenContainer(\n graph: SceneGraph,\n px: number,\n py: number,\n scopeId: string\n): SceneNode | null {\n const deepest = hitTestChildren(graph, px, py, scopeId, walkOf(true))\n for (let node: SceneNode | undefined = deepest ?? undefined; node && node.id !== scopeId;) {\n if (!opensByItself(graph, node) || ownsItsEmptyArea(graph, node)) return null\n node = node.parentId ? graph.nodes.get(node.parentId) : undefined\n }\n return deepest\n}\n\n/** Whether the point lies inside the node's rotated and flipped bounds. */\nexport function isPointInNode(graph: SceneGraph, nodeId: string, px: number, py: number): boolean {\n const node = graph.nodes.get(nodeId)\n return node !== undefined && containsPoint(px, py, node, graph, new Map())\n}\n\n/** Which layers take a drop, and which are only looked through, as in Figma. */\ninterface DropRules {\n takes: (node: SceneNode) => boolean\n passThrough: ReadonlySet<NodeType>\n}\n\nconst LAYER_TARGETS = new Set<NodeType>(['FRAME', 'SECTION', 'COMPONENT', 'INSTANCE', 'SLIDE'])\nconst COMPONENT_TARGETS = new Set<NodeType>(['FRAME', 'SECTION', 'INSTANCE', 'SLIDE'])\n\nfunction dropRules(options: DropTargetOptions): DropRules {\n const { componentSetIds } = options\n if (!componentSetIds) {\n return {\n takes: (node) => LAYER_TARGETS.has(node.type),\n passThrough: new Set([...SLIDE_HOLDER_TYPES, 'GROUP', 'COMPONENT_SET'])\n }\n }\n // Components never go into other components, and a set only takes back its own variants.\n return {\n takes: (node) =>\n COMPONENT_TARGETS.has(node.type) ||\n (node.type === 'COMPONENT_SET' && componentSetIds.has(node.id)),\n passThrough: new Set([...SLIDE_HOLDER_TYPES, 'GROUP'])\n }\n}\n\nfunction dropTargetIn(\n graph: SceneGraph,\n px: number,\n py: number,\n parent: SceneNode,\n excludeIds: ReadonlySet<string>,\n rules: DropRules,\n transformCache: Map<string, boolean>\n): SceneNode | null {\n // A clipped-away part of a child is not under the cursor.\n if (clipsChildren(parent) && !containsPoint(px, py, parent, graph, transformCache)) return null\n\n for (let i = parent.childIds.length - 1; i >= 0; i--) {\n const childId = parent.childIds[i]\n if (excludeIds.has(childId)) continue\n const child = graph.nodes.get(childId)\n if (!child || child.internalOnly || !child.visible || child.locked) continue\n const target = rules.takes(child)\n if (!target && !rules.passThrough.has(child.type)) continue\n\n const deeper = dropTargetIn(graph, px, py, child, excludeIds, rules, transformCache)\n if (deeper) return deeper\n if (target && containsPoint(px, py, child, graph, transformCache)) return child\n }\n\n return null\n}\n\nexport interface DropTargetOptions {\n /**\n * Set when the dropped layers are all main components: the component sets they come from.\n * Components then go only into frames, sections, instances, and those sets.\n */\n componentSetIds?: ReadonlySet<string>\n}\n\n/**\n * The topmost unlocked frame, section, component, or instance under the point, in its rotated\n * shape and inside its clipping ancestors. Groups and component sets are looked through but never\n * returned, except that a set takes dropped components; locked layers and their contents are\n * skipped.\n */\nexport function hitTestDropTarget(\n graph: SceneGraph,\n px: number,\n py: number,\n excludeIds: ReadonlySet<string>,\n scopeId?: string,\n options: DropTargetOptions = {}\n): SceneNode | null {\n const scope = graph.nodes.get(scopeId ?? graph.rootId)\n if (!scope) return null\n return dropTargetIn(graph, px, py, scope, excludeIds, dropRules(options), new Map())\n}\n"],"mappings":";;;;;;;;AAUA,MAAM,kCAAkB,IAAI,IAAc;CACxC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;;AAED,MAAM,qCAAqB,IAAI,IAAc,CAAC,aAAa,YAAY,CAAC;AACxE,MAAM,yCAAyB,IAAI,IAAc,CAAC,aAAa,UAAU,CAAC;;AAG1E,SAAS,WAAW,MAA0B;CAC5C,OAAO,KAAK,MAAM,KAAK,UAAU,KAAK,KAAK,QAAQ,KAAK,UAAU;AACpE;AAEA,SAAS,WAAW,OAAmB,MAA0B;CAC/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CAE3F,KAAK,IAAI,IAAI,OAAO,SAAS,SAAS,GAAG,KAAK,GAAG,KAAK;EACpD,MAAM,UAAU,OAAO,SAAS;EAChC,IAAI,WAAW,IAAI,OAAO,GAAG;EAC7B,MAAM,QAAQ,MAAM,MAAM,IAAI,OAAO;EACrC,IAAI,CAAC,SAAS,MAAM,gBAAgB,CAAC,MAAM,WAAW,MAAM,QAAQ;EACpE,MAAM,SAAS,MAAM,MAAM,KAAK;EAChC,IAAI,CAAC,UAAU,CAAC,MAAM,YAAY,IAAI,MAAM,IAAI,GAAG;EAEnD,MAAM,SAAS,aAAa,OAAO,IAAI,IAAI,OAAO,YAAY,OAAO,cAAc;EACnF,IAAI,QAAQ,OAAO;EACnB,IAAI,UAAU,cAAc,IAAI,IAAI,OAAO,OAAO,cAAc,GAAG,OAAO;CAC5E;CAEA,OAAO;AACT;;;;;;;AAgBA,SAAgB,kBACd,OACA,IACA,IACA,YACA,SACA,UAA6B,CAAC,GACZ;CAClB,MAAM,QAAQ,MAAM,MAAM,IAAI,WAAW,MAAM,MAAM;CACrD,IAAI,CAAC,OAAO,OAAO;CACnB,OAAO,aAAa,OAAO,IAAI,IAAI,OAAO,YAAY,UAAU,OAAO,mBAAG,IAAI,IAAI,CAAC;AACrF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CommittedGraphEventError } from "./buffered-events.js";
|
|
2
2
|
import { SceneGraph } from "./graph.js";
|
|
3
|
-
import { ArcData, AxisSizingMode, BlendMode, CODE_SYNTAX_PLATFORMS, CharacterStyleOverride, CodeSyntaxPlatform, CommentReply, CommentThread, ComponentPropertyDefinition, ComponentPropertyReference, ComponentPropertyReferenceField, ComponentPropertyType, ConnectorControlPoint, ConnectorEndpoint, ConnectorLabelPosition, ConnectorLineType, ConnectorMagnet, ConstraintType,
|
|
3
|
+
import { ArcData, AxisSizingMode, BlendMode, CODE_SYNTAX_PLATFORMS, CharacterStyleOverride, CodeSyntaxPlatform, ColorProfile, CommentReply, CommentThread, ComponentPropertyDefinition, ComponentPropertyReference, ComponentPropertyReferenceField, ComponentPropertyType, ConnectorControlPoint, ConnectorEndpoint, ConnectorLabelPosition, ConnectorLineType, ConnectorMagnet, ConstraintType, CubicBezier, DerivedTextGlyph, DocumentKind, DocumentRecordKind, EASING_CURVES, Easing, EasingCurve, Effect, EnabledLibraryBinding, ExportColorProfile, ExportSetting, ExportSize, FigmaLayoutMetadata, FigmaSourcePayload, Fill, FillType, FontFeature, FontVariation, GeometryPath, GlassEffectParams, GradientStop, GradientTransform, GridPosition, GridTrack, GridTrackSizing, HandleMirroring, HyperlinkTarget, ImageFilters, ImageScaleMode, LayoutAlign, LayoutAlignSelf, LayoutCounterAlign, LayoutDirection, LayoutGrid, LayoutMode, LayoutSizing, LayoutWrap, LeadingTrim, LibraryAssetIdentity, LibraryAssetRef, LibraryAssetSource, MODE_ATTRIBUTE_PATTERN, MaskType, NodeChangeObserver, NodeType, NoiseEffectParams, NoiseType, NumericNodeProperty, PatternAlignment, PatternTileType, PluginDataEntry, PluginRelaunchDataEntry, ProgressiveBlur, SceneGraphEventHandlers, SceneGraphEvents, SceneNode, SharedStyle, SharedStyleKind, SharedStyleType, SlotSettings, SourceLibraryPublication, SourceMetadata, Spring, Stroke, StrokeCap, StrokeJoin, StyleRun, SymbolLink, TEXT_BINDABLE_FIELDS, TOKEN_UNITS, TextAlignVertical, TextAutoResize, TextBindableField, TextBoundVariables, TextCase, TextDecoration, TextDecorationStyle, TextDirection, TextLength, TextListType, TextParagraphSpacingField, TextParagraphStyle, TextPathData, TextureEffectParams, TokenExpression, TokenUnit, VARIABLE_FORMULA_OPERATORS, VARIABLE_SCOPES, VARIABLE_TYPES, Variable, VariableAlias, VariableCollection, VariableCollectionMode, VariableColorExpression, VariableFormula, VariableFormulaLiteral, VariableFormulaNode, VariableFormulaOperation, VariableFormulaOperator, VariableFormulaType, VariableLiteral, VariableModeMap, VariableScope, VariableType, VariableUnsupportedExpression, VariableValue, VariantPropSpec, VectorNetwork, VectorRegion, VectorSegment, VectorVertex, WindingRule, isLibraryCollection, isModeAttributeName } from "./types.js";
|
|
4
4
|
import { generateId, setIdSession } from "./ids.js";
|
|
5
|
-
export { ArcData, AxisSizingMode, BlendMode, CODE_SYNTAX_PLATFORMS, CharacterStyleOverride, CodeSyntaxPlatform, CommentReply, CommentThread, CommittedGraphEventError, ComponentPropertyDefinition, ComponentPropertyReference, ComponentPropertyReferenceField, ComponentPropertyType, ConnectorControlPoint, ConnectorEndpoint, ConnectorLabelPosition, ConnectorLineType, ConnectorMagnet, ConstraintType,
|
|
5
|
+
export { ArcData, AxisSizingMode, BlendMode, CODE_SYNTAX_PLATFORMS, CharacterStyleOverride, CodeSyntaxPlatform, ColorProfile, CommentReply, CommentThread, CommittedGraphEventError, ComponentPropertyDefinition, ComponentPropertyReference, ComponentPropertyReferenceField, ComponentPropertyType, ConnectorControlPoint, ConnectorEndpoint, ConnectorLabelPosition, ConnectorLineType, ConnectorMagnet, ConstraintType, CubicBezier, DerivedTextGlyph, DocumentKind, DocumentRecordKind, EASING_CURVES, Easing, EasingCurve, Effect, EnabledLibraryBinding, ExportColorProfile, ExportSetting, ExportSize, FigmaLayoutMetadata, FigmaSourcePayload, Fill, FillType, FontFeature, FontVariation, GeometryPath, GlassEffectParams, GradientStop, GradientTransform, GridPosition, GridTrack, GridTrackSizing, HandleMirroring, HyperlinkTarget, ImageFilters, ImageScaleMode, LayoutAlign, LayoutAlignSelf, LayoutCounterAlign, LayoutDirection, LayoutGrid, LayoutMode, LayoutSizing, LayoutWrap, LeadingTrim, LibraryAssetIdentity, LibraryAssetRef, LibraryAssetSource, MODE_ATTRIBUTE_PATTERN, MaskType, NodeChangeObserver, NodeType, NoiseEffectParams, NoiseType, NumericNodeProperty, PatternAlignment, PatternTileType, PluginDataEntry, PluginRelaunchDataEntry, ProgressiveBlur, SceneGraph, SceneGraphEventHandlers, SceneGraphEvents, SceneNode, SharedStyle, SharedStyleKind, SharedStyleType, SlotSettings, SourceLibraryPublication, SourceMetadata, Spring, Stroke, StrokeCap, StrokeJoin, StyleRun, SymbolLink, TEXT_BINDABLE_FIELDS, TOKEN_UNITS, TextAlignVertical, TextAutoResize, TextBindableField, TextBoundVariables, TextCase, TextDecoration, TextDecorationStyle, TextDirection, TextLength, TextListType, TextParagraphSpacingField, TextParagraphStyle, TextPathData, TextureEffectParams, TokenExpression, TokenUnit, VARIABLE_FORMULA_OPERATORS, VARIABLE_SCOPES, VARIABLE_TYPES, Variable, VariableAlias, VariableCollection, VariableCollectionMode, VariableColorExpression, VariableFormula, VariableFormulaLiteral, VariableFormulaNode, VariableFormulaOperation, VariableFormulaOperator, VariableFormulaType, VariableLiteral, VariableModeMap, VariableScope, VariableType, VariableUnsupportedExpression, VariableValue, VariantPropSpec, VectorNetwork, VectorRegion, VectorSegment, VectorVertex, WindingRule, generateId, isLibraryCollection, isModeAttributeName, setIdSession };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CommittedGraphEventError } from "./buffered-events.js";
|
|
2
2
|
import { generateId, setIdSession } from "./ids.js";
|
|
3
|
-
import { CODE_SYNTAX_PLATFORMS, MODE_ATTRIBUTE_PATTERN, TEXT_BINDABLE_FIELDS, TOKEN_UNITS, VARIABLE_FORMULA_OPERATORS, VARIABLE_SCOPES, isLibraryCollection, isModeAttributeName } from "./types.js";
|
|
3
|
+
import { CODE_SYNTAX_PLATFORMS, EASING_CURVES, MODE_ATTRIBUTE_PATTERN, TEXT_BINDABLE_FIELDS, TOKEN_UNITS, VARIABLE_FORMULA_OPERATORS, VARIABLE_SCOPES, VARIABLE_TYPES, isLibraryCollection, isModeAttributeName } from "./types.js";
|
|
4
4
|
import { SceneGraph } from "./graph.js";
|
|
5
|
-
export { CODE_SYNTAX_PLATFORMS, CommittedGraphEventError, MODE_ATTRIBUTE_PATTERN, SceneGraph, TEXT_BINDABLE_FIELDS, TOKEN_UNITS, VARIABLE_FORMULA_OPERATORS, VARIABLE_SCOPES, generateId, isLibraryCollection, isModeAttributeName, setIdSession };
|
|
5
|
+
export { CODE_SYNTAX_PLATFORMS, CommittedGraphEventError, EASING_CURVES, MODE_ATTRIBUTE_PATTERN, SceneGraph, TEXT_BINDABLE_FIELDS, TOKEN_UNITS, VARIABLE_FORMULA_OPERATORS, VARIABLE_SCOPES, VARIABLE_TYPES, generateId, isLibraryCollection, isModeAttributeName, setIdSession };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { resizedChildRect } from "../resize.js";
|
|
1
2
|
import { TEXT_METRIC_FIELDS, TEXT_SHAPING_FIELDS } from "../fields/text.js";
|
|
2
3
|
import { layoutSizing } from "../layout/sizing.js";
|
|
3
|
-
import { resizedChildRect } from "../resize.js";
|
|
4
4
|
import { isEqual } from "es-toolkit/predicate";
|
|
5
5
|
//#region src/instances/content-size.ts
|
|
6
6
|
const METRIC_FIELDS = new Set(TEXT_METRIC_FIELDS);
|
|
@@ -6,13 +6,13 @@ declare const INSTANCE_SYNC_TEXT_PROPS: readonly ["name", "text", "fontFamily",
|
|
|
6
6
|
* instance ("This property cannot be overridden in an instance"), so its copies always follow.
|
|
7
7
|
* A layer in an auto layout flow takes its position from the layout instead.
|
|
8
8
|
*/
|
|
9
|
-
declare const INSTANCE_FOLLOWED_FIELDS: readonly ["x", "y", "rotation", "flipX", "flipY", "horizontalConstraint", "verticalConstraint", "layoutPositioning", "counterAxisAlignContent", "isMask", "maskType", "maskIsOutline", "booleanOperation", "isExposedInstance", "connectorStart", "connectorEnd", "connectorLineType", "connectorStartCap", "connectorEndCap", "arcData", "pointCount", "starInnerRadius", "shapeWithTextType", "shapeUserHeight", "shapeTruncates"];
|
|
9
|
+
declare const INSTANCE_FOLLOWED_FIELDS: readonly ["x", "y", "rotation", "flipX", "flipY", "horizontalConstraint", "verticalConstraint", "layoutPositioning", "counterAxisAlignContent", "isMask", "maskType", "maskIsOutline", "booleanOperation", "isExposedInstance", "connectorStart", "connectorEnd", "connectorLineType", "connectorStartCap", "connectorEndCap", "arcData", "pointCount", "starInnerRadius", "shapeWithTextType", "slide", "animation", "shapeUserHeight", "shapeTruncates"];
|
|
10
10
|
/** Fields a component's layer gives its copies unless an instance overrides them. */
|
|
11
11
|
declare const INSTANCE_SYNC_PROPS: (keyof SceneNode)[];
|
|
12
12
|
/** Fields an edit to a layer inside an instance records as that instance's override. */
|
|
13
13
|
declare const INSTANCE_OVERRIDE_FIELDS: readonly [...(keyof SceneNode)[], "name", "text", "fontFamily", "fontSize", "fontWeight", "italic", "lineHeight", "letterSpacing", "paragraphSpacing", "paragraphIndent", "textAlignHorizontal", "textAlignVertical", "textCase", "textDecoration", "textDecorationStyle", "textDecorationThickness", "textUnderlineOffset", "textDecorationFills", "textDecorationSkipInk", "fontFeatures", "fontVariations", "opticalSizeFromFontSize", "textDirection", "textAutoResize", "textTruncation", "maxLines", "leadingTrim", "listSpacing", "hangingList", "styleRuns", "textParagraphs", "layoutGrow", "layoutAlignSelf", "locked", "visible"];
|
|
14
14
|
/** Fields a component's layer gives the copies of it in every instance. */
|
|
15
|
-
declare const INSTANCE_SYNC_FIELDS: readonly [...(keyof SceneNode)[], "name", "text", "fontFamily", "fontSize", "fontWeight", "italic", "lineHeight", "letterSpacing", "paragraphSpacing", "paragraphIndent", "textAlignHorizontal", "textAlignVertical", "textCase", "textDecoration", "textDecorationStyle", "textDecorationThickness", "textUnderlineOffset", "textDecorationFills", "textDecorationSkipInk", "fontFeatures", "fontVariations", "opticalSizeFromFontSize", "textDirection", "textAutoResize", "textTruncation", "maxLines", "leadingTrim", "listSpacing", "hangingList", "styleRuns", "textParagraphs", "layoutGrow", "layoutAlignSelf", "locked", "visible", "x", "y", "rotation", "flipX", "flipY", "horizontalConstraint", "verticalConstraint", "layoutPositioning", "counterAxisAlignContent", "isMask", "maskType", "maskIsOutline", "booleanOperation", "isExposedInstance", "connectorStart", "connectorEnd", "connectorLineType", "connectorStartCap", "connectorEndCap", "arcData", "pointCount", "starInnerRadius", "shapeWithTextType", "shapeUserHeight", "shapeTruncates"];
|
|
15
|
+
declare const INSTANCE_SYNC_FIELDS: readonly [...(keyof SceneNode)[], "name", "text", "fontFamily", "fontSize", "fontWeight", "italic", "lineHeight", "letterSpacing", "paragraphSpacing", "paragraphIndent", "textAlignHorizontal", "textAlignVertical", "textCase", "textDecoration", "textDecorationStyle", "textDecorationThickness", "textUnderlineOffset", "textDecorationFills", "textDecorationSkipInk", "fontFeatures", "fontVariations", "opticalSizeFromFontSize", "textDirection", "textAutoResize", "textTruncation", "maxLines", "leadingTrim", "listSpacing", "hangingList", "styleRuns", "textParagraphs", "layoutGrow", "layoutAlignSelf", "locked", "visible", "x", "y", "rotation", "flipX", "flipY", "horizontalConstraint", "verticalConstraint", "layoutPositioning", "counterAxisAlignContent", "isMask", "maskType", "maskIsOutline", "booleanOperation", "isExposedInstance", "connectorStart", "connectorEnd", "connectorLineType", "connectorStartCap", "connectorEndCap", "arcData", "pointCount", "starInnerRadius", "shapeWithTextType", "slide", "animation", "shapeUserHeight", "shapeTruncates"];
|
|
16
16
|
//#endregion
|
|
17
17
|
export { INSTANCE_FOLLOWED_FIELDS, INSTANCE_OVERRIDE_FIELDS, INSTANCE_SYNC_FIELDS, INSTANCE_SYNC_PROPS, INSTANCE_SYNC_TEXT_PROPS };
|
|
18
18
|
//# sourceMappingURL=fields.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fields.d.ts","names":[],"sources":["../../src/instances/fields.ts"],"mappings":";;cASa;;;;;;cA4BA;;
|
|
1
|
+
{"version":3,"file":"fields.d.ts","names":[],"sources":["../../src/instances/fields.ts"],"mappings":";;cASa;;;;;;cA4BA;;cA2BA,4BAA4B;;cAwB5B,8CAAwB;;cAQxB,0CAAoB"}
|
package/dist/instances/fields.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fields.js","names":[],"sources":["../../src/instances/fields.ts"],"sourcesContent":["import { difference } from 'es-toolkit/array'\n\nimport { CORNER_FIELDS, PAINT_FIELDS, STROKE_FIELDS } from '../fields/appearance'\nimport { SIZE_FIELDS, TRANSFORM_FIELDS } from '../fields/geometry'\nimport { AUTO_LAYOUT_FIELDS, SIZE_CONSTRAINT_FIELDS } from '../fields/layout'\nimport { TEXT_STYLE_FIELDS } from '../fields/text'\nimport { STYLE_LINK_FIELDS } from '../shared-styles'\nimport type { SceneNode } from '../types'\n\nexport const INSTANCE_SYNC_TEXT_PROPS = [\n 'name',\n 'text',\n ...TEXT_STYLE_FIELDS,\n 'textDirection',\n 'textAutoResize',\n 'textTruncation',\n 'maxLines',\n 'leadingTrim',\n 'listSpacing',\n 'hangingList',\n // Styled ranges belong to the characters: an instance that overrides its text keeps them.\n 'styleRuns',\n 'textParagraphs'\n] as const\n\n/** Fields that belong to another one: overriding the owner keeps them too. */\nexport const INSTANCE_SYNC_FIELD_OWNERS: Readonly<Partial<Record<string, string>>> = {\n fillStyleId: 'fills',\n styleRuns: 'text',\n textParagraphs: 'text'\n}\n\n/**\n * Where a component's layer sits and how it is shaped, which Figma refuses to override in an\n * instance (\"This property cannot be overridden in an instance\"), so its copies always follow.\n * A layer in an auto layout flow takes its position from the layout instead.\n */\nexport const INSTANCE_FOLLOWED_FIELDS = [\n ...TRANSFORM_FIELDS,\n 'horizontalConstraint',\n 'verticalConstraint',\n 'layoutPositioning',\n 'counterAxisAlignContent',\n 'isMask',\n 'maskType',\n 'maskIsOutline',\n 'booleanOperation',\n 'isExposedInstance',\n 'connectorStart',\n 'connectorEnd',\n 'connectorLineType',\n 'connectorStartCap',\n 'connectorEndCap',\n 'arcData',\n 'pointCount',\n 'starInnerRadius',\n 'shapeWithTextType',\n 'shapeUserHeight',\n 'shapeTruncates'\n] as const\n\n/** Fields a component's layer gives its copies unless an instance overrides them. */\nexport const INSTANCE_SYNC_PROPS: (keyof SceneNode)[] = difference(\n [\n ...SIZE_FIELDS,\n ...SIZE_CONSTRAINT_FIELDS,\n ...PAINT_FIELDS,\n ...STROKE_FIELDS,\n ...CORNER_FIELDS,\n ...AUTO_LAYOUT_FIELDS,\n 'itemReverseZIndex',\n 'gridPosition',\n 'clipsContent',\n 'layoutGrids',\n 'boundVariables',\n 'variableModes',\n // Applied shared styles follow the component unless an instance overrides them.\n ...STYLE_LINK_FIELDS\n ],\n INSTANCE_FOLLOWED_FIELDS\n)\n\n/** How a layer inside an instance sits in its parent and whether it is locked, which its overrides may change. */\nexport const INSTANCE_SYNC_CHILD_PROPS = ['layoutGrow', 'layoutAlignSelf', 'locked'] as const\n\n/** Fields an edit to a layer inside an instance records as that instance's override. */\nexport const INSTANCE_OVERRIDE_FIELDS = [\n ...INSTANCE_SYNC_PROPS,\n ...INSTANCE_SYNC_TEXT_PROPS,\n ...INSTANCE_SYNC_CHILD_PROPS,\n 'visible'\n] as const\n\n/** Fields a component's layer gives the copies of it in every instance. */\nexport const INSTANCE_SYNC_FIELDS = [\n ...INSTANCE_OVERRIDE_FIELDS,\n ...INSTANCE_FOLLOWED_FIELDS\n] as const\n"],"mappings":";;;;;;;AASA,MAAa,2BAA2B;CACtC;CACA;CACA,GAAG;CACH;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;AACF;;AAGA,MAAa,6BAAwE;CACnF,aAAa;CACb,WAAW;CACX,gBAAgB;AAClB;;;;;;AAOA,MAAa,2BAA2B;CACtC,GAAG;CACH;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;AAGA,MAAa,sBAA2C,WACtD;CACE,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH;CACA;CACA;CACA;CACA;CACA;CAEA,GAAG;AACL,GACA,wBACF;;AAGA,MAAa,4BAA4B;CAAC;CAAc;CAAmB;AAAQ;;AAGnF,MAAa,2BAA2B;CACtC,GAAG;CACH,GAAG;CACH,GAAG;CACH;AACF;;AAGA,MAAa,uBAAuB,CAClC,GAAG,0BACH,GAAG,wBACL"}
|
|
1
|
+
{"version":3,"file":"fields.js","names":[],"sources":["../../src/instances/fields.ts"],"sourcesContent":["import { difference } from 'es-toolkit/array'\n\nimport { CORNER_FIELDS, PAINT_FIELDS, STROKE_FIELDS } from '../fields/appearance'\nimport { SIZE_FIELDS, TRANSFORM_FIELDS } from '../fields/geometry'\nimport { AUTO_LAYOUT_FIELDS, SIZE_CONSTRAINT_FIELDS } from '../fields/layout'\nimport { TEXT_STYLE_FIELDS } from '../fields/text'\nimport { STYLE_LINK_FIELDS } from '../shared-styles'\nimport type { SceneNode } from '../types'\n\nexport const INSTANCE_SYNC_TEXT_PROPS = [\n 'name',\n 'text',\n ...TEXT_STYLE_FIELDS,\n 'textDirection',\n 'textAutoResize',\n 'textTruncation',\n 'maxLines',\n 'leadingTrim',\n 'listSpacing',\n 'hangingList',\n // Styled ranges belong to the characters: an instance that overrides its text keeps them.\n 'styleRuns',\n 'textParagraphs'\n] as const\n\n/** Fields that belong to another one: overriding the owner keeps them too. */\nexport const INSTANCE_SYNC_FIELD_OWNERS: Readonly<Partial<Record<string, string>>> = {\n fillStyleId: 'fills',\n styleRuns: 'text',\n textParagraphs: 'text'\n}\n\n/**\n * Where a component's layer sits and how it is shaped, which Figma refuses to override in an\n * instance (\"This property cannot be overridden in an instance\"), so its copies always follow.\n * A layer in an auto layout flow takes its position from the layout instead.\n */\nexport const INSTANCE_FOLLOWED_FIELDS = [\n ...TRANSFORM_FIELDS,\n 'horizontalConstraint',\n 'verticalConstraint',\n 'layoutPositioning',\n 'counterAxisAlignContent',\n 'isMask',\n 'maskType',\n 'maskIsOutline',\n 'booleanOperation',\n 'isExposedInstance',\n 'connectorStart',\n 'connectorEnd',\n 'connectorLineType',\n 'connectorStartCap',\n 'connectorEndCap',\n 'arcData',\n 'pointCount',\n 'starInnerRadius',\n 'shapeWithTextType',\n 'slide',\n 'animation',\n 'shapeUserHeight',\n 'shapeTruncates'\n] as const\n\n/** Fields a component's layer gives its copies unless an instance overrides them. */\nexport const INSTANCE_SYNC_PROPS: (keyof SceneNode)[] = difference(\n [\n ...SIZE_FIELDS,\n ...SIZE_CONSTRAINT_FIELDS,\n ...PAINT_FIELDS,\n ...STROKE_FIELDS,\n ...CORNER_FIELDS,\n ...AUTO_LAYOUT_FIELDS,\n 'itemReverseZIndex',\n 'gridPosition',\n 'clipsContent',\n 'layoutGrids',\n 'boundVariables',\n 'variableModes',\n // Applied shared styles follow the component unless an instance overrides them.\n ...STYLE_LINK_FIELDS\n ],\n INSTANCE_FOLLOWED_FIELDS\n)\n\n/** How a layer inside an instance sits in its parent and whether it is locked, which its overrides may change. */\nexport const INSTANCE_SYNC_CHILD_PROPS = ['layoutGrow', 'layoutAlignSelf', 'locked'] as const\n\n/** Fields an edit to a layer inside an instance records as that instance's override. */\nexport const INSTANCE_OVERRIDE_FIELDS = [\n ...INSTANCE_SYNC_PROPS,\n ...INSTANCE_SYNC_TEXT_PROPS,\n ...INSTANCE_SYNC_CHILD_PROPS,\n 'visible'\n] as const\n\n/** Fields a component's layer gives the copies of it in every instance. */\nexport const INSTANCE_SYNC_FIELDS = [\n ...INSTANCE_OVERRIDE_FIELDS,\n ...INSTANCE_FOLLOWED_FIELDS\n] as const\n"],"mappings":";;;;;;;AASA,MAAa,2BAA2B;CACtC;CACA;CACA,GAAG;CACH;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;AACF;;AAGA,MAAa,6BAAwE;CACnF,aAAa;CACb,WAAW;CACX,gBAAgB;AAClB;;;;;;AAOA,MAAa,2BAA2B;CACtC,GAAG;CACH;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;AAGA,MAAa,sBAA2C,WACtD;CACE,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH;CACA;CACA;CACA;CACA;CACA;CAEA,GAAG;AACL,GACA,wBACF;;AAGA,MAAa,4BAA4B;CAAC;CAAc;CAAmB;AAAQ;;AAGnF,MAAa,2BAA2B;CACtC,GAAG;CACH,GAAG;CACH,GAAG;CACH;AACF;;AAGA,MAAa,uBAAuB,CAClC,GAAG,0BACH,GAAG,wBACL"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/instances/index.ts"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/instances/index.ts"],"mappings":";;;;;;;iBA0DgB,2BAA2B,WAAW,YAAY,QAAQ;iBAM1D,eACd,OAAO,YACP,qBACA,kBACA,YAAW,QAAQ,aAClB;iBAoEa,yBACd,OAAO,YACP,oBACA,qBACA,OAAM;UAmCS;;;;;;EAMf;;iBAgBc,sBACd,OAAO,YACP,oBACA,uBACE,aAAoB;iBAuDR,cAAc,OAAO,YAAY;;;;;iBAQjC,sBAAsB,OAAO,YAAY,cAAc;;iBAOvD,aAAa,OAAO,YAAY;iBAwChC,eAAe,OAAO,YAAY;iBAwDlC,iBAAiB,OAAO,YAAY,qBAAqB;iBAMzD,aAAa,OAAO,YAAY,sBAAsB;;;;iBActD,oBAAoB,OAAO,YAAY,gBAAgB;;;;;iBAUvD,uBAAuB,MAAM,WAAW,SAAS,QAAQ;iBAMzD,uBACd,OAAO,YACP,gBACA,QAAQ"}
|
package/dist/instances/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { clearInstanceOverrides, cloneInstanceOverrideState, getInstanceOverride, hasInstanceOverride as hasInstanceOverride$1, setInstanceOverride } from "./overrides.js";
|
|
2
|
+
import { collectResizeDescendants, computeConstrainedResizeChanges, sharedResizeSnapshot } from "../resize.js";
|
|
2
3
|
import { findInstanceAncestor, instanceMainComponent } from "./main-component.js";
|
|
3
4
|
import { detachOwnedSlotContent, restoreOwnedSlotContent } from "../slots/frames.js";
|
|
4
5
|
import { changesMoreThanStrokeLines } from "../strokes.js";
|
|
@@ -9,8 +10,10 @@ import { canCreateInstance, createsComponentCycle, cycleSafeParent } from "./cyc
|
|
|
9
10
|
import { INSTANCE_FOLLOWED_FIELDS, INSTANCE_OVERRIDE_FIELDS, INSTANCE_SYNC_FIELDS, INSTANCE_SYNC_PROPS, INSTANCE_SYNC_TEXT_PROPS } from "./fields.js";
|
|
10
11
|
import { bindingProtection, enclosingInstanceOverrideFields, isProtectedSyncField, syncBindingFields } from "./protection.js";
|
|
11
12
|
import { walkInstanceSources } from "./source-walk.js";
|
|
12
|
-
import { applySyncedStrokeLines, cloneChildrenWithMapping, copyProp, sourceInTargetCoordinates, syncChildren, updateSyncedProps } from "./sync.js";
|
|
13
|
+
import { applySyncedStrokeLines, cloneChildrenWithMapping, copyProp, sourceInTargetCoordinates, syncChildren, updateSyncedProps, withSyncedStyleBindings } from "./sync.js";
|
|
13
14
|
import { followComponentLayers } from "./swap.js";
|
|
15
|
+
import { omitBy } from "es-toolkit/object";
|
|
16
|
+
import { isEmptyObject } from "es-toolkit/predicate";
|
|
14
17
|
//#region src/instances/index.ts
|
|
15
18
|
function copyInstanceComponentProps(component) {
|
|
16
19
|
const props = {};
|
|
@@ -30,9 +33,43 @@ function createInstance(graph, componentId, parentId, overrides = {}) {
|
|
|
30
33
|
componentId
|
|
31
34
|
});
|
|
32
35
|
cloneChildrenWithMapping(graph, component.id, instance.id);
|
|
36
|
+
placeCopiedChildrenForSize(graph, component, instance);
|
|
33
37
|
applyBoundPaintColorsIn(graph, instance.id);
|
|
34
38
|
return instance;
|
|
35
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Places a new instance's copies as its own size asks, from the size the component gave them.
|
|
42
|
+
* Cloning writes them at the component's size, in the instance's coordinates, so an instance
|
|
43
|
+
* created straight at another size would otherwise keep every layer at the component's size and
|
|
44
|
+
* place, while resizing it to the same size scales them; Figma scales a copy's `scale` layers
|
|
45
|
+
* however it reaches that size.
|
|
46
|
+
*/
|
|
47
|
+
function placeCopiedChildrenForSize(graph, component, instance) {
|
|
48
|
+
if (instance.childIds.length === 0) return;
|
|
49
|
+
const from = sourceInTargetCoordinates(component, instance.componentScale);
|
|
50
|
+
if (from.width === instance.width && from.height === instance.height) return;
|
|
51
|
+
const originals = collectResizeDescendants(graph, instance.id, sharedResizeSnapshot);
|
|
52
|
+
if (!originals) return;
|
|
53
|
+
for (let pass = 0; pass <= originals.size; pass++) {
|
|
54
|
+
const changes = computeConstrainedResizeChanges(graph, instance.id, from, instance, originals);
|
|
55
|
+
const resizesLayout = [...changes].some(([id, change]) => resizesLayoutFrame(graph, id, change));
|
|
56
|
+
for (const [id, change] of changes) writeChanged(graph, id, change);
|
|
57
|
+
if (!resizesLayout) return;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/** Writes only what differs: the plan places every layer, most of them where they already are. */
|
|
61
|
+
function writeChanged(graph, id, change) {
|
|
62
|
+
const node = graph.nodes.get(id);
|
|
63
|
+
if (!node) return;
|
|
64
|
+
const changed = omitBy(change, (value, key) => node[key] === value);
|
|
65
|
+
if (!isEmptyObject(changed)) graph.updateNode(id, changed);
|
|
66
|
+
}
|
|
67
|
+
function resizesLayoutFrame(graph, id, change) {
|
|
68
|
+
const node = graph.nodes.get(id);
|
|
69
|
+
if (!node || node.layoutMode === "NONE") return false;
|
|
70
|
+
const { width = node.width, height = node.height } = change;
|
|
71
|
+
return width !== node.width || height !== node.height;
|
|
72
|
+
}
|
|
36
73
|
function populateInstanceChildren(graph, instanceId, componentId, mode = "deep") {
|
|
37
74
|
const instance = graph.nodes.get(instanceId);
|
|
38
75
|
const component = graph.nodes.get(componentId);
|
|
@@ -127,16 +164,18 @@ function syncInstancesOf(graph, componentId, instances) {
|
|
|
127
164
|
if (syncing.has(componentId)) return;
|
|
128
165
|
syncing.add(componentId);
|
|
129
166
|
try {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
167
|
+
withSyncedStyleBindings(graph, () => {
|
|
168
|
+
groupCopyRemovals(graph, (removals) => {
|
|
169
|
+
for (const instance of instances) {
|
|
170
|
+
const source = sourceInTargetCoordinates(component, instance.componentScale);
|
|
171
|
+
const { updates, kept } = ownSyncedProps(graph, instance, source);
|
|
172
|
+
keepOwnContentSize(graph, updates, instance, source);
|
|
173
|
+
updateSyncedProps(graph, instance, updates, kept);
|
|
174
|
+
const context = createInstanceSyncContext(instance.id, instance.instanceOverrides);
|
|
175
|
+
syncChildren(graph, component.id, instance.id, instance.instanceOverrides, context);
|
|
176
|
+
removeLeftoverCopies(graph, context, removals);
|
|
177
|
+
}
|
|
178
|
+
});
|
|
140
179
|
});
|
|
141
180
|
} finally {
|
|
142
181
|
syncing.delete(componentId);
|