@open-pencil/scene-graph 0.17.0-beta.7 → 0.18.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/behaviours/index.d.ts +3 -2
- package/dist/behaviours/index.js +2 -1
- package/dist/behaviours/kinds.d.ts.map +1 -1
- package/dist/behaviours/kinds.js +15 -8
- package/dist/behaviours/kinds.js.map +1 -1
- package/dist/behaviours/model.d.ts +2 -2
- package/dist/behaviours/model.d.ts.map +1 -1
- package/dist/behaviours/model.js.map +1 -1
- package/dist/behaviours/schema.d.ts +136 -1
- package/dist/behaviours/schema.d.ts.map +1 -1
- package/dist/behaviours/schema.js +17 -2
- package/dist/behaviours/schema.js.map +1 -1
- package/dist/behaviours/spec.d.ts.map +1 -1
- package/dist/behaviours/spec.js +4 -0
- package/dist/behaviours/spec.js.map +1 -1
- package/dist/behaviours/transition.d.ts +23 -0
- package/dist/behaviours/transition.d.ts.map +1 -0
- package/dist/behaviours/transition.js +36 -0
- package/dist/behaviours/transition.js.map +1 -0
- package/dist/checkpoint.d.ts.map +1 -1
- package/dist/checkpoint.js +2 -0
- package/dist/checkpoint.js.map +1 -1
- package/dist/color/index.d.ts +12 -9
- package/dist/color/index.d.ts.map +1 -1
- package/dist/color/index.js +15 -25
- package/dist/color/index.js.map +1 -1
- package/dist/color/management.d.ts +51 -23
- package/dist/color/management.d.ts.map +1 -1
- package/dist/color/management.js +154 -149
- package/dist/color/management.js.map +1 -1
- package/dist/color/okhcl.d.ts +28 -10
- package/dist/color/okhcl.d.ts.map +1 -1
- package/dist/color/okhcl.js +56 -40
- package/dist/color/okhcl.js.map +1 -1
- package/dist/color/schema.d.ts +6 -1
- package/dist/color/schema.d.ts.map +1 -1
- package/dist/color/schema.js +10 -1
- package/dist/color/schema.js.map +1 -1
- package/dist/constraints.d.ts.map +1 -1
- package/dist/constraints.js +2 -1
- package/dist/constraints.js.map +1 -1
- package/dist/copy.d.ts +7 -1
- package/dist/copy.d.ts.map +1 -1
- package/dist/copy.js +22 -1
- package/dist/copy.js.map +1 -1
- package/dist/corners.d.ts +3 -1
- package/dist/corners.d.ts.map +1 -1
- package/dist/corners.js +3 -1
- package/dist/corners.js.map +1 -1
- package/dist/css/grid.js +1 -1
- package/dist/css/index.d.ts +3 -2
- package/dist/css/index.js +3 -2
- package/dist/css/motion.d.ts +12 -0
- package/dist/css/motion.d.ts.map +1 -0
- package/dist/css/motion.js +60 -0
- package/dist/css/motion.js.map +1 -0
- package/dist/css/shadows.d.ts +4 -3
- package/dist/css/shadows.d.ts.map +1 -1
- package/dist/css/shadows.js +8 -18
- package/dist/css/shadows.js.map +1 -1
- package/dist/css/values.d.ts +6 -3
- package/dist/css/values.d.ts.map +1 -1
- package/dist/css/values.js +23 -5
- package/dist/css/values.js.map +1 -1
- package/dist/fields/index.d.ts +2 -2
- package/dist/fields/index.js +2 -2
- package/dist/fields/layout.d.ts +3 -1
- package/dist/fields/layout.d.ts.map +1 -1
- package/dist/fields/layout.js +9 -1
- package/dist/fields/layout.js.map +1 -1
- package/dist/figjam/palette.js +1 -1
- package/dist/font-style.d.ts.map +1 -1
- package/dist/font-style.js +7 -3
- package/dist/font-style.js.map +1 -1
- package/dist/generated/index.d.ts +6 -2
- package/dist/generated/index.d.ts.map +1 -1
- package/dist/generated/index.js +14 -4
- package/dist/generated/index.js.map +1 -1
- package/dist/geometry.d.ts +6 -1
- package/dist/geometry.d.ts.map +1 -1
- package/dist/geometry.js +10 -2
- package/dist/geometry.js.map +1 -1
- package/dist/graph.d.ts +29 -4
- package/dist/graph.d.ts.map +1 -1
- package/dist/graph.js +59 -9
- package/dist/graph.js.map +1 -1
- package/dist/group-bounds.d.ts +5 -2
- package/dist/group-bounds.d.ts.map +1 -1
- package/dist/group-bounds.js +38 -8
- package/dist/group-bounds.js.map +1 -1
- package/dist/hit-test.d.ts.map +1 -1
- package/dist/hit-test.js +19 -8
- package/dist/hit-test.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/instances/content-size.js +1 -1
- package/dist/instances/fields.d.ts +2 -2
- package/dist/instances/fields.d.ts.map +1 -1
- package/dist/instances/fields.js +2 -0
- package/dist/instances/fields.js.map +1 -1
- package/dist/instances/index.d.ts.map +1 -1
- package/dist/instances/index.js +50 -11
- package/dist/instances/index.js.map +1 -1
- package/dist/instances/sync.js +67 -7
- package/dist/instances/sync.js.map +1 -1
- package/dist/layout/flow.d.ts +16 -0
- package/dist/layout/flow.d.ts.map +1 -0
- package/dist/layout/flow.js +34 -0
- package/dist/layout/flow.js.map +1 -0
- package/dist/layout/index.d.ts +4 -3
- package/dist/layout/index.js +4 -3
- package/dist/layout/keywords.d.ts.map +1 -1
- package/dist/layout/keywords.js +7 -1
- package/dist/layout/keywords.js.map +1 -1
- package/dist/layout/sizing.d.ts +9 -1
- package/dist/layout/sizing.d.ts.map +1 -1
- package/dist/layout/sizing.js +17 -1
- package/dist/layout/sizing.js.map +1 -1
- package/dist/layout/spacing.d.ts +7 -1
- package/dist/layout/spacing.d.ts.map +1 -1
- package/dist/layout/spacing.js +10 -1
- package/dist/layout/spacing.js.map +1 -1
- package/dist/mesh/geometry.d.ts +83 -0
- package/dist/mesh/geometry.d.ts.map +1 -0
- package/dist/mesh/geometry.js +441 -0
- package/dist/mesh/geometry.js.map +1 -0
- package/dist/mesh/index.d.ts +4 -0
- package/dist/mesh/index.js +4 -0
- package/dist/mesh/model.d.ts +28 -0
- package/dist/mesh/model.d.ts.map +1 -0
- package/dist/mesh/model.js +40 -0
- package/dist/mesh/model.js.map +1 -0
- package/dist/mesh/schema.d.ts +191 -0
- package/dist/mesh/schema.d.ts.map +1 -0
- package/dist/mesh/schema.js +56 -0
- package/dist/mesh/schema.js.map +1 -0
- package/dist/mutation-impact.d.ts +2 -0
- package/dist/mutation-impact.d.ts.map +1 -1
- package/dist/mutation-impact.js +18 -7
- package/dist/mutation-impact.js.map +1 -1
- package/dist/node-defaults.d.ts +3 -1
- package/dist/node-defaults.d.ts.map +1 -1
- package/dist/node-defaults.js +22 -6
- package/dist/node-defaults.js.map +1 -1
- package/dist/paints/index.d.ts +5 -3
- package/dist/paints/index.js +5 -3
- package/dist/paints/pattern.d.ts +5 -1
- package/dist/paints/pattern.d.ts.map +1 -1
- package/dist/paints/pattern.js +33 -1
- package/dist/paints/pattern.js.map +1 -1
- package/dist/paints/shows.d.ts +4 -1
- package/dist/paints/shows.d.ts.map +1 -1
- package/dist/paints/shows.js +8 -1
- package/dist/paints/shows.js.map +1 -1
- package/dist/paints/solid.d.ts +11 -0
- package/dist/paints/solid.d.ts.map +1 -0
- package/dist/paints/solid.js +18 -0
- package/dist/paints/solid.js.map +1 -0
- package/dist/paints/stills.d.ts +74 -0
- package/dist/paints/stills.d.ts.map +1 -0
- package/dist/paints/stills.js +113 -0
- package/dist/paints/stills.js.map +1 -0
- package/dist/plugin-data/field.d.ts.map +1 -1
- package/dist/plugin-data/field.js +2 -0
- package/dist/plugin-data/field.js.map +1 -1
- package/dist/plugin-data/fields.d.ts +67 -0
- package/dist/plugin-data/fields.d.ts.map +1 -1
- package/dist/plugin-data/fields.js +12 -7
- package/dist/plugin-data/fields.js.map +1 -1
- package/dist/resize.d.ts +10 -3
- package/dist/resize.d.ts.map +1 -1
- package/dist/resize.js +34 -3
- package/dist/resize.js.map +1 -1
- package/dist/scaling/index.d.ts +2 -2
- package/dist/scaling/index.js +2 -2
- package/dist/scaling/node.d.ts +2 -1
- package/dist/scaling/node.d.ts.map +1 -1
- package/dist/scaling/node.js +27 -7
- package/dist/scaling/node.js.map +1 -1
- package/dist/shaders/index.d.ts +2 -3
- package/dist/shaders/index.js +2 -3
- package/dist/shaders/model.d.ts +3 -11
- package/dist/shaders/model.d.ts.map +1 -1
- package/dist/shaders/model.js +13 -36
- package/dist/shaders/model.js.map +1 -1
- package/dist/shaders/schema.d.ts +1 -1
- package/dist/shaders/schema.js +1 -1
- package/dist/shaders/schema.js.map +1 -1
- package/dist/shape-with-text/document.js +276 -0
- package/dist/shape-with-text/document.js.map +1 -0
- package/dist/shape-with-text/geometry.d.ts +13 -1
- package/dist/shape-with-text/geometry.d.ts.map +1 -1
- package/dist/shape-with-text/geometry.js +103 -41
- package/dist/shape-with-text/geometry.js.map +1 -1
- package/dist/shape-with-text/index.d.ts +2 -2
- package/dist/shape-with-text/index.js +2 -2
- package/dist/shared-style-index.d.ts +21 -0
- package/dist/shared-style-index.d.ts.map +1 -0
- package/dist/shared-style-index.js +72 -0
- package/dist/shared-style-index.js.map +1 -0
- package/dist/shared-styles.d.ts +3 -3
- package/dist/shared-styles.d.ts.map +1 -1
- package/dist/shared-styles.js +16 -7
- package/dist/shared-styles.js.map +1 -1
- package/dist/slides/drop.d.ts +32 -0
- package/dist/slides/drop.d.ts.map +1 -0
- package/dist/slides/drop.js +81 -0
- package/dist/slides/drop.js.map +1 -0
- package/dist/slides/index.d.ts +56 -0
- package/dist/slides/index.d.ts.map +1 -0
- package/dist/slides/index.js +134 -0
- package/dist/slides/index.js.map +1 -0
- package/dist/slides/motion.d.ts +55 -0
- package/dist/slides/motion.d.ts.map +1 -0
- package/dist/slides/motion.js +142 -0
- package/dist/slides/motion.js.map +1 -0
- package/dist/slides/playback.d.ts +59 -0
- package/dist/slides/playback.d.ts.map +1 -0
- package/dist/slides/playback.js +188 -0
- package/dist/slides/playback.js.map +1 -0
- package/dist/slides/types.d.ts +62 -0
- package/dist/slides/types.d.ts.map +1 -0
- package/dist/slides/types.js +39 -0
- package/dist/slides/types.js.map +1 -0
- package/dist/statuses/workflow.js +1 -1
- package/dist/text/direction.d.ts +6 -3
- package/dist/text/direction.d.ts.map +1 -1
- package/dist/text/direction.js +12 -12
- package/dist/text/direction.js.map +1 -1
- package/dist/text/index.d.ts +2 -1
- package/dist/text/index.js +3 -2
- package/dist/text/name.d.ts +22 -0
- package/dist/text/name.d.ts.map +1 -0
- package/dist/text/name.js +38 -0
- package/dist/text/name.js.map +1 -0
- package/dist/text/references.d.ts.map +1 -1
- package/dist/text/references.js +1 -2
- package/dist/text/references.js.map +1 -1
- package/dist/thumbnail.d.ts +23 -0
- package/dist/thumbnail.d.ts.map +1 -0
- package/dist/thumbnail.js +47 -0
- package/dist/thumbnail.js.map +1 -0
- package/dist/transfer/apply.d.ts.map +1 -1
- package/dist/transfer/apply.js +14 -3
- package/dist/transfer/apply.js.map +1 -1
- package/dist/transfer/copied.d.ts +6 -1
- package/dist/transfer/copied.d.ts.map +1 -1
- package/dist/transfer/copied.js +2 -2
- package/dist/transfer/copied.js.map +1 -1
- package/dist/transfer/dependencies.d.ts +4 -1
- package/dist/transfer/dependencies.d.ts.map +1 -1
- package/dist/transfer/dependencies.js +10 -1
- package/dist/transfer/dependencies.js.map +1 -1
- package/dist/transfer/history.js +2 -0
- package/dist/transfer/history.js.map +1 -1
- package/dist/transfer/identity.js +18 -3
- package/dist/transfer/identity.js.map +1 -1
- package/dist/transfer/index.d.ts +2 -1
- package/dist/transfer/index.js +4 -3
- package/dist/transfer/library.d.ts +45 -0
- package/dist/transfer/library.d.ts.map +1 -0
- package/dist/transfer/library.js +102 -0
- package/dist/transfer/library.js.map +1 -0
- package/dist/transfer/nodes.d.ts.map +1 -1
- package/dist/transfer/nodes.js +9 -0
- package/dist/transfer/nodes.js.map +1 -1
- package/dist/transfer/plan.d.ts +9 -0
- package/dist/transfer/plan.d.ts.map +1 -1
- package/dist/transfer/plan.js +51 -6
- package/dist/transfer/plan.js.map +1 -1
- package/dist/transfer/remove.js +7 -1
- package/dist/transfer/remove.js.map +1 -1
- package/dist/transfer/validation.js +8 -4
- package/dist/transfer/validation.js.map +1 -1
- package/dist/transfer/variables.d.ts.map +1 -1
- package/dist/transfer/variables.js +2 -1
- package/dist/transfer/variables.js.map +1 -1
- package/dist/types.d.ts +91 -13
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +33 -1
- package/dist/types.js.map +1 -1
- package/dist/variables/bindings.d.ts +11 -6
- package/dist/variables/bindings.d.ts.map +1 -1
- package/dist/variables/bindings.js +162 -38
- package/dist/variables/bindings.js.map +1 -1
- package/dist/variables/easing.d.ts +48 -0
- package/dist/variables/easing.d.ts.map +1 -0
- package/dist/variables/easing.js +321 -0
- package/dist/variables/easing.js.map +1 -0
- package/dist/variables/formula/index.d.ts +4 -2
- package/dist/variables/formula/index.d.ts.map +1 -1
- package/dist/variables/formula/index.js +26 -9
- package/dist/variables/formula/index.js.map +1 -1
- package/dist/variables/formula/parse.js +1 -1
- package/dist/variables/formula/schema.js +1 -1
- package/dist/variables/formula/signatures.d.ts +2 -2
- package/dist/variables/formula/signatures.d.ts.map +1 -1
- package/dist/variables/formula/signatures.js.map +1 -1
- package/dist/variables/formula/tree.d.ts +2 -2
- package/dist/variables/formula/tree.d.ts.map +1 -1
- package/dist/variables/formula/tree.js.map +1 -1
- package/dist/variables/index.d.ts +22 -5
- package/dist/variables/index.d.ts.map +1 -1
- package/dist/variables/index.js +67 -17
- package/dist/variables/index.js.map +1 -1
- package/dist/variables/lookup.js +1 -1
- package/dist/variables/lookup.js.map +1 -1
- package/dist/variables/motion.d.ts +46 -0
- package/dist/variables/motion.d.ts.map +1 -0
- package/dist/variables/motion.js +107 -0
- package/dist/variables/motion.js.map +1 -0
- package/dist/variables/paints.d.ts +10 -2
- package/dist/variables/paints.d.ts.map +1 -1
- package/dist/variables/paints.js +24 -10
- package/dist/variables/paints.js.map +1 -1
- package/dist/variables/resolution.d.ts.map +1 -1
- package/dist/variables/resolution.js +10 -9
- package/dist/variables/resolution.js.map +1 -1
- package/dist/variables/schema.d.ts +59 -1
- package/dist/variables/schema.d.ts.map +1 -1
- package/dist/variables/schema.js +36 -1
- package/dist/variables/schema.js.map +1 -1
- package/dist/variables/style-bindings.d.ts +23 -0
- package/dist/variables/style-bindings.d.ts.map +1 -0
- package/dist/variables/style-bindings.js +83 -0
- package/dist/variables/style-bindings.js.map +1 -0
- package/package.json +21 -2
- package/src/behaviours/index.ts +1 -0
- package/src/behaviours/kinds.ts +5 -1
- package/src/behaviours/model.ts +2 -2
- package/src/behaviours/schema.ts +19 -2
- package/src/behaviours/spec.ts +5 -0
- package/src/behaviours/transition.ts +46 -0
- package/src/checkpoint.ts +2 -0
- package/src/color/index.ts +15 -24
- package/src/color/management.ts +144 -168
- package/src/color/okhcl.ts +62 -43
- package/src/color/schema.ts +13 -0
- package/src/constraints.ts +2 -1
- package/src/copy.ts +29 -0
- package/src/corners.ts +3 -0
- package/src/css/index.ts +2 -0
- package/src/css/motion.ts +51 -0
- package/src/css/shadows.ts +8 -23
- package/src/css/values.ts +34 -4
- package/src/fields/layout.ts +9 -0
- package/src/font-style.ts +8 -3
- package/src/generated/index.ts +15 -3
- package/src/geometry.ts +13 -1
- package/src/graph.ts +72 -9
- package/src/group-bounds.ts +54 -13
- package/src/hit-test.ts +13 -8
- package/src/instances/fields.ts +2 -0
- package/src/instances/index.ts +71 -12
- package/src/instances/sync.ts +93 -11
- package/src/layout/flow.ts +34 -0
- package/src/layout/index.ts +1 -0
- package/src/layout/keywords.ts +7 -1
- package/src/layout/sizing.ts +30 -0
- package/src/layout/spacing.ts +12 -0
- package/src/mesh/geometry.ts +433 -0
- package/src/mesh/index.ts +3 -0
- package/src/mesh/model.ts +50 -0
- package/src/mesh/schema.ts +81 -0
- package/src/mutation-impact.ts +23 -7
- package/src/node-defaults.ts +22 -5
- package/src/paints/index.ts +2 -0
- package/src/paints/pattern.ts +55 -0
- package/src/paints/shows.ts +9 -0
- package/src/paints/solid.ts +10 -0
- package/src/paints/stills.ts +182 -0
- package/src/plugin-data/field.ts +3 -0
- package/src/plugin-data/fields.ts +15 -2
- package/src/resize.ts +32 -20
- package/src/scaling/index.ts +1 -1
- package/src/scaling/node.ts +43 -6
- package/src/shaders/index.ts +0 -1
- package/src/shaders/model.ts +19 -49
- package/src/shaders/schema.ts +1 -1
- package/src/shape-with-text/document.ts +175 -0
- package/src/shape-with-text/geometry.ts +99 -27
- package/src/shared-style-index.ts +106 -0
- package/src/shared-styles.ts +21 -14
- package/src/slides/drop.ts +94 -0
- package/src/slides/index.ts +125 -0
- package/src/slides/motion.ts +169 -0
- package/src/slides/playback.ts +200 -0
- package/src/slides/types.ts +94 -0
- package/src/text/direction.ts +13 -23
- package/src/text/index.ts +1 -0
- package/src/text/name.ts +39 -0
- package/src/text/references.ts +3 -3
- package/src/thumbnail.ts +52 -0
- package/src/transfer/apply.ts +16 -3
- package/src/transfer/copied.ts +7 -2
- package/src/transfer/dependencies.ts +10 -1
- package/src/transfer/history.ts +2 -0
- package/src/transfer/identity.ts +34 -2
- package/src/transfer/index.ts +6 -0
- package/src/transfer/library.ts +153 -0
- package/src/transfer/nodes.ts +20 -0
- package/src/transfer/plan.ts +96 -10
- package/src/transfer/remove.ts +6 -2
- package/src/transfer/validation.ts +15 -7
- package/src/transfer/variables.ts +8 -2
- package/src/types.ts +115 -11
- package/src/variables/bindings.ts +260 -36
- package/src/variables/easing.ts +282 -0
- package/src/variables/formula/index.ts +33 -14
- package/src/variables/formula/signatures.ts +6 -2
- package/src/variables/formula/tree.ts +3 -3
- package/src/variables/index.ts +90 -37
- package/src/variables/lookup.ts +1 -1
- package/src/variables/motion.ts +151 -0
- package/src/variables/paints.ts +29 -7
- package/src/variables/resolution.ts +11 -5
- package/src/variables/schema.ts +41 -0
- package/src/variables/style-bindings.ts +137 -0
- package/dist/shaders/still.d.ts +0 -18
- package/dist/shaders/still.d.ts.map +0 -1
- package/dist/shaders/still.js +0 -36
- package/dist/shaders/still.js.map +0 -1
- package/src/shaders/still.ts +0 -41
package/src/corners.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import type { SceneNode } from './types'
|
|
2
2
|
|
|
3
|
+
/** The radius a pill takes: round at the ends at any size a layer reaches. */
|
|
4
|
+
export const PILL_RADIUS = 9999
|
|
5
|
+
|
|
3
6
|
/** A rectangle's corner radii, clockwise from the top left. */
|
|
4
7
|
export type CornerRadii = [
|
|
5
8
|
topLeft: number,
|
package/src/css/index.ts
CHANGED
|
@@ -8,6 +8,7 @@ export {
|
|
|
8
8
|
parseCSSJustifyContent,
|
|
9
9
|
type CSSAspectRatio
|
|
10
10
|
} from './layout'
|
|
11
|
+
export { parseCSSEasing, parseCSSTime } from './motion'
|
|
11
12
|
export { parseCSSShadows } from './shadows'
|
|
12
13
|
export {
|
|
13
14
|
CSS_GENERIC_FONT_FAMILIES,
|
|
@@ -34,5 +35,6 @@ export {
|
|
|
34
35
|
parseCSSURLs,
|
|
35
36
|
parsePaintFallback,
|
|
36
37
|
parseFragmentReference,
|
|
38
|
+
splitCSSLayers,
|
|
37
39
|
splitCSSValue
|
|
38
40
|
} from './values'
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import valueParser from 'postcss-value-parser'
|
|
2
|
+
|
|
3
|
+
import type { Easing } from '../types'
|
|
4
|
+
import { easingForBezier, easingPreset } from '../variables/easing'
|
|
5
|
+
import { dimension } from './values'
|
|
6
|
+
|
|
7
|
+
/** A CSS `<time>` in seconds: `250ms` or `0.25s`; a bare number is seconds. Null otherwise. */
|
|
8
|
+
export function parseCSSTime(value: string): number | null {
|
|
9
|
+
const parsed = dimension(value.trim())
|
|
10
|
+
if (!parsed) return null
|
|
11
|
+
if (parsed.unit === 'ms') return parsed.number / 1000
|
|
12
|
+
return parsed.unit === 's' || parsed.unit === '' ? parsed.number : null
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** The CSS keywords that name one of Figma's curves, and `step-end`, which holds. */
|
|
16
|
+
const KEYWORD_CURVES: Partial<Record<string, Easing['easing']>> = {
|
|
17
|
+
linear: 'LINEAR',
|
|
18
|
+
'ease-in': 'EASE_IN',
|
|
19
|
+
'ease-out': 'OUT_CUBIC',
|
|
20
|
+
'ease-in-out': 'INOUT_CUBIC',
|
|
21
|
+
'step-end': 'HOLD'
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* A CSS easing function as an easing: a keyword Figma has a preset for, `ease`, or
|
|
26
|
+
* `cubic-bezier(x1, y1, x2, y2)` with both x between 0 and 1. Null for anything else.
|
|
27
|
+
*/
|
|
28
|
+
export function parseCSSEasing(value: string): Easing | null {
|
|
29
|
+
const nodes = valueParser(value.trim()).nodes.filter((node) => node.type !== 'space')
|
|
30
|
+
const [node] = nodes
|
|
31
|
+
if (nodes.length !== 1) return null
|
|
32
|
+
if (node.type === 'word') {
|
|
33
|
+
const keyword = node.value.toLowerCase()
|
|
34
|
+
if (keyword === 'ease')
|
|
35
|
+
return { easing: 'CUSTOM_CUBIC', bezier: { x1: 0.25, y1: 0.1, x2: 0.25, y2: 1 } }
|
|
36
|
+
const curve = KEYWORD_CURVES[keyword]
|
|
37
|
+
return curve ? easingPreset(curve) : null
|
|
38
|
+
}
|
|
39
|
+
if (node.type !== 'function' || node.value.toLowerCase() !== 'cubic-bezier') return null
|
|
40
|
+
// Exactly four numbers between commas: nothing else, such as a fifth argument or a function.
|
|
41
|
+
const parts = node.nodes.filter((part) => part.type !== 'space')
|
|
42
|
+
const separated = parts.every((part, index) =>
|
|
43
|
+
index % 2 === 0 ? part.type === 'word' : part.type === 'div' && part.value === ','
|
|
44
|
+
)
|
|
45
|
+
if (parts.length !== 7 || !separated) return null
|
|
46
|
+
const numbers = parts.filter((_, index) => index % 2 === 0).map((part) => dimension(part.value))
|
|
47
|
+
if (numbers.some((number) => number?.unit !== '')) return null
|
|
48
|
+
const [x1, y1, x2, y2] = numbers.map((number) => number?.number ?? 0)
|
|
49
|
+
if (x1 < 0 || x1 > 1 || x2 < 0 || x2 > 1) return null
|
|
50
|
+
return easingForBezier({ x1, y1, x2, y2 })
|
|
51
|
+
}
|
package/src/css/shadows.ts
CHANGED
|
@@ -3,30 +3,14 @@ import valueParser, { type Node } from 'postcss-value-parser'
|
|
|
3
3
|
import { tryParseColor } from '../color'
|
|
4
4
|
import { BLACK } from '../constants'
|
|
5
5
|
import type { Color } from '../primitives'
|
|
6
|
-
import type { Effect } from '../types'
|
|
7
|
-
import { parseCSSNumber } from './values'
|
|
8
|
-
|
|
9
|
-
/** The layers of a shadow list, split at its top-level commas. */
|
|
10
|
-
function layersOf(nodes: Node[]): Node[][] {
|
|
11
|
-
const layers: Node[][] = []
|
|
12
|
-
let current: Node[] = []
|
|
13
|
-
for (const node of nodes) {
|
|
14
|
-
if (node.type === 'div' && node.value === ',') {
|
|
15
|
-
layers.push(current)
|
|
16
|
-
current = []
|
|
17
|
-
} else if (node.type !== 'space' && node.type !== 'comment') {
|
|
18
|
-
current.push(node)
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
layers.push(current)
|
|
22
|
-
return layers
|
|
23
|
-
}
|
|
6
|
+
import type { ColorProfile, Effect } from '../types'
|
|
7
|
+
import { cssLayerNodes, parseCSSNumber } from './values'
|
|
24
8
|
|
|
25
9
|
/**
|
|
26
10
|
* One layer: `inset`, two to four lengths, and a color in any order. Without a color it is
|
|
27
11
|
* black, as `currentColor` usually is; a layer with anything else, such as `none`, is dropped.
|
|
28
12
|
*/
|
|
29
|
-
function shadowOf(nodes: Node[]): Effect[] {
|
|
13
|
+
function shadowOf(nodes: Node[], profile: ColorProfile): Effect[] {
|
|
30
14
|
let inset = false
|
|
31
15
|
let color: Color | null = null
|
|
32
16
|
const lengths: number[] = []
|
|
@@ -40,7 +24,7 @@ function shadowOf(nodes: Node[]): Effect[] {
|
|
|
40
24
|
lengths.push(length)
|
|
41
25
|
continue
|
|
42
26
|
}
|
|
43
|
-
const parsed = tryParseColor(valueParser.stringify(node))
|
|
27
|
+
const parsed = tryParseColor(valueParser.stringify(node), profile)
|
|
44
28
|
if (!parsed || color) return []
|
|
45
29
|
color = parsed
|
|
46
30
|
}
|
|
@@ -60,9 +44,10 @@ function shadowOf(nodes: Node[]): Effect[] {
|
|
|
60
44
|
|
|
61
45
|
/**
|
|
62
46
|
* The shadows of a CSS `box-shadow` or `text-shadow` list, such as
|
|
63
|
-
* `0 4px 8px rgb(0 0 0 / 0.2), inset 0 1px #fff`: drop shadows, and inner shadows for `inset
|
|
47
|
+
* `0 4px 8px rgb(0 0 0 / 0.2), inset 0 1px #fff`: drop shadows, and inner shadows for `inset`,
|
|
48
|
+
* their colors read into `profile`.
|
|
64
49
|
*/
|
|
65
|
-
export function parseCSSShadows(value: string | undefined): Effect[] {
|
|
50
|
+
export function parseCSSShadows(value: string | undefined, profile: ColorProfile): Effect[] {
|
|
66
51
|
if (!value) return []
|
|
67
|
-
return
|
|
52
|
+
return cssLayerNodes(valueParser(value).nodes).flatMap((layer) => shadowOf(layer, profile))
|
|
68
53
|
}
|
package/src/css/values.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { compact } from 'es-toolkit'
|
|
2
|
-
import valueParser from 'postcss-value-parser'
|
|
2
|
+
import valueParser, { type Node } from 'postcss-value-parser'
|
|
3
3
|
import { decode, parsePath } from 'ufo'
|
|
4
4
|
|
|
5
5
|
import { tryParseColor } from '../color'
|
|
6
6
|
import type { Color } from '../primitives'
|
|
7
|
+
import type { ColorProfile } from '../types'
|
|
7
8
|
|
|
8
9
|
/** A CSS dimension's number and lowercase unit, or null. */
|
|
9
10
|
export function dimension(value: string): { number: number; unit: string } | null {
|
|
@@ -37,13 +38,42 @@ export function parseCSSNumber(value: string | undefined): number | null {
|
|
|
37
38
|
}
|
|
38
39
|
}
|
|
39
40
|
|
|
40
|
-
/** A CSS color that paints something
|
|
41
|
-
export function parseCSSColor(
|
|
41
|
+
/** A CSS color that paints something, as components in `profile`; null for an invalid or transparent one. */
|
|
42
|
+
export function parseCSSColor(
|
|
43
|
+
value: string | undefined,
|
|
44
|
+
profile: ColorProfile = 'srgb'
|
|
45
|
+
): Color | null {
|
|
42
46
|
if (!value) return null
|
|
43
|
-
const color = tryParseColor(value.trim())
|
|
47
|
+
const color = tryParseColor(value.trim(), profile)
|
|
44
48
|
return color && color.a > 0 ? color : null
|
|
45
49
|
}
|
|
46
50
|
|
|
51
|
+
/**
|
|
52
|
+
* The layers of a comma-separated CSS list, such as `box-shadow` or `background-image`, split at
|
|
53
|
+
* its top-level commas, each without its spaces and comments.
|
|
54
|
+
*/
|
|
55
|
+
export function cssLayerNodes(nodes: readonly Node[]): Node[][] {
|
|
56
|
+
const layers: Node[][] = []
|
|
57
|
+
let current: Node[] = []
|
|
58
|
+
for (const node of nodes) {
|
|
59
|
+
if (node.type === 'div' && node.value === ',') {
|
|
60
|
+
layers.push(current)
|
|
61
|
+
current = []
|
|
62
|
+
} else if (node.type !== 'space' && node.type !== 'comment') {
|
|
63
|
+
current.push(node)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
layers.push(current)
|
|
67
|
+
return layers
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** The layers of a comma-separated CSS list as text, each its parts joined by single spaces. */
|
|
71
|
+
export function splitCSSLayers(value: string): string[] {
|
|
72
|
+
return cssLayerNodes(valueParser(value).nodes).map((layer) =>
|
|
73
|
+
layer.map((node) => valueParser.stringify(node)).join(' ')
|
|
74
|
+
)
|
|
75
|
+
}
|
|
76
|
+
|
|
47
77
|
/** The space-separated parts of a CSS value, keeping functions such as `rgb(0, 0, 0)` whole. */
|
|
48
78
|
export function splitCSSValue(value: string): string[] {
|
|
49
79
|
return valueParser(value)
|
package/src/fields/layout.ts
CHANGED
|
@@ -46,3 +46,12 @@ export const LAYOUT_AFFECTING_KEYS: ReadonlySet<string> = new Set([
|
|
|
46
46
|
'gridPosition',
|
|
47
47
|
...SIZE_CONSTRAINT_FIELDS
|
|
48
48
|
])
|
|
49
|
+
|
|
50
|
+
/** Fields layout never reads, so an edit to these alone leaves every layer where it is. */
|
|
51
|
+
export const LAYOUT_NEUTRAL_FIELDS: ReadonlySet<string> = new Set([
|
|
52
|
+
'name',
|
|
53
|
+
'locked',
|
|
54
|
+
'expanded',
|
|
55
|
+
'exportSettings',
|
|
56
|
+
'pluginData'
|
|
57
|
+
] satisfies (keyof SceneNode)[])
|
package/src/font-style.ts
CHANGED
|
@@ -100,9 +100,14 @@ export function normalizeFontFamily(family: string): string {
|
|
|
100
100
|
return family.replace(/\s+(Variable|\d+(?:pt|px|em))$/i, '')
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
+
/** The name of the standard weight nearest `weight`, from Thin at 100 to Black at 900. */
|
|
104
|
+
function weightName(weight: number): string {
|
|
105
|
+
const nearest = Math.min(900, Math.max(100, Math.round(weight / 100) * 100))
|
|
106
|
+
return FONT_WEIGHT_NAMES[nearest] ?? 'Regular'
|
|
107
|
+
}
|
|
108
|
+
|
|
103
109
|
export function faceLoadKey(weight: number, italic = false): string {
|
|
104
|
-
const
|
|
105
|
-
const label = FONT_WEIGHT_NAMES[rounded] ?? 'Regular'
|
|
110
|
+
const label = weightName(weight)
|
|
106
111
|
return italic ? `${label} Italic` : label
|
|
107
112
|
}
|
|
108
113
|
|
|
@@ -111,7 +116,7 @@ export function faceLoadKey(weight: number, italic = false): string {
|
|
|
111
116
|
* for the regular weight), for a face whose font has not said its own.
|
|
112
117
|
*/
|
|
113
118
|
export function standardStyleName(weight: number, italic = false): string {
|
|
114
|
-
const label =
|
|
119
|
+
const label = weightName(weight)
|
|
115
120
|
if (!italic) return label
|
|
116
121
|
return label === 'Regular' ? 'Italic' : `${label} Italic`
|
|
117
122
|
}
|
package/src/generated/index.ts
CHANGED
|
@@ -61,14 +61,26 @@ export function withGeneratedFrameSize(
|
|
|
61
61
|
return { ...kind.sized(changes, node), ...changes }
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
/**
|
|
64
|
+
/** A deck's slides, and the rows and grid that lay them out: their size and place are the deck's. */
|
|
65
|
+
export const DECK_TYPES: ReadonlySet<NodeType> = new Set<NodeType>([
|
|
66
|
+
'SLIDE',
|
|
67
|
+
'SLIDE_ROW',
|
|
68
|
+
'SLIDE_GRID'
|
|
69
|
+
])
|
|
70
|
+
|
|
71
|
+
/** Whether a layer is placed by its X and Y: any but a deck's slides, rows, and grid. */
|
|
72
|
+
export function layerMoves(node: Pick<SceneNode, 'type'>): boolean {
|
|
73
|
+
return !DECK_TYPES.has(node.type)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Whether a layer turns: any layer but a generated frame that stays upright, or a deck's slides. */
|
|
65
77
|
export function layerRotates(node: Pick<SceneNode, 'type'>): boolean {
|
|
66
|
-
return generatedFrameKind(node)?.rotates ?? true
|
|
78
|
+
return !DECK_TYPES.has(node.type) && (generatedFrameKind(node)?.rotates ?? true)
|
|
67
79
|
}
|
|
68
80
|
|
|
69
81
|
/** Whether a layer's resize handles and W and H fields resize it freely. */
|
|
70
82
|
export function layerResizes(node: Pick<SceneNode, 'type'>): boolean {
|
|
71
|
-
return generatedFrameKind(node)?.resizes ?? true
|
|
83
|
+
return !DECK_TYPES.has(node.type) && (generatedFrameKind(node)?.resizes ?? true)
|
|
72
84
|
}
|
|
73
85
|
|
|
74
86
|
export type { GeneratedFrameKind } from './kind'
|
package/src/geometry.ts
CHANGED
|
@@ -216,7 +216,8 @@ const SIDE_STROKE_TYPES: ReadonlySet<string> = new Set<SceneNode['type']>([
|
|
|
216
216
|
'COMPONENT',
|
|
217
217
|
'INSTANCE',
|
|
218
218
|
'SECTION',
|
|
219
|
-
'GROUP'
|
|
219
|
+
'GROUP',
|
|
220
|
+
'SLIDE'
|
|
220
221
|
])
|
|
221
222
|
|
|
222
223
|
/**
|
|
@@ -227,6 +228,17 @@ export function drawsStrokeSides(node: StrokeSidesInput): boolean {
|
|
|
227
228
|
return node.independentStrokeWeights === true && (!node.type || SIDE_STROKE_TYPES.has(node.type))
|
|
228
229
|
}
|
|
229
230
|
|
|
231
|
+
/**
|
|
232
|
+
* Whether `stroke` draws anything on `node`. A zero weight draws nothing, as in Figma, unless the
|
|
233
|
+
* node strokes each side by its own weight.
|
|
234
|
+
*/
|
|
235
|
+
export function drawsStroke(
|
|
236
|
+
node: StrokeSidesInput,
|
|
237
|
+
stroke: Pick<Stroke, 'visible' | 'weight'>
|
|
238
|
+
): boolean {
|
|
239
|
+
return stroke.visible && (stroke.weight > 0 || drawsStrokeSides(node))
|
|
240
|
+
}
|
|
241
|
+
|
|
230
242
|
/** The share of a stroke's weight that lies outside the shape it outlines. */
|
|
231
243
|
export function strokeAlignShare(align: Stroke['align']): number {
|
|
232
244
|
if (align === 'OUTSIDE') return 1
|
package/src/graph.ts
CHANGED
|
@@ -15,7 +15,7 @@ import { cloneNodeProps, type NodeCloneMode } from './copy'
|
|
|
15
15
|
import { bindNodeEvents } from './events'
|
|
16
16
|
import { TRANSFORM_FIELDS } from './fields/geometry'
|
|
17
17
|
import { LAYOUT_AFFECTING_KEYS } from './fields/layout'
|
|
18
|
-
import { withGeneratedFrameSize } from './generated'
|
|
18
|
+
import { isGeneratedFrame, withGeneratedFrameSize } from './generated'
|
|
19
19
|
import * as HitTest from './hit-test'
|
|
20
20
|
import { generateId } from './ids'
|
|
21
21
|
import * as Instances from './instances'
|
|
@@ -24,18 +24,21 @@ import Matrix from './matrix'
|
|
|
24
24
|
import { CONTAINER_TYPES, createDefaultNode } from './node-defaults'
|
|
25
25
|
import { updateNodePreview, type NodePreviewObserver } from './preview'
|
|
26
26
|
import type { Color, Rect, Vector } from './primitives'
|
|
27
|
+
import { SharedStyleIndex } from './shared-style-index'
|
|
27
28
|
import { markSourceFieldsEdited } from './source-metadata'
|
|
28
29
|
import { strokeLineChanges } from './strokes'
|
|
30
|
+
import { newTextNameChanges, textNameChanges } from './text/name'
|
|
29
31
|
import { textCacheInvalidationChanges } from './text/picture'
|
|
30
32
|
import { remapCopiedReferences } from './transfer/copied'
|
|
31
33
|
import type {
|
|
32
|
-
|
|
34
|
+
ColorProfile,
|
|
33
35
|
DocumentKind,
|
|
34
36
|
EnabledLibraryBinding,
|
|
35
37
|
NodeChangeObserver,
|
|
36
38
|
NodeType,
|
|
37
39
|
SceneGraphEventHandlers,
|
|
38
40
|
SceneNode,
|
|
41
|
+
SharedStyleType,
|
|
39
42
|
Variable,
|
|
40
43
|
VariableCollection,
|
|
41
44
|
VariableType,
|
|
@@ -53,6 +56,7 @@ type GraphScope =
|
|
|
53
56
|
| 'layout'
|
|
54
57
|
| 'derivedLayout'
|
|
55
58
|
| 'componentDerived'
|
|
59
|
+
| 'peerChanges'
|
|
56
60
|
|
|
57
61
|
export class SceneGraph {
|
|
58
62
|
nodes = new Map<string, SceneNode>()
|
|
@@ -63,7 +67,7 @@ export class SceneGraph {
|
|
|
63
67
|
figKiwiVersion: number | null = null
|
|
64
68
|
/** Deflated kiwi schema bytes from the original .fig file, preserved for roundtrip fidelity. */
|
|
65
69
|
figSchemaDeflated: Uint8Array | null = null
|
|
66
|
-
documentColorSpace:
|
|
70
|
+
documentColorSpace: ColorProfile = 'srgb'
|
|
67
71
|
documentKind: DocumentKind = 'design'
|
|
68
72
|
enabledLibraries = new Map<string, EnabledLibraryBinding>()
|
|
69
73
|
readonly emitter = new BufferedSceneEmitter()
|
|
@@ -74,7 +78,8 @@ export class SceneGraph {
|
|
|
74
78
|
importedState: 0,
|
|
75
79
|
layout: 0,
|
|
76
80
|
derivedLayout: 0,
|
|
77
|
-
componentDerived: 0
|
|
81
|
+
componentDerived: 0,
|
|
82
|
+
peerChanges: 0
|
|
78
83
|
}
|
|
79
84
|
private previewObservers: NodePreviewObserver[] = []
|
|
80
85
|
private readonly changeObservers = new Set<NodeChangeObserver>()
|
|
@@ -87,6 +92,7 @@ export class SceneGraph {
|
|
|
87
92
|
instanceIndex = new Map<string, Set<string>>()
|
|
88
93
|
/** Every connector in the graph, so routing need not scan every layer. */
|
|
89
94
|
connectorIds = new Set<string>()
|
|
95
|
+
readonly sharedStyleIndex = new SharedStyleIndex(() => this.nodes)
|
|
90
96
|
|
|
91
97
|
constructor(private readonly idGenerator: () => string = generateId) {
|
|
92
98
|
const root = createDefaultNode(this.idGenerator, 'FRAME', {
|
|
@@ -164,6 +170,20 @@ export class SceneGraph {
|
|
|
164
170
|
return this.outsideWrites > 0
|
|
165
171
|
}
|
|
166
172
|
|
|
173
|
+
/**
|
|
174
|
+
* Runs `write`, a collaborator's change arriving, outside every edit in progress. The change
|
|
175
|
+
* already holds what the collaborator's edit derived from it, such as the layers its component's
|
|
176
|
+
* instances gained, so this graph must not derive them again under ids of its own.
|
|
177
|
+
*/
|
|
178
|
+
applyPeerChangesDuring<T>(write: () => T): T {
|
|
179
|
+
return this.withScope('peerChanges', () => this.runOutsideEdits(write))
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** Whether a collaborator's change is being applied (`applyPeerChangesDuring`). */
|
|
183
|
+
get isApplyingPeerChanges(): boolean {
|
|
184
|
+
return this.scopeDepths.peerChanges > 0
|
|
185
|
+
}
|
|
186
|
+
|
|
167
187
|
/**
|
|
168
188
|
* Pauses the recorders open now, and only those, until the returned function resumes them: a
|
|
169
189
|
* recorder that opens while an earlier pause is still pending, such as during a script's load
|
|
@@ -332,6 +352,16 @@ export class SceneGraph {
|
|
|
332
352
|
return Variables.getVariablesByType(this, type)
|
|
333
353
|
}
|
|
334
354
|
|
|
355
|
+
/** Every variable but the deleted ones, which only their bindings still reach. */
|
|
356
|
+
getLiveVariables(): Variable[] {
|
|
357
|
+
return Variables.liveVariables(this)
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/** Every collection but the deleted ones. */
|
|
361
|
+
getLiveCollections(): VariableCollection[] {
|
|
362
|
+
return Variables.liveCollections(this)
|
|
363
|
+
}
|
|
364
|
+
|
|
335
365
|
bindVariable(nodeId: string, field: string, variableId: string): void {
|
|
336
366
|
Variables.bindVariable(this, nodeId, field, variableId)
|
|
337
367
|
}
|
|
@@ -453,6 +483,7 @@ export class SceneGraph {
|
|
|
453
483
|
node.parentId = parentId
|
|
454
484
|
this.nodes.set(node.id, node)
|
|
455
485
|
if (node.type === 'CONNECTOR') this.connectorIds.add(node.id)
|
|
486
|
+
this.sharedStyleIndex.added(node)
|
|
456
487
|
for (const observer of this.changeObservers) observer.created(node)
|
|
457
488
|
if (node.type === 'INSTANCE' && node.componentId) this.indexInstance(node.componentId, node.id)
|
|
458
489
|
this.emitter.emit('node:created', node)
|
|
@@ -465,7 +496,11 @@ export class SceneGraph {
|
|
|
465
496
|
|
|
466
497
|
createNode(type: NodeType, parentId: string, overrides: Partial<SceneNode> = {}): SceneNode {
|
|
467
498
|
const node = createDefaultNode(() => this.generateEntityId(), type, overrides)
|
|
468
|
-
Object.assign(
|
|
499
|
+
Object.assign(
|
|
500
|
+
node,
|
|
501
|
+
strokeLineChanges(node, overrides),
|
|
502
|
+
this.textName(newTextNameChanges(node, overrides), parentId)
|
|
503
|
+
)
|
|
469
504
|
const parent = this.nodes.get(parentId)
|
|
470
505
|
this.willChangeNode(parent)
|
|
471
506
|
parent?.childIds.push(node.id)
|
|
@@ -611,14 +646,39 @@ export class SceneGraph {
|
|
|
611
646
|
this.applyNodeChanges(node, this.impliedChanges(node, omitBy(changes, isUndefined)))
|
|
612
647
|
}
|
|
613
648
|
|
|
649
|
+
/** The node of the shared style with this ID, when the document holds one of `type`. */
|
|
650
|
+
getSharedStyleNode(styleId: string, type: SharedStyleType): SceneNode | undefined {
|
|
651
|
+
return this.sharedStyleIndex.styleNode(styleId, type)
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
private styleIndexWillChange(node: SceneNode, changes: Partial<SceneNode>): boolean {
|
|
655
|
+
return !this.isApplyingLayout && this.sharedStyleIndex.willChange(node, changes)
|
|
656
|
+
}
|
|
657
|
+
|
|
614
658
|
/**
|
|
615
|
-
* `changes` with what they also set: a size from outside layout on a generated frame,
|
|
616
|
-
*
|
|
659
|
+
* `changes` with what they also set: a size from outside layout on a generated frame, strokes
|
|
660
|
+
* and the layer's line fields kept in agreement (`strokeLineChanges`), and the name of a text
|
|
661
|
+
* layer that follows its text (`textName`).
|
|
617
662
|
*/
|
|
618
663
|
private impliedChanges(node: SceneNode, changes: Partial<SceneNode>): Partial<SceneNode> {
|
|
619
664
|
const sized = this.isApplyingLayout ? changes : withGeneratedFrameSize(node, changes)
|
|
620
|
-
const
|
|
621
|
-
|
|
665
|
+
const implied = {
|
|
666
|
+
...strokeLineChanges(node, sized),
|
|
667
|
+
...this.textName(textNameChanges(node, sized), node.parentId)
|
|
668
|
+
}
|
|
669
|
+
return isEmptyObject(implied) ? sized : { ...sized, ...implied }
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
/**
|
|
673
|
+
* What a write sets on a text layer's name (`textNameChanges`, `newTextNameChanges`), except while a
|
|
674
|
+
* document loads with names of its own; in an instance, whose layers take their component's
|
|
675
|
+
* names, as Figma's do, even with their text overridden; and in a generated frame, such as a
|
|
676
|
+
* sticky note's body, which keeps its template's name while the frame is named by it.
|
|
677
|
+
*/
|
|
678
|
+
private textName(named: Partial<SceneNode>, parentId: string | null): Partial<SceneNode> {
|
|
679
|
+
if (this.isApplyingImportedState || isEmptyObject(named)) return {}
|
|
680
|
+
const copied = (n: SceneNode) => n.type === 'INSTANCE' || isGeneratedFrame(n)
|
|
681
|
+
return parentId && this.closest(parentId, copied) ? {} : named
|
|
622
682
|
}
|
|
623
683
|
|
|
624
684
|
/** Replay captured properties without dropping explicit undefined values or absent keys. */
|
|
@@ -673,9 +733,11 @@ export class SceneGraph {
|
|
|
673
733
|
changes,
|
|
674
734
|
this.scopeDepths.sourceMetadata === 0 && !this.isApplyingDerivedLayout
|
|
675
735
|
)
|
|
736
|
+
const restyled = this.styleIndexWillChange(node, changes)
|
|
676
737
|
Object.assign(node, changes)
|
|
677
738
|
this.followListBindings(node, changes)
|
|
678
739
|
for (const key of absent) Reflect.deleteProperty(node, key)
|
|
740
|
+
this.sharedStyleIndex.didChange(node, restyled)
|
|
679
741
|
this.publishNodeUpdate(id, changes)
|
|
680
742
|
}
|
|
681
743
|
|
|
@@ -793,6 +855,7 @@ export class SceneGraph {
|
|
|
793
855
|
|
|
794
856
|
if (node.type === 'INSTANCE' && node.componentId) this.unindexInstance(node.componentId, id)
|
|
795
857
|
this.connectorIds.delete(id)
|
|
858
|
+
this.sharedStyleIndex.removed(node)
|
|
796
859
|
this.nodes.delete(id)
|
|
797
860
|
this.emitter.emit('node:deleted', id, node.parentId)
|
|
798
861
|
}
|
package/src/group-bounds.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
import { isEqual } from 'es-toolkit'
|
|
2
|
+
|
|
1
3
|
import { getAxisAlignedBoundsInParent, getNodeLocalMatrix } from './coordinate'
|
|
4
|
+
import { copyGeometryPaths } from './copy'
|
|
2
5
|
import type { SceneGraph } from './graph'
|
|
6
|
+
import { isEmptyBoolean } from './layout/flow'
|
|
3
7
|
import { isVisibleMask, maskRuns } from './masks'
|
|
4
8
|
import Matrix from './matrix'
|
|
5
9
|
import { FITTED_CONTAINER_TYPES } from './node-defaults'
|
|
@@ -12,9 +16,12 @@ import type { SceneNode } from './types'
|
|
|
12
16
|
*/
|
|
13
17
|
export type GroupFitGraph = Pick<SceneGraph, 'getNode' | 'rootId'>
|
|
14
18
|
|
|
15
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* Where a layer sits, with a connector's ends, since a free end is in the parent's axes too, and
|
|
21
|
+
* a boolean's saved geometry, which it drops when it loses its last operand.
|
|
22
|
+
*/
|
|
16
23
|
type Placement = Pick<SceneNode, 'x' | 'y' | 'width' | 'height'> &
|
|
17
|
-
Partial<Pick<SceneNode, 'connectorStart' | 'connectorEnd'>>
|
|
24
|
+
Partial<Pick<SceneNode, 'connectorStart' | 'connectorEnd' | 'fillGeometry' | 'strokeGeometry'>>
|
|
18
25
|
|
|
19
26
|
/** What `fitEnclosingGroups` changed, so a caller can undo and redo it. */
|
|
20
27
|
export interface GroupFit {
|
|
@@ -34,6 +41,13 @@ export interface GroupFitOptions {
|
|
|
34
41
|
|
|
35
42
|
function placement(node: SceneNode): Placement {
|
|
36
43
|
const box = { x: node.x, y: node.y, width: node.width, height: node.height }
|
|
44
|
+
if (node.type === 'BOOLEAN_OPERATION') {
|
|
45
|
+
return {
|
|
46
|
+
...box,
|
|
47
|
+
fillGeometry: copyGeometryPaths(node.fillGeometry),
|
|
48
|
+
strokeGeometry: copyGeometryPaths(node.strokeGeometry)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
37
51
|
if (node.type !== 'CONNECTOR') return box
|
|
38
52
|
return {
|
|
39
53
|
...box,
|
|
@@ -72,18 +86,22 @@ function fittedAncestors(graph: SceneGraph, parentIds: Iterable<string>): SceneN
|
|
|
72
86
|
}
|
|
73
87
|
|
|
74
88
|
/**
|
|
75
|
-
* The layers a group's box covers, bottom to top. Hidden layers do not count, as in Figma
|
|
76
|
-
*
|
|
77
|
-
* the layers
|
|
89
|
+
* The layers a group's box covers, bottom to top. Hidden layers do not count, as in Figma, nor do
|
|
90
|
+
* booleans with no operands unless they keep a finite saved fill and a box sized to it, since a
|
|
91
|
+
* group counts a layer by its box. A mask hides the layers above it outside its shape, so they
|
|
92
|
+
* count only through the mask: the box is the layers below it and the masks.
|
|
78
93
|
*/
|
|
79
94
|
function groupBoundingLayers(children: readonly SceneNode[]): SceneNode[] {
|
|
80
95
|
const shown = children.filter((child) => child.visible)
|
|
81
96
|
const runs = maskRuns(shown, isVisibleMask)
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
97
|
+
const covered =
|
|
98
|
+
runs.length === 0
|
|
99
|
+
? shown
|
|
100
|
+
: [
|
|
101
|
+
...shown.slice(0, runs[0].start),
|
|
102
|
+
...runs.flatMap((run) => shown.slice(run.start, run.maskedStart))
|
|
103
|
+
]
|
|
104
|
+
return covered.filter((layer) => !isEmptyBoolean(layer))
|
|
87
105
|
}
|
|
88
106
|
|
|
89
107
|
/**
|
|
@@ -203,14 +221,37 @@ function fitGroup(
|
|
|
203
221
|
}
|
|
204
222
|
}
|
|
205
223
|
|
|
206
|
-
/**
|
|
207
|
-
|
|
224
|
+
/**
|
|
225
|
+
* A group left without layers goes away. A boolean stays, as in Figma, as a layer of no size at its
|
|
226
|
+
* parent's origin, without the geometry its operands made.
|
|
227
|
+
*/
|
|
228
|
+
function settleEmptyContainer(graph: SceneGraph, group: SceneNode, fit: GroupFit) {
|
|
229
|
+
if (group.type === 'BOOLEAN_OPERATION') {
|
|
230
|
+
collapseEmptyBoolean(graph, group, fit)
|
|
231
|
+
return
|
|
232
|
+
}
|
|
208
233
|
if (group.type !== 'GROUP' || !group.parentId) return
|
|
209
234
|
const index = graph.getNode(group.parentId)?.childIds.indexOf(group.id) ?? -1
|
|
210
235
|
fit.removed.push({ node: structuredClone(group), index })
|
|
211
236
|
graph.deleteNode(group.id)
|
|
212
237
|
}
|
|
213
238
|
|
|
239
|
+
function collapseEmptyBoolean(graph: SceneGraph, boolean: SceneNode, fit: GroupFit) {
|
|
240
|
+
const before = placement(boolean)
|
|
241
|
+
const collapsed: Placement = {
|
|
242
|
+
x: 0,
|
|
243
|
+
y: 0,
|
|
244
|
+
width: 0,
|
|
245
|
+
height: 0,
|
|
246
|
+
fillGeometry: [],
|
|
247
|
+
strokeGeometry: []
|
|
248
|
+
}
|
|
249
|
+
if (isEqual(before, collapsed)) return
|
|
250
|
+
if (!fit.before.has(boolean.id)) fit.before.set(boolean.id, before)
|
|
251
|
+
graph.updateNode(boolean.id, collapsed)
|
|
252
|
+
fit.after.set(boolean.id, collapsed)
|
|
253
|
+
}
|
|
254
|
+
|
|
214
255
|
/**
|
|
215
256
|
* Refits the groups and booleans around these parents to their children, keeping every child where
|
|
216
257
|
* it is on the canvas, and removes groups left empty, as Figma does after a layer inside one moves,
|
|
@@ -225,7 +266,7 @@ export function fitEnclosingGroups(
|
|
|
225
266
|
const fit: GroupFit = { before: new Map(), after: new Map(), removed: [] }
|
|
226
267
|
for (const group of fittedAncestors(graph, parentIds)) {
|
|
227
268
|
const children = graph.getChildren(group.id)
|
|
228
|
-
if (children.length === 0)
|
|
269
|
+
if (children.length === 0) settleEmptyContainer(graph, group, fit)
|
|
229
270
|
else fitGroup(graph, group, children, fit, options)
|
|
230
271
|
}
|
|
231
272
|
return fit.before.size === 0 && fit.removed.length === 0 ? null : fit
|
package/src/hit-test.ts
CHANGED
|
@@ -15,8 +15,13 @@ const CONTAINER_TYPES = new Set<NodeType>([
|
|
|
15
15
|
'SECTION',
|
|
16
16
|
'COMPONENT',
|
|
17
17
|
'COMPONENT_SET',
|
|
18
|
-
'INSTANCE'
|
|
18
|
+
'INSTANCE',
|
|
19
|
+
'SLIDE',
|
|
20
|
+
'SLIDE_ROW',
|
|
21
|
+
'SLIDE_GRID'
|
|
19
22
|
])
|
|
23
|
+
/** What holds a deck's slides: never selected from the canvas, and no target of a drop. */
|
|
24
|
+
const SLIDE_HOLDER_TYPES = new Set<NodeType>(['SLIDE_ROW', 'SLIDE_GRID'])
|
|
20
25
|
const OPAQUE_CONTAINER_TYPES = new Set<NodeType>(['COMPONENT', 'INSTANCE'])
|
|
21
26
|
|
|
22
27
|
/** Whether a container's own paints show, so its empty area is drawn (`paintShows`). */
|
|
@@ -292,13 +297,13 @@ export function hitTestDeep(
|
|
|
292
297
|
|
|
293
298
|
/**
|
|
294
299
|
* A container a click looks into by itself, as in Figma: a top-level frame (on the page or in a
|
|
295
|
-
* section) or
|
|
300
|
+
* section), section, or slide that holds layers, a component set, and what holds a deck's slides. On a FigJam board frames stay
|
|
296
301
|
* closed (`framesOpen` false): a click inside one selects the frame.
|
|
297
302
|
*/
|
|
298
303
|
function opensByItself(graph: SceneGraph, node: SceneNode, framesOpen = true): boolean {
|
|
299
|
-
if (node.type === 'COMPONENT_SET') return true
|
|
304
|
+
if (node.type === 'COMPONENT_SET' || SLIDE_HOLDER_TYPES.has(node.type)) return true
|
|
300
305
|
if (node.childIds.length === 0) return false
|
|
301
|
-
if (node.type === 'SECTION') return true
|
|
306
|
+
if (node.type === 'SECTION' || node.type === 'SLIDE') return true
|
|
302
307
|
return framesOpen && node.type === 'FRAME' && isTopLevel(graph, node)
|
|
303
308
|
}
|
|
304
309
|
|
|
@@ -463,15 +468,15 @@ interface DropRules {
|
|
|
463
468
|
passThrough: ReadonlySet<NodeType>
|
|
464
469
|
}
|
|
465
470
|
|
|
466
|
-
const LAYER_TARGETS = new Set<NodeType>(['FRAME', 'SECTION', 'COMPONENT', 'INSTANCE'])
|
|
467
|
-
const COMPONENT_TARGETS = new Set<NodeType>(['FRAME', 'SECTION', 'INSTANCE'])
|
|
471
|
+
const LAYER_TARGETS = new Set<NodeType>(['FRAME', 'SECTION', 'COMPONENT', 'INSTANCE', 'SLIDE'])
|
|
472
|
+
const COMPONENT_TARGETS = new Set<NodeType>(['FRAME', 'SECTION', 'INSTANCE', 'SLIDE'])
|
|
468
473
|
|
|
469
474
|
function dropRules(options: DropTargetOptions): DropRules {
|
|
470
475
|
const { componentSetIds } = options
|
|
471
476
|
if (!componentSetIds) {
|
|
472
477
|
return {
|
|
473
478
|
takes: (node) => LAYER_TARGETS.has(node.type),
|
|
474
|
-
passThrough: new Set(['GROUP', 'COMPONENT_SET'])
|
|
479
|
+
passThrough: new Set([...SLIDE_HOLDER_TYPES, 'GROUP', 'COMPONENT_SET'])
|
|
475
480
|
}
|
|
476
481
|
}
|
|
477
482
|
// Components never go into other components, and a set only takes back its own variants.
|
|
@@ -479,7 +484,7 @@ function dropRules(options: DropTargetOptions): DropRules {
|
|
|
479
484
|
takes: (node) =>
|
|
480
485
|
COMPONENT_TARGETS.has(node.type) ||
|
|
481
486
|
(node.type === 'COMPONENT_SET' && componentSetIds.has(node.id)),
|
|
482
|
-
passThrough: new Set(['GROUP'])
|
|
487
|
+
passThrough: new Set([...SLIDE_HOLDER_TYPES, 'GROUP'])
|
|
483
488
|
}
|
|
484
489
|
}
|
|
485
490
|
|