@moondraft/import 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/SOURCE.md +115 -1
- package/dist/adapter/convert.d.ts +2 -0
- package/dist/adapter/convert.js +175 -84
- 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 +2 -1
- package/dist/adapter/file-components.js +5 -2
- package/dist/adapter/file-resources.js +234 -25
- package/dist/adapter/file-typography.d.ts +6 -0
- package/dist/adapter/file-typography.js +44 -0
- package/dist/adapter/link.d.ts +7 -0
- package/dist/adapter/link.js +87 -24
- 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/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/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 +114 -29
- package/dist/taco/figma-import/import/instances.d.ts +9 -3
- package/dist/taco/figma-import/import/instances.js +319 -43
- 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 +2 -2
package/dist/adapter/convert.js
CHANGED
|
@@ -28,7 +28,9 @@ import { EXPRESSION_TYPES } from '../taco/model/expressions/types.js';
|
|
|
28
28
|
import { expressionColorToHex } from '../taco/model/expressions/values.js';
|
|
29
29
|
import { withoutTextMeasurement } from '../taco/model/text-reads.js';
|
|
30
30
|
import { createInstanceResolveCache, resolveComponent, resolveInstance } from '../taco/model/instance-resolver.js';
|
|
31
|
+
import { applyFileTypography } from './file-typography.js';
|
|
31
32
|
import { linkWithLayers, unmark } from './link.js';
|
|
33
|
+
const supportsGrid = 'layoutData.gridCell' in editorSchema.Properties;
|
|
32
34
|
// Figma stores float32 sizes. Comparing after layout or instance scaling can
|
|
33
35
|
// also include rounding from the arithmetic that produced the two sizes.
|
|
34
36
|
function sameFigmaSize(a, b, absoluteTolerance = 0) {
|
|
@@ -75,6 +77,8 @@ function fittedGroupAxis(size, children, axis) {
|
|
|
75
77
|
if (minimum <= far)
|
|
76
78
|
return { extent: far, minimum };
|
|
77
79
|
}
|
|
80
|
+
const supportsVideo = 'mediaType' in editorSchema.AssetSchema.properties &&
|
|
81
|
+
editorSchema.firstError(editorSchema.PaintSchema, { k: 'video', asset: 'clip' }) === null;
|
|
78
82
|
/** Converts a reader colour to the RGBA precision used by imported paints.
|
|
79
83
|
* @param hex - Source hex colour or expression colour.
|
|
80
84
|
* @returns Normalized channels, or null for a non-colour value.
|
|
@@ -106,20 +110,31 @@ export function runStyle(s) {
|
|
|
106
110
|
...(features.length > 0 && { features: Object.fromEntries(features.map(([tag, value]) => [tag, Number(value)])) }),
|
|
107
111
|
...(s.fontVariations && { variations: s.fontVariations }), size, lineHeight: +(size * (s.lineHeight ?? 1.2)).toFixed(3),
|
|
108
112
|
weight, italic: !!s.italic, underline: !!s.underline, ...(s.strikethrough ? { strikethrough: true } : {}),
|
|
113
|
+
...(s.textCase && s.textCase !== 'original' && { textCase: s.textCase }),
|
|
109
114
|
color: rgba(s.color) ?? [0, 0, 0, 1], letterSpacing: s.letterSpacing ?? 0,
|
|
110
115
|
};
|
|
111
116
|
}
|
|
112
117
|
const EXPORT_QUALITY = { low: 0.5, medium: 0.75, high: 0.92 };
|
|
118
|
+
/** Most export rows the editor keeps on one layer (its schema's `exports` limit). */
|
|
119
|
+
const MAX_EXPORTS = 32;
|
|
113
120
|
/** A source layer's export rows as the editor's `exports`: the format, the constraint as a scale, a width or a
|
|
114
|
-
* height, the suffix, and for JPEG the quality as a number. The rest of a row
|
|
115
|
-
*
|
|
116
|
-
|
|
121
|
+
* height, the suffix, and for JPEG the quality as a number. The rest of a row has no counterpart; `lost` hears of
|
|
122
|
+
* each field that differs from what the editor exports anyway (rows past the editor's limit, basic resampling, a
|
|
123
|
+
* drawing of overlapping layers, SVG id attributes). */
|
|
124
|
+
function exportsOf(rows, lost) {
|
|
117
125
|
if (!rows?.length)
|
|
118
126
|
return undefined;
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
127
|
+
for (let n = rows.length - MAX_EXPORTS; n > 0; n--)
|
|
128
|
+
lost(`export setting beyond the editor's ${MAX_EXPORTS}-row limit`);
|
|
129
|
+
return rows.slice(0, MAX_EXPORTS).map(({ format, constraint, suffix, quality, resampling, ignoreOverlappingLayers, includeIdAttribute }) => {
|
|
130
|
+
if (resampling !== 'detailed' && format !== 'svg')
|
|
131
|
+
lost('export setting resampling (basic)');
|
|
132
|
+
if (!ignoreOverlappingLayers && format !== 'pdf')
|
|
133
|
+
lost('export setting contents only (off: overlapping layers drawn)');
|
|
134
|
+
if (includeIdAttribute && format === 'svg')
|
|
135
|
+
lost('export setting SVG id attributes (always)');
|
|
136
|
+
return { format, [constraint.type]: constraint.value, suffix, ...(format === 'jpeg' && { quality: EXPORT_QUALITY[quality] }) };
|
|
137
|
+
});
|
|
123
138
|
}
|
|
124
139
|
/**
|
|
125
140
|
* Converts one page of a Taco document to Moondraft records.
|
|
@@ -146,7 +161,7 @@ export function figmaClipboardPage(doc, instanceSources) {
|
|
|
146
161
|
* @internal
|
|
147
162
|
*/
|
|
148
163
|
export function allPages(doc, options) {
|
|
149
|
-
const file = { expanded: new Map(), nestedBooleans: new Map(), omittedLinks: new Map() };
|
|
164
|
+
const file = { expanded: new Map(), nestedBooleans: new Map(), omittedLinks: new Map(), expandedReasons: new Map() };
|
|
150
165
|
return { ...convert(doc, doc.pageOrder.map((id) => doc.pages[id]), options, true, file, true), ...file };
|
|
151
166
|
}
|
|
152
167
|
// The boolean group operations (FrameNode.boolean) a live Figma boolean operation carries.
|
|
@@ -250,8 +265,8 @@ function expand(doc, pages, options, explicit, file, deferHyperlinks) {
|
|
|
250
265
|
// A nested instance layer stands for its instance node, any other for its source.
|
|
251
266
|
const layerNodeId = (layer) => layer.instance?.instanceId ?? layer.sourceNodeId;
|
|
252
267
|
// Override fields the size rules read; the rest of an override map comes from the resolved layer.
|
|
253
|
-
const SIZE_OVERRIDES = new Set(['sizing', 'padding', 'textStyle', 'lineBoxOnly', 'frame', 'x', 'y', 'width', 'height', 'resizing', 'layoutPositioning', 'constraints', 'layout', 'variableModes', 'variableBindings', 'expressions']);
|
|
254
|
-
const SIZE_BINDINGS = new Set(['width', 'height', 'gap', 'paddingTop', 'paddingRight', 'paddingBottom', 'paddingLeft', 'fontFamily']);
|
|
268
|
+
const SIZE_OVERRIDES = new Set(['sizing', 'padding', 'gridCell', 'textStyle', 'lineBoxOnly', 'frame', 'x', 'y', 'width', 'height', 'resizing', 'layoutPositioning', 'constraints', 'layout', 'variableModes', 'variableBindings', 'expressions']);
|
|
269
|
+
const SIZE_BINDINGS = new Set(['width', 'height', 'gap', 'columnGap', 'rowGap', 'paddingTop', 'paddingRight', 'paddingBottom', 'paddingLeft', 'fontFamily']);
|
|
255
270
|
function sizeOverrides(o) {
|
|
256
271
|
const out = {};
|
|
257
272
|
for (const [k, v] of Object.entries(o)) {
|
|
@@ -541,12 +556,15 @@ function expand(doc, pages, options, explicit, file, deferHyperlinks) {
|
|
|
541
556
|
return out;
|
|
542
557
|
}
|
|
543
558
|
function boxAt(scopes, id) {
|
|
559
|
+
let inner;
|
|
544
560
|
for (const { boxes, prefix, fillScale } of scopes ?? []) {
|
|
545
561
|
const box = boxes.get(prefix + id);
|
|
546
|
-
if (box)
|
|
562
|
+
if (box && !box.inner)
|
|
547
563
|
return { box, fillScale };
|
|
564
|
+
if (box)
|
|
565
|
+
inner ??= fillScale === undefined ? { box } : { box, fillScale };
|
|
548
566
|
}
|
|
549
|
-
return
|
|
567
|
+
return inner;
|
|
550
568
|
}
|
|
551
569
|
function descendSlots(map, instanceId) {
|
|
552
570
|
const out = {}, prefix = `${instanceId};`;
|
|
@@ -659,7 +677,7 @@ function expand(doc, pages, options, explicit, file, deferHyperlinks) {
|
|
|
659
677
|
continue; // a name (a layer renamed in an instance) is kept
|
|
660
678
|
if (k === 'propertyValues')
|
|
661
679
|
out.propertyValues = { ...out.propertyValues, ...v };
|
|
662
|
-
else if (['textStyle', 'variableBindings', 'variableModes', 'expressions', 'style', 'sizing', 'padding', 'layout'].includes(k))
|
|
680
|
+
else if (['textStyle', 'variableBindings', 'variableModes', 'expressions', 'style', 'sizing', 'padding', 'layout', 'gridCell'].includes(k))
|
|
663
681
|
out[k] = { ...out[k], ...v };
|
|
664
682
|
else
|
|
665
683
|
out[k] = v;
|
|
@@ -671,13 +689,19 @@ function expand(doc, pages, options, explicit, file, deferHyperlinks) {
|
|
|
671
689
|
}
|
|
672
690
|
}
|
|
673
691
|
// ---- Paints and colours.
|
|
692
|
+
const posters = new Map();
|
|
674
693
|
const stops = (s) => s.map((x) => [Math.min(1, Math.max(0, x.offset)), rgba(x.color) ?? [0, 0, 0, 1]]);
|
|
675
694
|
// Whether a model draws a fill: its compact one, or a shown paint in look.fills.
|
|
676
695
|
const shownFills = (m) => !!m.fill || !!m.look?.fills?.some((p) => p.visible !== false);
|
|
677
696
|
// A paint for the wire (packages/editor/src/renderer/wire.ts paint()), or null when dropped. A hidden paint keeps its
|
|
678
697
|
// place in the list (visible: false), as Figma keeps it; one that would be dropped is left out without counting.
|
|
679
698
|
// tile: the scale of an image fill Figma tiles (figma-import's metadata.figma.tiles, see taco/.../carry.ts).
|
|
699
|
+
// A paint's blend mode goes on the wire as its code (blend; normal is none).
|
|
680
700
|
function paint(p, tile) {
|
|
701
|
+
if (p.blendMode !== undefined && p.blendMode !== 'normal') {
|
|
702
|
+
const q = paint({ ...p, blendMode: undefined }, tile);
|
|
703
|
+
return q && { ...q, blend: BLEND_MODES.indexOf(p.blendMode) };
|
|
704
|
+
}
|
|
681
705
|
if (p.visible === false) {
|
|
682
706
|
const had = new Map(dropped), q = paint({ ...p, visible: true }, tile);
|
|
683
707
|
dropped.clear();
|
|
@@ -712,11 +736,25 @@ function expand(doc, pages, options, explicit, file, deferHyperlinks) {
|
|
|
712
736
|
return { k: 'angular', cx: p.center?.x ?? 0.5, cy: p.center?.y ?? 0.5, start: p.angle ?? 0, stops: stops(p.stops), o };
|
|
713
737
|
if (p.kind === 'image') {
|
|
714
738
|
const asset = doc.assets?.[p.assetId];
|
|
715
|
-
if (asset?.kind !== 'image' || asset.source?.kind !== 'data') {
|
|
739
|
+
if ((asset?.kind !== 'image' && asset?.kind !== 'video') || asset.source?.kind !== 'data') {
|
|
716
740
|
drop('image fill: asset missing or not inline data');
|
|
717
741
|
return null;
|
|
718
742
|
}
|
|
719
|
-
|
|
743
|
+
let kind = asset.kind;
|
|
744
|
+
if (kind === 'video' && !supportsVideo) {
|
|
745
|
+
if (!posters.has(p.assetId)) {
|
|
746
|
+
const header = typeof asset.poster === 'string' && /^data:(image\/[a-z0-9.+-]+);base64,/i.exec(asset.poster);
|
|
747
|
+
if (!header) {
|
|
748
|
+
drop('Video fill requires a newer editor');
|
|
749
|
+
return null;
|
|
750
|
+
}
|
|
751
|
+
posters.set(p.assetId, { id: p.assetId, kind: 'image', width: asset.width, height: asset.height,
|
|
752
|
+
mimeType: header[1], source: { kind: 'data', data: asset.poster.slice(header[0].length) } });
|
|
753
|
+
}
|
|
754
|
+
approximate('Video fill requires a newer editor, kept its poster');
|
|
755
|
+
kind = 'image';
|
|
756
|
+
}
|
|
757
|
+
return { k: kind, asset: p.assetId, fit: { contain: 0, fit: 0, cover: 1, fill: 2, stretch: 2 }[p.fit] ?? 1, o };
|
|
720
758
|
}
|
|
721
759
|
drop(`paint ${p.kind}`);
|
|
722
760
|
return null;
|
|
@@ -851,6 +889,26 @@ function expand(doc, pages, options, explicit, file, deferHyperlinks) {
|
|
|
851
889
|
if (o.layout)
|
|
852
890
|
eff.layout = { ...n.layout, ...o.layout };
|
|
853
891
|
const figma = n.metadata?.figma;
|
|
892
|
+
if (eff.layout?.kind === 'grid') {
|
|
893
|
+
const { columns, ...grid } = eff.layout;
|
|
894
|
+
if (supportsGrid)
|
|
895
|
+
eff.layout = { ...grid, columnTracks: grid.columnTracks ?? Array.from({ length: columns }, () => ({ kind: 'fill' })) };
|
|
896
|
+
else {
|
|
897
|
+
for (const field of Object.keys(grid))
|
|
898
|
+
drop(`Grid layout ${field} requires a newer editor`);
|
|
899
|
+
eff.layout = { kind: 'absolute' };
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
const cell = place ? place.gridCell : o.gridCell ? { ...figma?.gridCell, ...o.gridCell } : figma?.gridCell;
|
|
903
|
+
if (cell) {
|
|
904
|
+
if (supportsGrid)
|
|
905
|
+
eff.gridCell = cell;
|
|
906
|
+
else {
|
|
907
|
+
delete eff.gridCell;
|
|
908
|
+
for (const field of Object.keys(cell))
|
|
909
|
+
drop(`Grid child ${field} requires a newer editor`);
|
|
910
|
+
}
|
|
911
|
+
}
|
|
854
912
|
if (figma?.fillSizing)
|
|
855
913
|
eff.resizing = { ...figma.fillSizing, ...eff.resizing };
|
|
856
914
|
if (figma?.groupConstraints)
|
|
@@ -895,8 +953,9 @@ function expand(doc, pages, options, explicit, file, deferHyperlinks) {
|
|
|
895
953
|
}
|
|
896
954
|
const allBindings = { ...n.variableBindings, ...o.variableBindings };
|
|
897
955
|
// A literal instance gap replaces the main's binding. A binding authored on the same override still wins.
|
|
898
|
-
|
|
899
|
-
|
|
956
|
+
for (const gap of ['gap', 'columnGap', 'rowGap'])
|
|
957
|
+
if (o.layout?.[gap] !== undefined && !o.variableBindings?.[gap])
|
|
958
|
+
delete allBindings[gap];
|
|
900
959
|
const bindings = L ? Object.fromEntries(Object.entries(allBindings).filter(([k]) => SIZE_BINDINGS.has(k) || (place && k === 'opacity'))) : allBindings;
|
|
901
960
|
for (const key of ['fillColor', 'strokeColor', 'textColor']) {
|
|
902
961
|
if (!bindings[key] || (explicit && key !== 'textColor'))
|
|
@@ -943,8 +1002,8 @@ function expand(doc, pages, options, explicit, file, deferHyperlinks) {
|
|
|
943
1002
|
eff[key] = v;
|
|
944
1003
|
else if (key === 'opacity')
|
|
945
1004
|
eff.opacity = v;
|
|
946
|
-
else if (key === 'gap')
|
|
947
|
-
eff.layout = { ...eff.layout,
|
|
1005
|
+
else if (key === 'gap' || key === 'columnGap' || key === 'rowGap')
|
|
1006
|
+
eff.layout = { ...eff.layout, [key]: v };
|
|
948
1007
|
else if (pad)
|
|
949
1008
|
eff.layout = { ...eff.layout, padding: { ...eff.layout?.padding, [pad[1].toLowerCase()]: v } };
|
|
950
1009
|
else if (key === 'cornerRadius') {
|
|
@@ -1030,7 +1089,7 @@ function expand(doc, pages, options, explicit, file, deferHyperlinks) {
|
|
|
1030
1089
|
common.visible = false;
|
|
1031
1090
|
active.id = common.id;
|
|
1032
1091
|
// The layer's export settings (an instance's own go to its expanded root, never its component's).
|
|
1033
|
-
const exports = place ? place.exports : exportsOf(eff.exportSettings);
|
|
1092
|
+
const exports = place ? place.exports : exportsOf(eff.exportSettings, drop);
|
|
1034
1093
|
if (exports)
|
|
1035
1094
|
common.exports = exports;
|
|
1036
1095
|
// The node's blend mode (an instance's applies to its expanded root, which takes this common record).
|
|
@@ -1089,7 +1148,7 @@ function expand(doc, pages, options, explicit, file, deferHyperlinks) {
|
|
|
1089
1148
|
if (eff.opacity !== undefined && (setOpacity || sameVariant || n.opacity !== storedOpacity(doc.nodes[target], stored, ctx.modes)))
|
|
1090
1149
|
inner.variantOpacity = { id: target, opacity: common.opacity };
|
|
1091
1150
|
note('instances expanded');
|
|
1092
|
-
const placed = { name: common.name, blendMode: eff.blendMode, exports, stored: root.frame, frame: { ...root.frame, ...frame, width: eff.width ?? frame.width, height: eff.height ?? frame.height, x: eff.x ?? frame.x, y: eff.y ?? frame.y }, rotation, sizing: eff.sizing, resizing: eff.resizing, layoutPositioning: eff.layoutPositioning, constraints: eff.constraints, variableModes: { ...n.variableModes, ...o.variableModes }, layer, ...(ownKeys.length ? { moved: ownKeys } : {}) };
|
|
1151
|
+
const placed = { name: common.name, blendMode: eff.blendMode, exports, stored: root.frame, frame: { ...root.frame, ...frame, width: eff.width ?? frame.width, height: eff.height ?? frame.height, x: eff.x ?? frame.x, y: eff.y ?? frame.y }, rotation, gridCell: eff.gridCell, sizing: eff.sizing, resizing: eff.resizing, layoutPositioning: eff.layoutPositioning, constraints: eff.constraints, variableModes: { ...n.variableModes, ...o.variableModes }, layer, ...(ownKeys.length ? { moved: ownKeys } : {}) };
|
|
1093
1152
|
if (ownKeys.length)
|
|
1094
1153
|
inner.moved = { id: target, style: Object.fromEntries(ownKeys.map((k) => [k, r.style?.[k]])) };
|
|
1095
1154
|
// A swapped component (an override or expression changed componentId) keeps the instance's size only when that
|
|
@@ -1341,13 +1400,18 @@ function expand(doc, pages, options, explicit, file, deferHyperlinks) {
|
|
|
1341
1400
|
if ((!place || ((place.trial || place.swapped) && k in (eff.variantSize ?? {}))) && eff[k] !== undefined)
|
|
1342
1401
|
f[k] = eff[k];
|
|
1343
1402
|
// A path follows its constraint in shapeNode, from its stored place (moved here too, it would move twice).
|
|
1344
|
-
if (kept) {
|
|
1403
|
+
if (kept && !kept.inner) {
|
|
1345
1404
|
const [a, b, c, d, x, y] = kept.transform;
|
|
1346
1405
|
const { width, height } = kept;
|
|
1347
1406
|
Object.assign(f, { width, height, x: x + ((a - 1) * width + c * height) / 2, y: y + (b * width + (d - 1) * height) / 2 });
|
|
1348
1407
|
}
|
|
1349
|
-
else
|
|
1350
|
-
|
|
1408
|
+
else {
|
|
1409
|
+
if (rs && !place && f.width !== undefined && n.shape !== 'path')
|
|
1410
|
+
follow(f, eff.constraints, rs);
|
|
1411
|
+
// A text Figma measured at its size there (`inner`) keeps that size, placed by its constraints.
|
|
1412
|
+
if (kept)
|
|
1413
|
+
Object.assign(f, { width: kept.width, height: kept.height });
|
|
1414
|
+
}
|
|
1351
1415
|
// Absolute children follow constraints; auto-layout children are positioned below.
|
|
1352
1416
|
// A size from the component's own expressions is the variant's size, which its children were placed in.
|
|
1353
1417
|
const from = place?.stored ?? { ...frame, ...eff.variantSize }, free = !eff.layout || eff.layout.kind === 'absolute';
|
|
@@ -1373,7 +1437,7 @@ function expand(doc, pages, options, explicit, file, deferHyperlinks) {
|
|
|
1373
1437
|
const node = { ...eff, sizing: { width: n.layout?.widthSizing, height: n.layout?.heightSizing },
|
|
1374
1438
|
resizing: { ...eff.resizing, ...place.resizing } };
|
|
1375
1439
|
const item = { model: m, node, children: [] };
|
|
1376
|
-
const fixed = !
|
|
1440
|
+
const fixed = (!node.layout || node.layout.kind === 'absolute') ||
|
|
1377
1441
|
(sizingOf(node, 'width') !== 'hug' && sizingOf(node, 'height') !== 'hug');
|
|
1378
1442
|
if (fixed && !L.children.some(containsInstance)) {
|
|
1379
1443
|
layoutFrame(item);
|
|
@@ -1381,7 +1445,7 @@ function expand(doc, pages, options, explicit, file, deferHyperlinks) {
|
|
|
1381
1445
|
}
|
|
1382
1446
|
}
|
|
1383
1447
|
appearance(m, style, 'frame', n.metadata?.figma);
|
|
1384
|
-
if (n.metadata?.figma?.strokesIncluded === true && (eff.layout
|
|
1448
|
+
if (n.metadata?.figma?.strokesIncluded === true && (eff.layout && eff.layout.kind !== 'absolute')) {
|
|
1385
1449
|
eff.layout = { ...eff.layout, strokesIncluded: true };
|
|
1386
1450
|
}
|
|
1387
1451
|
const r = radii(style);
|
|
@@ -1538,7 +1602,7 @@ function expand(doc, pages, options, explicit, file, deferHyperlinks) {
|
|
|
1538
1602
|
}
|
|
1539
1603
|
m.layoutData = layoutData(item.node, item.instance);
|
|
1540
1604
|
const flow = m.layoutData.layout?.kind;
|
|
1541
|
-
if (n.type === 'frame' && n.metadata?.figma?.firstOnTop === true && (flow
|
|
1605
|
+
if (n.type === 'frame' && n.metadata?.figma?.firstOnTop === true && (flow && flow !== 'absolute'))
|
|
1542
1606
|
m.firstOnTop = true;
|
|
1543
1607
|
// Figma lays out again an instance it re-hugs, nested instances and all, and stores the result: where the stored
|
|
1544
1608
|
// main-axis size is not what its children's stored sizes add up to, the nested ones were laid out anew and the
|
|
@@ -1589,7 +1653,7 @@ function expand(doc, pages, options, explicit, file, deferHyperlinks) {
|
|
|
1589
1653
|
// keeps an instance root at its placed size, so what hugging gives back is its children's extent (p75 Overview
|
|
1590
1654
|
// Cards: a 60 px stored body whose texts hug to 52 re-hugs, as Figma did).
|
|
1591
1655
|
for (const [axis, key] of [['width', 'w'], ['height', 'h']]) {
|
|
1592
|
-
if (item.node.sizing?.[axis] === undefined && item.node.resizing?.[axis] === 'fixed' && item.node.layout?.[`${axis}Sizing`] === 'hug' && Math.abs((item.instance ? hugged(item, axis) ?? m[key] : m[key]) - f[axis]) < 0.01 && !item.remeasured) {
|
|
1656
|
+
if (flow !== 'grid' && item.node.sizing?.[axis] === undefined && item.node.resizing?.[axis] === 'fixed' && item.node.layout?.[`${axis}Sizing`] === 'hug' && Math.abs((item.instance ? hugged(item, axis) ?? m[key] : m[key]) - f[axis]) < 0.01 && !item.remeasured) {
|
|
1593
1657
|
m.layoutData.sizing = { ...m.layoutData.sizing, [axis]: 'fixed' };
|
|
1594
1658
|
(item.frozen ??= []).push(axis);
|
|
1595
1659
|
}
|
|
@@ -1602,7 +1666,7 @@ function expand(doc, pages, options, explicit, file, deferHyperlinks) {
|
|
|
1602
1666
|
const main = lay?.kind === 'horizontal' ? 'width' : 'height';
|
|
1603
1667
|
const hugAxes = ['width', 'height'].filter((axis) => (item.node.sizing?.[axis] ?? lay?.[`${axis}Sizing`]) === 'hug');
|
|
1604
1668
|
const fromStart = hugAxes.every((axis) => [undefined, 'start'].includes(axis === main ? lay?.justify : lay?.align));
|
|
1605
|
-
if (!ctx.comps.length && !place && hugAxes.length && fromStart) {
|
|
1669
|
+
if (flow !== 'grid' && !ctx.comps.length && !place && hugAxes.length && fromStart) {
|
|
1606
1670
|
m.keepSize = true;
|
|
1607
1671
|
if (Math.abs(m.w - f.width) > 0.01 || Math.abs(m.h - f.height) > 0.01)
|
|
1608
1672
|
approximate('page-level hug frames laid out at other than their stored size');
|
|
@@ -1622,7 +1686,8 @@ function expand(doc, pages, options, explicit, file, deferHyperlinks) {
|
|
|
1622
1686
|
if (n.type === 'text') {
|
|
1623
1687
|
const model = textNode(n, L ? { ...eff, ...resolvedText(r, full, eff, copiedColours) } : eff, o, common, f, rotation, style, ctx.modes);
|
|
1624
1688
|
if (kept) {
|
|
1625
|
-
|
|
1689
|
+
if (!kept.inner)
|
|
1690
|
+
model.t = [...kept.transform];
|
|
1626
1691
|
model.h = kept.height;
|
|
1627
1692
|
if (model.autoResize)
|
|
1628
1693
|
model.keepSize = true;
|
|
@@ -1759,7 +1824,7 @@ function expand(doc, pages, options, explicit, file, deferHyperlinks) {
|
|
|
1759
1824
|
return o.padding !== undefined || o.layout?.padding !== undefined;
|
|
1760
1825
|
if (key === 'direction' || key === 'layout.kind')
|
|
1761
1826
|
return o.layout?.kind !== undefined;
|
|
1762
|
-
if (['gap', 'align', 'justify', 'wrap', 'wrapGap'].includes(key))
|
|
1827
|
+
if (['gap', 'columnGap', 'rowGap', 'align', 'justify', 'wrap', 'wrapGap'].includes(key))
|
|
1763
1828
|
return o.layout?.[key] !== undefined;
|
|
1764
1829
|
if (key === 'layout.widthSizing' || key === 'resizing.width')
|
|
1765
1830
|
return o.sizing?.width !== undefined;
|
|
@@ -1956,7 +2021,7 @@ function expand(doc, pages, options, explicit, file, deferHyperlinks) {
|
|
|
1956
2021
|
eff['style.cornerRadii'] = num ? { topLeft: v, topRight: v, bottomRight: v, bottomLeft: v } : v;
|
|
1957
2022
|
return;
|
|
1958
2023
|
}
|
|
1959
|
-
if (['gap', 'padding', 'align', 'justify', 'direction'].includes(key)) {
|
|
2024
|
+
if (['gap', 'columnGap', 'rowGap', 'padding', 'align', 'justify', 'direction'].includes(key)) {
|
|
1960
2025
|
// Expressions spell the stored 'space-between' as the enum case .space_between.
|
|
1961
2026
|
if (key === 'justify' && v === 'space_between')
|
|
1962
2027
|
v = 'space-between';
|
|
@@ -1990,7 +2055,7 @@ function expand(doc, pages, options, explicit, file, deferHyperlinks) {
|
|
|
1990
2055
|
? { ...p, ...linearEndpoints(p.angle ?? 180, localBox(m)) } : resolveLinearCall(p, () => localBox(m));
|
|
1991
2056
|
function fillPaint(p, tile, m, cropLayerBox, cropPaintBox) {
|
|
1992
2057
|
const converted = paint(paintInBox(p, m), tile);
|
|
1993
|
-
const crop = converted?.k === 'image' && imageCropOf(p);
|
|
2058
|
+
const crop = (converted?.k === 'image' || converted?.k === 'video') && imageCropOf(p);
|
|
1994
2059
|
if (!crop)
|
|
1995
2060
|
return converted;
|
|
1996
2061
|
const placement = imageCropPlacement(crop, cropPaintBox ?? localBox(m), cropLayerBox);
|
|
@@ -2005,7 +2070,7 @@ function expand(doc, pages, options, explicit, file, deferHyperlinks) {
|
|
|
2005
2070
|
function appearance(m, style, kind, carried = {}, cropLayerBox) {
|
|
2006
2071
|
const tiles = new Map(Array.isArray(carried.tiles) ? carried.tiles : []);
|
|
2007
2072
|
const fills = (style.fills ?? []).map((p, i) => fillPaint(p, tiles.get(i), m, cropLayerBox)).filter(Boolean), look = {};
|
|
2008
|
-
if (fills.length === 1 && fills[0].k === 'solid' && fills[0].o === 1 && fills[0].visible !== false)
|
|
2073
|
+
if (fills.length === 1 && fills[0].k === 'solid' && fills[0].o === 1 && fills[0].visible !== false && !fills[0].blend)
|
|
2009
2074
|
m.fill = fills[0].c;
|
|
2010
2075
|
else if (fills.length)
|
|
2011
2076
|
look.fills = fills;
|
|
@@ -2022,10 +2087,10 @@ function expand(doc, pages, options, explicit, file, deferHyperlinks) {
|
|
|
2022
2087
|
m.stroke = p.k === 'solid' ? p.c : [0, 0, 0, 1];
|
|
2023
2088
|
m.strokeWidth = s.width;
|
|
2024
2089
|
const st = { position: { center: 0, inside: 1, outside: 2 }[s.position] ?? 0, join: { miter: 0, bevel: 1, round: 2 }[s.join] ?? null, cap: { none: 0, round: 1, square: 2 }[s.dashCap] ?? 0 };
|
|
2025
|
-
if (p.k !== 'solid' || p.o !== 1) {
|
|
2090
|
+
if (p.k !== 'solid' || p.o !== 1 || p.blend) {
|
|
2026
2091
|
st.paint = p;
|
|
2027
2092
|
if (p.k !== 'solid')
|
|
2028
|
-
note(`sent: ${p.k}${p.k === 'image' ? '' : ' gradient'} strokes`);
|
|
2093
|
+
note(`sent: ${p.k}${p.k === 'image' || p.k === 'video' ? '' : ' gradient'} strokes`);
|
|
2029
2094
|
}
|
|
2030
2095
|
if (s.dash?.length)
|
|
2031
2096
|
st.dash = s.dash;
|
|
@@ -2065,7 +2130,7 @@ function expand(doc, pages, options, explicit, file, deferHyperlinks) {
|
|
|
2065
2130
|
look.backgroundBlur = { radius: style.backgroundBlur };
|
|
2066
2131
|
for (const p of fills)
|
|
2067
2132
|
if (p.k !== 'solid')
|
|
2068
|
-
note(`sent: ${p.k}${p.k === 'image' ? '' : ' gradient'} fills`);
|
|
2133
|
+
note(`sent: ${p.k}${p.k === 'image' || p.k === 'video' ? '' : ' gradient'} fills`);
|
|
2069
2134
|
if (shadows.length)
|
|
2070
2135
|
note('sent: nodes with shadows');
|
|
2071
2136
|
if (look.layerBlur)
|
|
@@ -2105,6 +2170,47 @@ function expand(doc, pages, options, explicit, file, deferHyperlinks) {
|
|
|
2105
2170
|
const endpoints = new Set(segments.flatMap(s => [s.a, s.b]));
|
|
2106
2171
|
return netBounds({ vertices: net.vertices.filter(v => endpoints.has(v.id)), segments });
|
|
2107
2172
|
}
|
|
2173
|
+
// A component's vector network is read once for every layer that shows it: instances and the trial layouts that size
|
|
2174
|
+
// them convert the same source many times. Converted networks are values that layout and linking replace, never edit.
|
|
2175
|
+
const sharedNets = new Map();
|
|
2176
|
+
function pathNet(vn) {
|
|
2177
|
+
const r4 = (x) => (Number.isInteger(x) ? x : +x.toFixed(4)) || 0;
|
|
2178
|
+
let at;
|
|
2179
|
+
// An elliptical arc (svg-import keeps SVG's) becomes cubics of at most 90 degrees, through new vertices; its id
|
|
2180
|
+
// stands for them all in the regions' loops (`parts`).
|
|
2181
|
+
const vertices = vn.vertices.map((v) => ({ id: v.id, x: r4(v.x), y: r4(v.y) })), segments = [], parts = new Map();
|
|
2182
|
+
let arcs = 0, lostSegments = 0;
|
|
2183
|
+
for (const s of vn.segments) {
|
|
2184
|
+
if (s.kind === 'elliptical-arc')
|
|
2185
|
+
at ??= new Map(vn.vertices.map((v) => [v.id, [v.x, v.y]]));
|
|
2186
|
+
if (s.kind === 'elliptical-arc' && at?.has(s.start) && at.has(s.end)) {
|
|
2187
|
+
const { points, handles } = arcCubics(at.get(s.start), at.get(s.end), s.radiusX, s.radiusY, s.xAxisRotation ?? 0, !!s.largeArc, !!s.sweep);
|
|
2188
|
+
if (handles.length) {
|
|
2189
|
+
arcs++;
|
|
2190
|
+
const ids = points.map((_, i) => `${s.id}~v${i + 1}`);
|
|
2191
|
+
points.forEach(([x, y], i) => vertices.push({ id: ids[i], x: r4(x), y: r4(y) }));
|
|
2192
|
+
const ends = [s.start, ...ids, s.end], own = handles.map((_, i) => (i ? `${s.id}~${i}` : s.id));
|
|
2193
|
+
handles.forEach(([ha, hb], i) => segments.push({ id: own[i], a: ends[i], b: ends[i + 1], ha: ha.map(r4), hb: hb.map(r4) }));
|
|
2194
|
+
parts.set(s.id, own);
|
|
2195
|
+
continue;
|
|
2196
|
+
}
|
|
2197
|
+
}
|
|
2198
|
+
else if (s.kind !== 'line' && s.kind !== 'cubic')
|
|
2199
|
+
lostSegments++;
|
|
2200
|
+
segments.push({ id: s.id, a: s.start, b: s.end, ha: s.kind === 'cubic' ? [s.startHandle.dx, s.startHandle.dy].map(r4) : [0, 0], hb: s.kind === 'cubic' ? [s.endHandle.dx, s.endHandle.dy].map(r4) : [0, 0] });
|
|
2201
|
+
}
|
|
2202
|
+
const seg = new Map(segments.map((s) => [s.id, s]));
|
|
2203
|
+
const regions = (vn.regions ?? []).filter((r) => r.loops.length);
|
|
2204
|
+
const outlines = regions.map((r) => ({ w: r.windingRule === 'evenodd' ? 1 : 0, loops: r.loops.map((l) => {
|
|
2205
|
+
const refs = l.segments.flatMap((x) => {
|
|
2206
|
+
const rev = x.direction === 'reverse', ids = parts.get(x.segmentId) ?? [x.segmentId];
|
|
2207
|
+
return (rev ? [...ids].reverse() : ids).map((id) => [id, rev]);
|
|
2208
|
+
});
|
|
2209
|
+
const end = ([id, rev]) => (rev ? seg.get(id).a : seg.get(id).b), start = ([id, rev]) => (rev ? seg.get(id).b : seg.get(id).a);
|
|
2210
|
+
return { refs, open: start(refs[0]) !== end(refs[refs.length - 1]) };
|
|
2211
|
+
}) }));
|
|
2212
|
+
return { vertices, segments, next: vertices.length + segments.length, regions: outlines, fills: regions.map((r) => r.fills), lostSegments, arcs };
|
|
2213
|
+
}
|
|
2108
2214
|
function shapeNode(n, eff, common, f, rotation, style, rs, kept, children) {
|
|
2109
2215
|
let net, t, box, shape;
|
|
2110
2216
|
let regionFills = [];
|
|
@@ -2118,45 +2224,17 @@ function expand(doc, pages, options, explicit, file, deferHyperlinks) {
|
|
|
2118
2224
|
return m;
|
|
2119
2225
|
}
|
|
2120
2226
|
if (n.shape === 'path') {
|
|
2121
|
-
const vn = n.vectorNetwork
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
for (const s of vn.segments) {
|
|
2128
|
-
if (s.kind === 'elliptical-arc')
|
|
2129
|
-
at ??= new Map(vn.vertices.map((v) => [v.id, [v.x, v.y]]));
|
|
2130
|
-
if (s.kind === 'elliptical-arc' && at?.has(s.start) && at.has(s.end)) {
|
|
2131
|
-
const { points, handles } = arcCubics(at.get(s.start), at.get(s.end), s.radiusX, s.radiusY, s.xAxisRotation ?? 0, !!s.largeArc, !!s.sweep);
|
|
2132
|
-
if (handles.length) {
|
|
2133
|
-
arcs++;
|
|
2134
|
-
const ids = points.map((_, i) => `${s.id}~v${i + 1}`);
|
|
2135
|
-
points.forEach(([x, y], i) => vertices.push({ id: ids[i], x: r4(x), y: r4(y) }));
|
|
2136
|
-
const ends = [s.start, ...ids, s.end], own = handles.map((_, i) => (i ? `${s.id}~${i}` : s.id));
|
|
2137
|
-
handles.forEach(([ha, hb], i) => segments.push({ id: own[i], a: ends[i], b: ends[i + 1], ha: ha.map(r4), hb: hb.map(r4) }));
|
|
2138
|
-
parts.set(s.id, own);
|
|
2139
|
-
continue;
|
|
2140
|
-
}
|
|
2141
|
-
}
|
|
2142
|
-
else if (s.kind !== 'line' && s.kind !== 'cubic')
|
|
2143
|
-
drop('path segment kind');
|
|
2144
|
-
segments.push({ id: s.id, a: s.start, b: s.end, ha: s.kind === 'cubic' ? [s.startHandle.dx, s.startHandle.dy].map(r4) : [0, 0], hb: s.kind === 'cubic' ? [s.endHandle.dx, s.endHandle.dy].map(r4) : [0, 0] });
|
|
2145
|
-
}
|
|
2146
|
-
if (arcs)
|
|
2227
|
+
const vn = n.vectorNetwork;
|
|
2228
|
+
const shared = sharedNets.get(vn) ?? pathNet(vn);
|
|
2229
|
+
sharedNets.set(vn, shared);
|
|
2230
|
+
for (let k = 0; k < shared.lostSegments; k++)
|
|
2231
|
+
drop('path segment kind');
|
|
2232
|
+
if (shared.arcs)
|
|
2147
2233
|
approximate('elliptical arcs split into cubics');
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
const refs = l.segments.flatMap((x) => {
|
|
2153
|
-
const rev = x.direction === 'reverse', ids = parts.get(x.segmentId) ?? [x.segmentId];
|
|
2154
|
-
return (rev ? [...ids].reverse() : ids).map((id) => [id, rev]);
|
|
2155
|
-
});
|
|
2156
|
-
const end = ([id, rev]) => (rev ? seg.get(id).a : seg.get(id).b), start = ([id, rev]) => (rev ? seg.get(id).b : seg.get(id).a);
|
|
2157
|
-
return { refs, open: start(refs[0]) !== end(refs[refs.length - 1]) };
|
|
2158
|
-
}) }));
|
|
2159
|
-
regionFills = regions.map((r) => r.fills);
|
|
2234
|
+
// Each model owns its network and region records (region fills are its own); the geometry is shared.
|
|
2235
|
+
net = { vertices: shared.vertices, segments: shared.segments, loops: [], next: shared.next,
|
|
2236
|
+
regions: shared.regions.map(({ w, loops }) => ({ w, loops })) };
|
|
2237
|
+
regionFills = shared.fills;
|
|
2160
2238
|
t = (kept?.transform ?? eff.exprTransform ?? n.transform ?? [1, 0, 0, 1, f.x ?? 0, f.y ?? 0]).map((v) => +v.toFixed(6));
|
|
2161
2239
|
if (kept?.pathScale) {
|
|
2162
2240
|
let [sx, sy] = kept.pathScale;
|
|
@@ -2380,7 +2458,7 @@ function expand(doc, pages, options, explicit, file, deferHyperlinks) {
|
|
|
2380
2458
|
// node's expressions.
|
|
2381
2459
|
const weights = new Map();
|
|
2382
2460
|
// What sizes a run's glyphs (not its colour or decoration).
|
|
2383
|
-
const faceOf = (s) => JSON.stringify([s.fontFamily, s.fontStyle, s.fontVariations, s.openTypeFeatures, s.fontSize ?? 16, s.fontWeight ?? 400, !!s.italic, s.lineHeight ?? 1.2, s.letterSpacing ?? 0]);
|
|
2461
|
+
const faceOf = (s) => JSON.stringify([s.fontFamily, s.fontStyle, s.fontVariations, s.openTypeFeatures, s.textCase === 'original' ? undefined : s.textCase, s.fontSize ?? 16, s.fontWeight ?? 400, !!s.italic, s.lineHeight ?? 1.2, s.letterSpacing ?? 0]);
|
|
2384
2462
|
const runColour = (run) => ({ ...doc.theme?.textStyles?.[run.styleId], ...run.overrides }).color;
|
|
2385
2463
|
const hexOf = (c) => (typeof c === 'string' ? c : c?.hex)?.toLowerCase();
|
|
2386
2464
|
// A text's paragraphs: stored, or set as characters (each line one paragraph in the first run's style).
|
|
@@ -2509,8 +2587,10 @@ function expand(doc, pages, options, explicit, file, deferHyperlinks) {
|
|
|
2509
2587
|
}
|
|
2510
2588
|
if (explicit && r.styleId && doc.theme?.textStyles?.[r.styleId])
|
|
2511
2589
|
Object.assign(want, { textStyle: r.styleId });
|
|
2512
|
-
if (
|
|
2513
|
-
Object.assign(want, {
|
|
2590
|
+
if (file && r.fileTypography) {
|
|
2591
|
+
Object.assign(want, { fileTypography: r.fileTypography, ...(r.fileOwnTypography && { fileOwnTypography: r.fileOwnTypography }) });
|
|
2592
|
+
applyFileTypography(want, r.fileTypography, !!r.filePercentTracking, id => resolveVariable(id, modes, doc.variableAliases));
|
|
2593
|
+
}
|
|
2514
2594
|
if (file && (r.fileTextColor !== undefined || r.filePlainTextColor !== undefined)) {
|
|
2515
2595
|
const field = r.filePlainTextColor !== undefined ? 'filePlainTextColor' : 'fileTextColor';
|
|
2516
2596
|
const ref = r[field];
|
|
@@ -2554,7 +2634,8 @@ function expand(doc, pages, options, explicit, file, deferHyperlinks) {
|
|
|
2554
2634
|
let h = f.height, storedHeight;
|
|
2555
2635
|
const first = (eff.paragraphs ?? n.paragraphs)?.[0]?.runs?.[0], stored = n.paragraphs?.[0]?.runs?.[0];
|
|
2556
2636
|
if (first && stored && styles.length && ['height', 'width-and-height'].includes(eff.autoResize)) {
|
|
2557
|
-
const base = { ...doc.theme?.textStyles?.[stored.styleId], ...stored.overrides }
|
|
2637
|
+
const base = { ...doc.theme?.textStyles?.[stored.styleId], ...stored.overrides };
|
|
2638
|
+
const was = stored.fileLineHeightPx ?? (base.fontSize ?? 16) * (base.lineHeight ?? 1.2);
|
|
2558
2639
|
const now = boxLine || Math.max(...styles.map((x) => x.lineHeight));
|
|
2559
2640
|
// Changed text: estimate its line count from an average Inter advance (0.55 em), as no shaper runs here.
|
|
2560
2641
|
const storedText = (n.paragraphs ?? []).map((p) => (p.runs ?? []).map((r) => r.text ?? '').join('')).join('\n'), text = lines.join('\n');
|
|
@@ -2715,7 +2796,7 @@ function expand(doc, pages, options, explicit, file, deferHyperlinks) {
|
|
|
2715
2796
|
}
|
|
2716
2797
|
// Image assets the models use, listed in out.assets (and in the report, with their bytes).
|
|
2717
2798
|
const assets = {}, used = new Set(), files = [];
|
|
2718
|
-
const collectImage = (p) => { if (p?.k === 'image')
|
|
2799
|
+
const collectImage = (p) => { if (p?.k === 'image' || p?.k === 'video')
|
|
2719
2800
|
used.add(p.asset); };
|
|
2720
2801
|
for (const m of models) {
|
|
2721
2802
|
for (const p of m.look?.fills ?? [])
|
|
@@ -2726,9 +2807,11 @@ function expand(doc, pages, options, explicit, file, deferHyperlinks) {
|
|
|
2726
2807
|
collectImage(p);
|
|
2727
2808
|
}
|
|
2728
2809
|
for (const id of [...used].sort()) {
|
|
2729
|
-
const a =
|
|
2810
|
+
const a = posters.get(id) ?? doc.assets[id];
|
|
2811
|
+
const src = options.assetSrc?.(id, a) ?? `assets/${id}.${a.mimeType === 'image/jpeg' ? 'jpg' : a.mimeType.split('/')[1]}`;
|
|
2730
2812
|
files.push({ id, src, mimeType: a.mimeType, data: a.source.data });
|
|
2731
|
-
assets[id] = { src, w: a.width, h: a.height
|
|
2813
|
+
assets[id] = { src, w: a.width, h: a.height, ...(a.kind === 'video' && { mediaType: 'video',
|
|
2814
|
+
...(a.poster && { poster: a.poster }), ...(a.duration !== undefined && { duration: a.duration }) }) };
|
|
2732
2815
|
}
|
|
2733
2816
|
const out = { leading: 'half', ...(!explicit && { page: pages[0].name }), ...(options.source !== undefined ? { source: options.source } : {}), models, ...(used.size ? { assets } : {}) };
|
|
2734
2817
|
return { out, affected, nestedBooleans, counts: { dropped, expressionErrors, notes, approximations, weights }, depth: depthMax, files };
|
|
@@ -2739,12 +2822,19 @@ function convert(doc, pages, options, explicit, file, deferHyperlinks = false) {
|
|
|
2739
2822
|
const models = out.models;
|
|
2740
2823
|
const linked = options.link === false ? null : linkWithLayers(out, true, file && (id => doc.nodes[id]?.expressions?.componentId), !!file);
|
|
2741
2824
|
if (linked && !explicit) {
|
|
2742
|
-
// Clipboard mains synthesized from expansions get their presets from the source definition.
|
|
2825
|
+
// Clipboard mains synthesized from expansions get their presets from the source definition. A variant set's main
|
|
2826
|
+
// is the set's root showing one variant, a frame of the root's: the main is that variant, so it takes the
|
|
2827
|
+
// variant's presets and the frame keeps none.
|
|
2828
|
+
const lost = (what) => counts.dropped.set(what, (counts.dropped.get(what) ?? 0) + 1);
|
|
2743
2829
|
for (const main of out.models) {
|
|
2744
2830
|
if (main.kind !== 'frame' || main.parent !== '@components' || main.component !== main.id)
|
|
2745
2831
|
continue;
|
|
2746
2832
|
const source = doc.nodes[main.sourceId ?? ''];
|
|
2747
|
-
const
|
|
2833
|
+
const set = source !== undefined && Object.values(doc.components).some(c => c.rootId === source.id && c.properties?.some((p) => p.kind === 'enum'));
|
|
2834
|
+
const variant = set ? out.models.find(m => m.parent === main.id && (source.children ?? []).includes(m.sourceId ?? '')) : undefined;
|
|
2835
|
+
const exports = variant ? variant.exports : exportsOf(source?.exportSettings, lost);
|
|
2836
|
+
if (variant)
|
|
2837
|
+
delete variant.exports;
|
|
2748
2838
|
if (exports)
|
|
2749
2839
|
main.exports = exports;
|
|
2750
2840
|
}
|
|
@@ -2764,6 +2854,7 @@ function convert(doc, pages, options, explicit, file, deferHyperlinks = false) {
|
|
|
2764
2854
|
}
|
|
2765
2855
|
if (file && linked) {
|
|
2766
2856
|
file.omittedLinks = linked.omittedLinks;
|
|
2857
|
+
file.expandedReasons = linked.expandedReasons;
|
|
2767
2858
|
const { expanded } = file;
|
|
2768
2859
|
// Only appearance and text are needed after linking. The resource stage may replace
|
|
2769
2860
|
// paints on a surviving layer, so retain the pre-link look and stroke containers.
|
|
@@ -3,10 +3,32 @@ import type { DocumentJSON } from '@moondraft/editor/schema';
|
|
|
3
3
|
import type { FigmaTree, FigmaTreeNode } from '../taco/figma-import/import/tree.ts';
|
|
4
4
|
import type { readFileMessage } from '../taco/figma-import/import/walk.ts';
|
|
5
5
|
import type { FigmaImportResult } from '../taco/figma-import/index.ts';
|
|
6
|
+
declare const feature: {
|
|
7
|
+
readonly annotations: 'developer annotations are not imported';
|
|
8
|
+
readonly measurements: 'developer measurements are not imported';
|
|
9
|
+
readonly sectionStatus: 'section status is not imported';
|
|
10
|
+
readonly sectionStatusInfo: 'section status is not imported';
|
|
11
|
+
readonly devStatus: 'section status is not imported';
|
|
12
|
+
};
|
|
13
|
+
type Field = keyof typeof feature;
|
|
14
|
+
/**
|
|
15
|
+
* Finds the instances whose overrides hold active annotations or measurements. Read it before the instances' override
|
|
16
|
+
* data is released.
|
|
17
|
+
* @param tree - The reader's Figma tree.
|
|
18
|
+
* @returns The handoff fields set by each such instance's overrides, by Figma ID.
|
|
19
|
+
*/
|
|
20
|
+
export declare function handoffOverrides(tree: FigmaTree): Map<string, readonly Field[]>;
|
|
6
21
|
/** Keeps handoff-bearing clipboard layers distinct when merging variant trees. */
|
|
7
22
|
export declare function handoffSources(tree: FigmaTree): ReadonlySet<string>;
|
|
8
|
-
/**
|
|
9
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Installs Figma handoff metadata on the layers that survived conversion and reports any omitted fields: those of
|
|
25
|
+
* layers left out (`leftOut`, named in the report) and the handoff that instances set in overrides (`overrides`), which
|
|
26
|
+
* is not kept.
|
|
27
|
+
*/
|
|
28
|
+
export declare function figmaHandoff(result: FigmaImportResult, sources: ReturnType<typeof readFileMessage>['sources'], doc: DocumentJSON, options: {
|
|
10
29
|
instanceSources?: ReadonlyMap<string, string>;
|
|
11
30
|
setSources?: ReadonlyMap<string, FigmaTreeNode>;
|
|
31
|
+
leftOut: ReadonlySet<string>;
|
|
32
|
+
overrides: ReadonlyMap<string, readonly Field[]>;
|
|
12
33
|
}): ImportReportEntry[];
|
|
34
|
+
export {};
|