@vielzeug/codex 26.11.23 → 26.11.24
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/data/catalog.json +56 -53
- package/data/llms-full.txt +325 -57
- package/data/llms.txt +1 -1
- package/data/manifest.json +1 -1
- package/data/packages/atlas.json +15 -4
- package/data/packages/ink.json +15 -6
- package/data/packages/stage.json +14 -13
- package/data/packages/wire.json +21 -6
- package/data/refine.json +208 -204
- package/package.json +2 -2
package/data/llms-full.txt
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Vielzeug: Full Documentation
|
|
2
2
|
|
|
3
|
-
> Complete documentation for 52 packages. Version: 26.11.
|
|
3
|
+
> Complete documentation for 52 packages. Version: 26.11.23
|
|
4
4
|
|
|
5
5
|
---
|
|
6
6
|
|
|
@@ -2860,6 +2860,7 @@ index.queryPoint({ x: 5, y: 5 }); // ['a']
|
|
|
2860
2860
|
- Rect math: union, closed-interval intersection, containment, inflation, and bounds-from-points
|
|
2861
2861
|
- Snapping: `snapRect()` alignment/grid/equal-gap guides with `kind`-tagged targets, plus pure `alignRects()`/`distributeRects()`
|
|
2862
2862
|
- Narrow-phase geometry: `pointInPolygon`, `distanceToPolyline`, `pointNearPolygon` for exact stroke and polygon hit-testing
|
|
2863
|
+
- Frames: `frameMatrix()` local→world placement, `boundsOfFrame()` world AABBs, and `resizeRect()` editor resize math with min and aspect locks
|
|
2863
2864
|
- `AtlasError` / `AtlasConfigError`: typed errors; the camera follows the Vielzeug disposal contract
|
|
2864
2865
|
- Zero runtime dependencies, no DOM requirement: works in Node, Workers, and SSR
|
|
2865
2866
|
|
|
@@ -2880,20 +2881,23 @@ index.queryPoint({ x: 5, y: 5 }); // ['a']
|
|
|
2880
2881
|
|
|
2881
2882
|
## API Overview
|
|
2882
2883
|
|
|
2883
|
-
| Symbol | Purpose
|
|
2884
|
-
| ------------------------------------ |
|
|
2885
|
-
| `createCamera()` | Pan/zoom/rotate camera with anchor-preserving transforms
|
|
2886
|
-
| `createSpatialIndex()` | Dynamic R-tree over world-space rects
|
|
2887
|
-
| `multiply()` etc. | Canvas2D-order matrix composition
|
|
2888
|
-
| `rectFromPoints()` | AABB of a point set
|
|
2889
|
-
| `pointInPolygon()` | Even-odd ray-cast containment
|
|
2890
|
-
| `distanceToPolyline()` | Distance to the nearest segment
|
|
2891
|
-
| `snapRect()` | Alignment, grid, and equal-gap snapping with guides
|
|
2892
|
-
| `alignRects()` | Align rects to a shared edge or center
|
|
2893
|
-
| `distributeRects()` | Equalize gaps along one axis
|
|
2894
|
-
| `
|
|
2895
|
-
| `
|
|
2896
|
-
| `
|
|
2884
|
+
| Symbol | Purpose | Execution | Common gotcha |
|
|
2885
|
+
| ------------------------------------ | ---------------------------------------------------------- | --------- | ----------------------------------------------------------- |
|
|
2886
|
+
| `createCamera()` | Pan/zoom/rotate camera with anchor-preserving transforms | Sync | `x`/`y` is the world point at the viewport centre |
|
|
2887
|
+
| `createSpatialIndex()` | Dynamic R-tree over world-space rects | Sync | Broad-phase only: bounds overlap, not exact shape hits |
|
|
2888
|
+
| `multiply()` etc. | Canvas2D-order matrix composition | Sync | Element order is `[a,b,c,d,e,f]`, not row-major 3×3 |
|
|
2889
|
+
| `rectFromPoints()` | AABB of a point set | Sync | Returns `null` only for iterable input that may be empty |
|
|
2890
|
+
| `pointInPolygon()` | Even-odd ray-cast containment | Sync | Boundary points are implementation-defined; add tolerance |
|
|
2891
|
+
| `distanceToPolyline()` | Distance to the nearest segment | Sync | Returns `Infinity` for empty paths |
|
|
2892
|
+
| `snapRect()` | Alignment, grid, and equal-gap snapping with guides | Sync | Each axis resolves independently; alignment wins |
|
|
2893
|
+
| `alignRects()` | Align rects to a shared edge or center | Sync | Pure: returns new rects, input untouched |
|
|
2894
|
+
| `distributeRects()` | Equalize gaps along one axis | Sync | Needs 3+ rects; outermost rects stay fixed |
|
|
2895
|
+
| `frameMatrix()` | Local→world matrix for a positioned, rotated, scaled frame | Sync | `origin` is a world pivot; defaults to `{ x, y }` |
|
|
2896
|
+
| `boundsOfFrame()` | AABB of a rect under a frame matrix | Sync | Grows the bounds for rotation; not a tight oriented box |
|
|
2897
|
+
| `resizeRect()` | Resize a rect by dragging named edges | Sync | `aspect` is width/height; corner drags derive the free axis |
|
|
2898
|
+
| `AtlasError` | Base class for all atlas errors | Sync | Narrow with `instanceof AtlasError` |
|
|
2899
|
+
| `AtlasConfigError` | Invalid options and negative tolerances | Sync | Thrown at call time |
|
|
2900
|
+
| `Point` / `Rect` / `Size` / `Matrix` | Structural shapes shared across the canvas toolkit | Sync | All readonly; treat as values |
|
|
2897
2901
|
|
|
2898
2902
|
## Package Entry Point
|
|
2899
2903
|
|
|
@@ -3020,6 +3024,38 @@ All matrices use Canvas2D element order `[a, b, c, d, e, f]`; composition `multi
|
|
|
3020
3024
|
|
|
3021
3025
|
---
|
|
3022
3026
|
|
|
3027
|
+
## Frame Functions
|
|
3028
|
+
|
|
3029
|
+
A frame places a local shape in world space: a position, an optional clockwise rotation (radians), and an optional scale pivoting around a world `origin`.
|
|
3030
|
+
|
|
3031
|
+
```ts
|
|
3032
|
+
function frameMatrix(options: FrameOptions): Matrix;
|
|
3033
|
+
function boundsOfFrame(rect: Rect, matrix: Matrix): Rect;
|
|
3034
|
+
function resizeRect(rect: Rect, edges: ResizeEdges, point: Point, options?: ResizeOptions): Rect;
|
|
3035
|
+
```
|
|
3036
|
+
|
|
3037
|
+
| Function | Description |
|
|
3038
|
+
| --------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
3039
|
+
| `frameMatrix({ x, y, rotation?, scale?, origin? })` | Local→world matrix: `around(origin, rotate · scale) · translate(x, y)`; `origin` defaults to `{ x, y }`, `scale` is a number or `{ x?, y? }` |
|
|
3040
|
+
| `boundsOfFrame(rect, matrix)` | Axis-aligned world bounds: the AABB of the four transformed corners |
|
|
3041
|
+
| `resizeRect(rect, edges, point, { min?, aspect? })` | Resized rect dragging the edge(s) named by `edges` (`'e'`, `'w'`, `'n'`, `'s'`, or a corner like `'nw'`) to `point`; opposite edge(s) stay fixed |
|
|
3042
|
+
|
|
3043
|
+
`frameMatrix` composes the matrix helpers for the common positioned-shape case, so `apply(frameMatrix({ rotation, scale, x, y }), localPoint)` places a shape's local coordinates in the world. `boundsOfFrame` pairs with it for culling and selection: rotation grows the AABB, which is what a spatial index needs.
|
|
3044
|
+
|
|
3045
|
+
`resizeRect` is the resize-handle math for editors. `min` (default 0) keeps the result from collapsing on either axis. `aspect` (width/height) locks the ratio: a corner drag derives the free axis from the axis that moved further, an edge drag grows the free dimension about its centre.
|
|
3046
|
+
|
|
3047
|
+
```ts
|
|
3048
|
+
import { boundsOfFrame, frameMatrix, resizeRect } from '@vielzeug/atlas';
|
|
3049
|
+
|
|
3050
|
+
const frame = frameMatrix({ rotation: Math.PI / 6, scale: 2, x: 100, y: 50 });
|
|
3051
|
+
boundsOfFrame({ height: 40, width: 100, x: 0, y: 0 }, frame); // world AABB
|
|
3052
|
+
resizeRect(selection, 'se', worldPointer, { min: 4 }); // drag the bottom-right corner
|
|
3053
|
+
```
|
|
3054
|
+
|
|
3055
|
+
All three throw `AtlasConfigError` on non-finite inputs; `resizeRect` also throws for unknown `edges`, a negative `min`, or a non-positive `aspect`.
|
|
3056
|
+
|
|
3057
|
+
---
|
|
3058
|
+
|
|
3023
3059
|
## Geometry Functions
|
|
3024
3060
|
|
|
3025
3061
|
| Function | Description |
|
|
@@ -3065,10 +3101,10 @@ From the `@vielzeug/atlas/grid` subpath:
|
|
|
3065
3101
|
|
|
3066
3102
|
## Errors
|
|
3067
3103
|
|
|
3068
|
-
| Class | Thrown when
|
|
3069
|
-
| ------------------ |
|
|
3070
|
-
| `AtlasError` | Base class; catch-all via `instanceof AtlasError`
|
|
3071
|
-
| `AtlasConfigError` | Invalid options/clamps
|
|
3104
|
+
| Class | Thrown when |
|
|
3105
|
+
| ------------------ | ------------------------------------------------------------------------------- |
|
|
3106
|
+
| `AtlasError` | Base class; catch-all via `instanceof AtlasError` |
|
|
3107
|
+
| `AtlasConfigError` | Invalid options/clamps, negative snap or query tolerances, and bad frame inputs |
|
|
3072
3108
|
|
|
3073
3109
|
### Usage Guide
|
|
3074
3110
|
|
|
@@ -3227,6 +3263,36 @@ scaleOf(transform); // average axis scale
|
|
|
3227
3263
|
toCssMatrix(transform); // 'matrix(...)' for CSS transforms
|
|
3228
3264
|
```
|
|
3229
3265
|
|
|
3266
|
+
## Frames and Resizing
|
|
3267
|
+
|
|
3268
|
+
Shapes on a board are placed with a position, an optional rotation, and an optional scale. `frameMatrix()` composes that into one local→world matrix, and `boundsOfFrame()` turns a local rect into the world AABB your spatial index and selection queries need:
|
|
3269
|
+
|
|
3270
|
+
```ts
|
|
3271
|
+
import { apply, boundsOfFrame, frameMatrix } from '@vielzeug/atlas';
|
|
3272
|
+
|
|
3273
|
+
const frame = frameMatrix({ rotation: Math.PI / 6, scale: 2, x: 100, y: 50 });
|
|
3274
|
+
const world = apply(frame, localPoint); // local → world
|
|
3275
|
+
const aabb = boundsOfFrame(localRect, frame); // world AABB, ready for index.set()
|
|
3276
|
+
```
|
|
3277
|
+
|
|
3278
|
+
`origin` pivots rotation and scale around a world point; it defaults to `{ x, y }`, which makes rotation and scale pure post-transforms of the placement. `toCssMatrix(frame)` feeds the same transform straight to a DOM overlay.
|
|
3279
|
+
|
|
3280
|
+
Resize handles are the other half of editor math. `resizeRect()` takes the dragged handle's direction (`'e'`, `'nw'`, …), the pointer's world position, and keeps the opposite edge(s) fixed:
|
|
3281
|
+
|
|
3282
|
+
```ts
|
|
3283
|
+
import { resizeRect } from '@vielzeug/atlas';
|
|
3284
|
+
|
|
3285
|
+
// Dragging the bottom-right handle; shapes never collapse below 4 units.
|
|
3286
|
+
const next = resizeRect(selection, 'se', worldPointer, { min: 4 });
|
|
3287
|
+
// Shift-drag convention: lock the selection's current ratio.
|
|
3288
|
+
const square = resizeRect(selection, 'se', worldPointer, {
|
|
3289
|
+
aspect: selection.width / selection.height,
|
|
3290
|
+
min: 4,
|
|
3291
|
+
});
|
|
3292
|
+
```
|
|
3293
|
+
|
|
3294
|
+
On a corner drag with `aspect` set, the axis the pointer moved further along drives the other, so the drag feels direct from either side. Commit the returned rect to your model on pointer-up, the same way you commit a snapped move.
|
|
3295
|
+
|
|
3230
3296
|
## Tile Grids
|
|
3231
3297
|
|
|
3232
3298
|
Tile and map editors live on a square grid. The `@vielzeug/atlas/grid` subpath converts between world coordinates and tile coordinates, and enumerates only the tiles a viewport can see:
|
|
@@ -3283,6 +3349,7 @@ saveGame(fog.exportState()); // serializable { seen, visible } key lists
|
|
|
3283
3349
|
### REPL Examples
|
|
3284
3350
|
|
|
3285
3351
|
- createCamera - Pan, zoom and culling (id: `atlas-camera`)
|
|
3352
|
+
- frameMatrix + resizeRect - Rotated frame with resize handles (id: `atlas-frames`)
|
|
3286
3353
|
- snapRect - Magnetic snapping and guides (id: `atlas-snap`)
|
|
3287
3354
|
|
|
3288
3355
|
---
|
|
@@ -13854,39 +13921,49 @@ function strokeWidths(points: readonly StrokePoint[], options: StrokeWidthOption
|
|
|
13854
13921
|
|
|
13855
13922
|
Returns one width per point from real pen speed and optional pressure. Speed is `distance / Δtime` between consecutive points, which stays correct after any stabilization, smoothing, or simplification. Slow widens, fast narrows, clamped to a fixed `[0.25, 2]` scale. When any point lacks `time` — or a Δtime is zero — velocity modulation is disabled for the whole stroke (width becomes `width × pressure`) instead of guessing speed from sample spacing.
|
|
13856
13923
|
|
|
13857
|
-
| Parameter | Type | Description
|
|
13858
|
-
| --------- | ------------------------ |
|
|
13859
|
-
| `points` | `readonly StrokePoint[]` | Stroke samples (at least one)
|
|
13860
|
-
| `options` | `StrokeWidthOptions` | `width` (required, > 0), `thinning` in `[0, 1]` (default `0.5`), `referenceSpeed` in px/ms (default `0.5`) |
|
|
13924
|
+
| Parameter | Type | Description |
|
|
13925
|
+
| --------- | ------------------------ | --------------------------------------------------------------------------------------------------------------------------------------- |
|
|
13926
|
+
| `points` | `readonly StrokePoint[]` | Stroke samples (at least one) |
|
|
13927
|
+
| `options` | `StrokeWidthOptions` | `width` (required, > 0), `thinning` in `[0, 1]` (default `0.5`), `referenceSpeed` in px/ms (default `0.5`), `taper`, `simulatePressure` |
|
|
13861
13928
|
|
|
13862
13929
|
**Returns:** `number[]` with the same length as `points`. The first point uses the forward segment; degenerate (zero-length) segments keep the previous scale so stationary samples do not spike.
|
|
13863
13930
|
|
|
13864
13931
|
Pressure multiplies the result through a curve where `0.5` (the neutral value a mouse reports) maps to exactly `1`: the range is `[0.5, 1.25]`, so a neutral-pressure stroke is as wide as one without pressure data.
|
|
13865
13932
|
|
|
13933
|
+
`taper` fades the width in over `taper.start` and out over `taper.end` units of arc length (same units as `width`): a smoothstep ramp from a `0.15` floor at the tip to full width at the taper length, multiplied on top of the speed/pressure profile. `simulatePressure` (default `false`) synthesizes pressure for points that have none on a timed stroke: the width multiplier ramps from `0.5` at each tip to neutral across the first and last 15% of arc length, so mouse strokes thin at the ends. Points that carry real `pressure` always use it, and untimed strokes ignore the option.
|
|
13934
|
+
|
|
13866
13935
|
**Example**
|
|
13867
13936
|
|
|
13868
13937
|
```ts
|
|
13869
13938
|
import { strokeWidths } from '@vielzeug/ink';
|
|
13870
13939
|
|
|
13871
13940
|
const widths = strokeWidths(samples, { width: 6, thinning: 0.5 });
|
|
13941
|
+
const tapered = strokeWidths(samples, { width: 6, taper: { start: 30, end: 30 }, simulatePressure: true });
|
|
13872
13942
|
```
|
|
13873
13943
|
|
|
13874
|
-
Throws `InkConfigError` for a non-positive `width` or `referenceSpeed`, a `thinning` outside `[0, 1]`, or an empty `points` array.
|
|
13944
|
+
Throws `InkConfigError` for a non-positive `width` or `referenceSpeed`, a `thinning` outside `[0, 1]`, a negative or non-finite `taper` length, or an empty `points` array.
|
|
13875
13945
|
|
|
13876
13946
|
---
|
|
13877
13947
|
|
|
13878
13948
|
### `strokeOutline()`
|
|
13879
13949
|
|
|
13880
13950
|
```ts
|
|
13881
|
-
function strokeOutline(
|
|
13951
|
+
function strokeOutline(
|
|
13952
|
+
points: readonly StrokePoint[],
|
|
13953
|
+
widths: number | readonly number[],
|
|
13954
|
+
options?: StrokeOutlineOptions,
|
|
13955
|
+
): Point[];
|
|
13882
13956
|
```
|
|
13883
13957
|
|
|
13884
13958
|
Returns a closed polygon approximating the variable-width stroke: start cap, left offsets forward, end cap, right offsets backward, with no repeated final vertex. Pass a constant `widths` number for a uniform stroke.
|
|
13885
13959
|
|
|
13886
|
-
| Parameter | Type | Description
|
|
13887
|
-
| --------- | ----------------------------- |
|
|
13888
|
-
| `points` | `readonly StrokePoint[]` | Stroke samples (at least one)
|
|
13889
|
-
| `widths` | `number \| readonly number[]` | Constant width, or per-point widths from `strokeWidths()`
|
|
13960
|
+
| Parameter | Type | Description |
|
|
13961
|
+
| --------- | ----------------------------- | --------------------------------------------------------------------------------- |
|
|
13962
|
+
| `points` | `readonly StrokePoint[]` | Stroke samples (at least one) |
|
|
13963
|
+
| `widths` | `number \| readonly number[]` | Constant width, or per-point widths from `strokeWidths()` |
|
|
13964
|
+
| `options` | `StrokeOutlineOptions` | `cap` (default `'round'`), `join` (default `'round'`), `miterLimit` (default `4`) |
|
|
13965
|
+
|
|
13966
|
+
`cap` selects the end treatment: `'round'` half-circle caps, `'butt'` no cap points, `'square'` a half-width tangent extension at each end. `join` handles turns sharper than 90°, where naive offsetting makes the inner side cross itself: `'round'` keeps the plain offset samples (current default output), `'bevel'` replaces each sharp joint with the two adjacent segment-offset points, dropping the crossing spike, and `'miter'` extends to the offset-line intersection while the miter length stays within `miterLimit` × half width, falling back to bevel beyond it.
|
|
13890
13967
|
|
|
13891
13968
|
**Returns:** `Point[]` ring, deterministic for deterministic input.
|
|
13892
13969
|
|
|
@@ -13897,9 +13974,10 @@ import { strokeOutline } from '@vielzeug/ink';
|
|
|
13897
13974
|
|
|
13898
13975
|
const ring = strokeOutline(samples, widths);
|
|
13899
13976
|
const uniform = strokeOutline(samples, 4);
|
|
13977
|
+
const marker = strokeOutline(samples, 4, { cap: 'square', join: 'miter', miterLimit: 6 });
|
|
13900
13978
|
```
|
|
13901
13979
|
|
|
13902
|
-
Throws `InkConfigError` when an array `widths` length differs from `points` length or any width is not a positive finite number.
|
|
13980
|
+
Throws `InkConfigError` when an array `widths` length differs from `points` length or any width is not a positive finite number, when `cap` or `join` is not a known variant, or when `miterLimit` is not a positive finite number.
|
|
13903
13981
|
|
|
13904
13982
|
---
|
|
13905
13983
|
|
|
@@ -13988,6 +14066,31 @@ interface StrokeWidthOptions {
|
|
|
13988
14066
|
width: number; // required, > 0
|
|
13989
14067
|
thinning?: number; // [0, 1], default 0.5
|
|
13990
14068
|
referenceSpeed?: number; // > 0, default 0.5 (px per ms)
|
|
14069
|
+
taper?: StrokeTaperOptions; // arc-length end fade, default none
|
|
14070
|
+
simulatePressure?: boolean; // default false; timed strokes only
|
|
14071
|
+
}
|
|
14072
|
+
```
|
|
14073
|
+
|
|
14074
|
+
```ts
|
|
14075
|
+
interface StrokeTaperOptions {
|
|
14076
|
+
start?: number; // fade-in length along arc length, >= 0, default 0
|
|
14077
|
+
end?: number; // fade-out length along arc length, >= 0, default 0
|
|
14078
|
+
}
|
|
14079
|
+
```
|
|
14080
|
+
|
|
14081
|
+
```ts
|
|
14082
|
+
type StrokeCap = 'round' | 'butt' | 'square';
|
|
14083
|
+
```
|
|
14084
|
+
|
|
14085
|
+
```ts
|
|
14086
|
+
type StrokeJoin = 'round' | 'bevel' | 'miter';
|
|
14087
|
+
```
|
|
14088
|
+
|
|
14089
|
+
```ts
|
|
14090
|
+
interface StrokeOutlineOptions {
|
|
14091
|
+
cap?: StrokeCap; // default 'round'
|
|
14092
|
+
join?: StrokeJoin; // default 'round'
|
|
14093
|
+
miterLimit?: number; // > 0, default 4 (miter length / half width)
|
|
13991
14094
|
}
|
|
13992
14095
|
```
|
|
13993
14096
|
|
|
@@ -14000,10 +14103,10 @@ interface PolylineToSvgPathOptions {
|
|
|
14000
14103
|
|
|
14001
14104
|
## Errors
|
|
14002
14105
|
|
|
14003
|
-
| Error | Trigger
|
|
14004
|
-
| ---------------- |
|
|
14005
|
-
| `InkError` | Base class; catch all ink errors with `instanceof InkError`
|
|
14006
|
-
| `InkConfigError` | Invalid options (strength, tension, steps, width, thinning, precision, tolerance, …) or point-count mismatches |
|
|
14106
|
+
| Error | Trigger |
|
|
14107
|
+
| ---------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
14108
|
+
| `InkError` | Base class; catch all ink errors with `instanceof InkError` |
|
|
14109
|
+
| `InkConfigError` | Invalid options (strength, tension, steps, width, thinning, precision, tolerance, cap, join, miterLimit, taper, …) or point-count mismatches |
|
|
14007
14110
|
|
|
14008
14111
|
### Usage Guide
|
|
14009
14112
|
|
|
@@ -14072,6 +14175,16 @@ const widths = strokeWidths(stabilized, {
|
|
|
14072
14175
|
|
|
14073
14176
|
When points carry `pressure` (normalized `[0, 1]`), it multiplies the result: `0.5` is neutral and maps to exactly `1`, so a mouse (which reports `0.5`) draws as wide as a device without pressure data. When any point lacks `time`, velocity modulation is disabled for the whole stroke — width becomes `width × pressure` — instead of guessing speed from sample spacing.
|
|
14074
14177
|
|
|
14178
|
+
`taper` fades the ends: within the first `taper.start` and last `taper.end` units of arc length, the width is multiplied by a smoothstep ramp that bottoms out at `0.15` of full width at the tips. `simulatePressure` gives mouse strokes the same in/out feel by synthesizing pressure for points that have none (ramping to `0.5×` width at each tip over the last 15% of arc length); points with real `pressure` always keep it.
|
|
14179
|
+
|
|
14180
|
+
```ts
|
|
14181
|
+
const tapered = strokeWidths(stabilized, {
|
|
14182
|
+
width: 6,
|
|
14183
|
+
taper: { start: 40, end: 40 }, // 40 px of arc length faded at each end
|
|
14184
|
+
simulatePressure: true, // thin the ends of pressure-less mouse strokes
|
|
14185
|
+
});
|
|
14186
|
+
```
|
|
14187
|
+
|
|
14075
14188
|
## Build the Outline
|
|
14076
14189
|
|
|
14077
14190
|
`strokeOutline()` offsets each sample by half its width along the local normal and closes the ring with half-circle caps at both ends. The result is a plain `Point[]` you can fill with any renderer.
|
|
@@ -14083,6 +14196,12 @@ const ring = strokeOutline(stabilized, widths); // variable width, closed polygo
|
|
|
14083
14196
|
const uniform = strokeOutline(stabilized, 6); // constant width, no array needed
|
|
14084
14197
|
```
|
|
14085
14198
|
|
|
14199
|
+
`cap` changes the ends: `'butt'` stops at the last offsets, `'square'` extends each end by half the width along the tangent. `join` fixes the crossing spike naive offsetting produces at turns sharper than 90°: `'bevel'` cuts the corner with the two adjacent offset points, and `'miter'` extends to the exact intersection while its length stays within `miterLimit` × half width, falling back to bevel beyond that.
|
|
14200
|
+
|
|
14201
|
+
```ts
|
|
14202
|
+
const marker = strokeOutline(stabilized, 6, { cap: 'square', join: 'miter', miterLimit: 6 });
|
|
14203
|
+
```
|
|
14204
|
+
|
|
14086
14205
|
## Simplify Before Serializing
|
|
14087
14206
|
|
|
14088
14207
|
Long strokes accumulate samples. `simplifyStroke()` runs Ramer-Douglas-Peucker and returns a subsequence of the input, so object identity, `pressure`, and `time` survive. Apply it to the outline before emitting SVG to shrink path data.
|
|
@@ -14195,6 +14314,7 @@ const drag = createDragGesture(surface, {
|
|
|
14195
14314
|
|
|
14196
14315
|
### REPL Examples
|
|
14197
14316
|
|
|
14317
|
+
- strokeOutline options - caps, joins, and taper (id: `ink-outline-options`)
|
|
14198
14318
|
- stabilizeStroke - Jitter-free ink (id: `ink-smoothing`)
|
|
14199
14319
|
|
|
14200
14320
|
---
|
|
@@ -34951,7 +35071,7 @@ stage.invalidate('tokens'); // only the tokens layer repaints
|
|
|
34951
35071
|
- **Dirty repaints**: invalidate one layer or all; frames coalesce via an injectable scheduler
|
|
34952
35072
|
- **DPR-aware transforms**: paint in world units, the stage scales by `dpr × matrix`
|
|
34953
35073
|
- **`StageController`**: one control type shared by main-thread and worker stages
|
|
34954
|
-
- **`toBlob()`**: PNG export of the composited canvas, flushing pending frames, with typed unsupported-capability errors
|
|
35074
|
+
- **`toBlob()`**: PNG export of the composited canvas, flushing pending frames, with optional world-space `region`/`scale` re-render and typed unsupported-capability errors
|
|
34955
35075
|
- **Injectable surfaces**: `createSurface` factory for tests and `OffscreenCanvas` workers
|
|
34956
35076
|
- **`@vielzeug/stage/worker`**: worker-rendered stages via a transferred `OffscreenCanvas` and a typed scene channel
|
|
34957
35077
|
|
|
@@ -35006,6 +35126,9 @@ type StageSurface = {
|
|
|
35006
35126
|
};
|
|
35007
35127
|
type CreateSurface = (width: number, height: number) => StageSurface;
|
|
35008
35128
|
|
|
35129
|
+
/** Options for `toBlob()`: blob encoding plus an optional world-space crop and density. */
|
|
35130
|
+
type StageBlobOptions = Readonly;
|
|
35131
|
+
|
|
35009
35132
|
/**
|
|
35010
35133
|
* The control surface both stage modes share. A main-thread `Stage` and a
|
|
35011
35134
|
* `WorkerStage` are interchangeable wherever only control is needed.
|
|
@@ -35013,7 +35136,7 @@ type CreateSurface = (width: number, height: number) => StageSurface;
|
|
|
35013
35136
|
type StageController = Readonly void;
|
|
35014
35137
|
setTransform: (matrix: Matrix) => void;
|
|
35015
35138
|
invalidate: (layerId?: string) => void;
|
|
35016
|
-
toBlob: (options?:
|
|
35139
|
+
toBlob: (options?: StageBlobOptions) => Promise;
|
|
35017
35140
|
dispose: () => void;
|
|
35018
35141
|
readonly disposed: boolean;
|
|
35019
35142
|
readonly disposalSignal: AbortSignal;
|
|
@@ -35074,6 +35197,16 @@ stage.invalidate('scene');
|
|
|
35074
35197
|
|
|
35075
35198
|
`toBlob()` flushes a pending frame before rasterizing, so it always exports the current frame. Paint callbacks receive a context whose transform is `dpr × matrix`, so they draw in world units. Clear and reset with `ctx.setTransform(1, 0, 0, 1, 0, 0)` only if you must paint in device pixels.
|
|
35076
35199
|
|
|
35200
|
+
### `toBlob(options?)`
|
|
35201
|
+
|
|
35202
|
+
```ts
|
|
35203
|
+
type StageBlobOptions = Readonly;
|
|
35204
|
+
```
|
|
35205
|
+
|
|
35206
|
+
Without `region`/`scale`, the stage exports its current canvas at the current device scale. With them, the stage re-paints every layer into scratch surfaces against `translate(-region) × scale` and composites the result into an offscreen surface sized `region.width × scale` by `region.height × scale` (rounded, at least 1 pixel per side) — layer caches are keyed to the live viewport transform, so a crop cannot reuse the cached composite. The cost is a full repaint; the live viewport, caches, and dirty flags are untouched. `scale` defaults to the current device pixels per world unit (`dpr × matrix scale`), which matches the on-screen density; paint callbacks see `frame.dpr = 1` and `frame.visibleRect = region` during an export.
|
|
35207
|
+
|
|
35208
|
+
Invalid `region` (non-finite coordinates or non-positive size) or `scale` (non-positive or non-finite) throws `StageConfigError`; on a worker stage the failure arrives as `StageError`.
|
|
35209
|
+
|
|
35077
35210
|
---
|
|
35078
35211
|
|
|
35079
35212
|
## Worker Subpath (`@vielzeug/stage/worker`)
|
|
@@ -35088,16 +35221,16 @@ The worker owns its layer painters: `serveStage`'s `setup` supplies them, and th
|
|
|
35088
35221
|
|
|
35089
35222
|
`Scene` is the application payload type shared by `sendScene` and `onScene`, so neither side casts. Invalid size, DPR, or matrix input throws `StageConfigError` on the main thread, exactly like `createStage`. Worker-side exceptions are surfaced through `reportError`. The message protocol is internal: its version is checked once at the init/ready handshake, and a mismatch rejects `ready` with a `StageError` and disposes the stage.
|
|
35090
35223
|
|
|
35091
|
-
`createWorkerStage` throws `StageUnsupportedError` when the canvas cannot transfer control (`transferControlToOffscreen` missing). `dispose()` posts a final `dispose` command, rejects in-flight `toBlob()` promises with `StageDisposedError`, aborts `disposalSignal` (terminate the worker from there — the creator owns it), and makes later calls inert.
|
|
35224
|
+
`createWorkerStage` throws `StageUnsupportedError` when the canvas cannot transfer control (`transferControlToOffscreen` missing). `dispose()` posts a final `dispose` command, rejects in-flight `toBlob()` promises with `StageDisposedError`, aborts `disposalSignal` (terminate the worker from there — the creator owns it), and makes later calls inert. `toBlob(options?)` forwards `StageBlobOptions` — including `region` and `scale` — verbatim; the worker performs the same region re-paint export on its `OffscreenCanvas` pipeline.
|
|
35092
35225
|
|
|
35093
35226
|
## Errors
|
|
35094
35227
|
|
|
35095
|
-
| Class | Thrown when
|
|
35096
|
-
| ----------------------- |
|
|
35097
|
-
| `StageError` | Base class; catch all stage failures with `instanceof`
|
|
35098
|
-
| `StageConfigError` | Non-positive sizes, non-finite matrices, duplicate/unknown ids
|
|
35099
|
-
| `StageDisposedError` | `toBlob()` after `dispose()`, or worker blob rejected on disposal
|
|
35100
|
-
| `StageUnsupportedError` | No 2D context on a surface, or `canvas.toBlob` missing/failing
|
|
35228
|
+
| Class | Thrown when |
|
|
35229
|
+
| ----------------------- | ----------------------------------------------------------------------------------------- |
|
|
35230
|
+
| `StageError` | Base class; catch all stage failures with `instanceof` |
|
|
35231
|
+
| `StageConfigError` | Non-positive sizes, non-finite matrices, duplicate/unknown ids, bad `toBlob` region/scale |
|
|
35232
|
+
| `StageDisposedError` | `toBlob()` after `dispose()`, or worker blob rejected on disposal |
|
|
35233
|
+
| `StageUnsupportedError` | No 2D context on a surface, or `canvas.toBlob` missing/failing |
|
|
35101
35234
|
|
|
35102
35235
|
### Usage Guide
|
|
35103
35236
|
|
|
@@ -35170,6 +35303,18 @@ await navigator.clipboard.write([new ClipboardItem({ 'image/png': blob })]);
|
|
|
35170
35303
|
|
|
35171
35304
|
`toBlob()` flushes any pending repaint before rasterizing, so it always captures the current frame — no manual `render()` first. It throws `StageUnsupportedError` when the canvas cannot produce a blob — the stage never silently degrades.
|
|
35172
35305
|
|
|
35306
|
+
For a crop or a higher resolution, pass `region` (world units) and `scale` (export pixels per world unit):
|
|
35307
|
+
|
|
35308
|
+
```ts
|
|
35309
|
+
// Export the visible area at 2× the on-screen density.
|
|
35310
|
+
const blob = await stage.toBlob({
|
|
35311
|
+
region: stage.visibleRect,
|
|
35312
|
+
scale: stage.dpr * cameraZoom * 2,
|
|
35313
|
+
});
|
|
35314
|
+
```
|
|
35315
|
+
|
|
35316
|
+
The stage re-paints every layer into scratch surfaces against the region transform, so the cost is a full repaint rather than a blit of the cached composite; the live viewport and its caches are untouched. `scale` defaults to the current device pixels per world unit, and omitting `region` exports the visible rect. A non-positive or non-finite `region`/`scale` throws `StageConfigError`.
|
|
35317
|
+
|
|
35173
35318
|
## Testing with Injected Surfaces
|
|
35174
35319
|
|
|
35175
35320
|
Inject a fake surface factory and scheduler to unit-test paint behaviour without a GPU:
|
|
@@ -35235,7 +35380,7 @@ Notes:
|
|
|
35235
35380
|
|
|
35236
35381
|
- The worker owns its painters. `serveStage`'s `setup` returns the `layers` (and optional `onScene`/`onDispose` hooks); the main thread never names layers.
|
|
35237
35382
|
- The canvas transfer is **one-shot**: `createWorkerStage` calls `transferControlToOffscreen()` on construction. To go back to main-thread rendering, mount a fresh `` element.
|
|
35238
|
-
- `toBlob()` sends a `blob` command and resolves with the worker's response; requests are correlated by id and reject with `StageDisposedError` if the client is disposed while one is in flight.
|
|
35383
|
+
- `toBlob()` sends a `blob` command and resolves with the worker's response; requests are correlated by id and reject with `StageDisposedError` if the client is disposed while one is in flight. `region` and `scale` are forwarded verbatim and applied worker-side.
|
|
35239
35384
|
- `sendScene(scene)` forwards your typed payload to the worker's `onScene(scene, stage)` hook — useful for mirroring model state (e.g. token moves) without shipping painters to the main thread. The handler decides which layers to invalidate; nothing repaints automatically.
|
|
35240
35385
|
- Invalid size, DPR, or matrix input throws `StageConfigError` on the main thread, exactly like `createStage`.
|
|
35241
35386
|
- Worker-side exceptions are reported through `reportError`, the same path an uncaught main-thread paint error takes. The protocol version is checked once at the init/ready handshake; a stale cached worker rejects `ready` with a `StageError` and disposes the stage.
|
|
@@ -40468,8 +40613,12 @@ const groups = findCyclicGroups(
|
|
|
40468
40613
|
| `bezierRoute()` | Cubic bezier geometry between two ports | Sync | Returns a `CubicBezier`, not a string — serialize with `bezierToSvgPath()` |
|
|
40469
40614
|
| `orthogonalRoute()` | A\* Manhattan polyline avoiding padded obstacles | Sync | Returns `null` when blocked; waypoints appear only at bends |
|
|
40470
40615
|
| `portAnchor()` | World position of a port on a node rect | Sync | `offset` is a 0..1 fraction along the side, not a distance |
|
|
40616
|
+
| `floatingSide()` | Rect side facing a world point | Sync | Dominant axis from the rect center; ties go horizontal |
|
|
40471
40617
|
| `bezierToSvgPath()` | SVG `d` string from a `CubicBezier` | Sync | Emits one absolute `M`/`C` pair |
|
|
40472
|
-
| `polylineToSvgPath()` | SVG `d` string from a polyline | Sync | Empty input returns `''`, not an error
|
|
40618
|
+
| `polylineToSvgPath()` | SVG `d` string from a polyline | Sync | Empty input returns `''`, not an error; `cornerRadius` adds `Q` arcs |
|
|
40619
|
+
| `arrowhead()` | Triangle points capping a line at its tip | Sync | `direction` is normalized; returns points, not an SVG path |
|
|
40620
|
+
| `pointOnBezier()` / `pointOnPolyline()` | Point at a length-normalized `t` on a shape | Sync | `t` is arc length, not the raw bezier parameter |
|
|
40621
|
+
| `hitBezier()` / `hitPolyline()` | Closest point within a threshold | Sync | Returns `null` past the threshold; bezier `t` is sampled |
|
|
40473
40622
|
| `topologicalOrder()` | Kahn ordering with input-order tie breaks | Sync | Throws `WireGraphError` on any cycle |
|
|
40474
40623
|
| `findCyclicGroups()` | Cyclic SCCs via iterative Tarjan | Sync | Reports components (sets), not every elementary cycle |
|
|
40475
40624
|
| `WireError` | Base class for all wire errors | Sync | Narrow with `instanceof WireError` |
|
|
@@ -40526,14 +40675,31 @@ function bezierRoute(from: PortAnchor, to: PortAnchor, options?: BezierRouteOpti
|
|
|
40526
40675
|
|
|
40527
40676
|
Builds a cubic bezier segment whose control points extend `handleLength` units outward from each port along its side, so the curve leaves and enters ports perpendicular to the node edge.
|
|
40528
40677
|
|
|
40529
|
-
| Parameter | Type | Description
|
|
40530
|
-
| --------- | -------------------- |
|
|
40531
|
-
| `from` | `PortAnchor` | Source port with its side
|
|
40532
|
-
| `to` | `PortAnchor` | Target port with its side
|
|
40533
|
-
| `options` | `BezierRouteOptions` | `handleLength` (default 40) control-point reach |
|
|
40678
|
+
| Parameter | Type | Description |
|
|
40679
|
+
| --------- | -------------------- | --------------------------------------------------------------------------- |
|
|
40680
|
+
| `from` | `PortAnchor` | Source port with its side |
|
|
40681
|
+
| `to` | `PortAnchor` | Target port with its side |
|
|
40682
|
+
| `options` | `BezierRouteOptions` | `handleLength` (default 40) control-point reach; `selfLoop` (default false) |
|
|
40534
40683
|
|
|
40535
40684
|
**Returns:** a `CubicBezier` (`from`, `c1`, `c2`, `to`) for canvas or SVG rendering; use `bezierToSvgPath()` for an SVG `d` string. Throws `WireConfigError` for a negative or non-finite `handleLength`.
|
|
40536
40685
|
|
|
40686
|
+
With `selfLoop: true` and both ports on the same side, each handle grows to `1.5 ×` the distance between the ports (never below `handleLength`), so a from→to pair on one node bulges outward into a visible loop instead of collapsing onto the node edge. The shape is deterministic: both handles use the same widened length, keeping the loop symmetric about the port midpoint. The option is ignored when the ports face different sides.
|
|
40687
|
+
|
|
40688
|
+
### `floatingSide()`
|
|
40689
|
+
|
|
40690
|
+
```ts
|
|
40691
|
+
function floatingSide(rect: Rect, toward: Point): PortSide;
|
|
40692
|
+
```
|
|
40693
|
+
|
|
40694
|
+
Returns the side of `rect` facing the point `toward`, chosen by the dominant axis from the rect's center — the larger of `|dx|` and `|dy|` wins. Useful for ports that follow the pointer ("floating" edges) without storing a fixed side.
|
|
40695
|
+
|
|
40696
|
+
| Parameter | Type | Description |
|
|
40697
|
+
| --------- | ------- | -------------------------------- |
|
|
40698
|
+
| `rect` | `Rect` | Node bounding box |
|
|
40699
|
+
| `toward` | `Point` | World point the side should face |
|
|
40700
|
+
|
|
40701
|
+
**Returns:** the facing `PortSide`. Ties (`|dx| === |dy|`, including a target exactly on the center) resolve to the horizontal side, with `right` for a zero offset. Throws `WireConfigError` for non-finite rect or point coordinates.
|
|
40702
|
+
|
|
40537
40703
|
### `orthogonalRoute()`
|
|
40538
40704
|
|
|
40539
40705
|
```ts
|
|
@@ -40563,11 +40729,68 @@ Serializes as an absolute `M`/`C` command, rounded to six decimals with no `-0`
|
|
|
40563
40729
|
### `polylineToSvgPath()`
|
|
40564
40730
|
|
|
40565
40731
|
```ts
|
|
40566
|
-
function polylineToSvgPath(points: readonly Point[]): string;
|
|
40732
|
+
function polylineToSvgPath(points: readonly Point[], options?: PolylinePathOptions): string;
|
|
40567
40733
|
```
|
|
40568
40734
|
|
|
40569
40735
|
Serializes as absolute `M`/`L` commands, rounded to six decimals with no `-0` or exponent noise.
|
|
40570
40736
|
|
|
40737
|
+
| Parameter | Type | Description |
|
|
40738
|
+
| --------- | --------------------- | ---------------------------------------------------------------- |
|
|
40739
|
+
| `points` | `readonly Point[]` | Waypoints, bends included |
|
|
40740
|
+
| `options` | `PolylinePathOptions` | `cornerRadius` (default 0) rounds interior corners with `Q` arcs |
|
|
40741
|
+
|
|
40742
|
+
With `cornerRadius > 0`, each interior corner is replaced by a straight run into the corner, a quadratic `Q` arc through it, and a run out — the corner point itself is not emitted. The radius is clamped per corner to half of its shortest adjacent run, so tight bends never overlap; collinear waypoints and zero-length runs are skipped, keeping the path continuous. `orthogonalRoute()` output stays a raw waypoint polyline — rounding is a rendering decision applied here at serialization time. Throws `WireConfigError` for a negative or non-finite `cornerRadius`.
|
|
40743
|
+
|
|
40744
|
+
---
|
|
40745
|
+
|
|
40746
|
+
## Editing Geometry
|
|
40747
|
+
|
|
40748
|
+
These helpers are DOM-free and node-model-free: they work on the raw geometry `bezierRoute()` and `orthogonalRoute()` produce, for editors that need hit-testing, markers, and drag feedback.
|
|
40749
|
+
|
|
40750
|
+
### `arrowhead()`
|
|
40751
|
+
|
|
40752
|
+
```ts
|
|
40753
|
+
function arrowhead(tip: Point, direction: Point, options?: ArrowheadOptions): Point[];
|
|
40754
|
+
```
|
|
40755
|
+
|
|
40756
|
+
Builds a filled triangle capping a line at `tip`. The apex sits at `tip`; the base sits `length` behind it along `-direction`, `width` apart. `direction` may be any non-zero vector — it is normalized internally — and points the way the line arrives at the tip.
|
|
40757
|
+
|
|
40758
|
+
| Parameter | Type | Description |
|
|
40759
|
+
| ----------- | ------------------ | ----------------------------------------------------------------- |
|
|
40760
|
+
| `tip` | `Point` | Apex of the arrowhead |
|
|
40761
|
+
| `direction` | `Point` | Arrival direction toward the tip (normalized) |
|
|
40762
|
+
| `options` | `ArrowheadOptions` | `length` (default 10) shaft reach; `width` (default 6) base width |
|
|
40763
|
+
|
|
40764
|
+
**Returns:** `[tip, baseLeft, baseRight]` — three points to fill as a polygon. Throws `WireConfigError` for non-finite points, a zero `direction`, or non-positive/non-finite `length`/`width`.
|
|
40765
|
+
|
|
40766
|
+
### `pointOnBezier()` / `pointOnPolyline()`
|
|
40767
|
+
|
|
40768
|
+
```ts
|
|
40769
|
+
function pointOnBezier(curve: CubicBezier, t: number): Point;
|
|
40770
|
+
function pointOnPolyline(points: readonly Point[], t: number): Point;
|
|
40771
|
+
```
|
|
40772
|
+
|
|
40773
|
+
Point at parameter `t` where `t` is normalized by total arc length, not by the raw bezier parameter or segment index: `t = 0.5` is the point halfway along the drawn wire. Polyline results are exact; the bezier mapping uses a fixed 64-sample arc-length lookup table, so `t` lands within roughly one sample cell of the true length fraction — sub-pixel for typical wire sizes.
|
|
40774
|
+
|
|
40775
|
+
**Returns:** the point at that length. Degenerate zero-length shapes return their start for every `t`. Throws `WireConfigError` for non-finite inputs, fewer than two polyline points, or `t` outside `[0, 1]`.
|
|
40776
|
+
|
|
40777
|
+
### `hitBezier()` / `hitPolyline()`
|
|
40778
|
+
|
|
40779
|
+
```ts
|
|
40780
|
+
function hitBezier(curve: CubicBezier, point: Point, options?: HitOptions): HitResult | null;
|
|
40781
|
+
function hitPolyline(points: readonly Point[], point: Point, options?: HitOptions): HitResult | null;
|
|
40782
|
+
```
|
|
40783
|
+
|
|
40784
|
+
Closest point on the shape to `point`, for click selection without invisible DOM hit targets. `hitPolyline` tests every segment analytically (exact); `hitBezier` finds the nearest of 64 samples, then refines with a ternary search on the true curve, so the reported `distance` is accurate while `t` carries the table's arc-length tolerance.
|
|
40785
|
+
|
|
40786
|
+
| Parameter | Type | Description |
|
|
40787
|
+
| ------------------ | ---------------------------------- | -------------------------------------------------- |
|
|
40788
|
+
| `curve` / `points` | `CubicBezier` / `readonly Point[]` | The shape to test |
|
|
40789
|
+
| `point` | `Point` | Query point |
|
|
40790
|
+
| `options` | `HitOptions` | `threshold` (default 4) maximum distance for a hit |
|
|
40791
|
+
|
|
40792
|
+
**Returns:** a `HitResult` (`t` length-normalized in `[0, 1]`, `distance` Euclidean) or `null` when the closest point is farther than `threshold`. For zoom-independent screen picking, divide a screen-pixel threshold by the camera zoom before calling. Same validation errors as the `pointOn*` helpers.
|
|
40793
|
+
|
|
40571
40794
|
---
|
|
40572
40795
|
|
|
40573
40796
|
## Graph Functions
|
|
@@ -40592,11 +40815,11 @@ Iterative Tarjan SCCs. Each returned group is an SCC with more than one node, or
|
|
|
40592
40815
|
|
|
40593
40816
|
## Errors
|
|
40594
40817
|
|
|
40595
|
-
| Class | Thrown when
|
|
40596
|
-
| ----------------- |
|
|
40597
|
-
| `WireError` | Base class; catch-all via `instanceof WireError`
|
|
40598
|
-
| `WireGraphError` | Unknown edge endpoints, duplicate node ids, cyclic `topologicalOrder()`
|
|
40599
|
-
| `WireConfigError` | Negative or non-finite `handleLength`, `padding`, `stub`, or `
|
|
40818
|
+
| Class | Thrown when |
|
|
40819
|
+
| ----------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
|
|
40820
|
+
| `WireError` | Base class; catch-all via `instanceof WireError` |
|
|
40821
|
+
| `WireGraphError` | Unknown edge endpoints, duplicate node ids, cyclic `topologicalOrder()` |
|
|
40822
|
+
| `WireConfigError` | Negative or non-finite `handleLength`, `padding`, `stub`, `bendPenalty`, `cornerRadius`, edit sizes, thresholds, or `t`; bad port offset |
|
|
40600
40823
|
|
|
40601
40824
|
### Usage Guide
|
|
40602
40825
|
|
|
@@ -40642,7 +40865,7 @@ const top = portAnchor(nodeBounds, 'top', 0.25);
|
|
|
40642
40865
|
bezierRoute({ side: 'bottom', x: 60, y: 100 }, { side: 'top', x: 60, y: 220 });
|
|
40643
40866
|
```
|
|
40644
40867
|
|
|
40645
|
-
A free endpoint that is not on a node — the cursor while dragging a wire, say — picks a side explicitly: `{ ...cursor, side: 'left' }`.
|
|
40868
|
+
A free endpoint that is not on a node — the cursor while dragging a wire, say — picks a side explicitly: `{ ...cursor, side: 'left' }`, or computes the facing side with `floatingSide(nodeBounds, cursor)`.
|
|
40646
40869
|
|
|
40647
40870
|
## Routing Around Obstacles
|
|
40648
40871
|
|
|
@@ -40667,6 +40890,50 @@ Four contracts matter for editors:
|
|
|
40667
40890
|
|
|
40668
40891
|
Routes may hug the padded boundary exactly; raise `padding` if you want more clearance.
|
|
40669
40892
|
|
|
40893
|
+
## Rounded Corners
|
|
40894
|
+
|
|
40895
|
+
`polylineToSvgPath()` accepts a `cornerRadius` that replaces each interior bend with a quadratic arc — orthogonal wires stop looking like pipe fittings with one option:
|
|
40896
|
+
|
|
40897
|
+
```ts
|
|
40898
|
+
const points = orthogonalRoute(outPort, inPort, { obstacles: nodeBounds });
|
|
40899
|
+
if (points) pathElement.setAttribute('d', polylineToSvgPath(points, { cornerRadius: 8 }));
|
|
40900
|
+
```
|
|
40901
|
+
|
|
40902
|
+
The radius is clamped per corner to half of its shortest adjacent run, so a bend between two short runs simply rounds as much as fits instead of self-overlapping. The router itself never rounds: `orthogonalRoute()` keeps returning raw waypoints, and rounding stays a rendering decision you can toggle per zoom level or theme.
|
|
40903
|
+
|
|
40904
|
+
## Editing Geometry
|
|
40905
|
+
|
|
40906
|
+
Editors need to answer "what did the user click?" without invisible DOM hit targets. The edit helpers work on the geometry the routers already produce:
|
|
40907
|
+
|
|
40908
|
+
```ts
|
|
40909
|
+
import { hitBezier, hitPolyline } from '@vielzeug/wire';
|
|
40910
|
+
|
|
40911
|
+
// World-space click, threshold scaled so the pick area is zoom-independent.
|
|
40912
|
+
const threshold = 8 / camera.zoom;
|
|
40913
|
+
const hit =
|
|
40914
|
+
edge.geometry.kind === 'bezier'
|
|
40915
|
+
? hitBezier(edge.geometry.curve, worldPoint, { threshold })
|
|
40916
|
+
: hitPolyline(edge.geometry.points, worldPoint, { threshold });
|
|
40917
|
+
if (hit) selectEdge(edge.id, hit.t); // t is normalized by arc length
|
|
40918
|
+
```
|
|
40919
|
+
|
|
40920
|
+
`hit.t` and the matching `pointOnBezier()` / `pointOnPolyline()` are parameterized by arc length, so `t = 0.5` is always the midpoint of the drawn wire — useful for labels and drag handles regardless of how lopsided the underlying bezier handles are.
|
|
40921
|
+
|
|
40922
|
+
For arrowheads, `arrowhead()` returns the three triangle points capping a line at its tip; pass the arrival direction (any non-zero vector — it is normalized):
|
|
40923
|
+
|
|
40924
|
+
```ts
|
|
40925
|
+
import { arrowhead, pointOnBezier } from '@vielzeug/wire';
|
|
40926
|
+
|
|
40927
|
+
const tip = curve.to;
|
|
40928
|
+
const arriving = { x: tip.x - curve.c2.x, y: tip.y - curve.c2.y };
|
|
40929
|
+
const [apex, left, right] = arrowhead(tip, arriving, { length: 8, width: 5 });
|
|
40930
|
+
```
|
|
40931
|
+
|
|
40932
|
+
Two more routing-polish pieces round out editors:
|
|
40933
|
+
|
|
40934
|
+
- **`floatingSide(rect, toward)`** returns the rect side facing a point — the dominant axis from the rect center — so an edge can track the cursor across node sides without storing a fixed port side.
|
|
40935
|
+
- **`selfLoop: true` on `bezierRoute()`** widens both handles to `1.5 ×` the port spacing when the endpoints share a side, so an edge from a node's `out` port back to its own `in` port bulges into a visible loop instead of collapsing onto the node edge.
|
|
40936
|
+
|
|
40670
40937
|
## Ordering the Graph
|
|
40671
40938
|
|
|
40672
40939
|
`topologicalOrder()` returns node ids in dependency order. Ties break by position in the input array, so the same editor state always produces the same order:
|
|
@@ -40707,4 +40974,5 @@ A group is a _set_ of mutually reachable nodes, not a path through them — disp
|
|
|
40707
40974
|
|
|
40708
40975
|
### REPL Examples
|
|
40709
40976
|
|
|
40977
|
+
- edit - Arrowheads, arc-length t, hit testing (id: `wire-edit`)
|
|
40710
40978
|
- orthogonalRoute - Edges around nodes (id: `wire-routing`)
|
package/data/llms.txt
CHANGED
package/data/manifest.json
CHANGED