@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/transfer/nodes.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { cloneNodeProps } from '../copy'
|
|
2
2
|
import { overriddenBindingField, remapInstanceOverrideState } from '../instances/overrides'
|
|
3
3
|
import { referencedStyleIds } from '../shared-styles'
|
|
4
|
-
import {
|
|
4
|
+
import { styleRunReferences } from '../text/references'
|
|
5
5
|
import type { ComponentPropertyType, SceneNode } from '../types'
|
|
6
6
|
import { requireTransferReference as required } from './references'
|
|
7
|
+
import { remappedResourceReferences } from './resources'
|
|
7
8
|
import type { VariableTransferReferences } from './variables'
|
|
8
9
|
|
|
9
10
|
export function semanticTransferReferences(node: SceneNode): string[] {
|
|
@@ -65,51 +66,36 @@ export function prepareNodeTransfer(
|
|
|
65
66
|
result.componentId = source.componentId ? node(source.componentId) : null
|
|
66
67
|
result.instanceOverrides = remapInstanceOverrideState(source.instanceOverrides, {
|
|
67
68
|
node,
|
|
68
|
-
variable
|
|
69
|
+
variable,
|
|
70
|
+
collection: (id) => refs.collections.get(id)
|
|
69
71
|
})
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
result.variableModes = Object.fromEntries(
|
|
74
|
-
Object.entries(source.variableModes).map(([collection, mode]) => [
|
|
75
|
-
required(refs.collections, collection, 'collection'),
|
|
76
|
-
required(refs.modes, mode, 'mode')
|
|
77
|
-
])
|
|
78
|
-
)
|
|
79
|
-
for (const field of [
|
|
80
|
-
'fillStyleId',
|
|
81
|
-
'strokeStyleId',
|
|
82
|
-
'textStyleId',
|
|
83
|
-
'effectStyleId',
|
|
84
|
-
'gridStyleId'
|
|
85
|
-
] as const) {
|
|
86
|
-
result[field] = source[field] ? style(source[field]) : null
|
|
87
|
-
}
|
|
88
|
-
if (result.styleRuns) {
|
|
89
|
-
// A link to a layer the transfer leaves behind keeps naming it.
|
|
90
|
-
result.styleRuns = remapStyleRunReferences(result.styleRuns, {
|
|
72
|
+
Object.assign(
|
|
73
|
+
result,
|
|
74
|
+
remappedResourceReferences(source, {
|
|
91
75
|
variable,
|
|
76
|
+
collection: (id) => required(refs.collections, id, 'collection'),
|
|
77
|
+
mode: (id) => required(refs.modes, id, 'mode'),
|
|
92
78
|
style,
|
|
93
|
-
|
|
79
|
+
// A link to a layer the transfer leaves behind keeps naming it.
|
|
80
|
+
layer: (id) => refs.nodes.get(id) ?? id
|
|
94
81
|
})
|
|
95
|
-
|
|
82
|
+
)
|
|
96
83
|
// A connector keeps the layers it was attached to when they are left behind; the end becomes
|
|
97
84
|
// free where nothing by that ID exists, as a pasted Figma connector does.
|
|
98
85
|
for (const field of ['connectorStart', 'connectorEnd'] as const) {
|
|
99
86
|
const endpoint = result[field]
|
|
100
87
|
if (endpoint?.nodeId) endpoint.nodeId = refs.nodes.get(endpoint.nodeId) ?? endpoint.nodeId
|
|
101
88
|
}
|
|
102
|
-
for (const region of result.vectorNetwork?.regions ?? [])
|
|
103
|
-
if (region.fillStyleId) region.fillStyleId = style(region.fillStyleId)
|
|
104
89
|
result.componentPropertyDefinitions = source.componentPropertyDefinitions.map((definition) => ({
|
|
105
90
|
...structuredClone(definition),
|
|
106
91
|
id: property(definition.id),
|
|
107
92
|
defaultValue: propertyValue(definition.id, definition.defaultValue)
|
|
108
93
|
}))
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
propertyId
|
|
112
|
-
|
|
94
|
+
// A reference to a property that neither the transfer nor its destination defines names nothing.
|
|
95
|
+
result.componentPropertyReferences = source.componentPropertyReferences.flatMap((reference) => {
|
|
96
|
+
const propertyId = refs.properties.get(reference.propertyId)
|
|
97
|
+
return propertyId ? [{ ...reference, propertyId }] : []
|
|
98
|
+
})
|
|
113
99
|
result.componentPropertyAssignments = values(source.componentPropertyAssignments)
|
|
114
100
|
// Variant values are keyed by display names, unlike definition-ID assignments.
|
|
115
101
|
result.componentPropertyValues = { ...source.componentPropertyValues }
|
package/src/transfer/plan.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { SceneGraph } from '../graph'
|
|
2
|
+
import { sharedStyleLayers } from '../shared-styles'
|
|
2
3
|
import type { ComponentPropertyType, SceneNode } from '../types'
|
|
3
4
|
import { prepareNodeTransfer } from './nodes'
|
|
4
|
-
import { requireTransferReference } from './references'
|
|
5
5
|
import { prepareVariableTransfer } from './variables'
|
|
6
6
|
|
|
7
7
|
export interface GraphTransferInput {
|
|
@@ -73,14 +73,12 @@ export function prepareGraphTransfer(input: GraphTransferInput) {
|
|
|
73
73
|
}
|
|
74
74
|
// Layers name a style by the style's own ID, which a transferred style keeps unless the
|
|
75
75
|
// target already holds another style by it: IDs read from Figma are only unique in one file.
|
|
76
|
-
const
|
|
77
|
-
for (const node of target.getAllNodes())
|
|
78
|
-
if (node.sharedStyleType !== null && node.source.id) targetStyleIds.add(node.source.id)
|
|
76
|
+
const targetStyles = sharedStyleLayers(target)
|
|
79
77
|
const styles = new Map<string, string>()
|
|
80
78
|
for (const node of ordered) {
|
|
81
79
|
const id = node.source.id
|
|
82
80
|
if (node.sharedStyleType === null || !id) continue
|
|
83
|
-
styles.set(id,
|
|
81
|
+
styles.set(id, targetStyles.has(id) ? allocate() : id)
|
|
84
82
|
}
|
|
85
83
|
const references = {
|
|
86
84
|
nodes,
|
|
@@ -119,12 +117,6 @@ export function prepareGraphTransfer(input: GraphTransferInput) {
|
|
|
119
117
|
props: withStyleId(node, prepareNodeTransfer(node, references), styles)
|
|
120
118
|
})),
|
|
121
119
|
...resources,
|
|
122
|
-
activeModes: new Map(
|
|
123
|
-
[...source.activeMode].map(([collection, mode]) => [
|
|
124
|
-
requireTransferReference(collections, collection, 'collection'),
|
|
125
|
-
requireTransferReference(modes, mode, 'mode')
|
|
126
|
-
])
|
|
127
|
-
),
|
|
128
120
|
images: new Map([...source.images].map(([hash, bytes]) => [hash, bytes.slice()]))
|
|
129
121
|
}
|
|
130
122
|
}
|
package/src/transfer/remove.ts
CHANGED
|
@@ -30,10 +30,13 @@ export function removeGraphTransfer(graph: SceneGraph, plan: GraphTransferPlan):
|
|
|
30
30
|
}
|
|
31
31
|
graph.withBufferedEvents(() => {
|
|
32
32
|
for (const node of plan.nodes.toReversed()) graph.deleteNode(node.id)
|
|
33
|
-
for (const id of variables)
|
|
33
|
+
for (const id of variables) {
|
|
34
|
+
graph.willChangeVariable(id)
|
|
35
|
+
graph.variables.delete(id)
|
|
36
|
+
}
|
|
34
37
|
for (const id of collections) {
|
|
38
|
+
graph.willChangeCollection(id)
|
|
35
39
|
graph.variableCollections.delete(id)
|
|
36
|
-
graph.activeMode.delete(id)
|
|
37
40
|
}
|
|
38
41
|
})
|
|
39
42
|
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { isEqual } from 'es-toolkit'
|
|
2
|
+
|
|
3
|
+
import { STYLE_LINK_FIELDS } from '../shared-styles'
|
|
4
|
+
import { remapStyleRunReferences } from '../text/references'
|
|
5
|
+
import type { SceneNode } from '../types'
|
|
6
|
+
|
|
7
|
+
/** How a layer's references to variables, collections, modes, and styles are renamed. */
|
|
8
|
+
export interface ResourceReferences {
|
|
9
|
+
variable: (id: string) => string
|
|
10
|
+
collection: (id: string) => string
|
|
11
|
+
mode: (id: string) => string
|
|
12
|
+
style: (id: string) => string
|
|
13
|
+
/** The layer a text link names; links keep naming theirs without it. */
|
|
14
|
+
layer?: (id: string) => string
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* `node`'s references to variables, collections, modes, and styles, renamed as a copy into
|
|
19
|
+
* another document renames them: its bindings, the modes it sets, the styles it and its text
|
|
20
|
+
* ranges and vector regions use. Only the fields that change are returned. Instance overrides
|
|
21
|
+
* name layers too, so their callers rename them with the layers.
|
|
22
|
+
*/
|
|
23
|
+
export function remappedResourceReferences(
|
|
24
|
+
node: SceneNode,
|
|
25
|
+
references: ResourceReferences
|
|
26
|
+
): Partial<SceneNode> {
|
|
27
|
+
const { variable, collection, mode, style, layer } = references
|
|
28
|
+
const remapped: Partial<SceneNode> = {
|
|
29
|
+
boundVariables: Object.fromEntries(
|
|
30
|
+
Object.entries(node.boundVariables).map(([field, id]) => [field, variable(id)])
|
|
31
|
+
),
|
|
32
|
+
variableModes: Object.fromEntries(
|
|
33
|
+
Object.entries(node.variableModes).map(([id, modeId]) => [collection(id), mode(modeId)])
|
|
34
|
+
),
|
|
35
|
+
styleRuns: remapStyleRunReferences(node.styleRuns, { variable, style, node: layer })
|
|
36
|
+
}
|
|
37
|
+
for (const field of STYLE_LINK_FIELDS) {
|
|
38
|
+
const id = node[field]
|
|
39
|
+
if (id) remapped[field] = style(id)
|
|
40
|
+
}
|
|
41
|
+
if (node.vectorNetwork?.regions.some((region) => region.fillStyleId)) {
|
|
42
|
+
remapped.vectorNetwork = {
|
|
43
|
+
...node.vectorNetwork,
|
|
44
|
+
regions: node.vectorNetwork.regions.map((region) =>
|
|
45
|
+
region.fillStyleId ? { ...region, fillStyleId: style(region.fillStyleId) } : region
|
|
46
|
+
)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return Object.fromEntries(
|
|
50
|
+
Object.entries(remapped).filter(
|
|
51
|
+
([field, value]) => !isEqual(value, node[field as keyof SceneNode])
|
|
52
|
+
)
|
|
53
|
+
)
|
|
54
|
+
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { uniq } from 'es-toolkit'
|
|
2
|
+
|
|
3
|
+
import type { SceneGraph } from '../graph'
|
|
1
4
|
import type { Variable, VariableCollection, VariableValue } from '../types'
|
|
2
5
|
import { mapVariableValueReferences } from '../variables/value'
|
|
3
6
|
import { requireTransferReference as mapped } from './references'
|
|
@@ -81,3 +84,34 @@ export function prepareVariableTransfer(
|
|
|
81
84
|
}))
|
|
82
85
|
}
|
|
83
86
|
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Copies the variables `ids` and the collections `collectionIds` into `target`, IDs kept. Each
|
|
90
|
+
* collection comes from the first of its `sources` that has it, and its variables with it; a
|
|
91
|
+
* variable it lacks there comes from the next. A collection keeps only the variables copied.
|
|
92
|
+
*/
|
|
93
|
+
export function copyVariableTables(
|
|
94
|
+
target: SceneGraph,
|
|
95
|
+
ids: ReadonlySet<string>,
|
|
96
|
+
collectionIds: Iterable<string>,
|
|
97
|
+
sources: (collectionId: string) => readonly SceneGraph[]
|
|
98
|
+
): void {
|
|
99
|
+
for (const collectionId of collectionIds) {
|
|
100
|
+
const graphs = sources(collectionId)
|
|
101
|
+
const first = <T>(read: (graph: SceneGraph) => T | undefined): T | undefined =>
|
|
102
|
+
graphs.map(read).find((found) => found !== undefined)
|
|
103
|
+
const collection = first((graph) => graph.variableCollections.get(collectionId))
|
|
104
|
+
if (!collection) continue
|
|
105
|
+
const members = uniq(
|
|
106
|
+
graphs.flatMap((graph) => graph.variableCollections.get(collectionId)?.variableIds ?? [])
|
|
107
|
+
).filter((id) => ids.has(id))
|
|
108
|
+
target.variableCollections.set(collectionId, {
|
|
109
|
+
...structuredClone(collection),
|
|
110
|
+
variableIds: members
|
|
111
|
+
})
|
|
112
|
+
for (const id of members) {
|
|
113
|
+
const variable = first((graph) => graph.variables.get(id))
|
|
114
|
+
if (variable) target.variables.set(id, structuredClone(variable))
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -34,12 +34,26 @@ export type SceneGraphEventHandlers = Partial<{
|
|
|
34
34
|
) => void
|
|
35
35
|
}>
|
|
36
36
|
|
|
37
|
+
/** The document's records besides its nodes, which edits report changing as they do nodes. */
|
|
38
|
+
export type DocumentRecordKind = 'variable' | 'collection'
|
|
39
|
+
|
|
37
40
|
/** Hears about nodes as an edit adds and changes them, synchronously and before each change. */
|
|
38
41
|
export interface NodeChangeObserver {
|
|
39
42
|
/** A node is about to change and is still as it was. */
|
|
40
43
|
before: (node: SceneNode) => void
|
|
41
44
|
/** A node was just added. */
|
|
42
45
|
created: (node: SceneNode) => void
|
|
46
|
+
/**
|
|
47
|
+
* A variable or collection is about to change, be added, or be removed, and is still as it
|
|
48
|
+
* was: absent, for one about to be added.
|
|
49
|
+
*/
|
|
50
|
+
beforeRecord?: (kind: DocumentRecordKind, id: string) => void
|
|
51
|
+
/**
|
|
52
|
+
* The edit being observed waits on something outside it (`SceneGraph.waitOutsideEdit`): until
|
|
53
|
+
* `resume`, nodes change for someone else's edit, not this one.
|
|
54
|
+
*/
|
|
55
|
+
pause?: () => void
|
|
56
|
+
resume?: () => void
|
|
43
57
|
}
|
|
44
58
|
|
|
45
59
|
export type DocumentColorSpace = 'srgb' | 'display-p3'
|
|
@@ -243,8 +257,39 @@ export interface Stroke extends Fill {
|
|
|
243
257
|
dashPattern?: number[]
|
|
244
258
|
}
|
|
245
259
|
|
|
260
|
+
/**
|
|
261
|
+
* A Glass effect's lens, in Figma's plugin terms: how far in from the edge it bends what is
|
|
262
|
+
* behind the layer (`depth`, 1 to 100 px) and how strongly (`refraction`, 0 to 1), the light it
|
|
263
|
+
* catches (`lightAngle` in degrees, 0 lighting the top edge, and `lightIntensity`, 0 to 1), and how
|
|
264
|
+
* far the colours split (`dispersion`, 0 to 1). The effect's `radius` frosts the glass.
|
|
265
|
+
*/
|
|
266
|
+
export interface GlassEffectParams {
|
|
267
|
+
refraction: number
|
|
268
|
+
depth: number
|
|
269
|
+
lightAngle: number
|
|
270
|
+
lightIntensity: number
|
|
271
|
+
dispersion: number
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* A progressive blur's ramp, in Figma's plugin terms: the blur grows from `startRadius` at
|
|
276
|
+
* `startOffset` to the effect's `radius` at `endOffset`, both points fractions of the layer's
|
|
277
|
+
* size, and holds each end's radius beyond it.
|
|
278
|
+
*/
|
|
279
|
+
export interface ProgressiveBlur {
|
|
280
|
+
startRadius: number
|
|
281
|
+
startOffset: Vector
|
|
282
|
+
endOffset: Vector
|
|
283
|
+
}
|
|
284
|
+
|
|
246
285
|
export interface Effect {
|
|
247
|
-
type:
|
|
286
|
+
type:
|
|
287
|
+
| 'DROP_SHADOW'
|
|
288
|
+
| 'INNER_SHADOW'
|
|
289
|
+
| 'LAYER_BLUR'
|
|
290
|
+
| 'BACKGROUND_BLUR'
|
|
291
|
+
| 'FOREGROUND_BLUR'
|
|
292
|
+
| 'GLASS'
|
|
248
293
|
color: Color
|
|
249
294
|
offset: Vector
|
|
250
295
|
radius: number
|
|
@@ -252,6 +297,10 @@ export interface Effect {
|
|
|
252
297
|
visible: boolean
|
|
253
298
|
blendMode?: BlendMode
|
|
254
299
|
showShadowBehindNode?: boolean
|
|
300
|
+
/** Set on a `GLASS` effect, and only there. */
|
|
301
|
+
glass?: GlassEffectParams
|
|
302
|
+
/** Set on a layer or background blur that is progressive, and only there. */
|
|
303
|
+
progressive?: ProgressiveBlur
|
|
255
304
|
}
|
|
256
305
|
|
|
257
306
|
export type ConstraintType = 'MIN' | 'CENTER' | 'MAX' | 'STRETCH' | 'SCALE'
|
|
@@ -443,9 +492,37 @@ export interface PluginDataEntry {
|
|
|
443
492
|
value: string
|
|
444
493
|
}
|
|
445
494
|
|
|
495
|
+
/** A fixed width or height in pixels an export is scaled to, instead of a multiplier. */
|
|
496
|
+
export interface ExportSize {
|
|
497
|
+
type: 'WIDTH' | 'HEIGHT'
|
|
498
|
+
value: number
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
/** The colour profile an export is written in; the document's own unless set. */
|
|
502
|
+
export type ExportColorProfile = 'DOCUMENT' | 'SRGB' | 'DISPLAY_P3_V4'
|
|
503
|
+
|
|
504
|
+
/**
|
|
505
|
+
* One export a layer keeps. The options past `scale` and `format` are Figma's and read as Figma's
|
|
506
|
+
* defaults when left out.
|
|
507
|
+
*/
|
|
446
508
|
export interface ExportSetting {
|
|
447
509
|
scale: number
|
|
448
510
|
format: ExportFormatId
|
|
511
|
+
/** Appended to the file name. */
|
|
512
|
+
suffix?: string
|
|
513
|
+
/** A size that replaces `scale`. */
|
|
514
|
+
size?: ExportSize
|
|
515
|
+
/** Only the layer, without what overlaps it (default true). */
|
|
516
|
+
contentsOnly?: boolean
|
|
517
|
+
/** The layer's box rather than everything it draws, for text (default false). */
|
|
518
|
+
useAbsoluteBounds?: boolean
|
|
519
|
+
colorProfile?: ExportColorProfile
|
|
520
|
+
/** SVG: text as outlines rather than `<text>` (default true). */
|
|
521
|
+
svgOutlineText?: boolean
|
|
522
|
+
/** SVG: every layer's name as its element's `id` (default false). */
|
|
523
|
+
svgIdAttribute?: boolean
|
|
524
|
+
/** SVG: strokes as strokes where possible rather than masked outlines (default true). */
|
|
525
|
+
svgSimplifyStroke?: boolean
|
|
449
526
|
}
|
|
450
527
|
|
|
451
528
|
export interface PluginRelaunchDataEntry {
|
|
@@ -822,6 +899,11 @@ export interface SceneNode {
|
|
|
822
899
|
sharedSymbolVersion: string | null
|
|
823
900
|
publishedVersion: string | null
|
|
824
901
|
librarySource: LibraryAssetSource | null
|
|
902
|
+
/**
|
|
903
|
+
* The layer of a library's source document that a library definition's layer copies, which pairs
|
|
904
|
+
* it with the same layer in the library's next revision whatever that layer is called by then.
|
|
905
|
+
*/
|
|
906
|
+
libraryLayerId: string | null
|
|
825
907
|
isPublishable: boolean
|
|
826
908
|
isSymbolPublishable: boolean
|
|
827
909
|
/**
|
package/src/undo.ts
CHANGED
|
@@ -5,10 +5,29 @@ export interface UndoEntry {
|
|
|
5
5
|
coalesceKey?: string
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Why committed history changed: a new step, a change joining the newest step, undo, redo, or
|
|
10
|
+
* clearing it.
|
|
11
|
+
*/
|
|
12
|
+
export type HistoryChange = 'record' | 'join' | 'undo' | 'redo' | 'clear'
|
|
13
|
+
|
|
8
14
|
export interface UndoManagerOptions {
|
|
9
15
|
limit?: number
|
|
10
|
-
/**
|
|
11
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Called after recording, joining, undoing, redoing, or clearing committed history, with which,
|
|
18
|
+
* and with the step recorded or joined for `'record'` and `'join'`.
|
|
19
|
+
*/
|
|
20
|
+
onChange?: (change: HistoryChange, step?: UndoEntry) => void
|
|
21
|
+
/**
|
|
22
|
+
* Called when an edit ends without a step, its changes undone or amounting to nothing: a batch
|
|
23
|
+
* rolled back, or an edit reported with `discardEdit`. History is unchanged, so `onChange` is not.
|
|
24
|
+
*/
|
|
25
|
+
onDiscard?: () => void
|
|
26
|
+
/**
|
|
27
|
+
* Runs an undo or a redo, which the editor runs outside edits in progress
|
|
28
|
+
* (`SceneGraph.runOutsideEdits`), so an agent's edit open meanwhile does not record it.
|
|
29
|
+
*/
|
|
30
|
+
runReplay?: (replay: () => void) => void
|
|
12
31
|
}
|
|
13
32
|
|
|
14
33
|
interface UndoBatch {
|
|
@@ -28,11 +47,15 @@ export class UndoManager {
|
|
|
28
47
|
private openEdits = 0
|
|
29
48
|
private readonly settlers = new Set<() => void>()
|
|
30
49
|
private readonly limit: number
|
|
31
|
-
private readonly onChange: (() => void) | undefined
|
|
50
|
+
private readonly onChange: ((change: HistoryChange, step?: UndoEntry) => void) | undefined
|
|
51
|
+
private readonly onDiscard: (() => void) | undefined
|
|
52
|
+
private readonly runReplay: (replay: () => void) => void
|
|
32
53
|
|
|
33
54
|
constructor(options: UndoManagerOptions = {}) {
|
|
34
55
|
this.limit = options.limit ?? DEFAULT_HISTORY_LIMIT
|
|
35
56
|
this.onChange = options.onChange
|
|
57
|
+
this.onDiscard = options.onDiscard
|
|
58
|
+
this.runReplay = options.runReplay ?? ((replay) => replay())
|
|
36
59
|
}
|
|
37
60
|
|
|
38
61
|
apply(entry: UndoEntry): void {
|
|
@@ -86,7 +109,7 @@ export class UndoManager {
|
|
|
86
109
|
if (!entry) return null
|
|
87
110
|
this.replay(() => entry.inverse())
|
|
88
111
|
this.redoStack.push(entry)
|
|
89
|
-
this.onChange?.()
|
|
112
|
+
this.onChange?.('undo')
|
|
90
113
|
return entry.label
|
|
91
114
|
}
|
|
92
115
|
|
|
@@ -96,7 +119,7 @@ export class UndoManager {
|
|
|
96
119
|
if (!entry) return null
|
|
97
120
|
this.replay(() => entry.forward())
|
|
98
121
|
this.undoStack.push(entry)
|
|
99
|
-
this.onChange?.()
|
|
122
|
+
this.onChange?.('redo')
|
|
100
123
|
return entry.label
|
|
101
124
|
}
|
|
102
125
|
|
|
@@ -127,9 +150,23 @@ export class UndoManager {
|
|
|
127
150
|
}
|
|
128
151
|
|
|
129
152
|
rollbackBatch(): void {
|
|
130
|
-
const batch = this.batches.
|
|
153
|
+
const batch = this.batches.at(-1)
|
|
131
154
|
if (!batch) return
|
|
132
|
-
|
|
155
|
+
// Still open while it rolls back, so what the rollback changes belongs to the batch.
|
|
156
|
+
try {
|
|
157
|
+
for (const entry of batch.entries.toReversed()) entry.inverse()
|
|
158
|
+
} finally {
|
|
159
|
+
this.batches.pop()
|
|
160
|
+
}
|
|
161
|
+
this.onDiscard?.()
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Reports an edit that ended without a step, rolled back or changing nothing, as a rolled-back
|
|
166
|
+
* batch does. Called once the edit has closed, so `isRecording` tells whether another is open.
|
|
167
|
+
*/
|
|
168
|
+
discardEdit(): void {
|
|
169
|
+
this.onDiscard?.()
|
|
133
170
|
}
|
|
134
171
|
|
|
135
172
|
/** Abandon provisional history without replaying it or changing committed undo/redo entries. */
|
|
@@ -141,7 +178,7 @@ export class UndoManager {
|
|
|
141
178
|
this.undoStack = []
|
|
142
179
|
this.redoStack = []
|
|
143
180
|
this.discardBatches()
|
|
144
|
-
this.onChange?.()
|
|
181
|
+
this.onChange?.('clear')
|
|
145
182
|
}
|
|
146
183
|
|
|
147
184
|
/** Whether undo or redo is replaying a step, whose changes are history rather than new edits. */
|
|
@@ -170,13 +207,14 @@ export class UndoManager {
|
|
|
170
207
|
entry.inverse()
|
|
171
208
|
inverse()
|
|
172
209
|
}
|
|
210
|
+
this.onChange?.('join', last)
|
|
173
211
|
return true
|
|
174
212
|
}
|
|
175
213
|
|
|
176
214
|
private replay(step: () => void) {
|
|
177
215
|
this.replaying++
|
|
178
216
|
try {
|
|
179
|
-
step
|
|
217
|
+
this.runReplay(step)
|
|
180
218
|
} finally {
|
|
181
219
|
this.replaying--
|
|
182
220
|
}
|
|
@@ -274,7 +312,7 @@ export class UndoManager {
|
|
|
274
312
|
}
|
|
275
313
|
this.redoStack = []
|
|
276
314
|
this.trimUndoStack()
|
|
277
|
-
this.onChange?.()
|
|
315
|
+
this.onChange?.('record', this.undoStack.at(-1))
|
|
278
316
|
}
|
|
279
317
|
|
|
280
318
|
private trimUndoStack(): void {
|