@pairdraw/scene-graph 0.19.2 → 0.21.0
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/color/index.d.ts +28 -7
- package/dist/color/index.d.ts.map +1 -1
- package/dist/color/index.js +40 -15
- package/dist/color/index.js.map +1 -1
- package/dist/color/management.d.ts +19 -6
- package/dist/color/management.d.ts.map +1 -1
- package/dist/color/management.js +56 -1
- package/dist/color/management.js.map +1 -1
- package/dist/color/profile.d.ts +32 -0
- package/dist/color/profile.d.ts.map +1 -0
- package/dist/color/profile.js +140 -0
- package/dist/color/profile.js.map +1 -0
- package/dist/comments/index.d.ts +2 -2
- package/dist/comments/index.js +2 -2
- package/dist/comments/merge.d.ts.map +1 -1
- package/dist/comments/merge.js +1 -0
- package/dist/comments/merge.js.map +1 -1
- package/dist/comments/schema.d.ts +3 -1
- package/dist/comments/schema.d.ts.map +1 -1
- package/dist/comments/schema.js +19 -2
- package/dist/comments/schema.js.map +1 -1
- package/dist/comments/threads.d.ts +3 -1
- package/dist/comments/threads.d.ts.map +1 -1
- package/dist/comments/threads.js +2 -1
- 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.map +1 -1
- package/dist/components/properties.js +7 -7
- package/dist/components/properties.js.map +1 -1
- package/dist/components/variants.d.ts +12 -1
- package/dist/components/variants.d.ts.map +1 -1
- package/dist/components/variants.js +30 -1
- package/dist/components/variants.js.map +1 -1
- package/dist/constants.d.ts +25 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +94 -1
- package/dist/constants.js.map +1 -1
- package/dist/copy.d.ts.map +1 -1
- package/dist/copy.js +17 -1
- package/dist/copy.js.map +1 -1
- package/dist/css/index.d.ts +2 -2
- package/dist/css/index.js +2 -2
- package/dist/css/shadows.d.ts +2 -2
- package/dist/css/shadows.d.ts.map +1 -1
- package/dist/css/shadows.js +4 -4
- package/dist/css/shadows.js.map +1 -1
- package/dist/css/text.d.ts +17 -1
- package/dist/css/text.d.ts.map +1 -1
- package/dist/css/text.js +62 -1
- package/dist/css/text.js.map +1 -1
- package/dist/css/values.d.ts +7 -2
- package/dist/css/values.d.ts.map +1 -1
- package/dist/css/values.js +8 -4
- package/dist/css/values.js.map +1 -1
- package/dist/design-memory/index.d.ts +3 -0
- package/dist/design-memory/index.js +3 -0
- package/dist/design-memory/model.d.ts +33 -0
- package/dist/design-memory/model.d.ts.map +1 -0
- package/dist/design-memory/model.js +142 -0
- package/dist/design-memory/model.js.map +1 -0
- package/dist/design-memory/schema.d.ts +76 -0
- package/dist/design-memory/schema.d.ts.map +1 -0
- package/dist/design-memory/schema.js +72 -0
- package/dist/design-memory/schema.js.map +1 -0
- package/dist/effects.d.ts +7 -4
- package/dist/effects.d.ts.map +1 -1
- package/dist/effects.js +9 -4
- package/dist/effects.js.map +1 -1
- package/dist/empty-values.js +102 -0
- package/dist/empty-values.js.map +1 -0
- package/dist/fields/components.d.ts +9 -0
- package/dist/fields/components.d.ts.map +1 -0
- package/dist/fields/components.js +24 -0
- package/dist/fields/components.js.map +1 -0
- package/dist/fields/index.d.ts +3 -2
- package/dist/fields/index.js +3 -2
- package/dist/fields/layout.d.ts +3 -1
- package/dist/fields/layout.d.ts.map +1 -1
- package/dist/fields/layout.js +10 -1
- package/dist/fields/layout.js.map +1 -1
- package/dist/graph.d.ts +12 -1
- package/dist/graph.d.ts.map +1 -1
- package/dist/graph.js +39 -7
- package/dist/graph.js.map +1 -1
- package/dist/grid-values.d.ts +10 -0
- package/dist/grid-values.d.ts.map +1 -0
- package/dist/grid-values.js +53 -0
- package/dist/grid-values.js.map +1 -0
- package/dist/hit-test/drop.d.ts +20 -0
- package/dist/hit-test/drop.d.ts.map +1 -0
- package/dist/hit-test/drop.js +54 -0
- package/dist/hit-test/drop.js.map +1 -0
- package/dist/hit-test/geometry.js +86 -0
- package/dist/hit-test/geometry.js.map +1 -0
- package/dist/hit-test/masks.d.ts +14 -0
- package/dist/hit-test/masks.d.ts.map +1 -0
- package/dist/hit-test/masks.js +41 -0
- package/dist/hit-test/masks.js.map +1 -0
- package/dist/hit-test/paint.d.ts +6 -0
- package/dist/hit-test/paint.d.ts.map +1 -0
- package/dist/hit-test/paint.js +19 -0
- package/dist/hit-test/paint.js.map +1 -0
- package/dist/hit-test.d.ts +4 -15
- package/dist/hit-test.d.ts.map +1 -1
- package/dist/hit-test.js +5 -173
- package/dist/hit-test.js.map +1 -1
- package/dist/images.d.ts +3 -2
- package/dist/images.d.ts.map +1 -1
- package/dist/images.js +18 -2
- package/dist/images.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/instances/copies.js +2 -1
- package/dist/instances/copies.js.map +1 -1
- 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 +2 -1
- package/dist/instances/index.d.ts.map +1 -1
- package/dist/instances/index.js +13 -12
- package/dist/instances/index.js.map +1 -1
- package/dist/instances/overrides.d.ts +15 -1
- package/dist/instances/overrides.d.ts.map +1 -1
- package/dist/instances/overrides.js +37 -1
- package/dist/instances/overrides.js.map +1 -1
- package/dist/instances/source-walk.d.ts +12 -0
- package/dist/instances/source-walk.d.ts.map +1 -0
- package/dist/instances/swap-overrides.js +3 -3
- package/dist/instances/swap-overrides.js.map +1 -1
- package/dist/instances/sync.js +9 -7
- package/dist/instances/sync.js.map +1 -1
- package/dist/node-defaults.d.ts.map +1 -1
- package/dist/node-defaults.js +43 -38
- package/dist/node-defaults.js.map +1 -1
- package/dist/plugin-data/fields.d.ts +90 -0
- package/dist/plugin-data/fields.d.ts.map +1 -1
- package/dist/plugin-data/fields.js +33 -24
- package/dist/plugin-data/fields.js.map +1 -1
- package/dist/plugin-data/index.d.ts +2 -2
- package/dist/plugin-data/index.js +2 -2
- package/dist/plugin-data/schema.d.ts +6 -1
- package/dist/plugin-data/schema.d.ts.map +1 -1
- package/dist/plugin-data/schema.js +24 -1
- package/dist/plugin-data/schema.js.map +1 -1
- package/dist/preview.d.ts.map +1 -1
- package/dist/preview.js +2 -0
- package/dist/preview.js.map +1 -1
- package/dist/scaling/node.d.ts.map +1 -1
- package/dist/scaling/node.js +5 -1
- package/dist/scaling/node.js.map +1 -1
- package/dist/shaders/animation.d.ts +21 -0
- package/dist/shaders/animation.d.ts.map +1 -0
- package/dist/shaders/animation.js +25 -0
- package/dist/shaders/animation.js.map +1 -0
- package/dist/shaders/index.d.ts +2 -1
- package/dist/shaders/index.js +2 -1
- package/dist/slots/content.d.ts.map +1 -1
- package/dist/slots/content.js +4 -4
- package/dist/slots/content.js.map +1 -1
- package/dist/statuses/index.d.ts +2 -2
- package/dist/statuses/index.js +2 -2
- package/dist/statuses/workflow.d.ts +3 -1
- package/dist/statuses/workflow.d.ts.map +1 -1
- package/dist/statuses/workflow.js +6 -2
- package/dist/statuses/workflow.js.map +1 -1
- package/dist/token-sources/document.d.ts +26 -0
- package/dist/token-sources/document.d.ts.map +1 -0
- package/dist/token-sources/document.js +80 -0
- package/dist/token-sources/document.js.map +1 -0
- package/dist/token-sources/index.d.ts +3 -0
- package/dist/token-sources/index.js +3 -0
- package/dist/token-sources/schema.d.ts +43 -0
- package/dist/token-sources/schema.d.ts.map +1 -0
- package/dist/token-sources/schema.js +50 -0
- package/dist/token-sources/schema.js.map +1 -0
- package/dist/transfer/variables.d.ts.map +1 -1
- package/dist/transfer/variables.js +1 -1
- package/dist/transfer/variables.js.map +1 -1
- package/dist/types.d.ts +135 -15
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/variables/bindings.d.ts +6 -5
- package/dist/variables/bindings.d.ts.map +1 -1
- package/dist/variables/bindings.js +24 -16
- package/dist/variables/bindings.js.map +1 -1
- package/dist/variables/formula/index.d.ts.map +1 -1
- package/dist/variables/formula/index.js +12 -6
- package/dist/variables/formula/index.js.map +1 -1
- package/dist/variables/index.d.ts +14 -1
- package/dist/variables/index.d.ts.map +1 -1
- package/dist/variables/index.js +38 -10
- package/dist/variables/index.js.map +1 -1
- package/dist/variables/paints.d.ts +9 -8
- package/dist/variables/paints.d.ts.map +1 -1
- package/dist/variables/paints.js +35 -26
- package/dist/variables/paints.js.map +1 -1
- package/dist/variables/resolver.d.ts +45 -0
- package/dist/variables/resolver.d.ts.map +1 -0
- package/dist/variables/resolver.js +106 -0
- package/dist/variables/resolver.js.map +1 -0
- package/dist/variations/copy.d.ts +16 -0
- package/dist/variations/copy.d.ts.map +1 -0
- package/dist/variations/copy.js +78 -0
- package/dist/variations/copy.js.map +1 -0
- package/dist/variations/index.d.ts +6 -0
- package/dist/variations/index.js +6 -0
- package/dist/variations/match.d.ts +23 -0
- package/dist/variations/match.d.ts.map +1 -0
- package/dist/variations/match.js +80 -0
- package/dist/variations/match.js.map +1 -0
- package/dist/variations/model.d.ts +39 -0
- package/dist/variations/model.d.ts.map +1 -0
- package/dist/variations/model.js +90 -0
- package/dist/variations/model.js.map +1 -0
- package/dist/variations/pick.d.ts +43 -0
- package/dist/variations/pick.d.ts.map +1 -0
- package/dist/variations/pick.js +211 -0
- package/dist/variations/pick.js.map +1 -0
- package/dist/variations/schema.d.ts +27 -0
- package/dist/variations/schema.d.ts.map +1 -0
- package/dist/variations/schema.js +27 -0
- package/dist/variations/schema.js.map +1 -0
- package/package.json +21 -1
- package/src/color/index.ts +43 -9
- package/src/color/management.ts +54 -1
- package/src/color/profile.ts +131 -0
- package/src/comments/merge.ts +3 -0
- package/src/comments/schema.ts +32 -2
- package/src/comments/threads.ts +5 -2
- package/src/components/properties.ts +13 -7
- package/src/components/variants.ts +39 -0
- package/src/constants.ts +75 -0
- package/src/copy.ts +20 -1
- package/src/css/index.ts +7 -1
- package/src/css/shadows.ts +8 -5
- package/src/css/text.ts +62 -0
- package/src/css/values.ts +12 -5
- package/src/design-memory/index.ts +2 -0
- package/src/design-memory/model.ts +143 -0
- package/src/design-memory/schema.ts +84 -0
- package/src/effects.ts +16 -7
- package/src/empty-values.ts +117 -0
- package/src/fields/components.ts +21 -0
- package/src/fields/index.ts +1 -0
- package/src/fields/layout.ts +10 -0
- package/src/graph.ts +50 -6
- package/src/grid-values.ts +47 -0
- package/src/hit-test/drop.ts +90 -0
- package/src/hit-test/geometry.ts +131 -0
- package/src/hit-test/masks.ts +57 -0
- package/src/hit-test/paint.ts +24 -0
- package/src/hit-test.ts +8 -277
- package/src/images.ts +27 -3
- package/src/instances/copies.ts +2 -1
- package/src/instances/fields.ts +2 -0
- package/src/instances/index.ts +20 -11
- package/src/instances/overrides.ts +49 -0
- package/src/instances/swap-overrides.ts +3 -2
- package/src/instances/sync.ts +11 -7
- package/src/node-defaults.ts +51 -41
- package/src/plugin-data/fields.ts +34 -32
- package/src/plugin-data/index.ts +1 -0
- package/src/plugin-data/schema.ts +30 -0
- package/src/preview.ts +2 -0
- package/src/scaling/node.ts +7 -2
- package/src/shaders/animation.ts +39 -0
- package/src/shaders/index.ts +1 -0
- package/src/slots/content.ts +8 -4
- package/src/statuses/workflow.ts +6 -4
- package/src/token-sources/document.ts +104 -0
- package/src/token-sources/index.ts +2 -0
- package/src/token-sources/schema.ts +59 -0
- package/src/transfer/variables.ts +2 -1
- package/src/types.ts +145 -14
- package/src/variables/bindings.ts +35 -18
- package/src/variables/formula/index.ts +19 -18
- package/src/variables/index.ts +49 -10
- package/src/variables/paints.ts +64 -29
- package/src/variables/resolver.ts +178 -0
- package/src/variations/copy.ts +89 -0
- package/src/variations/index.ts +5 -0
- package/src/variations/match.ts +100 -0
- package/src/variations/model.ts +132 -0
- package/src/variations/pick.ts +293 -0
- package/src/variations/schema.ts +29 -0
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export type InstanceOverrideField = string
|
|
2
2
|
|
|
3
|
+
import type { SceneNode } from '../types'
|
|
4
|
+
|
|
3
5
|
export interface InstanceOverrideState {
|
|
4
6
|
self: Map<InstanceOverrideField, unknown>
|
|
5
7
|
descendants: Map<string, Map<InstanceOverrideField, unknown>>
|
|
@@ -74,6 +76,53 @@ export function createInstanceOverrideState(): InstanceOverrideState {
|
|
|
74
76
|
return { self: new Map(), descendants: new Map() }
|
|
75
77
|
}
|
|
76
78
|
|
|
79
|
+
const SHARED_STATE_WRITE =
|
|
80
|
+
'the shared empty instance overrides are read-only; call ownInstanceOverrides(node) first'
|
|
81
|
+
|
|
82
|
+
/** A map the shared state throws from on every write, which still answers all reads. */
|
|
83
|
+
class SharedOverrideMap<K, V> extends Map<K, V> {
|
|
84
|
+
override set(key: K, value: V): this {
|
|
85
|
+
void key
|
|
86
|
+
void value
|
|
87
|
+
throw new Error(SHARED_STATE_WRITE)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
override delete(key: K): boolean {
|
|
91
|
+
void key
|
|
92
|
+
throw new Error(SHARED_STATE_WRITE)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
override clear(): void {
|
|
96
|
+
throw new Error(SHARED_STATE_WRITE)
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* What a layer holds until it records an override of its own. Shared and frozen, so an empty state
|
|
102
|
+
* costs nothing per layer and a write that skipped `ownInstanceOverrides` throws where it happens
|
|
103
|
+
* instead of reaching every layer of every document.
|
|
104
|
+
*/
|
|
105
|
+
export const EMPTY_INSTANCE_OVERRIDES: InstanceOverrideState = Object.freeze({
|
|
106
|
+
self: new SharedOverrideMap<InstanceOverrideField, unknown>(),
|
|
107
|
+
descendants: new SharedOverrideMap<string, Map<InstanceOverrideField, unknown>>()
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
export function isEmptyInstanceOverrideState(state: InstanceOverrideState): boolean {
|
|
111
|
+
return state.self.size === 0 && state.descendants.size === 0
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* The layer's own override state, giving it a fresh one when it still holds the shared empty
|
|
116
|
+
* state. Writers record through this and then persist it with `updateNode`, so the change reaches
|
|
117
|
+
* events and undo instead of only the layer.
|
|
118
|
+
*/
|
|
119
|
+
export function ownInstanceOverrides(node: SceneNode): InstanceOverrideState {
|
|
120
|
+
if (node.instanceOverrides !== EMPTY_INSTANCE_OVERRIDES) return node.instanceOverrides
|
|
121
|
+
const owned = createInstanceOverrideState()
|
|
122
|
+
node.instanceOverrides = owned
|
|
123
|
+
return owned
|
|
124
|
+
}
|
|
125
|
+
|
|
77
126
|
export interface SerializedOverrideValue {
|
|
78
127
|
defined: boolean
|
|
79
128
|
value?: unknown
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
isLayerReferenceOverride,
|
|
6
6
|
overriddenBindingField,
|
|
7
7
|
overriddenVariableModeCollection,
|
|
8
|
+
ownInstanceOverrides,
|
|
8
9
|
setInstanceOverride
|
|
9
10
|
} from './overrides'
|
|
10
11
|
import { copyProp } from './sync'
|
|
@@ -117,7 +118,7 @@ export function restoreInstanceOverrides(
|
|
|
117
118
|
const changes = changesFor(layer)
|
|
118
119
|
if (Object.keys(changes).length) graph.updateNode(child.id, changes)
|
|
119
120
|
for (const field of layer.fields)
|
|
120
|
-
setInstanceOverride(instance
|
|
121
|
+
setInstanceOverride(ownInstanceOverrides(instance), instance.id, child.id, field)
|
|
121
122
|
}
|
|
122
|
-
graph.updateNode(instance.id, { instanceOverrides: instance
|
|
123
|
+
graph.updateNode(instance.id, { instanceOverrides: ownInstanceOverrides(instance) })
|
|
123
124
|
}
|
package/src/instances/sync.ts
CHANGED
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
copyAppliedBoundPaints,
|
|
24
24
|
keepCopyBoundPaints
|
|
25
25
|
} from '../variables/paints'
|
|
26
|
+
import { createVariableResolver, type VariableResolver } from '../variables/resolver'
|
|
26
27
|
import { scaleVariableBindingUnits } from '../variables/units'
|
|
27
28
|
import { applyEnclosingAssignments, assignedFieldValues, propertyDrivenFields } from './assignments'
|
|
28
29
|
import { keepOwnContentSize, remeasureChangedText, type SyncedPlacement } from './content-size'
|
|
@@ -220,13 +221,14 @@ export function updateSyncedProps(
|
|
|
220
221
|
/** A field the copy keeps as its own, which the sync leaves as it is. */
|
|
221
222
|
kept: (field: string) => boolean = () => false
|
|
222
223
|
): void {
|
|
223
|
-
|
|
224
|
+
const resolver = createVariableResolver(graph)
|
|
225
|
+
resolveBoundNumbersInPlace(graph, target, updates, kept, resolver)
|
|
224
226
|
if (updates.fills || updates.strokes || updates.boundVariables) {
|
|
225
227
|
applySyncedModes(graph, target, updates)
|
|
226
|
-
keepCopyBoundPaints(graph, target, updates)
|
|
228
|
+
keepCopyBoundPaints(graph, target, updates, resolver)
|
|
227
229
|
}
|
|
228
230
|
// After the copy's own bound paints, which can bring its strokes into the write.
|
|
229
|
-
applySyncedStrokeLines(graph, target, updates, kept)
|
|
231
|
+
applySyncedStrokeLines(graph, target, updates, kept, resolver)
|
|
230
232
|
const changed = Object.fromEntries(
|
|
231
233
|
Object.entries(updates).filter(
|
|
232
234
|
([key, value]) => !isEqual(target[key as keyof SceneNode], value)
|
|
@@ -246,7 +248,8 @@ function resolveBoundNumbersInPlace(
|
|
|
246
248
|
graph: SceneGraph,
|
|
247
249
|
target: SceneNode,
|
|
248
250
|
updates: Partial<SceneNode>,
|
|
249
|
-
kept: (field: string) => boolean
|
|
251
|
+
kept: (field: string) => boolean,
|
|
252
|
+
resolver: VariableResolver
|
|
250
253
|
): void {
|
|
251
254
|
const bound = updates.boundVariables ?? target.boundVariables
|
|
252
255
|
// The fields the sync writes, and the ones it binds anew, which keep an equal value only in
|
|
@@ -259,7 +262,7 @@ function resolveBoundNumbersInPlace(
|
|
|
259
262
|
)
|
|
260
263
|
if (synced.length === 0) return
|
|
261
264
|
applySyncedModes(graph, target, updates)
|
|
262
|
-
const resolved = resolvedNumericBindings(graph, { ...target, ...updates })
|
|
265
|
+
const resolved = resolvedNumericBindings(graph, { ...target, ...updates }, 'active', resolver)
|
|
263
266
|
Object.assign(updates, pick(resolved, synced as (keyof SceneNode)[]))
|
|
264
267
|
}
|
|
265
268
|
|
|
@@ -278,7 +281,8 @@ export function applySyncedStrokeLines(
|
|
|
278
281
|
graph: SceneGraph,
|
|
279
282
|
target: SceneNode,
|
|
280
283
|
updates: Partial<SceneNode>,
|
|
281
|
-
kept: (field: string) => boolean
|
|
284
|
+
kept: (field: string) => boolean,
|
|
285
|
+
resolver: VariableResolver = createVariableResolver(graph)
|
|
282
286
|
): void {
|
|
283
287
|
const strokes = updates.strokes
|
|
284
288
|
const first = strokes?.at(0)
|
|
@@ -289,7 +293,7 @@ export function applySyncedStrokeLines(
|
|
|
289
293
|
const weightScale =
|
|
290
294
|
(updates.variableBindingScales ?? target.variableBindingScales).strokeWeight ?? 1
|
|
291
295
|
const resolvedWeight = boundWeight
|
|
292
|
-
?
|
|
296
|
+
? resolver.forNode(target.id, 'active').number(boundWeight)
|
|
293
297
|
: undefined
|
|
294
298
|
const lines: StrokeLines = {}
|
|
295
299
|
let set = false
|
package/src/node-defaults.ts
CHANGED
|
@@ -5,7 +5,8 @@ import {
|
|
|
5
5
|
DEFAULT_STROKE_WEIGHT
|
|
6
6
|
} from './constants'
|
|
7
7
|
import { normalizeEffects } from './effects'
|
|
8
|
-
import {
|
|
8
|
+
import { EMPTY_LIST, EMPTY_RECORD, shareEmptyNodeValues } from './empty-values'
|
|
9
|
+
import { EMPTY_INSTANCE_OVERRIDES } from './instances/overrides'
|
|
9
10
|
import { NO_LETTER_SPACING } from './text/lengths'
|
|
10
11
|
import type { NodeType, SceneNode, SourceMetadata } from './types'
|
|
11
12
|
|
|
@@ -14,18 +15,19 @@ export function createDefaultSourceMetadata(): SourceMetadata {
|
|
|
14
15
|
format: null,
|
|
15
16
|
id: null,
|
|
16
17
|
orderKey: null,
|
|
17
|
-
editedFields:
|
|
18
|
+
editedFields: EMPTY_LIST,
|
|
18
19
|
fig: {
|
|
19
20
|
rawSize: null,
|
|
20
21
|
rawTransform: null,
|
|
21
|
-
rawNodeFields:
|
|
22
|
+
rawNodeFields: EMPTY_RECORD,
|
|
22
23
|
layout: null,
|
|
23
|
-
symbolOverrides:
|
|
24
|
-
componentPropAssignments:
|
|
25
|
-
derivedSymbolData:
|
|
24
|
+
symbolOverrides: EMPTY_LIST,
|
|
25
|
+
componentPropAssignments: EMPTY_LIST,
|
|
26
|
+
derivedSymbolData: EMPTY_LIST,
|
|
26
27
|
derivedSymbolDataLayoutVersion: null,
|
|
27
28
|
uniformScaleFactor: null
|
|
28
|
-
}
|
|
29
|
+
},
|
|
30
|
+
drawio: null
|
|
29
31
|
}
|
|
30
32
|
}
|
|
31
33
|
|
|
@@ -100,7 +102,10 @@ export function createDefaultNode(
|
|
|
100
102
|
type: NodeType,
|
|
101
103
|
overrides: Partial<SceneNode> = {}
|
|
102
104
|
): SceneNode {
|
|
103
|
-
|
|
105
|
+
// A literal ending in a spread is built one field at a time, and V8 keeps an object given this
|
|
106
|
+
// many fields that way in dictionary mode, about 3 KB more per layer; a spread copy of a
|
|
107
|
+
// finished literal keeps fast fields, in JavaScriptCore as well.
|
|
108
|
+
const defaults = {
|
|
104
109
|
id: generateId(),
|
|
105
110
|
type,
|
|
106
111
|
name: type.charAt(0) + type.slice(1).toLowerCase(),
|
|
@@ -114,11 +119,13 @@ export function createDefaultNode(
|
|
|
114
119
|
source: createDefaultSourceMetadata(),
|
|
115
120
|
derivedLayout: null,
|
|
116
121
|
fills:
|
|
117
|
-
type === 'TEXT'
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
+
type === 'TEXT'
|
|
123
|
+
? [{ type: 'SOLID' as const, color: BLACK, opacity: 1, visible: true }]
|
|
124
|
+
: EMPTY_LIST,
|
|
125
|
+
strokes: EMPTY_LIST,
|
|
126
|
+
effects: EMPTY_LIST,
|
|
127
|
+
layoutGrids: EMPTY_LIST,
|
|
128
|
+
guides: EMPTY_LIST,
|
|
122
129
|
fillStyleId: null,
|
|
123
130
|
strokeStyleId: null,
|
|
124
131
|
textStyleId: null,
|
|
@@ -136,6 +143,8 @@ export function createDefaultNode(
|
|
|
136
143
|
visible: true,
|
|
137
144
|
locked: false,
|
|
138
145
|
clipsContent: false,
|
|
146
|
+
overflowDirection: 'NONE',
|
|
147
|
+
scrollBehavior: 'SCROLLS',
|
|
139
148
|
text: '',
|
|
140
149
|
fontSize: 14,
|
|
141
150
|
fontFamily: DEFAULT_FONT_FAMILY,
|
|
@@ -155,8 +164,8 @@ export function createDefaultNode(
|
|
|
155
164
|
layoutAlignSelf: 'AUTO',
|
|
156
165
|
vectorNetwork: null,
|
|
157
166
|
handleMirroring: 'NONE',
|
|
158
|
-
fillGeometry:
|
|
159
|
-
strokeGeometry:
|
|
167
|
+
fillGeometry: EMPTY_LIST,
|
|
168
|
+
strokeGeometry: EMPTY_LIST,
|
|
160
169
|
arcData: null,
|
|
161
170
|
textAlignVertical: 'TOP',
|
|
162
171
|
textAutoResize: 'NONE',
|
|
@@ -164,24 +173,24 @@ export function createDefaultNode(
|
|
|
164
173
|
textDecoration: 'NONE',
|
|
165
174
|
textDecorationStyle: 'SOLID',
|
|
166
175
|
textDecorationThickness: null,
|
|
167
|
-
textDecorationFills:
|
|
176
|
+
textDecorationFills: EMPTY_LIST,
|
|
168
177
|
textDecorationSkipInk: true,
|
|
169
178
|
textUnderlineOffset: null,
|
|
170
179
|
maxLines: null,
|
|
171
|
-
textParagraphs:
|
|
180
|
+
textParagraphs: EMPTY_LIST,
|
|
172
181
|
listSpacing: 0,
|
|
173
182
|
paragraphSpacing: 0,
|
|
174
183
|
paragraphIndent: 0,
|
|
175
184
|
hangingList: false,
|
|
176
|
-
styleRuns:
|
|
177
|
-
fontVariations:
|
|
185
|
+
styleRuns: EMPTY_LIST,
|
|
186
|
+
fontVariations: EMPTY_LIST,
|
|
178
187
|
opticalSizeFromFontSize: true,
|
|
179
|
-
fontFeatures:
|
|
188
|
+
fontFeatures: EMPTY_LIST,
|
|
180
189
|
horizontalConstraint: 'MIN',
|
|
181
190
|
verticalConstraint: 'MIN',
|
|
182
191
|
strokeCap: 'NONE',
|
|
183
192
|
strokeJoin: 'MITER',
|
|
184
|
-
dashPattern:
|
|
193
|
+
dashPattern: EMPTY_LIST,
|
|
185
194
|
borderTopWeight: 0,
|
|
186
195
|
borderRightWeight: 0,
|
|
187
196
|
borderBottomWeight: 0,
|
|
@@ -200,14 +209,14 @@ export function createDefaultNode(
|
|
|
200
209
|
connectorLineType: 'ELBOWED',
|
|
201
210
|
connectorStartCap: 'ROUND',
|
|
202
211
|
connectorEndCap: 'ARROW_LINES',
|
|
203
|
-
connectorControlPoints:
|
|
212
|
+
connectorControlPoints: EMPTY_LIST,
|
|
204
213
|
connectorCurveHandles: null,
|
|
205
214
|
connectorLabelPosition: null,
|
|
206
215
|
isMask: false,
|
|
207
216
|
maskType: 'ALPHA',
|
|
208
217
|
maskIsOutline: false,
|
|
209
|
-
gridTemplateColumns:
|
|
210
|
-
gridTemplateRows:
|
|
218
|
+
gridTemplateColumns: EMPTY_LIST,
|
|
219
|
+
gridTemplateRows: EMPTY_LIST,
|
|
211
220
|
gridColumnGap: 0,
|
|
212
221
|
gridRowGap: 0,
|
|
213
222
|
gridPosition: null,
|
|
@@ -223,11 +232,11 @@ export function createDefaultNode(
|
|
|
223
232
|
shapeUserHeight: 0,
|
|
224
233
|
shapeTruncates: false,
|
|
225
234
|
componentId: null,
|
|
226
|
-
instanceOverrides:
|
|
227
|
-
componentPropertyDefinitions:
|
|
228
|
-
componentPropertyReferences:
|
|
229
|
-
componentPropertyAssignments:
|
|
230
|
-
componentPropertyValues:
|
|
235
|
+
instanceOverrides: EMPTY_INSTANCE_OVERRIDES,
|
|
236
|
+
componentPropertyDefinitions: EMPTY_LIST,
|
|
237
|
+
componentPropertyReferences: EMPTY_LIST,
|
|
238
|
+
componentPropertyAssignments: EMPTY_RECORD,
|
|
239
|
+
componentPropertyValues: EMPTY_RECORD,
|
|
231
240
|
componentKey: null,
|
|
232
241
|
sourceLibraryKey: null,
|
|
233
242
|
publishId: null,
|
|
@@ -239,18 +248,18 @@ export function createDefaultNode(
|
|
|
239
248
|
isSymbolPublishable: false,
|
|
240
249
|
isExposedInstance: false,
|
|
241
250
|
symbolDescription: '',
|
|
242
|
-
symbolLinks:
|
|
243
|
-
variantPropSpecs:
|
|
244
|
-
boundVariables:
|
|
245
|
-
variableBindingScales:
|
|
246
|
-
variableAssignmentScales:
|
|
251
|
+
symbolLinks: EMPTY_LIST,
|
|
252
|
+
variantPropSpecs: EMPTY_LIST,
|
|
253
|
+
boundVariables: EMPTY_RECORD,
|
|
254
|
+
variableBindingScales: EMPTY_RECORD,
|
|
255
|
+
variableAssignmentScales: EMPTY_RECORD,
|
|
247
256
|
componentScale: 1,
|
|
248
|
-
variableModes:
|
|
249
|
-
exportSettings:
|
|
257
|
+
variableModes: EMPTY_RECORD,
|
|
258
|
+
exportSettings: EMPTY_LIST,
|
|
250
259
|
status: null,
|
|
251
|
-
pluginData:
|
|
252
|
-
pluginRelaunchData:
|
|
253
|
-
prototypeReactions:
|
|
260
|
+
pluginData: EMPTY_LIST,
|
|
261
|
+
pluginRelaunchData: EMPTY_LIST,
|
|
262
|
+
prototypeReactions: EMPTY_LIST,
|
|
254
263
|
internalOnly: false,
|
|
255
264
|
flipX: false,
|
|
256
265
|
flipY: false,
|
|
@@ -259,10 +268,11 @@ export function createDefaultNode(
|
|
|
259
268
|
derivedTextHeight: null,
|
|
260
269
|
textPathData: null,
|
|
261
270
|
textPathBox: null,
|
|
262
|
-
booleanOperation: undefined
|
|
263
|
-
...overrides
|
|
271
|
+
booleanOperation: undefined
|
|
264
272
|
} satisfies CompleteNodeFields
|
|
273
|
+
const node: SceneNode = { ...defaults, ...overrides }
|
|
265
274
|
node.effects = normalizeEffects(node.effects)
|
|
275
|
+
shareEmptyNodeValues(node, Object.keys(overrides))
|
|
266
276
|
return node
|
|
267
277
|
}
|
|
268
278
|
|
|
@@ -5,6 +5,7 @@ import { behaviourSchema } from '../behaviours/schema'
|
|
|
5
5
|
import { browserNodeSchema } from '../browser-node/schema'
|
|
6
6
|
import type { OkHCLPayload } from '../color/okhcl'
|
|
7
7
|
import { commentThreadsSchema } from '../comments/schema'
|
|
8
|
+
import { designMemorySchema } from '../design-memory/schema'
|
|
8
9
|
import { clampExportQuality, isExportFormatId, type ExportFormatId } from '../export-format'
|
|
9
10
|
import { clampExportScale } from '../export-scale'
|
|
10
11
|
import { FIG_COMPRESSIONS } from '../fig-compression'
|
|
@@ -13,25 +14,25 @@ import type { Color, Rect, Vector } from '../primitives'
|
|
|
13
14
|
import { scriptNodeSchema } from '../script/schema'
|
|
14
15
|
import { shaderPaintSchema } from '../shaders/schema'
|
|
15
16
|
import { nodeStatusSchema, statusWorkflowSchema } from '../statuses/schema'
|
|
17
|
+
import { tokenSourcesSchema } from '../token-sources/schema'
|
|
16
18
|
import {
|
|
17
19
|
MODE_ATTRIBUTE_PATTERN,
|
|
18
20
|
TOKEN_UNITS,
|
|
19
|
-
type EnabledLibraryBinding,
|
|
20
21
|
type ExportSetting,
|
|
21
22
|
type LayoutDirection,
|
|
22
23
|
type LibraryAssetSource,
|
|
23
24
|
type PluginDataEntry,
|
|
24
|
-
type SourceLibraryPublication,
|
|
25
25
|
type TextDirection,
|
|
26
26
|
type TokenUnit
|
|
27
27
|
} from '../types'
|
|
28
|
+
import { variationSetSchema, variationStandInSchema } from '../variations/schema'
|
|
28
29
|
import {
|
|
29
30
|
jsonPluginDataField,
|
|
30
31
|
textPluginDataField,
|
|
31
32
|
withoutPluginData,
|
|
32
33
|
type PluginDataKey
|
|
33
34
|
} from './field'
|
|
34
|
-
import { webCitationSchema } from './schema'
|
|
35
|
+
import { enabledLibrariesSchema, sourceLibraryPublicationSchema, webCitationSchema } from './schema'
|
|
35
36
|
|
|
36
37
|
const DIRECTIONS = ['AUTO', 'LTR', 'RTL'] as const satisfies readonly (
|
|
37
38
|
| TextDirection
|
|
@@ -76,6 +77,11 @@ const exportSettingsSchema: v.GenericSchema<unknown, ExportSetting[]> = v.array(
|
|
|
76
77
|
)
|
|
77
78
|
)
|
|
78
79
|
|
|
80
|
+
const clipboardOriginSchema = v.object({
|
|
81
|
+
documentId: v.pipe(v.string(), v.nonEmpty(), v.maxLength(64)),
|
|
82
|
+
nodeId: v.pipe(v.string(), v.nonEmpty(), v.maxLength(64))
|
|
83
|
+
})
|
|
84
|
+
|
|
79
85
|
const librarySourceSchema: v.GenericSchema<unknown, LibraryAssetSource> = v.pipe(
|
|
80
86
|
v.object({
|
|
81
87
|
identity: v.object({ libraryId: v.string(), assetKey: v.string(), revisionId: v.string() }),
|
|
@@ -89,25 +95,6 @@ const librarySourceSchema: v.GenericSchema<unknown, LibraryAssetSource> = v.pipe
|
|
|
89
95
|
}))
|
|
90
96
|
)
|
|
91
97
|
|
|
92
|
-
const enabledLibrarySchema = v.object({
|
|
93
|
-
libraryId: v.string(),
|
|
94
|
-
revisionId: v.string(),
|
|
95
|
-
enabled: v.optional(v.unknown())
|
|
96
|
-
})
|
|
97
|
-
|
|
98
|
-
/** Invalid entries are skipped one by one, so one bad binding keeps the others. */
|
|
99
|
-
const enabledLibrariesSchema: v.GenericSchema<unknown, EnabledLibraryBinding[]> = v.pipe(
|
|
100
|
-
v.array(v.unknown()),
|
|
101
|
-
v.transform((items) =>
|
|
102
|
-
items.flatMap((item) => {
|
|
103
|
-
const parsed = v.safeParse(enabledLibrarySchema, item)
|
|
104
|
-
if (!parsed.success) return []
|
|
105
|
-
const { libraryId, revisionId, enabled } = parsed.output
|
|
106
|
-
return [{ libraryId, revisionId, enabled: enabled === true }]
|
|
107
|
-
})
|
|
108
|
-
)
|
|
109
|
-
)
|
|
110
|
-
|
|
111
98
|
// Shape only. Whether a string is valid CSS is checked where it is written into a stylesheet.
|
|
112
99
|
const cssTextSchema = v.pipe(v.string(), v.trim(), v.nonEmpty(), v.maxLength(1000))
|
|
113
100
|
|
|
@@ -193,15 +180,6 @@ const meshFillsSchema: v.GenericSchema<unknown, StoredMeshFill[]> = v.pipe(
|
|
|
193
180
|
)
|
|
194
181
|
)
|
|
195
182
|
|
|
196
|
-
const sourceLibraryPublicationSchema: v.GenericSchema<unknown, SourceLibraryPublication> = v.object(
|
|
197
|
-
{
|
|
198
|
-
libraryId: v.string(),
|
|
199
|
-
revisionId: v.string(),
|
|
200
|
-
name: v.string(),
|
|
201
|
-
catalogSource: v.optional(v.string())
|
|
202
|
-
}
|
|
203
|
-
)
|
|
204
|
-
|
|
205
183
|
/**
|
|
206
184
|
* Every plugin-data entry Pairdraw writes under {@link PAIRDRAW_PLUGIN_ID}: state Figma's
|
|
207
185
|
* format has no field for. Add a key here, never as a string elsewhere, so reading and writing
|
|
@@ -228,6 +206,11 @@ export const PAIRDRAW_PLUGIN_DATA = {
|
|
|
228
206
|
textPathBox: jsonPluginDataField('textPathBox', 'format', textPathBoxSchema),
|
|
229
207
|
/** The library asset a node was inserted from. */
|
|
230
208
|
librarySource: jsonPluginDataField('librarySource', 'bookkeeping', librarySourceSchema),
|
|
209
|
+
/**
|
|
210
|
+
* Where a layer of a pasted component came from: the copying document's root id and the node's id
|
|
211
|
+
* there. A later paste of the same snapshot into that document reuses the component it made.
|
|
212
|
+
*/
|
|
213
|
+
clipboardOrigin: jsonPluginDataField('clipboardOrigin', 'bookkeeping', clipboardOriginSchema),
|
|
231
214
|
/**
|
|
232
215
|
* The document root's id, on the DOCUMENT node, whose own GUID is always Figma's `0:0`; the
|
|
233
216
|
* root keeps it across a save as every layer keeps its GUID.
|
|
@@ -245,10 +228,19 @@ export const PAIRDRAW_PLUGIN_DATA = {
|
|
|
245
228
|
'bookkeeping',
|
|
246
229
|
sourceLibraryPublicationSchema
|
|
247
230
|
),
|
|
231
|
+
/**
|
|
232
|
+
* The `.pen` documents this document imports, by alias and relative path, on the DOCUMENT node.
|
|
233
|
+
* A `.pen` file names them in its own `imports`, so a save writes them back from here.
|
|
234
|
+
*/
|
|
235
|
+
penImports: jsonPluginDataField('penImports', 'bookkeeping', v.record(v.string(), v.string())),
|
|
248
236
|
/** Canvas comment threads, deleted ones included, on the DOCUMENT node. */
|
|
249
237
|
comments: jsonPluginDataField('comments', 'bookkeeping', commentThreadsSchema),
|
|
250
238
|
/** The statuses layers can be in, on the DOCUMENT node. */
|
|
251
239
|
statuses: jsonPluginDataField('statuses', 'bookkeeping', statusWorkflowSchema),
|
|
240
|
+
/** The code the document's variables are linked to, on the DOCUMENT node. */
|
|
241
|
+
tokenSources: jsonPluginDataField('tokenSources', 'bookkeeping', tokenSourcesSchema),
|
|
242
|
+
/** The design rules agents follow in the document, on the DOCUMENT node. */
|
|
243
|
+
designMemory: jsonPluginDataField('designMemory', 'bookkeeping', designMemorySchema),
|
|
252
244
|
/** How tightly the document's `.fig` data is compressed, on the DOCUMENT node. */
|
|
253
245
|
figCompression: textPluginDataField('figCompression', 'bookkeeping', FIG_COMPRESSIONS),
|
|
254
246
|
/** A layer's status, any state of the workflow; Figma's `sectionStatusInfo` knows only two. */
|
|
@@ -289,7 +281,17 @@ export const PAIRDRAW_PLUGIN_DATA = {
|
|
|
289
281
|
* A snapshot of one page: its address, viewport, and when it was refreshed. The picture is
|
|
290
282
|
* the layer's image fill. An address that is not an http or https page does not decode.
|
|
291
283
|
*/
|
|
292
|
-
browserNode: jsonPluginDataField('browserNode', 'content', browserNodeSchema)
|
|
284
|
+
browserNode: jsonPluginDataField('browserNode', 'content', browserNodeSchema),
|
|
285
|
+
/**
|
|
286
|
+
* On a section, that its children are variations of another layer: which one, and how that
|
|
287
|
+
* layer looked when they were made. A copy of the section is an ordinary section.
|
|
288
|
+
*/
|
|
289
|
+
variationSet: jsonPluginDataField('variationSet', 'bookkeeping', variationSetSchema),
|
|
290
|
+
/**
|
|
291
|
+
* On a layer of a version, the main component or component set of the original it stands in
|
|
292
|
+
* for, so a pick keeps that component rather than pairing it by name.
|
|
293
|
+
*/
|
|
294
|
+
variationStandIn: jsonPluginDataField('variationStandIn', 'bookkeeping', variationStandInSchema)
|
|
293
295
|
} satisfies Record<string, PluginDataKey>
|
|
294
296
|
|
|
295
297
|
const NOT_CONTENT = Object.values(PAIRDRAW_PLUGIN_DATA).filter((field) => field.role !== 'content')
|
package/src/plugin-data/index.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import * as v from 'valibot'
|
|
2
2
|
|
|
3
|
+
import type { EnabledLibraryBinding, SourceLibraryPublication } from '../types'
|
|
4
|
+
|
|
3
5
|
/** A quote kept on a sticky. A longer passage is cut before it is stored. */
|
|
4
6
|
export const CITATION_QUOTE_LIMIT = 2_000
|
|
5
7
|
|
|
@@ -33,3 +35,31 @@ export const webCitationSchema = v.object({
|
|
|
33
35
|
})
|
|
34
36
|
|
|
35
37
|
export type WebCitation = v.InferOutput<typeof webCitationSchema>
|
|
38
|
+
|
|
39
|
+
const enabledLibrarySchema = v.object({
|
|
40
|
+
libraryId: v.string(),
|
|
41
|
+
revisionId: v.string(),
|
|
42
|
+
enabled: v.optional(v.unknown())
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
/** One library a document switched on; invalid entries are skipped one by one. */
|
|
46
|
+
export const enabledLibrariesSchema: v.GenericSchema<unknown, EnabledLibraryBinding[]> = v.pipe(
|
|
47
|
+
v.array(v.unknown()),
|
|
48
|
+
v.transform((items) =>
|
|
49
|
+
items.flatMap((item) => {
|
|
50
|
+
const parsed = v.safeParse(enabledLibrarySchema, item)
|
|
51
|
+
if (!parsed.success) return []
|
|
52
|
+
const { libraryId, revisionId, enabled } = parsed.output
|
|
53
|
+
return [{ libraryId, revisionId, enabled: enabled === true }]
|
|
54
|
+
})
|
|
55
|
+
)
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
/** The library a document publishes as: its identity, its revision, and where it was published. */
|
|
59
|
+
export const sourceLibraryPublicationSchema: v.GenericSchema<unknown, SourceLibraryPublication> =
|
|
60
|
+
v.object({
|
|
61
|
+
libraryId: v.string(),
|
|
62
|
+
revisionId: v.string(),
|
|
63
|
+
name: v.string(),
|
|
64
|
+
catalogSource: v.optional(v.string())
|
|
65
|
+
})
|
package/src/preview.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { normalizeEffects } from './effects'
|
|
2
|
+
import { shareEmptyNodeValues } from './empty-values'
|
|
2
3
|
import { textCacheInvalidationChanges } from './text/picture'
|
|
3
4
|
import type { SceneNode } from './types'
|
|
4
5
|
import { normalizeVectorNetwork } from './vector-network'
|
|
@@ -80,5 +81,6 @@ export function updateNodePreview(
|
|
|
80
81
|
beforeUpdate?.(node, normalizedChanges)
|
|
81
82
|
graph.positionPreviewVersion++
|
|
82
83
|
Object.assign(node, normalizedChanges)
|
|
84
|
+
shareEmptyNodeValues(node, Object.keys(normalizedChanges))
|
|
83
85
|
return normalizedChanges
|
|
84
86
|
}
|
package/src/scaling/node.ts
CHANGED
|
@@ -52,8 +52,13 @@ function scaledStrokes(strokes: readonly Stroke[], scale: number): Stroke[] {
|
|
|
52
52
|
function scaledEffects(effects: readonly Effect[], scale: number): Effect[] {
|
|
53
53
|
return effects.map((effect) => {
|
|
54
54
|
const copy = structuredClone(effect)
|
|
55
|
-
// A shader effect has no geometry of its own
|
|
56
|
-
if (copy.type === 'SHADER') return copy
|
|
55
|
+
// A shader effect has no geometry of its own, and a noise's grain keeps its size.
|
|
56
|
+
if (copy.type === 'SHADER' || copy.type === 'NOISE') return copy
|
|
57
|
+
// A texture roughens the edges by its radius; its grain keeps its size too.
|
|
58
|
+
if (copy.type === 'TEXTURE') {
|
|
59
|
+
copy.radius *= scale
|
|
60
|
+
return copy
|
|
61
|
+
}
|
|
57
62
|
copy.offset = { x: copy.offset.x * scale, y: copy.offset.y * scale }
|
|
58
63
|
copy.radius *= scale
|
|
59
64
|
copy.spread *= scale
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { ShaderComponent, ShaderPreset } from './schema'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* What the library says of an effect's motion: whether it is driven by time, and whether a
|
|
5
|
+
* `speed` prop of its own decides how fast it moves.
|
|
6
|
+
*/
|
|
7
|
+
export interface ShaderEffectMotion {
|
|
8
|
+
animates: boolean
|
|
9
|
+
speed: boolean
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** What the caller knows of an effect's motion, or undefined for an effect it does not know yet. */
|
|
13
|
+
export type ShaderMotion = (type: string) => ShaderEffectMotion | undefined
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Whether `component` draws a picture that changes with time. An effect missing from the
|
|
17
|
+
* library's metadata counts as animated, so a newer effect plays rather than freezing; `speed: 0`
|
|
18
|
+
* and an `animated` switch turned off stop it.
|
|
19
|
+
*/
|
|
20
|
+
function componentAnimates(component: ShaderComponent, motion: ShaderMotion): boolean {
|
|
21
|
+
const props = component.props ?? {}
|
|
22
|
+
if (props.animated === true) return true
|
|
23
|
+
const known = motion(component.type)
|
|
24
|
+
const moves =
|
|
25
|
+
typeof props.speed === 'number'
|
|
26
|
+
? props.speed !== 0
|
|
27
|
+
: known === undefined || known.animates || known.speed
|
|
28
|
+
if (moves) return true
|
|
29
|
+
return (component.children ?? []).some((child) => componentAnimates(child, motion))
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Whether `preset` changes between frames: any of its effects animates. A preset of still
|
|
34
|
+
* effects, or one whose animated effects are all at `speed: 0`, draws one picture forever and
|
|
35
|
+
* does not need a player.
|
|
36
|
+
*/
|
|
37
|
+
export function presetAnimates(preset: ShaderPreset, motion: ShaderMotion): boolean {
|
|
38
|
+
return preset.components.some((component) => componentAnimates(component, motion))
|
|
39
|
+
}
|
package/src/shaders/index.ts
CHANGED
package/src/slots/content.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { isGeneratedFrame } from '../generated'
|
|
2
2
|
import type { SceneGraph } from '../graph'
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
getInstanceOverride,
|
|
5
|
+
ownInstanceOverrides,
|
|
6
|
+
setInstanceOverride
|
|
7
|
+
} from '../instances/overrides'
|
|
4
8
|
import { cloneChildrenWithMapping } from '../instances/sync'
|
|
5
9
|
import type { SceneNode } from '../types'
|
|
6
10
|
import { applyBoundPaintColorsIn } from '../variables/paints'
|
|
@@ -63,7 +67,7 @@ export function claimSlotContent(
|
|
|
63
67
|
): void {
|
|
64
68
|
const { frame, instance, propertyId } = scope
|
|
65
69
|
if (ownsSlotContent(graph, frame, propertyId)) return
|
|
66
|
-
const overrides = instance
|
|
70
|
+
const overrides = ownInstanceOverrides(instance)
|
|
67
71
|
for (const node of descendants(graph, frame, false)) {
|
|
68
72
|
overrides.descendants.delete(node.id)
|
|
69
73
|
if (node.type !== 'INSTANCE') {
|
|
@@ -76,10 +80,10 @@ export function claimSlotContent(
|
|
|
76
80
|
if (!fields) continue
|
|
77
81
|
for (const [field, value] of fields)
|
|
78
82
|
if (field !== 'sourceComponentId')
|
|
79
|
-
setInstanceOverride(node
|
|
83
|
+
setInstanceOverride(ownInstanceOverrides(node), node.id, inner.id, field, value)
|
|
80
84
|
overrides.descendants.delete(inner.id)
|
|
81
85
|
}
|
|
82
|
-
graph.updateNode(node.id, { instanceOverrides: node
|
|
86
|
+
graph.updateNode(node.id, { instanceOverrides: ownInstanceOverrides(node) })
|
|
83
87
|
}
|
|
84
88
|
graph.updateNode(instance.id, {
|
|
85
89
|
instanceOverrides: overrides,
|
package/src/statuses/workflow.ts
CHANGED
|
@@ -63,10 +63,12 @@ export type StatusWorkflowPreset = keyof typeof STATUS_WORKFLOW_PRESETS
|
|
|
63
63
|
* Ready for dev and Completed read as statuses without setup.
|
|
64
64
|
*/
|
|
65
65
|
export function readStatusWorkflow(graph: SceneGraph): StatusWorkflow {
|
|
66
|
-
return (
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
66
|
+
return readStoredStatusWorkflow(graph) ?? STATUS_WORKFLOW_PRESETS.handoff
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** The workflow the document stored, or `undefined` when it never chose one. */
|
|
70
|
+
export function readStoredStatusWorkflow(graph: SceneGraph): StatusWorkflow | undefined {
|
|
71
|
+
return readPluginData(graph.getNode(graph.rootId)?.pluginData, statuses)
|
|
70
72
|
}
|
|
71
73
|
|
|
72
74
|
/** Stores the workflow on the document node, as an undoable document change. */
|