@weasel-js/core 1.5.0 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/CHANGELOG.md +363 -0
  2. package/dist/autoPoseDescriptor-Dr6CwNZK.d.ts +26 -0
  3. package/dist/{chunk-UCPV7JXC.js → chunk-3LPQ2XZG.js} +4 -159
  4. package/dist/chunk-3LPQ2XZG.js.map +1 -0
  5. package/dist/{chunk-MG7OXCAI.js → chunk-GREL4MVO.js} +2276 -1485
  6. package/dist/chunk-GREL4MVO.js.map +1 -0
  7. package/dist/chunk-HAGOFNP5.js +162 -0
  8. package/dist/chunk-HAGOFNP5.js.map +1 -0
  9. package/dist/chunk-LXJDWBEL.js +318 -0
  10. package/dist/chunk-LXJDWBEL.js.map +1 -0
  11. package/dist/{chunk-BDWAA634.js → chunk-P6MGECVO.js} +3 -3
  12. package/dist/{chunk-BDWAA634.js.map → chunk-P6MGECVO.js.map} +1 -1
  13. package/dist/{chunk-MQI4PIX3.js → chunk-XXQ6FLCJ.js} +3 -3
  14. package/dist/{chunk-MQI4PIX3.js.map → chunk-XXQ6FLCJ.js.map} +1 -1
  15. package/dist/clipboard.d.ts +1 -1
  16. package/dist/clone.d.ts +2 -2
  17. package/dist/{depSchema-nMqj_qTM.d.ts → depSchema-BubKMv-2.d.ts} +67 -78
  18. package/dist/{grid-BrIa38gG.d.ts → grid-Z_Af3vTl.d.ts} +1 -1
  19. package/dist/index.d.ts +647 -382
  20. package/dist/index.js +6 -4
  21. package/dist/insert.d.ts +3 -3
  22. package/dist/insert.js +2 -1
  23. package/dist/insert.js.map +1 -1
  24. package/dist/math-E3rZn4bR.d.ts +282 -0
  25. package/dist/math.d.ts +5 -0
  26. package/dist/math.js +4 -0
  27. package/dist/math.js.map +1 -0
  28. package/dist/move.d.ts +4 -4
  29. package/dist/move.js +3 -2
  30. package/dist/move.js.map +1 -1
  31. package/dist/{options-BDyCnrp8.d.ts → options-BPcmwYk7.d.ts} +1 -1
  32. package/dist/{autoPoseDescriptor-CvjflWJK.d.ts → pointSnapToGrid-CgcK2R_I.d.ts} +2 -26
  33. package/dist/{poseDescriptor-CGOgIgf8.d.ts → poseDescriptor-PgfVKfa0.d.ts} +1 -1
  34. package/dist/renderer.d.ts +5 -6
  35. package/dist/renderer.js +6 -4
  36. package/dist/resize.d.ts +5 -4
  37. package/dist/resize.js +3 -2
  38. package/dist/{types-DMyo7dnM.d.ts → types-BHGdrOcu.d.ts} +1 -1
  39. package/dist/{types-DtjCJA5r.d.ts → types-BdaK9PcP.d.ts} +1 -1
  40. package/package.json +14 -10
  41. package/dist/chunk-MG7OXCAI.js.map +0 -1
  42. package/dist/chunk-UCPV7JXC.js.map +0 -1
