@moondraft/import 0.1.0 → 0.3.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 (98) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/README.md +2 -2
  3. package/SOURCE.md +343 -4
  4. package/dist/adapter/convert.d.ts +26 -2
  5. package/dist/adapter/convert.js +817 -217
  6. package/dist/adapter/figma-descriptions.d.ts +7 -0
  7. package/dist/adapter/figma-descriptions.js +34 -0
  8. package/dist/adapter/figma-grids.d.ts +12 -0
  9. package/dist/adapter/figma-grids.js +175 -0
  10. package/dist/adapter/figma-handoff.d.ts +34 -0
  11. package/dist/adapter/figma-handoff.js +188 -0
  12. package/dist/adapter/figma-hyperlinks.d.ts +13 -0
  13. package/dist/adapter/figma-hyperlinks.js +77 -0
  14. package/dist/adapter/figma.d.ts +4 -1
  15. package/dist/adapter/figma.js +15 -4
  16. package/dist/adapter/file-components.d.ts +10 -3
  17. package/dist/adapter/file-components.js +126 -33
  18. package/dist/adapter/file-resources.js +545 -47
  19. package/dist/adapter/file-typography.d.ts +6 -0
  20. package/dist/adapter/file-typography.js +44 -0
  21. package/dist/adapter/image-crop.d.ts +18 -0
  22. package/dist/adapter/image-crop.js +30 -0
  23. package/dist/adapter/link.d.ts +12 -1
  24. package/dist/adapter/link.js +380 -113
  25. package/dist/adapter/payload.js +3 -3
  26. package/dist/adapter/variables.d.ts +2 -1
  27. package/dist/adapter/variables.js +5 -2
  28. package/dist/figma-file.d.ts +1 -0
  29. package/dist/figma-file.js +1 -0
  30. package/dist/figma.d.ts +1 -0
  31. package/dist/figma.js +191 -35
  32. package/dist/index.d.ts +1 -0
  33. package/dist/index.js +1 -0
  34. package/dist/report.d.ts +59 -1
  35. package/dist/report.js +176 -30
  36. package/dist/serialize.d.ts +7 -0
  37. package/dist/serialize.js +79 -0
  38. package/dist/taco/figma-import/container/kiwiContainer.d.ts +3 -0
  39. package/dist/taco/figma-import/container/kiwiContainer.js +1 -1
  40. package/dist/taco/figma-import/figFile.js +3 -0
  41. package/dist/taco/figma-import/import/carry.d.ts +14 -1
  42. package/dist/taco/figma-import/import/carry.js +34 -1
  43. package/dist/taco/figma-import/import/componentProps.d.ts +10 -4
  44. package/dist/taco/figma-import/import/componentProps.js +29 -13
  45. package/dist/taco/figma-import/import/componentSets.d.ts +2 -0
  46. package/dist/taco/figma-import/import/componentSets.js +1 -1
  47. package/dist/taco/figma-import/import/converters/effects.d.ts +3 -13
  48. package/dist/taco/figma-import/import/converters/effects.js +4 -34
  49. package/dist/taco/figma-import/import/converters/exportSettings.d.ts +4 -0
  50. package/dist/taco/figma-import/import/converters/exportSettings.js +75 -0
  51. package/dist/taco/figma-import/import/converters/frame.d.ts +1 -1
  52. package/dist/taco/figma-import/import/converters/frame.js +15 -6
  53. package/dist/taco/figma-import/import/converters/gradient.d.ts +2 -0
  54. package/dist/taco/figma-import/import/converters/gradient.js +3 -1
  55. package/dist/taco/figma-import/import/converters/grid.d.ts +12 -0
  56. package/dist/taco/figma-import/import/converters/grid.js +97 -0
  57. package/dist/taco/figma-import/import/converters/group.d.ts +2 -4
  58. package/dist/taco/figma-import/import/converters/group.js +6 -15
  59. package/dist/taco/figma-import/import/converters/image.d.ts +2 -1
  60. package/dist/taco/figma-import/import/converters/image.js +60 -16
  61. package/dist/taco/figma-import/import/converters/layout.d.ts +8 -7
  62. package/dist/taco/figma-import/import/converters/layout.js +66 -37
  63. package/dist/taco/figma-import/import/converters/rectangle.d.ts +1 -1
  64. package/dist/taco/figma-import/import/converters/rectangle.js +3 -3
  65. package/dist/taco/figma-import/import/converters/section.d.ts +2 -3
  66. package/dist/taco/figma-import/import/converters/section.js +5 -11
  67. package/dist/taco/figma-import/import/converters/shared.d.ts +9 -5
  68. package/dist/taco/figma-import/import/converters/shared.js +23 -10
  69. package/dist/taco/figma-import/import/converters/text.d.ts +38 -1
  70. package/dist/taco/figma-import/import/converters/text.js +248 -32
  71. package/dist/taco/figma-import/import/converters/vector.d.ts +36 -15
  72. package/dist/taco/figma-import/import/converters/vector.js +214 -73
  73. package/dist/taco/figma-import/import/converters/vectorNetwork.d.ts +19 -3
  74. package/dist/taco/figma-import/import/converters/vectorNetwork.js +147 -29
  75. package/dist/taco/figma-import/import/instances.d.ts +32 -5
  76. package/dist/taco/figma-import/import/instances.js +613 -130
  77. package/dist/taco/figma-import/import/styles.d.ts +2 -0
  78. package/dist/taco/figma-import/import/styles.js +6 -0
  79. package/dist/taco/figma-import/import/types.d.ts +8 -0
  80. package/dist/taco/figma-import/import/variables.d.ts +5 -2
  81. package/dist/taco/figma-import/import/variables.js +65 -31
  82. package/dist/taco/figma-import/import/variantTrees.d.ts +1 -1
  83. package/dist/taco/figma-import/import/variantTrees.js +46 -4
  84. package/dist/taco/figma-import/import/walk.d.ts +62 -7
  85. package/dist/taco/figma-import/import/walk.js +328 -122
  86. package/dist/taco/figma-import/kiwi/message.d.ts +4 -2
  87. package/dist/taco/figma-import/kiwi/message.js +59 -15
  88. package/dist/taco/model/codec.d.ts +2 -2
  89. package/dist/taco/model/codec.js +72 -8
  90. package/dist/taco/model/component-evaluation.d.ts +2 -0
  91. package/dist/taco/model/component-evaluation.js +7 -0
  92. package/dist/taco/model/instance-resolver.d.ts +6 -2
  93. package/dist/taco/model/instance-resolver.js +50 -18
  94. package/dist/taco/model/sha256.js +13 -8
  95. package/dist/taco/model/types.d.ts +57 -5
  96. package/dist/taco/model/types.js +4 -0
  97. package/dist/taco/svg-import/style/computed.js +1 -0
  98. package/package.json +3 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,49 @@
