@moondraft/import 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/README.md +2 -2
  3. package/SOURCE.md +343 -4
  4. package/dist/adapter/convert.d.ts +26 -2
  5. package/dist/adapter/convert.js +817 -217
  6. package/dist/adapter/figma-descriptions.d.ts +7 -0
  7. package/dist/adapter/figma-descriptions.js +34 -0
  8. package/dist/adapter/figma-grids.d.ts +12 -0
  9. package/dist/adapter/figma-grids.js +175 -0
  10. package/dist/adapter/figma-handoff.d.ts +34 -0
  11. package/dist/adapter/figma-handoff.js +188 -0
  12. package/dist/adapter/figma-hyperlinks.d.ts +13 -0
  13. package/dist/adapter/figma-hyperlinks.js +77 -0
  14. package/dist/adapter/figma.d.ts +4 -1
  15. package/dist/adapter/figma.js +15 -4
  16. package/dist/adapter/file-components.d.ts +10 -3
  17. package/dist/adapter/file-components.js +126 -33
  18. package/dist/adapter/file-resources.js +545 -47
  19. package/dist/adapter/file-typography.d.ts +6 -0
  20. package/dist/adapter/file-typography.js +44 -0
  21. package/dist/adapter/image-crop.d.ts +18 -0
  22. package/dist/adapter/image-crop.js +30 -0
  23. package/dist/adapter/link.d.ts +12 -1
  24. package/dist/adapter/link.js +380 -113
  25. package/dist/adapter/payload.js +3 -3
  26. package/dist/adapter/variables.d.ts +2 -1
  27. package/dist/adapter/variables.js +5 -2
  28. package/dist/figma-file.d.ts +1 -0
  29. package/dist/figma-file.js +1 -0
  30. package/dist/figma.d.ts +1 -0
  31. package/dist/figma.js +191 -35
  32. package/dist/index.d.ts +1 -0
  33. package/dist/index.js +1 -0
  34. package/dist/report.d.ts +59 -1
  35. package/dist/report.js +176 -30
  36. package/dist/serialize.d.ts +7 -0
  37. package/dist/serialize.js +79 -0
  38. package/dist/taco/figma-import/container/kiwiContainer.d.ts +3 -0
  39. package/dist/taco/figma-import/container/kiwiContainer.js +1 -1
  40. package/dist/taco/figma-import/figFile.js +3 -0
  41. package/dist/taco/figma-import/import/carry.d.ts +14 -1
  42. package/dist/taco/figma-import/import/carry.js +34 -1
  43. package/dist/taco/figma-import/import/componentProps.d.ts +10 -4
  44. package/dist/taco/figma-import/import/componentProps.js +29 -13
  45. package/dist/taco/figma-import/import/componentSets.d.ts +2 -0
  46. package/dist/taco/figma-import/import/componentSets.js +1 -1
  47. package/dist/taco/figma-import/import/converters/effects.d.ts +3 -13
  48. package/dist/taco/figma-import/import/converters/effects.js +4 -34
  49. package/dist/taco/figma-import/import/converters/exportSettings.d.ts +4 -0
  50. package/dist/taco/figma-import/import/converters/exportSettings.js +75 -0
  51. package/dist/taco/figma-import/import/converters/frame.d.ts +1 -1
  52. package/dist/taco/figma-import/import/converters/frame.js +15 -6
  53. package/dist/taco/figma-import/import/converters/gradient.d.ts +2 -0
  54. package/dist/taco/figma-import/import/converters/gradient.js +3 -1
  55. package/dist/taco/figma-import/import/converters/grid.d.ts +12 -0
  56. package/dist/taco/figma-import/import/converters/grid.js +97 -0
  57. package/dist/taco/figma-import/import/converters/group.d.ts +2 -4
  58. package/dist/taco/figma-import/import/converters/group.js +6 -15
  59. package/dist/taco/figma-import/import/converters/image.d.ts +2 -1
  60. package/dist/taco/figma-import/import/converters/image.js +60 -16
  61. package/dist/taco/figma-import/import/converters/layout.d.ts +8 -7
  62. package/dist/taco/figma-import/import/converters/layout.js +66 -37
  63. package/dist/taco/figma-import/import/converters/rectangle.d.ts +1 -1
  64. package/dist/taco/figma-import/import/converters/rectangle.js +3 -3
  65. package/dist/taco/figma-import/import/converters/section.d.ts +2 -3
  66. package/dist/taco/figma-import/import/converters/section.js +5 -11
  67. package/dist/taco/figma-import/import/converters/shared.d.ts +9 -5
  68. package/dist/taco/figma-import/import/converters/shared.js +23 -10
  69. package/dist/taco/figma-import/import/converters/text.d.ts +38 -1
  70. package/dist/taco/figma-import/import/converters/text.js +248 -32
  71. package/dist/taco/figma-import/import/converters/vector.d.ts +36 -15
  72. package/dist/taco/figma-import/import/converters/vector.js +214 -73
  73. package/dist/taco/figma-import/import/converters/vectorNetwork.d.ts +19 -3
  74. package/dist/taco/figma-import/import/converters/vectorNetwork.js +147 -29
  75. package/dist/taco/figma-import/import/instances.d.ts +32 -5
  76. package/dist/taco/figma-import/import/instances.js +613 -130
  77. package/dist/taco/figma-import/import/styles.d.ts +2 -0
  78. package/dist/taco/figma-import/import/styles.js +6 -0
  79. package/dist/taco/figma-import/import/types.d.ts +8 -0
  80. package/dist/taco/figma-import/import/variables.d.ts +5 -2
  81. package/dist/taco/figma-import/import/variables.js +65 -31
  82. package/dist/taco/figma-import/import/variantTrees.d.ts +1 -1
  83. package/dist/taco/figma-import/import/variantTrees.js +46 -4
  84. package/dist/taco/figma-import/import/walk.d.ts +62 -7
  85. package/dist/taco/figma-import/import/walk.js +328 -122
  86. package/dist/taco/figma-import/kiwi/message.d.ts +4 -2
  87. package/dist/taco/figma-import/kiwi/message.js +59 -15
  88. package/dist/taco/model/codec.d.ts +2 -2
  89. package/dist/taco/model/codec.js +72 -8
  90. package/dist/taco/model/component-evaluation.d.ts +2 -0
  91. package/dist/taco/model/component-evaluation.js +7 -0
  92. package/dist/taco/model/instance-resolver.d.ts +6 -2
  93. package/dist/taco/model/instance-resolver.js +50 -18
  94. package/dist/taco/model/sha256.js +13 -8
  95. package/dist/taco/model/types.d.ts +57 -5
  96. package/dist/taco/model/types.js +4 -0
  97. package/dist/taco/svg-import/style/computed.js +1 -0
  98. package/package.json +3 -2
