@open-pencil/scene-graph 0.17.0-beta.4 → 0.17.0-beta.6
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/dist/buffered-events.js +1 -1
- package/dist/buffered-events.js.map +1 -1
- package/dist/clipping.d.ts +7 -1
- package/dist/clipping.d.ts.map +1 -1
- package/dist/clipping.js +23 -19
- package/dist/clipping.js.map +1 -1
- package/dist/comments/schema.d.ts.map +1 -1
- package/dist/comments/schema.js +1 -0
- package/dist/comments/schema.js.map +1 -1
- package/dist/comments/threads.d.ts +2 -0
- package/dist/comments/threads.d.ts.map +1 -1
- package/dist/comments/threads.js +11 -5
- package/dist/comments/threads.js.map +1 -1
- package/dist/components/index.d.ts +2 -2
- package/dist/components/index.js +2 -2
- package/dist/components/properties.d.ts +1 -3
- package/dist/components/properties.d.ts.map +1 -1
- package/dist/components/properties.js +3 -10
- package/dist/components/properties.js.map +1 -1
- package/dist/constants.d.ts +12 -2
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +42 -1
- package/dist/constants.js.map +1 -1
- package/dist/copy.d.ts.map +1 -1
- package/dist/copy.js +2 -0
- package/dist/copy.js.map +1 -1
- package/dist/corners.d.ts +22 -0
- package/dist/corners.d.ts.map +1 -0
- package/dist/corners.js +52 -0
- package/dist/corners.js.map +1 -0
- package/dist/css/grid.d.ts +4 -1
- package/dist/css/grid.d.ts.map +1 -1
- package/dist/css/grid.js +40 -7
- package/dist/css/grid.js.map +1 -1
- package/dist/css/index.d.ts +3 -3
- package/dist/css/index.js +3 -3
- package/dist/css/layout.d.ts +13 -1
- package/dist/css/layout.d.ts.map +1 -1
- package/dist/css/layout.js +26 -1
- package/dist/css/layout.js.map +1 -1
- package/dist/css/values.d.ts +23 -1
- package/dist/css/values.d.ts.map +1 -1
- package/dist/css/values.js +39 -1
- package/dist/css/values.js.map +1 -1
- package/dist/font-style.d.ts +2 -1
- package/dist/font-style.d.ts.map +1 -1
- package/dist/font-style.js +31 -6
- package/dist/font-style.js.map +1 -1
- package/dist/geometry.d.ts +68 -3
- package/dist/geometry.d.ts.map +1 -1
- package/dist/geometry.js +159 -25
- package/dist/geometry.js.map +1 -1
- package/dist/gradient.d.ts +9 -2
- package/dist/gradient.d.ts.map +1 -1
- package/dist/gradient.js +29 -1
- package/dist/gradient.js.map +1 -1
- package/dist/graph.d.ts +9 -2
- package/dist/graph.d.ts.map +1 -1
- package/dist/graph.js +46 -10
- package/dist/graph.js.map +1 -1
- package/dist/group-bounds.d.ts.map +1 -1
- package/dist/group-bounds.js +4 -3
- package/dist/group-bounds.js.map +1 -1
- package/dist/guides.d.ts +11 -2
- package/dist/guides.d.ts.map +1 -1
- package/dist/guides.js +30 -1
- package/dist/guides.js.map +1 -1
- package/dist/hit-test.d.ts.map +1 -1
- package/dist/hit-test.js +57 -5
- package/dist/hit-test.js.map +1 -1
- package/dist/icons/fit.d.ts +17 -0
- package/dist/icons/fit.d.ts.map +1 -0
- package/dist/icons/fit.js +21 -0
- package/dist/icons/fit.js.map +1 -0
- package/dist/icons/glyph.d.ts.map +1 -1
- package/dist/icons/glyph.js +5 -4
- package/dist/icons/glyph.js.map +1 -1
- package/dist/icons/index.d.ts +2 -1
- package/dist/icons/index.js +2 -1
- package/dist/ids.js +1 -1
- package/dist/ids.js.map +1 -1
- package/dist/images.d.ts +14 -4
- package/dist/images.d.ts.map +1 -1
- package/dist/images.js +45 -5
- package/dist/images.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/instances/assignments.js +39 -6
- package/dist/instances/assignments.js.map +1 -1
- package/dist/instances/index.d.ts +6 -1
- package/dist/instances/index.d.ts.map +1 -1
- package/dist/instances/index.js +58 -9
- package/dist/instances/index.js.map +1 -1
- package/dist/instances/kept-overrides.js +2 -2
- package/dist/instances/kept-overrides.js.map +1 -1
- package/dist/instances/matching.js +68 -0
- package/dist/instances/matching.js.map +1 -0
- package/dist/instances/overrides.d.ts +4 -1
- package/dist/instances/overrides.d.ts.map +1 -1
- package/dist/instances/overrides.js +13 -1
- package/dist/instances/overrides.js.map +1 -1
- package/dist/instances/protection.js +67 -0
- package/dist/instances/protection.js.map +1 -0
- package/dist/instances/swap.js +7 -5
- package/dist/instances/swap.js.map +1 -1
- package/dist/instances/sync.js +34 -116
- package/dist/instances/sync.js.map +1 -1
- package/dist/layout/guides.d.ts +17 -1
- package/dist/layout/guides.d.ts.map +1 -1
- package/dist/layout/guides.js +31 -11
- package/dist/layout/guides.js.map +1 -1
- package/dist/layout/index.d.ts +5 -2
- package/dist/layout/index.js +5 -2
- package/dist/layout/limits.d.ts +40 -0
- package/dist/layout/limits.d.ts.map +1 -0
- package/dist/layout/limits.js +54 -0
- package/dist/layout/limits.js.map +1 -0
- package/dist/layout/sizing.d.ts.map +1 -1
- package/dist/layout/sizing.js +0 -1
- package/dist/layout/sizing.js.map +1 -1
- package/dist/layout/spacing.d.ts +10 -0
- package/dist/layout/spacing.d.ts.map +1 -0
- package/dist/layout/spacing.js +12 -0
- package/dist/layout/spacing.js.map +1 -0
- package/dist/layout/strokes.d.ts +10 -0
- package/dist/layout/strokes.d.ts.map +1 -0
- package/dist/layout/strokes.js +30 -0
- package/dist/layout/strokes.js.map +1 -0
- package/dist/masks.d.ts +28 -0
- package/dist/masks.d.ts.map +1 -0
- package/dist/masks.js +53 -0
- package/dist/masks.js.map +1 -0
- package/dist/matrix.d.ts +2 -1
- package/dist/matrix.d.ts.map +1 -1
- package/dist/matrix.js +14 -1
- package/dist/matrix.js.map +1 -1
- package/dist/node-defaults.d.ts +9 -1
- package/dist/node-defaults.d.ts.map +1 -1
- package/dist/node-defaults.js +65 -38
- package/dist/node-defaults.js.map +1 -1
- package/dist/outline/flatten.d.ts.map +1 -1
- package/dist/outline/flatten.js +24 -17
- package/dist/outline/flatten.js.map +1 -1
- package/dist/outline/hit.d.ts +2 -8
- package/dist/outline/hit.d.ts.map +1 -1
- package/dist/outline/hit.js +16 -25
- package/dist/outline/hit.js.map +1 -1
- package/dist/outline/index.d.ts +3 -3
- package/dist/outline/index.js +3 -3
- package/dist/outline/shapes.d.ts +3 -1
- package/dist/outline/shapes.d.ts.map +1 -1
- package/dist/outline/shapes.js +18 -39
- package/dist/outline/shapes.js.map +1 -1
- package/dist/paints/index.d.ts +3 -1
- package/dist/paints/index.js +3 -1
- package/dist/paints/pattern.d.ts +13 -0
- package/dist/paints/pattern.d.ts.map +1 -0
- package/dist/paints/pattern.js +47 -0
- package/dist/paints/pattern.js.map +1 -0
- package/dist/paints/shows.d.ts +11 -0
- package/dist/paints/shows.d.ts.map +1 -0
- package/dist/paints/shows.js +16 -0
- package/dist/paints/shows.js.map +1 -0
- package/dist/parse-path.d.ts +4 -1
- package/dist/parse-path.d.ts.map +1 -1
- package/dist/parse-path.js +15 -1
- package/dist/parse-path.js.map +1 -1
- package/dist/paths/arc.d.ts +32 -0
- package/dist/paths/arc.d.ts.map +1 -0
- package/dist/paths/arc.js +49 -0
- package/dist/paths/arc.js.map +1 -0
- package/dist/paths/index.d.ts +5 -0
- package/dist/paths/index.js +5 -0
- package/dist/paths/network.d.ts +63 -0
- package/dist/paths/network.d.ts.map +1 -0
- package/dist/paths/network.js +315 -0
- package/dist/paths/network.js.map +1 -0
- package/dist/paths/sink.d.ts +20 -0
- package/dist/paths/sink.d.ts.map +1 -0
- package/dist/paths/sink.js +32 -0
- package/dist/paths/sink.js.map +1 -0
- package/dist/paths/smooth-corners.d.ts +25 -0
- package/dist/paths/smooth-corners.d.ts.map +1 -0
- package/dist/paths/smooth-corners.js +196 -0
- package/dist/paths/smooth-corners.js.map +1 -0
- package/dist/plugin-data/fields.d.ts +4 -0
- package/dist/plugin-data/fields.d.ts.map +1 -1
- package/dist/plugin-data/fields.js +2 -0
- package/dist/plugin-data/fields.js.map +1 -1
- package/dist/polygon.d.ts +1 -3
- package/dist/polygon.d.ts.map +1 -1
- package/dist/polygon.js +1 -16
- package/dist/polygon.js.map +1 -1
- package/dist/primitives/index.d.ts +1 -7
- package/dist/primitives/index.d.ts.map +1 -1
- package/dist/resize.d.ts.map +1 -1
- package/dist/resize.js +5 -5
- package/dist/resize.js.map +1 -1
- package/dist/scaling/node.d.ts.map +1 -1
- package/dist/scaling/node.js +25 -3
- package/dist/scaling/node.js.map +1 -1
- package/dist/shaders/model.d.ts.map +1 -1
- package/dist/shaders/model.js +1 -1
- package/dist/shaders/model.js.map +1 -1
- package/dist/shared-styles.d.ts.map +1 -1
- package/dist/shared-styles.js +2 -9
- package/dist/shared-styles.js.map +1 -1
- package/dist/strokes.d.ts +39 -0
- package/dist/strokes.d.ts.map +1 -0
- package/dist/strokes.js +104 -0
- package/dist/strokes.js.map +1 -0
- package/dist/text/auto-resize.d.ts +15 -0
- package/dist/text/auto-resize.d.ts.map +1 -0
- package/dist/text/auto-resize.js +23 -0
- package/dist/text/auto-resize.js.map +1 -0
- package/dist/text/index.d.ts +5 -3
- package/dist/text/index.js +5 -3
- package/dist/text/lengths.d.ts +6 -1
- package/dist/text/lengths.d.ts.map +1 -1
- package/dist/text/lengths.js +10 -1
- package/dist/text/lengths.js.map +1 -1
- package/dist/text/overflow.d.ts +14 -5
- package/dist/text/overflow.d.ts.map +1 -1
- package/dist/text/overflow.js +24 -6
- package/dist/text/overflow.js.map +1 -1
- package/dist/text/path.js +10 -0
- package/dist/text/path.js.map +1 -0
- package/dist/text/picture.js +5 -5
- package/dist/text/picture.js.map +1 -1
- package/dist/text/runs.d.ts +29 -0
- package/dist/text/runs.d.ts.map +1 -0
- package/dist/text/runs.js +72 -0
- package/dist/text/runs.js.map +1 -0
- package/dist/transfer/dependencies.d.ts.map +1 -1
- package/dist/transfer/dependencies.js +3 -2
- package/dist/transfer/dependencies.js.map +1 -1
- package/dist/transfer/nodes.js +2 -1
- package/dist/transfer/nodes.js.map +1 -1
- package/dist/types.d.ts +56 -10
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/variables/index.d.ts +4 -3
- package/dist/variables/index.d.ts.map +1 -1
- package/dist/variables/index.js +4 -3
- package/dist/variables/index.js.map +1 -1
- package/dist/variables/lookup.d.ts +20 -0
- package/dist/variables/lookup.d.ts.map +1 -0
- package/dist/variables/lookup.js +34 -0
- package/dist/variables/lookup.js.map +1 -0
- package/dist/variables/paints.d.ts +35 -4
- package/dist/variables/paints.d.ts.map +1 -1
- package/dist/variables/paints.js +67 -16
- package/dist/variables/paints.js.map +1 -1
- package/dist/variables/resolution.d.ts +3 -1
- package/dist/variables/resolution.d.ts.map +1 -1
- package/dist/variables/resolution.js +8 -3
- package/dist/variables/resolution.js.map +1 -1
- package/dist/variables/subtree.js +1 -1
- package/dist/variables/subtree.js.map +1 -1
- package/dist/vector-network.d.ts.map +1 -1
- package/dist/vector-network.js +13 -79
- package/dist/vector-network.js.map +1 -1
- package/package.json +28 -7
- package/src/buffered-events.ts +2 -1
- package/src/clipping.ts +11 -8
- package/src/comments/schema.ts +1 -0
- package/src/comments/threads.ts +13 -5
- package/src/components/properties.ts +3 -14
- package/src/constants.ts +25 -1
- package/src/copy.ts +2 -0
- package/src/corners.ts +93 -0
- package/src/css/grid.ts +49 -7
- package/src/css/index.ts +13 -2
- package/src/css/layout.ts +36 -0
- package/src/css/values.ts +49 -0
- package/src/font-style.ts +38 -4
- package/src/geometry.ts +223 -28
- package/src/gradient.ts +23 -1
- package/src/graph.ts +35 -10
- package/src/group-bounds.ts +7 -3
- package/src/guides.ts +26 -1
- package/src/hit-test.ts +68 -10
- package/src/icons/fit.ts +24 -0
- package/src/icons/glyph.ts +6 -4
- package/src/icons/index.ts +1 -0
- package/src/ids.ts +1 -1
- package/src/images.ts +67 -7
- package/src/instances/assignments.ts +65 -7
- package/src/instances/index.ts +77 -13
- package/src/instances/kept-overrides.ts +2 -5
- package/src/instances/matching.ts +101 -0
- package/src/instances/overrides.ts +18 -0
- package/src/instances/protection.ts +103 -0
- package/src/instances/swap.ts +12 -9
- package/src/instances/sync.ts +52 -184
- package/src/layout/guides.ts +42 -9
- package/src/layout/index.ts +3 -0
- package/src/layout/limits.ts +64 -0
- package/src/layout/sizing.ts +0 -2
- package/src/layout/spacing.ts +11 -0
- package/src/layout/strokes.ts +23 -0
- package/src/masks.ts +51 -0
- package/src/matrix.ts +15 -2
- package/src/node-defaults.ts +71 -36
- package/src/outline/flatten.ts +31 -18
- package/src/outline/hit.ts +16 -33
- package/src/outline/index.ts +2 -2
- package/src/outline/shapes.ts +19 -36
- package/src/paints/index.ts +2 -0
- package/src/paints/pattern.ts +45 -0
- package/src/paints/shows.ts +13 -0
- package/src/parse-path.ts +14 -0
- package/src/paths/arc.ts +59 -0
- package/src/paths/index.ts +4 -0
- package/src/paths/network.ts +411 -0
- package/src/paths/sink.ts +50 -0
- package/src/paths/smooth-corners.ts +357 -0
- package/src/plugin-data/fields.ts +2 -0
- package/src/polygon.ts +0 -17
- package/src/primitives/index.ts +0 -5
- package/src/resize.ts +6 -7
- package/src/scaling/node.ts +29 -3
- package/src/shaders/model.ts +2 -1
- package/src/shared-styles.ts +3 -4
- package/src/strokes.ts +121 -0
- package/src/text/auto-resize.ts +25 -0
- package/src/text/index.ts +2 -0
- package/src/text/lengths.ts +11 -0
- package/src/text/overflow.ts +32 -6
- package/src/text/path.ts +13 -0
- package/src/text/picture.ts +5 -5
- package/src/text/runs.ts +80 -0
- package/src/transfer/dependencies.ts +4 -2
- package/src/transfer/nodes.ts +2 -1
- package/src/types.ts +62 -8
- package/src/variables/index.ts +1 -0
- package/src/variables/lookup.ts +31 -0
- package/src/variables/paints.ts +101 -20
- package/src/variables/resolution.ts +15 -2
- package/src/variables/subtree.ts +1 -1
- package/src/vector-network.ts +19 -142
- package/dist/random.d.ts +0 -7
- package/dist/random.d.ts.map +0 -1
- package/dist/random.js +0 -25
- package/dist/random.js.map +0 -1
- package/src/random.ts +0 -28
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//#region src/layout/strokes.ts
|
|
2
|
+
/**
|
|
3
|
+
* The stroke a frame counts inside its padding, per side: its visible INSIDE strokes when its
|
|
4
|
+
* strokes are included in layout, as Figma lays it out and as a CSS border takes room.
|
|
5
|
+
*/
|
|
6
|
+
function includedStrokeWeights(node) {
|
|
7
|
+
const stroke = node.strokes.find((paint) => paint.visible);
|
|
8
|
+
if (!node.strokesIncludedInLayout || stroke?.align !== "INSIDE") return {
|
|
9
|
+
top: 0,
|
|
10
|
+
right: 0,
|
|
11
|
+
bottom: 0,
|
|
12
|
+
left: 0
|
|
13
|
+
};
|
|
14
|
+
if (!node.independentStrokeWeights) return {
|
|
15
|
+
top: stroke.weight,
|
|
16
|
+
right: stroke.weight,
|
|
17
|
+
bottom: stroke.weight,
|
|
18
|
+
left: stroke.weight
|
|
19
|
+
};
|
|
20
|
+
return {
|
|
21
|
+
top: node.borderTopWeight,
|
|
22
|
+
right: node.borderRightWeight,
|
|
23
|
+
bottom: node.borderBottomWeight,
|
|
24
|
+
left: node.borderLeftWeight
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { includedStrokeWeights };
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=strokes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strokes.js","names":[],"sources":["../../src/layout/strokes.ts"],"sourcesContent":["import type { SceneNode } from '../types'\n\n/**\n * The stroke a frame counts inside its padding, per side: its visible INSIDE strokes when its\n * strokes are included in layout, as Figma lays it out and as a CSS border takes room.\n */\nexport function includedStrokeWeights(\n node: SceneNode\n): Record<'top' | 'right' | 'bottom' | 'left', number> {\n const stroke = node.strokes.find((paint) => paint.visible)\n if (!node.strokesIncludedInLayout || stroke?.align !== 'INSIDE') {\n return { top: 0, right: 0, bottom: 0, left: 0 }\n }\n if (!node.independentStrokeWeights) {\n return { top: stroke.weight, right: stroke.weight, bottom: stroke.weight, left: stroke.weight }\n }\n return {\n top: node.borderTopWeight,\n right: node.borderRightWeight,\n bottom: node.borderBottomWeight,\n left: node.borderLeftWeight\n }\n}\n"],"mappings":";;;;;AAMA,SAAgB,sBACd,MACqD;CACrD,MAAM,SAAS,KAAK,QAAQ,MAAM,UAAU,MAAM,OAAO;CACzD,IAAI,CAAC,KAAK,2BAA2B,QAAQ,UAAU,UACrD,OAAO;EAAE,KAAK;EAAG,OAAO;EAAG,QAAQ;EAAG,MAAM;CAAE;CAEhD,IAAI,CAAC,KAAK,0BACR,OAAO;EAAE,KAAK,OAAO;EAAQ,OAAO,OAAO;EAAQ,QAAQ,OAAO;EAAQ,MAAM,OAAO;CAAO;CAEhG,OAAO;EACL,KAAK,KAAK;EACV,OAAO,KAAK;EACZ,QAAQ,KAAK;EACb,MAAM,KAAK;CACb;AACF"}
|
package/dist/masks.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { SceneNode } from "./types.js";
|
|
2
|
+
//#region src/masks.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* The layer as it masks: an outline mask masks with its shape alone, so Figma ignores how opaque
|
|
5
|
+
* its fills are, and the canvas and hit testing take them as opaque.
|
|
6
|
+
*/
|
|
7
|
+
declare function asMaskShape(node: SceneNode): SceneNode;
|
|
8
|
+
/** Whether a layer masks its siblings: a mask that is shown, since a hidden mask masks nothing. */
|
|
9
|
+
declare function isVisibleMask(node: Pick<SceneNode, 'visible' | 'isMask'>): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* A run of masks and the siblings they mask, as indices into the children: the masks are
|
|
12
|
+
* `[start, maskedStart)` and what they mask `[maskedStart, end)`, which may be empty.
|
|
13
|
+
*/
|
|
14
|
+
interface MaskRun {
|
|
15
|
+
readonly start: number;
|
|
16
|
+
readonly maskedStart: number;
|
|
17
|
+
readonly end: number;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Where masks act among a container's children, bottom to top. A visible mask, with the visible
|
|
21
|
+
* masks right after it, masks every sibling after them up to the next visible mask, which starts
|
|
22
|
+
* a run of its own; a sibling that is hidden or a hidden mask is masked like any other (Figma
|
|
23
|
+
* desktop, live). Children before the first mask are not in any run.
|
|
24
|
+
*/
|
|
25
|
+
declare function maskRuns<T>(children: readonly T[], isMask: (child: T) => boolean): MaskRun[];
|
|
26
|
+
//#endregion
|
|
27
|
+
export { MaskRun, asMaskShape, isVisibleMask, maskRuns };
|
|
28
|
+
//# sourceMappingURL=masks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"masks.d.ts","names":[],"sources":["../src/masks.ts"],"mappings":";;;;;;iBAMgB,YAAY,MAAM,YAAY;;iBAS9B,cAAc,MAAM,KAAK;;;;;UAQxB;WACN;WACA;WACA;;;;;;;;iBASK,SAAS,GAAG,mBAAmB,KAAK,SAAS,OAAO,gBAAgB"}
|
package/dist/masks.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
//#region src/masks.ts
|
|
2
|
+
/**
|
|
3
|
+
* The layer as it masks: an outline mask masks with its shape alone, so Figma ignores how opaque
|
|
4
|
+
* its fills are, and the canvas and hit testing take them as opaque.
|
|
5
|
+
*/
|
|
6
|
+
function asMaskShape(node) {
|
|
7
|
+
if (node.maskType !== "VECTOR") return node;
|
|
8
|
+
return {
|
|
9
|
+
...node,
|
|
10
|
+
fills: node.fills.map((fill) => ({
|
|
11
|
+
...fill,
|
|
12
|
+
opacity: 1,
|
|
13
|
+
color: {
|
|
14
|
+
...fill.color,
|
|
15
|
+
a: 1
|
|
16
|
+
}
|
|
17
|
+
}))
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/** Whether a layer masks its siblings: a mask that is shown, since a hidden mask masks nothing. */
|
|
21
|
+
function isVisibleMask(node) {
|
|
22
|
+
return node.visible && node.isMask;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Where masks act among a container's children, bottom to top. A visible mask, with the visible
|
|
26
|
+
* masks right after it, masks every sibling after them up to the next visible mask, which starts
|
|
27
|
+
* a run of its own; a sibling that is hidden or a hidden mask is masked like any other (Figma
|
|
28
|
+
* desktop, live). Children before the first mask are not in any run.
|
|
29
|
+
*/
|
|
30
|
+
function maskRuns(children, isMask) {
|
|
31
|
+
const runs = [];
|
|
32
|
+
let index = 0;
|
|
33
|
+
while (index < children.length) {
|
|
34
|
+
if (!isMask(children[index])) {
|
|
35
|
+
index++;
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
const start = index;
|
|
39
|
+
while (index < children.length && isMask(children[index])) index++;
|
|
40
|
+
const maskedStart = index;
|
|
41
|
+
while (index < children.length && !isMask(children[index])) index++;
|
|
42
|
+
runs.push({
|
|
43
|
+
start,
|
|
44
|
+
maskedStart,
|
|
45
|
+
end: index
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return runs;
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
51
|
+
export { asMaskShape, isVisibleMask, maskRuns };
|
|
52
|
+
|
|
53
|
+
//# sourceMappingURL=masks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"masks.js","names":[],"sources":["../src/masks.ts"],"sourcesContent":["import type { SceneNode } from './types'\n\n/**\n * The layer as it masks: an outline mask masks with its shape alone, so Figma ignores how opaque\n * its fills are, and the canvas and hit testing take them as opaque.\n */\nexport function asMaskShape(node: SceneNode): SceneNode {\n if (node.maskType !== 'VECTOR') return node\n return {\n ...node,\n fills: node.fills.map((fill) => ({ ...fill, opacity: 1, color: { ...fill.color, a: 1 } }))\n }\n}\n\n/** Whether a layer masks its siblings: a mask that is shown, since a hidden mask masks nothing. */\nexport function isVisibleMask(node: Pick<SceneNode, 'visible' | 'isMask'>): boolean {\n return node.visible && node.isMask\n}\n\n/**\n * A run of masks and the siblings they mask, as indices into the children: the masks are\n * `[start, maskedStart)` and what they mask `[maskedStart, end)`, which may be empty.\n */\nexport interface MaskRun {\n readonly start: number\n readonly maskedStart: number\n readonly end: number\n}\n\n/**\n * Where masks act among a container's children, bottom to top. A visible mask, with the visible\n * masks right after it, masks every sibling after them up to the next visible mask, which starts\n * a run of its own; a sibling that is hidden or a hidden mask is masked like any other (Figma\n * desktop, live). Children before the first mask are not in any run.\n */\nexport function maskRuns<T>(children: readonly T[], isMask: (child: T) => boolean): MaskRun[] {\n const runs: MaskRun[] = []\n let index = 0\n while (index < children.length) {\n if (!isMask(children[index])) {\n index++\n continue\n }\n const start = index\n while (index < children.length && isMask(children[index])) index++\n const maskedStart = index\n while (index < children.length && !isMask(children[index])) index++\n runs.push({ start, maskedStart, end: index })\n }\n return runs\n}\n"],"mappings":";;;;;AAMA,SAAgB,YAAY,MAA4B;CACtD,IAAI,KAAK,aAAa,UAAU,OAAO;CACvC,OAAO;EACL,GAAG;EACH,OAAO,KAAK,MAAM,KAAK,UAAU;GAAE,GAAG;GAAM,SAAS;GAAG,OAAO;IAAE,GAAG,KAAK;IAAO,GAAG;GAAE;EAAE,EAAE;CAC3F;AACF;;AAGA,SAAgB,cAAc,MAAsD;CAClF,OAAO,KAAK,WAAW,KAAK;AAC9B;;;;;;;AAkBA,SAAgB,SAAY,UAAwB,QAA0C;CAC5F,MAAM,OAAkB,CAAC;CACzB,IAAI,QAAQ;CACZ,OAAO,QAAQ,SAAS,QAAQ;EAC9B,IAAI,CAAC,OAAO,SAAS,MAAM,GAAG;GAC5B;GACA;EACF;EACA,MAAM,QAAQ;EACd,OAAO,QAAQ,SAAS,UAAU,OAAO,SAAS,MAAM,GAAG;EAC3D,MAAM,cAAc;EACpB,OAAO,QAAQ,SAAS,UAAU,CAAC,OAAO,SAAS,MAAM,GAAG;EAC5D,KAAK,KAAK;GAAE;GAAO;GAAa,KAAK;EAAM,CAAC;CAC9C;CACA,OAAO;AACT"}
|
package/dist/matrix.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Vector } from "./primitives/index.js";
|
|
1
|
+
import { Matrix as Matrix$1, Vector } from "./primitives/index.js";
|
|
2
2
|
//#region src/matrix.d.ts
|
|
3
3
|
type Mat3 = number[];
|
|
4
4
|
declare const Matrix: {
|
|
@@ -10,6 +10,7 @@ declare const Matrix: {
|
|
|
10
10
|
invert: (m: Mat3) => Mat3 | null;
|
|
11
11
|
mapPoints: (matrix: Mat3, ptArr: number[]) => number[];
|
|
12
12
|
mapPoint: (m: Mat3, p: Vector) => Vector;
|
|
13
|
+
fromAffine: (t: Matrix$1) => Mat3;
|
|
13
14
|
};
|
|
14
15
|
//#endregion
|
|
15
16
|
export { Mat3, Matrix as default };
|
package/dist/matrix.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"matrix.d.ts","names":[],"sources":["../src/matrix.ts"],"mappings":";;KAEY;
|
|
1
|
+
{"version":3,"file":"matrix.d.ts","names":[],"sources":["../src/matrix.ts"],"mappings":";;KAEY;cAmHN;EAjHe,gBAAA;EAmBI,cAAA,IAAA,WAAS;EAOV,aAAA,YAAM,eAAe;EAEnB,UAAA,iBAAM,aAAA,gBAAmB;EAmB/B,SAAA,YAAM,YAAY,aAAA,gBAAmB;EAiBtC,SAAA,GAAA,SAAO;EA0BC,YAAA,QAAA,MAAI;EAeV,WAAA,GAAA,MAAI,GAAK,WAAS;EAMhB,aAAA,GAAA,aAAkB"}
|
package/dist/matrix.js
CHANGED
|
@@ -104,6 +104,18 @@ const mapPoint = (m, p) => {
|
|
|
104
104
|
y: arr[1]
|
|
105
105
|
};
|
|
106
106
|
};
|
|
107
|
+
/** A 2 × 3 affine transform, as Figma stores gradient and image transforms, as a 3 × 3 matrix. */
|
|
108
|
+
const fromAffine = (t) => [
|
|
109
|
+
t.m00,
|
|
110
|
+
t.m01,
|
|
111
|
+
t.m02,
|
|
112
|
+
t.m10,
|
|
113
|
+
t.m11,
|
|
114
|
+
t.m12,
|
|
115
|
+
0,
|
|
116
|
+
0,
|
|
117
|
+
1
|
|
118
|
+
];
|
|
107
119
|
const Matrix = {
|
|
108
120
|
identity,
|
|
109
121
|
multiply,
|
|
@@ -112,7 +124,8 @@ const Matrix = {
|
|
|
112
124
|
scaled,
|
|
113
125
|
invert,
|
|
114
126
|
mapPoints,
|
|
115
|
-
mapPoint
|
|
127
|
+
mapPoint,
|
|
128
|
+
fromAffine
|
|
116
129
|
};
|
|
117
130
|
//#endregion
|
|
118
131
|
export { Matrix as default };
|
package/dist/matrix.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"matrix.js","names":[],"sources":["../src/matrix.ts"],"sourcesContent":["import type { Vector } from './primitives'\n\nexport type Mat3 = number[]\n\nconst identity = (): Mat3 => [1, 0, 0, 0, 1, 0, 0, 0, 1]\n\nconst multiply2 = (m1: Mat3, m2: Mat3): Mat3 => {\n // row-major general 3x3 multiply: out = m1 * m2\n return [\n m1[0] * m2[0] + m1[1] * m2[3] + m1[2] * m2[6],\n m1[0] * m2[1] + m1[1] * m2[4] + m1[2] * m2[7],\n m1[0] * m2[2] + m1[1] * m2[5] + m1[2] * m2[8],\n\n m1[3] * m2[0] + m1[4] * m2[3] + m1[5] * m2[6],\n m1[3] * m2[1] + m1[4] * m2[4] + m1[5] * m2[7],\n m1[3] * m2[2] + m1[4] * m2[5] + m1[5] * m2[8],\n\n m1[6] * m2[0] + m1[7] * m2[3] + m1[8] * m2[6],\n m1[6] * m2[1] + m1[7] * m2[4] + m1[8] * m2[7],\n m1[6] * m2[2] + m1[7] * m2[5] + m1[8] * m2[8]\n ]\n}\n\nconst multiply = (...ms: Mat3[]): Mat3 => {\n if (ms.length === 0) return identity()\n let out = ms[0].slice()\n for (let i = 1; i < ms.length; i++) out = multiply2(out, ms[i])\n return out\n}\n\nconst translated = (dx: number, dy: number): Mat3 => [1, 0, dx, 0, 1, dy, 0, 0, 1]\n\nconst rotated = (radians: number, px = 0, py = 0): Mat3 => {\n const s = Math.sin(radians)\n const c = Math.cos(radians)\n // exactly like ck.Matrix.rotated\n return [\n c,\n -s,\n s * py + (1 - c) * px,\n\n s,\n c,\n -s * px + (1 - c) * py,\n\n 0,\n 0,\n 1\n ]\n}\n\nconst scaled = (sx: number, sy: number, px = 0, py = 0): Mat3 => {\n // match ck.Matrix.scaled\n return [\n sx,\n 0,\n px - sx * px,\n\n 0,\n sy,\n py - sy * py,\n\n 0,\n 0,\n 1\n ]\n}\n\nconst invert = (m: Mat3): Mat3 | null => {\n // match ck.Matrix.invert (Sarrus)\n const det =\n m[0] * m[4] * m[8] +\n m[1] * m[5] * m[6] +\n m[2] * m[3] * m[7] -\n m[2] * m[4] * m[6] -\n m[1] * m[3] * m[8] -\n m[0] * m[5] * m[7]\n if (!det) return null\n\n return [\n (m[4] * m[8] - m[5] * m[7]) / det,\n (m[2] * m[7] - m[1] * m[8]) / det,\n (m[1] * m[5] - m[2] * m[4]) / det,\n\n (m[5] * m[6] - m[3] * m[8]) / det,\n (m[0] * m[8] - m[2] * m[6]) / det,\n (m[2] * m[3] - m[0] * m[5]) / det,\n\n (m[3] * m[7] - m[4] * m[6]) / det,\n (m[1] * m[6] - m[0] * m[7]) / det,\n (m[0] * m[4] - m[1] * m[3]) / det\n ]\n}\n\nconst mapPoints = (matrix: Mat3, ptArr: number[]): number[] => {\n if (ptArr.length % 2) throw new Error('mapPoints requires even length [x,y,...].')\n const out = ptArr.slice()\n for (let i = 0; i < out.length; i += 2) {\n const x = out[i]\n const y = out[i + 1]\n const denom = matrix[6] * x + matrix[7] * y + matrix[8]\n const xTrans = matrix[0] * x + matrix[1] * y + matrix[2]\n const yTrans = matrix[3] * x + matrix[4] * y + matrix[5]\n out[i] = xTrans / denom\n out[i + 1] = yTrans / denom\n }\n return out\n}\n\nconst mapPoint = (m: Mat3, p: Vector): Vector => {\n const arr = mapPoints(m, [p.x, p.y])\n return { x: arr[0], y: arr[1] }\n}\n\nconst
|
|
1
|
+
{"version":3,"file":"matrix.js","names":[],"sources":["../src/matrix.ts"],"sourcesContent":["import type { Matrix as AffineTransform, Vector } from './primitives'\n\nexport type Mat3 = number[]\n\nconst identity = (): Mat3 => [1, 0, 0, 0, 1, 0, 0, 0, 1]\n\nconst multiply2 = (m1: Mat3, m2: Mat3): Mat3 => {\n // row-major general 3x3 multiply: out = m1 * m2\n return [\n m1[0] * m2[0] + m1[1] * m2[3] + m1[2] * m2[6],\n m1[0] * m2[1] + m1[1] * m2[4] + m1[2] * m2[7],\n m1[0] * m2[2] + m1[1] * m2[5] + m1[2] * m2[8],\n\n m1[3] * m2[0] + m1[4] * m2[3] + m1[5] * m2[6],\n m1[3] * m2[1] + m1[4] * m2[4] + m1[5] * m2[7],\n m1[3] * m2[2] + m1[4] * m2[5] + m1[5] * m2[8],\n\n m1[6] * m2[0] + m1[7] * m2[3] + m1[8] * m2[6],\n m1[6] * m2[1] + m1[7] * m2[4] + m1[8] * m2[7],\n m1[6] * m2[2] + m1[7] * m2[5] + m1[8] * m2[8]\n ]\n}\n\nconst multiply = (...ms: Mat3[]): Mat3 => {\n if (ms.length === 0) return identity()\n let out = ms[0].slice()\n for (let i = 1; i < ms.length; i++) out = multiply2(out, ms[i])\n return out\n}\n\nconst translated = (dx: number, dy: number): Mat3 => [1, 0, dx, 0, 1, dy, 0, 0, 1]\n\nconst rotated = (radians: number, px = 0, py = 0): Mat3 => {\n const s = Math.sin(radians)\n const c = Math.cos(radians)\n // exactly like ck.Matrix.rotated\n return [\n c,\n -s,\n s * py + (1 - c) * px,\n\n s,\n c,\n -s * px + (1 - c) * py,\n\n 0,\n 0,\n 1\n ]\n}\n\nconst scaled = (sx: number, sy: number, px = 0, py = 0): Mat3 => {\n // match ck.Matrix.scaled\n return [\n sx,\n 0,\n px - sx * px,\n\n 0,\n sy,\n py - sy * py,\n\n 0,\n 0,\n 1\n ]\n}\n\nconst invert = (m: Mat3): Mat3 | null => {\n // match ck.Matrix.invert (Sarrus)\n const det =\n m[0] * m[4] * m[8] +\n m[1] * m[5] * m[6] +\n m[2] * m[3] * m[7] -\n m[2] * m[4] * m[6] -\n m[1] * m[3] * m[8] -\n m[0] * m[5] * m[7]\n if (!det) return null\n\n return [\n (m[4] * m[8] - m[5] * m[7]) / det,\n (m[2] * m[7] - m[1] * m[8]) / det,\n (m[1] * m[5] - m[2] * m[4]) / det,\n\n (m[5] * m[6] - m[3] * m[8]) / det,\n (m[0] * m[8] - m[2] * m[6]) / det,\n (m[2] * m[3] - m[0] * m[5]) / det,\n\n (m[3] * m[7] - m[4] * m[6]) / det,\n (m[1] * m[6] - m[0] * m[7]) / det,\n (m[0] * m[4] - m[1] * m[3]) / det\n ]\n}\n\nconst mapPoints = (matrix: Mat3, ptArr: number[]): number[] => {\n if (ptArr.length % 2) throw new Error('mapPoints requires even length [x,y,...].')\n const out = ptArr.slice()\n for (let i = 0; i < out.length; i += 2) {\n const x = out[i]\n const y = out[i + 1]\n const denom = matrix[6] * x + matrix[7] * y + matrix[8]\n const xTrans = matrix[0] * x + matrix[1] * y + matrix[2]\n const yTrans = matrix[3] * x + matrix[4] * y + matrix[5]\n out[i] = xTrans / denom\n out[i + 1] = yTrans / denom\n }\n return out\n}\n\nconst mapPoint = (m: Mat3, p: Vector): Vector => {\n const arr = mapPoints(m, [p.x, p.y])\n return { x: arr[0], y: arr[1] }\n}\n\n/** A 2 × 3 affine transform, as Figma stores gradient and image transforms, as a 3 × 3 matrix. */\nconst fromAffine = (t: AffineTransform): Mat3 => [t.m00, t.m01, t.m02, t.m10, t.m11, t.m12, 0, 0, 1]\n\nconst Matrix = {\n identity,\n multiply,\n translated,\n rotated,\n scaled,\n invert,\n mapPoints,\n mapPoint,\n fromAffine\n}\nexport default Matrix\n"],"mappings":";AAIA,MAAM,iBAAuB;CAAC;CAAG;CAAG;CAAG;CAAG;CAAG;CAAG;CAAG;CAAG;AAAC;AAEvD,MAAM,aAAa,IAAU,OAAmB;CAE9C,OAAO;EACL,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG;EAC3C,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG;EAC3C,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG;EAE3C,GAAG,KAAK,GAAG,KAAK,GAAG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MAAM,MAAM,UAAU,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;CACnC,OAAO;EAAE,GAAG,IAAI;EAAI,GAAG,IAAI;CAAG;AAChC;;AAGA,MAAM,cAAc,MAA6B;CAAC,EAAE;CAAK,EAAE;CAAK,EAAE;CAAK,EAAE;CAAK,EAAE;CAAK,EAAE;CAAK;CAAG;CAAG;AAAC;AAEnG,MAAM,SAAS;CACb;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF"}
|
package/dist/node-defaults.d.ts
CHANGED
|
@@ -16,7 +16,15 @@ declare const SIDE_STROKE_TYPES: ReadonlySet<NodeType>;
|
|
|
16
16
|
/** The kinds that hold layers of their own on the canvas: what a shadow or a clip encloses. */
|
|
17
17
|
declare const LAYER_CONTAINER_TYPES: ReadonlySet<NodeType>;
|
|
18
18
|
declare function isLayerContainer(node: Pick<SceneNode, 'type'>): boolean;
|
|
19
|
+
/** The kinds that clip their children when their clip content is on. */
|
|
20
|
+
declare const CLIPPING_TYPES: ReadonlySet<NodeType>;
|
|
21
|
+
/**
|
|
22
|
+
* Whether a layer clips its children: a frame, component, component set or instance with clip
|
|
23
|
+
* content on. A section or group has no such setting in Figma and never clips, whatever an import
|
|
24
|
+
* left in `clipsContent` (Figma desktop, live).
|
|
25
|
+
*/
|
|
26
|
+
declare function clipsChildren(node: Pick<SceneNode, 'type' | 'clipsContent'>): boolean;
|
|
19
27
|
declare const CONTAINER_TYPES: Set<NodeType>;
|
|
20
28
|
//#endregion
|
|
21
|
-
export { CONTAINER_TYPES, FITTED_CONTAINER_TYPES, LAYER_CONTAINER_TYPES, SIDE_STROKE_TYPES, createDefaultNode, createDefaultSourceMetadata, defaultStrokeAlign, isLayerContainer, newStrokeGeometry };
|
|
29
|
+
export { CLIPPING_TYPES, CONTAINER_TYPES, FITTED_CONTAINER_TYPES, LAYER_CONTAINER_TYPES, SIDE_STROKE_TYPES, clipsChildren, createDefaultNode, createDefaultSourceMetadata, defaultStrokeAlign, isLayerContainer, newStrokeGeometry };
|
|
22
30
|
//# sourceMappingURL=node-defaults.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-defaults.d.ts","names":[],"sources":["../src/node-defaults.ts"],"mappings":";;iBAUgB,+BAA+B;;iBA4B/B,mBAAmB,MAAM,WAAW;;;;;iBASpC,kBACd,MAAM,KAAK,yDACV,KAAK;
|
|
1
|
+
{"version":3,"file":"node-defaults.d.ts","names":[],"sources":["../src/node-defaults.ts"],"mappings":";;iBAUgB,+BAA+B;;iBA4B/B,mBAAmB,MAAM,WAAW;;;;;iBASpC,kBACd,MAAM,KAAK,yDACV,KAAK;iBAoBQ,kBACd,0BACA,MAAM,UACN,YAAW,QAAQ,aAClB;;cAsLU,wBAAwB,YAAY;;cAMpC,mBAAmB,YAAY;;cAS/B,uBAAuB,YAAY;iBAShC,iBAAiB,MAAM,KAAK;;cAK/B,gBAAgB,YAAY;;;;;;iBAYzB,cAAc,MAAM,KAAK;cAI5B,iBAAe,IAAA"}
|
package/dist/node-defaults.js
CHANGED
|
@@ -37,30 +37,42 @@ function newStrokeGeometry(node) {
|
|
|
37
37
|
align: first?.align ?? node.strokeAlign
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
|
+
/** A caller's list, or a fresh empty one: a list default belongs to the one layer it was made for. */
|
|
41
|
+
function ownList(given) {
|
|
42
|
+
return given ?? [];
|
|
43
|
+
}
|
|
44
|
+
/** A caller's record, or a fresh empty one, for the same reason. */
|
|
45
|
+
function ownRecord(given) {
|
|
46
|
+
return given ?? {};
|
|
47
|
+
}
|
|
48
|
+
/** A new layer's fills: black on text, none elsewhere. */
|
|
49
|
+
function defaultFills(type) {
|
|
50
|
+
return type === "TEXT" ? [{
|
|
51
|
+
type: "SOLID",
|
|
52
|
+
color: BLACK,
|
|
53
|
+
opacity: 1,
|
|
54
|
+
visible: true
|
|
55
|
+
}] : [];
|
|
56
|
+
}
|
|
40
57
|
function createDefaultNode(generateId, type, overrides = {}) {
|
|
41
58
|
return {
|
|
42
59
|
id: generateId(),
|
|
43
60
|
type,
|
|
44
61
|
name: type.charAt(0) + type.slice(1).toLowerCase(),
|
|
45
62
|
parentId: null,
|
|
46
|
-
childIds:
|
|
63
|
+
childIds: ownList(overrides.childIds),
|
|
47
64
|
x: 0,
|
|
48
65
|
y: 0,
|
|
49
66
|
width: 100,
|
|
50
67
|
height: 100,
|
|
51
68
|
rotation: 0,
|
|
52
|
-
source: createDefaultSourceMetadata(),
|
|
69
|
+
source: overrides.source ?? createDefaultSourceMetadata(),
|
|
53
70
|
derivedLayout: null,
|
|
54
|
-
fills:
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}] : [],
|
|
60
|
-
strokes: [],
|
|
61
|
-
effects: [],
|
|
62
|
-
layoutGrids: [],
|
|
63
|
-
guides: [],
|
|
71
|
+
fills: overrides.fills ?? defaultFills(type),
|
|
72
|
+
strokes: ownList(overrides.strokes),
|
|
73
|
+
effects: ownList(overrides.effects),
|
|
74
|
+
layoutGrids: ownList(overrides.layoutGrids),
|
|
75
|
+
guides: ownList(overrides.guides),
|
|
64
76
|
fillStyleId: null,
|
|
65
77
|
strokeStyleId: null,
|
|
66
78
|
textStyleId: null,
|
|
@@ -109,8 +121,8 @@ function createDefaultNode(generateId, type, overrides = {}) {
|
|
|
109
121
|
layoutAlignSelf: "AUTO",
|
|
110
122
|
vectorNetwork: null,
|
|
111
123
|
handleMirroring: "NONE",
|
|
112
|
-
fillGeometry:
|
|
113
|
-
strokeGeometry:
|
|
124
|
+
fillGeometry: ownList(overrides.fillGeometry),
|
|
125
|
+
strokeGeometry: ownList(overrides.strokeGeometry),
|
|
114
126
|
arcData: null,
|
|
115
127
|
textAlignVertical: "TOP",
|
|
116
128
|
textAutoResize: "NONE",
|
|
@@ -118,24 +130,24 @@ function createDefaultNode(generateId, type, overrides = {}) {
|
|
|
118
130
|
textDecoration: "NONE",
|
|
119
131
|
textDecorationStyle: "SOLID",
|
|
120
132
|
textDecorationThickness: null,
|
|
121
|
-
textDecorationFills:
|
|
133
|
+
textDecorationFills: ownList(overrides.textDecorationFills),
|
|
122
134
|
textDecorationSkipInk: true,
|
|
123
135
|
textUnderlineOffset: null,
|
|
124
136
|
maxLines: null,
|
|
125
|
-
textParagraphs:
|
|
137
|
+
textParagraphs: ownList(overrides.textParagraphs),
|
|
126
138
|
listSpacing: 0,
|
|
127
139
|
paragraphSpacing: 0,
|
|
128
140
|
paragraphIndent: 0,
|
|
129
141
|
hangingList: false,
|
|
130
|
-
styleRuns:
|
|
131
|
-
fontVariations:
|
|
142
|
+
styleRuns: ownList(overrides.styleRuns),
|
|
143
|
+
fontVariations: ownList(overrides.fontVariations),
|
|
132
144
|
opticalSizeFromFontSize: true,
|
|
133
|
-
fontFeatures:
|
|
145
|
+
fontFeatures: ownList(overrides.fontFeatures),
|
|
134
146
|
horizontalConstraint: "MIN",
|
|
135
147
|
verticalConstraint: "MIN",
|
|
136
148
|
strokeCap: "NONE",
|
|
137
149
|
strokeJoin: "MITER",
|
|
138
|
-
dashPattern:
|
|
150
|
+
dashPattern: ownList(overrides.dashPattern),
|
|
139
151
|
borderTopWeight: 0,
|
|
140
152
|
borderRightWeight: 0,
|
|
141
153
|
borderBottomWeight: 0,
|
|
@@ -154,14 +166,14 @@ function createDefaultNode(generateId, type, overrides = {}) {
|
|
|
154
166
|
connectorLineType: "ELBOWED",
|
|
155
167
|
connectorStartCap: "ROUND",
|
|
156
168
|
connectorEndCap: "ARROW_LINES",
|
|
157
|
-
connectorControlPoints:
|
|
169
|
+
connectorControlPoints: ownList(overrides.connectorControlPoints),
|
|
158
170
|
connectorCurveHandles: null,
|
|
159
171
|
connectorLabelPosition: null,
|
|
160
172
|
isMask: false,
|
|
161
173
|
maskType: "ALPHA",
|
|
162
174
|
maskIsOutline: false,
|
|
163
|
-
gridTemplateColumns:
|
|
164
|
-
gridTemplateRows:
|
|
175
|
+
gridTemplateColumns: ownList(overrides.gridTemplateColumns),
|
|
176
|
+
gridTemplateRows: ownList(overrides.gridTemplateRows),
|
|
165
177
|
gridColumnGap: 0,
|
|
166
178
|
gridRowGap: 0,
|
|
167
179
|
gridPosition: null,
|
|
@@ -177,11 +189,11 @@ function createDefaultNode(generateId, type, overrides = {}) {
|
|
|
177
189
|
shapeUserHeight: 0,
|
|
178
190
|
shapeTruncates: false,
|
|
179
191
|
componentId: null,
|
|
180
|
-
instanceOverrides: createInstanceOverrideState(),
|
|
181
|
-
componentPropertyDefinitions:
|
|
182
|
-
componentPropertyReferences:
|
|
183
|
-
componentPropertyAssignments:
|
|
184
|
-
componentPropertyValues:
|
|
192
|
+
instanceOverrides: overrides.instanceOverrides ?? createInstanceOverrideState(),
|
|
193
|
+
componentPropertyDefinitions: ownList(overrides.componentPropertyDefinitions),
|
|
194
|
+
componentPropertyReferences: ownList(overrides.componentPropertyReferences),
|
|
195
|
+
componentPropertyAssignments: ownRecord(overrides.componentPropertyAssignments),
|
|
196
|
+
componentPropertyValues: ownRecord(overrides.componentPropertyValues),
|
|
185
197
|
componentKey: null,
|
|
186
198
|
sourceLibraryKey: null,
|
|
187
199
|
publishId: null,
|
|
@@ -194,17 +206,17 @@ function createDefaultNode(generateId, type, overrides = {}) {
|
|
|
194
206
|
isSymbolPublishable: false,
|
|
195
207
|
isExposedInstance: false,
|
|
196
208
|
symbolDescription: "",
|
|
197
|
-
symbolLinks:
|
|
198
|
-
variantPropSpecs:
|
|
199
|
-
boundVariables:
|
|
200
|
-
variableBindingScales:
|
|
201
|
-
variableAssignmentScales:
|
|
209
|
+
symbolLinks: ownList(overrides.symbolLinks),
|
|
210
|
+
variantPropSpecs: ownList(overrides.variantPropSpecs),
|
|
211
|
+
boundVariables: ownRecord(overrides.boundVariables),
|
|
212
|
+
variableBindingScales: ownRecord(overrides.variableBindingScales),
|
|
213
|
+
variableAssignmentScales: ownRecord(overrides.variableAssignmentScales),
|
|
202
214
|
componentScale: 1,
|
|
203
|
-
variableModes:
|
|
204
|
-
exportSettings:
|
|
215
|
+
variableModes: ownRecord(overrides.variableModes),
|
|
216
|
+
exportSettings: ownList(overrides.exportSettings),
|
|
205
217
|
status: null,
|
|
206
|
-
pluginData:
|
|
207
|
-
pluginRelaunchData:
|
|
218
|
+
pluginData: ownList(overrides.pluginData),
|
|
219
|
+
pluginRelaunchData: ownList(overrides.pluginRelaunchData),
|
|
208
220
|
internalOnly: false,
|
|
209
221
|
flipX: false,
|
|
210
222
|
flipY: false,
|
|
@@ -239,6 +251,21 @@ const LAYER_CONTAINER_TYPES = /* @__PURE__ */ new Set([
|
|
|
239
251
|
function isLayerContainer(node) {
|
|
240
252
|
return LAYER_CONTAINER_TYPES.has(node.type);
|
|
241
253
|
}
|
|
254
|
+
/** The kinds that clip their children when their clip content is on. */
|
|
255
|
+
const CLIPPING_TYPES = /* @__PURE__ */ new Set([
|
|
256
|
+
"FRAME",
|
|
257
|
+
"COMPONENT",
|
|
258
|
+
"COMPONENT_SET",
|
|
259
|
+
"INSTANCE"
|
|
260
|
+
]);
|
|
261
|
+
/**
|
|
262
|
+
* Whether a layer clips its children: a frame, component, component set or instance with clip
|
|
263
|
+
* content on. A section or group has no such setting in Figma and never clips, whatever an import
|
|
264
|
+
* left in `clipsContent` (Figma desktop, live).
|
|
265
|
+
*/
|
|
266
|
+
function clipsChildren(node) {
|
|
267
|
+
return node.clipsContent && CLIPPING_TYPES.has(node.type);
|
|
268
|
+
}
|
|
242
269
|
const CONTAINER_TYPES = /* @__PURE__ */ new Set([
|
|
243
270
|
"CANVAS",
|
|
244
271
|
"FRAME",
|
|
@@ -250,6 +277,6 @@ const CONTAINER_TYPES = /* @__PURE__ */ new Set([
|
|
|
250
277
|
"INSTANCE"
|
|
251
278
|
]);
|
|
252
279
|
//#endregion
|
|
253
|
-
export { CONTAINER_TYPES, FITTED_CONTAINER_TYPES, LAYER_CONTAINER_TYPES, SIDE_STROKE_TYPES, createDefaultNode, createDefaultSourceMetadata, defaultStrokeAlign, isLayerContainer, newStrokeGeometry };
|
|
280
|
+
export { CLIPPING_TYPES, CONTAINER_TYPES, FITTED_CONTAINER_TYPES, LAYER_CONTAINER_TYPES, SIDE_STROKE_TYPES, clipsChildren, createDefaultNode, createDefaultSourceMetadata, defaultStrokeAlign, isLayerContainer, newStrokeGeometry };
|
|
254
281
|
|
|
255
282
|
//# sourceMappingURL=node-defaults.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-defaults.js","names":[],"sources":["../src/node-defaults.ts"],"sourcesContent":["import {\n BLACK,\n DEFAULT_FONT_FAMILY,\n DEFAULT_STROKE_MITER_LIMIT,\n DEFAULT_STROKE_WEIGHT\n} from './constants'\nimport { createInstanceOverrideState } from './instances/overrides'\nimport { NO_LETTER_SPACING } from './text/lengths'\nimport type { NodeType, SceneNode, SourceMetadata } from './types'\n\nexport function createDefaultSourceMetadata(): SourceMetadata {\n return {\n format: null,\n id: null,\n orderKey: null,\n editedFields: [],\n fig: {\n rawSize: null,\n rawTransform: null,\n rawNodeFields: {},\n layout: null,\n symbolOverrides: [],\n componentPropAssignments: [],\n derivedSymbolData: [],\n derivedSymbolDataLayoutVersion: null,\n uniformScaleFactor: null\n }\n }\n}\n\n/**\n * Every SceneNode field. Nodes start with all of them, so setting any field later keeps the\n * shape every node shares; a key added after creation turns a JavaScriptCore object into a\n * slower, larger dictionary.\n */\ntype CompleteNodeFields = SceneNode & Record<keyof SceneNode, unknown>\n\n/** Where Figma aligns a new node's strokes: centered on lines and vectors, outside text, else inside. */\nexport function defaultStrokeAlign(type: NodeType): SceneNode['strokeAlign'] {\n if (type === 'LINE' || type === 'VECTOR') return 'CENTER'\n return type === 'TEXT' ? 'OUTSIDE' : 'INSIDE'\n}\n\n/**\n * Weight and alignment a stroke added to `node` takes: its first stroke's, or what the node keeps\n * with none. Adding a stroke from the panel and from the plugin API both go through here.\n */\nexport function newStrokeGeometry(\n node: Pick<SceneNode, 'strokes' | 'strokeWeight' | 'strokeAlign'>\n): Pick<SceneNode['strokes'][number], 'weight' | 'align'> {\n const first = node.strokes.at(0)\n return { weight: first?.weight ?? node.strokeWeight, align: first?.align ?? node.strokeAlign }\n}\n\nexport function createDefaultNode(\n generateId: () => string,\n type: NodeType,\n overrides: Partial<SceneNode> = {}\n): SceneNode {\n return {\n id: generateId(),\n type,\n name: type.charAt(0) + type.slice(1).toLowerCase(),\n parentId: null,\n childIds: [],\n x: 0,\n y: 0,\n width: 100,\n height: 100,\n rotation: 0,\n source: createDefaultSourceMetadata(),\n derivedLayout: null,\n fills:\n type === 'TEXT' ? [{ type: 'SOLID' as const, color: BLACK, opacity: 1, visible: true }] : [],\n strokes: [],\n effects: [],\n layoutGrids: [],\n guides: [],\n fillStyleId: null,\n strokeStyleId: null,\n textStyleId: null,\n effectStyleId: null,\n gridStyleId: null,\n sharedStyleType: null,\n opacity: 1,\n cornerRadius: 0,\n topLeftRadius: 0,\n topRightRadius: 0,\n bottomRightRadius: 0,\n bottomLeftRadius: 0,\n independentCorners: false,\n cornerSmoothing: 0,\n visible: true,\n locked: false,\n clipsContent: false,\n text: '',\n fontSize: 14,\n fontFamily: DEFAULT_FONT_FAMILY,\n fontWeight: 400,\n italic: false,\n fontStyle: null,\n textAlignHorizontal: 'LEFT',\n textDirection: 'AUTO',\n textLanguage: null,\n leadingTrim: 'NONE',\n lineHeight: null,\n letterSpacing: NO_LETTER_SPACING,\n layoutMode: 'NONE',\n layoutDirection: 'AUTO',\n layoutWrap: 'NO_WRAP',\n primaryAxisAlign: 'MIN',\n counterAxisAlign: 'MIN',\n primaryAxisSizing: 'FIXED',\n counterAxisSizing: 'FIXED',\n itemSpacing: 0,\n counterAxisSpacing: 0,\n paddingTop: 0,\n paddingRight: 0,\n paddingBottom: 0,\n paddingLeft: 0,\n blendMode: 'PASS_THROUGH',\n layoutPositioning: 'AUTO',\n layoutGrow: 0,\n layoutAlignSelf: 'AUTO',\n vectorNetwork: null,\n handleMirroring: 'NONE',\n fillGeometry: [],\n strokeGeometry: [],\n arcData: null,\n textAlignVertical: 'TOP',\n textAutoResize: 'NONE',\n textCase: 'ORIGINAL',\n textDecoration: 'NONE',\n textDecorationStyle: 'SOLID',\n textDecorationThickness: null,\n textDecorationFills: [],\n textDecorationSkipInk: true,\n textUnderlineOffset: null,\n maxLines: null,\n textParagraphs: [],\n listSpacing: 0,\n paragraphSpacing: 0,\n paragraphIndent: 0,\n hangingList: false,\n styleRuns: [],\n fontVariations: [],\n opticalSizeFromFontSize: true,\n fontFeatures: [],\n horizontalConstraint: 'MIN',\n verticalConstraint: 'MIN',\n strokeCap: 'NONE',\n strokeJoin: 'MITER',\n dashPattern: [],\n borderTopWeight: 0,\n borderRightWeight: 0,\n borderBottomWeight: 0,\n borderLeftWeight: 0,\n independentStrokeWeights: false,\n strokeWeight: DEFAULT_STROKE_WEIGHT,\n strokeAlign: defaultStrokeAlign(type),\n strokeMiterLimit: DEFAULT_STROKE_MITER_LIMIT,\n minWidth: null,\n maxWidth: null,\n minHeight: null,\n maxHeight: null,\n targetAspectRatio: null,\n connectorStart: null,\n connectorEnd: null,\n connectorLineType: 'ELBOWED',\n connectorStartCap: 'ROUND',\n connectorEndCap: 'ARROW_LINES',\n connectorControlPoints: [],\n connectorCurveHandles: null,\n connectorLabelPosition: null,\n isMask: false,\n maskType: 'ALPHA',\n maskIsOutline: false,\n gridTemplateColumns: [],\n gridTemplateRows: [],\n gridColumnGap: 0,\n gridRowGap: 0,\n gridPosition: null,\n counterAxisAlignContent: 'AUTO',\n itemReverseZIndex: false,\n strokesIncludedInLayout: false,\n expanded: true,\n textTruncation: 'DISABLED',\n autoRename: true,\n pointCount: 5,\n // Figma's: the golden-ratio star, whose inner points line up with its outer ones.\n starInnerRadius: (3 - Math.sqrt(5)) / 2,\n shapeWithTextType: 'SQUARE',\n shapeUserHeight: 0,\n shapeTruncates: false,\n componentId: null,\n instanceOverrides: createInstanceOverrideState(),\n componentPropertyDefinitions: [],\n componentPropertyReferences: [],\n componentPropertyAssignments: {},\n componentPropertyValues: {},\n componentKey: null,\n sourceLibraryKey: null,\n publishId: null,\n overrideKey: null,\n sharedSymbolVersion: null,\n publishedVersion: null,\n librarySource: null,\n libraryLayerId: null,\n isPublishable: false,\n isSymbolPublishable: false,\n isExposedInstance: false,\n symbolDescription: '',\n symbolLinks: [],\n variantPropSpecs: [],\n boundVariables: {},\n variableBindingScales: {},\n variableAssignmentScales: {},\n componentScale: 1,\n variableModes: {},\n exportSettings: [],\n status: null,\n pluginData: [],\n pluginRelaunchData: [],\n internalOnly: false,\n flipX: false,\n flipY: false,\n textPicture: null,\n derivedTextGlyphs: null,\n derivedTextHeight: null,\n textPathData: null,\n textPathBox: null,\n booleanOperation: undefined,\n ...overrides\n } satisfies CompleteNodeFields\n}\n\n/** Containers whose bounds follow their children and that set no coordinate space, as in Figma. */\nexport const FITTED_CONTAINER_TYPES: ReadonlySet<NodeType> = new Set<NodeType>([\n 'GROUP',\n 'BOOLEAN_OPERATION'\n])\n\n/** Layers whose stroke can take a weight per side, as Figma's `strokeTopWeight` and its siblings. */\nexport const SIDE_STROKE_TYPES: ReadonlySet<NodeType> = new Set<NodeType>([\n 'RECTANGLE',\n 'FRAME',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE'\n])\n\n/** The kinds that hold layers of their own on the canvas: what a shadow or a clip encloses. */\nexport const LAYER_CONTAINER_TYPES: ReadonlySet<NodeType> = new Set<NodeType>([\n 'FRAME',\n 'GROUP',\n 'SECTION',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE'\n])\n\nexport function isLayerContainer(node: Pick<SceneNode, 'type'>): boolean {\n return LAYER_CONTAINER_TYPES.has(node.type)\n}\n\nexport const CONTAINER_TYPES = new Set<NodeType>([\n 'CANVAS',\n 'FRAME',\n 'GROUP',\n 'BOOLEAN_OPERATION',\n 'SECTION',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE'\n])\n"],"mappings":";;;;AAUA,SAAgB,8BAA8C;CAC5D,OAAO;EACL,QAA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BAAmB;EACnB,iBAAiB;EACjB,gBAAgB;EAChB,aAAa;EACb,mBAAmB,4BAA4B;EAC/C,8BAA8B,CAAC;EAC/B,6BAA6B,CAAC;EAC9B,8BAA8B,CAAC;EAC/B,yBAAyB,CAAC;EAC1B,cAAc;EACd,kBAAkB;EAClB,WAAW;EACX,aAAa;EACb,qBAAqB;EACrB,kBAAkB;EAClB,eAAe;EACf,gBAAgB;EAChB,eAAe;EACf,qBAAqB;EACrB,mBAAmB;EACnB,mBAAmB;EACnB,aAAa,CAAC;EACd,kBAAkB,CAAC;EACnB,gBAAgB,CAAC;EACjB,uBAAuB,CAAC;EACxB,0BAA0B,CAAC;EAC3B,gBAAgB;EAChB,eAAe,CAAC;EAChB,gBAAgB,CAAC;EACjB,QAAQ;EACR,YAAY,CAAC;EACb,oBAAoB,CAAC;EACrB,cAAc;EACd,OAAO;EACP,OAAO;EACP,aAAa;EACb,mBAAmB;EACnB,mBAAmB;EACnB,cAAc;EACd,aAAa;EACb,kBAAkB,KAAA;EAClB,GAAG;CACL;AACF;;AAGA,MAAa,yCAAgD,IAAI,IAAc,CAC7E,SACA,mBACF,CAAC;;AAGD,MAAa,oCAA2C,IAAI,IAAc;CACxE;CACA;CACA;CACA;CACA;AACF,CAAC;;AAGD,MAAa,wCAA+C,IAAI,IAAc;CAC5E;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,SAAgB,iBAAiB,MAAwC;CACvE,OAAO,sBAAsB,IAAI,KAAK,IAAI;AAC5C;AAEA,MAAa,kCAAkB,IAAI,IAAc;CAC/C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"node-defaults.js","names":[],"sources":["../src/node-defaults.ts"],"sourcesContent":["import {\n BLACK,\n DEFAULT_FONT_FAMILY,\n DEFAULT_STROKE_MITER_LIMIT,\n DEFAULT_STROKE_WEIGHT\n} from './constants'\nimport { createInstanceOverrideState } from './instances/overrides'\nimport { NO_LETTER_SPACING } from './text/lengths'\nimport type { NodeType, SceneNode, SourceMetadata } from './types'\n\nexport function createDefaultSourceMetadata(): SourceMetadata {\n return {\n format: null,\n id: null,\n orderKey: null,\n editedFields: [],\n fig: {\n rawSize: null,\n rawTransform: null,\n rawNodeFields: {},\n layout: null,\n symbolOverrides: [],\n componentPropAssignments: [],\n derivedSymbolData: [],\n derivedSymbolDataLayoutVersion: null,\n uniformScaleFactor: null\n }\n }\n}\n\n/**\n * Every SceneNode field. Nodes start with all of them, so setting any field later keeps the\n * shape every node shares; a key added after creation turns a JavaScriptCore object into a\n * slower, larger dictionary.\n */\ntype CompleteNodeFields = SceneNode & Record<keyof SceneNode, unknown>\n\n/** Where Figma aligns a new node's strokes: centered on lines and vectors, outside text, else inside. */\nexport function defaultStrokeAlign(type: NodeType): SceneNode['strokeAlign'] {\n if (type === 'LINE' || type === 'VECTOR') return 'CENTER'\n return type === 'TEXT' ? 'OUTSIDE' : 'INSIDE'\n}\n\n/**\n * Weight and alignment a stroke added to `node` takes: its first stroke's, or what the node keeps\n * with none. Adding a stroke from the panel and from the plugin API both go through here.\n */\nexport function newStrokeGeometry(\n node: Pick<SceneNode, 'strokes' | 'strokeWeight' | 'strokeAlign'>\n): Pick<SceneNode['strokes'][number], 'weight' | 'align'> {\n const first = node.strokes.at(0)\n return { weight: first?.weight ?? node.strokeWeight, align: first?.align ?? node.strokeAlign }\n}\n\n/** A caller's list, or a fresh empty one: a list default belongs to the one layer it was made for. */\nfunction ownList<T>(given: T[] | undefined): T[] {\n return given ?? []\n}\n\n/** A caller's record, or a fresh empty one, for the same reason. */\nfunction ownRecord<V>(given: Record<string, V> | undefined): Record<string, V> {\n return given ?? {}\n}\n\n/** A new layer's fills: black on text, none elsewhere. */\nfunction defaultFills(type: NodeType): SceneNode['fills'] {\n return type === 'TEXT' ? [{ type: 'SOLID', color: BLACK, opacity: 1, visible: true }] : []\n}\n\nexport function createDefaultNode(\n generateId: () => string,\n type: NodeType,\n overrides: Partial<SceneNode> = {}\n): SceneNode {\n // A literal ending in a spread is built one field at a time, and V8 keeps an object given this\n // many fields that way in dictionary mode, about 3 KB more per layer; a spread copy of a\n // finished literal keeps fast fields, in JavaScriptCore as well.\n // Imports supply most lists and records, so a default is made only where the caller gives none.\n const defaults = {\n id: generateId(),\n type,\n name: type.charAt(0) + type.slice(1).toLowerCase(),\n parentId: null,\n childIds: ownList(overrides.childIds),\n x: 0,\n y: 0,\n width: 100,\n height: 100,\n rotation: 0,\n source: overrides.source ?? createDefaultSourceMetadata(),\n derivedLayout: null,\n fills: overrides.fills ?? defaultFills(type),\n strokes: ownList(overrides.strokes),\n effects: ownList(overrides.effects),\n layoutGrids: ownList(overrides.layoutGrids),\n guides: ownList(overrides.guides),\n fillStyleId: null,\n strokeStyleId: null,\n textStyleId: null,\n effectStyleId: null,\n gridStyleId: null,\n sharedStyleType: null,\n opacity: 1,\n cornerRadius: 0,\n topLeftRadius: 0,\n topRightRadius: 0,\n bottomRightRadius: 0,\n bottomLeftRadius: 0,\n independentCorners: false,\n cornerSmoothing: 0,\n visible: true,\n locked: false,\n clipsContent: false,\n text: '',\n fontSize: 14,\n fontFamily: DEFAULT_FONT_FAMILY,\n fontWeight: 400,\n italic: false,\n fontStyle: null,\n textAlignHorizontal: 'LEFT',\n textDirection: 'AUTO',\n textLanguage: null,\n leadingTrim: 'NONE',\n lineHeight: null,\n letterSpacing: NO_LETTER_SPACING,\n layoutMode: 'NONE',\n layoutDirection: 'AUTO',\n layoutWrap: 'NO_WRAP',\n primaryAxisAlign: 'MIN',\n counterAxisAlign: 'MIN',\n primaryAxisSizing: 'FIXED',\n counterAxisSizing: 'FIXED',\n itemSpacing: 0,\n counterAxisSpacing: 0,\n paddingTop: 0,\n paddingRight: 0,\n paddingBottom: 0,\n paddingLeft: 0,\n blendMode: 'PASS_THROUGH',\n layoutPositioning: 'AUTO',\n layoutGrow: 0,\n layoutAlignSelf: 'AUTO',\n vectorNetwork: null,\n handleMirroring: 'NONE',\n fillGeometry: ownList(overrides.fillGeometry),\n strokeGeometry: ownList(overrides.strokeGeometry),\n arcData: null,\n textAlignVertical: 'TOP',\n textAutoResize: 'NONE',\n textCase: 'ORIGINAL',\n textDecoration: 'NONE',\n textDecorationStyle: 'SOLID',\n textDecorationThickness: null,\n textDecorationFills: ownList(overrides.textDecorationFills),\n textDecorationSkipInk: true,\n textUnderlineOffset: null,\n maxLines: null,\n textParagraphs: ownList(overrides.textParagraphs),\n listSpacing: 0,\n paragraphSpacing: 0,\n paragraphIndent: 0,\n hangingList: false,\n styleRuns: ownList(overrides.styleRuns),\n fontVariations: ownList(overrides.fontVariations),\n opticalSizeFromFontSize: true,\n fontFeatures: ownList(overrides.fontFeatures),\n horizontalConstraint: 'MIN',\n verticalConstraint: 'MIN',\n strokeCap: 'NONE',\n strokeJoin: 'MITER',\n dashPattern: ownList(overrides.dashPattern),\n borderTopWeight: 0,\n borderRightWeight: 0,\n borderBottomWeight: 0,\n borderLeftWeight: 0,\n independentStrokeWeights: false,\n strokeWeight: DEFAULT_STROKE_WEIGHT,\n strokeAlign: defaultStrokeAlign(type),\n strokeMiterLimit: DEFAULT_STROKE_MITER_LIMIT,\n minWidth: null,\n maxWidth: null,\n minHeight: null,\n maxHeight: null,\n targetAspectRatio: null,\n connectorStart: null,\n connectorEnd: null,\n connectorLineType: 'ELBOWED',\n connectorStartCap: 'ROUND',\n connectorEndCap: 'ARROW_LINES',\n connectorControlPoints: ownList(overrides.connectorControlPoints),\n connectorCurveHandles: null,\n connectorLabelPosition: null,\n isMask: false,\n maskType: 'ALPHA',\n maskIsOutline: false,\n gridTemplateColumns: ownList(overrides.gridTemplateColumns),\n gridTemplateRows: ownList(overrides.gridTemplateRows),\n gridColumnGap: 0,\n gridRowGap: 0,\n gridPosition: null,\n counterAxisAlignContent: 'AUTO',\n itemReverseZIndex: false,\n strokesIncludedInLayout: false,\n expanded: true,\n textTruncation: 'DISABLED',\n autoRename: true,\n pointCount: 5,\n // Figma's: the golden-ratio star, whose inner points line up with its outer ones.\n starInnerRadius: (3 - Math.sqrt(5)) / 2,\n shapeWithTextType: 'SQUARE',\n shapeUserHeight: 0,\n shapeTruncates: false,\n componentId: null,\n instanceOverrides: overrides.instanceOverrides ?? createInstanceOverrideState(),\n componentPropertyDefinitions: ownList(overrides.componentPropertyDefinitions),\n componentPropertyReferences: ownList(overrides.componentPropertyReferences),\n componentPropertyAssignments: ownRecord(overrides.componentPropertyAssignments),\n componentPropertyValues: ownRecord(overrides.componentPropertyValues),\n componentKey: null,\n sourceLibraryKey: null,\n publishId: null,\n overrideKey: null,\n sharedSymbolVersion: null,\n publishedVersion: null,\n librarySource: null,\n libraryLayerId: null,\n isPublishable: false,\n isSymbolPublishable: false,\n isExposedInstance: false,\n symbolDescription: '',\n symbolLinks: ownList(overrides.symbolLinks),\n variantPropSpecs: ownList(overrides.variantPropSpecs),\n boundVariables: ownRecord(overrides.boundVariables),\n variableBindingScales: ownRecord(overrides.variableBindingScales),\n variableAssignmentScales: ownRecord(overrides.variableAssignmentScales),\n componentScale: 1,\n variableModes: ownRecord(overrides.variableModes),\n exportSettings: ownList(overrides.exportSettings),\n status: null,\n pluginData: ownList(overrides.pluginData),\n pluginRelaunchData: ownList(overrides.pluginRelaunchData),\n internalOnly: false,\n flipX: false,\n flipY: false,\n textPicture: null,\n derivedTextGlyphs: null,\n derivedTextHeight: null,\n textPathData: null,\n textPathBox: null,\n booleanOperation: undefined\n } satisfies CompleteNodeFields\n return { ...defaults, ...overrides }\n}\n\n/** Containers whose bounds follow their children and that set no coordinate space, as in Figma. */\nexport const FITTED_CONTAINER_TYPES: ReadonlySet<NodeType> = new Set<NodeType>([\n 'GROUP',\n 'BOOLEAN_OPERATION'\n])\n\n/** Layers whose stroke can take a weight per side, as Figma's `strokeTopWeight` and its siblings. */\nexport const SIDE_STROKE_TYPES: ReadonlySet<NodeType> = new Set<NodeType>([\n 'RECTANGLE',\n 'FRAME',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE'\n])\n\n/** The kinds that hold layers of their own on the canvas: what a shadow or a clip encloses. */\nexport const LAYER_CONTAINER_TYPES: ReadonlySet<NodeType> = new Set<NodeType>([\n 'FRAME',\n 'GROUP',\n 'SECTION',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE'\n])\n\nexport function isLayerContainer(node: Pick<SceneNode, 'type'>): boolean {\n return LAYER_CONTAINER_TYPES.has(node.type)\n}\n\n/** The kinds that clip their children when their clip content is on. */\nexport const CLIPPING_TYPES: ReadonlySet<NodeType> = new Set<NodeType>([\n 'FRAME',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE'\n])\n\n/**\n * Whether a layer clips its children: a frame, component, component set or instance with clip\n * content on. A section or group has no such setting in Figma and never clips, whatever an import\n * left in `clipsContent` (Figma desktop, live).\n */\nexport function clipsChildren(node: Pick<SceneNode, 'type' | 'clipsContent'>): boolean {\n return node.clipsContent && CLIPPING_TYPES.has(node.type)\n}\n\nexport const CONTAINER_TYPES = new Set<NodeType>([\n 'CANVAS',\n 'FRAME',\n 'GROUP',\n 'BOOLEAN_OPERATION',\n 'SECTION',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE'\n])\n"],"mappings":";;;;AAUA,SAAgB,8BAA8C;CAC5D,OAAO;EACL,QAAQ;EACR,IAAI;EACJ,UAAU;EACV,cAAc,CAAC;EACf,KAAK;GACH,SAAS;GACT,cAAc;GACd,eAAe,CAAC;GAChB,QAAQ;GACR,iBAAiB,CAAC;GAClB,0BAA0B,CAAC;GAC3B,mBAAmB,CAAC;GACpB,gCAAgC;GAChC,oBAAoB;EACtB;CACF;AACF;;AAUA,SAAgB,mBAAmB,MAA0C;CAC3E,IAAI,SAAS,UAAU,SAAS,UAAU,OAAO;CACjD,OAAO,SAAS,SAAS,YAAY;AACvC;;;;;AAMA,SAAgB,kBACd,MACwD;CACxD,MAAM,QAAQ,KAAK,QAAQ,GAAG,CAAC;CAC/B,OAAO;EAAE,QAAQ,OAAO,UAAU,KAAK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rF,OAAO,KAAK,gBAAgB,eAAe,IAAI,KAAK,IAAI;AAC1D;AAEA,MAAa,kCAAkB,IAAI,IAAc;CAC/C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flatten.d.ts","names":[],"sources":["../../src/outline/flatten.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"flatten.d.ts","names":[],"sources":["../../src/outline/flatten.ts"],"mappings":";;;;iBAuCgB,cACd,SAAS,eACT,eACA,oBACC;;;;;iBAoBa,WAAW,SAAS,eAAe,gBAAgB,oBAAoB;;iBAiDvE,aAAa,MAAM,YAAY,oBAAoB"}
|
package/dist/outline/flatten.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { cubicPoint } from "../cubic.js";
|
|
2
|
+
import { buildChains } from "../paths/network.js";
|
|
2
3
|
import { GeometryCommand, readGeometryBlob } from "../geometry.js";
|
|
4
|
+
import { appendAll } from "@open-pencil/std/arrays";
|
|
3
5
|
//#region src/outline/flatten.ts
|
|
4
6
|
/**
|
|
5
7
|
* Keeps a huge curve at a tiny tolerance from flattening into an unbounded number of points, while
|
|
@@ -58,30 +60,35 @@ function loopPoints(network, loop, tolerance) {
|
|
|
58
60
|
const along = segmentPoints(network, index, tolerance);
|
|
59
61
|
if (!segment || !along) continue;
|
|
60
62
|
const forward = segment.start === current;
|
|
61
|
-
points
|
|
63
|
+
appendAll(points, forward ? along : along.toReversed());
|
|
62
64
|
current = forward ? segment.end : segment.start;
|
|
63
65
|
}
|
|
64
66
|
return points;
|
|
65
67
|
}
|
|
66
68
|
/**
|
|
67
|
-
* The network's segments joined into runs,
|
|
68
|
-
*
|
|
69
|
+
* The network's segments joined into runs, chained through the vertices they share as the canvas
|
|
70
|
+
* draws an open network (`buildChains`), each run walked from its open end.
|
|
69
71
|
*/
|
|
70
72
|
function segmentRuns(network, tolerance) {
|
|
71
73
|
const runs = [];
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
74
|
+
for (const chain of buildChains(network.segments)) {
|
|
75
|
+
let current = chain.start;
|
|
76
|
+
let run = [];
|
|
77
|
+
for (const index of chain.segments) {
|
|
78
|
+
const segment = network.segments[index];
|
|
79
|
+
const forward = segment.start === current;
|
|
80
|
+
current = forward ? segment.end : segment.start;
|
|
81
|
+
const along = segmentPoints(network, index, tolerance);
|
|
82
|
+
if (!along) {
|
|
83
|
+
if (run.length > 1) runs.push(run);
|
|
84
|
+
run = [];
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
const points = forward ? along : along.toReversed();
|
|
88
|
+
appendAll(run, run.length > 0 ? points.slice(1) : points);
|
|
81
89
|
}
|
|
82
|
-
|
|
90
|
+
if (run.length > 1) runs.push(run);
|
|
83
91
|
}
|
|
84
|
-
if (run.length > 1) runs.push(run);
|
|
85
92
|
return runs;
|
|
86
93
|
}
|
|
87
94
|
/** The contours of a Figma geometry blob, curves flattened to within `tolerance`. */
|
|
@@ -121,8 +128,8 @@ function blobContours(blob, tolerance) {
|
|
|
121
128
|
x: end.x + 2 / 3 * (q.x - end.x),
|
|
122
129
|
y: end.y + 2 / 3 * (q.y - end.y)
|
|
123
130
|
};
|
|
124
|
-
contour
|
|
125
|
-
} else contour
|
|
131
|
+
appendAll(contour, cubicPoints(last, c1, c2, end, tolerance));
|
|
132
|
+
} else appendAll(contour, cubicPoints(last, {
|
|
126
133
|
x: c[0],
|
|
127
134
|
y: c[1]
|
|
128
135
|
}, {
|
|
@@ -154,7 +161,7 @@ function commandContours(commands, tolerance) {
|
|
|
154
161
|
x: command.x,
|
|
155
162
|
y: command.y
|
|
156
163
|
});
|
|
157
|
-
else contour
|
|
164
|
+
else appendAll(contour, cubicPoints(last, {
|
|
158
165
|
x: command.x1,
|
|
159
166
|
y: command.y1
|
|
160
167
|
}, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flatten.js","names":[],"sources":["../../src/outline/flatten.ts"],"sourcesContent":["import { cubicPoint } from '../cubic'\nimport { GeometryCommand, readGeometryBlob } from '../geometry'\nimport type { PolygonOutlineCommand } from '../polygon'\nimport type { Vector } from '../primitives'\nimport type { VectorNetwork } from '../types'\n\n/**\n * Keeps a huge curve at a tiny tolerance from flattening into an unbounded number of points, while\n * leaving room for the largest arcs at the maximum zoom: a 100,000-unit circle at 25,600% needs\n * about 12,000 steps to stay within the click pad.\n */\nconst MAX_CURVE_STEPS = 65_536\n\n/**\n * Steps that keep a cubic's polyline within `tolerance` of it: equal steps in t stray at most\n * M / (8n²) from a curve whose second derivative is at most M, and for a cubic\n * M ≤ 6 · max(|p0 − 2p1 + p2|, |p1 − 2p2 + p3|).\n */\nfunction curveSteps(p0: Vector, p1: Vector, p2: Vector, p3: Vector, tolerance: number): number {\n const bend = Math.max(\n Math.hypot(p0.x - 2 * p1.x + p2.x, p0.y - 2 * p1.y + p2.y),\n Math.hypot(p1.x - 2 * p2.x + p3.x, p1.y - 2 * p2.y + p3.y)\n )\n const steps = Math.ceil(Math.sqrt((6 * bend) / (8 * tolerance)))\n return Math.min(MAX_CURVE_STEPS, Math.max(1, steps))\n}\n\n/** Points along a cubic after its start, within `tolerance` of it, ending on `p3`. */\nfunction cubicPoints(p0: Vector, p1: Vector, p2: Vector, p3: Vector, tolerance: number): Vector[] {\n const steps = curveSteps(p0, p1, p2, p3, tolerance)\n const points: Vector[] = []\n for (let step = 1; step <= steps; step++) points.push(cubicPoint(p0, p1, p2, p3, step / steps))\n return points\n}\n\n/** Points along a vector network segment, from its start to its end, in network coordinates. */\nexport function segmentPoints(\n network: VectorNetwork,\n index: number,\n tolerance: number\n): Vector[] | null {\n // `at` counts a negative index from the end and truncates a fraction; a loop naming either\n // refers to no segment.\n if (!Number.isInteger(index) || index < 0) return null\n const segment = network.segments.at(index)\n if (!segment || segment.start < 0 || segment.end < 0) return null\n const p0 = network.vertices.at(segment.start)\n const p3 = network.vertices.at(segment.end)\n if (!p0 || !p3) return null\n const { tangentStart: a, tangentEnd: b } = segment\n if (a.x === 0 && a.y === 0 && b.x === 0 && b.y === 0) return [p0, p3]\n const p1 = { x: p0.x + a.x, y: p0.y + a.y }\n const p2 = { x: p3.x + b.x, y: p3.y + b.y }\n return [p0, ...cubicPoints(p0, p1, p2, p3, tolerance)]\n}\n\n/**\n * A loop's points in the order it is walked. Segments in a loop can be stored either way round,\n * so each is followed from the vertex the previous one ended on.\n */\nexport function loopPoints(network: VectorNetwork, loop: number[], tolerance: number): Vector[] {\n const { segments } = network\n const first = segments.at(loop[0] ?? -1)\n const second = segments.at(loop[1] ?? -1)\n if (!first) return []\n // Walk the first segment toward the vertex it shares with the next one.\n const firstForward = !second || first.end === second.start || first.end === second.end\n let current = firstForward ? first.start : first.end\n const points: Vector[] = []\n for (const index of loop) {\n const segment = segments.at(index)\n const along = segmentPoints(network, index, tolerance)\n if (!segment || !along) continue\n const forward = segment.start === current\n points.push(...(forward ? along : along.toReversed()))\n current = forward ? segment.end : segment.start\n }\n return points\n}\n\n/**\n * The network's segments joined into runs, a run continuing while each segment starts where the\n * last ended, as a path draws them one after another.\n */\nexport function segmentRuns(network: VectorNetwork, tolerance: number): Vector[][] {\n const runs: Vector[][] = []\n let run: Vector[] = []\n let end = -1\n for (const [index, segment] of network.segments.entries()) {\n const along = segmentPoints(network, index, tolerance)\n if (!along) continue\n if (segment.start === end && run.length > 0) run.push(...along.slice(1))\n else {\n if (run.length > 1) runs.push(run)\n run = along\n }\n end = segment.end\n }\n if (run.length > 1) runs.push(run)\n return runs\n}\n\n/** The contours of a Figma geometry blob, curves flattened to within `tolerance`. */\nexport function blobContours(blob: Uint8Array, tolerance: number): Vector[][] {\n const contours: Vector[][] = []\n let contour: Vector[] = []\n const flush = () => {\n if (contour.length > 1) contours.push(contour)\n contour = []\n }\n readGeometryBlob(blob, (command, c) => {\n if (command === GeometryCommand.CLOSE) return flush()\n if (command === GeometryCommand.MOVE) {\n flush()\n contour.push({ x: c[0], y: c[1] })\n return\n }\n const end = { x: c[c.length - 2], y: c[c.length - 1] }\n const last = contour.at(-1)\n if (!last || command === GeometryCommand.LINE) {\n contour.push(end)\n } else if (command === GeometryCommand.QUAD) {\n // A quadratic as the cubic with the same curve.\n const q = { x: c[0], y: c[1] }\n const c1 = { x: last.x + (2 / 3) * (q.x - last.x), y: last.y + (2 / 3) * (q.y - last.y) }\n const c2 = { x: end.x + (2 / 3) * (q.x - end.x), y: end.y + (2 / 3) * (q.y - end.y) }\n contour.push(...cubicPoints(last, c1, c2, end, tolerance))\n } else {\n contour.push(...cubicPoints(last, { x: c[0], y: c[1] }, { x: c[2], y: c[3] }, end, tolerance))\n }\n })\n flush()\n return contours\n}\n\n/** The contours of polygon outline commands, curves flattened to within `tolerance`. */\nexport function commandContours(\n commands: readonly PolygonOutlineCommand[],\n tolerance: number\n): Vector[][] {\n const contours: Vector[][] = []\n let contour: Vector[] = []\n for (const command of commands) {\n if (command.type === 'Z' || command.type === 'M') {\n if (contour.length > 1) contours.push(contour)\n contour = command.type === 'M' ? [{ x: command.x, y: command.y }] : []\n continue\n }\n const last = contour.at(-1) ?? { x: 0, y: 0 }\n if (command.type !== 'C') contour.push({ x: command.x, y: command.y })\n else\n contour.push(\n ...cubicPoints(\n last,\n { x: command.x1, y: command.y1 },\n { x: command.x2, y: command.y2 },\n { x: command.x, y: command.y },\n tolerance\n )\n )\n }\n if (contour.length > 1) contours.push(contour)\n return contours\n}\n\n/** Points around an ellipse arc from `start` to `end` radians, at most `tolerance` off it. */\nexport function arcPoints(\n cx: number,\n cy: number,\n rx: number,\n ry: number,\n start: number,\n end: number,\n tolerance: number\n): Vector[] {\n const radius = Math.max(rx, ry)\n // A chord over angle θ strays r(1 − cos(θ/2)) from the arc.\n const step =\n radius > tolerance ? 2 * Math.acos(Math.max(-1, 1 - tolerance / radius)) : Math.PI / 2\n const steps = Math.min(\n MAX_CURVE_STEPS,\n Math.max(1, Math.ceil(Math.abs(end - start) / Math.max(step, 1e-3)))\n )\n const points: Vector[] = []\n for (let i = 0; i <= steps; i++) {\n const angle = start + ((end - start) * i) / steps\n points.push({ x: cx + rx * Math.cos(angle), y: cy + ry * Math.sin(angle) })\n }\n return points\n}\n"],"mappings":";;;;;;;;AAWA,MAAM,kBAAkB;;;;;;AAOxB,SAAS,WAAW,IAAY,IAAY,IAAY,IAAY,WAA2B;CAC7F,MAAM,OAAO,KAAK,IAChB,KAAK,MAAM,GAAG,IAAI,IAAI,GAAG,IAAI,GAAG,GAAG,GAAG,IAAI,IAAI,GAAG,IAAI,GAAG,CAAC,GACzD,KAAK,MAAM,GAAG,IAAI,IAAI,GAAG,IAAI,GAAG,GAAG,GAAG,IAAI,IAAI,GAAG,IAAI,GAAG,CAAC,CAC3D;CACA,MAAM,QAAQ,KAAK,KAAK,KAAK,KAAM,IAAI,QAAS,IAAI,UAAU,CAAC;CAC/D,OAAO,KAAK,IAAI,iBAAiB,KAAK,IAAI,GAAG,KAAK,CAAC;AACrD;;AAGA,SAAS,YAAY,IAAY,IAAY,IAAY,IAAY,WAA6B;CAChG,MAAM,QAAQ,WAAW,IAAI,IAAI,IAAI,IAAI,SAAS;CAClD,MAAM,SAAmB,CAAC;CAC1B,KAAK,IAAI,OAAO,GAAG,QAAQ,OAAO,QAAQ,OAAO,KAAK,WAAW,IAAI,IAAI,IAAI,IAAI,OAAO,KAAK,CAAC;CAC9F,OAAO;AACT;;AAGA,SAAgB,cACd,SACA,OACA,WACiB;CAGjB,IAAI,CAAC,OAAO,UAAU,KAAK,KAAK,QAAQ,GAAG,OAAO;CAClD,MAAM,UAAU,QAAQ,SAAS,GAAG,KAAK;CACzC,IAAI,CAAC,WAAW,QAAQ,QAAQ,KAAK,QAAQ,MAAM,GAAG,OAAO;CAC7D,MAAM,KAAK,QAAQ,SAAS,GAAG,QAAQ,KAAK;CAC5C,MAAM,KAAK,QAAQ,SAAS,GAAG,QAAQ,G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,KAAK,IACjB,iBACA,KAAK,IAAI,GAAG,KAAK,KAAK,KAAK,IAAI,MAAM,KAAK,IAAI,KAAK,IAAI,MAAM,IAAI,CAAC,CAAC,CACrE;CACA,MAAM,SAAmB,CAAC;CAC1B,KAAK,IAAI,IAAI,GAAG,KAAK,OAAO,KAAK;EAC/B,MAAM,QAAQ,SAAU,MAAM,SAAS,IAAK;EAC5C,OAAO,KAAK;GAAE,GAAG,KAAK,KAAK,KAAK,IAAI,KAAK;GAAG,GAAG,KAAK,KAAK,KAAK,IAAI,KAAK;EAAE,CAAC;CAC5E;CACA,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"flatten.js","names":[],"sources":["../../src/outline/flatten.ts"],"sourcesContent":["import { appendAll } from '@open-pencil/std/arrays'\n\nimport { cubicPoint } from '../cubic'\nimport { GeometryCommand, readGeometryBlob } from '../geometry'\nimport { buildChains } from '../paths/network'\nimport type { PolygonOutlineCommand } from '../polygon'\nimport type { Vector } from '../primitives'\nimport type { VectorNetwork } from '../types'\n\n/**\n * Keeps a huge curve at a tiny tolerance from flattening into an unbounded number of points, while\n * leaving room for the largest arcs at the maximum zoom: a 100,000-unit circle at 25,600% needs\n * about 12,000 steps to stay within the click pad.\n */\nconst MAX_CURVE_STEPS = 65_536\n\n/**\n * Steps that keep a cubic's polyline within `tolerance` of it: equal steps in t stray at most\n * M / (8n²) from a curve whose second derivative is at most M, and for a cubic\n * M ≤ 6 · max(|p0 − 2p1 + p2|, |p1 − 2p2 + p3|).\n */\nfunction curveSteps(p0: Vector, p1: Vector, p2: Vector, p3: Vector, tolerance: number): number {\n const bend = Math.max(\n Math.hypot(p0.x - 2 * p1.x + p2.x, p0.y - 2 * p1.y + p2.y),\n Math.hypot(p1.x - 2 * p2.x + p3.x, p1.y - 2 * p2.y + p3.y)\n )\n const steps = Math.ceil(Math.sqrt((6 * bend) / (8 * tolerance)))\n return Math.min(MAX_CURVE_STEPS, Math.max(1, steps))\n}\n\n/** Points along a cubic after its start, within `tolerance` of it, ending on `p3`. */\nfunction cubicPoints(p0: Vector, p1: Vector, p2: Vector, p3: Vector, tolerance: number): Vector[] {\n const steps = curveSteps(p0, p1, p2, p3, tolerance)\n const points: Vector[] = []\n for (let step = 1; step <= steps; step++) points.push(cubicPoint(p0, p1, p2, p3, step / steps))\n return points\n}\n\n/** Points along a vector network segment, from its start to its end, in network coordinates. */\nexport function segmentPoints(\n network: VectorNetwork,\n index: number,\n tolerance: number\n): Vector[] | null {\n // `at` counts a negative index from the end and truncates a fraction; a loop naming either\n // refers to no segment.\n if (!Number.isInteger(index) || index < 0) return null\n const segment = network.segments.at(index)\n if (!segment || segment.start < 0 || segment.end < 0) return null\n const p0 = network.vertices.at(segment.start)\n const p3 = network.vertices.at(segment.end)\n if (!p0 || !p3) return null\n const { tangentStart: a, tangentEnd: b } = segment\n if (a.x === 0 && a.y === 0 && b.x === 0 && b.y === 0) return [p0, p3]\n const p1 = { x: p0.x + a.x, y: p0.y + a.y }\n const p2 = { x: p3.x + b.x, y: p3.y + b.y }\n return [p0, ...cubicPoints(p0, p1, p2, p3, tolerance)]\n}\n\n/**\n * A loop's points in the order it is walked. Segments in a loop can be stored either way round,\n * so each is followed from the vertex the previous one ended on.\n */\nexport function loopPoints(network: VectorNetwork, loop: number[], tolerance: number): Vector[] {\n const { segments } = network\n const first = segments.at(loop[0] ?? -1)\n const second = segments.at(loop[1] ?? -1)\n if (!first) return []\n // Walk the first segment toward the vertex it shares with the next one.\n const firstForward = !second || first.end === second.start || first.end === second.end\n let current = firstForward ? first.start : first.end\n const points: Vector[] = []\n for (const index of loop) {\n const segment = segments.at(index)\n const along = segmentPoints(network, index, tolerance)\n if (!segment || !along) continue\n const forward = segment.start === current\n appendAll(points, forward ? along : along.toReversed())\n current = forward ? segment.end : segment.start\n }\n return points\n}\n\n/**\n * The network's segments joined into runs, chained through the vertices they share as the canvas\n * draws an open network (`buildChains`), each run walked from its open end.\n */\nexport function segmentRuns(network: VectorNetwork, tolerance: number): Vector[][] {\n const runs: Vector[][] = []\n for (const chain of buildChains(network.segments)) {\n let current = chain.start\n let run: Vector[] = []\n for (const index of chain.segments) {\n const segment = network.segments[index]\n const forward = segment.start === current\n current = forward ? segment.end : segment.start\n const along = segmentPoints(network, index, tolerance)\n // A segment naming a missing vertex breaks the run: what follows starts a run of its own.\n if (!along) {\n if (run.length > 1) runs.push(run)\n run = []\n continue\n }\n const points = forward ? along : along.toReversed()\n appendAll(run, run.length > 0 ? points.slice(1) : points)\n }\n if (run.length > 1) runs.push(run)\n }\n return runs\n}\n\n/** The contours of a Figma geometry blob, curves flattened to within `tolerance`. */\nexport function blobContours(blob: Uint8Array, tolerance: number): Vector[][] {\n const contours: Vector[][] = []\n let contour: Vector[] = []\n const flush = () => {\n if (contour.length > 1) contours.push(contour)\n contour = []\n }\n readGeometryBlob(blob, (command, c) => {\n if (command === GeometryCommand.CLOSE) return flush()\n if (command === GeometryCommand.MOVE) {\n flush()\n contour.push({ x: c[0], y: c[1] })\n return\n }\n const end = { x: c[c.length - 2], y: c[c.length - 1] }\n const last = contour.at(-1)\n if (!last || command === GeometryCommand.LINE) {\n contour.push(end)\n } else if (command === GeometryCommand.QUAD) {\n // A quadratic as the cubic with the same curve.\n const q = { x: c[0], y: c[1] }\n const c1 = { x: last.x + (2 / 3) * (q.x - last.x), y: last.y + (2 / 3) * (q.y - last.y) }\n const c2 = { x: end.x + (2 / 3) * (q.x - end.x), y: end.y + (2 / 3) * (q.y - end.y) }\n appendAll(contour, cubicPoints(last, c1, c2, end, tolerance))\n } else {\n appendAll(\n contour,\n cubicPoints(last, { x: c[0], y: c[1] }, { x: c[2], y: c[3] }, end, tolerance)\n )\n }\n })\n flush()\n return contours\n}\n\n/** The contours of polygon outline commands, curves flattened to within `tolerance`. */\nexport function commandContours(\n commands: readonly PolygonOutlineCommand[],\n tolerance: number\n): Vector[][] {\n const contours: Vector[][] = []\n let contour: Vector[] = []\n for (const command of commands) {\n if (command.type === 'Z' || command.type === 'M') {\n if (contour.length > 1) contours.push(contour)\n contour = command.type === 'M' ? [{ x: command.x, y: command.y }] : []\n continue\n }\n const last = contour.at(-1) ?? { x: 0, y: 0 }\n if (command.type !== 'C') contour.push({ x: command.x, y: command.y })\n else\n appendAll(\n contour,\n cubicPoints(\n last,\n { x: command.x1, y: command.y1 },\n { x: command.x2, y: command.y2 },\n { x: command.x, y: command.y },\n tolerance\n )\n )\n }\n if (contour.length > 1) contours.push(contour)\n return contours\n}\n\n/** Points around an ellipse arc from `start` to `end` radians, at most `tolerance` off it. */\nexport function arcPoints(\n cx: number,\n cy: number,\n rx: number,\n ry: number,\n start: number,\n end: number,\n tolerance: number\n): Vector[] {\n const radius = Math.max(rx, ry)\n // A chord over angle θ strays r(1 − cos(θ/2)) from the arc.\n const step =\n radius > tolerance ? 2 * Math.acos(Math.max(-1, 1 - tolerance / radius)) : Math.PI / 2\n const steps = Math.min(\n MAX_CURVE_STEPS,\n Math.max(1, Math.ceil(Math.abs(end - start) / Math.max(step, 1e-3)))\n )\n const points: Vector[] = []\n for (let i = 0; i <= steps; i++) {\n const angle = start + ((end - start) * i) / steps\n points.push({ x: cx + rx * Math.cos(angle), y: cy + ry * Math.sin(angle) })\n }\n return points\n}\n"],"mappings":";;;;;;;;;;AAcA,MAAM,kBAAkB;;;;;;AAOxB,SAAS,WAAW,IAAY,IAAY,IAAY,IAAY,WAA2B;CAC7F,MAAM,OAAO,KAAK,IAChB,KAAK,MAAM,GAAG,IAAI,IAAI,GAAG,IAAI,GAAG,GAAG,GAAG,IAAI,IAAI,GAAG,IAAI,GAAG,CAAC,GACzD,KAAK,MAAM,GAAG,IAAI,IAAI,GAAG,IAAI,GAAG,GAAG,GAAG,IAAI,IAAI,GAAG,IAAI,GAAG,CAAC,CAC3D;CACA,MAAM,QAAQ,KAAK,KAAK,KAAK,KAAM,IAAI,QAAS,IAAI,UAAU,CAAC;CAC/D,OAAO,KAAK,IAAI,iBAAiB,KAAK,IAAI,GAAG,KAAK,CAAC;AACrD;;AAGA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