@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
@@ -1,11 +1,17 @@
1
1
  import { constrainChildren, entryOf, formatExpressionName, getNodeBounds, layerPathKey, paragraphsFromCharacters, parseLayerPath, PROPERTIES_DROPPED_BY_FIELD, TEXT_STYLE_PROPERTIES, } from "../../model/index.js";
2
+ import { gridAxis, gridCell, gridChildFields } from "./converters/grid.js";
3
+ import { autoLayoutOf } from "./converters/layout.js";
4
+ import { withImageCrop } from "./carry.js";
2
5
  import { field, guidText, isObject } from "./fields.js";
3
6
  import { isDetachedStyle, STYLE_REFERENCE_FIELDS, styleBackedList } from "./styles.js";
4
7
  import { assignedPropertyValues, assignedValueOf, propertyByFigmaId } from "./componentProps.js";
5
- import { readNumbers, STROKE_CAPS } from "./converters/shared.js";
6
- import { KEPT_LINE_HEIGHT_FIELD } from "./converters/text.js";
8
+ import { frameGeometry, readNumbers, STROKE_CAPS } from "./converters/shared.js";
9
+ import { hyperlinkOf, inheritOpenTypeToggles, KEPT_LINE_HEIGHT_FIELD, LAID_OUT_LINES_FIELD, OWN_TYPOGRAPHY, TEXT_VARIABLE_FIELDS, OPEN_TYPE_FIELDS, OPEN_TYPE_TOGGLES } from "./converters/text.js";
10
+ import { exportSettingsOf } from "./converters/exportSettings.js";
7
11
  /** The `variableConsumptionMap` fields that bind each merged override field. */
8
12
  const BOUND_BY_OVERRIDE = {
13
+ fontName: ["FONT_FAMILY", "FONT_STYLE", "FONT_WEIGHT"], fontSize: ["FONT_SIZE"],
14
+ lineHeight: ["LINE_HEIGHT"], letterSpacing: ["LETTER_SPACING"],
9
15
  size: ["WIDTH", "HEIGHT"], visible: ["VISIBLE"], opacity: ["OPACITY"],
10
16
  strokeWeight: ["STROKE_WEIGHT", "BORDER_TOP_WEIGHT", "BORDER_RIGHT_WEIGHT", "BORDER_BOTTOM_WEIGHT", "BORDER_LEFT_WEIGHT"],
11
17
  };