1
1
  # Changelog
2
2
 
3
+ ## Unreleased
4
+
5
+ ## 0.3.0 — 2026-11-27
6
+
7
+ - The peer dependency on `@moondraft/editor` is now `>=0.5.0 <0.6.0`. Install the editor 0.5.0 or later in the
8
+ 0.5 line.
9
+
10
+ - The import report says why each Figma instance stays expanded into plain layers ("expanded instance: its content draws outside its box" and so on), one entry per reason.
11
+ - Figma variant choices bound to a variable (`RESOLVE_VARIANT` expressions) stay bound on instances and in instance overrides, so imported instances switch variant with the mode; a visibility bound through `IS_TRUTHY` keeps its boolean variable. A variant binding on a layer that is not an instance, or one naming a property its set lacks, is still reported.
12
+ - Saved Figma files import with less memory again: equal decoded GUIDs, vectors, matrices and colors share one object, the derived pass skips the editing index of component occurrences, and the derived document hands over its records instead of copying them. Output is unchanged.
13
+ - Saved Figma files use less memory and time to import: decoded node records are compact, each vector network is converted once for every layer that shows it, and the derived document is handed over without a second copy. Output is unchanged.
14
+ - Figma truncation: a linked instance keeps its own line limit and ellipsis as overrides, a derived line limit counts Figma's laid-out lines (the instance's own where it stores them), auto-height text with a maximum height gets a derived limit, an outer instance's truncation override reads against the inner instance's, and an override's unknown truncation is reported
15
+ - Figma export presets: an instance override that names its component by override key sets that instance's presets, a pasted variant's main takes the selected variant's presets, and every preset field the import cannot keep (SVG text outlines and ids, colour profile, JPEG quality, rows past 32 and the rest) is reported by field.
16
+ - Figma fill and stroke paints keep their blend modes, linear dodge and linear burn included, instead of dropping them.
17
+
18
+ ## 0.2.0 — 2026-11-27
19
+
20
+ ### Highlights
21
+
22
+ - Imports keep text hyperlinks, OpenType features, layout grids, per-layer export settings and variable scopes.
23
+ - Instance overrides resolve through nested swaps, and imports of large Figma files are faster and use less memory.
24
+
25
+ ### Added
26
+
27
+ - Import text hyperlinks, OpenType feature toggles and variants, text truncation and line limits, and text colour
28
+ bindings and paint-style links.
29
+ - Import frame layout grids and grid styles, per-layer export settings, boolean operations, page dividers, canvas
30
+ stacking, image fill crops, flipped instances, legacy rectangles, variable font axes and handoff metadata.
31
+ - Keep variable scopes, code syntax and descriptions, independent stroke-side and corner bindings, vector region
32
+ fills, and caps on every open vector end. Open vector networks are filled.
33
+ - Instances keep overrides for clipping, corner smoothing and auto layout.
34
+
35
+ ### Changed
36
+
37
+ - The peer dependency on `@moondraft/editor` is now `>=0.4.0 <0.5.0`. Install the editor 0.4.0 or later in the
38
+ 0.4 line.
39
+ - Import reports group repeated entries.
40
+ - Large Figma imports run in about half the time and use less memory.
41
+
42
+ ### Fixed
43
+
44
+ - Import angle-based linear gradients again, and prop overrides only on nested instances.
45
+ - Resolve overrides through nested instance swaps and report swaps that the nesting check rejects.
46
+
3
47
  ## 0.1.0
4
48
 
5
49
  - Import SVG files and markup, and Figma clipboard content, as editable layers.