@@ -1,3 +1,6 @@
1
+ import { getVectorNetworkBounds } from "../../../model/index.js";
2
+ import { gridAxis, reportUnknownGridFields } from "./grid.js";
3
+ import { carry, clearConstraints } from "../carry.js";
1
4
  import { isObject } from "../fields.js";
2
5
  /**
3
6
  * A finite number field, or `undefined`. Figma writes NaN in some stack
@@ -27,44 +30,49 @@ const JUSTIFY = {
27
30
  const ALIGN = { MIN: "start", CENTER: "center", MAX: "end" };
28
31
  const SIZING = { FIXED: "fixed", RESIZE_TO_FIT: "hug", RESIZE_TO_FIT_WITH_IMPLICIT_SIZE: "hug" };
29
32
  /**
30
- * A Figma HORIZONTAL or VERTICAL auto layout as a Taco stack, or `undefined`
33
+ * A Figma grid or stack as a Taco auto layout, or `undefined`
31
34
  * for free layout. The walk turns the stack off again unless every child in
32
35
  * the flow was imported and is visible (see `stackBlocker`). An absent
33
36
  * `stackPrimarySizing` hugs and an absent `stackCounterSizing` is fixed, as
34
37
  * measured on real Figma files.
35
38
  */
36
- export function stackLayoutOf(change, report) {
39
+ export function autoLayoutOf(change, report, lost = (field) => report("property-left-out", `grid layout field ${field}`)) {
37
40
  const mode = change["stackMode"];
38
- if (mode === "GRID") {
39
- report("property-left-out", "grid auto layout is not imported yet; children keep their positions");
40
- return undefined;
41
- }
42
- if (mode !== "HORIZONTAL" && mode !== "VERTICAL")
41
+ if (mode !== "GRID" && mode !== "HORIZONTAL" && mode !== "VERTICAL")
43
42
  return undefined;
44
43
  const vertical = mode === "VERTICAL";
45
- const justify = enumField(change, "stackPrimaryAlignItems", JUSTIFY);
46
- if (justify === null)
47
- report("property-left-out", `stackPrimaryAlignItems ${String(change["stackPrimaryAlignItems"])} is not imported; children pack from the start`);
48
- const align = enumField(change, "stackCounterAlignItems", ALIGN);
49
- if (align === null)
50
- report("approximated", `stackCounterAlignItems ${String(change["stackCounterAlignItems"])} is imported as start`);
51
- const primary = enumField(change, "stackPrimarySizing", SIZING) ?? "hug";
52
- 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
44
  // Figma's file omits a padding field that is 0, on every side: a missing
58
45
  // `stackPaddingRight` or `stackPaddingBottom` is 0, not a copy of the left or
59
46
  // top padding. Only the legacy single `stackPadding` stands in for all four.
60
47
  const all = numberField(change, "stackPadding") ?? 0;
61
48
  const left = numberField(change, "stackHorizontalPadding") ?? all;
62
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`);
63
71
  const wrapGap = numberField(change, "stackCounterSpacing");
64
72
  return {
65
73
  kind: vertical ? "vertical" : "horizontal",
66
74
  gap: numberField(change, "stackSpacing") ?? 0,
67
- padding: { left, right: numberField(change, "stackPaddingRight") ?? all, top, bottom: numberField(change, "stackPaddingBottom") ?? all },
75
+ padding,
68
76
  align: align ?? "start",
69
77
  justify: justify ?? "start",
70
78
  ...(change["stackWrap"] === "WRAP"
@@ -94,9 +102,8 @@ export function sizeLimitsOf(change) {
94
102
  * the cross axis. Taco has no grow weights, so any grow above 0 fills. A
95
103
  * flow child loses its constraints, taken off `node` itself, as they apply
96
104
  * only to absolute children.
97
- * `cannotFill` names the kind of a child that Taco does not let fill (a group
98
- * or a path); such a child keeps its fixed size and the report says so. A
99
- * line fills only its width, as its height is always 0.
105
+ * Upright, unlocked groups and paths in a non-wrapping stack carry Fill in
106
+ * metadata for the adapter. A line fills only its width, as its height is always 0.
100
107
  *
101
108
  * Figma keeps one sizing per axis, and Fill wins over the child's own Hug: a
102
109
  * frame that hugs an axis, or text that sizes it to its content, shows the
@@ -105,29 +112,17 @@ export function sizeLimitsOf(change) {
105
112
  * sizes to its content, so such a child gets the fill and a fixed size on that
106
113
  * axis instead, and the report says so.
107
114
  */
108
- export function stackChildFields(change, vertical, node, report, cannotFill) {
115
+ export function stackChildFields(change, vertical, wraps, node, report) {
109
116
  if (change["stackPositioning"] === "ABSOLUTE")
110
117
  return { layoutPositioning: "absolute" };
111
118
  // Constraints act on a flow child neither in Figma nor in Taco, so the child keeps none.
112
- if ("constraints" in node)
113
- delete node.constraints;
119
+ clearConstraints(node);
114
120
  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
121
  const alignSelf = change["stackChildAlignSelf"];
122
122
  const stretch = alignSelf === "STRETCH";
123
123
  if (alignSelf !== undefined && alignSelf !== "AUTO" && !stretch) {
124
124
  report("property-left-out", `stackChildAlignSelf ${String(alignSelf)} is not imported; the child follows the frame's alignment`);
125
125
  }
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
126
  const fillMain = grow > 0;
132
127
  const line = node.type === "shape" && node.shape === "line";
133
128
  const fillHeight = vertical ? fillMain : stretch;
@@ -140,6 +135,40 @@ export function stackChildFields(change, vertical, node, report, cannotFill) {
140
135
  };
141
136
  if (fill.width === undefined && fill.height === undefined)
142
137
  return {};
138
+ const carried = node.type === "group" || (node.type === "shape" && node.shape === "path");
139
+ if (carried) {
140
+ const turned = node.type === "group" ? Math.abs(node.rotation ?? 0) > 1e-4 :
141
+ Math.abs(node.transform[1]) > 1e-6 || Math.abs(node.transform[2]) > 1e-6 ||
142
+ (node.transform[0] < 0 && node.transform[3] < 0);
143
+ const reason = wraps ? "wrapping stacks require line sizing and breaks to agree" :
144
+ turned ? "rotated geometry needs fill sizing in parent axes" :
145
+ node.aspectRatioLocked ? "aspect-locked fill needs to preserve the ratio across both axes" : undefined;
146
+ if (reason) {
147
+ report("property-left-out", `${node.type === "group" ? "group" : "path"} Fill is left out: ${reason}`);
148
+ return {};
149
+ }
150
+ if (node.type === "shape") {
151
+ // A flat outline cannot grow by scaling on its empty axis. Let other fill
152
+ // children share that space, and keep any fill along the outline itself.
153
+ const bounds = getVectorNetworkBounds(node.vectorNetwork, node.transform);
154
+ for (const axis of ["width", "height"]) {
155
+ if (fill[axis] && !bounds?.[axis]) {
156
+ delete fill[axis];
157
+ report("property-left-out", `path Fill is left out on the ${axis} because its outline has zero extent there`);
158
+ }
159
+ }
160
+ if (!fill.width && !fill.height)
161
+ return {};
162
+ }
163
+ }
164
+ if ((vertical ? fill.height : fill.width) && grow !== 1) {
165
+ report("approximated", `stackChildPrimaryGrow ${String(grow)} is imported as Fill; Taco has no grow weights`);
166
+ }
167
+ if (carried) {
168
+ const limits = node.type === "shape" ? sizeLimitsOf(change) : {};
169
+ carry(node, { fillSizing: { ...limits, ...fill } });
170
+ return {};
171
+ }
143
172
  const resizing = "resizing" in node ? node.resizing : undefined;
144
173
  return { resizing: { ...resizing, ...fill }, ...fixedWhereFilled(node, fill, report) };
145
174
  }
