@weasel-js/labkit 1.4.0-pre.1 → 1.4.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 (120) hide show
  1. package/dist/_dts/{CanvasStackContext-LnCfqNBA.d.ts → CanvasStackContext-BIRUVVGH.d.ts} +1 -1
  2. package/dist/_dts/PrefsForm.d-CgxUequc.d.ts +20 -0
  3. package/dist/_dts/{frac-C-2c72Ij.d.ts → frac-X7mWgd7y.d.ts} +10 -4
  4. package/dist/_dts/{index-BDVzvRzQ.d.ts → index-FEa1MudK.d.ts} +8 -2
  5. package/dist/_dts/{types-DYMaEvM5.d.ts → types-ChVJJHvk.d.ts} +3 -0
  6. package/dist/_dts/{types-D6s4b7if.d.ts → types-lg4TSCb2.d.ts} +3 -1
  7. package/dist/_dts/{useTrialState-gmMvZqPc.d.ts → useTrialState-Cdm13fvl.d.ts} +2 -1
  8. package/dist/_dts/weasel-canvas-FJTFi3ZZ.d.ts +5041 -0
  9. package/dist/canvas/index.d.ts +16 -16
  10. package/dist/canvas/index.js +2 -2
  11. package/dist/chrome/index.d.ts +6 -6
  12. package/dist/chrome/index.js +5 -5
  13. package/dist/chunk-2YILQ7Y5.js +33 -0
  14. package/dist/chunk-2YILQ7Y5.js.map +1 -0
  15. package/dist/{chunk-TO2FUOKF.js → chunk-53AZ2O2N.js} +16 -13
  16. package/dist/chunk-53AZ2O2N.js.map +1 -0
  17. package/dist/{chunk-QB5SM4BM.js → chunk-7TRFMIWX.js} +55 -41
  18. package/dist/chunk-7TRFMIWX.js.map +1 -0
  19. package/dist/{chunk-6OEYTYML.js → chunk-BMQWLKOL.js} +15 -15
  20. package/dist/chunk-BMQWLKOL.js.map +1 -0
  21. package/dist/{chunk-M75ZU6ZZ.js → chunk-D7QIPGEB.js} +3 -3
  22. package/dist/{chunk-M75ZU6ZZ.js.map → chunk-D7QIPGEB.js.map} +1 -1
  23. package/dist/{chunk-L5QJOOLV.js → chunk-DG2IFMLA.js} +1309 -273
  24. package/dist/chunk-DG2IFMLA.js.map +1 -0
  25. package/dist/{chunk-LN6JDUGB.js → chunk-HXXTULDN.js} +2 -2
  26. package/dist/{chunk-LN6JDUGB.js.map → chunk-HXXTULDN.js.map} +1 -1
  27. package/dist/{chunk-RBGKL7NF.js → chunk-J6SBFZYT.js} +1807 -1814
  28. package/dist/chunk-J6SBFZYT.js.map +1 -0
  29. package/dist/{chunk-XJ6N32QP.js → chunk-LJSIUFYD.js} +14 -30
  30. package/dist/chunk-LJSIUFYD.js.map +1 -0
  31. package/dist/{chunk-AE5CNVRU.js → chunk-MIT3ISW4.js} +37 -31
  32. package/dist/chunk-MIT3ISW4.js.map +1 -0
  33. package/dist/{chunk-HHGVISVZ.js → chunk-MSR7EVS6.js} +7 -5
  34. package/dist/chunk-MSR7EVS6.js.map +1 -0
  35. package/dist/{chunk-ESIQNQ6K.js → chunk-OFCBEZMU.js} +12 -6
  36. package/dist/chunk-OFCBEZMU.js.map +1 -0
  37. package/dist/{chunk-HMFODCOX.js → chunk-PP7ZWAMV.js} +83 -75
  38. package/dist/chunk-PP7ZWAMV.js.map +1 -0
  39. package/dist/{chunk-E2UQVZ44.js → chunk-RLOXQZW3.js} +3 -3
  40. package/dist/{chunk-E2UQVZ44.js.map → chunk-RLOXQZW3.js.map} +1 -1
  41. package/dist/controls/index.d.ts +4 -3
  42. package/dist/controls/index.js +3 -3
  43. package/dist/dragdrop/index.d.ts +5 -5
  44. package/dist/dragdrop/index.js +2 -2
  45. package/dist/index.d.ts +57 -77
  46. package/dist/index.js +308 -161
  47. package/dist/index.js.map +1 -1
  48. package/dist/job/index.js +1 -1
  49. package/dist/layers/index.d.ts +6 -6
  50. package/dist/layers/index.js +3 -3
  51. package/dist/loupe/index.d.ts +7 -13
  52. package/dist/loupe/index.js +2 -2
  53. package/dist/passthrough/weasel-canvas.d.ts +3 -343
  54. package/dist/passthrough/weasel-canvas.js +1 -1
  55. package/dist/passthrough/weasel-ui.d.ts +141 -2866
  56. package/dist/passthrough/weasel-ui.js +2 -2
  57. package/dist/primitives/index.js +4 -4
  58. package/dist/state/index.d.ts +3 -3
  59. package/dist/state/index.js +4 -2
  60. package/dist/state/index.js.map +1 -1
  61. package/dist/styles.css +74 -5
  62. package/dist/surface/index.d.ts +17 -2
  63. package/dist/surface/index.js +3 -2
  64. package/dist/ui/layers/index.js +2 -2
  65. package/dist/undo/index.d.ts +6 -5
  66. package/package.json +8 -8
  67. package/src/annotations/AnnotationOverlay.tsx +10 -6
  68. package/src/annotations/Annotations.less +6 -0
  69. package/src/annotations/Annotations.overlay.test.tsx +113 -0
  70. package/src/annotations/MarkList.tsx +3 -2
  71. package/src/canvas/CanvasStack.tsx +8 -13
  72. package/src/canvas/useOrbit.test.ts +93 -1
  73. package/src/canvas/useOrbit.ts +41 -34
  74. package/src/canvas/usePanZoom.test.ts +102 -1
  75. package/src/canvas/usePanZoom.ts +54 -36
  76. package/src/config/builder.test.ts +5 -0
  77. package/src/config/builder.ts +6 -0
  78. package/src/config/types.ts +1 -0
  79. package/src/controls/ControlPanel.test.tsx +23 -0
  80. package/src/controls/ControlPanel.tsx +3 -0
  81. package/src/job/useJob.ts +1 -1
  82. package/src/lab/Lab.surface.test.tsx +8 -3
  83. package/src/lab/LabHeader.test.tsx +12 -0
  84. package/src/lab/LabHeader.tsx +16 -6
  85. package/src/lab/Workspace.tsx +1 -1
  86. package/src/layers/LayerList.test.tsx +72 -1
  87. package/src/layers/LayerList.tsx +40 -32
  88. package/src/passthrough/weasel-ui.test.ts +9 -0
  89. package/src/passthrough/weasel-ui.ts +4 -0
  90. package/src/primitives/FloatingPanel.test.tsx +82 -0
  91. package/src/primitives/FloatingPanel.tsx +59 -41
  92. package/src/primitives/ZoomControl.tsx +2 -0
  93. package/src/state/store.ts +10 -0
  94. package/src/state/types.ts +3 -0
  95. package/src/surface/AGENTS.md +11 -1
  96. package/src/surface/index.ts +7 -1
  97. package/src/surface/useSurfaceTile.ts +20 -2
  98. package/src/surface/useTiledSurface.ts +4 -1
  99. package/src/theme/Interstellar.stories.tsx +4 -3
  100. package/src/theme/base.less +39 -1
  101. package/src/trial/Trial.less +27 -5
  102. package/src/trial/TrialBody.test.tsx +67 -0
  103. package/src/trial/TrialBody.tsx +155 -0
  104. package/src/trial/TrialChrome.tsx +18 -10
  105. package/src/trial/index.ts +2 -0
  106. package/dist/_dts/DrawCommand-B3bskUsC.d.ts +0 -564
  107. package/dist/_dts/PrefsForm-BkUJZx0A.d.ts +0 -204
  108. package/dist/_dts/fitViewToBounds-dZ2UDB6e.d.ts +0 -21
  109. package/dist/_dts/shapeKinds-Cx_rxwsa.d.ts +0 -87
  110. package/dist/_dts/types-C-gh9Ap-.d.ts +0 -695
  111. package/dist/chunk-6OEYTYML.js.map +0 -1
  112. package/dist/chunk-AE5CNVRU.js.map +0 -1
  113. package/dist/chunk-ESIQNQ6K.js.map +0 -1
  114. package/dist/chunk-HHGVISVZ.js.map +0 -1
  115. package/dist/chunk-HMFODCOX.js.map +0 -1
  116. package/dist/chunk-L5QJOOLV.js.map +0 -1
  117. package/dist/chunk-QB5SM4BM.js.map +0 -1
  118. package/dist/chunk-RBGKL7NF.js.map +0 -1
  119. package/dist/chunk-TO2FUOKF.js.map +0 -1
  120. package/dist/chunk-XJ6N32QP.js.map +0 -1
