@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/dist/node-defaults.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { BLACK, DEFAULT_FONT_FAMILY } from "./constants.js";
|
|
2
2
|
import { normalizeEffects } from "./effects.js";
|
|
3
|
+
import { EMPTY_LIST, EMPTY_RECORD, shareEmptyNodeValues } from "./empty-values.js";
|
|
3
4
|
import { createInstanceOverrideState } from "./instances/overrides.js";
|
|
4
5
|
import { NO_LETTER_SPACING } from "./text/lengths.js";
|
|
5
6
|
//#region src/node-defaults.ts
|
|
@@ -8,18 +9,19 @@ function createDefaultSourceMetadata() {
|
|
|
8
9
|
format: null,
|
|
9
10
|
id: null,
|
|
10
11
|
orderKey: null,
|
|
11
|
-
editedFields:
|
|
12
|
+
editedFields: EMPTY_LIST,
|
|
12
13
|
fig: {
|
|
13
14
|
rawSize: null,
|
|
14
15
|
rawTransform: null,
|
|
15
|
-
rawNodeFields:
|
|
16
|
+
rawNodeFields: EMPTY_RECORD,
|
|
16
17
|
layout: null,
|
|
17
|
-
symbolOverrides:
|
|
18
|
-
componentPropAssignments:
|
|
19
|
-
derivedSymbolData:
|
|
18
|
+
symbolOverrides: EMPTY_LIST,
|
|
19
|
+
componentPropAssignments: EMPTY_LIST,
|
|
20
|
+
derivedSymbolData: EMPTY_LIST,
|
|
20
21
|
derivedSymbolDataLayoutVersion: null,
|
|
21
22
|
uniformScaleFactor: null
|
|
22
|
-
}
|
|
23
|
+
},
|
|
24
|
+
drawio: null
|
|
23
25
|
};
|
|
24
26
|
}
|
|
25
27
|
/** Where Figma aligns a new node's strokes: centered on lines and vectors, outside text, else inside. */
|
|
@@ -53,6 +55,26 @@ function defaultNodeName(type) {
|
|
|
53
55
|
function textLayerName(type, text) {
|
|
54
56
|
return text.split(/\r\n|\r|\n/).map((line) => line.trim()).filter((line) => line !== "").join(" ") || defaultNodeName(type);
|
|
55
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* The fields auto layout sets on the frame that holds it, with the value each holds when no frame
|
|
60
|
+
* lays anything out. A page holds layers; it is not one, so none of these apply to it and a page
|
|
61
|
+
* that took them would place its layers by a container nobody can see.
|
|
62
|
+
*/
|
|
63
|
+
const FRAME_LAYOUT_DEFAULTS = {
|
|
64
|
+
layoutMode: "NONE",
|
|
65
|
+
layoutDirection: "AUTO",
|
|
66
|
+
layoutWrap: "NO_WRAP",
|
|
67
|
+
primaryAxisAlign: "MIN",
|
|
68
|
+
counterAxisAlign: "MIN",
|
|
69
|
+
primaryAxisSizing: "FIXED",
|
|
70
|
+
counterAxisSizing: "FIXED",
|
|
71
|
+
itemSpacing: 0,
|
|
72
|
+
counterAxisSpacing: 0,
|
|
73
|
+
paddingTop: 0,
|
|
74
|
+
paddingRight: 0,
|
|
75
|
+
paddingBottom: 0,
|
|
76
|
+
paddingLeft: 0
|
|
77
|
+
};
|
|
56
78
|
function createDefaultNode(generateId, type, overrides = {}) {
|
|
57
79
|
const node = {
|
|
58
80
|
id: generateId(),
|
|
@@ -72,11 +94,11 @@ function createDefaultNode(generateId, type, overrides = {}) {
|
|
|
72
94
|
color: BLACK,
|
|
73
95
|
opacity: 1,
|
|
74
96
|
visible: true
|
|
75
|
-
}] :
|
|
76
|
-
strokes:
|
|
77
|
-
effects:
|
|
78
|
-
layoutGrids:
|
|
79
|
-
guides:
|
|
97
|
+
}] : EMPTY_LIST,
|
|
98
|
+
strokes: EMPTY_LIST,
|
|
99
|
+
effects: EMPTY_LIST,
|
|
100
|
+
layoutGrids: EMPTY_LIST,
|
|
101
|
+
guides: EMPTY_LIST,
|
|
80
102
|
fillStyleId: null,
|
|
81
103
|
strokeStyleId: null,
|
|
82
104
|
textStyleId: null,
|
|
@@ -94,6 +116,8 @@ function createDefaultNode(generateId, type, overrides = {}) {
|
|
|
94
116
|
visible: true,
|
|
95
117
|
locked: false,
|
|
96
118
|
clipsContent: false,
|
|
119
|
+
overflowDirection: "NONE",
|
|
120
|
+
scrollBehavior: "SCROLLS",
|
|
97
121
|
text: "",
|
|
98
122
|
fontSize: 14,
|
|
99
123
|
fontFamily: DEFAULT_FONT_FAMILY,
|
|
@@ -106,27 +130,15 @@ function createDefaultNode(generateId, type, overrides = {}) {
|
|
|
106
130
|
leadingTrim: "NONE",
|
|
107
131
|
lineHeight: null,
|
|
108
132
|
letterSpacing: NO_LETTER_SPACING,
|
|
109
|
-
|
|
110
|
-
layoutDirection: "AUTO",
|
|
111
|
-
layoutWrap: "NO_WRAP",
|
|
112
|
-
primaryAxisAlign: "MIN",
|
|
113
|
-
counterAxisAlign: "MIN",
|
|
114
|
-
primaryAxisSizing: "FIXED",
|
|
115
|
-
counterAxisSizing: "FIXED",
|
|
116
|
-
itemSpacing: 0,
|
|
117
|
-
counterAxisSpacing: 0,
|
|
118
|
-
paddingTop: 0,
|
|
119
|
-
paddingRight: 0,
|
|
120
|
-
paddingBottom: 0,
|
|
121
|
-
paddingLeft: 0,
|
|
133
|
+
...FRAME_LAYOUT_DEFAULTS,
|
|
122
134
|
blendMode: "PASS_THROUGH",
|
|
123
135
|
layoutPositioning: "AUTO",
|
|
124
136
|
layoutGrow: 0,
|
|
125
137
|
layoutAlignSelf: "AUTO",
|
|
126
138
|
vectorNetwork: null,
|
|
127
139
|
handleMirroring: "NONE",
|
|
128
|
-
fillGeometry:
|
|
129
|
-
strokeGeometry:
|
|
140
|
+
fillGeometry: EMPTY_LIST,
|
|
141
|
+
strokeGeometry: EMPTY_LIST,
|
|
130
142
|
arcData: null,
|
|
131
143
|
textAlignVertical: "TOP",
|
|
132
144
|
textAutoResize: "NONE",
|
|
@@ -134,24 +146,24 @@ function createDefaultNode(generateId, type, overrides = {}) {
|
|
|
134
146
|
textDecoration: "NONE",
|
|
135
147
|
textDecorationStyle: "SOLID",
|
|
136
148
|
textDecorationThickness: null,
|
|
137
|
-
textDecorationFills:
|
|
149
|
+
textDecorationFills: EMPTY_LIST,
|
|
138
150
|
textDecorationSkipInk: true,
|
|
139
151
|
textUnderlineOffset: null,
|
|
140
152
|
maxLines: null,
|
|
141
|
-
textParagraphs:
|
|
153
|
+
textParagraphs: EMPTY_LIST,
|
|
142
154
|
listSpacing: 0,
|
|
143
155
|
paragraphSpacing: 0,
|
|
144
156
|
paragraphIndent: 0,
|
|
145
157
|
hangingList: false,
|
|
146
|
-
styleRuns:
|
|
147
|
-
fontVariations:
|
|
158
|
+
styleRuns: EMPTY_LIST,
|
|
159
|
+
fontVariations: EMPTY_LIST,
|
|
148
160
|
opticalSizeFromFontSize: true,
|
|
149
|
-
fontFeatures:
|
|
161
|
+
fontFeatures: EMPTY_LIST,
|
|
150
162
|
horizontalConstraint: "MIN",
|
|
151
163
|
verticalConstraint: "MIN",
|
|
152
164
|
strokeCap: "NONE",
|
|
153
165
|
strokeJoin: "MITER",
|
|
154
|
-
dashPattern:
|
|
166
|
+
dashPattern: EMPTY_LIST,
|
|
155
167
|
borderTopWeight: 0,
|
|
156
168
|
borderRightWeight: 0,
|
|
157
169
|
borderBottomWeight: 0,
|
|
@@ -170,14 +182,14 @@ function createDefaultNode(generateId, type, overrides = {}) {
|
|
|
170
182
|
connectorLineType: "ELBOWED",
|
|
171
183
|
connectorStartCap: "ROUND",
|
|
172
184
|
connectorEndCap: "ARROW_LINES",
|
|
173
|
-
connectorControlPoints:
|
|
185
|
+
connectorControlPoints: EMPTY_LIST,
|
|
174
186
|
connectorCurveHandles: null,
|
|
175
187
|
connectorLabelPosition: null,
|
|
176
188
|
isMask: false,
|
|
177
189
|
maskType: "ALPHA",
|
|
178
190
|
maskIsOutline: false,
|
|
179
|
-
gridTemplateColumns:
|
|
180
|
-
gridTemplateRows:
|
|
191
|
+
gridTemplateColumns: EMPTY_LIST,
|
|
192
|
+
gridTemplateRows: EMPTY_LIST,
|
|
181
193
|
gridColumnGap: 0,
|
|
182
194
|
gridRowGap: 0,
|
|
183
195
|
gridPosition: null,
|
|
@@ -194,10 +206,10 @@ function createDefaultNode(generateId, type, overrides = {}) {
|
|
|
194
206
|
shapeTruncates: false,
|
|
195
207
|
componentId: null,
|
|
196
208
|
instanceOverrides: createInstanceOverrideState(),
|
|
197
|
-
componentPropertyDefinitions:
|
|
198
|
-
componentPropertyReferences:
|
|
199
|
-
componentPropertyAssignments:
|
|
200
|
-
componentPropertyValues:
|
|
209
|
+
componentPropertyDefinitions: EMPTY_LIST,
|
|
210
|
+
componentPropertyReferences: EMPTY_LIST,
|
|
211
|
+
componentPropertyAssignments: EMPTY_RECORD,
|
|
212
|
+
componentPropertyValues: EMPTY_RECORD,
|
|
201
213
|
componentKey: null,
|
|
202
214
|
sourceLibraryKey: null,
|
|
203
215
|
publishId: null,
|
|
@@ -209,18 +221,18 @@ function createDefaultNode(generateId, type, overrides = {}) {
|
|
|
209
221
|
isSymbolPublishable: false,
|
|
210
222
|
isExposedInstance: false,
|
|
211
223
|
symbolDescription: "",
|
|
212
|
-
symbolLinks:
|
|
213
|
-
variantPropSpecs:
|
|
214
|
-
boundVariables:
|
|
215
|
-
variableBindingScales:
|
|
216
|
-
variableAssignmentScales:
|
|
224
|
+
symbolLinks: EMPTY_LIST,
|
|
225
|
+
variantPropSpecs: EMPTY_LIST,
|
|
226
|
+
boundVariables: EMPTY_RECORD,
|
|
227
|
+
variableBindingScales: EMPTY_RECORD,
|
|
228
|
+
variableAssignmentScales: EMPTY_RECORD,
|
|
217
229
|
componentScale: 1,
|
|
218
|
-
variableModes:
|
|
219
|
-
exportSettings:
|
|
230
|
+
variableModes: EMPTY_RECORD,
|
|
231
|
+
exportSettings: EMPTY_LIST,
|
|
220
232
|
status: null,
|
|
221
|
-
pluginData:
|
|
222
|
-
pluginRelaunchData:
|
|
223
|
-
prototypeReactions:
|
|
233
|
+
pluginData: EMPTY_LIST,
|
|
234
|
+
pluginRelaunchData: EMPTY_LIST,
|
|
235
|
+
prototypeReactions: EMPTY_LIST,
|
|
224
236
|
internalOnly: false,
|
|
225
237
|
flipX: false,
|
|
226
238
|
flipY: false,
|
|
@@ -233,6 +245,7 @@ function createDefaultNode(generateId, type, overrides = {}) {
|
|
|
233
245
|
...overrides
|
|
234
246
|
};
|
|
235
247
|
node.effects = normalizeEffects(node.effects);
|
|
248
|
+
shareEmptyNodeValues(node, Object.keys(overrides));
|
|
236
249
|
return node;
|
|
237
250
|
}
|
|
238
251
|
/** Containers whose bounds follow their children and that set no coordinate space, as in Figma. */
|
|
@@ -256,6 +269,6 @@ const CONTAINER_TYPES = /* @__PURE__ */ new Set([
|
|
|
256
269
|
"INSTANCE"
|
|
257
270
|
]);
|
|
258
271
|
//#endregion
|
|
259
|
-
export { CONTAINER_TYPES, FITTED_CONTAINER_TYPES, SIDE_STROKE_TYPES, createDefaultNode, createDefaultSourceMetadata, defaultNodeName, defaultStrokeAlign, newStrokeGeometry, textLayerName };
|
|
272
|
+
export { CONTAINER_TYPES, FITTED_CONTAINER_TYPES, FRAME_LAYOUT_DEFAULTS, SIDE_STROKE_TYPES, createDefaultNode, createDefaultSourceMetadata, defaultNodeName, defaultStrokeAlign, newStrokeGeometry, textLayerName };
|
|
260
273
|
|
|
261
274
|
//# sourceMappingURL=node-defaults.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-defaults.js","names":[],"sources":["../src/node-defaults.ts"],"sourcesContent":["import {\n BLACK,\n DEFAULT_FONT_FAMILY,\n DEFAULT_STROKE_MITER_LIMIT,\n DEFAULT_STROKE_WEIGHT\n} from './constants'\nimport { normalizeEffects } from './effects'\nimport { createInstanceOverrideState } from './instances/overrides'\nimport { NO_LETTER_SPACING } from './text/lengths'\nimport type { NodeType, SceneNode, SourceMetadata } from './types'\n\nexport function createDefaultSourceMetadata(): SourceMetadata {\n return {\n format: null,\n id: null,\n orderKey: null,\n editedFields: [],\n fig: {\n rawSize: null,\n rawTransform: null,\n rawNodeFields: {},\n layout: null,\n symbolOverrides: [],\n componentPropAssignments: [],\n derivedSymbolData: [],\n derivedSymbolDataLayoutVersion: null,\n uniformScaleFactor: null\n }\n }\n}\n\n/**\n * Every SceneNode field. Nodes start with all of them, so setting any field later keeps the\n * shape every node shares; a key added after creation turns a JavaScriptCore object into a\n * slower, larger dictionary.\n */\ntype CompleteNodeFields = SceneNode & Record<keyof SceneNode, unknown>\n\n/** Where Figma aligns a new node's strokes: centered on lines and vectors, outside text, else inside. */\nexport function defaultStrokeAlign(type: NodeType): SceneNode['strokeAlign'] {\n if (type === 'LINE' || type === 'VECTOR') return 'CENTER'\n return type === 'TEXT' ? 'OUTSIDE' : 'INSIDE'\n}\n\n/**\n * Weight and alignment a stroke added to `node` takes: its first stroke's, or what the node keeps\n * with none. Adding a stroke from the panel and from the plugin API both go through here.\n */\nexport function newStrokeGeometry(\n node: Pick<SceneNode, 'strokes' | 'strokeWeight' | 'strokeAlign'>\n): Pick<SceneNode['strokes'][number], 'weight' | 'align'> {\n const first = node.strokes.at(0)\n return { weight: first?.weight ?? node.strokeWeight, align: first?.align ?? node.strokeAlign }\n}\n\n/**\n * The name a layer of `type` carries when nothing names it, as Figma writes a type's name: words\n * of a compound type apart, so a shape with text is a \"Shape with text\".\n */\nexport function defaultNodeName(type: NodeType): string {\n const words = type.toLowerCase().replaceAll('_', ' ')\n return words.charAt(0).toUpperCase() + words.slice(1)\n}\n\n/**\n * The name Figma gives a layer that follows its text: the characters trimmed, on one line, and\n * the type's own name while they hold nothing.\n */\nexport function textLayerName(type: NodeType, text: string): string {\n const lines = text\n .split(/\\r\\n|\\r|\\n/)\n .map((line) => line.trim())\n .filter((line) => line !== '')\n return lines.join(' ') || defaultNodeName(type)\n}\n\nexport function createDefaultNode(\n generateId: () => string,\n type: NodeType,\n overrides: Partial<SceneNode> = {}\n): SceneNode {\n const node = {\n id: generateId(),\n type,\n name: type.charAt(0) + type.slice(1).toLowerCase(),\n parentId: null,\n childIds: [],\n x: 0,\n y: 0,\n width: 100,\n height: 100,\n rotation: 0,\n source: createDefaultSourceMetadata(),\n derivedLayout: null,\n fills:\n type === 'TEXT' ? [{ type: 'SOLID' as const, color: BLACK, opacity: 1, visible: true }] : [],\n strokes: [],\n effects: [],\n layoutGrids: [],\n guides: [],\n fillStyleId: null,\n strokeStyleId: null,\n textStyleId: null,\n effectStyleId: null,\n gridStyleId: null,\n sharedStyleType: null,\n opacity: 1,\n cornerRadius: 0,\n topLeftRadius: 0,\n topRightRadius: 0,\n bottomRightRadius: 0,\n bottomLeftRadius: 0,\n independentCorners: false,\n cornerSmoothing: 0,\n visible: true,\n locked: false,\n clipsContent: false,\n text: '',\n fontSize: 14,\n fontFamily: DEFAULT_FONT_FAMILY,\n fontWeight: 400,\n italic: false,\n fontStyle: null,\n textAlignHorizontal: 'LEFT',\n textDirection: 'AUTO',\n textLanguage: null,\n leadingTrim: 'NONE',\n lineHeight: null,\n letterSpacing: NO_LETTER_SPACING,\n layoutMode: 'NONE',\n layoutDirection: 'AUTO',\n layoutWrap: 'NO_WRAP',\n primaryAxisAlign: 'MIN',\n counterAxisAlign: 'MIN',\n primaryAxisSizing: 'FIXED',\n counterAxisSizing: 'FIXED',\n itemSpacing: 0,\n counterAxisSpacing: 0,\n paddingTop: 0,\n paddingRight: 0,\n paddingBottom: 0,\n paddingLeft: 0,\n blendMode: 'PASS_THROUGH',\n layoutPositioning: 'AUTO',\n layoutGrow: 0,\n layoutAlignSelf: 'AUTO',\n vectorNetwork: null,\n handleMirroring: 'NONE',\n fillGeometry: [],\n strokeGeometry: [],\n arcData: null,\n textAlignVertical: 'TOP',\n textAutoResize: 'NONE',\n textCase: 'ORIGINAL',\n textDecoration: 'NONE',\n textDecorationStyle: 'SOLID',\n textDecorationThickness: null,\n textDecorationFills: [],\n textDecorationSkipInk: true,\n textUnderlineOffset: null,\n maxLines: null,\n textParagraphs: [],\n listSpacing: 0,\n paragraphSpacing: 0,\n paragraphIndent: 0,\n hangingList: false,\n styleRuns: [],\n fontVariations: [],\n opticalSizeFromFontSize: true,\n fontFeatures: [],\n horizontalConstraint: 'MIN',\n verticalConstraint: 'MIN',\n strokeCap: 'NONE',\n strokeJoin: 'MITER',\n dashPattern: [],\n borderTopWeight: 0,\n borderRightWeight: 0,\n borderBottomWeight: 0,\n borderLeftWeight: 0,\n independentStrokeWeights: false,\n strokeWeight: DEFAULT_STROKE_WEIGHT,\n strokeAlign: defaultStrokeAlign(type),\n strokeMiterLimit: DEFAULT_STROKE_MITER_LIMIT,\n minWidth: null,\n maxWidth: null,\n minHeight: null,\n maxHeight: null,\n targetAspectRatio: null,\n connectorStart: null,\n connectorEnd: null,\n connectorLineType: 'ELBOWED',\n connectorStartCap: 'ROUND',\n connectorEndCap: 'ARROW_LINES',\n connectorControlPoints: [],\n connectorCurveHandles: null,\n connectorLabelPosition: null,\n isMask: false,\n maskType: 'ALPHA',\n maskIsOutline: false,\n gridTemplateColumns: [],\n gridTemplateRows: [],\n gridColumnGap: 0,\n gridRowGap: 0,\n gridPosition: null,\n counterAxisAlignContent: 'AUTO',\n itemReverseZIndex: false,\n strokesIncludedInLayout: false,\n expanded: true,\n textTruncation: 'DISABLED',\n autoRename: true,\n pointCount: 5,\n starInnerRadius: 0.38,\n shapeWithTextType: 'SQUARE',\n shapeUserHeight: 0,\n shapeTruncates: false,\n componentId: null,\n instanceOverrides: createInstanceOverrideState(),\n componentPropertyDefinitions: [],\n componentPropertyReferences: [],\n componentPropertyAssignments: {},\n componentPropertyValues: {},\n componentKey: null,\n sourceLibraryKey: null,\n publishId: null,\n overrideKey: null,\n sharedSymbolVersion: null,\n publishedVersion: null,\n librarySource: null,\n isPublishable: false,\n isSymbolPublishable: false,\n isExposedInstance: false,\n symbolDescription: '',\n symbolLinks: [],\n variantPropSpecs: [],\n boundVariables: {},\n variableBindingScales: {},\n variableAssignmentScales: {},\n componentScale: 1,\n variableModes: {},\n exportSettings: [],\n status: null,\n pluginData: [],\n pluginRelaunchData: [],\n prototypeReactions: [],\n internalOnly: false,\n flipX: false,\n flipY: false,\n textPicture: null,\n derivedTextGlyphs: null,\n derivedTextHeight: null,\n textPathData: null,\n textPathBox: null,\n booleanOperation: undefined,\n ...overrides\n } satisfies CompleteNodeFields\n node.effects = normalizeEffects(node.effects)\n return node\n}\n\n/** Containers whose bounds follow their children and that set no coordinate space, as in Figma. */\nexport const FITTED_CONTAINER_TYPES: ReadonlySet<NodeType> = new Set<NodeType>([\n 'GROUP',\n 'BOOLEAN_OPERATION'\n])\n\n/** Layers whose stroke can take a weight per side, as Figma's `strokeTopWeight` and its siblings. */\nexport const SIDE_STROKE_TYPES: ReadonlySet<NodeType> = new Set<NodeType>([\n 'RECTANGLE',\n 'FRAME',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE'\n])\n\nexport const CONTAINER_TYPES = new Set<NodeType>([\n 'CANVAS',\n 'FRAME',\n 'GROUP',\n 'BOOLEAN_OPERATION',\n 'SECTION',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE'\n])\n"],"mappings":";;;;;AAWA,SAAgB,8BAA8C;C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c;CAC/C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"node-defaults.js","names":[],"sources":["../src/node-defaults.ts"],"sourcesContent":["import {\n BLACK,\n DEFAULT_FONT_FAMILY,\n DEFAULT_STROKE_MITER_LIMIT,\n DEFAULT_STROKE_WEIGHT\n} from './constants'\nimport { normalizeEffects } from './effects'\nimport { EMPTY_LIST, EMPTY_RECORD, shareEmptyNodeValues } from './empty-values'\nimport { createInstanceOverrideState } from './instances/overrides'\nimport { NO_LETTER_SPACING } from './text/lengths'\nimport type { NodeType, SceneNode, SourceMetadata } from './types'\n\nexport function createDefaultSourceMetadata(): SourceMetadata {\n return {\n format: null,\n id: null,\n orderKey: null,\n editedFields: EMPTY_LIST,\n fig: {\n rawSize: null,\n rawTransform: null,\n rawNodeFields: EMPTY_RECORD,\n layout: null,\n symbolOverrides: EMPTY_LIST,\n componentPropAssignments: EMPTY_LIST,\n derivedSymbolData: EMPTY_LIST,\n derivedSymbolDataLayoutVersion: null,\n uniformScaleFactor: null\n },\n drawio: null\n }\n}\n\n/**\n * Every SceneNode field. Nodes start with all of them, so setting any field later keeps the\n * shape every node shares; a key added after creation turns a JavaScriptCore object into a\n * slower, larger dictionary.\n */\ntype CompleteNodeFields = SceneNode & Record<keyof SceneNode, unknown>\n\n/** Where Figma aligns a new node's strokes: centered on lines and vectors, outside text, else inside. */\nexport function defaultStrokeAlign(type: NodeType): SceneNode['strokeAlign'] {\n if (type === 'LINE' || type === 'VECTOR') return 'CENTER'\n return type === 'TEXT' ? 'OUTSIDE' : 'INSIDE'\n}\n\n/**\n * Weight and alignment a stroke added to `node` takes: its first stroke's, or what the node keeps\n * with none. Adding a stroke from the panel and from the plugin API both go through here.\n */\nexport function newStrokeGeometry(\n node: Pick<SceneNode, 'strokes' | 'strokeWeight' | 'strokeAlign'>\n): Pick<SceneNode['strokes'][number], 'weight' | 'align'> {\n const first = node.strokes.at(0)\n return { weight: first?.weight ?? node.strokeWeight, align: first?.align ?? node.strokeAlign }\n}\n\n/**\n * The name a layer of `type` carries when nothing names it, as Figma writes a type's name: words\n * of a compound type apart, so a shape with text is a \"Shape with text\".\n */\nexport function defaultNodeName(type: NodeType): string {\n const words = type.toLowerCase().replaceAll('_', ' ')\n return words.charAt(0).toUpperCase() + words.slice(1)\n}\n\n/**\n * The name Figma gives a layer that follows its text: the characters trimmed, on one line, and\n * the type's own name while they hold nothing.\n */\nexport function textLayerName(type: NodeType, text: string): string {\n const lines = text\n .split(/\\r\\n|\\r|\\n/)\n .map((line) => line.trim())\n .filter((line) => line !== '')\n return lines.join(' ') || defaultNodeName(type)\n}\n\n/**\n * The fields auto layout sets on the frame that holds it, with the value each holds when no frame\n * lays anything out. A page holds layers; it is not one, so none of these apply to it and a page\n * that took them would place its layers by a container nobody can see.\n */\nexport const FRAME_LAYOUT_DEFAULTS = {\n layoutMode: 'NONE',\n layoutDirection: 'AUTO',\n layoutWrap: 'NO_WRAP',\n primaryAxisAlign: 'MIN',\n counterAxisAlign: 'MIN',\n primaryAxisSizing: 'FIXED',\n counterAxisSizing: 'FIXED',\n itemSpacing: 0,\n counterAxisSpacing: 0,\n paddingTop: 0,\n paddingRight: 0,\n paddingBottom: 0,\n paddingLeft: 0\n} as const satisfies Partial<SceneNode>\n\nexport function createDefaultNode(\n generateId: () => string,\n type: NodeType,\n overrides: Partial<SceneNode> = {}\n): SceneNode {\n // A literal ending in a spread is built one field at a time, and V8 keeps an object given this\n // many fields that way in dictionary mode, about 3 KB more per layer; a spread copy of a\n // finished literal keeps fast fields, in JavaScriptCore as well.\n const defaults = {\n id: generateId(),\n type,\n name: type.charAt(0) + type.slice(1).toLowerCase(),\n parentId: null,\n childIds: [],\n x: 0,\n y: 0,\n width: 100,\n height: 100,\n rotation: 0,\n source: createDefaultSourceMetadata(),\n derivedLayout: null,\n fills:\n type === 'TEXT'\n ? [{ type: 'SOLID' as const, color: BLACK, opacity: 1, visible: true }]\n : EMPTY_LIST,\n strokes: EMPTY_LIST,\n effects: EMPTY_LIST,\n layoutGrids: EMPTY_LIST,\n guides: EMPTY_LIST,\n fillStyleId: null,\n strokeStyleId: null,\n textStyleId: null,\n effectStyleId: null,\n gridStyleId: null,\n sharedStyleType: null,\n opacity: 1,\n cornerRadius: 0,\n topLeftRadius: 0,\n topRightRadius: 0,\n bottomRightRadius: 0,\n bottomLeftRadius: 0,\n independentCorners: false,\n cornerSmoothing: 0,\n visible: true,\n locked: false,\n clipsContent: false,\n overflowDirection: 'NONE',\n scrollBehavior: 'SCROLLS',\n text: '',\n fontSize: 14,\n fontFamily: DEFAULT_FONT_FAMILY,\n fontWeight: 400,\n italic: false,\n fontStyle: null,\n textAlignHorizontal: 'LEFT',\n textDirection: 'AUTO',\n textLanguage: null,\n leadingTrim: 'NONE',\n lineHeight: null,\n letterSpacing: NO_LETTER_SPACING,\n ...FRAME_LAYOUT_DEFAULTS,\n blendMode: 'PASS_THROUGH',\n layoutPositioning: 'AUTO',\n layoutGrow: 0,\n layoutAlignSelf: 'AUTO',\n vectorNetwork: null,\n handleMirroring: 'NONE',\n fillGeometry: EMPTY_LIST,\n strokeGeometry: EMPTY_LIST,\n arcData: null,\n textAlignVertical: 'TOP',\n textAutoResize: 'NONE',\n textCase: 'ORIGINAL',\n textDecoration: 'NONE',\n textDecorationStyle: 'SOLID',\n textDecorationThickness: null,\n textDecorationFills: EMPTY_LIST,\n textDecorationSkipInk: true,\n textUnderlineOffset: null,\n maxLines: null,\n textParagraphs: EMPTY_LIST,\n listSpacing: 0,\n paragraphSpacing: 0,\n paragraphIndent: 0,\n hangingList: false,\n styleRuns: EMPTY_LIST,\n fontVariations: EMPTY_LIST,\n opticalSizeFromFontSize: true,\n fontFeatures: EMPTY_LIST,\n horizontalConstraint: 'MIN',\n verticalConstraint: 'MIN',\n strokeCap: 'NONE',\n strokeJoin: 'MITER',\n dashPattern: EMPTY_LIST,\n borderTopWeight: 0,\n borderRightWeight: 0,\n borderBottomWeight: 0,\n borderLeftWeight: 0,\n independentStrokeWeights: false,\n strokeWeight: DEFAULT_STROKE_WEIGHT,\n strokeAlign: defaultStrokeAlign(type),\n strokeMiterLimit: DEFAULT_STROKE_MITER_LIMIT,\n minWidth: null,\n maxWidth: null,\n minHeight: null,\n maxHeight: null,\n targetAspectRatio: null,\n connectorStart: null,\n connectorEnd: null,\n connectorLineType: 'ELBOWED',\n connectorStartCap: 'ROUND',\n connectorEndCap: 'ARROW_LINES',\n connectorControlPoints: EMPTY_LIST,\n connectorCurveHandles: null,\n connectorLabelPosition: null,\n isMask: false,\n maskType: 'ALPHA',\n maskIsOutline: false,\n gridTemplateColumns: EMPTY_LIST,\n gridTemplateRows: EMPTY_LIST,\n gridColumnGap: 0,\n gridRowGap: 0,\n gridPosition: null,\n counterAxisAlignContent: 'AUTO',\n itemReverseZIndex: false,\n strokesIncludedInLayout: false,\n expanded: true,\n textTruncation: 'DISABLED',\n autoRename: true,\n pointCount: 5,\n starInnerRadius: 0.38,\n shapeWithTextType: 'SQUARE',\n shapeUserHeight: 0,\n shapeTruncates: false,\n componentId: null,\n instanceOverrides: createInstanceOverrideState(),\n componentPropertyDefinitions: EMPTY_LIST,\n componentPropertyReferences: EMPTY_LIST,\n componentPropertyAssignments: EMPTY_RECORD,\n componentPropertyValues: EMPTY_RECORD,\n componentKey: null,\n sourceLibraryKey: null,\n publishId: null,\n overrideKey: null,\n sharedSymbolVersion: null,\n publishedVersion: null,\n librarySource: null,\n isPublishable: false,\n isSymbolPublishable: false,\n isExposedInstance: false,\n symbolDescription: '',\n symbolLinks: EMPTY_LIST,\n variantPropSpecs: EMPTY_LIST,\n boundVariables: EMPTY_RECORD,\n variableBindingScales: EMPTY_RECORD,\n variableAssignmentScales: EMPTY_RECORD,\n componentScale: 1,\n variableModes: EMPTY_RECORD,\n exportSettings: EMPTY_LIST,\n status: null,\n pluginData: EMPTY_LIST,\n pluginRelaunchData: EMPTY_LIST,\n prototypeReactions: EMPTY_LIST,\n internalOnly: false,\n flipX: false,\n flipY: false,\n textPicture: null,\n derivedTextGlyphs: null,\n derivedTextHeight: null,\n textPathData: null,\n textPathBox: null,\n booleanOperation: undefined\n } satisfies CompleteNodeFields\n const node: SceneNode = { ...defaults, ...overrides }\n node.effects = normalizeEffects(node.effects)\n shareEmptyNodeValues(node, Object.keys(overrides))\n return node\n}\n\n/** Containers whose bounds follow their children and that set no coordinate space, as in Figma. */\nexport const FITTED_CONTAINER_TYPES: ReadonlySet<NodeType> = new Set<NodeType>([\n 'GROUP',\n 'BOOLEAN_OPERATION'\n])\n\n/** Layers whose stroke can take a weight per side, as Figma's `strokeTopWeight` and its siblings. */\nexport const SIDE_STROKE_TYPES: ReadonlySet<NodeType> = new Set<NodeType>([\n 'RECTANGLE',\n 'FRAME',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE'\n])\n\nexport const CONTAINER_TYPES = new Set<NodeType>([\n 'CANVAS',\n 'FRAME',\n 'GROUP',\n 'BOOLEAN_OPERATION',\n 'SECTION',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE'\n])\n"],"mappings":";;;;;;AAYA,SAAgB,8BAA8C;CAC5D,OAAO;EACL,QAAQ;EACR,IAAI;EACJ,UAAU;EACV,cAAc;EACd,KAAK;GACH,SAAS;GACT,cAAc;GACd,eAAe;GACf,QAAQ;GACR,iBAAiB;GACjB,0BAA0B;GAC1B,mBAAmB;GACnB,gCAAgC;GAChC,oBAAoB;EACtB;EACA,QAAQ;CACV;AACF;;AAUA,SAAgB,mBAAmB,MAA0C;CAC3E,IAAI,SAAS,UAAU,SAAS,UAAU,OAAO;CACjD,OAAO,SAAS,SAAS,YAAY;AACvC;;;;;AAMA,SAAgB,kBACd,MACwD;CACxD,MAAM,QAAQ,KAAK,QAAQ,GAAG,CAAC;CAC/B,OAAO;EAAE,QAAQ,OAAO,UAAU,KAAK;EAAc,OAAO,OAAO,SAAS,KAAK;CAAY;AAC/F;;;;;AAMA,SAAgB,gBAAgB,MAAwB;CACtD,MA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BAAkB;EAClB,eAAe;EACf,eAAe;EACf,qBAAqB;EACrB,mBAAmB;EACnB,mBAAmB;EACnB,aAAa;EACb,kBAAkB;EAClB,gBAAgB;EAChB,uBAAuB;EACvB,0BAA0B;EAC1B,gBAAgB;EAChB,eAAe;EACf,gBAAgB;EAChB,QAAQ;EACR,YAAY;EACZ,oBAAoB;EACpB,oBAAoB;EACpB,cAAc;EACd,OAAO;EACP,OAAO;EACP,aAAa;EACb,mBAAmB;EACnB,mBAAmB;EACnB,cAAc;EACd,aAAa;EACb,kBAAkB,KAAA;EAEmB,GAAG;CAAU;CACpD,KAAK,UAAU,iBAAiB,KAAK,OAAO;CAC5C,qBAAqB,MAAM,OAAO,KAAK,SAAS,CAAC;CACjD,OAAO;AACT;;AAGA,MAAa,yCAAgD,IAAI,IAAc,CAC7E,SACA,mBACF,CAAC;;AAGD,MAAa,oCAA2C,IAAI,IAAc;CACxE;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,MAAa,kCAAkB,IAAI,IAAc;CAC/C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC"}
|
|
@@ -86,6 +86,67 @@ declare const PAIRDRAW_PLUGIN_DATA: {
|
|
|
86
86
|
};
|
|
87
87
|
}[];
|
|
88
88
|
}>;
|
|
89
|
+
/** The code the document's variables are linked to, on the DOCUMENT node. */
|
|
90
|
+
tokenSources: PluginDataField<{
|
|
91
|
+
id: string;
|
|
92
|
+
kind: "css" | "folder" | "dtcg";
|
|
93
|
+
name: string;
|
|
94
|
+
path?: string | undefined;
|
|
95
|
+
syncedAt?: string | undefined;
|
|
96
|
+
snapshot: {
|
|
97
|
+
[x: string]: {
|
|
98
|
+
[x: string]: string;
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
names?: {
|
|
102
|
+
[x: string]: string;
|
|
103
|
+
} | undefined;
|
|
104
|
+
currentNames?: {
|
|
105
|
+
[x: string]: string;
|
|
106
|
+
} | undefined;
|
|
107
|
+
modes?: {
|
|
108
|
+
[x: string]: {
|
|
109
|
+
[x: string]: string;
|
|
110
|
+
};
|
|
111
|
+
} | undefined;
|
|
112
|
+
}[]>;
|
|
113
|
+
/** The design rules agents follow in the document, on the DOCUMENT node. */
|
|
114
|
+
designMemory: PluginDataField<{
|
|
115
|
+
version: 1;
|
|
116
|
+
colors: {
|
|
117
|
+
fromSystem: boolean;
|
|
118
|
+
values: string[];
|
|
119
|
+
enforce: "refuse" | "warn" | "off";
|
|
120
|
+
};
|
|
121
|
+
fonts: {
|
|
122
|
+
fromSystem: boolean;
|
|
123
|
+
values: string[];
|
|
124
|
+
enforce: "refuse" | "warn" | "off";
|
|
125
|
+
};
|
|
126
|
+
fontSizes: {
|
|
127
|
+
fromSystem: boolean;
|
|
128
|
+
values: number[];
|
|
129
|
+
enforce: "refuse" | "warn" | "off";
|
|
130
|
+
};
|
|
131
|
+
spacing: {
|
|
132
|
+
fromSystem: boolean;
|
|
133
|
+
values: number[];
|
|
134
|
+
enforce: "refuse" | "warn" | "off";
|
|
135
|
+
};
|
|
136
|
+
radius: {
|
|
137
|
+
fromSystem: boolean;
|
|
138
|
+
values: number[];
|
|
139
|
+
enforce: "refuse" | "warn" | "off";
|
|
140
|
+
};
|
|
141
|
+
decisions: {
|
|
142
|
+
id: string;
|
|
143
|
+
text: string;
|
|
144
|
+
author: "person" | "agent";
|
|
145
|
+
}[];
|
|
146
|
+
examples: {
|
|
147
|
+
nodeId: string;
|
|
148
|
+
}[];
|
|
149
|
+
}>;
|
|
89
150
|
/** How tightly the document's `.fig` data is compressed, on the DOCUMENT node. */
|
|
90
151
|
figCompression: PluginDataField<"fast" | "smaller" | "smallest">;
|
|
91
152
|
/** A layer's status, any state of the workflow; Figma's `sectionStatusInfo` knows only two. */
|
|
@@ -208,6 +269,20 @@ declare const PAIRDRAW_PLUGIN_DATA: {
|
|
|
208
269
|
preset: string;
|
|
209
270
|
refreshedAt: string;
|
|
210
271
|
}>;
|
|
272
|
+
/**
|
|
273
|
+
* On a section, that its children are variations of another layer: which one, and how that
|
|
274
|
+
* layer looked when they were made. A copy of the section is an ordinary section.
|
|
275
|
+
*/
|
|
276
|
+
variationSet: PluginDataField<{
|
|
277
|
+
version: 1;
|
|
278
|
+
originalId: string;
|
|
279
|
+
originalFingerprint?: string | undefined;
|
|
280
|
+
}>;
|
|
281
|
+
/**
|
|
282
|
+
* On a layer of a version, the main component or component set of the original it stands in
|
|
283
|
+
* for, so a pick keeps that component rather than pairing it by name.
|
|
284
|
+
*/
|
|
285
|
+
variationStandIn: PluginDataField<string>;
|
|
211
286
|
};
|
|
212
287
|
/**
|
|
213
288
|
* A node's plugin data that is part of its content, in a stable order: Pairdraw's content
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fields.d.ts","names":[],"sources":["../../src/plugin-data/fields.ts"],"mappings":";;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"fields.d.ts","names":[],"sources":["../../src/plugin-data/fields.ts"],"mappings":";;;;;;;;;;;;UAyHiB;EACf;EACA;;;UAWe;EACf,OAAO;EACP,cAAc;IAAiB;IAAa;;;;UA0B7B;EACf;EACA;EACA;EACA;EACA;IAAU,UAAU;IAAQ,OAAO;;;;;;;;cA6CxB;;iBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA0GG,kBAAkB,kBAAkB,oBAAoB"}
|
|
@@ -3,6 +3,7 @@ import { agentNotesSchema } from "../agent-notes/schema.js";
|
|
|
3
3
|
import { behaviourSchema } from "../behaviours/schema.js";
|
|
4
4
|
import { browserNodeSchema } from "../browser-node/schema.js";
|
|
5
5
|
import { commentThreadsSchema } from "../comments/schema.js";
|
|
6
|
+
import { designMemorySchema } from "../design-memory/schema.js";
|
|
6
7
|
import { clampExportQuality, isExportFormatId } from "../export-format.js";
|
|
7
8
|
import { clampExportScale } from "../export-scale.js";
|
|
8
9
|
import { FIG_COMPRESSIONS } from "../fig-compression.js";
|
|
@@ -10,7 +11,9 @@ import { iconSchema, iconTintSchema } from "../icons/schema.js";
|
|
|
10
11
|
import { scriptNodeSchema } from "../script/schema.js";
|
|
11
12
|
import { shaderPaintSchema } from "../shaders/schema.js";
|
|
12
13
|
import { nodeStatusSchema, statusWorkflowSchema } from "../statuses/schema.js";
|
|
14
|
+
import { tokenSourcesSchema } from "../token-sources/schema.js";
|
|
13
15
|
import { MODE_ATTRIBUTE_PATTERN, TOKEN_UNITS } from "../types.js";
|
|
16
|
+
import { variationSetSchema, variationStandInSchema } from "../variations/schema.js";
|
|
14
17
|
import { webCitationSchema } from "./schema.js";
|
|
15
18
|
import * as v from "valibot";
|
|
16
19
|
//#region src/plugin-data/fields.ts
|
|
@@ -165,6 +168,10 @@ const PAIRDRAW_PLUGIN_DATA = {
|
|
|
165
168
|
comments: jsonPluginDataField("comments", "bookkeeping", commentThreadsSchema),
|
|
166
169
|
/** The statuses layers can be in, on the DOCUMENT node. */
|
|
167
170
|
statuses: jsonPluginDataField("statuses", "bookkeeping", statusWorkflowSchema),
|
|
171
|
+
/** The code the document's variables are linked to, on the DOCUMENT node. */
|
|
172
|
+
tokenSources: jsonPluginDataField("tokenSources", "bookkeeping", tokenSourcesSchema),
|
|
173
|
+
/** The design rules agents follow in the document, on the DOCUMENT node. */
|
|
174
|
+
designMemory: jsonPluginDataField("designMemory", "bookkeeping", designMemorySchema),
|
|
168
175
|
/** How tightly the document's `.fig` data is compressed, on the DOCUMENT node. */
|
|
169
176
|
figCompression: textPluginDataField("figCompression", "bookkeeping", FIG_COMPRESSIONS),
|
|
170
177
|
/** A layer's status, any state of the workflow; Figma's `sectionStatusInfo` knows only two. */
|
|
@@ -197,7 +204,17 @@ const PAIRDRAW_PLUGIN_DATA = {
|
|
|
197
204
|
* A snapshot of one page: its address, viewport, and when it was refreshed. The picture is
|
|
198
205
|
* the layer's image fill. An address that is not an http or https page does not decode.
|
|
199
206
|
*/
|
|
200
|
-
browserNode: jsonPluginDataField("browserNode", "content", browserNodeSchema)
|
|
207
|
+
browserNode: jsonPluginDataField("browserNode", "content", browserNodeSchema),
|
|
208
|
+
/**
|
|
209
|
+
* On a section, that its children are variations of another layer: which one, and how that
|
|
210
|
+
* layer looked when they were made. A copy of the section is an ordinary section.
|
|
211
|
+
*/
|
|
212
|
+
variationSet: jsonPluginDataField("variationSet", "bookkeeping", variationSetSchema),
|
|
213
|
+
/**
|
|
214
|
+
* On a layer of a version, the main component or component set of the original it stands in
|
|
215
|
+
* for, so a pick keeps that component rather than pairing it by name.
|
|
216
|
+
*/
|
|
217
|
+
variationStandIn: jsonPluginDataField("variationStandIn", "bookkeeping", variationStandInSchema)
|
|
201
218
|
};
|
|
202
219
|
const NOT_CONTENT = Object.values(PAIRDRAW_PLUGIN_DATA).filter((field) => field.role !== "content");
|
|
203
220
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fields.js","names":[],"sources":["../../src/plugin-data/fields.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport { agentNotesSchema } from '../agent-notes/schema'\nimport { behaviourSchema } from '../behaviours/schema'\nimport { browserNodeSchema } from '../browser-node/schema'\nimport type { OkHCLPayload } from '../color/okhcl'\nimport { commentThreadsSchema } from '../comments/schema'\nimport { clampExportQuality, isExportFormatId, type ExportFormatId } from '../export-format'\nimport { clampExportScale } from '../export-scale'\nimport { FIG_COMPRESSIONS } from '../fig-compression'\nimport { iconSchema, iconTintSchema } from '../icons/schema'\nimport type { Color, Rect, Vector } from '../primitives'\nimport { scriptNodeSchema } from '../script/schema'\nimport { shaderPaintSchema } from '../shaders/schema'\nimport { nodeStatusSchema, statusWorkflowSchema } from '../statuses/schema'\nimport {\n MODE_ATTRIBUTE_PATTERN,\n TOKEN_UNITS,\n type EnabledLibraryBinding,\n type ExportSetting,\n type LayoutDirection,\n type LibraryAssetSource,\n type PluginDataEntry,\n type SourceLibraryPublication,\n type TextDirection,\n type TokenUnit\n} from '../types'\nimport {\n jsonPluginDataField,\n textPluginDataField,\n withoutPluginData,\n type PluginDataKey\n} from './field'\nimport { webCitationSchema } from './schema'\n\nconst DIRECTIONS = ['AUTO', 'LTR', 'RTL'] as const satisfies readonly (\n | TextDirection\n | LayoutDirection\n)[]\n\nconst textPathBoxSchema: v.GenericSchema<unknown, Rect> = v.pipe(\n v.object({ x: v.number(), y: v.number(), width: v.number(), height: v.number() }),\n v.check(\n ({ x, y, width, height }) => Number.isFinite(x + y + width + height) && width > 0 && height > 0\n )\n)\n\n/** String-valued entries of a JSON object; other entries are dropped, not rejected. */\nconst boundVariablesSchema = v.pipe(\n v.custom<Record<string, unknown>>(\n (value) => typeof value === 'object' && value !== null && !Array.isArray(value)\n ),\n v.transform((value) =>\n Object.fromEntries(\n Object.entries(value).filter(\n (entry): entry is [string, string] => typeof entry[1] === 'string'\n )\n )\n )\n)\n\n/** Every entry must be valid, or the whole value is ignored in favour of native settings. */\nconst exportSettingsSchema: v.GenericSchema<unknown, ExportSetting[]> = v.array(\n v.pipe(\n v.object({\n scale: v.pipe(v.number(), v.finite()),\n format: v.custom<ExportFormatId>(isExportFormatId),\n quality: v.optional(v.pipe(v.number(), v.finite()))\n }),\n // Clamp at the file boundary: imported plugin data may carry a scale the UI never produces.\n v.transform(({ scale, format, quality }) => ({\n scale: clampExportScale(scale),\n format,\n ...(quality === undefined ? {} : { quality: clampExportQuality(quality) })\n }))\n )\n)\n\nconst librarySourceSchema: v.GenericSchema<unknown, LibraryAssetSource> = v.pipe(\n v.object({\n identity: v.object({ libraryId: v.string(), assetKey: v.string(), revisionId: v.string() }),\n sourceNodeId: v.optional(v.unknown()),\n readOnly: v.optional(v.unknown())\n }),\n v.transform(({ identity, sourceNodeId, readOnly }) => ({\n identity,\n sourceNodeId: typeof sourceNodeId === 'string' ? sourceNodeId : null,\n readOnly: readOnly === true\n }))\n)\n\nconst enabledLibrarySchema = v.object({\n libraryId: v.string(),\n revisionId: v.string(),\n enabled: v.optional(v.unknown())\n})\n\n/** Invalid entries are skipped one by one, so one bad binding keeps the others. */\nconst enabledLibrariesSchema: v.GenericSchema<unknown, EnabledLibraryBinding[]> = v.pipe(\n v.array(v.unknown()),\n v.transform((items) =>\n items.flatMap((item) => {\n const parsed = v.safeParse(enabledLibrarySchema, item)\n if (!parsed.success) return []\n const { libraryId, revisionId, enabled } = parsed.output\n return [{ libraryId, revisionId, enabled: enabled === true }]\n })\n )\n)\n\n// Shape only. Whether a string is valid CSS is checked where it is written into a stylesheet.\nconst cssTextSchema = v.pipe(v.string(), v.trim(), v.nonEmpty(), v.maxLength(1000))\n\n/**\n * A layer an instance shows in place of one of its component's layers, which Figma has no\n * override for: the GUID path of the component layer it replaces, as an override's `guidPath`\n * spells it, and the replacement's own records as a Base64 Kiwi `NODE_CHANGES` message.\n */\nexport interface StoredReplacedLayer {\n path: string[]\n records: string\n}\n\nconst replacedLayersSchema: v.GenericSchema<unknown, StoredReplacedLayer[]> = v.array(\n v.object({\n path: v.pipe(v.array(v.pipe(v.string(), v.regex(/^\\d+:\\d+$/))), v.minLength(1)),\n records: v.pipe(v.string(), v.nonEmpty())\n })\n)\n\n/** Token fields Figma has no slot for, with mode ids as the file spells them. */\nexport interface StoredToken {\n unit?: TokenUnit\n expressions?: Record<string, { css: string; resolved?: number }>\n}\n\nconst tokenSchema: v.GenericSchema<unknown, StoredToken> = v.object({\n unit: v.optional(v.picklist(TOKEN_UNITS)),\n expressions: v.optional(\n v.record(\n v.string(),\n v.object({ css: cssTextSchema, resolved: v.optional(v.pipe(v.number(), v.finite())) })\n )\n )\n})\n\nconst okhclSchema: v.GenericSchema<unknown, OkHCLPayload> = v.object({\n version: v.literal(1),\n kind: v.picklist(['fill', 'stroke']),\n index: v.number(),\n color: v.object({\n h: v.number(),\n c: v.number(),\n l: v.number(),\n a: v.fallback(v.optional(v.number()), undefined)\n })\n})\n\n/** A mesh paint Figma's format has no type for, stored beside its solid fallback paint. */\nexport interface StoredMeshFill {\n kind: 'fill' | 'stroke'\n index: number\n columns: number\n rows: number\n points: { position: Vector; color: Color }[]\n}\n\n/** Invalid entries are skipped one by one, so one bad mesh keeps the others. */\nconst meshFillsSchema: v.GenericSchema<unknown, StoredMeshFill[]> = v.pipe(\n v.array(v.unknown()),\n v.transform((items) =>\n items.flatMap((item) => {\n const parsed = v.safeParse(\n v.object({\n kind: v.picklist(['fill', 'stroke']),\n index: v.pipe(v.number(), v.integer(), v.minValue(0)),\n columns: v.pipe(v.number(), v.integer(), v.minValue(1)),\n rows: v.pipe(v.number(), v.integer(), v.minValue(1)),\n points: v.array(\n v.object({\n position: v.object({ x: v.number(), y: v.number() }),\n color: v.object({ r: v.number(), g: v.number(), b: v.number(), a: v.number() })\n })\n )\n }),\n item\n )\n if (!parsed.success) return []\n const { kind, index, columns, rows, points } = parsed.output\n if (points.length !== (columns + 1) * (rows + 1)) return []\n return [{ kind, index, columns, rows, points }]\n })\n )\n)\n\nconst sourceLibraryPublicationSchema: v.GenericSchema<unknown, SourceLibraryPublication> = v.object(\n {\n libraryId: v.string(),\n revisionId: v.string(),\n name: v.string(),\n catalogSource: v.optional(v.string())\n }\n)\n\n/**\n * Every plugin-data entry Pairdraw writes under {@link PAIRDRAW_PLUGIN_ID}: state Figma's\n * format has no field for. Add a key here, never as a string elsewhere, so reading and writing\n * it share one schema.\n */\nexport const PAIRDRAW_PLUGIN_DATA = {\n /** A text node's direction, on TEXT nodes. */\n textDirection: textPluginDataField('textDirection', 'format', DIRECTIONS),\n /** An auto-layout frame's direction. */\n layoutDirection: textPluginDataField('layoutDirection', 'format', DIRECTIONS),\n /**\n * A primary axis alignment Figma has no mode for, on auto-layout frames; the record keeps\n * Figma's space between, and a frame whose record says otherwise was changed in Figma.\n */\n primaryAxisAlign: textPluginDataField('primaryAxisAlign', 'format', ['SPACE_AROUND']),\n /** Marks a component set Figma would read as a plain frame, and a script node Figma has no type for. */\n nodeType: textPluginDataField('nodeType', 'format', ['COMPONENT_SET', 'SCRIPT']),\n /** Variable bindings by field path, including those Figma cannot store natively. */\n boundVariables: jsonPluginDataField('boundVariables', 'format', boundVariablesSchema),\n exportSettings: jsonPluginDataField('exportSettings', 'format', exportSettingsSchema),\n /** Layers an instance shows in place of its component's, on the instance's own record. */\n replacedLayers: jsonPluginDataField('replacedLayers', 'format', replacedLayersSchema),\n /** The node-local rect a TEXT_PATH layout maps onto, which Kiwi has no field for. */\n textPathBox: jsonPluginDataField('textPathBox', 'format', textPathBoxSchema),\n /** The library asset a node was inserted from. */\n librarySource: jsonPluginDataField('librarySource', 'bookkeeping', librarySourceSchema),\n /**\n * The document root's id, on the DOCUMENT node, whose own GUID is always Figma's `0:0`; the\n * root keeps it across a save as every layer keeps its GUID.\n */\n documentId: jsonPluginDataField(\n 'documentId',\n 'bookkeeping',\n v.pipe(v.string(), v.nonEmpty(), v.maxLength(64))\n ),\n /** Libraries enabled for the document, on the DOCUMENT node. */\n enabledLibraries: jsonPluginDataField('enabledLibraries', 'bookkeeping', enabledLibrariesSchema),\n /** The library this document publishes as, on the DOCUMENT node. */\n sourceLibraryPublication: jsonPluginDataField(\n 'sourceLibraryPublication',\n 'bookkeeping',\n sourceLibraryPublicationSchema\n ),\n /** Canvas comment threads, deleted ones included, on the DOCUMENT node. */\n comments: jsonPluginDataField('comments', 'bookkeeping', commentThreadsSchema),\n /** The statuses layers can be in, on the DOCUMENT node. */\n statuses: jsonPluginDataField('statuses', 'bookkeeping', statusWorkflowSchema),\n /** How tightly the document's `.fig` data is compressed, on the DOCUMENT node. */\n figCompression: textPluginDataField('figCompression', 'bookkeeping', FIG_COMPRESSIONS),\n /** A layer's status, any state of the workflow; Figma's `sectionStatusInfo` knows only two. */\n status: jsonPluginDataField('status', 'format', nodeStatusSchema),\n /** Unit and CSS expressions, on each VARIABLE. */\n token: jsonPluginDataField('token', 'format', tokenSchema),\n /** Mode conditions by mode id, on each VARIABLE_SET. */\n modeConditions: jsonPluginDataField(\n 'modeConditions',\n 'format',\n v.record(v.string(), cssTextSchema)\n ),\n /** The attribute that switches manual modes, on each VARIABLE_SET. */\n modeAttribute: jsonPluginDataField(\n 'modeAttribute',\n 'format',\n v.pipe(v.string(), v.trim(), v.maxLength(100), v.regex(MODE_ATTRIBUTE_PATTERN))\n ),\n /** One entry per paint picked in OkHCL, so the picker reopens on the same coordinates. */\n okhcl: jsonPluginDataField('okhcl', 'content', okhclSchema),\n /** How a main component or component set behaves as a control in preview. */\n behaviour: jsonPluginDataField('behaviour', 'content', behaviourSchema),\n /** The icon a frame draws, such as `lucide:home`, on the frame its paths are in. */\n icon: jsonPluginDataField('icon', 'content', iconSchema),\n /** Which of an icon path's paints its icon's color sets, on each path the source drew in it. */\n iconTint: jsonPluginDataField('iconTint', 'content', iconTintSchema),\n /** One entry per paint that draws a shader, matched to its image paint by the frame's hash. */\n shader: jsonPluginDataField('shader', 'content', shaderPaintSchema),\n /** A script node's source and its `@input` values, on the SCRIPT node. */\n script: jsonPluginDataField('script', 'content', scriptNodeSchema),\n /** One entry per mesh paint, beside the solid fallback its record carries. */\n meshFills: jsonPluginDataField('meshFills', 'format', meshFillsSchema),\n /** Notes a person left on a layer for agents: what it means or does, and a request about it. */\n agentNotes: jsonPluginDataField('agentNotes', 'content', agentNotesSchema),\n /** A page a sticky cites: its URL, title, quote, and the time the page was read. */\n webCitation: jsonPluginDataField('webCitation', 'content', webCitationSchema),\n /**\n * A snapshot of one page: its address, viewport, and when it was refreshed. The picture is\n * the layer's image fill. An address that is not an http or https page does not decode.\n */\n browserNode: jsonPluginDataField('browserNode', 'content', browserNodeSchema)\n} satisfies Record<string, PluginDataKey>\n\nconst NOT_CONTENT = Object.values(PAIRDRAW_PLUGIN_DATA).filter((field) => field.role !== 'content')\n\n/**\n * A node's plugin data that is part of its content, in a stable order: Pairdraw's content\n * fields and every other plugin's entries, which the node carries wherever it goes. Format\n * copies of node fields and bookkeeping are left out.\n */\nexport function contentPluginData(entries: readonly PluginDataEntry[]): PluginDataEntry[] {\n return withoutPluginData(entries, NOT_CONTENT).sort(\n (a, b) => a.pluginId.localeCompare(b.pluginId) || a.key.localeCompare(b.key)\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAmCA,MAAM,aAAa;CAAC;CAAQ;CAAO;AAAK;AAKxC,MAAM,oBAAoD,EAAE,KAC1D,EAAE,OAAO;CAAE,GAAG,EAAE,OAAO;CAAG,GAAG,EAAE,OAAO;CAAG,OAAO,EAAE,OAAO;CAAG,QAAQ,EAAE,OAAO;AAAE,CAAC,GAChF,EAAE,OACC,EAAE,GAAG,GAAG,OAAO,aAAa,OAAO,SAAS,IAAI,IAAI,QAAQ,MAAM,KAAK,QAAQ,KAAK,SAAS,CAChG,CACF;;AAGA,MAAM,uBAAuB,EAAE,KAC7B,EAAE,QACC,UAAU,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK,CAChF,GACA,EAAE,WAAW,UACX,OAAO,YACL,OAAO,QAAQ,KAAK,CAAC,CAAC,QACnB,UAAqC,OAAO,MAAM,OAAO,QAC5D,CACF,CACF,CACF;;AAGA,MAAM,uBAAkE,EAAE,MACxE,EAAE,KACA,EAAE,OAAO;CACP,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,OAAO,CAAC;CACpC,QAAQ,EAAE,OAAuB,gBAAgB;CACjD,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,OAAO,CAAC,CAAC;AACpD,CAAC,GAED,EAAE,WAAW,EAAE,OAAO,QAAQ,eAAe;CAC3C,OAAO,iBAAiB,KAAK;CAC7B;CACA,GAAI,YAAY,KAAA,IAAY,CAAC,IAAI,EAAE,SAAS,mBAAmB,OAAO,EAAE;AAC1E,EAAE,CACJ,CACF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AoB,kBAAkB,eAAe,gBAAgB;;CAErF,QAAQ,oBAAoB,UAAU,UAAU,gBAAgB;;CAEhE,OAAO,oBAAoB,SAAS,UAAU,WAAW;;CAEzD,gBAAgB,oBACd,kBACA,UACA,EAAE,OAAO,EAAE,OAAO,GAAG,aAAa,CACpC;;CAEA,eAAe,oBACb,iBACA,UACA,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,KAAK,GAAG,EAAE,UAAU,GAAG,GAAG,EAAE,MAAM,sBAAsB,CAAC,CAChF;;CAEA,OAAO,oBAAoB,SAAS,WAAW,WAAW;;CAE1D,WAAW,oBAAoB,aAAa,WAAW,eAAe;;CAEtE,MAAM,oBAAoB,QAAQ,WAAW,UAAU;;CAEvD,UAAU,oBAAoB,YAAY,WAAW,cAAc;;CAEnE,QAAQ,oBAAoB,UAAU,WAAW,iBAAiB;;CAElE,QAAQ,oBAAoB,UAAU,WAAW,gBAAgB;;CAEjE,WAAW,oBAAoB,aAAa,UAAU,eAAe;;CAErE,YAAY,oBAAoB,cAAc,WAAW,gBAAgB;;CAEzE,aAAa,oBAAoB,eAAe,WAAW,iBAAiB;;;;;CAK5E,aAAa,oBAAoB,eAAe,WAAW,iBAAiB;AAC9E;AAEA,MAAM,cAAc,OAAO,OAAO,oBAAoB,CAAC,CAAC,QAAQ,UAAU,MAAM,SAAS,SAAS;;;;;;AAOlG,SAAgB,kBAAkB,SAAwD;CACxF,OAAO,kBAAkB,SAAS,WAAW,CAAC,CAAC,MAC5C,GAAG,MAAM,EAAE,SAAS,cAAc,EAAE,QAAQ,KAAK,EAAE,IAAI,cAAc,EAAE,GAAG,CAC7E;AACF"}
|
|
1
|
+
{"version":3,"file":"fields.js","names":[],"sources":["../../src/plugin-data/fields.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport { agentNotesSchema } from '../agent-notes/schema'\nimport { behaviourSchema } from '../behaviours/schema'\nimport { browserNodeSchema } from '../browser-node/schema'\nimport type { OkHCLPayload } from '../color/okhcl'\nimport { commentThreadsSchema } from '../comments/schema'\nimport { designMemorySchema } from '../design-memory/schema'\nimport { clampExportQuality, isExportFormatId, type ExportFormatId } from '../export-format'\nimport { clampExportScale } from '../export-scale'\nimport { FIG_COMPRESSIONS } from '../fig-compression'\nimport { iconSchema, iconTintSchema } from '../icons/schema'\nimport type { Color, Rect, Vector } from '../primitives'\nimport { scriptNodeSchema } from '../script/schema'\nimport { shaderPaintSchema } from '../shaders/schema'\nimport { nodeStatusSchema, statusWorkflowSchema } from '../statuses/schema'\nimport { tokenSourcesSchema } from '../token-sources/schema'\nimport {\n MODE_ATTRIBUTE_PATTERN,\n TOKEN_UNITS,\n type EnabledLibraryBinding,\n type ExportSetting,\n type LayoutDirection,\n type LibraryAssetSource,\n type PluginDataEntry,\n type SourceLibraryPublication,\n type TextDirection,\n type TokenUnit\n} from '../types'\nimport { variationSetSchema, variationStandInSchema } from '../variations/schema'\nimport {\n jsonPluginDataField,\n textPluginDataField,\n withoutPluginData,\n type PluginDataKey\n} from './field'\nimport { webCitationSchema } from './schema'\n\nconst DIRECTIONS = ['AUTO', 'LTR', 'RTL'] as const satisfies readonly (\n | TextDirection\n | LayoutDirection\n)[]\n\nconst textPathBoxSchema: v.GenericSchema<unknown, Rect> = v.pipe(\n v.object({ x: v.number(), y: v.number(), width: v.number(), height: v.number() }),\n v.check(\n ({ x, y, width, height }) => Number.isFinite(x + y + width + height) && width > 0 && height > 0\n )\n)\n\n/** String-valued entries of a JSON object; other entries are dropped, not rejected. */\nconst boundVariablesSchema = v.pipe(\n v.custom<Record<string, unknown>>(\n (value) => typeof value === 'object' && value !== null && !Array.isArray(value)\n ),\n v.transform((value) =>\n Object.fromEntries(\n Object.entries(value).filter(\n (entry): entry is [string, string] => typeof entry[1] === 'string'\n )\n )\n )\n)\n\n/** Every entry must be valid, or the whole value is ignored in favour of native settings. */\nconst exportSettingsSchema: v.GenericSchema<unknown, ExportSetting[]> = v.array(\n v.pipe(\n v.object({\n scale: v.pipe(v.number(), v.finite()),\n format: v.custom<ExportFormatId>(isExportFormatId),\n quality: v.optional(v.pipe(v.number(), v.finite()))\n }),\n // Clamp at the file boundary: imported plugin data may carry a scale the UI never produces.\n v.transform(({ scale, format, quality }) => ({\n scale: clampExportScale(scale),\n format,\n ...(quality === undefined ? {} : { quality: clampExportQuality(quality) })\n }))\n )\n)\n\nconst librarySourceSchema: v.GenericSchema<unknown, LibraryAssetSource> = v.pipe(\n v.object({\n identity: v.object({ libraryId: v.string(), assetKey: v.string(), revisionId: v.string() }),\n sourceNodeId: v.optional(v.unknown()),\n readOnly: v.optional(v.unknown())\n }),\n v.transform(({ identity, sourceNodeId, readOnly }) => ({\n identity,\n sourceNodeId: typeof sourceNodeId === 'string' ? sourceNodeId : null,\n readOnly: readOnly === true\n }))\n)\n\nconst enabledLibrarySchema = v.object({\n libraryId: v.string(),\n revisionId: v.string(),\n enabled: v.optional(v.unknown())\n})\n\n/** Invalid entries are skipped one by one, so one bad binding keeps the others. */\nconst enabledLibrariesSchema: v.GenericSchema<unknown, EnabledLibraryBinding[]> = v.pipe(\n v.array(v.unknown()),\n v.transform((items) =>\n items.flatMap((item) => {\n const parsed = v.safeParse(enabledLibrarySchema, item)\n if (!parsed.success) return []\n const { libraryId, revisionId, enabled } = parsed.output\n return [{ libraryId, revisionId, enabled: enabled === true }]\n })\n )\n)\n\n// Shape only. Whether a string is valid CSS is checked where it is written into a stylesheet.\nconst cssTextSchema = v.pipe(v.string(), v.trim(), v.nonEmpty(), v.maxLength(1000))\n\n/**\n * A layer an instance shows in place of one of its component's layers, which Figma has no\n * override for: the GUID path of the component layer it replaces, as an override's `guidPath`\n * spells it, and the replacement's own records as a Base64 Kiwi `NODE_CHANGES` message.\n */\nexport interface StoredReplacedLayer {\n path: string[]\n records: string\n}\n\nconst replacedLayersSchema: v.GenericSchema<unknown, StoredReplacedLayer[]> = v.array(\n v.object({\n path: v.pipe(v.array(v.pipe(v.string(), v.regex(/^\\d+:\\d+$/))), v.minLength(1)),\n records: v.pipe(v.string(), v.nonEmpty())\n })\n)\n\n/** Token fields Figma has no slot for, with mode ids as the file spells them. */\nexport interface StoredToken {\n unit?: TokenUnit\n expressions?: Record<string, { css: string; resolved?: number }>\n}\n\nconst tokenSchema: v.GenericSchema<unknown, StoredToken> = v.object({\n unit: v.optional(v.picklist(TOKEN_UNITS)),\n expressions: v.optional(\n v.record(\n v.string(),\n v.object({ css: cssTextSchema, resolved: v.optional(v.pipe(v.number(), v.finite())) })\n )\n )\n})\n\nconst okhclSchema: v.GenericSchema<unknown, OkHCLPayload> = v.object({\n version: v.literal(1),\n kind: v.picklist(['fill', 'stroke']),\n index: v.number(),\n color: v.object({\n h: v.number(),\n c: v.number(),\n l: v.number(),\n a: v.fallback(v.optional(v.number()), undefined)\n })\n})\n\n/** A mesh paint Figma's format has no type for, stored beside its solid fallback paint. */\nexport interface StoredMeshFill {\n kind: 'fill' | 'stroke'\n index: number\n columns: number\n rows: number\n points: { position: Vector; color: Color }[]\n}\n\n/** Invalid entries are skipped one by one, so one bad mesh keeps the others. */\nconst meshFillsSchema: v.GenericSchema<unknown, StoredMeshFill[]> = v.pipe(\n v.array(v.unknown()),\n v.transform((items) =>\n items.flatMap((item) => {\n const parsed = v.safeParse(\n v.object({\n kind: v.picklist(['fill', 'stroke']),\n index: v.pipe(v.number(), v.integer(), v.minValue(0)),\n columns: v.pipe(v.number(), v.integer(), v.minValue(1)),\n rows: v.pipe(v.number(), v.integer(), v.minValue(1)),\n points: v.array(\n v.object({\n position: v.object({ x: v.number(), y: v.number() }),\n color: v.object({ r: v.number(), g: v.number(), b: v.number(), a: v.number() })\n })\n )\n }),\n item\n )\n if (!parsed.success) return []\n const { kind, index, columns, rows, points } = parsed.output\n if (points.length !== (columns + 1) * (rows + 1)) return []\n return [{ kind, index, columns, rows, points }]\n })\n )\n)\n\nconst sourceLibraryPublicationSchema: v.GenericSchema<unknown, SourceLibraryPublication> = v.object(\n {\n libraryId: v.string(),\n revisionId: v.string(),\n name: v.string(),\n catalogSource: v.optional(v.string())\n }\n)\n\n/**\n * Every plugin-data entry Pairdraw writes under {@link PAIRDRAW_PLUGIN_ID}: state Figma's\n * format has no field for. Add a key here, never as a string elsewhere, so reading and writing\n * it share one schema.\n */\nexport const PAIRDRAW_PLUGIN_DATA = {\n /** A text node's direction, on TEXT nodes. */\n textDirection: textPluginDataField('textDirection', 'format', DIRECTIONS),\n /** An auto-layout frame's direction. */\n layoutDirection: textPluginDataField('layoutDirection', 'format', DIRECTIONS),\n /**\n * A primary axis alignment Figma has no mode for, on auto-layout frames; the record keeps\n * Figma's space between, and a frame whose record says otherwise was changed in Figma.\n */\n primaryAxisAlign: textPluginDataField('primaryAxisAlign', 'format', ['SPACE_AROUND']),\n /** Marks a component set Figma would read as a plain frame, and a script node Figma has no type for. */\n nodeType: textPluginDataField('nodeType', 'format', ['COMPONENT_SET', 'SCRIPT']),\n /** Variable bindings by field path, including those Figma cannot store natively. */\n boundVariables: jsonPluginDataField('boundVariables', 'format', boundVariablesSchema),\n exportSettings: jsonPluginDataField('exportSettings', 'format', exportSettingsSchema),\n /** Layers an instance shows in place of its component's, on the instance's own record. */\n replacedLayers: jsonPluginDataField('replacedLayers', 'format', replacedLayersSchema),\n /** The node-local rect a TEXT_PATH layout maps onto, which Kiwi has no field for. */\n textPathBox: jsonPluginDataField('textPathBox', 'format', textPathBoxSchema),\n /** The library asset a node was inserted from. */\n librarySource: jsonPluginDataField('librarySource', 'bookkeeping', librarySourceSchema),\n /**\n * The document root's id, on the DOCUMENT node, whose own GUID is always Figma's `0:0`; the\n * root keeps it across a save as every layer keeps its GUID.\n */\n documentId: jsonPluginDataField(\n 'documentId',\n 'bookkeeping',\n v.pipe(v.string(), v.nonEmpty(), v.maxLength(64))\n ),\n /** Libraries enabled for the document, on the DOCUMENT node. */\n enabledLibraries: jsonPluginDataField('enabledLibraries', 'bookkeeping', enabledLibrariesSchema),\n /** The library this document publishes as, on the DOCUMENT node. */\n sourceLibraryPublication: jsonPluginDataField(\n 'sourceLibraryPublication',\n 'bookkeeping',\n sourceLibraryPublicationSchema\n ),\n /** Canvas comment threads, deleted ones included, on the DOCUMENT node. */\n comments: jsonPluginDataField('comments', 'bookkeeping', commentThreadsSchema),\n /** The statuses layers can be in, on the DOCUMENT node. */\n statuses: jsonPluginDataField('statuses', 'bookkeeping', statusWorkflowSchema),\n /** The code the document's variables are linked to, on the DOCUMENT node. */\n tokenSources: jsonPluginDataField('tokenSources', 'bookkeeping', tokenSourcesSchema),\n /** The design rules agents follow in the document, on the DOCUMENT node. */\n designMemory: jsonPluginDataField('designMemory', 'bookkeeping', designMemorySchema),\n /** How tightly the document's `.fig` data is compressed, on the DOCUMENT node. */\n figCompression: textPluginDataField('figCompression', 'bookkeeping', FIG_COMPRESSIONS),\n /** A layer's status, any state of the workflow; Figma's `sectionStatusInfo` knows only two. */\n status: jsonPluginDataField('status', 'format', nodeStatusSchema),\n /** Unit and CSS expressions, on each VARIABLE. */\n token: jsonPluginDataField('token', 'format', tokenSchema),\n /** Mode conditions by mode id, on each VARIABLE_SET. */\n modeConditions: jsonPluginDataField(\n 'modeConditions',\n 'format',\n v.record(v.string(), cssTextSchema)\n ),\n /** The attribute that switches manual modes, on each VARIABLE_SET. */\n modeAttribute: jsonPluginDataField(\n 'modeAttribute',\n 'format',\n v.pipe(v.string(), v.trim(), v.maxLength(100), v.regex(MODE_ATTRIBUTE_PATTERN))\n ),\n /** One entry per paint picked in OkHCL, so the picker reopens on the same coordinates. */\n okhcl: jsonPluginDataField('okhcl', 'content', okhclSchema),\n /** How a main component or component set behaves as a control in preview. */\n behaviour: jsonPluginDataField('behaviour', 'content', behaviourSchema),\n /** The icon a frame draws, such as `lucide:home`, on the frame its paths are in. */\n icon: jsonPluginDataField('icon', 'content', iconSchema),\n /** Which of an icon path's paints its icon's color sets, on each path the source drew in it. */\n iconTint: jsonPluginDataField('iconTint', 'content', iconTintSchema),\n /** One entry per paint that draws a shader, matched to its image paint by the frame's hash. */\n shader: jsonPluginDataField('shader', 'content', shaderPaintSchema),\n /** A script node's source and its `@input` values, on the SCRIPT node. */\n script: jsonPluginDataField('script', 'content', scriptNodeSchema),\n /** One entry per mesh paint, beside the solid fallback its record carries. */\n meshFills: jsonPluginDataField('meshFills', 'format', meshFillsSchema),\n /** Notes a person left on a layer for agents: what it means or does, and a request about it. */\n agentNotes: jsonPluginDataField('agentNotes', 'content', agentNotesSchema),\n /** A page a sticky cites: its URL, title, quote, and the time the page was read. */\n webCitation: jsonPluginDataField('webCitation', 'content', webCitationSchema),\n /**\n * A snapshot of one page: its address, viewport, and when it was refreshed. The picture is\n * the layer's image fill. An address that is not an http or https page does not decode.\n */\n browserNode: jsonPluginDataField('browserNode', 'content', browserNodeSchema),\n /**\n * On a section, that its children are variations of another layer: which one, and how that\n * layer looked when they were made. A copy of the section is an ordinary section.\n */\n variationSet: jsonPluginDataField('variationSet', 'bookkeeping', variationSetSchema),\n /**\n * On a layer of a version, the main component or component set of the original it stands in\n * for, so a pick keeps that component rather than pairing it by name.\n */\n variationStandIn: jsonPluginDataField('variationStandIn', 'bookkeeping', variationStandInSchema)\n} satisfies Record<string, PluginDataKey>\n\nconst NOT_CONTENT = Object.values(PAIRDRAW_PLUGIN_DATA).filter((field) => field.role !== 'content')\n\n/**\n * A node's plugin data that is part of its content, in a stable order: Pairdraw's content\n * fields and every other plugin's entries, which the node carries wherever it goes. Format\n * copies of node fields and bookkeeping are left out.\n */\nexport function contentPluginData(entries: readonly PluginDataEntry[]): PluginDataEntry[] {\n return withoutPluginData(entries, NOT_CONTENT).sort(\n (a, b) => a.pluginId.localeCompare(b.pluginId) || a.key.localeCompare(b.key)\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAsCA,MAAM,aAAa;CAAC;CAAQ;CAAO;AAAK;AAKxC,MAAM,oBAAoD,EAAE,KAC1D,EAAE,OAAO;CAAE,GAAG,EAAE,OAAO;CAAG,GAAG,EAAE,OAAO;CAAG,OAAO,EAAE,OAAO;CAAG,QAAQ,EAAE,OAA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;;CAE1D,WAAW,oBAAoB,aAAa,WAAW,eAAe;;CAEtE,MAAM,oBAAoB,QAAQ,WAAW,UAAU;;CAEvD,UAAU,oBAAoB,YAAY,WAAW,cAAc;;CAEnE,QAAQ,oBAAoB,UAAU,WAAW,iBAAiB;;CAElE,QAAQ,oBAAoB,UAAU,WAAW,gBAAgB;;CAEjE,WAAW,oBAAoB,aAAa,UAAU,eAAe;;CAErE,YAAY,oBAAoB,cAAc,WAAW,gBAAgB;;CAEzE,aAAa,oBAAoB,eAAe,WAAW,iBAAiB;;;;;CAK5E,aAAa,oBAAoB,eAAe,WAAW,iBAAiB;;;;;CAK5E,cAAc,oBAAoB,gBAAgB,eAAe,kBAAkB;;;;;CAKnF,kBAAkB,oBAAoB,oBAAoB,eAAe,sBAAsB;AACjG;AAEA,MAAM,cAAc,OAAO,OAAO,oBAAoB,CAAC,CAAC,QAAQ,UAAU,MAAM,SAAS,SAAS;;;;;;AAOlG,SAAgB,kBAAkB,SAAwD;CACxF,OAAO,kBAAkB,SAAS,WAAW,CAAC,CAAC,MAC5C,GAAG,MAAM,EAAE,SAAS,cAAc,EAAE,QAAQ,KAAK,EAAE,IAAI,cAAc,EAAE,GAAG,CAC7E;AACF"}
|
package/dist/preview.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preview.d.ts","names":[],"sources":["../src/preview.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"preview.d.ts","names":[],"sources":["../src/preview.ts"],"mappings":";;KAMY,uBAAuB,MAAM,WAAW,SAAS,QAAQ;KAEhE;EACH,OAAO,YAAY;EACnB;EACA;;iBAwCc,kBACd,OAAO,cACP,YACA,SAAS,QAAQ,YACjB,eAAe,sBACd,QAAQ"}
|
package/dist/preview.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { normalizeEffects } from "./effects.js";
|
|
2
|
+
import { shareEmptyNodeValues } from "./empty-values.js";
|
|
2
3
|
import { normalizeVectorNetwork } from "./vector-network.js";
|
|
3
4
|
import { textCacheInvalidationChanges } from "./text/picture.js";
|
|
4
5
|
//#region src/preview.ts
|
|
@@ -60,6 +61,7 @@ function updateNodePreview(graph, id, changes, beforeUpdate) {
|
|
|
60
61
|
beforeUpdate?.(node, normalizedChanges);
|
|
61
62
|
graph.positionPreviewVersion++;
|
|
62
63
|
Object.assign(node, normalizedChanges);
|
|
64
|
+
shareEmptyNodeValues(node, Object.keys(normalizedChanges));
|
|
63
65
|
return normalizedChanges;
|
|
64
66
|
}
|
|
65
67
|
//#endregion
|
package/dist/preview.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preview.js","names":[],"sources":["../src/preview.ts"],"sourcesContent":["import { normalizeEffects } from './effects'\nimport { textCacheInvalidationChanges } from './text/picture'\nimport type { SceneNode } from './types'\nimport { normalizeVectorNetwork } from './vector-network'\n\nexport type NodePreviewObserver = (node: SceneNode, changes: Partial<SceneNode>) => void\n\ntype PreviewGraph = {\n nodes: Map<string, SceneNode>\n positionPreviewVersion: number\n clearAbsPosCache: () => void\n}\n\nconst LAYOUT_AFFECTING_KEYS = new Set<string>([\n 'x',\n 'y',\n 'width',\n 'height',\n 'rotation',\n 'flipX',\n 'flipY',\n 'parentId',\n 'childIds',\n 'layoutMode',\n 'layoutDirection',\n 'layoutWrap',\n 'primaryAxisSizing',\n 'counterAxisSizing',\n 'itemSpacing',\n 'counterAxisSpacing',\n 'paddingTop',\n 'paddingRight',\n 'paddingBottom',\n 'paddingLeft',\n 'layoutGrow',\n 'layoutAlignSelf',\n 'layoutPositioning',\n 'minWidth',\n 'maxWidth',\n 'minHeight',\n 'maxHeight',\n 'visible',\n 'text',\n 'fontSize',\n 'lineHeight',\n 'letterSpacing',\n 'styleRuns',\n 'textAutoResize'\n])\n\nexport function updateNodePreview(\n graph: PreviewGraph,\n id: string,\n changes: Partial<SceneNode>,\n beforeUpdate?: NodePreviewObserver\n): Partial<SceneNode> | null {\n const node = graph.nodes.get(id)\n if (!node) return null\n changes = Object.fromEntries(\n (Object.entries(changes) as Array<[string, unknown]>).filter(([, value]) => value !== undefined)\n )\n if ((Object.keys(changes) as (keyof SceneNode)[]).every((key) => node[key] === changes[key])) {\n return null\n }\n const affectsLayout = Object.keys(changes).some((key) => LAYOUT_AFFECTING_KEYS.has(key))\n if (affectsLayout) graph.clearAbsPosCache()\n let normalizedChanges = changes\n if (node.type === 'TEXT') {\n normalizedChanges = { ...textCacheInvalidationChanges(node, changes), ...changes }\n }\n if (changes.vectorNetwork) {\n normalizedChanges = {\n ...normalizedChanges,\n vectorNetwork: normalizeVectorNetwork(changes.vectorNetwork)\n }\n }\n if (changes.effects) {\n normalizedChanges = { ...normalizedChanges, effects: normalizeEffects(changes.effects) }\n }\n beforeUpdate?.(node, normalizedChanges)\n graph.positionPreviewVersion++\n Object.assign(node, normalizedChanges)\n return normalizedChanges\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"preview.js","names":[],"sources":["../src/preview.ts"],"sourcesContent":["import { normalizeEffects } from './effects'\nimport { shareEmptyNodeValues } from './empty-values'\nimport { textCacheInvalidationChanges } from './text/picture'\nimport type { SceneNode } from './types'\nimport { normalizeVectorNetwork } from './vector-network'\n\nexport type NodePreviewObserver = (node: SceneNode, changes: Partial<SceneNode>) => void\n\ntype PreviewGraph = {\n nodes: Map<string, SceneNode>\n positionPreviewVersion: number\n clearAbsPosCache: () => void\n}\n\nconst LAYOUT_AFFECTING_KEYS = new Set<string>([\n 'x',\n 'y',\n 'width',\n 'height',\n 'rotation',\n 'flipX',\n 'flipY',\n 'parentId',\n 'childIds',\n 'layoutMode',\n 'layoutDirection',\n 'layoutWrap',\n 'primaryAxisSizing',\n 'counterAxisSizing',\n 'itemSpacing',\n 'counterAxisSpacing',\n 'paddingTop',\n 'paddingRight',\n 'paddingBottom',\n 'paddingLeft',\n 'layoutGrow',\n 'layoutAlignSelf',\n 'layoutPositioning',\n 'minWidth',\n 'maxWidth',\n 'minHeight',\n 'maxHeight',\n 'visible',\n 'text',\n 'fontSize',\n 'lineHeight',\n 'letterSpacing',\n 'styleRuns',\n 'textAutoResize'\n])\n\nexport function updateNodePreview(\n graph: PreviewGraph,\n id: string,\n changes: Partial<SceneNode>,\n beforeUpdate?: NodePreviewObserver\n): Partial<SceneNode> | null {\n const node = graph.nodes.get(id)\n if (!node) return null\n changes = Object.fromEntries(\n (Object.entries(changes) as Array<[string, unknown]>).filter(([, value]) => value !== undefined)\n )\n if ((Object.keys(changes) as (keyof SceneNode)[]).every((key) => node[key] === changes[key])) {\n return null\n }\n const affectsLayout = Object.keys(changes).some((key) => LAYOUT_AFFECTING_KEYS.has(key))\n if (affectsLayout) graph.clearAbsPosCache()\n let normalizedChanges = changes\n if (node.type === 'TEXT') {\n normalizedChanges = { ...textCacheInvalidationChanges(node, changes), ...changes }\n }\n if (changes.vectorNetwork) {\n normalizedChanges = {\n ...normalizedChanges,\n vectorNetwork: normalizeVectorNetwork(changes.vectorNetwork)\n }\n }\n if (changes.effects) {\n normalizedChanges = { ...normalizedChanges, effects: normalizeEffects(changes.effects) }\n }\n beforeUpdate?.(node, normalizedChanges)\n graph.positionPreviewVersion++\n Object.assign(node, normalizedChanges)\n shareEmptyNodeValues(node, Object.keys(normalizedChanges))\n return normalizedChanges\n}\n"],"mappings":";;;;;AAcA,MAAM,wCAAwB,IAAI,IAAY;CAC5C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,SAAgB,kBACd,OACA,IACA,SACA,cAC2B;CAC3B,MAAM,OAAO,MAAM,MAAM,IAAI,EAAE;CAC/B,IAAI,CAAC,MAAM,OAAO;CAClB,UAAU,OAAO,YACd,OAAO,QAAQ,OAAO,CAAC,CAA8B,QAAQ,GAAG,WAAW,UAAU,KAAA,CAAS,CACjG;CACA,IAAK,OAAO,KAAK,OAAO,CAAC,CAAyB,OAAO,QAAQ,KAAK,SAAS,QAAQ,IAAI,GACzF,OAAO;CAGT,IADsB,OAAO,KAAK,OAAO,CAAC,CAAC,MAAM,QAAQ,sBAAsB,IAAI,GAAG,CACtE,GAAG,MAAM,iBAAiB;CAC1C,IAAI,oBAAoB;CACxB,IAAI,KAAK,SAAS,QAChB,oBAAoB;EAAE,GAAG,6BAA6B,MAAM,OAAO;EAAG,GAAG;CAAQ;CAEnF,IAAI,QAAQ,eACV,oBAAoB;EAClB,GAAG;EACH,eAAe,uBAAuB,QAAQ,aAAa;CAC7D;CAEF,IAAI,QAAQ,SACV,oBAAoB;EAAE,GAAG;EAAmB,SAAS,iBAAiB,QAAQ,OAAO;CAAE;CAEzF,eAAe,MAAM,iBAAiB;CACtC,MAAM;CACN,OAAO,OAAO,MAAM,iBAAiB;CACrC,qBAAqB,MAAM,OAAO,KAAK,iBAAiB,CAAC;CACzD,OAAO;AACT"}
|
package/dist/resize.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resize.d.ts","names":[],"sources":["../src/resize.ts"],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"resize.d.ts","names":[],"sources":["../src/resize.ts"],"mappings":";;;;;;;;;KAmBY,iBAAiB,KAC3B;UAiBQ;EACR,QAAQ,aAAa;;;KAeX,kBAAkB;EAAS;EAAkB;;;iBAyDzC,iBACd,QAAQ,MACR,MAAM,KAAK,2BACX,YAAY,gBACZ,UAAU,iBACT;KAwBE,mBACH,OAAO,MACP,cAAc,KAAK,2BACnB,aAAa,KAAK,2BAClB,YAAY,gBACZ,UAAU,gBACV,gCACG;;;;;cAuCQ,sBAAoB;;;;;;cAOpB,4BAA0B;iBAEvB,gBACd,OAAO,MACP,cAAc,KAAK,2BACnB,aAAa,KAAK,4BACjB;iBAIa,4BACd,eAAe,sBACf,uBACA,wBACA,eACA,iBACC;;iBA8Ba,qBAAqB,MAAM,YAAY;;;;;;;iBAoDvC,sBACd,MAAM,KACJ,kJAUF,mBACA,oBACA,eACA,iBACC,QAAQ;;;;;;;;iBA0CK,qBACd,MAAM,WACN,eACA,iBACC,KAAK,QAAQ;KAkBX,iBAAiB,KAAK;;iBAGX,sBACd,MAAM,gBACN,YACA,aACC,KAAK,QAAQ;iBAmBA,yBACd,OAAO,aACP,iBACC,YAAY;;;;;iBAwBC,YACd,MAAM,KAAK,+BACX,SAAS,KAAK,+BACd,kBACA,mBACC,QAAQ,KAAK;iBASA,gCACd,OAAO,aACP,gBACA,YAAY,KAAK,2BACjB,WAAW,KAAK,2BAChB,WAAW,oBAAoB,kBAC9B,YAAY,QAAQ"}
|
package/dist/resize.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { cloneVectorNetwork } from "./vector-network.js";
|
|
2
2
|
import { copyDerivedGlyphs, copyGeometryPaths, copyStroke, copyStrokes, scaleGeometryPaths } from "./copy.js";
|
|
3
3
|
import { enforcedAspectRatio } from "./layout/aspect-ratio.js";
|
|
4
|
+
import { followsPath } from "./text/path.js";
|
|
4
5
|
//#region src/resize.ts
|
|
5
6
|
const CONSTRAINT_CONTAINER_TYPES = /* @__PURE__ */ new Set([
|
|
6
7
|
"FRAME",
|
|
@@ -226,7 +227,7 @@ function scaledGeometryChanges(orig, origWidth, origHeight, width, height) {
|
|
|
226
227
|
const outlineOnly = orig.type === "TEXT" || orig.type === "VECTOR" && !hasPath(orig);
|
|
227
228
|
if (orig.strokeGeometry.length > 0) changes.strokeGeometry = outlineOnly ? scaleGeometryPaths(orig.strokeGeometry, sx, sy) : [];
|
|
228
229
|
Object.assign(changes, scaledPathTextChanges(orig, sx, sy));
|
|
229
|
-
if (orig.strokes.length > 0 &&
|
|
230
|
+
if (orig.strokes.length > 0 && followsPath(orig)) changes.strokes = scaleStrokes(orig.strokes, sx, sy);
|
|
230
231
|
return changes;
|
|
231
232
|
}
|
|
232
233
|
/**
|
|
@@ -249,13 +250,9 @@ function shapeGeometryChanges(node, width, height) {
|
|
|
249
250
|
if (changes.strokeGeometry) geometry.strokeGeometry = changes.strokeGeometry;
|
|
250
251
|
return geometry;
|
|
251
252
|
}
|
|
252
|
-
function isScaledPathText(orig) {
|
|
253
|
-
const glyphs = orig.derivedTextGlyphs ?? [];
|
|
254
|
-
return glyphs.length > 0 && (!!orig.textPathData || !!orig.textPathBox || glyphs.some((glyph) => (glyph.rotation ?? 0) !== 0));
|
|
255
|
-
}
|
|
256
253
|
/** The baked glyphs and layout box of path text, scaled with the layer; nothing for other text. */
|
|
257
254
|
function scaledPathTextChanges(orig, sx, sy) {
|
|
258
|
-
if (!
|
|
255
|
+
if (!followsPath(orig)) return {};
|
|
259
256
|
const changes = { derivedTextGlyphs: scaleDerivedGlyphs(orig.derivedTextGlyphs, sx, sy) };
|
|
260
257
|
if (orig.textPathBox) changes.textPathBox = {
|
|
261
258
|
x: orig.textPathBox.x * sx,
|