@@ -1,3 +1,3 @@
1
1
  import type { FigmaNodeConverter } from "../walk.ts";
2
- /** A Figma ROUNDED_RECTANGLE (the Rectangle tool's node) as a Taco rectangle. */
2
+ /** A plain or rounded Figma rectangle as a Taco rectangle. */
3
3
  export declare const convertRectangle: FigmaNodeConverter;
@@ -1,11 +1,11 @@
1
- import { drawnAsPlainRectangle, nodeEffects } from "./effects.js";
1
+ import { nodeEffects } from "./effects.js";
2
2
  import { framedBase, visualStyle } from "./shared.js";
3
- /** A Figma ROUNDED_RECTANGLE (the Rectangle tool's node) as a Taco rectangle. */
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)
7
7
  return null;
8
8
  const visual = visualStyle(node, walk);
9
- const rectangle = { ...base, type: "shape", shape: "rectangle", style: { ...visual, ...nodeEffects(node, walk, drawnAsPlainRectangle(visual, false)) } };
9
+ const rectangle = { ...base, type: "shape", shape: "rectangle", style: { ...visual, ...nodeEffects(node, walk) } };
10
10
  return rectangle;
11
11
  };
@@ -2,8 +2,7 @@ import type { FigmaNodeConverter } from "../walk.ts";
2
2
  /**
3
3
  * A Figma SECTION as a Taco frame with free layout. Sections never clip
4
4
  * their content in Figma, so `clipContent` is false and `frameMaskDisabled`
5
- * is ignored. Fields only a section has are
6
- * reported: `sectionContentsHidden` (the contents are collapsed in Figma)
7
- * and `devStatus` (the "ready for dev" mark), unless it says `NONE`.
5
+ * is ignored. `sectionContentsHidden` (collapsed contents) is reported.
6
+ * Moondraft imports section status from the original Figma nodes.
8
7
  */