@@ -37,9 +43,12 @@ function overriddenBindingFields(name, value, before) {
37
43
  * `change` with the `overridden` fields merged in and without the component's bindings of the fields they change:
38
44
  * Figma unbinds a field that an override sets, so the instance takes the override's value, not the component's variable.
39
45
  */
40
- function withOverrides(change, overridden) {
46
+ function withOverrides(change, overridden, replacesTextStyle) {
41
47
  const merged = { ...change, ...overridden };
42
48
  const unbound = new Set(Object.entries(overridden).flatMap(([name, value]) => overriddenBindingFields(name, value, change[name])));
49
+ if (replacesTextStyle)
50
+ for (const field of Object.keys(TEXT_VARIABLE_FIELDS))
51
+ unbound.add(field);
43
52
  const map = change["variableConsumptionMap"];
44
53
  if (unbound.size === 0 || !isObject(map) || !Array.isArray(map["entries"]))
45
54
  return merged;
@@ -108,6 +117,50 @@ function withBindingEntries(map, over) {
108
117
  const named = new Set(overEntries.map(fieldOf));
109
118
  return { ...isObject(map) ? map : {}, entries: [...entriesOf(map).filter((entry) => !named.has(fieldOf(entry))), ...overEntries] };
110
119
  }
120
+ const typographyFields = new Set(["styleIdForText", ...Object.values(TEXT_VARIABLE_FIELDS).map(([, name]) => name)]);
121
+ function typographyEntries(change) {
122
+ const map = change["variableConsumptionMap"];
123
+ if (!isObject(map) || !Array.isArray(map["entries"]))
124
+ return [];
125
+ return map["entries"].filter((entry) => isObject(entry) && typeof entry["variableField"] === "string" && Object.hasOwn(TEXT_VARIABLE_FIELDS, entry["variableField"]));
126
+ }
127
+ function hasRangeTypography(data) {
128
+ if (!isObject(data) || !Array.isArray(data["styleOverrideTable"]))
129
+ return false;
130
+ return data["styleOverrideTable"].some(range => isObject(range) &&
131
+ (Object.keys(range).some(name => typographyFields.has(name)) || typographyEntries(range).length > 0));
132
+ }
133
+ /** The typography already applied to this text by instances inside the one being converted. */
134
+ function innerTextFields(target, context) {
135
+ if (target.layer.node.type !== "text" || !context.nestedTextFields)
136
+ return;
137
+ let inherited;
138
+ for (let i = target.through.length - 1; i >= 0; i--) {
139
+ const { instance, inner } = target.through[i];
140
+ const change = context.nestedTextFields(instance, inner);
141
+ if (!change)
142
+ continue;
143
+ const fields = {};
144
+ for (const name of typographyFields)
145
+ if (name in change)
146
+ fields[name] = change[name];
147
+ // What the inner instance shows of the truncation, so an outer override reads against it (`mergeOverrides`).
148
+ for (const name of ["textTruncation", "maxLines"])
149
+ if (name in change)
150
+ fields[name] = change[name];
151
+ const data = change["textData"];
152
+ // A replacement range table can introduce bindings or remove ones on the underlying text.
153
+ if (data && (hasRangeTypography(data) || hasRangeTypography(inherited?.["textData"] ?? target.layer.figma.change["textData"])))
154
+ fields["textData"] = data;
155
+ const entries = typographyEntries(change);
156
+ if (!Object.keys(fields).length && !entries.length)
157
+ continue;
158
+ const base = { ...target.layer.figma.change, ...inherited };
159
+ const unbound = withOverrides(base, fields, fields["styleIdForText"] !== undefined);
160
+ inherited = { ...inherited, ...fields, variableConsumptionMap: withBindingEntries(unbound["variableConsumptionMap"], { entries }) };
161
+ }
162
+ return inherited;
163
+ }
111
164
  /**
112
165
  * Writes `null` in each override for a binding the model would keep from a nested instance's own override (`mergeOverrides`
113
166
  * in the model) of a field the override sets plainly. Runs once every instance has its overrides, since the nested instances
@@ -133,32 +186,60 @@ export function unbindInnerBindings(overrides, nested) {
133
186
  overrides[key] = { ...override, variableBindings: { ...override.variableBindings, ...nulls } };
134
187
  }
135
188
  }
136
- /** The key an override path step names a layer by: its `overrideKey`, else its guid. */
189
+ /** The `overrideKey` Figma writes on a layer that has none of its own (both halves `0xFFFFFFFF`). */
190
+ const NO_OVERRIDE_KEY = "4294967295:4294967295";
191
+ /** The key an override path step names a layer by: its `overrideKey`, else (none, or the no-key marker) its guid. */
137
192
  export function overrideKeyOf(node) {
138
193
  const key = node.change["overrideKey"];
139
- return key === undefined ? node.id : guidText(key, `node ${node.id} overrideKey`);
194
+ const text = key === undefined ? undefined : guidText(key, `node ${node.id} overrideKey`);
195
+ return text === undefined || text === NO_OVERRIDE_KEY ? node.id : text;
140
196
  }
141
197
  /**
142
198
  * Override fields whose effect the walk reads by converting the layer with
143
199
  * and without them (`convertAlone`): paints, strokes, effects and the styles that back them, visibility,
144
- * opacity, and a text layer's characters and style.
200
+ * opacity, and a text layer's characters, style and truncation.
145
201
  */
146
202
  const CONVERTED_FIELDS = new Set([
147
203
  "fillPaints", "strokePaints", "strokeWeight", "strokeAlign", "strokeJoin", "strokeCap", "dashPattern", "miterLimit",
148
204
  "borderStrokeWeightsIndependent", "borderTopWeight", "borderBottomWeight", "borderLeftWeight", "borderRightWeight", "effects",
149
205
  "styleIdForEffect", "styleIdForFill", "styleIdForStrokeFill", "visible", "opacity",
150
206
  "textData", "styleIdForText", "fontName", "fontSize", "lineHeight", "letterSpacing", "textAlignHorizontal", "paragraphSpacing", "listSpacing", "textCase", "textDecoration", "fontVariations", "hyperlink",
207
+ "cornerSmoothing", "textTruncation", "maxLines", ...OPEN_TYPE_FIELDS,
151
208
  ]);
152
- /**
153
- * Override fields of an auto layout frame's own Hug or Fixed size, read like
154
- * `CONVERTED_FIELDS` and written as `LayerOverride.sizing` (see `sizingBetween`):
155
- * on a frame layer, and on a nested instance layer under the path of the root
156
- * of the component it shows. On any other layer they stay reported.
157
- */
158
- const SIZING_FIELDS = new Set(["stackPrimarySizing", "stackCounterSizing"]);
209
+ /** Fields applied to a frame or to the component root shown by a nested instance. */
210
+ const STACK_FIELDS = { gap: "stackSpacing", align: "stackCounterAlignItems", justify: "stackPrimaryAlignItems",
211
+ wrap: "stackWrap", wrapGap: "stackCounterSpacing", alignContent: "stackCounterAlignContent" };
212
+ const GRID_FIELDS = { columns: "gridColumns", columnTracks: "gridColumnsSizing", rowTracks: "gridRowsSizing",
213
+ columnGap: "gridColumnGap", rowGap: "gridRowGap" };
214
+ const FRAME_FIELDS = new Set(["stackPrimarySizing", "stackCounterSizing", "stackMode", ...Object.values(STACK_FIELDS), "gridRows", ...Object.values(GRID_FIELDS),
215
+ "frameMaskDisabled", "cornerSmoothing"]);
216
+ /** Keep only changed members, including explicit defaults which clear an inherited setting. */
217
+ function frameOverrides(base, next, authored = {}) {
218
+ const before = base.layout, after = next.layout;
219
+ const layout = {};
220
+ if (before.kind !== after.kind || "stackMode" in authored)
221
+ layout.kind = after.kind;
222
+ if (after.kind === "horizontal" || after.kind === "vertical") {
223
+ const from = before.kind === "horizontal" || before.kind === "vertical" ? before : undefined;
224
+ for (const key of ["gap", "align", "justify", "wrap", "wrapGap", "alignContent"]) {
225
+ if (after[key] !== from?.[key] || STACK_FIELDS[key] in authored)
226
+ layout[key] = after[key] ?? (key === "wrap" ? false : key === "alignContent" ? "auto" : after.gap);
227
+ }
228
+ }
229
+ if (after.kind === "grid") {
230
+ for (const key of Object.keys(GRID_FIELDS)) {
231
+ if (before.kind !== "grid" || !same(before[key], after[key]) || GRID_FIELDS[key] in authored)
232
+ layout[key] = after[key];
233
+ }
234
+ }
235
+ const sizing = before.kind === "absolute" && after.kind !== "absolute" ? { width: after.widthSizing, height: after.heightSizing } : undefined;
236
+ return { ...(Object.keys(layout).length && { layout }), ...(sizing && { sizing }),
237
+ ...(before.kind === "absolute" && after.kind !== "absolute" && { padding: after.padding }),
238
+ ...(!!base.clipContent !== !!next.clipContent && { clipContent: !!next.clipContent }) };
239
+ }
159
240
  /**
160
241
  * Padding override fields and the side each sets (`stackPadding`, Figma's older single value, sets every side the
161
- * entry does not set on its own), as `stackLayoutOf` reads them.
242
+ * entry does not set on its own), as `autoLayoutOf` reads them.
162
243
  */
163
244
  const PADDING_FIELDS = {
164
245
  stackHorizontalPadding: ["left"], stackPaddingRight: ["right"], stackVerticalPadding: ["top"], stackPaddingBottom: ["bottom"],
@@ -169,16 +250,16 @@ const PADDING_FIELDS_OF_SIDE = {
169
250
  };
170
251
  /**
171
252
  * Fields that change neither pixels nor behaviour, so they are skipped
172
- * without a report: Figma's own bookkeeping, the font file version it
173
- * loaded, and Dev Mode annotations and measurements, which only Figma's
174
- * editor shows.
253
+ * without a report: Figma's own bookkeeping and the font file version it loaded.
175
254
  */
176
255
  const BOOKKEEPING_FIELDS = new Set([
177
- "guidPath", "overrideLevel", "textUserLayoutVersion", "vectorOperationVersion", "fontVersion", "annotations", "measurements",
256
+ "guidPath", "overrideLevel", "textUserLayoutVersion", "vectorOperationVersion", "fontVersion",
178
257
  ]);
258
+ /** Dev Mode annotations and measurements. The editor adapter reports them with the layer's own (`figmaHandoff`). */
259
+ const HANDOFF_OVERRIDE_FIELDS = new Set(["annotations", "measurements"]);
179
260
  /** The parts of a converted layer an instance can override, as `LayerOverride` fields, plus those it cannot. */
180
- const STYLE_OVERRIDES = ["fills", "strokes", "shadows", "layerBlur", "backgroundBlur"];
181
- const same = (a, b) => JSON.stringify(a) === JSON.stringify(b);
261
+ const STYLE_OVERRIDES = ["cornerSmoothing", "fills", "strokes", "shadows", "layerBlur", "backgroundBlur"];
262
+ const same = (a, b) => JSON.stringify(a, withImageCrop) === JSON.stringify(b, withImageCrop);
182
263
  function styleOf(node) {
183
264
  return "style" in node && node.style !== undefined ? node.style : {};
184
265
  }
@@ -274,7 +355,7 @@ function overrideBetween(base, next, report) {
274
355
  const nextStyle = styleOf(next);
275
356
  for (const name of STYLE_OVERRIDES) {
276
357
  if (!same(baseStyle[name], nextStyle[name]))
277
- override[name] = nextStyle[name] ?? (name === "layerBlur" || name === "backgroundBlur" ? 0 : []);
358
+ override[name] = nextStyle[name] ?? (name === "layerBlur" || name === "backgroundBlur" || name === "cornerSmoothing" ? 0 : []);
278
359
  }
279
360
  for (const name of new Set([...Object.keys(baseStyle), ...Object.keys(nextStyle)])) {
280
361
  if (!STYLE_OVERRIDES.includes(name) && !same(baseStyle[name], nextStyle[name])) {
@@ -307,12 +388,18 @@ function overrideBetween(base, next, report) {
307
388
  if (realigned !== undefined && override["paragraphs"] === undefined)
308
389
  override["textAlign"] = realigned.align;
309
390
  }
391
+ // `null` takes away a line limit or truncation the component has.
392
+ if (base.type === "text" && next.type === "text") {
393
+ for (const name of ["maxLines", "truncate"])
394
+ if (base[name] !== next[name])
395
+ override[name] = next[name] ?? null;
396
+ }
310
397
  return override;
311
398
  }
312
399
  /**
313
400
  * The `LayerOverride.sizing` that turns the Hug or Fixed sizing of `base` (a
314
401
  * component layer, converted on its own) into that of `next` (the same layer
315
- * with an instance's override fields, converted), both by `stackLayoutOf`, or
402
+ * with an instance's override fields, converted), both by `autoLayoutOf`, or
316
403
  * `undefined` when nothing differs or either is not a stack. An axis where the
317
404
  * layer fills its stack is taken off later, by `dropSizingWhereFilled`.
318
405
  */
@@ -400,6 +487,14 @@ export function dropSizingWhereFilled(overrides, nodes, roots) {
400
487
  const INSIDE_LEFT_OUT = "inside a left-out swap";
401
488
  /** The override fields that give a text layer another line height, so an instance that sets one keeps its own. */
402
489
  const LINE_HEIGHT_SETTERS = ["lineHeight", "styleIdForText", "fontSize"];
490
+ /** Override fields that set a text's lines otherwise than its component's. */
491
+ const LINE_SETTERS = [...LINE_HEIGHT_SETTERS, "textData", "fontName", "letterSpacing", "paragraphSpacing", "listSpacing", "fontVariations", KEPT_LINE_HEIGHT_FIELD];
492
+ /** Whether override fields bind a variable to the line height or font size. */
493
+ function bindsLeading(fields, where) {
494
+ const map = field(fields, "variableConsumptionMap", "object", where);
495
+ return (map && field(map, "entries", "list", `${where} variableConsumptionMap`) || [])
496
+ .some((item) => isObject(item) && (item["variableField"] === "LINE_HEIGHT" || item["variableField"] === "FONT_SIZE"));
497
+ }
403
498
  /**
404
499
  * The one line height in pixels Figma laid out every line of a text at, read from its stored layout (`derivedTextData`,
405
500
  * on a text node or a `derivedSymbolData` entry), or `undefined` without lines or with lines of different heights.
@@ -488,7 +583,7 @@ function pathPlacedOtherThanFigma(node, placed, figmaBefore, figmaAfter) {
488
583
  * constraints unless it was resized (`swappedInstance` in the model), which is not simulated
489
584
  * here, so a resized instance with one counts as laid out otherwise.
490
585
  */
491
- function constrainedOtherThanFigma(instance, component, self, nodes, swappedToOtherSize) {
586
+ function constrainedOtherThanFigma(instance, component, self, nodes, swappedToOtherSize, kept) {
492
587
  const from = component.root.frame;
493
588
  if (self.frame.width === from.width && self.frame.height === from.height)
494
589
  return false;
@@ -519,11 +614,14 @@ function constrainedOtherThanFigma(instance, component, self, nodes, swappedToOt
519
614
  return true;
520
615
  const placed = new Map(constrainChildren(nodes, component.root.id, from, self.frame).map((node) => [node.id, node]));
521
616
  for (const [key, { figma, node }] of component.layers) {
522
- if (node.id === component.root.id)
617
+ if (node.id === component.root.id || kept?.has(layerPathKey([node.id])))
523
618
  continue;
524
619
  const at = `node ${figma.id}`;
525
620
  const derived = laidOut.get(key);
526
621
  const override = overridden.get(key);
622
+ // For saved files, only compare paths with a derived entry. Other layers still follow constraints.
623
+ if (kept && !derived)
624
+ continue;
527
625
  const sizeAfter = derived?.["size"] ?? override?.["size"] ?? figma.change["size"];
528
626
  const transformAfter = derived?.["transform"] ?? override?.["transform"] ?? figma.change["transform"];
529
627
  if (!("frame" in node)) {
@@ -558,6 +656,35 @@ function constrainedOtherThanFigma(instance, component, self, nodes, swappedToOt
558
656
  }
559
657
  return false;
560
658
  }
659
+ /** A derived entry can omit fields that still have their authored or component values. */
660
+ function storedBox(layer, derived, authored) {
661
+ const { figma, node } = layer;
662
+ const path = node.type === "shape" && node.shape === "path";
663
+ if (path && [derived, authored].every(entry => entry?.["size"] === undefined && entry?.["transform"] === undefined))
664
+ return undefined;
665
+ const geometry = frameGeometry({ ...figma, change: {
666
+ size: derived["size"] ?? authored?.["size"] ?? figma.change["size"],
667
+ transform: derived["transform"] ?? authored?.["transform"] ?? figma.change["transform"],
668
+ } });
669
+ if (!geometry)
670
+ return undefined;
671
+ const { sides: { x: width, y: height }, m } = geometry;
672
+ if (width < 0 || height < 0)
673
+ return undefined;
674
+ const transform = [m.m00, m.m10, m.m01, m.m11, m.m02, m.m12];
675
+ if (!path)
676
+ return { width, height, transform };
677
+ const before = figma.change["size"];
678
+ if (!isObject(before))
679
+ return undefined;
680
+ const original = readNumbers(before, ["x", "y"], `node ${figma.id} size`);
681
+ if (!original || (!original.x && width) || (!original.y && height))
682
+ return undefined;
683
+ const pathScale = [original.x ? width / original.x : 1, original.y ? height / original.y : 1];
684
+ if (!pathScale.every(Number.isFinite))
685
+ return undefined;
686
+ return { width, height, transform, pathScale };
687
+ }
561
688
  /**
562
689
  * The axes an instance hugs where Figma stored another size for it (`size`)
563
690
  * than the one it laid its root out at (the `derivedSymbolData` entry whose
@@ -598,8 +725,8 @@ function storedOverHug(instance, component, self) {
598
725
  * an override under the root's path, and so does a Hug or Fixed axis that
599
726
  * differs. Each `symbolOverrides` path step names a layer by its
600
727
  * `overrideKey` (or guid); a step past the first goes through a nested
601
- * instance into the component it shows, after any swap the same instance
602
- * makes on a shorter path, by an override or an instance swap property value. Fields become `LayerOverride` fields where Taco
728
+ * instance into the component it shows, after explicit swaps by this instance or its nested holders,
729
+ * or a swap driven by a component property. Fields become `LayerOverride` fields where Taco
603
730
  * has them (`overriddenSymbolID` a swap, `componentPropAssignments` property
604
731
  * values, paints, effects, visibility, opacity, text); the rest are counted
605
732
  * through `leftOutField`. A swap in `refusedSwaps` is left out, and so is
@@ -611,23 +738,65 @@ export function instanceFields(instance, component, self, context) {
611
738
  const where = `node ${instance.id}`;
612
739
  const overrides = {};
613
740
  const overrideAt = (key) => (overrides[key] ??= {});
741
+ const assignedLinks = new Map();
742
+ const captureLinks = (shown, path) => (id, data, text) => {
743
+ const key = `${path}/${id}`, table = data["styleOverrideTable"];
744
+ if (Array.isArray(table) && table.some(row => isObject(row) && Object.hasOwn(row, "hyperlink")))
745
+ assignedLinks.set(key, { shown, path, id, text, data });
746
+ else
747
+ assignedLinks.delete(key);
748
+ };
614
749
  const componentIdOf = (symbolId) => context.component(symbolId)?.componentId;
615
750
  const swapsKept = new Set();
616
751
  const refusedSwap = (container, target) => context.refusedSwaps?.get(`${container.symbol.id}>${target}`);
752
+ const pathSwaps = new Map();
753
+ const swapsAtPath = (path) => {
754
+ let record = pathSwaps.get(path);
755
+ if (!record)
756
+ pathSwaps.set(path, record = {});
757
+ return record;
758
+ };
617
759
  // Checks an instance swap value of `inComponent`'s property: the reason it is left out, else `undefined`, and the swap is kept.
618
- const leftOutValue = (inComponent) => (symbolId, property) => {
760
+ const leftOutValue = (inComponent, path) => (symbolId, property) => {
619
761
  const refused = refusedSwap(inComponent, symbolId);
620
- if (refused === undefined && inComponent.boundSwaps.has(property))
621
- swapsKept.add(`${inComponent.symbol.id}>${symbolId}`);
762
+ // Another variant can bind an assignment which is dormant on the stored component.
763
+ const properties = swapsAtPath(path).properties ??= {};
764
+ if (refused === undefined) {
765
+ properties[property] = symbolId;
766
+ if (inComponent.boundSwaps.has(property))
767
+ swapsKept.add(`${inComponent.symbol.id}>${symbolId}`);
768
+ }
769
+ else
770
+ properties[property] ??= INSIDE_LEFT_OUT;
622
771
  return refused;
623
772
  };
773
+ const symbolData = field(instance.change, "symbolData", "object", where) ?? {};
774
+ const entries = (field(symbolData, "symbolOverrides", "list", `${where} symbolData`) ?? []).flatMap((entry, index) => {
775
+ const at = `${where} symbolOverrides[${String(index)}]`;
776
+ if (!isObject(entry))
777
+ return [];
778
+ const path = field(entry, "guidPath", "object", at);
779
+ const guids = path === undefined ? [] : field(path, "guids", "list", `${at}.guidPath`) ?? [];
780
+ return [{ keys: guids.map((guid) => guidText(guid, `${at}.guidPath`)), entry, at }];
781
+ }).sort((a, b) => a.keys.length - b.keys.length);
782
+ const rootFields = Object.assign({}, ...entries.filter(({ keys }) => keys.length === 1 && keys[0] === component.symbol.id)
783
+ .map(({ entry }) => Object.fromEntries(Object.entries(entry).filter(([key]) => FRAME_FIELDS.has(key) || Object.hasOwn(PADDING_FIELDS, key)))));
784
+ const ownFields = { ...instance.change, ...rootFields };
785
+ if (Object.keys(rootFields).length) {
786
+ const converted = context.convertAlone(instance, rootFields);
787
+ if (converted?.type === "frame")
788
+ self = { ...self, layout: converted.layout, style: { ...self.style, cornerSmoothing: converted.style?.cornerSmoothing ?? 0 },
789
+ clipContent: !!converted.clipContent };
790
+ }
624
791
  // The instance's own frame against the component root.
625
792
  const rootKey = layerPathKey([component.root.id]);
626
793
  const rootStyle = styleOf(component.root);
627
794
  const ownStyle = styleOf(self);
628
795
  for (const name of STYLE_OVERRIDES) {
796
+ if (name === "cornerSmoothing" && ownFields.cornerSmoothing === undefined)
797
+ continue;
629
798
  if (!same(rootStyle[name], ownStyle[name]))
630
- overrideAt(rootKey)[name] = ownStyle[name] ?? (name === "layerBlur" || name === "backgroundBlur" ? 0 : []);
799
+ overrideAt(rootKey)[name] = ownStyle[name] ?? (name === "layerBlur" || name === "backgroundBlur" || name === "cornerSmoothing" ? 0 : []);
631
800
  }
632
801
  for (const name of new Set([...Object.keys(rootStyle), ...Object.keys(ownStyle)])) {
633
802
  if (context.fileOverride && (name === "cornerRadius" || name === "cornerRadii"))
@@ -636,9 +805,19 @@ export function instanceFields(instance, component, self, context) {
636
805
  context.report("property-left-out", `an instance's own ${name} differs from its component and is left out: Taco instances cannot override it`);
637
806
  }
638
807
  }
639
- if (self.clipContent !== component.root.clipContent) {
640
- context.report("property-left-out", "an instance's own clipping differs from its component and is left out: Taco instances cannot override it");
808
+ // A sparse INSTANCE can omit its entire stack and clip flag. Only authored fields replace the template.
809
+ if (component.root.layout.kind === "grid" || ownFields.stackMode === undefined || rootFields.stackMode !== undefined || ownFields.stackMode !== component.symbol.change["stackMode"]) {
810
+ const stack = Object.keys(ownFields).some(key => FRAME_FIELDS.has(key) && (key.startsWith("stack") || key.startsWith("grid")) || Object.hasOwn(PADDING_FIELDS, key));
811
+ const layout = stack || Object.keys(ownFields).some(key => key.startsWith("grid"))
812
+ ? autoLayoutOf({ ...component.symbol.change, ...ownFields }, () => { }, field => {
813
+ if (Object.hasOwn(ownFields, field.split(".")[0]))
814
+ context.report("property-left-out", `grid layout field ${field}`);
815
+ }) : undefined;
816
+ self = { ...self, layout: layout ?? (ownFields.stackMode === undefined ? component.root.layout : self.layout) };
641
817
  }
818
+ Object.assign(overrideAt(rootKey), frameOverrides(component.root, {
819
+ ...self, clipContent: !!(ownFields.frameMaskDisabled === undefined ? component.root.clipContent : self.clipContent),
820
+ }));
642
821
  if (component.root.layout.kind !== "absolute" && self.layout.kind !== "absolute") {
643
822
  const sizing = {};
644
823
  for (const [axis, key] of [["width", "widthSizing"], ["height", "heightSizing"]]) {
@@ -670,20 +849,6 @@ export function instanceFields(instance, component, self, context) {
670
849
  if (Object.keys(padding).length > 0)
671
850
  overrideAt(rootKey)["padding"] = padding;
672
851
  }
673
- const { widthSizing: _ownWidth, heightSizing: _ownHeight, padding: _ownPadding, ...ownLayout } = self.layout;
674
- const { widthSizing: _rootWidth, heightSizing: _rootHeight, padding: _rootPadding, ...rootLayout } = component.root.layout;
675
- if (!same(ownLayout, rootLayout)) {
676
- context.report("property-left-out", "an instance's own auto layout differs from its component and is left out: Taco instances cannot override it");
677
- }
678
- const symbolData = field(instance.change, "symbolData", "object", where) ?? {};
679
- const entries = (field(symbolData, "symbolOverrides", "list", `${where} symbolData`) ?? []).flatMap((entry, index) => {
680
- const at = `${where} symbolOverrides[${String(index)}]`;
681
- if (!isObject(entry))
682
- return [];
683
- const path = field(entry, "guidPath", "object", at);
684
- const guids = path === undefined ? [] : field(path, "guids", "list", `${at}.guidPath`) ?? [];
685
- return [{ keys: guids.map((guid) => guidText(guid, `${at}.guidPath`)), entry, at }];
686
- }).sort((a, b) => a.keys.length - b.keys.length);
687
852
  // The property values set for the instance at each path's Figma keys ("" for this instance), for instance swap properties.
688
853
  const assignmentsAt = new Map([["", field(instance.change, "componentPropAssignments", "list", where) ?? []]]);
689
854
  for (const { keys, entry, at } of entries) {
@@ -691,35 +856,37 @@ export function instanceFields(instance, component, self, context) {
691
856
  if (list !== undefined && keys.length > 0)
692
857
  assignmentsAt.set(keys.join("/"), [...assignmentsAt.get(keys.join("/")) ?? [], ...list]);
693
858
  }
694
- // The property values the nested instance layer at `keys` is given in the component that holds it; this instance's own
695
- // values at that path go on top of them.
696
- // A layer this instance swaps by an override is given only the values that override carries, so it holds none.
697
- const heldAssignments = (keys) => {
698
- if (keys.length === 0 || swaps.has(keys.join("/")))
699
- return [];
700
- const host = resolve(keys);
701
- if (host === undefined || host === INSIDE_LEFT_OUT || "flattenedInto" in host || host.layer.figma.type !== "INSTANCE")
702
- return [];
703
- return field(host.layer.figma.change, "componentPropAssignments", "list", `node ${host.layer.figma.id}`) ?? [];
859
+ // Each holder's path ends at the bound layer. The assignment belongs to its parent instance
860
+ // (the empty path for the innermost holder). An explicit swap resets values from deeper holders.
861
+ const heldPropertySwap = (through, property) => {
862
+ for (const holder of through) {
863
+ const parent = layerPathKey(parseLayerPath(holder.inner).slice(0, -1));
864
+ const inherited = context.nestedSwaps(holder.instance, parent);
865
+ const value = inherited?.properties?.[property];
866
+ if (value !== undefined || inherited?.symbol !== undefined)
867
+ return value;
868
+ }
869
+ return undefined;
704
870
  };
705
- // The symbol an instance swap property value gives a nested instance layer, set where the instance it is in sits (`inKeys`):
706
- // by that instance's layer in its own component, then by this instance.
707
- const propertySwap = (layer, inComponent, inKeys) => {
871
+ // A placement's own assignment takes precedence over its enclosing holders. With `ownOnly`, only this instance's
872
+ // own assignments at `parentKey` count.
873
+ const propertySwap = (layer, inComponent, parentKey, through, ownOnly = false) => {
708
874
  let symbolId;
709
- const assignments = [...heldAssignments(inKeys), ...assignmentsAt.get(inKeys.join("/")) ?? []];
710
875
  for (const ref of field(layer.change, "componentPropRefs", "list", `node ${layer.id}`) ?? []) {
711
876
  if (!isObject(ref) || ref["componentPropNodeField"] !== "OVERRIDDEN_SYMBOL_ID" || ref["defID"] === undefined || ref["isDeleted"] === true)
712
877
  continue;
713
878
  const property = propertyByFigmaId(inComponent.properties, guidText(ref["defID"], `node ${layer.id} componentPropRefs`));
714
879
  if (property === undefined)
715
880
  continue;
716
- for (const assignment of assignments) {
881
+ let own;
882
+ for (const assignment of assignmentsAt.get(parentKey) ?? []) {
717
883
  if (!isObject(assignment) || assignment["defID"] === undefined)
718
884
  continue;
719
885
  if (propertyByFigmaId(inComponent.properties, guidText(assignment["defID"], `${where} componentPropAssignments`)) !== property)
720
886
  continue;
721
- symbolId = assignedValueOf(assignment, `${where} componentPropAssignments`).symbolId ?? symbolId;
887
+ own = assignedValueOf(assignment, `${where} componentPropAssignments`).symbolId ?? own;
722
888
  }
889
+ symbolId = own ?? (ownOnly || swaps.has(parentKey) ? undefined : heldPropertySwap(through, property.definition.id)) ?? symbolId;
723
890
  }
724
891
  return symbolId;
725
892
  };
@@ -727,15 +894,34 @@ export function instanceFields(instance, component, self, context) {
727
894
  // property value, else its own. `INSIDE_LEFT_OUT` when the nesting check left out the swap or value it would show.
728
895
  const swaps = new Map();
729
896
  const leftOutSwaps = new Set();
730
- const shownAt = (keys, layer, inComponent) => {
897
+ const shownAt = (keys, layer, inComponent, through) => {
731
898
  const key = keys.join("/");
732
899
  const swapped = swaps.get(key);
733
900
  if (swapped !== undefined)
734
901
  return context.component(swapped);
735
902
  if (leftOutSwaps.has(key))
736
903
  return INSIDE_LEFT_OUT;
737
- const valued = propertySwap(layer, inComponent, keys.slice(0, -1));
738
- if (valued !== undefined && refusedSwap(inComponent, valued) !== undefined)
904
+ // This instance's own swap property value outranks a swap a nested instance authored below it. A Taco swap override
905
+ // outranks a property value, so where such a swap differs the value is written as this instance's swap too.
906
+ const assigned = through.length === 0 ? undefined : propertySwap(layer, inComponent, keys.slice(0, -1).join("/"), through, true);
907
+ if (assigned !== undefined) {
908
+ if (refusedSwap(inComponent, assigned) !== undefined)
909
+ return INSIDE_LEFT_OUT;
910
+ const componentId = componentIdOf(assigned);
911
+ if (componentId !== undefined && through.some(({ instance, inner }) => (context.nestedSwaps(instance, inner)?.symbol ?? assigned) !== assigned)) {
912
+ const key = layerPathKey([through[0].instance.id, ...parseLayerPath(through[0].inner)]);
913
+ overrideAt(key)["componentId"] = componentId;
914
+ swapsAtPath(key).symbol = assigned;
915
+ }
916
+ return context.component(assigned);
917
+ }
918
+ for (const holder of through) {
919
+ const inherited = context.nestedSwaps(holder.instance, holder.inner)?.symbol;
920
+ if (inherited !== undefined)
921
+ return inherited === INSIDE_LEFT_OUT ? INSIDE_LEFT_OUT : context.component(inherited);
922
+ }
923
+ const valued = propertySwap(layer, inComponent, keys.slice(0, -1).join("/"), through);
924
+ if (valued === INSIDE_LEFT_OUT || (valued !== undefined && refusedSwap(inComponent, valued) !== undefined))
739
925
  return INSIDE_LEFT_OUT;
740
926
  return context.component(valued ?? shownSymbol(layer) ?? "");
741
927
  };
@@ -753,14 +939,14 @@ export function instanceFields(instance, component, self, context) {
753
939
  return flattenedInto === undefined ? undefined : { flattenedInto };
754
940
  }
755
941
  ids.push(layer.node.id);
942
+ const through = instances.map((instance, at) => ({ instance, inner: layerPathKey(ids.slice(at + 1)) }));
756
943
  if (i === keys.length - 1) {
757
- const through = instances.map((instance, at) => ({ instance, inner: layerPathKey(ids.slice(at + 1)) }));
758
944
  return { key: layerPathKey(ids), layer, component: inComponent, through };
759
945
  }
760
946
  if (layer.figma.type !== "INSTANCE")
761
947
  return undefined;
762
948
  instances.push(layer.node);
763
- inComponent = shownAt(keys.slice(0, i + 1), layer.figma, inComponent);
949
+ inComponent = shownAt(keys.slice(0, i + 1), layer.figma, inComponent, through);
764
950
  }
765
951
  return undefined;
766
952
  };
@@ -814,15 +1000,100 @@ export function instanceFields(instance, component, self, context) {
814
1000
  }
815
1001
  return reset;
816
1002
  };
817
- let unmatched = 0;
818
- let insideLeftOut = 0;
1003
+ /**
1004
+ * Gives the nested instances inside the instance at `keys` (`[]` for this one), which shows `shown`, the values in `list` that
1005
+ * name a property `shown` does not declare but a component shown by one of those instances does: each goes to the
1006
+ * shallowest nested instances whose shown component declares it, read against that component, where the instance's
1007
+ * `derivedSymbolData` lays out a layer bound to that property inside it (Figma ignores a stale value). Returns the other values.
1008
+ */
1009
+ let derivedPaths;
1010
+ // Whether the instance's `derivedSymbolData` lays out a layer of `nested`, shown at `keys`, that is bound to `defId`'s property.
1011
+ const laysOutBound = (nested, keys, defId) => {
1012
+ derivedPaths ??= new Set((field(instance.change, "derivedSymbolData", "list", where) ?? []).flatMap((entry, index) => {
1013
+ const at = `${where} derivedSymbolData[${String(index)}]`;
1014
+ const path = isObject(entry) ? field(entry, "guidPath", "object", at) : undefined;
1015
+ return path === undefined ? [] : [(field(path, "guids", "list", `${at}.guidPath`) ?? []).map(guid => guidText(guid, `${at}.guidPath`)).join("/")];
1016
+ }));
1017
+ const property = propertyByFigmaId(nested.properties, defId);
1018
+ for (const [key, layer] of nested.layers) {
1019
+ const bound = (field(layer.figma.change, "componentPropRefs", "list", `node ${layer.figma.id}`) ?? []).some(ref => isObject(ref) && ref["defID"] !== undefined
1020
+ && ref["isDeleted"] !== true && propertyByFigmaId(nested.properties, guidText(ref["defID"], `node ${layer.figma.id} componentPropRefs`)) === property);
1021
+ if (bound && derivedPaths.has([...keys, key].join("/")))
1022
+ return true;
1023
+ }
1024
+ return false;
1025
+ };
1026
+ const assignNestedValues = (list, shown, keys, at) => {
1027
+ if (list === undefined)
1028
+ return list;
1029
+ const own = [];
1030
+ const below = new Map();
1031
+ for (const assignment of list) {
1032
+ const defId = isObject(assignment) && assignment["defID"] !== undefined ? guidText(assignment["defID"], `${at} componentPropAssignments`) : undefined;
1033
+ if (defId === undefined || shown.variantDefs.has(defId) || propertyByFigmaId(shown.properties, defId) !== undefined) {
1034
+ own.push(assignment);
1035
+ continue;
1036
+ }
1037
+ const found = [];
1038
+ for (let level = [{ keys, component: shown }]; level.length > 0 && found.length === 0;) {
1039
+ const next = [];
1040
+ for (const { keys: outer, component: inside } of level) {
1041
+ for (const [key, layer] of inside.layers) {
1042
+ if (layer.figma.type !== "INSTANCE")
1043
+ continue;
1044
+ const path = [...outer, key];
1045
+ const target = resolve(path);
1046
+ if (target === undefined || target === INSIDE_LEFT_OUT || "flattenedInto" in target || target.layer !== layer)
1047
+ continue;
1048
+ const nested = shownAt(path, layer.figma, inside, target.through);
1049
+ if (nested === undefined || nested === INSIDE_LEFT_OUT)
1050
+ continue;
1051
+ if (propertyByFigmaId(nested.properties, defId) !== undefined) {
1052
+ if (laysOutBound(nested, [...outer, key], defId))
1053
+ found.push({ target, shown: nested });
1054
+ }
1055
+ else
1056
+ next.push({ keys: path, component: nested });
1057
+ }
1058
+ }
1059
+ level = next;
1060
+ }
1061
+ if (found.length === 0)
1062
+ own.push(assignment);
1063
+ for (const { target, shown: nested } of found) {
1064
+ let gathered = below.get(target.key);
1065
+ if (gathered === undefined)
1066
+ below.set(target.key, gathered = { shown: nested, list: [] });
1067
+ gathered.list.push(assignment);
1068
+ }
1069
+ }
1070
+ for (const [key, { shown: nested, list: values }] of below) {
1071
+ const read = assignedPropertyValues(values, nested.properties, nested.variantDefs, componentIdOf, leftOutValue(nested, key), at, context.report, captureLinks(nested, key));
1072
+ const override = overrideAt(key);
1073
+ if (Object.keys(read).length > 0)
1074
+ override["propertyValues"] = { ...read, ...override["propertyValues"] };
1075
+ }
1076
+ return own;
1077
+ };
1078
+ const insideLeftOut = new Set();
819
1079
  const pending = new Map();
820
1080
  const targets = [];
1081
+ let rootExports;
1082
+ const symbolKey = overrideKeyOf(component.symbol);
821
1083
  // Swaps first, shorter paths before longer ones, so property values and deeper paths are read against the component swapped in.
822
1084
  for (const { keys, entry, at } of entries) {
823
- // A path naming the component itself targets the instance, which already carries those values.
1085
+ // A path of one step naming the component's root, by its guid or by its override key, holds the instance's own
1086
+ // export presets.
1087
+ const rootPath = keys.length === 1 && (keys[0] === component.symbol.id || keys[0] === symbolKey);
1088
+ if (rootPath && entry["exportSettings"] !== undefined)
1089
+ rootExports = entry["exportSettings"];
1090
+ // A path naming the component itself by guid targets the instance, which already carries those values; one naming
1091
+ // it by override key goes on as an override of the root layer.
824
1092
  if (keys.length === 1 && keys[0] === component.symbol.id)
825
1093
  continue;
1094
+ if (!rootPath && entry["exportSettings"] !== undefined) {
1095
+ context.report("property-left-out", "an export settings override on an inherited layer is left out");
1096
+ }
826
1097
  const target = keys.length === 0 ? undefined : resolve(keys);
827
1098
  if (target !== undefined && target !== INSIDE_LEFT_OUT && "flattenedInto" in target) {
828
1099
  context.report("property-left-out", `an override of an operand of the boolean operation ${JSON.stringify(target.flattenedInto)} is left out: the boolean operation is flattened to its outline`);
@@ -830,9 +1101,11 @@ export function instanceFields(instance, component, self, context) {
830
1101
  }
831
1102
  if (target === undefined || target === INSIDE_LEFT_OUT) {
832
1103
  if (target === undefined)
833
- unmatched += 1;
1104
+ context.report("property-left-out", keys.some(key => !context.hasSourceKey(key))
1105
+ ? "an override path contains a GUID with no source layer or override key"
1106
+ : "an override path that names no imported layer of the component is left out");
834
1107
  else
835
- insideLeftOut += 1;
1108
+ insideLeftOut.add(entry);
836
1109
  continue;
837
1110
  }
838
1111
  let gathered = pending.get(target.key);
@@ -850,6 +1123,8 @@ export function instanceFields(instance, component, self, context) {
850
1123
  else if (refused !== undefined) {
851
1124
  context.report("property-left-out", `a swap ${refused}`);
852
1125
  leftOutSwaps.add(keys.join("/"));
1126
+ if (!swaps.has(keys.join("/")))
1127
+ swapsAtPath(target.key).symbol = INSIDE_LEFT_OUT;
853
1128
  }
854
1129
  else {
855
1130
  gathered.override["componentId"] = swapped;
@@ -857,15 +1132,56 @@ export function instanceFields(instance, component, self, context) {
857
1132
  if (Object.keys(reset).length > 0)
858
1133
  gathered.override["propertyValues"] = { ...gathered.override["propertyValues"], ...reset };
859
1134
  swaps.set(keys.join("/"), symbolId);
1135
+ swapsAtPath(target.key).symbol = symbolId;
860
1136
  swapsKept.add(`${target.component.symbol.id}>${symbolId}`);
861
1137
  }
862
1138
  }
1139
+ const boxes = new Map(), texts = new Map();
1140
+ const from = component.root.frame;
1141
+ const resizedFreeFrame = component.root.layout.kind === "absolute" && (self.frame.width !== from.width || self.frame.height !== from.height);
1142
+ if (context.fileLayout) {
1143
+ const authored = new Map();
1144
+ for (const { keys, entry } of entries) {
1145
+ const key = keys.join("/");
1146
+ authored.set(key, { ...authored.get(key), ...entry });
1147
+ }
1148
+ for (const [index, entry] of (field(instance.change, "derivedSymbolData", "list", where) ?? []).entries()) {
1149
+ if (!isObject(entry) || (!resizedFreeFrame && entry["size"] === undefined && entry["derivedTextData"] === undefined))
1150
+ continue;
1151
+ const at = `${where} derivedSymbolData[${String(index)}]`;
1152
+ const path = field(entry, "guidPath", "object", at);
1153
+ const keys = (path === undefined ? [] : field(path, "guids", "list", `${at}.guidPath`) ?? []).map(guid => guidText(guid, `${at}.guidPath`));
1154
+ const target = resolve(keys);
1155
+ if (!target || target === INSIDE_LEFT_OUT || "flattenedInto" in target || target.layer.node.id === target.component.root.id)
1156
+ continue;
1157
+ // A stack can allocate a different size even when the stored group or vector
1158
+ // matches its main. Keep that explicit size as an input to the adapter.
1159
+ const layer = target.layer.node;
1160
+ const change = target.layer.figma.change;
1161
+ const requestsFill = change["stackPositioning"] !== "ABSOLUTE" &&
1162
+ (Number(change["stackChildPrimaryGrow"]) > 0 || change["stackChildAlignSelf"] === "STRETCH");
1163
+ const fillLayer = layer.type === "group" || (layer.type === "shape" && layer.shape === "path");
1164
+ // A self-sizing text keeps the size Figma measured it at here (its text or font may be overridden): measured
1165
+ // again, without the document's fonts, it would come out at another size. An entry with the text's glyphs and no
1166
+ // size is one Figma measured at the size it has without the entry (`inner`).
1167
+ const sizesItself = layer.type === "text"
1168
+ && ["WIDTH_AND_HEIGHT", "HEIGHT"].includes(String(authored.get(keys.join("/"))?.["textAutoResize"] ?? change["textAutoResize"]));
1169
+ if (!resizedFreeFrame && !(fillLayer && requestsFill) && !sizesItself)
1170
+ continue;
1171
+ const box = storedBox(target.layer, entry, authored.get(keys.join("/")));
1172
+ if (box && !resizedFreeFrame && sizesItself)
1173
+ texts.set(target.key, entry["size"] === undefined ? { ...box, inner: true } : box);
1174
+ else if (box)
1175
+ boxes.set(target.key, box);
1176
+ }
1177
+ context.fileLayout(boxes, !resizedFreeFrame, texts);
1178
+ }
863
1179
  if (component.root.layout.kind === "absolute") {
864
1180
  // A nested instance layer of the component that this instance swaps (by an override or a property value) to a component of another size.
865
1181
  const swappedToOtherSize = [...component.layers].some(([key, { figma, node }]) => {
866
- if (figma.type !== "INSTANCE" || !("frame" in node))
1182
+ if (figma.type !== "INSTANCE" || !("frame" in node) || boxes.has(layerPathKey([node.id])))
867
1183
  return false;
868
- const shown = shownAt([key], figma, component);
1184
+ const shown = shownAt([key], figma, component, []);
869
1185
  const own = context.component(shownSymbol(figma) ?? "");
870
1186
  if (shown === undefined || shown === INSIDE_LEFT_OUT || shown === own)
871
1187
  return false;
@@ -874,16 +1190,86 @@ export function instanceFields(instance, component, self, context) {
874
1190
  return false;
875
1191
  return Math.abs(shown.root.frame.width - node.frame.width) > 0.01 || Math.abs(shown.root.frame.height - node.frame.height) > 0.01;
876
1192
  });
877
- if (constrainedOtherThanFigma(instance, component, self, context.nodes, swappedToOtherSize)) {
1193
+ if (constrainedOtherThanFigma(instance, component, self, context.nodes, swappedToOtherSize, context.fileLayout ? boxes : undefined)) {
878
1194
  context.report("approximated", "the layers of a resized instance follow their constraints to sizes or positions other than the ones Figma laid out for it");
879
1195
  }
880
1196
  }
1197
+ // Grid cell anchors are GUIDs in the source and indices in the model. Resolve an
1198
+ // occurrence's authored and inherited anchors against the same final track order.
1199
+ const gridParents = new Map();
1200
+ const rememberGrid = (owner, source, prefix, fields) => {
1201
+ if (fields.gridRows === undefined && fields.gridColumns === undefined)
1202
+ return;
1203
+ const parent = layersByFigmaId(owner).get(source.id);
1204
+ if (!parent)
1205
+ return;
1206
+ const key = layerPathKey([...prefix, parent.node.id]);
1207
+ gridParents.set(key, { source, owner, prefix, fields: { ...gridParents.get(key)?.fields, ...fields } });
1208
+ };
1209
+ rememberGrid(component, component.symbol, [], ownFields);
1210
+ for (const { gathered: { target }, keys, entry } of targets) {
1211
+ if (entry.gridRows === undefined && entry.gridColumns === undefined)
1212
+ continue;
1213
+ const path = parseLayerPath(target.key);
1214
+ if (target.layer.figma.type === "INSTANCE") {
1215
+ const shown = shownAt(keys, target.layer.figma, target.component, target.through);
1216
+ if (shown && shown !== INSIDE_LEFT_OUT)
1217
+ rememberGrid(shown, shown.symbol, path, entry);
1218
+ }
1219
+ else
1220
+ rememberGrid(target.component, target.layer.figma, path.slice(0, -1), entry);
1221
+ }
1222
+ const axesOf = (frame) => ({ rows: gridAxis(frame, "gridRows", () => { }).indices,
1223
+ columns: gridAxis(frame, "gridColumns", () => { }).indices });
1224
+ const gridAxes = new Map();
1225
+ for (const [key, { owner, source, fields, prefix }] of gridParents) {
1226
+ const effective = { ...source.change, ...fields };
1227
+ if (effective.stackMode !== "GRID")
1228
+ continue;
1229
+ const axes = axesOf(effective), original = axesOf(source.change);
1230
+ gridAxes.set(key, axes);
1231
+ for (const child of source.children) {
1232
+ const layer = layersByFigmaId(owner).get(child.id);
1233
+ if (!layer)
1234
+ continue;
1235
+ const anchors = { ...(fields.gridRows !== undefined && { gridRowAnchor: child.change.gridRowAnchor }),
1236
+ ...(fields.gridColumns !== undefined && { gridColumnAnchor: child.change.gridColumnAnchor }) };
1237
+ const cell = gridCell(anchors, axes.rows, axes.columns, field => context.leftOutField(field), true);
1238
+ const inherited = gridCell(anchors, original.rows, original.columns, () => { }, true);
1239
+ const changed = Object.entries(cell).filter(([axis, value]) => inherited?.[axis] !== value);
1240
+ if (changed.length)
1241
+ overrideAt(layerPathKey([...prefix, layer.node.id])).gridCell = Object.fromEntries(changed);
1242
+ }
1243
+ }
881
1244
  const modeOverrides = new Map();
882
1245
  for (const { keys, entry, at, gathered } of targets) {
883
1246
  const { target } = gathered;
884
1247
  const isInstance = target.layer.figma.type === "INSTANCE";
1248
+ let readCell = false;
885
1249
  for (const [name, value] of Object.entries(entry)) {
886
- if (BOOKKEEPING_FIELDS.has(name) || (name === "overriddenSymbolID" && isInstance))
1250
+ if (gridChildFields.has(name)) {
1251
+ if (readCell)
1252
+ continue;
1253
+ readCell = true;
1254
+ const parentId = target.layer.figma.parentId;
1255
+ const parent = parentId && layersByFigmaId(target.component).get(parentId);
1256
+ const key = parent && layerPathKey([...parseLayerPath(target.key).slice(0, -1), parent.node.id]);
1257
+ if (parent && key && (gridAxes.has(key) || parent.figma.change.stackMode === "GRID")) {
1258
+ const axes = gridAxes.get(key) ?? axesOf(parent.figma.change);
1259
+ gridAxes.set(key, axes);
1260
+ const cell = gridCell(entry, axes.rows, axes.columns, field => context.leftOutField(field), true);
1261
+ if (Object.keys(cell).length)
1262
+ gathered.override.gridCell = { ...gathered.override.gridCell, ...cell };
1263
+ }
1264
+ else
1265
+ for (const field of Object.keys(entry))
1266
+ if (gridChildFields.has(field))
1267
+ context.leftOutField(field);
1268
+ continue;
1269
+ }
1270
+ if (BOOKKEEPING_FIELDS.has(name) || name === "exportSettings" || (name === "overriddenSymbolID" && isInstance))
1271
+ continue;
1272
+ if (HANDOFF_OVERRIDE_FIELDS.has(name))
887
1273
  continue;
888
1274
  // Figma's record of the variable bindings this override set, which `variableConsumptionMap` beside it holds too.
889
1275
  if (name === "parameterConsumptionMap" && entry["variableConsumptionMap"] !== undefined) {
@@ -893,14 +1279,24 @@ export function instanceFields(instance, component, self, context) {
893
1279
  continue;
894
1280
  }
895
1281
  if (name === "componentPropAssignments" && isInstance) {
896
- const shown = shownAt(keys, target.layer.figma, target.component);
1282
+ const shown = shownAt(keys, target.layer.figma, target.component, target.through);
897
1283
  if (shown === INSIDE_LEFT_OUT)
898
- insideLeftOut += 1;
1284
+ insideLeftOut.add(entry);
899
1285
  if (shown === undefined || shown === INSIDE_LEFT_OUT)
900
1286
  continue;
901
- const values = assignedPropertyValues(field(entry, name, "list", at), shown.properties, shown.variantDefs, componentIdOf, leftOutValue(shown), at, context.report);
1287
+ const values = assignedPropertyValues(assignNestedValues(field(entry, name, "list", at), shown, keys, at), shown.properties, shown.variantDefs, componentIdOf, leftOutValue(shown, target.key), at, context.report, captureLinks(shown, target.key));
902
1288
  if (Object.keys(values).length > 0)
903
1289
  gathered.override["propertyValues"] = { ...gathered.override["propertyValues"], ...values };
1290
+ // Each swap-bound layer the values reach shows the value over a swap made below this instance (`shownAt`).
1291
+ for (const [key, layer] of shown.layers) {
1292
+ if (layer.figma.type !== "INSTANCE" || !(field(layer.figma.change, "componentPropRefs", "list", `node ${layer.figma.id}`) ?? [])
1293
+ .some(ref => isObject(ref) && ref["componentPropNodeField"] === "OVERRIDDEN_SYMBOL_ID"))
1294
+ continue;
1295
+ const path = [...keys, key];
1296
+ const bound = resolve(path);
1297
+ if (bound !== undefined && bound !== INSIDE_LEFT_OUT && !("flattenedInto" in bound) && bound.layer === layer)
1298
+ shownAt(path, layer.figma, shown, bound.through);
1299
+ }
904
1300
  }
905
1301
  else if (name === "variableModeBySetMap" && (target.through.length === 0 || context.fileOverride)) {
906
1302
  // The instance's modes on a layer of the component reach the bound font styles under it; Taco keeps no other part.
@@ -908,43 +1304,30 @@ export function instanceFields(instance, component, self, context) {
908
1304
  if (!context.fileOverride)
909
1305
  context.leftOutField(name);
910
1306
  }
911
- else if (SIZING_FIELDS.has(name) && (target.layer.node.type === "frame" || isInstance)) {
912
- const shown = isInstance ? shownAt(keys, target.layer.figma, target.component) : undefined;
1307
+ else if ((FRAME_FIELDS.has(name) || Object.hasOwn(PADDING_FIELDS, name)) && (target.layer.node.type === "frame" || isInstance)) {
1308
+ const shown = isInstance ? shownAt(keys, target.layer.figma, target.component, target.through) : undefined;
913
1309
  if (shown === INSIDE_LEFT_OUT)
914
- insideLeftOut += 1;
1310
+ insideLeftOut.add(entry);
915
1311
  else if (isInstance && shown === undefined)
916
1312
  context.leftOutField(name);
917
1313
  else {
918
1314
  const { figma } = target.layer;
919
1315
  const under = (inner) => layerPathKey([...parseLayerPath(inner), shown.root.id]);
920
1316
  const key = shown === undefined ? target.key : under(target.key);
921
- gathered.sizing ??= {
1317
+ gathered.frame ??= {
922
1318
  fields: {}, at: overrideAt(key), key, from: shown === undefined || figma.change["stackMode"] !== undefined ? figma : shown.symbol,
923
1319
  holders: shown === undefined ? target.through
924
1320
  : [...target.through.map(({ instance, inner }) => ({ instance, inner: under(inner) })), { instance: target.layer.node, inner: layerPathKey([shown.root.id]) }],
925
1321
  };
926
- gathered.sizing.fields[name] = value;
927
- }
928
- }
929
- else if (Object.hasOwn(PADDING_FIELDS, name) && (target.layer.node.type === "frame" || isInstance)) {
930
- // A nested instance is padded by the root of the component it shows, so its padding goes under that root's path.
931
- const shown = isInstance ? shownAt(keys, target.layer.figma, target.component) : undefined;
932
- const frame = isInstance ? (shown === undefined || shown === INSIDE_LEFT_OUT ? undefined : shown.root) : target.layer.node;
933
- const amount = typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : undefined;
934
- if (shown === INSIDE_LEFT_OUT)
935
- insideLeftOut += 1;
936
- else if (frame?.type !== "frame" || frame.layout.kind === "absolute" || amount === undefined)
937
- context.leftOutField(name);
938
- else {
939
- const key = shown === undefined ? target.key : layerPathKey([...parseLayerPath(target.key), shown.root.id]);
940
- const at = overrideAt(key);
941
- const padding = { ...at["padding"] };
942
- // `stackPadding` fills only the sides the entry does not set on its own.
943
- const sides = PADDING_FIELDS[name];
944
- for (const side of sides)
945
- if (sides.length === 1 || !PADDING_FIELDS_OF_SIDE[side].some((own) => entry[own] !== undefined))
946
- padding[side] = amount;
947
- at["padding"] = padding;
1322
+ if (Object.hasOwn(PADDING_FIELDS, name)) {
1323
+ const sides = PADDING_FIELDS[name];
1324
+ if (typeof value !== "number" || !Number.isFinite(value) || value < 0)
1325
+ context.leftOutField(name);
1326
+ else
1327
+ (gathered.frame.padding ??= []).push({ name, value, sides: sides.filter(side => sides.length === 1 || !PADDING_FIELDS_OF_SIDE[side].some(key => key in entry)) });
1328
+ }
1329
+ else
1330
+ gathered.frame.fields[name] = value;
948
1331
  }
949
1332
  }
950
1333
  else if (name === "name") {
@@ -959,6 +1342,9 @@ export function instanceFields(instance, component, self, context) {
959
1342
  // The native override supports radii directly. fileOverride has recorded the authored values.
960
1343
  continue;
961
1344
  }
1345
+ else if (name === "textTruncation" && value !== "DISABLED" && value !== "ENDING") {
1346
+ context.report("property-left-out", `an override's text truncation ${String(value)} is not imported; the layer keeps its component's`);
1347
+ }
962
1348
  else if (CONVERTED_FIELDS.has(name) || name === "variableConsumptionMap") {
963
1349
  gathered.fields[name] = value;
964
1350
  // A style the override names but the message lacks is reported as on a text layer; Figma's detach id is no style.
@@ -1006,7 +1392,9 @@ export function instanceFields(instance, component, self, context) {
1006
1392
  if (own === undefined || Math.abs(stored - own) <= 0.01)
1007
1393
  continue;
1008
1394
  const pathText = keys.join("/");
1009
- if (entries.some((set) => set.keys.join("/") === pathText && LINE_HEIGHT_SETTERS.some((name) => Object.hasOwn(set.entry, name))))
1395
+ // An override that binds the line height or size to a variable draws at the variable's value instead.
1396
+ if (entries.some((set) => set.keys.join("/") === pathText && (LINE_HEIGHT_SETTERS.some((name) => Object.hasOwn(set.entry, name))
1397
+ || bindsLeading(set.entry, at))))
1010
1398
  continue;
1011
1399
  let gathered = pending.get(target.key);
1012
1400
  if (gathered === undefined)
@@ -1014,33 +1402,78 @@ export function instanceFields(instance, component, self, context) {
1014
1402
  gathered.fields[KEPT_LINE_HEIGHT_FIELD] = stored;
1015
1403
  context.report("approximated", "instance keeps Figma's stored line height from before its text style changed");
1016
1404
  }
1405
+ // A text's line limit counts the lines this instance stores for it, not its component's, where it sets them otherwise.
1406
+ const laidOut = new Map();
1407
+ for (const [index, entry] of (field(instance.change, "derivedSymbolData", "list", where) ?? []).entries()) {
1408
+ const derived = isObject(entry) && isObject(entry["derivedTextData"]) ? entry["derivedTextData"]["baselines"] : undefined;
1409
+ if (!Array.isArray(derived))
1410
+ continue;
1411
+ const at = `${where} derivedSymbolData[${String(index)}]`;
1412
+ const path = field(entry, "guidPath", "object", at);
1413
+ const target = path === undefined ? undefined : resolve((field(path, "guids", "list", `${at}.guidPath`) ?? []).map((guid) => guidText(guid, `${at}.guidPath`)));
1414
+ if (target !== undefined && target !== INSIDE_LEFT_OUT && !("flattenedInto" in target))
1415
+ laidOut.set(target.key, derived);
1416
+ }
1417
+ for (const { target, fields } of pending.values()) {
1418
+ if (target.layer.node.type !== "text" || Object.keys(fields).length === 0)
1419
+ continue;
1420
+ const own = laidOut.get(target.key);
1421
+ if (own !== undefined)
1422
+ fields[LAID_OUT_LINES_FIELD] = own;
1423
+ else if (LINE_SETTERS.some((name) => name in fields))
1424
+ fields[LAID_OUT_LINES_FIELD] = [];
1425
+ }
1017
1426
  const heldSizing = new Map();
1018
- for (const { target, fields, override, sizing } of pending.values()) {
1019
- if (sizing !== undefined) {
1020
- const base = context.convertAlone(sizing.from);
1021
- const next = context.convertAlone(sizing.from, sizing.fields);
1022
- const changed = base === null || next === null ? undefined : sizingBetween(base, next, sizing.fields);
1427
+ for (const { target, fields, override, frame } of pending.values()) {
1428
+ if (frame !== undefined) {
1429
+ const base = context.convertAlone(frame.from);
1430
+ const next = context.convertAlone(frame.from, frame.fields);
1431
+ if (base?.type === "frame" && next?.type === "frame") {
1432
+ Object.assign(frame.at, frameOverrides(base, next, frame.fields));
1433
+ // Resolve padding after stackMode, even when separate entries enable the stack and pad it.
1434
+ for (const { name, sides, value } of frame.padding ?? []) {
1435
+ if (next.layout.kind === "absolute")
1436
+ context.leftOutField(name);
1437
+ else {
1438
+ const padding = (frame.at.padding ??= {});
1439
+ for (const side of sides)
1440
+ padding[side] = value;
1441
+ }
1442
+ }
1443
+ if ("cornerSmoothing" in frame.fields)
1444
+ frame.at.cornerSmoothing = next.style?.cornerSmoothing ?? 0;
1445
+ if ("frameMaskDisabled" in frame.fields)
1446
+ frame.at.clipContent = !!next.clipContent;
1447
+ }
1448
+ const changed = base === null || next === null ? undefined : sizingBetween(base, next, frame.fields);
1023
1449
  if (changed?.sizing !== undefined)
1024
- sizing.at["sizing"] = changed.sizing;
1025
- if (changed?.sizing !== undefined && sizing.holders.length > 0)
1026
- heldSizing.set(sizing.key, { axes: changed.same, holders: sizing.holders });
1450
+ frame.at["sizing"] = changed.sizing;
1451
+ if (changed?.sizing !== undefined && frame.holders.length > 0)
1452
+ heldSizing.set(frame.key, { axes: changed.same, holders: frame.holders });
1027
1453
  }
1028
1454
  const { figma } = target.layer;
1029
1455
  const direct = target.through.length === 0;
1030
1456
  if (Object.keys(fields).length === 0 && !(direct && readsModes(target.layer)))
1031
1457
  continue;
1032
1458
  const { variableConsumptionMap: ownMap, ...plain } = fields;
1459
+ if (OPEN_TYPE_TOGGLES.some(name => name in plain))
1460
+ Object.assign(plain, inheritOpenTypeToggles(figma.change, plain));
1033
1461
  // A locally authored paint or effect list replaces the main's style reference as well as its list.
1034
1462
  if (context.fileOverride)
1035
1463
  for (const [ref, list] of STYLE_REFERENCE_FIELDS)
1036
1464
  if (list in plain && !(ref in plain))
1037
1465
  plain[ref] = undefined;
1038
1466
  const shownBy = direct ? { instance, symbol: component.symbol, modes: modeOverrides } : undefined;
1039
- const base = context.convertAlone(figma);
1040
- // A text's line height is converted from its variable, so the bindings the override supplies or replaces go in too.
1041
- const textBindings = ownMap !== undefined && target.layer.node.type === "text"
1042
- && (bindsField({ variableConsumptionMap: ownMap }, "LINE_HEIGHT") || bindsField({ variableConsumptionMap: ownMap }, "FONT_SIZE"));
1043
- const converted = textBindings ? { ...plain, variableConsumptionMap: withBindingEntries(figma.change["variableConsumptionMap"], ownMap) } : plain;
1467
+ const inherited = innerTextFields(target, context);
1468
+ const base = context.convertAlone(figma, inherited);
1469
+ // Convert each text run with the sources left after applying the instance's literals and bindings.
1470
+ const replacesTextStyle = !!context.fileOverride && plain["styleIdForText"] !== undefined;
1471
+ const textBindings = target.layer.node.type === "text" && (ownMap !== undefined || replacesTextStyle || context.fileOverride && Object.keys(plain).some(k => ["fontName", "fontSize", "lineHeight", "letterSpacing"].includes(k)));
1472
+ const unbound = withOverrides(inherited ? { ...figma.change, ...inherited } : figma.change, plain, replacesTextStyle);
1473
+ const mergedMap = ownMap === undefined ? unbound["variableConsumptionMap"] : withBindingEntries(unbound["variableConsumptionMap"], ownMap);
1474
+ const own = target.layer.node.type === "text" && (ownMap !== undefined || plain["textData"] !== undefined)
1475
+ ? { [OWN_TYPOGRAPHY]: { ...(ownMap !== undefined && { variableConsumptionMap: ownMap }), ...(plain["textData"] !== undefined && { textData: true }) } } : {};
1476
+ const converted = textBindings || inherited ? { ...inherited, ...plain, variableConsumptionMap: mergedMap, ...own } : { ...plain, ...own };
1044
1477
  // Only a layer that reads its instance's modes converts once per instance; the rest share one conversion.
1045
1478
  const next = context.convertAlone(figma, converted, readsModes(target.layer) || textBindings ? shownBy : undefined);
1046
1479
  if (base === null || next === null) {
@@ -1054,8 +1487,7 @@ export function instanceFields(instance, component, self, context) {
1054
1487
  context.report("property-left-out", `an override of a layer's stroke cap to ${cap} is left out: Taco has no such cap`);
1055
1488
  }
1056
1489
  // The bindings the override makes: a variable it binds, and `null` for a component binding of a field it sets plainly.
1057
- const unbound = withOverrides(figma.change, plain);
1058
- const nextFigma = { ...figma, change: ownMap === undefined ? unbound : { ...unbound, variableConsumptionMap: withBindingEntries(unbound["variableConsumptionMap"], ownMap) } };
1490
+ const nextFigma = { ...figma, change: ownMap === undefined ? unbound : { ...unbound, variableConsumptionMap: mergedMap } };
1059
1491
  const before = context.bindingsOf(base, figma);
1060
1492
  const after = context.bindingsOf(next, nextFigma, shownBy);
1061
1493
  // Between the bound layers, so that a font style the override binds, or this instance's modes give, reaches the text.
@@ -1090,7 +1522,55 @@ export function instanceFields(instance, component, self, context) {
1090
1522
  return found;
1091
1523
  };
1092
1524
  // The property values this instance gives its component, read here for the slot frames they show or hide.
1093
- const propertyValues = assignedPropertyValues(field(instance.change, "componentPropAssignments", "list", where), component.properties, component.variantDefs, componentIdOf, leftOutValue(component), where, context.report);
1525
+ const propertyValues = assignedPropertyValues(assignNestedValues(field(instance.change, "componentPropAssignments", "list", where), component, [], where), component.properties, component.variantDefs, componentIdOf, leftOutValue(component, ""), where, context.report, captureLinks(component, ""));
1526
+ for (const { shown, path, id, text, data } of assignedLinks.values()) {
1527
+ const table = new Map();
1528
+ for (const row of data["styleOverrideTable"]) {
1529
+ if (isObject(row) && typeof row["styleID"] === "number" && row["styleID"] !== 0 && Object.hasOwn(row, "hyperlink"))
1530
+ table.set(row["styleID"], hyperlinkOf(row["hyperlink"], context.report));
1531
+ }
1532
+ const ids = field(data, "characterStyleIDs", "list", where) ?? [];
1533
+ const prefix = path ? parseLayerPath(path) : [];
1534
+ for (const { figma, node } of shown.layers.values()) {
1535
+ if (node.type !== "text")
1536
+ continue;
1537
+ const ref = field(figma.change, "componentPropRefs", "list", where)?.findLast(ref => isObject(ref) && ref["componentPropNodeField"] === "TEXT_DATA" && ref["defID"] !== undefined && ref["isDeleted"] !== true);
1538
+ if (!isObject(ref) || propertyByFigmaId(shown.properties, guidText(ref["defID"], where))?.definition.id !== id)
1539
+ continue;
1540
+ const key = layerPathKey([...prefix, node.id]);
1541
+ const at = overrideAt(key), fields = pending.get(key)?.fields;
1542
+ // A paint override can produce full paragraphs too. Use their formatting for the
1543
+ // assignment unless the occurrence actually overrode its text body or links.
1544
+ if (at["characters"] !== undefined || (at["paragraphs"] !== undefined &&
1545
+ (fields?.["textData"] !== undefined || fields?.["hyperlink"] !== undefined)))
1546
+ continue;
1547
+ const source = at["paragraphs"];
1548
+ let i = 0, applied = false;
1549
+ const paragraphs = paragraphsFromCharacters(text, source ?? node.paragraphs).map(paragraph => {
1550
+ const runs = paragraph.runs.flatMap(run => {
1551
+ if (!run.text)
1552
+ return [run];
1553
+ const { hyperlink: inherited, ...style } = run;
1554
+ const parts = [];
1555
+ for (const char of run.text) {
1556
+ const raw = ids[i++], override = typeof raw === "number" && table.has(raw);
1557
+ const hyperlink = override ? table.get(raw) : inherited;
1558
+ const last = parts.at(-1);
1559
+ if (last && last.hyperlink === hyperlink)
1560
+ last.text += char;
1561
+ else
1562
+ parts.push({ ...style, text: char, ...(hyperlink !== undefined && { hyperlink }) });
1563
+ applied ||= override;
1564
+ }
1565
+ return parts;
1566
+ });
1567
+ ++i; // The paragraph break also consumes a Figma character style ID.
1568
+ return { ...paragraph, runs };
1569
+ });
1570
+ if (applied)
1571
+ at["paragraphs"] = paragraphs;
1572
+ }
1573
+ }
1094
1574
  // Whether a frame keeps its size along `axis` when its parent is resized: only Left and Right, Top and Bottom, or Scale stretch it.
1095
1575
  const stretches = (node, axis) => {
1096
1576
  const constraint = "constraints" in node ? node.constraints?.[axis === "width" ? "horizontal" : "vertical"] : undefined;
@@ -1134,7 +1614,7 @@ export function instanceFields(instance, component, self, context) {
1134
1614
  else if (target === undefined || "flattenedInto" in target || target.layer.figma.type !== "INSTANCE")
1135
1615
  inComponent = undefined;
1136
1616
  else {
1137
- inComponent = shownAt(keys, target.layer.figma, target.component);
1617
+ inComponent = shownAt(keys, target.layer.figma, target.component, target.through);
1138
1618
  pathIds = parseLayerPath(target.key) ?? [];
1139
1619
  const nested = target.layer.node;
1140
1620
  values = { ...nested.propertyValues, ...overrides[target.key]?.["propertyValues"] };
@@ -1172,7 +1652,9 @@ export function instanceFields(instance, component, self, context) {
1172
1652
  const unconditioned = boundLayers.filter(({ node }) => node.condition === undefined);
1173
1653
  const slotLayer = unconditioned.find(effectivelyVisible) ?? unconditioned[0];
1174
1654
  if (property === undefined || slotLayer === undefined) {
1175
- context.report("property-left-out", "the content placed in a slot names no imported slot of the component; it is left out");
1655
+ context.report("property-left-out", keys.length
1656
+ ? "a nested slot assignment has no imported slot declaration or bound frame"
1657
+ : "the content placed in a slot names no imported slot of the component; it is left out");
1176
1658
  continue;
1177
1659
  }
1178
1660
  const pathKey = layerPathKey(pathIds);
@@ -1215,7 +1697,7 @@ export function instanceFields(instance, component, self, context) {
1215
1697
  const nextStyle = styleOf(next);
1216
1698
  for (const name of STYLE_OVERRIDES) {
1217
1699
  if (!same(baseStyle[name], nextStyle[name]))
1218
- at[name] = nextStyle[name] ?? (name === "layerBlur" || name === "backgroundBlur" ? 0 : []);
1700
+ at[name] = nextStyle[name] ?? (name === "layerBlur" || name === "backgroundBlur" || name === "cornerSmoothing" ? 0 : []);
1219
1701
  }
1220
1702
  if (next.opacity !== boundBase.opacity)
1221
1703
  at["opacity"] = next.opacity;
@@ -1232,7 +1714,7 @@ export function instanceFields(instance, component, self, context) {
1232
1714
  if (Object.keys(bindings).length > 0)
1233
1715
  at["variableBindings"] = { ...at["variableBindings"], ...bindings };
1234
1716
  }
1235
- // Instances cannot override layout, so the slot frame's direction, gap, padding and alignment hold.
1717
+ // Slot content contributes children to the host, whose own layout arranges them.
1236
1718
  const layoutOf = (frame) => {
1237
1719
  if (frame.type !== "frame")
1238
1720
  return undefined;
@@ -1244,18 +1726,19 @@ export function instanceFields(instance, component, self, context) {
1244
1726
  context.report("approximated", "a slot's content frame has another layout (direction, gap, padding or alignment) than its slot frame; the slot frame's layout is used");
1245
1727
  }
1246
1728
  }
1247
- if (unmatched > 0)
1248
- context.report("property-left-out", "an override path that names no imported layer of the component is left out");
1249
- if (insideLeftOut > 0)
1729
+ for (const _ of insideLeftOut)
1250
1730
  context.report("property-left-out", "an override inside a swap that was left out is left out too");
1251
1731
  const kept = Object.fromEntries(Object.entries(overrides).filter(([, value]) => Object.keys(value).length > 0));
1732
+ // Some instances store their own rows only on the override of the root.
1733
+ const exportSettings = instance.change["exportSettings"] === undefined ? exportSettingsOf(rootExports, context.report) : undefined;
1252
1734
  return {
1253
1735
  fields: {
1736
+ ...(exportSettings === undefined ? {} : { exportSettings }),
1254
1737
  ...(Object.keys(kept).length > 0 ? { overrides: kept } : {}),
1255
1738
  ...(Object.keys(propertyValues).length > 0 ? { propertyValues } : {}),
1256
1739
  ...(Object.keys(slots).length > 0 ? { slots } : {}),
1257
1740
  },
1258
- swaps: swapsKept,
1741
+ swaps: swapsKept, pathSwaps,
1259
1742
  filledSlots,
1260
1743
  nested: new Map([...pending.values()].filter(({ target }) => target.through.length > 0).map(({ target }) => [target.key, target.through])),
1261
1744
  heldSizing,