@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/index.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
restoreOwnedSlotContent,
|
|
6
6
|
type ParkedSlotContent
|
|
7
7
|
} from '../slots/frames'
|
|
8
|
+
import { changesMoreThanStrokeLines } from '../strokes'
|
|
8
9
|
import type { SceneNode } from '../types'
|
|
9
10
|
import { applyBoundPaintColorsIn, keepCopyBoundPaints } from '../variables/paints'
|
|
10
11
|
import { keepOwnContentSize } from './content-size'
|
|
@@ -14,19 +15,24 @@ import { INSTANCE_OVERRIDE_FIELDS, INSTANCE_SYNC_PROPS } from './fields'
|
|
|
14
15
|
import { findInstanceAncestor, instanceMainComponent } from './main-component'
|
|
15
16
|
import {
|
|
16
17
|
clearInstanceOverrides,
|
|
18
|
+
cloneInstanceOverrideState,
|
|
17
19
|
getInstanceOverride,
|
|
18
20
|
hasInstanceOverride as hasNodeInstanceOverride,
|
|
19
21
|
setInstanceOverride
|
|
20
22
|
} from './overrides'
|
|
21
|
-
import { followComponentLayers } from './swap'
|
|
22
23
|
import {
|
|
23
24
|
bindingProtection,
|
|
24
|
-
cloneChildrenWithMapping,
|
|
25
|
-
copyProp,
|
|
26
25
|
enclosingInstanceOverrideFields,
|
|
27
26
|
isProtectedSyncField,
|
|
27
|
+
syncBindingFields
|
|
28
|
+
} from './protection'
|
|
29
|
+
import { walkInstanceSources } from './source-walk'
|
|
30
|
+
import { followComponentLayers } from './swap'
|
|
31
|
+
import {
|
|
32
|
+
applySyncedStrokeLines,
|
|
33
|
+
cloneChildrenWithMapping,
|
|
34
|
+
copyProp,
|
|
28
35
|
sourceInTargetCoordinates,
|
|
29
|
-
syncBindingFields,
|
|
30
36
|
syncChildren,
|
|
31
37
|
updateSyncedProps
|
|
32
38
|
} from './sync'
|
|
@@ -147,15 +153,14 @@ export function swapInstanceComponent(
|
|
|
147
153
|
const previousComponent = namedAfter(graph, instance, component)
|
|
148
154
|
recordNestedSwap(graph, instance, componentId)
|
|
149
155
|
const source = sourceInTargetCoordinates(component, instance.componentScale)
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
...ownSyncedProps(graph, instance, source).updates
|
|
153
|
-
}
|
|
156
|
+
const own = ownSyncedProps(graph, instance, source)
|
|
157
|
+
const updates: Partial<SceneNode> = { componentId, ...own.updates }
|
|
154
158
|
|
|
155
159
|
if (!keepName && (!previousComponent || instance.name === previousComponent.name))
|
|
156
160
|
updates.name = component.name
|
|
157
161
|
|
|
158
162
|
keepCopyBoundPaints(graph, instance, updates)
|
|
163
|
+
applySyncedStrokeLines(instance, updates, own.kept)
|
|
159
164
|
const slotContent = detachOwnedSlotContent(graph, instance)
|
|
160
165
|
graph.updateNode(instanceId, updates)
|
|
161
166
|
followComponentLayers(graph, instance, component, parkedContent(slotContent))
|
|
@@ -249,6 +254,8 @@ function syncInstancesOf(
|
|
|
249
254
|
export function detachInstance(graph: SceneGraph, instanceId: string): void {
|
|
250
255
|
const node = graph.nodes.get(instanceId)
|
|
251
256
|
if (node?.type !== 'INSTANCE') return
|
|
257
|
+
for (const nested of outermostNestedInstances(graph, node))
|
|
258
|
+
adoptNestedOverrides(graph, node, nested)
|
|
252
259
|
if (node.componentId) {
|
|
253
260
|
graph.instanceIndex.get(node.componentId)?.delete(instanceId)
|
|
254
261
|
}
|
|
@@ -257,6 +264,49 @@ export function detachInstance(graph: SceneGraph, instanceId: string): void {
|
|
|
257
264
|
clearInstanceOverrides(node.instanceOverrides)
|
|
258
265
|
}
|
|
259
266
|
|
|
267
|
+
// A swap's bookkeeping belongs to the instance enclosing the swapped one, never to the swapped one.
|
|
268
|
+
const OWNER_ONLY_FIELDS = new Set(['componentId', 'sourceComponentId'])
|
|
269
|
+
|
|
270
|
+
function outermostNestedInstances(graph: SceneGraph, instance: SceneNode): SceneNode[] {
|
|
271
|
+
return graph
|
|
272
|
+
.getChildren(instance.id)
|
|
273
|
+
.flatMap((child) =>
|
|
274
|
+
child.type === 'INSTANCE' ? [child] : outermostNestedInstances(graph, child)
|
|
275
|
+
)
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* An instance a detached one holds stands on its own once that one is a frame, and so must what
|
|
280
|
+
* makes it differ from its component. Cloned in, it kept the overrides of the instance it copies,
|
|
281
|
+
* under that instance's layers; those, and the ones the detached instance recorded on its layers,
|
|
282
|
+
* now go under its own.
|
|
283
|
+
*/
|
|
284
|
+
function adoptNestedOverrides(graph: SceneGraph, detached: SceneNode, nested: SceneNode): void {
|
|
285
|
+
const ownLayer = new Map<string, string>()
|
|
286
|
+
walkInstanceSources(graph, nested, (source, target) => {
|
|
287
|
+
ownLayer.set(source.id, target.id)
|
|
288
|
+
return true
|
|
289
|
+
})
|
|
290
|
+
const { self, descendants: kept } = cloneInstanceOverrideState(nested.instanceOverrides)
|
|
291
|
+
const outer = cloneInstanceOverrideState(detached.instanceOverrides).descendants
|
|
292
|
+
const descendants = new Map<string, Map<string, unknown>>()
|
|
293
|
+
const claim = (layerId: string, fields: Map<string, unknown>): void => {
|
|
294
|
+
const merged = descendants.get(layerId)
|
|
295
|
+
if (!merged) descendants.set(layerId, fields)
|
|
296
|
+
else for (const [field, value] of fields) merged.set(field, value)
|
|
297
|
+
}
|
|
298
|
+
// What was recorded on its own layers is more recent than what it copied, so it is laid on top.
|
|
299
|
+
for (const [layerId, fields] of kept)
|
|
300
|
+
if (ownLayer.has(layerId)) claim(ownLayer.get(layerId) ?? layerId, fields)
|
|
301
|
+
for (const [layerId, fields] of kept) if (!ownLayer.has(layerId)) claim(layerId, fields)
|
|
302
|
+
for (const [layerId, fields] of outer) {
|
|
303
|
+
if (layerId === nested.id) {
|
|
304
|
+
for (const [field, value] of fields) if (!OWNER_ONLY_FIELDS.has(field)) self.set(field, value)
|
|
305
|
+
} else if (graph.isDescendant(layerId, nested.id)) claim(layerId, fields)
|
|
306
|
+
}
|
|
307
|
+
graph.updateNode(nested.id, { instanceOverrides: { self, descendants } })
|
|
308
|
+
}
|
|
309
|
+
|
|
260
310
|
export function getMainComponent(graph: SceneGraph, instanceId: string): SceneNode | undefined {
|
|
261
311
|
const node = graph.nodes.get(instanceId)
|
|
262
312
|
if (!node?.componentId) return undefined
|
|
@@ -283,6 +333,16 @@ export function hasInstanceOverride(graph: SceneGraph, nodeId: string, field: st
|
|
|
283
333
|
return hasNodeInstanceOverride(instance.instanceOverrides, instance.id, nodeId, field)
|
|
284
334
|
}
|
|
285
335
|
|
|
336
|
+
/**
|
|
337
|
+
* The fields `changes` overrides on an instance layer. New strokes that change only what the
|
|
338
|
+
* layer's line fields say override those fields, not the paints (`changesMoreThanStrokeLines`).
|
|
339
|
+
*/
|
|
340
|
+
export function instanceOverrideFields(node: SceneNode, changes: Partial<SceneNode>): string[] {
|
|
341
|
+
const fields = Object.keys(changes)
|
|
342
|
+
if (!changes.strokes || changesMoreThanStrokeLines(node, changes)) return fields
|
|
343
|
+
return fields.filter((field) => field !== 'strokes')
|
|
344
|
+
}
|
|
345
|
+
|
|
286
346
|
export function recordInstanceOverride(
|
|
287
347
|
graph: SceneGraph,
|
|
288
348
|
nodeId: string,
|
|
@@ -295,10 +355,14 @@ export function recordInstanceOverride(
|
|
|
295
355
|
(INSTANCE_OVERRIDE_FIELDS as readonly string[]).includes(field)
|
|
296
356
|
)
|
|
297
357
|
|
|
298
|
-
|
|
358
|
+
const added = relevant.filter(
|
|
359
|
+
(field) => !hasNodeInstanceOverride(instance.instanceOverrides, instance.id, nodeId, field)
|
|
360
|
+
)
|
|
361
|
+
if (added.length === 0) return
|
|
299
362
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
363
|
+
// A new state rather than an edit of the old one, so a preview that captured the old state
|
|
364
|
+
// puts it back on cancel.
|
|
365
|
+
const overrides = cloneInstanceOverrideState(instance.instanceOverrides)
|
|
366
|
+
for (const field of added) setInstanceOverride(overrides, instance.id, nodeId, field)
|
|
367
|
+
graph.updateNode(instance.id, { instanceOverrides: overrides })
|
|
304
368
|
}
|
|
@@ -2,14 +2,11 @@
|
|
|
2
2
|
import { omit } from 'es-toolkit/object'
|
|
3
3
|
import { isEqual } from 'es-toolkit/predicate'
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
overriddenAssignmentId,
|
|
7
|
-
reapplyComponentPropertyAssignments
|
|
8
|
-
} from '../components/properties'
|
|
5
|
+
import { reapplyComponentPropertyAssignments } from '../components/properties'
|
|
9
6
|
import type { SceneGraph } from '../graph'
|
|
10
7
|
import type { SceneNode } from '../types'
|
|
11
8
|
import { instanceMainComponent } from './main-component'
|
|
12
|
-
import { overriddenBindingField } from './overrides'
|
|
9
|
+
import { overriddenAssignmentId, overriddenBindingField } from './overrides'
|
|
13
10
|
|
|
14
11
|
/** Where a switch runs: the switched instance and the instances enclosing the layers it changes. */
|
|
15
12
|
export interface OverrideScope {
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// Pairing an instance's children with its component's before a sync copies fields across.
|
|
2
|
+
import type { SceneGraph } from '../graph'
|
|
3
|
+
import type { SceneNode } from '../types'
|
|
4
|
+
import type { InstanceSyncContext } from './copies'
|
|
5
|
+
import {
|
|
6
|
+
copiedComponentLayerId,
|
|
7
|
+
hasInstanceOverride,
|
|
8
|
+
setInstanceOverride,
|
|
9
|
+
type InstanceOverrideState
|
|
10
|
+
} from './overrides'
|
|
11
|
+
|
|
12
|
+
/** Links a copy to the component layer it matched, reporting each changed node and its owner. */
|
|
13
|
+
function linkMatchedChild(
|
|
14
|
+
graph: SceneGraph,
|
|
15
|
+
context: InstanceSyncContext,
|
|
16
|
+
instParentId: string,
|
|
17
|
+
instChild: SceneNode,
|
|
18
|
+
compChildId: string
|
|
19
|
+
): void {
|
|
20
|
+
const { overrides } = context
|
|
21
|
+
const recorded = hasInstanceOverride(overrides, instParentId, instChild.id, 'sourceComponentId')
|
|
22
|
+
if (instChild.type === 'INSTANCE' || recorded) {
|
|
23
|
+
const owner = graph.nodes.get(context.instanceId)
|
|
24
|
+
graph.willChangeNode(owner)
|
|
25
|
+
setInstanceOverride(overrides, instParentId, instChild.id, 'sourceComponentId', compChildId)
|
|
26
|
+
if (owner) graph.updateNode(owner.id, { instanceOverrides: owner.instanceOverrides })
|
|
27
|
+
}
|
|
28
|
+
if (instChild.type !== 'INSTANCE') graph.updateNode(instChild.id, { componentId: compChildId })
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Children no link pairs, matched by type and name where the counts leave no doubt. */
|
|
32
|
+
export function matchFallbackChildren(
|
|
33
|
+
graph: SceneGraph,
|
|
34
|
+
compParent: SceneNode,
|
|
35
|
+
instParent: SceneNode,
|
|
36
|
+
instParentId: string,
|
|
37
|
+
context: InstanceSyncContext,
|
|
38
|
+
instChildMap: Map<string, SceneNode>,
|
|
39
|
+
usedInstChildIds: Set<string>
|
|
40
|
+
): void {
|
|
41
|
+
const fallbackByType = new Map<SceneNode['type'], Map<string, SceneNode[]>>()
|
|
42
|
+
const remainingCandidateCount = new Map<SceneNode['type'], number>()
|
|
43
|
+
const unmatchedComponentCount = new Map<SceneNode['type'], number>()
|
|
44
|
+
for (const compChildId of compParent.childIds) {
|
|
45
|
+
if (instChildMap.has(compChildId)) continue
|
|
46
|
+
const child = graph.nodes.get(compChildId)
|
|
47
|
+
if (child) {
|
|
48
|
+
unmatchedComponentCount.set(child.type, (unmatchedComponentCount.get(child.type) ?? 0) + 1)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
for (const childId of instParent.childIds) {
|
|
52
|
+
const child = graph.nodes.get(childId)
|
|
53
|
+
if (!child || usedInstChildIds.has(child.id)) continue
|
|
54
|
+
remainingCandidateCount.set(child.type, (remainingCandidateCount.get(child.type) ?? 0) + 1)
|
|
55
|
+
let byName = fallbackByType.get(child.type)
|
|
56
|
+
if (!byName) {
|
|
57
|
+
byName = new Map()
|
|
58
|
+
fallbackByType.set(child.type, byName)
|
|
59
|
+
}
|
|
60
|
+
const queue = byName.get(child.name)
|
|
61
|
+
if (queue) queue.push(child)
|
|
62
|
+
else byName.set(child.name, [child])
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Match by name and type with FIFO queues to preserve sibling order in linear time.
|
|
66
|
+
for (const compChildId of compParent.childIds) {
|
|
67
|
+
if (instChildMap.has(compChildId)) continue
|
|
68
|
+
const compChild = graph.nodes.get(compChildId)
|
|
69
|
+
if (!compChild) continue
|
|
70
|
+
const candidatesByName = fallbackByType.get(compChild.type)
|
|
71
|
+
const candidateCount = remainingCandidateCount.get(compChild.type) ?? 0
|
|
72
|
+
if (candidateCount > (unmatchedComponentCount.get(compChild.type) ?? 0)) continue
|
|
73
|
+
const match = candidatesByName?.get(compChild.name)?.shift()
|
|
74
|
+
if (!match) continue
|
|
75
|
+
remainingCandidateCount.set(compChild.type, candidateCount - 1)
|
|
76
|
+
instChildMap.set(compChildId, match)
|
|
77
|
+
usedInstChildIds.add(match.id)
|
|
78
|
+
linkMatchedChild(graph, context, instParentId, match, compChildId)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Children already linked to a component child by sourceComponentId or componentId. */
|
|
83
|
+
export function matchLinkedChildren(
|
|
84
|
+
graph: SceneGraph,
|
|
85
|
+
instParent: SceneNode,
|
|
86
|
+
instParentId: string,
|
|
87
|
+
overrides: InstanceOverrideState,
|
|
88
|
+
compChildIdSet: ReadonlySet<string>,
|
|
89
|
+
instChildMap: Map<string, SceneNode>,
|
|
90
|
+
usedInstChildIds: Set<string>
|
|
91
|
+
): void {
|
|
92
|
+
for (const childId of instParent.childIds) {
|
|
93
|
+
const child = graph.nodes.get(childId)
|
|
94
|
+
if (!child) continue
|
|
95
|
+
const mappedComponentId = copiedComponentLayerId(overrides, instParentId, child)
|
|
96
|
+
if (mappedComponentId && compChildIdSet.has(mappedComponentId)) {
|
|
97
|
+
instChildMap.set(mappedComponentId, child)
|
|
98
|
+
usedInstChildIds.add(child.id)
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -110,6 +110,19 @@ export interface InstanceOverrideReferenceMapper {
|
|
|
110
110
|
node: (id: string) => string
|
|
111
111
|
variable: (id: string) => string
|
|
112
112
|
collection?: (id: string) => string | undefined
|
|
113
|
+
property?: (id: string) => string | undefined
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const ASSIGNMENT_OVERRIDE_PREFIX = 'componentPropertyAssignments/'
|
|
117
|
+
|
|
118
|
+
export function assignmentOverrideField(propertyId: string): string {
|
|
119
|
+
return `${ASSIGNMENT_OVERRIDE_PREFIX}${propertyId}`
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function overriddenAssignmentId(field: string): string | undefined {
|
|
123
|
+
return field.startsWith(ASSIGNMENT_OVERRIDE_PREFIX)
|
|
124
|
+
? field.slice(ASSIGNMENT_OVERRIDE_PREFIX.length)
|
|
125
|
+
: undefined
|
|
113
126
|
}
|
|
114
127
|
|
|
115
128
|
const VARIABLE_MODE_FIELD_PREFIX = 'variableModes/'
|
|
@@ -136,6 +149,11 @@ export function remapInstanceOverrideState(
|
|
|
136
149
|
return value
|
|
137
150
|
}
|
|
138
151
|
const remapField = (field: string): string | undefined => {
|
|
152
|
+
const property = overriddenAssignmentId(field)
|
|
153
|
+
if (property !== undefined && references.property) {
|
|
154
|
+
const mapped = references.property(property)
|
|
155
|
+
return mapped === undefined ? undefined : assignmentOverrideField(mapped)
|
|
156
|
+
}
|
|
139
157
|
const collection = variableModeOverrideCollection(field)
|
|
140
158
|
if (collection === undefined || !references.collection) {
|
|
141
159
|
return field
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// What an instance's copy keeps through a sync: the fields it, or an instance around it, overrides.
|
|
2
|
+
import { isEmptyObject } from 'es-toolkit/predicate'
|
|
3
|
+
|
|
4
|
+
import type { SceneGraph } from '../graph'
|
|
5
|
+
import type { SceneNode } from '../types'
|
|
6
|
+
import { effectBindingTarget, paintBindingTarget } from '../variables/fields'
|
|
7
|
+
import { ownsSelfFillField } from './main-component'
|
|
8
|
+
import {
|
|
9
|
+
bindingOverrideField,
|
|
10
|
+
overriddenBindingField,
|
|
11
|
+
type InstanceOverrideState
|
|
12
|
+
} from './overrides'
|
|
13
|
+
|
|
14
|
+
/** Protection for a copy that keeps nothing of its own. */
|
|
15
|
+
export const NOTHING_PROTECTED = (_field: string): boolean => false
|
|
16
|
+
|
|
17
|
+
export function bindingProtection(scopes: ReadonlySet<string>[]): (field: string) => boolean {
|
|
18
|
+
const fields = new Set<string>()
|
|
19
|
+
for (const scope of scopes) {
|
|
20
|
+
const perField = [...scope].some((field) => overriddenBindingField(field) !== null)
|
|
21
|
+
for (const field of scope) {
|
|
22
|
+
if (field !== 'boundVariables' || !perField) fields.add(field)
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return (field) => {
|
|
26
|
+
if (fields.has(field)) return true
|
|
27
|
+
// Paints and effects an instance set itself own their bindings too, bound or not.
|
|
28
|
+
const binding = overriddenBindingField(field)
|
|
29
|
+
if (binding === null) return false
|
|
30
|
+
const paint = paintBindingTarget(binding)
|
|
31
|
+
if (paint) return fields.has(paint.list)
|
|
32
|
+
return fields.has('effects') && effectBindingTarget(binding) !== null
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function isUnbound(node: SceneNode): boolean {
|
|
37
|
+
return isEmptyObject(node.boundVariables) && isEmptyObject(node.variableBindingScales)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function syncBindingFields(
|
|
41
|
+
target: SceneNode,
|
|
42
|
+
source: SceneNode,
|
|
43
|
+
updates: Partial<SceneNode>,
|
|
44
|
+
protectedField: (field: string) => boolean
|
|
45
|
+
): void {
|
|
46
|
+
if (protectedField('boundVariables') || (isUnbound(source) && isUnbound(target))) {
|
|
47
|
+
return
|
|
48
|
+
}
|
|
49
|
+
const bindings = { ...source.boundVariables }
|
|
50
|
+
const scales = { ...source.variableBindingScales }
|
|
51
|
+
for (const field of new Set([
|
|
52
|
+
...Object.keys(source.boundVariables),
|
|
53
|
+
...Object.keys(target.boundVariables),
|
|
54
|
+
...Object.keys(target.variableBindingScales)
|
|
55
|
+
])) {
|
|
56
|
+
if (!protectedField(bindingOverrideField(field))) continue
|
|
57
|
+
if (!Object.hasOwn(target.boundVariables, field)) Reflect.deleteProperty(bindings, field)
|
|
58
|
+
else bindings[field] = target.boundVariables[field]
|
|
59
|
+
if (target.variableBindingScales[field] === undefined) Reflect.deleteProperty(scales, field)
|
|
60
|
+
else scales[field] = target.variableBindingScales[field]
|
|
61
|
+
}
|
|
62
|
+
updates.boundVariables = bindings
|
|
63
|
+
updates.variableBindingScales = scales
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function isProtectedSyncField(
|
|
67
|
+
node: SceneNode,
|
|
68
|
+
key: string,
|
|
69
|
+
protectedField: (field: string) => boolean
|
|
70
|
+
): boolean {
|
|
71
|
+
return (
|
|
72
|
+
protectedField(key) ||
|
|
73
|
+
(key in node.boundVariables &&
|
|
74
|
+
(protectedField('boundVariables') || protectedField(bindingOverrideField(key))))
|
|
75
|
+
)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function enclosingInstanceOverrideFields(graph: SceneGraph, node: SceneNode): Set<string>[] {
|
|
79
|
+
const fields: Set<string>[] = []
|
|
80
|
+
if (!node.parentId) return fields
|
|
81
|
+
graph.closest(node.parentId, (ancestor) => {
|
|
82
|
+
if (ancestor.type === 'INSTANCE') {
|
|
83
|
+
fields.push(new Set(ancestor.instanceOverrides.descendants.get(node.id)?.keys()))
|
|
84
|
+
}
|
|
85
|
+
return false
|
|
86
|
+
})
|
|
87
|
+
return fields
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** The fields a copy keeps: its own overrides and those of every instance around it. */
|
|
91
|
+
export function childBindingProtection(
|
|
92
|
+
graph: SceneGraph,
|
|
93
|
+
child: SceneNode,
|
|
94
|
+
overrides: InstanceOverrideState
|
|
95
|
+
) {
|
|
96
|
+
const fields = enclosingInstanceOverrideFields(graph, child)
|
|
97
|
+
fields.push(new Set(overrides.descendants.get(child.id)?.keys()))
|
|
98
|
+
if (child.instanceOverrides.self.size === 0 && fields.every((scope) => scope.size === 0)) {
|
|
99
|
+
return NOTHING_PROTECTED
|
|
100
|
+
}
|
|
101
|
+
const protectedField = bindingProtection(fields)
|
|
102
|
+
return (field: string) => protectedField(field) || ownsSelfFillField(child, field)
|
|
103
|
+
}
|
package/src/instances/swap.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { isEqual } from 'es-toolkit/predicate'
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} from '../components/properties'
|
|
3
|
+
import { appendAll } from '@open-pencil/std/arrays'
|
|
4
|
+
|
|
5
|
+
import { reapplyComponentPropertyAssignments } from '../components/properties'
|
|
7
6
|
import type { SceneGraph } from '../graph'
|
|
8
7
|
import { ownsSlotContent, slotPropertyId } from '../slots/frames'
|
|
9
8
|
import type { SceneNode } from '../types'
|
|
@@ -11,12 +10,16 @@ import { applyBoundPaintColorsIn, refreshBoundPaintsIn } from '../variables/pain
|
|
|
11
10
|
import { applyEnclosingAssignments } from './assignments'
|
|
12
11
|
import { keepOverrides, restoreOverrides, type OverrideScope } from './kept-overrides'
|
|
13
12
|
import { ownsSelfFillField } from './main-component'
|
|
14
|
-
import { hasInstanceOverride, overriddenBindingField, setInstanceOverride } from './overrides'
|
|
15
13
|
import {
|
|
16
|
-
|
|
14
|
+
hasInstanceOverride,
|
|
15
|
+
overriddenAssignmentId,
|
|
16
|
+
overriddenBindingField,
|
|
17
|
+
setInstanceOverride
|
|
18
|
+
} from './overrides'
|
|
19
|
+
import { bindingProtection, NOTHING_PROTECTED } from './protection'
|
|
20
|
+
import {
|
|
17
21
|
cloneChildInCoordinates,
|
|
18
22
|
cloneChildrenWithMapping,
|
|
19
|
-
NOTHING_PROTECTED,
|
|
20
23
|
syncCopy,
|
|
21
24
|
type MatchedCopy
|
|
22
25
|
} from './sync'
|
|
@@ -128,7 +131,7 @@ function untakenCopies(byLayer: CopiesByLayer): SceneNode[] {
|
|
|
128
131
|
}
|
|
129
132
|
}
|
|
130
133
|
for (const namesakes of byLayer.unlinked.values()) {
|
|
131
|
-
untaken
|
|
134
|
+
appendAll(untaken, namesakes)
|
|
132
135
|
}
|
|
133
136
|
return untaken
|
|
134
137
|
}
|
|
@@ -328,7 +331,7 @@ function matchCopies(swap: Swap, compParent: SceneNode, instParent: SceneNode) {
|
|
|
328
331
|
retyped.set(index, copy)
|
|
329
332
|
return undefined
|
|
330
333
|
})
|
|
331
|
-
stale
|
|
334
|
+
appendAll(stale, untakenCopies(byLayer))
|
|
332
335
|
return { matched, stale, retyped }
|
|
333
336
|
}
|
|
334
337
|
|