@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.
- package/CHANGELOG.md +44 -0
- package/README.md +2 -2
- package/SOURCE.md +343 -4
- package/dist/adapter/convert.d.ts +26 -2
- package/dist/adapter/convert.js +817 -217
- package/dist/adapter/figma-descriptions.d.ts +7 -0
- package/dist/adapter/figma-descriptions.js +34 -0
- package/dist/adapter/figma-grids.d.ts +12 -0
- package/dist/adapter/figma-grids.js +175 -0
- package/dist/adapter/figma-handoff.d.ts +34 -0
- package/dist/adapter/figma-handoff.js +188 -0
- package/dist/adapter/figma-hyperlinks.d.ts +13 -0
- package/dist/adapter/figma-hyperlinks.js +77 -0
- package/dist/adapter/figma.d.ts +4 -1
- package/dist/adapter/figma.js +15 -4
- package/dist/adapter/file-components.d.ts +10 -3
- package/dist/adapter/file-components.js +126 -33
- package/dist/adapter/file-resources.js +545 -47
- package/dist/adapter/file-typography.d.ts +6 -0
- package/dist/adapter/file-typography.js +44 -0
- package/dist/adapter/image-crop.d.ts +18 -0
- package/dist/adapter/image-crop.js +30 -0
- package/dist/adapter/link.d.ts +12 -1
- package/dist/adapter/link.js +380 -113
- package/dist/adapter/payload.js +3 -3
- package/dist/adapter/variables.d.ts +2 -1
- package/dist/adapter/variables.js +5 -2
- package/dist/figma-file.d.ts +1 -0
- package/dist/figma-file.js +1 -0
- package/dist/figma.d.ts +1 -0
- package/dist/figma.js +191 -35
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/report.d.ts +59 -1
- package/dist/report.js +176 -30
- package/dist/serialize.d.ts +7 -0
- package/dist/serialize.js +79 -0
- package/dist/taco/figma-import/container/kiwiContainer.d.ts +3 -0
- package/dist/taco/figma-import/container/kiwiContainer.js +1 -1
- package/dist/taco/figma-import/figFile.js +3 -0
- package/dist/taco/figma-import/import/carry.d.ts +14 -1
- package/dist/taco/figma-import/import/carry.js +34 -1
- package/dist/taco/figma-import/import/componentProps.d.ts +10 -4
- package/dist/taco/figma-import/import/componentProps.js +29 -13
- package/dist/taco/figma-import/import/componentSets.d.ts +2 -0
- package/dist/taco/figma-import/import/componentSets.js +1 -1
- package/dist/taco/figma-import/import/converters/effects.d.ts +3 -13
- package/dist/taco/figma-import/import/converters/effects.js +4 -34
- package/dist/taco/figma-import/import/converters/exportSettings.d.ts +4 -0
- package/dist/taco/figma-import/import/converters/exportSettings.js +75 -0
- package/dist/taco/figma-import/import/converters/frame.d.ts +1 -1
- package/dist/taco/figma-import/import/converters/frame.js +15 -6
- package/dist/taco/figma-import/import/converters/gradient.d.ts +2 -0
- package/dist/taco/figma-import/import/converters/gradient.js +3 -1
- package/dist/taco/figma-import/import/converters/grid.d.ts +12 -0
- package/dist/taco/figma-import/import/converters/grid.js +97 -0
- package/dist/taco/figma-import/import/converters/group.d.ts +2 -4
- package/dist/taco/figma-import/import/converters/group.js +6 -15
- package/dist/taco/figma-import/import/converters/image.d.ts +2 -1
- package/dist/taco/figma-import/import/converters/image.js +60 -16
- package/dist/taco/figma-import/import/converters/layout.d.ts +8 -7
- package/dist/taco/figma-import/import/converters/layout.js +66 -37
- package/dist/taco/figma-import/import/converters/rectangle.d.ts +1 -1
- package/dist/taco/figma-import/import/converters/rectangle.js +3 -3
- package/dist/taco/figma-import/import/converters/section.d.ts +2 -3
- package/dist/taco/figma-import/import/converters/section.js +5 -11
- package/dist/taco/figma-import/import/converters/shared.d.ts +9 -5
- package/dist/taco/figma-import/import/converters/shared.js +23 -10
- package/dist/taco/figma-import/import/converters/text.d.ts +38 -1
- package/dist/taco/figma-import/import/converters/text.js +248 -32
- package/dist/taco/figma-import/import/converters/vector.d.ts +36 -15
- package/dist/taco/figma-import/import/converters/vector.js +214 -73
- package/dist/taco/figma-import/import/converters/vectorNetwork.d.ts +19 -3
- package/dist/taco/figma-import/import/converters/vectorNetwork.js +147 -29
- package/dist/taco/figma-import/import/instances.d.ts +32 -5
- package/dist/taco/figma-import/import/instances.js +613 -130
- package/dist/taco/figma-import/import/styles.d.ts +2 -0
- package/dist/taco/figma-import/import/styles.js +6 -0
- package/dist/taco/figma-import/import/types.d.ts +8 -0
- package/dist/taco/figma-import/import/variables.d.ts +5 -2
- package/dist/taco/figma-import/import/variables.js +65 -31
- package/dist/taco/figma-import/import/variantTrees.d.ts +1 -1
- package/dist/taco/figma-import/import/variantTrees.js +46 -4
- package/dist/taco/figma-import/import/walk.d.ts +62 -7
- package/dist/taco/figma-import/import/walk.js +328 -122
- package/dist/taco/figma-import/kiwi/message.d.ts +4 -2
- package/dist/taco/figma-import/kiwi/message.js +59 -15
- package/dist/taco/model/codec.d.ts +2 -2
- package/dist/taco/model/codec.js +72 -8
- package/dist/taco/model/component-evaluation.d.ts +2 -0
- package/dist/taco/model/component-evaluation.js +7 -0
- package/dist/taco/model/instance-resolver.d.ts +6 -2
- package/dist/taco/model/instance-resolver.js +50 -18
- package/dist/taco/model/sha256.js +13 -8
- package/dist/taco/model/types.d.ts +57 -5
- package/dist/taco/model/types.js +4 -0
- package/dist/taco/svg-import/style/computed.js +1 -0
- package/package.json +3 -2
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { formatExpressionName, componentNestingGraph, entryOf, findComponentCycle, fitAllGroups, layerPathKey, ownedChildIds, } from "../../model/index.js";
|
|
1
|
+
import { formatExpressionName, buildParentMap, componentNestingGraph, entryOf, findComponentCycle, fitAllGroups, layerPathKey, nodeLocalTransform, ownedChildIds, parseLayerPath, } from "../../model/index.js";
|
|
2
2
|
import { field, guidText, isObject } from "./fields.js";
|
|
3
3
|
import { isDetachedStyle } from "./styles.js";
|
|
4
4
|
import { convertEllipse } from "./converters/ellipse.js";
|
|
5
|
-
import { sniffImageMimeType } from "./converters/image.js";
|
|
5
|
+
import { sniffImageMimeType, sniffVideoMimeType } from "./converters/image.js";
|
|
6
6
|
import { convertFrame, isFigmaGroup } from "./converters/frame.js";
|
|
7
|
+
import { gridAxis, gridCell } from "./converters/grid.js";
|
|
7
8
|
import { stackChildFields } from "./converters/layout.js";
|
|
8
9
|
import { convertGroup } from "./converters/group.js";
|
|
9
10
|
import { convertLine } from "./converters/line.js";
|
|
@@ -15,12 +16,12 @@ import { mergeComponentSets, planSet, withoutVariantParts } from "./componentSet
|
|
|
15
16
|
import { nestingMemo, nestingSearch, swapsToCut } from "./nestingCycles.js";
|
|
16
17
|
import { convertSection } from "./converters/section.js";
|
|
17
18
|
import { convertText, figmaTextStyle } from "./converters/text.js";
|
|
18
|
-
import { convertBooleanOperation, convertStarOrPolygon, convertVector } from "./converters/vector.js";
|
|
19
|
+
import { convertBooleanOperation, convertStarOrPolygon, convertVector, whyFlattened } from "./converters/vector.js";
|
|
19
20
|
import { blobReader } from "./blobs.js";
|
|
20
|
-
import { carryMarks } from "./carry.js";
|
|
21
|
+
import { carry, carryMarks, clearConstraints, withImageCrop } from "./carry.js";
|
|
21
22
|
import { nodeEffects } from "./converters/effects.js";
|
|
22
23
|
import { frameGeometry, visualStyle } from "./converters/shared.js";
|
|
23
|
-
import { bindLayerVariables, figmaVariableModes, foldsVariableAlpha, keptFontSize, readFigmaVariables } from "./variables.js";
|
|
24
|
+
import { bindLayerVariables, figmaVariableModes, foldsVariableAlpha, keptFontSize, typographyVariable, readFigmaVariables } from "./variables.js";
|
|
24
25
|
import { buildFigmaTree, chooseRoots, rootSourceOf, withAncestorTransforms } from "./tree.js";
|
|
25
26
|
import { DEFAULT_FIGMA_IMPORT_LIMITS, FigmaImportError } from "./types.js";
|
|
26
27
|
/**
|
|
@@ -35,6 +36,7 @@ const CONVERTERS = {
|
|
|
35
36
|
FRAME: convertFrame,
|
|
36
37
|
GROUP: convertGroup,
|
|
37
38
|
LINE: convertLine,
|
|
39
|
+
RECTANGLE: convertRectangle,
|
|
38
40
|
REGULAR_POLYGON: convertStarOrPolygon,
|
|
39
41
|
ROUNDED_RECTANGLE: convertRectangle,
|
|
40
42
|
SECTION: convertSection,
|
|
@@ -147,11 +149,45 @@ export function readFileMessage(message, options) {
|
|
|
147
149
|
const { result, sources } = walkMessage(message, options, true);
|
|
148
150
|
return { ...result, sources };
|
|
149
151
|
}
|
|
150
|
-
|
|
152
|
+
// Keep the exported lookup independent of the layer walk's temporary maps and blob reader.
|
|
153
|
+
function styleLookup(tree) {
|
|
154
|
+
let stylesByKey;
|
|
155
|
+
const styleKey = (styleType, key) => `${styleType}\u0000${key}`;
|
|
156
|
+
return (reference, styleType) => {
|
|
157
|
+
if (!isObject(reference))
|
|
158
|
+
return undefined;
|
|
159
|
+
const guid = reference["guid"];
|
|
160
|
+
let found;
|
|
161
|
+
if (isObject(guid) && Number.isInteger(guid["sessionID"]) && Number.isInteger(guid["localID"]))
|
|
162
|
+
found = tree.nodes.get(guidText(guid, "style reference"));
|
|
163
|
+
if (found?.change["styleType"] !== styleType) {
|
|
164
|
+
const key = isObject(reference["assetRef"]) ? reference["assetRef"]["key"] : undefined;
|
|
165
|
+
if (typeof key !== "string")
|
|
166
|
+
return undefined;
|
|
167
|
+
if (stylesByKey === undefined) {
|
|
168
|
+
stylesByKey = new Map();
|
|
169
|
+
for (const node of tree.nodes.values()) {
|
|
170
|
+
const nodeKey = node.change["key"];
|
|
171
|
+
const nodeType = node.change["styleType"];
|
|
172
|
+
if (typeof nodeType !== "string" || typeof nodeKey !== "string")
|
|
173
|
+
continue;
|
|
174
|
+
const byKey = styleKey(nodeType, nodeKey);
|
|
175
|
+
if (!stylesByKey.has(byKey))
|
|
176
|
+
stylesByKey.set(byKey, node);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
found = stylesByKey.get(styleKey(styleType, key));
|
|
180
|
+
}
|
|
181
|
+
return found;
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
/** Reads converted layers with their original Figma nodes for Moondraft's adapters. */
|
|
185
|
+
export function walkMessage(message, options, native, distinctSources) {
|
|
151
186
|
const rootSource = rootSourceOf(message, options.roots);
|
|
152
187
|
const limits = { ...DEFAULT_FIGMA_IMPORT_LIMITS[rootSource], ...options.limits };
|
|
153
188
|
const tree = buildFigmaTree(message, limits);
|
|
154
189
|
const sharedStyle = (node) => ["TEXT", "FILL", "EFFECT"].includes(String(node.change["styleType"]));
|
|
190
|
+
const skipStyle = (node) => node.change["styleType"] === "GRID" || native && sharedStyle(node);
|
|
155
191
|
const chosen = chooseRoots(message, tree, rootSource);
|
|
156
192
|
const insideCache = { counts: new Map(), kept: new Set(), named: new Set() };
|
|
157
193
|
for (const group of chosen.groups)
|
|
@@ -161,23 +197,28 @@ function walkMessage(message, options, native) {
|
|
|
161
197
|
const blob = blobReader(message);
|
|
162
198
|
const assets = {};
|
|
163
199
|
const missingImages = new Set();
|
|
164
|
-
const image = (hash, size) => {
|
|
165
|
-
const id = `figma
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
200
|
+
const image = (hash, size, media) => {
|
|
201
|
+
const id = `figma-${media?.video ? "video" : "image"}-${hash}`;
|
|
202
|
+
const cached = assets[id];
|
|
203
|
+
if (cached && !(cached.placeholder && media?.bytes)) {
|
|
204
|
+
if (media?.poster && !cached.poster)
|
|
205
|
+
return assets[id] = { ...cached, poster: media.poster };
|
|
206
|
+
return cached;
|
|
207
|
+
}
|
|
208
|
+
if (missingImages.has(id) && !media?.bytes)
|
|
169
209
|
return null;
|
|
170
|
-
missingImages.add(
|
|
171
|
-
const supplied = options.images?.(hash);
|
|
210
|
+
missingImages.add(id);
|
|
211
|
+
const supplied = media?.bytes ? { bytes: media.bytes } : options.images?.(hash);
|
|
172
212
|
if (supplied === undefined)
|
|
173
213
|
return `image ${hash.slice(0, 8)} was not supplied`;
|
|
174
|
-
const mimeType = supplied.mimeType ?? sniffImageMimeType(supplied.bytes);
|
|
214
|
+
const mimeType = supplied.mimeType ?? (media?.video ? sniffVideoMimeType(supplied.bytes) : sniffImageMimeType(supplied.bytes));
|
|
215
|
+
if (media?.video && !mimeType?.startsWith("video/"))
|
|
216
|
+
return "video bytes were not supplied";
|
|
175
217
|
if (mimeType === undefined)
|
|
176
218
|
return `image ${hash.slice(0, 8)} is not a PNG, JPEG, GIF or WebP file`;
|
|
177
219
|
const width = supplied.width ?? size?.width;
|
|
178
220
|
const height = supplied.height ?? size?.height;
|
|
179
|
-
assets[id] = { id, hash, mimeType, bytes: supplied.bytes, ...(width !== undefined ? { width } : {}), ...(height !== undefined ? { height } : {}) };
|
|
180
|
-
return { assetId: id };
|
|
221
|
+
return assets[id] = { id, hash, mimeType, bytes: supplied.bytes, ...(supplied.placeholder && { placeholder: true }), ...(media?.poster && { poster: media.poster }), ...(width !== undefined ? { width } : {}), ...(height !== undefined ? { height } : {}) };
|
|
181
222
|
};
|
|
182
223
|
const paintIndices = new Map();
|
|
183
224
|
const effectFields = new Map();
|
|
@@ -187,10 +228,10 @@ function walkMessage(message, options, native) {
|
|
|
187
228
|
} : {};
|
|
188
229
|
const vectorCommands = { left: limits.vectorCommands, limit: limits.vectorCommands };
|
|
189
230
|
// `withLayersInside`: the entry leaves out the layers inside the node too.
|
|
190
|
-
const add = (link, kind, reason, withLayersInside = false) => {
|
|
231
|
+
const add = (link, kind, reason, withLayersInside = false, count = 1) => {
|
|
191
232
|
const { node } = link;
|
|
192
233
|
const layersInside = withLayersInside ? layersInsideByType(node, insideCache) : [];
|
|
193
|
-
report.push({ nodeId: node.id, nodeType: node.type, nodePath: pathText(link), layerType: layerTypeOf(node), kind, reason, layersInside });
|
|
234
|
+
report.push({ nodeId: node.id, nodeType: node.type, nodePath: pathText(link), layerType: layerTypeOf(node), kind, reason, layersInside, ...(count > 1 && { count }) });
|
|
194
235
|
};
|
|
195
236
|
for (const id of chosen.missing) {
|
|
196
237
|
report.push({ nodeId: id, nodeType: "", nodePath: "", layerType: "", kind: "node-left-out", reason: "the copied node is not in the message", layersInside: [] });
|
|
@@ -260,35 +301,9 @@ function walkMessage(message, options, native) {
|
|
|
260
301
|
}
|
|
261
302
|
return textStylesByKey.get(key);
|
|
262
303
|
};
|
|
263
|
-
|
|
264
|
-
// name: by guid, else by the library key a copy of the style in the message carries.
|
|
265
|
-
let stylesByKey;
|
|
266
|
-
const styleKey = (styleType, key) => `${styleType}\u0000${key}`;
|
|
304
|
+
const styleNodeFor = styleLookup(tree);
|
|
267
305
|
const styleList = (reference, styleType) => {
|
|
268
|
-
|
|
269
|
-
return undefined;
|
|
270
|
-
const guid = reference["guid"];
|
|
271
|
-
let found;
|
|
272
|
-
if (isObject(guid) && Number.isInteger(guid["sessionID"]) && Number.isInteger(guid["localID"]))
|
|
273
|
-
found = tree.nodes.get(guidText(guid, "style reference"));
|
|
274
|
-
if (found?.change["styleType"] !== styleType) {
|
|
275
|
-
const key = isObject(reference["assetRef"]) ? reference["assetRef"]["key"] : undefined;
|
|
276
|
-
if (typeof key !== "string")
|
|
277
|
-
return undefined;
|
|
278
|
-
if (stylesByKey === undefined) {
|
|
279
|
-
stylesByKey = new Map();
|
|
280
|
-
for (const node of tree.nodes.values()) {
|
|
281
|
-
const nodeKey = node.change["key"];
|
|
282
|
-
const nodeType = node.change["styleType"];
|
|
283
|
-
if (typeof nodeType !== "string" || typeof nodeKey !== "string")
|
|
284
|
-
continue;
|
|
285
|
-
const byKey = styleKey(nodeType, nodeKey);
|
|
286
|
-
if (!stylesByKey.has(byKey))
|
|
287
|
-
stylesByKey.set(byKey, node);
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
found = stylesByKey.get(styleKey(styleType, key));
|
|
291
|
-
}
|
|
306
|
+
const found = styleNodeFor(reference, styleType);
|
|
292
307
|
if (found === undefined)
|
|
293
308
|
return undefined;
|
|
294
309
|
const list = styleType === "EFFECT" ? "effects" : "fillPaints";
|
|
@@ -339,7 +354,12 @@ function walkMessage(message, options, native) {
|
|
|
339
354
|
},
|
|
340
355
|
...(native && {
|
|
341
356
|
copiedPaintAlpha: (paint, opacity) => foldsVariableAlpha(paint, opacity, node, variables, node.id, shownBy),
|
|
342
|
-
|
|
357
|
+
textFillStyle: (reference) => styleNodeFor(reference, "FILL")?.id,
|
|
358
|
+
textColorVariable: (data) => {
|
|
359
|
+
const variable = variables.variableOf(data, node.id);
|
|
360
|
+
return "id" in variable && variable.type === "color" ? variable.id : null;
|
|
361
|
+
},
|
|
362
|
+
typographyVariable: (field, data) => typographyVariable(variables, field, data, node.id),
|
|
343
363
|
}),
|
|
344
364
|
keptFontSize: (layer) => keptFontSize(layer, node, variables, shownBy),
|
|
345
365
|
};
|
|
@@ -360,7 +380,7 @@ function walkMessage(message, options, native) {
|
|
|
360
380
|
use = { change: node.change };
|
|
361
381
|
else {
|
|
362
382
|
const id = options.idSource();
|
|
363
|
-
const style = figmaTextStyle(node.change, node.name, say, `text style ${node.id}`, [...(layer === undefined ? [] : [layer]), ...layersNaming(node)], variableNumberOf(node).variableNumber);
|
|
383
|
+
const style = figmaTextStyle(node.change, node.name, say, `text style ${node.id}`, [...(layer === undefined ? [] : [layer]), ...layersNaming(node)], native ? undefined : variableNumberOf(node).variableNumber);
|
|
364
384
|
textStyles[id] = style;
|
|
365
385
|
use = { change: node.change, shared: { id, style } };
|
|
366
386
|
}
|
|
@@ -540,13 +560,15 @@ function walkMessage(message, options, native) {
|
|
|
540
560
|
// Converts a layer on its own for instance overrides: no children, no reports, its own vector budget. The same layer with the
|
|
541
561
|
// same override fields is converted once, so instances that repeat an override spend no more of the budget.
|
|
542
562
|
const aloneCommands = { left: limits.vectorCommands, limit: limits.vectorCommands };
|
|
543
|
-
const convertAloneOnce = (node, shownBy) => {
|
|
563
|
+
const convertAloneOnce = (node, fields, shownBy) => {
|
|
544
564
|
const converter = node.type === "INSTANCE" || node.type === "SYMBOL" ? convertFrame : converterFor(node.type);
|
|
545
565
|
if (converter === undefined)
|
|
546
566
|
return null;
|
|
547
567
|
let leftOut = false;
|
|
548
568
|
const converted = converter(node, {
|
|
549
569
|
newId: () => "override", convertChildren: () => [], blob, image, vectorCommands: aloneCommands, textStyle: textStyleFor(null), styleList, ...trackPaints, ...variableNumberOf(node, shownBy),
|
|
570
|
+
...(native && { instanceTypography: fields, plainTextPaint: (range) => range?.["fillPaints"] !== undefined || range?.["styleIdForFill"] !== undefined
|
|
571
|
+
? fields["textData"] !== undefined : fields["fillPaints"] !== undefined || fields["styleIdForFill"] !== undefined }),
|
|
550
572
|
report: (kind) => { if (kind === "node-left-out")
|
|
551
573
|
leftOut = true; },
|
|
552
574
|
});
|
|
@@ -579,7 +601,7 @@ function walkMessage(message, options, native) {
|
|
|
579
601
|
}
|
|
580
602
|
return cached.layer;
|
|
581
603
|
}
|
|
582
|
-
const converted = convertAloneOnce(Object.keys(fields).length === 0 ? node : { ...node, change: { ...node.change, ...fields } }, shownBy);
|
|
604
|
+
const converted = convertAloneOnce(Object.keys(fields).length === 0 ? node : { ...node, change: { ...node.change, ...fields } }, fields, shownBy);
|
|
583
605
|
byFields.set(key, { layer: converted, fields });
|
|
584
606
|
return converted;
|
|
585
607
|
};
|
|
@@ -607,7 +629,10 @@ function walkMessage(message, options, native) {
|
|
|
607
629
|
const stack = [];
|
|
608
630
|
// Every node converted, by any walk (page or component), for the variable bindings once stacks are settled.
|
|
609
631
|
const everyImported = [];
|
|
632
|
+
const omittedSubtrees = new Set();
|
|
610
633
|
/** Runs the steps on `stack` until it is empty. `walkVisited` holds the nodes this walk imported; `imported` the converted node of each. */
|
|
634
|
+
// The layer participates in an imported stack or grid. A root has no imported parent.
|
|
635
|
+
const inAutoLayoutFlow = (step) => step.inStack === true && step.node.change["stackPositioning"] !== "ABSOLUTE";
|
|
611
636
|
const runSteps = (walkVisited, imported, rootList) => {
|
|
612
637
|
for (let step = stack.pop(); step !== undefined; step = stack.pop()) {
|
|
613
638
|
const { depth, node, component } = step;
|
|
@@ -620,16 +645,18 @@ function walkMessage(message, options, native) {
|
|
|
620
645
|
continue;
|
|
621
646
|
}
|
|
622
647
|
if (isSlotContent(node) && step.host !== true) {
|
|
648
|
+
omittedSubtrees.add(step.source ?? node);
|
|
623
649
|
add(link, "node-left-out", "a slot's content frame is imported only as the content of the instances that put it in a slot");
|
|
624
650
|
continue;
|
|
625
651
|
}
|
|
626
652
|
walkVisited.add(node.id);
|
|
627
653
|
// A parent is converted before its children, so a parent with a layer has it by now.
|
|
628
|
-
if (
|
|
654
|
+
if (skipStyle(node) || native && (node.type === "VARIABLE" || node.type === "VARIABLE_SET"))
|
|
629
655
|
continue;
|
|
630
656
|
const parentLayer = step.parent === null || !Object.hasOwn(layerIds, step.parent.node.id) ? undefined : layerIds[step.parent.node.id];
|
|
631
657
|
// A left-out node takes the layers inside it along; the reason says how many.
|
|
632
658
|
const leaveOut = (reason) => {
|
|
659
|
+
omittedSubtrees.add(step.source ?? node);
|
|
633
660
|
if (parentLayer !== undefined && !Object.hasOwn(layerIds, node.id))
|
|
634
661
|
layerIds[node.id] = parentLayer;
|
|
635
662
|
const inside = node.children.length === 0 ? 0 : countLayersInside(node, insideCache);
|
|
@@ -690,6 +717,7 @@ function walkMessage(message, options, native) {
|
|
|
690
717
|
converted = converter(node, {
|
|
691
718
|
newId: () => options.idSource(),
|
|
692
719
|
convertChildren: () => (childIds ??= []),
|
|
720
|
+
inFlow: inAutoLayoutFlow(step),
|
|
693
721
|
report: (kind, reason) => (kind === "node-left-out" ? leaveOut(reason) : add(link, kind, reason)),
|
|
694
722
|
blob,
|
|
695
723
|
image,
|
|
@@ -702,8 +730,8 @@ function walkMessage(message, options, native) {
|
|
|
702
730
|
if (converted === null)
|
|
703
731
|
continue;
|
|
704
732
|
carryMarks(converted);
|
|
705
|
-
if (step.inSection === true
|
|
706
|
-
|
|
733
|
+
if (step.inSection === true)
|
|
734
|
+
clearConstraints(converted);
|
|
707
735
|
let slotFrame = step.inSlotFrame === true;
|
|
708
736
|
if (component !== undefined && step.content === true)
|
|
709
737
|
inComponents.add(node.id);
|
|
@@ -717,8 +745,8 @@ function walkMessage(message, options, native) {
|
|
|
717
745
|
const key = overrideKeyOf(node);
|
|
718
746
|
if (!component.layers.has(key))
|
|
719
747
|
component.layers.set(key, { figma: node, node: converted });
|
|
720
|
-
if (node.type === "BOOLEAN_OPERATION") {
|
|
721
|
-
//
|
|
748
|
+
if (node.type === "BOOLEAN_OPERATION" && childIds === undefined) {
|
|
749
|
+
// A flattened one's operands are not layers, so an override of one names the boolean operation in its report line.
|
|
722
750
|
const operands = [...node.children];
|
|
723
751
|
for (let i = 0; i < operands.length; i++) {
|
|
724
752
|
const operand = operands[i];
|
|
@@ -751,18 +779,25 @@ function walkMessage(message, options, native) {
|
|
|
751
779
|
if (step.into === rootList)
|
|
752
780
|
roots.push(converted);
|
|
753
781
|
if (childIds === undefined) {
|
|
754
|
-
if (node.type === "BOOLEAN_OPERATION")
|
|
755
|
-
|
|
782
|
+
if (node.type === "BOOLEAN_OPERATION") {
|
|
783
|
+
for (const child of node.children)
|
|
784
|
+
omittedSubtrees.add(child);
|
|
785
|
+
const why = whyFlattened(node, inAutoLayoutFlow(step));
|
|
786
|
+
add(link, "approximated", `the boolean operation is flattened to its outline; its operands are not imported${why === undefined ? "" : `: ${why}`}`, true);
|
|
787
|
+
}
|
|
756
788
|
else if (node.children.length > 0 && node.type !== "INSTANCE" && node.type !== "SYMBOL") {
|
|
789
|
+
for (const child of node.children)
|
|
790
|
+
omittedSubtrees.add(child);
|
|
757
791
|
add(link, "property-left-out", `${layersText(countLayersInside(node, insideCache))} left out: a ${node.type} has no children in Taco`, true);
|
|
758
792
|
}
|
|
759
793
|
continue;
|
|
760
794
|
}
|
|
761
795
|
const inSection = node.type === "SECTION" || (step.inSection === true && converted.type === "group");
|
|
796
|
+
const inStack = converted.type === "frame" && converted.layout.kind !== "absolute";
|
|
762
797
|
for (let i = node.children.length - 1; i >= 0; i--) {
|
|
763
798
|
stack.push({
|
|
764
799
|
node: node.children[i], depth: depth + 1, parent: link, into: childIds, inSection, ...(component !== undefined ? { component } : {}),
|
|
765
|
-
...(step.content === true ? { content: true } : {}), ...(slotFrame ? { inSlotFrame: true } : {}),
|
|
800
|
+
...(step.content === true ? { content: true } : {}), ...(slotFrame ? { inSlotFrame: true } : {}), ...(inStack ? { inStack: true } : {}),
|
|
766
801
|
});
|
|
767
802
|
}
|
|
768
803
|
}
|
|
@@ -794,15 +829,17 @@ function walkMessage(message, options, native) {
|
|
|
794
829
|
return name !== "" ? name : set !== undefined ? componentNameOf(set) : "Component";
|
|
795
830
|
};
|
|
796
831
|
const setProperties = new Map();
|
|
832
|
+
// The property defs whose dropped preferred values are already reported (`propertiesOf`).
|
|
833
|
+
const reportedDefs = new WeakSet();
|
|
797
834
|
for (const symbol of symbolOrder) {
|
|
798
835
|
const symbolLink = linkOf(symbol);
|
|
799
836
|
const report = (kind, reason) => addCounted(symbolLink, kind, reason);
|
|
800
|
-
const properties = propertiesOf(symbol, tree.nodes, componentOf, componentsByKey, report);
|
|
837
|
+
const properties = propertiesOf(symbol, tree.nodes, componentOf, componentsByKey, report, reportedDefs);
|
|
801
838
|
const set = native && setOf(symbol);
|
|
802
839
|
if (set) {
|
|
803
840
|
let shared = setProperties.get(set);
|
|
804
841
|
if (!shared) {
|
|
805
|
-
shared = propertiesOf(set, tree.nodes, componentOf, componentsByKey, (kind, reason) => add(variableLinkOf(set), kind, reason));
|
|
842
|
+
shared = propertiesOf(set, tree.nodes, componentOf, componentsByKey, (kind, reason) => add(variableLinkOf(set), kind, reason), reportedDefs);
|
|
806
843
|
setProperties.set(set, shared);
|
|
807
844
|
}
|
|
808
845
|
const own = new Set(properties.map(p => p.definition.id));
|
|
@@ -903,7 +940,27 @@ function walkMessage(message, options, native) {
|
|
|
903
940
|
const finished = instances.map((entry) => ({ ...entry, refusedSwaps: new Map(), swaps: new Set(), nested: new Map(), heldSizing: new Map(), filledSlots: [], said: [] }));
|
|
904
941
|
const nodeRecord = Object.fromEntries(nodes.map((node) => [node.id, node]));
|
|
905
942
|
const occurrenceFields = new Map();
|
|
906
|
-
const
|
|
943
|
+
const instanceBoxes = new Map();
|
|
944
|
+
const instanceFillSizes = new Map();
|
|
945
|
+
// Resolve inherited swaps by imported layer IDs. A holder can be finished later in file order or lose a
|
|
946
|
+
// swap in the cycle check. Revisit just the instances that consulted a path whose answer changed.
|
|
947
|
+
const pathSwaps = new Map();
|
|
948
|
+
const readers = new Map();
|
|
949
|
+
let sourceOverrideKeys;
|
|
950
|
+
const hasSourceKey = (key) => {
|
|
951
|
+
if (tree.nodes.has(key))
|
|
952
|
+
return true;
|
|
953
|
+
if (!sourceOverrideKeys) {
|
|
954
|
+
sourceOverrideKeys = new Set();
|
|
955
|
+
for (const node of tree.nodes.values()) {
|
|
956
|
+
const guid = node.change["overrideKey"];
|
|
957
|
+
if (isObject(guid) && Number.isInteger(guid["sessionID"]) && Number.isInteger(guid["localID"]))
|
|
958
|
+
sourceOverrideKeys.add(overrideKeyOf(node));
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
return sourceOverrideKeys.has(key);
|
|
962
|
+
};
|
|
963
|
+
const finish = (entry, pending) => {
|
|
907
964
|
const { stub, figma, self, link, refusedSwaps, said } = entry;
|
|
908
965
|
const component = importedComponents.get(shownSymbol(figma));
|
|
909
966
|
if (component === undefined)
|
|
@@ -913,13 +970,42 @@ function walkMessage(message, options, native) {
|
|
|
913
970
|
delete stub["propertyValues"];
|
|
914
971
|
delete stub["slots"];
|
|
915
972
|
const fields = new Map();
|
|
973
|
+
const watchPath = (holder, path) => {
|
|
974
|
+
let paths = readers.get(holder);
|
|
975
|
+
if (!paths)
|
|
976
|
+
readers.set(holder, paths = new Map());
|
|
977
|
+
let used = paths.get(path);
|
|
978
|
+
if (!used)
|
|
979
|
+
paths.set(path, used = new Set());
|
|
980
|
+
used.add(entry);
|
|
981
|
+
};
|
|
916
982
|
const made = instanceFields(figma, component, self, {
|
|
917
|
-
...(native && {
|
|
983
|
+
...(native && {
|
|
984
|
+
nestedTextFields(holder, path) {
|
|
985
|
+
watchPath(holder, path);
|
|
986
|
+
return occurrenceFields.get(holder.id)?.get(path);
|
|
987
|
+
},
|
|
988
|
+
fileOverride(path, change) {
|
|
918
989
|
fields.set(path, { ...fields.get(path), ...change });
|
|
919
|
-
}
|
|
990
|
+
},
|
|
991
|
+
fileLayout(boxes, fillOnly, texts) {
|
|
992
|
+
const id = stub["id"];
|
|
993
|
+
instanceBoxes.delete(id);
|
|
994
|
+
instanceFillSizes.delete(id);
|
|
995
|
+
if (boxes.size)
|
|
996
|
+
(fillOnly ? instanceFillSizes : instanceBoxes).set(id, boxes);
|
|
997
|
+
if (texts.size)
|
|
998
|
+
instanceBoxes.set(id, texts);
|
|
999
|
+
},
|
|
1000
|
+
}),
|
|
920
1001
|
slotFills: entry.slotFills,
|
|
921
1002
|
component: (symbolId) => importedComponents.get(symbolId),
|
|
922
1003
|
refusedSwaps,
|
|
1004
|
+
hasSourceKey,
|
|
1005
|
+
nestedSwaps(holder, path) {
|
|
1006
|
+
watchPath(holder, path);
|
|
1007
|
+
return pathSwaps.get(holder)?.get(path);
|
|
1008
|
+
},
|
|
923
1009
|
nodes: nodeRecord,
|
|
924
1010
|
convertAlone,
|
|
925
1011
|
bindingsOf,
|
|
@@ -944,16 +1030,40 @@ function walkMessage(message, options, native) {
|
|
|
944
1030
|
seen.count += 1;
|
|
945
1031
|
}),
|
|
946
1032
|
});
|
|
1033
|
+
const previousFields = occurrenceFields.get(stub["id"]);
|
|
947
1034
|
if (fields.size)
|
|
948
1035
|
occurrenceFields.set(stub["id"], fields);
|
|
1036
|
+
else
|
|
1037
|
+
occurrenceFields.delete(stub["id"]);
|
|
1038
|
+
const holder = nodeRecord[stub["id"]];
|
|
1039
|
+
const previous = pathSwaps.get(holder);
|
|
1040
|
+
pathSwaps.set(holder, made.pathSwaps);
|
|
1041
|
+
for (const [path, used] of readers.get(holder) ?? []) {
|
|
1042
|
+
const before = previous?.get(path), after = made.pathSwaps.get(path);
|
|
1043
|
+
const prior = previousFields?.get(path), current = fields.get(path);
|
|
1044
|
+
const changedFields = prior !== current && (!prior || !current || Object.keys(prior).length !== Object.keys(current).length
|
|
1045
|
+
|| Object.keys(prior).some(key => prior[key] !== current[key]));
|
|
1046
|
+
if (changedFields || before?.symbol !== after?.symbol || JSON.stringify(before?.properties) !== JSON.stringify(after?.properties)) {
|
|
1047
|
+
for (const reader of used)
|
|
1048
|
+
pending.add(reader);
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
949
1051
|
Object.assign(stub, made.fields);
|
|
950
1052
|
entry.swaps = made.swaps;
|
|
951
1053
|
entry.nested = made.nested;
|
|
952
1054
|
entry.heldSizing = made.heldSizing;
|
|
953
1055
|
entry.filledSlots = made.filledSlots;
|
|
954
1056
|
};
|
|
955
|
-
|
|
956
|
-
|
|
1057
|
+
const finishAll = (pending) => {
|
|
1058
|
+
const touched = new Set();
|
|
1059
|
+
for (const entry of pending) {
|
|
1060
|
+
pending.delete(entry);
|
|
1061
|
+
finish(entry, pending);
|
|
1062
|
+
touched.add(entry);
|
|
1063
|
+
}
|
|
1064
|
+
return touched;
|
|
1065
|
+
};
|
|
1066
|
+
finishAll(new Set(finished));
|
|
957
1067
|
// The nesting check, over the walks that resolving a component or a page instance can take from a component into another
|
|
958
1068
|
// (`nestingSearch`): through the instances placed inside components, and through each swap an instance makes by an override
|
|
959
1069
|
// or an instance swap property value, from the component whose layer it swaps, while the component that holds that instance
|
|
@@ -961,28 +1071,27 @@ function walkMessage(message, options, native) {
|
|
|
961
1071
|
// components are checked first, then each page instance's swaps against those kept, so a cycle that a page instance closes
|
|
962
1072
|
// costs that instance's swap, not a swap every instance of a component shows. Each cycle found loses a swap, by file order
|
|
963
1073
|
// (`swapsToCut`). A swap left out takes along what the instance sets inside the component that swap would show, so an
|
|
964
|
-
//
|
|
1074
|
+
// enclosing override may now resolve against a different component.
|
|
965
1075
|
{
|
|
966
1076
|
const symbolOf = new Map([...componentIds].map(([symbolId, componentId]) => [componentId, symbolId]));
|
|
967
1077
|
const kept = new Map();
|
|
968
|
-
const keep = (from, to) => {
|
|
969
|
-
let set = kept.get(from);
|
|
970
|
-
if (set === undefined)
|
|
971
|
-
kept.set(from, set = new Set());
|
|
972
|
-
set.add(to);
|
|
973
|
-
};
|
|
974
1078
|
const nodesById = new Map(nodes.map((node) => [node.id, node]));
|
|
975
|
-
|
|
1079
|
+
const refreshKept = (symbolId) => {
|
|
1080
|
+
const targets = new Set();
|
|
1081
|
+
kept.set(symbolId, targets);
|
|
1082
|
+
const root = importedComponents.get(symbolId).root;
|
|
976
1083
|
for (const pending = [root.id], seen = new Set(); pending.length > 0;) {
|
|
977
1084
|
const id = pending.pop();
|
|
978
1085
|
const node = seen.has(id) ? undefined : nodesById.get(id);
|
|
979
1086
|
seen.add(id);
|
|
980
1087
|
if (node?.type === "instance")
|
|
981
|
-
|
|
1088
|
+
targets.add(symbolOf.get(node.componentId));
|
|
982
1089
|
if (node !== undefined)
|
|
983
1090
|
pending.push(...ownedChildIds(node));
|
|
984
1091
|
}
|
|
985
|
-
}
|
|
1092
|
+
};
|
|
1093
|
+
for (const symbolId of importedComponents.keys())
|
|
1094
|
+
refreshKept(symbolId);
|
|
986
1095
|
const order = symbolOrder.map((symbol) => symbol.id);
|
|
987
1096
|
const fileIndex = new Map(order.map((id, at) => [id, at]));
|
|
988
1097
|
const componentEntries = finished.filter((entry) => entry.owner !== undefined);
|
|
@@ -1002,48 +1111,76 @@ function walkMessage(message, options, native) {
|
|
|
1002
1111
|
byOwner.set(ownerOf(entry), list = []);
|
|
1003
1112
|
list.push(entry);
|
|
1004
1113
|
}
|
|
1005
|
-
|
|
1114
|
+
let memo = nestingMemo();
|
|
1006
1115
|
// The swaps each entry of `cutting` makes, as the search holds them.
|
|
1007
1116
|
const made = new Map(cutting.map((entry) => [entry, swapsOf([entry])]));
|
|
1008
|
-
const
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1117
|
+
const buildSearch = () => nestingSearch(order, kept, [...fixed, ...[...made.values()].flat()]);
|
|
1118
|
+
let search = buildSearch();
|
|
1119
|
+
for (let i = 0; i < roots.length;) {
|
|
1120
|
+
const [root, rootOwner] = roots[i];
|
|
1121
|
+
const cycle = search(root, rootOwner, memo);
|
|
1122
|
+
if (cycle === null) {
|
|
1123
|
+
i++;
|
|
1124
|
+
continue;
|
|
1125
|
+
}
|
|
1126
|
+
const keptSteps = new Map();
|
|
1127
|
+
const swaps = [];
|
|
1128
|
+
for (const { from, to, owner } of cycle) {
|
|
1129
|
+
if (owner !== undefined && byOwner.has(owner))
|
|
1130
|
+
swaps.push(`${from}>${to}`);
|
|
1131
|
+
else
|
|
1132
|
+
keptSteps.set(from, new Set([to]));
|
|
1133
|
+
}
|
|
1134
|
+
const ids = cycle.map((step) => step.from).sort((a, b) => fileIndex.get(a) - fileIndex.get(b));
|
|
1135
|
+
const cut = swapsToCut(ids, keptSteps, swaps);
|
|
1136
|
+
if (cut.size === 0)
|
|
1137
|
+
throw new Error(`the nesting check found a cycle with no swap to leave out, through ${ids.map(nameOf).join(" > ")}`);
|
|
1138
|
+
const changed = new Set();
|
|
1139
|
+
for (const { from, to, owner } of cycle) {
|
|
1140
|
+
const swap = `${from}>${to}`;
|
|
1141
|
+
if (!cut.has(swap))
|
|
1142
|
+
continue;
|
|
1143
|
+
const reason = from === to ? `to ${nameOf(to)} inside ${nameOf(from)} itself is left out: it would nest a component in itself`
|
|
1144
|
+
: `to ${nameOf(to)} inside ${nameOf(from)} is left out: ${nameOf(to)} can contain ${nameOf(from)}, so it would nest a component in itself`;
|
|
1145
|
+
for (const entry of byOwner.get(owner)) {
|
|
1146
|
+
if (!entry.swaps.has(swap))
|
|
1027
1147
|
continue;
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1148
|
+
entry.refusedSwaps.set(swap, reason);
|
|
1149
|
+
changed.add(entry);
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
const gone = [];
|
|
1153
|
+
let gained = false;
|
|
1154
|
+
const slotOwners = new Set();
|
|
1155
|
+
for (const entry of finishAll(changed)) {
|
|
1156
|
+
// A newly reachable slot host can contain instances even if its holder gained no swap.
|
|
1157
|
+
if (entry.owner !== undefined && entry.slotFills.length)
|
|
1158
|
+
slotOwners.add(entry.owner);
|
|
1159
|
+
const previous = made.get(entry);
|
|
1160
|
+
if (!previous)
|
|
1161
|
+
continue; // Page swaps are checked after the component swaps settle.
|
|
1162
|
+
const retained = previous.filter(swap => entry.swaps.has(`${swap.from}>${swap.to}`));
|
|
1163
|
+
if (retained.length < entry.swaps.size) {
|
|
1164
|
+
made.set(entry, swapsOf([entry]));
|
|
1165
|
+
gained = true;
|
|
1037
1166
|
}
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
const
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1167
|
+
else if (retained.length < previous.length) {
|
|
1168
|
+
made.set(entry, retained);
|
|
1169
|
+
for (const swap of previous)
|
|
1170
|
+
if (!entry.swaps.has(`${swap.from}>${swap.to}`))
|
|
1171
|
+
gone.push(swap);
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
if (gained || slotOwners.size > 0) {
|
|
1175
|
+
for (const owner of slotOwners)
|
|
1176
|
+
refreshKept(owner);
|
|
1177
|
+
// A previously safe root can now reach the new edge. Its cached walk ends are stale too.
|
|
1178
|
+
search = buildSearch();
|
|
1179
|
+
memo = nestingMemo();
|
|
1180
|
+
i = 0;
|
|
1046
1181
|
}
|
|
1182
|
+
else
|
|
1183
|
+
search.remove(gone);
|
|
1047
1184
|
}
|
|
1048
1185
|
};
|
|
1049
1186
|
check(componentEntries, [], order.map((id) => [id, undefined]));
|
|
@@ -1095,6 +1232,17 @@ function walkMessage(message, options, native) {
|
|
|
1095
1232
|
// A group whose frame changes when fitted to its layers (`fitGroups`) would move its stack's other children.
|
|
1096
1233
|
const fitted = stacks.length === 0 ? {} : fitAllGroups(Object.fromEntries(nodes.map((node) => [node.id, node])));
|
|
1097
1234
|
settleStacks(stacks, add, (node) => node.type === "group" && entryOf(fitted, node.id) !== node);
|
|
1235
|
+
// Fill is decided here, after resolving instance paths. Discard candidate
|
|
1236
|
+
// allocations for paths whose rotation or stack prevented importing Fill.
|
|
1237
|
+
for (const [id, boxes] of instanceFillSizes) {
|
|
1238
|
+
for (const path of boxes.keys()) {
|
|
1239
|
+
const figma = nodeRecord[parseLayerPath(path).at(-1)]?.metadata?.["figma"];
|
|
1240
|
+
if (!isObject(figma) || !figma["fillSizing"])
|
|
1241
|
+
boxes.delete(path);
|
|
1242
|
+
}
|
|
1243
|
+
if (!boxes.size)
|
|
1244
|
+
instanceFillSizes.delete(id);
|
|
1245
|
+
}
|
|
1098
1246
|
const componentRoots = new Set([...importedComponents.values()].map(({ root }) => root.id));
|
|
1099
1247
|
for (const { stub, heldSizing } of finished) {
|
|
1100
1248
|
dropUnheldSizing(stub["overrides"], heldSizing);
|
|
@@ -1142,7 +1290,7 @@ function walkMessage(message, options, native) {
|
|
|
1142
1290
|
const folded = boundSelf.style?.[name];
|
|
1143
1291
|
if (rootOverride[name] === undefined || folded === undefined)
|
|
1144
1292
|
continue;
|
|
1145
|
-
if (JSON.stringify(folded) === JSON.stringify(component.root.style?.[name] ?? []))
|
|
1293
|
+
if (JSON.stringify(folded, withImageCrop) === JSON.stringify(component.root.style?.[name] ?? [], withImageCrop))
|
|
1146
1294
|
delete rootOverride[name];
|
|
1147
1295
|
else
|
|
1148
1296
|
rootOverride[name] = folded;
|
|
@@ -1184,7 +1332,11 @@ function walkMessage(message, options, native) {
|
|
|
1184
1332
|
}
|
|
1185
1333
|
// The literal reader merges variant trees. The native file adapter needs the original member mains.
|
|
1186
1334
|
const fittedNodes = fitAllGroups(Object.fromEntries(nodes.map((node) => [node.id, node])));
|
|
1335
|
+
if (instanceBoxes.size && nodes.some(node => node.type === "group")) {
|
|
1336
|
+
fitInstanceBoxes(instanceBoxes, nodeRecord, fittedNodes);
|
|
1337
|
+
}
|
|
1187
1338
|
const fittedList = nodes.map((node) => entryOf(fittedNodes, node.id) ?? node);
|
|
1339
|
+
const distinct = distinctSources?.(tree);
|
|
1188
1340
|
const sets = native ? { nodes: fittedList, components, layerOf: new Map(), componentOf: new Map() } : mergeComponentSets({
|
|
1189
1341
|
theme: {
|
|
1190
1342
|
defaultTextStyleId: "figma-import-default",
|
|
@@ -1193,6 +1345,7 @@ function walkMessage(message, options, native) {
|
|
|
1193
1345
|
textStyles: { "figma-import-default": figmaTextStyle({}, "Default", () => undefined, "component sets"), ...textStyles },
|
|
1194
1346
|
},
|
|
1195
1347
|
nodes: fittedList, components, figmaNodes: tree.nodes, newId: () => options.idSource(), keyOf, nameOf: componentNameOf,
|
|
1348
|
+
...(distinct?.size && { distinctLayers: new Set(everyImported.filter(({ figma }) => distinct.has(figma.id)).map(({ node }) => node.id)) }),
|
|
1196
1349
|
variants: [...importedComponents.values()].map(({ symbol, componentId, root }) => ({ symbol, componentId, root })),
|
|
1197
1350
|
report: (node, kind, reason) => addCounted(linkOf(node), kind, reason),
|
|
1198
1351
|
});
|
|
@@ -1208,7 +1361,7 @@ function walkMessage(message, options, native) {
|
|
|
1208
1361
|
if (typeof plan === "string")
|
|
1209
1362
|
add(variableLinkOf(node), "approximated", plan);
|
|
1210
1363
|
else
|
|
1211
|
-
variants.set(node.id, { plan, properties: setProperties.get(node) ?? propertiesOf(node, tree.nodes, componentOf, componentsByKey, (kind, reason) => add(variableLinkOf(node), kind, reason)) });
|
|
1364
|
+
variants.set(node.id, { plan, properties: setProperties.get(node) ?? propertiesOf(node, tree.nodes, componentOf, componentsByKey, (kind, reason) => add(variableLinkOf(node), kind, reason), reportedDefs) });
|
|
1212
1365
|
}
|
|
1213
1366
|
const type = node.change["styleType"];
|
|
1214
1367
|
if (type === "TEXT")
|
|
@@ -1220,16 +1373,16 @@ function walkMessage(message, options, native) {
|
|
|
1220
1373
|
const frame = { id: walk.newId(), type: "frame", name: node.name, visible: true, locked: false, opacity: 1, rotation: 0,
|
|
1221
1374
|
frame: { x: 0, y: 0, width: Number(size?.["x"] ?? 1), height: Number(size?.["y"] ?? 1) },
|
|
1222
1375
|
children: [], layout: { kind: "absolute" }, clipContent: false,
|
|
1223
|
-
style: type === "FILL" ? visualStyle(size ? node : { ...node, change: { ...node.change, size: { x: 1, y: 1 } } }, walk) : nodeEffects(node, walk
|
|
1376
|
+
style: type === "FILL" ? visualStyle(size ? node : { ...node, change: { ...node.change, size: { x: 1, y: 1 } } }, walk) : nodeEffects(node, walk) };
|
|
1224
1377
|
carryMarks(frame);
|
|
1225
1378
|
styleLayers.set(node.id, frame);
|
|
1226
1379
|
}
|
|
1227
1380
|
}
|
|
1228
1381
|
for (const { link, kind, reason, count } of counted.values()) {
|
|
1229
|
-
add(link, kind,
|
|
1382
|
+
add(link, kind, reason, false, count);
|
|
1230
1383
|
}
|
|
1231
1384
|
for (const orphan of tree.orphans) {
|
|
1232
|
-
if ((
|
|
1385
|
+
if (skipStyle(orphan) || visited.has(orphan.id) || inComponents.has(orphan.id) || slotContents.has(orphan.id) || orphan.type === "VARIABLE" || orphan.type === "VARIABLE_SET")
|
|
1233
1386
|
continue;
|
|
1234
1387
|
const reason = orphan.parentId === undefined ? "the node has no parentIndex" : `its parent ${orphan.parentId} is not in the message`;
|
|
1235
1388
|
add({ node: orphan, parent: null }, "node-left-out", `${reason}; it and ${layersText(countLayersInside(orphan, insideCache))} are not imported`, true);
|
|
@@ -1245,13 +1398,42 @@ function walkMessage(message, options, native) {
|
|
|
1245
1398
|
componentGuids[figmaId] = componentId;
|
|
1246
1399
|
const componentPlacements = Object.fromEntries([...placements].flatMap(([layer, symbol]) => sets.componentOf.has(symbol) ? [] : [[layer, componentGuids[symbol]]]));
|
|
1247
1400
|
return {
|
|
1248
|
-
sources: { variables, variants, tree, styleLayers, textStyleUses, paintIndices, effectFields, occurrenceFields, imported: everyImported },
|
|
1401
|
+
sources: { variables, variants, tree, styleLayers, styleNodeFor, textStyleUses, paintIndices, effectFields, occurrenceFields, instanceBoxes, instanceFillSizes, imported: everyImported, omittedSubtrees },
|
|
1249
1402
|
result: {
|
|
1250
1403
|
rootSource, roots: roots.map((root) => mergedById.get(root.id) ?? root), nodes: sets.nodes, pages, report, assets, layerIds, components: sets.components, componentIds: componentGuids, componentPlacements,
|
|
1251
1404
|
variableCollections: variables?.collections ?? {}, textStyles,
|
|
1252
1405
|
},
|
|
1253
1406
|
};
|
|
1254
1407
|
}
|
|
1408
|
+
/** Rebase Figma's boxes into the local coordinates of the fitted groups. */
|
|
1409
|
+
function fitInstanceBoxes(instanceBoxes, original, fitted) {
|
|
1410
|
+
const parents = buildParentMap(original);
|
|
1411
|
+
const origins = new Map();
|
|
1412
|
+
function groupOrigin(id) {
|
|
1413
|
+
if (id === undefined || original[id]?.type !== "group")
|
|
1414
|
+
return [0, 0];
|
|
1415
|
+
const found = origins.get(id);
|
|
1416
|
+
if (found)
|
|
1417
|
+
return found;
|
|
1418
|
+
const [a, b, c, d, x, y] = nodeLocalTransform(original[id]);
|
|
1419
|
+
const [, , , , fittedX, fittedY] = nodeLocalTransform(fitted[id]);
|
|
1420
|
+
const [px, py] = groupOrigin(parents.get(id));
|
|
1421
|
+
const dx = fittedX - x + px, dy = fittedY - y + py;
|
|
1422
|
+
const offset = [a * dx + b * dy, c * dx + d * dy];
|
|
1423
|
+
origins.set(id, offset);
|
|
1424
|
+
return offset;
|
|
1425
|
+
}
|
|
1426
|
+
for (const boxes of instanceBoxes.values())
|
|
1427
|
+
for (const [path, box] of boxes) {
|
|
1428
|
+
const id = parseLayerPath(path).at(-1);
|
|
1429
|
+
const [px, py] = groupOrigin(parents.get(id));
|
|
1430
|
+
const [dx, dy] = groupOrigin(id);
|
|
1431
|
+
if (px === 0 && py === 0 && dx === 0 && dy === 0)
|
|
1432
|
+
continue;
|
|
1433
|
+
const [a, b, c, d, x, y] = box.transform;
|
|
1434
|
+
boxes.set(path, { ...box, transform: [a, b, c, d, x + a * dx + c * dy - px, y + b * dx + d * dy - py] });
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1255
1437
|
/**
|
|
1256
1438
|
* Keeps each imported stack only when every Figma child in its flow (all but
|
|
1257
1439
|
* "Ignore auto layout" children) was imported into it: a left-out child would
|
|
@@ -1272,26 +1454,50 @@ function settleStacks(stacks, add, refits) {
|
|
|
1272
1454
|
const entry = imported.get(child);
|
|
1273
1455
|
return entry !== undefined && members.has(entry.node.id) ? entry : undefined;
|
|
1274
1456
|
};
|
|
1457
|
+
const grid = stack.node.type === "frame" && stack.node.layout.kind === "grid";
|
|
1275
1458
|
const flow = stack.figma.children.filter((child) => child.change["stackPositioning"] !== "ABSOLUTE");
|
|
1276
1459
|
const blocker = flow.find((child) => {
|
|
1277
1460
|
const entry = member(child);
|
|
1278
|
-
return entry === undefined || (entry.node.visible && refits(entry.node));
|
|
1461
|
+
return grid ? entry === undefined && child.change.visible !== false : entry === undefined || (entry.node.visible && refits(entry.node));
|
|
1279
1462
|
});
|
|
1463
|
+
const firstOnTop = stack.figma.change["stackReverseZIndex"] === true;
|
|
1280
1464
|
if (blocker !== undefined) {
|
|
1281
1465
|
const why = member(blocker) !== undefined ? "changes size or position when fitted to its layers, as a Taco group is"
|
|
1282
1466
|
: imported.has(blocker) ? "was imported on its own, outside this frame" : "was not imported";
|
|
1283
1467
|
add(stack.link, "property-left-out", `auto layout is left off, so children keep their positions: child ${blocker.type} ${JSON.stringify(blocker.name)} ${why}`);
|
|
1468
|
+
if (firstOnTop)
|
|
1469
|
+
add(stack.link, "property-left-out", "stackReverseZIndex (first child on top) requires auto layout");
|
|
1284
1470
|
Object.assign(stack.node, { layout: { kind: "absolute" } });
|
|
1285
1471
|
continue;
|
|
1286
1472
|
}
|
|
1473
|
+
if (firstOnTop)
|
|
1474
|
+
carry(stack.node, { firstOnTop: true });
|
|
1475
|
+
if (grid) {
|
|
1476
|
+
const rows = gridAxis(stack.figma.change, "gridRows", () => { }).indices;
|
|
1477
|
+
const columns = gridAxis(stack.figma.change, "gridColumns", () => { }).indices;
|
|
1478
|
+
for (const child of stack.figma.children) {
|
|
1479
|
+
const entry = member(child);
|
|
1480
|
+
const lost = (field) => add(entry?.link ?? stack.link, "property-left-out", `grid layout field ${field}`);
|
|
1481
|
+
if (!entry) {
|
|
1482
|
+
for (const field of Object.keys(child.change))
|
|
1483
|
+
if (field.startsWith("grid"))
|
|
1484
|
+
lost(field);
|
|
1485
|
+
continue;
|
|
1486
|
+
}
|
|
1487
|
+
const cell = gridCell(child.change, rows, columns, lost);
|
|
1488
|
+
if (Object.keys(cell).length)
|
|
1489
|
+
carry(entry.node, { gridCell: cell });
|
|
1490
|
+
Object.assign(entry.node, stackChildFields(child.change, false, false, entry.node, (kind, reason) => add(entry.link, kind, reason)));
|
|
1491
|
+
}
|
|
1492
|
+
continue;
|
|
1493
|
+
}
|
|
1287
1494
|
const vertical = stack.node.type === "frame" && stack.node.layout.kind === "vertical";
|
|
1495
|
+
const wraps = stack.figma.change["stackWrap"] === "WRAP";
|
|
1288
1496
|
for (const child of stack.figma.children) {
|
|
1289
1497
|
const entry = member(child);
|
|
1290
1498
|
if (entry === undefined)
|
|
1291
1499
|
continue;
|
|
1292
|
-
|
|
1293
|
-
const cannotFill = entry.node.type === "group" ? "a group" : entry.node.type === "shape" && entry.node.shape === "path" ? "a path" : undefined;
|
|
1294
|
-
Object.assign(entry.node, stackChildFields(entry.figma.change, vertical, entry.node, (kind, reason) => add(entry.link, kind, reason), cannotFill));
|
|
1500
|
+
Object.assign(entry.node, stackChildFields(entry.figma.change, vertical, wraps, entry.node, (kind, reason) => add(entry.link, kind, reason)));
|
|
1295
1501
|
}
|
|
1296
1502
|
}
|
|
1297
1503
|
}
|