package/README.md CHANGED
@@ -25,10 +25,10 @@ To convert a saved Figma design in Node, save this as `convert.mjs` and run `nod
25
25
 
26
26
  ```js
27
27
  import { readFile, writeFile } from 'node:fs/promises'
28
- import { openFigmaFile } from '@moondraft/import'
28
+ import { openFigmaFile, serializeImportDocument } from '@moondraft/import'
29
29
 
30
30
  const { document, report } = await openFigmaFile(await readFile('design.fig'))
31
- await writeFile('design.json', JSON.stringify(document))
31
+ await writeFile('design.json', serializeImportDocument(document))
32
32
  console.log(report)
33
33
  ```
34
34
 
package/SOURCE.md CHANGED
@@ -36,8 +36,12 @@ node packages/import/scripts/sync-taco.mjs [taco-packages-dir]
36
36
  ```
37
37
 
38
38
  The script deletes `src/taco` and `test/taco`, copies the files again, makes the rewrites below and then applies
39
- `patches/*.patch` in order with `git apply`. On an unchanged source the tree comes out the same as before. If a patch
40
- no longer applies, the sync stops there: update the patch and this log.
39
+ `patches/*.patch` in sorted filename order with `git apply`. On an unchanged source the tree comes out the same as
40
+ before. If a patch no longer applies, the sync stops there. Update the patch and this log.
41
+
42
+ At merge time, give each new patch the next free number after the last patch on `main` and update this log.
43
+ Before merging, run the sync in a clean checkout against the pinned source commit. The replay must succeed and
44
+ reproduce the checked-in `src/taco/` and `test/taco/` byte for byte, with no missing or extra files.
41
45
 
42
46
  ### Mechanical rewrites (made by the script, not patches)
43
47
 
@@ -52,6 +56,8 @@ no longer applies, the sync stops there: update the patch and this log.
52
56
 
53
57
  ## Local patches
54
58
 
59
+ Quoted patch numbers in copied test markers retain the numbers used when those tests were written.
60
+
55
61
  ### `patches/0001-parameter-properties-as-fields.patch`
56
62
 
57
63
  This repo compiles with `erasableSyntaxOnly`, and Node's type stripping refuses TypeScript parameter properties
@@ -135,14 +141,242 @@ would change its aspect-ratio fit. The path and its paint share the image's orig
135
141
 
136
142
  The SVG and Figma linear-gradient converters retain the original stops and unit-box endpoints for on-canvas editing. Under a shear, the axis follows the transformed gradient normal in local pixels. Layer gradients require both endpoints. For flat SVG geometry the importer preserves the gradient slope and offset along the surviving axis. A flat shape perpendicular to the gradient takes the colour sampled at its position. Layer syntax resolves an authored CSS angle when the owning layer supplies its paint box. The gradient expectations in the copied tests use the endpoint representation.
137
143
 
138
- ### `patches/0005-portable-font-style.patch`
144
+ ### `patches/0006-portable-font-style.patch`
139
145
 
140
146
  Carry the original Figma face style name through the intermediate text style and its codec into editor text palettes.
141
147
 
142
- ### `patches/0006-native-figma-file.patch`
148
+ ### `patches/0007-native-figma-file.patch`
143
149
 
144
150
  The saved-file adapter reads each original variant tree, property declaration, variable alias and style definition before conversion to literals. The reader carries the source paint and effect indexes, font-size bindings and authored override paths needed to associate those definitions with their native layer fields. The reader checks reachable variable values for copied paint alpha and valid text metrics. An explicit instance paint also replaces its inherited style reference. Unpublished resources reuse the model’s synchronous SHA-256 implementation, extended to accept file bytes. Clipboard imports continue to use the literal reader.
145
151
 