@@ -0,0 +1,162 @@
1
+ import { isPathLike, translatePath, boundsOfPath } from './chunk-3LPQ2XZG.js';
2
+
3
+ // src/core/units.ts
4
+ function resolveUnit(v, unitSystem) {
5
+ if (typeof v === "number") return v;
6
+ if (!unitSystem) {
7
+ throw new Error(
8
+ `resolveUnit: tagged value { value: ${v.value}, unit: '${v.unit}' } requires a UnitSystem`
9
+ );
10
+ }
11
+ const factor = unitSystem.units[v.unit];
12
+ if (factor === void 0) {
13
+ const known = Object.keys(unitSystem.units).join(", ") || "(none)";
14
+ throw new Error(
15
+ `resolveUnit: unknown unit '${v.unit}' (system base: '${unitSystem.base}', known units: ${known})`
16
+ );
17
+ }
18
+ return v.value * factor;
19
+ }
20
+ function formatUnit(baseValue, displayUnit, unitSystem, opts) {
21
+ const factor = unitSystem.units[displayUnit];
22
+ if (factor === void 0) {
23
+ const known = Object.keys(unitSystem.units).join(", ") || "(none)";
24
+ throw new Error(
25
+ `formatUnit: unknown unit '${displayUnit}' (system base: '${unitSystem.base}', known units: ${known})`
26
+ );
27
+ }
28
+ const precision = opts?.precision ?? 2;
29
+ const suffix = opts?.suffix ?? true;
30
+ const display = baseValue / factor;
31
+ let s = display.toFixed(precision);
32
+ if (s.includes(".")) {
33
+ s = s.replace(/0+$/, "").replace(/\.$/, "");
34
+ }
35
+ return suffix ? `${s}${displayUnit}` : s;
36
+ }
37
+ var IMPERIAL_INCHES = {
38
+ base: "in",
39
+ units: { in: 1, ft: 12, yd: 36, mi: 63360 }
40
+ };
41
+ var METRIC_MM = {
42
+ base: "mm",
43
+ units: { mm: 1, cm: 10, m: 1e3, km: 1e6 }
44
+ };
45
+ var ANGLE_RADIANS = {
46
+ base: "rad",
47
+ units: { rad: 1, deg: Math.PI / 180, turn: Math.PI * 2 }
48
+ };
49
+ var PIXELS = {
50
+ base: "px",
51
+ units: { px: 1 }
52
+ };
53
+
54
+ // src/interactions/gestures/shared/strategies/grid.ts
55
+ var RECT_ORIGIN_PROJECTION = {
56
+ getOrigin: (p) => ({ x: p.x, y: p.y }),
57
+ translate: (p, dx, dy) => ({ ...p, x: p.x + dx, y: p.y + dy })
58
+ };
59
+ var AUTO_ORIGIN_PROJECTION = {
60
+ getOrigin: (p) => {
61
+ if (isPathLike(p)) {
62
+ const b = boundsOfPath(p);
63
+ return { x: b.x, y: b.y };
64
+ }
65
+ const r = p;
66
+ return { x: r.x, y: r.y };
67
+ },
68
+ translate: (p, dx, dy) => {
69
+ if (isPathLike(p)) return translatePath(p, dx, dy);
70
+ const r = p;
71
+ return { ...r, x: r.x + dx, y: r.y + dy };
72
+ }
73
+ };
74
+ function gridSnapStrategy(spacing, arg) {
75
+ const isOpts = typeof arg === "object" && arg !== null && ("origin" in arg || "debug" in arg || "unitSystem" in arg) && !("base" in arg);
76
+ const optsArg = isOpts ? arg : null;
77
+ const unitSystem = optsArg ? optsArg.unitSystem : arg;
78
+ const proj = optsArg && optsArg.origin ? optsArg.origin : AUTO_ORIGIN_PROJECTION;
79
+ const debug = optsArg ? optsArg.debug : void 0;
80
+ const c = resolveUnit(spacing, unitSystem);
81
+ return {
82
+ snap(pose) {
83
+ const o = proj.getOrigin(pose);
84
+ const sx = Math.round(o.x / c) * c;
85
+ const sy = Math.round(o.y / c) * c;
86
+ debug?.recordSnapCandidate({ x: sx, y: sy }, true);
87
+ return proj.translate(pose, sx - o.x, sy - o.y);
88
+ }
89
+ };
90
+ }
91
+ function pointToGridCell(point, spacing, unitSystem, origin = { x: 0, y: 0 }) {
92
+ const s = resolveUnit(spacing, unitSystem);
93
+ return {
94
+ col: Math.floor((point.x - origin.x) / s),
95
+ row: Math.floor((point.y - origin.y) / s)
96
+ };
97
+ }
98
+
99
+ // src/core/viewport/pxExtent.ts
100
+ function pxExtent(px, scale) {
101
+ return {
102
+ x: px / Math.abs(scale.x),
103
+ y: px / Math.abs(scale.y)
104
+ };
105
+ }
106
+ function scaleDelta(dx, dy, scale) {
107
+ return { x: dx * scale.x, y: dy * scale.y };
108
+ }
109
+ function withinPxBox(dx, dy, px, scale) {
110
+ const s = scaleDelta(dx, dy, scale);
111
+ return Math.abs(s.x) <= px && Math.abs(s.y) <= px;
112
+ }
113
+ function withinPxRadius(dx, dy, px, scale) {
114
+ const s = scaleDelta(dx, dy, scale);
115
+ return s.x * s.x + s.y * s.y <= px * px;
116
+ }
117
+
118
+ // src/interactions/gestures/shared/strategies/guides.ts
119
+ var DEFAULT_GUIDE_TOLERANCE_PX = 6;
120
+ function guideSnapStrategy(getGuides, options = {}) {
121
+ const tolerance = options.tolerance ?? DEFAULT_GUIDE_TOLERANCE_PX;
122
+ const getView = options.getView;
123
+ const proj = options.origin ?? RECT_ORIGIN_PROJECTION;
124
+ return {
125
+ snap(pose) {
126
+ const guides = getGuides();
127
+ if (guides.length === 0) return null;
128
+ const tol = getView ? pxExtent(tolerance, getView().scale) : { x: tolerance, y: tolerance };
129
+ const o = proj.getOrigin(pose);
130
+ let bestDx = 0;
131
+ let bestAbsDx = Infinity;
132
+ let bestDy = 0;
133
+ let bestAbsDy = Infinity;
134
+ for (const g of guides) {
135
+ if (g.axis === "x") {
136
+ const d = g.offset - o.x;
137
+ const ad = Math.abs(d);
138
+ if (ad <= tol.x && ad < bestAbsDx) {
139
+ bestAbsDx = ad;
140
+ bestDx = d;
141
+ }
142
+ } else {
143
+ const d = g.offset - o.y;
144
+ const ad = Math.abs(d);
145
+ if (ad <= tol.y && ad < bestAbsDy) {
146
+ bestAbsDy = ad;
147
+ bestDy = d;
148
+ }
149
+ }
150
+ }
151
+ if (bestAbsDx === Infinity && bestAbsDy === Infinity) return null;
152
+ const dx = bestAbsDx === Infinity ? 0 : bestDx;
153
+ const dy = bestAbsDy === Infinity ? 0 : bestDy;
154
+ if (dx === 0 && dy === 0) return null;
155
+ return proj.translate(pose, dx, dy);
156
+ }
157
+ };
158
+ }
159
+
160
+ export { ANGLE_RADIANS, DEFAULT_GUIDE_TOLERANCE_PX, IMPERIAL_INCHES, METRIC_MM, PIXELS, RECT_ORIGIN_PROJECTION, formatUnit, gridSnapStrategy, guideSnapStrategy, pointToGridCell, pxExtent, resolveUnit, scaleDelta, withinPxBox, withinPxRadius };
161
+ //# sourceMappingURL=chunk-HAGOFNP5.js.map
162
+ //# sourceMappingURL=chunk-HAGOFNP5.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/core/units.ts","../src/interactions/gestures/shared/strategies/grid.ts","../src/core/viewport/pxExtent.ts","../src/interactions/gestures/shared/strategies/guides.ts"],"names":[],"mappings":";;;AA+BO,SAAS,WAAA,CAAY,GAAc,UAAA,EAAiC;AACzE,EAAA,IAAI,OAAO,CAAA,KAAM,QAAA,EAAU,OAAO,CAAA;AAClC,EAAA,IAAI,CAAC,UAAA,EAAY;AACf,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,CAAA,mCAAA,EAAsC,CAAA,CAAE,KAAK,CAAA,SAAA,EAAY,EAAE,IAAI,CAAA,yBAAA;AAAA,KACjE;AAAA,EACF;AACA,EAAA,MAAM,MAAA,GAAS,UAAA,CAAW,KAAA,CAAM,CAAA,CAAE,IAAI,CAAA;AACtC,EAAA,IAAI,WAAW,MAAA,EAAW;AACxB,IAAA,MAAM,KAAA,GAAQ,OAAO,IAAA,CAAK,UAAA,CAAW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kit stores all coordinates as bare numbers in a single base unit\n * chosen by the consumer app. To make API call sites self-documenting,\n * the public surface accepts `UnitValue` — either a bare number (interpreted\n * as base units) or a `{ value, unit }` tag that's resolved against a\n * `UnitSystem` at the API boundary. Internals never see units.\n *\n * Linear factors only. No per-axis units. No mixed-unit arithmetic.\n */\n\n/** A unit name (e.g. `'in'`, `'ft'`, `'mm'`). Looked up in a `UnitSystem`. */\nexport type Unit = string;\n\n/** Conversion table mapping unit names to factors against a base unit. */\nexport interface UnitSystem {\n /** Name of the base unit, e.g. 'in'. All conversions resolve to this. */\n base: Unit;\n /** Factor to multiply a value in `unit` by to get base units. base unit's factor is 1. */\n units: Record<Unit, number>;\n}\n\n/** Value at a unit-aware API boundary: bare number (in base units) or `{ value, unit }` tag. */\nexport type UnitValue = number | { value: number; unit: Unit };\n\n/**\n * Resolve a UnitValue to a number in base units.\n * - bare number: returned as-is (assumed base)\n * - tagged: looks up factor; throws if unit not in unit system\n */\nexport function resolveUnit(v: UnitValue, unitSystem?: UnitSystem): number {\n if (typeof v === 'number') return v;\n if (!unitSystem) {\n throw new Error(\n `resolveUnit: tagged value { value: ${v.value}, unit: '${v.unit}' } requires a UnitSystem`,\n );\n }\n const factor = unitSystem.units[v.unit];\n if (factor === undefined) {\n const known = Object.keys(unitSystem.units).join(', ') || '(none)';\n throw new Error(\n `resolveUnit: unknown unit '${v.unit}' (system base: '${unitSystem.base}', known units: ${known})`,\n );\n }\n return v.value * factor;\n}\n\n/**\n * Format a base-unit number as a string in the named display unit.\n * e.g. formatUnit(36, 'ft', IMPERIAL_INCHES) => '3ft'\n * Default precision: 2. Trailing zeros trimmed.\n */\nexport function formatUnit(\n baseValue: number,\n displayUnit: Unit,\n unitSystem: UnitSystem,\n opts?: { precision?: number; suffix?: boolean },\n): string {\n const factor = unitSystem.units[displayUnit];\n if (factor === undefined) {\n const known = Object.keys(unitSystem.units).join(', ') || '(none)';\n throw new Error(\n `formatUnit: unknown unit '${displayUnit}' (system base: '${unitSystem.base}', known units: ${known})`,\n );\n }\n const precision = opts?.precision ?? 2;\n const suffix = opts?.suffix ?? true;\n const display = baseValue / factor;\n // Trim trailing zeros (and a dangling decimal point) without losing precision.\n let s = display.toFixed(precision);\n if (s.includes('.')) {\n s = s.replace(/0+$/, '').replace(/\\.$/, '');\n }\n return suffix ? `${s}${displayUnit}` : s;\n}\n\n/** Imperial unit system with base 'in'. */\nexport const IMPERIAL_INCHES: UnitSystem = {\n base: 'in',\n units: { in: 1, ft: 12, yd: 36, mi: 63360 },\n};\n\n/** Metric unit system with base 'mm'. */\nexport const METRIC_MM: UnitSystem = {\n base: 'mm',\n units: { mm: 1, cm: 10, m: 1000, km: 1_000_000 },\n};\n\n/** Angle unit system with base 'rad'. */\nexport const ANGLE_RADIANS: UnitSystem = {\n base: 'rad',\n units: { rad: 1, deg: Math.PI / 180, turn: Math.PI * 2 },\n};\n\n/** Pixel unit system — sole unit is the base. */\nexport const PIXELS: UnitSystem = {\n base: 'px',\n units: { px: 1 },\n};\n","import type { SnapStrategy } from '../../types';\nimport { resolveUnit, type UnitSystem, type UnitValue } from 'core/units';\nimport type { DebugSink } from '../../../../debug/types';\nimport { isPathLike } from 'interactions/actions/resize/autoPoseDescriptor';\nimport { boundsOfPath } from 'features/paths/bounds';\nimport { translatePath } from 'features/paths/transform';\nimport type { Path } from 'features/paths/types';\n\n/**\n * Projection used by `gridSnapStrategy` when `TPose` doesn't expose `{x,y}`\n * directly (Path, polygon, etc.). The strategy reads the snap point via\n * `getOrigin`, rounds it to the grid, then asks `translate` to move the\n * pose by the resulting delta.\n */\nexport interface OriginProjection<TPose> {\n getOrigin(pose: TPose): { x: number; y: number };\n translate(pose: TPose, dx: number, dy: number): TPose;\n}\n\n/** Identity projection for `TPose extends { x; y }`. */\nexport const RECT_ORIGIN_PROJECTION: OriginProjection<{ x: number; y: number }> = {\n getOrigin: (p) => ({ x: p.x, y: p.y }),\n translate: (p, dx, dy) => ({ ...p, x: p.x + dx, y: p.y + dy }),\n};\n\n/** Per-call dispatch: routes Path-shaped poses to the path origin/translate\n * helpers and everything else to `RECT_ORIGIN_PROJECTION`. Default for\n * `gridSnapStrategy` so consumers with Path TPose don't have to thread\n * `pathOriginProjection` explicitly. */\nexport const AUTO_ORIGIN_PROJECTION: OriginProjection<unknown> = {\n getOrigin: (p) => {\n if (isPathLike(p)) {\n const b = boundsOfPath(p as Path);\n return { x: b.x, y: b.y };\n }\n const r = p as { x: number; y: number };\n return { x: r.x, y: r.y };\n },\n translate: (p, dx, dy) => {\n if (isPathLike(p)) return translatePath(p as Path, dx, dy);\n const r = p as { x: number; y: number };\n return { ...r, x: r.x + dx, y: r.y + dy };\n },\n};\n\n/** Snap-strategy that rounds the pose's origin to the nearest multiple of\n * `spacing` (resolved through `unitSystem`). For non-rect TPose pass an\n * `OriginProjection` so the strategy knows how to read/write the origin. */\nexport function gridSnapStrategy<TPose>(\n spacing: UnitValue,\n unitSystem?: UnitSystem,\n): SnapStrategy<TPose>;\n/** As above, additionally reporting each candidate to a debug sink. */\nexport function gridSnapStrategy<TPose>(\n spacing: UnitValue,\n opts: { unitSystem?: UnitSystem; debug?: DebugSink },\n): SnapStrategy<TPose>;\n/** As above, for a `TPose` that is not a rect: `origin` tells the strategy how\n * to read and write the pose's origin. */\nexport function gridSnapStrategy<TPose>(\n spacing: UnitValue,\n opts: { unitSystem?: UnitSystem; origin: OriginProjection<TPose>; debug?: DebugSink },\n): SnapStrategy<TPose>;\n/** Snap-strategy that rounds the pose's origin to the nearest multiple of\n * `spacing` (resolved through `unitSystem`). For non-rect TPose pass an\n * `OriginProjection` so the strategy knows how to read/write the origin. */\nexport function gridSnapStrategy<TPose>(\n spacing: UnitValue,\n arg?: UnitSystem | { unitSystem?: UnitSystem; origin?: OriginProjection<TPose>; debug?: DebugSink },\n): SnapStrategy<TPose> {\n const isOpts =\n typeof arg === 'object' &&\n arg !== null &&\n ('origin' in arg || 'debug' in arg || 'unitSystem' in arg) &&\n !('base' in arg);\n const optsArg = isOpts\n ? (arg as { unitSystem?: UnitSystem; origin?: OriginProjection<TPose>; debug?: DebugSink })\n : null;\n const unitSystem = optsArg ? optsArg.unitSystem : (arg as UnitSystem | undefined);\n const proj: OriginProjection<TPose> = optsArg && optsArg.origin\n ? optsArg.origin\n : (AUTO_ORIGIN_PROJECTION as unknown as OriginProjection<TPose>);\n const debug: DebugSink | undefined = optsArg ? optsArg.debug : undefined;\n const c = resolveUnit(spacing, unitSystem);\n return {\n snap(pose) {\n const o = proj.getOrigin(pose);\n const sx = Math.round(o.x / c) * c;\n const sy = Math.round(o.y / c) * c;\n debug?.recordSnapCandidate({ x: sx, y: sy }, true);\n return proj.translate(pose, sx - o.x, sy - o.y);\n },\n };\n}\n\n/**\n * Compute the integer cell `{col, row}` that contains `point`, given a grid\n * `spacing` and optional `origin` and `unitSystem`. Pair with\n * `createCellHighlightLayer` (its `getCell` callback) to draw a snap-target\n * preview that uses the same spacing as `gridSnapStrategy` — so the visual\n * and behavioral grids stay in lockstep:\n *\n * const SPACING = 20;\n * const snap = gridSnapStrategy(SPACING);\n * // visual grid:\n * createGridLayer({ spacing: SPACING, bounds: () => ... });\n * // hover-preview overlay:\n * createCellHighlightLayer({\n * spacing: SPACING,\n * getCell: () => hoverPoint && pointToGridCell(hoverPoint, SPACING),\n * });\n */\nexport function pointToGridCell(\n point: { x: number; y: number },\n spacing: UnitValue,\n unitSystem?: UnitSystem,\n origin: { x: number; y: number } = { x: 0, y: 0 },\n): { col: number; row: number } {\n const s = resolveUnit(spacing, unitSystem);\n return {\n col: Math.floor((point.x - origin.x) / s),\n row: Math.floor((point.y - origin.y) / s),\n };\n}\n","/**\n * Screen-pixel lengths in world units, per axis.\n *\n * Chrome declares its hit zones in screen pixels — an 8px handle stays 8px at\n * every zoom, because it paints in screen space. Converting one such length to\n * world units with a single scalar (see `meanScale`) is exact only under\n * uniform zoom; per-axis it is too generous on one axis and too mean on the\n * other, so the pickable region stops matching the painted one.\n *\n * Prefer {@link withinPxBox} / {@link withinPxRadius}, which compare in screen\n * space and so can't drift from the paint at all. {@link pxExtent} is for the\n * cases that must stay in world units — a tolerance handed to geometry that\n * doesn't know about the view.\n */\n\nexport interface Scale2 {\n x: number;\n y: number;\n}\n\n/** One screen-pixel length as world-space extents, per axis. `scale` is a\n * view's, so neither axis is zero (see `View`). */\nexport function pxExtent(px: number, scale: Scale2): { x: number; y: number } {\n return {\n x: px / Math.abs(scale.x),\n y: px / Math.abs(scale.y),\n };\n}\n\n/** World delta → screen delta. Only the scale participates: translation\n * cancels in a difference, and the kit's views carry no skew. */\nexport function scaleDelta(dx: number, dy: number, scale: Scale2): { x: number; y: number } {\n return { x: dx * scale.x, y: dy * scale.y };\n}\n\n/**\n * Is a world-space delta inside a screen-space square of half-extent `px`?\n *\n * The square is axis-aligned **on screen**, which is what a handle painted in\n * screen space actually is — so this stays true under non-uniform zoom and\n * under a rotated target, where an axis-aligned world-space test is a rotated\n * rectangle on screen.\n */\nexport function withinPxBox(dx: number, dy: number, px: number, scale: Scale2): boolean {\n const s = scaleDelta(dx, dy, scale);\n return Math.abs(s.x) <= px && Math.abs(s.y) <= px;\n}\n\n/** Is a world-space delta inside a screen-space circle of radius `px`? */\nexport function withinPxRadius(dx: number, dy: number, px: number, scale: Scale2): boolean {\n const s = scaleDelta(dx, dy, scale);\n return s.x * s.x + s.y * s.y <= px * px;\n}\n","import type { SnapStrategy } from '../../types';\nimport type { Guide } from 'features/guides/types';\nimport type { View } from 'core/viewport/view';\nimport { pxExtent } from 'core/viewport/pxExtent';\nimport type { OriginProjection } from './grid';\nimport { RECT_ORIGIN_PROJECTION } from './grid';\n\n/** Default snap tolerance (screen pixels). */\nexport const DEFAULT_GUIDE_TOLERANCE_PX = 6;\n\n/** Options for `guideSnapStrategy`. */\nexport interface GuideSnapOptions<TPose> {\n /**\n * Tolerance, in screen pixels (CSS px) when `getView` is provided, or in\n * world units otherwise. Defaults to `DEFAULT_GUIDE_TOLERANCE_PX`.\n */\n tolerance?: number;\n /**\n * Read the active view transform. When supplied, `tolerance` is interpreted\n * in screen pixels and divided by `view.scale` so the trigger zone stays\n * the same on screen as the user zooms in/out. Without it, `tolerance`\n * is treated as world units.\n */\n getView?: () => View;\n /**\n * Projection used when `TPose` doesn't expose `{x, y}` directly (Path,\n * polygon, etc.) — same contract as `gridSnapStrategy`. Defaults to the\n * rect-pose identity projection.\n */\n origin?: OriginProjection<TPose>;\n}\n\n/**\n * Snap-strategy that snaps the pose's origin to the nearest guide line on\n * each axis when within tolerance. Each axis is considered independently:\n * a vertical guide (`axis: 'x'`) constrains X, a horizontal guide\n * (`axis: 'y'`) constrains Y. When multiple guides are within range on the\n * same axis, the closest wins.\n *\n * Pair with `useGuides` for storage and `createGuidesLayer` for rendering.\n *\n * **Composition:** combining with `gridSnapStrategy` is left to the\n * consumer in v1 — typically by picking one based on a modifier key, or\n * by stacking two move/resize/insert behaviors in priority order.\n */\nexport function guideSnapStrategy<TPose extends { x: number; y: number }>(\n getGuides: () => readonly Guide[],\n options?: Omit<GuideSnapOptions<TPose>, 'origin'>,\n): SnapStrategy<TPose>;\n/** As above, for a `TPose` that is not a rect: `origin` tells the strategy how\n * to read and write the pose's origin. */\nexport function guideSnapStrategy<TPose>(\n getGuides: () => readonly Guide[],\n options: GuideSnapOptions<TPose> & { origin: OriginProjection<TPose> },\n): SnapStrategy<TPose>;\n/** Snap a pose's origin to the nearest guide line within tolerance, per axis. */\nexport function guideSnapStrategy<TPose>(\n getGuides: () => readonly Guide[],\n options: GuideSnapOptions<TPose> = {},\n): SnapStrategy<TPose> {\n const tolerance = options.tolerance ?? DEFAULT_GUIDE_TOLERANCE_PX;\n const getView = options.getView;\n const proj: OriginProjection<TPose> =\n options.origin ?? (RECT_ORIGIN_PROJECTION as unknown as OriginProjection<TPose>);\n\n return {\n snap(pose) {\n const guides = getGuides();\n if (guides.length === 0) return null;\n\n // Convert tolerance to world units, per axis: a guide on the x axis is\n // matched by a horizontal distance, so it answers to `scale.x` alone.\n // With no view, treat tolerance as already-world.\n const tol = getView ? pxExtent(tolerance, getView().scale) : { x: tolerance, y: tolerance };\n\n const o = proj.getOrigin(pose);\n\n let bestDx = 0;\n let bestAbsDx = Infinity;\n let bestDy = 0;\n let bestAbsDy = Infinity;\n\n for (const g of guides) {\n if (g.axis === 'x') {\n const d = g.offset - o.x;\n const ad = Math.abs(d);\n if (ad <= tol.x && ad < bestAbsDx) {\n bestAbsDx = ad;\n bestDx = d;\n }\n } else {\n const d = g.offset - o.y;\n const ad = Math.abs(d);\n if (ad <= tol.y && ad < bestAbsDy) {\n bestAbsDy = ad;\n bestDy = d;\n }\n }\n }\n\n if (bestAbsDx === Infinity && bestAbsDy === Infinity) return null;\n const dx = bestAbsDx === Infinity ? 0 : bestDx;\n const dy = bestAbsDy === Infinity ? 0 : bestDy;\n if (dx === 0 && dy === 0) return null;\n return proj.translate(pose, dx, dy);\n },\n };\n}\n"]}
@@ -0,0 +1,318 @@
1
+ import { rectToContour, DEFAULT_FLATTEN_TOLERANCE, forEachSegment, PATH_Z, PATH_C, flattenCubicWithArcLen, PATH_Q, flattenQuadraticWithArcLen, PATH_L, PATH_M } from '@weasel-js/geom';
2
+
3
+ // src/features/simulation/types.ts
4
+ var DEFAULT_ALPHA_DECAY = 1 - Math.pow(1e-3, 1 / 300);
5
+ var DEFAULT_ALPHA_MIN = 1e-3;
6
+ var DEFAULT_VELOCITY_DECAY = 0.4;
7
+
8
+ // src/features/simulation/createSimulation.ts
9
+ function createSimulation(opts) {
10
+ let nodes = opts.nodes;
11
+ let forces = opts.forces ?? [];
12
+ let alpha = opts.alpha ?? 1;
13
+ let alphaMin = opts.alphaMin ?? DEFAULT_ALPHA_MIN;
14
+ let alphaDecay = opts.alphaDecay ?? DEFAULT_ALPHA_DECAY;
15
+ let alphaTarget = opts.alphaTarget ?? 0;
16
+ let velocityDecay = opts.velocityDecay ?? DEFAULT_VELOCITY_DECAY;
17
+ const random = opts.random ?? Math.random;
18
+ function prime(list) {
19
+ list.forEach((n, i) => {
20
+ n.index = i;
21
+ if (n.vx == null) n.vx = 0;
22
+ if (n.vy == null) n.vy = 0;
23
+ });
24
+ }
25
+ prime(nodes);
26
+ for (const f of forces) f.initialize?.(nodes, random);
27
+ function step() {
28
+ alpha += (alphaTarget - alpha) * alphaDecay;
29
+ for (const f of forces) f(alpha);
30
+ const friction = 1 - velocityDecay;
31
+ for (const n of nodes) {
32
+ if (n.fx == null) {
33
+ n.vx = (n.vx ?? 0) * friction;
34
+ if (!Number.isFinite(n.vx)) n.vx = 0;
35
+ n.x += n.vx;
36
+ if (!Number.isFinite(n.x)) n.x = 0;
37
+ } else {
38
+ n.x = n.fx;
39
+ n.vx = 0;
40
+ }
41
+ if (n.fy == null) {
42
+ n.vy = (n.vy ?? 0) * friction;
43
+ if (!Number.isFinite(n.vy)) n.vy = 0;
44
+ n.y += n.vy;
45
+ if (!Number.isFinite(n.y)) n.y = 0;
46
+ } else {
47
+ n.y = n.fy;
48
+ n.vy = 0;
49
+ }
50
+ }
51
+ }
52
+ const core = {
53
+ get nodes() {
54
+ return nodes;
55
+ },
56
+ setNodes(next) {
57
+ nodes = next;
58
+ prime(nodes);
59
+ for (const f of forces) f.initialize?.(nodes, random);
60
+ return core;
61
+ },
62
+ setForces(next) {
63
+ const old = forces;
64
+ forces = next;
65
+ for (const f of next) {
66
+ if (!old.includes(f)) f.initialize?.(nodes, random);
67
+ }
68
+ return core;
69
+ },
70
+ alpha(value) {
71
+ if (value === void 0) return alpha;
72
+ alpha = value;
73
+ return core;
74
+ },
75
+ alphaTarget(value) {
76
+ if (value === void 0) return alphaTarget;
77
+ alphaTarget = value;
78
+ return core;
79
+ },
80
+ alphaDecay(value) {
81
+ if (value === void 0) return alphaDecay;
82
+ alphaDecay = value;
83
+ return core;
84
+ },
85
+ alphaMin(value) {
86
+ if (value === void 0) return alphaMin;
87
+ alphaMin = value;
88
+ return core;
89
+ },
90
+ velocityDecay(value) {
91
+ if (value === void 0) return velocityDecay;
92
+ velocityDecay = value;
93
+ return core;
94
+ },
95
+ tick(iterations = 1) {
96
+ for (let i = 0; i < iterations; i++) step();
97
+ return core;
98
+ },
99
+ isSettled() {
100
+ return alpha < alphaMin && alphaTarget === 0;
101
+ }
102
+ };
103
+ return core;
104
+ }
105
+
106
+ // src/interactions/actions/rotate/geometry.ts
107
+ function aabbCenter(bounds) {
108
+ return { x: bounds.x + bounds.width / 2, y: bounds.y + bounds.height / 2 };
109
+ }
110
+ function rotatePoint(px, py, cx, cy, angle) {
111
+ const c = Math.cos(angle);
112
+ const s = Math.sin(angle);
113
+ const dx = px - cx;
114
+ const dy = py - cy;
115
+ return { x: cx + dx * c - dy * s, y: cy + dx * s + dy * c };
116
+ }
117
+ function rectCorners(bounds) {
118
+ return [
119
+ { x: bounds.x, y: bounds.y },
120
+ { x: bounds.x + bounds.width, y: bounds.y },
121
+ { x: bounds.x + bounds.width, y: bounds.y + bounds.height },
122
+ { x: bounds.x, y: bounds.y + bounds.height }
123
+ ];
124
+ }
125
+ function rotatedRectCorners(pose) {
126
+ const c = aabbCenter(pose);
127
+ return rectCorners(pose).map((p) => rotatePoint(p.x, p.y, c.x, c.y, pose.rotation));
128
+ }
129
+ function pointInRotatedRect(pose, worldX, worldY) {
130
+ const c = aabbCenter(pose);
131
+ const local = rotatePoint(worldX, worldY, c.x, c.y, -pose.rotation);
132
+ return local.x >= pose.x && local.x <= pose.x + pose.width && local.y >= pose.y && local.y <= pose.y + pose.height;
133
+ }
134
+ function extractPolylines(path, opts = {}) {
135
+ if (path.kind === "rect") return [extractRect(path)];
136
+ return extractPolygon(path, opts);
137
+ }
138
+ function extractRect(p) {
139
+ const { x, y, width: w, height: h } = p;
140
+ return {
141
+ points: Array.from(rectToContour(x, y, w, h)),
142
+ closed: true,
143
+ anchorA: new Uint32Array([0, 1, 2, 3]),
144
+ anchorB: new Uint32Array([0, 1, 2, 3]),
145
+ anchorT: new Float32Array([0, 0, 0, 0])
146
+ };
147
+ }
148
+ function extractPolygon(p, opts) {
149
+ const tolerance = opts.flattenTolerance ?? DEFAULT_FLATTEN_TOLERANCE;
150
+ const { commands, coords } = p;
151
+ const out = [];
152
+ let anchorCounter = 0;
153
+ let pts = null;
154
+ let aA = null;
155
+ let aB = null;
156
+ let aT = null;
157
+ let current = null;
158
+ let prevAnchor = -1;
159
+ const beginContour = () => {
160
+ pts = [];
161
+ aA = [];
162
+ aB = [];
163
+ aT = [];
164
+ const next = { points: pts, closed: false };
165
+ out.push(next);
166
+ return next;
167
+ };
168
+ const dropDuplicateClosingPoint = () => {
169
+ if (!pts || !aA || !aB || !aT) return;
170
+ const n = pts.length / 2;
171
+ if (n < 2) return;
172
+ if (pts[0] !== pts[(n - 1) * 2] || pts[1] !== pts[(n - 1) * 2 + 1]) return;
173
+ pts.length -= 2;
174
+ aA.length -= 1;
175
+ aB.length -= 1;
176
+ aT.length -= 1;
177
+ };
178
+ const commit = (target) => {
179
+ if (!pts || !aA || !aB || !aT) return;
180
+ target.anchorA = new Uint32Array(aA);
181
+ target.anchorB = new Uint32Array(aB);
182
+ target.anchorT = new Float32Array(aT);
183
+ };
184
+ const pushCurveAnchors = (segStart, arcAccum, total, target) => {
185
+ for (let k = 0; k < arcAccum.length; k++) {
186
+ aA.push(prevAnchor);
187
+ aB.push(target);
188
+ aT.push(total > 0 ? arcAccum[k] / total : 0);
189
+ }
190
+ const lastIdx = segStart + arcAccum.length - 1;
191
+ aA[lastIdx] = target;
192
+ aB[lastIdx] = target;
193
+ aT[lastIdx] = 0;
194
+ };
195
+ forEachSegment(commands, coords, (cmd, coordIdx, prevX, prevY) => {
196
+ switch (cmd) {
197
+ case PATH_M:
198
+ case PATH_L: {
199
+ if (cmd === PATH_M) {
200
+ if (current) commit(current);
201
+ current = beginContour();
202
+ }
203
+ pts.push(coords[coordIdx], coords[coordIdx + 1]);
204
+ aA.push(anchorCounter);
205
+ aB.push(anchorCounter);
206
+ aT.push(0);
207
+ prevAnchor = anchorCounter;
208
+ anchorCounter++;
209
+ break;
210
+ }
211
+ case PATH_Q: {
212
+ const target = anchorCounter;
213
+ const segStart = pts.length / 2;
214
+ const arcAccum = [];
215
+ const total = flattenQuadraticWithArcLen(
216
+ prevX,
217
+ prevY,
218
+ coords[coordIdx],
219
+ coords[coordIdx + 1],
220
+ coords[coordIdx + 2],
221
+ coords[coordIdx + 3],
222
+ tolerance,
223
+ pts,
224
+ arcAccum
225
+ );
226
+ pushCurveAnchors(segStart, arcAccum, total, target);
227
+ prevAnchor = target;
228
+ anchorCounter++;
229
+ break;
230
+ }
231
+ case PATH_C: {
232
+ const target = anchorCounter;
233
+ const segStart = pts.length / 2;
234
+ const arcAccum = [];
235
+ const total = flattenCubicWithArcLen(
236
+ prevX,
237
+ prevY,
238
+ coords[coordIdx],
239
+ coords[coordIdx + 1],
240
+ coords[coordIdx + 2],
241
+ coords[coordIdx + 3],
242
+ coords[coordIdx + 4],
243
+ coords[coordIdx + 5],
244
+ tolerance,
245
+ pts,
246
+ arcAccum
247
+ );
248
+ pushCurveAnchors(segStart, arcAccum, total, target);
249
+ prevAnchor = target;
250
+ anchorCounter++;
251
+ break;
252
+ }
253
+ case PATH_Z: {
254
+ if (current) {
255
+ current.closed = true;
256
+ dropDuplicateClosingPoint();
257
+ }
258
+ break;
259
+ }
260
+ default:
261
+ throw new Error(`extractPolylines: unknown command code ${cmd}`);
262
+ }
263
+ });
264
+ if (current) commit(current);
265
+ return out;
266
+ }
267
+
268
+ // src/features/paths/pathAt.ts
269
+ function pointAlongPath(path, t, opts = {}) {
270
+ const polylines = extractPolylines(
271
+ path,
272
+ opts.flattenTolerance === void 0 ? {} : { flattenTolerance: opts.flattenTolerance }
273
+ );
274
+ const segments = [];
275
+ let total = 0;
276
+ let first;
277
+ for (const pl of polylines) {
278
+ const count = pl.points.length / 2;
279
+ if (count === 0) continue;
280
+ first ??= { x: pl.points[0], y: pl.points[1] };
281
+ const last2 = pl.closed ? count : count - 1;
282
+ for (let i = 0; i < last2; i++) {
283
+ const j = (i + 1) % count;
284
+ const ax = pl.points[i * 2];
285
+ const ay = pl.points[i * 2 + 1];
286
+ const bx = pl.points[j * 2];
287
+ const by = pl.points[j * 2 + 1];
288
+ const len = Math.hypot(bx - ax, by - ay);
289
+ if (len === 0) continue;
290
+ segments.push({ ax, ay, bx, by, len });
291
+ total += len;
292
+ }
293
+ }
294
+ if (first === void 0) return null;
295
+ if (segments.length === 0) return { point: first, tangent: { x: 1, y: 0 } };
296
+ const target = Math.min(Math.max(t, 0), 1) * total;
297
+ let walked = 0;
298
+ for (const seg of segments) {
299
+ if (walked + seg.len < target) {
300
+ walked += seg.len;
301
+ continue;
302
+ }
303
+ const u = (target - walked) / seg.len;
304
+ return {
305
+ point: { x: seg.ax + (seg.bx - seg.ax) * u, y: seg.ay + (seg.by - seg.ay) * u },
306
+ tangent: { x: (seg.bx - seg.ax) / seg.len, y: (seg.by - seg.ay) / seg.len }
307
+ };
308
+ }
309
+ const last = segments[segments.length - 1];
310
+ return {
311
+ point: { x: last.bx, y: last.by },
312
+ tangent: { x: (last.bx - last.ax) / last.len, y: (last.by - last.ay) / last.len }
313
+ };
314
+ }
315
+
316
+ export { DEFAULT_ALPHA_DECAY, DEFAULT_ALPHA_MIN, DEFAULT_VELOCITY_DECAY, aabbCenter, createSimulation, extractPolylines, pointAlongPath, pointInRotatedRect, rectCorners, rotatePoint, rotatedRectCorners };
317
+ //# sourceMappingURL=chunk-LXJDWBEL.js.map
318
+ //# sourceMappingURL=chunk-LXJDWBEL.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/features/simulation/types.ts","../src/features/simulation/createSimulation.ts","../src/interactions/actions/rotate/geometry.ts","../src/features/paths/tessellate/polyline.ts","../src/features/paths/pathAt.ts"],"names":["last"],"mappings":";;;AAmHO,IAAM,sBAAsB,CAAA,GAAI,IAAA,CAAK,GAAA,CAAI,IAAA,EAAO,IAAI,GAAG;AAEvD,IAAM,iBAAA,GAAoB;AAG1B,IAAM,sBAAA,GAAyB;;;ACjG/B,SAAS,iBACd,IAAA,EACuB;A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M,IAAA,GAAO,QAAA,CAAS,QAAA,CAAS,MAAA,GAAS,CAAC,CAAA;AACzC,EAAA,OAAO;AAAA,IACL,OAAO,EAAE,CAAA,EAAG,KAAK,EAAA,EAAI,CAAA,EAAG,KAAK,EAAA,EAAG;AAAA,IAChC,OAAA,EAAS,EAAE,CAAA,EAAA,CAAI,IAAA,CAAK,KAAK,IAAA,CAAK,EAAA,IAAM,IAAA,CAAK,GAAA,EAAK,IAAI,IAAA,CAAK,EAAA,GAAK,IAAA,CAAK,EAAA,IAAM,KAAK,GAAA;AAAI,GAClF;AACF","file":"chunk-LXJDWBEL.js","sourcesContent":["/**\n * Minimal node interface for the simulation primitive. Matches d3-force's\n * node shape exactly so d3-force's bundled forces work without translation.\n *\n * Consumers extend this with arbitrary additional fields (id, label, etc.).\n */\nexport interface SimulationNode {\n x: number;\n y: number;\n vx?: number;\n vy?: number;\n /** Pin x to this value when non-null. The integrator skips x/vx for the node. */\n fx?: number | null;\n fy?: number | null;\n /** Array index, written by `initialize`. Some forces (e.g. forceLink) rely on it. */\n index?: number;\n}\n\n/**\n * Force protocol — contract-compatible with d3-force. A force is a function\n * called once per tick with the current alpha; it mutates `vx`/`vy` on nodes.\n * Optional `initialize` lets the force compute setup (link indices, etc.).\n */\nexport interface SimulationForce<TNode extends SimulationNode = SimulationNode> {\n (alpha: number): void;\n initialize?(nodes: TNode[], random?: () => number): void;\n}\n\n/** Options for `useSimulation`: everything {@link SimulationOptions} carries,\n * plus the loop's own callbacks and clock. */\nexport interface UseSimulationOptions<TNode extends SimulationNode>\n extends SimulationOptions<TNode> {\n /** Fired after each integration step. */\n onTick?: (nodes: TNode[]) => void;\n /** Fired once when the sim settles (alpha < alphaMin && alphaTarget === 0). */\n onEnd?: () => void;\n\n // Test injection (mirrors useAnimator):\n /** Optional rAF injection. Defaults to window.requestAnimationFrame. */\n requestFrame?: (cb: (t: number) => void) => number;\n cancelFrame?: (handle: number) => void;\n}\n\n/**\n * A force simulation over a set of nodes, with no clock of its own.\n *\n * Each tick applies every force and then integrates velocities, scaled by\n * `alpha` — a temperature that decays toward `alphaTarget` so the layout\n * settles instead of jittering forever. Raise `alphaTarget` to reheat it,\n * which is what a drag does.\n *\n * Nodes are mutated in place; the simulation holds the array, not a copy.\n *\n * Nothing here advances time. {@link Simulation} adds the frame loop; a caller\n * that wants the whole relaxation at once — a layout pass, a pre-warm, a test\n * — drives {@link SimulationCore.tick} itself.\n */\nexport interface SimulationCore<TNode extends SimulationNode> {\n readonly nodes: TNode[];\n\n setNodes(nodes: TNode[]): this;\n setForces(forces: SimulationForce<TNode>[]): this;\n\n alpha(): number;\n alpha(value: number): this;\n alphaTarget(): number;\n alphaTarget(value: number): this;\n alphaDecay(): number;\n alphaDecay(value: number): this;\n alphaMin(): number;\n alphaMin(value: number): this;\n velocityDecay(): number;\n velocityDecay(value: number): this;\n\n /**\n * Run the tick body synchronously `iterations` times. Does NOT fire\n * onTick or onEnd (matches d3-force). Used for offscreen pre-warm and tests.\n */\n tick(iterations?: number): this;\n\n isSettled(): boolean;\n}\n\n/** A {@link SimulationCore} running on a frame loop. */\nexport interface Simulation<TNode extends SimulationNode> extends SimulationCore<TNode> {\n /** Resume the RAF loop. If alpha < alphaMin, reset alpha to 1. */\n restart(): this;\n /** Cancel the RAF loop. Does not change alpha. */\n stop(): this;\n}\n\n/** What {@link SimulationCore} needs: the nodes, the forces acting on them,\n * and the cooling schedule. {@link UseSimulationOptions} adds the loop's. */\nexport interface SimulationOptions<TNode extends SimulationNode> {\n /** Mutable array of nodes. Kit + forces mutate vx/vy/x/y in place. */\n nodes: TNode[];\n /** Forces applied per tick. Each may implement `initialize` for setup. */\n forces?: SimulationForce<TNode>[];\n\n /** Initial alpha. Default 1. */\n alpha?: number;\n /** Settle threshold. When alpha drops below and alphaTarget is 0, onEnd fires. Default 0.001. */\n alphaMin?: number;\n /** Per-tick decay rate toward alphaTarget. Default 1 - 0.001^(1/300) ≈ 0.0228. */\n alphaDecay?: number;\n /** Target alpha. Set above alphaMin to keep sim warm (e.g. during drag). Default 0. */\n alphaTarget?: number;\n /** Friction multiplier on velocity per tick: vx *= (1 - velocityDecay). Default 0.4. */\n velocityDecay?: number;\n /** Handed to each force's `initialize`. Default `Math.random`; pass a seeded\n * source to make a run reproducible. */\n random?: () => number;\n}\n\n/** Default alpha decay: such that alpha drops from 1 to alphaMin (0.001) in 300 ticks. */\nexport const DEFAULT_ALPHA_DECAY = 1 - Math.pow(0.001, 1 / 300);\n/** Alpha below which a cooling simulation is considered settled. */\nexport const DEFAULT_ALPHA_MIN = 0.001;\n/** Fraction of velocity shed each tick — friction. Higher settles sooner and\n * overshoots less. */\nexport const DEFAULT_VELOCITY_DECAY = 0.4;\n","/**\n * The integrator, with no clock attached.\n *\n * Velocity-Verlet over a pluggable force list, contract-compatible with\n * d3-force so d3's own bundled forces drop in untranslated. Nothing here\n * advances time: `tick()` is the only thing that moves a node, and the caller\n * decides how often to call it. `useSimulation` calls it once a frame; a\n * layout pass calls it a few hundred times in one go and reads the result.\n *\n * Splitting it out is what lets a *pure* function run a relaxation — a React\n * hook cannot, and the alternative was a second integrator drifting away from\n * this one.\n */\nimport {\n DEFAULT_ALPHA_DECAY,\n DEFAULT_ALPHA_MIN,\n DEFAULT_VELOCITY_DECAY,\n type SimulationCore,\n type SimulationForce,\n type SimulationNode,\n type SimulationOptions,\n} from './types';\n\nexport function createSimulation<TNode extends SimulationNode>(\n opts: SimulationOptions<TNode>,\n): SimulationCore<TNode> {\n let nodes = opts.nodes;\n let forces = opts.forces ?? [];\n let alpha = opts.alpha ?? 1;\n let alphaMin = opts.alphaMin ?? DEFAULT_ALPHA_MIN;\n let alphaDecay = opts.alphaDecay ?? DEFAULT_ALPHA_DECAY;\n let alphaTarget = opts.alphaTarget ?? 0;\n let velocityDecay = opts.velocityDecay ?? DEFAULT_VELOCITY_DECAY;\n const random = opts.random ?? Math.random;\n\n /** `index` is what `forceLink` and friends address nodes by, and a d3 force\n * does `n.vx += …` without checking, so both must exist before the first\n * tick or the first tick produces NaN. */\n function prime(list: TNode[]): void {\n list.forEach((n, i) => {\n n.index = i;\n if (n.vx == null) n.vx = 0;\n if (n.vy == null) n.vy = 0;\n });\n }\n\n prime(nodes);\n for (const f of forces) f.initialize?.(nodes, random);\n\n function step(): void {\n alpha += (alphaTarget - alpha) * alphaDecay;\n for (const f of forces) f(alpha);\n\n const friction = 1 - velocityDecay;\n for (const n of nodes) {\n if (n.fx == null) {\n n.vx = (n.vx ?? 0) * friction;\n // A non-finite velocity — force overflow, or two nodes exactly\n // coincident — would reach the renderer as geometry and cost\n // pathological tessellation work without throwing anywhere.\n if (!Number.isFinite(n.vx)) n.vx = 0;\n n.x += n.vx;\n if (!Number.isFinite(n.x)) n.x = 0;\n } else {\n n.x = n.fx;\n n.vx = 0;\n }\n if (n.fy == null) {\n n.vy = (n.vy ?? 0) * friction;\n if (!Number.isFinite(n.vy)) n.vy = 0;\n n.y += n.vy;\n if (!Number.isFinite(n.y)) n.y = 0;\n } else {\n n.y = n.fy;\n n.vy = 0;\n }\n }\n }\n\n /* eslint-disable @typescript-eslint/no-explicit-any */\n const core: any = {\n get nodes() {\n return nodes;\n },\n setNodes(next: TNode[]) {\n nodes = next;\n prime(nodes);\n for (const f of forces) f.initialize?.(nodes, random);\n return core;\n },\n setForces(next: SimulationForce<TNode>[]) {\n const old = forces;\n forces = next;\n for (const f of next) {\n if (!old.includes(f)) f.initialize?.(nodes, random);\n }\n return core;\n },\n alpha(value?: number) {\n if (value === undefined) return alpha;\n alpha = value;\n return core;\n },\n alphaTarget(value?: number) {\n if (value === undefined) return alphaTarget;\n alphaTarget = value;\n return core;\n },\n alphaDecay(value?: number) {\n if (value === undefined) return alphaDecay;\n alphaDecay = value;\n return core;\n },\n alphaMin(value?: number) {\n if (value === undefined) return alphaMin;\n alphaMin = value;\n return core;\n },\n velocityDecay(value?: number) {\n if (value === undefined) return velocityDecay;\n velocityDecay = value;\n return core;\n },\n tick(iterations: number = 1) {\n for (let i = 0; i < iterations; i++) step();\n return core;\n },\n isSettled() {\n return alpha < alphaMin && alphaTarget === 0;\n },\n };\n /* eslint-enable @typescript-eslint/no-explicit-any */\n return core as SimulationCore<TNode>;\n}\n","import type { RotatedPose } from '../../gestures/types';\nimport type { Bounds } from 'core/viewport/fitViewToBounds';\n\n/** AABB center of an unrotated rect — the canonical rotation pivot. */\nexport function aabbCenter(bounds: Bounds): { x: number; y: number } {\n return { x: bounds.x + bounds.width / 2, y: bounds.y + bounds.height / 2 };\n}\n\n/** Rotate `(px, py)` by `angle` (radians) around `(cx, cy)`. */\nexport function rotatePoint(\n px: number,\n py: number,\n cx: number,\n cy: number,\n angle: number,\n): { x: number; y: number } {\n const c = Math.cos(angle);\n const s = Math.sin(angle);\n const dx = px - cx;\n const dy = py - cy;\n return { x: cx + dx * c - dy * s, y: cy + dx * s + dy * c };\n}\n\n/** Four corners of an unrotated rect, in TL/TR/BR/BL order. */\nexport function rectCorners(bounds: Bounds): { x: number; y: number }[] {\n return [\n { x: bounds.x, y: bounds.y },\n { x: bounds.x + bounds.width, y: bounds.y },\n { x: bounds.x + bounds.width, y: bounds.y + bounds.height },\n { x: bounds.x, y: bounds.y + bounds.height },\n ];\n}\n\n/** Four corners of a rotated rect (rotation around AABB center), in\n * TL/TR/BR/BL order. Useful for selection-overlay rendering. */\nexport function rotatedRectCorners(pose: RotatedPose): { x: number; y: number }[] {\n const c = aabbCenter(pose);\n return rectCorners(pose).map((p) => rotatePoint(p.x, p.y, c.x, c.y, pose.rotation));\n}\n\n/** Hit-test a world point against a rotated rect (rotation around AABB\n * center). Standard pattern: invert the rotation and AABB-test in the\n * rect's local frame. */\nexport function pointInRotatedRect(\n pose: RotatedPose,\n worldX: number,\n worldY: number,\n): boolean {\n const c = aabbCenter(pose);\n const local = rotatePoint(worldX, worldY, c.x, c.y, -pose.rotation);\n return (\n local.x >= pose.x &&\n local.x <= pose.x + pose.width &&\n local.y >= pose.y &&\n local.y <= pose.y + pose.height\n );\n}\n","import { forEachSegment, rectToContour } from '@weasel-js/geom';\nimport {\n PATH_M,\n PATH_L,\n PATH_Z,\n PATH_C,\n PATH_Q,\n DEFAULT_FLATTEN_TOLERANCE,\n flattenCubicWithArcLen,\n flattenQuadraticWithArcLen,\n} from '@weasel-js/geom';\nimport type { Path, PolygonPath, RectPath } from '../../../core/geometry/path';\n\nexport interface Polyline {\n /** Interleaved x,y vertices (length = 2 × point count). */\n points: number[];\n /** Whether the contour was closed (ends with Z, or is a RectPath). */\n closed: boolean;\n /** For each point, the previous anchor index. Anchor-aligned points set A === B. */\n anchorA?: Uint32Array;\n /** For each point, the next anchor index. */\n anchorB?: Uint32Array;\n /** For each point, the arc-length fraction along (A, B). 0 at anchor A; for anchor-aligned, set to 0. */\n anchorT?: Float32Array;\n /** Per-point stroke width, populated by the tessellator when the Stroke\n * carries `vertexWidths`. Undefined means uniform `Stroke.width`. */\n widths?: Float32Array;\n}\n\nexport interface ExtractOptions {\n flattenTolerance?: number;\n}\n\nexport function extractPolylines(path: Path, opts: ExtractOptions = {}): Polyline[] {\n if (path.kind === 'rect') return [extractRect(path)];\n return extractPolygon(path, opts);\n}\n\nfunction extractRect(p: RectPath): Polyline {\n const { x, y, width: w, height: h } = p;\n return {\n points: Array.from(rectToContour(x, y, w, h)),\n closed: true,\n anchorA: new Uint32Array([0, 1, 2, 3]),\n anchorB: new Uint32Array([0, 1, 2, 3]),\n anchorT: new Float32Array([0, 0, 0, 0]),\n };\n}\n\nfunction extractPolygon(p: PolygonPath, opts: ExtractOptions): Polyline[] {\n const tolerance = opts.flattenTolerance ?? DEFAULT_FLATTEN_TOLERANCE;\n const { commands, coords } = p;\n const out: Polyline[] = [];\n // Anchors are numbered globally (across all contours) in command-stream order.\n let anchorCounter = 0;\n\n // Builders for the current polyline.\n let pts: number[] | null = null;\n let aA: number[] | null = null;\n let aB: number[] | null = null;\n let aT: number[] | null = null;\n let current: Polyline | null = null;\n\n let prevAnchor = -1;\n\n const beginContour = (): Polyline => {\n pts = [];\n aA = [];\n aB = [];\n aT = [];\n const next: Polyline = { points: pts, closed: false };\n out.push(next);\n return next;\n };\n\n /**\n * A closed contour's last point repeating its first is redundant — Z already\n * says \"return to the start\" — and it is *harmful*: it leaves a zero-length\n * closing segment, which the stroker discards along with the wrap-around\n * join it should have carried, notching the ribbon at the contour's start.\n *\n * Every font outline serialized by opentype.js is written this way, as is a\n * great deal of hand-written and exported SVG, so this is the common case\n * rather than a defensive edge. Exact equality is the right test: the\n * duplicate is a re-emission of the same number, not an approach to it, and\n * a near-miss is a genuine (if tiny) segment the author asked for.\n */\n const dropDuplicateClosingPoint = (): void => {\n if (!pts || !aA || !aB || !aT) return;\n const n = pts.length / 2;\n if (n < 2) return;\n if (pts[0] !== pts[(n - 1) * 2] || pts[1] !== pts[(n - 1) * 2 + 1]) return;\n pts.length -= 2;\n aA.length -= 1;\n aB.length -= 1;\n aT.length -= 1;\n };\n\n const commit = (target: Polyline): void => {\n if (!pts || !aA || !aB || !aT) return;\n target.anchorA = new Uint32Array(aA);\n target.anchorB = new Uint32Array(aB);\n target.anchorT = new Float32Array(aT);\n };\n\n // Fill anchorA/B/T for each point a curve just appended: interior points\n // interpolate (prevAnchor → target), and the final point is pinned to the\n // target so the draw-time lerp returns anchor B's color exactly.\n const pushCurveAnchors = (segStart: number, arcAccum: number[], total: number, target: number): void => {\n for (let k = 0; k < arcAccum.length; k++) {\n aA!.push(prevAnchor);\n aB!.push(target);\n aT!.push(total > 0 ? arcAccum[k] / total : 0);\n }\n const lastIdx = (segStart + arcAccum.length) - 1;\n aA![lastIdx] = target;\n aB![lastIdx] = target;\n aT![lastIdx] = 0;\n };\n\n forEachSegment(commands, coords, (cmd, coordIdx, prevX, prevY) => {\n switch (cmd) {\n case PATH_M:\n case PATH_L: {\n if (cmd === PATH_M) {\n if (current) commit(current);\n current = beginContour();\n }\n pts!.push(coords[coordIdx], coords[coordIdx + 1]);\n aA!.push(anchorCounter);\n aB!.push(anchorCounter);\n aT!.push(0);\n prevAnchor = anchorCounter;\n anchorCounter++;\n break;\n }\n case PATH_Q: {\n const target = anchorCounter;\n const segStart = pts!.length / 2;\n const arcAccum: number[] = [];\n const total = flattenQuadraticWithArcLen(\n prevX, prevY,\n coords[coordIdx], coords[coordIdx + 1],\n coords[coordIdx + 2], coords[coordIdx + 3],\n tolerance, pts!, arcAccum,\n );\n pushCurveAnchors(segStart, arcAccum, total, target);\n prevAnchor = target;\n anchorCounter++;\n break;\n }\n case PATH_C: {\n const target = anchorCounter;\n const segStart = pts!.length / 2;\n const arcAccum: number[] = [];\n const total = flattenCubicWithArcLen(\n prevX, prevY,\n coords[coordIdx], coords[coordIdx + 1],\n coords[coordIdx + 2], coords[coordIdx + 3],\n coords[coordIdx + 4], coords[coordIdx + 5],\n tolerance, pts!, arcAccum,\n );\n pushCurveAnchors(segStart, arcAccum, total, target);\n prevAnchor = target;\n anchorCounter++;\n break;\n }\n case PATH_Z: {\n if (current) {\n current.closed = true;\n dropDuplicateClosingPoint();\n }\n break;\n }\n default:\n throw new Error(`extractPolylines: unknown command code ${cmd}`);\n }\n });\n\n if (current) commit(current);\n return out;\n}\n","/**\n * A station along a path: where it is at a fraction of its length, and which\n * way it is heading there.\n *\n * For anything positioned *along* geometry rather than beside it — a label on a\n * routed edge, a tick on a curve, a badge near an arrowhead. Curves are\n * flattened first, so the fraction is arc length along the drawn shape rather\n * than a curve parameter, which is what makes 0.5 look like the middle.\n */\nimport type { Vec2 } from 'core/geometry/polygonHitTestRect';\nimport type { Path } from 'core/geometry/path';\nimport { extractPolylines } from './tessellate/polyline';\n\nexport interface PathStation {\n point: Vec2;\n /** Unit vector along the path at `point`, pointing toward the end. */\n tangent: Vec2;\n}\n\nexport interface PointAlongPathOptions {\n /** Curve flattening tolerance, in world units. Default 0.5. */\n flattenTolerance?: number;\n}\n\n/**\n * Where `path` is at `t` of its total length, and its heading there.\n *\n * `t` is clamped to 0..1. Subpaths are measured in order and treated as one\n * run, the way a browser measures a whole `<path>`. Returns `null` for a path\n * with no points at all; a path of zero length answers at its single point,\n * heading along +X.\n */\nexport function pointAlongPath(\n path: Path,\n t: number,\n opts: PointAlongPathOptions = {},\n): PathStation | null {\n const polylines = extractPolylines(\n path,\n opts.flattenTolerance === undefined ? {} : { flattenTolerance: opts.flattenTolerance },\n );\n\n /** Every segment, in order, with the length it contributes. */\n const segments: { ax: number; ay: number; bx: number; by: number; len: number }[] = [];\n let total = 0;\n let first: Vec2 | undefined;\n for (const pl of polylines) {\n const count = pl.points.length / 2;\n if (count === 0) continue;\n first ??= { x: pl.points[0]!, y: pl.points[1]! };\n const last = pl.closed ? count : count - 1;\n for (let i = 0; i < last; i++) {\n const j = (i + 1) % count;\n const ax = pl.points[i * 2]!;\n const ay = pl.points[i * 2 + 1]!;\n const bx = pl.points[j * 2]!;\n const by = pl.points[j * 2 + 1]!;\n const len = Math.hypot(bx - ax, by - ay);\n if (len === 0) continue;\n segments.push({ ax, ay, bx, by, len });\n total += len;\n }\n }\n\n if (first === undefined) return null;\n if (segments.length === 0) return { point: first, tangent: { x: 1, y: 0 } };\n\n const target = Math.min(Math.max(t, 0), 1) * total;\n let walked = 0;\n for (const seg of segments) {\n if (walked + seg.len < target) {\n walked += seg.len;\n continue;\n }\n const u = (target - walked) / seg.len;\n return {\n point: { x: seg.ax + (seg.bx - seg.ax) * u, y: seg.ay + (seg.by - seg.ay) * u },\n tangent: { x: (seg.bx - seg.ax) / seg.len, y: (seg.by - seg.ay) / seg.len },\n };\n }\n\n // Float drift can leave `target` a hair past the last segment.\n const last = segments[segments.length - 1]!;\n return {\n point: { x: last.bx, y: last.by },\n tangent: { x: (last.bx - last.ax) / last.len, y: (last.by - last.ay) / last.len },\n };\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { RECT_ORIGIN_PROJECTION } from './chunk-UCPV7JXC.js';
1
+ import { RECT_ORIGIN_PROJECTION } from './chunk-HAGOFNP5.js';
2
2
  import { registerOpFactory, captureSlot, slotFromIndex, resolveSlot } from './chunk-4RJP2N2L.js';
3
3
 
4
4
  // src/core/ops/transform.ts
@@ -124,5 +124,5 @@ function snap(strategy, opts = {}) {
124
124
  }
125
125
 
126
126
  export { createReparentOp, createTransformOp, snap };
127
- //# sourceMappingURL=chunk-BDWAA634.js.map
128
- //# sourceMappingURL=chunk-BDWAA634.js.map
127
+ //# sourceMappingURL=chunk-P6MGECVO.js.map
128
+ //# sourceMappingURL=chunk-P6MGECVO.js.map