@pairdraw/scene-graph 0.19.2 → 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.
Files changed (166) hide show
  1. package/dist/components/index.d.ts +2 -2
  2. package/dist/components/index.js +2 -2
  3. package/dist/components/variants.d.ts +12 -1
  4. package/dist/components/variants.d.ts.map +1 -1
  5. package/dist/components/variants.js +30 -1
  6. package/dist/components/variants.js.map +1 -1
  7. package/dist/constants.d.ts +25 -1
  8. package/dist/constants.d.ts.map +1 -1
  9. package/dist/constants.js +94 -1
  10. package/dist/constants.js.map +1 -1
  11. package/dist/copy.d.ts.map +1 -1
  12. package/dist/copy.js +17 -1
  13. package/dist/copy.js.map +1 -1
  14. package/dist/css/index.d.ts +2 -2
  15. package/dist/css/index.js +2 -2
  16. package/dist/css/text.d.ts +17 -1
  17. package/dist/css/text.d.ts.map +1 -1
  18. package/dist/css/text.js +62 -1
  19. package/dist/css/text.js.map +1 -1
  20. package/dist/design-memory/index.d.ts +3 -0
  21. package/dist/design-memory/index.js +3 -0
  22. package/dist/design-memory/model.d.ts +33 -0
  23. package/dist/design-memory/model.d.ts.map +1 -0
  24. package/dist/design-memory/model.js +142 -0
  25. package/dist/design-memory/model.js.map +1 -0
  26. package/dist/design-memory/schema.d.ts +76 -0
  27. package/dist/design-memory/schema.d.ts.map +1 -0
  28. package/dist/design-memory/schema.js +72 -0
  29. package/dist/design-memory/schema.js.map +1 -0
  30. package/dist/effects.d.ts +7 -4
  31. package/dist/effects.d.ts.map +1 -1
  32. package/dist/effects.js +9 -4
  33. package/dist/effects.js.map +1 -1
  34. package/dist/empty-values.js +93 -0
  35. package/dist/empty-values.js.map +1 -0
  36. package/dist/fields/components.d.ts +9 -0
  37. package/dist/fields/components.d.ts.map +1 -0
  38. package/dist/fields/components.js +24 -0
  39. package/dist/fields/components.js.map +1 -0
  40. package/dist/fields/index.d.ts +3 -2
  41. package/dist/fields/index.js +3 -2
  42. package/dist/fields/layout.d.ts +3 -1
  43. package/dist/fields/layout.d.ts.map +1 -1
  44. package/dist/fields/layout.js +10 -1
  45. package/dist/fields/layout.js.map +1 -1
  46. package/dist/graph.d.ts +8 -1
  47. package/dist/graph.d.ts.map +1 -1
  48. package/dist/graph.js +28 -5
  49. package/dist/graph.js.map +1 -1
  50. package/dist/grid-values.d.ts +10 -0
  51. package/dist/grid-values.d.ts.map +1 -0
  52. package/dist/grid-values.js +53 -0
  53. package/dist/grid-values.js.map +1 -0
  54. package/dist/hit-test/drop.d.ts +20 -0
  55. package/dist/hit-test/drop.d.ts.map +1 -0
  56. package/dist/hit-test/drop.js +54 -0
  57. package/dist/hit-test/drop.js.map +1 -0
  58. package/dist/hit-test/geometry.js +86 -0
  59. package/dist/hit-test/geometry.js.map +1 -0
  60. package/dist/hit-test/masks.d.ts +14 -0
  61. package/dist/hit-test/masks.d.ts.map +1 -0
  62. package/dist/hit-test/masks.js +41 -0
  63. package/dist/hit-test/masks.js.map +1 -0
  64. package/dist/hit-test/paint.d.ts +6 -0
  65. package/dist/hit-test/paint.d.ts.map +1 -0
  66. package/dist/hit-test/paint.js +19 -0
  67. package/dist/hit-test/paint.js.map +1 -0
  68. package/dist/hit-test.d.ts +4 -15
  69. package/dist/hit-test.d.ts.map +1 -1
  70. package/dist/hit-test.js +5 -173
  71. package/dist/hit-test.js.map +1 -1
  72. package/dist/index.d.ts +2 -2
  73. package/dist/instances/fields.d.ts.map +1 -1
  74. package/dist/instances/fields.js +2 -0
  75. package/dist/instances/fields.js.map +1 -1
  76. package/dist/instances/index.d.ts +2 -1
  77. package/dist/instances/index.d.ts.map +1 -1
  78. package/dist/instances/index.js +1 -1
  79. package/dist/instances/index.js.map +1 -1
  80. package/dist/instances/source-walk.d.ts +12 -0
  81. package/dist/instances/source-walk.d.ts.map +1 -0
  82. package/dist/node-defaults.d.ts.map +1 -1
  83. package/dist/node-defaults.js +41 -36
  84. package/dist/node-defaults.js.map +1 -1
  85. package/dist/plugin-data/fields.d.ts +75 -0
  86. package/dist/plugin-data/fields.d.ts.map +1 -1
  87. package/dist/plugin-data/fields.js +18 -1
  88. package/dist/plugin-data/fields.js.map +1 -1
  89. package/dist/preview.d.ts.map +1 -1
  90. package/dist/preview.js +2 -0
  91. package/dist/preview.js.map +1 -1
  92. package/dist/scaling/node.d.ts.map +1 -1
  93. package/dist/scaling/node.js +5 -1
  94. package/dist/scaling/node.js.map +1 -1
  95. package/dist/token-sources/document.d.ts +26 -0
  96. package/dist/token-sources/document.d.ts.map +1 -0
  97. package/dist/token-sources/document.js +80 -0
  98. package/dist/token-sources/document.js.map +1 -0
  99. package/dist/token-sources/index.d.ts +3 -0
  100. package/dist/token-sources/index.js +3 -0
  101. package/dist/token-sources/schema.d.ts +43 -0
  102. package/dist/token-sources/schema.d.ts.map +1 -0
  103. package/dist/token-sources/schema.js +50 -0
  104. package/dist/token-sources/schema.js.map +1 -0
  105. package/dist/types.d.ts +102 -14
  106. package/dist/types.d.ts.map +1 -1
  107. package/dist/types.js.map +1 -1
  108. package/dist/variations/copy.d.ts +16 -0
  109. package/dist/variations/copy.d.ts.map +1 -0
  110. package/dist/variations/copy.js +78 -0
  111. package/dist/variations/copy.js.map +1 -0
  112. package/dist/variations/index.d.ts +6 -0
  113. package/dist/variations/index.js +6 -0
  114. package/dist/variations/match.d.ts +23 -0
  115. package/dist/variations/match.d.ts.map +1 -0
  116. package/dist/variations/match.js +80 -0
  117. package/dist/variations/match.js.map +1 -0
  118. package/dist/variations/model.d.ts +39 -0
  119. package/dist/variations/model.d.ts.map +1 -0
  120. package/dist/variations/model.js +90 -0
  121. package/dist/variations/model.js.map +1 -0
  122. package/dist/variations/pick.d.ts +43 -0
  123. package/dist/variations/pick.d.ts.map +1 -0
  124. package/dist/variations/pick.js +211 -0
  125. package/dist/variations/pick.js.map +1 -0
  126. package/dist/variations/schema.d.ts +27 -0
  127. package/dist/variations/schema.d.ts.map +1 -0
  128. package/dist/variations/schema.js +27 -0
  129. package/dist/variations/schema.js.map +1 -0
  130. package/package.json +21 -1
  131. package/src/components/variants.ts +39 -0
  132. package/src/constants.ts +75 -0
  133. package/src/copy.ts +20 -1
  134. package/src/css/index.ts +7 -1
  135. package/src/css/text.ts +62 -0
  136. package/src/design-memory/index.ts +2 -0
  137. package/src/design-memory/model.ts +143 -0
  138. package/src/design-memory/schema.ts +84 -0
  139. package/src/effects.ts +16 -7
  140. package/src/empty-values.ts +101 -0
  141. package/src/fields/components.ts +21 -0
  142. package/src/fields/index.ts +1 -0
  143. package/src/fields/layout.ts +10 -0
  144. package/src/graph.ts +37 -5
  145. package/src/grid-values.ts +47 -0
  146. package/src/hit-test/drop.ts +90 -0
  147. package/src/hit-test/geometry.ts +131 -0
  148. package/src/hit-test/masks.ts +57 -0
  149. package/src/hit-test/paint.ts +24 -0
  150. package/src/hit-test.ts +8 -277
  151. package/src/instances/fields.ts +2 -0
  152. package/src/instances/index.ts +1 -0
  153. package/src/node-defaults.ts +49 -39
  154. package/src/plugin-data/fields.ts +18 -1
  155. package/src/preview.ts +2 -0
  156. package/src/scaling/node.ts +7 -2
  157. package/src/token-sources/document.ts +104 -0
  158. package/src/token-sources/index.ts +2 -0
  159. package/src/token-sources/schema.ts +59 -0
  160. package/src/types.ts +115 -13
  161. package/src/variations/copy.ts +89 -0
  162. package/src/variations/index.ts +5 -0
  163. package/src/variations/match.ts +100 -0
  164. package/src/variations/model.ts +132 -0
  165. package/src/variations/pick.ts +293 -0
  166. package/src/variations/schema.ts +29 -0
