@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.
- package/CHANGELOG.md +29 -0
- package/README.md +2 -2
- package/SOURCE.md +229 -4
- package/dist/adapter/convert.d.ts +24 -2
- package/dist/adapter/convert.js +669 -160
- 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 +12 -0
- package/dist/adapter/figma-handoff.js +167 -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 +14 -4
- package/dist/adapter/file-components.d.ts +9 -3
- package/dist/adapter/file-components.js +122 -32
- package/dist/adapter/file-resources.js +316 -27
- package/dist/adapter/image-crop.d.ts +18 -0
- package/dist/adapter/image-crop.js +30 -0
- package/dist/adapter/link.d.ts +5 -1
- package/dist/adapter/link.js +308 -104
- package/dist/adapter/payload.js +1 -1
- package/dist/adapter/variables.d.ts +2 -1
- package/dist/adapter/variables.js +5 -2
- package/dist/figma.js +167 -33
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/report.d.ts +28 -1
- package/dist/report.js +102 -29
- 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/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/exportSettings.d.ts +4 -0
- package/dist/taco/figma-import/import/converters/exportSettings.js +49 -0
- package/dist/taco/figma-import/import/converters/frame.js +8 -0
- 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/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 +1 -1
- package/dist/taco/figma-import/import/converters/image.js +22 -11
- package/dist/taco/figma-import/import/converters/layout.d.ts +3 -4
- package/dist/taco/figma-import/import/converters/layout.js +40 -21
- package/dist/taco/figma-import/import/converters/rectangle.d.ts +1 -1
- package/dist/taco/figma-import/import/converters/rectangle.js +1 -1
- package/dist/taco/figma-import/import/converters/section.d.ts +2 -3
- package/dist/taco/figma-import/import/converters/section.js +3 -9
- package/dist/taco/figma-import/import/converters/shared.d.ts +7 -4
- package/dist/taco/figma-import/import/converters/shared.js +15 -5
- package/dist/taco/figma-import/import/converters/text.d.ts +14 -1
- package/dist/taco/figma-import/import/converters/text.js +143 -12
- 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 +25 -4
- package/dist/taco/figma-import/import/instances.js +324 -117
- 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/variables.d.ts +3 -2
- package/dist/taco/figma-import/import/variables.js +37 -30
- package/dist/taco/figma-import/import/variantTrees.d.ts +1 -1
- package/dist/taco/figma-import/import/variantTrees.js +44 -4
- package/dist/taco/figma-import/import/walk.d.ts +53 -5
- package/dist/taco/figma-import/import/walk.js +273 -106
- package/dist/taco/figma-import/kiwi/message.d.ts +4 -2
- package/dist/taco/figma-import/kiwi/message.js +13 -11
- package/dist/taco/model/codec.d.ts +1 -1
- package/dist/taco/model/codec.js +37 -7
- 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 +48 -18
- package/dist/taco/model/sha256.js +13 -8
- package/dist/taco/model/types.d.ts +23 -1
- package/package.json +3 -2
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { constrainChildren, entryOf, formatExpressionName, getNodeBounds, layerPathKey, paragraphsFromCharacters, parseLayerPath, PROPERTIES_DROPPED_BY_FIELD, TEXT_STYLE_PROPERTIES, } from "../../model/index.js";
|
|
2
|
+
import { stackLayoutOf } from "./converters/layout.js";
|
|
3
|
+
import { withImageCrop } from "./carry.js";
|
|
2
4
|
import { field, guidText, isObject } from "./fields.js";
|
|
3
5
|
import { isDetachedStyle, STYLE_REFERENCE_FIELDS, styleBackedList } from "./styles.js";
|
|
4
6
|
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";
|
|
7
|
+
import { frameGeometry, readNumbers, STROKE_CAPS } from "./converters/shared.js";
|
|
8
|
+
import { hyperlinkOf, inheritOpenTypeToggles, KEPT_LINE_HEIGHT_FIELD, OPEN_TYPE_FIELDS, OPEN_TYPE_TOGGLES } from "./converters/text.js";
|
|
9
|
+
import { exportSettingsOf } from "./converters/exportSettings.js";
|
|
7
10
|
/** The `variableConsumptionMap` fields that bind each merged override field. */
|
|
8
11
|
const BOUND_BY_OVERRIDE = {
|
|
9
12
|
size: ["WIDTH", "HEIGHT"], visible: ["VISIBLE"], opacity: ["OPACITY"],
|
|
@@ -141,21 +144,38 @@ export function overrideKeyOf(node) {
|
|
|
141
144
|
/**
|
|
142
145
|
* Override fields whose effect the walk reads by converting the layer with
|
|
143
146
|
* and without them (`convertAlone`): paints, strokes, effects and the styles that back them, visibility,
|
|
144
|
-
* opacity, and a text layer's characters and
|
|
147
|
+
* opacity, and a text layer's characters, style and truncation.
|
|
145
148
|
*/
|
|
146
149
|
const CONVERTED_FIELDS = new Set([
|
|
147
150
|
"fillPaints", "strokePaints", "strokeWeight", "strokeAlign", "strokeJoin", "strokeCap", "dashPattern", "miterLimit",
|
|
148
151
|
"borderStrokeWeightsIndependent", "borderTopWeight", "borderBottomWeight", "borderLeftWeight", "borderRightWeight", "effects",
|
|
149
152
|
"styleIdForEffect", "styleIdForFill", "styleIdForStrokeFill", "visible", "opacity",
|
|
150
153
|
"textData", "styleIdForText", "fontName", "fontSize", "lineHeight", "letterSpacing", "textAlignHorizontal", "paragraphSpacing", "listSpacing", "textCase", "textDecoration", "fontVariations", "hyperlink",
|
|
154
|
+
"cornerSmoothing", "textTruncation", "maxLines", ...OPEN_TYPE_FIELDS,
|
|
151
155
|
]);
|
|
152
|
-
/**
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
*/
|
|
158
|
-
|
|
156
|
+
/** Fields applied to a frame or to the component root shown by a nested instance. */
|
|
157
|
+
const STACK_FIELDS = { gap: "stackSpacing", align: "stackCounterAlignItems", justify: "stackPrimaryAlignItems",
|
|
158
|
+
wrap: "stackWrap", wrapGap: "stackCounterSpacing", alignContent: "stackCounterAlignContent" };
|
|
159
|
+
const FRAME_FIELDS = new Set(["stackPrimarySizing", "stackCounterSizing", "stackMode", ...Object.values(STACK_FIELDS),
|
|
160
|
+
"frameMaskDisabled", "cornerSmoothing"]);
|
|
161
|
+
/** Keep only changed members, including explicit defaults which clear an inherited setting. */
|
|
162
|
+
function frameOverrides(base, next, authored = {}) {
|
|
163
|
+
const before = base.layout, after = next.layout;
|
|
164
|
+
const layout = {};
|
|
165
|
+
if (before.kind !== after.kind || "stackMode" in authored)
|
|
166
|
+
layout.kind = after.kind;
|
|
167
|
+
if (after.kind === "horizontal" || after.kind === "vertical") {
|
|
168
|
+
const from = before.kind === "horizontal" || before.kind === "vertical" ? before : undefined;
|
|
169
|
+
for (const key of ["gap", "align", "justify", "wrap", "wrapGap", "alignContent"]) {
|
|
170
|
+
if (after[key] !== from?.[key] || STACK_FIELDS[key] in authored)
|
|
171
|
+
layout[key] = after[key] ?? (key === "wrap" ? false : key === "alignContent" ? "auto" : after.gap);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
const sizing = before.kind === "absolute" && after.kind !== "absolute" ? { width: after.widthSizing, height: after.heightSizing } : undefined;
|
|
175
|
+
return { ...(Object.keys(layout).length && { layout }), ...(sizing && { sizing }),
|
|
176
|
+
...(before.kind === "absolute" && after.kind !== "absolute" && { padding: after.padding }),
|
|
177
|
+
...(!!base.clipContent !== !!next.clipContent && { clipContent: !!next.clipContent }) };
|
|
178
|
+
}
|
|
159
179
|
/**
|
|
160
180
|
* Padding override fields and the side each sets (`stackPadding`, Figma's older single value, sets every side the
|
|
161
181
|
* entry does not set on its own), as `stackLayoutOf` reads them.
|
|
@@ -169,16 +189,16 @@ const PADDING_FIELDS_OF_SIDE = {
|
|
|
169
189
|
};
|
|
170
190
|
/**
|
|
171
191
|
* Fields that change neither pixels nor behaviour, so they are skipped
|
|
172
|
-
* without a report: Figma's own bookkeeping
|
|
173
|
-
* loaded, and Dev Mode annotations and measurements, which only Figma's
|
|
174
|
-
* editor shows.
|
|
192
|
+
* without a report: Figma's own bookkeeping and the font file version it loaded.
|
|
175
193
|
*/
|
|
176
194
|
const BOOKKEEPING_FIELDS = new Set([
|
|
177
|
-
"guidPath", "overrideLevel", "textUserLayoutVersion", "vectorOperationVersion", "fontVersion",
|
|
195
|
+
"guidPath", "overrideLevel", "textUserLayoutVersion", "vectorOperationVersion", "fontVersion",
|
|
178
196
|
]);
|
|
197
|
+
const HANDOFF_OVERRIDE_FIELDS = new Set(["annotations", "measurements"]);
|
|
198
|
+
const activeHandoffOverride = (value) => value !== undefined && (!Array.isArray(value) || value.some((item) => !isObject(item) || item["isDeleted"] !== true));
|
|
179
199
|
/** 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);
|
|
200
|
+
const STYLE_OVERRIDES = ["cornerSmoothing", "fills", "strokes", "shadows", "layerBlur", "backgroundBlur"];
|
|
201
|
+
const same = (a, b) => JSON.stringify(a, withImageCrop) === JSON.stringify(b, withImageCrop);
|
|
182
202
|
function styleOf(node) {
|
|
183
203
|
return "style" in node && node.style !== undefined ? node.style : {};
|
|
184
204
|
}
|
|
@@ -274,7 +294,7 @@ function overrideBetween(base, next, report) {
|
|
|
274
294
|
const nextStyle = styleOf(next);
|
|
275
295
|
for (const name of STYLE_OVERRIDES) {
|
|
276
296
|
if (!same(baseStyle[name], nextStyle[name]))
|
|
277
|
-
override[name] = nextStyle[name] ?? (name === "layerBlur" || name === "backgroundBlur" ? 0 : []);
|
|
297
|
+
override[name] = nextStyle[name] ?? (name === "layerBlur" || name === "backgroundBlur" || name === "cornerSmoothing" ? 0 : []);
|
|
278
298
|
}
|
|
279
299
|
for (const name of new Set([...Object.keys(baseStyle), ...Object.keys(nextStyle)])) {
|
|
280
300
|
if (!STYLE_OVERRIDES.includes(name) && !same(baseStyle[name], nextStyle[name])) {
|
|
@@ -307,6 +327,12 @@ function overrideBetween(base, next, report) {
|
|
|
307
327
|
if (realigned !== undefined && override["paragraphs"] === undefined)
|
|
308
328
|
override["textAlign"] = realigned.align;
|
|
309
329
|
}
|
|
330
|
+
// `null` takes away a line limit or truncation the component has.
|
|
331
|
+
if (base.type === "text" && next.type === "text") {
|
|
332
|
+
for (const name of ["maxLines", "truncate"])
|
|
333
|
+
if (base[name] !== next[name])
|
|
334
|
+
override[name] = next[name] ?? null;
|
|
335
|
+
}
|
|
310
336
|
return override;
|
|
311
337
|
}
|
|
312
338
|
/**
|
|
@@ -488,7 +514,7 @@ function pathPlacedOtherThanFigma(node, placed, figmaBefore, figmaAfter) {
|
|
|
488
514
|
* constraints unless it was resized (`swappedInstance` in the model), which is not simulated
|
|
489
515
|
* here, so a resized instance with one counts as laid out otherwise.
|
|
490
516
|
*/
|
|
491
|
-
function constrainedOtherThanFigma(instance, component, self, nodes, swappedToOtherSize) {
|
|
517
|
+
function constrainedOtherThanFigma(instance, component, self, nodes, swappedToOtherSize, kept) {
|
|
492
518
|
const from = component.root.frame;
|
|
493
519
|
if (self.frame.width === from.width && self.frame.height === from.height)
|
|
494
520
|
return false;
|
|
@@ -519,11 +545,14 @@ function constrainedOtherThanFigma(instance, component, self, nodes, swappedToOt
|
|
|
519
545
|
return true;
|
|
520
546
|
const placed = new Map(constrainChildren(nodes, component.root.id, from, self.frame).map((node) => [node.id, node]));
|
|
521
547
|
for (const [key, { figma, node }] of component.layers) {
|
|
522
|
-
if (node.id === component.root.id)
|
|
548
|
+
if (node.id === component.root.id || kept?.has(layerPathKey([node.id])))
|
|
523
549
|
continue;
|
|
524
550
|
const at = `node ${figma.id}`;
|
|
525
551
|
const derived = laidOut.get(key);
|
|
526
552
|
const override = overridden.get(key);
|
|
553
|
+
// For saved files, only compare paths with a derived entry. Other layers still follow constraints.
|
|
554
|
+
if (kept && !derived)
|
|
555
|
+
continue;
|
|
527
556
|
const sizeAfter = derived?.["size"] ?? override?.["size"] ?? figma.change["size"];
|
|
528
557
|
const transformAfter = derived?.["transform"] ?? override?.["transform"] ?? figma.change["transform"];
|
|
529
558
|
if (!("frame" in node)) {
|
|
@@ -558,6 +587,35 @@ function constrainedOtherThanFigma(instance, component, self, nodes, swappedToOt
|
|
|
558
587
|
}
|
|
559
588
|
return false;
|
|
560
589
|
}
|
|
590
|
+
/** A derived entry can omit fields that still have their authored or component values. */
|
|
591
|
+
function storedBox(layer, derived, authored) {
|
|
592
|
+
const { figma, node } = layer;
|
|
593
|
+
const path = node.type === "shape" && node.shape === "path";
|
|
594
|
+
if (path && [derived, authored].every(entry => entry?.["size"] === undefined && entry?.["transform"] === undefined))
|
|
595
|
+
return undefined;
|
|
596
|
+
const geometry = frameGeometry({ ...figma, change: {
|
|
597
|
+
size: derived["size"] ?? authored?.["size"] ?? figma.change["size"],
|
|
598
|
+
transform: derived["transform"] ?? authored?.["transform"] ?? figma.change["transform"],
|
|
599
|
+
} });
|
|
600
|
+
if (!geometry)
|
|
601
|
+
return undefined;
|
|
602
|
+
const { sides: { x: width, y: height }, m } = geometry;
|
|
603
|
+
if (width < 0 || height < 0)
|
|
604
|
+
return undefined;
|
|
605
|
+
const transform = [m.m00, m.m10, m.m01, m.m11, m.m02, m.m12];
|
|
606
|
+
if (!path)
|
|
607
|
+
return { width, height, transform };
|
|
608
|
+
const before = figma.change["size"];
|
|
609
|
+
if (!isObject(before))
|
|
610
|
+
return undefined;
|
|
611
|
+
const original = readNumbers(before, ["x", "y"], `node ${figma.id} size`);
|
|
612
|
+
if (!original || (!original.x && width) || (!original.y && height))
|
|
613
|
+
return undefined;
|
|
614
|
+
const pathScale = [original.x ? width / original.x : 1, original.y ? height / original.y : 1];
|
|
615
|
+
if (!pathScale.every(Number.isFinite))
|
|
616
|
+
return undefined;
|
|
617
|
+
return { width, height, transform, pathScale };
|
|
618
|
+
}
|
|
561
619
|
/**
|
|
562
620
|
* The axes an instance hugs where Figma stored another size for it (`size`)
|
|
563
621
|
* than the one it laid its root out at (the `derivedSymbolData` entry whose
|
|
@@ -598,8 +656,8 @@ function storedOverHug(instance, component, self) {
|
|
|
598
656
|
* an override under the root's path, and so does a Hug or Fixed axis that
|
|
599
657
|
* differs. Each `symbolOverrides` path step names a layer by its
|
|
600
658
|
* `overrideKey` (or guid); a step past the first goes through a nested
|
|
601
|
-
* instance into the component it shows, after
|
|
602
|
-
*
|
|
659
|
+
* instance into the component it shows, after explicit swaps by this instance or its nested holders,
|
|
660
|
+
* or a swap driven by a component property. Fields become `LayerOverride` fields where Taco
|
|
603
661
|
* has them (`overriddenSymbolID` a swap, `componentPropAssignments` property
|
|
604
662
|
* values, paints, effects, visibility, opacity, text); the rest are counted
|
|
605
663
|
* through `leftOutField`. A swap in `refusedSwaps` is left out, and so is
|
|
@@ -611,23 +669,65 @@ export function instanceFields(instance, component, self, context) {
|
|
|
611
669
|
const where = `node ${instance.id}`;
|
|
612
670
|
const overrides = {};
|
|
613
671
|
const overrideAt = (key) => (overrides[key] ??= {});
|
|
672
|
+
const assignedLinks = new Map();
|
|
673
|
+
const captureLinks = (shown, path) => (id, data, text) => {
|
|
674
|
+
const key = `${path}/${id}`, table = data["styleOverrideTable"];
|
|
675
|
+
if (Array.isArray(table) && table.some(row => isObject(row) && Object.hasOwn(row, "hyperlink")))
|
|
676
|
+
assignedLinks.set(key, { shown, path, id, text, data });
|
|
677
|
+
else
|
|
678
|
+
assignedLinks.delete(key);
|
|
679
|
+
};
|
|
614
680
|
const componentIdOf = (symbolId) => context.component(symbolId)?.componentId;
|
|
615
681
|
const swapsKept = new Set();
|
|
616
682
|
const refusedSwap = (container, target) => context.refusedSwaps?.get(`${container.symbol.id}>${target}`);
|
|
683
|
+
const pathSwaps = new Map();
|
|
684
|
+
const swapsAtPath = (path) => {
|
|
685
|
+
let record = pathSwaps.get(path);
|
|
686
|
+
if (!record)
|
|
687
|
+
pathSwaps.set(path, record = {});
|
|
688
|
+
return record;
|
|
689
|
+
};
|
|
617
690
|
// 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) => {
|
|
691
|
+
const leftOutValue = (inComponent, path) => (symbolId, property) => {
|
|
619
692
|
const refused = refusedSwap(inComponent, symbolId);
|
|
620
|
-
|
|
621
|
-
|
|
693
|
+
// Another variant can bind an assignment which is dormant on the stored component.
|
|
694
|
+
const properties = swapsAtPath(path).properties ??= {};
|
|
695
|
+
if (refused === undefined) {
|
|
696
|
+
properties[property] = symbolId;
|
|
697
|
+
if (inComponent.boundSwaps.has(property))
|
|
698
|
+
swapsKept.add(`${inComponent.symbol.id}>${symbolId}`);
|
|
699
|
+
}
|
|
700
|
+
else
|
|
701
|
+
properties[property] ??= INSIDE_LEFT_OUT;
|
|
622
702
|
return refused;
|
|
623
703
|
};
|
|
704
|
+
const symbolData = field(instance.change, "symbolData", "object", where) ?? {};
|
|
705
|
+
const entries = (field(symbolData, "symbolOverrides", "list", `${where} symbolData`) ?? []).flatMap((entry, index) => {
|
|
706
|
+
const at = `${where} symbolOverrides[${String(index)}]`;
|
|
707
|
+
if (!isObject(entry))
|
|
708
|
+
return [];
|
|
709
|
+
const path = field(entry, "guidPath", "object", at);
|
|
710
|
+
const guids = path === undefined ? [] : field(path, "guids", "list", `${at}.guidPath`) ?? [];
|
|
711
|
+
return [{ keys: guids.map((guid) => guidText(guid, `${at}.guidPath`)), entry, at }];
|
|
712
|
+
}).sort((a, b) => a.keys.length - b.keys.length);
|
|
713
|
+
const rootFields = Object.assign({}, ...entries.filter(({ keys }) => keys.length === 1 && keys[0] === component.symbol.id)
|
|
714
|
+
.map(({ entry }) => Object.fromEntries(Object.entries(entry).filter(([key]) => FRAME_FIELDS.has(key) || Object.hasOwn(PADDING_FIELDS, key)))));
|
|
715
|
+
const ownFields = { ...instance.change, ...rootFields };
|
|
716
|
+
if (Object.keys(rootFields).length) {
|
|
717
|
+
const converted = context.convertAlone(instance, rootFields);
|
|
718
|
+
if (converted?.type === "frame")
|
|
719
|
+
self = { ...self, layout: converted.layout, style: { ...self.style, cornerSmoothing: converted.style?.cornerSmoothing ?? 0 },
|
|
720
|
+
clipContent: !!converted.clipContent };
|
|
721
|
+
}
|
|
624
722
|
// The instance's own frame against the component root.
|
|
625
723
|
const rootKey = layerPathKey([component.root.id]);
|
|
626
724
|
const rootStyle = styleOf(component.root);
|
|
627
725
|
const ownStyle = styleOf(self);
|
|
628
726
|
for (const name of STYLE_OVERRIDES) {
|
|
727
|
+
if (name === "cornerSmoothing" && ownFields.cornerSmoothing === undefined)
|
|
728
|
+
continue;
|
|
629
729
|
if (!same(rootStyle[name], ownStyle[name]))
|
|
630
|
-
overrideAt(rootKey)[name] = ownStyle[name] ?? (name === "layerBlur" || name === "backgroundBlur" ? 0 : []);
|
|
730
|
+
overrideAt(rootKey)[name] = ownStyle[name] ?? (name === "layerBlur" || name === "backgroundBlur" || name === "cornerSmoothing" ? 0 : []);
|
|
631
731
|
}
|
|
632
732
|
for (const name of new Set([...Object.keys(rootStyle), ...Object.keys(ownStyle)])) {
|
|
633
733
|
if (context.fileOverride && (name === "cornerRadius" || name === "cornerRadii"))
|
|
@@ -636,9 +736,15 @@ export function instanceFields(instance, component, self, context) {
|
|
|
636
736
|
context.report("property-left-out", `an instance's own ${name} differs from its component and is left out: Taco instances cannot override it`);
|
|
637
737
|
}
|
|
638
738
|
}
|
|
639
|
-
|
|
640
|
-
|
|
739
|
+
// A sparse INSTANCE can omit its entire stack and clip flag. Only authored fields replace the template.
|
|
740
|
+
if (ownFields.stackMode === undefined || rootFields.stackMode !== undefined || ownFields.stackMode !== component.symbol.change["stackMode"]) {
|
|
741
|
+
const stack = Object.keys(ownFields).some(key => FRAME_FIELDS.has(key) && key.startsWith("stack") || Object.hasOwn(PADDING_FIELDS, key));
|
|
742
|
+
const layout = stack ? stackLayoutOf({ ...component.symbol.change, ...ownFields }, () => { }) : undefined;
|
|
743
|
+
self = { ...self, layout: layout ?? (ownFields.stackMode === undefined ? component.root.layout : self.layout) };
|
|
641
744
|
}
|
|
745
|
+
Object.assign(overrideAt(rootKey), frameOverrides(component.root, {
|
|
746
|
+
...self, clipContent: !!(ownFields.frameMaskDisabled === undefined ? component.root.clipContent : self.clipContent),
|
|
747
|
+
}));
|
|
642
748
|
if (component.root.layout.kind !== "absolute" && self.layout.kind !== "absolute") {
|
|
643
749
|
const sizing = {};
|
|
644
750
|
for (const [axis, key] of [["width", "widthSizing"], ["height", "heightSizing"]]) {
|
|
@@ -670,20 +776,6 @@ export function instanceFields(instance, component, self, context) {
|
|
|
670
776
|
if (Object.keys(padding).length > 0)
|
|
671
777
|
overrideAt(rootKey)["padding"] = padding;
|
|
672
778
|
}
|
|
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
779
|
// The property values set for the instance at each path's Figma keys ("" for this instance), for instance swap properties.
|
|
688
780
|
const assignmentsAt = new Map([["", field(instance.change, "componentPropAssignments", "list", where) ?? []]]);
|
|
689
781
|
for (const { keys, entry, at } of entries) {
|
|
@@ -691,35 +783,36 @@ export function instanceFields(instance, component, self, context) {
|
|
|
691
783
|
if (list !== undefined && keys.length > 0)
|
|
692
784
|
assignmentsAt.set(keys.join("/"), [...assignmentsAt.get(keys.join("/")) ?? [], ...list]);
|
|
693
785
|
}
|
|
694
|
-
//
|
|
695
|
-
//
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
786
|
+
// Each holder's path ends at the bound layer. The assignment belongs to its parent instance
|
|
787
|
+
// (the empty path for the innermost holder). An explicit swap resets values from deeper holders.
|
|
788
|
+
const heldPropertySwap = (through, property) => {
|
|
789
|
+
for (const holder of through) {
|
|
790
|
+
const parent = layerPathKey(parseLayerPath(holder.inner).slice(0, -1));
|
|
791
|
+
const inherited = context.nestedSwaps(holder.instance, parent);
|
|
792
|
+
const value = inherited?.properties?.[property];
|
|
793
|
+
if (value !== undefined || inherited?.symbol !== undefined)
|
|
794
|
+
return value;
|
|
795
|
+
}
|
|
796
|
+
return undefined;
|
|
704
797
|
};
|
|
705
|
-
//
|
|
706
|
-
|
|
707
|
-
const propertySwap = (layer, inComponent, inKeys) => {
|
|
798
|
+
// A placement's own assignment takes precedence over its enclosing holders.
|
|
799
|
+
const propertySwap = (layer, inComponent, parentKey, through) => {
|
|
708
800
|
let symbolId;
|
|
709
|
-
const assignments = [...heldAssignments(inKeys), ...assignmentsAt.get(inKeys.join("/")) ?? []];
|
|
710
801
|
for (const ref of field(layer.change, "componentPropRefs", "list", `node ${layer.id}`) ?? []) {
|
|
711
802
|
if (!isObject(ref) || ref["componentPropNodeField"] !== "OVERRIDDEN_SYMBOL_ID" || ref["defID"] === undefined || ref["isDeleted"] === true)
|
|
712
803
|
continue;
|
|
713
804
|
const property = propertyByFigmaId(inComponent.properties, guidText(ref["defID"], `node ${layer.id} componentPropRefs`));
|
|
714
805
|
if (property === undefined)
|
|
715
806
|
continue;
|
|
716
|
-
|
|
807
|
+
let own;
|
|
808
|
+
for (const assignment of assignmentsAt.get(parentKey) ?? []) {
|
|
717
809
|
if (!isObject(assignment) || assignment["defID"] === undefined)
|
|
718
810
|
continue;
|
|
719
811
|
if (propertyByFigmaId(inComponent.properties, guidText(assignment["defID"], `${where} componentPropAssignments`)) !== property)
|
|
720
812
|
continue;
|
|
721
|
-
|
|
813
|
+
own = assignedValueOf(assignment, `${where} componentPropAssignments`).symbolId ?? own;
|
|
722
814
|
}
|
|
815
|
+
symbolId = own ?? (swaps.has(parentKey) ? undefined : heldPropertySwap(through, property.definition.id)) ?? symbolId;
|
|
723
816
|
}
|
|
724
817
|
return symbolId;
|
|
725
818
|
};
|
|
@@ -727,15 +820,20 @@ export function instanceFields(instance, component, self, context) {
|
|
|
727
820
|
// property value, else its own. `INSIDE_LEFT_OUT` when the nesting check left out the swap or value it would show.
|
|
728
821
|
const swaps = new Map();
|
|
729
822
|
const leftOutSwaps = new Set();
|
|
730
|
-
const shownAt = (keys, layer, inComponent) => {
|
|
823
|
+
const shownAt = (keys, layer, inComponent, through) => {
|
|
731
824
|
const key = keys.join("/");
|
|
732
825
|
const swapped = swaps.get(key);
|
|
733
826
|
if (swapped !== undefined)
|
|
734
827
|
return context.component(swapped);
|
|
735
828
|
if (leftOutSwaps.has(key))
|
|
736
829
|
return INSIDE_LEFT_OUT;
|
|
737
|
-
|
|
738
|
-
|
|
830
|
+
for (const holder of through) {
|
|
831
|
+
const inherited = context.nestedSwaps(holder.instance, holder.inner)?.symbol;
|
|
832
|
+
if (inherited !== undefined)
|
|
833
|
+
return inherited === INSIDE_LEFT_OUT ? INSIDE_LEFT_OUT : context.component(inherited);
|
|
834
|
+
}
|
|
835
|
+
const valued = propertySwap(layer, inComponent, keys.slice(0, -1).join("/"), through);
|
|
836
|
+
if (valued === INSIDE_LEFT_OUT || (valued !== undefined && refusedSwap(inComponent, valued) !== undefined))
|
|
739
837
|
return INSIDE_LEFT_OUT;
|
|
740
838
|
return context.component(valued ?? shownSymbol(layer) ?? "");
|
|
741
839
|
};
|
|
@@ -753,14 +851,14 @@ export function instanceFields(instance, component, self, context) {
|
|
|
753
851
|
return flattenedInto === undefined ? undefined : { flattenedInto };
|
|
754
852
|
}
|
|
755
853
|
ids.push(layer.node.id);
|
|
854
|
+
const through = instances.map((instance, at) => ({ instance, inner: layerPathKey(ids.slice(at + 1)) }));
|
|
756
855
|
if (i === keys.length - 1) {
|
|
757
|
-
const through = instances.map((instance, at) => ({ instance, inner: layerPathKey(ids.slice(at + 1)) }));
|
|
758
856
|
return { key: layerPathKey(ids), layer, component: inComponent, through };
|
|
759
857
|
}
|
|
760
858
|
if (layer.figma.type !== "INSTANCE")
|
|
761
859
|
return undefined;
|
|
762
860
|
instances.push(layer.node);
|
|
763
|
-
inComponent = shownAt(keys.slice(0, i + 1), layer.figma, inComponent);
|
|
861
|
+
inComponent = shownAt(keys.slice(0, i + 1), layer.figma, inComponent, through);
|
|
764
862
|
}
|
|
765
863
|
return undefined;
|
|
766
864
|
};
|
|
@@ -814,15 +912,24 @@ export function instanceFields(instance, component, self, context) {
|
|
|
814
912
|
}
|
|
815
913
|
return reset;
|
|
816
914
|
};
|
|
817
|
-
|
|
818
|
-
let insideLeftOut = 0;
|
|
915
|
+
const insideLeftOut = new Set();
|
|
819
916
|
const pending = new Map();
|
|
820
917
|
const targets = [];
|
|
918
|
+
let rootExports;
|
|
821
919
|
// Swaps first, shorter paths before longer ones, so property values and deeper paths are read against the component swapped in.
|
|
822
920
|
for (const { keys, entry, at } of entries) {
|
|
823
921
|
// A path naming the component itself targets the instance, which already carries those values.
|
|
824
|
-
if (keys.length === 1 && keys[0] === component.symbol.id)
|
|
922
|
+
if (keys.length === 1 && keys[0] === component.symbol.id) {
|
|
923
|
+
for (const name of HANDOFF_OVERRIDE_FIELDS)
|
|
924
|
+
if (activeHandoffOverride(entry[name]))
|
|
925
|
+
context.leftOutField(name);
|
|
926
|
+
if (entry["exportSettings"] !== undefined)
|
|
927
|
+
rootExports = entry["exportSettings"];
|
|
825
928
|
continue;
|
|
929
|
+
}
|
|
930
|
+
if (entry["exportSettings"] !== undefined) {
|
|
931
|
+
context.report("property-left-out", "an export settings override on an inherited layer is left out");
|
|
932
|
+
}
|
|
826
933
|
const target = keys.length === 0 ? undefined : resolve(keys);
|
|
827
934
|
if (target !== undefined && target !== INSIDE_LEFT_OUT && "flattenedInto" in target) {
|
|
828
935
|
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 +937,11 @@ export function instanceFields(instance, component, self, context) {
|
|
|
830
937
|
}
|
|
831
938
|
if (target === undefined || target === INSIDE_LEFT_OUT) {
|
|
832
939
|
if (target === undefined)
|
|
833
|
-
|
|
940
|
+
context.report("property-left-out", keys.some(key => !context.hasSourceKey(key))
|
|
941
|
+
? "an override path contains a GUID with no source layer or override key"
|
|
942
|
+
: "an override path that names no imported layer of the component is left out");
|
|
834
943
|
else
|
|
835
|
-
insideLeftOut
|
|
944
|
+
insideLeftOut.add(entry);
|
|
836
945
|
continue;
|
|
837
946
|
}
|
|
838
947
|
let gathered = pending.get(target.key);
|
|
@@ -850,6 +959,8 @@ export function instanceFields(instance, component, self, context) {
|
|
|
850
959
|
else if (refused !== undefined) {
|
|
851
960
|
context.report("property-left-out", `a swap ${refused}`);
|
|
852
961
|
leftOutSwaps.add(keys.join("/"));
|
|
962
|
+
if (!swaps.has(keys.join("/")))
|
|
963
|
+
swapsAtPath(target.key).symbol = INSIDE_LEFT_OUT;
|
|
853
964
|
}
|
|
854
965
|
else {
|
|
855
966
|
gathered.override["componentId"] = swapped;
|
|
@@ -857,15 +968,49 @@ export function instanceFields(instance, component, self, context) {
|
|
|
857
968
|
if (Object.keys(reset).length > 0)
|
|
858
969
|
gathered.override["propertyValues"] = { ...gathered.override["propertyValues"], ...reset };
|
|
859
970
|
swaps.set(keys.join("/"), symbolId);
|
|
971
|
+
swapsAtPath(target.key).symbol = symbolId;
|
|
860
972
|
swapsKept.add(`${target.component.symbol.id}>${symbolId}`);
|
|
861
973
|
}
|
|
862
974
|
}
|
|
975
|
+
const boxes = new Map();
|
|
976
|
+
const from = component.root.frame;
|
|
977
|
+
const resizedFreeFrame = component.root.layout.kind === "absolute" && (self.frame.width !== from.width || self.frame.height !== from.height);
|
|
978
|
+
if (context.fileLayout) {
|
|
979
|
+
const authored = new Map();
|
|
980
|
+
for (const { keys, entry } of entries) {
|
|
981
|
+
const key = keys.join("/");
|
|
982
|
+
authored.set(key, { ...authored.get(key), ...entry });
|
|
983
|
+
}
|
|
984
|
+
for (const [index, entry] of (field(instance.change, "derivedSymbolData", "list", where) ?? []).entries()) {
|
|
985
|
+
if (!isObject(entry) || (!resizedFreeFrame && entry["size"] === undefined))
|
|
986
|
+
continue;
|
|
987
|
+
const at = `${where} derivedSymbolData[${String(index)}]`;
|
|
988
|
+
const path = field(entry, "guidPath", "object", at);
|
|
989
|
+
const keys = (path === undefined ? [] : field(path, "guids", "list", `${at}.guidPath`) ?? []).map(guid => guidText(guid, `${at}.guidPath`));
|
|
990
|
+
const target = resolve(keys);
|
|
991
|
+
if (!target || target === INSIDE_LEFT_OUT || "flattenedInto" in target || target.layer.node.id === target.component.root.id)
|
|
992
|
+
continue;
|
|
993
|
+
// A stack can allocate a different size even when the stored group or vector
|
|
994
|
+
// matches its main. Keep that explicit size as an input to the adapter.
|
|
995
|
+
const layer = target.layer.node;
|
|
996
|
+
const change = target.layer.figma.change;
|
|
997
|
+
const requestsFill = change["stackPositioning"] !== "ABSOLUTE" &&
|
|
998
|
+
(Number(change["stackChildPrimaryGrow"]) > 0 || change["stackChildAlignSelf"] === "STRETCH");
|
|
999
|
+
const fillLayer = layer.type === "group" || (layer.type === "shape" && layer.shape === "path");
|
|
1000
|
+
if (!resizedFreeFrame && !(fillLayer && requestsFill))
|
|
1001
|
+
continue;
|
|
1002
|
+
const box = storedBox(target.layer, entry, authored.get(keys.join("/")));
|
|
1003
|
+
if (box)
|
|
1004
|
+
boxes.set(target.key, box);
|
|
1005
|
+
}
|
|
1006
|
+
context.fileLayout(boxes, !resizedFreeFrame);
|
|
1007
|
+
}
|
|
863
1008
|
if (component.root.layout.kind === "absolute") {
|
|
864
1009
|
// 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
1010
|
const swappedToOtherSize = [...component.layers].some(([key, { figma, node }]) => {
|
|
866
|
-
if (figma.type !== "INSTANCE" || !("frame" in node))
|
|
1011
|
+
if (figma.type !== "INSTANCE" || !("frame" in node) || boxes.has(layerPathKey([node.id])))
|
|
867
1012
|
return false;
|
|
868
|
-
const shown = shownAt([key], figma, component);
|
|
1013
|
+
const shown = shownAt([key], figma, component, []);
|
|
869
1014
|
const own = context.component(shownSymbol(figma) ?? "");
|
|
870
1015
|
if (shown === undefined || shown === INSIDE_LEFT_OUT || shown === own)
|
|
871
1016
|
return false;
|
|
@@ -874,7 +1019,7 @@ export function instanceFields(instance, component, self, context) {
|
|
|
874
1019
|
return false;
|
|
875
1020
|
return Math.abs(shown.root.frame.width - node.frame.width) > 0.01 || Math.abs(shown.root.frame.height - node.frame.height) > 0.01;
|
|
876
1021
|
});
|
|
877
|
-
if (constrainedOtherThanFigma(instance, component, self, context.nodes, swappedToOtherSize)) {
|
|
1022
|
+
if (constrainedOtherThanFigma(instance, component, self, context.nodes, swappedToOtherSize, context.fileLayout ? boxes : undefined)) {
|
|
878
1023
|
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
1024
|
}
|
|
880
1025
|
}
|
|
@@ -883,8 +1028,13 @@ export function instanceFields(instance, component, self, context) {
|
|
|
883
1028
|
const { target } = gathered;
|
|
884
1029
|
const isInstance = target.layer.figma.type === "INSTANCE";
|
|
885
1030
|
for (const [name, value] of Object.entries(entry)) {
|
|
886
|
-
if (BOOKKEEPING_FIELDS.has(name) || (name === "overriddenSymbolID" && isInstance))
|
|
1031
|
+
if (BOOKKEEPING_FIELDS.has(name) || name === "exportSettings" || (name === "overriddenSymbolID" && isInstance))
|
|
887
1032
|
continue;
|
|
1033
|
+
if (HANDOFF_OVERRIDE_FIELDS.has(name)) {
|
|
1034
|
+
if (activeHandoffOverride(value))
|
|
1035
|
+
context.leftOutField(name);
|
|
1036
|
+
continue;
|
|
1037
|
+
}
|
|
888
1038
|
// Figma's record of the variable bindings this override set, which `variableConsumptionMap` beside it holds too.
|
|
889
1039
|
if (name === "parameterConsumptionMap" && entry["variableConsumptionMap"] !== undefined) {
|
|
890
1040
|
const extras = parameterMapExtras(value, entry["variableConsumptionMap"]);
|
|
@@ -893,12 +1043,12 @@ export function instanceFields(instance, component, self, context) {
|
|
|
893
1043
|
continue;
|
|
894
1044
|
}
|
|
895
1045
|
if (name === "componentPropAssignments" && isInstance) {
|
|
896
|
-
const shown = shownAt(keys, target.layer.figma, target.component);
|
|
1046
|
+
const shown = shownAt(keys, target.layer.figma, target.component, target.through);
|
|
897
1047
|
if (shown === INSIDE_LEFT_OUT)
|
|
898
|
-
insideLeftOut
|
|
1048
|
+
insideLeftOut.add(entry);
|
|
899
1049
|
if (shown === undefined || shown === INSIDE_LEFT_OUT)
|
|
900
1050
|
continue;
|
|
901
|
-
const values = assignedPropertyValues(field(entry, name, "list", at), shown.properties, shown.variantDefs, componentIdOf, leftOutValue(shown), at, context.report);
|
|
1051
|
+
const values = assignedPropertyValues(field(entry, name, "list", at), shown.properties, shown.variantDefs, componentIdOf, leftOutValue(shown, target.key), at, context.report, captureLinks(shown, target.key));
|
|
902
1052
|
if (Object.keys(values).length > 0)
|
|
903
1053
|
gathered.override["propertyValues"] = { ...gathered.override["propertyValues"], ...values };
|
|
904
1054
|
}
|
|
@@ -908,43 +1058,30 @@ export function instanceFields(instance, component, self, context) {
|
|
|
908
1058
|
if (!context.fileOverride)
|
|
909
1059
|
context.leftOutField(name);
|
|
910
1060
|
}
|
|
911
|
-
else if (
|
|
912
|
-
const shown = isInstance ? shownAt(keys, target.layer.figma, target.component) : undefined;
|
|
1061
|
+
else if ((FRAME_FIELDS.has(name) || Object.hasOwn(PADDING_FIELDS, name)) && (target.layer.node.type === "frame" || isInstance)) {
|
|
1062
|
+
const shown = isInstance ? shownAt(keys, target.layer.figma, target.component, target.through) : undefined;
|
|
913
1063
|
if (shown === INSIDE_LEFT_OUT)
|
|
914
|
-
insideLeftOut
|
|
1064
|
+
insideLeftOut.add(entry);
|
|
915
1065
|
else if (isInstance && shown === undefined)
|
|
916
1066
|
context.leftOutField(name);
|
|
917
1067
|
else {
|
|
918
1068
|
const { figma } = target.layer;
|
|
919
1069
|
const under = (inner) => layerPathKey([...parseLayerPath(inner), shown.root.id]);
|
|
920
1070
|
const key = shown === undefined ? target.key : under(target.key);
|
|
921
|
-
gathered.
|
|
1071
|
+
gathered.frame ??= {
|
|
922
1072
|
fields: {}, at: overrideAt(key), key, from: shown === undefined || figma.change["stackMode"] !== undefined ? figma : shown.symbol,
|
|
923
1073
|
holders: shown === undefined ? target.through
|
|
924
1074
|
: [...target.through.map(({ instance, inner }) => ({ instance, inner: under(inner) })), { instance: target.layer.node, inner: layerPathKey([shown.root.id]) }],
|
|
925
1075
|
};
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
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;
|
|
1076
|
+
if (Object.hasOwn(PADDING_FIELDS, name)) {
|
|
1077
|
+
const sides = PADDING_FIELDS[name];
|
|
1078
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value < 0)
|
|
1079
|
+
context.leftOutField(name);
|
|
1080
|
+
else
|
|
1081
|
+
(gathered.frame.padding ??= []).push({ name, value, sides: sides.filter(side => sides.length === 1 || !PADDING_FIELDS_OF_SIDE[side].some(key => key in entry)) });
|
|
1082
|
+
}
|
|
1083
|
+
else
|
|
1084
|
+
gathered.frame.fields[name] = value;
|
|
948
1085
|
}
|
|
949
1086
|
}
|
|
950
1087
|
else if (name === "name") {
|
|
@@ -1015,21 +1152,40 @@ export function instanceFields(instance, component, self, context) {
|
|
|
1015
1152
|
context.report("approximated", "instance keeps Figma's stored line height from before its text style changed");
|
|
1016
1153
|
}
|
|
1017
1154
|
const heldSizing = new Map();
|
|
1018
|
-
for (const { target, fields, override,
|
|
1019
|
-
if (
|
|
1020
|
-
const base = context.convertAlone(
|
|
1021
|
-
const next = context.convertAlone(
|
|
1022
|
-
|
|
1155
|
+
for (const { target, fields, override, frame } of pending.values()) {
|
|
1156
|
+
if (frame !== undefined) {
|
|
1157
|
+
const base = context.convertAlone(frame.from);
|
|
1158
|
+
const next = context.convertAlone(frame.from, frame.fields);
|
|
1159
|
+
if (base?.type === "frame" && next?.type === "frame") {
|
|
1160
|
+
Object.assign(frame.at, frameOverrides(base, next, frame.fields));
|
|
1161
|
+
// Resolve padding after stackMode, even when separate entries enable the stack and pad it.
|
|
1162
|
+
for (const { name, sides, value } of frame.padding ?? []) {
|
|
1163
|
+
if (next.layout.kind === "absolute")
|
|
1164
|
+
context.leftOutField(name);
|
|
1165
|
+
else {
|
|
1166
|
+
const padding = (frame.at.padding ??= {});
|
|
1167
|
+
for (const side of sides)
|
|
1168
|
+
padding[side] = value;
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1171
|
+
if ("cornerSmoothing" in frame.fields)
|
|
1172
|
+
frame.at.cornerSmoothing = next.style?.cornerSmoothing ?? 0;
|
|
1173
|
+
if ("frameMaskDisabled" in frame.fields)
|
|
1174
|
+
frame.at.clipContent = !!next.clipContent;
|
|
1175
|
+
}
|
|
1176
|
+
const changed = base === null || next === null ? undefined : sizingBetween(base, next, frame.fields);
|
|
1023
1177
|
if (changed?.sizing !== undefined)
|
|
1024
|
-
|
|
1025
|
-
if (changed?.sizing !== undefined &&
|
|
1026
|
-
heldSizing.set(
|
|
1178
|
+
frame.at["sizing"] = changed.sizing;
|
|
1179
|
+
if (changed?.sizing !== undefined && frame.holders.length > 0)
|
|
1180
|
+
heldSizing.set(frame.key, { axes: changed.same, holders: frame.holders });
|
|
1027
1181
|
}
|
|
1028
1182
|
const { figma } = target.layer;
|
|
1029
1183
|
const direct = target.through.length === 0;
|
|
1030
1184
|
if (Object.keys(fields).length === 0 && !(direct && readsModes(target.layer)))
|
|
1031
1185
|
continue;
|
|
1032
1186
|
const { variableConsumptionMap: ownMap, ...plain } = fields;
|
|
1187
|
+
if (OPEN_TYPE_TOGGLES.some(name => name in plain))
|
|
1188
|
+
Object.assign(plain, inheritOpenTypeToggles(figma.change, plain));
|
|
1033
1189
|
// A locally authored paint or effect list replaces the main's style reference as well as its list.
|
|
1034
1190
|
if (context.fileOverride)
|
|
1035
1191
|
for (const [ref, list] of STYLE_REFERENCE_FIELDS)
|
|
@@ -1090,7 +1246,55 @@ export function instanceFields(instance, component, self, context) {
|
|
|
1090
1246
|
return found;
|
|
1091
1247
|
};
|
|
1092
1248
|
// 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);
|
|
1249
|
+
const propertyValues = assignedPropertyValues(field(instance.change, "componentPropAssignments", "list", where), component.properties, component.variantDefs, componentIdOf, leftOutValue(component, ""), where, context.report, captureLinks(component, ""));
|
|
1250
|
+
for (const { shown, path, id, text, data } of assignedLinks.values()) {
|
|
1251
|
+
const table = new Map();
|
|
1252
|
+
for (const row of data["styleOverrideTable"]) {
|
|
1253
|
+
if (isObject(row) && typeof row["styleID"] === "number" && row["styleID"] !== 0 && Object.hasOwn(row, "hyperlink"))
|
|
1254
|
+
table.set(row["styleID"], hyperlinkOf(row["hyperlink"], context.report));
|
|
1255
|
+
}
|
|
1256
|
+
const ids = field(data, "characterStyleIDs", "list", where) ?? [];
|
|
1257
|
+
const prefix = path ? parseLayerPath(path) : [];
|
|
1258
|
+
for (const { figma, node } of shown.layers.values()) {
|
|
1259
|
+
if (node.type !== "text")
|
|
1260
|
+
continue;
|
|
1261
|
+
const ref = field(figma.change, "componentPropRefs", "list", where)?.findLast(ref => isObject(ref) && ref["componentPropNodeField"] === "TEXT_DATA" && ref["defID"] !== undefined && ref["isDeleted"] !== true);
|
|
1262
|
+
if (!isObject(ref) || propertyByFigmaId(shown.properties, guidText(ref["defID"], where))?.definition.id !== id)
|
|
1263
|
+
continue;
|
|
1264
|
+
const key = layerPathKey([...prefix, node.id]);
|
|
1265
|
+
const at = overrideAt(key), fields = pending.get(key)?.fields;
|
|
1266
|
+
// A paint override can produce full paragraphs too. Use their formatting for the
|
|
1267
|
+
// assignment unless the occurrence actually overrode its text body or links.
|
|
1268
|
+
if (at["characters"] !== undefined || (at["paragraphs"] !== undefined &&
|
|
1269
|
+
(fields?.["textData"] !== undefined || fields?.["hyperlink"] !== undefined)))
|
|
1270
|
+
continue;
|
|
1271
|
+
const source = at["paragraphs"];
|
|
1272
|
+
let i = 0, applied = false;
|
|
1273
|
+
const paragraphs = paragraphsFromCharacters(text, source ?? node.paragraphs).map(paragraph => {
|
|
1274
|
+
const runs = paragraph.runs.flatMap(run => {
|
|
1275
|
+
if (!run.text)
|
|
1276
|
+
return [run];
|
|
1277
|
+
const { hyperlink: inherited, ...style } = run;
|
|
1278
|
+
const parts = [];
|
|
1279
|
+
for (const char of run.text) {
|
|
1280
|
+
const raw = ids[i++], override = typeof raw === "number" && table.has(raw);
|
|
1281
|
+
const hyperlink = override ? table.get(raw) : inherited;
|
|
1282
|
+
const last = parts.at(-1);
|
|
1283
|
+
if (last && last.hyperlink === hyperlink)
|
|
1284
|
+
last.text += char;
|
|
1285
|
+
else
|
|
1286
|
+
parts.push({ ...style, text: char, ...(hyperlink !== undefined && { hyperlink }) });
|
|
1287
|
+
applied ||= override;
|
|
1288
|
+
}
|
|
1289
|
+
return parts;
|
|
1290
|
+
});
|
|
1291
|
+
++i; // The paragraph break also consumes a Figma character style ID.
|
|
1292
|
+
return { ...paragraph, runs };
|
|
1293
|
+
});
|
|
1294
|
+
if (applied)
|
|
1295
|
+
at["paragraphs"] = paragraphs;
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1094
1298
|
// 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
1299
|
const stretches = (node, axis) => {
|
|
1096
1300
|
const constraint = "constraints" in node ? node.constraints?.[axis === "width" ? "horizontal" : "vertical"] : undefined;
|
|
@@ -1134,7 +1338,7 @@ export function instanceFields(instance, component, self, context) {
|
|
|
1134
1338
|
else if (target === undefined || "flattenedInto" in target || target.layer.figma.type !== "INSTANCE")
|
|
1135
1339
|
inComponent = undefined;
|
|
1136
1340
|
else {
|
|
1137
|
-
inComponent = shownAt(keys, target.layer.figma, target.component);
|
|
1341
|
+
inComponent = shownAt(keys, target.layer.figma, target.component, target.through);
|
|
1138
1342
|
pathIds = parseLayerPath(target.key) ?? [];
|
|
1139
1343
|
const nested = target.layer.node;
|
|
1140
1344
|
values = { ...nested.propertyValues, ...overrides[target.key]?.["propertyValues"] };
|
|
@@ -1172,7 +1376,9 @@ export function instanceFields(instance, component, self, context) {
|
|
|
1172
1376
|
const unconditioned = boundLayers.filter(({ node }) => node.condition === undefined);
|
|
1173
1377
|
const slotLayer = unconditioned.find(effectivelyVisible) ?? unconditioned[0];
|
|
1174
1378
|
if (property === undefined || slotLayer === undefined) {
|
|
1175
|
-
context.report("property-left-out",
|
|
1379
|
+
context.report("property-left-out", keys.length
|
|
1380
|
+
? "a nested slot assignment has no imported slot declaration or bound frame"
|
|
1381
|
+
: "the content placed in a slot names no imported slot of the component; it is left out");
|
|
1176
1382
|
continue;
|
|
1177
1383
|
}
|
|
1178
1384
|
const pathKey = layerPathKey(pathIds);
|
|
@@ -1215,7 +1421,7 @@ export function instanceFields(instance, component, self, context) {
|
|
|
1215
1421
|
const nextStyle = styleOf(next);
|
|
1216
1422
|
for (const name of STYLE_OVERRIDES) {
|
|
1217
1423
|
if (!same(baseStyle[name], nextStyle[name]))
|
|
1218
|
-
at[name] = nextStyle[name] ?? (name === "layerBlur" || name === "backgroundBlur" ? 0 : []);
|
|
1424
|
+
at[name] = nextStyle[name] ?? (name === "layerBlur" || name === "backgroundBlur" || name === "cornerSmoothing" ? 0 : []);
|
|
1219
1425
|
}
|
|
1220
1426
|
if (next.opacity !== boundBase.opacity)
|
|
1221
1427
|
at["opacity"] = next.opacity;
|
|
@@ -1232,7 +1438,7 @@ export function instanceFields(instance, component, self, context) {
|
|
|
1232
1438
|
if (Object.keys(bindings).length > 0)
|
|
1233
1439
|
at["variableBindings"] = { ...at["variableBindings"], ...bindings };
|
|
1234
1440
|
}
|
|
1235
|
-
//
|
|
1441
|
+
// Slot content contributes children to the host, whose own layout arranges them.
|
|
1236
1442
|
const layoutOf = (frame) => {
|
|
1237
1443
|
if (frame.type !== "frame")
|
|
1238
1444
|
return undefined;
|
|
@@ -1244,18 +1450,19 @@ export function instanceFields(instance, component, self, context) {
|
|
|
1244
1450
|
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
1451
|
}
|
|
1246
1452
|
}
|
|
1247
|
-
|
|
1248
|
-
context.report("property-left-out", "an override path that names no imported layer of the component is left out");
|
|
1249
|
-
if (insideLeftOut > 0)
|
|
1453
|
+
for (const _ of insideLeftOut)
|
|
1250
1454
|
context.report("property-left-out", "an override inside a swap that was left out is left out too");
|
|
1251
1455
|
const kept = Object.fromEntries(Object.entries(overrides).filter(([, value]) => Object.keys(value).length > 0));
|
|
1456
|
+
// Some instances store their own rows only on the override of the root.
|
|
1457
|
+
const exportSettings = instance.change["exportSettings"] === undefined ? exportSettingsOf(rootExports, context.report) : undefined;
|
|
1252
1458
|
return {
|
|
1253
1459
|
fields: {
|
|
1460
|
+
...(exportSettings === undefined ? {} : { exportSettings }),
|
|
1254
1461
|
...(Object.keys(kept).length > 0 ? { overrides: kept } : {}),
|
|
1255
1462
|
...(Object.keys(propertyValues).length > 0 ? { propertyValues } : {}),
|
|
1256
1463
|
...(Object.keys(slots).length > 0 ? { slots } : {}),
|
|
1257
1464
|
},
|
|
1258
|
-
swaps: swapsKept,
|
|
1465
|
+
swaps: swapsKept, pathSwaps,
|
|
1259
1466
|
filledSlots,
|
|
1260
1467
|
nested: new Map([...pending.values()].filter(({ target }) => target.through.length > 0).map(({ target }) => [target.key, target.through])),
|
|
1261
1468
|
heldSizing,
|