@weasel-js/core 1.6.0 → 1.6.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.
@@ -1,6 +1,33 @@
1
1
  import { M as MoveBehavior, S as SnapStrategy } from './types-D_74YlWs.js';
2
2
  import { DebugSink } from '@weasel-js/routing';
3
3
 
4
+ /** Option surface for the `move` action.
5
+ *
6
+ * Lives in a sibling file (not `move.ts`) so the type contract stays stable
7
+ * even after the legacy `useMove` hook is gone.
8
+ * Consumers should import from here directly; `move.ts` re-exports the
9
+ * same symbol for back-compat. */
10
+
11
+ /** Options for the `move` action: the behaviors (snapping, momentum) layered
12
+ * over the raw drag, and how a gesture expands a group into its leaves. */
13
+ interface UseMoveOptions<TPose> {
14
+ behaviors?: MoveBehavior<TPose>[];
15
+ dragThresholdPx?: number;
16
+ moveLabel?: string;
17
+ /** Reserved for transient gestures (no history entry). Move is never transient
18
+ * in practice; accepted for API consistency but ignored. */
19
+ transient?: boolean;
20
+ onGestureStart?(ids: string[]): void;
21
+ onGestureEnd?(committed: boolean): void;
22
+ /** Optional: expand the incoming id list before pose lookups. Used for
23
+ * group expansion (groups have no pose; their leaves do).
24
+ * Called once at `start()`. The returned list flows through ctx,
25
+ * overlay (`overlay.draggedIds` is the **expanded** leaves), and op
26
+ * generation. Returning `[]` aborts the gesture cleanly.
27
+ * Default: identity. */
28
+ expandIds?: (ids: string[]) => string[];
29
+ }
30
+
4
31
  /**
5
32
  * Units — a tiny customizable unit system for canvas-kit APIs.
6
33
  *
@@ -66,33 +93,6 @@ declare const ANGLE_RADIANS: UnitSystem;
66
93
  /** Pixel unit system — sole unit is the base. */
67
94
  declare const PIXELS: UnitSystem;
68
95
 
