@pairdraw/scene-graph 0.19.1 → 0.20.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/behaviours/index.d.ts +2 -2
- package/dist/behaviours/index.js +2 -2
- package/dist/behaviours/spec.d.ts +6 -1
- package/dist/behaviours/spec.d.ts.map +1 -1
- package/dist/behaviours/spec.js +62 -5
- package/dist/behaviours/spec.js.map +1 -1
- package/dist/canvas-layout.js +66 -0
- package/dist/canvas-layout.js.map +1 -0
- package/dist/components/index.d.ts +2 -2
- package/dist/components/index.js +2 -2
- 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/coordinate.js +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/text.d.ts +22 -1
- package/dist/css/text.d.ts.map +1 -1
- package/dist/css/text.js +81 -1
- package/dist/css/text.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 +93 -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/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/graph.d.ts +8 -1
- package/dist/graph.d.ts.map +1 -1
- package/dist/graph.js +36 -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/group-bounds.d.ts +4 -1
- package/dist/group-bounds.d.ts.map +1 -1
- package/dist/group-bounds.js +11 -1
- package/dist/group-bounds.js.map +1 -1
- 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 +33 -178
- package/dist/hit-test.js.map +1 -1
- package/dist/index.d.ts +2 -2
- 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 +1 -1
- package/dist/instances/index.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/node-defaults.d.ts +21 -1
- package/dist/node-defaults.d.ts.map +1 -1
- package/dist/node-defaults.js +63 -50
- package/dist/node-defaults.js.map +1 -1
- package/dist/plugin-data/fields.d.ts +75 -0
- package/dist/plugin-data/fields.d.ts.map +1 -1
- package/dist/plugin-data/fields.js +18 -1
- package/dist/plugin-data/fields.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/resize.d.ts.map +1 -1
- package/dist/resize.js +3 -6
- package/dist/resize.js.map +1 -1
- package/dist/scaling/node.d.ts.map +1 -1
- package/dist/scaling/node.js +28 -4
- package/dist/scaling/node.js.map +1 -1
- package/dist/shared-styles.d.ts +3 -1
- package/dist/shared-styles.d.ts.map +1 -1
- package/dist/shared-styles.js +7 -1
- package/dist/shared-styles.js.map +1 -1
- package/dist/text/path.js +11 -0
- package/dist/text/path.js.map +1 -0
- package/dist/text/picture.d.ts.map +1 -1
- package/dist/text/picture.js +5 -5
- package/dist/text/picture.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/copied.d.ts +14 -0
- package/dist/transfer/copied.d.ts.map +1 -0
- package/dist/transfer/copied.js +52 -0
- package/dist/transfer/copied.js.map +1 -0
- package/dist/transfer/index.d.ts +2 -1
- package/dist/transfer/index.js +2 -1
- package/dist/transfer/nodes.js +7 -0
- package/dist/transfer/nodes.js.map +1 -1
- package/dist/types.d.ts +104 -15
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/undo.d.ts +6 -0
- package/dist/undo.d.ts.map +1 -1
- package/dist/undo.js +13 -0
- package/dist/undo.js.map +1 -1
- package/dist/variables/index.d.ts.map +1 -1
- package/dist/variables/index.js.map +1 -1
- 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/behaviours/spec.ts +94 -4
- package/src/canvas-layout.ts +76 -0
- package/src/components/variants.ts +39 -0
- package/src/constants.ts +75 -0
- package/src/copy.ts +20 -1
- package/src/css/index.ts +12 -1
- package/src/css/text.ts +86 -0
- 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 +101 -0
- package/src/fields/components.ts +21 -0
- package/src/fields/index.ts +1 -0
- package/src/fields/layout.ts +10 -0
- package/src/generated/shape-with-text.ts +28 -2
- package/src/graph.ts +48 -6
- package/src/grid-values.ts +47 -0
- package/src/group-bounds.ts +13 -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 +78 -291
- package/src/instances/fields.ts +2 -0
- package/src/instances/index.ts +1 -0
- package/src/node-defaults.ts +71 -52
- package/src/plugin-data/fields.ts +18 -1
- package/src/preview.ts +2 -0
- package/src/resize.ts +3 -14
- package/src/scaling/node.ts +34 -5
- package/src/shared-styles.ts +8 -0
- package/src/text/path.ts +14 -0
- package/src/text/picture.ts +5 -2
- 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/copied.ts +72 -0
- package/src/transfer/index.ts +1 -0
- package/src/transfer/nodes.ts +10 -0
- package/src/types.ts +117 -14
- package/src/undo.ts +11 -0
- package/src/variables/index.ts +1 -4
- 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
package/src/node-defaults.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
DEFAULT_STROKE_WEIGHT
|
|
6
6
|
} from './constants'
|
|
7
7
|
import { normalizeEffects } from './effects'
|
|
8
|
+
import { EMPTY_LIST, EMPTY_RECORD, shareEmptyNodeValues } from './empty-values'
|
|
8
9
|
import { createInstanceOverrideState } from './instances/overrides'
|
|
9
10
|
import { NO_LETTER_SPACING } from './text/lengths'
|
|
10
11
|
import type { NodeType, SceneNode, SourceMetadata } from './types'
|
|
@@ -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
|
|
|
@@ -74,12 +76,36 @@ export function textLayerName(type: NodeType, text: string): string {
|
|
|
74
76
|
return lines.join(' ') || defaultNodeName(type)
|
|
75
77
|
}
|
|
76
78
|
|
|
79
|
+
/**
|
|
80
|
+
* The fields auto layout sets on the frame that holds it, with the value each holds when no frame
|
|
81
|
+
* lays anything out. A page holds layers; it is not one, so none of these apply to it and a page
|
|
82
|
+
* that took them would place its layers by a container nobody can see.
|
|
83
|
+
*/
|
|
84
|
+
export const FRAME_LAYOUT_DEFAULTS = {
|
|
85
|
+
layoutMode: 'NONE',
|
|
86
|
+
layoutDirection: 'AUTO',
|
|
87
|
+
layoutWrap: 'NO_WRAP',
|
|
88
|
+
primaryAxisAlign: 'MIN',
|
|
89
|
+
counterAxisAlign: 'MIN',
|
|
90
|
+
primaryAxisSizing: 'FIXED',
|
|
91
|
+
counterAxisSizing: 'FIXED',
|
|
92
|
+
itemSpacing: 0,
|
|
93
|
+
counterAxisSpacing: 0,
|
|
94
|
+
paddingTop: 0,
|
|
95
|
+
paddingRight: 0,
|
|
96
|
+
paddingBottom: 0,
|
|
97
|
+
paddingLeft: 0
|
|
98
|
+
} as const satisfies Partial<SceneNode>
|
|
99
|
+
|
|
77
100
|
export function createDefaultNode(
|
|
78
101
|
generateId: () => string,
|
|
79
102
|
type: NodeType,
|
|
80
103
|
overrides: Partial<SceneNode> = {}
|
|
81
104
|
): SceneNode {
|
|
82
|
-
|
|
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 = {
|
|
83
109
|
id: generateId(),
|
|
84
110
|
type,
|
|
85
111
|
name: type.charAt(0) + type.slice(1).toLowerCase(),
|
|
@@ -93,11 +119,13 @@ export function createDefaultNode(
|
|
|
93
119
|
source: createDefaultSourceMetadata(),
|
|
94
120
|
derivedLayout: null,
|
|
95
121
|
fills:
|
|
96
|
-
type === 'TEXT'
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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,
|
|
101
129
|
fillStyleId: null,
|
|
102
130
|
strokeStyleId: null,
|
|
103
131
|
textStyleId: null,
|
|
@@ -115,6 +143,8 @@ export function createDefaultNode(
|
|
|
115
143
|
visible: true,
|
|
116
144
|
locked: false,
|
|
117
145
|
clipsContent: false,
|
|
146
|
+
overflowDirection: 'NONE',
|
|
147
|
+
scrollBehavior: 'SCROLLS',
|
|
118
148
|
text: '',
|
|
119
149
|
fontSize: 14,
|
|
120
150
|
fontFamily: DEFAULT_FONT_FAMILY,
|
|
@@ -127,27 +157,15 @@ export function createDefaultNode(
|
|
|
127
157
|
leadingTrim: 'NONE',
|
|
128
158
|
lineHeight: null,
|
|
129
159
|
letterSpacing: NO_LETTER_SPACING,
|
|
130
|
-
|
|
131
|
-
layoutDirection: 'AUTO',
|
|
132
|
-
layoutWrap: 'NO_WRAP',
|
|
133
|
-
primaryAxisAlign: 'MIN',
|
|
134
|
-
counterAxisAlign: 'MIN',
|
|
135
|
-
primaryAxisSizing: 'FIXED',
|
|
136
|
-
counterAxisSizing: 'FIXED',
|
|
137
|
-
itemSpacing: 0,
|
|
138
|
-
counterAxisSpacing: 0,
|
|
139
|
-
paddingTop: 0,
|
|
140
|
-
paddingRight: 0,
|
|
141
|
-
paddingBottom: 0,
|
|
142
|
-
paddingLeft: 0,
|
|
160
|
+
...FRAME_LAYOUT_DEFAULTS,
|
|
143
161
|
blendMode: 'PASS_THROUGH',
|
|
144
162
|
layoutPositioning: 'AUTO',
|
|
145
163
|
layoutGrow: 0,
|
|
146
164
|
layoutAlignSelf: 'AUTO',
|
|
147
165
|
vectorNetwork: null,
|
|
148
166
|
handleMirroring: 'NONE',
|
|
149
|
-
fillGeometry:
|
|
150
|
-
strokeGeometry:
|
|
167
|
+
fillGeometry: EMPTY_LIST,
|
|
168
|
+
strokeGeometry: EMPTY_LIST,
|
|
151
169
|
arcData: null,
|
|
152
170
|
textAlignVertical: 'TOP',
|
|
153
171
|
textAutoResize: 'NONE',
|
|
@@ -155,24 +173,24 @@ export function createDefaultNode(
|
|
|
155
173
|
textDecoration: 'NONE',
|
|
156
174
|
textDecorationStyle: 'SOLID',
|
|
157
175
|
textDecorationThickness: null,
|
|
158
|
-
textDecorationFills:
|
|
176
|
+
textDecorationFills: EMPTY_LIST,
|
|
159
177
|
textDecorationSkipInk: true,
|
|
160
178
|
textUnderlineOffset: null,
|
|
161
179
|
maxLines: null,
|
|
162
|
-
textParagraphs:
|
|
180
|
+
textParagraphs: EMPTY_LIST,
|
|
163
181
|
listSpacing: 0,
|
|
164
182
|
paragraphSpacing: 0,
|
|
165
183
|
paragraphIndent: 0,
|
|
166
184
|
hangingList: false,
|
|
167
|
-
styleRuns:
|
|
168
|
-
fontVariations:
|
|
185
|
+
styleRuns: EMPTY_LIST,
|
|
186
|
+
fontVariations: EMPTY_LIST,
|
|
169
187
|
opticalSizeFromFontSize: true,
|
|
170
|
-
fontFeatures:
|
|
188
|
+
fontFeatures: EMPTY_LIST,
|
|
171
189
|
horizontalConstraint: 'MIN',
|
|
172
190
|
verticalConstraint: 'MIN',
|
|
173
191
|
strokeCap: 'NONE',
|
|
174
192
|
strokeJoin: 'MITER',
|
|
175
|
-
dashPattern:
|
|
193
|
+
dashPattern: EMPTY_LIST,
|
|
176
194
|
borderTopWeight: 0,
|
|
177
195
|
borderRightWeight: 0,
|
|
178
196
|
borderBottomWeight: 0,
|
|
@@ -191,14 +209,14 @@ export function createDefaultNode(
|
|
|
191
209
|
connectorLineType: 'ELBOWED',
|
|
192
210
|
connectorStartCap: 'ROUND',
|
|
193
211
|
connectorEndCap: 'ARROW_LINES',
|
|
194
|
-
connectorControlPoints:
|
|
212
|
+
connectorControlPoints: EMPTY_LIST,
|
|
195
213
|
connectorCurveHandles: null,
|
|
196
214
|
connectorLabelPosition: null,
|
|
197
215
|
isMask: false,
|
|
198
216
|
maskType: 'ALPHA',
|
|
199
217
|
maskIsOutline: false,
|
|
200
|
-
gridTemplateColumns:
|
|
201
|
-
gridTemplateRows:
|
|
218
|
+
gridTemplateColumns: EMPTY_LIST,
|
|
219
|
+
gridTemplateRows: EMPTY_LIST,
|
|
202
220
|
gridColumnGap: 0,
|
|
203
221
|
gridRowGap: 0,
|
|
204
222
|
gridPosition: null,
|
|
@@ -215,10 +233,10 @@ export function createDefaultNode(
|
|
|
215
233
|
shapeTruncates: false,
|
|
216
234
|
componentId: null,
|
|
217
235
|
instanceOverrides: createInstanceOverrideState(),
|
|
218
|
-
componentPropertyDefinitions:
|
|
219
|
-
componentPropertyReferences:
|
|
220
|
-
componentPropertyAssignments:
|
|
221
|
-
componentPropertyValues:
|
|
236
|
+
componentPropertyDefinitions: EMPTY_LIST,
|
|
237
|
+
componentPropertyReferences: EMPTY_LIST,
|
|
238
|
+
componentPropertyAssignments: EMPTY_RECORD,
|
|
239
|
+
componentPropertyValues: EMPTY_RECORD,
|
|
222
240
|
componentKey: null,
|
|
223
241
|
sourceLibraryKey: null,
|
|
224
242
|
publishId: null,
|
|
@@ -230,18 +248,18 @@ export function createDefaultNode(
|
|
|
230
248
|
isSymbolPublishable: false,
|
|
231
249
|
isExposedInstance: false,
|
|
232
250
|
symbolDescription: '',
|
|
233
|
-
symbolLinks:
|
|
234
|
-
variantPropSpecs:
|
|
235
|
-
boundVariables:
|
|
236
|
-
variableBindingScales:
|
|
237
|
-
variableAssignmentScales:
|
|
251
|
+
symbolLinks: EMPTY_LIST,
|
|
252
|
+
variantPropSpecs: EMPTY_LIST,
|
|
253
|
+
boundVariables: EMPTY_RECORD,
|
|
254
|
+
variableBindingScales: EMPTY_RECORD,
|
|
255
|
+
variableAssignmentScales: EMPTY_RECORD,
|
|
238
256
|
componentScale: 1,
|
|
239
|
-
variableModes:
|
|
240
|
-
exportSettings:
|
|
257
|
+
variableModes: EMPTY_RECORD,
|
|
258
|
+
exportSettings: EMPTY_LIST,
|
|
241
259
|
status: null,
|
|
242
|
-
pluginData:
|
|
243
|
-
pluginRelaunchData:
|
|
244
|
-
prototypeReactions:
|
|
260
|
+
pluginData: EMPTY_LIST,
|
|
261
|
+
pluginRelaunchData: EMPTY_LIST,
|
|
262
|
+
prototypeReactions: EMPTY_LIST,
|
|
245
263
|
internalOnly: false,
|
|
246
264
|
flipX: false,
|
|
247
265
|
flipY: false,
|
|
@@ -250,10 +268,11 @@ export function createDefaultNode(
|
|
|
250
268
|
derivedTextHeight: null,
|
|
251
269
|
textPathData: null,
|
|
252
270
|
textPathBox: null,
|
|
253
|
-
booleanOperation: undefined
|
|
254
|
-
...overrides
|
|
271
|
+
booleanOperation: undefined
|
|
255
272
|
} satisfies CompleteNodeFields
|
|
273
|
+
const node: SceneNode = { ...defaults, ...overrides }
|
|
256
274
|
node.effects = normalizeEffects(node.effects)
|
|
275
|
+
shareEmptyNodeValues(node, Object.keys(overrides))
|
|
257
276
|
return node
|
|
258
277
|
}
|
|
259
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,6 +14,7 @@ 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,
|
|
@@ -25,6 +27,7 @@ import {
|
|
|
25
27
|
type TextDirection,
|
|
26
28
|
type TokenUnit
|
|
27
29
|
} from '../types'
|
|
30
|
+
import { variationSetSchema, variationStandInSchema } from '../variations/schema'
|
|
28
31
|
import {
|
|
29
32
|
jsonPluginDataField,
|
|
30
33
|
textPluginDataField,
|
|
@@ -249,6 +252,10 @@ export const PAIRDRAW_PLUGIN_DATA = {
|
|
|
249
252
|
comments: jsonPluginDataField('comments', 'bookkeeping', commentThreadsSchema),
|
|
250
253
|
/** The statuses layers can be in, on the DOCUMENT node. */
|
|
251
254
|
statuses: jsonPluginDataField('statuses', 'bookkeeping', statusWorkflowSchema),
|
|
255
|
+
/** The code the document's variables are linked to, on the DOCUMENT node. */
|
|
256
|
+
tokenSources: jsonPluginDataField('tokenSources', 'bookkeeping', tokenSourcesSchema),
|
|
257
|
+
/** The design rules agents follow in the document, on the DOCUMENT node. */
|
|
258
|
+
designMemory: jsonPluginDataField('designMemory', 'bookkeeping', designMemorySchema),
|
|
252
259
|
/** How tightly the document's `.fig` data is compressed, on the DOCUMENT node. */
|
|
253
260
|
figCompression: textPluginDataField('figCompression', 'bookkeeping', FIG_COMPRESSIONS),
|
|
254
261
|
/** A layer's status, any state of the workflow; Figma's `sectionStatusInfo` knows only two. */
|
|
@@ -289,7 +296,17 @@ export const PAIRDRAW_PLUGIN_DATA = {
|
|
|
289
296
|
* A snapshot of one page: its address, viewport, and when it was refreshed. The picture is
|
|
290
297
|
* the layer's image fill. An address that is not an http or https page does not decode.
|
|
291
298
|
*/
|
|
292
|
-
browserNode: jsonPluginDataField('browserNode', 'content', browserNodeSchema)
|
|
299
|
+
browserNode: jsonPluginDataField('browserNode', 'content', browserNodeSchema),
|
|
300
|
+
/**
|
|
301
|
+
* On a section, that its children are variations of another layer: which one, and how that
|
|
302
|
+
* layer looked when they were made. A copy of the section is an ordinary section.
|
|
303
|
+
*/
|
|
304
|
+
variationSet: jsonPluginDataField('variationSet', 'bookkeeping', variationSetSchema),
|
|
305
|
+
/**
|
|
306
|
+
* On a layer of a version, the main component or component set of the original it stands in
|
|
307
|
+
* for, so a pick keeps that component rather than pairing it by name.
|
|
308
|
+
*/
|
|
309
|
+
variationStandIn: jsonPluginDataField('variationStandIn', 'bookkeeping', variationStandInSchema)
|
|
293
310
|
} satisfies Record<string, PluginDataKey>
|
|
294
311
|
|
|
295
312
|
const NOT_CONTENT = Object.values(PAIRDRAW_PLUGIN_DATA).filter((field) => field.role !== 'content')
|
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/resize.ts
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
} from './copy'
|
|
8
8
|
import { enforcedAspectRatio } from './layout/aspect-ratio'
|
|
9
9
|
import type { Rect } from './primitives'
|
|
10
|
+
import { followsPath } from './text/path'
|
|
10
11
|
import type { ConstraintType, DerivedTextGlyph, SceneNode, Stroke, VectorNetwork } from './types'
|
|
11
12
|
import { cloneVectorNetwork } from './vector-network'
|
|
12
13
|
|
|
@@ -332,7 +333,7 @@ export function scaledGeometryChanges(
|
|
|
332
333
|
Object.assign(changes, scaledPathTextChanges(orig, sx, sy))
|
|
333
334
|
// Glyphs scaled as a picture take their strokes along; any other stroke keeps its weight, as
|
|
334
335
|
// Figma reports it, even where only a scaled outline can draw it.
|
|
335
|
-
if (orig.strokes.length > 0 &&
|
|
336
|
+
if (orig.strokes.length > 0 && followsPath(orig)) {
|
|
336
337
|
changes.strokes = scaleStrokes(orig.strokes, sx, sy)
|
|
337
338
|
}
|
|
338
339
|
return changes
|
|
@@ -369,25 +370,13 @@ export function shapeGeometryChanges(
|
|
|
369
370
|
|
|
370
371
|
type PathTextFields = Pick<SceneNode, 'derivedTextGlyphs' | 'textPathData' | 'textPathBox'>
|
|
371
372
|
|
|
372
|
-
// Path text scales with its path, including baked path text that kept only rotated glyphs;
|
|
373
|
-
// other text reflows in the new box, so its glyphs are dropped.
|
|
374
|
-
function isScaledPathText(orig: PathTextFields): boolean {
|
|
375
|
-
const glyphs = orig.derivedTextGlyphs ?? []
|
|
376
|
-
return (
|
|
377
|
-
glyphs.length > 0 &&
|
|
378
|
-
(!!orig.textPathData ||
|
|
379
|
-
!!orig.textPathBox ||
|
|
380
|
-
glyphs.some((glyph) => (glyph.rotation ?? 0) !== 0))
|
|
381
|
-
)
|
|
382
|
-
}
|
|
383
|
-
|
|
384
373
|
/** The baked glyphs and layout box of path text, scaled with the layer; nothing for other text. */
|
|
385
374
|
export function scaledPathTextChanges(
|
|
386
375
|
orig: PathTextFields,
|
|
387
376
|
sx: number,
|
|
388
377
|
sy: number
|
|
389
378
|
): Pick<Partial<SceneNode>, 'derivedTextGlyphs' | 'textPathBox'> {
|
|
390
|
-
if (!
|
|
379
|
+
if (!followsPath(orig)) return {}
|
|
391
380
|
const changes: Pick<Partial<SceneNode>, 'derivedTextGlyphs' | 'textPathBox'> = {
|
|
392
381
|
derivedTextGlyphs: scaleDerivedGlyphs(orig.derivedTextGlyphs, sx, sy)
|
|
393
382
|
}
|
package/src/scaling/node.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { scaleGeometryPaths } from '../copy'
|
|
2
|
-
import { scaledPathTextChanges } from '../resize'
|
|
1
|
+
import { copyDerivedGlyphs, scaleGeometryPaths } from '../copy'
|
|
3
2
|
import { scaledTextLength } from '../text/lengths'
|
|
4
3
|
import { TEXT_PARAGRAPH_SPACING_FIELDS } from '../text/paragraphs'
|
|
4
|
+
import { followsPath } from '../text/path'
|
|
5
5
|
import {
|
|
6
6
|
type Effect,
|
|
7
7
|
type Fill,
|
|
@@ -14,6 +14,29 @@ import {
|
|
|
14
14
|
} from '../types'
|
|
15
15
|
import { cloneVectorNetwork } from '../vector-network'
|
|
16
16
|
|
|
17
|
+
function scaledPathText(node: SceneNode, scale: number): Partial<SceneNode> {
|
|
18
|
+
if (!node.textPathData && !followsPath(node)) {
|
|
19
|
+
return {}
|
|
20
|
+
}
|
|
21
|
+
const box = node.textPathBox
|
|
22
|
+
return {
|
|
23
|
+
derivedTextGlyphs:
|
|
24
|
+
copyDerivedGlyphs(node.derivedTextGlyphs)?.map((glyph) => ({
|
|
25
|
+
...glyph,
|
|
26
|
+
x: glyph.x * scale,
|
|
27
|
+
y: glyph.y * scale,
|
|
28
|
+
fontSize: glyph.fontSize * scale,
|
|
29
|
+
...(glyph.advance === undefined ? {} : { advance: glyph.advance * scale })
|
|
30
|
+
})) ?? null,
|
|
31
|
+
textPathBox: box && {
|
|
32
|
+
x: box.x * scale,
|
|
33
|
+
y: box.y * scale,
|
|
34
|
+
width: box.width * scale,
|
|
35
|
+
height: box.height * scale
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
17
40
|
function scaledOptional(value: number | null, scale: number): number | null {
|
|
18
41
|
return value == null ? null : value * scale
|
|
19
42
|
}
|
|
@@ -29,8 +52,13 @@ function scaledStrokes(strokes: readonly Stroke[], scale: number): Stroke[] {
|
|
|
29
52
|
function scaledEffects(effects: readonly Effect[], scale: number): Effect[] {
|
|
30
53
|
return effects.map((effect) => {
|
|
31
54
|
const copy = structuredClone(effect)
|
|
32
|
-
// A shader effect has no geometry of its own
|
|
33
|
-
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
|
+
}
|
|
34
62
|
copy.offset = { x: copy.offset.x * scale, y: copy.offset.y * scale }
|
|
35
63
|
copy.radius *= scale
|
|
36
64
|
copy.spread *= scale
|
|
@@ -141,6 +169,7 @@ export function scaleNodeChanges(
|
|
|
141
169
|
paragraphSpacing: node.paragraphSpacing * scale,
|
|
142
170
|
paragraphIndent: node.paragraphIndent * scale,
|
|
143
171
|
textParagraphs: scaledParagraphStyles(node.textParagraphs, scale),
|
|
172
|
+
derivedTextHeight: scaledOptional(node.derivedTextHeight, scale),
|
|
144
173
|
itemSpacing: node.itemSpacing * scale,
|
|
145
174
|
counterAxisSpacing: node.counterAxisSpacing * scale,
|
|
146
175
|
paddingTop: node.paddingTop * scale,
|
|
@@ -165,6 +194,6 @@ export function scaleNodeChanges(
|
|
|
165
194
|
vectorNetwork: scaledVectorNetwork(node, scale),
|
|
166
195
|
fillGeometry: scaleGeometryPaths(node.fillGeometry, scale, scale),
|
|
167
196
|
strokeGeometry: scaleGeometryPaths(node.strokeGeometry, scale, scale),
|
|
168
|
-
...
|
|
197
|
+
...scaledPathText(node, scale)
|
|
169
198
|
}
|
|
170
199
|
}
|
package/src/shared-styles.ts
CHANGED
|
@@ -90,6 +90,14 @@ export function sharedStyleTypeForKind(kind: SharedStyleKind): SharedStyleType {
|
|
|
90
90
|
return STYLE_TYPES[kind]
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
+
/** The document's shared style layers, by the source ID layers link them by. */
|
|
94
|
+
export function sharedStyleLayers(graph: SceneGraph): Map<string, SceneNode> {
|
|
95
|
+
const styles = new Map<string, SceneNode>()
|
|
96
|
+
for (const node of graph.getAllNodes())
|
|
97
|
+
if (node.sharedStyleType !== null && node.source.id) styles.set(node.source.id, node)
|
|
98
|
+
return styles
|
|
99
|
+
}
|
|
100
|
+
|
|
93
101
|
export function getSharedStyles(graph: SceneGraph, kind: SharedStyleKind): SharedStyle[] {
|
|
94
102
|
const type = sharedStyleTypeForKind(kind)
|
|
95
103
|
const styles: SharedStyle[] = []
|
package/src/text/path.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { SceneNode } from '../types'
|
|
2
|
+
|
|
3
|
+
/** Whether the node's glyphs were baked along a path, including rotated-as-a-picture text. */
|
|
4
|
+
export function followsPath(
|
|
5
|
+
node: Pick<SceneNode, 'derivedTextGlyphs' | 'textPathData' | 'textPathBox'>
|
|
6
|
+
): boolean {
|
|
7
|
+
const glyphs = node.derivedTextGlyphs ?? []
|
|
8
|
+
if (glyphs.length === 0) {
|
|
9
|
+
return false
|
|
10
|
+
}
|
|
11
|
+
return (
|
|
12
|
+
!!node.textPathData || !!node.textPathBox || glyphs.some((glyph) => (glyph.rotation ?? 0) !== 0)
|
|
13
|
+
)
|
|
14
|
+
}
|
package/src/text/picture.ts
CHANGED
|
@@ -39,13 +39,16 @@ export function textCacheInvalidationChanges(
|
|
|
39
39
|
// A successful path-text edit supplies reflowed glyphs in `changes`. Every
|
|
40
40
|
// other mutation path must drop stale baked glyphs and path identity rather
|
|
41
41
|
// than pair new text/style with old visible outlines.
|
|
42
|
-
if (
|
|
42
|
+
if (glyphsInvalidated && !changes.derivedTextGlyphs) {
|
|
43
43
|
// Path-text resize supplies transformed glyphs through the resize workflow. A raw box
|
|
44
44
|
// preview keeps them until that workflow commits or an actual shaping edit occurs.
|
|
45
45
|
const onlyPathBoxResize =
|
|
46
46
|
!!node.textPathData && keys.every((key) => key === 'width' || key === 'height')
|
|
47
|
-
|
|
47
|
+
const placesPath = keys.includes('textPathBox') && !!changes.textPathBox
|
|
48
|
+
if (node.derivedTextGlyphs && !onlyPathBoxResize) {
|
|
48
49
|
invalidated.derivedTextGlyphs = null
|
|
50
|
+
}
|
|
51
|
+
if (node.textPathData && !onlyPathBoxResize && !placesPath) {
|
|
49
52
|
invalidated.textPathData = null
|
|
50
53
|
}
|
|
51
54
|
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import * as v from 'valibot'
|
|
2
|
+
|
|
3
|
+
import type { SceneGraph } from '../graph'
|
|
4
|
+
import { readPluginData, withPluginData } from '../plugin-data/field'
|
|
5
|
+
import { PAIRDRAW_PLUGIN_DATA } from '../plugin-data/fields'
|
|
6
|
+
import type { PluginDataEntry } from '../types'
|
|
7
|
+
import { relativeTokenPathSchema, type TokenSource } from './schema'
|
|
8
|
+
|
|
9
|
+
const { tokenSources } = PAIRDRAW_PLUGIN_DATA
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The code a document's variables are linked to, with what it held at the last sync. The links
|
|
13
|
+
* live in Pairdraw's plugin data on the document node, so they travel with the `.fig` file and
|
|
14
|
+
* Figma ignores them; where each file is on this computer stays with the app, not the document.
|
|
15
|
+
*/
|
|
16
|
+
export function readTokenSources(graph: SceneGraph): TokenSource[] {
|
|
17
|
+
return readPluginData(graph.getNode(graph.rootId)?.pluginData, tokenSources) ?? []
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The links with their snapshots keyed by the graph's variable and mode ids. A format that keys
|
|
22
|
+
* variables and modes by name, such as `.pen`, gives them new ids when it reads them back; the
|
|
23
|
+
* names the file stored when it was saved, or the last sync's where the file recorded none, find
|
|
24
|
+
* them again. `names` and the snapshot's token identities are kept as they were. Links whose
|
|
25
|
+
* variables are all gone are left as they are.
|
|
26
|
+
*/
|
|
27
|
+
export function rekeyTokenSources(
|
|
28
|
+
graph: SceneGraph,
|
|
29
|
+
sources: readonly TokenSource[]
|
|
30
|
+
): TokenSource[] {
|
|
31
|
+
const collectionsByName = new Map(
|
|
32
|
+
[...graph.variableCollections.values()].map((collection) => [collection.name, collection])
|
|
33
|
+
)
|
|
34
|
+
const variablesByKey = new Map<string, string>()
|
|
35
|
+
for (const variable of graph.variables.values()) {
|
|
36
|
+
const collection = graph.variableCollections.get(variable.collectionId)
|
|
37
|
+
if (collection) variablesByKey.set(`${collection.name}/${variable.name}`, variable.id)
|
|
38
|
+
}
|
|
39
|
+
const currentModeId = (collectionName: string, modeId: string, modes: TokenSource['modes']) => {
|
|
40
|
+
const name = modes?.[collectionName]?.[modeId]
|
|
41
|
+
if (name === undefined) return modeId
|
|
42
|
+
const mode = collectionsByName.get(collectionName)?.modes.find((entry) => entry.name === name)
|
|
43
|
+
return mode?.modeId ?? modeId
|
|
44
|
+
}
|
|
45
|
+
return sources.map((source) => {
|
|
46
|
+
const ids = new Map<string, string>()
|
|
47
|
+
for (const [id, key] of Object.entries(source.currentNames ?? source.names ?? {})) {
|
|
48
|
+
const current = variablesByKey.get(key)
|
|
49
|
+
if (current !== undefined) ids.set(id, current)
|
|
50
|
+
}
|
|
51
|
+
if (ids.size === 0) return source
|
|
52
|
+
const collectionOf = (id: string) => {
|
|
53
|
+
const variable = graph.variables.get(id)
|
|
54
|
+
return variable ? graph.variableCollections.get(variable.collectionId)?.name : undefined
|
|
55
|
+
}
|
|
56
|
+
const snapshot: TokenSource['snapshot'] = {}
|
|
57
|
+
for (const [oldId, values] of Object.entries(source.snapshot)) {
|
|
58
|
+
const id = ids.get(oldId) ?? oldId
|
|
59
|
+
const collection = collectionOf(id)
|
|
60
|
+
const entry: Record<string, string> = {}
|
|
61
|
+
for (const [modeId, signature] of Object.entries(values)) {
|
|
62
|
+
entry[collection ? currentModeId(collection, modeId, source.modes) : modeId] = signature
|
|
63
|
+
}
|
|
64
|
+
snapshot[id] = { ...snapshot[id], ...entry }
|
|
65
|
+
}
|
|
66
|
+
const names = Object.fromEntries(
|
|
67
|
+
Object.entries(source.names ?? {}).map(([id, key]) => [ids.get(id) ?? id, key])
|
|
68
|
+
)
|
|
69
|
+
const modes = source.modes
|
|
70
|
+
? Object.fromEntries(
|
|
71
|
+
Object.entries(source.modes).map(([collectionName, byMode]) => [
|
|
72
|
+
collectionName,
|
|
73
|
+
Object.fromEntries(
|
|
74
|
+
Object.entries(byMode).map(([modeId, name]) => [
|
|
75
|
+
currentModeId(collectionName, modeId, source.modes),
|
|
76
|
+
name
|
|
77
|
+
])
|
|
78
|
+
)
|
|
79
|
+
])
|
|
80
|
+
)
|
|
81
|
+
: undefined
|
|
82
|
+
return { ...source, snapshot, names, ...(modes ? { modes } : {}) }
|
|
83
|
+
})
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* The document node's plugin data holding `sources` in place of its links, for an edit that
|
|
88
|
+
* writes them, undoably or not, as one change to the node.
|
|
89
|
+
*/
|
|
90
|
+
export function tokenSourcesPluginData(
|
|
91
|
+
graph: SceneGraph,
|
|
92
|
+
sources: readonly TokenSource[]
|
|
93
|
+
): PluginDataEntry[] {
|
|
94
|
+
// A path that is not relative would make the reader drop the whole link; the link keeps going
|
|
95
|
+
// by its name instead.
|
|
96
|
+
const stored = sources.map(({ path, ...source }) =>
|
|
97
|
+
path !== undefined && v.is(relativeTokenPathSchema, path) ? { ...source, path } : source
|
|
98
|
+
)
|
|
99
|
+
return withPluginData(
|
|
100
|
+
graph.getNode(graph.rootId)?.pluginData ?? [],
|
|
101
|
+
tokenSources,
|
|
102
|
+
stored.length > 0 ? stored : undefined
|
|
103
|
+
)
|
|
104
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import * as v from 'valibot'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A path from the document's folder, never one that names a place on its own: no leading `/` or
|
|
5
|
+
* `\\` (POSIX roots, UNC shares), no `~` (a home folder), and no drive letter or URL scheme such
|
|
6
|
+
* as `C:` or `file:`.
|
|
7
|
+
*/
|
|
8
|
+
export const relativeTokenPathSchema = v.pipe(
|
|
9
|
+
v.string(),
|
|
10
|
+
v.nonEmpty(),
|
|
11
|
+
v.maxLength(1024),
|
|
12
|
+
v.check(
|
|
13
|
+
(path) => !/^(?:[/\\~]|[a-z][\w+.-]*:)/i.test(path),
|
|
14
|
+
'A linked path is relative to the document'
|
|
15
|
+
)
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
const tokenSourceSchema = v.object({
|
|
19
|
+
id: v.pipe(v.string(), v.nonEmpty(), v.maxLength(64)),
|
|
20
|
+
/** A stylesheet, a project folder, or W3C design token files. */
|
|
21
|
+
kind: v.picklist(['css', 'folder', 'dtcg']),
|
|
22
|
+
/** The file or folder name, for people. */
|
|
23
|
+
name: v.pipe(v.string(), v.maxLength(256)),
|
|
24
|
+
/** Where it is from the document's folder, when the document has one. */
|
|
25
|
+
path: v.optional(relativeTokenPathSchema),
|
|
26
|
+
syncedAt: v.optional(v.pipe(v.string(), v.isoTimestamp())),
|
|
27
|
+
/** What the code held at the last sync: a value signature by variable id and mode id. */
|
|
28
|
+
snapshot: v.record(v.string(), v.record(v.string(), v.string())),
|
|
29
|
+
/**
|
|
30
|
+
* The token each variable was at the last sync, `Collection/name` by variable id, so a variable
|
|
31
|
+
* deleted on the canvas is known when the code still has it.
|
|
32
|
+
*/
|
|
33
|
+
names: v.optional(v.record(v.string(), v.string())),
|
|
34
|
+
/**
|
|
35
|
+
* The names the document held when it was saved, `Collection/name` by variable id. A format that
|
|
36
|
+
* keys variables by name gives them new ids when it reads them back; this finds a renamed
|
|
37
|
+
* variable's new id while `names` keeps the token it was at the last sync.
|
|
38
|
+
*/
|
|
39
|
+
currentNames: v.optional(v.record(v.string(), v.string())),
|
|
40
|
+
/**
|
|
41
|
+
* The mode names the document holds, by collection name and mode id. A format that keys variables
|
|
42
|
+
* and modes by name gives them new ids when it reads them back, and this maps the snapshot onto
|
|
43
|
+
* those.
|
|
44
|
+
*/
|
|
45
|
+
modes: v.optional(v.record(v.string(), v.record(v.string(), v.string())))
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
export type TokenSource = v.InferOutput<typeof tokenSourceSchema>
|
|
49
|
+
|
|
50
|
+
/** The code a document's variables are linked to; entries that cannot be read are left out. */
|
|
51
|
+
export const tokenSourcesSchema: v.GenericSchema<unknown, TokenSource[]> = v.pipe(
|
|
52
|
+
v.array(v.unknown()),
|
|
53
|
+
v.transform((items) =>
|
|
54
|
+
items.flatMap((item) => {
|
|
55
|
+
const parsed = v.safeParse(tokenSourceSchema, item)
|
|
56
|
+
return parsed.success ? [parsed.output] : []
|
|
57
|
+
})
|
|
58
|
+
)
|
|
59
|
+
)
|