@@ -1,564 +0,0 @@
1
- import { P as Path } from './types-C-gh9Ap-.js';
2
-
3
- /**
4
- * Viewport state. `(view.x, view.y)` is the **world point currently
5
- * rendered at the canvas top-left**; `view.scale.x` / `view.scale.y` is
6
- * pixels per world unit on each axis (default `{ x: 1, y: 1 }`). So:
7
- *
8
- * screenX = (worldX - view.x) * view.scale.x
9
- * screenY = (worldY - view.y) * view.scale.y
10
- * worldX = screenX / view.scale.x + view.x
11
- * worldY = screenY / view.scale.y + view.y
12
- *
13
- * `scale` is always a 2-vector. Input convenience types
14
- * {@link ZoomFactor} and {@link ZoomBound} let callers pass a scalar
15
- * when they want both axes treated the same.
16
- */
17
- interface View {
18
- x: number;
19
- y: number;
20
- scale: {
21
- x: number;
22
- y: number;
23
- };
24
- }
25
-
26
- /**
27
- * A registered texture, named by the registry that holds it.
28
- *
29
- * The handle is here rather than beside the registry because `FillStyle`'s
30
- * pattern variant names it, and paint is a leaf: the registry lives in the
31
- * renderer and imports this back.
32
- */
33
- interface TextureHandle {
34
- readonly id: string;
35
- }
36
-
37
- /**
38
- * FillStyle and Stroke types — the unified shape for "what color or texture
39
- * paints these pixels," modeled on SVG's paint-server concept.
40
- *
41
- * - `FillStyle` is a tagged union: solid color, pattern, or gradient. Used
42
- * wherever a kit option previously took `fillStyle: string`.
43
- * - `Stroke` pairs a `FillStyle` with structural stroke parameters (width, dash,
44
- * line cap/join, alignment).
45
- * - These types are consumed by the GL renderer's DrawCommand path fills
46
- * and strokes.
47
- *
48
- * The 2D `applyPaint` / `applyStroke` / `renderFilledRegion` helpers that
49
- * formerly lived alongside these types were deleted with the 2D backend in
50
- * Step 10. `alignedStrokeRect` survives as a pure geometry helper used by
51
- * path tessellation and the selection overlay.
52
- */
53
-
54
- /**
55
- * Color/texture strategy for fills (and, via `Stroke.paint`, strokes).
56
- *
57
- * `fill` is optional and defaults to `'solid'` — `{ color: '#abc' }` is
58
- * equivalent to `{ fill: 'solid', color: '#abc' }`. Pattern paints must set
59
- * `fill: 'pattern'` explicitly.
60
- *
61
- * The `'pattern'` variant's payload is either a `TilePatternSpec` — plain
62
- * data naming one of the built-in tiles, which survives serialization — or a
63
- * `TextureHandle` for a tile the consumer built itself via
64
- * `createTilePattern()`. A handle is a session-scoped registry key, so a
65
- * paint carrying one cannot be persisted or exported; prefer the spec.
66
- *
67
- * `units` on a pattern names the space the tile's origin and scale live in,
68
- * not the space of any geometry (a pattern has none). Under `'bounds'` the
69
- * tile anchors to the painted node's box, so the pattern travels with the
70
- * node and a resize reveals more tiles rather than stretching them;
71
- * `fillInPoseFrame` resolves that to a `'local'` paint with an explicit
72
- * `origin` before the renderer sees it.
73
- */
74
- type FillStyle = {
75
- fill?: 'solid';
76
- color: string;
77
- opacity?: number;
78
- } | {
79
- fill: 'pattern';
80
- pattern: TextureHandle | TilePatternSpec;
81
- units?: GradientUnits;
82
- origin?: {
83
- x: number;
84
- y: number;
85
- };
86
- opacity?: number;
87
- } | {
88
- fill: 'linear-gradient';
89
- from: {
90
- x: number;
91
- y: number;
92
- };
93
- to: {
94
- x: number;
95
- y: number;
96
- };
97
- stops: GradStop[];
98
- units?: GradientUnits;
99
- opacity?: number;
100
- } | {
101
- fill: 'radial-gradient';
102
- center: {
103
- x: number;
104
- y: number;
105
- };
106
- radius: number;
107
- stops: GradStop[];
108
- units?: GradientUnits;
109
- opacity?: number;
110
- } | {
111
- fill: 'conic-gradient';
112
- center: {
113
- x: number;
114
- y: number;
115
- };
116
- angle: number;
117
- stops: GradStop[];
118
- units?: GradientUnits;
119
- opacity?: number;
120
- };
121
- /**
122
- * Which coordinate space a gradient's geometry (`from`/`to`, `center`,
123
- * `radius`) is expressed in. SVG's `gradientUnits`, plus an option for
124
- * paints that are themselves viewport furniture.
125
- *
126
- * - `'bounds'`: fractions of the painted node's bounding box, `0..1` on each
127
- * axis — SVG `objectBoundingBox`. Resolved by the node painter, before the
128
- * renderer sees it, so the paint follows the node through moves, resizes
129
- * and rotation. What a gradient on a scene node wants.
130
- * - `'local'`: the coordinate space the geometry was handed to the renderer
131
- * in — the enclosing group's frame. For draw commands a consumer builds
132
- * itself, where "the coordinates I just wrote" is the useful frame.
133
- * - `'world'`: scene coordinates. The paint stays put under pan and zoom
134
- * while the geometry moves through it. SVG `userSpaceOnUse`. Requires the
135
- * renderer to have been handed a view matrix; falls back to `'screen'`
136
- * when it has not.
137
- * - `'screen'`: CSS pixels of the drawing surface. For overlays and
138
- * viewport-fixed washes that should not move with the content at all.
139
- *
140
- * Defaults to `'screen'`, which is the behavior every gradient had before
141
- * this field existed.
142
- */
143
- type GradientUnits = 'bounds' | 'local' | 'world' | 'screen';
144
- /**
145
- * A built-in tile, described as plain data. The serializable half of the
146
- * pattern paint: `resolvePatternSpec()` turns one into a `TextureHandle`
147
- * at paint time, memoized so identical specs share a texture.
148
- *
149
- * `size` is the tile's edge length, and doubles as its extent in paint
150
- * space — a bigger `size` rasterizes a bigger tile rather than magnifying
151
- * a small one, which is why there is no separate scale field.
152
- */
153
- interface TilePatternSpec {
154
- tile: 'hatch' | 'crosshatch' | 'dots' | 'chunks';
155
- color: string;
156
- /** `chunks` only — omit for a transparent tile background. */
157
- bg?: string;
158
- size?: number;
159
- /** `hatch` / `crosshatch`. */
160
- lineWidth?: number;
161
- /** `dots`. */
162
- radius?: number;
163
- /** `chunks`. */
164
- density?: number;
165
- chunkSize?: number;
166
- seed?: number;
167
- }
168
- /** A single color stop within a gradient. `offset` is in 0..1. */
169
- interface GradStop {
170
- offset: number;
171
- color: string;
172
- }
173
- /**
174
- * Where a stroke sits relative to the geometric edge it strokes.
175
- *
176
- * - `'center'` (default): canvas-native — half the stroke width sits inside
177
- * the geometry, half outside.
178
- * - `'inner'`: the entire stroke lies inside the geometry. The outer edge of
179
- * the stroke coincides with the geometric edge.
180
- * - `'outer'`: the entire stroke lies outside the geometry. The inner edge
181
- * of the stroke coincides with the geometric edge.
182
- *
183
- * Mirrors the (proposed) SVG `stroke-alignment` property. Honoring `inner`
184
- * or `outer` is the renderer's responsibility — for axis-aligned rects, the
185
- * kit shifts coordinates by `width / 2`. For arbitrary paths, renderers
186
- * typically use a stencil mask of the stroked path against the geometry.
187
- */
188
- type StrokeAlign = 'center' | 'inner' | 'outer';
189
- /**
190
- * The kit's built-in marker vocabulary, open on the string the way
191
- * `PaintKind` is so a consumer's registered key typechecks.
192
- */
193
- type KitMarkerKey = 'arrow' | 'arrow-open' | 'arrow-concave' | 'diamond' | 'diamond-hollow' | 'circle' | 'square' | 'bar';
194
- type MarkerKey = KitMarkerKey | (string & {});
195
- /**
196
- * A marker on one end (or every interior vertex) of a stroke.
197
- *
198
- * `size` reuses `Stroke.width`'s unit system: a bare number scales with the
199
- * resolved stroke width, `{ px }` pins screen pixels. That is SVG's
200
- * `markerUnits` in the idiom this codebase already resolves at draw time.
201
- * Omitted, the marker is one stroke width per unit.
202
- */
203
- type MarkerRef = MarkerKey | {
204
- key: MarkerKey;
205
- size?: number | {
206
- px: number;
207
- };
208
- };
209
- /** Stroke style: a FillStyle plus structural line parameters. */
210
- interface Stroke {
211
- paint: FillStyle;
212
- /** World units, or `{ px }` for screen pixels — resolved against the
213
- * accumulated transform scale at draw time, so it holds its on-screen
214
- * thickness as the view zooms. */
215
- width?: number | {
216
- px: number;
217
- };
218
- /** Per `CanvasRenderingContext2D.setLineDash` — empty/omitted = solid. */
219
- dash?: number[];
220
- /** Marker at the first vertex of each open subpath, rotated to point back
221
- * along the line (SVG's `auto-start-reverse`, as the only behavior). */
222
- markerStart?: MarkerRef;
223
- /** Marker at every interior authored vertex, on the bisector of the
224
- * incoming and outgoing directions. Never insets the stroke. */
225
- markerMid?: MarkerRef;
226
- /** Marker at the last vertex of each open subpath. */
227
- markerEnd?: MarkerRef;
228
- cap?: 'butt' | 'round' | 'square';
229
- join?: 'miter' | 'round' | 'bevel';
230
- /**
231
- * Miter join fallback threshold. When the miter length exceeds
232
- * `miterLimit * width / 2`, the join falls back to a bevel. Default 4,
233
- * matching SVG — which is also what the kit's own serializer implies when
234
- * it omits the attribute for an unset field. Canvas2D's 10 lets an acute
235
- * corner throw a spike four times the half-width.
236
- */
237
- miterLimit?: number;
238
- /** Where the stroke sits relative to the geometric edge. Default `'center'`. */
239
- align?: StrokeAlign;
240
- /**
241
- * Per-anchor RGBA, flat (length = 4 × countPathAnchors(path)). Each
242
- * value in 0..1. Arc-length interpolated across the tessellated ribbon
243
- * between consecutive anchors. When set, `paint` is still required —
244
- * its `opacity` (and color, as a placeholder) flow through the shader.
245
- */
246
- vertexColors?: number[];
247
- /**
248
- * Per-anchor stroke width (length = `countPathAnchors(path)`). When set,
249
- * the tessellator interpolates half-widths along each segment to produce
250
- * a tapered ribbon. `width` is used as the fallback for any anchor whose
251
- * entry is missing or non-finite. Pressure-driven pencil strokes use
252
- * this; pair with `pressureToWidth` to derive widths from stylus input.
253
- *
254
- * Joins between adjacent segments whose widths differ by more than
255
- * `varyingWidthJoinThreshold` (default 1.5×) are forced to bevel
256
- * regardless of the `join` setting — miter math is unstable when widths
257
- * vary across the corner; smooth round joins with mismatched widths
258
- * are a future enhancement.
259
- */
260
- vertexWidths?: number[];
261
- /**
262
- * Max width ratio (greater / lesser) at which a non-bevel join is
263
- * preserved when `vertexWidths` causes adjacent segments to differ.
264
- * Beyond this ratio the join falls back to bevel. Default 1.5. Ignored
265
- * when `vertexWidths` is absent.
266
- */
267
- varyingWidthJoinThreshold?: number;
268
- }
269
-
270
- /**
271
- * 2D affine matrix utilities. Column-major 9-element Float32Array, matching
272
- * `WebGL2RenderingContext.uniformMatrix3fv` byte order so we can pass the
273
- * array directly without a transpose flag.
274
- *
275
- * Layout (column-major):
276
- * [m00, m10, 0,
277
- * m01, m11, 0,
278
- * tx, ty, 1]
279
- *
280
- * `apply(m, x, y)` returns `[m * (x, y, 1)] = [m00*x + m01*y + tx,
281
- * m10*x + m11*y + ty]`.
282
- */
283
- type Mat3 = Float32Array;
284
-
285
- /**
286
- * Typography for `TextPose` and friends. Every field is optional; consumers
287
- * pass `{}` or override the few they care about. Defaults live in
288
- * `DEFAULT_TEXT_STYLE` and are applied at render/measure time, never written
289
- * back to the pose.
290
- *
291
- * Paint is not typography and does not live here. A text node carries its
292
- * fill and stroke in `data.fill` / `data.stroke`, the slots every other node
293
- * kind uses; `resolveTextStyle` takes them as its second argument and
294
- * `StyledRun.fill` / `.stroke` override them per range.
295
- */
296
-
297
- /**
298
- * Horizontal alignment. `start` / `end` resolve against the reading direction;
299
- * `left` / `right` are absolute. Same five values as CSS `text-align`, with
300
- * the same split between the relative pair and the absolute pair.
301
- */
302
- type TextAlign = 'left' | 'center' | 'right' | 'start' | 'end';
303
- /** Reading direction, which is what gives `start` / `end` their meaning. */
304
- type TextDirection = 'ltr' | 'rtl';
305
- /** User-facing text style. All fields optional; defaults applied at render time via `resolveTextStyle`. */
306
- interface TextStyle {
307
- /** Font size in world units. Default 16. */
308
- fontSize?: number;
309
- /** Default `'sans-serif'`. */
310
- fontFamily?: string;
311
- /** Default 400. */
312
- fontWeight?: number | string;
313
- /** Default `'normal'`. */
314
- fontStyle?: 'normal' | 'italic';
315
- /** Default `'left'`. Pass `'start'` to align by reading order instead. */
316
- align?: TextAlign;
317
- /** Reading direction, resolving `align: 'start' | 'end'`. Default `'ltr'`. */
318
- direction?: TextDirection;
319
- /** Multiplier applied to `fontSize`. Default 1.2. */
320
- lineHeight?: number;
321
- /**
322
- * Caret color used by the edit overlay. Defaults to the node's fill when
323
- * that fill is solid; falls back to `#000` for non-solid paints.
324
- */
325
- caretColor?: string;
326
- /**
327
- * Selection background color used by the edit overlay's `::selection`
328
- * pseudo-element. Defaults to a 25%-opacity tint of `caretColor` via CSS
329
- * `color-mix`. Pass `'none'` to fall back to the browser-native highlight.
330
- */
331
- selectionBackground?: string;
332
- /** Selection text color paired with `selectionBackground`. Default: inherits text color. */
333
- selectionColor?: string;
334
- /** Extra advance added after each glyph, in world units. Default 0. */
335
- letterSpacing?: number;
336
- /** Default `false`. */
337
- underline?: boolean;
338
- /** Default `false`. */
339
- strikethrough?: boolean;
340
- /** Default `false`. */
341
- overline?: boolean;
342
- }
343
-
344
- /**
345
- * Apply node-level `ResolvedTextStyle` defaults to each `StyledRun`,
346
- * producing a fully-resolved run with every styling field set. Downstream
347
- * layout and draw never re-resolve defaults — `ResolvedRun` is the
348
- * canonical shape the renderer consumes.
349
- *
350
- * `bold`/`italic` toggles on a run are folded into `fontWeight`/`fontStyle`:
351
- * `bold: true` → fontWeight 700, `italic: true` → fontStyle 'italic'.
352
- * Explicit `fontFamily` / `fontSize` / `fill` / `letterSpacing` on the run
353
- * override the node-level value (`letterSpacing: 0` on a run is an override,
354
- * not an absence — it zeroes inherited tracking).
355
- *
356
- * `underline` / `strikethrough` / `overline` are *additive*, like
357
- * `bold`/`italic`: a run can turn a decoration on but never off, so they
358
- * resolve as `run.x || style.x` and not `run.x ?? style.x`. See the header of
359
- * `runs/rangeStyle.ts` for why the model collapses the tri-state.
360
- *
361
- * `script` is folded the same way the toggles are, into the two primitives it
362
- * is a preset over: `baselineShift` and `fontScale`. Both come out as one
363
- * world-unit `baselineShift` and a final `fontSize`, so layout never learns
364
- * that superscripts exist — it places a run against a baseline and an offset.
365
- */
366
-
367
- /** A run with every style resolved against the node's text style — no
368
- * optional inheritance left. This is what layout and painting consume. */
369
- interface ResolvedRun {
370
- text: string;
371
- fontFamily: string;
372
- fontSize: number;
373
- fontWeight: number;
374
- fontStyle: 'normal' | 'italic';
375
- fill: FillStyle;
376
- /** Outline over this run's glyphs, or absent for none. Painted only on the
377
- * outline tier — a distance field has no geometry to stroke. */
378
- stroke?: Stroke;
379
- /** Extra advance added after each glyph of this run, in world units. */
380
- letterSpacing: number;
381
- /** Draw a rule below this run's baseline. Additive over the node style. */
382
- underline: boolean;
383
- /** Draw a rule through this run's x-height. Additive over the node style. */
384
- strikethrough: boolean;
385
- /** Draw a rule above this run's ascent. Additive over the node style. */
386
- overline: boolean;
387
- /**
388
- * How far this run sits off the line's shared baseline, in world units;
389
- * positive raises. 0 for ordinary text.
390
- *
391
- * Already multiplied out against the inherited font size, and already
392
- * carrying whatever `script` asked for — layout adds it to a baseline and
393
- * asks nothing about where it came from.
394
- */
395
- baselineShift: number;
396
- }
397
-
398
- /**
399
- * Box vertical alignment for text draw commands. Given the command's box
400
- * `height` and the laid-out text block's height, returns the Y offset to
401
- * apply to every quad. `'top'` (or an undefined `align`, or a missing box
402
- * `height`) is the legacy behavior: offset 0.
403
- */
404
- type TextVerticalAlign = 'top' | 'center' | 'bottom';
405
-
406
- /**
407
- * registerProgram — public API for registering custom shader programs.
408
- *
409
- * Stores raw GLSL source strings in a module-level registry. GL compilation
410
- * happens on each WeaselRenderer via WeaselRenderer.registerProgram(), which
411
- * calls getProgramSource() and compiles the result. This keeps registerProgram
412
- * GL-context-agnostic — identical pattern to registerFont storing ImageBitmap.
413
- *
414
- * Module-level state = source strings only; compiled GL
415
- * programs live on each renderer's programRegistry (Map<id, ShaderProgram>).
416
- *
417
- * Lifecycle: program sources live for the module lifetime. No unregister in v1.
418
- */
419
-
420
- /** Opaque handle to a compiled custom shader program. */
421
- interface ShaderProgramHandle {
422
- readonly id: string;
423
- }
424
- /**
425
- * Scalar and vector uniform types accepted by the custom shader uniform binder.
426
- *
427
- * | TS type | GL call |
428
- * |-------------------------|--------------------------------------|
429
- * | number | uniform1f |
430
- * | [n, n] | uniform2fv |
431
- * | [n, n, n] | uniform3fv |
432
- * | [n, n, n, n] | uniform4fv |
433
- * | Float32Array length 9 | uniformMatrix3fv (column-major) |
434
- * | Float32Array length 16 | uniformMatrix4fv (column-major) |
435
- * | TextureHandle | bind to next tex unit + uniform1i |
436
- */
437
- type ShaderUniform = number | [number, number] | [number, number, number] | [number, number, number, number] | Float32Array | TextureHandle;
438
-
439
- /** DrawCommand variants implemented through step 6. */
440
- type DrawCommand = PathDrawCommand | GroupDrawCommand | TextDrawCommand | ImageDrawCommand | ShaderDrawCommand;
441
- /** Draw a path, filled and/or stroked. The workhorse command: every shape the
442
- * kit draws that is not text, an image, or a custom shader is one of these. */
443
- interface PathDrawCommand {
444
- kind: 'path';
445
- path: Path;
446
- /** Any `FillStyle` variant: solid, pattern, or gradient (linear/radial/conic). */
447
- fill?: FillStyle;
448
- /** Stroke spec. Only solid `paint` supported through step 4. */
449
- stroke?: Stroke;
450
- /**
451
- * Optional flat RGBA-per-path-anchor color array (length =
452
- * `4 × countPathAnchors(path)`, floats in 0..1). The renderer
453
- * arc-length-interpolates these per-anchor colors across the
454
- * flattened/triangulated mesh between consecutive anchors using the
455
- * mesh's `anchorA` / `anchorB` / `anchorT` parameterization.
456
- *
457
- * **`fill` must also be set when using `vertexColors`.** The renderer
458
- * only enters the per-vertex shader path when the command has a fill
459
- * (the fill provides the opacity uniform; the vertex colors override
460
- * the fill's color). Pass any solid `fill` (e.g. `{ color: '#fff' }`)
461
- * as the placeholder; the per-vertex colors win in the shader.
462
- */
463
- vertexColors?: number[];
464
- }
465
- /** Draw a list of commands under a shared transform, opacity, color matrix
466
- * and clip. Groups nest, and their effects accumulate down the stack — this
467
- * is how a container node's transform reaches its descendants. */
468
- interface GroupDrawCommand {
469
- kind: 'group';
470
- transform?: Mat3;
471
- alpha?: number;
472
- /**
473
- * Optional 4×5 color matrix (row-major, 20 numbers) — `out = M₄ₓ₄ * in + bias`.
474
- * Accumulated multiplicatively down the group stack. Defaults to identity.
475
- */
476
- colorMatrix?: number[];
477
- /** Optional clip path. When set, the renderer rasterizes this path into
478
- * the stencil buffer before drawing `children`; the children paint only
479
- * where the clip covers. Nested groups with clips intersect — a child
480
- * cannot escape an ancestor's clip. Max 7 nesting levels; the renderer
481
- * throws if exceeded. */
482
- clip?: Path;
483
- children: DrawCommand[];
484
- }
485
- /**
486
- * Text draw command. Renders one or more runs at (`x`, `y`) in screen
487
- * space, optionally word-wrapping at `maxWidth`. The renderer resolves
488
- * each run's `(fontFamily, fontWeight, fontStyle)` to an MSDF atlas via
489
- * `resolveFontVariant` and bucket-draws by atlas + color group.
490
- *
491
- * `style` carries node-level defaults (`lineHeight`, anti-alias width)
492
- * that don't belong on individual runs.
493
- */
494
- interface TextDrawCommand {
495
- kind: 'text';
496
- x: number;
497
- y: number;
498
- runs: ResolvedRun[];
499
- maxWidth?: number;
500
- align?: 'left' | 'center' | 'right';
501
- style: TextStyle;
502
- /** Box height for vertical alignment. When set with `verticalAlign`,
503
- * the laid-out block shifts within `[y, y+height]`. */
504
- height?: number;
505
- /** Default 'top' — the legacy top-anchored behavior. */
506
- verticalAlign?: TextVerticalAlign;
507
- }
508
- /**
509
- * Image draw command — renders `image` at screen-space rect (x, y, w, h).
510
- * The image is stretched to fit; no tiling. Use a pattern FillStyle on a path
511
- * for tiling.
512
- */
513
- interface ImageDrawCommand {
514
- kind: 'image';
515
- image: ImageBitmap;
516
- x: number;
517
- y: number;
518
- w: number;
519
- h: number;
520
- opacity?: number;
521
- /** Magnification filter. `'linear'` (default) smooths; `'nearest'` shows
522
- * device pixels as hard squares — required by anything magnifying a
523
- * framebuffer readback, where blur destroys the point of the readback. */
524
- sampling?: 'linear' | 'nearest';
525
- /** Sub-rectangle of `image` to draw, in bitmap pixels from the top-left.
526
- * Omitted draws the whole bitmap. Not range-checked: a rect past the edge
527
- * samples outside [0..1], which CLAMP_TO_EDGE smears. With
528
- * `sampling: 'linear'` the filter reaches half a texel beyond `source`, so
529
- * atlas frames need a gutter (see `SpriteSheet.spacing`) or `'nearest'`. */
530
- source?: {
531
- x: number;
532
- y: number;
533
- w: number;
534
- h: number;
535
- };
536
- /** Mirror the sampled region within the destination rect. The quad does not
537
- * move — a flipped draw covers exactly the pixels an unflipped one does. */
538
- flipX?: boolean;
539
- flipY?: boolean;
540
- }
541
- /**
542
- * Custom shader draw command. The renderer generates a quad over `bounds`
543
- * and dispatches the consumer's fragment shader with the kit's vertex prelude.
544
- *
545
- * `uniforms` keys must match names declared in the consumer's fragment shader.
546
- * The kit automatically sets `u_bounds`, `u_view`, and `u_proj` — do not
547
- * declare those in `uniforms`.
548
- *
549
- * @experimental API may change before v2.
550
- */
551
- interface ShaderDrawCommand {
552
- kind: 'shader';
553
- program: ShaderProgramHandle;
554
- uniforms: Record<string, ShaderUniform>;
555
- /** Screen-space bounding rect in CSS pixels. */
556
- bounds: {
557
- x: number;
558
- y: number;
559
- w: number;
560
- h: number;
561
- };
562
- }
563
-
564
- export type { DrawCommand as D, FillStyle as F, PathDrawCommand as P, Stroke as S, TextStyle as T, View as V };