@open-pencil/scene-graph 0.17.0-beta.1 → 0.17.0-beta.3
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/arrow-caps.d.ts.map +1 -1
- package/dist/arrow-caps.js +2 -5
- package/dist/arrow-caps.js.map +1 -1
- package/dist/asset-keys.d.ts +11 -1
- package/dist/asset-keys.d.ts.map +1 -1
- package/dist/asset-keys.js +16 -1
- package/dist/asset-keys.js.map +1 -1
- package/dist/behaviours/index.d.ts +2 -2
- package/dist/behaviours/index.js +2 -2
- package/dist/behaviours/kinds.d.ts +11 -5
- package/dist/behaviours/kinds.d.ts.map +1 -1
- package/dist/behaviours/kinds.js +76 -75
- package/dist/behaviours/kinds.js.map +1 -1
- package/dist/behaviours/layers.d.ts.map +1 -1
- package/dist/behaviours/layers.js +3 -2
- package/dist/behaviours/layers.js.map +1 -1
- package/dist/behaviours/model.d.ts +7 -4
- package/dist/behaviours/model.d.ts.map +1 -1
- package/dist/behaviours/model.js +16 -9
- package/dist/behaviours/model.js.map +1 -1
- package/dist/behaviours/schema.d.ts +118 -4
- package/dist/behaviours/schema.d.ts.map +1 -1
- package/dist/behaviours/schema.js +18 -3
- package/dist/behaviours/schema.js.map +1 -1
- package/dist/behaviours/spec.d.ts.map +1 -1
- package/dist/behaviours/spec.js +3 -2
- package/dist/behaviours/spec.js.map +1 -1
- package/dist/bindings.js +9 -1
- package/dist/bindings.js.map +1 -1
- package/dist/checkpoint.d.ts +31 -2
- package/dist/checkpoint.d.ts.map +1 -1
- package/dist/checkpoint.js +211 -10
- package/dist/checkpoint.js.map +1 -1
- package/dist/components/index.d.ts +3 -3
- package/dist/components/index.js +3 -3
- package/dist/components/properties.d.ts +18 -1
- package/dist/components/properties.d.ts.map +1 -1
- package/dist/components/properties.js +66 -3
- package/dist/components/properties.js.map +1 -1
- package/dist/components/variants.d.ts +16 -10
- package/dist/components/variants.d.ts.map +1 -1
- package/dist/components/variants.js +39 -13
- package/dist/components/variants.js.map +1 -1
- package/dist/connectors/hit.d.ts.map +1 -1
- package/dist/connectors/hit.js +1 -7
- package/dist/connectors/hit.js.map +1 -1
- package/dist/connectors/pieces.d.ts.map +1 -1
- package/dist/connectors/pieces.js +2 -5
- package/dist/connectors/pieces.js.map +1 -1
- package/dist/constants.d.ts +6 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +17 -1
- package/dist/constants.js.map +1 -1
- package/dist/constraints.d.ts +25 -0
- package/dist/constraints.d.ts.map +1 -0
- package/dist/constraints.js +51 -0
- package/dist/constraints.js.map +1 -0
- package/dist/coordinate.d.ts +64 -1
- package/dist/coordinate.d.ts.map +1 -1
- package/dist/coordinate.js +217 -1
- package/dist/coordinate.js.map +1 -1
- package/dist/copy.d.ts.map +1 -1
- package/dist/copy.js +17 -16
- package/dist/copy.js.map +1 -1
- package/dist/css/blend.d.ts +11 -0
- package/dist/css/blend.d.ts.map +1 -0
- package/dist/css/blend.js +30 -0
- package/dist/css/blend.js.map +1 -0
- package/dist/css/index.d.ts +4 -2
- package/dist/css/index.js +4 -2
- package/dist/css/text.d.ts +28 -1
- package/dist/css/text.d.ts.map +1 -1
- package/dist/css/text.js +84 -17
- package/dist/css/text.js.map +1 -1
- package/dist/css/transform.d.ts +34 -0
- package/dist/css/transform.d.ts.map +1 -0
- package/dist/css/transform.js +320 -0
- package/dist/css/transform.js.map +1 -0
- package/dist/css/values.d.ts.map +1 -1
- package/dist/css/values.js +11 -1
- package/dist/css/values.js.map +1 -1
- package/dist/cubic.d.ts +7 -0
- package/dist/cubic.d.ts.map +1 -0
- package/dist/cubic.js +17 -0
- package/dist/cubic.js.map +1 -0
- package/dist/export-format.d.ts +14 -1
- package/dist/export-format.d.ts.map +1 -1
- package/dist/export-format.js +26 -1
- package/dist/export-format.js.map +1 -1
- package/dist/fields/text.d.ts +2 -2
- package/dist/fields/text.d.ts.map +1 -1
- package/dist/fields/text.js +2 -1
- package/dist/fields/text.js.map +1 -1
- package/dist/figjam/index.d.ts +2 -2
- package/dist/figjam/index.js +2 -2
- package/dist/figjam/palette.d.ts +13 -2
- package/dist/figjam/palette.d.ts.map +1 -1
- package/dist/figjam/palette.js +30 -2
- package/dist/figjam/palette.js.map +1 -1
- package/dist/generated/index.d.ts +2 -2
- package/dist/generated/index.js +2 -2
- package/dist/generated/shape-with-text.d.ts +7 -2
- package/dist/generated/shape-with-text.d.ts.map +1 -1
- package/dist/generated/shape-with-text.js +20 -3
- package/dist/generated/shape-with-text.js.map +1 -1
- package/dist/geometry.d.ts +37 -46
- package/dist/geometry.d.ts.map +1 -1
- package/dist/geometry.js +80 -137
- package/dist/geometry.js.map +1 -1
- package/dist/graph.d.ts +49 -12
- package/dist/graph.d.ts.map +1 -1
- package/dist/graph.js +125 -27
- package/dist/graph.js.map +1 -1
- package/dist/group-bounds.d.ts +14 -4
- package/dist/group-bounds.d.ts.map +1 -1
- package/dist/group-bounds.js +76 -11
- package/dist/group-bounds.js.map +1 -1
- package/dist/guides.d.ts +3 -1
- package/dist/guides.d.ts.map +1 -1
- package/dist/guides.js +5 -1
- package/dist/guides.js.map +1 -1
- package/dist/hit-test.d.ts +5 -0
- package/dist/hit-test.d.ts.map +1 -1
- package/dist/hit-test.js +57 -38
- package/dist/hit-test.js.map +1 -1
- package/dist/images.d.ts +27 -3
- package/dist/images.d.ts.map +1 -1
- package/dist/images.js +57 -3
- package/dist/images.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/instances/fields.d.ts +2 -2
- package/dist/instances/fields.d.ts.map +1 -1
- package/dist/instances/fields.js +8 -0
- package/dist/instances/fields.js.map +1 -1
- package/dist/instances/index.d.ts +1 -3
- package/dist/instances/index.d.ts.map +1 -1
- package/dist/instances/index.js +39 -30
- package/dist/instances/index.js.map +1 -1
- package/dist/instances/kept-overrides.js +204 -0
- package/dist/instances/kept-overrides.js.map +1 -0
- package/dist/instances/main-component.d.ts +3 -1
- package/dist/instances/main-component.d.ts.map +1 -1
- package/dist/instances/main-component.js +10 -2
- package/dist/instances/main-component.js.map +1 -1
- package/dist/instances/overrides.d.ts +4 -1
- package/dist/instances/overrides.d.ts.map +1 -1
- package/dist/instances/overrides.js +18 -2
- package/dist/instances/overrides.js.map +1 -1
- package/dist/instances/placement.js +55 -12
- package/dist/instances/placement.js.map +1 -1
- package/dist/instances/swap.js +291 -0
- package/dist/instances/swap.js.map +1 -0
- package/dist/instances/sync.js +112 -39
- package/dist/instances/sync.js.map +1 -1
- package/dist/node-defaults.d.ts.map +1 -1
- package/dist/node-defaults.js +2 -1
- package/dist/node-defaults.js.map +1 -1
- package/dist/order-keys.d.ts +3 -1
- package/dist/order-keys.d.ts.map +1 -1
- package/dist/order-keys.js +6 -1
- package/dist/order-keys.js.map +1 -1
- package/dist/outline/flatten.d.ts +15 -0
- package/dist/outline/flatten.d.ts.map +1 -0
- package/dist/outline/flatten.js +189 -0
- package/dist/outline/flatten.js.map +1 -0
- package/dist/outline/heads.js +34 -0
- package/dist/outline/heads.js.map +1 -0
- package/dist/outline/hit.d.ts +21 -0
- package/dist/outline/hit.d.ts.map +1 -0
- package/dist/outline/hit.js +276 -0
- package/dist/outline/hit.js.map +1 -0
- package/dist/outline/index.d.ts +5 -0
- package/dist/outline/index.js +5 -0
- package/dist/outline/point.d.ts +16 -0
- package/dist/outline/point.d.ts.map +1 -0
- package/dist/outline/point.js +42 -0
- package/dist/outline/point.js.map +1 -0
- package/dist/outline/shapes.d.ts +35 -0
- package/dist/outline/shapes.d.ts.map +1 -0
- package/dist/outline/shapes.js +181 -0
- package/dist/outline/shapes.js.map +1 -0
- package/dist/plugin-data/fields.d.ts +4 -1
- package/dist/plugin-data/fields.d.ts.map +1 -1
- package/dist/plugin-data/fields.js +21 -4
- package/dist/plugin-data/fields.js.map +1 -1
- package/dist/resize.d.ts +22 -11
- package/dist/resize.d.ts.map +1 -1
- package/dist/resize.js +227 -93
- package/dist/resize.js.map +1 -1
- package/dist/scaling/index.d.ts +3 -2
- package/dist/scaling/index.js +3 -2
- 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/scaling/snapshot.d.ts +25 -0
- package/dist/scaling/snapshot.d.ts.map +1 -0
- package/dist/scaling/snapshot.js +39 -0
- package/dist/scaling/snapshot.js.map +1 -0
- package/dist/scaling/tree.d.ts +24 -2
- package/dist/scaling/tree.d.ts.map +1 -1
- package/dist/scaling/tree.js +38 -15
- package/dist/scaling/tree.js.map +1 -1
- package/dist/shaders/model.d.ts.map +1 -1
- package/dist/shaders/model.js +2 -1
- package/dist/shaders/model.js.map +1 -1
- package/dist/shared-styles.d.ts +16 -1
- package/dist/shared-styles.d.ts.map +1 -1
- package/dist/shared-styles.js +69 -2
- package/dist/shared-styles.js.map +1 -1
- package/dist/slots/authoring.d.ts +3 -2
- package/dist/slots/authoring.d.ts.map +1 -1
- package/dist/slots/authoring.js +5 -3
- package/dist/slots/authoring.js.map +1 -1
- package/dist/slots/content.d.ts.map +1 -1
- package/dist/slots/content.js +6 -1
- package/dist/slots/content.js.map +1 -1
- package/dist/slots/frames.d.ts +2 -0
- package/dist/slots/frames.d.ts.map +1 -1
- package/dist/slots/frames.js +7 -2
- package/dist/slots/frames.js.map +1 -1
- package/dist/text/direction.d.ts +3 -1
- package/dist/text/direction.d.ts.map +1 -1
- package/dist/text/direction.js +5 -1
- package/dist/text/direction.js.map +1 -1
- package/dist/text/index.d.ts +2 -2
- package/dist/text/index.js +3 -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 +2 -2
- package/dist/text/overflow.js.map +1 -1
- package/dist/text/picture.d.ts +1 -2
- package/dist/text/picture.d.ts.map +1 -1
- package/dist/text/picture.js +1 -4
- package/dist/text/picture.js.map +1 -1
- package/dist/transfer/apply.d.ts.map +1 -1
- package/dist/transfer/apply.js +1 -6
- package/dist/transfer/apply.js.map +1 -1
- package/dist/transfer/copied.d.ts +35 -3
- package/dist/transfer/copied.d.ts.map +1 -1
- package/dist/transfer/copied.js +44 -13
- package/dist/transfer/copied.js.map +1 -1
- package/dist/transfer/dependencies.d.ts +38 -0
- package/dist/transfer/dependencies.d.ts.map +1 -0
- package/dist/transfer/dependencies.js +100 -0
- package/dist/transfer/dependencies.js.map +1 -0
- package/dist/transfer/history.js +0 -1
- package/dist/transfer/history.js.map +1 -1
- package/dist/transfer/index.d.ts +5 -3
- package/dist/transfer/index.js +5 -3
- package/dist/transfer/nodes.d.ts.map +1 -1
- package/dist/transfer/nodes.js +16 -19
- package/dist/transfer/nodes.js.map +1 -1
- package/dist/transfer/plan.d.ts +0 -1
- package/dist/transfer/plan.js +3 -5
- package/dist/transfer/plan.js.map +1 -1
- package/dist/transfer/remove.js +5 -2
- package/dist/transfer/remove.js.map +1 -1
- package/dist/transfer/resources.d.ts +21 -0
- package/dist/transfer/resources.d.ts.map +1 -0
- package/dist/transfer/resources.js +38 -0
- package/dist/transfer/resources.js.map +1 -0
- package/dist/transfer/variables.d.ts +8 -1
- package/dist/transfer/variables.d.ts.map +1 -1
- package/dist/transfer/variables.js +24 -1
- package/dist/transfer/variables.js.map +1 -1
- package/dist/types.d.ts +73 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/undo.d.ts +28 -3
- package/dist/undo.d.ts.map +1 -1
- package/dist/undo.js +24 -7
- package/dist/undo.js.map +1 -1
- package/dist/variables/bindings.d.ts +37 -11
- package/dist/variables/bindings.d.ts.map +1 -1
- package/dist/variables/bindings.js +122 -74
- package/dist/variables/bindings.js.map +1 -1
- package/dist/variables/fields.d.ts +19 -1
- package/dist/variables/fields.d.ts.map +1 -1
- package/dist/variables/fields.js +36 -1
- package/dist/variables/fields.js.map +1 -1
- package/dist/variables/formula/check.d.ts +1 -1
- package/dist/variables/formula/index.d.ts +2 -2
- package/dist/variables/formula/index.js +1 -1
- package/dist/variables/formula/index.js.map +1 -1
- package/dist/variables/formula/print.d.ts +1 -1
- package/dist/variables/formula/signatures.js +1 -1
- package/dist/variables/index.d.ts +7 -7
- package/dist/variables/index.d.ts.map +1 -1
- package/dist/variables/index.js +57 -26
- package/dist/variables/index.js.map +1 -1
- package/dist/variables/paints.d.ts +57 -0
- package/dist/variables/paints.d.ts.map +1 -0
- package/dist/variables/paints.js +231 -0
- package/dist/variables/paints.js.map +1 -0
- package/dist/variables/resolution.d.ts +14 -11
- package/dist/variables/resolution.d.ts.map +1 -1
- package/dist/variables/resolution.js +36 -17
- package/dist/variables/resolution.js.map +1 -1
- package/dist/variables/subtree.js +17 -0
- package/dist/variables/subtree.js.map +1 -0
- package/dist/vector-network.d.ts.map +1 -1
- package/dist/vector-network.js +2 -8
- package/dist/vector-network.js.map +1 -1
- package/package.json +14 -1
- package/src/arrow-caps.ts +2 -5
- package/src/asset-keys.ts +20 -0
- package/src/behaviours/kinds.ts +51 -34
- package/src/behaviours/layers.ts +4 -2
- package/src/behaviours/model.ts +22 -11
- package/src/behaviours/schema.ts +20 -4
- package/src/behaviours/spec.ts +8 -2
- package/src/bindings.ts +11 -2
- package/src/checkpoint.ts +319 -17
- package/src/components/properties.ts +101 -2
- package/src/components/variants.ts +51 -30
- package/src/connectors/hit.ts +1 -12
- package/src/connectors/pieces.ts +2 -5
- package/src/constants.ts +17 -0
- package/src/constraints.ts +60 -0
- package/src/coordinate.ts +220 -0
- package/src/copy.ts +18 -19
- package/src/css/blend.ts +27 -0
- package/src/css/index.ts +18 -1
- package/src/css/text.ts +85 -17
- package/src/css/transform.ts +266 -0
- package/src/css/values.ts +8 -0
- package/src/cubic.ts +14 -0
- package/src/export-format.ts +29 -0
- package/src/fields/text.ts +3 -1
- package/src/figjam/palette.ts +29 -1
- package/src/generated/shape-with-text.ts +28 -2
- package/src/geometry.ts +97 -206
- package/src/graph.ts +155 -45
- package/src/group-bounds.ts +84 -17
- package/src/guides.ts +5 -0
- package/src/hit-test.ts +93 -64
- package/src/images.ts +71 -3
- package/src/instances/fields.ts +8 -0
- package/src/instances/index.ts +62 -31
- package/src/instances/kept-overrides.ts +280 -0
- package/src/instances/main-component.ts +12 -0
- package/src/instances/overrides.ts +27 -1
- package/src/instances/placement.ts +63 -10
- package/src/instances/swap.ts +456 -0
- package/src/instances/sync.ts +176 -50
- package/src/node-defaults.ts +3 -1
- package/src/order-keys.ts +6 -0
- package/src/outline/flatten.ts +190 -0
- package/src/outline/heads.ts +52 -0
- package/src/outline/hit.ts +369 -0
- package/src/outline/index.ts +4 -0
- package/src/outline/point.ts +59 -0
- package/src/outline/shapes.ts +207 -0
- package/src/plugin-data/fields.ts +21 -2
- package/src/resize.ts +267 -119
- package/src/scaling/index.ts +9 -1
- package/src/scaling/node.ts +9 -1
- package/src/scaling/snapshot.ts +51 -0
- package/src/scaling/tree.ts +63 -19
- package/src/shaders/model.ts +2 -3
- package/src/shared-styles.ts +90 -1
- package/src/slots/authoring.ts +5 -3
- package/src/slots/content.ts +6 -1
- package/src/slots/frames.ts +9 -7
- package/src/text/direction.ts +5 -0
- package/src/text/lengths.ts +10 -0
- package/src/text/overflow.ts +2 -2
- package/src/text/picture.ts +0 -4
- package/src/transfer/apply.ts +1 -13
- package/src/transfer/copied.ts +83 -15
- package/src/transfer/dependencies.ts +126 -0
- package/src/transfer/history.ts +0 -6
- package/src/transfer/index.ts +20 -2
- package/src/transfer/nodes.ts +17 -31
- package/src/transfer/plan.ts +3 -11
- package/src/transfer/remove.ts +5 -2
- package/src/transfer/resources.ts +54 -0
- package/src/transfer/variables.ts +34 -0
- package/src/types.ts +83 -1
- package/src/undo.ts +48 -10
- package/src/variables/bindings.ts +152 -88
- package/src/variables/fields.ts +46 -1
- package/src/variables/formula/index.ts +3 -1
- package/src/variables/index.ts +90 -39
- package/src/variables/paints.ts +296 -0
- package/src/variables/resolution.ts +39 -28
- package/src/variables/subtree.ts +15 -0
- package/src/vector-network.ts +4 -2
package/src/shaders/model.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { sha1 } from '@noble/hashes/legacy.js'
|
|
|
2
2
|
import { bytesToHex, utf8ToBytes } from '@noble/hashes/utils.js'
|
|
3
3
|
|
|
4
4
|
import { TRANSPARENT } from '../constants'
|
|
5
|
+
import { imagePaintHashes } from '../images'
|
|
5
6
|
import { readAllPluginData, withAllPluginData } from '../plugin-data/field'
|
|
6
7
|
import { OPEN_PENCIL_PLUGIN_DATA } from '../plugin-data/fields'
|
|
7
8
|
import { randomHex } from '../random'
|
|
@@ -43,9 +44,7 @@ export function withShaderPaints(
|
|
|
43
44
|
paints: readonly Fill[],
|
|
44
45
|
shaders: readonly ShaderPaint[] = []
|
|
45
46
|
): SceneNode['pluginData'] {
|
|
46
|
-
const shown = new Set(
|
|
47
|
-
paints.flatMap((paint) => (paint.type === 'IMAGE' && paint.imageHash ? [paint.imageHash] : []))
|
|
48
|
-
)
|
|
47
|
+
const shown = new Set(imagePaintHashes(paints))
|
|
49
48
|
const byImage = new Map(readShaderPaints(node).map((shader) => [shader.image, shader]))
|
|
50
49
|
for (const shader of shaders) byImage.set(shader.image, shader)
|
|
51
50
|
return withAllPluginData(
|
package/src/shared-styles.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import { compact, isEqual, omit } from 'es-toolkit'
|
|
1
|
+
import { compact, isEqual, omit, pick } from 'es-toolkit'
|
|
2
2
|
|
|
3
|
+
import { BLACK } from './constants'
|
|
4
|
+
import { copyEffects, copyFills, copyLayoutGrids } from './copy'
|
|
3
5
|
import type { SceneGraph } from './graph'
|
|
6
|
+
import { newStrokeGeometry } from './node-defaults'
|
|
7
|
+
import { randomHex } from './random'
|
|
4
8
|
import { styleRunReferences } from './text/references'
|
|
5
9
|
import type {
|
|
6
10
|
CharacterStyleOverride,
|
|
@@ -99,6 +103,14 @@ export function sharedStyleTypeForKind(kind: SharedStyleKind): SharedStyleType {
|
|
|
99
103
|
return STYLE_TYPES[kind]
|
|
100
104
|
}
|
|
101
105
|
|
|
106
|
+
/** The document's shared style layers, by the source ID layers link them by. */
|
|
107
|
+
export function sharedStyleLayers(graph: SceneGraph): Map<string, SceneNode> {
|
|
108
|
+
const styles = new Map<string, SceneNode>()
|
|
109
|
+
for (const node of graph.getAllNodes())
|
|
110
|
+
if (node.sharedStyleType !== null && node.source.id) styles.set(node.source.id, node)
|
|
111
|
+
return styles
|
|
112
|
+
}
|
|
113
|
+
|
|
102
114
|
export function getSharedStyles(graph: SceneGraph, kind: SharedStyleKind): SharedStyle[] {
|
|
103
115
|
const type = sharedStyleTypeForKind(kind)
|
|
104
116
|
const styles: SharedStyle[] = []
|
|
@@ -145,3 +157,80 @@ export function styleDetachmentChanges(
|
|
|
145
157
|
}
|
|
146
158
|
return next
|
|
147
159
|
}
|
|
160
|
+
|
|
161
|
+
/** The node of the shared style with `id`, when the document holds one of `type`. */
|
|
162
|
+
export function findSharedStyle(
|
|
163
|
+
graph: SceneGraph,
|
|
164
|
+
id: string,
|
|
165
|
+
type: SharedStyleType
|
|
166
|
+
): SceneNode | undefined {
|
|
167
|
+
if (!id) return undefined
|
|
168
|
+
for (const node of graph.getAllNodes()) {
|
|
169
|
+
if (node.sharedStyleType === type && node.source.id === id) return node
|
|
170
|
+
}
|
|
171
|
+
return undefined
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** A new local style's ID, in the shape Figma gives one: `S:` and a 40-digit hex key. */
|
|
175
|
+
export function newSharedStyleId(): string {
|
|
176
|
+
return `S:${randomHex(20)},`
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const INTERNAL_CANVAS_NAME = 'Internal Only Canvas'
|
|
180
|
+
|
|
181
|
+
/** The page that holds the document's styles out of view, as a `.fig` file keeps them; made once. */
|
|
182
|
+
export function internalCanvas(graph: SceneGraph): SceneNode {
|
|
183
|
+
const existing = graph.getPages(true).find((page) => page.internalOnly)
|
|
184
|
+
if (existing) return existing
|
|
185
|
+
return graph.createNode('CANVAS', graph.rootId, {
|
|
186
|
+
name: INTERNAL_CANVAS_NAME,
|
|
187
|
+
width: 0,
|
|
188
|
+
height: 0,
|
|
189
|
+
internalOnly: true
|
|
190
|
+
})
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* A paint style's paints as a layer's strokes: every paint, each keeping the weight, alignment,
|
|
195
|
+
* and line style of the stroke it replaces, or of the layer's first; no paints clear the strokes
|
|
196
|
+
* (Figma desktop 126).
|
|
197
|
+
*/
|
|
198
|
+
function strokesFromStyle(target: SceneNode, style: SceneNode): SceneNode['strokes'] {
|
|
199
|
+
// Without strokes, the layer keeps the weight and alignment a new stroke takes.
|
|
200
|
+
const fallback: Stroke = target.strokes[0] ?? {
|
|
201
|
+
type: 'SOLID',
|
|
202
|
+
color: BLACK,
|
|
203
|
+
opacity: 1,
|
|
204
|
+
visible: true,
|
|
205
|
+
...newStrokeGeometry(target)
|
|
206
|
+
}
|
|
207
|
+
return copyFills(style.fills).map((paint, index) => ({
|
|
208
|
+
...paint,
|
|
209
|
+
...pick(target.strokes[index] ?? fallback, STROKE_LINE_KEYS)
|
|
210
|
+
}))
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* What a layer takes from a shared style it starts using: the style's fields and the reference
|
|
215
|
+
* that keeps it attached. Without the style's node, the reference alone.
|
|
216
|
+
*/
|
|
217
|
+
export function sharedStylePatch(
|
|
218
|
+
kind: SharedStyleKind,
|
|
219
|
+
target: SceneNode,
|
|
220
|
+
styleId: string,
|
|
221
|
+
style: SceneNode | null
|
|
222
|
+
): Partial<SceneNode> {
|
|
223
|
+
const patch: Partial<SceneNode> = { [STYLE_REF_KEYS[kind]]: styleId }
|
|
224
|
+
if (!style) return patch
|
|
225
|
+
if (kind === 'fill') patch.fills = copyFills(style.fills)
|
|
226
|
+
else if (kind === 'stroke') patch.strokes = strokesFromStyle(target, style)
|
|
227
|
+
else if (kind === 'effect') patch.effects = copyEffects(style.effects)
|
|
228
|
+
else if (kind === 'grid') patch.layoutGrids = copyLayoutGrids(style.layoutGrids)
|
|
229
|
+
else Object.assign(patch, structuredClone(pick(style, SHARED_STYLE_FIELDS.text)))
|
|
230
|
+
return patch
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/** A layer leaving a shared style: it keeps the style's values, without the reference. */
|
|
234
|
+
export function sharedStyleDetachPatch(kind: SharedStyleKind): Partial<SceneNode> {
|
|
235
|
+
return { [STYLE_REF_KEYS[kind]]: null }
|
|
236
|
+
}
|
package/src/slots/authoring.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { propertyOwner } from '../components/properties'
|
|
1
2
|
import type { SceneGraph } from '../graph'
|
|
2
3
|
import type { ComponentPropertyDefinition, SceneNode, SlotSettings } from '../types'
|
|
3
4
|
import { slotPropertyId } from './frames'
|
|
@@ -10,13 +11,14 @@ export const DEFAULT_SLOT_SETTINGS: SlotSettings = {
|
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
|
-
* The main component
|
|
14
|
-
* instance are not authored there, so a
|
|
14
|
+
* The main component or set that defines the slots inside a layer: the component the layer
|
|
15
|
+
* belongs to, or that component's set. Layers of an instance are not authored there, so a
|
|
16
|
+
* layer under an instance has none.
|
|
15
17
|
*/
|
|
16
18
|
export function slotOwner(graph: SceneGraph, node: SceneNode): SceneNode | undefined {
|
|
17
19
|
let current = node.parentId ? graph.getNode(node.parentId) : undefined
|
|
18
20
|
while (current && current.type !== 'CANVAS') {
|
|
19
|
-
if (current.type === 'COMPONENT') return current
|
|
21
|
+
if (current.type === 'COMPONENT') return propertyOwner(graph, current)
|
|
20
22
|
if (current.type === 'INSTANCE') return undefined
|
|
21
23
|
current = current.parentId ? graph.getNode(current.parentId) : undefined
|
|
22
24
|
}
|
package/src/slots/content.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { SceneGraph } from '../graph'
|
|
|
3
3
|
import { getInstanceOverride, setInstanceOverride } from '../instances/overrides'
|
|
4
4
|
import { cloneChildrenWithMapping } from '../instances/sync'
|
|
5
5
|
import type { SceneNode } from '../types'
|
|
6
|
+
import { applyBoundPaintColorsIn } from '../variables/paints'
|
|
6
7
|
import { ownsSlotContent, slotPropertyId } from './frames'
|
|
7
8
|
|
|
8
9
|
/**
|
|
@@ -68,6 +69,7 @@ export function claimSlotContent(
|
|
|
68
69
|
): void {
|
|
69
70
|
const { frame, instance, propertyId } = scope
|
|
70
71
|
if (ownsSlotContent(graph, frame, propertyId)) return
|
|
72
|
+
graph.willChangeNode(instance)
|
|
71
73
|
const overrides = instance.instanceOverrides
|
|
72
74
|
for (const node of descendants(graph, frame, false)) {
|
|
73
75
|
overrides.descendants.delete(node.id)
|
|
@@ -76,6 +78,7 @@ export function claimSlotContent(
|
|
|
76
78
|
continue
|
|
77
79
|
}
|
|
78
80
|
// A nested instance keeps the overrides its former owner applied inside it.
|
|
81
|
+
graph.willChangeNode(node)
|
|
79
82
|
for (const inner of descendants(graph, node, true)) {
|
|
80
83
|
const fields = overrides.descendants.get(inner.id)
|
|
81
84
|
if (!fields) continue
|
|
@@ -114,7 +117,9 @@ export function resetSlotContent(
|
|
|
114
117
|
Reflect.deleteProperty(assignments, propertyId)
|
|
115
118
|
graph.updateNode(instance.id, { componentPropertyAssignments: assignments })
|
|
116
119
|
const source = componentSource(instance, frame)
|
|
117
|
-
if (source
|
|
120
|
+
if (!source || !graph.nodes.has(source)) return
|
|
121
|
+
cloneChildrenWithMapping(graph, source, frame.id)
|
|
122
|
+
for (const childId of frame.childIds) applyBoundPaintColorsIn(graph, childId)
|
|
118
123
|
}
|
|
119
124
|
|
|
120
125
|
/** Remove everything from the slot; the instance keeps owning it, now empty. */
|
package/src/slots/frames.ts
CHANGED
|
@@ -56,6 +56,8 @@ interface ParkedSlot {
|
|
|
56
56
|
name: string
|
|
57
57
|
/** Content layer ids, in layer order. */
|
|
58
58
|
content: string[]
|
|
59
|
+
ownerId: string
|
|
60
|
+
propertyId: string
|
|
59
61
|
}
|
|
60
62
|
|
|
61
63
|
/** Owned slot content parked under an instance while its component changes. */
|
|
@@ -112,13 +114,18 @@ export function detachOwnedSlotContent(graph: SceneGraph, instance: SceneNode):
|
|
|
112
114
|
continue
|
|
113
115
|
const content = [...frame.childIds]
|
|
114
116
|
for (const id of content) graph.insertChildAt(id, instance.id, instance.childIds.length)
|
|
115
|
-
parked.slots.push({ path, name, content })
|
|
117
|
+
parked.slots.push({ path, name, content, ownerId: owner.id, propertyId })
|
|
116
118
|
}
|
|
117
119
|
}
|
|
118
120
|
visit(instance, [])
|
|
119
121
|
return parked
|
|
120
122
|
}
|
|
121
123
|
|
|
124
|
+
function assignsOtherContent(owner: SceneNode, propertyId: string, slot: ParkedSlot): boolean {
|
|
125
|
+
const parkedFromHere = owner.id === slot.ownerId && propertyId === slot.propertyId
|
|
126
|
+
return !parkedFromHere && Object.hasOwn(owner.componentPropertyAssignments, propertyId)
|
|
127
|
+
}
|
|
128
|
+
|
|
122
129
|
/** Move parked content into the slots of the same names and paths, and reassign them. */
|
|
123
130
|
export function restoreOwnedSlotContent(
|
|
124
131
|
graph: SceneGraph,
|
|
@@ -142,12 +149,7 @@ export function restoreOwnedSlotContent(
|
|
|
142
149
|
return !!propertyId && slotName(graph, owner, propertyId) === slot.name
|
|
143
150
|
})
|
|
144
151
|
const propertyId = frame && slotPropertyId(frame)
|
|
145
|
-
if (
|
|
146
|
-
!owner ||
|
|
147
|
-
!frame ||
|
|
148
|
-
!propertyId ||
|
|
149
|
-
Object.hasOwn(owner.componentPropertyAssignments, propertyId)
|
|
150
|
-
) {
|
|
152
|
+
if (!owner || !frame || !propertyId || assignsOtherContent(owner, propertyId, slot)) {
|
|
151
153
|
for (const id of slot.content) graph.deleteNode(id)
|
|
152
154
|
continue
|
|
153
155
|
}
|
package/src/text/direction.ts
CHANGED
|
@@ -4,6 +4,11 @@ const RTL_CHAR_RE =
|
|
|
4
4
|
/\p{Script=Arabic}|\p{Script=Hebrew}|\p{Script=Syriac}|\p{Script=Thaana}|\p{Script=Nko}|\p{Script=Adlam}/u
|
|
5
5
|
const LTR_CHAR_RE = /\p{Script=Latin}|\p{Script=Cyrillic}|\p{Script=Greek}/u
|
|
6
6
|
|
|
7
|
+
/** Whether the text has a letter of a right-to-left script, such as Arabic or Hebrew. */
|
|
8
|
+
export function containsRTLText(text: string): boolean {
|
|
9
|
+
return RTL_CHAR_RE.test(text)
|
|
10
|
+
}
|
|
11
|
+
|
|
7
12
|
export function detectTextDirection(text: string): Exclude<TextDirection, 'AUTO'> {
|
|
8
13
|
for (const char of text) {
|
|
9
14
|
if (RTL_CHAR_RE.test(char)) return 'RTL'
|
package/src/text/lengths.ts
CHANGED
|
@@ -13,6 +13,16 @@ export function lineHeightPixels(lineHeight: TextLength | null, fontSize: number
|
|
|
13
13
|
return lineHeight ? textLengthPixels(lineHeight, fontSize) : null
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* How far apart a line height sets lines at `fontSize`, as Figma steps them: a height in pixels
|
|
18
|
+
* as it is, a percent one to whole pixels (Figma desktop 126); null when it is automatic.
|
|
19
|
+
*/
|
|
20
|
+
export function lineStepPixels(lineHeight: TextLength | null, fontSize: number): number | null {
|
|
21
|
+
if (!lineHeight) return null
|
|
22
|
+
const pixels = textLengthPixels(lineHeight, fontSize)
|
|
23
|
+
return lineHeight.unit === 'PIXELS' ? pixels : Math.round(pixels)
|
|
24
|
+
}
|
|
25
|
+
|
|
16
26
|
/** A length in pixels, as a bound number variable and most authored formats give one. */
|
|
17
27
|
export function pixelLength(value: number): TextLength {
|
|
18
28
|
return { value, unit: 'PIXELS' }
|
package/src/text/overflow.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SceneNode } from '../types'
|
|
2
2
|
|
|
3
|
-
type TextBoundsNode = Pick<
|
|
3
|
+
type TextBoundsNode = Pick<SceneNode, 'type' | 'height' | 'derivedTextHeight'>
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* How far a text's lines reach below its box: a fixed-size box does not clip them, as in Figma,
|
package/src/text/picture.ts
CHANGED
package/src/transfer/apply.ts
CHANGED
|
@@ -24,14 +24,6 @@ function validate(target: SceneGraph, plan: GraphTransferPlan): void {
|
|
|
24
24
|
plan.collections,
|
|
25
25
|
variableIdentityReferences(plan.variables, plan.collections)
|
|
26
26
|
)
|
|
27
|
-
for (const [id, mode] of plan.activeModes) {
|
|
28
|
-
if (
|
|
29
|
-
!plan.collections
|
|
30
|
-
.find((collection) => collection.id === id)
|
|
31
|
-
?.modes.some((entry) => entry.modeId === mode)
|
|
32
|
-
)
|
|
33
|
-
throw new Error(`Invalid transferred active mode ${id}:${mode}`)
|
|
34
|
-
}
|
|
35
27
|
for (const collection of plan.collections) claim(collection.id)
|
|
36
28
|
for (const variable of plan.variables) claim(variable.id)
|
|
37
29
|
const parents = new Set(target.nodes.keys())
|
|
@@ -64,7 +56,6 @@ export function applyGraphTransfer(target: SceneGraph, input: GraphTransferPlan)
|
|
|
64
56
|
try {
|
|
65
57
|
for (const collection of plan.collections) target.addCollection(collection)
|
|
66
58
|
for (const variable of plan.variables) target.addVariable(variable)
|
|
67
|
-
for (const [id, mode] of plan.activeModes) target.activeMode.set(id, mode)
|
|
68
59
|
for (const [hash, bytes] of plan.images)
|
|
69
60
|
if (!target.images.has(hash)) target.images.set(hash, bytes)
|
|
70
61
|
for (const node of plan.nodes)
|
|
@@ -73,10 +64,7 @@ export function applyGraphTransfer(target: SceneGraph, input: GraphTransferPlan)
|
|
|
73
64
|
for (const node of plan.nodes.toReversed())
|
|
74
65
|
if (target.getNode(node.id)) target.deleteNode(node.id)
|
|
75
66
|
for (const variable of plan.variables) target.variables.delete(variable.id)
|
|
76
|
-
for (const collection of plan.collections)
|
|
77
|
-
target.variableCollections.delete(collection.id)
|
|
78
|
-
target.activeMode.delete(collection.id)
|
|
79
|
-
}
|
|
67
|
+
for (const collection of plan.collections) target.variableCollections.delete(collection.id)
|
|
80
68
|
for (const hash of imageIds) target.images.delete(hash)
|
|
81
69
|
throw error
|
|
82
70
|
}
|
package/src/transfer/copied.ts
CHANGED
|
@@ -3,44 +3,103 @@ import { isEqual, mapValues } from 'es-toolkit'
|
|
|
3
3
|
import { componentPropertyDefinitions } from '../components/properties'
|
|
4
4
|
import type { SceneGraph } from '../graph'
|
|
5
5
|
import { remapInstanceOverrideState } from '../instances/overrides'
|
|
6
|
+
import { remapStyleRunReferences } from '../text/references'
|
|
6
7
|
import type { ComponentPropertyDefinition, SceneNode } from '../types'
|
|
7
8
|
|
|
9
|
+
/** How a layer's references to other layers are resolved anew. */
|
|
10
|
+
export interface ReferenceResolvers {
|
|
11
|
+
/** The component a reference names now; `previous` is the one the layer named, if any. */
|
|
12
|
+
component: (id: string, previous: string | null) => string
|
|
13
|
+
/** The layer an override names now; `component` is the one its instance now draws. */
|
|
14
|
+
layer: (id: string, component: string | null) => string
|
|
15
|
+
/** The layer a connector's end follows now. */
|
|
16
|
+
endpoint: (id: string) => string
|
|
17
|
+
/**
|
|
18
|
+
* The layer a text link names now. Without it links keep naming their layers, as Figma's
|
|
19
|
+
* duplicate and paste do (desktop 126); copies into another document, which lacks those
|
|
20
|
+
* layers, pass it.
|
|
21
|
+
*/
|
|
22
|
+
link?: (id: string) => string
|
|
23
|
+
variable: (id: string) => string
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Copies placed in another document, whose text links must follow the copy. */
|
|
27
|
+
export interface CopiedReferenceOptions {
|
|
28
|
+
followTextLinks?: boolean
|
|
29
|
+
}
|
|
30
|
+
|
|
8
31
|
function swapPropertyIds(definitions: readonly ComponentPropertyDefinition[]): string[] {
|
|
9
32
|
return definitions
|
|
10
33
|
.filter((definition) => definition.type === 'INSTANCE_SWAP')
|
|
11
34
|
.map((definition) => definition.id)
|
|
12
35
|
}
|
|
13
36
|
|
|
14
|
-
|
|
37
|
+
/** The instance-swap properties `nodes` define, whose values name components. */
|
|
38
|
+
export function instanceSwapPropertyIds(nodes: Iterable<SceneNode>): Set<string> {
|
|
39
|
+
return new Set([...nodes].flatMap((node) => swapPropertyIds(node.componentPropertyDefinitions)))
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* `node`'s references to other layers, resolved anew: its main component, the layers its
|
|
44
|
+
* overrides change and the components they swap in, the components its instance-swap properties
|
|
45
|
+
* default to or are set to, and the layers its connector ends follow. `previous` is the layer
|
|
46
|
+
* whose references these replace, so a resolver can keep what it already pointed at. Only the
|
|
47
|
+
* fields whose references change are returned: every write is an update collaboration sends.
|
|
48
|
+
*/
|
|
49
|
+
export function resolvedReferences(
|
|
15
50
|
node: SceneNode,
|
|
16
|
-
|
|
51
|
+
previous: SceneNode,
|
|
52
|
+
resolve: ReferenceResolvers,
|
|
17
53
|
swapProperties: ReadonlySet<string>
|
|
18
54
|
): Partial<SceneNode> {
|
|
19
55
|
const changes: Partial<SceneNode> = {}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
56
|
+
const componentId = node.componentId
|
|
57
|
+
? resolve.component(node.componentId, previous.componentId)
|
|
58
|
+
: null
|
|
59
|
+
if (componentId !== node.componentId) changes.componentId = componentId
|
|
23
60
|
const overrides = remapInstanceOverrideState(node.instanceOverrides, {
|
|
24
|
-
node:
|
|
25
|
-
variable:
|
|
61
|
+
node: (id) => resolve.layer(id, componentId),
|
|
62
|
+
variable: resolve.variable
|
|
26
63
|
})
|
|
27
64
|
if (!isEqual(overrides, node.instanceOverrides)) changes.instanceOverrides = overrides
|
|
65
|
+
const previousDefaults = new Map(
|
|
66
|
+
previous.componentPropertyDefinitions.map((definition) => [
|
|
67
|
+
definition.id,
|
|
68
|
+
definition.defaultValue
|
|
69
|
+
])
|
|
70
|
+
)
|
|
28
71
|
const definitions = node.componentPropertyDefinitions.map((definition) =>
|
|
29
72
|
definition.type === 'INSTANCE_SWAP' && definition.defaultValue
|
|
30
|
-
? {
|
|
73
|
+
? {
|
|
74
|
+
...definition,
|
|
75
|
+
defaultValue: resolve.component(
|
|
76
|
+
definition.defaultValue,
|
|
77
|
+
previousDefaults.get(definition.id) ?? null
|
|
78
|
+
)
|
|
79
|
+
}
|
|
31
80
|
: definition
|
|
32
81
|
)
|
|
33
82
|
if (!isEqual(definitions, node.componentPropertyDefinitions))
|
|
34
83
|
changes.componentPropertyDefinitions = definitions
|
|
35
84
|
const assignments = mapValues(node.componentPropertyAssignments, (value, id) =>
|
|
36
|
-
swapProperties.has(id)
|
|
85
|
+
swapProperties.has(id)
|
|
86
|
+
? resolve.component(value, previous.componentPropertyAssignments[id] ?? null)
|
|
87
|
+
: value
|
|
37
88
|
)
|
|
38
89
|
if (!isEqual(assignments, node.componentPropertyAssignments))
|
|
39
90
|
changes.componentPropertyAssignments = assignments
|
|
40
91
|
for (const field of ['connectorStart', 'connectorEnd'] as const) {
|
|
41
92
|
const endpoint = node[field]
|
|
42
|
-
|
|
43
|
-
|
|
93
|
+
const nodeId = endpoint?.nodeId ? resolve.endpoint(endpoint.nodeId) : null
|
|
94
|
+
if (endpoint && nodeId && nodeId !== endpoint.nodeId) changes[field] = { ...endpoint, nodeId }
|
|
95
|
+
}
|
|
96
|
+
if (resolve.link) {
|
|
97
|
+
const styleRuns = remapStyleRunReferences(node.styleRuns, {
|
|
98
|
+
variable: (id) => id,
|
|
99
|
+
style: (id) => id,
|
|
100
|
+
node: resolve.link
|
|
101
|
+
})
|
|
102
|
+
if (!isEqual(styleRuns, node.styleRuns)) changes.styleRuns = styleRuns
|
|
44
103
|
}
|
|
45
104
|
return changes
|
|
46
105
|
}
|
|
@@ -51,22 +110,31 @@ function remappedReferences(
|
|
|
51
110
|
* components an instance-swap property defaults to or is set to, and the layers a connector's
|
|
52
111
|
* ends follow. `mappedIds` maps each copied layer to its copy, such as a library copy or a design
|
|
53
112
|
* JSX render folded into the layers it replaces; a reference outside the copy stays as it is, and
|
|
54
|
-
* so do variable IDs, since the copies keep their source's variables.
|
|
113
|
+
* so do variable IDs, since the copies keep their source's variables. Text links follow the copy
|
|
114
|
+
* only with `followTextLinks`.
|
|
55
115
|
*/
|
|
56
116
|
export function remapCopiedReferences(
|
|
57
117
|
graph: SceneGraph,
|
|
58
|
-
mappedIds: ReadonlyMap<string, string
|
|
118
|
+
mappedIds: ReadonlyMap<string, string>,
|
|
119
|
+
options: CopiedReferenceOptions = {}
|
|
59
120
|
): void {
|
|
60
121
|
const mapped = (id: string) => mappedIds.get(id) ?? id
|
|
122
|
+
const resolve: ReferenceResolvers = {
|
|
123
|
+
component: mapped,
|
|
124
|
+
layer: mapped,
|
|
125
|
+
endpoint: mapped,
|
|
126
|
+
link: options.followTextLinks ? mapped : undefined,
|
|
127
|
+
variable: (id) => id
|
|
128
|
+
}
|
|
61
129
|
const copies = [...mappedIds.values()].flatMap((id) => graph.getNode(id) ?? [])
|
|
62
|
-
const copiedSwaps = copies
|
|
130
|
+
const copiedSwaps = instanceSwapPropertyIds(copies)
|
|
63
131
|
for (const node of copies) {
|
|
64
132
|
// An instance's swap property may be defined on a component the copy leaves behind.
|
|
65
133
|
const swapProperties = new Set([
|
|
66
134
|
...copiedSwaps,
|
|
67
135
|
...swapPropertyIds(componentPropertyDefinitions(graph, node))
|
|
68
136
|
])
|
|
69
|
-
const changes =
|
|
137
|
+
const changes = resolvedReferences(node, node, resolve, swapProperties)
|
|
70
138
|
if (Object.keys(changes).length > 0) graph.updateNode(node.id, changes)
|
|
71
139
|
}
|
|
72
140
|
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import type { SceneGraph } from '../graph'
|
|
2
|
+
import { imagePaintHashes } from '../images'
|
|
3
|
+
import { overriddenBindingField } from '../instances/overrides'
|
|
4
|
+
import { referencedStyleIds, sharedStyleLayers } from '../shared-styles'
|
|
5
|
+
import { styleRunReferences } from '../text/references'
|
|
6
|
+
import type { SceneNode } from '../types'
|
|
7
|
+
import { isUnsupportedVariableValue, variableValueReferences } from '../variables/value'
|
|
8
|
+
import { regionFills } from '../vector-network'
|
|
9
|
+
|
|
10
|
+
/** What layers need from their document to draw the same in another one. */
|
|
11
|
+
export interface LayerDependencies {
|
|
12
|
+
/** The variables the layers and their styles bind, and every variable those alias. */
|
|
13
|
+
variables: Set<string>
|
|
14
|
+
/**
|
|
15
|
+
* The collections of those variables, those the layers set a mode of, and those a kept
|
|
16
|
+
* expression names a mode of.
|
|
17
|
+
*/
|
|
18
|
+
collections: Set<string>
|
|
19
|
+
/** The shared styles the layers use, as the style layers that define them. */
|
|
20
|
+
styles: SceneNode[]
|
|
21
|
+
/** The images the layers and their styles paint with. */
|
|
22
|
+
images: Set<string>
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** The variables a layer names: its own bindings, its characters', and its overrides'. */
|
|
26
|
+
export function layerVariableIds(node: SceneNode): string[] {
|
|
27
|
+
const { self, descendants } = node.instanceOverrides
|
|
28
|
+
const overridden = [...self, ...[...descendants.values()].flatMap((fields) => [...fields])]
|
|
29
|
+
return [
|
|
30
|
+
...Object.values(node.boundVariables),
|
|
31
|
+
...styleRunReferences(node.styleRuns).variables,
|
|
32
|
+
...overridden.flatMap(([field, value]) =>
|
|
33
|
+
typeof value === 'string' && overriddenBindingField(field) !== null ? [value] : []
|
|
34
|
+
)
|
|
35
|
+
]
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The images a layer paints with: its fills, strokes, vector regions, text decorations, and
|
|
40
|
+
* characters.
|
|
41
|
+
*/
|
|
42
|
+
export function layerImageHashes(node: SceneNode): string[] {
|
|
43
|
+
return imagePaintHashes([
|
|
44
|
+
...node.fills,
|
|
45
|
+
...node.strokes,
|
|
46
|
+
...regionFills(node.vectorNetwork),
|
|
47
|
+
...node.textDecorationFills,
|
|
48
|
+
...node.styleRuns.flatMap((run) => [
|
|
49
|
+
...(run.style.fills ?? []),
|
|
50
|
+
...(run.style.textDecorationFills ?? [])
|
|
51
|
+
])
|
|
52
|
+
])
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The variables, collections, styles, and images `layers` depend on, as a copy into another
|
|
57
|
+
* document must carry them: a style brings what it binds and paints with in turn, and a variable
|
|
58
|
+
* brings the variables it aliases.
|
|
59
|
+
*/
|
|
60
|
+
export function layerDependencies(
|
|
61
|
+
graph: SceneGraph,
|
|
62
|
+
layers: Iterable<SceneNode>
|
|
63
|
+
): LayerDependencies {
|
|
64
|
+
const collections = new Set<string>()
|
|
65
|
+
const images = new Set<string>()
|
|
66
|
+
const styles = new Map<string, SceneNode>()
|
|
67
|
+
const pending: string[] = []
|
|
68
|
+
let styleLayers: Map<string, SceneNode> | undefined
|
|
69
|
+
const styleLayer = (id: string): SceneNode | undefined =>
|
|
70
|
+
(styleLayers ??= sharedStyleLayers(graph)).get(id)
|
|
71
|
+
const visit = (node: SceneNode): void => {
|
|
72
|
+
for (const hash of layerImageHashes(node)) images.add(hash)
|
|
73
|
+
pending.push(...layerVariableIds(node))
|
|
74
|
+
for (const id of Object.keys(node.variableModes))
|
|
75
|
+
if (graph.variableCollections.has(id)) collections.add(id)
|
|
76
|
+
for (const id of referencedStyleIds(node)) {
|
|
77
|
+
const style = styles.has(id) ? undefined : styleLayer(id)
|
|
78
|
+
if (!style) continue
|
|
79
|
+
styles.set(id, style)
|
|
80
|
+
visit(style)
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
for (const node of layers) visit(node)
|
|
84
|
+
const resolved = variableDependencies(graph, pending)
|
|
85
|
+
for (const id of resolved.collections) collections.add(id)
|
|
86
|
+
return { variables: resolved.variables, collections, styles: [...styles.values()], images }
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* These variables and every variable they alias, at any depth, with their collections and the
|
|
91
|
+
* collections a kept expression names a mode of.
|
|
92
|
+
*/
|
|
93
|
+
export function variableDependencies(
|
|
94
|
+
graph: SceneGraph,
|
|
95
|
+
ids: Iterable<string>
|
|
96
|
+
): Pick<LayerDependencies, 'variables' | 'collections'> {
|
|
97
|
+
const pending = [...ids]
|
|
98
|
+
const variables = new Set<string>()
|
|
99
|
+
const collections = new Set<string>()
|
|
100
|
+
let modeCollections: Map<string, string> | undefined
|
|
101
|
+
const collectionOfMode = (modeId: string): string | undefined => {
|
|
102
|
+
modeCollections ??= new Map(
|
|
103
|
+
[...graph.variableCollections.values()].flatMap((collection) =>
|
|
104
|
+
collection.modes.map((mode) => [mode.modeId, collection.id] as const)
|
|
105
|
+
)
|
|
106
|
+
)
|
|
107
|
+
return modeCollections.get(modeId)
|
|
108
|
+
}
|
|
109
|
+
for (let id = pending.pop(); id !== undefined; id = pending.pop()) {
|
|
110
|
+
if (variables.has(id)) continue
|
|
111
|
+
const variable = graph.variables.get(id)
|
|
112
|
+
if (!variable) continue
|
|
113
|
+
variables.add(id)
|
|
114
|
+
collections.add(variable.collectionId)
|
|
115
|
+
for (const value of Object.values(variable.valuesByMode)) {
|
|
116
|
+
pending.push(...variableValueReferences(value))
|
|
117
|
+
// A kept expression can name a mode of a collection none of its aliases reach.
|
|
118
|
+
if (!isUnsupportedVariableValue(value)) continue
|
|
119
|
+
for (const modeId of value.modes) {
|
|
120
|
+
const collection = collectionOfMode(modeId)
|
|
121
|
+
if (collection) collections.add(collection)
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return { variables, collections }
|
|
126
|
+
}
|
package/src/transfer/history.ts
CHANGED
|
@@ -33,12 +33,6 @@ export function captureTransferredState(
|
|
|
33
33
|
requireValue(graph.variableCollections.get(collection.id), 'collection', collection.id)
|
|
34
34
|
)
|
|
35
35
|
),
|
|
36
|
-
activeModes: new Map(
|
|
37
|
-
original.collections.map((collection) => [
|
|
38
|
-
collection.id,
|
|
39
|
-
requireValue(graph.activeMode.get(collection.id), 'active mode', collection.id)
|
|
40
|
-
])
|
|
41
|
-
),
|
|
42
36
|
images: new Map(
|
|
43
37
|
[...original.images.keys()].map((hash) => [
|
|
44
38
|
hash,
|
package/src/transfer/index.ts
CHANGED
|
@@ -3,5 +3,23 @@ export { captureTransferredState } from './history'
|
|
|
3
3
|
export { applyGraphTransfer, type GraphTransferPlan } from './apply'
|
|
4
4
|
export { prepareGraphTransfer, type GraphTransferInput } from './plan'
|
|
5
5
|
export { prepareNodeTransfer, type NodeTransferReferences } from './nodes'
|
|
6
|
-
export {
|
|
7
|
-
|
|
6
|
+
export {
|
|
7
|
+
copyVariableTables,
|
|
8
|
+
prepareVariableTransfer,
|
|
9
|
+
type VariableTransferReferences
|
|
10
|
+
} from './variables'
|
|
11
|
+
export {
|
|
12
|
+
instanceSwapPropertyIds,
|
|
13
|
+
remapCopiedReferences,
|
|
14
|
+
resolvedReferences,
|
|
15
|
+
type CopiedReferenceOptions,
|
|
16
|
+
type ReferenceResolvers
|
|
17
|
+
} from './copied'
|
|
18
|
+
export {
|
|
19
|
+
layerDependencies,
|
|
20
|
+
layerImageHashes,
|
|
21
|
+
layerVariableIds,
|
|
22
|
+
variableDependencies,
|
|
23
|
+
type LayerDependencies
|
|
24
|
+
} from './dependencies'
|
|
25
|
+
export { remappedResourceReferences, type ResourceReferences } from './resources'
|