@moondraft/import 0.1.0 → 0.2.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 (84) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/README.md +2 -2
  3. package/SOURCE.md +229 -4
  4. package/dist/adapter/convert.d.ts +24 -2
  5. package/dist/adapter/convert.js +669 -160
  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 +12 -0
  11. package/dist/adapter/figma-handoff.js +167 -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 +14 -4
  16. package/dist/adapter/file-components.d.ts +9 -3
  17. package/dist/adapter/file-components.js +122 -32
  18. package/dist/adapter/file-resources.js +316 -27
  19. package/dist/adapter/image-crop.d.ts +18 -0
  20. package/dist/adapter/image-crop.js +30 -0
  21. package/dist/adapter/link.d.ts +5 -1
  22. package/dist/adapter/link.js +308 -104
  23. package/dist/adapter/payload.js +1 -1
  24. package/dist/adapter/variables.d.ts +2 -1
  25. package/dist/adapter/variables.js +5 -2
  26. package/dist/figma.js +167 -33
  27. package/dist/index.d.ts +1 -0
  28. package/dist/index.js +1 -0
  29. package/dist/report.d.ts +28 -1
  30. package/dist/report.js +102 -29
  31. package/dist/serialize.d.ts +7 -0
  32. package/dist/serialize.js +79 -0
  33. package/dist/taco/figma-import/container/kiwiContainer.d.ts +3 -0
  34. package/dist/taco/figma-import/container/kiwiContainer.js +1 -1
  35. package/dist/taco/figma-import/import/carry.d.ts +14 -1
  36. package/dist/taco/figma-import/import/carry.js +34 -1
  37. package/dist/taco/figma-import/import/componentProps.d.ts +10 -4
  38. package/dist/taco/figma-import/import/componentProps.js +29 -13
  39. package/dist/taco/figma-import/import/componentSets.d.ts +2 -0
  40. package/dist/taco/figma-import/import/componentSets.js +1 -1
  41. package/dist/taco/figma-import/import/converters/exportSettings.d.ts +4 -0
  42. package/dist/taco/figma-import/import/converters/exportSettings.js +49 -0
  43. package/dist/taco/figma-import/import/converters/frame.js +8 -0
  44. package/dist/taco/figma-import/import/converters/gradient.d.ts +2 -0
  45. package/dist/taco/figma-import/import/converters/gradient.js +3 -1
  46. package/dist/taco/figma-import/import/converters/group.d.ts +2 -4
  47. package/dist/taco/figma-import/import/converters/group.js +6 -15
  48. package/dist/taco/figma-import/import/converters/image.d.ts +1 -1
  49. package/dist/taco/figma-import/import/converters/image.js +22 -11
  50. package/dist/taco/figma-import/import/converters/layout.d.ts +3 -4
  51. package/dist/taco/figma-import/import/converters/layout.js +40 -21
  52. package/dist/taco/figma-import/import/converters/rectangle.d.ts +1 -1
  53. package/dist/taco/figma-import/import/converters/rectangle.js +1 -1
  54. package/dist/taco/figma-import/import/converters/section.d.ts +2 -3
  55. package/dist/taco/figma-import/import/converters/section.js +3 -9
  56. package/dist/taco/figma-import/import/converters/shared.d.ts +7 -4
  57. package/dist/taco/figma-import/import/converters/shared.js +15 -5
  58. package/dist/taco/figma-import/import/converters/text.d.ts +14 -1
  59. package/dist/taco/figma-import/import/converters/text.js +143 -12
  60. package/dist/taco/figma-import/import/converters/vector.d.ts +36 -15
  61. package/dist/taco/figma-import/import/converters/vector.js +214 -73
  62. package/dist/taco/figma-import/import/converters/vectorNetwork.d.ts +19 -3
  63. package/dist/taco/figma-import/import/converters/vectorNetwork.js +147 -29
  64. package/dist/taco/figma-import/import/instances.d.ts +25 -4
  65. package/dist/taco/figma-import/import/instances.js +324 -117
  66. package/dist/taco/figma-import/import/styles.d.ts +2 -0
  67. package/dist/taco/figma-import/import/styles.js +6 -0
  68. package/dist/taco/figma-import/import/variables.d.ts +3 -2
  69. package/dist/taco/figma-import/import/variables.js +37 -30
  70. package/dist/taco/figma-import/import/variantTrees.d.ts +1 -1
  71. package/dist/taco/figma-import/import/variantTrees.js +44 -4
  72. package/dist/taco/figma-import/import/walk.d.ts +53 -5
  73. package/dist/taco/figma-import/import/walk.js +273 -106
  74. package/dist/taco/figma-import/kiwi/message.d.ts +4 -2
  75. package/dist/taco/figma-import/kiwi/message.js +13 -11
  76. package/dist/taco/model/codec.d.ts +1 -1
  77. package/dist/taco/model/codec.js +37 -7
  78. package/dist/taco/model/component-evaluation.d.ts +2 -0
  79. package/dist/taco/model/component-evaluation.js +7 -0
  80. package/dist/taco/model/instance-resolver.d.ts +6 -2
  81. package/dist/taco/model/instance-resolver.js +48 -18
  82. package/dist/taco/model/sha256.js +13 -8
  83. package/dist/taco/model/types.d.ts +23 -1
  84. package/package.json +3 -2
