@open-pencil/scene-graph 0.17.0-beta.3 → 0.17.0-beta.5
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/arrays.d.ts +17 -0
- package/dist/arrays.d.ts.map +1 -0
- package/dist/arrays.js +38 -0
- package/dist/arrays.js.map +1 -0
- 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/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 +2 -9
- package/dist/components/properties.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 +16 -7
- package/dist/css/grid.js.map +1 -1
- package/dist/css/index.d.ts +2 -2
- package/dist/css/index.js +2 -2
- package/dist/css/values.d.ts +6 -1
- package/dist/css/values.d.ts.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 +155 -5
- 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 +4 -0
- package/dist/graph.d.ts.map +1 -1
- package/dist/graph.js +30 -4
- 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/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/instances/assignments.js +39 -6
- package/dist/instances/assignments.js.map +1 -1
- package/dist/instances/index.d.ts.map +1 -1
- package/dist/instances/index.js +39 -2
- 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 +10 -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 +4 -2
- package/dist/layout/index.js +4 -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/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 +16 -1
- 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/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 +43 -0
- package/dist/paths/network.d.ts.map +1 -0
- package/dist/paths/network.js +249 -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/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/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 +4 -3
- package/dist/text/index.js +4 -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/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 +21 -8
- 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 +12 -76
- package/dist/vector-network.js.map +1 -1
- package/package.json +25 -1
- package/src/arrays.ts +37 -0
- package/src/buffered-events.ts +2 -1
- package/src/clipping.ts +11 -8
- package/src/components/properties.ts +1 -13
- package/src/corners.ts +93 -0
- package/src/css/grid.ts +21 -7
- package/src/css/index.ts +1 -1
- package/src/font-style.ts +38 -4
- package/src/geometry.ts +219 -6
- package/src/gradient.ts +23 -1
- package/src/graph.ts +22 -4
- 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 +5 -4
- package/src/icons/index.ts +1 -0
- package/src/images.ts +67 -7
- package/src/instances/assignments.ts +65 -7
- package/src/instances/index.ts +53 -4
- 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 +11 -9
- package/src/instances/sync.ts +11 -184
- package/src/layout/guides.ts +42 -9
- package/src/layout/index.ts +2 -0
- package/src/layout/limits.ts +64 -0
- package/src/layout/sizing.ts +0 -2
- package/src/layout/spacing.ts +11 -0
- package/src/masks.ts +51 -0
- package/src/matrix.ts +15 -2
- package/src/node-defaults.ts +23 -3
- package/src/outline/flatten.ts +30 -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/paths/arc.ts +59 -0
- package/src/paths/index.ts +4 -0
- package/src/paths/network.ts +334 -0
- package/src/paths/sink.ts +50 -0
- package/src/paths/smooth-corners.ts +356 -0
- package/src/plugin-data/fields.ts +2 -0
- package/src/polygon.ts +0 -17
- package/src/resize.ts +6 -7
- package/src/scaling/node.ts +29 -3
- package/src/text/auto-resize.ts +25 -0
- package/src/text/index.ts +1 -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/transfer/dependencies.ts +3 -2
- package/src/transfer/nodes.ts +2 -1
- package/src/types.ts +25 -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 +14 -2
- package/src/variables/subtree.ts +1 -1
- package/src/vector-network.ts +17 -138
package/dist/outline/flatten.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { cubicPoint } from "../cubic.js";
|
|
2
2
|
import { GeometryCommand, readGeometryBlob } from "../geometry.js";
|
|
3
|
+
import { appendAll } from "../arrays.js";
|
|
4
|
+
import { buildChains } from "../paths/network.js";
|
|
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,OA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AG,GAC/B;GAAE,GAAG,QAAQ;GAAI,GAAG,QAAQ;EAAG,GAC/B;GAAE,GAAG,QAAQ;GAAG,GAAG,QAAQ;EAAE,GAC7B,SACF,CACF;CACJ;CACA,IAAI,QAAQ,SAAS,GAAG,SAAS,KAAK,OAAO;CAC7C,OAAO;AACT;;AAGA,SAAgB,UACd,IACA,IACA,IACA,IACA,OACA,KACA,WACU;CACV,MAAM,SAAS,KAAK,IAAI,IAAI,EAAE;CAE9B,MAAM,OACJ,SAAS,YAAY,IAAI,KAAK,KAAK,KAAK,IAAI,IAAI,IAAI,YAAY,MAAM,CAAC,IAAI,KAAK,KAAK;CACvF,MAAM,QAAQ,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 '../arrays'\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":";;;;;;;;;;AAaA,MAAM,kBAAkB;;;;;;AAOxB,SAAS,WAAW,IAAY,IAAY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C1B,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"}
|
package/dist/outline/hit.d.ts
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import { SceneGraph } from "../graph.js";
|
|
2
|
-
import {
|
|
2
|
+
import { SceneNode } from "../types.js";
|
|
3
3
|
//#region src/outline/hit.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* Whether a paint makes its layer clickable, as in Figma: a visible paint that shows something.
|
|
6
|
-
* A paint at 0% opacity, or a gradient whose stops are all transparent, does not; 1% does, and
|
|
7
|
-
* the layer's own opacity does not matter.
|
|
8
|
-
*/
|
|
9
|
-
declare function isHitPaint(paint: Fill): boolean;
|
|
10
4
|
/** The farthest a layer's clickable strokes reach outside its box, in its own units. */
|
|
11
5
|
declare function strokeReach(node: SceneNode): number;
|
|
12
6
|
/**
|
|
@@ -17,5 +11,5 @@ declare function strokeReach(node: SceneNode): number;
|
|
|
17
11
|
*/
|
|
18
12
|
declare function hitsShape(graph: SceneGraph, node: SceneNode, px: number, py: number, pad?: number): boolean | null;
|
|
19
13
|
//#endregion
|
|
20
|
-
export { hitsShape,
|
|
14
|
+
export { hitsShape, strokeReach };
|
|
21
15
|
//# sourceMappingURL=hit.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hit.d.ts","names":[],"sources":["../../src/outline/hit.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"hit.d.ts","names":[],"sources":["../../src/outline/hit.ts"],"mappings":";;;;iBA+BgB,YAAY,MAAM;;;;;;;iBAmTlB,UACd,OAAO,YACP,MAAM,WACN,YACA,YACA"}
|
package/dist/outline/hit.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import Matrix from "../matrix.js";
|
|
2
2
|
import { getWorldMatrix } from "../coordinate.js";
|
|
3
3
|
import { arrowCapOverflow, isArrowCap, lineStrokeEnds } from "../arrow-caps.js";
|
|
4
|
+
import { strokeWeightOf } from "../geometry.js";
|
|
4
5
|
import { containsByWinding, distanceToLines, distanceToSegment } from "./point.js";
|
|
6
|
+
import { paintShows } from "../paints/shows.js";
|
|
5
7
|
import { hitsArrowHeads } from "./heads.js";
|
|
6
8
|
import { shapeOutline } from "./shapes.js";
|
|
7
9
|
import { compact } from "es-toolkit";
|
|
@@ -10,35 +12,24 @@ import { compact } from "es-toolkit";
|
|
|
10
12
|
const EDGE_SAMPLES = 8;
|
|
11
13
|
/** How far a flattened curve may stray from the shape when nothing tighter is asked for. */
|
|
12
14
|
const DEFAULT_TOLERANCE = .25;
|
|
13
|
-
/**
|
|
14
|
-
* Whether a paint makes its layer clickable, as in Figma: a visible paint that shows something.
|
|
15
|
-
* A paint at 0% opacity, or a gradient whose stops are all transparent, does not; 1% does, and
|
|
16
|
-
* the layer's own opacity does not matter.
|
|
17
|
-
*/
|
|
18
|
-
function isHitPaint(paint) {
|
|
19
|
-
if (!paint.visible || !(paint.opacity > 0)) return false;
|
|
20
|
-
if (paint.gradientStops) return paint.gradientStops.some((stop) => stop.color.a > 0);
|
|
21
|
-
if (paint.type === "SOLID") return paint.color.a > 0;
|
|
22
|
-
return true;
|
|
23
|
-
}
|
|
24
15
|
function insideArea(area, point) {
|
|
25
16
|
return containsByWinding(area.contours, area.windingRule, point);
|
|
26
17
|
}
|
|
27
|
-
/** A stroke's weight
|
|
28
|
-
function
|
|
29
|
-
|
|
30
|
-
return Number.isFinite(
|
|
18
|
+
/** A stroke's weight, the widest side with sides of their own, for layers without per-side lines. */
|
|
19
|
+
function hitWeight(node, stroke) {
|
|
20
|
+
const weight = strokeWeightOf(node, stroke);
|
|
21
|
+
return Number.isFinite(weight) ? weight : node.strokeWeight;
|
|
31
22
|
}
|
|
32
23
|
/** The farthest a layer's clickable strokes reach outside its box, in its own units. */
|
|
33
24
|
function strokeReach(node) {
|
|
34
25
|
let reach = 0;
|
|
35
26
|
for (const stroke of node.strokes) {
|
|
36
|
-
if (!
|
|
37
|
-
const weight =
|
|
27
|
+
if (!paintShows(stroke)) continue;
|
|
28
|
+
const weight = hitWeight(node, stroke);
|
|
38
29
|
const side = node.type === "LINE" || stroke.align === "OUTSIDE";
|
|
39
30
|
reach = Math.max(reach, side ? weight : weight / 2);
|
|
40
31
|
}
|
|
41
|
-
const hitStrokes = node.strokes.filter(
|
|
32
|
+
const hitStrokes = node.strokes.filter(paintShows);
|
|
42
33
|
return Math.max(reach, arrowCapOverflow(hitStrokes, node.strokeCap, node.vectorNetwork));
|
|
43
34
|
}
|
|
44
35
|
function localPoint(graph, node, px, py) {
|
|
@@ -217,7 +208,7 @@ function strokeHits(node, stroke, probe, pad) {
|
|
|
217
208
|
if (probe.strokeAreaWithin) return probe.strokeAreaWithin(pad);
|
|
218
209
|
const align = probe.closed && !probe.centered ? stroke.align : "CENTER";
|
|
219
210
|
if (probe.strokeOnEdge) {
|
|
220
|
-
const weight =
|
|
211
|
+
const weight = hitWeight(node, stroke);
|
|
221
212
|
return probe.edgeWithin(strokeReachAt(align, weight, probe.inside) + pad);
|
|
222
213
|
}
|
|
223
214
|
const cap = stroke.cap ?? node.strokeCap;
|
|
@@ -227,7 +218,7 @@ function strokeHits(node, stroke, probe, pad) {
|
|
|
227
218
|
return line.distance <= band + pad;
|
|
228
219
|
};
|
|
229
220
|
if (node.type === "LINE" && probe.local) {
|
|
230
|
-
const weight =
|
|
221
|
+
const weight = hitWeight(node, stroke);
|
|
231
222
|
if (!(weight > 0)) return false;
|
|
232
223
|
const { start, end } = lineStrokeEnds(node.width, node.height, weight, cap);
|
|
233
224
|
if (reaches(measureLine([start, end], [true, true], probe.local), weight / 2)) return true;
|
|
@@ -249,11 +240,11 @@ function strokeHits(node, stroke, probe, pad) {
|
|
|
249
240
|
}
|
|
250
241
|
const network = node.type === "VECTOR" ? node.vectorNetwork : null;
|
|
251
242
|
if (network && probe.local) {
|
|
252
|
-
const weight =
|
|
243
|
+
const weight = hitWeight(node, stroke);
|
|
253
244
|
if (weight > 0 && hitsArrowHeads(network, cap, weight, probe.local, pad)) return true;
|
|
254
245
|
}
|
|
255
246
|
return probe.lines.some((line, index) => {
|
|
256
|
-
const weight = probe.lineWeights?.[index] ??
|
|
247
|
+
const weight = probe.lineWeights?.[index] ?? hitWeight(node, stroke);
|
|
257
248
|
if (!(weight > 0)) return false;
|
|
258
249
|
return reaches(line, strokeReachAt(align, weight, probe.inside));
|
|
259
250
|
});
|
|
@@ -267,10 +258,10 @@ function strokeHits(node, stroke, probe, pad) {
|
|
|
267
258
|
function hitsShape(graph, node, px, py, pad = 0) {
|
|
268
259
|
const probe = probeNode(graph, node, px, py, pad > 0 ? Math.min(DEFAULT_TOLERANCE, pad / 4) : DEFAULT_TOLERANCE);
|
|
269
260
|
if (!probe) return null;
|
|
270
|
-
if (node.fills.filter(
|
|
271
|
-
return node.strokes.some((stroke) =>
|
|
261
|
+
if (node.fills.filter(paintShows).length > 0 && probe.closed && (probe.inside || probe.edgeWithin(pad))) return true;
|
|
262
|
+
return node.strokes.some((stroke) => paintShows(stroke) && strokeHits(node, stroke, probe, pad));
|
|
272
263
|
}
|
|
273
264
|
//#endregion
|
|
274
|
-
export { hitsShape,
|
|
265
|
+
export { hitsShape, strokeReach };
|
|
275
266
|
|
|
276
267
|
//# sourceMappingURL=hit.js.map
|
package/dist/outline/hit.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hit.js","names":[],"sources":["../../src/outline/hit.ts"],"sourcesContent":["import { compact } from 'es-toolkit'\n\nimport { arrowCapOverflow, isArrowCap, lineStrokeEnds } from '../arrow-caps'\nimport { getWorldMatrix } from '../coordinate'\nimport type { SceneGraph } from '../graph'\nimport Matrix from '../matrix'\nimport type { Vector } from '../primitives'\nimport type { Fill, SceneNode, Stroke } from '../types'\nimport { hitsArrowHeads } from './heads'\nimport { containsByWinding, distanceToLines, distanceToSegment } from './point'\nimport { shapeOutline, type OutlineArea, type ShapeOutline } from './shapes'\n\n/** Points tested along each edge near the point for whether the filled result changes there. */\nconst EDGE_SAMPLES = 8\n\n/** How far a flattened curve may stray from the shape when nothing tighter is asked for. */\nconst DEFAULT_TOLERANCE = 0.25\n\n/**\n * Whether a paint makes its layer clickable, as in Figma: a visible paint that shows something.\n * A paint at 0% opacity, or a gradient whose stops are all transparent, does not; 1% does, and\n * the layer's own opacity does not matter.\n */\nexport function isHitPaint(paint: Fill): boolean {\n if (!paint.visible || !(paint.opacity > 0)) return false\n if (paint.gradientStops) return paint.gradientStops.some((stop) => stop.color.a > 0)\n if (paint.type === 'SOLID') return paint.color.a > 0\n return true\n}\n\nfunction insideArea(area: OutlineArea, point: Vector): boolean {\n return containsByWinding(area.contours, area.windingRule, point)\n}\n\n/** A stroke's weight; with independent borders the widest side, for layers without per-side lines. */\nfunction strokeWeightOf(node: SceneNode, stroke: Stroke): number {\n if (node.independentStrokeWeights) {\n return Math.max(\n node.borderTopWeight,\n node.borderRightWeight,\n node.borderBottomWeight,\n node.borderLeftWeight\n )\n }\n return Number.isFinite(stroke.weight) ? stroke.weight : node.strokeWeight\n}\n\n/** The farthest a layer's clickable strokes reach outside its box, in its own units. */\nexport function strokeReach(node: SceneNode): number {\n let reach = 0\n for (const stroke of node.strokes) {\n if (!isHitPaint(stroke)) continue\n const weight = strokeWeightOf(node, stroke)\n // A line's stroke lies a full weight to one side of it.\n const side = node.type === 'LINE' || stroke.align === 'OUTSIDE'\n reach = Math.max(reach, side ? weight : weight / 2)\n }\n // Arrow heads reach past the stroke.\n const hitStrokes = node.strokes.filter(isHitPaint)\n return Math.max(reach, arrowCapOverflow(hitStrokes, node.strokeCap, node.vectorNetwork))\n}\n\nfunction localPoint(graph: SceneGraph, node: SceneNode, px: number, py: number): Vector | null {\n const inverse = Matrix.invert(getWorldMatrix(node, graph))\n if (!inverse) return null\n const [x, y] = Matrix.mapPoints(inverse, [px, py])\n return { x, y }\n}\n\ninterface Probe {\n inside: boolean\n /** The point in the layer's own coordinates, where its outline has one. */\n local?: Vector\n /**\n * Whether the outline of the filled area passes within `radius` of the point, counting only\n * edges where the filled result changes from one side to the other.\n */\n edgeWithin: (radius: number) => boolean\n /** Each line a stroke follows, measured from the point in canvas units. */\n lines: LineReach[]\n /** Each line's own stroke weight, where sides differ. */\n lineWeights?: number[]\n /** Whether the layer has an area of its own; strokes on lines are always centred. */\n closed: boolean\n /** Strokes centre on the lines whatever their alignment. */\n centered?: boolean\n /** Strokes follow the filled area's outline, for a shape combined from operands. */\n strokeOnEdge?: boolean\n /** Whether the point lies on or within `radius` of the saved outline a stroke fills. */\n strokeAreaWithin?: (radius: number) => boolean\n}\n\n/**\n * Whether an outline made of `edges` passes within `radius` of the point, counting a stretch of\n * edge only where `insideAt` changes from one side of it to the other: edges that cancel or that\n * lie hidden inside or outside the result count for nothing.\n */\nfunction changingEdgeWithin(\n edges: Vector[][],\n insideAt: (x: number, y: number) => boolean | null,\n point: Vector,\n radius: number,\n tolerance: number\n): boolean {\n const step = Math.max(1e-6, Math.min(tolerance, radius / 4) / 4)\n for (const edge of edges) {\n for (let i = 0; i + 1 < edge.length; i++) {\n const a = edge[i]\n const b = edge[i + 1]\n if (a.x === b.x && a.y === b.y) continue\n if (distanceToSegment(point, a, b) > radius) continue\n const dx = b.x - a.x\n const dy = b.y - a.y\n const length = Math.hypot(dx, dy)\n const nx = -dy / length\n const ny = dx / length\n // The part of the edge inside the circle, sampled evenly.\n const centre = ((point.x - a.x) * dx + (point.y - a.y) * dy) / (length * length)\n const offset = Math.abs((point.x - a.x) * nx + (point.y - a.y) * ny)\n const half = Math.sqrt(Math.max(0, radius * radius - offset * offset)) / length\n const from = Math.max(0, centre - half)\n const to = Math.min(1, centre + half)\n for (let k = 0; k <= EDGE_SAMPLES; k++) {\n const t = from + ((to - from) * k) / EDGE_SAMPLES\n const qx = a.x + dx * t\n const qy = a.y + dy * t\n const left = insideAt(qx + nx * step, qy + ny * step)\n const right = insideAt(qx - nx * step, qy - ny * step)\n if (left !== null && right !== null && left !== right) return true\n }\n }\n }\n return false\n}\n\n/**\n * How a point lies from a line: its distance, and past an open end how far beyond the end it is\n * along the line and how far across it, for a flat cap that paints nothing past the end.\n */\ninterface LineReach {\n distance: number\n beyond: number\n across: number\n}\n\nfunction measureLine(\n line: Vector[],\n ends: [boolean, boolean] | undefined,\n point: Vector\n): LineReach {\n const reach: LineReach = { distance: distanceToLines([line], point), beyond: 0, across: 0 }\n if (!ends || line.length < 2) return reach\n // Past an open end, the point projects beyond the first or last segment.\n const tips: Array<[boolean, Vector, Vector]> = [\n [ends[0], line[0], line[1]],\n [ends[1], line[line.length - 1], line[line.length - 2]]\n ]\n for (const [open, tip, next] of tips) {\n if (!open) continue\n const dx = tip.x - next.x\n const dy = tip.y - next.y\n const length = Math.hypot(dx, dy)\n if (length === 0) continue\n const along = ((point.x - tip.x) * dx + (point.y - tip.y) * dy) / length\n if (along <= 0 || Math.hypot(point.x - tip.x, point.y - tip.y) > reach.distance + 1e-9) continue\n reach.beyond = along\n reach.across = Math.abs((point.x - tip.x) * dy - (point.y - tip.y) * dx) / length\n }\n return reach\n}\n\nfunction probeOutline(outline: ShapeOutline, point: Vector, tolerance: number): Probe {\n const insideAt = (x: number, y: number) =>\n outline.areas.some((area) => insideArea(area, { x, y }))\n const edges = outline.areas.flatMap((area) => area.contours.map(closedLoop))\n const { strokeAreas } = outline\n return {\n inside: insideAt(point.x, point.y),\n local: point,\n edgeWithin: (radius) => changingEdgeWithin(edges, insideAt, point, radius, tolerance),\n lines: outline.lines.map((line, index) => measureLine(line, outline.lineEnds?.[index], point)),\n lineWeights: outline.lineWeights,\n closed: outline.areas.some((area) => area.contours.length > 0),\n centered: outline.strokeCentered,\n strokeAreaWithin: strokeAreas\n ? (radius) =>\n strokeAreas.some((area) => insideArea(area, point)) ||\n changingEdgeWithin(\n strokeAreas.flatMap((area) => area.contours.map(closedLoop)),\n (x, y) => strokeAreas.some((area) => insideArea(area, { x, y })),\n point,\n radius,\n tolerance\n )\n : undefined\n }\n}\n\nfunction closedLoop(contour: Vector[]): Vector[] {\n const first = contour.at(0)\n return first ? [...contour, first] : contour\n}\n\nconst BOOLEAN_COMBINE: Record<\n NonNullable<SceneNode['booleanOperation']>,\n (hits: boolean[]) => boolean\n> = {\n UNION: (hits) => hits.some(Boolean),\n INTERSECT: (hits) => hits.length > 0 && hits.every(Boolean),\n SUBTRACT: ([first = false, ...rest]) => first && !rest.some(Boolean),\n EXCLUDE: (hits) => compact(hits).length % 2 === 1\n}\n\n/** The lines an operand draws its outline along, in canvas coordinates. */\nfunction operandEdges(graph: SceneGraph, node: SceneNode, tolerance: number): Vector[][] {\n if (node.type === 'BOOLEAN_OPERATION' && node.fillGeometry.length === 0) {\n return graph\n .getChildren(node.id)\n .filter((child) => child.visible)\n .flatMap((child) => operandEdges(graph, child, tolerance))\n }\n const outline =\n node.type === 'BOOLEAN_OPERATION'\n ? shapeOutline({ ...node, type: 'VECTOR', vectorNetwork: null }, tolerance)\n : shapeOutline(node, tolerance)\n if (!outline) return []\n const world = getWorldMatrix(node, graph)\n const local = [\n ...outline.lines,\n ...outline.areas.flatMap((area) => area.contours.map(closedLoop))\n ]\n return local.map((line) =>\n line.map((point) => {\n const [x, y] = Matrix.mapPoints(world, [point.x, point.y])\n return { x, y }\n })\n )\n}\n\n/**\n * A boolean operation without saved geometry, combined from its operands as it draws. Its outline\n * runs along the operand edges where the combined result changes from one side to the other, so\n * edges hidden inside or outside the result count for nothing. Each side is probed at most a\n * quarter of a screen pixel out, so a result thinner than that, which draws no visible pixel, is\n * not seen.\n */\nfunction probeBoolean(\n graph: SceneGraph,\n node: SceneNode,\n px: number,\n py: number,\n tolerance: number\n): Probe | null {\n const operands = graph.getChildren(node.id).filter((child) => child.visible)\n if (operands.length === 0) return null\n const combine = BOOLEAN_COMBINE[node.booleanOperation ?? 'UNION']\n const insideAt = (x: number, y: number): boolean | null => {\n const hits: boolean[] = []\n for (const operand of operands) {\n const probe = probeNode(graph, operand, x, y, tolerance)\n if (!probe) return null\n hits.push(probe.inside)\n }\n return combine(hits)\n }\n const inside = insideAt(px, py)\n if (inside === null) return null\n const point = { x: px, y: py }\n const edges = operands.flatMap((operand) => operandEdges(graph, operand, tolerance))\n return {\n inside,\n edgeWithin: (radius) => changingEdgeWithin(edges, insideAt, point, radius, tolerance),\n lines: [],\n closed: true,\n strokeOnEdge: true\n }\n}\n\nfunction probeNode(\n graph: SceneGraph,\n node: SceneNode,\n px: number,\n py: number,\n tolerance: number\n): Probe | null {\n if (node.type === 'BOOLEAN_OPERATION' && node.fillGeometry.length === 0) {\n return probeBoolean(graph, node, px, py, tolerance)\n }\n const outline =\n node.type === 'BOOLEAN_OPERATION'\n ? shapeOutline({ ...node, type: 'VECTOR', vectorNetwork: null }, tolerance)\n : shapeOutline(node, tolerance)\n if (!outline) return null\n const point = localPoint(graph, node, px, py)\n return point ? probeOutline(outline, point, tolerance) : null\n}\n\n/** How far from a line a stroke's band reaches toward the point, beyond which it misses. */\nfunction strokeReachAt(align: Stroke['align'], weight: number, inside: boolean): number {\n if (align === 'INSIDE') return inside ? weight : 0\n if (align === 'OUTSIDE') return inside ? 0 : weight\n return weight / 2\n}\n\nfunction strokeHits(node: SceneNode, stroke: Stroke, probe: Probe, pad: number): boolean {\n if (probe.strokeAreaWithin) return probe.strokeAreaWithin(pad)\n const align = probe.closed && !probe.centered ? stroke.align : 'CENTER'\n if (probe.strokeOnEdge) {\n const weight = strokeWeightOf(node, stroke)\n return probe.edgeWithin(strokeReachAt(align, weight, probe.inside) + pad)\n }\n // A flat cap ends the stroke at the line's end; round and square caps paint past it.\n const cap = stroke.cap ?? node.strokeCap\n const flatEnds = cap === 'NONE'\n const reaches = (line: LineReach, band: number): boolean => {\n if (flatEnds && line.beyond > 0) {\n // Past a flat end, the distance to the painted band's square end.\n return Math.hypot(line.beyond, Math.max(0, line.across - band)) <= pad\n }\n return line.distance <= band + pad\n }\n if (node.type === 'LINE' && probe.local) {\n // Figma strokes a line a full weight to one side, along the path the renderer draws.\n const weight = strokeWeightOf(node, stroke)\n if (!(weight > 0)) return false\n const { start, end } = lineStrokeEnds(node.width, node.height, weight, cap)\n if (reaches(measureLine([start, end], [true, true], probe.local), weight / 2)) return true\n if (!isArrowCap(cap)) return false\n const still = { x: 0, y: 0 }\n const shaft = {\n vertices: [start, end],\n segments: [{ start: 0, end: 1, tangentStart: still, tangentEnd: still }],\n regions: []\n }\n return hitsArrowHeads(shaft, cap, weight, probe.local, pad)\n }\n const network = node.type === 'VECTOR' ? node.vectorNetwork : null\n if (network && probe.local) {\n const weight = strokeWeightOf(node, stroke)\n if (weight > 0 && hitsArrowHeads(network, cap, weight, probe.local, pad)) return true\n }\n return probe.lines.some((line, index) => {\n const weight = probe.lineWeights?.[index] ?? strokeWeightOf(node, stroke)\n // A side with no weight paints no border.\n if (!(weight > 0)) return false\n return reaches(line, strokeReachAt(align, weight, probe.inside))\n })\n}\n\n/**\n * Whether a click at the canvas point lands on the shape, as in Figma: inside the area a\n * clickable fill covers, or on the band a clickable stroke draws, either grown by `pad` canvas\n * units. A shape whose paints show nothing is never hit. Null for a layer without an outline to\n * test, which is hit by its box.\n */\nexport function hitsShape(\n graph: SceneGraph,\n node: SceneNode,\n px: number,\n py: number,\n pad = 0\n): boolean | null {\n const tolerance = pad > 0 ? Math.min(DEFAULT_TOLERANCE, pad / 4) : DEFAULT_TOLERANCE\n const probe = probeNode(graph, node, px, py, tolerance)\n if (!probe) return null\n const fills = node.fills.filter(isHitPaint)\n if (fills.length > 0 && probe.closed && (probe.inside || probe.edgeWithin(pad))) return true\n return node.strokes.some((stroke) => isHitPaint(stroke) && strokeHits(node, stroke, probe, pad))\n}\n"],"mappings":";;;;;;;;;AAaA,MAAM,eAAe;;AAGrB,MAAM,oBAAoB;;;;;;AAO1B,SAAgB,WAAW,OAAsB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JpB,UAAU,CAAC,OAAO,GAAG;GACrB,UAAU,CAAC;IAAE,OAAO;IAAG,KAAK;IAAG,cAAc;IAAO,YAAY;GAAM,CAAC;GACvE,SAAS,CAAC;EAEc,GAAG,KAAK,QAAQ,MAAM,OAAO,GAAG;CAC5D;CACA,MAAM,UAAU,KAAK,SAAS,WAAW,KAAK,gBAAgB;CAC9D,IAAI,WAAW,MAAM,OAAO;EAC1B,MAAM,SAAS,eAAe,MAAM,MAAM;EAC1C,IAAI,SAAS,KAAK,eAAe,SAAS,KAAK,QAAQ,MAAM,OAAO,GAAG,GAAG,OAAO;CACnF;CACA,OAAO,MAAM,MAAM,MAAM,MAAM,UAAU;EACvC,MAAM,SAAS,MAAM,cAAc,UAAU,eAAe,MAAM,MAAM;EAExE,IAAI,EAAE,SAAS,IAAI,OAAO;EAC1B,OAAO,QAAQ,MAAM,cAAc,OAAO,QAAQ,MAAM,MAAM,CAAC;CACjE,CAAC;AACH;;;;;;;AAQA,SAAgB,UACd,OACA,MACA,IACA,IACA,MAAM,GACU;CAEhB,MAAM,QAAQ,UAAU,OAAO,MAAM,IAAI,IADvB,MAAM,IAAI,KAAK,IAAI,mBAAmB,MAAM,CAAC,IAAI,iBACb;CACtD,IAAI,CAAC,OAAO,OAAO;CAEnB,IADc,KAAK,MAAM,OAAO,UACxB,CAAC,CAAC,SAAS,KAAK,MAAM,WAAW,MAAM,UAAU,MAAM,WAAW,GAAG,IAAI,OAAO;CACxF,OAAO,KAAK,QAAQ,MAAM,WAAW,WAAW,MAAM,KAAK,WAAW,MAAM,QAAQ,OAAO,GAAG,CAAC;AACjG"}
|
|
1
|
+
{"version":3,"file":"hit.js","names":[],"sources":["../../src/outline/hit.ts"],"sourcesContent":["import { compact } from 'es-toolkit'\n\nimport { arrowCapOverflow, isArrowCap, lineStrokeEnds } from '../arrow-caps'\nimport { getWorldMatrix } from '../coordinate'\nimport { strokeWeightOf } from '../geometry'\nimport type { SceneGraph } from '../graph'\nimport Matrix from '../matrix'\nimport { paintShows } from '../paints/shows'\nimport type { Vector } from '../primitives'\nimport type { SceneNode, Stroke } from '../types'\nimport { hitsArrowHeads } from './heads'\nimport { containsByWinding, distanceToLines, distanceToSegment } from './point'\nimport { shapeOutline, type OutlineArea, type ShapeOutline } from './shapes'\n\n/** Points tested along each edge near the point for whether the filled result changes there. */\nconst EDGE_SAMPLES = 8\n\n/** How far a flattened curve may stray from the shape when nothing tighter is asked for. */\nconst DEFAULT_TOLERANCE = 0.25\n\nfunction insideArea(area: OutlineArea, point: Vector): boolean {\n return containsByWinding(area.contours, area.windingRule, point)\n}\n\n/** A stroke's weight, the widest side with sides of their own, for layers without per-side lines. */\nfunction hitWeight(node: SceneNode, stroke: Stroke): number {\n const weight = strokeWeightOf(node, stroke)\n return Number.isFinite(weight) ? weight : node.strokeWeight\n}\n\n/** The farthest a layer's clickable strokes reach outside its box, in its own units. */\nexport function strokeReach(node: SceneNode): number {\n let reach = 0\n for (const stroke of node.strokes) {\n if (!paintShows(stroke)) continue\n const weight = hitWeight(node, stroke)\n // A line's stroke lies a full weight to one side of it.\n const side = node.type === 'LINE' || stroke.align === 'OUTSIDE'\n reach = Math.max(reach, side ? weight : weight / 2)\n }\n // Arrow heads reach past the stroke.\n const hitStrokes = node.strokes.filter(paintShows)\n return Math.max(reach, arrowCapOverflow(hitStrokes, node.strokeCap, node.vectorNetwork))\n}\n\nfunction localPoint(graph: SceneGraph, node: SceneNode, px: number, py: number): Vector | null {\n const inverse = Matrix.invert(getWorldMatrix(node, graph))\n if (!inverse) return null\n const [x, y] = Matrix.mapPoints(inverse, [px, py])\n return { x, y }\n}\n\ninterface Probe {\n inside: boolean\n /** The point in the layer's own coordinates, where its outline has one. */\n local?: Vector\n /**\n * Whether the outline of the filled area passes within `radius` of the point, counting only\n * edges where the filled result changes from one side to the other.\n */\n edgeWithin: (radius: number) => boolean\n /** Each line a stroke follows, measured from the point in canvas units. */\n lines: LineReach[]\n /** Each line's own stroke weight, where sides differ. */\n lineWeights?: number[]\n /** Whether the layer has an area of its own; strokes on lines are always centred. */\n closed: boolean\n /** Strokes centre on the lines whatever their alignment. */\n centered?: boolean\n /** Strokes follow the filled area's outline, for a shape combined from operands. */\n strokeOnEdge?: boolean\n /** Whether the point lies on or within `radius` of the saved outline a stroke fills. */\n strokeAreaWithin?: (radius: number) => boolean\n}\n\n/**\n * Whether an outline made of `edges` passes within `radius` of the point, counting a stretch of\n * edge only where `insideAt` changes from one side of it to the other: edges that cancel or that\n * lie hidden inside or outside the result count for nothing.\n */\nfunction changingEdgeWithin(\n edges: Vector[][],\n insideAt: (x: number, y: number) => boolean | null,\n point: Vector,\n radius: number,\n tolerance: number\n): boolean {\n const step = Math.max(1e-6, Math.min(tolerance, radius / 4) / 4)\n for (const edge of edges) {\n for (let i = 0; i + 1 < edge.length; i++) {\n const a = edge[i]\n const b = edge[i + 1]\n if (a.x === b.x && a.y === b.y) continue\n if (distanceToSegment(point, a, b) > radius) continue\n const dx = b.x - a.x\n const dy = b.y - a.y\n const length = Math.hypot(dx, dy)\n const nx = -dy / length\n const ny = dx / length\n // The part of the edge inside the circle, sampled evenly.\n const centre = ((point.x - a.x) * dx + (point.y - a.y) * dy) / (length * length)\n const offset = Math.abs((point.x - a.x) * nx + (point.y - a.y) * ny)\n const half = Math.sqrt(Math.max(0, radius * radius - offset * offset)) / length\n const from = Math.max(0, centre - half)\n const to = Math.min(1, centre + half)\n for (let k = 0; k <= EDGE_SAMPLES; k++) {\n const t = from + ((to - from) * k) / EDGE_SAMPLES\n const qx = a.x + dx * t\n const qy = a.y + dy * t\n const left = insideAt(qx + nx * step, qy + ny * step)\n const right = insideAt(qx - nx * step, qy - ny * step)\n if (left !== null && right !== null && left !== right) return true\n }\n }\n }\n return false\n}\n\n/**\n * How a point lies from a line: its distance, and past an open end how far beyond the end it is\n * along the line and how far across it, for a flat cap that paints nothing past the end.\n */\ninterface LineReach {\n distance: number\n beyond: number\n across: number\n}\n\nfunction measureLine(\n line: Vector[],\n ends: [boolean, boolean] | undefined,\n point: Vector\n): LineReach {\n const reach: LineReach = { distance: distanceToLines([line], point), beyond: 0, across: 0 }\n if (!ends || line.length < 2) return reach\n // Past an open end, the point projects beyond the first or last segment.\n const tips: Array<[boolean, Vector, Vector]> = [\n [ends[0], line[0], line[1]],\n [ends[1], line[line.length - 1], line[line.length - 2]]\n ]\n for (const [open, tip, next] of tips) {\n if (!open) continue\n const dx = tip.x - next.x\n const dy = tip.y - next.y\n const length = Math.hypot(dx, dy)\n if (length === 0) continue\n const along = ((point.x - tip.x) * dx + (point.y - tip.y) * dy) / length\n if (along <= 0 || Math.hypot(point.x - tip.x, point.y - tip.y) > reach.distance + 1e-9) continue\n reach.beyond = along\n reach.across = Math.abs((point.x - tip.x) * dy - (point.y - tip.y) * dx) / length\n }\n return reach\n}\n\nfunction probeOutline(outline: ShapeOutline, point: Vector, tolerance: number): Probe {\n const insideAt = (x: number, y: number) =>\n outline.areas.some((area) => insideArea(area, { x, y }))\n const edges = outline.areas.flatMap((area) => area.contours.map(closedLoop))\n const { strokeAreas } = outline\n return {\n inside: insideAt(point.x, point.y),\n local: point,\n edgeWithin: (radius) => changingEdgeWithin(edges, insideAt, point, radius, tolerance),\n lines: outline.lines.map((line, index) => measureLine(line, outline.lineEnds?.[index], point)),\n lineWeights: outline.lineWeights,\n closed: outline.areas.some((area) => area.contours.length > 0),\n centered: outline.strokeCentered,\n strokeAreaWithin: strokeAreas\n ? (radius) =>\n strokeAreas.some((area) => insideArea(area, point)) ||\n changingEdgeWithin(\n strokeAreas.flatMap((area) => area.contours.map(closedLoop)),\n (x, y) => strokeAreas.some((area) => insideArea(area, { x, y })),\n point,\n radius,\n tolerance\n )\n : undefined\n }\n}\n\nfunction closedLoop(contour: Vector[]): Vector[] {\n const first = contour.at(0)\n return first ? [...contour, first] : contour\n}\n\nconst BOOLEAN_COMBINE: Record<\n NonNullable<SceneNode['booleanOperation']>,\n (hits: boolean[]) => boolean\n> = {\n UNION: (hits) => hits.some(Boolean),\n INTERSECT: (hits) => hits.length > 0 && hits.every(Boolean),\n SUBTRACT: ([first = false, ...rest]) => first && !rest.some(Boolean),\n EXCLUDE: (hits) => compact(hits).length % 2 === 1\n}\n\n/** The lines an operand draws its outline along, in canvas coordinates. */\nfunction operandEdges(graph: SceneGraph, node: SceneNode, tolerance: number): Vector[][] {\n if (node.type === 'BOOLEAN_OPERATION' && node.fillGeometry.length === 0) {\n return graph\n .getChildren(node.id)\n .filter((child) => child.visible)\n .flatMap((child) => operandEdges(graph, child, tolerance))\n }\n const outline =\n node.type === 'BOOLEAN_OPERATION'\n ? shapeOutline({ ...node, type: 'VECTOR', vectorNetwork: null }, tolerance)\n : shapeOutline(node, tolerance)\n if (!outline) return []\n const world = getWorldMatrix(node, graph)\n const local = [\n ...outline.lines,\n ...outline.areas.flatMap((area) => area.contours.map(closedLoop))\n ]\n return local.map((line) =>\n line.map((point) => {\n const [x, y] = Matrix.mapPoints(world, [point.x, point.y])\n return { x, y }\n })\n )\n}\n\n/**\n * A boolean operation without saved geometry, combined from its operands as it draws. Its outline\n * runs along the operand edges where the combined result changes from one side to the other, so\n * edges hidden inside or outside the result count for nothing. Each side is probed at most a\n * quarter of a screen pixel out, so a result thinner than that, which draws no visible pixel, is\n * not seen.\n */\nfunction probeBoolean(\n graph: SceneGraph,\n node: SceneNode,\n px: number,\n py: number,\n tolerance: number\n): Probe | null {\n const operands = graph.getChildren(node.id).filter((child) => child.visible)\n if (operands.length === 0) return null\n const combine = BOOLEAN_COMBINE[node.booleanOperation ?? 'UNION']\n const insideAt = (x: number, y: number): boolean | null => {\n const hits: boolean[] = []\n for (const operand of operands) {\n const probe = probeNode(graph, operand, x, y, tolerance)\n if (!probe) return null\n hits.push(probe.inside)\n }\n return combine(hits)\n }\n const inside = insideAt(px, py)\n if (inside === null) return null\n const point = { x: px, y: py }\n const edges = operands.flatMap((operand) => operandEdges(graph, operand, tolerance))\n return {\n inside,\n edgeWithin: (radius) => changingEdgeWithin(edges, insideAt, point, radius, tolerance),\n lines: [],\n closed: true,\n strokeOnEdge: true\n }\n}\n\nfunction probeNode(\n graph: SceneGraph,\n node: SceneNode,\n px: number,\n py: number,\n tolerance: number\n): Probe | null {\n if (node.type === 'BOOLEAN_OPERATION' && node.fillGeometry.length === 0) {\n return probeBoolean(graph, node, px, py, tolerance)\n }\n const outline =\n node.type === 'BOOLEAN_OPERATION'\n ? shapeOutline({ ...node, type: 'VECTOR', vectorNetwork: null }, tolerance)\n : shapeOutline(node, tolerance)\n if (!outline) return null\n const point = localPoint(graph, node, px, py)\n return point ? probeOutline(outline, point, tolerance) : null\n}\n\n/** How far from a line a stroke's band reaches toward the point, beyond which it misses. */\nfunction strokeReachAt(align: Stroke['align'], weight: number, inside: boolean): number {\n if (align === 'INSIDE') return inside ? weight : 0\n if (align === 'OUTSIDE') return inside ? 0 : weight\n return weight / 2\n}\n\nfunction strokeHits(node: SceneNode, stroke: Stroke, probe: Probe, pad: number): boolean {\n if (probe.strokeAreaWithin) return probe.strokeAreaWithin(pad)\n const align = probe.closed && !probe.centered ? stroke.align : 'CENTER'\n if (probe.strokeOnEdge) {\n const weight = hitWeight(node, stroke)\n return probe.edgeWithin(strokeReachAt(align, weight, probe.inside) + pad)\n }\n // A flat cap ends the stroke at the line's end; round and square caps paint past it.\n const cap = stroke.cap ?? node.strokeCap\n const flatEnds = cap === 'NONE'\n const reaches = (line: LineReach, band: number): boolean => {\n if (flatEnds && line.beyond > 0) {\n // Past a flat end, the distance to the painted band's square end.\n return Math.hypot(line.beyond, Math.max(0, line.across - band)) <= pad\n }\n return line.distance <= band + pad\n }\n if (node.type === 'LINE' && probe.local) {\n // Figma strokes a line a full weight to one side, along the path the renderer draws.\n const weight = hitWeight(node, stroke)\n if (!(weight > 0)) return false\n const { start, end } = lineStrokeEnds(node.width, node.height, weight, cap)\n if (reaches(measureLine([start, end], [true, true], probe.local), weight / 2)) return true\n if (!isArrowCap(cap)) return false\n const still = { x: 0, y: 0 }\n const shaft = {\n vertices: [start, end],\n segments: [{ start: 0, end: 1, tangentStart: still, tangentEnd: still }],\n regions: []\n }\n return hitsArrowHeads(shaft, cap, weight, probe.local, pad)\n }\n const network = node.type === 'VECTOR' ? node.vectorNetwork : null\n if (network && probe.local) {\n const weight = hitWeight(node, stroke)\n if (weight > 0 && hitsArrowHeads(network, cap, weight, probe.local, pad)) return true\n }\n return probe.lines.some((line, index) => {\n const weight = probe.lineWeights?.[index] ?? hitWeight(node, stroke)\n // A side with no weight paints no border.\n if (!(weight > 0)) return false\n return reaches(line, strokeReachAt(align, weight, probe.inside))\n })\n}\n\n/**\n * Whether a click at the canvas point lands on the shape, as in Figma: inside the area a\n * clickable fill covers, or on the band a clickable stroke draws, either grown by `pad` canvas\n * units. A shape whose paints show nothing is never hit. Null for a layer without an outline to\n * test, which is hit by its box.\n */\nexport function hitsShape(\n graph: SceneGraph,\n node: SceneNode,\n px: number,\n py: number,\n pad = 0\n): boolean | null {\n const tolerance = pad > 0 ? Math.min(DEFAULT_TOLERANCE, pad / 4) : DEFAULT_TOLERANCE\n const probe = probeNode(graph, node, px, py, tolerance)\n if (!probe) return null\n const fills = node.fills.filter(paintShows)\n if (fills.length > 0 && probe.closed && (probe.inside || probe.edgeWithin(pad))) return true\n return node.strokes.some((stroke) => paintShows(stroke) && strokeHits(node, stroke, probe, pad))\n}\n"],"mappings":";;;;;;;;;;;AAeA,MAAM,eAAe;;AAGrB,MAAM,oBAAoB;AAE1B,SAAS,WAAW,MAAmB,OAAwB;CAC7D,OAAO,kBAAkB,KAAK,UAAU,KAAK,aAAa,KAAK;AACjE;;AAGA,SAAS,UAAU,MAAiB,QAAwB;CAC1D,MAAM,SAAS,eAAe,MAAM,MAAM;CAC1C,OAAO,OAAO,SAAS,MAAM,IAAI,SAAS,KAAK;AACjD;;AAGA,SAAgB,YAAY,MAAyB;CACnD,IAAI,QAAQ;CACZ,KAAK,MAAM,UAAU,KAAK,SAAS;EACjC,IAAI,CAAC,WAAW,MAAM,GAAG;EACzB,MAAM,SAAS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ACA,MAAM,GACU;CAEhB,MAAM,QAAQ,UAAU,OAAO,MAAM,IAAI,IADvB,MAAM,IAAI,KAAK,IAAI,mBAAmB,MAAM,CAAC,IAAI,iBACb;CACtD,IAAI,CAAC,OAAO,OAAO;CAEnB,IADc,KAAK,MAAM,OAAO,UACxB,CAAC,CAAC,SAAS,KAAK,MAAM,WAAW,MAAM,UAAU,MAAM,WAAW,GAAG,IAAI,OAAO;CACxF,OAAO,KAAK,QAAQ,MAAM,WAAW,WAAW,MAAM,KAAK,WAAW,MAAM,QAAQ,OAAO,GAAG,CAAC;AACjG"}
|
package/dist/outline/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { hitsShape,
|
|
2
|
-
import { OutlineArea, ShapeOutline, shapeOutline } from "./shapes.js";
|
|
1
|
+
import { hitsShape, strokeReach } from "./hit.js";
|
|
2
|
+
import { OutlineArea, ShapeOutline, isWholeEllipse, shapeOutline } from "./shapes.js";
|
|
3
3
|
import { blobContours, loopPoints, segmentPoints } from "./flatten.js";
|
|
4
4
|
import { containsByWinding, distanceToLines, distanceToSegment, windingNumber } from "./point.js";
|
|
5
|
-
export { type OutlineArea, type ShapeOutline, blobContours, containsByWinding, distanceToLines, distanceToSegment, hitsShape,
|
|
5
|
+
export { type OutlineArea, type ShapeOutline, blobContours, containsByWinding, distanceToLines, distanceToSegment, hitsShape, isWholeEllipse, loopPoints, segmentPoints, shapeOutline, strokeReach, windingNumber };
|
package/dist/outline/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { containsByWinding, distanceToLines, distanceToSegment, windingNumber } from "./point.js";
|
|
2
2
|
import { blobContours, loopPoints, segmentPoints } from "./flatten.js";
|
|
3
|
-
import { shapeOutline } from "./shapes.js";
|
|
4
|
-
import { hitsShape,
|
|
5
|
-
export { blobContours, containsByWinding, distanceToLines, distanceToSegment, hitsShape,
|
|
3
|
+
import { isWholeEllipse, shapeOutline } from "./shapes.js";
|
|
4
|
+
import { hitsShape, strokeReach } from "./hit.js";
|
|
5
|
+
export { blobContours, containsByWinding, distanceToLines, distanceToSegment, hitsShape, isWholeEllipse, loopPoints, segmentPoints, shapeOutline, strokeReach, windingNumber };
|
package/dist/outline/shapes.d.ts
CHANGED
|
@@ -25,11 +25,13 @@ interface ShapeOutline {
|
|
|
25
25
|
/** The saved outline a stroke fills, for a shape whose stroke has no lines to follow. */
|
|
26
26
|
strokeAreas?: OutlineArea[];
|
|
27
27
|
}
|
|
28
|
+
/** Whether a layer is an unbroken ellipse: an ELLIPSE whose arc, if any, is a whole turn with no hole. */
|
|
29
|
+
declare function isWholeEllipse(node: Pick<SceneNode, 'type' | 'arcData'>): boolean;
|
|
28
30
|
/**
|
|
29
31
|
* The outline a click is tested against, in the node's own coordinates, with curves within
|
|
30
32
|
* `tolerance` of the shape; null for layers tested by their box, such as text.
|
|
31
33
|
*/
|
|
32
34
|
declare function shapeOutline(node: SceneNode, tolerance: number): ShapeOutline | null;
|
|
33
35
|
//#endregion
|
|
34
|
-
export { OutlineArea, ShapeOutline, shapeOutline };
|
|
36
|
+
export { OutlineArea, ShapeOutline, isWholeEllipse, shapeOutline };
|
|
35
37
|
//# sourceMappingURL=shapes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shapes.d.ts","names":[],"sources":["../../src/outline/shapes.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"shapes.d.ts","names":[],"sources":["../../src/outline/shapes.ts"],"mappings":";;;;UAgBiB;EACf,aAAa;EACb,UAAU;;;;;;UAOK;EACf,OAAO;EACP,OAAO;;EAEP;;;;;EAKA;;EAEA,WAAW;;EAEX,cAAc;;;iBAqDA,eAAe,MAAM,KAAK;;;;;iBAkE1B,aAAa,MAAM,WAAW,oBAAoB"}
|
package/dist/outline/shapes.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { borderWeights, sweepsWholeTurn } from "../geometry.js";
|
|
2
|
+
import { nodeCornerRadii } from "../corners.js";
|
|
3
|
+
import { arcOutline } from "../paths/arc.js";
|
|
1
4
|
import { polygonOutline } from "../polygon.js";
|
|
2
5
|
import { arcPoints, blobContours, commandContours, loopPoints, segmentPoints, segmentRuns } from "./flatten.js";
|
|
3
6
|
//#region src/outline/shapes.ts
|
|
@@ -16,24 +19,9 @@ function fromContours(contours, windingRule = "NONZERO") {
|
|
|
16
19
|
lines: contours.map(closed)
|
|
17
20
|
};
|
|
18
21
|
}
|
|
19
|
-
function cornerRadii(node) {
|
|
20
|
-
const radii = node.independentCorners ? [
|
|
21
|
-
node.topLeftRadius,
|
|
22
|
-
node.topRightRadius,
|
|
23
|
-
node.bottomRightRadius,
|
|
24
|
-
node.bottomLeftRadius
|
|
25
|
-
] : [
|
|
26
|
-
node.cornerRadius,
|
|
27
|
-
node.cornerRadius,
|
|
28
|
-
node.cornerRadius,
|
|
29
|
-
node.cornerRadius
|
|
30
|
-
];
|
|
31
|
-
const limit = Math.min(node.width, node.height) / 2;
|
|
32
|
-
return radii.map((radius) => Math.max(0, Math.min(radius, limit)));
|
|
33
|
-
}
|
|
34
22
|
function rectangleContour(node, tolerance) {
|
|
35
23
|
const { width: w, height: h } = node;
|
|
36
|
-
const [tl, tr, br, bl] =
|
|
24
|
+
const [tl, tr, br, bl] = nodeCornerRadii(node);
|
|
37
25
|
const corner = (cx, cy, r, from) => r > 0 ? arcPoints(cx, cy, r, r, from, from + Math.PI / 2, tolerance) : [{
|
|
38
26
|
x: cx,
|
|
39
27
|
y: cy
|
|
@@ -52,7 +40,7 @@ function rectangleContour(node, tolerance) {
|
|
|
52
40
|
*/
|
|
53
41
|
function rectangleSides(node, tolerance) {
|
|
54
42
|
const { width: w, height: h } = node;
|
|
55
|
-
const [tl, tr, br, bl] =
|
|
43
|
+
const [tl, tr, br, bl] = nodeCornerRadii(node);
|
|
56
44
|
const quarter = Math.PI / 4;
|
|
57
45
|
const arc = (cx, cy, r, from) => r > 0 ? arcPoints(cx, cy, r, r, from, from + quarter, tolerance) : [{
|
|
58
46
|
x: cx,
|
|
@@ -65,30 +53,21 @@ function rectangleSides(node, tolerance) {
|
|
|
65
53
|
[...arc(w - br, h - br, br, quarter), ...arc(bl, h - bl, bl, 2 * quarter)],
|
|
66
54
|
[...arc(bl, h - bl, bl, 3 * quarter), ...arc(tl, tl, tl, 4 * quarter)]
|
|
67
55
|
],
|
|
68
|
-
lineWeights: [
|
|
69
|
-
node.borderTopWeight,
|
|
70
|
-
node.borderRightWeight,
|
|
71
|
-
node.borderBottomWeight,
|
|
72
|
-
node.borderLeftWeight
|
|
73
|
-
]
|
|
56
|
+
lineWeights: [...borderWeights(node)]
|
|
74
57
|
};
|
|
75
58
|
}
|
|
76
|
-
|
|
77
|
-
function
|
|
78
|
-
|
|
79
|
-
const ry = node.height / 2;
|
|
59
|
+
/** Whether a layer is an unbroken ellipse: an ELLIPSE whose arc, if any, is a whole turn with no hole. */
|
|
60
|
+
function isWholeEllipse(node) {
|
|
61
|
+
if (node.type !== "ELLIPSE") return false;
|
|
80
62
|
const arc = node.arcData;
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}, ...outer]];
|
|
90
|
-
const hole = arcPoints(rx, ry, rx * inner, ry * inner, whole ? start + FULL_TURN : end, start, tolerance);
|
|
91
|
-
return whole ? [outer, hole] : [[...outer, ...hole]];
|
|
63
|
+
return !arc || arc.innerRadius <= 0 && sweepsWholeTurn(arc.startingAngle, arc.endingAngle);
|
|
64
|
+
}
|
|
65
|
+
function ellipseContours(node, tolerance) {
|
|
66
|
+
const { cx, cy, contours } = arcOutline(node);
|
|
67
|
+
return contours.map((contour) => contour.flatMap((step) => step.type === "centre" ? [{
|
|
68
|
+
x: cx,
|
|
69
|
+
y: cy
|
|
70
|
+
}] : arcPoints(cx, cy, step.rx, step.ry, step.start, step.start + step.sweep, tolerance)));
|
|
92
71
|
}
|
|
93
72
|
function vectorOutline(node, tolerance) {
|
|
94
73
|
const network = node.vectorNetwork;
|
|
@@ -176,6 +155,6 @@ function shapeOutline(node, tolerance) {
|
|
|
176
155
|
}
|
|
177
156
|
}
|
|
178
157
|
//#endregion
|
|
179
|
-
export { shapeOutline };
|
|
158
|
+
export { isWholeEllipse, shapeOutline };
|
|
180
159
|
|
|
181
160
|
//# sourceMappingURL=shapes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shapes.js","names":[],"sources":["../../src/outline/shapes.ts"],"sourcesContent":["import { polygonOutline } from '../polygon'\nimport type { Vector } from '../primitives'\nimport type { SceneNode, WindingRule } from '../types'\nimport {\n arcPoints,\n blobContours,\n commandContours,\n loopPoints,\n segmentPoints,\n segmentRuns\n} from './flatten'\n\n/** Contours filled together under one winding rule. */\nexport interface OutlineArea {\n windingRule: WindingRule\n contours: Vector[][]\n}\n\n/**\n * A shape's geometry in its own coordinates, curves flattened: the areas its fills cover and the\n * lines its strokes follow, closed contours ending where they began.\n */\nexport interface ShapeOutline {\n areas: OutlineArea[]\n lines: Vector[][]\n /** Each line's own stroke weight, where sides differ, as a rectangle's independent borders. */\n lineWeights?: number[]\n /**\n * Strokes centre on the lines whatever their alignment, as on a network without regions that is\n * open or has no saved stroke geometry.\n */\n strokeCentered?: boolean\n /** For each line, whether its start and its end are open ends, where a stroke's cap is drawn. */\n lineEnds?: Array<[boolean, boolean]>\n /** The saved outline a stroke fills, for a shape whose stroke has no lines to follow. */\n strokeAreas?: OutlineArea[]\n}\n\nfunction closed(contour: Vector[]): Vector[] {\n const first = contour.at(0)\n const last = contour.at(-1)\n if (!first || !last || (first.x === last.x && first.y === last.y)) return contour\n return [...contour, first]\n}\n\nfunction fromContours(contours: Vector[][], windingRule: WindingRule = 'NONZERO'): ShapeOutline {\n return { areas: [{ windingRule, contours }], lines: contours.map(closed) }\n}\n\nfunction cornerRadii(node: SceneNode): [number, number, number, number] {\n const radii: [number, number, number, number] = node.independentCorners\n ? [node.topLeftRadius, node.topRightRadius, node.bottomRightRadius, node.bottomLeftRadius]\n : [node.cornerRadius, node.cornerRadius, node.cornerRadius, node.cornerRadius]\n const limit = Math.min(node.width, node.height) / 2\n return radii.map((radius) => Math.max(0, Math.min(radius, limit))) as typeof radii\n}\n\nfunction rectangleContour(node: SceneNode, tolerance: number): Vector[] {\n const { width: w, height: h } = node\n const [tl, tr, br, bl] = cornerRadii(node)\n const corner = (cx: number, cy: number, r: number, from: number): Vector[] =>\n r > 0 ? arcPoints(cx, cy, r, r, from, from + Math.PI / 2, tolerance) : [{ x: cx, y: cy }]\n return [\n ...corner(w - tr, tr, tr, -Math.PI / 2),\n ...corner(w - br, h - br, br, 0),\n ...corner(bl, h - bl, bl, Math.PI / 2),\n ...corner(tl, tl, tl, Math.PI)\n ]\n}\n\n/**\n * A rectangle's four sides with the weight each draws its border at: top, right, bottom, left.\n * Each side runs from the middle of one rounded corner to the middle of the next, as its border\n * is drawn round them.\n */\nfunction rectangleSides(\n node: SceneNode,\n tolerance: number\n): Pick<ShapeOutline, 'lines' | 'lineWeights'> {\n const { width: w, height: h } = node\n const [tl, tr, br, bl] = cornerRadii(node)\n const quarter = Math.PI / 4\n const arc = (cx: number, cy: number, r: number, from: number): Vector[] =>\n r > 0 ? arcPoints(cx, cy, r, r, from, from + quarter, tolerance) : [{ x: cx, y: cy }]\n return {\n lines: [\n [...arc(tl, tl, tl, 5 * quarter), ...arc(w - tr, tr, tr, -2 * quarter)],\n [...arc(w - tr, tr, tr, -quarter), ...arc(w - br, h - br, br, 0)],\n [...arc(w - br, h - br, br, quarter), ...arc(bl, h - bl, bl, 2 * quarter)],\n [...arc(bl, h - bl, bl, 3 * quarter), ...arc(tl, tl, tl, 4 * quarter)]\n ],\n lineWeights: [\n node.borderTopWeight,\n node.borderRightWeight,\n node.borderBottomWeight,\n node.borderLeftWeight\n ]\n }\n}\n\nconst FULL_TURN = Math.PI * 2\n\nfunction ellipseContours(node: SceneNode, tolerance: number): Vector[][] {\n const rx = node.width / 2\n const ry = node.height / 2\n const arc = node.arcData\n const start = arc?.startingAngle ?? 0\n const end = arc?.endingAngle ?? FULL_TURN\n const inner = arc?.innerRadius ?? 0\n const whole = Math.abs(end - start) >= FULL_TURN - 1e-6\n const outer = arcPoints(rx, ry, rx, ry, start, whole ? start + FULL_TURN : end, tolerance)\n if (inner <= 0) return [whole ? outer : [{ x: rx, y: ry }, ...outer]]\n const hole = arcPoints(\n rx,\n ry,\n rx * inner,\n ry * inner,\n whole ? start + FULL_TURN : end,\n start,\n tolerance\n )\n // A whole ring is two loops wound opposite ways; a part ring is one outline across its ends.\n return whole ? [outer, hole] : [[...outer, ...hole]]\n}\n\nfunction vectorOutline(node: SceneNode, tolerance: number): ShapeOutline | null {\n const network = node.vectorNetwork\n const geometry = node.fillGeometry.map((path) => ({\n windingRule: path.windingRule,\n contours: path.commandsBlob.length > 0 ? blobContours(path.commandsBlob, tolerance) : []\n }))\n if (!network) {\n if (geometry.length === 0 && node.strokeGeometry.length === 0) return null\n // Without a network the renderer fills the saved stroke geometry, or draws no stroke.\n const strokeAreas = node.strokeGeometry.map((path) => ({\n windingRule: path.windingRule,\n contours: path.commandsBlob.length > 0 ? blobContours(path.commandsBlob, tolerance) : []\n }))\n return { areas: geometry, lines: [], strokeAreas }\n }\n // A vertex on one segment only is an open end.\n const degree = new Map<number, number>()\n for (const segment of network.segments) {\n degree.set(segment.start, (degree.get(segment.start) ?? 0) + 1)\n degree.set(segment.end, (degree.get(segment.end) ?? 0) + 1)\n }\n const lines: Vector[][] = []\n const lineEnds: Array<[boolean, boolean]> = []\n for (const [index, segment] of network.segments.entries()) {\n const points = segmentPoints(network, index, tolerance)\n if (!points) continue\n lines.push(points)\n lineEnds.push([degree.get(segment.start) === 1, degree.get(segment.end) === 1])\n }\n // Without regions the stroke draws centred on each segment, unless a closed network carries\n // saved stroke geometry, which the renderer draws with its alignment.\n const open = lineEnds.some(([start, end]) => start || end)\n const strokeCentered = network.regions.length === 0 && (open || node.strokeGeometry.length === 0)\n if (geometry.length > 0) return { areas: geometry, lines, lineEnds, strokeCentered }\n const areas =\n network.regions.length > 0\n ? network.regions.map((region) => ({\n windingRule: region.windingRule,\n contours: region.loops.map((loop) => loopPoints(network, loop, tolerance))\n }))\n : // Without regions a fill closes each run of segments, as a path fill does.\n [{ windingRule: 'NONZERO' as const, contours: segmentRuns(network, tolerance) }]\n return { areas, lines, lineEnds, strokeCentered }\n}\n\n/**\n * The outline a click is tested against, in the node's own coordinates, with curves within\n * `tolerance` of the shape; null for layers tested by their box, such as text.\n */\nexport function shapeOutline(node: SceneNode, tolerance: number): ShapeOutline | null {\n switch (node.type) {\n case 'RECTANGLE':\n case 'ROUNDED_RECTANGLE': {\n const outline = fromContours([rectangleContour(node, tolerance)])\n return node.independentStrokeWeights\n ? { ...outline, ...rectangleSides(node, tolerance) }\n : outline\n }\n case 'ELLIPSE': {\n if (node.fillGeometry.length > 0) return vectorOutline(node, tolerance)\n return fromContours(ellipseContours(node, tolerance))\n }\n case 'POLYGON':\n case 'STAR':\n return fromContours(commandContours(polygonOutline(node), tolerance))\n case 'LINE':\n return {\n areas: [],\n lines: [\n [\n { x: 0, y: 0 },\n { x: node.width, y: node.height }\n ]\n ],\n lineEnds: [[true, true]]\n }\n case 'VECTOR':\n return vectorOutline(node, tolerance)\n default:\n return null\n }\n}\n"],"mappings":";;;AAsCA,SAAS,OAAO,SAA6B;CAC3C,MAAM,QAAQ,QAAQ,GAAG,CAAC;CAC1B,MAAM,OAAO,QAAQ,GAAG,EAAE;CAC1B,IAAI,CAAC,SAAS,CAAC,QAAS,MAAM,MAAM,KAAK,KAAK,MAAM,MAAM,KAAK,GAAI,OAAO;CAC1E,OAAO,CAAC,GAAG,SAAS,KAAK;AAC3B;AAEA,SAAS,aAAa,UAAsB,cAA2B,WAAyB;CAC9F,OAAO;EAAE,OAAO,CAAC;GAAE;GAAa;EAAS,CAAC;EAAG,OAAO,SAAS,IAAI,MAAM;CAAE;AAC3E;AAEA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AE,OAPP,QAAQ,QAAQ,SAAS,IACrB,QAAQ,QAAQ,KAAK,YAAY;GAC/B,aAAa,OAAO;GACpB,UAAU,OAAO,MAAM,KAAK,SAAS,WAAW,SAAS,MAAM,SAAS,CAAC;EAC3E,EAAE,IAEF,CAAC;GAAE,aAAa;GAAoB,UAAU,YAAY,SAAS,SAAS;EAAE,CAAC;EACrE;EAAO;EAAU;CAAe;AAClD;;;;;AAMA,SAAgB,aAAa,MAAiB,WAAwC;CACpF,QAAQ,KAAK,MAAb;EACE,KAAK;EACL,KAAK,qBAAqB;GACxB,MAAM,UAAU,aAAa,CAAC,iBAAiB,MAAM,SAAS,CAAC,CAAC;GAChE,OAAO,KAAK,2BACR;IAAE,GAAG;IAAS,GAAG,eAAe,MAAM,SAAS;GAAE,IACjD;EACN;EACA,KAAK;GACH,IAAI,KAAK,aAAa,SAAS,GAAG,OAAO,cAAc,MAAM,SAAS;GACtE,OAAO,aAAa,gBAAgB,MAAM,SAAS,CAAC;EAEtD,KAAK;EACL,KAAK,QACH,OAAO,aAAa,gBAAgB,eAAe,IAAI,GAAG,SAAS,CAAC;EACtE,KAAK,QACH,OAAO;GACL,OAAO,CAAC;GACR,OAAO,CACL,CACE;IAAE,GAAG;IAAG,GAAG;GAAE,GACb;IAAE,GAAG,KAAK;IAAO,GAAG,KAAK;GAAO,CAClC,CACF;GACA,UAAU,CAAC,CAAC,MAAM,IAAI,CAAC;EACzB;EACF,KAAK,UACH,OAAO,cAAc,MAAM,SAAS;EACtC,SACE,OAAO;CACX;AACF"}
|
|
1
|
+
{"version":3,"file":"shapes.js","names":[],"sources":["../../src/outline/shapes.ts"],"sourcesContent":["import { nodeCornerRadii } from '../corners'\nimport { borderWeights, sweepsWholeTurn } from '../geometry'\nimport { arcOutline } from '../paths/arc'\nimport { polygonOutline } from '../polygon'\nimport type { Vector } from '../primitives'\nimport type { SceneNode, WindingRule } from '../types'\nimport {\n arcPoints,\n blobContours,\n commandContours,\n loopPoints,\n segmentPoints,\n segmentRuns\n} from './flatten'\n\n/** Contours filled together under one winding rule. */\nexport interface OutlineArea {\n windingRule: WindingRule\n contours: Vector[][]\n}\n\n/**\n * A shape's geometry in its own coordinates, curves flattened: the areas its fills cover and the\n * lines its strokes follow, closed contours ending where they began.\n */\nexport interface ShapeOutline {\n areas: OutlineArea[]\n lines: Vector[][]\n /** Each line's own stroke weight, where sides differ, as a rectangle's independent borders. */\n lineWeights?: number[]\n /**\n * Strokes centre on the lines whatever their alignment, as on a network without regions that is\n * open or has no saved stroke geometry.\n */\n strokeCentered?: boolean\n /** For each line, whether its start and its end are open ends, where a stroke's cap is drawn. */\n lineEnds?: Array<[boolean, boolean]>\n /** The saved outline a stroke fills, for a shape whose stroke has no lines to follow. */\n strokeAreas?: OutlineArea[]\n}\n\nfunction closed(contour: Vector[]): Vector[] {\n const first = contour.at(0)\n const last = contour.at(-1)\n if (!first || !last || (first.x === last.x && first.y === last.y)) return contour\n return [...contour, first]\n}\n\nfunction fromContours(contours: Vector[][], windingRule: WindingRule = 'NONZERO'): ShapeOutline {\n return { areas: [{ windingRule, contours }], lines: contours.map(closed) }\n}\n\nfunction rectangleContour(node: SceneNode, tolerance: number): Vector[] {\n const { width: w, height: h } = node\n const [tl, tr, br, bl] = nodeCornerRadii(node)\n const corner = (cx: number, cy: number, r: number, from: number): Vector[] =>\n r > 0 ? arcPoints(cx, cy, r, r, from, from + Math.PI / 2, tolerance) : [{ x: cx, y: cy }]\n return [\n ...corner(w - tr, tr, tr, -Math.PI / 2),\n ...corner(w - br, h - br, br, 0),\n ...corner(bl, h - bl, bl, Math.PI / 2),\n ...corner(tl, tl, tl, Math.PI)\n ]\n}\n\n/**\n * A rectangle's four sides with the weight each draws its border at: top, right, bottom, left.\n * Each side runs from the middle of one rounded corner to the middle of the next, as its border\n * is drawn round them.\n */\nfunction rectangleSides(\n node: SceneNode,\n tolerance: number\n): Pick<ShapeOutline, 'lines' | 'lineWeights'> {\n const { width: w, height: h } = node\n const [tl, tr, br, bl] = nodeCornerRadii(node)\n const quarter = Math.PI / 4\n const arc = (cx: number, cy: number, r: number, from: number): Vector[] =>\n r > 0 ? arcPoints(cx, cy, r, r, from, from + quarter, tolerance) : [{ x: cx, y: cy }]\n return {\n lines: [\n [...arc(tl, tl, tl, 5 * quarter), ...arc(w - tr, tr, tr, -2 * quarter)],\n [...arc(w - tr, tr, tr, -quarter), ...arc(w - br, h - br, br, 0)],\n [...arc(w - br, h - br, br, quarter), ...arc(bl, h - bl, bl, 2 * quarter)],\n [...arc(bl, h - bl, bl, 3 * quarter), ...arc(tl, tl, tl, 4 * quarter)]\n ],\n lineWeights: [...borderWeights(node)]\n }\n}\n\n/** Whether a layer is an unbroken ellipse: an ELLIPSE whose arc, if any, is a whole turn with no hole. */\nexport function isWholeEllipse(node: Pick<SceneNode, 'type' | 'arcData'>): boolean {\n if (node.type !== 'ELLIPSE') return false\n const arc = node.arcData\n return !arc || (arc.innerRadius <= 0 && sweepsWholeTurn(arc.startingAngle, arc.endingAngle))\n}\n\nfunction ellipseContours(node: SceneNode, tolerance: number): Vector[][] {\n const { cx, cy, contours } = arcOutline(node)\n return contours.map((contour) =>\n contour.flatMap((step) =>\n step.type === 'centre'\n ? [{ x: cx, y: cy }]\n : arcPoints(cx, cy, step.rx, step.ry, step.start, step.start + step.sweep, tolerance)\n )\n )\n}\n\nfunction vectorOutline(node: SceneNode, tolerance: number): ShapeOutline | null {\n const network = node.vectorNetwork\n const geometry = node.fillGeometry.map((path) => ({\n windingRule: path.windingRule,\n contours: path.commandsBlob.length > 0 ? blobContours(path.commandsBlob, tolerance) : []\n }))\n if (!network) {\n if (geometry.length === 0 && node.strokeGeometry.length === 0) return null\n // Without a network the renderer fills the saved stroke geometry, or draws no stroke.\n const strokeAreas = node.strokeGeometry.map((path) => ({\n windingRule: path.windingRule,\n contours: path.commandsBlob.length > 0 ? blobContours(path.commandsBlob, tolerance) : []\n }))\n return { areas: geometry, lines: [], strokeAreas }\n }\n // A vertex on one segment only is an open end.\n const degree = new Map<number, number>()\n for (const segment of network.segments) {\n degree.set(segment.start, (degree.get(segment.start) ?? 0) + 1)\n degree.set(segment.end, (degree.get(segment.end) ?? 0) + 1)\n }\n const lines: Vector[][] = []\n const lineEnds: Array<[boolean, boolean]> = []\n for (const [index, segment] of network.segments.entries()) {\n const points = segmentPoints(network, index, tolerance)\n if (!points) continue\n lines.push(points)\n lineEnds.push([degree.get(segment.start) === 1, degree.get(segment.end) === 1])\n }\n // Without regions the stroke draws centred on each segment, unless a closed network carries\n // saved stroke geometry, which the renderer draws with its alignment.\n const open = lineEnds.some(([start, end]) => start || end)\n const strokeCentered = network.regions.length === 0 && (open || node.strokeGeometry.length === 0)\n if (geometry.length > 0) return { areas: geometry, lines, lineEnds, strokeCentered }\n const areas =\n network.regions.length > 0\n ? network.regions.map((region) => ({\n windingRule: region.windingRule,\n contours: region.loops.map((loop) => loopPoints(network, loop, tolerance))\n }))\n : // Without regions a fill closes each run of segments, as a path fill does.\n [{ windingRule: 'NONZERO' as const, contours: segmentRuns(network, tolerance) }]\n return { areas, lines, lineEnds, strokeCentered }\n}\n\n/**\n * The outline a click is tested against, in the node's own coordinates, with curves within\n * `tolerance` of the shape; null for layers tested by their box, such as text.\n */\nexport function shapeOutline(node: SceneNode, tolerance: number): ShapeOutline | null {\n switch (node.type) {\n case 'RECTANGLE':\n case 'ROUNDED_RECTANGLE': {\n const outline = fromContours([rectangleContour(node, tolerance)])\n return node.independentStrokeWeights\n ? { ...outline, ...rectangleSides(node, tolerance) }\n : outline\n }\n case 'ELLIPSE': {\n if (node.fillGeometry.length > 0) return vectorOutline(node, tolerance)\n return fromContours(ellipseContours(node, tolerance))\n }\n case 'POLYGON':\n case 'STAR':\n return fromContours(commandContours(polygonOutline(node), tolerance))\n case 'LINE':\n return {\n areas: [],\n lines: [\n [\n { x: 0, y: 0 },\n { x: node.width, y: node.height }\n ]\n ],\n lineEnds: [[true, true]]\n }\n case 'VECTOR':\n return vectorOutline(node, tolerance)\n default:\n return null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AC;EAC3E,EAAE,IAEF,CAAC;GAAE,aAAa;GAAoB,UAAU,YAAY,SAAS,SAAS;EAAE,CAAC;EACrE;EAAO;EAAU;CAAe;AAClD;;;;;AAMA,SAAgB,aAAa,MAAiB,WAAwC;CACpF,QAAQ,KAAK,MAAb;EACE,KAAK;EACL,KAAK,qBAAqB;GACxB,MAAM,UAAU,aAAa,CAAC,iBAAiB,MAAM,SAAS,CAAC,CAAC;GAChE,OAAO,KAAK,2BACR;IAAE,GAAG;IAAS,GAAG,eAAe,MAAM,SAAS;GAAE,IACjD;EACN;EACA,KAAK;GACH,IAAI,KAAK,aAAa,SAAS,GAAG,OAAO,cAAc,MAAM,SAAS;GACtE,OAAO,aAAa,gBAAgB,MAAM,SAAS,CAAC;EAEtD,KAAK;EACL,KAAK,QACH,OAAO,aAAa,gBAAgB,eAAe,IAAI,GAAG,SAAS,CAAC;EACtE,KAAK,QACH,OAAO;GACL,OAAO,CAAC;GACR,OAAO,CACL,CACE;IAAE,GAAG;IAAG,GAAG;GAAE,GACb;IAAE,GAAG,KAAK;IAAO,GAAG,KAAK;GAAO,CAClC,CACF;GACA,UAAU,CAAC,CAAC,MAAM,IAAI,CAAC;EACzB;EACF,KAAK,UACH,OAAO,cAAc,MAAM,SAAS;EACtC,SACE,OAAO;CACX;AACF"}
|
package/dist/paints/index.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
|
+
import { PatternTileLayout, patternTileLayout } from "./pattern.js";
|
|
1
2
|
import { fillSchema, gradientStopSchema, paintTransformSchema } from "./schema.js";
|
|
2
|
-
|
|
3
|
+
import { paintShows } from "./shows.js";
|
|
4
|
+
export { PatternTileLayout, fillSchema, gradientStopSchema, paintShows, paintTransformSchema, patternTileLayout };
|
package/dist/paints/index.js
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
|
+
import { paintShows } from "./shows.js";
|
|
2
|
+
import { patternTileLayout } from "./pattern.js";
|
|
1
3
|
import { fillSchema, gradientStopSchema, paintTransformSchema } from "./schema.js";
|
|
2
|
-
export { fillSchema, gradientStopSchema, paintTransformSchema };
|
|
4
|
+
export { fillSchema, gradientStopSchema, paintShows, paintTransformSchema, patternTileLayout };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Rect, Vector } from "../primitives/index.js";
|
|
2
|
+
import { Fill, SceneNode } from "../types.js";
|
|
3
|
+
//#region src/paints/pattern.d.ts
|
|
4
|
+
/** Where a pattern's source repeats in one tile: the tile, the source's scale, and its copies. */
|
|
5
|
+
interface PatternTileLayout {
|
|
6
|
+
rect: Rect;
|
|
7
|
+
scale: number;
|
|
8
|
+
positions: Vector[];
|
|
9
|
+
}
|
|
10
|
+
declare function patternTileLayout(source: Pick<SceneNode, 'width' | 'height'>, fill: Fill): PatternTileLayout;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { PatternTileLayout, patternTileLayout };
|
|
13
|
+
//# sourceMappingURL=pattern.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pattern.d.ts","names":[],"sources":["../../src/paints/pattern.ts"],"mappings":";;;;UAIiB;EACf,MAAM;EACN;EACA,WAAW;;iBAcG,kBACd,QAAQ,KAAK,gCACb,MAAM,OACL"}
|