@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.
- package/CHANGELOG.md +44 -0
- package/README.md +2 -2
- package/SOURCE.md +343 -4
- package/dist/adapter/convert.d.ts +26 -2
- package/dist/adapter/convert.js +817 -217
- package/dist/adapter/figma-descriptions.d.ts +7 -0
- package/dist/adapter/figma-descriptions.js +34 -0
- package/dist/adapter/figma-grids.d.ts +12 -0
- package/dist/adapter/figma-grids.js +175 -0
- package/dist/adapter/figma-handoff.d.ts +34 -0
- package/dist/adapter/figma-handoff.js +188 -0
- package/dist/adapter/figma-hyperlinks.d.ts +13 -0
- package/dist/adapter/figma-hyperlinks.js +77 -0
- package/dist/adapter/figma.d.ts +4 -1
- package/dist/adapter/figma.js +15 -4
- package/dist/adapter/file-components.d.ts +10 -3
- package/dist/adapter/file-components.js +126 -33
- package/dist/adapter/file-resources.js +545 -47
- package/dist/adapter/file-typography.d.ts +6 -0
- package/dist/adapter/file-typography.js +44 -0
- package/dist/adapter/image-crop.d.ts +18 -0
- package/dist/adapter/image-crop.js +30 -0
- package/dist/adapter/link.d.ts +12 -1
- package/dist/adapter/link.js +380 -113
- package/dist/adapter/payload.js +3 -3
- package/dist/adapter/variables.d.ts +2 -1
- package/dist/adapter/variables.js +5 -2
- 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 +191 -35
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/report.d.ts +59 -1
- package/dist/report.js +176 -30
- package/dist/serialize.d.ts +7 -0
- package/dist/serialize.js +79 -0
- package/dist/taco/figma-import/container/kiwiContainer.d.ts +3 -0
- package/dist/taco/figma-import/container/kiwiContainer.js +1 -1
- package/dist/taco/figma-import/figFile.js +3 -0
- package/dist/taco/figma-import/import/carry.d.ts +14 -1
- package/dist/taco/figma-import/import/carry.js +34 -1
- package/dist/taco/figma-import/import/componentProps.d.ts +10 -4
- package/dist/taco/figma-import/import/componentProps.js +29 -13
- package/dist/taco/figma-import/import/componentSets.d.ts +2 -0
- package/dist/taco/figma-import/import/componentSets.js +1 -1
- package/dist/taco/figma-import/import/converters/effects.d.ts +3 -13
- package/dist/taco/figma-import/import/converters/effects.js +4 -34
- package/dist/taco/figma-import/import/converters/exportSettings.d.ts +4 -0
- package/dist/taco/figma-import/import/converters/exportSettings.js +75 -0
- package/dist/taco/figma-import/import/converters/frame.d.ts +1 -1
- package/dist/taco/figma-import/import/converters/frame.js +15 -6
- package/dist/taco/figma-import/import/converters/gradient.d.ts +2 -0
- package/dist/taco/figma-import/import/converters/gradient.js +3 -1
- package/dist/taco/figma-import/import/converters/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 +2 -4
- package/dist/taco/figma-import/import/converters/group.js +6 -15
- package/dist/taco/figma-import/import/converters/image.d.ts +2 -1
- package/dist/taco/figma-import/import/converters/image.js +60 -16
- package/dist/taco/figma-import/import/converters/layout.d.ts +8 -7
- package/dist/taco/figma-import/import/converters/layout.js +66 -37
- package/dist/taco/figma-import/import/converters/rectangle.d.ts +1 -1
- package/dist/taco/figma-import/import/converters/rectangle.js +3 -3
- package/dist/taco/figma-import/import/converters/section.d.ts +2 -3
- package/dist/taco/figma-import/import/converters/section.js +5 -11
- package/dist/taco/figma-import/import/converters/shared.d.ts +9 -5
- package/dist/taco/figma-import/import/converters/shared.js +23 -10
- package/dist/taco/figma-import/import/converters/text.d.ts +38 -1
- package/dist/taco/figma-import/import/converters/text.js +248 -32
- package/dist/taco/figma-import/import/converters/vector.d.ts +36 -15
- package/dist/taco/figma-import/import/converters/vector.js +214 -73
- package/dist/taco/figma-import/import/converters/vectorNetwork.d.ts +19 -3
- package/dist/taco/figma-import/import/converters/vectorNetwork.js +147 -29
- package/dist/taco/figma-import/import/instances.d.ts +32 -5
- package/dist/taco/figma-import/import/instances.js +613 -130
- package/dist/taco/figma-import/import/styles.d.ts +2 -0
- package/dist/taco/figma-import/import/styles.js +6 -0
- package/dist/taco/figma-import/import/types.d.ts +8 -0
- package/dist/taco/figma-import/import/variables.d.ts +5 -2
- package/dist/taco/figma-import/import/variables.js +65 -31
- package/dist/taco/figma-import/import/variantTrees.d.ts +1 -1
- package/dist/taco/figma-import/import/variantTrees.js +46 -4
- package/dist/taco/figma-import/import/walk.d.ts +62 -7
- package/dist/taco/figma-import/import/walk.js +328 -122
- package/dist/taco/figma-import/kiwi/message.d.ts +4 -2
- package/dist/taco/figma-import/kiwi/message.js +59 -15
- package/dist/taco/model/codec.d.ts +2 -2
- package/dist/taco/model/codec.js +72 -8
- package/dist/taco/model/component-evaluation.d.ts +2 -0
- package/dist/taco/model/component-evaluation.js +7 -0
- package/dist/taco/model/instance-resolver.d.ts +6 -2
- package/dist/taco/model/instance-resolver.js +50 -18
- package/dist/taco/model/sha256.js +13 -8
- package/dist/taco/model/types.d.ts +57 -5
- package/dist/taco/model/types.js +4 -0
- package/dist/taco/svg-import/style/computed.js +1 -0
- package/package.json +3 -2
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { TextStyle } from '@moondraft/editor/schema';
|
|
2
|
+
import type { VariableValue } from './variables.ts';
|
|
3
|
+
export declare const supportsTypographyBindings: boolean;
|
|
4
|
+
export declare const supportsTextField: (field: string) => boolean;
|
|
5
|
+
/** Keeps the drawn metrics and, on an older peer, the literal face in the selected mode. */
|
|
6
|
+
export declare function applyFileTypography(style: TextStyle, refs: Readonly<Record<string, string | null>>, percentTracking: boolean, resolve: (id: string) => VariableValue | undefined): void;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import * as editor from '@moondraft/editor/core';
|
|
2
|
+
import { fontStyleWeight } from '../taco/figma-import/import/converters/text.js';
|
|
3
|
+
// Font size bindings predate the peer’s typography binding lookup.
|
|
4
|
+
export const supportsTypographyBindings = 'bindingField' in editor && !!editor.bindingField('styles.0.family');
|
|
5
|
+
export const supportsTextField = (field) => field === 'size' || supportsTypographyBindings;
|
|
6
|
+
/** Keeps the drawn metrics and, on an older peer, the literal face in the selected mode. */
|
|
7
|
+
export function applyFileTypography(style, refs, percentTracking, resolve) {
|
|
8
|
+
if (!supportsTypographyBindings) {
|
|
9
|
+
const family = refs.family && resolve(refs.family), name = refs.style && resolve(refs.style);
|
|
10
|
+
const weight = refs.weight && resolve(refs.weight);
|
|
11
|
+
if (typeof family === 'string')
|
|
12
|
+
style.family = family;
|
|
13
|
+
if (typeof name === 'string') {
|
|
14
|
+
const metrics = fontStyleWeight(name);
|
|
15
|
+
style.style = name;
|
|
16
|
+
style.weight = metrics.fontWeight ?? 400;
|
|
17
|
+
style.italic = metrics.italic;
|
|
18
|
+
}
|
|
19
|
+
if (typeof weight === 'number') {
|
|
20
|
+
style.weight = weight;
|
|
21
|
+
if (!name)
|
|
22
|
+
style.style = editor.fontStyleName(weight, style.italic);
|
|
23
|
+
}
|
|
24
|
+
if ((name || weight) && style.variations?.wght !== undefined)
|
|
25
|
+
style.variations = { ...style.variations, wght: style.weight };
|
|
26
|
+
}
|
|
27
|
+
if (refs.lineHeight) {
|
|
28
|
+
const pixels = resolve(refs.lineHeight);
|
|
29
|
+
if (typeof pixels === 'number')
|
|
30
|
+
style.lineHeight = pixels;
|
|
31
|
+
if (supportsTypographyBindings)
|
|
32
|
+
style.lineHeightMode = 'px';
|
|
33
|
+
}
|
|
34
|
+
if (refs.letterSpacing && (percentTracking || !supportsTypographyBindings)) {
|
|
35
|
+
const spacing = resolve(refs.letterSpacing);
|
|
36
|
+
if (typeof spacing === 'number') {
|
|
37
|
+
const boundSize = percentTracking && refs.size ? resolve(refs.size) : undefined;
|
|
38
|
+
const size = typeof boundSize === 'number' ? boundSize : style.size;
|
|
39
|
+
style.letterSpacing = percentTracking ? spacing * size / 100 : spacing;
|
|
40
|
+
}
|
|
41
|
+
if (percentTracking)
|
|
42
|
+
style.letterSpacingMode = 'percent';
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { localBox } from '@moondraft/editor/core';
|
|
2
|
+
import type { Paint } from '@moondraft/editor/schema';
|
|
3
|
+
import type { FigmaImageCrop } from '../taco/figma-import/import/carry.ts';
|
|
4
|
+
type ImagePaint = Extract<Paint, {
|
|
5
|
+
k: 'image';
|
|
6
|
+
}>;
|
|
7
|
+
type Box = ReturnType<typeof localBox>;
|
|
8
|
+
/** Places the full image in the paint box by inverting Figma's layer-to-image UV mapping. */
|
|
9
|
+
export declare function imageCropPlacement({ matrix, aspect }: FigmaImageCrop, paintBox: Box, layerBox?: {
|
|
10
|
+
x: number;
|
|
11
|
+
y: number;
|
|
12
|
+
width: number;
|
|
13
|
+
height: number;
|
|
14
|
+
}): {
|
|
15
|
+
fit: 1 | 2;
|
|
16
|
+
transform: NonNullable<ImagePaint['transform']>;
|
|
17
|
+
} | undefined;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { apply, inv, localBox } from '@moondraft/editor/core';
|
|
2
|
+
const tolerance = 1e-4; // The Figma matrix and box are stored as floats.
|
|
3
|
+
const near = (a, b) => Math.abs(a - b) <= tolerance * Math.max(a, b);
|
|
4
|
+
/** Places the full image in the paint box by inverting Figma's layer-to-image UV mapping. */
|
|
5
|
+
export function imageCropPlacement({ matrix, aspect }, paintBox, layerBox = paintBox) {
|
|
6
|
+
const { width, height } = layerBox;
|
|
7
|
+
const [m00, m10, m01, m11] = matrix;
|
|
8
|
+
if (!(width > 0 && height > 0 && paintBox.width > 0 && paintBox.height > 0 && m00 * m11 - m10 * m01 > 0))
|
|
9
|
+
return;
|
|
10
|
+
const imageToLayer = inv([...matrix]);
|
|
11
|
+
const [a, b, c, d] = imageToLayer;
|
|
12
|
+
const ux = a * width, uy = b * height, vx = c * width, vy = d * height;
|
|
13
|
+
const w = Math.hypot(ux, uy), h = Math.hypot(vx, vy);
|
|
14
|
+
if (!(w > 0 && h > 0) || Math.abs((ux / w) * (vx / h) + (uy / w) * (vy / h)) > tolerance)
|
|
15
|
+
return;
|
|
16
|
+
const sx = w / paintBox.width, sy = h / paintBox.height;
|
|
17
|
+
const fit = near(sx, sy) ? 2 : 1;
|
|
18
|
+
// Stretch handles equal zoom on both box axes. Otherwise a cover fit supplies the image's aspect ratio,
|
|
19
|
+
// and one of its axes spans the box exactly. When the image is unavailable, infer its ratio from the crop.
|
|
20
|
+
if (fit === 1 && aspect !== undefined && !near(w / h, aspect))
|
|
21
|
+
return;
|
|
22
|
+
const scale = Math.min(sx, sy);
|
|
23
|
+
const [cx, cy] = apply(imageToLayer, 0.5, 0.5);
|
|
24
|
+
const x = (cx * width + (layerBox.x - paintBox.x)) / paintBox.width - 0.5;
|
|
25
|
+
const y = (cy * height + (layerBox.y - paintBox.y)) / paintBox.height - 0.5;
|
|
26
|
+
const rotation = Math.atan2(uy, ux) * 180 / Math.PI + 0;
|
|
27
|
+
if (!(scale > 0) || ![x, y, scale, rotation].every(Number.isFinite))
|
|
28
|
+
return;
|
|
29
|
+
return { fit, transform: { x, y, scale, rotation } };
|
|
30
|
+
}
|
package/dist/adapter/link.d.ts
CHANGED
|
@@ -5,6 +5,15 @@ export declare const MARKERS: string[];
|
|
|
5
5
|
* @param m - Converted model to update.
|
|
6
6
|
*/
|
|
7
7
|
export declare const unmark: (m: any) => void;
|
|
8
|
+
/**
|
|
9
|
+
* Describes in plain words why an instance stays expanded, from linking's reason for it (LinkCounts.unlinked).
|
|
10
|
+
* @param reason - Linking's reason.
|
|
11
|
+
* @returns What the report says after "expanded instance: ".
|
|
12
|
+
*/
|
|
13
|
+
export declare function expansionReason(reason: string): string;
|
|
14
|
+
/** A text's style index per UTF-16 unit, from styleAt or the file's runs ([length, style]). */
|
|
15
|
+
export declare function styleAtOf(m: any): any;
|
|
16
|
+
export declare const supportsRunPaint: boolean;
|
|
8
17
|
/** What linkComponents did: models before and after, instances linked, mains on the page and hidden mains used,
|
|
9
18
|
* the instances left expanded by their first difference, and how variant sets were linked (a main per variant, or
|
|
10
19
|
* one for the set). */
|
|
@@ -39,7 +48,9 @@ export declare function linkComponents(doc: {
|
|
|
39
48
|
/** @internal Links components and tracks where their expanded layers went for import reports. */
|
|
40
49
|
export declare function linkWithLayers(doc: {
|
|
41
50
|
models: any[];
|
|
42
|
-
}, trackLayers?: boolean): {
|
|
51
|
+
}, trackLayers?: boolean, swapBinding?: (source: string) => string | undefined, nativeFile?: boolean): {
|
|
43
52
|
counts: LinkCounts;
|
|
44
53
|
aliases: Map<string, string[]>;
|
|
54
|
+
omittedLinks: Map<string, Set<string>>;
|
|
55
|
+
expandedReasons: Map<string, string>;
|
|
45
56
|
};
|