@@ -35,6 +35,8 @@ export type StyleBackedList = keyof typeof STYLE_BACKED;
35
35
  export declare const STYLE_REFERENCE_FIELDS: ReadonlyMap<string, StyleBackedList>;
36
36
  /** Figma's style reference for "no style": a guid with both parts 0xffffffff, written when a layer or an override detaches a style. */
37
37
  export declare function isDetachedStyle(reference: unknown): boolean;
38
+ /** A grid style reference, including the GUID used in older files. A detach takes precedence over a legacy ID. */
39
+ export declare function gridStyleReference(change: FigmaObject): unknown;
38
40
  /**
39
41
  * The `effects`, `fillPaints` or `strokePaints` Figma draws for a layer whose fields are `change`: those of the style
40
42
  * the layer names (`styleIdForEffect`, `styleIdForFill`, `styleIdForStrokeFill`), else the layer's own. Figma draws a
@@ -15,6 +15,12 @@ export function isDetachedStyle(reference) {
15
15
  const guid = isObject(reference) ? reference["guid"] : undefined;
16
16
  return isObject(guid) && guid["sessionID"] === 0xffffffff && guid["localID"] === 0xffffffff;
17
17
  }
18
+ /** A grid style reference, including the GUID used in older files. A detach takes precedence over a legacy ID. */
19
+ export function gridStyleReference(change) {
20
+ const legacy = change["inheritGridStyleID"];
21
+ const reference = change["styleIdForGrid"] ?? (legacy === undefined ? undefined : { guid: legacy });
22
+ return isDetachedStyle(reference) ? undefined : reference;
23
+ }
18
24
  /** The report reason for a layer whose `list` names a style the message does not have. */