69
- /** Option surface for the `move` action.
70
- *
71
- * Lives in a sibling file (not `move.ts`) so the type contract stays stable
72
- * even after the legacy `useMove` hook is gone.
73
- * Consumers should import from here directly; `move.ts` re-exports the
74
- * same symbol for back-compat. */
75
-
76
- /** Options for the `move` action: the behaviors (snapping, momentum) layered
77
- * over the raw drag, and how a gesture expands a group into its leaves. */
78
- interface UseMoveOptions<TPose> {
79
- behaviors?: MoveBehavior<TPose>[];
80
- dragThresholdPx?: number;
81
- moveLabel?: string;
82
- /** Reserved for transient gestures (no history entry). Move is never transient
83
- * in practice; accepted for API consistency but ignored. */
84
- transient?: boolean;
85
- onGestureStart?(ids: string[]): void;
86
- onGestureEnd?(committed: boolean): void;
87
- /** Optional: expand the incoming id list before pose lookups. Used for
88
- * group expansion (groups have no pose; their leaves do).
89
- * Called once at `start()`. The returned list flows through ctx,
90
- * overlay (`overlay.draggedIds` is the **expanded** leaves), and op
91
- * generation. Returning `[]` aborts the gesture cleanly.
92
- * Default: identity. */
93
- expandIds?: (ids: string[]) => string[];
94
- }
95
-
96
96
  /**
97
97
  * Projection used by `gridSnapStrategy` when `TPose` doesn't expose `{x,y}`
98
98
  * directly (Path, polygon, etc.). The strategy reads the snap point via
@@ -4,6 +4,117 @@ import { b as RotatedPose } from './poseDescriptor-rZa9W5hJ.js';
4
4
  import '@weasel-js/geom';
5
5
  import './autoPoseDescriptor-_XOyF7t4.js';
6
6
 
7
+ /**
8
+ * Fluent builder for `PolygonPath`. Hides the `Uint8Array` / `Float32Array`
9
+ * encoding behind move/line/curve/close calls and a final `build()`. Use
10
+ * this to construct paths in tests and demos; production callers that need
11
+ * to mutate large paths in place should reach for the raw arrays directly.
12
+ *
13
+ * Numeric capacity grows by doubling — typical for amortized O(1) push.
14
+ *
15
+ * Also exposes `rectPath` / `polygonFromPoints` shortcuts for the common
16
+ * cases. `rectPath` returns the lighter `RectPath` subtype, not a polygon.
17
+ */
18
+
19
+ /** Fluent builder for `PolygonPath`; hides the `Uint8Array`/`Float32Array` encoding behind move/line/curve/close calls. */
20
+ declare class PathBuilder {
21
+ private cmds;
22
+ private xs;
23
+ private fillRule;
24
+ /** Seed a builder with an existing `PolygonPath`. Useful for extending
25
+ * an in-flight path with another segment (e.g. appending a cubic to
26
+ * the end of a curve in response to a user action) without hand-
27
+ * reaching into the `commands` / `coords` typed arrays.
28
+ *
29
+ * ```ts
30
+ * const next = PathBuilder.fromPath(current).curveTo(...).build();
31
+ * ```
32
+ */
33
+ static fromPath(path: PolygonPath): PathBuilder;
34
+ setFillRule(rule: PathFillRule): this;
35
+ moveTo(x: number, y: number): this;
36
+ lineTo(x: number, y: number): this;
37
+ /** Cubic bezier to (x, y) with control points (x1, y1) and (x2, y2). */
38
+ curveTo(x1: number, y1: number, x2: number, y2: number, x: number, y: number): this;
39
+ /** Quadratic bezier to (x, y) with control point (x1, y1). */
40
+ quadTo(x1: number, y1: number, x: number, y: number): this;
41
+ close(): this;
42
+ build(): PolygonPath;
43
+ }
44
+ /** Construct a `RectPath` (the fast-path subtype). */
45
+ declare function rectPath(x: number, y: number, width: number, height: number): RectPath;
46
+ /** Build an open polyline from a flat list of points — the same geometry as
47
+ * {@link polygonFromPoints} without the closing edge. A freehand stroke and a
48
+ * measurement line want this; a region wants the closed one. */
49
+ declare function polylineFromPoints(points: readonly {
50
+ x: number;
51
+ y: number;
52
+ }[]): PolygonPath | RectPath;
53
+ /** Build a closed polygon from a flat list of points. */
54
+ declare function polygonFromPoints(points: readonly {
55
+ x: number;
56
+ y: number;
57
+ }[], opts?: {
58
+ fillRule?: PathFillRule;
59
+ }): PolygonPath;
60
+ /** Closed ellipse inscribed in `bounds`, as a 4-cubic-Bezier `PolygonPath`.
61
+ * Matches the geometry `useEllipseTool`'s overlay paints. */
62
+ declare function ellipsePath(bounds: {
63
+ x: number;
64
+ y: number;
65
+ width: number;
66
+ height: number;
67
+ }): PolygonPath;
68
+ /** Closed regular n-gon centered at `center`, circumscribed by `radius`.
69
+ * `rotation` is in radians; default 0 puts the first vertex on the +x axis. */
70
+ declare function regularPolygonPath(center: {
71
+ x: number;
72
+ y: number;
73
+ }, radius: number, sides: number, rotation?: number): PolygonPath;
74
+ /** Closed n-pointed star centered at `center`, alternating `outerRadius` and
75
+ * `innerRadius` (default `outerRadius / 2`). `rotation` is in radians. */
76
+ declare function starPath(center: {
77
+ x: number;
78
+ y: number;
79
+ }, outerRadius: number, points?: number, innerRadius?: number, rotation?: number): PolygonPath;
80
+ /** Open 2-vertex polyline from `a` to `b` — strokeable, not fillable. */
81
+ declare function linePath(a: {
82
+ x: number;
83
+ y: number;
84
+ }, b: {
85
+ x: number;
86
+ y: number;
87
+ }): PolygonPath;
88
+
89
+ /**
90
+ * A station along a path: where it is at a fraction of its length, and which
91
+ * way it is heading there.
92
+ *
93
+ * For anything positioned *along* geometry rather than beside it — a label on a
94
+ * routed edge, a tick on a curve, a badge near an arrowhead. Curves are
95
+ * flattened first, so the fraction is arc length along the drawn shape rather
96
+ * than a curve parameter, which is what makes 0.5 look like the middle.
97
+ */
98
+
99
+ interface PathStation {
100
+ point: Point2;
101
+ /** Unit vector along the path at `point`, pointing toward the end. */
102
+ tangent: Point2;
103
+ }
104
+ interface PointAlongPathOptions {
105
+ /** Curve flattening tolerance, in world units. Default 0.5. */
106
+ flattenTolerance?: number;
107
+ }
108
+ /**
109
+ * Where `path` is at `t` of its total length, and its heading there.
110
+ *
111
+ * `t` is clamped to 0..1. Subpaths are measured in order and treated as one
112
+ * run, the way a browser measures a whole `<path>`. Returns `null` for a path
113
+ * with no points at all; a path of zero length answers at its single point,
114
+ * heading along +X.
115
+ */
116
+ declare function pointAlongPath(path: Path, t: number, opts?: PointAlongPathOptions): PathStation | null;
117
+
7
118
  /**
8
119
  * Minimal node interface for the simulation primitive. Matches d3-force's
9
120
  * node shape exactly so d3-force's bundled forces work without translation.
@@ -128,117 +239,6 @@ declare const DEFAULT_VELOCITY_DECAY = 0.4;
128
239
 
129
240
  declare function createSimulation<TNode extends SimulationNode>(opts: SimulationOptions<TNode>): SimulationCore<TNode>;
130
241
 
131
- /**
132
- * Fluent builder for `PolygonPath`. Hides the `Uint8Array` / `Float32Array`
133
- * encoding behind move/line/curve/close calls and a final `build()`. Use
134
- * this to construct paths in tests and demos; production callers that need
135
- * to mutate large paths in place should reach for the raw arrays directly.
136
- *
137
- * Numeric capacity grows by doubling — typical for amortized O(1) push.
138
- *
139
- * Also exposes `rectPath` / `polygonFromPoints` shortcuts for the common
140
- * cases. `rectPath` returns the lighter `RectPath` subtype, not a polygon.
141
- */
142
-
143
- /** Fluent builder for `PolygonPath`; hides the `Uint8Array`/`Float32Array` encoding behind move/line/curve/close calls. */
144
- declare class PathBuilder {
145
- private cmds;
146
- private xs;
147
- private fillRule;
148
- /** Seed a builder with an existing `PolygonPath`. Useful for extending
149
- * an in-flight path with another segment (e.g. appending a cubic to
150
- * the end of a curve in response to a user action) without hand-
151
- * reaching into the `commands` / `coords` typed arrays.
152
- *
153
- * ```ts
154
- * const next = PathBuilder.fromPath(current).curveTo(...).build();
155
- * ```
156
- */
157
- static fromPath(path: PolygonPath): PathBuilder;
158
- setFillRule(rule: PathFillRule): this;
159
- moveTo(x: number, y: number): this;
160
- lineTo(x: number, y: number): this;
161
- /** Cubic bezier to (x, y) with control points (x1, y1) and (x2, y2). */
162
- curveTo(x1: number, y1: number, x2: number, y2: number, x: number, y: number): this;
163
- /** Quadratic bezier to (x, y) with control point (x1, y1). */
164
- quadTo(x1: number, y1: number, x: number, y: number): this;
165
- close(): this;
166
- build(): PolygonPath;
167
- }
168
- /** Construct a `RectPath` (the fast-path subtype). */
169
- declare function rectPath(x: number, y: number, width: number, height: number): RectPath;
170
- /** Build an open polyline from a flat list of points — the same geometry as
171
- * {@link polygonFromPoints} without the closing edge. A freehand stroke and a
172
- * measurement line want this; a region wants the closed one. */
173
- declare function polylineFromPoints(points: readonly {
174
- x: number;
175
- y: number;
176
- }[]): PolygonPath | RectPath;
177
- /** Build a closed polygon from a flat list of points. */
178
- declare function polygonFromPoints(points: readonly {
179
- x: number;
180
- y: number;
181
- }[], opts?: {
182
- fillRule?: PathFillRule;
183
- }): PolygonPath;
184
- /** Closed ellipse inscribed in `bounds`, as a 4-cubic-Bezier `PolygonPath`.
185
- * Matches the geometry `useEllipseTool`'s overlay paints. */
186
- declare function ellipsePath(bounds: {
187
- x: number;
188
- y: number;
189
- width: number;
190
- height: number;
191
- }): PolygonPath;
192
- /** Closed regular n-gon centered at `center`, circumscribed by `radius`.
193
- * `rotation` is in radians; default 0 puts the first vertex on the +x axis. */
194
- declare function regularPolygonPath(center: {
195
- x: number;
196
- y: number;
197
- }, radius: number, sides: number, rotation?: number): PolygonPath;
198
- /** Closed n-pointed star centered at `center`, alternating `outerRadius` and
199
- * `innerRadius` (default `outerRadius / 2`). `rotation` is in radians. */
200
- declare function starPath(center: {
201
- x: number;
202
- y: number;
203
- }, outerRadius: number, points?: number, innerRadius?: number, rotation?: number): PolygonPath;
204
- /** Open 2-vertex polyline from `a` to `b` — strokeable, not fillable. */
205
- declare function linePath(a: {
206
- x: number;
207
- y: number;
208
- }, b: {
209
- x: number;
210
- y: number;
211
- }): PolygonPath;
212
-
213
- /**
214
- * A station along a path: where it is at a fraction of its length, and which
215
- * way it is heading there.
216
- *
217
- * For anything positioned *along* geometry rather than beside it — a label on a
218
- * routed edge, a tick on a curve, a badge near an arrowhead. Curves are
219
- * flattened first, so the fraction is arc length along the drawn shape rather
220
- * than a curve parameter, which is what makes 0.5 look like the middle.
221
- */
222
-
223
- interface PathStation {
224
- point: Point2;
225
- /** Unit vector along the path at `point`, pointing toward the end. */
226
- tangent: Point2;
227
- }
228
- interface PointAlongPathOptions {
229
- /** Curve flattening tolerance, in world units. Default 0.5. */
230
- flattenTolerance?: number;
231
- }
232
- /**
233
- * Where `path` is at `t` of its total length, and its heading there.
234
- *
235
- * `t` is clamped to 0..1. Subpaths are measured in order and treated as one
236
- * run, the way a browser measures a whole `<path>`. Returns `null` for a path
237
- * with no points at all; a path of zero length answers at its single point,
238
- * heading along +X.
239
- */
240
- declare function pointAlongPath(path: Path, t: number, opts?: PointAlongPathOptions): PathStation | null;
241
-
242
242
  /** AABB center of an unrotated rect — the canonical rotation pivot. */
243
243
  declare function aabbCenter(bounds: Bounds): {
244
244
  x: number;