@moondraft/import 0.2.0 → 0.4.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 +26 -0
- package/SOURCE.md +138 -1
- package/dist/adapter/convert.d.ts +2 -0
- package/dist/adapter/convert.js +192 -85
- package/dist/adapter/figma-handoff.d.ts +24 -2
- package/dist/adapter/figma-handoff.js +39 -18
- package/dist/adapter/figma.js +2 -1
- package/dist/adapter/file-components.d.ts +20 -1
- package/dist/adapter/file-components.js +91 -12
- package/dist/adapter/file-resources.d.ts +5 -0
- package/dist/adapter/file-resources.js +286 -40
- package/dist/adapter/file-typography.d.ts +6 -0
- package/dist/adapter/file-typography.js +44 -0
- package/dist/adapter/link.d.ts +8 -1
- package/dist/adapter/link.js +219 -105
- package/dist/adapter/payload.js +2 -2
- package/dist/adapter/variables.d.ts +1 -1
- package/dist/figma-file.d.ts +1 -0
- package/dist/figma-file.js +1 -0
- package/dist/figma.d.ts +1 -0
- package/dist/figma.js +41 -19
- package/dist/report.d.ts +37 -6
- package/dist/report.js +91 -18
- package/dist/taco/figma-import/figFile.js +3 -0
- package/dist/taco/figma-import/import/carry.d.ts +11 -1
- package/dist/taco/figma-import/import/carry.js +8 -0
- package/dist/taco/figma-import/import/converters/effects.d.ts +3 -13
- package/dist/taco/figma-import/import/converters/effects.js +4 -34
- package/dist/taco/figma-import/import/converters/exportSettings.js +26 -0
- package/dist/taco/figma-import/import/converters/frame.d.ts +1 -1
- package/dist/taco/figma-import/import/converters/frame.js +8 -7
- package/dist/taco/figma-import/import/converters/grid.d.ts +12 -0
- package/dist/taco/figma-import/import/converters/grid.js +97 -0
- package/dist/taco/figma-import/import/converters/group.d.ts +1 -0
- package/dist/taco/figma-import/import/converters/group.js +5 -2
- package/dist/taco/figma-import/import/converters/image.d.ts +1 -0
- package/dist/taco/figma-import/import/converters/image.js +38 -5
- package/dist/taco/figma-import/import/converters/layout.d.ts +5 -3
- package/dist/taco/figma-import/import/converters/layout.js +26 -16
- package/dist/taco/figma-import/import/converters/rectangle.js +2 -2
- package/dist/taco/figma-import/import/converters/section.js +2 -2
- package/dist/taco/figma-import/import/converters/shared.d.ts +2 -1
- package/dist/taco/figma-import/import/converters/shared.js +8 -5
- package/dist/taco/figma-import/import/converters/text.d.ts +24 -0
- package/dist/taco/figma-import/import/converters/text.js +121 -31
- package/dist/taco/figma-import/import/instances.d.ts +19 -3
- package/dist/taco/figma-import/import/instances.js +337 -60
- package/dist/taco/figma-import/import/types.d.ts +8 -0
- package/dist/taco/figma-import/import/variables.d.ts +2 -0
- package/dist/taco/figma-import/import/variables.js +28 -1
- package/dist/taco/figma-import/import/variantTrees.js +2 -0
- package/dist/taco/figma-import/import/walk.d.ts +9 -2
- package/dist/taco/figma-import/import/walk.js +69 -30
- package/dist/taco/figma-import/kiwi/message.js +52 -10
- package/dist/taco/model/codec.d.ts +1 -1
- package/dist/taco/model/codec.js +40 -6
- package/dist/taco/model/instance-resolver.js +3 -1
- package/dist/taco/model/types.d.ts +36 -6
- package/dist/taco/model/types.js +4 -0
- package/dist/taco/svg-import/style/computed.js +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { isObject } from "../fields.js";
|
|
2
|
+
const guid = (v) => isObject(v) && Number.isInteger(v.sessionID) && Number.isInteger(v.localID)
|
|
3
|
+
? `${v.sessionID}:${v.localID}` : undefined;
|
|
4
|
+
const frameFields = ["gridColumns", "gridRows", "gridColumnsSizing", "gridRowsSizing", "gridRowGap", "gridColumnGap"];
|
|
5
|
+
export const gridChildFields = new Set(["gridColumnAnchor", "gridRowAnchor", "gridColumnSpan", "gridRowSpan", "gridChildHorizontalAlign", "gridChildVerticalAlign"]);
|
|
6
|
+
const knownFields = new Set([...frameFields, ...gridChildFields]);
|
|
7
|
+
export function reportUnknownGridFields(change, lost) {
|
|
8
|
+
for (const name of Object.keys(change))
|
|
9
|
+
if (name.startsWith("grid") && !knownFields.has(name))
|
|
10
|
+
lost(name);
|
|
11
|
+
}
|
|
12
|
+
function entries(raw, field, lost) {
|
|
13
|
+
if (raw === undefined)
|
|
14
|
+
return [];
|
|
15
|
+
if (isObject(raw) && Array.isArray(raw.entries))
|
|
16
|
+
return raw.entries;
|
|
17
|
+
lost(field);
|
|
18
|
+
return [];
|
|
19
|
+
}
|
|
20
|
+
function trackSize(raw) {
|
|
21
|
+
if (!isObject(raw))
|
|
22
|
+
return;
|
|
23
|
+
if (raw.type === "HUG")
|
|
24
|
+
return { kind: "auto" };
|
|
25
|
+
const n = raw.value;
|
|
26
|
+
if (raw.type === "FLEX" && (n === undefined || typeof n === "number" && Number.isFinite(n) && n > 0))
|
|
27
|
+
return { kind: "fill", weight: n ?? 1 };
|
|
28
|
+
if (raw.type === "FIXED" && typeof n === "number" && Number.isFinite(n) && n >= 0)
|
|
29
|
+
return { kind: "fixed", size: n };
|
|
30
|
+
}
|
|
31
|
+
/** Join sizing records to the ordered GUIDs. Children reference this same order by ID. */
|
|
32
|
+
export function gridAxis(change, name, lost) {
|
|
33
|
+
const order = new Map();
|
|
34
|
+
for (const e of entries(change[name], name, lost)) {
|
|
35
|
+
const id = isObject(e) && guid(e.id);
|
|
36
|
+
if (!id || !isObject(e) || typeof e.position !== "string" || order.has(id)) {
|
|
37
|
+
lost(name);
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
order.set(id, e.position);
|
|
41
|
+
}
|
|
42
|
+
const ids = [...order.keys()].sort((a, b) => order.get(a) < order.get(b) ? -1 : order.get(a) > order.get(b) ? 1 : 0);
|
|
43
|
+
const indices = new Map(ids.map((id, index) => [id, index]));
|
|
44
|
+
const tracks = Array.from({ length: Math.max(1, ids.length) }, () => ({ kind: "fill" }));
|
|
45
|
+
const field = name + "Sizing";
|
|
46
|
+
for (const e of entries(change[field], field, lost)) {
|
|
47
|
+
const id = isObject(e) && guid(e.id), i = id ? indices.get(id) : undefined;
|
|
48
|
+
if (i === undefined || !isObject(e) || !isObject(e.trackSize)) {
|
|
49
|
+
lost(field);
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
const { minSizing, maxSizing } = e.trackSize;
|
|
53
|
+
const min = trackSize(minSizing), max = trackSize(maxSizing);
|
|
54
|
+
if (minSizing !== undefined && (!min || max && JSON.stringify(min) !== JSON.stringify(max)))
|
|
55
|
+
lost(field + ".minSizing");
|
|
56
|
+
if (maxSizing !== undefined && !max)
|
|
57
|
+
lost(field + ".maxSizing");
|
|
58
|
+
if (!min && !max && minSizing === undefined && maxSizing === undefined)
|
|
59
|
+
lost(field);
|
|
60
|
+
tracks[i] = max ?? min ?? tracks[i];
|
|
61
|
+
}
|
|
62
|
+
return { indices, tracks };
|
|
63
|
+
}
|
|
64
|
+
export function gridCell(change, rows, columns, lost, override = false) {
|
|
65
|
+
if (!override && change.stackMode !== "GRID")
|
|
66
|
+
reportUnknownGridFields(change, lost);
|
|
67
|
+
const cell = {};
|
|
68
|
+
for (const [name, ids, align, key] of [["Row", rows, "Vertical", "alignY"], ["Column", columns, "Horizontal", "alignX"]]) {
|
|
69
|
+
const axis = name.toLowerCase(), anchorField = "grid" + name + "Anchor", anchor = change[anchorField];
|
|
70
|
+
if (anchor !== undefined) {
|
|
71
|
+
const id = guid(anchor), i = id && ids.get(id);
|
|
72
|
+
if (typeof i === "number" && i <= 65535)
|
|
73
|
+
cell[axis] = i;
|
|
74
|
+
else
|
|
75
|
+
lost(anchorField);
|
|
76
|
+
}
|
|
77
|
+
const spanField = "grid" + name + "Span", span = change[spanField];
|
|
78
|
+
if (span !== undefined) {
|
|
79
|
+
if (typeof span === "number" && Number.isInteger(span) && span > 0 && span <= 65535)
|
|
80
|
+
cell[axis + "Span"] = span;
|
|
81
|
+
else
|
|
82
|
+
lost(spanField);
|
|
83
|
+
}
|
|
84
|
+
const field = "gridChild" + align + "Align", value = change[field];
|
|
85
|
+
if (value === "MIN" || (override && value === "AUTO"))
|
|
86
|
+
cell[key] = "start";
|
|
87
|
+
else if (value === "CENTER")
|
|
88
|
+
cell[key] = "center";
|
|
89
|
+
else if (value === "MAX")
|
|
90
|
+
cell[key] = "end";
|
|
91
|
+
else if (value === "STRETCH")
|
|
92
|
+
cell[key] = "stretch";
|
|
93
|
+
else if (value !== undefined && value !== "AUTO")
|
|
94
|
+
lost(field);
|
|
95
|
+
}
|
|
96
|
+
return cell;
|
|
97
|
+
}
|
|
@@ -15,5 +15,6 @@ import type { FigmaNodeConverter } from "../walk.ts";
|
|
|
15
15
|
*
|
|
16
16
|
* A Taco group follows its layers' constraints (see `NodeBase.constraints`).
|
|
17
17
|
* The adapter reads the group's own constraints from its Figma metadata.
|
|
18
|
+
* Moondraft patch: its shadows and blurs are carried there too (`carryEffects`).
|
|
18
19
|
*/
|
|
19
20
|
export declare const convertGroup: FigmaNodeConverter;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { carry } from "../carry.js";
|
|
1
|
+
import { carry, carryEffects } from "../carry.js";
|
|
2
|
+
import { nodeEffects } from "./effects.js";
|
|
2
3
|
import { framedBase } from "./shared.js";
|
|
3
4
|
/**
|
|
4
5
|
* A Figma group (a FRAME that `convertFrame` finds to be a group) as a Taco
|
|
@@ -16,9 +17,10 @@ import { framedBase } from "./shared.js";
|
|
|
16
17
|
*
|
|
17
18
|
* A Taco group follows its layers' constraints (see `NodeBase.constraints`).
|
|
18
19
|
* The adapter reads the group's own constraints from its Figma metadata.
|
|
20
|
+
* Moondraft patch: its shadows and blurs are carried there too (`carryEffects`).
|
|
19
21
|
*/
|
|
20
22
|
export const convertGroup = (node, walk) => {
|
|
21
|
-
const base = framedBase(node, walk, "Group");
|
|
23
|
+
const base = framedBase(node, walk, "Group", true);
|
|
22
24
|
if (base === null)
|
|
23
25
|
return null;
|
|
24
26
|
// `framedBase` sets no variable bindings; a group's type allows no width or height binding.
|
|
@@ -26,5 +28,6 @@ export const convertGroup = (node, walk) => {
|
|
|
26
28
|
const group = { ...fields, type: "group", children: walk.convertChildren() };
|
|
27
29
|
if (constraints !== undefined)
|
|
28
30
|
carry(group, { groupConstraints: { ...constraints } });
|
|
31
|
+
carryEffects(group, nodeEffects(node, walk));
|
|
29
32
|
return group;
|
|
30
33
|
};
|
|
@@ -3,6 +3,7 @@ import { type FigmaObject } from "../fields.ts";
|
|
|
3
3
|
import type { NodeWalk } from "../walk.ts";
|
|
4
4
|
/** The MIME type of PNG, JPEG, GIF and WebP bytes, read from their first bytes; `undefined` for anything else. */
|
|
5
5
|
export declare function sniffImageMimeType(bytes: Uint8Array): string | undefined;
|
|
6
|
+
export declare function sniffVideoMimeType(bytes: Uint8Array): string | undefined;
|
|
6
7
|
export declare function hexText(bytes: Uint8Array): string;
|
|
7
8
|
/**
|
|
8
9
|
* A Figma IMAGE paint as a Taco image paint whose asset the host supplied
|
|
@@ -14,6 +14,13 @@ export function sniffImageMimeType(bytes) {
|
|
|
14
14
|
return "image/webp";
|
|
15
15
|
return undefined;
|
|
16
16
|
}
|
|
17
|
+
export function sniffVideoMimeType(bytes) {
|
|
18
|
+
if (bytes[0] === 0x1a && bytes[1] === 0x45 && bytes[2] === 0xdf && bytes[3] === 0xa3)
|
|
19
|
+
return "video/webm";
|
|
20
|
+
if (String.fromCharCode(...bytes.subarray(4, 8)) === "ftyp")
|
|
21
|
+
return String.fromCharCode(...bytes.subarray(8, 12)) === "qt " ? "video/quicktime" : "video/mp4";
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
17
24
|
export function hexText(bytes) {
|
|
18
25
|
return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
19
26
|
}
|
|
@@ -52,13 +59,39 @@ function imageFit(paint, at) {
|
|
|
52
59
|
* and image adjustments (`paintFilter`, `filterColorAdjust`) are reported, not kept.
|
|
53
60
|
*/
|
|
54
61
|
export function imagePaint(paint, at, label, walk, fill) {
|
|
55
|
-
const
|
|
56
|
-
const hash = image?.["hash"];
|
|
57
|
-
if (!(hash instanceof Uint8Array) || hash.length === 0)
|
|
58
|
-
return "the image paint has no image hash";
|
|
62
|
+
const isVideo = paint.type === "VIDEO";
|
|
59
63
|
const width = field(paint, "originalImageWidth", "number", at);
|
|
60
64
|
const height = field(paint, "originalImageHeight", "number", at);
|
|
61
|
-
const
|
|
65
|
+
const size = width !== undefined && height !== undefined ? { width, height } : undefined;
|
|
66
|
+
const read = (name) => {
|
|
67
|
+
const ref = field(paint, name, "object", at), hash = ref?.hash;
|
|
68
|
+
if (!(hash instanceof Uint8Array) || !hash.length)
|
|
69
|
+
return "the image paint has no image hash";
|
|
70
|
+
const bytes = isVideo && typeof ref?.dataBlob === "number" ? walk.blob(ref.dataBlob) : undefined;
|
|
71
|
+
return walk.image(hexText(hash), size, bytes ? { bytes } : undefined);
|
|
72
|
+
};
|
|
73
|
+
let asset = read("image");
|
|
74
|
+
if (isVideo) {
|
|
75
|
+
if (!asset || typeof asset === "string" || asset.placeholder) {
|
|
76
|
+
const thumbnail = read("imageThumbnail");
|
|
77
|
+
if (thumbnail && typeof thumbnail !== "string")
|
|
78
|
+
asset = thumbnail;
|
|
79
|
+
}
|
|
80
|
+
const poster = asset && typeof asset !== "string" && !asset.placeholder ? asset : undefined;
|
|
81
|
+
const hash = field(paint, "video", "object", at)?.hash;
|
|
82
|
+
const clip = hash instanceof Uint8Array && hash.length ? walk.image(hexText(hash), size, { video: true, ...(poster && { poster }) }) : undefined;
|
|
83
|
+
if (clip && typeof clip !== "string") {
|
|
84
|
+
asset = clip;
|
|
85
|
+
if (!clip.poster)
|
|
86
|
+
walk.report("property-left-out", `${label}: no poster supplied on this video fill`);
|
|
87
|
+
}
|
|
88
|
+
else if (poster)
|
|
89
|
+
walk.report("approximated", `${label}: video media unavailable, kept its poster as an image`);
|
|
90
|
+
else if (!asset || typeof asset === "string")
|
|
91
|
+
return "video media and poster unavailable";
|
|
92
|
+
else
|
|
93
|
+
walk.report("property-left-out", `${label}: video media and poster unavailable`);
|
|
94
|
+
}
|
|
62
95
|
if (asset === null || typeof asset === "string")
|
|
63
96
|
return asset;
|
|
64
97
|
const { fit, approximated, tile, crop } = imageFit(paint, at);
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import type { FrameNode, FramedNodeBase, NodeResizing, SceneNode,
|
|
1
|
+
import type { FrameNode, FramedNodeBase, NodeResizing, SceneNode, TextNode } from "../../../model/index.ts";
|
|
2
2
|
import { type FigmaObject } from "../fields.ts";
|
|
3
3
|
import type { FigmaImportReportKind } from "../types.ts";
|
|
4
4
|
type Report = (kind: FigmaImportReportKind, reason: string) => void;
|
|
5
5
|
/**
|
|
6
|
-
* A Figma
|
|
6
|
+
* A Figma grid or stack as a Taco auto layout, or `undefined`
|
|
7
7
|
* for free layout. The walk turns the stack off again unless every child in
|
|
8
8
|
* the flow was imported and is visible (see `stackBlocker`). An absent
|
|
9
9
|
* `stackPrimarySizing` hugs and an absent `stackCounterSizing` is fixed, as
|
|
10
10
|
* measured on real Figma files.
|
|
11
11
|
*/
|
|
12
|
-
export declare function
|
|
12
|
+
export declare function autoLayoutOf(change: FigmaObject, report: Report, lost?: (field: string) => void): Exclude<FrameNode["layout"], {
|
|
13
|
+
kind: "absolute";
|
|
14
|
+
}> | undefined;
|
|
13
15
|
/** `minSize` and `maxSize` as Taco size limits; Figma writes 0 for an unset limit. */
|
|
14
16
|
export declare function sizeLimitsOf(change: FigmaObject): NodeResizing;
|
|
15
17
|
/**
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getVectorNetworkBounds } from "../../../model/index.js";
|
|
2
|
+
import { gridAxis, reportUnknownGridFields } from "./grid.js";
|
|
2
3
|
import { carry, clearConstraints } from "../carry.js";
|
|
3
4
|
import { isObject } from "../fields.js";
|
|
4
5
|
/**
|
|
@@ -29,40 +30,49 @@ const JUSTIFY = {
|
|
|
29
30
|
const ALIGN = { MIN: "start", CENTER: "center", MAX: "end" };
|
|
30
31
|
const SIZING = { FIXED: "fixed", RESIZE_TO_FIT: "hug", RESIZE_TO_FIT_WITH_IMPLICIT_SIZE: "hug" };
|
|
31
32
|
/**
|
|
32
|
-
* A Figma
|
|
33
|
+
* A Figma grid or stack as a Taco auto layout, or `undefined`
|
|
33
34
|
* for free layout. The walk turns the stack off again unless every child in
|
|
34
35
|
* the flow was imported and is visible (see `stackBlocker`). An absent
|
|
35
36
|
* `stackPrimarySizing` hugs and an absent `stackCounterSizing` is fixed, as
|
|
36
37
|
* measured on real Figma files.
|
|
37
38
|
*/
|
|
38
|
-
export function
|
|
39
|
+
export function autoLayoutOf(change, report, lost = (field) => report("property-left-out", `grid layout field ${field}`)) {
|
|
39
40
|
const mode = change["stackMode"];
|
|
40
|
-
if (mode
|
|
41
|
-
report("property-left-out", "grid auto layout is not imported yet; children keep their positions");
|
|
42
|
-
return undefined;
|
|
43
|
-
}
|
|
44
|
-
if (mode !== "HORIZONTAL" && mode !== "VERTICAL")
|
|
41
|
+
if (mode !== "GRID" && mode !== "HORIZONTAL" && mode !== "VERTICAL")
|
|
45
42
|
return undefined;
|
|
46
43
|
const vertical = mode === "VERTICAL";
|
|
47
|
-
const justify = enumField(change, "stackPrimaryAlignItems", JUSTIFY);
|
|
48
|
-
if (justify === null)
|
|
49
|
-
report("property-left-out", `stackPrimaryAlignItems ${String(change["stackPrimaryAlignItems"])} is not imported; children pack from the start`);
|
|
50
|
-
const align = enumField(change, "stackCounterAlignItems", ALIGN);
|
|
51
|
-
if (align === null)
|
|
52
|
-
report("approximated", `stackCounterAlignItems ${String(change["stackCounterAlignItems"])} is imported as start`);
|
|
53
|
-
const primary = enumField(change, "stackPrimarySizing", SIZING) ?? "hug";
|
|
54
|
-
const counter = enumField(change, "stackCounterSizing", SIZING) ?? "fixed";
|
|
55
44
|
// Figma's file omits a padding field that is 0, on every side: a missing
|
|
56
45
|
// `stackPaddingRight` or `stackPaddingBottom` is 0, not a copy of the left or
|
|
57
46
|
// top padding. Only the legacy single `stackPadding` stands in for all four.
|
|
58
47
|
const all = numberField(change, "stackPadding") ?? 0;
|
|
59
48
|
const left = numberField(change, "stackHorizontalPadding") ?? all;
|
|
60
49
|
const top = numberField(change, "stackVerticalPadding") ?? all;
|
|
50
|
+
const padding = { left, right: numberField(change, "stackPaddingRight") ?? all, top, bottom: numberField(change, "stackPaddingBottom") ?? all };
|
|
51
|
+
const primary = enumField(change, "stackPrimarySizing", SIZING) ?? (mode === "GRID" ? "fixed" : "hug");
|
|
52
|
+
const counter = enumField(change, "stackCounterSizing", SIZING) ?? "fixed";
|
|
53
|
+
if (mode === "GRID") {
|
|
54
|
+
reportUnknownGridFields(change, lost);
|
|
55
|
+
const rows = gridAxis(change, "gridRows", lost), columns = gridAxis(change, "gridColumns", lost);
|
|
56
|
+
function gap(field) {
|
|
57
|
+
const value = numberField(change, field);
|
|
58
|
+
if (value === undefined && change[field] !== undefined)
|
|
59
|
+
lost(field);
|
|
60
|
+
return value ?? 0;
|
|
61
|
+
}
|
|
62
|
+
return { kind: "grid", columns: columns.tracks.length, columnTracks: columns.tracks, rowTracks: rows.tracks,
|
|
63
|
+
columnGap: gap("gridColumnGap"), rowGap: gap("gridRowGap"), padding, heightSizing: counter, widthSizing: primary };
|
|
64
|
+
}
|
|
65
|
+
const justify = enumField(change, "stackPrimaryAlignItems", JUSTIFY);
|
|
66
|
+
if (justify === null)
|
|
67
|
+
report("property-left-out", `stackPrimaryAlignItems ${String(change["stackPrimaryAlignItems"])} is not imported; children pack from the start`);
|
|
68
|
+
const align = enumField(change, "stackCounterAlignItems", ALIGN);
|
|
69
|
+
if (align === null)
|
|
70
|
+
report("approximated", `stackCounterAlignItems ${String(change["stackCounterAlignItems"])} is imported as start`);
|
|
61
71
|
const wrapGap = numberField(change, "stackCounterSpacing");
|
|
62
72
|
return {
|
|
63
73
|
kind: vertical ? "vertical" : "horizontal",
|
|
64
74
|
gap: numberField(change, "stackSpacing") ?? 0,
|
|
65
|
-
padding
|
|
75
|
+
padding,
|
|
66
76
|
align: align ?? "start",
|
|
67
77
|
justify: justify ?? "start",
|
|
68
78
|
...(change["stackWrap"] === "WRAP"
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { nodeEffects } from "./effects.js";
|
|
2
2
|
import { framedBase, visualStyle } from "./shared.js";
|
|
3
3
|
/** A plain or rounded Figma rectangle as a Taco rectangle. */
|
|
4
4
|
export const convertRectangle = (node, walk) => {
|
|
@@ -6,6 +6,6 @@ export const convertRectangle = (node, walk) => {
|
|
|
6
6
|
if (base === null)
|
|
7
7
|
return null;
|
|
8
8
|
const visual = visualStyle(node, walk);
|
|
9
|
-
const rectangle = { ...base, type: "shape", shape: "rectangle", style: { ...visual, ...nodeEffects(node, walk
|
|
9
|
+
const rectangle = { ...base, type: "shape", shape: "rectangle", style: { ...visual, ...nodeEffects(node, walk) } };
|
|
10
10
|
return rectangle;
|
|
11
11
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { field } from "../fields.js";
|
|
2
|
-
import {
|
|
2
|
+
import { nodeEffects } from "./effects.js";
|
|
3
3
|
import { framedBase, visualStyle } from "./shared.js";
|
|
4
4
|
/**
|
|
5
5
|
* A Figma SECTION as a Taco frame with free layout. Sections never clip
|
|
@@ -16,7 +16,7 @@ export const convertSection = (node, walk) => {
|
|
|
16
16
|
if (base === null)
|
|
17
17
|
return null;
|
|
18
18
|
const visual = visualStyle(node, walk);
|
|
19
|
-
const style = { ...visual, ...nodeEffects(node, walk
|
|
19
|
+
const style = { ...visual, ...nodeEffects(node, walk) };
|
|
20
20
|
const frame = {
|
|
21
21
|
...base,
|
|
22
22
|
type: "frame",
|
|
@@ -7,7 +7,8 @@ import type { NodeWalk } from "../walk.ts";
|
|
|
7
7
|
/**
|
|
8
8
|
* A Figma blend mode enum name as a Taco blend mode: `undefined` for
|
|
9
9
|
* `NORMAL` and `PASS_THROUGH` (Taco's default), `null` when Taco has no such
|
|
10
|
-
* mode (`LINEAR_BURN`, `LINEAR_DODGE`
|
|
10
|
+
* mode (`LINEAR_BURN`, `LINEAR_DODGE` on a shadow; layers and paints map
|
|
11
|
+
* them through `LAYER_BLEND_MODES`).
|
|
11
12
|
*/
|
|
12
13
|
export declare function blendModeOf(value: string): BlendMode | undefined | null;
|
|
13
14
|
export declare function readNumbers<K extends string>(object: FigmaObject, keys: readonly K[], where: string): Record<K, number> | null;
|
|
@@ -9,7 +9,8 @@ import { exportSettingsOf } from "./exportSettings.js";
|
|
|
9
9
|
/**
|
|
10
10
|
* A Figma blend mode enum name as a Taco blend mode: `undefined` for
|
|
11
11
|
* `NORMAL` and `PASS_THROUGH` (Taco's default), `null` when Taco has no such
|
|
12
|
-
* mode (`LINEAR_BURN`, `LINEAR_DODGE`
|
|
12
|
+
* mode (`LINEAR_BURN`, `LINEAR_DODGE` on a shadow; layers and paints map
|
|
13
|
+
* them through `LAYER_BLEND_MODES`).
|
|
13
14
|
*/
|
|
14
15
|
export function blendModeOf(value) {
|
|
15
16
|
if (value === "NORMAL" || value === "PASS_THROUGH")
|
|
@@ -17,6 +18,8 @@ export function blendModeOf(value) {
|
|
|
17
18
|
const name = value.toLowerCase().replace(/_/g, "-");
|
|
18
19
|
return BLEND_MODES.includes(name) ? name : null;
|
|
19
20
|
}
|
|
21
|
+
/** Figma's linear dodge and burn, which layers and paints take, as their CSS `plus-` names. */
|
|
22
|
+
const LAYER_BLEND_MODES = { LINEAR_DODGE: "plus-lighter", LINEAR_BURN: "plus-darker" };
|
|
20
23
|
export function readNumbers(object, keys, where) {
|
|
21
24
|
const out = {};
|
|
22
25
|
for (const key of keys) {
|
|
@@ -42,7 +45,7 @@ export function hexColor(color) {
|
|
|
42
45
|
export function layerBase(node, walk, defaultName, effectsImported = false) {
|
|
43
46
|
const where = `node ${node.id}`;
|
|
44
47
|
const blend = field(node.change, "blendMode", "string", where);
|
|
45
|
-
const blendMode = blend === undefined ? undefined : blendModeOf(blend);
|
|
48
|
+
const blendMode = blend === undefined ? undefined : LAYER_BLEND_MODES[blend] ?? blendModeOf(blend);
|
|
46
49
|
if (blendMode === null)
|
|
47
50
|
walk.report("property-left-out", `blend mode ${String(blend)} has no Taco equivalent`);
|
|
48
51
|
const mask = field(node.change, "mask", "boolean", where) === true;
|
|
@@ -230,12 +233,12 @@ export function nodePaints(node, walk, list, box, source = styleBackedList(node.
|
|
|
230
233
|
walk.report("approximated", `${label}: ${gradient.approximated}`);
|
|
231
234
|
base = gradient.paint;
|
|
232
235
|
}
|
|
233
|
-
else if (type === "IMAGE") {
|
|
236
|
+
else if (type === "IMAGE" || type === "VIDEO") {
|
|
234
237
|
const image = imagePaint(paint, at, label, walk, list === "fillPaints");
|
|
235
238
|
if (image === null)
|
|
236
239
|
return;
|
|
237
240
|
if (typeof image === "string")
|
|
238
|
-
return walk.report("property-left-out", `${label} (
|
|
241
|
+
return walk.report("property-left-out", `${label} (${type}) is left out: ${image}`);
|
|
239
242
|
base = image;
|
|
240
243
|
}
|
|
241
244
|
else {
|
|
@@ -256,7 +259,7 @@ export function nodePaints(node, walk, list, box, source = styleBackedList(node.
|
|
|
256
259
|
}
|
|
257
260
|
const visible = field(paint, "visible", "boolean", at) ?? true;
|
|
258
261
|
const blend = field(paint, "blendMode", "string", at);
|
|
259
|
-
const blendMode = blend === undefined ? undefined : blendModeOf(blend);
|
|
262
|
+
const blendMode = blend === undefined ? undefined : LAYER_BLEND_MODES[blend] ?? blendModeOf(blend);
|
|
260
263
|
if (blendMode === null)
|
|
261
264
|
walk.report("property-left-out", `${label} blend mode ${String(blend)} has no Taco equivalent`);
|
|
262
265
|
const placed = {
|
|
@@ -30,12 +30,29 @@ export declare const KEPT_LINE_HEIGHT_FIELD = "tacoKeptLineHeight";
|
|
|
30
30
|
* font size, read from the same place as the line height itself (`runBinding`).
|
|
31
31
|
*/
|
|
32
32
|
export declare const convertText: FigmaNodeConverter;
|
|
33
|
+
/** Native palette key and authored Figma field for each typography binding. */
|
|
34
|
+
export declare const TEXT_VARIABLE_FIELDS: {
|
|
35
|
+
readonly FONT_SIZE: readonly ["size", "fontSize"];
|
|
36
|
+
readonly FONT_FAMILY: readonly ["family", "fontName"];
|
|
37
|
+
readonly FONT_STYLE: readonly ["style", "fontName"];
|
|
38
|
+
readonly FONT_WEIGHT: readonly ["weight", "fontName"];
|
|
39
|
+
readonly LINE_HEIGHT: readonly ["lineHeight", "lineHeight"];
|
|
40
|
+
readonly LETTER_SPACING: readonly ["letterSpacing", "letterSpacing"];
|
|
41
|
+
};
|
|
33
42
|
/** Figma stores the deviations from its feature defaults in separate on and off lists. */
|
|
34
43
|
export declare const OPEN_TYPE_TOGGLES: readonly ["toggledOnOTFeatures", "toggledOffOTFeatures"];
|
|
35
44
|
/** Figma fields that specify OpenType features on a layer, range or instance override. */
|
|
36
45
|
export declare const OPEN_TYPE_FIELDS: string[];
|
|
37
46
|
/** Keeps omitted toggle lists inherited, except for tags explicitly toggled the other way. */
|
|
38
47
|
export declare function inheritOpenTypeToggles(base: FigmaObject | undefined, own: FigmaObject): FigmaObject;
|
|
48
|
+
/**
|
|
49
|
+
* The variable data a run's `variableField` (`LINE_HEIGHT` or `FONT_SIZE`) is bound to, read where `styleFields` reads
|
|
50
|
+
* the field it binds (`name`): an override entry's own binding, or none when the entry sets its own value; else the text
|
|
51
|
+
* style's (`under`), else the node's.
|
|
52
|
+
*/
|
|
53
|
+
/** Override field naming the typography sources an instance override authors itself: its own variable map, and
|
|
54
|
+
* `textData: true` when its range table is its own. Set by `instances.ts`, read when the text converts. */
|
|
55
|
+
export declare const OWN_TYPOGRAPHY = "ownTypography";
|
|
39
56
|
/** An empty range hyperlink explicitly clears the layer's hyperlink. */
|
|
40
57
|
export declare function hyperlinkOf(value: unknown, report: NodeWalk["report"]): TextRun["hyperlink"];
|
|
41
58
|
/**
|
|
@@ -52,3 +69,10 @@ export declare function textColor(paints: readonly unknown[], report?: NodeWalk[
|
|
|
52
69
|
value: string;
|
|
53
70
|
paint: FigmaObject | undefined;
|
|
54
71
|
};
|
|
72
|
+
/**
|
|
73
|
+
* A field the importer adds to a text layer's Figma fields, never one Figma writes: the lines Figma laid this layer out
|
|
74
|
+
* in for an instance (its `derivedSymbolData` entry's `derivedTextData.baselines`), which replace the component's stored
|
|
75
|
+
* lines when the line limit a box holds is counted; an empty list where the instance changes how its lines are set but
|
|
76
|
+
* stores none, so the count follows the instance's own first line.
|
|
77
|
+
*/
|
|
78
|
+
export declare const LAID_OUT_LINES_FIELD = "tacoLaidOutLines";
|