@weasel-js/core 1.6.0 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +266 -0
- package/README.md +24 -4
- package/dist/{depSchema-BhgZc0-Q.d.ts → builtins-DLn2lCr_.d.ts} +693 -53
- package/dist/{chunk-BJN5ZRIJ.js → chunk-3TY6FHAF.js} +7 -4
- package/dist/chunk-3TY6FHAF.js.map +1 -0
- package/dist/{chunk-H6N2JSZ3.js → chunk-DGWNNKGD.js} +3 -3
- package/dist/{chunk-H6N2JSZ3.js.map → chunk-DGWNNKGD.js.map} +1 -1
- package/dist/{chunk-THCSDHII.js → chunk-G4ZGQMY7.js} +2453 -1264
- package/dist/chunk-G4ZGQMY7.js.map +1 -0
- package/dist/{chunk-HPFJUUTF.js → chunk-LU4IJ52W.js} +5 -61
- package/dist/chunk-LU4IJ52W.js.map +1 -0
- package/dist/{chunk-D4AAWR64.js → chunk-M24CLARN.js} +4 -4
- package/dist/{chunk-D4AAWR64.js.map → chunk-M24CLARN.js.map} +1 -1
- package/dist/{chunk-4RJP2N2L.js → chunk-NE27EOLP.js} +8 -5
- package/dist/chunk-NE27EOLP.js.map +1 -0
- package/dist/{chunk-DOBSZOPR.js → chunk-UPZY4ART.js} +3 -3
- package/dist/{chunk-DOBSZOPR.js.map → chunk-UPZY4ART.js.map} +1 -1
- package/dist/{chunk-T3UQ3F6R.js → chunk-WPNA6L5O.js} +47 -13
- package/dist/chunk-WPNA6L5O.js.map +1 -0
- package/dist/{chunk-44EWMJV2.js → chunk-XMAWPGTK.js} +5 -5
- package/dist/{chunk-44EWMJV2.js.map → chunk-XMAWPGTK.js.map} +1 -1
- package/dist/clipboard.d.ts +1 -1
- package/dist/clipboard.js +3 -3
- package/dist/clone.d.ts +2 -2
- package/dist/clone.js +3 -3
- package/dist/grid-CY5UKlZh.d.ts +98 -0
- package/dist/index.css +11 -35
- package/dist/index.css.map +1 -1
- package/dist/index.d.ts +912 -1148
- package/dist/index.js +9 -9
- package/dist/insert.d.ts +2 -3
- package/dist/insert.js +1 -1
- package/dist/math.d.ts +1 -1
- package/dist/move.d.ts +5 -4
- package/dist/move.js +4 -4
- package/dist/move.js.map +1 -1
- package/dist/patterns-builtin.js +1 -1
- package/dist/{pointSnapToGrid-7mCcm6qG.d.ts → pointSnapToGrid-Dp2IxLGb.d.ts} +53 -60
- package/dist/renderer.css +11 -35
- package/dist/renderer.css.map +1 -1
- package/dist/renderer.d.ts +17 -8
- package/dist/renderer.js +9 -9
- package/dist/resize.d.ts +3 -3
- package/dist/resize.js +2 -2
- package/dist/routing.d.ts +1 -1
- package/dist/routing.js +1 -1
- package/dist/{types-CxC8P6W0.d.ts → types-D-9QWBy5.d.ts} +9 -6
- package/dist/{types-D_74YlWs.d.ts → types-qYpyTAiZ.d.ts} +4 -7
- package/package.json +15 -12
- package/dist/chunk-4RJP2N2L.js.map +0 -1
- package/dist/chunk-BJN5ZRIJ.js.map +0 -1
- package/dist/chunk-HPFJUUTF.js.map +0 -1
- package/dist/chunk-T3UQ3F6R.js.map +0 -1
- package/dist/chunk-THCSDHII.js.map +0 -1
- package/dist/grid-Dx2gQbNv.d.ts +0 -158
- package/dist/options-CzjxFoYZ.d.ts +0 -67
- package/dist/{math-DRa6HBBs.d.ts → math-MCQcf_gc.d.ts} +111 -111
package/dist/grid-Dx2gQbNv.d.ts
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import { M as MoveBehavior, S as SnapStrategy } from './types-D_74YlWs.js';
|
|
2
|
-
import { DebugSink } from '@weasel-js/routing';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Units — a tiny customizable unit system for canvas-kit APIs.
|
|
6
|
-
*
|
|
7
|
-
* The kit stores all coordinates as bare numbers in a single base unit
|
|
8
|
-
* chosen by the consumer app. To make API call sites self-documenting,
|
|
9
|
-
* the public surface accepts `UnitValue` — either a bare number (interpreted
|
|
10
|
-
* as base units) or a `{ value, unit }` tag that's resolved against a
|
|
11
|
-
* `UnitSystem` at the API boundary. Internals never see units.
|
|
12
|
-
*
|
|
13
|
-
* An entry is affine — `base = value * factor + offset` — so a scale that
|
|
14
|
-
* puts zero somewhere else (degC against K) is expressible. No per-axis
|
|
15
|
-
* units. No mixed-unit arithmetic.
|
|
16
|
-
*/
|
|
17
|
-
/** A unit name (e.g. `'in'`, `'ft'`, `'mm'`). Looked up in a `UnitSystem`. */
|
|
18
|
-
type Unit = string;
|
|
19
|
-
/** What one unit is worth in base units: `base = value * factor + offset`. */
|
|
20
|
-
interface UnitScale {
|
|
21
|
-
factor: number;
|
|
22
|
-
/** Where this unit puts zero, in base units. Absent is 0 — a pure scale. */
|
|
23
|
-
offset?: number;
|
|
24
|
-
}
|
|
25
|
-
/** One unit's conversion. A bare number is the `{ factor }` shorthand. */
|
|
26
|
-
type UnitEntry = number | UnitScale;
|
|
27
|
-
/** Conversion table mapping unit names to their scale against a base unit. */
|
|
28
|
-
interface UnitSystem {
|
|
29
|
-
/** Name of the base unit, e.g. 'in'. All conversions resolve to this. */
|
|
30
|
-
base: Unit;
|
|
31
|
-
/** How to reach base units from each unit. The base unit's entry is 1. */
|
|
32
|
-
units: Record<Unit, UnitEntry>;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* One unit's scale, with the bare-number shorthand widened and the offset
|
|
36
|
-
* defaulted — what every conversion in the kit reads. Throws if the system
|
|
37
|
-
* does not carry the unit.
|
|
38
|
-
*/
|
|
39
|
-
declare function unitScale(unitSystem: UnitSystem, unit: Unit): Required<UnitScale>;
|
|
40
|
-
/** Value at a unit-aware API boundary: bare number (in base units) or `{ value, unit }` tag. */
|
|
41
|
-
type UnitValue = number | {
|
|
42
|
-
value: number;
|
|
43
|
-
unit: Unit;
|
|
44
|
-
};
|
|
45
|
-
/**
|
|
46
|
-
* Resolve a UnitValue to a number in base units.
|
|
47
|
-
* - bare number: returned as-is (assumed base)
|
|
48
|
-
* - tagged: looks up factor; throws if unit not in unit system
|
|
49
|
-
*/
|
|
50
|
-
declare function resolveUnit(v: UnitValue, unitSystem?: UnitSystem): number;
|
|
51
|
-
/**
|
|
52
|
-
* Format a base-unit number as a string in the named display unit.
|
|
53
|
-
* e.g. formatUnit(36, 'ft', IMPERIAL_INCHES) => '3ft'
|
|
54
|
-
* Default precision: 2. Trailing zeros trimmed.
|
|
55
|
-
*/
|
|
56
|
-
declare function formatUnit(baseValue: number, displayUnit: Unit, unitSystem: UnitSystem, opts?: {
|
|
57
|
-
precision?: number;
|
|
58
|
-
suffix?: boolean;
|
|
59
|
-
}): string;
|
|
60
|
-
/** Imperial unit system with base 'in'. */
|
|
61
|
-
declare const IMPERIAL_INCHES: UnitSystem;
|
|
62
|
-
/** Metric unit system with base 'mm'. */
|
|
63
|
-
declare const METRIC_MM: UnitSystem;
|
|
64
|
-
/** Angle unit system with base 'rad'. */
|
|
65
|
-
declare const ANGLE_RADIANS: UnitSystem;
|
|
66
|
-
/** Pixel unit system — sole unit is the base. */
|
|
67
|
-
declare const PIXELS: UnitSystem;
|
|
68
|
-
|
|
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
|
-
/**
|
|
97
|
-
* Projection used by `gridSnapStrategy` when `TPose` doesn't expose `{x,y}`
|
|
98
|
-
* directly (Path, polygon, etc.). The strategy reads the snap point via
|
|
99
|
-
* `getOrigin`, rounds it to the grid, then asks `translate` to move the
|
|
100
|
-
* pose by the resulting delta.
|
|
101
|
-
*/
|
|
102
|
-
interface OriginProjection<TPose> {
|
|
103
|
-
getOrigin(pose: TPose): {
|
|
104
|
-
x: number;
|
|
105
|
-
y: number;
|
|
106
|
-
};
|
|
107
|
-
translate(pose: TPose, dx: number, dy: number): TPose;
|
|
108
|
-
}
|
|
109
|
-
/** Identity projection for `TPose extends { x; y }`. */
|
|
110
|
-
declare const RECT_ORIGIN_PROJECTION: OriginProjection<{
|
|
111
|
-
x: number;
|
|
112
|
-
y: number;
|
|
113
|
-
}>;
|
|
114
|
-
/** Snap-strategy that rounds the pose's origin to the nearest multiple of
|
|
115
|
-
* `spacing` (resolved through `unitSystem`). For non-rect TPose pass an
|
|
116
|
-
* `OriginProjection` so the strategy knows how to read/write the origin. */
|
|
117
|
-
declare function gridSnapStrategy<TPose>(spacing: UnitValue, unitSystem?: UnitSystem): SnapStrategy<TPose>;
|
|
118
|
-
/** As above, additionally reporting each candidate to a debug sink. */
|
|
119
|
-
declare function gridSnapStrategy<TPose>(spacing: UnitValue, opts: {
|
|
120
|
-
unitSystem?: UnitSystem;
|
|
121
|
-
debug?: DebugSink;
|
|
122
|
-
}): SnapStrategy<TPose>;
|
|
123
|
-
/** As above, for a `TPose` that is not a rect: `origin` tells the strategy how
|
|
124
|
-
* to read and write the pose's origin. */
|
|
125
|
-
declare function gridSnapStrategy<TPose>(spacing: UnitValue, opts: {
|
|
126
|
-
unitSystem?: UnitSystem;
|
|
127
|
-
origin: OriginProjection<TPose>;
|
|
128
|
-
debug?: DebugSink;
|
|
129
|
-
}): SnapStrategy<TPose>;
|
|
130
|
-
/**
|
|
131
|
-
* Compute the integer cell `{col, row}` that contains `point`, given a grid
|
|
132
|
-
* `spacing` and optional `origin` and `unitSystem`. Pair with
|
|
133
|
-
* `createCellHighlightLayer` (its `getCell` callback) to draw a snap-target
|
|
134
|
-
* preview that uses the same spacing as `gridSnapStrategy` — so the visual
|
|
135
|
-
* and behavioral grids stay in lockstep:
|
|
136
|
-
*
|
|
137
|
-
* const SPACING = 20;
|
|
138
|
-
* const snap = gridSnapStrategy(SPACING);
|
|
139
|
-
* // visual grid:
|
|
140
|
-
* createGridLayer({ spacing: SPACING, bounds: () => ... });
|
|
141
|
-
* // hover-preview overlay:
|
|
142
|
-
* createCellHighlightLayer({
|
|
143
|
-
* spacing: SPACING,
|
|
144
|
-
* getCell: () => hoverPoint && pointToGridCell(hoverPoint, SPACING),
|
|
145
|
-
* });
|
|
146
|
-
*/
|
|
147
|
-
declare function pointToGridCell(point: {
|
|
148
|
-
x: number;
|
|
149
|
-
y: number;
|
|
150
|
-
}, spacing: UnitValue, unitSystem?: UnitSystem, origin?: {
|
|
151
|
-
x: number;
|
|
152
|
-
y: number;
|
|
153
|
-
}): {
|
|
154
|
-
col: number;
|
|
155
|
-
row: number;
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
export { ANGLE_RADIANS as A, IMPERIAL_INCHES as I, METRIC_MM as M, type OriginProjection as O, PIXELS as P, RECT_ORIGIN_PROJECTION as R, type UseMoveOptions as U, type UnitValue as a, type UnitSystem as b, type UnitEntry as c, type Unit as d, type UnitScale as e, formatUnit as f, gridSnapStrategy as g, pointToGridCell as p, resolveUnit as r, unitScale as u };
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { Op } from '@weasel-js/history';
|
|
2
|
-
import { I as InsertBehavior } from './types-D_74YlWs.js';
|
|
3
|
-
import { Bounds } from '@weasel-js/routing';
|
|
4
|
-
|
|
5
|
-
/** Option surface for the `insert` action.
|
|
6
|
-
*
|
|
7
|
-
* Lives in a sibling file (not `insert.ts`) so the type contract stays stable
|
|
8
|
-
* even after the legacy `useInsert` hook is gone.
|
|
9
|
-
* Consumers should import from here directly; `insert.ts` re-exports the
|
|
10
|
-
* same symbol for back-compat. */
|
|
11
|
-
|
|
12
|
-
/** Options for the `insert` action: what the drag bounds become, what a click
|
|
13
|
-
* with no drag does, and the behaviors that shape the pose along the way. */
|
|
14
|
-
interface UseInsertOptions<TPose, TNode extends {
|
|
15
|
-
id: string;
|
|
16
|
-
} = {
|
|
17
|
-
id: string;
|
|
18
|
-
}> {
|
|
19
|
-
behaviors?: InsertBehavior<TPose>[];
|
|
20
|
-
insertLabel?: string;
|
|
21
|
-
/** Reserved; insert is never transient in practice. Ignored. */
|
|
22
|
-
transient?: boolean;
|
|
23
|
-
/** Strictly-greater-than thresholds; bounds with width <= or height <= abort. Default { width: 0, height: 0 }. */
|
|
24
|
-
minBounds?: {
|
|
25
|
-
width: number;
|
|
26
|
-
height: number;
|
|
27
|
-
};
|
|
28
|
-
/** Construct the in-flight pose from the drag bounds. Defaults to the
|
|
29
|
-
* identity cast (treat bounds as TPose). Override for non-rect TPose
|
|
30
|
-
* (e.g. `(b) => rectPath(b)` or a polygon factory). */
|
|
31
|
-
posefromBounds?: (bounds: Bounds) => TPose;
|
|
32
|
-
/** Click / sub-threshold-drag fallback. When provided, a release whose
|
|
33
|
-
* bounds fall <= minBounds calls `pointInsert(start)` instead of aborting.
|
|
34
|
-
* Returning null aborts. The created object is dispatched as an InsertOp
|
|
35
|
-
* under the same `insertLabel`. */
|
|
36
|
-
pointInsert?: (point: {
|
|
37
|
-
x: number;
|
|
38
|
-
y: number;
|
|
39
|
-
}) => TNode | null;
|
|
40
|
-
/** Drag-disabled mode. When true, every release routes to pointInsert(start)
|
|
41
|
-
* regardless of bounds — commitInsert is never called. Used by tool hooks
|
|
42
|
-
* that wire only pointer.onClick (no marquee). */
|
|
43
|
-
clickOnly?: boolean;
|
|
44
|
-
/** Override for op dispatch on commit. When set, this is called instead of
|
|
45
|
-
* `dispatchApplyBatch(adapter, ...)`. Tool hooks that synthesize an adapter
|
|
46
|
-
* but want commits to route through the active tool ctx's `applyOps`
|
|
47
|
-
* (for history integration) supply a function that reads from a ref
|
|
48
|
-
* captured on handler entry. Read fresh on every commit, so a ref-reader
|
|
49
|
-
* works without retriggering memos. */
|
|
50
|
-
applyOps?: (ops: Op[], label: string) => void;
|
|
51
|
-
onGestureStart?: () => void;
|
|
52
|
-
onGestureEnd?: (committed: boolean) => void;
|
|
53
|
-
/** Optional: snap world-space points to the active grid (or any other
|
|
54
|
-
* snap target). Applied to every coord the gesture ingests, so both the
|
|
55
|
-
* live marquee overlay and the committed bounds track the snapped
|
|
56
|
-
* values. When omitted, behavior is identical to today (identity
|
|
57
|
-
* passthrough). */
|
|
58
|
-
snapPoint?: (p: {
|
|
59
|
-
x: number;
|
|
60
|
-
y: number;
|
|
61
|
-
}) => {
|
|
62
|
-
x: number;
|
|
63
|
-
y: number;
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export type { UseInsertOptions as U };
|
|
@@ -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;
|