152
+ ### `patches/0008-report-noise.patch`
153
+
154
+ Fewer repeated report entries from component property defs. A deleted def (Figma keeps an id alone, or an id that
155
+ points at a removed set def) is skipped without a report instead of being reported as an unknown property type. A
156
+ def's dropped preferred values are reported for the first symbol that reads it only, not again for each variant of
157
+ its set: `propertiesOf` takes a set of reported defs that the walk shares across symbols. Two tests in the copied
158
+ `convert-instance.test.ts` cover this, each marked "Moondraft patch 0007".
159
+
160
+ ### `patches/0009-text-truncation.patch`
161
+
162
+ Figma's ending truncation becomes the text's `truncate: "ellipsis"`, and its line limit `maxLines`. A fixed-size box without a limit ends at the lines its height holds. Instance overrides carry both; `null` takes the component's away. The intermediate text node and layer override gain the two optional fields, which the codec checks and the instance resolver applies.
163
+
164
+
165
+ ### `patches/0010-repeated-collection-names.patch`
166
+
167
+ The native file reader keeps the Figma name of each variable collection, even when two collections share one. Native
168
+ records name a collection by its id, as Figma does, so numbering the second one ("Theme 2") only changed its name on
169
+ export and round trip. The literal reader still numbers a repeated name, because its `var('collection/name')`
170
+ expressions need distinct names. `test/editor-hook.test.ts` covers two same-name collections with bound layers.
171
+
172
+ ### `patches/0011-live-boolean-groups.patch`
173
+
174
+ A Figma `BOOLEAN_OPERATION` that Moondraft's boolean group can stand for (`liveBooleanOf` in `converters/vector.ts`:
175
+ union, subtract, intersect or exclude; a transform that only moves and turns; not filling its auto layout parent, and in
176
+ an auto layout flow only where its operands fill its box; shown operands that are shapes, nested boolean operations or
177
+ groups of those; regions not painted apart) becomes a frame holding its operands, which the walk imports as layers. The
178
+ frame carries its operation and the `fillGeometry` outline (in its own space) in `metadata.figma.boolean`, which also
179
+ splits clipboard variants (`variantTrees.ts`);
180
+ the adapter (`src/adapter/convert.ts`) makes it a boolean group whose first result is that outline. "In an auto layout
181
+ flow" means placed by a stack or grid the walk imported, and a nested
182
+ boolean operation counts with its operands' box, as the adapter fits it. One with no outline is kept live anyway (the
183
+ renderer cuts its result); in a flow where its operands do not fill its box it carries `fixedBox`, and the adapter puts
184
+ it in a plain frame of its own box. Any other is
185
+ flattened as before, and its report line gives the reason. Changed expectations in `convert-vector.test.ts` and
186
+ `convert-instance.test.ts` are marked "Moondraft patch 0010".
187
+
188
+ ### `patches/0012-vector-stroke-caps.patch`
189
+
190
+ The Figma vector reader carries a map of cap overrides by open vertex ID in `metadata.figma.vectorStrokeCaps`.
191
+ An open vertex uses its own override, then the override on its incident segment, then the node's cap. The
192
+ reader still reports unknown cap values and style overrides without an open endpoint. A horizontal vector
193
+ that becomes a stretchable line keeps each override on its original end. Clipboard variant merging keeps
194
+ different override maps on separate layers. Vector arrowheads use the existing endpoint cap types and Figma's
195
+ dash cap stays separate.
196
+
197
+ ### `patches/0013-strokes-in-layout.patch`
198
+
199
+ Horizontal and vertical Figma frames with `bordersTakeSpace` carry `metadata.figma.strokesIncluded`. The adapter
200
+ sets `layoutData.layout.strokesIncluded` so inside stroke widths affect child placement and sizing. Clipboard variants
201
+ keep distinct layers when the setting differs.
202
+
203
+ ### `patches/0014-first-on-top.patch`
204
+
205
+ The Figma reader carries `stackReverseZIndex: true` on imported horizontal and vertical stacks as
206
+ `metadata.figma.firstOnTop`. Clipboard variant merges keep frames with different stacking separate. The adapter
207
+ writes the editor's `firstOnTop` frame property and preserves child order. A stack that falls back to free layout
208
+ still reports the omitted stacking setting.
209
+
210
+ ### `patches/0015-resized-instance-layout.patch`
211
+
212
+ The saved-file reader carries `derivedSymbolData` boxes for resized instances of free-layout components. It resolves
213
+ layer paths through nested instances, uses the authored or component value for an omitted size or transform, and
214
+ adjusts local transforms when the reader fits groups. The native adapter places the layers at those boxes, and the
215
+ linker stores the differences as existing geometry overrides where it can link the instance.
216
+
217
+ ### `patches/0016-figma-handoff-metadata.patch`
218
+
219
+ Expose the reader's original node relationships to the clipboard adapter. The adapter uses them for both file
220
+ and clipboard import to store Figma annotations, measurements and development status in `data.figma`. Clipboard
221
+ variant merges keep layers with handoff metadata distinct, and copies inside hidden mains keep their source
222
+ instance IDs. Active layer status takes precedence over the canvas map. The adapter reports metadata omitted from
223
+ skipped subtrees, and the reader reports active annotations and measurements in instance overrides, including
224
+ overrides of the instance root.
225
+
226
+ ### `patches/0017-group-and-vector-fill.patch`
227
+
228
+ The Figma reader carries main-axis grow and cross-axis stretch on non-rotated, aspect-unlocked groups and
229
+ paths in non-wrapping stacks, together with the size limits of paths that fill, as `metadata.figma.fillSizing`.
230
+ The adapter maps them to the editor's `layoutData.resizing`. The reader reports other requested group and path fill.
231
+ Groups carry their own resize constraints as `metadata.figma.groupConstraints` where constraints apply,
232
+ and the adapter writes them to `layoutData.constraints`. Clipboard variants with different carried sizing
233
+ or constraints keep distinct layers. A path with zero extent on a requested axis keeps its size on that
234
+ axis and the reader reports the omission. Its other axis can still fill. The adapter keeps a small positive
235
+ minimum on group fill axes so scale-constrained children can recover after a stack collapses.
236
+
237
+ ### `patches/0018-image-fill-crops.patch`
238
+
239
+ The Figma reader carries non-identity STRETCH image-fill matrices on the imported paints. The crop travels with each
240
+ paint through instance overrides, and clipboard variants with different cropped fills retain distinct layers. The
241
+ adapter inverts the layer-to-image mapping and writes the editor's existing image paint transform. It uses stretch
242
+ for crop axes that scale equally relative to the box and cover for crops that retain the image's aspect ratio.
243
+ The importer reports crops the paint transform cannot represent, such as reflections and shears.
244
+
245
+ ### `patches/0019-nested-instance-swaps.patch`
246
+
247
+ The Figma reader follows explicit swaps authored by enclosing instances when resolving an override path. It uses the
248
+ outermost applicable swap and follows swap property assignments on the replacement. If rejecting a swap changes
249
+ a dependent path, the reader checks any newly exposed swap edges for cycles. Unresolved entries are
250
+ counted individually. The report distinguishes missing source GUIDs or override keys from paths that have no layer
251
+ in the shown component, and identifies nested slot assignments that lack an imported declaration or bound frame.
252
+ The reader retains swap assignments that a different variant can bind. After rejecting a swap that changes which
253
+ slot hosts a component owns, it checks the refreshed nesting edges before accepting the remaining swaps.
254
+
255
+ ### `patches/0020-vector-region-fills.patch`
256
+
257
+ Resolve the style IDs of vector network regions and fallback `fillGeometry` paths through the vector style table.
258
+ Keep explicit empty paint lists and inherit the layer's fills when a region has no override. Region gradients use
259
+ the region bounds, while inherited gradients use the combined path bounds. The adapter keeps the editable network
260
+ and writes its own paints to `Region.fills`, including image tiling carried on the paints.
261
+
262
+ ### `patches/0021-fill-open-vector-networks.patch`
263
+
264
+ For a filled Figma vector network with no stored regions, the reader walks its segments into subpaths, ending
265
+ each chain where it reaches a junction or an endpoint. The subpaths share one nonzero fill region. Open loops
266
+ use the existing `implicitClose` flag so the fill closes without adding a segment to the stroke. Synthetic
267
+ tests cover separate subpaths, a cubic, and chains meeting at a junction.
268
+
269
+ ### `patches/0022-legacy-rectangles.patch`
270
+
271
+ The Figma reader sends legacy `RECTANGLE` nodes through the same editable rectangle converter as `ROUNDED_RECTANGLE`.
272
+
273
+ ### `patches/0023-frame-layout-grids.patch`
274
+
275
+ The Figma reader keeps grid style definitions available for lookup by GUID or library key. It skips them when
276
+ walking layers and recognizes grid-bearing frames in the group heuristic. Clipboard variants retain distinct
277
+ grid-bearing layers. The adapter writes each frame's guides to `layoutGrids` and reports shared grid styles
278
+ when it inlines their grids onto frames.
279
+
280
+ ### `patches/0024-reduce-import-allocations.patch`
281
+
282
+ The Kiwi decoder sizes short arrays up front and checks duplicate message fields against the record it is building.
283
+ Saved-file conversion reuses component computations while releasing each resolved occurrence tree after use.
284
+ Style and variable lookups retain their indexes without keeping the reader’s image callback and temporary tables alive.
285
+ The synchronous SHA-256 fallback reads full blocks from the input and allocates only the final padding blocks.
286
+
287
+ ### `patches/0025-stable-fill-layout.patch`
288
+
289
+ The file reader retains explicit vector sizes from instance layout when the imported path fills its stack.
290
+ It resolves each stored path through component swaps and checks fill eligibility after the stack is finalized.
291
+ The adapter holds conflicting stored allocations and lays out the remaining siblings. For groups it enables
292
+ a fill axis only when the children scale to its fitted bounds, with a minimum large enough to preserve
293
+ smaller paths through collapse. A multi-paint path and its painted regions scale together when their opacity wrapper resizes.
294
+
295
+ ### `patches/0026-vector-region-fill-review.patch`
296
+
297
+ Resolve and bound the combined region paint lists and gradient stops before converting any of them. If the
298
+ renderer limit is exceeded, keep the network, inherit the layer paints, and report the fallback. Detached
299
+ styles without a fill list also inherit. Outline styles report unused fields. Clipboard variants compare region
300
+ image placements, and the adapter keeps region-only assets, places crops using the stored layer size and
301
+ the combined region bounds, and isolates opacity for translucent paths with multiple authored regions.
302
+
303
+ ### `patches/0027-stored-fill-allocations.patch`
304
+
305
+ The file reader tracks explicit group and vector fill sizes separately from free-layout geometry. The adapter
306
+ uses these sizes in the placing instance’s scale and reconciles enclosing stacks before their descendants.
307
+
308
+ ### `patches/0028-variable-descriptions.patch`
309
+
310
+ Remove the Figma reader's loss report for variable descriptions. The saved-file adapter reads the description from
311
+ the original variable record, alongside the component, variant set and style descriptions.
312
+
313
+ ### `patches/0029-reduce-file-import-work.patch`
314
+
315
+ The Kiwi reader lets the file adapter compact each root array record immediately after decoding it.
316
+ Vector paint bounds are measured when a gradient needs them. The instance resolver can return
317
+ content, overrides and slot selections
318
+ before layout for the saved-file adapter, which computes its own geometry.
319
+
320
+ ### `patches/0030-figma-export-settings.patch`
321
+
322
+ Read ordered Figma export presets into the layer's `exportSettings` list for file and clipboard import. An instance
323
+ keeps its own presets, including ones stored on its root override. Report preset changes and clears on inherited
324
+ layers, which the editor's instance override schema cannot express.
325
+
326
+ ### `patches/0031-figma-variable-scopes.patch`
327
+
328
+ Skip the scope omission report for native saved-file imports. The adapter reads scopes and platform code syntax
329
+ from the original variable records. The reader still uses scopes to convert opacity units and reports scope
330
+ omissions in its literal import path.
331
+
332
+ ### `patches/0032-text-colour-variables.patch`
333
+
334
+ The saved-file reader identifies the variable on the solid paint drawn by each text run and retains
335
+ independent paint opacity. The adapter uses this provenance when building the native palette.
336
+
337
+ ### `patches/0033-figma-opentype-features.patch`
338
+
339
+ Read Figma's OpenType toggle lists and typography switches into each run's `openTypeFeatures`.
340
+ The reader keeps them on shared typography and instance overrides. An empty run override clears
341
+ inherited settings. The editor adapter converts the settings to numeric feature values for shaping.
342
+
343
+ ### `patches/0034-text-hyperlinks.patch`
344
+
345
+ Carry URL and GUID links on Figma text runs. Range overrides can replace or clear a layer link. Text component
346
+ assignments preserve inherited links on ranges without a hyperlink field and write explicit clears. A paint
347
+ override supplies the palette for links on assigned text. Evaluating
348
+ an unchanged characters property keeps the source's linked ranges. The adapter accepts HTTP, HTTPS and mailto
349
+ URLs. File and clipboard import resolve pending GUIDs to native layers and pages. The public page converter
350
+ omits and reports GUID destinations when it lacks the Figma source lookup. A saved instance that inherits its
351
+ text palette follows the main’s links and colour bindings. The importer reports each omitted instance link
352
+ override. An instance with an explicit paint keeps the links in its imported palette.
353
+
354
+ ### `patches/0035-text-paint-styles.patch`
355
+
356
+ The saved-file reader carries the fill style GUID of each text run through conversion. An explicit
357
+ range paint replaces the layer's style. Paint styles authored by an instance override are marked so
358
+ the native adapter can keep the resolved colour and report the lost link.
359
+
360
+ ### `patches/0036-independent-edge-bindings.patch`
361
+
362
+ The saved-file adapter reads independent corner radius and stroke side bindings from the source records.
363
+ The vendored reader leaves those fields to the adapter, including groups previously collapsed into a
364
+ single binding. The literal reader retains its existing handling.
365
+
366
+ ### `patches/0037-instance-frame-overrides.patch`
367
+
368
+ The Figma reader keeps per-instance clipping, corner smoothing and stack settings on the affected
369
+ component layer or root. The vendored resolver composes the layout members across nested instances.
370
+
371
+ ### `patches/0038-grid-auto-layout.patch`
372
+
373
+ The reader joins grid track sizing to Figma's ordered row and column IDs. It keeps the tracks,
374
+ gaps and instance layout overrides in the frame layout, and carries child anchors, spans and
375
+ alignment in `metadata.figma.gridCell` for the editor layout engine. An unsupported sizing
376
+ function or unresolved anchor produces a diagnostic naming the affected field. Instance sizing
377
+ uses the inherited track IDs, and a reordered axis remaps the child anchors that still inherit
378
+ their GUIDs. If a visible flow child is missing, the frame keeps the remaining source positions.
379
+
146
380
  ## Code and data from elsewhere