@@ -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. */
@@ -92,11 +94,11 @@ function createDefaultNode(generateId, type, overrides = {}) {
92
94
  color: BLACK,
93
95
  opacity: 1,
94
96
  visible: true
95
- }] : [],
96
- strokes: [],
97
- effects: [],
98
- layoutGrids: [],
99
- guides: [],
97
+ }] : EMPTY_LIST,
98
+ strokes: EMPTY_LIST,
99
+ effects: EMPTY_LIST,
100
+ layoutGrids: EMPTY_LIST,
101
+ guides: EMPTY_LIST,
100
102
  fillStyleId: null,
101
103
  strokeStyleId: null,
102
104
  textStyleId: null,
@@ -114,6 +116,8 @@ function createDefaultNode(generateId, type, overrides = {}) {
114
116
  visible: true,
115
117
  locked: false,
116
118
  clipsContent: false,
119
+ overflowDirection: "NONE",
120
+ scrollBehavior: "SCROLLS",
117
121
  text: "",
118
122
  fontSize: 14,
119
123
  fontFamily: DEFAULT_FONT_FAMILY,
@@ -133,8 +137,8 @@ function createDefaultNode(generateId, type, overrides = {}) {
133
137
  layoutAlignSelf: "AUTO",
134
138
  vectorNetwork: null,
135
139
  handleMirroring: "NONE",
136
- fillGeometry: [],
137
- strokeGeometry: [],
140
+ fillGeometry: EMPTY_LIST,
141
+ strokeGeometry: EMPTY_LIST,
138
142
  arcData: null,
139
143
  textAlignVertical: "TOP",
140
144
  textAutoResize: "NONE",
@@ -142,24 +146,24 @@ function createDefaultNode(generateId, type, overrides = {}) {
142
146
  textDecoration: "NONE",
143
147
  textDecorationStyle: "SOLID",
144
148
  textDecorationThickness: null,
145
- textDecorationFills: [],
149
+ textDecorationFills: EMPTY_LIST,
146
150
  textDecorationSkipInk: true,
147
151
  textUnderlineOffset: null,
148
152
  maxLines: null,
149
- textParagraphs: [],
153
+ textParagraphs: EMPTY_LIST,
150
154
  listSpacing: 0,
151
155
  paragraphSpacing: 0,
152
156
  paragraphIndent: 0,
153
157
  hangingList: false,
154
- styleRuns: [],
155
- fontVariations: [],
158
+ styleRuns: EMPTY_LIST,
159
+ fontVariations: EMPTY_LIST,
156
160
  opticalSizeFromFontSize: true,
157
- fontFeatures: [],
161
+ fontFeatures: EMPTY_LIST,
158
162
  horizontalConstraint: "MIN",
159
163
  verticalConstraint: "MIN",
160
164
  strokeCap: "NONE",
161
165
  strokeJoin: "MITER",
162
- dashPattern: [],
166
+ dashPattern: EMPTY_LIST,
163
167
  borderTopWeight: 0,
164
168
  borderRightWeight: 0,
165
169
  borderBottomWeight: 0,
@@ -178,14 +182,14 @@ function createDefaultNode(generateId, type, overrides = {}) {
178
182
  connectorLineType: "ELBOWED",
179
183
  connectorStartCap: "ROUND",
180
184
  connectorEndCap: "ARROW_LINES",
181
- connectorControlPoints: [],
185
+ connectorControlPoints: EMPTY_LIST,
182
186
  connectorCurveHandles: null,
183
187
  connectorLabelPosition: null,
184
188
  isMask: false,
185
189
  maskType: "ALPHA",
186
190
  maskIsOutline: false,
187
- gridTemplateColumns: [],
188
- gridTemplateRows: [],
191
+ gridTemplateColumns: EMPTY_LIST,
192
+ gridTemplateRows: EMPTY_LIST,
189
193
  gridColumnGap: 0,
190
194
  gridRowGap: 0,
191
195
  gridPosition: null,
@@ -202,10 +206,10 @@ function createDefaultNode(generateId, type, overrides = {}) {
202
206
  shapeTruncates: false,
203
207
  componentId: null,
204
208
  instanceOverrides: createInstanceOverrideState(),
205
- componentPropertyDefinitions: [],
206
- componentPropertyReferences: [],
207
- componentPropertyAssignments: {},
208
- componentPropertyValues: {},
209
+ componentPropertyDefinitions: EMPTY_LIST,
210
+ componentPropertyReferences: EMPTY_LIST,
211
+ componentPropertyAssignments: EMPTY_RECORD,
212
+ componentPropertyValues: EMPTY_RECORD,
209
213
  componentKey: null,
210
214
  sourceLibraryKey: null,
211
215
  publishId: null,
@@ -217,18 +221,18 @@ function createDefaultNode(generateId, type, overrides = {}) {
217
221
  isSymbolPublishable: false,
218
222
  isExposedInstance: false,
219
223
  symbolDescription: "",
220
- symbolLinks: [],
221
- variantPropSpecs: [],
222
- boundVariables: {},
223
- variableBindingScales: {},
224
- variableAssignmentScales: {},
224
+ symbolLinks: EMPTY_LIST,
225
+ variantPropSpecs: EMPTY_LIST,
226
+ boundVariables: EMPTY_RECORD,
227
+ variableBindingScales: EMPTY_RECORD,
228
+ variableAssignmentScales: EMPTY_RECORD,
225
229
  componentScale: 1,
226
- variableModes: {},
227
- exportSettings: [],
230
+ variableModes: EMPTY_RECORD,
231
+ exportSettings: EMPTY_LIST,
228
232
  status: null,
229
- pluginData: [],
230
- pluginRelaunchData: [],
231
- prototypeReactions: [],
233
+ pluginData: EMPTY_LIST,
234
+ pluginRelaunchData: EMPTY_LIST,
235
+ prototypeReactions: EMPTY_LIST,
232
236
  internalOnly: false,
233
237
  flipX: false,
234
238
  flipY: false,
@@ -241,6 +245,7 @@ function createDefaultNode(generateId, type, overrides = {}) {
241
245
  ...overrides
242
246
  };
243
247
  node.effects = normalizeEffects(node.effects);
248
+ shareEmptyNodeValues(node, Object.keys(overrides));
244
249
  return node;
245
250
  }
246
251
  /** Containers whose bounds follow their children and that set no coordinate space, as in Figma. */
@@ -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\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 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 ...FRAME_LAYOUT_DEFAULTS,\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;CAC5D,OAAO;EACL,QAAQ;EACR,IAAI;EACJ,UAAU;EACV,cAAc,CAAC;EACf,KAAK;GACH,SAAS;GACT,cAAc;GACd,eAAe,CAAC;GAChB,QAAQ;GACR,iBAAiB,CAAC;GAClB,0BA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AAC;EACzB,uBAAuB;EACvB,wBAAwB;EACxB,QAAQ;EACR,UAAU;EACV,eAAe;EACf,qBAAqB,CAAC;EACtB,kBAAkB,CAAC;EACnB,eAAe;EACf,YAAY;EACZ,cAAc;EACd,yBAAyB;EACzB,mBAAmB;EACnB,yBAAyB;EACzB,UAAU;EACV,gBAAgB;EAChB,YAAY;EACZ,YAAY;EACZ,iBAAiB;EACjB,mBAAmB;EACnB,iBAAiB;EACjB,gBAAgB;EAChB,aAAa;EACb,mBAAmB,4BAA4B;EAC/C,8BAA8B,CAAC;EAC/B,6BAA6B,CAAC;EAC9B,8BAA8B,CAAC;EAC/B,yBAAyB,CAAC;EAC1B,cAAc;EACd,kBAAkB;EAClB,WAAW;EACX,aAAa;EACb,qBAAqB;EACrB,kBAAkB;EAClB,eAAe;EACf,eAAe;EACf,qBAAqB;EACrB,mBAAmB;EACnB,mBAAmB;EACnB,aAAa,CAAC;EACd,kBAAkB,CAAC;EACnB,gBAAgB,CAAC;EACjB,uBAAuB,CAAC;EACxB,0BAA0B,CAAC;EAC3B,gBAAgB;EAChB,eAAe,CAAC;EAChB,gBAAgB,CAAC;EACjB,QAAQ;EACR,YAAY,CAAC;EACb,oBAAoB,CAAC;EACrB,oBAAoB,CAAC;EACrB,cAAc;EACd,OAAO;EACP,OAAO;EACP,aAAa;EACb,mBAAmB;EACnB,mBAAmB;EACnB,cAAc;EACd,aAAa;EACb,kBAAkB,KAAA;EAClB,GAAG;CACL;CACA,KAAK,UAAU,iBAAiB,KAAK,OAAO;CAC5C,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"}
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,MAAM,QAAQ,KAAK,YAAY,CAAC,CAAC,WAAW,KAAK,GAAG;CACpD,OAAO,MAAM,OAAO,CAAC,CAAC,CAAC,YAAY,IAAI,MAAM,MAAM,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BAAuB;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":";;;;;;;;;;;;UAsHiB;EACf;EACA;;;UAWe;EACf,OAAO;EACP,cAAc;IAAiB;IAAa;;;;UA0B7B;EACf;EACA;EACA;EACA;EACA;IAAU,UAAU;IAAQ,OAAO;;;;;;;;cA6CxB;;iBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA4FG,kBAAkB,kBAAkB,oBAAoB"}
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,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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,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,E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AAc,EAAE,GAAG,CAC7E;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"preview.d.ts","names":[],"sources":["../src/preview.ts"],"mappings":";;KAKY,uBAAuB,MAAM,WAAW,SAAS,QAAQ;KAEhE;EACH,OAAO,YAAY;EACnB;EACA;;iBAwCc,kBACd,OAAO,cACP,YACA,SAAS,QAAQ,YACjB,eAAe,sBACd,QAAQ"}
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
@@ -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":";;;;AAaA,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,OAAO;AACT"}
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"}
@@ -1 +1 @@
1
- {"version":3,"file":"node.d.ts","names":[],"sources":["../../src/scaling/node.ts"],"mappings":";;iBAyIgB,iBACd,MAAM,WACN,eACA,yBACC,QAAQ"}
1
+ {"version":3,"file":"node.d.ts","names":[],"sources":["../../src/scaling/node.ts"],"mappings":";;iBA8IgB,iBACd,MAAM,WACN,eACA,yBACC,QAAQ"}
@@ -36,7 +36,11 @@ function scaledStrokes(strokes, scale) {
36
36
  function scaledEffects(effects, scale) {
37
37
  return effects.map((effect) => {
38
38
  const copy = structuredClone(effect);
39
- if (copy.type === "SHADER") return copy;
39
+ if (copy.type === "SHADER" || copy.type === "NOISE") return copy;
40
+ if (copy.type === "TEXTURE") {
41
+ copy.radius *= scale;
42
+ return copy;
43
+ }
40
44
  copy.offset = {
41
45
  x: copy.offset.x * scale,
42
46
  y: copy.offset.y * scale
@@ -1 +1 @@
1
- {"version":3,"file":"node.js","names":[],"sources":["../../src/scaling/node.ts"],"sourcesContent":["import { copyDerivedGlyphs, scaleGeometryPaths } from '../copy'\nimport { scaledTextLength } from '../text/lengths'\nimport { TEXT_PARAGRAPH_SPACING_FIELDS } from '../text/paragraphs'\nimport { followsPath } from '../text/path'\nimport {\n type Effect,\n type Fill,\n type GridTrack,\n type LayoutGrid,\n type SceneNode,\n type Stroke,\n type StyleRun,\n type TextParagraphStyle\n} from '../types'\nimport { cloneVectorNetwork } from '../vector-network'\n\nfunction scaledPathText(node: SceneNode, scale: number): Partial<SceneNode> {\n if (!node.textPathData && !followsPath(node)) {\n return {}\n }\n const box = node.textPathBox\n return {\n derivedTextGlyphs:\n copyDerivedGlyphs(node.derivedTextGlyphs)?.map((glyph) => ({\n ...glyph,\n x: glyph.x * scale,\n y: glyph.y * scale,\n fontSize: glyph.fontSize * scale,\n ...(glyph.advance === undefined ? {} : { advance: glyph.advance * scale })\n })) ?? null,\n textPathBox: box && {\n x: box.x * scale,\n y: box.y * scale,\n width: box.width * scale,\n height: box.height * scale\n }\n }\n}\n\nfunction scaledOptional(value: number | null, scale: number): number | null {\n return value == null ? null : value * scale\n}\n\nfunction scaledStrokes(strokes: readonly Stroke[], scale: number): Stroke[] {\n return strokes.map((stroke) => ({\n ...structuredClone(stroke),\n weight: stroke.weight * scale,\n dashPattern: stroke.dashPattern?.map((value) => value * scale)\n }))\n}\n\nfunction scaledEffects(effects: readonly Effect[], scale: number): Effect[] {\n return effects.map((effect) => {\n const copy = structuredClone(effect)\n // A shader effect has no geometry of its own; only a shadow's measures follow the layer.\n if (copy.type === 'SHADER') return copy\n copy.offset = { x: copy.offset.x * scale, y: copy.offset.y * scale }\n copy.radius *= scale\n copy.spread *= scale\n return copy\n })\n}\n\nfunction scaledFills(fills: readonly Fill[], scale: number): Fill[] {\n return fills.map((fill) => ({\n ...structuredClone(fill),\n scale: fill.scale == null ? undefined : fill.scale * scale,\n spacing: fill.spacing == null ? undefined : fill.spacing * scale,\n patternSpacing: fill.patternSpacing\n ? { x: fill.patternSpacing.x * scale, y: fill.patternSpacing.y * scale }\n : undefined,\n noiseSize: fill.noiseSize\n ? { x: fill.noiseSize.x * scale, y: fill.noiseSize.y * scale }\n : undefined\n }))\n}\n\nfunction scaledStyleRuns(styleRuns: readonly StyleRun[], scale: number): StyleRun[] {\n return styleRuns.map((run) => ({\n ...structuredClone(run),\n style: {\n ...structuredClone(run.style),\n fontSize: run.style.fontSize == null ? undefined : run.style.fontSize * scale,\n letterSpacing: run.style.letterSpacing && scaledTextLength(run.style.letterSpacing, scale),\n lineHeight: run.style.lineHeight && scaledTextLength(run.style.lineHeight, scale),\n textDecorationThickness: scaledOptional(run.style.textDecorationThickness ?? null, scale),\n textUnderlineOffset: scaledOptional(run.style.textUnderlineOffset ?? null, scale)\n }\n }))\n}\n\nfunction scaledParagraphStyles(\n paragraphs: readonly TextParagraphStyle[],\n scale: number\n): TextParagraphStyle[] {\n return paragraphs.map((style) => {\n const scaled = { ...style }\n for (const field of TEXT_PARAGRAPH_SPACING_FIELDS) {\n const value = style[field]\n if (value !== undefined) scaled[field] = value * scale\n }\n return scaled\n })\n}\n\nfunction scaledLayoutGrids(grids: readonly LayoutGrid[], scale: number): LayoutGrid[] {\n return grids.map((grid) => ({\n ...structuredClone(grid),\n offset: grid.offset == null ? undefined : grid.offset * scale,\n sectionSize: grid.sectionSize == null ? undefined : grid.sectionSize * scale,\n gutterSize: grid.gutterSize == null ? undefined : grid.gutterSize * scale\n }))\n}\n\nfunction scaledGridTracks(tracks: readonly GridTrack[], scale: number): GridTrack[] {\n return tracks.map((track) => ({\n ...track,\n value: track.sizing === 'FIXED' ? track.value * scale : track.value\n }))\n}\n\nfunction scaledVectorNetwork(node: SceneNode, scale: number): SceneNode['vectorNetwork'] {\n if (!node.vectorNetwork) return null\n const network = cloneVectorNetwork(node.vectorNetwork)\n for (const vertex of network.vertices) {\n vertex.x *= scale\n vertex.y *= scale\n }\n for (const segment of network.segments) {\n segment.tangentStart.x *= scale\n segment.tangentStart.y *= scale\n segment.tangentEnd.x *= scale\n segment.tangentEnd.y *= scale\n }\n return network\n}\n\nexport function scaleNodeChanges(\n node: SceneNode,\n scale: number,\n scalePosition: boolean\n): Partial<SceneNode> {\n return {\n x: scalePosition ? node.x * scale : node.x,\n y: scalePosition ? node.y * scale : node.y,\n width: node.width * scale,\n height: node.height * scale,\n minWidth: scaledOptional(node.minWidth, scale),\n maxWidth: scaledOptional(node.maxWidth, scale),\n minHeight: scaledOptional(node.minHeight, scale),\n maxHeight: scaledOptional(node.maxHeight, scale),\n cornerRadius: node.cornerRadius * scale,\n topLeftRadius: node.topLeftRadius * scale,\n topRightRadius: node.topRightRadius * scale,\n bottomRightRadius: node.bottomRightRadius * scale,\n bottomLeftRadius: node.bottomLeftRadius * scale,\n fontSize: node.fontSize * scale,\n letterSpacing: scaledTextLength(node.letterSpacing, scale),\n lineHeight: node.lineHeight && scaledTextLength(node.lineHeight, scale),\n textDecorationThickness: scaledOptional(node.textDecorationThickness, scale),\n textUnderlineOffset: scaledOptional(node.textUnderlineOffset, scale),\n styleRuns: scaledStyleRuns(node.styleRuns, scale),\n listSpacing: node.listSpacing * scale,\n paragraphSpacing: node.paragraphSpacing * scale,\n paragraphIndent: node.paragraphIndent * scale,\n textParagraphs: scaledParagraphStyles(node.textParagraphs, scale),\n derivedTextHeight: scaledOptional(node.derivedTextHeight, scale),\n itemSpacing: node.itemSpacing * scale,\n counterAxisSpacing: node.counterAxisSpacing * scale,\n paddingTop: node.paddingTop * scale,\n paddingRight: node.paddingRight * scale,\n paddingBottom: node.paddingBottom * scale,\n paddingLeft: node.paddingLeft * scale,\n gridColumnGap: node.gridColumnGap * scale,\n gridRowGap: node.gridRowGap * scale,\n gridTemplateColumns: scaledGridTracks(node.gridTemplateColumns, scale),\n gridTemplateRows: scaledGridTracks(node.gridTemplateRows, scale),\n strokes: scaledStrokes(node.strokes, scale),\n strokeWeight: node.strokeWeight * scale,\n dashPattern: node.dashPattern.map((value) => value * scale),\n borderTopWeight: node.borderTopWeight * scale,\n borderRightWeight: node.borderRightWeight * scale,\n borderBottomWeight: node.borderBottomWeight * scale,\n borderLeftWeight: node.borderLeftWeight * scale,\n strokeMiterLimit: node.strokeMiterLimit,\n effects: scaledEffects(node.effects, scale),\n fills: scaledFills(node.fills, scale),\n layoutGrids: scaledLayoutGrids(node.layoutGrids, scale),\n vectorNetwork: scaledVectorNetwork(node, scale),\n fillGeometry: scaleGeometryPaths(node.fillGeometry, scale, scale),\n strokeGeometry: scaleGeometryPaths(node.strokeGeometry, scale, scale),\n ...scaledPathText(node, scale)\n }\n}\n"],"mappings":";;;;;;AAgBA,SAAS,eAAe,MAAiB,OAAmC;CAC1E,IAAI,CAAC,KAAK,gBAAgB,CAAC,YAAY,IAAI,GACzC,OAAO,CAAC;CAEV,MAAM,MAAM,KAAK;CACjB,OAAO;EACL,mBACE,kBAAkB,KAAK,iBAAiB,CAAC,EAAE,KAAK,WAAW;GACzD,GAAG;GACH,GAAG,MAAM,IAAI;GACb,GAAG,MAAM,IAAI;GACb,UAAU,MAAM,WAAW;GAC3B,GAAI,MAAM,YAAY,KAAA,IAAY,CAAC,IAAI,EAAE,SAAS,MAAM,UAAU,MAAM;EAC1E,EAAE,KAAK;EACT,aAAa,OAAO;GAClB,GAAG,IAAI,IAAI;GACX,GAAG,IAAI,IAAI;GACX,OAAO,IAAI,QAAQ;GACnB,QAAQ,IAAI,SAAS;EACvB;CACF;AACF;AAEA,SAAS,eAAe,OAAsB,OAA8B;CAC1E,OAAO,SAAS,OAAO,OAAO,QAAQ;AACxC;AAEA,SAAS,cAAc,SAA4B,OAAyB;CAC1E,OAAO,QAAQ,KAAK,YAAY;EAC9B,GAAG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AC1C,kBAAkB,KAAK;EACvB,SAAS,cAAc,KAAK,SAAS,KAAK;EAC1C,OAAO,YAAY,KAAK,OAAO,KAAK;EACpC,aAAa,kBAAkB,KAAK,aAAa,KAAK;EACtD,eAAe,oBAAoB,MAAM,KAAK;EAC9C,cAAc,mBAAmB,KAAK,cAAc,OAAO,KAAK;EAChE,gBAAgB,mBAAmB,KAAK,gBAAgB,OAAO,KAAK;EACpE,GAAG,eAAe,MAAM,KAAK;CAC/B;AACF"}
1
+ {"version":3,"file":"node.js","names":[],"sources":["../../src/scaling/node.ts"],"sourcesContent":["import { copyDerivedGlyphs, scaleGeometryPaths } from '../copy'\nimport { scaledTextLength } from '../text/lengths'\nimport { TEXT_PARAGRAPH_SPACING_FIELDS } from '../text/paragraphs'\nimport { followsPath } from '../text/path'\nimport {\n type Effect,\n type Fill,\n type GridTrack,\n type LayoutGrid,\n type SceneNode,\n type Stroke,\n type StyleRun,\n type TextParagraphStyle\n} from '../types'\nimport { cloneVectorNetwork } from '../vector-network'\n\nfunction scaledPathText(node: SceneNode, scale: number): Partial<SceneNode> {\n if (!node.textPathData && !followsPath(node)) {\n return {}\n }\n const box = node.textPathBox\n return {\n derivedTextGlyphs:\n copyDerivedGlyphs(node.derivedTextGlyphs)?.map((glyph) => ({\n ...glyph,\n x: glyph.x * scale,\n y: glyph.y * scale,\n fontSize: glyph.fontSize * scale,\n ...(glyph.advance === undefined ? {} : { advance: glyph.advance * scale })\n })) ?? null,\n textPathBox: box && {\n x: box.x * scale,\n y: box.y * scale,\n width: box.width * scale,\n height: box.height * scale\n }\n }\n}\n\nfunction scaledOptional(value: number | null, scale: number): number | null {\n return value == null ? null : value * scale\n}\n\nfunction scaledStrokes(strokes: readonly Stroke[], scale: number): Stroke[] {\n return strokes.map((stroke) => ({\n ...structuredClone(stroke),\n weight: stroke.weight * scale,\n dashPattern: stroke.dashPattern?.map((value) => value * scale)\n }))\n}\n\nfunction scaledEffects(effects: readonly Effect[], scale: number): Effect[] {\n return effects.map((effect) => {\n const copy = structuredClone(effect)\n // A shader effect has no geometry of its own, and a noise's grain keeps its size.\n if (copy.type === 'SHADER' || copy.type === 'NOISE') return copy\n // A texture roughens the edges by its radius; its grain keeps its size too.\n if (copy.type === 'TEXTURE') {\n copy.radius *= scale\n return copy\n }\n copy.offset = { x: copy.offset.x * scale, y: copy.offset.y * scale }\n copy.radius *= scale\n copy.spread *= scale\n return copy\n })\n}\n\nfunction scaledFills(fills: readonly Fill[], scale: number): Fill[] {\n return fills.map((fill) => ({\n ...structuredClone(fill),\n scale: fill.scale == null ? undefined : fill.scale * scale,\n spacing: fill.spacing == null ? undefined : fill.spacing * scale,\n patternSpacing: fill.patternSpacing\n ? { x: fill.patternSpacing.x * scale, y: fill.patternSpacing.y * scale }\n : undefined,\n noiseSize: fill.noiseSize\n ? { x: fill.noiseSize.x * scale, y: fill.noiseSize.y * scale }\n : undefined\n }))\n}\n\nfunction scaledStyleRuns(styleRuns: readonly StyleRun[], scale: number): StyleRun[] {\n return styleRuns.map((run) => ({\n ...structuredClone(run),\n style: {\n ...structuredClone(run.style),\n fontSize: run.style.fontSize == null ? undefined : run.style.fontSize * scale,\n letterSpacing: run.style.letterSpacing && scaledTextLength(run.style.letterSpacing, scale),\n lineHeight: run.style.lineHeight && scaledTextLength(run.style.lineHeight, scale),\n textDecorationThickness: scaledOptional(run.style.textDecorationThickness ?? null, scale),\n textUnderlineOffset: scaledOptional(run.style.textUnderlineOffset ?? null, scale)\n }\n }))\n}\n\nfunction scaledParagraphStyles(\n paragraphs: readonly TextParagraphStyle[],\n scale: number\n): TextParagraphStyle[] {\n return paragraphs.map((style) => {\n const scaled = { ...style }\n for (const field of TEXT_PARAGRAPH_SPACING_FIELDS) {\n const value = style[field]\n if (value !== undefined) scaled[field] = value * scale\n }\n return scaled\n })\n}\n\nfunction scaledLayoutGrids(grids: readonly LayoutGrid[], scale: number): LayoutGrid[] {\n return grids.map((grid) => ({\n ...structuredClone(grid),\n offset: grid.offset == null ? undefined : grid.offset * scale,\n sectionSize: grid.sectionSize == null ? undefined : grid.sectionSize * scale,\n gutterSize: grid.gutterSize == null ? undefined : grid.gutterSize * scale\n }))\n}\n\nfunction scaledGridTracks(tracks: readonly GridTrack[], scale: number): GridTrack[] {\n return tracks.map((track) => ({\n ...track,\n value: track.sizing === 'FIXED' ? track.value * scale : track.value\n }))\n}\n\nfunction scaledVectorNetwork(node: SceneNode, scale: number): SceneNode['vectorNetwork'] {\n if (!node.vectorNetwork) return null\n const network = cloneVectorNetwork(node.vectorNetwork)\n for (const vertex of network.vertices) {\n vertex.x *= scale\n vertex.y *= scale\n }\n for (const segment of network.segments) {\n segment.tangentStart.x *= scale\n segment.tangentStart.y *= scale\n segment.tangentEnd.x *= scale\n segment.tangentEnd.y *= scale\n }\n return network\n}\n\nexport function scaleNodeChanges(\n node: SceneNode,\n scale: number,\n scalePosition: boolean\n): Partial<SceneNode> {\n return {\n x: scalePosition ? node.x * scale : node.x,\n y: scalePosition ? node.y * scale : node.y,\n width: node.width * scale,\n height: node.height * scale,\n minWidth: scaledOptional(node.minWidth, scale),\n maxWidth: scaledOptional(node.maxWidth, scale),\n minHeight: scaledOptional(node.minHeight, scale),\n maxHeight: scaledOptional(node.maxHeight, scale),\n cornerRadius: node.cornerRadius * scale,\n topLeftRadius: node.topLeftRadius * scale,\n topRightRadius: node.topRightRadius * scale,\n bottomRightRadius: node.bottomRightRadius * scale,\n bottomLeftRadius: node.bottomLeftRadius * scale,\n fontSize: node.fontSize * scale,\n letterSpacing: scaledTextLength(node.letterSpacing, scale),\n lineHeight: node.lineHeight && scaledTextLength(node.lineHeight, scale),\n textDecorationThickness: scaledOptional(node.textDecorationThickness, scale),\n textUnderlineOffset: scaledOptional(node.textUnderlineOffset, scale),\n styleRuns: scaledStyleRuns(node.styleRuns, scale),\n listSpacing: node.listSpacing * scale,\n paragraphSpacing: node.paragraphSpacing * scale,\n paragraphIndent: node.paragraphIndent * scale,\n textParagraphs: scaledParagraphStyles(node.textParagraphs, scale),\n derivedTextHeight: scaledOptional(node.derivedTextHeight, scale),\n itemSpacing: node.itemSpacing * scale,\n counterAxisSpacing: node.counterAxisSpacing * scale,\n paddingTop: node.paddingTop * scale,\n paddingRight: node.paddingRight * scale,\n paddingBottom: node.paddingBottom * scale,\n paddingLeft: node.paddingLeft * scale,\n gridColumnGap: node.gridColumnGap * scale,\n gridRowGap: node.gridRowGap * scale,\n gridTemplateColumns: scaledGridTracks(node.gridTemplateColumns, scale),\n gridTemplateRows: scaledGridTracks(node.gridTemplateRows, scale),\n strokes: scaledStrokes(node.strokes, scale),\n strokeWeight: node.strokeWeight * scale,\n dashPattern: node.dashPattern.map((value) => value * scale),\n borderTopWeight: node.borderTopWeight * scale,\n borderRightWeight: node.borderRightWeight * scale,\n borderBottomWeight: node.borderBottomWeight * scale,\n borderLeftWeight: node.borderLeftWeight * scale,\n strokeMiterLimit: node.strokeMiterLimit,\n effects: scaledEffects(node.effects, scale),\n fills: scaledFills(node.fills, scale),\n layoutGrids: scaledLayoutGrids(node.layoutGrids, scale),\n vectorNetwork: scaledVectorNetwork(node, scale),\n fillGeometry: scaleGeometryPaths(node.fillGeometry, scale, scale),\n strokeGeometry: scaleGeometryPaths(node.strokeGeometry, scale, scale),\n ...scaledPathText(node, scale)\n }\n}\n"],"mappings":";;;;;;AAgBA,SAAS,eAAe,MAAiB,OAAmC;CAC1E,IAAI,CAAC,KAAK,gBAAgB,CAAC,YAAY,IAAI,GACzC,OAAO,CAAC;CAEV,MAAM,MAAM,KAAK;CACjB,OAAO;EACL,mBACE,kBAAkB,KAAK,iBAAiB,CAAC,EAAE,KAAK,WAAW;GACzD,GAAG;GACH,GAAG,MAAM,IAAI;GACb,GAAG,MAAM,IAAI;GACb,UAAU,MAAM,WAAW;GAC3B,GAAI,MAAM,YAAY,KAAA,IAAY,CAAC,IAAI,EAAE,SAAS,MAAM,UAAU,MAAM;EAC1E,EAAE,KAAK;EACT,aAAa,OAAO;GAClB,GAAG,IAAI,IAAI;GAC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a;EAC9B,qBAAqB,iBAAiB,KAAK,qBAAqB,KAAK;EACrE,kBAAkB,iBAAiB,KAAK,kBAAkB,KAAK;EAC/D,SAAS,cAAc,KAAK,SAAS,KAAK;EAC1C,cAAc,KAAK,eAAe;EAClC,aAAa,KAAK,YAAY,KAAK,UAAU,QAAQ,KAAK;EAC1D,iBAAiB,KAAK,kBAAkB;EACxC,mBAAmB,KAAK,oBAAoB;EAC5C,oBAAoB,KAAK,qBAAqB;EAC9C,kBAAkB,KAAK,mBAAmB;EAC1C,kBAAkB,KAAK;EACvB,SAAS,cAAc,KAAK,SAAS,KAAK;EAC1C,OAAO,YAAY,KAAK,OAAO,KAAK;EACpC,aAAa,kBAAkB,KAAK,aAAa,KAAK;EACtD,eAAe,oBAAoB,MAAM,KAAK;EAC9C,cAAc,mBAAmB,KAAK,cAAc,OAAO,KAAK;EAChE,gBAAgB,mBAAmB,KAAK,gBAAgB,OAAO,KAAK;EACpE,GAAG,eAAe,MAAM,KAAK;CAC/B;AACF"}
@@ -0,0 +1,26 @@
1
+ import { SceneGraph } from "../graph.js";
2
+ import { PluginDataEntry } from "../types.js";
3
+ import { TokenSource } from "./schema.js";
4
+ //#region src/token-sources/document.d.ts
5
+ /**
6
+ * The code a document's variables are linked to, with what it held at the last sync. The links
7
+ * live in Pairdraw's plugin data on the document node, so they travel with the `.fig` file and
8
+ * Figma ignores them; where each file is on this computer stays with the app, not the document.
9
+ */
10
+ declare function readTokenSources(graph: SceneGraph): TokenSource[];
11
+ /**
12
+ * The links with their snapshots keyed by the graph's variable and mode ids. A format that keys
13
+ * variables and modes by name, such as `.pen`, gives them new ids when it reads them back; the
14
+ * names the file stored when it was saved, or the last sync's where the file recorded none, find
15
+ * them again. `names` and the snapshot's token identities are kept as they were. Links whose
16
+ * variables are all gone are left as they are.
17
+ */
18
+ declare function rekeyTokenSources(graph: SceneGraph, sources: readonly TokenSource[]): TokenSource[];
19
+ /**
20
+ * The document node's plugin data holding `sources` in place of its links, for an edit that
21
+ * writes them, undoably or not, as one change to the node.
22
+ */
23
+ declare function tokenSourcesPluginData(graph: SceneGraph, sources: readonly TokenSource[]): PluginDataEntry[];
24
+ //#endregion
25
+ export { readTokenSources, rekeyTokenSources, tokenSourcesPluginData };
26
+ //# sourceMappingURL=document.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"document.d.ts","names":[],"sources":["../../src/token-sources/document.ts"],"mappings":";;;;;;;;;iBAegB,iBAAiB,OAAO,aAAa;;;;;;;;iBAWrC,kBACd,OAAO,YACP,kBAAkB,gBACjB;;;;;iBA4Da,uBACd,OAAO,YACP,kBAAkB,gBACjB"}