9
8
  export declare const convertSection: FigmaNodeConverter;
@@ -1,28 +1,22 @@
1
- import { field, isObject } from "../fields.js";
2
- import { drawnAsPlainRectangle, nodeEffects } from "./effects.js";
1
+ import { field } from "../fields.js";
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
6
6
  * their content in Figma, so `clipContent` is false and `frameMaskDisabled`
7
- * is ignored. Fields only a section has are
8
- * reported: `sectionContentsHidden` (the contents are collapsed in Figma)
9
- * and `devStatus` (the "ready for dev" mark), unless it says `NONE`.
7
+ * is ignored. `sectionContentsHidden` (collapsed contents) is reported.
8
+ * Moondraft imports section status from the original Figma nodes.
10
9
  */
11
10
  export const convertSection = (node, walk) => {
12
11
  const where = `node ${node.id}`;
13
12
  if (field(node.change, "sectionContentsHidden", "boolean", where) === true) {
14
13
  walk.report("property-left-out", "sectionContentsHidden is not imported; the contents are shown");
15
14
  }
16
- const devStatus = node.change["devStatus"];
17
- const devType = isObject(devStatus) ? field(devStatus, "type", "string", `${where} devStatus`) : undefined;
18
- if (devStatus !== undefined && devType !== "NONE") {
19
- walk.report("property-left-out", `devStatus${devType === undefined ? "" : ` ${devType}`} is not imported`);
20
- }
21
15
  const base = framedBase(node, walk, "Section", true);
22
16
  if (base === null)
23
17
  return null;
24
18
  const visual = visualStyle(node, walk);
25
- const style = { ...visual, ...nodeEffects(node, walk, drawnAsPlainRectangle(visual, true)) };
19
+ const style = { ...visual, ...nodeEffects(node, walk) };
26
20
  const frame = {
27
21
  ...base,
28
22
  type: "frame",
@@ -1,12 +1,14 @@
1
1
  import { type BlendMode, type FramedNodeBase, type NodeBase, type Paint, type DashCap, type ResizeConstraints, type Stroke, type VisualStyle } from "../../../model/index.ts";
2
+ import type { StrokeCap } from "../../../model/types.ts";
2
3
  import { type FigmaObject } from "../fields.ts";
3
- import { type Box } from "./gradient.ts";
4
+ import { type PaintBounds } from "./gradient.ts";
4
5
  import type { FigmaTreeNode } from "../tree.ts";
5
6
  import type { NodeWalk } from "../walk.ts";
6
7
  /**
7
8
  * A Figma blend mode enum name as a Taco blend mode: `undefined` for
8
9
  * `NORMAL` and `PASS_THROUGH` (Taco's default), `null` when Taco has no such
9
- * mode (`LINEAR_BURN`, `LINEAR_DODGE`).
10
+ * mode (`LINEAR_BURN`, `LINEAR_DODGE` on a shadow; layers and paints map
11
+ * them through `LAYER_BLEND_MODES`).
10
12
  */
11
13
  export declare function blendModeOf(value: string): BlendMode | undefined | null;
12
14
  export declare function readNumbers<K extends string>(object: FigmaObject, keys: readonly K[], where: string): Record<K, number> | null;
@@ -24,7 +26,7 @@ export declare function layerBase(node: FigmaTreeNode, walk: NodeWalk, defaultNa
24
26
  * `constraints`, or `undefined` when both are MIN (or absent), Taco's
25
27
  * default. A value Taco has no match for (such as FIXED_MIN) is reported and
26
28
  * read as MIN. They are taken off again where they do not apply: from a
27
- * group by `convertGroup`, from a child in an auto layout flow by
29
+ * group (carried in its metadata) by `convertGroup`, from a child in an auto layout flow by
28
30
  * `stackChildFields`, and from a layer in a section (directly or through
29
31
  * groups) by the walk, as Figma applies none when a section is resized.
30
32
  */
@@ -52,9 +54,11 @@ export declare function framedBase(node: FigmaTreeNode, walk: NodeWalk, defaultN
52
54
  * is the box the renderer places it on instead when that differs, such as a
53
55
  * vector region's bounds.
54
56
  */
55
- export declare function nodePaints(node: Pick<FigmaTreeNode, "id" | "change">, walk: NodeWalk, list: "fillPaints" | "strokePaints", box?: Box): Paint[];
57
+ export declare function nodePaints(node: Pick<FigmaTreeNode, "id" | "change">, walk: NodeWalk, list: "fillPaints" | "strokePaints", box?: PaintBounds, source?: readonly unknown[]): Paint[];
56
58
  /** Figma's `strokeCap` names Taco has, as path ends and dash ends alike. */
57
59
  export declare const STROKE_CAPS: Readonly<Record<string, DashCap>>;
60
+ /** Figma's vector endpoint styles, including heads that dashes cannot use. */
61
+ export declare function endCapOf(value: unknown): StrokeCap | undefined;
58
62
  /**
59
63
  * Stroke paints with the node's weight, alignment, join, miter limit and
60
64
  * dashes, gradients placed on `box` (the node's box when left out). Kiwi
@@ -63,6 +67,6 @@ export declare const STROKE_CAPS: Readonly<Record<string, DashCap>>;
63
67
  * `sides` reads Figma's separate side weights, which only rectangles and
64
68
  * frames have. A dashed stroke's dash ends follow `strokeCap`, as in Figma.
65
69
  */
66
- export declare function nodeStrokes(node: FigmaTreeNode, walk: NodeWalk, box?: Box, sides?: boolean): Stroke[];
70
+ export declare function nodeStrokes(node: FigmaTreeNode, walk: NodeWalk, box?: PaintBounds, sides?: boolean): Stroke[];
67
71
  /** Solid, gradient and image fills and strokes and corners as a Taco style; other paint types are reported and left out. */
68
72
  export declare function visualStyle(node: FigmaTreeNode, walk: NodeWalk): VisualStyle;
@@ -5,10 +5,12 @@ import { moveMark } from "../carry.js";
5
5
  import { gradientShape, onBox } from "./gradient.js";
6
6
  import { styleBackedList } from "../styles.js";
7
7
  import { sizeLimitsOf } from "./layout.js";
8
+ import { exportSettingsOf } from "./exportSettings.js";
8
9
  /**
9
10
  * A Figma blend mode enum name as a Taco blend mode: `undefined` for
10
11
  * `NORMAL` and `PASS_THROUGH` (Taco's default), `null` when Taco has no such
11
- * mode (`LINEAR_BURN`, `LINEAR_DODGE`).
12
+ * mode (`LINEAR_BURN`, `LINEAR_DODGE` on a shadow; layers and paints map
13
+ * them through `LAYER_BLEND_MODES`).
12
14
  */
13
15
  export function blendModeOf(value) {
14
16
  if (value === "NORMAL" || value === "PASS_THROUGH")
@@ -16,6 +18,8 @@ export function blendModeOf(value) {
16
18
  const name = value.toLowerCase().replace(/_/g, "-");
17
19
  return BLEND_MODES.includes(name) ? name : null;
18
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" };
19
23
  export function readNumbers(object, keys, where) {
20
24
  const out = {};
21
25
  for (const key of keys) {
@@ -41,7 +45,7 @@ export function hexColor(color) {
41
45
  export function layerBase(node, walk, defaultName, effectsImported = false) {
42
46
  const where = `node ${node.id}`;
43
47
  const blend = field(node.change, "blendMode", "string", where);
44
- const blendMode = blend === undefined ? undefined : blendModeOf(blend);
48
+ const blendMode = blend === undefined ? undefined : LAYER_BLEND_MODES[blend] ?? blendModeOf(blend);
45
49
  if (blendMode === null)
46
50
  walk.report("property-left-out", `blend mode ${String(blend)} has no Taco equivalent`);
47
51
  const mask = field(node.change, "mask", "boolean", where) === true;
@@ -62,6 +66,7 @@ export function layerBase(node, walk, defaultName, effectsImported = false) {
62
66
  // Figma sets `targetAspectRatio` (width and height) when a layer's aspect ratio is locked; auto layout then keeps
63
67
  // that ratio, whatever the layer's stored size.
64
68
  const aspectRatio = aspectRatioOf(node.change, where);
69
+ const exportSettings = exportSettingsOf(node.change["exportSettings"], walk.report);
65
70
  return {
66
71
  id: walk.newId(),
67
72
  name: node.name === "" ? defaultName : node.name,
@@ -72,6 +77,7 @@ export function layerBase(node, walk, defaultName, effectsImported = false) {
72
77
  ...(mask ? { mask } : {}),
73
78
  ...(constraints ? { constraints } : {}),
74
79
  ...(aspectRatio === undefined ? {} : { aspectRatioLocked: true, aspectRatio }),
80
+ ...(exportSettings === undefined ? {} : { exportSettings }),
75
81
  ...(outline ? { metadata: { figma: { maskType: "vector" } } } : {}),
76
82
  };
77
83
  }
@@ -92,7 +98,7 @@ const VERTICAL = { MIN: "top", MAX: "bottom", STRETCH: "top-bottom", CENTER: "ce
92
98
  * `constraints`, or `undefined` when both are MIN (or absent), Taco's
93
99
  * default. A value Taco has no match for (such as FIXED_MIN) is reported and
94
100
  * read as MIN. They are taken off again where they do not apply: from a
95
- * group by `convertGroup`, from a child in an auto layout flow by
101
+ * group (carried in its metadata) by `convertGroup`, from a child in an auto layout flow by
96
102
  * `stackChildFields`, and from a layer in a section (directly or through
97
103
  * groups) by the walk, as Figma applies none when a section is resized.
98
104
  */
@@ -207,12 +213,11 @@ function gradientPaint(node, walk, paint, type, at, box) {
207
213
  * is the box the renderer places it on instead when that differs, such as a
208
214
  * vector region's bounds.
209
215
  */
210
- export function nodePaints(node, walk, list, box) {
216
+ export function nodePaints(node, walk, list, box, source = styleBackedList(node.change, list, walk.styleList, `node ${node.id}`, walk.report) ?? []) {
211
217
  const where = `node ${node.id}`;
212
218
  const what = list === "fillPaints" ? "fill" : "stroke";
213
219
  const paints = [];
214
220
  const indices = walk.paintIndices ? [] : undefined;
215
- const source = styleBackedList(node.change, list, walk.styleList, where, walk.report) ?? [];
216
221
  source.forEach((paint, index) => {
217
222
  const at = `${where} ${list}[${String(index)}]`;
218
223
  const label = `${what} ${String(index + 1)}`;
@@ -221,19 +226,19 @@ export function nodePaints(node, walk, list, box) {
221
226
  const type = field(paint, "type", "string", at);
222
227
  let base;
223
228
  if (type?.startsWith("GRADIENT_")) {
224
- const gradient = gradientPaint(node, walk, paint, type, at, box);
229
+ const gradient = gradientPaint(node, walk, paint, type, at, typeof box === "function" ? box() : box);
225
230
  if (typeof gradient === "string")
226
231
  return walk.report("property-left-out", `${label} (${type}) is left out: ${gradient}`);
227
232
  if (gradient.approximated)
228
233
  walk.report("approximated", `${label}: ${gradient.approximated}`);
229
234
  base = gradient.paint;
230
235
  }
231
- else if (type === "IMAGE") {
232
- const image = imagePaint(paint, at, label, walk);
236
+ else if (type === "IMAGE" || type === "VIDEO") {
237
+ const image = imagePaint(paint, at, label, walk, list === "fillPaints");
233
238
  if (image === null)
234
239
  return;
235
240
  if (typeof image === "string")
236
- return walk.report("property-left-out", `${label} (IMAGE) is left out: ${image}`);
241
+ return walk.report("property-left-out", `${label} (${type}) is left out: ${image}`);
237
242
  base = image;
238
243
  }
239
244
  else {
@@ -254,7 +259,7 @@ export function nodePaints(node, walk, list, box) {
254
259
  }
255
260
  const visible = field(paint, "visible", "boolean", at) ?? true;
256
261
  const blend = field(paint, "blendMode", "string", at);
257
- const blendMode = blend === undefined ? undefined : blendModeOf(blend);
262
+ const blendMode = blend === undefined ? undefined : LAYER_BLEND_MODES[blend] ?? blendModeOf(blend);
258
263
  if (blendMode === null)
259
264
  walk.report("property-left-out", `${label} blend mode ${String(blend)} has no Taco equivalent`);
260
265
  const placed = {
@@ -277,6 +282,14 @@ const STROKE_JOINS = { MITER: "miter", BEVEL: "bevel", ROUND: "round" };
277
282
  const MAX_DASH_LENGTHS = 64;
278
283
  /** Figma's `strokeCap` names Taco has, as path ends and dash ends alike. */
279
284
  export const STROKE_CAPS = { NONE: "none", ROUND: "round", SQUARE: "square" };
285
+ const END_CAPS = {
286
+ ...STROKE_CAPS, ARROW_LINES: "line-arrow", ARROW_EQUILATERAL: "triangle-arrow",
287
+ TRIANGLE_FILLED: "reversed-triangle", CIRCLE_FILLED: "circle-arrow", DIAMOND_FILLED: "diamond-arrow",
288
+ };
289
+ /** Figma's vector endpoint styles, including heads that dashes cannot use. */
290
+ export function endCapOf(value) {
291
+ return typeof value === "string" && Object.hasOwn(END_CAPS, value) ? END_CAPS[value] : undefined;
292
+ }
280
293
  /**
281
294
  * Figma's separate side weights as Taco side widths, or `undefined` when the
282
295
  * node uses one weight. With `borderStrokeWeightsIndependent` Kiwi leaves out
@@ -1,4 +1,4 @@
1
- import type { TextStyle } from "../../../model/index.ts";
1
+ import type { TextRun, TextStyle } from "../../../model/index.ts";
2
2
  import { type FigmaObject } from "../fields.ts";
3
3
  import type { FigmaNodeConverter, NodeWalk } from "../walk.ts";
4
4
  /** The weight a Figma font style name such as "Semi Bold Italic" names (undefined when it names no known weight), and whether it is italic. */
@@ -30,6 +30,31 @@ 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
+ };
42
+ /** Figma stores the deviations from its feature defaults in separate on and off lists. */
43
+ export declare const OPEN_TYPE_TOGGLES: readonly ["toggledOnOTFeatures", "toggledOffOTFeatures"];
44
+ /** Figma fields that specify OpenType features on a layer, range or instance override. */
45
+ export declare const OPEN_TYPE_FIELDS: string[];
46
+ /** Keeps omitted toggle lists inherited, except for tags explicitly toggled the other way. */
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";
56
+ /** An empty range hyperlink explicitly clears the layer's hyperlink. */
57
+ export declare function hyperlinkOf(value: unknown, report: NodeWalk["report"]): TextRun["hyperlink"];
33
58
  /**
34
59
  * A Figma text style node (`styleType` TEXT) as a Taco text style, read as a
35
60
  * run of a node without overrides is; a value it lacks is Figma's default.
@@ -39,3 +64,15 @@ export declare const convertText: FigmaNodeConverter;
39
64
  * layers that use the style report it.
40
65
  */
41
66
  export declare function figmaTextStyle(change: FigmaObject, name: string, report: NodeWalk["report"], where: string, layers?: readonly FigmaObject[], variableNumber?: NodeWalk["variableNumber"]): TextStyle;
67
+ /** The top visible solid fill as a colour with the paint's opacity in its alpha; other fills are reported. */
68
+ export declare function textColor(paints: readonly unknown[], report?: NodeWalk["report"], where?: string): {
69
+ value: string;
70
+ paint: FigmaObject | undefined;
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";