19
25
  function missingStyleReason(list) {
20
26
  const { style, what } = STYLE_BACKED[list];
@@ -86,8 +86,9 @@ export interface ShownBy {
86
86
  * every `VARIABLE` in it with a value for each mode. A set or variable Figma marks deleted (`isSoftDeleted`) is left
87
87
  * out, as is a variable whose set is not in the message or whose type Taco lacks; each is reported. Taco variables
88
88
  * hold no aliases, so an alias takes the value it resolves to: in the same mode within its own collection, else in
89
- * the other collection's default mode. A mode without a value takes the default mode's. Two collections of one name
90
- * get a number, so that `var('collection/name')` can tell them apart. A number variable scoped to opacity alone (layer
89
+ * the other collection's default mode. A mode without a value takes the default mode's. Without `keepAliases`, two
90
+ * collections of one name get a number, so that `var('collection/name')` can tell them apart; with it, each keeps
91
+ * its Figma name. A number variable scoped to opacity alone (layer
91
92
  * or color opacity) holds Figma's percentage, so it is imported divided by 100, on Taco's 0 to 1 scale. Ids come from
92
93
  * `newId`.
93
94
  * @param nodes - Source nodes in file order.
@@ -26,13 +26,20 @@ function bySortPosition(items, position) {
26
26
  .map(({ item }) => item);
27
27
  }
28
28
  const quoted = (text) => JSON.stringify(text);
29
+ // Parsing callbacks belong to the read stage. The returned variable lookups must
30
+ // not retain the walk's report callback (and with it the decoded file and all its caches).
31
+ function leaveOutVariable(known, node, report, why) {
32
+ known.set(node, { missing: `the variable ${quoted(node.name)} is not imported: ${why}` });
33
+ report(node, "node-left-out", `the variable is not imported: ${why}`);
34
+ }
29
35
  /**
30
36
  * Every `VARIABLE_SET` of the message as a collection, its modes in Figma's order (the first is the default), and
31
37
  * every `VARIABLE` in it with a value for each mode. A set or variable Figma marks deleted (`isSoftDeleted`) is left
32
38
  * out, as is a variable whose set is not in the message or whose type Taco lacks; each is reported. Taco variables
33
39
  * hold no aliases, so an alias takes the value it resolves to: in the same mode within its own collection, else in
34
- * the other collection's default mode. A mode without a value takes the default mode's. Two collections of one name
35
- * get a number, so that `var('collection/name')` can tell them apart. A number variable scoped to opacity alone (layer
40
+ * the other collection's default mode. A mode without a value takes the default mode's. Without `keepAliases`, two
41
+ * collections of one name get a number, so that `var('collection/name')` can tell them apart; with it, each keeps
42
+ * its Figma name. A number variable scoped to opacity alone (layer
36
43
  * or color opacity) holds Figma's percentage, so it is imported divided by 100, on Taco's 0 to 1 scale. Ids come from
37
44
  * `newId`.
38
45
  * @param nodes - Source nodes in file order.
@@ -87,24 +94,28 @@ export function readFigmaVariables(nodes, newId, report, keepAliases = false) {
87
94
  sources.set(id, node);
88
95
  setVariables.set(id, {});
89
96
  const modeNames = new Set();
90
- const set = { node, id, modes: modes.map((mode, index) => {
91
- const base = mode.name || `Mode ${String(index + 1)}`;
92
- let name = base;
93
- if (keepAliases) {
94
- for (let i = 2; modeNames.has(name); i++)
95
- name = base + " " + String(i);
96
- if (name !== base)
97
- report(node, "approximated", `variable mode renamed from ${quoted(base)} to ${quoted(name)}`);
98
- modeNames.add(name);
99
- }
100
- return { ...mode, id: newId(), name };
101
- }) };
97
+ const namedModes = [];
98
+ for (const [index, mode] of modes.entries()) {
99
+ const base = mode.name || `Mode ${String(index + 1)}`;
100
+ let name = base;
101
+ if (keepAliases) {
102
+ for (let i = 2; modeNames.has(name); i++)
103
+ name = base + " " + String(i);
104
+ if (name !== base)
105
+ report(node, "approximated", `variable mode renamed from ${quoted(base)} to ${quoted(name)}`);
106
+ modeNames.add(name);
107
+ }
108
+ namedModes.push({ ...mode, id: newId(), name });
109
+ }
110
+ const set = { node, id, modes: namedModes };
102
111
  for (const at of keys)
103
112
  setsByKey.set(at, set);
104
113
  const base = node.name || "Collection";
105
114
  let name = base;
106
- for (let seen = 2; names.has(name); seen++)
107
- name = `${base} ${String(seen)}`;
115
+ // Native file records name collections by id, as Figma does, so only the literal reader numbers a repeated name.
116
+ if (!keepAliases)
117
+ for (let seen = 2; names.has(name); seen++)
118
+ name = `${base} ${String(seen)}`;
108
119
  names.add(name);
109
120
  if (name !== base)
110
121
  report(node, "approximated", `the variable collection is imported as ${quoted(name)}: another collection is named ${quoted(base)}`);
@@ -173,13 +184,8 @@ export function readFigmaVariables(nodes, newId, report, keepAliases = false) {
173
184
  };
174
185
  const known = new Map();
175
186
  let scoped;
176
- let described;
177
187
  for (const node of bySortPosition(variables, (variable) => field(variable.change, "sortPosition", "string", `node ${variable.id}`))) {
178
188
  const where = `node ${node.id}`;
179
- const leaveOut = (why) => {
180
- known.set(node, { missing: `the variable ${quoted(node.name)} is not imported: ${why}` });
181
- report(node, "node-left-out", `the variable is not imported: ${why}`);
182
- };
183
189
  if (deleted(node)) {
184
190
  known.set(node, { missing: `the variable ${quoted(node.name)} is deleted in Figma` });
185
191
  report(node, "node-left-out", "the variable is deleted in Figma; it is not imported");
@@ -187,13 +193,13 @@ export function readFigmaVariables(nodes, newId, report, keepAliases = false) {
187
193
  }
188
194
  const set = setOf(node);
189
195
  if (typeof set === "string") {
190
- leaveOut(set);
196
+ leaveOutVariable(known, node, report, set);
191
197
  continue;
192
198
  }
193
199
  const figmaType = field(node.change, "variableResolvedType", "string", where);
194
200
  const type = figmaType === undefined || !Object.hasOwn(TYPES, figmaType) ? undefined : TYPES[figmaType];
195
201
  if (type === undefined) {
196
- leaveOut(`Taco variables have no ${figmaType ?? "typeless"} type`);
202
+ leaveOutVariable(known, node, report, `Taco variables have no ${figmaType ?? "typeless"} type`);
197
203
  continue;
198
204
  }
199
205
  const resolved = set.modes.map((mode) => {
@@ -202,7 +208,7 @@ export function readFigmaVariables(nodes, newId, report, keepAliases = false) {
202
208
  });
203
209
  const fallback = resolved[0].value !== undefined ? resolved[0] : resolved.find((entry) => entry.value !== undefined);
204
210
  if (fallback?.value === undefined) {
205
- leaveOut(`no mode has a value Taco can hold (${resolved.map(({ mode, reason }) => `${quoted(mode.name)}: ${reason ?? ""}`).join(", ")})`);
211
+ leaveOutVariable(known, node, report, `no mode has a value Taco can hold (${resolved.map(({ mode, reason }) => `${quoted(mode.name)}: ${reason ?? ""}`).join(", ")})`);
206
212
  continue;
207
213
  }
208
214
  const scopes = field(node.change, "variableScopes", "list", where) ?? [];
@@ -219,10 +225,8 @@ export function readFigmaVariables(nodes, newId, report, keepAliases = false) {
219
225
  if (!keepAliases && aliased.length > 0) {
220
226
  report(node, "approximated", `aliases are imported as the values they resolve to, so the variable no longer follows them: ${aliased.map(({ mode, aliases }) => `${quoted(mode.name)} → ${aliases.map(quoted).join(" → ")}`).join(", ")}`);
221
227
  }
222
- if (scopes.some((scope) => scope !== "ALL_SCOPES"))
228
+ if (!keepAliases && scopes.some((scope) => scope !== "ALL_SCOPES"))
223
229
  scoped = { node: scoped?.node ?? node, count: (scoped?.count ?? 0) + 1 };
224
- if ((field(node.change, "description", "string", where) ?? "") !== "")
225
- described = { node: described?.node ?? node, count: (described?.count ?? 0) + 1 };
226
230
  const id = newId();
227
231
  if (keepAliases) {
228
232
  sources.set(id, node);
@@ -270,9 +274,6 @@ export function readFigmaVariables(nodes, newId, report, keepAliases = false) {
270
274
  if (scoped !== undefined) {
271
275
  report(scoped.node, "property-left-out", `Figma variable scopes are not imported: ${String(scoped.count)} scoped variable${scoped.count === 1 ? " is" : "s are"} offered for every property of ${scoped.count === 1 ? "its" : "their"} type, first this one`);
272
276
  }
273
- if (described !== undefined) {
274
- report(described.node, "property-left-out", `variable descriptions are not imported: ${String(described.count)} variable${described.count === 1 ? " has" : "s have"} one, first this one`);
275
- }
276
277
  // The value of the variable an `ALIAS` binding `data` of layer `figma` names, in the mode the layer uses (`fontStyleOf`).
277
278
  const valueAt = (data, type, figma, where, shownBy) => {
278
279
  if (!isObject(data) || field(data, "dataType", "string", where) !== "ALIAS")
@@ -544,6 +545,12 @@ export function bindLayerVariables(layer, figma, variables, report, overridden =
544
545
  const bound = group.fields.filter((name) => byField.has(name));
545
546
  if (bound.length === 0)
546
547
  continue;
548
+ // Saved files install these fields independently from their original records in the native adapter.
549
+ if (variables?.sources.size) {
550
+ for (const name of bound)
551
+ byField.delete(name);
552
+ continue;
553
+ }
547
554
  const keys = bound.map((name) => JSON.stringify(byField.get(name)));
548
555
  if (bound.length === group.fields.length && keys.every((key) => key === keys[0])) {
549
556
  candidates.push({ label: bound.join(", "), property: group.property, data: byField.get(bound[0]) });
@@ -14,7 +14,7 @@ export declare function remapVariantNode(node: SceneNode, mapping: ReadonlyMap<N
14
14
  componentId: ComponentDefinition["id"];
15
15
  condition: string;
16
16
  }>): SceneNode;
17
- export declare function mergeVariantTrees(nodes: readonly SceneNode[], components: readonly ComponentDefinition[], plans: readonly VariantTreePlan[], theme: DocumentTheme): {
17
+ export declare function mergeVariantTrees(nodes: readonly SceneNode[], components: readonly ComponentDefinition[], plans: readonly VariantTreePlan[], theme: DocumentTheme, distinctLayers?: ReadonlySet<NodeId>): {
18
18
  nodes: SceneNode[];
19
19
  layerOf: ReadonlyMap<NodeId, NodeId>;
20
20
  };
@@ -1,6 +1,10 @@
1
1
  import { EXPRESSION_TYPES, checkExpressionSource, componentExpressionEnvironment, componentValueEnvironment, evaluateExpression, expressionValuesEqual, computableFieldsOf, computableFieldType, expressionValueSource, formatExpressionString, layerPathKey, parseExpression, parseLayerPath, resolveTextStyle, storedFieldValue, variablePropertiesOfField, variablesByExpressionName, variableExpressionType, writeValueTable, } from "../../model/index.js";
2
- const stable = (value) => JSON.stringify(value, (_, item) => item !== null && typeof item === "object" && !Array.isArray(item)
3
- ? Object.fromEntries(Object.entries(item).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0)) : item);
2
+ import { imageCropOf, imageTileOf, withImageCrop } from "./carry.js";
3
+ const stable = (value) => JSON.stringify(value, (key, item) => {
4
+ const carried = withImageCrop(key, item);
5
+ return carried !== null && typeof carried === "object" && !Array.isArray(carried)
6
+ ? Object.fromEntries(Object.entries(carried).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0)) : carried;
7
+ });
4
8
  const same = (values) => {
5
9
  const first = stable(values[0]);
6
10
  return values.every((value) => stable(value) === first);
@@ -180,6 +184,31 @@ function remainder(document, member, root) {
180
184
  // Moondraft patch (carry.ts): metadata (what figma-import carries) does not split a layer; the merged layer keeps the first variant's.
181
185
  for (const key of ["id", "children", "expressions", "condition", "metadata"])
182
186
  delete rest[key];
187
+ // Geometry and layout settings carried for Moondraft can differ between variants and split the layer.
188
+ const figma = node.metadata?.["figma"];
189
+ if (figma?.boolean !== undefined)
190
+ rest["boolean"] = figma.boolean;
191
+ if (figma?.vectorStrokeCaps && Object.keys(figma.vectorStrokeCaps).length > 0)
192
+ rest["vectorStrokeCaps"] = figma.vectorStrokeCaps;
193
+ if (figma?.firstOnTop === true)
194
+ rest["firstOnTop"] = true;
195
+ if (figma?.fillSizing !== undefined)
196
+ rest["fillSizing"] = figma.fillSizing;
197
+ if (figma?.groupConstraints !== undefined)
198
+ rest["groupConstraints"] = figma.groupConstraints;
199
+ // Region paints keep image placement in WeakMap marks, which structuredClone cannot copy.
200
+ if (node.type === "shape" && node.shape === "path") {
201
+ const placement = node.vectorNetwork.regions.flatMap((region, regionIndex) => (region.fills ?? []).flatMap((paint, paintIndex) => {
202
+ if (paint.kind !== "image")
203
+ return [];
204
+ const tile = imageTileOf(paint), crop = imageCropOf(paint);
205
+ return tile === undefined && crop === undefined ? [] : [{ regionIndex, paintIndex, tile, crop }];
206
+ }));
207
+ if (placement.length > 0)
208
+ rest["regionImagePlacement"] = placement;
209
+ if (figma?.regionCropSize !== undefined)
210
+ rest["regionCropSize"] = figma.regionCropSize;
211
+ }
183
212
  if (root)
184
213
  for (const key of ["name", "aspectRatio", "aspectRatioLocked"])
185
214
  delete rest[key];
@@ -210,8 +239,12 @@ function remainder(document, member, root) {
210
239
  if (layout !== undefined && layout["kind"] !== "absolute") {
211
240
  for (const key of ["gap", "wrapGap", "columnGap", "rowGap", "padding", "align", "justify", "wrap"])
212
241
  delete layout[key];
213
- if (["horizontal", "vertical"].includes(String(layout["kind"])))
242
+ if (["horizontal", "vertical"].includes(String(layout["kind"]))) {
214
243
  layout["kind"] = "stack";
244
+ const figma = node.metadata?.["figma"];
245
+ if (figma?.strokesIncluded === true)
246
+ layout["strokesIncluded"] = true;
247
+ }
215
248
  }
216
249
  if (node.type === "instance") {
217
250
  delete rest["propertyValues"];
@@ -269,7 +302,7 @@ export function remapVariantNode(node, mapping, scopes = new Map()) {
269
302
  }
270
303
  return { ...node, overrides, ...(slots === undefined ? {} : { slots }) };
271
304
  }
272
- export function mergeVariantTrees(nodes, components, plans, theme) {
305
+ export function mergeVariantTrees(nodes, components, plans, theme, distinctLayers) {
273
306
  const byId = new Map(nodes.map((node) => [node.id, node]));
274
307
  const document = { nodes: Object.fromEntries(byId), components: Object.fromEntries(components.map((component) => [component.id, component])), theme };
275
308
  const mapping = new Map();
@@ -334,6 +367,8 @@ export function mergeVariantTrees(nodes, components, plans, theme) {
334
367
  const members = group.members.map((member) => member.remapped ? member : ({ ...member, node: remapVariantNode(member.node, mapping, scopes), remapped: true }));
335
368
  const base = members[0].node;
336
369
  const id = base.id;
370
+ if (distinctLayers?.size)
371
+ fail("layer metadata", members.map(({ node }) => distinctLayers.has(node.id) ? node.id : undefined));
337
372
  const rest = members.map((member) => remainder(document, member, root));
338
373
  for (const other of rest.slice(1))
339
374
  for (const field of differences(rest[0], other)) {
@@ -361,6 +396,11 @@ export function mergeVariantTrees(nodes, components, plans, theme) {
361
396
  const bound = members.map(({ node }) => variablePropertiesOfField(field).map((key) => node.variableBindings?.[key]));
362
397
  if (same(values) && same(existing) && same(bound))
363
398
  continue;
399
+ // A fill expression cannot carry crop marks on the paints it creates.
400
+ if (field === "fills" && values.some((value) => value?.kind === "list" && value.items.some((item) => item.kind === "paint" && imageCropOf(item.value)))) {
401
+ fail(field, values);
402
+ continue;
403
+ }
364
404
  // A text expression changes every run; differing rich runs cannot be represented by one field.
365
405
  if (base.type === "text" && members.some(({ node }) => node.type === "text" && (node.paragraphs.length !== 1 || node.paragraphs[0].runs.length !== 1)) && !["width", "height", "visible", "opacity"].includes(field)) {
366
406
  fail(`paragraphs (${field})`, members.map(({ node }) => node.type === "text" ? node.paragraphs : undefined));
@@ -1,9 +1,10 @@
1
1
  import { type AssetId, type ComponentDefinition, type ComponentId, type NodeId, type SceneNode, type TextNode, type TextStyle, type TextStyleId } from "../../model/index.ts";
2
2
  import { type FigmaObject } from "./fields.ts";
3
3
  import { type FigmaStyleList } from "./styles.ts";
4
+ import { type StoredFigmaBox } from "./instances.ts";
4
5
  import { type ImportedProperty } from "./componentProps.ts";
5
6
  import { planSet } from "./componentSets.ts";
6
- import { type FigmaTreeNode } from "./tree.ts";
7
+ import { type FigmaTree, type FigmaTreeNode } from "./tree.ts";
7
8
  import { type FigmaImportedPage, type FigmaImportOptions } from "./types.ts";
8
9
  import type { FigmaImportedImage, FigmaImportReportEntry, FigmaImportReportKind, FigmaImportResult } from "./types.ts";
9
10
  /** What a converter gets besides the node it converts. */
@@ -18,6 +19,8 @@ export interface NodeWalk {
18
19
  convertChildren(): readonly NodeId[];
19
20
  /** Adds a report entry about this node. */
20
21
  report(kind: FigmaImportReportKind, reason: string): void;
22
+ /** Moondraft patch 0010: whether the node is placed by its parent's auto layout (not absolute in it). */
23
+ readonly inFlow?: boolean;
21
24
  /** The bytes of a blob the node refers to (see `blobReader`), or `undefined` when the message has no such blob. */
22
25
  blob(reference: number): Uint8Array | undefined;
23
26
  /**
@@ -29,9 +32,7 @@ export interface NodeWalk {
29
32
  image(hashHex: string, size?: {
30
33
  width: number;
31
34
  height: number;
32
- }): {
33
- assetId: AssetId;
34
- } | string | null;
35
+ }): FigmaImportedImage | string | null;
35
36
  /** Records the source indexes of paints accepted by the native file adapter.
36
37
  * @param source - Original Figma paint list.
37
38
  * @param indices - Original indexes in output order.
@@ -85,6 +86,12 @@ export interface NodeWalk {
85
86
  * @returns The local variable ID, or null for an unresolved binding.
86
87
  */
87
88
  fontSizeVariable?(data: unknown): string | null;
89
+ /** Local variable ID for the solid paint drawn by a saved text run, or null to keep its literal. */
90
+ textColorVariable?(data: unknown): string | null;
91
+ /** Source GUID of a named fill style on a saved text run. */
92
+ textFillStyle?(reference: unknown): string | undefined;
93
+ /** Whether a run draws paint authored in this file instance override. */
94
+ plainTextPaint?(range: FigmaObject | undefined): boolean;
88
95
  /** The font size Taco draws text `layer`, converted from this node, at where it keeps the node's font size binding (`keptFontSize`). */
89
96
  keptFontSize?(layer: TextNode): number | undefined;
90
97
  }
@@ -127,13 +134,17 @@ export declare function readFileMessage(message: unknown, options: FigmaImportOp
127
134
  plan: Exclude<ReturnType<typeof planSet>, string>;
128
135
  properties: ImportedProperty[];
129
136
  }>;
130
- tree: import("./tree.ts").FigmaTree;
137
+ tree: FigmaTree;
131
138
  styleLayers: Map<string, SceneNode>;
139
+ styleNodeFor: (reference: unknown, styleType: string) => FigmaTreeNode | undefined;
132
140
  textStyleUses: Map<FigmaTreeNode, FigmaTextStyleUse>;
133
141
  paintIndices: Map<readonly unknown[], number[]>;
134
142
  effectFields: Map<Readonly<Record<string, unknown>>, string>;
135
143
  occurrenceFields: Map<string, Map<string, Readonly<Record<string, unknown>>>>;
144
+ instanceBoxes: Map<string, Map<string, StoredFigmaBox>>;
145
+ instanceFillSizes: Map<string, Map<string, StoredFigmaBox>>;
136
146
  imported: ImportedNode[];
147
+ omittedSubtrees: Set<FigmaTreeNode>;
137
148
  };
138
149
  rootSource: import("./types.ts").FigmaRootSource;
139
150
  roots: SceneNode[];
@@ -150,6 +161,43 @@ export declare function readFileMessage(message: unknown, options: FigmaImportOp
150
161
  variableCollections: Readonly<Record<string, import("../../model/types.ts").VariableCollection>>;
151
162
  textStyles: Record<string, TextStyle>;
152
163
  };
164
+ /** Reads converted layers with their original Figma nodes for Moondraft's adapters. */
165
+ export declare function walkMessage(message: unknown, options: FigmaImportOptions, native: boolean, distinctSources?: (tree: FigmaTree) => ReadonlySet<string>): {
166
+ sources: {
167
+ variables: import("./variables.ts").FigmaVariables | undefined;
168
+ variants: Map<string, {
169
+ plan: Exclude<ReturnType<typeof planSet>, string>;
170
+ properties: ImportedProperty[];
171
+ }>;
172
+ tree: FigmaTree;
173
+ styleLayers: Map<string, SceneNode>;
174
+ styleNodeFor: (reference: unknown, styleType: string) => FigmaTreeNode | undefined;
175
+ textStyleUses: Map<FigmaTreeNode, FigmaTextStyleUse>;
176
+ paintIndices: Map<readonly unknown[], number[]>;
177
+ effectFields: Map<Readonly<Record<string, unknown>>, string>;
178
+ occurrenceFields: Map<string, Map<string, Readonly<Record<string, unknown>>>>;
179
+ instanceBoxes: Map<string, Map<string, StoredFigmaBox>>;
180
+ instanceFillSizes: Map<string, Map<string, StoredFigmaBox>>;
181
+ imported: ImportedNode[];
182
+ omittedSubtrees: Set<FigmaTreeNode>;
183
+ };
184
+ result: {
185
+ rootSource: import("./types.ts").FigmaRootSource;
186
+ roots: SceneNode[];
187
+ nodes: SceneNode[];
188
+ pages: FigmaImportedPage[];
189
+ report: FigmaImportReportEntry[];
190
+ assets: Record<AssetId, FigmaImportedImage>;
191
+ layerIds: Record<string, NodeId>;
192
+ components: ComponentDefinition[];
193
+ componentIds: Record<string, ComponentId>;
194
+ componentPlacements: {
195
+ [k: string]: ComponentId;
196
+ };
197
+ variableCollections: Readonly<Record<string, import("../../model/types.ts").VariableCollection>>;
198
+ textStyles: Record<string, TextStyle>;
199
+ };
200
+ };
153
201
  /** A converted node with the Figma node it came from and its path. */
154
202
  interface ImportedNode {
155
203
  readonly node: SceneNode;