@open-pencil/scene-graph 0.17.0-beta.4 → 0.17.0-beta.6
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/buffered-events.js +1 -1
- package/dist/buffered-events.js.map +1 -1
- package/dist/clipping.d.ts +7 -1
- package/dist/clipping.d.ts.map +1 -1
- package/dist/clipping.js +23 -19
- package/dist/clipping.js.map +1 -1
- package/dist/comments/schema.d.ts.map +1 -1
- package/dist/comments/schema.js +1 -0
- package/dist/comments/schema.js.map +1 -1
- package/dist/comments/threads.d.ts +2 -0
- package/dist/comments/threads.d.ts.map +1 -1
- package/dist/comments/threads.js +11 -5
- package/dist/comments/threads.js.map +1 -1
- package/dist/components/index.d.ts +2 -2
- package/dist/components/index.js +2 -2
- package/dist/components/properties.d.ts +1 -3
- package/dist/components/properties.d.ts.map +1 -1
- package/dist/components/properties.js +3 -10
- package/dist/components/properties.js.map +1 -1
- package/dist/constants.d.ts +12 -2
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +42 -1
- package/dist/constants.js.map +1 -1
- package/dist/copy.d.ts.map +1 -1
- package/dist/copy.js +2 -0
- package/dist/copy.js.map +1 -1
- package/dist/corners.d.ts +22 -0
- package/dist/corners.d.ts.map +1 -0
- package/dist/corners.js +52 -0
- package/dist/corners.js.map +1 -0
- package/dist/css/grid.d.ts +4 -1
- package/dist/css/grid.d.ts.map +1 -1
- package/dist/css/grid.js +40 -7
- package/dist/css/grid.js.map +1 -1
- package/dist/css/index.d.ts +3 -3
- package/dist/css/index.js +3 -3
- package/dist/css/layout.d.ts +13 -1
- package/dist/css/layout.d.ts.map +1 -1
- package/dist/css/layout.js +26 -1
- package/dist/css/layout.js.map +1 -1
- package/dist/css/values.d.ts +23 -1
- package/dist/css/values.d.ts.map +1 -1
- package/dist/css/values.js +39 -1
- package/dist/css/values.js.map +1 -1
- package/dist/font-style.d.ts +2 -1
- package/dist/font-style.d.ts.map +1 -1
- package/dist/font-style.js +31 -6
- package/dist/font-style.js.map +1 -1
- package/dist/geometry.d.ts +68 -3
- package/dist/geometry.d.ts.map +1 -1
- package/dist/geometry.js +159 -25
- package/dist/geometry.js.map +1 -1
- package/dist/gradient.d.ts +9 -2
- package/dist/gradient.d.ts.map +1 -1
- package/dist/gradient.js +29 -1
- package/dist/gradient.js.map +1 -1
- package/dist/graph.d.ts +9 -2
- package/dist/graph.d.ts.map +1 -1
- package/dist/graph.js +46 -10
- package/dist/graph.js.map +1 -1
- package/dist/group-bounds.d.ts.map +1 -1
- package/dist/group-bounds.js +4 -3
- package/dist/group-bounds.js.map +1 -1
- package/dist/guides.d.ts +11 -2
- package/dist/guides.d.ts.map +1 -1
- package/dist/guides.js +30 -1
- package/dist/guides.js.map +1 -1
- package/dist/hit-test.d.ts.map +1 -1
- package/dist/hit-test.js +57 -5
- package/dist/hit-test.js.map +1 -1
- package/dist/icons/fit.d.ts +17 -0
- package/dist/icons/fit.d.ts.map +1 -0
- package/dist/icons/fit.js +21 -0
- package/dist/icons/fit.js.map +1 -0
- package/dist/icons/glyph.d.ts.map +1 -1
- package/dist/icons/glyph.js +5 -4
- package/dist/icons/glyph.js.map +1 -1
- package/dist/icons/index.d.ts +2 -1
- package/dist/icons/index.js +2 -1
- package/dist/ids.js +1 -1
- package/dist/ids.js.map +1 -1
- package/dist/images.d.ts +14 -4
- package/dist/images.d.ts.map +1 -1
- package/dist/images.js +45 -5
- package/dist/images.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/instances/assignments.js +39 -6
- package/dist/instances/assignments.js.map +1 -1
- package/dist/instances/index.d.ts +6 -1
- package/dist/instances/index.d.ts.map +1 -1
- package/dist/instances/index.js +58 -9
- package/dist/instances/index.js.map +1 -1
- package/dist/instances/kept-overrides.js +2 -2
- package/dist/instances/kept-overrides.js.map +1 -1
- package/dist/instances/matching.js +68 -0
- package/dist/instances/matching.js.map +1 -0
- package/dist/instances/overrides.d.ts +4 -1
- package/dist/instances/overrides.d.ts.map +1 -1
- package/dist/instances/overrides.js +13 -1
- package/dist/instances/overrides.js.map +1 -1
- package/dist/instances/protection.js +67 -0
- package/dist/instances/protection.js.map +1 -0
- package/dist/instances/swap.js +7 -5
- package/dist/instances/swap.js.map +1 -1
- package/dist/instances/sync.js +34 -116
- package/dist/instances/sync.js.map +1 -1
- package/dist/layout/guides.d.ts +17 -1
- package/dist/layout/guides.d.ts.map +1 -1
- package/dist/layout/guides.js +31 -11
- package/dist/layout/guides.js.map +1 -1
- package/dist/layout/index.d.ts +5 -2
- package/dist/layout/index.js +5 -2
- package/dist/layout/limits.d.ts +40 -0
- package/dist/layout/limits.d.ts.map +1 -0
- package/dist/layout/limits.js +54 -0
- package/dist/layout/limits.js.map +1 -0
- package/dist/layout/sizing.d.ts.map +1 -1
- package/dist/layout/sizing.js +0 -1
- package/dist/layout/sizing.js.map +1 -1
- package/dist/layout/spacing.d.ts +10 -0
- package/dist/layout/spacing.d.ts.map +1 -0
- package/dist/layout/spacing.js +12 -0
- package/dist/layout/spacing.js.map +1 -0
- package/dist/layout/strokes.d.ts +10 -0
- package/dist/layout/strokes.d.ts.map +1 -0
- package/dist/layout/strokes.js +30 -0
- package/dist/layout/strokes.js.map +1 -0
- package/dist/masks.d.ts +28 -0
- package/dist/masks.d.ts.map +1 -0
- package/dist/masks.js +53 -0
- package/dist/masks.js.map +1 -0
- package/dist/matrix.d.ts +2 -1
- package/dist/matrix.d.ts.map +1 -1
- package/dist/matrix.js +14 -1
- package/dist/matrix.js.map +1 -1
- package/dist/node-defaults.d.ts +9 -1
- package/dist/node-defaults.d.ts.map +1 -1
- package/dist/node-defaults.js +65 -38
- package/dist/node-defaults.js.map +1 -1
- package/dist/outline/flatten.d.ts.map +1 -1
- package/dist/outline/flatten.js +24 -17
- package/dist/outline/flatten.js.map +1 -1
- package/dist/outline/hit.d.ts +2 -8
- package/dist/outline/hit.d.ts.map +1 -1
- package/dist/outline/hit.js +16 -25
- package/dist/outline/hit.js.map +1 -1
- package/dist/outline/index.d.ts +3 -3
- package/dist/outline/index.js +3 -3
- package/dist/outline/shapes.d.ts +3 -1
- package/dist/outline/shapes.d.ts.map +1 -1
- package/dist/outline/shapes.js +18 -39
- package/dist/outline/shapes.js.map +1 -1
- package/dist/paints/index.d.ts +3 -1
- package/dist/paints/index.js +3 -1
- package/dist/paints/pattern.d.ts +13 -0
- package/dist/paints/pattern.d.ts.map +1 -0
- package/dist/paints/pattern.js +47 -0
- package/dist/paints/pattern.js.map +1 -0
- package/dist/paints/shows.d.ts +11 -0
- package/dist/paints/shows.d.ts.map +1 -0
- package/dist/paints/shows.js +16 -0
- package/dist/paints/shows.js.map +1 -0
- package/dist/parse-path.d.ts +4 -1
- package/dist/parse-path.d.ts.map +1 -1
- package/dist/parse-path.js +15 -1
- package/dist/parse-path.js.map +1 -1
- package/dist/paths/arc.d.ts +32 -0
- package/dist/paths/arc.d.ts.map +1 -0
- package/dist/paths/arc.js +49 -0
- package/dist/paths/arc.js.map +1 -0
- package/dist/paths/index.d.ts +5 -0
- package/dist/paths/index.js +5 -0
- package/dist/paths/network.d.ts +63 -0
- package/dist/paths/network.d.ts.map +1 -0
- package/dist/paths/network.js +315 -0
- package/dist/paths/network.js.map +1 -0
- package/dist/paths/sink.d.ts +20 -0
- package/dist/paths/sink.d.ts.map +1 -0
- package/dist/paths/sink.js +32 -0
- package/dist/paths/sink.js.map +1 -0
- package/dist/paths/smooth-corners.d.ts +25 -0
- package/dist/paths/smooth-corners.d.ts.map +1 -0
- package/dist/paths/smooth-corners.js +196 -0
- package/dist/paths/smooth-corners.js.map +1 -0
- package/dist/plugin-data/fields.d.ts +4 -0
- package/dist/plugin-data/fields.d.ts.map +1 -1
- package/dist/plugin-data/fields.js +2 -0
- package/dist/plugin-data/fields.js.map +1 -1
- package/dist/polygon.d.ts +1 -3
- package/dist/polygon.d.ts.map +1 -1
- package/dist/polygon.js +1 -16
- package/dist/polygon.js.map +1 -1
- package/dist/primitives/index.d.ts +1 -7
- package/dist/primitives/index.d.ts.map +1 -1
- package/dist/resize.d.ts.map +1 -1
- package/dist/resize.js +5 -5
- package/dist/resize.js.map +1 -1
- package/dist/scaling/node.d.ts.map +1 -1
- package/dist/scaling/node.js +25 -3
- package/dist/scaling/node.js.map +1 -1
- package/dist/shaders/model.d.ts.map +1 -1
- package/dist/shaders/model.js +1 -1
- package/dist/shaders/model.js.map +1 -1
- package/dist/shared-styles.d.ts.map +1 -1
- package/dist/shared-styles.js +2 -9
- package/dist/shared-styles.js.map +1 -1
- package/dist/strokes.d.ts +39 -0
- package/dist/strokes.d.ts.map +1 -0
- package/dist/strokes.js +104 -0
- package/dist/strokes.js.map +1 -0
- package/dist/text/auto-resize.d.ts +15 -0
- package/dist/text/auto-resize.d.ts.map +1 -0
- package/dist/text/auto-resize.js +23 -0
- package/dist/text/auto-resize.js.map +1 -0
- package/dist/text/index.d.ts +5 -3
- package/dist/text/index.js +5 -3
- package/dist/text/lengths.d.ts +6 -1
- package/dist/text/lengths.d.ts.map +1 -1
- package/dist/text/lengths.js +10 -1
- package/dist/text/lengths.js.map +1 -1
- package/dist/text/overflow.d.ts +14 -5
- package/dist/text/overflow.d.ts.map +1 -1
- package/dist/text/overflow.js +24 -6
- package/dist/text/overflow.js.map +1 -1
- package/dist/text/path.js +10 -0
- package/dist/text/path.js.map +1 -0
- package/dist/text/picture.js +5 -5
- package/dist/text/picture.js.map +1 -1
- package/dist/text/runs.d.ts +29 -0
- package/dist/text/runs.d.ts.map +1 -0
- package/dist/text/runs.js +72 -0
- package/dist/text/runs.js.map +1 -0
- package/dist/transfer/dependencies.d.ts.map +1 -1
- package/dist/transfer/dependencies.js +3 -2
- package/dist/transfer/dependencies.js.map +1 -1
- package/dist/transfer/nodes.js +2 -1
- package/dist/transfer/nodes.js.map +1 -1
- package/dist/types.d.ts +56 -10
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/variables/index.d.ts +4 -3
- package/dist/variables/index.d.ts.map +1 -1
- package/dist/variables/index.js +4 -3
- package/dist/variables/index.js.map +1 -1
- package/dist/variables/lookup.d.ts +20 -0
- package/dist/variables/lookup.d.ts.map +1 -0
- package/dist/variables/lookup.js +34 -0
- package/dist/variables/lookup.js.map +1 -0
- package/dist/variables/paints.d.ts +35 -4
- package/dist/variables/paints.d.ts.map +1 -1
- package/dist/variables/paints.js +67 -16
- package/dist/variables/paints.js.map +1 -1
- package/dist/variables/resolution.d.ts +3 -1
- package/dist/variables/resolution.d.ts.map +1 -1
- package/dist/variables/resolution.js +8 -3
- package/dist/variables/resolution.js.map +1 -1
- package/dist/variables/subtree.js +1 -1
- package/dist/variables/subtree.js.map +1 -1
- package/dist/vector-network.d.ts.map +1 -1
- package/dist/vector-network.js +13 -79
- package/dist/vector-network.js.map +1 -1
- package/package.json +28 -7
- package/src/buffered-events.ts +2 -1
- package/src/clipping.ts +11 -8
- package/src/comments/schema.ts +1 -0
- package/src/comments/threads.ts +13 -5
- package/src/components/properties.ts +3 -14
- package/src/constants.ts +25 -1
- package/src/copy.ts +2 -0
- package/src/corners.ts +93 -0
- package/src/css/grid.ts +49 -7
- package/src/css/index.ts +13 -2
- package/src/css/layout.ts +36 -0
- package/src/css/values.ts +49 -0
- package/src/font-style.ts +38 -4
- package/src/geometry.ts +223 -28
- package/src/gradient.ts +23 -1
- package/src/graph.ts +35 -10
- package/src/group-bounds.ts +7 -3
- package/src/guides.ts +26 -1
- package/src/hit-test.ts +68 -10
- package/src/icons/fit.ts +24 -0
- package/src/icons/glyph.ts +6 -4
- package/src/icons/index.ts +1 -0
- package/src/ids.ts +1 -1
- package/src/images.ts +67 -7
- package/src/instances/assignments.ts +65 -7
- package/src/instances/index.ts +77 -13
- package/src/instances/kept-overrides.ts +2 -5
- package/src/instances/matching.ts +101 -0
- package/src/instances/overrides.ts +18 -0
- package/src/instances/protection.ts +103 -0
- package/src/instances/swap.ts +12 -9
- package/src/instances/sync.ts +52 -184
- package/src/layout/guides.ts +42 -9
- package/src/layout/index.ts +3 -0
- package/src/layout/limits.ts +64 -0
- package/src/layout/sizing.ts +0 -2
- package/src/layout/spacing.ts +11 -0
- package/src/layout/strokes.ts +23 -0
- package/src/masks.ts +51 -0
- package/src/matrix.ts +15 -2
- package/src/node-defaults.ts +71 -36
- package/src/outline/flatten.ts +31 -18
- package/src/outline/hit.ts +16 -33
- package/src/outline/index.ts +2 -2
- package/src/outline/shapes.ts +19 -36
- package/src/paints/index.ts +2 -0
- package/src/paints/pattern.ts +45 -0
- package/src/paints/shows.ts +13 -0
- package/src/parse-path.ts +14 -0
- package/src/paths/arc.ts +59 -0
- package/src/paths/index.ts +4 -0
- package/src/paths/network.ts +411 -0
- package/src/paths/sink.ts +50 -0
- package/src/paths/smooth-corners.ts +357 -0
- package/src/plugin-data/fields.ts +2 -0
- package/src/polygon.ts +0 -17
- package/src/primitives/index.ts +0 -5
- package/src/resize.ts +6 -7
- package/src/scaling/node.ts +29 -3
- package/src/shaders/model.ts +2 -1
- package/src/shared-styles.ts +3 -4
- package/src/strokes.ts +121 -0
- package/src/text/auto-resize.ts +25 -0
- package/src/text/index.ts +2 -0
- package/src/text/lengths.ts +11 -0
- package/src/text/overflow.ts +32 -6
- package/src/text/path.ts +13 -0
- package/src/text/picture.ts +5 -5
- package/src/text/runs.ts +80 -0
- package/src/transfer/dependencies.ts +4 -2
- package/src/transfer/nodes.ts +2 -1
- package/src/types.ts +62 -8
- package/src/variables/index.ts +1 -0
- package/src/variables/lookup.ts +31 -0
- package/src/variables/paints.ts +101 -20
- package/src/variables/resolution.ts +15 -2
- package/src/variables/subtree.ts +1 -1
- package/src/vector-network.ts +19 -142
- package/dist/random.d.ts +0 -7
- package/dist/random.d.ts.map +0 -1
- package/dist/random.js +0 -25
- package/dist/random.js.map +0 -1
- package/src/random.ts +0 -28
package/src/instances/sync.ts
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
// Child cloning and property synchronization shared by instance creation, swap, and sync.
|
|
2
2
|
import { uniq } from 'es-toolkit/array'
|
|
3
3
|
import { pick } from 'es-toolkit/object'
|
|
4
|
-
import {
|
|
4
|
+
import { isEqual } from 'es-toolkit/predicate'
|
|
5
5
|
|
|
6
6
|
import { cloneNodeProps, copyEffects, copyFills, copyStrokes, copyStyleRuns } from '../copy'
|
|
7
7
|
import type { NodeCloneMode } from '../copy'
|
|
8
8
|
import type { SceneGraph } from '../graph'
|
|
9
9
|
import { scaleNodeChanges } from '../scaling/node'
|
|
10
10
|
import { ownsSlotContent, slotPropertyId } from '../slots/frames'
|
|
11
|
+
import {
|
|
12
|
+
STROKE_LINE_FIELDS,
|
|
13
|
+
STROKE_LINE_KEYS,
|
|
14
|
+
strokeLine,
|
|
15
|
+
type StrokeLines,
|
|
16
|
+
withStrokeLines
|
|
17
|
+
} from '../strokes'
|
|
11
18
|
import type { SceneNode } from '../types'
|
|
12
19
|
import { resolvedNumericBindings } from '../variables/bindings'
|
|
13
|
-
import {
|
|
14
|
-
effectBindingTarget,
|
|
15
|
-
isNumericVariableBindingField,
|
|
16
|
-
paintBindingTarget
|
|
17
|
-
} from '../variables/fields'
|
|
20
|
+
import { isNumericVariableBindingField } from '../variables/fields'
|
|
18
21
|
import {
|
|
19
22
|
applyBoundPaintColorsIn,
|
|
20
23
|
copyAppliedBoundPaints,
|
|
@@ -31,16 +34,20 @@ import {
|
|
|
31
34
|
type InstanceSyncContext
|
|
32
35
|
} from './copies'
|
|
33
36
|
import { INSTANCE_SYNC_FIELD_OWNERS, INSTANCE_SYNC_FIELDS } from './fields'
|
|
34
|
-
import {
|
|
37
|
+
import { sourceWithEffectiveFill } from './main-component'
|
|
38
|
+
import { matchFallbackChildren, matchLinkedChildren } from './matching'
|
|
35
39
|
import {
|
|
36
|
-
bindingOverrideField,
|
|
37
40
|
copiedComponentLayerId,
|
|
38
41
|
hasInstanceOverride as hasNodeInstanceOverride,
|
|
39
|
-
overriddenBindingField,
|
|
40
|
-
setInstanceOverride,
|
|
41
42
|
type InstanceOverrideState
|
|
42
43
|
} from './overrides'
|
|
43
44
|
import { fitCopiedGroup, PLACEMENT_FIELDS, placedByConstraints } from './placement'
|
|
45
|
+
import {
|
|
46
|
+
childBindingProtection,
|
|
47
|
+
isProtectedSyncField,
|
|
48
|
+
NOTHING_PROTECTED,
|
|
49
|
+
syncBindingFields
|
|
50
|
+
} from './protection'
|
|
44
51
|
import { followVectorGeometry } from './vector-geometry'
|
|
45
52
|
|
|
46
53
|
function setSceneProp<K extends keyof SceneNode>(
|
|
@@ -83,67 +90,6 @@ export function copyProp(
|
|
|
83
90
|
}
|
|
84
91
|
}
|
|
85
92
|
|
|
86
|
-
export function bindingProtection(scopes: ReadonlySet<string>[]): (field: string) => boolean {
|
|
87
|
-
const fields = new Set<string>()
|
|
88
|
-
for (const scope of scopes) {
|
|
89
|
-
const perField = [...scope].some((field) => overriddenBindingField(field) !== null)
|
|
90
|
-
for (const field of scope) {
|
|
91
|
-
if (field !== 'boundVariables' || !perField) fields.add(field)
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
return (field) => {
|
|
95
|
-
if (fields.has(field)) return true
|
|
96
|
-
// Paints and effects an instance set itself own their bindings too, bound or not.
|
|
97
|
-
const binding = overriddenBindingField(field)
|
|
98
|
-
if (binding === null) return false
|
|
99
|
-
const paint = paintBindingTarget(binding)
|
|
100
|
-
if (paint) return fields.has(paint.list)
|
|
101
|
-
return fields.has('effects') && effectBindingTarget(binding) !== null
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
function isUnbound(node: SceneNode): boolean {
|
|
106
|
-
return isEmptyObject(node.boundVariables) && isEmptyObject(node.variableBindingScales)
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export function syncBindingFields(
|
|
110
|
-
target: SceneNode,
|
|
111
|
-
source: SceneNode,
|
|
112
|
-
updates: Partial<SceneNode>,
|
|
113
|
-
protectedField: (field: string) => boolean
|
|
114
|
-
): void {
|
|
115
|
-
if (protectedField('boundVariables') || (isUnbound(source) && isUnbound(target))) {
|
|
116
|
-
return
|
|
117
|
-
}
|
|
118
|
-
const bindings = { ...source.boundVariables }
|
|
119
|
-
const scales = { ...source.variableBindingScales }
|
|
120
|
-
for (const field of new Set([
|
|
121
|
-
...Object.keys(source.boundVariables),
|
|
122
|
-
...Object.keys(target.boundVariables),
|
|
123
|
-
...Object.keys(target.variableBindingScales)
|
|
124
|
-
])) {
|
|
125
|
-
if (!protectedField(bindingOverrideField(field))) continue
|
|
126
|
-
if (!Object.hasOwn(target.boundVariables, field)) Reflect.deleteProperty(bindings, field)
|
|
127
|
-
else bindings[field] = target.boundVariables[field]
|
|
128
|
-
if (target.variableBindingScales[field] === undefined) Reflect.deleteProperty(scales, field)
|
|
129
|
-
else scales[field] = target.variableBindingScales[field]
|
|
130
|
-
}
|
|
131
|
-
updates.boundVariables = bindings
|
|
132
|
-
updates.variableBindingScales = scales
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
export function isProtectedSyncField(
|
|
136
|
-
node: SceneNode,
|
|
137
|
-
key: string,
|
|
138
|
-
protectedField: (field: string) => boolean
|
|
139
|
-
): boolean {
|
|
140
|
-
return (
|
|
141
|
-
protectedField(key) ||
|
|
142
|
-
(key in node.boundVariables &&
|
|
143
|
-
(protectedField('boundVariables') || protectedField(bindingOverrideField(key))))
|
|
144
|
-
)
|
|
145
|
-
}
|
|
146
|
-
|
|
147
93
|
export function sourceInTargetCoordinates(source: SceneNode, targetScale: number): SceneNode {
|
|
148
94
|
const factor = targetScale / source.componentScale
|
|
149
95
|
if (!Number.isFinite(factor) || factor <= 0) throw new Error('Invalid component coordinate scale')
|
|
@@ -162,8 +108,6 @@ const SYNCED_FIELDS = INSTANCE_SYNC_FIELDS.filter((key) => key !== 'boundVariabl
|
|
|
162
108
|
position: key === 'x' || key === 'y'
|
|
163
109
|
}))
|
|
164
110
|
|
|
165
|
-
export const NOTHING_PROTECTED = (_field: string): boolean => false
|
|
166
|
-
|
|
167
111
|
interface SyncedFieldsInput {
|
|
168
112
|
compParent: SceneNode
|
|
169
113
|
instParent: SceneNode
|
|
@@ -217,6 +161,8 @@ export function updateSyncedProps(
|
|
|
217
161
|
applySyncedModes(graph, target, updates)
|
|
218
162
|
keepCopyBoundPaints(graph, target, updates)
|
|
219
163
|
}
|
|
164
|
+
// After the copy's own bound paints, which can bring its strokes into the write.
|
|
165
|
+
applySyncedStrokeLines(target, updates, kept)
|
|
220
166
|
let changed: Partial<SceneNode> | undefined
|
|
221
167
|
for (const key of Object.keys(updates)) {
|
|
222
168
|
const current = target[key as keyof SceneNode]
|
|
@@ -235,6 +181,38 @@ export function updateSyncedProps(
|
|
|
235
181
|
graph.updateNode(target.id, changed)
|
|
236
182
|
}
|
|
237
183
|
|
|
184
|
+
/**
|
|
185
|
+
* Strokes a sync or swap gives a copy draw with the copy's own line fields: the weight,
|
|
186
|
+
* alignment, cap, join, or dash it overrides, and a bound weight resolved in its modes. Figma
|
|
187
|
+
* keeps a stroke weight override when the component's color changes (live).
|
|
188
|
+
*/
|
|
189
|
+
export function applySyncedStrokeLines(
|
|
190
|
+
target: SceneNode,
|
|
191
|
+
updates: Partial<SceneNode>,
|
|
192
|
+
kept: (field: string) => boolean
|
|
193
|
+
): void {
|
|
194
|
+
const strokes = updates.strokes
|
|
195
|
+
const first = strokes?.at(0)
|
|
196
|
+
if (!strokes || !first) return
|
|
197
|
+
const lines: StrokeLines = {}
|
|
198
|
+
let set = false
|
|
199
|
+
for (const key of STROKE_LINE_KEYS) {
|
|
200
|
+
const field = STROKE_LINE_FIELDS[key]
|
|
201
|
+
const own = kept(field)
|
|
202
|
+
const value = own ? target[field] : updates[field]
|
|
203
|
+
if (value === undefined) continue
|
|
204
|
+
// A field the copy overrides holds for every stroke; the component's own values keep its
|
|
205
|
+
// strokes' differences unless a binding resolved the first one apart.
|
|
206
|
+
const differs = own
|
|
207
|
+
? strokes.some((stroke) => !isEqual(value, strokeLine(stroke, key)))
|
|
208
|
+
: !isEqual(value, strokeLine(first, key))
|
|
209
|
+
if (!differs) continue
|
|
210
|
+
Reflect.set(lines, key, value)
|
|
211
|
+
set = true
|
|
212
|
+
}
|
|
213
|
+
if (set) updates.strokes = withStrokeLines(strokes, lines)
|
|
214
|
+
}
|
|
215
|
+
|
|
238
216
|
/**
|
|
239
217
|
* A bound number the sync writes takes the value it resolves to where the copy sits, not the
|
|
240
218
|
* one its component holds: an instance that sets another mode, or sits in one that does, shows
|
|
@@ -310,95 +288,6 @@ export function cloneChildrenWithMapping(
|
|
|
310
288
|
}
|
|
311
289
|
}
|
|
312
290
|
|
|
313
|
-
export function enclosingInstanceOverrideFields(graph: SceneGraph, node: SceneNode): Set<string>[] {
|
|
314
|
-
const fields: Set<string>[] = []
|
|
315
|
-
let parent = node.parentId ? graph.nodes.get(node.parentId) : undefined
|
|
316
|
-
while (parent) {
|
|
317
|
-
if (parent.type === 'INSTANCE') {
|
|
318
|
-
fields.push(new Set(parent.instanceOverrides.descendants.get(node.id)?.keys()))
|
|
319
|
-
}
|
|
320
|
-
parent = parent.parentId ? graph.nodes.get(parent.parentId) : undefined
|
|
321
|
-
}
|
|
322
|
-
return fields
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
function childBindingProtection(
|
|
326
|
-
graph: SceneGraph,
|
|
327
|
-
child: SceneNode,
|
|
328
|
-
overrides: InstanceOverrideState
|
|
329
|
-
) {
|
|
330
|
-
const fields = enclosingInstanceOverrideFields(graph, child)
|
|
331
|
-
fields.push(new Set(overrides.descendants.get(child.id)?.keys()))
|
|
332
|
-
if (child.instanceOverrides.self.size === 0 && fields.every((scope) => scope.size === 0)) {
|
|
333
|
-
return NOTHING_PROTECTED
|
|
334
|
-
}
|
|
335
|
-
const protectedField = bindingProtection(fields)
|
|
336
|
-
return (field: string) => protectedField(field) || ownsSelfFillField(child, field)
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
function linkMatchedChild(
|
|
340
|
-
overrides: InstanceOverrideState,
|
|
341
|
-
instParentId: string,
|
|
342
|
-
instChild: SceneNode,
|
|
343
|
-
compChildId: string
|
|
344
|
-
): void {
|
|
345
|
-
if (instChild.type === 'INSTANCE') {
|
|
346
|
-
setInstanceOverride(overrides, instParentId, instChild.id, 'sourceComponentId', compChildId)
|
|
347
|
-
} else {
|
|
348
|
-
instChild.componentId = compChildId
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
function matchFallbackChildren(
|
|
353
|
-
graph: SceneGraph,
|
|
354
|
-
compParent: SceneNode,
|
|
355
|
-
instParent: SceneNode,
|
|
356
|
-
instParentId: string,
|
|
357
|
-
overrides: InstanceOverrideState,
|
|
358
|
-
instChildMap: Map<string, SceneNode>,
|
|
359
|
-
usedInstChildIds: Set<string>
|
|
360
|
-
): void {
|
|
361
|
-
const fallbackByType = new Map<SceneNode['type'], Map<string, SceneNode[]>>()
|
|
362
|
-
const remainingCandidateCount = new Map<SceneNode['type'], number>()
|
|
363
|
-
const unmatchedComponentCount = new Map<SceneNode['type'], number>()
|
|
364
|
-
for (const compChildId of compParent.childIds) {
|
|
365
|
-
if (instChildMap.has(compChildId)) continue
|
|
366
|
-
const child = graph.nodes.get(compChildId)
|
|
367
|
-
if (child) {
|
|
368
|
-
unmatchedComponentCount.set(child.type, (unmatchedComponentCount.get(child.type) ?? 0) + 1)
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
for (const childId of instParent.childIds) {
|
|
372
|
-
const child = graph.nodes.get(childId)
|
|
373
|
-
if (!child || usedInstChildIds.has(child.id)) continue
|
|
374
|
-
remainingCandidateCount.set(child.type, (remainingCandidateCount.get(child.type) ?? 0) + 1)
|
|
375
|
-
let byName = fallbackByType.get(child.type)
|
|
376
|
-
if (!byName) {
|
|
377
|
-
byName = new Map()
|
|
378
|
-
fallbackByType.set(child.type, byName)
|
|
379
|
-
}
|
|
380
|
-
const queue = byName.get(child.name)
|
|
381
|
-
if (queue) queue.push(child)
|
|
382
|
-
else byName.set(child.name, [child])
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
// Match by name and type with FIFO queues to preserve sibling order in linear time.
|
|
386
|
-
for (const compChildId of compParent.childIds) {
|
|
387
|
-
if (instChildMap.has(compChildId)) continue
|
|
388
|
-
const compChild = graph.nodes.get(compChildId)
|
|
389
|
-
if (!compChild) continue
|
|
390
|
-
const candidatesByName = fallbackByType.get(compChild.type)
|
|
391
|
-
const candidateCount = remainingCandidateCount.get(compChild.type) ?? 0
|
|
392
|
-
if (candidateCount > (unmatchedComponentCount.get(compChild.type) ?? 0)) continue
|
|
393
|
-
const match = candidatesByName?.get(compChild.name)?.shift()
|
|
394
|
-
if (!match) continue
|
|
395
|
-
remainingCandidateCount.set(compChild.type, candidateCount - 1)
|
|
396
|
-
instChildMap.set(compChildId, match)
|
|
397
|
-
usedInstChildIds.add(match.id)
|
|
398
|
-
linkMatchedChild(overrides, instParentId, match, compChildId)
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
|
|
402
291
|
function sortInstanceChildren(
|
|
403
292
|
graph: SceneGraph,
|
|
404
293
|
instParent: SceneNode,
|
|
@@ -478,27 +367,6 @@ function isCyclicSync(graph: SceneGraph, compParentId: string, instParentId: str
|
|
|
478
367
|
return compParentId === instParentId || graph.isDescendant(instParentId, compParentId)
|
|
479
368
|
}
|
|
480
369
|
|
|
481
|
-
/** Children already linked to a component child by sourceComponentId or componentId. */
|
|
482
|
-
function matchLinkedChildren(
|
|
483
|
-
graph: SceneGraph,
|
|
484
|
-
instParent: SceneNode,
|
|
485
|
-
instParentId: string,
|
|
486
|
-
overrides: InstanceOverrideState,
|
|
487
|
-
compChildIdSet: ReadonlySet<string>,
|
|
488
|
-
instChildMap: Map<string, SceneNode>,
|
|
489
|
-
usedInstChildIds: Set<string>
|
|
490
|
-
): void {
|
|
491
|
-
for (const childId of instParent.childIds) {
|
|
492
|
-
const child = graph.nodes.get(childId)
|
|
493
|
-
if (!child) continue
|
|
494
|
-
const mappedComponentId = copiedComponentLayerId(overrides, instParentId, child)
|
|
495
|
-
if (mappedComponentId && compChildIdSet.has(mappedComponentId)) {
|
|
496
|
-
instChildMap.set(mappedComponentId, child)
|
|
497
|
-
usedInstChildIds.add(child.id)
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
|
|
502
370
|
/**
|
|
503
371
|
* Pass 3 of a sync: bring along the copy of a layer moved here inside the component, bring back
|
|
504
372
|
* one the sync removed when its layer returns, or clone a layer the instance has no copy of. A
|
|
@@ -579,7 +447,7 @@ export function syncChildren(
|
|
|
579
447
|
compParent,
|
|
580
448
|
instParent,
|
|
581
449
|
instParentId,
|
|
582
|
-
|
|
450
|
+
context,
|
|
583
451
|
instChildMap,
|
|
584
452
|
usedInstChildIds
|
|
585
453
|
)
|
package/src/layout/guides.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Color } from '../primitives'
|
|
1
2
|
import type { LayoutGrid, SceneNode } from '../types'
|
|
2
3
|
|
|
3
4
|
export interface LayoutGuideLine {
|
|
@@ -5,7 +6,8 @@ export interface LayoutGuideLine {
|
|
|
5
6
|
position: number
|
|
6
7
|
}
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
/** The most lines one guide draws or snaps to on an axis. */
|
|
10
|
+
export const MAX_LAYOUT_GUIDE_LINES = 10_000
|
|
9
11
|
|
|
10
12
|
/** Figma's Auto count, as its archive stores it: as many sections as fit. */
|
|
11
13
|
export const AUTO_LAYOUT_GRID_COUNT = 2_147_483_647
|
|
@@ -24,18 +26,49 @@ export function layoutGridCount(grid: LayoutGrid): number {
|
|
|
24
26
|
return isAutoGridCount(count) ? AUTO_LAYOUT_GRID_COUNT : (count ?? 1)
|
|
25
27
|
}
|
|
26
28
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
/** Figma's color for a new guide: red at 10%. */
|
|
30
|
+
export const DEFAULT_LAYOUT_GRID_COLOR: Readonly<Color> = Object.freeze({
|
|
31
|
+
r: 1,
|
|
32
|
+
g: 0,
|
|
33
|
+
b: 0,
|
|
34
|
+
a: 0.1
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
/** A guide's pattern in Figma's plugin names, from either shape: the archive's `STRIPES` along an `axis`. */
|
|
38
|
+
export function layoutGridPattern(
|
|
39
|
+
grid: Pick<LayoutGrid, 'pattern' | 'axis'>
|
|
40
|
+
): 'COLUMNS' | 'ROWS' | 'GRID' {
|
|
41
|
+
if (grid.pattern === 'GRID' || grid.pattern === 'ROWS' || grid.pattern === 'COLUMNS') {
|
|
42
|
+
return grid.pattern
|
|
43
|
+
}
|
|
44
|
+
return grid.axis === 'Y' ? 'ROWS' : 'COLUMNS'
|
|
31
45
|
}
|
|
32
46
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
47
|
+
/**
|
|
48
|
+
* A guide's alignment, from either shape. One set without any stretches, as the plugin API and
|
|
49
|
+
* export have read it; a file's guide always has one, as Figma drops a guide without it.
|
|
50
|
+
*/
|
|
51
|
+
export function layoutGridAlignment(
|
|
52
|
+
grid: Pick<LayoutGrid, 'alignment' | 'type'>
|
|
53
|
+
): 'MIN' | 'CENTER' | 'MAX' | 'STRETCH' {
|
|
54
|
+
return grid.alignment ?? grid.type ?? 'STRETCH'
|
|
37
55
|
}
|
|
38
56
|
|
|
57
|
+
/** Whether a file's guide record names an alignment; Figma drops one that does not (live). */
|
|
58
|
+
export function hasLayoutGridAlignment(
|
|
59
|
+
grid: Partial<Pick<LayoutGrid, 'alignment' | 'type'>>
|
|
60
|
+
): boolean {
|
|
61
|
+
return grid.type !== undefined || grid.alignment !== undefined
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** A guide's color, Figma's new-guide red for one set without any. */
|
|
65
|
+
export function layoutGridColor(grid: Pick<LayoutGrid, 'color'>): Color {
|
|
66
|
+
return { ...(grid.color ?? DEFAULT_LAYOUT_GRID_COLOR) }
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const pattern = layoutGridPattern
|
|
70
|
+
const alignment = layoutGridAlignment
|
|
71
|
+
|
|
39
72
|
/**
|
|
40
73
|
* How many sections a guide draws. Auto fits as many fixed sections as the frame holds, counting
|
|
41
74
|
* the offset once from the aligned edge, as Figma desktop 126 draws them.
|
package/src/layout/index.ts
CHANGED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { GridTrack } from '../types'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Bounds for the numbers layout computes with and for the values it writes back.
|
|
5
|
+
*
|
|
6
|
+
* Layout tolerates a span of zero or a track list a tool wrote by mistake, but not every
|
|
7
|
+
* consumer does: a document carrying absurd geometry cannot be rasterized, a grid template
|
|
8
|
+
* naming a billion tracks allocates one entry per track, and a text layer set at 1e9 px makes
|
|
9
|
+
* font shaping build a run of glyphs no memory holds. Every path that writes a layout value
|
|
10
|
+
* clamps to these bounds, and tool schemas reject values outside them.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/** The largest size or position, in pixels, that a layout value may carry. */
|
|
14
|
+
export const MAX_LAYOUT_LENGTH = 1_000_000
|
|
15
|
+
|
|
16
|
+
/** The largest gap, padding, or stroke a layout value may carry, in pixels. */
|
|
17
|
+
export const MAX_LAYOUT_SPACING = 100_000
|
|
18
|
+
|
|
19
|
+
/** The largest number of tracks one grid template may name. */
|
|
20
|
+
export const MAX_GRID_TRACKS = 1_000
|
|
21
|
+
|
|
22
|
+
/** The last grid line a placement may name; line 0 leaves placement to auto-flow. */
|
|
23
|
+
export const MAX_GRID_LINE = 1_000
|
|
24
|
+
|
|
25
|
+
/** The most tracks one grid item may span. */
|
|
26
|
+
export const MAX_GRID_SPAN = 1_000
|
|
27
|
+
|
|
28
|
+
/** The largest rotation, in degrees, a layout or transform may carry. */
|
|
29
|
+
export const MAX_LAYOUT_ANGLE = 360_000
|
|
30
|
+
|
|
31
|
+
/** The largest font size, in pixels, text may be set in. */
|
|
32
|
+
export const MAX_FONT_SIZE = 10_000
|
|
33
|
+
|
|
34
|
+
/** The largest ratio a layout factor, such as a flex grow share, may carry. */
|
|
35
|
+
export const MAX_LAYOUT_FACTOR = 1_000
|
|
36
|
+
|
|
37
|
+
/** The largest line height or letter spacing, in pixels or percent, a text may carry. */
|
|
38
|
+
export const MAX_TEXT_LENGTH = 10_000
|
|
39
|
+
|
|
40
|
+
/** A length that cannot be negative, such as a size, padding, gap, or radius. */
|
|
41
|
+
export function clampLayoutLength(value: number, max = MAX_LAYOUT_LENGTH): number {
|
|
42
|
+
if (!Number.isFinite(value)) return 0
|
|
43
|
+
return Math.min(max, Math.max(0, value))
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** A coordinate that may be negative, such as a position. */
|
|
47
|
+
export function clampLayoutPosition(value: number, max = MAX_LAYOUT_LENGTH): number {
|
|
48
|
+
if (!Number.isFinite(value)) return 0
|
|
49
|
+
return Math.min(max, Math.max(-max, value))
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** A font size in pixels, at least one and at most `MAX_FONT_SIZE`; fractions are kept. */
|
|
53
|
+
export function clampFontSize(value: number): number {
|
|
54
|
+
if (!Number.isFinite(value)) return 1
|
|
55
|
+
return Math.min(MAX_FONT_SIZE, Math.max(1, value))
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** A grid template's tracks, with at most `MAX_GRID_TRACKS` of them and no negative sizes. */
|
|
59
|
+
export function clampGridTracks(tracks: readonly GridTrack[]): GridTrack[] {
|
|
60
|
+
return tracks.slice(0, MAX_GRID_TRACKS).map((track) => ({
|
|
61
|
+
...track,
|
|
62
|
+
value: clampLayoutLength(track.value)
|
|
63
|
+
}))
|
|
64
|
+
}
|
package/src/layout/sizing.ts
CHANGED
|
@@ -129,8 +129,6 @@ function textSizingUpdates(
|
|
|
129
129
|
axis === 'HORIZONTAL'
|
|
130
130
|
? textAutoResizeFor(hugsAxis, hugsOther)
|
|
131
131
|
: textAutoResizeFor(hugsOther, hugsAxis)
|
|
132
|
-
// Truncated text keeps truncating when it stops hugging.
|
|
133
|
-
if (autoResize === 'NONE' && node.textAutoResize === 'TRUNCATE') return {}
|
|
134
132
|
return autoResize === node.textAutoResize ? {} : { textAutoResize: autoResize }
|
|
135
133
|
}
|
|
136
134
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { SceneNode } from '../types'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The space between wrapped lines of an auto layout. A frame without its own follows the item
|
|
5
|
+
* spacing, as Figma's `counterAxisSpacing: null` does.
|
|
6
|
+
*/
|
|
7
|
+
export function counterAxisSpacingOf(
|
|
8
|
+
node: Pick<SceneNode, 'counterAxisSpacing' | 'itemSpacing'>
|
|
9
|
+
): number {
|
|
10
|
+
return node.counterAxisSpacing ?? node.itemSpacing
|
|
11
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { SceneNode } from '../types'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The stroke a frame counts inside its padding, per side: its visible INSIDE strokes when its
|
|
5
|
+
* strokes are included in layout, as Figma lays it out and as a CSS border takes room.
|
|
6
|
+
*/
|
|
7
|
+
export function includedStrokeWeights(
|
|
8
|
+
node: SceneNode
|
|
9
|
+
): Record<'top' | 'right' | 'bottom' | 'left', number> {
|
|
10
|
+
const stroke = node.strokes.find((paint) => paint.visible)
|
|
11
|
+
if (!node.strokesIncludedInLayout || stroke?.align !== 'INSIDE') {
|
|
12
|
+
return { top: 0, right: 0, bottom: 0, left: 0 }
|
|
13
|
+
}
|
|
14
|
+
if (!node.independentStrokeWeights) {
|
|
15
|
+
return { top: stroke.weight, right: stroke.weight, bottom: stroke.weight, left: stroke.weight }
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
top: node.borderTopWeight,
|
|
19
|
+
right: node.borderRightWeight,
|
|
20
|
+
bottom: node.borderBottomWeight,
|
|
21
|
+
left: node.borderLeftWeight
|
|
22
|
+
}
|
|
23
|
+
}
|
package/src/masks.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { SceneNode } from './types'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The layer as it masks: an outline mask masks with its shape alone, so Figma ignores how opaque
|
|
5
|
+
* its fills are, and the canvas and hit testing take them as opaque.
|
|
6
|
+
*/
|
|
7
|
+
export function asMaskShape(node: SceneNode): SceneNode {
|
|
8
|
+
if (node.maskType !== 'VECTOR') return node
|
|
9
|
+
return {
|
|
10
|
+
...node,
|
|
11
|
+
fills: node.fills.map((fill) => ({ ...fill, opacity: 1, color: { ...fill.color, a: 1 } }))
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Whether a layer masks its siblings: a mask that is shown, since a hidden mask masks nothing. */
|
|
16
|
+
export function isVisibleMask(node: Pick<SceneNode, 'visible' | 'isMask'>): boolean {
|
|
17
|
+
return node.visible && node.isMask
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* A run of masks and the siblings they mask, as indices into the children: the masks are
|
|
22
|
+
* `[start, maskedStart)` and what they mask `[maskedStart, end)`, which may be empty.
|
|
23
|
+
*/
|
|
24
|
+
export interface MaskRun {
|
|
25
|
+
readonly start: number
|
|
26
|
+
readonly maskedStart: number
|
|
27
|
+
readonly end: number
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Where masks act among a container's children, bottom to top. A visible mask, with the visible
|
|
32
|
+
* masks right after it, masks every sibling after them up to the next visible mask, which starts
|
|
33
|
+
* a run of its own; a sibling that is hidden or a hidden mask is masked like any other (Figma
|
|
34
|
+
* desktop, live). Children before the first mask are not in any run.
|
|
35
|
+
*/
|
|
36
|
+
export function maskRuns<T>(children: readonly T[], isMask: (child: T) => boolean): MaskRun[] {
|
|
37
|
+
const runs: MaskRun[] = []
|
|
38
|
+
let index = 0
|
|
39
|
+
while (index < children.length) {
|
|
40
|
+
if (!isMask(children[index])) {
|
|
41
|
+
index++
|
|
42
|
+
continue
|
|
43
|
+
}
|
|
44
|
+
const start = index
|
|
45
|
+
while (index < children.length && isMask(children[index])) index++
|
|
46
|
+
const maskedStart = index
|
|
47
|
+
while (index < children.length && !isMask(children[index])) index++
|
|
48
|
+
runs.push({ start, maskedStart, end: index })
|
|
49
|
+
}
|
|
50
|
+
return runs
|
|
51
|
+
}
|
package/src/matrix.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Vector } from './primitives'
|
|
1
|
+
import type { Matrix as AffineTransform, Vector } from './primitives'
|
|
2
2
|
|
|
3
3
|
export type Mat3 = number[]
|
|
4
4
|
|
|
@@ -112,5 +112,18 @@ const mapPoint = (m: Mat3, p: Vector): Vector => {
|
|
|
112
112
|
return { x: arr[0], y: arr[1] }
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
|
|
115
|
+
/** A 2 × 3 affine transform, as Figma stores gradient and image transforms, as a 3 × 3 matrix. */
|
|
116
|
+
const fromAffine = (t: AffineTransform): Mat3 => [t.m00, t.m01, t.m02, t.m10, t.m11, t.m12, 0, 0, 1]
|
|
117
|
+
|
|
118
|
+
const Matrix = {
|
|
119
|
+
identity,
|
|
120
|
+
multiply,
|
|
121
|
+
translated,
|
|
122
|
+
rotated,
|
|
123
|
+
scaled,
|
|
124
|
+
invert,
|
|
125
|
+
mapPoints,
|
|
126
|
+
mapPoint,
|
|
127
|
+
fromAffine
|
|
128
|
+
}
|
|
116
129
|
export default Matrix
|