@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,11 +1,24 @@
|
|
|
1
|
-
import type { SceneNode } from "../../model/index.ts";
|
|
1
|
+
import type { SceneNode, TransformMatrix } from "../../model/index.ts";
|
|
2
|
+
export interface FigmaImageCrop {
|
|
3
|
+
readonly matrix: TransformMatrix;
|
|
4
|
+
readonly aspect?: number;
|
|
5
|
+
}
|
|
2
6
|
/** Marks a Taco shadow as one Figma shows behind its node. */
|
|
3
7
|
export declare function markShadowBehind(shadow: object): void;
|
|
4
8
|
/** Marks a Taco image paint as one Figma tiles at `scale`. */
|
|
5
9
|
export declare function markTile(paint: object, scale: number): void;
|
|
10
|
+
/** Carries a Figma matrix from layer UVs to image UVs to the adapter. */
|
|
11
|
+
export declare function markImageCrop(paint: object, crop: FigmaImageCrop): void;
|
|
12
|
+
export declare function imageCropOf(paint: unknown): FigmaImageCrop | undefined;
|
|
13
|
+
/** Reads tiling directly from a region paint, which has no layer metadata index. */
|
|
14
|
+
export declare function imageTileOf(paint: object): number | undefined;
|
|
15
|
+
/** Includes the crop when comparing paints for instance and variant overrides. */
|
|
16
|
+
export declare function withImageCrop(_key: string, value: unknown): unknown;
|
|
6
17
|
/** Moves a mark to a copy of the marked object. */
|
|
7
18
|
export declare function moveMark(from: object, to: object): void;
|
|
8
19
|
/** Adds `data` to the layer's `metadata.figma`. */
|
|
9
20
|
export declare function carry(node: SceneNode, data: NonNullable<SceneNode["metadata"]>): void;
|
|
21
|
+
/** Clears a layer's constraints where Figma does not apply them. */
|
|
22
|
+
export declare function clearConstraints(node: SceneNode): void;
|
|
10
23
|
/** Carries the marks on a converted layer's shadows and fills into its metadata. */
|
|
11
24
|
export declare function carryMarks(node: SceneNode): void;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isObject } from "./fields.js";
|
|
1
2
|
const marks = new WeakMap();
|
|
2
3
|
/** Marks a Taco shadow as one Figma shows behind its node. */
|
|
3
4
|
export function markShadowBehind(shadow) {
|
|
@@ -7,6 +8,22 @@ export function markShadowBehind(shadow) {
|
|
|
7
8
|
export function markTile(paint, scale) {
|
|
8
9
|
marks.set(paint, { tile: scale });
|
|
9
10
|
}
|
|
11
|
+
/** Carries a Figma matrix from layer UVs to image UVs to the adapter. */
|
|
12
|
+
export function markImageCrop(paint, crop) {
|
|
13
|
+
marks.set(paint, { crop });
|
|
14
|
+
}
|
|
15
|
+
export function imageCropOf(paint) {
|
|
16
|
+
return paint !== null && typeof paint === "object" ? marks.get(paint)?.crop : undefined;
|
|
17
|
+
}
|
|
18
|
+
/** Reads tiling directly from a region paint, which has no layer metadata index. */
|
|
19
|
+
export function imageTileOf(paint) {
|
|
20
|
+
return marks.get(paint)?.tile;
|
|
21
|
+
}
|
|
22
|
+
/** Includes the crop when comparing paints for instance and variant overrides. */
|
|
23
|
+
export function withImageCrop(_key, value) {
|
|
24
|
+
const crop = imageCropOf(value);
|
|
25
|
+
return crop ? { ...value, crop } : value;
|
|
26
|
+
}
|
|
10
27
|
/** Moves a mark to a copy of the marked object. */
|
|
11
28
|
export function moveMark(from, to) {
|
|
12
29
|
const mark = marks.get(from);
|
|
@@ -19,12 +36,28 @@ export function carry(node, data) {
|
|
|
19
36
|
const had = typeof figma === "object" && figma !== null && !Array.isArray(figma) ? figma : {};
|
|
20
37
|
Object.assign(node, { metadata: { ...metadata, figma: { ...had, ...data } } });
|
|
21
38
|
}
|
|
39
|
+
/** Clears a layer's constraints where Figma does not apply them. */
|
|
40
|
+
export function clearConstraints(node) {
|
|
41
|
+
if ("constraints" in node)
|
|
42
|
+
delete node.constraints;
|
|
43
|
+
if (node.type !== "group" || node.metadata === undefined)
|
|
44
|
+
return;
|
|
45
|
+
const { figma, ...rest } = node.metadata;
|
|
46
|
+
if (!isObject(figma) || !Object.hasOwn(figma, "groupConstraints"))
|
|
47
|
+
return;
|
|
48
|
+
const { groupConstraints: _constraints, ...remaining } = figma;
|
|
49
|
+
const metadata = Object.keys(remaining).length > 0 ? { ...rest, figma: remaining } : rest;
|
|
50
|
+
if (Object.keys(metadata).length > 0)
|
|
51
|
+
Object.assign(node, { metadata });
|
|
52
|
+
else
|
|
53
|
+
delete node.metadata;
|
|
54
|
+
}
|
|
22
55
|
/** Carries the marks on a converted layer's shadows and fills into its metadata. */
|
|
23
56
|
export function carryMarks(node) {
|
|
24
57
|
const style = node.style;
|
|
25
58
|
const behind = (style?.shadows ?? []).flatMap((shadow, index) => marks.get(shadow)?.behind === true ? [index] : []);
|
|
26
59
|
const tiles = (style?.fills ?? []).flatMap((paint, index) => {
|
|
27
|
-
const scale =
|
|
60
|
+
const scale = imageTileOf(paint);
|
|
28
61
|
return scale === undefined ? [] : [[index, scale]];
|
|
29
62
|
});
|
|
30
63
|
if (behind.length === 0 && tiles.length === 0)
|
|
@@ -30,11 +30,16 @@ export declare function propertyNameOf(name: string, taken: ReadonlySet<string>)
|
|
|
30
30
|
* with its `preferredValues` mapped the same way and its `slotPropConfig`
|
|
31
31
|
* settings (`slotSettingsOf`); its default content is the
|
|
32
32
|
* frames bound to it. VARIANT defs are not properties here: each variant
|
|
33
|
-
* imports as its own component.
|
|
33
|
+
* imports as its own component. A deleted def (one with neither a type nor a
|
|
34
|
+
* name, as Figma keeps it after the property is removed) is skipped without a
|
|
35
|
+
* report. Other types are reported, and so is a name
|
|
34
36
|
* changed to be unique or
|
|
35
|
-
* to drop characters no name can hold (`propertyNameOf`).
|
|
37
|
+
* to drop characters no name can hold (`propertyNameOf`). Each dropped
|
|
38
|
+
* preferred value is reported once, not once per variant that reads the def:
|
|
39
|
+
* `reported` holds the defs already reported, so share one set across the
|
|
40
|
+
* symbols of an import.
|
|
36
41
|
*/
|
|
37
|
-
export declare function propertiesOf(symbol: FigmaTreeNode, nodes: ReadonlyMap<string, FigmaTreeNode>, componentOf: (symbolId: string) => ComponentId | undefined, componentsByKey: ComponentsByKey, report: PropertyReport): ImportedProperty[];
|
|
42
|
+
export declare function propertiesOf(symbol: FigmaTreeNode, nodes: ReadonlyMap<string, FigmaTreeNode>, componentOf: (symbolId: string) => ComponentId | undefined, componentsByKey: ComponentsByKey, report: PropertyReport, reported?: WeakSet<FigmaObject>): ImportedProperty[];
|
|
38
43
|
/** The Taco components a Figma component key names: a COMPONENT key its SYMBOL, a STATE_GROUP key its set's variants. */
|
|
39
44
|
export type ComponentsByKey = (type: "COMPONENT" | "STATE_GROUP", key: string) => readonly ComponentId[];
|
|
40
45
|
/**
|
|
@@ -63,6 +68,7 @@ export declare function variantDefIds(symbol: FigmaTreeNode, nodes: ReadonlyMap<
|
|
|
63
68
|
export interface AssignedValue {
|
|
64
69
|
readonly bool?: boolean;
|
|
65
70
|
readonly text?: string;
|
|
71
|
+
readonly textData?: FigmaObject;
|
|
66
72
|
/** The SYMBOL an instance swap value names. */
|
|
67
73
|
readonly symbolId?: string;
|
|
68
74
|
}
|
|
@@ -81,4 +87,4 @@ export declare function assignedValueOf(assignment: FigmaObject, at: string): As
|
|
|
81
87
|
* in the message, or a swap `leftOutSwap` gives a reason to leave out (it
|
|
82
88
|
* would nest a component in itself), is reported and left out.
|
|
83
89
|
*/
|
|
84
|
-
export declare function assignedPropertyValues(list: readonly unknown[] | undefined, properties: readonly ImportedProperty[], variantDefs: ReadonlySet<string>, componentOf: (symbolId: string) => ComponentId | undefined, leftOutSwap: (symbolId: string, property: ComponentPropertyId) => string | undefined, where: string, report: PropertyReport): Record<string, ComponentPropertyValue>;
|
|
90
|
+
export declare function assignedPropertyValues(list: readonly unknown[] | undefined, properties: readonly ImportedProperty[], variantDefs: ReadonlySet<string>, componentOf: (symbolId: string) => ComponentId | undefined, leftOutSwap: (symbolId: string, property: ComponentPropertyId) => string | undefined, where: string, report: PropertyReport, textAssignment?: (id: ComponentPropertyId, data: FigmaObject, characters: string) => void): Record<string, ComponentPropertyValue>;
|
|
@@ -50,11 +50,16 @@ function setDefsOf(symbol, nodes) {
|
|
|
50
50
|
* with its `preferredValues` mapped the same way and its `slotPropConfig`
|
|
51
51
|
* settings (`slotSettingsOf`); its default content is the
|
|
52
52
|
* frames bound to it. VARIANT defs are not properties here: each variant
|
|
53
|
-
* imports as its own component.
|
|
53
|
+
* imports as its own component. A deleted def (one with neither a type nor a
|
|
54
|
+
* name, as Figma keeps it after the property is removed) is skipped without a
|
|
55
|
+
* report. Other types are reported, and so is a name
|
|
54
56
|
* changed to be unique or
|
|
55
|
-
* to drop characters no name can hold (`propertyNameOf`).
|
|
57
|
+
* to drop characters no name can hold (`propertyNameOf`). Each dropped
|
|
58
|
+
* preferred value is reported once, not once per variant that reads the def:
|
|
59
|
+
* `reported` holds the defs already reported, so share one set across the
|
|
60
|
+
* symbols of an import.
|
|
56
61
|
*/
|
|
57
|
-
export function propertiesOf(symbol, nodes, componentOf, componentsByKey, report) {
|
|
62
|
+
export function propertiesOf(symbol, nodes, componentOf, componentsByKey, report, reported = new WeakSet()) {
|
|
58
63
|
const setDefs = setDefsOf(symbol, nodes);
|
|
59
64
|
const where = `node ${symbol.id} componentPropDefs`;
|
|
60
65
|
const names = new Set();
|
|
@@ -62,9 +67,11 @@ export function propertiesOf(symbol, nodes, componentOf, componentsByKey, report
|
|
|
62
67
|
const properties = [];
|
|
63
68
|
for (const [ownId, own] of defsById(symbol)) {
|
|
64
69
|
const parentId = own["parentPropDefId"] === undefined ? undefined : guidText(own["parentPropDefId"], where);
|
|
70
|
+
// The def whose preferred values this reading takes: the variant's own when it has some, else the set's.
|
|
71
|
+
const source = own["preferredValues"] !== undefined ? own : (parentId === undefined ? undefined : setDefs.get(parentId)) ?? own;
|
|
65
72
|
const def = { ...(parentId === undefined ? {} : setDefs.get(parentId)), ...own };
|
|
66
73
|
const type = field(def, "type", "string", where);
|
|
67
|
-
if (type === "VARIANT")
|
|
74
|
+
if (type === "VARIANT" || (type === undefined && def["name"] === undefined))
|
|
68
75
|
continue;
|
|
69
76
|
const figmaName = field(def, "name", "string", where) ?? "";
|
|
70
77
|
const initial = field(def, "initialValue", "object", where) ?? {};
|
|
@@ -86,12 +93,12 @@ export function propertiesOf(symbol, nodes, componentOf, componentsByKey, report
|
|
|
86
93
|
report("property-left-out", "an instance swap property is left out: its default component is not in the message");
|
|
87
94
|
continue;
|
|
88
95
|
}
|
|
89
|
-
const preferred = preferredOf(def, componentsByKey, where, report);
|
|
96
|
+
const preferred = preferredOf(def, componentsByKey, where, onceFor(source, reported, report));
|
|
90
97
|
definition = { ...base, kind: "instance", defaultValue: component, ...(preferred.length === 0 ? {} : { preferred }) };
|
|
91
98
|
}
|
|
92
99
|
else if (type === "SLOT") {
|
|
93
100
|
// The default content is the bound frames' own children, so a slot has no default value.
|
|
94
|
-
const preferred = preferredOf(def, componentsByKey, where, report, "a slot");
|
|
101
|
+
const preferred = preferredOf(def, componentsByKey, where, onceFor(source, reported, report), "a slot");
|
|
95
102
|
definition = { ...base, kind: "slot", ...(preferred.length === 0 ? {} : { preferred }), ...slotSettingsOf(def, where, report) };
|
|
96
103
|
}
|
|
97
104
|
else {
|
|
@@ -169,11 +176,16 @@ export function componentsByKeyOf(nodes, componentOf) {
|
|
|
169
176
|
return members.flatMap((member) => componentOf(member.id) ?? []);
|
|
170
177
|
};
|
|
171
178
|
}
|
|
179
|
+
/** `report` for the first reading of `def` that reports anything, and a report that drops everything for later ones. */
|
|
180
|
+
function onceFor(def, reported, report) {
|
|
181
|
+
if (reported.has(def))
|
|
182
|
+
return () => undefined;
|
|
183
|
+
return (kind, reason) => { reported.add(def); report(kind, reason); };
|
|
184
|
+
}
|
|
172
185
|
/**
|
|
173
186
|
* The components an INSTANCE_SWAP or SLOT def's `preferredValues.instanceSwapValues`
|
|
174
187
|
* name, in order and each once (`what` names the property in the report). A key of a component the import does not
|
|
175
|
-
* hold, or of another type, is dropped and reported
|
|
176
|
-
* reads the def, so a set's def counts once per variant.
|
|
188
|
+
* hold, or of another type, is dropped and reported (`propertiesOf` reports them for one reading of the def only).
|
|
177
189
|
*/
|
|
178
190
|
function preferredOf(def, componentsByKey, where, report, what = "an instance swap") {
|
|
179
191
|
const values = field(def, "preferredValues", "object", where);
|
|
@@ -259,13 +271,15 @@ export function assignedValueOf(assignment, at) {
|
|
|
259
271
|
const varValue = field(assignment, "varValue", "object", at);
|
|
260
272
|
const varAt = `${at}.varValue.value`;
|
|
261
273
|
const held = (varValue === undefined ? undefined : field(varValue, "value", "object", `${at}.varValue`)) ?? {};
|
|
262
|
-
const textOf = (object, where) => (object === undefined ? undefined : field(object, "characters", "string", where));
|
|
263
274
|
const bool = field(value, "boolValue", "boolean", at) ?? field(held, "boolValue", "boolean", varAt);
|
|
264
|
-
const
|
|
275
|
+
const plain = field(value, "textValue", "object", at);
|
|
276
|
+
const legacyText = plain && field(plain, "characters", "string", at);
|
|
277
|
+
const textData = legacyText === undefined ? field(held, "textDataValue", "object", varAt) : plain;
|
|
278
|
+
const text = legacyText ?? (textData && field(textData, "characters", "string", varAt));
|
|
265
279
|
const swap = field(held, "symbolIdValue", "object", varAt);
|
|
266
280
|
const symbolId = value["guidValue"] !== undefined ? guidText(value["guidValue"], at)
|
|
267
281
|
: swap?.["guid"] !== undefined ? guidText(swap["guid"], `${varAt}.symbolIdValue`) : undefined;
|
|
268
|
-
return { ...(bool === undefined ? {} : { bool }), ...(text === undefined ? {} : { text }), ...(symbolId === undefined ? {} : { symbolId }) };
|
|
282
|
+
return { ...(bool === undefined ? {} : { bool }), ...(text === undefined ? {} : { text, textData: textData }), ...(symbolId === undefined ? {} : { symbolId }) };
|
|
269
283
|
}
|
|
270
284
|
/**
|
|
271
285
|
* `componentPropAssignments` as Taco values of `properties`. A VARIANT value
|
|
@@ -275,7 +289,7 @@ export function assignedValueOf(assignment, at) {
|
|
|
275
289
|
* in the message, or a swap `leftOutSwap` gives a reason to leave out (it
|
|
276
290
|
* would nest a component in itself), is reported and left out.
|
|
277
291
|
*/
|
|
278
|
-
export function assignedPropertyValues(list, properties, variantDefs, componentOf, leftOutSwap, where, report) {
|
|
292
|
+
export function assignedPropertyValues(list, properties, variantDefs, componentOf, leftOutSwap, where, report, textAssignment) {
|
|
279
293
|
const values = {};
|
|
280
294
|
(list ?? []).forEach((assignment, index) => {
|
|
281
295
|
const at = `${where} componentPropAssignments[${String(index)}]`;
|
|
@@ -294,8 +308,10 @@ export function assignedPropertyValues(list, properties, variantDefs, componentO
|
|
|
294
308
|
const value = assignedValueOf(assignment, at);
|
|
295
309
|
if (definition.kind === "boolean" && value.bool !== undefined)
|
|
296
310
|
values[definition.id] = value.bool;
|
|
297
|
-
else if (definition.kind === "text" && value.text !== undefined)
|
|
311
|
+
else if (definition.kind === "text" && value.text !== undefined) {
|
|
298
312
|
values[definition.id] = value.text;
|
|
313
|
+
textAssignment?.(definition.id, value.textData, value.text);
|
|
314
|
+
}
|
|
299
315
|
else if (definition.kind === "instance" && value.symbolId !== undefined) {
|
|
300
316
|
const component = componentOf(value.symbolId);
|
|
301
317
|
const leftOut = component === undefined ? undefined : leftOutSwap(value.symbolId, definition.id);
|
|
@@ -18,6 +18,8 @@ export interface ComponentSetInput {
|
|
|
18
18
|
/** Every imported SYMBOL's component, in import order. */
|
|
19
19
|
readonly variants: readonly ImportedVariant[];
|
|
20
20
|
readonly figmaNodes: ReadonlyMap<string, FigmaTreeNode>;
|
|
21
|
+
/** Layers that carry source-specific metadata and must keep their identity across variants. */
|
|
22
|
+
readonly distinctLayers?: ReadonlySet<NodeId>;
|
|
21
23
|
readonly newId: () => NodeId;
|
|
22
24
|
/** The key of the set's component, from the set node. */
|
|
23
25
|
readonly keyOf: (set: FigmaTreeNode) => string;
|
|
@@ -642,6 +642,6 @@ export function mergeComponentSets(input) {
|
|
|
642
642
|
roots: plan.variants.map((variant) => variant.root.id), values: plan.values, properties: plan.properties,
|
|
643
643
|
presence: (indices) => factored(plan.properties, indices.map((at) => plan.properties.map((property) => plan.values[at][property.id]))) || "true",
|
|
644
644
|
split: (node, count, fields) => input.report(plan.set, "approximated", `split layer ${node} into ${String(count)} groups: ${fields.join(", ")}`),
|
|
645
|
-
})), input.theme);
|
|
645
|
+
})), input.theme, input.distinctLayers);
|
|
646
646
|
return { nodes: trees.nodes, components, componentOf, layerOf: trees.layerOf };
|
|
647
647
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ExportSetting } from "../../../model/types.ts";
|
|
2
|
+
import type { NodeWalk } from "../walk.ts";
|
|
3
|
+
/** Reads the export rows stored by a layer or by an instance's root override. */
|
|
4
|
+
export declare function exportSettingsOf(value: unknown, report: NodeWalk["report"]): ExportSetting[] | undefined;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { defaultExportQuality, exportConstraintProblem, exportSuffixProblem, MAX_EXPORT_SETTINGS } from "../../../model/export-settings.js";
|
|
2
|
+
import { isObject } from "../fields.js";
|
|
3
|
+
/** Reads the export rows stored by a layer or by an instance's root override. */
|
|
4
|
+
export function exportSettingsOf(value, report) {
|
|
5
|
+
if (value === undefined)
|
|
6
|
+
return undefined;
|
|
7
|
+
if (!Array.isArray(value)) {
|
|
8
|
+
report("property-left-out", "the export settings are not a list");
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
const settings = [];
|
|
12
|
+
for (const row of value) {
|
|
13
|
+
if (!isObject(row)) {
|
|
14
|
+
report("property-left-out", "an invalid export setting is left out");
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
const format = typeof row["imageType"] === "string" ? row["imageType"].toLowerCase() : undefined;
|
|
18
|
+
if (format !== "png" && format !== "jpeg" && format !== "svg" && format !== "pdf") {
|
|
19
|
+
report("property-left-out", `an export setting with format ${String(format)} is left out`);
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
const size = row["constraint"];
|
|
23
|
+
const type = isObject(size) ? size["type"] : undefined;
|
|
24
|
+
const unit = type === "CONTENT_WIDTH" ? "width" : type === "CONTENT_HEIGHT" ? "height"
|
|
25
|
+
: type === "CONTENT_SCALE" || size === undefined ? "scale" : undefined;
|
|
26
|
+
const amount = size === undefined ? 1 : isObject(size) ? size["value"] : undefined;
|
|
27
|
+
if (unit === undefined || typeof amount !== "number" || exportConstraintProblem({ type: unit, value: amount }) !== null) {
|
|
28
|
+
report("property-left-out", "an export setting with an invalid size is left out");
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
const suffix = row["suffix"] ?? "";
|
|
32
|
+
if (typeof suffix !== "string" || exportSuffixProblem(suffix) !== null) {
|
|
33
|
+
report("property-left-out", "an export setting with an invalid suffix is left out");
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
if (settings.length === MAX_EXPORT_SETTINGS) {
|
|
37
|
+
report("property-left-out", "an export setting beyond the reader's list limit is left out");
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
settings.push({
|
|
41
|
+
format, constraint: { type: unit, value: amount }, suffix,
|
|
42
|
+
quality: defaultExportQuality(format),
|
|
43
|
+
resampling: "detailed",
|
|
44
|
+
ignoreOverlappingLayers: row["contentsOnly"] !== false,
|
|
45
|
+
includeIdAttribute: row["svgIDMode"] === "ALWAYS",
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return settings.length === 0 ? undefined : settings;
|
|
49
|
+
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { carry } from "../carry.js";
|
|
1
2
|
import { field } from "../fields.js";
|
|
3
|
+
import { gridStyleReference } from "../styles.js";
|
|
2
4
|
import { drawnAsPlainRectangle, nodeEffects } from "./effects.js";
|
|
3
5
|
import { stackLayoutOf } from "./layout.js";
|
|
4
6
|
import { convertGroup } from "./group.js";
|
|
@@ -35,6 +37,9 @@ export const convertFrame = (node, walk) => {
|
|
|
35
37
|
clipContent: node.change["frameMaskDisabled"] !== true,
|
|
36
38
|
...(Object.keys(style).length > 0 ? { style } : {}),
|
|
37
39
|
};
|
|
40
|
+
if ((frame.layout.kind === "horizontal" || frame.layout.kind === "vertical") && node.change["bordersTakeSpace"] === true) {
|
|
41
|
+
carry(frame, { strokesIncluded: true });
|
|
42
|
+
}
|
|
38
43
|
return frame;
|
|
39
44
|
};
|
|
40
45
|
/**
|
|
@@ -45,6 +50,9 @@ export const convertFrame = (node, walk) => {
|
|
|
45
50
|
export function isFigmaGroup(change) {
|
|
46
51
|
if (change["resizeToFit"] !== true || change["frameMaskDisabled"] !== false)
|
|
47
52
|
return false;
|
|
53
|
+
const grids = change["layoutGrids"];
|
|
54
|
+
if ((Array.isArray(grids) && grids.length > 0) || gridStyleReference(change) !== undefined)
|
|
55
|
+
return false;
|
|
48
56
|
const stackMode = change["stackMode"];
|
|
49
57
|
if (stackMode !== undefined && stackMode !== "NONE")
|
|
50
58
|
return false;
|
|
@@ -52,6 +52,8 @@ export interface Box {
|
|
|
52
52
|
readonly width: number;
|
|
53
53
|
readonly height: number;
|
|
54
54
|
}
|
|
55
|
+
/** A vector computes its paint bounds on the first gradient that needs them. */
|
|
56
|
+
export type PaintBounds = Box | (() => Box | undefined);
|
|
55
57
|
/**
|
|
56
58
|
* The paint transform `m` of a `width` by `height` node re-expressed on
|
|
57
59
|
* `box`'s unit box, so the gradient stays where it is in node pixels when it
|
|
@@ -44,7 +44,9 @@ function clipStops(stops) {
|
|
|
44
44
|
const out = [];
|
|
45
45
|
if (stops[0].position < 0)
|
|
46
46
|
out.push({ position: 0, color: sample(stops, 0) });
|
|
47
|
-
|
|
47
|
+
for (const stop of stops)
|
|
48
|
+
if (stop.position >= 0 && stop.position <= 1)
|
|
49
|
+
out.push(stop);
|
|
48
50
|
if (stops[stops.length - 1].position > 1)
|
|
49
51
|
out.push({ position: 1, color: sample(stops, 1) });
|
|
50
52
|
return out.length === 1 ? [{ position: 0, color: out[0].color }, { position: 1, color: out[0].color }] : out;
|
|
@@ -13,9 +13,7 @@ import type { FigmaNodeConverter } from "../walk.ts";
|
|
|
13
13
|
* `clipsContent: false`) and fig2sketch (src/converter/group.py:12 builds a
|
|
14
14
|
* plain Sketch group).
|
|
15
15
|
*
|
|
16
|
-
* A Taco group
|
|
17
|
-
*
|
|
18
|
-
* on its layers, so each layer imports its own and the group's are left out;
|
|
19
|
-
* the report says so when they differ from a layer's.
|
|
16
|
+
* A Taco group follows its layers' constraints (see `NodeBase.constraints`).
|
|
17
|
+
* The adapter reads the group's own constraints from its Figma metadata.
|
|
20
18
|
*/
|
|
21
19
|
export declare const convertGroup: FigmaNodeConverter;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { carry } from "../carry.js";
|
|
2
|
+
import { framedBase } from "./shared.js";
|
|
2
3
|
/**
|
|
3
4
|
* A Figma group (a FRAME that `convertFrame` finds to be a group) as a Taco
|
|
4
5
|
* group. Figma stores each child's transform in the group's own space, with
|
|
@@ -13,10 +14,8 @@ import { constraintsOf, framedBase } from "./shared.js";
|
|
|
13
14
|
* `clipsContent: false`) and fig2sketch (src/converter/group.py:12 builds a
|
|
14
15
|
* plain Sketch group).
|
|
15
16
|
*
|
|
16
|
-
* A Taco group
|
|
17
|
-
*
|
|
18
|
-
* on its layers, so each layer imports its own and the group's are left out;
|
|
19
|
-
* the report says so when they differ from a layer's.
|
|
17
|
+
* A Taco group follows its layers' constraints (see `NodeBase.constraints`).
|
|
18
|
+
* The adapter reads the group's own constraints from its Figma metadata.
|
|
20
19
|
*/
|
|
21
20
|
export const convertGroup = (node, walk) => {
|
|
22
21
|
const base = framedBase(node, walk, "Group");
|
|
@@ -24,16 +23,8 @@ export const convertGroup = (node, walk) => {
|
|
|
24
23
|
return null;
|
|
25
24
|
// `framedBase` sets no variable bindings; a group's type allows no width or height binding.
|
|
26
25
|
const { variableBindings: _none, constraints, ...fields } = base;
|
|
27
|
-
if (constraints !== undefined) {
|
|
28
|
-
const own = `${String(node.change["horizontalConstraint"] ?? "MIN")}/${String(node.change["verticalConstraint"] ?? "MIN")}`;
|
|
29
|
-
const ignore = () => undefined;
|
|
30
|
-
const differs = node.children.some((child) => {
|
|
31
|
-
const layer = constraintsOf(child.change, ignore);
|
|
32
|
-
return layer?.horizontal !== constraints.horizontal || layer.vertical !== constraints.vertical;
|
|
33
|
-
});
|
|
34
|
-
if (differs)
|
|
35
|
-
walk.report("property-left-out", `the group's constraints ${own} are left out: a Taco group follows its layers' constraints, and its layers have their own`);
|
|
36
|
-
}
|
|
37
26
|
const group = { ...fields, type: "group", children: walk.convertChildren() };
|
|
27
|
+
if (constraints !== undefined)
|
|
28
|
+
carry(group, { groupConstraints: { ...constraints } });
|
|
38
29
|
return group;
|
|
39
30
|
};
|
|
@@ -10,4 +10,4 @@ export declare function hexText(bytes: Uint8Array): string;
|
|
|
10
10
|
* is left out for a reason already reported for the same image. Rotation
|
|
11
11
|
* and image adjustments (`paintFilter`, `filterColorAdjust`) are reported, not kept.
|
|
12
12
|
*/
|
|
13
|
-
export declare function imagePaint(paint: FigmaObject, at: string, label: string, walk: NodeWalk): Paint | string | null;
|
|
13
|
+
export declare function imagePaint(paint: FigmaObject, at: string, label: string, walk: NodeWalk, fill: boolean): Paint | string | null;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { intrinsicSize } from "../../../svg-import/structure/image.js";
|
|
1
2
|
import { field } from "../fields.js";
|
|
2
|
-
import { markTile } from "../carry.js";
|
|
3
|
+
import { markImageCrop, markTile } from "../carry.js";
|
|
3
4
|
/** The MIME type of PNG, JPEG, GIF and WebP bytes, read from their first bytes; `undefined` for anything else. */
|
|
4
5
|
export function sniffImageMimeType(bytes) {
|
|
5
6
|
const starts = (offset, text) => bytes.length >= offset + text.length && [...text].every((char, i) => bytes[offset + i] === char.charCodeAt(0));
|
|
@@ -18,10 +19,8 @@ export function hexText(bytes) {
|
|
|
18
19
|
}
|
|
19
20
|
/**
|
|
20
21
|
* Figma's `imageScaleMode` as a Taco fit. Kiwi leaves out an enum field at its
|
|
21
|
-
* first value, so an absent mode is STRETCH (Figma's "Crop")
|
|
22
|
-
*
|
|
23
|
-
* fig2sketch reads it (src/converter/style.py, `convert_image_paint`),
|
|
24
|
-
* FILL is cover, FIT is contain and STRETCH a stretch; Taco has no tiling.
|
|
22
|
+
* first value, so an absent mode is STRETCH (Figma's "Crop"). The crop
|
|
23
|
+
* matrix maps layer UVs to image UVs and is carried for the adapter.
|
|
25
24
|
*/
|
|
26
25
|
function imageFit(paint, at) {
|
|
27
26
|
const mode = field(paint, "imageScaleMode", "string", at) ?? "STRETCH";
|
|
@@ -31,9 +30,13 @@ function imageFit(paint, at) {
|
|
|
31
30
|
return { fit: "contain" };
|
|
32
31
|
if (mode === "STRETCH") {
|
|
33
32
|
const m = field(paint, "transform", "object", at);
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
if (m === undefined)
|
|
34
|
+
return { fit: "fill" };
|
|
35
|
+
const crop = [m["m00"] ?? 1, m["m10"] ?? 0, m["m01"] ?? 0, m["m11"] ?? 1, m["m02"] ?? 0, m["m12"] ?? 0];
|
|
36
|
+
if (!crop.every(Number.isFinite))
|
|
37
|
+
return { fit: "fill", approximated: "the image crop matrix is invalid" };
|
|
38
|
+
const identity = [1, 0, 0, 1, 0, 0];
|
|
39
|
+
return crop.some((entry, i) => entry !== identity[i]) ? { fit: "fill", crop: crop } : { fit: "fill" };
|
|
37
40
|
}
|
|
38
41
|
if (mode === "TILE") {
|
|
39
42
|
const scale = field(paint, "scale", "number", at) ?? 1;
|
|
@@ -48,7 +51,7 @@ function imageFit(paint, at) {
|
|
|
48
51
|
* is left out for a reason already reported for the same image. Rotation
|
|
49
52
|
* and image adjustments (`paintFilter`, `filterColorAdjust`) are reported, not kept.
|
|
50
53
|
*/
|
|
51
|
-
export function imagePaint(paint, at, label, walk) {
|
|
54
|
+
export function imagePaint(paint, at, label, walk, fill) {
|
|
52
55
|
const image = field(paint, "image", "object", at);
|
|
53
56
|
const hash = image?.["hash"];
|
|
54
57
|
if (!(hash instanceof Uint8Array) || hash.length === 0)
|
|
@@ -58,7 +61,7 @@ export function imagePaint(paint, at, label, walk) {
|
|
|
58
61
|
const asset = walk.image(hexText(hash), width !== undefined && height !== undefined ? { width, height } : undefined);
|
|
59
62
|
if (asset === null || typeof asset === "string")
|
|
60
63
|
return asset;
|
|
61
|
-
const { fit, approximated, tile } = imageFit(paint, at);
|
|
64
|
+
const { fit, approximated, tile, crop } = imageFit(paint, at);
|
|
62
65
|
if (approximated)
|
|
63
66
|
walk.report("approximated", `${label}: ${approximated}`);
|
|
64
67
|
const rotation = field(paint, "rotation", "number", at) ?? 0;
|
|
@@ -76,8 +79,16 @@ export function imagePaint(paint, at, label, walk) {
|
|
|
76
79
|
}
|
|
77
80
|
if (adjusted.size > 0)
|
|
78
81
|
walk.report("approximated", `${label}: the image adjustments (${[...adjusted].join(", ")}) are not kept`);
|
|
79
|
-
const imaged = { kind: "image", assetId: asset.
|
|
82
|
+
const imaged = { kind: "image", assetId: asset.id, ...(fit !== "cover" ? { fit } : {}) };
|
|
80
83
|
if (tile !== undefined)
|
|
81
84
|
markTile(imaged, tile);
|
|
85
|
+
if (crop && fill) {
|
|
86
|
+
const size = intrinsicSize(asset.mimeType, asset.bytes);
|
|
87
|
+
const w = size?.width || width || asset.width, h = size?.height || height || asset.height;
|
|
88
|
+
const aspect = w && h && w > 0 && h > 0 ? w / h : undefined;
|
|
89
|
+
markImageCrop(imaged, { matrix: crop, ...(aspect && { aspect }) });
|
|
90
|
+
}
|
|
91
|
+
else if (crop)
|
|
92
|
+
walk.report("approximated", `${label}: the image crop is not kept; the whole image is stretched to the box`);
|
|
82
93
|
return imaged;
|
|
83
94
|
}
|
|
@@ -19,9 +19,8 @@ export declare function sizeLimitsOf(change: FigmaObject): NodeResizing;
|
|
|
19
19
|
* the cross axis. Taco has no grow weights, so any grow above 0 fills. A
|
|
20
20
|
* flow child loses its constraints, taken off `node` itself, as they apply
|
|
21
21
|
* only to absolute children.
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* line fills only its width, as its height is always 0.
|
|
22
|
+
* Upright, unlocked groups and paths in a non-wrapping stack carry Fill in
|
|
23
|
+
* metadata for the adapter. A line fills only its width, as its height is always 0.
|
|
25
24
|
*
|
|
26
25
|
* Figma keeps one sizing per axis, and Fill wins over the child's own Hug: a
|
|
27
26
|
* frame that hugs an axis, or text that sizes it to its content, shows the
|
|
@@ -30,5 +29,5 @@ export declare function sizeLimitsOf(change: FigmaObject): NodeResizing;
|
|
|
30
29
|
* sizes to its content, so such a child gets the fill and a fixed size on that
|
|
31
30
|
* axis instead, and the report says so.
|
|
32
31
|
*/
|
|
33
|
-
export declare function stackChildFields(change: FigmaObject, vertical: boolean, node: SceneNode, report: Report
|
|
32
|
+
export declare function stackChildFields(change: FigmaObject, vertical: boolean, wraps: boolean, node: SceneNode, report: Report): Pick<FramedNodeBase, "layoutPositioning" | "resizing"> & Partial<Pick<TextNode, "autoResize" | "wrap"> & Pick<FrameNode, "layout">>;
|
|
34
33
|
export {};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { getVectorNetworkBounds } from "../../../model/index.js";
|
|
2
|
+
import { carry, clearConstraints } from "../carry.js";
|
|
1
3
|
import { isObject } from "../fields.js";
|
|
2
4
|
/**
|
|
3
5
|
* A finite number field, or `undefined`. Figma writes NaN in some stack
|
|
@@ -50,10 +52,6 @@ export function stackLayoutOf(change, report) {
|
|
|
50
52
|
report("approximated", `stackCounterAlignItems ${String(change["stackCounterAlignItems"])} is imported as start`);
|
|
51
53
|
const primary = enumField(change, "stackPrimarySizing", SIZING) ?? "hug";
|
|
52
54
|
const counter = enumField(change, "stackCounterSizing", SIZING) ?? "fixed";
|
|
53
|
-
if (change["stackReverseZIndex"] === true)
|
|
54
|
-
report("property-left-out", "stackReverseZIndex (first child on top) is not imported; later children stay on top");
|
|
55
|
-
if (change["bordersTakeSpace"] === true)
|
|
56
|
-
report("property-left-out", "strokes taking space in the auto layout (bordersTakeSpace) are not imported");
|
|
57
55
|
// Figma's file omits a padding field that is 0, on every side: a missing
|
|
58
56
|
// `stackPaddingRight` or `stackPaddingBottom` is 0, not a copy of the left or
|
|
59
57
|
// top padding. Only the legacy single `stackPadding` stands in for all four.
|
|
@@ -94,9 +92,8 @@ export function sizeLimitsOf(change) {
|
|
|
94
92
|
* the cross axis. Taco has no grow weights, so any grow above 0 fills. A
|
|
95
93
|
* flow child loses its constraints, taken off `node` itself, as they apply
|
|
96
94
|
* only to absolute children.
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
* line fills only its width, as its height is always 0.
|
|
95
|
+
* Upright, unlocked groups and paths in a non-wrapping stack carry Fill in
|
|
96
|
+
* metadata for the adapter. A line fills only its width, as its height is always 0.
|
|
100
97
|
*
|
|
101
98
|
* Figma keeps one sizing per axis, and Fill wins over the child's own Hug: a
|
|
102
99
|
* frame that hugs an axis, or text that sizes it to its content, shows the
|
|
@@ -105,29 +102,17 @@ export function sizeLimitsOf(change) {
|
|
|
105
102
|
* sizes to its content, so such a child gets the fill and a fixed size on that
|
|
106
103
|
* axis instead, and the report says so.
|
|
107
104
|
*/
|
|
108
|
-
export function stackChildFields(change, vertical, node, report
|
|
105
|
+
export function stackChildFields(change, vertical, wraps, node, report) {
|
|
109
106
|
if (change["stackPositioning"] === "ABSOLUTE")
|
|
110
107
|
return { layoutPositioning: "absolute" };
|
|
111
108
|
// Constraints act on a flow child neither in Figma nor in Taco, so the child keeps none.
|
|
112
|
-
|
|
113
|
-
delete node.constraints;
|
|
109
|
+
clearConstraints(node);
|
|
114
110
|
const grow = numberField(change, "stackChildPrimaryGrow") ?? 0;
|
|
115
|
-
if (grow > 0 && cannotFill !== undefined) {
|
|
116
|
-
report("approximated", `stackChildPrimaryGrow ${String(grow)} is not imported as Fill; ${cannotFill} cannot fill its parent in Taco, so it keeps its size`);
|
|
117
|
-
}
|
|
118
|
-
else if (grow !== 0 && grow !== 1) {
|
|
119
|
-
report("approximated", `stackChildPrimaryGrow ${String(grow)} is imported as Fill; Taco has no grow weights`);
|
|
120
|
-
}
|
|
121
111
|
const alignSelf = change["stackChildAlignSelf"];
|
|
122
112
|
const stretch = alignSelf === "STRETCH";
|
|
123
113
|
if (alignSelf !== undefined && alignSelf !== "AUTO" && !stretch) {
|
|
124
114
|
report("property-left-out", `stackChildAlignSelf ${String(alignSelf)} is not imported; the child follows the frame's alignment`);
|
|
125
115
|
}
|
|
126
|
-
if (stretch && cannotFill !== undefined) {
|
|
127
|
-
report("approximated", `stackChildAlignSelf STRETCH is not imported as Fill; ${cannotFill} cannot fill its parent in Taco, so it keeps its size`);
|
|
128
|
-
}
|
|
129
|
-
if (cannotFill !== undefined)
|
|
130
|
-
return {};
|
|
131
116
|
const fillMain = grow > 0;
|
|
132
117
|
const line = node.type === "shape" && node.shape === "line";
|
|
133
118
|
const fillHeight = vertical ? fillMain : stretch;
|
|
@@ -140,6 +125,40 @@ export function stackChildFields(change, vertical, node, report, cannotFill) {
|
|
|
140
125
|
};
|
|
141
126
|
if (fill.width === undefined && fill.height === undefined)
|
|
142
127
|
return {};
|
|
128
|
+
const carried = node.type === "group" || (node.type === "shape" && node.shape === "path");
|
|
129
|
+
if (carried) {
|
|
130
|
+
const turned = node.type === "group" ? Math.abs(node.rotation ?? 0) > 1e-4 :
|
|
131
|
+
Math.abs(node.transform[1]) > 1e-6 || Math.abs(node.transform[2]) > 1e-6 ||
|
|
132
|
+
(node.transform[0] < 0 && node.transform[3] < 0);
|
|
133
|
+
const reason = wraps ? "wrapping stacks require line sizing and breaks to agree" :
|
|
134
|
+
turned ? "rotated geometry needs fill sizing in parent axes" :
|
|
135
|
+
node.aspectRatioLocked ? "aspect-locked fill needs to preserve the ratio across both axes" : undefined;
|
|
136
|
+
if (reason) {
|
|
137
|
+
report("property-left-out", `${node.type === "group" ? "group" : "path"} Fill is left out: ${reason}`);
|
|
138
|
+
return {};
|
|
139
|
+
}
|
|
140
|
+
if (node.type === "shape") {
|
|
141
|
+
// A flat outline cannot grow by scaling on its empty axis. Let other fill
|
|
142
|
+
// children share that space, and keep any fill along the outline itself.
|
|
143
|
+
const bounds = getVectorNetworkBounds(node.vectorNetwork, node.transform);
|
|
144
|
+
for (const axis of ["width", "height"]) {
|
|
145
|
+
if (fill[axis] && !bounds?.[axis]) {
|
|
146
|
+
delete fill[axis];
|
|
147
|
+
report("property-left-out", `path Fill is left out on the ${axis} because its outline has zero extent there`);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (!fill.width && !fill.height)
|
|
151
|
+
return {};
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
if ((vertical ? fill.height : fill.width) && grow !== 1) {
|
|
155
|
+
report("approximated", `stackChildPrimaryGrow ${String(grow)} is imported as Fill; Taco has no grow weights`);
|
|
156
|
+
}
|
|
157
|
+
if (carried) {
|
|
158
|
+
const limits = node.type === "shape" ? sizeLimitsOf(change) : {};
|
|
159
|
+
carry(node, { fillSizing: { ...limits, ...fill } });
|
|
160
|
+
return {};
|
|
161
|
+
}
|
|
143
162
|
const resizing = "resizing" in node ? node.resizing : undefined;
|
|
144
163
|
return { resizing: { ...resizing, ...fill }, ...fixedWhereFilled(node, fill, report) };
|
|
145
164
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { drawnAsPlainRectangle, nodeEffects } from "./effects.js";
|
|
2
2
|
import { framedBase, visualStyle } from "./shared.js";
|
|
3
|
-
/** A
|
|
3
|
+
/** A plain or rounded Figma rectangle as a Taco rectangle. */
|
|
4
4
|
export const convertRectangle = (node, walk) => {
|
|
5
5
|
const base = framedBase(node, walk, "Rectangle", true);
|
|
6
6
|
if (base === null)
|