147
381
 
148
382
  - **VS Code themes (MIT).** taco's model adapts the Code - OSS `2026-dark` / `2026-light` colour themes in `code.ts`.
@@ -167,3 +401,108 @@ The saved-file adapter reads each original variant tree, property declaration, v
167
401
  type-checked: they need Node's types, which this repo does not install.
168
402
  - `npm run test:import` runs the copied tests (svg-import 1,418 and figma-import 755, about 25 s). It is not part of
169
403
  `npm test`.
404
+
405
+ ### `patches/0039-figma-video-fills.patch`
406
+
407
+ The reader resolves a VIDEO paint’s video hash from the archive and carries its poster through the existing image placement conversion. When the media is missing, it retains the available image and reports the substitution. An embedded thumbnail takes precedence over a clipboard placeholder. A poster supplied by a later fill is shared by every use of that clip.
408
+
409
+ ### `patches/0040-text-typography-variables.patch`
410
+
411
+ The saved-file reader tracks the source of each typography field through shared styles, text ranges and instance
412
+ overrides. A nested instance applies its inner text bindings before the enclosing instance’s overrides.
413
+ The adapter writes supported bindings into the native text palette, preserving percentage tracking
414
+ and pixel leading. Older editor peers keep the resolved literals for unsupported bindings. A saved instance
415
+ keeps its stored line height when it differs from the main’s, and resolved leading sizes fixed-text line limits and auto-height line counts.
416
+
417
+ A layer's typography binding stored beside a linked text style is stale (Figma detaches the style when a field is
418
+ bound), so the style's binding or literal wins unless an instance override sets or binds that field itself. An
419
+ instance that binds its own line height or font size draws at the token rather than its stored line height.
420
+ The bindings an instance override authors itself (its own variable map, or its own range table) are marked on each
421
+ run (`fileOwnTypography`), so an override that binds the main's own variable stays the occurrence's own binding.
422
+
423
+ ### `patches/0041-linear-blend-modes.patch`
424
+
425
+ The model's `BLEND_MODES` gains `plus-lighter` and `plus-darker` (codes 16 and 17, after luminosity, so the list
426
+ still follows the renderer's codes). A layer in Figma's `LINEAR_DODGE` or `LINEAR_BURN` takes them instead of a
427
+ "has no Taco equivalent" report; a paint or shadow in those modes is still reported, as before.
428
+ The SVG reader accepts `mix-blend-mode: plus-lighter` and `plus-darker` on an element the same way.
429
+
430
+ ### `patches/0042-figma-export-preset-fields.patch`
431
+
432
+ An instance override path of one step names the component's root by its guid or by its `overrideKey`; either way
433
+ its export presets are the instance's own (a path by override key still overrides the root's other fields). Export row fields a Taco row has no counterpart for
434
+ (`svgOutlineText`, `svgDataName`, `svgForceStrokeMasks`, `useAbsoluteBounds`, `colorProfile`, `quality`,
435
+ `useBicubicSampler`, `pdfPrint`) are reported by field when they hold a value that changes the row's format's file,
436
+ for the first 32 rows only: the adapter reports each later row whole.
437
+
438
+ ### `patches/0043-figma-text-case.patch`
439
+
440
+ Read Figma's `textCase` into each run's `textCase` (`upper`, `lower`, `title`, `smallCaps`, `smallCapsForced`) instead
441
+ of reporting it as left out. A layer or range case beats its shared typography's, and a run linked to a cased style
442
+ that draws as typed overrides it with `original`. The characters stay as typed; the editor adapter keeps the case on
443
+ the native text style, which the renderer applies to the drawn glyphs. An unknown case is still reported.
444
+
445
+ ### `patches/0044-negative-shadow-spread.patch`
446
+
447
+ The renderer now shrinks drop shadows and grows inner shadows' holes by a negative spread on every shape, so the
448
+ reader keeps a negative spread on every drop and inner shadow instead of writing 0 and reporting it.
449
+ `drawnAsPlainRectangle` and the `plainRectangle` argument of `nodeEffects` are gone with that rule.
450
+
451
+ ### `patches/0045-paint-blend-modes.patch`
452
+
453
+ A fill or stroke paint in Figma's `LINEAR_DODGE` or `LINEAR_BURN` takes `plus-lighter` or `plus-darker`, as a layer
454
+ does, instead of a "has no Taco equivalent" report; a shadow in those modes is still reported. The model's paint
455
+ `blendMode` is documented as blending with the layers behind too, as Figma draws it.
456
+
457
+ ### `patches/0046-truncation-overrides.patch`
458
+
459
+ The line limit derived for a fixed-size text box, or for auto-height text with a maximum height, counts the lines that
460
+ fit that height from Figma's laid-out lines (each at its own `lineY` and `lineHeight`, so uneven line heights and
461
+ paragraph spacing count), then lines of the last one's height below them; without laid-out lines every line is the
462
+ first run's height, as before. An instance text counts the lines its own `derivedSymbolData` entry stores, or its
463
+ own first line where an override sets its lines otherwise (line height, size, style, characters) and stores none.
464
+ An outer instance's truncation override is read against what the inner instance it goes through shows (its
465
+ `textTruncation` and `maxLines` join the inner fields), so the model's `mergeOverrides` (outer on top) resolves it.
466
+ An override's truncation other than `DISABLED` or `ENDING` is reported and left out, so the layer keeps its component's.
467
+
468
+ ### `patches/0047-figma-report-counts.patch`
469
+
470
+ A reason the reader says once with a count keeps its plain wording and carries the count in the entry's new `count`
471
+ field, instead of ending in "(N times, first here)", so the editor adapter reads the number without parsing the text.
472
+ Instance overrides' Dev Mode annotations and measurements are skipped without a report: the editor adapter reports them
473
+ on the instance with the layer's own annotations (`figmaHandoff`), not as unimported override fields.
474
+
475
+ ### `patches/0048-kiwi-fast-messages.patch`
476
+
477
+ The kiwi decoder returns a copy of each decoded message. It writes a message's fields by computed name, and V8 stores
478
+ an object written that way with more than a few fields as a hash table; the copy has fast properties. A node change
479
+ takes about a fifth of the memory, which cuts the decoded tree of a layer-heavy file by about 100 MB. Values are
480
+ unchanged.
481
+
482
+
483
+ ### `patches/0050-kiwi-shared-structs.patch`
484
+
485
+ The kiwi decoder shares one frozen object between equal structs made only of numbers (`GUID`, `Vector`, `Matrix`,
486
+ `Color`, `Rect` and the like), keyed by their field values in order (a varfloat never decodes to -0, so map keys lose nothing). A layer-heavy file
487
+ repeats a few thousand such values hundreds of thousands of times; sharing them cuts the decoded tree of the
488
+ ~50,000-layer file from about 270 MB to about 190 MB. Values are unchanged; nothing downstream writes to a decoded struct.
489
+
490
+ ### `patches/0051-derived-text-sizes.patch`
491
+
492
+ An instance keeps, for the editor adapter, the box Figma measured each self-sizing text at (`fileLayout`'s `texts`, from
493
+ the instance's `derivedSymbolData`), so a document loads at Figma's text sizes without the document's fonts. An entry
494
+ with the text's glyphs (`derivedTextData`) and no size is a text Figma measured at the size a nested instance, else its
495
+ component, gives it (`inner`): the adapter takes an inner level's stored box over it.
496
+
497
+ ### `patches/0052-nested-override-paths.patch`
498
+
499
+ Override paths resolve through nested and swapped instances in three more cases. A layer whose `overrideKey` is Figma's
500
+ no-key marker (both halves `0xFFFFFFFF`) is named by its guid, as override paths name it; before, every such layer of a
501
+ component shared the marker as its key, so paths through them missed or reached the first one. An instance's own
502
+ instance swap property value on a nested instance outranks a swap that a nested instance authored below it, as Figma
503
+ draws it; where the two differ, the value is also written as the instance's swap override, since the model's
504
+ `mergeOverrides` lets a swap override win over a property value. This holds for every swap-bound layer the value
505
+ reaches, whether or not a deeper override path goes through it. A property value that names a property the shown
506
+ component does not declare goes to the shallowest nested instances whose shown component (after swaps) declares it,
507
+ read against that component, but only where the instance's `derivedSymbolData` lays out a layer bound to that property
508
+ inside the nested instance (Figma ignores a stale value); any other such value is still reported.
@@ -1,4 +1,5 @@
1
- import type { DocumentJSON, TextStyle } from '@moondraft/editor/schema';
1
+ import { type DocumentJSON, type TextStyle } from '@moondraft/editor/schema';
2
+ import type { StoredFigmaBox } from '../taco/figma-import/import/instances.ts';
2
3
  import { type LinkCounts } from './link.ts';
3
4
  /** A taco document as JSON (schemaVersion 0.44.0): pages, nodes, components, theme and assets, read loosely. */
4
5
  export interface TacoDocument {
@@ -17,6 +18,12 @@ export interface TacoDocument {
17
18
  components: Record<string, any>;
18
19
  /** Placement layer IDs by component ID. */
19
20
  componentPlacements?: Readonly<Record<string, string>>;
21
+ /** Direct file aliases by variable and mode, used to resolve plain text overrides. */
22
+ variableAliases?: ReadonlyMap<string, ReadonlyMap<string, string>>;
23
+ /** Stored Figma boxes by instance ID and layer path, for saved files. */
24
+ instanceBoxes?: ReadonlyMap<string, ReadonlyMap<string, StoredFigmaBox>>;
25
+ /** Sizes saved for flow children, in the placing instance's coordinates. */
26
+ instanceFillSizes?: ReadonlyMap<string, ReadonlyMap<string, StoredFigmaBox>>;
20
27
  /** Source image assets by ID. */
21
28
  assets?: Record<string, any>;
22
29
  /** Theme metadata used to resolve variables and modes. */
@@ -36,6 +43,10 @@ export interface ConvertOptions {
36
43
  kitFixes?: boolean;
37
44
  /** The document's `source` header (the source file's name). */
38
45
  source?: string;
46
+ /** Receives the original reader IDs of expanded instance roots, keyed by converted model ID.
47
+ * @internal
48
+ */
49
+ instanceSources?: Map<string, string>;
39
50
  /**
40
51
  * Resolves the URL for an imported image. Defaults to `assets/<id>.<ext>`.
41
52
  * @param id - Imported asset ID.
@@ -109,14 +120,27 @@ export declare function toDocument(doc: TacoDocument, pageRef: string | number,
109
120
  /** Conversion diagnostics and the page's image assets. */
110
121
  report: ConvertReport;
111
122
  };
123
+ /** Converts the clipboard selection for the Figma adapter's subsequent GUID resolution pass. @internal */
124
+ export declare function figmaClipboardPage(doc: TacoDocument, instanceSources: Map<string, string>): {
125
+ doc: DocumentJSON;
126
+ report: ConvertReport;
127
+ };
112
128
  /** Converts all file pages and keeps the appearance of each linked occurrence.
113
129
  * @param doc - Source document.
114
130
  * @param options - Asset and conversion settings.
115
- * @returns Linked document, conversion report and the pre-link instance literals.
131
+ * @returns Linked document, conversion report, pre-link literals and nested boolean assignments.
116
132
  * @internal
117
133
  */
118
134
  export declare function allPages(doc: TacoDocument, options: ConvertOptions): {
135
+ omittedLinks: Map<string, Set<string>>;
136
+ /** Per instance left expanded, by its layer ID: why linking could not keep it an instance (link.ts tryLink). */
137
+ expandedReasons: Map<string, string>;
119
138
  expanded: Map<string, any>;
139
+ nestedBooleans: Map<string, NestedBooleanAssignments>;
120
140
  doc: DocumentJSON;
121
141
  report: ConvertReport;
122
142
  };
143
+ export interface NestedBooleanAssignments {
144
+ componentId: string;
145
+ values: Record<string, boolean>;
146
+ }