@weasel-js/core 0.5.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 +381 -0
- package/LICENSE +21 -0
- package/README.md +144 -0
- package/dist/DrawCommand-Dl0bXNfS.d.ts +500 -0
- package/dist/chunk-775XXAHR.js +216 -0
- package/dist/chunk-775XXAHR.js.map +1 -0
- package/dist/chunk-7V6JEOXE.js +27754 -0
- package/dist/chunk-7V6JEOXE.js.map +1 -0
- package/dist/chunk-AM6ARSPN.js +517 -0
- package/dist/chunk-AM6ARSPN.js.map +1 -0
- package/dist/chunk-BGGZ4CVF.js +248 -0
- package/dist/chunk-BGGZ4CVF.js.map +1 -0
- package/dist/chunk-BHVYVFGV.js +29 -0
- package/dist/chunk-BHVYVFGV.js.map +1 -0
- package/dist/chunk-CQNKCG34.js +831 -0
- package/dist/chunk-CQNKCG34.js.map +1 -0
- package/dist/chunk-GVCNT7UH.js +47 -0
- package/dist/chunk-GVCNT7UH.js.map +1 -0
- package/dist/chunk-PZ5AY32C.js +9 -0
- package/dist/chunk-PZ5AY32C.js.map +1 -0
- package/dist/chunk-UGFFCMQP.js +28 -0
- package/dist/chunk-UGFFCMQP.js.map +1 -0
- package/dist/chunk-VOVKONXA.js +103 -0
- package/dist/chunk-VOVKONXA.js.map +1 -0
- package/dist/chunk-Y52N27PF.js +39 -0
- package/dist/chunk-Y52N27PF.js.map +1 -0
- package/dist/clipboard.d.ts +91 -0
- package/dist/clipboard.js +6 -0
- package/dist/clipboard.js.map +1 -0
- package/dist/clone.d.ts +8 -0
- package/dist/clone.js +6 -0
- package/dist/clone.js.map +1 -0
- package/dist/fitViewToBounds-evGsnR8Q.d.ts +62 -0
- package/dist/grid-Cf87knjU.d.ts +153 -0
- package/dist/index-DZBYMsHI.d.ts +1555 -0
- package/dist/index.css +121 -0
- package/dist/index.css.map +1 -0
- package/dist/index.d.ts +10200 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/insert.d.ts +33 -0
- package/dist/insert.js +81 -0
- package/dist/insert.js.map +1 -0
- package/dist/move.d.ts +69 -0
- package/dist/move.js +145 -0
- package/dist/move.js.map +1 -0
- package/dist/options-BPPBWMa7.d.ts +64 -0
- package/dist/patterns-builtin.d.ts +55 -0
- package/dist/patterns-builtin.js +100 -0
- package/dist/patterns-builtin.js.map +1 -0
- package/dist/pointSnapToGrid-D7s7QmOF.d.ts +185 -0
- package/dist/registerFont-CP-wCsrz.d.ts +109 -0
- package/dist/registerTexture-BzHTLhD9.d.ts +25 -0
- package/dist/renderer.css +121 -0
- package/dist/renderer.css.map +1 -0
- package/dist/renderer.d.ts +376 -0
- package/dist/renderer.js +13 -0
- package/dist/renderer.js.map +1 -0
- package/dist/resize.d.ts +78 -0
- package/dist/resize.js +5 -0
- package/dist/resize.js.map +1 -0
- package/dist/routing.css +35 -0
- package/dist/routing.css.map +1 -0
- package/dist/routing.d.ts +14 -0
- package/dist/routing.js +4 -0
- package/dist/routing.js.map +1 -0
- package/dist/types-B6MMiodD.d.ts +59 -0
- package/dist/types-BJ8_cyT7.d.ts +130 -0
- package/dist/types-B_-khFM0.d.ts +331 -0
- package/dist/types-BjUi2vA-.d.ts +355 -0
- package/dist/types-Cpb4hii1.d.ts +445 -0
- package/dist/types-D2tTKEU0.d.ts +18 -0
- package/dist/view-DSQgxBJB.d.ts +63 -0
- package/package.json +96 -0
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
import { I as ImageMinification, G as GLImageCache } from './registerFont-CP-wCsrz.js';
|
|
2
|
+
export { V as ViewLike, i as isCanvasFont, r as registerCanvasFont, a as registerFont, s as subscribeGlyphReady, u as unregisterCanvasFont, v as viewToMat3 } from './registerFont-CP-wCsrz.js';
|
|
3
|
+
import { G as GradStop, M as Mat3, S as ShaderProgramHandle, D as DrawCommand, a as Stroke } from './DrawCommand-Dl0bXNfS.js';
|
|
4
|
+
export { b as GroupDrawCommand, I as ImageDrawCommand, P as PathDrawCommand, c as ShaderDrawCommand, d as ShaderUniform, e as SolidPaint, T as TextDrawCommand, m as mat3, r as registerProgram } from './DrawCommand-Dl0bXNfS.js';
|
|
5
|
+
import { P as Path } from './types-B6MMiodD.js';
|
|
6
|
+
export { T as TextureHandle, r as registerTexture } from './registerTexture-BzHTLhD9.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Minimal compile/link/lookup wrapper for a GL program. Throws
|
|
10
|
+
* `ShaderCompileError` on compile or link failure with the GL info log
|
|
11
|
+
* embedded in the error message — never returns a half-initialized program.
|
|
12
|
+
*
|
|
13
|
+
* Designed so test code can stub `getShaderParameter` / `getProgramParameter`
|
|
14
|
+
* via the recorder Proxy without further special-casing.
|
|
15
|
+
*/
|
|
16
|
+
type Stage = 'vertex' | 'fragment' | 'link';
|
|
17
|
+
declare class ShaderCompileError extends Error {
|
|
18
|
+
readonly stage: Stage;
|
|
19
|
+
readonly log: string;
|
|
20
|
+
constructor(stage: Stage, log: string);
|
|
21
|
+
}
|
|
22
|
+
declare class ShaderProgram {
|
|
23
|
+
private readonly gl;
|
|
24
|
+
readonly handle: WebGLProgram;
|
|
25
|
+
private readonly uniforms;
|
|
26
|
+
private readonly attributes;
|
|
27
|
+
constructor(gl: WebGL2RenderingContext, vertSrc: string, fragSrc: string);
|
|
28
|
+
private compile;
|
|
29
|
+
lookupUniforms(names: readonly string[]): void;
|
|
30
|
+
lookupAttributes(names: readonly string[]): void;
|
|
31
|
+
uniform(name: string): WebGLUniformLocation | undefined;
|
|
32
|
+
attribute(name: string): number | undefined;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* A tessellated representation of a Path, ready to upload to GL.
|
|
37
|
+
*
|
|
38
|
+
* - `vertices` is interleaved x,y in path-local coordinates (`Float32Array`
|
|
39
|
+
* of length `2 * vertexCount`).
|
|
40
|
+
* - `indices` are triangle indices into `vertices` (`Uint32Array`, length
|
|
41
|
+
* `3 * triangleCount`).
|
|
42
|
+
* - `requiresStencil` is set for paths whose fillRule is `'evenodd'` and
|
|
43
|
+
* whose triangulation is a *naive* per-contour fan rather than a clean
|
|
44
|
+
* inside/outside triangulation. The renderer must use a stencil
|
|
45
|
+
* two-pass when this flag is true. Single-contour paths and `'nonzero'`
|
|
46
|
+
* multi-contour paths leave it false.
|
|
47
|
+
* - `anchorA` / `anchorB` / `anchorT` parameterize each mesh vertex by
|
|
48
|
+
* the two consecutive path anchors it lies between and the arc-length
|
|
49
|
+
* fraction along that segment (0 = at A, 1 = at B). Vertices that fall
|
|
50
|
+
* exactly on an anchor set A === B and t = 0. Used at draw time when
|
|
51
|
+
* the DrawCommand supplies per-anchor colors so the renderer can lerp
|
|
52
|
+
* per mesh vertex. Optional — emitted by the path tessellators; absent
|
|
53
|
+
* on meshes built by other paths (e.g. text glyphs).
|
|
54
|
+
*/
|
|
55
|
+
interface Mesh {
|
|
56
|
+
readonly vertices: Float32Array;
|
|
57
|
+
readonly indices: Uint32Array;
|
|
58
|
+
readonly requiresStencil?: boolean;
|
|
59
|
+
readonly anchorA?: Uint32Array;
|
|
60
|
+
readonly anchorB?: Uint32Array;
|
|
61
|
+
readonly anchorT?: Float32Array;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
interface GLMeshHandle {
|
|
65
|
+
readonly vao: WebGLVertexArrayObject;
|
|
66
|
+
readonly indexCount: number;
|
|
67
|
+
readonly requiresStencil: boolean;
|
|
68
|
+
readonly anchorA?: Uint32Array;
|
|
69
|
+
readonly anchorB?: Uint32Array;
|
|
70
|
+
readonly anchorT?: Float32Array;
|
|
71
|
+
}
|
|
72
|
+
/** Resources to release when a Mesh is reclaimed by GC. */
|
|
73
|
+
interface MeshResources {
|
|
74
|
+
vao: WebGLVertexArrayObject;
|
|
75
|
+
vbo: WebGLBuffer;
|
|
76
|
+
ibo: WebGLBuffer;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Caches GL-side buffers + VAO per `Mesh` identity. Upload happens lazily
|
|
80
|
+
* on first `handleFor(mesh)` call.
|
|
81
|
+
*
|
|
82
|
+
* **GC-aware cleanup (deferred-delete queue):** when a Mesh becomes
|
|
83
|
+
* unreachable, the WeakMap entry is dropped automatically — but the
|
|
84
|
+
* underlying GL resources (VAO, VBO, IBO) would leak forever without an
|
|
85
|
+
* explicit `gl.delete*` call. We register each Mesh with a
|
|
86
|
+
* `FinalizationRegistry`; when the Mesh is reclaimed, the finalizer pushes
|
|
87
|
+
* the resources onto an internal queue. The renderer drains this queue at
|
|
88
|
+
* the start of each `render()` call (via `drainPendingDeletes()`), when GL
|
|
89
|
+
* is in a known state — no VAO bound, no draw mid-flight. Deleting from the
|
|
90
|
+
* finalizer directly was racy (it could fire between two `gl.bindVertexArray`
|
|
91
|
+
* calls inside `dispatch()`, sometimes corrupting the next draw); deferring
|
|
92
|
+
* the actual delete to a known-safe point keeps the use-after-free risk to
|
|
93
|
+
* zero.
|
|
94
|
+
*
|
|
95
|
+
* Caveats:
|
|
96
|
+
* - Finalizer timing is non-deterministic; resources may live for a frame
|
|
97
|
+
* or two beyond their Mesh, but they will be reclaimed.
|
|
98
|
+
* - If the GL context is lost between finalizer and drain, the drain
|
|
99
|
+
* no-ops safely (`gl.isContextLost()` makes deletes no-ops, and
|
|
100
|
+
* `gl.deleteBuffer(null)` is allowed).
|
|
101
|
+
*
|
|
102
|
+
* The cache is GL-context-bound; if the context is lost and re-created, the
|
|
103
|
+
* renderer should construct a new GLMeshCache. (Context loss handling lives
|
|
104
|
+
* in `WeaselRenderer`.)
|
|
105
|
+
*/
|
|
106
|
+
declare class GLMeshCache {
|
|
107
|
+
private readonly gl;
|
|
108
|
+
private readonly aPositionLoc;
|
|
109
|
+
private readonly map;
|
|
110
|
+
private readonly finalizer;
|
|
111
|
+
private readonly pendingDeletes;
|
|
112
|
+
/** Transient resources allocated this frame; freed at end of render(). */
|
|
113
|
+
private readonly transientThisFrame;
|
|
114
|
+
constructor(gl: WebGL2RenderingContext, aPositionLoc: number);
|
|
115
|
+
handleFor(mesh: Mesh): GLMeshHandle;
|
|
116
|
+
/**
|
|
117
|
+
* Upload a Mesh that the caller knows is single-use (e.g. the per-frame
|
|
118
|
+
* stroke ribbon from `tessellateStroke`). Returns a handle backed by fresh
|
|
119
|
+
* GL resources that the renderer will free deterministically at the end
|
|
120
|
+
* of the current frame via `freeTransient()`. Bypasses the WeakMap cache
|
|
121
|
+
* and the FinalizationRegistry, so transient meshes never wait on GC.
|
|
122
|
+
*/
|
|
123
|
+
uploadTransient(mesh: Mesh): GLMeshHandle;
|
|
124
|
+
/**
|
|
125
|
+
* Free all transient resources allocated since the last call. Called by
|
|
126
|
+
* the renderer at the end of each `render()`. Safe under context loss.
|
|
127
|
+
*/
|
|
128
|
+
freeTransient(): void;
|
|
129
|
+
/** @internal — for tests asserting the transient-list size. */
|
|
130
|
+
_transientCount(): number;
|
|
131
|
+
/**
|
|
132
|
+
* Free GL resources whose Mesh has been GC'd since the last drain.
|
|
133
|
+
* Called by the renderer at the top of each `render()`, before any draws.
|
|
134
|
+
*/
|
|
135
|
+
drainPendingDeletes(): void;
|
|
136
|
+
/** @internal — for tests asserting the queue size. */
|
|
137
|
+
_pendingDeleteCount(): number;
|
|
138
|
+
/** @internal — for tests that need to simulate the finalizer firing. */
|
|
139
|
+
_enqueueDeleteForTest(resources: MeshResources): void;
|
|
140
|
+
private upload;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* GL texture upload + cache for MSDF font atlases (and future images).
|
|
145
|
+
*
|
|
146
|
+
* Textures are keyed by a string id (the font family name or image id).
|
|
147
|
+
* Upload happens once; subsequent uploads for the same id are no-ops.
|
|
148
|
+
* The cache is GL-context-bound; discard and create a new one on context loss.
|
|
149
|
+
*
|
|
150
|
+
* Atlas format: RGBA UNSIGNED_BYTE, linear filtering, no mipmaps.
|
|
151
|
+
* Mipmap generation is deliberately skipped — MSDF works correctly with
|
|
152
|
+
* linear filtering, and mipmap resampling corrupts the multi-channel SDF signal.
|
|
153
|
+
*/
|
|
154
|
+
type TexSource = HTMLImageElement | ImageBitmap | ImageData | HTMLCanvasElement;
|
|
155
|
+
declare class GLTextureCache {
|
|
156
|
+
private readonly gl;
|
|
157
|
+
private readonly map;
|
|
158
|
+
constructor(gl: WebGL2RenderingContext);
|
|
159
|
+
has(id: string): boolean;
|
|
160
|
+
upload(id: string, source: TexSource): string;
|
|
161
|
+
/** Create a single-channel R8 texture from raw bytes (full upload).
|
|
162
|
+
* No-op if `id` already exists. Same LINEAR/CLAMP params as `upload`;
|
|
163
|
+
* UNPACK_ALIGNMENT dropped to 1 for non-4-aligned row widths. */
|
|
164
|
+
uploadR8(id: string, width: number, height: number, data: Uint8Array): void;
|
|
165
|
+
/** Patch a rect of an existing R8 texture with tightly-packed w×h bytes. */
|
|
166
|
+
subImageR8(id: string, x: number, y: number, w: number, h: number, data: Uint8Array): void;
|
|
167
|
+
bind(id: string, unit: number): void;
|
|
168
|
+
/**
|
|
169
|
+
* Delete every uploaded GL texture and clear the map. Called by
|
|
170
|
+
* `WeaselRenderer.dispose()`. The cache is unusable but refillable
|
|
171
|
+
* afterward — a subsequent `upload()` for a previously-seen id re-creates
|
|
172
|
+
* the texture rather than restoring the deleted one.
|
|
173
|
+
*/
|
|
174
|
+
free(): void;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* CPU gradient-ramp builder + GL 1×256 RGBA texture cache.
|
|
179
|
+
*
|
|
180
|
+
* Each unique stop list is uploaded once. Key = JSON.stringify(stops).
|
|
181
|
+
* The cache is GL-context-bound; discard and recreate on context loss.
|
|
182
|
+
*
|
|
183
|
+
* Output convention §2: texels are stored as straight RGBA. The fragment
|
|
184
|
+
* shader applies premultiplication before writing outColor.
|
|
185
|
+
*/
|
|
186
|
+
|
|
187
|
+
declare function buildGradientRamp(stops: GradStop[]): Uint8ClampedArray;
|
|
188
|
+
declare class GradientRampCache {
|
|
189
|
+
private readonly gl;
|
|
190
|
+
private readonly map;
|
|
191
|
+
private totalQueries;
|
|
192
|
+
private cacheHits;
|
|
193
|
+
constructor(gl: WebGL2RenderingContext);
|
|
194
|
+
upload(stops: GradStop[]): string;
|
|
195
|
+
bind(key: string, unit: number): void;
|
|
196
|
+
hitRate(): number;
|
|
197
|
+
resetStats(): void;
|
|
198
|
+
/**
|
|
199
|
+
* Delete every uploaded GL ramp texture and clear the map. Called by
|
|
200
|
+
* `WeaselRenderer.dispose()`. Only the GL textures are owned resources —
|
|
201
|
+
* `buildGradientRamp`'s CPU-side `Uint8ClampedArray` is transient per
|
|
202
|
+
* `upload()` call and already gone by the time a ramp is cached. The
|
|
203
|
+
* cache is unusable but refillable afterward (stats are left as-is; call
|
|
204
|
+
* `resetStats()` separately if desired).
|
|
205
|
+
*/
|
|
206
|
+
free(): void;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** Row-major 4×5 color matrix identity. */
|
|
210
|
+
declare const IDENTITY_COLOR_MATRIX: Float32Array<ArrayBuffer>;
|
|
211
|
+
interface GroupFrame {
|
|
212
|
+
transform?: Mat3;
|
|
213
|
+
alpha?: number;
|
|
214
|
+
/** Row-major 4×5 color matrix (20 floats). Absent leaves the stack unchanged. */
|
|
215
|
+
colorMatrix?: Float32Array | number[];
|
|
216
|
+
}
|
|
217
|
+
declare class GroupState {
|
|
218
|
+
private transformStack;
|
|
219
|
+
private alphaStack;
|
|
220
|
+
private colorMatrixStack;
|
|
221
|
+
get transform(): Mat3;
|
|
222
|
+
get alpha(): number;
|
|
223
|
+
get colorMatrix(): Float32Array;
|
|
224
|
+
push(frame: GroupFrame): void;
|
|
225
|
+
pop(): void;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
interface WeaselRendererOptions {
|
|
229
|
+
gl?: WebGL2RenderingContext;
|
|
230
|
+
canvas?: HTMLCanvasElement;
|
|
231
|
+
width: number;
|
|
232
|
+
height: number;
|
|
233
|
+
dpr: number;
|
|
234
|
+
/** MIN_FILTER strategy for image/pattern textures (`GLImageCache`).
|
|
235
|
+
* Default `'linear'` — the existing screen behavior. The headless
|
|
236
|
+
* `renderSceneToPixels` path passes `'mipmap'` for print-quality
|
|
237
|
+
* minification. Explicitly passing `'linear'` is always valid. */
|
|
238
|
+
imageMinification?: ImageMinification;
|
|
239
|
+
/** Flatness tolerance for curve tessellation, in WORLD units (see
|
|
240
|
+
* `TessellateOptions.flattenTolerance`). When set, path fills are
|
|
241
|
+
* tessellated fresh at this tolerance per frame (transient pool) instead
|
|
242
|
+
* of served from the Path-identity mesh cache — the cache key does not
|
|
243
|
+
* include tolerance. Default: unset — the existing cached behavior at
|
|
244
|
+
* `DEFAULT_FLATTEN_TOLERANCE`. The headless path derives this from the
|
|
245
|
+
* requested output scale; screen callers normally leave it unset. */
|
|
246
|
+
flattenTolerance?: number;
|
|
247
|
+
/** Per-render synchronous bake budget for dynamic canvas-SDF glyphs.
|
|
248
|
+
* Default DEFAULT_BAKE_BUDGET (16). The headless renderSceneToPixels
|
|
249
|
+
* path passes Infinity so print never defers a glyph. */
|
|
250
|
+
bakeBudget?: number;
|
|
251
|
+
}
|
|
252
|
+
declare class WeaselRenderer {
|
|
253
|
+
private readonly gl;
|
|
254
|
+
private pathFill;
|
|
255
|
+
private pathFillVColor;
|
|
256
|
+
private textSdf;
|
|
257
|
+
private textSdfR8;
|
|
258
|
+
private imageFill;
|
|
259
|
+
private gradFill;
|
|
260
|
+
private meshCache;
|
|
261
|
+
private textureCache;
|
|
262
|
+
private imageCache;
|
|
263
|
+
private gradRampCache;
|
|
264
|
+
private programRegistry;
|
|
265
|
+
private quadVbo;
|
|
266
|
+
private quadIbo;
|
|
267
|
+
/** Shared rect-fill geometry: 4 verts × 2 floats (dynamic), 6-index static IBO. */
|
|
268
|
+
private rectVao;
|
|
269
|
+
private rectVbo;
|
|
270
|
+
private rectIbo;
|
|
271
|
+
private readonly groupState;
|
|
272
|
+
private widthCss;
|
|
273
|
+
private heightCss;
|
|
274
|
+
private dpr;
|
|
275
|
+
private canvas;
|
|
276
|
+
private readonly imageMinification;
|
|
277
|
+
private readonly flattenTolerance?;
|
|
278
|
+
private readonly bakeBudget;
|
|
279
|
+
private contextLost;
|
|
280
|
+
private boundOnLost;
|
|
281
|
+
private boundOnRestored;
|
|
282
|
+
/** True after `dispose()`. A disposed renderer ignores further `render()`
|
|
283
|
+
* calls and `registerProgram()` calls. */
|
|
284
|
+
private disposed;
|
|
285
|
+
constructor(opts: WeaselRendererOptions);
|
|
286
|
+
/** Allocate the shared rect VAO + dynamic VBO (4 verts × 2 floats) + static
|
|
287
|
+
* IBO (6 indices). drawRectFast bufferSubData's the 4 corner coords each
|
|
288
|
+
* draw, avoiding per-rect buffer allocation in animated demos. */
|
|
289
|
+
private uploadRectGeometry;
|
|
290
|
+
private uploadQuadGeometry;
|
|
291
|
+
/**
|
|
292
|
+
* Compile a consumer-registered shader program against this renderer's GL context.
|
|
293
|
+
*
|
|
294
|
+
* Call once per renderer after the module-level `registerProgram()`.
|
|
295
|
+
* Throws `ShaderCompileError` if compilation fails.
|
|
296
|
+
*
|
|
297
|
+
* In dev mode, calling again with the same handle replaces the compiled program.
|
|
298
|
+
*
|
|
299
|
+
* @experimental
|
|
300
|
+
*/
|
|
301
|
+
registerProgram(handle: ShaderProgramHandle): void;
|
|
302
|
+
private applyViewport;
|
|
303
|
+
isContextLost(): boolean;
|
|
304
|
+
private onContextLost;
|
|
305
|
+
private onContextRestored;
|
|
306
|
+
/** Free the GL resources this renderer itself owns and detach context-loss
|
|
307
|
+
* listeners when a canvas was supplied. Idempotent.
|
|
308
|
+
*
|
|
309
|
+
* Scope: built-in shader programs, any consumer-registered programs, the
|
|
310
|
+
* shared quad/rect geometry, any in-flight transient meshes, and the
|
|
311
|
+
* enumerable Map-keyed caches (`GLTextureCache` atlas/image textures,
|
|
312
|
+
* `GradientRampCache` ramp textures) ARE freed.
|
|
313
|
+
*
|
|
314
|
+
* NOT freed: `GLImageCache` (bitmap/pattern textures) and `GLMeshCache`'s
|
|
315
|
+
* persistent per-Path mesh cache are keyed by `WeakMap`, not enumerable,
|
|
316
|
+
* and are only reclaimed when the GL context itself goes away (cf.
|
|
317
|
+
* `GLImageCache`'s own "deferred to v2" note). On a caller-owned
|
|
318
|
+
* long-lived context — the headless render-to-pixels path hands the same
|
|
319
|
+
* `gl` to many short-lived renderers — the image/pattern textures and
|
|
320
|
+
* persistent Path meshes each renderer uploads DO accumulate across
|
|
321
|
+
* renderer instances until the caller recycles the context.
|
|
322
|
+
*
|
|
323
|
+
* Also: a Mesh that gets GC'd after `dispose()` still lands in
|
|
324
|
+
* `GLMeshCache`'s `pendingDeletes` queue via its `FinalizationRegistry`,
|
|
325
|
+
* but nothing drains that queue post-dispose (only `render()` does) —
|
|
326
|
+
* those GL resources leak until the context goes away too.
|
|
327
|
+
*
|
|
328
|
+
* A disposed renderer ignores further `render()` and `registerProgram()`
|
|
329
|
+
* calls. */
|
|
330
|
+
dispose(): void;
|
|
331
|
+
render(commands: DrawCommand[]): void;
|
|
332
|
+
resize(dims: {
|
|
333
|
+
width: number;
|
|
334
|
+
height: number;
|
|
335
|
+
dpr: number;
|
|
336
|
+
}): void;
|
|
337
|
+
/** @internal */ _gl(): WebGL2RenderingContext;
|
|
338
|
+
/** @internal */ _pathFill(): ShaderProgram;
|
|
339
|
+
/** @internal */ _pathFillVColor(): ShaderProgram;
|
|
340
|
+
/** @internal */ _textSdf(): ShaderProgram;
|
|
341
|
+
/** @internal */ _textSdfR8(): ShaderProgram;
|
|
342
|
+
/** @internal */ _imageFill(): ShaderProgram;
|
|
343
|
+
/** @internal */ _gradFill(): ShaderProgram;
|
|
344
|
+
/** @internal */ _meshCache(): GLMeshCache;
|
|
345
|
+
/** @internal */ _textureCache(): GLTextureCache;
|
|
346
|
+
/** @internal */ _imageCache(): GLImageCache;
|
|
347
|
+
/** @internal */ _gradRampCache(): GradientRampCache;
|
|
348
|
+
/** @internal */ _groupState(): GroupState;
|
|
349
|
+
/** @internal */ _widthCss(): number;
|
|
350
|
+
/** @internal */ _heightCss(): number;
|
|
351
|
+
/** @internal */ _dpr(): number;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
interface TessellateOptions {
|
|
355
|
+
/** Flatness tolerance for bezier subdivision in path-local units. */
|
|
356
|
+
flattenTolerance?: number;
|
|
357
|
+
}
|
|
358
|
+
declare function tessellate(path: Path, opts?: TessellateOptions): Mesh;
|
|
359
|
+
|
|
360
|
+
interface StrokeOptions {
|
|
361
|
+
flattenTolerance?: number;
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Build a triangle-mesh ribbon from a stroked Path.
|
|
365
|
+
*
|
|
366
|
+
* Supports:
|
|
367
|
+
* - cap: 'butt' | 'round' | 'square'
|
|
368
|
+
* - join: 'miter' | 'round' | 'bevel'
|
|
369
|
+
* - center alignment directly; RectPath inner/outer alignment via a
|
|
370
|
+
* pre-shifted rect; PolygonPath inner/outer alignment via stencil at the
|
|
371
|
+
* renderer level
|
|
372
|
+
* - dash splitting
|
|
373
|
+
*/
|
|
374
|
+
declare function tessellateStroke(path: Path, stroke: Stroke, opts?: StrokeOptions): Mesh;
|
|
375
|
+
|
|
376
|
+
export { DrawCommand, IDENTITY_COLOR_MATRIX, ImageMinification, Mat3, type Mesh, ShaderCompileError, ShaderProgramHandle, type StrokeOptions, type TessellateOptions, WeaselRenderer, type WeaselRendererOptions, buildGradientRamp, tessellate, tessellateStroke };
|
package/dist/renderer.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { IDENTITY_COLOR_MATRIX, ShaderCompileError, WeaselRenderer, buildGradientRamp, isCanvasFont, mat3, registerCanvasFont, registerFont, registerProgram, subscribeGlyphReady, tessellate, tessellateStroke, unregisterCanvasFont, viewToMat3 } from './chunk-7V6JEOXE.js';
|
|
2
|
+
import './chunk-AM6ARSPN.js';
|
|
3
|
+
import './chunk-VOVKONXA.js';
|
|
4
|
+
import './chunk-BGGZ4CVF.js';
|
|
5
|
+
import './chunk-CQNKCG34.js';
|
|
6
|
+
import './chunk-775XXAHR.js';
|
|
7
|
+
import './chunk-UGFFCMQP.js';
|
|
8
|
+
import './chunk-BHVYVFGV.js';
|
|
9
|
+
import './chunk-GVCNT7UH.js';
|
|
10
|
+
export { registerTexture } from './chunk-Y52N27PF.js';
|
|
11
|
+
import './chunk-PZ5AY32C.js';
|
|
12
|
+
//# sourceMappingURL=renderer.js.map
|
|
13
|
+
//# sourceMappingURL=renderer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"renderer.js"}
|
package/dist/resize.d.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
export { C as CORNER_ANCHORS, a as CornerAnchor, b as CornerHandle, P as PoseProjection, R as RECT_POSE_DESCRIPTOR, c as ROTATED_POSE_DESCRIPTOR, U as UseResizeOptions, d as cornerPoint, e as cornerResizeHandles, f as fixedCornerOf, h as hitCornerHandle, p as pointSnapToGrid } from './pointSnapToGrid-D7s7QmOF.js';
|
|
2
|
+
import { R as ResizePose, B as BoundsConstraint, M as ModifierState } from './types-BjUi2vA-.js';
|
|
3
|
+
import { G as Guide } from './types-D2tTKEU0.js';
|
|
4
|
+
import { V as View } from './view-DSQgxBJB.js';
|
|
5
|
+
import './fitViewToBounds-evGsnR8Q.js';
|
|
6
|
+
import './types-BJ8_cyT7.js';
|
|
7
|
+
import '@weasel-js/history';
|
|
8
|
+
import './types-B_-khFM0.js';
|
|
9
|
+
|
|
10
|
+
declare function clampMinSize<TPose extends ResizePose>(args: {
|
|
11
|
+
minWidth: number;
|
|
12
|
+
minHeight: number;
|
|
13
|
+
}): BoundsConstraint<TPose>;
|
|
14
|
+
|
|
15
|
+
type ModKey$2 = keyof ModifierState;
|
|
16
|
+
/** Aspect-ratio lock: drag a corner/edge with `key` (default `'shift'`) held
|
|
17
|
+
* to keep the resized bounds at the start-pose's `width / height` ratio.
|
|
18
|
+
*
|
|
19
|
+
* Strategy:
|
|
20
|
+
* - Compute the proposed deltas in width and height (signed, relative to
|
|
21
|
+
* origin). Whichever axis has the larger absolute delta "wins"; the other
|
|
22
|
+
* is recomputed from `(originW / originH) * winnerDelta`.
|
|
23
|
+
* - The opposite corner/edge stays anchored — for the corner case we infer
|
|
24
|
+
* the anchor from the proposed bounds; for an edge handle we resize the
|
|
25
|
+
* orthogonal axis symmetrically around the dragged edge's anchor (the
|
|
26
|
+
* handle's own line stays put, the orthogonal axis grows/shrinks centered
|
|
27
|
+
* on the un-dragged edge — see notes below).
|
|
28
|
+
* - No-op when the modifier is not held, when the origin has zero width or
|
|
29
|
+
* height (no defined ratio), or when the proposed pose hasn't moved.
|
|
30
|
+
*
|
|
31
|
+
* Edge-handle handling: with `anchor.x !== 'free' && anchor.y === 'free'`
|
|
32
|
+
* (an `e` or `w` handle), only the width was driven by the pointer. We pick
|
|
33
|
+
* the new height as `width / ratio` and pin it to the un-dragged y axis by
|
|
34
|
+
* anchoring at the origin's top edge (`y` stays at `origin.y`). Symmetric
|
|
35
|
+
* for `n` / `s`.
|
|
36
|
+
*/
|
|
37
|
+
declare function lockAspectWithModifier<TPose extends ResizePose>(opts?: {
|
|
38
|
+
key?: ModKey$2;
|
|
39
|
+
}): BoundsConstraint<TPose>;
|
|
40
|
+
|
|
41
|
+
type ModKey$1 = keyof ModifierState;
|
|
42
|
+
declare function snapToGrid<TPose extends ResizePose>(args: {
|
|
43
|
+
spacing: number;
|
|
44
|
+
bypassKey?: ModKey$1;
|
|
45
|
+
suspendBelowDim?: boolean;
|
|
46
|
+
}): BoundsConstraint<TPose>;
|
|
47
|
+
|
|
48
|
+
type ModKey = keyof ModifierState;
|
|
49
|
+
/** Options for the resize-flavored `snapToGuides`. */
|
|
50
|
+
interface SnapToGuidesResizeArgs {
|
|
51
|
+
/** Stable getter into the live guide list (typically from `useGuides`). */
|
|
52
|
+
getGuides: () => readonly Guide[];
|
|
53
|
+
/** Snap tolerance (screen px when `getView` is set, world units otherwise). */
|
|
54
|
+
tolerance?: number;
|
|
55
|
+
/** Read the active view; required for screen-pixel tolerance. */
|
|
56
|
+
getView?: () => View;
|
|
57
|
+
/** Modifier key that bypasses snapping while held. */
|
|
58
|
+
bypassKey?: ModKey;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Resize behavior that snaps the active edge of the dragged rect to the
|
|
62
|
+
* nearest guide on the corresponding axis when within `tolerance`. The
|
|
63
|
+
* "free" axis is left untouched. The fixed (anchor) edge stays pinned;
|
|
64
|
+
* only the moving edge snaps.
|
|
65
|
+
*
|
|
66
|
+
* On the X axis, vertical guides (`axis: 'x'`) constrain the moving vertical
|
|
67
|
+
* edge — east when `anchor.x === 'min'` (west pinned), west when `'max'`.
|
|
68
|
+
* Likewise on Y for horizontal guides.
|
|
69
|
+
*/
|
|
70
|
+
declare function snapToGuides<TPose extends ResizePose>(args: SnapToGuidesResizeArgs): BoundsConstraint<TPose>;
|
|
71
|
+
|
|
72
|
+
/** The kit's standard resize behaviors, applied when a consumer doesn't
|
|
73
|
+
* supply its own list: shift-drag locks the start pose's aspect ratio.
|
|
74
|
+
* Pass an explicit `behaviors: []` to opt out. Stateless, so one shared
|
|
75
|
+
* frozen instance is safe across every gesture. */
|
|
76
|
+
declare const DEFAULT_RESIZE_BEHAVIORS: readonly BoundsConstraint<ResizePose>[];
|
|
77
|
+
|
|
78
|
+
export { DEFAULT_RESIZE_BEHAVIORS, clampMinSize, lockAspectWithModifier, snapToGrid, snapToGuides };
|
package/dist/resize.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { CORNER_ANCHORS, DEFAULT_RESIZE_BEHAVIORS, clampMinSize, cornerPoint, cornerResizeHandles, fixedCornerOf, hitCornerHandle, lockAspectWithModifier, pointSnapToGrid, snapToGrid, snapToGuides } from './chunk-BGGZ4CVF.js';
|
|
2
|
+
export { RECT_POSE_DESCRIPTOR, ROTATED_POSE_DESCRIPTOR } from './chunk-CQNKCG34.js';
|
|
3
|
+
import './chunk-PZ5AY32C.js';
|
|
4
|
+
//# sourceMappingURL=resize.js.map
|
|
5
|
+
//# sourceMappingURL=resize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"resize.js"}
|
package/dist/routing.css
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/* src/tools/routing/reflection/ToolDebugOverlay.module.css */
|
|
2
|
+
.overlay {
|
|
3
|
+
position: absolute;
|
|
4
|
+
bottom: 12px;
|
|
5
|
+
right: 12px;
|
|
6
|
+
min-width: 180px;
|
|
7
|
+
padding: 8px 10px;
|
|
8
|
+
background: rgba(20, 20, 24, 0.86);
|
|
9
|
+
color: #eaeaea;
|
|
10
|
+
font:
|
|
11
|
+
11px/1.4 ui-monospace,
|
|
12
|
+
"SF Mono",
|
|
13
|
+
Menlo,
|
|
14
|
+
monospace;
|
|
15
|
+
border: 1px solid rgba(255, 255, 255, 0.1);
|
|
16
|
+
border-radius: 4px;
|
|
17
|
+
pointer-events: none;
|
|
18
|
+
user-select: none;
|
|
19
|
+
}
|
|
20
|
+
.row {
|
|
21
|
+
display: flex;
|
|
22
|
+
justify-content: space-between;
|
|
23
|
+
gap: 12px;
|
|
24
|
+
}
|
|
25
|
+
.label {
|
|
26
|
+
color: #888;
|
|
27
|
+
}
|
|
28
|
+
.value {
|
|
29
|
+
color: #f5f5f5;
|
|
30
|
+
}
|
|
31
|
+
.empty {
|
|
32
|
+
color: #888;
|
|
33
|
+
font-style: italic;
|
|
34
|
+
}
|
|
35
|
+
/*# sourceMappingURL=routing.css.map */
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/tools/routing/reflection/ToolDebugOverlay.module.css"],"sourcesContent":["/* src/tools/routing/reflection/ToolDebugOverlay.module.css */\n.overlay {\n position: absolute;\n bottom: 12px;\n right: 12px;\n min-width: 180px;\n padding: 8px 10px;\n background: rgba(20, 20, 24, 0.86);\n color: #eaeaea;\n font: 11px/1.4 ui-monospace, \"SF Mono\", Menlo, monospace;\n border: 1px solid rgba(255, 255, 255, 0.1);\n border-radius: 4px;\n pointer-events: none;\n user-select: none;\n}\n\n.row {\n display: flex;\n justify-content: space-between;\n gap: 12px;\n}\n\n.label {\n color: #888;\n}\n\n.value {\n color: #f5f5f5;\n}\n\n.empty {\n color: #888;\n font-style: italic;\n}\n"],"mappings":";AACA,CAAC;AACC,YAAU;AACV,UAAQ;AACR,SAAO;AACP,aAAW;AACX,WAAS,IAAI;AACb,cAAY,KAAK,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE;AAC7B,SAAO;AACP;AAAA,IAAM,IAAI,CAAC,IAAI,YAAY;AAAA,IAAE,SAAS;AAAA,IAAE,KAAK;AAAA,IAAE;AAC/C,UAAQ,IAAI,MAAM,KAAK,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE;AACtC,iBAAe;AACf,kBAAgB;AAChB,eAAa;AACf;AAEA,CAAC;AACC,WAAS;AACT,mBAAiB;AACjB,OAAK;AACP;AAEA,CAAC;AACC,SAAO;AACT;AAEA,CAAC;AACC,SAAO;AACT;AAEA,CAAC;AACC,SAAO;AACP,cAAY;AACd;","names":[]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { N as ActionFn, Q as AffordanceHit, V as BeginSpec, X as Conflict, Y as EmptyHit, Z as HitResult, _ as ModifierRoute, $ as NodeHit, a0 as NodeRef, a1 as NodeRefHit, a2 as PhaseDef, a3 as RegistryEntry, a4 as Result, a5 as RouteEntry, a6 as RouteGesture, a7 as RoutePhase, a8 as RouteResolvedInfo, a9 as RouteTable, aa as ToolDebugOverlay, ab as ToolDebugOverlayProps, ac as ToolDef, f as ToolKeybinding, ad as ViewportPhaseDef, ae as ViewportToolDef, af as apply, ag as begin, ah as buildActionRegistry, ai as cancel, aj as claim, ak as commit, al as defineTool, am as defineViewportTool, an as findConflicts, ao as formatRouteResolved, ap as forwardActionTo, aq as hold, ar as none, as as resolveRoute, at as useToolDebugInfo } from './index-DZBYMsHI.js';
|
|
2
|
+
export { ChannelRef, DescribeRouteOptions, GESTURE_DESCRIPTORS, GestureArgSpec, GestureDescriptor, GestureName, ModRequirement, ModifierCombo, ModifierKey, ParsedModifiers, ParsedRoute, PhaseAtom, RESERVED_ID_NAMES, RESERVED_ID_PREFIXES, ROUTE_FIELD_DEFINITIONS, ROUTE_TERMS, RouteDescriptionPart, RouteFieldName, RouteTermLabel, canonicalModifiers, collapseShiftPairs, describeRoute, describeRouteParts, formatPhaseAtom, formatRoute, getGestureDescriptor, isKnownGestureName, mods, parseRoute } from '@weasel-js/gestures';
|
|
3
|
+
import './types-Cpb4hii1.js';
|
|
4
|
+
import '@weasel-js/history';
|
|
5
|
+
import './types-B6MMiodD.js';
|
|
6
|
+
import 'react';
|
|
7
|
+
import './view-DSQgxBJB.js';
|
|
8
|
+
import './types-BjUi2vA-.js';
|
|
9
|
+
import './types-B_-khFM0.js';
|
|
10
|
+
import './fitViewToBounds-evGsnR8Q.js';
|
|
11
|
+
import './DrawCommand-Dl0bXNfS.js';
|
|
12
|
+
import './registerTexture-BzHTLhD9.js';
|
|
13
|
+
import './types-BJ8_cyT7.js';
|
|
14
|
+
import '@weasel-js/modes';
|
package/dist/routing.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { GESTURE_DESCRIPTORS, RESERVED_ID_NAMES, RESERVED_ID_PREFIXES, ROUTE_FIELD_DEFINITIONS, ROUTE_TERMS, ToolDebugOverlay, apply, begin, buildActionRegistry, cancel, canonicalModifiers, claim, collapseShiftPairs, commit, defineTool, defineViewportTool, describeRoute, describeRouteParts, findConflicts, formatPhaseAtom, formatRoute, formatRouteResolved, forwardActionTo, getGestureDescriptor, hold, isKnownGestureName, mods, none, parseRoute, resolveRoute, useToolDebugInfo } from './chunk-AM6ARSPN.js';
|
|
2
|
+
import './chunk-PZ5AY32C.js';
|
|
3
|
+
//# sourceMappingURL=routing.js.map
|
|
4
|
+
//# sourceMappingURL=routing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"routing.js"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Path data model. Vector-graphics primitive used kit-wide as the canonical
|
|
3
|
+
* shape (replacing per-shape ad-hoc poses). SVG-style command stream so we
|
|
4
|
+
* cover lines, polygons, beziers, and multi-contour shapes (think the inner
|
|
5
|
+
* hole of an "O") under one type.
|
|
6
|
+
*
|
|
7
|
+
* Storage: command codes in a `Uint8Array`, parameters in a `Float32Array`.
|
|
8
|
+
* Each command consumes a fixed number of float coords from the parameter
|
|
9
|
+
* array; the parser walks both arrays in lockstep. This keeps interaction
|
|
10
|
+
* hot loops monomorphic and keeps GC pressure low under heavy edits.
|
|
11
|
+
*
|
|
12
|
+
* Two path subtypes are distinguished at the type level so common-case
|
|
13
|
+
* machinery (selection AABBs, area-select intersection, hit-testing rect
|
|
14
|
+
* silhouettes) can short-circuit on `RectPath` without paying the polygon
|
|
15
|
+
* kernel cost. Polymorphic kernels accept either via the `Path` union and
|
|
16
|
+
* dispatch on `kind`.
|
|
17
|
+
*/
|
|
18
|
+
/** Command code: moveTo. */
|
|
19
|
+
declare const PATH_M = 0;
|
|
20
|
+
/** Command code: lineTo. */
|
|
21
|
+
declare const PATH_L = 1;
|
|
22
|
+
/** Command code: cubic bezier (`bezierCurveTo`). */
|
|
23
|
+
declare const PATH_C = 2;
|
|
24
|
+
/** Command code: quadratic bezier (`quadraticCurveTo`). */
|
|
25
|
+
declare const PATH_Q = 3;
|
|
26
|
+
/** Command code: close subpath. */
|
|
27
|
+
declare const PATH_Z = 4;
|
|
28
|
+
/** Float coords consumed by each command, indexed by command code. */
|
|
29
|
+
declare const PATH_CMD_LENGTHS: readonly number[];
|
|
30
|
+
/** Fill rule used by polygon path hit-testing and `ctx.fill()`. */
|
|
31
|
+
type PathFillRule = 'nonzero' | 'evenodd';
|
|
32
|
+
/**
|
|
33
|
+
* Polygon path with arbitrary contours and optional bezier segments.
|
|
34
|
+
* Multi-contour: each `M` opens a new subpath; `Z` closes the current one.
|
|
35
|
+
* Open subpaths (no `Z`) render as polylines and don't contribute to fills.
|
|
36
|
+
*/
|
|
37
|
+
interface PolygonPath {
|
|
38
|
+
kind: 'polygon';
|
|
39
|
+
commands: Uint8Array;
|
|
40
|
+
coords: Float32Array;
|
|
41
|
+
fillRule: PathFillRule;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Axis-aligned rectangle. Fast path for the (very common) case where the
|
|
45
|
+
* shape is just a rect — preserves O(1) bounds and hit-test, avoids the
|
|
46
|
+
* polygon kernel entirely. Promote to `PolygonPath` only when the shape
|
|
47
|
+
* grows beyond what a rect can express.
|
|
48
|
+
*/
|
|
49
|
+
interface RectPath {
|
|
50
|
+
kind: 'rect';
|
|
51
|
+
x: number;
|
|
52
|
+
y: number;
|
|
53
|
+
width: number;
|
|
54
|
+
height: number;
|
|
55
|
+
}
|
|
56
|
+
/** Canonical path shape — either an axis-aligned rect (fast path) or a polygon command stream. */
|
|
57
|
+
type Path = PolygonPath | RectPath;
|
|
58
|
+
|
|
59
|
+
export { type Path as P, type RectPath as R, type PolygonPath as a, type PathFillRule as b, PATH_C as c, PATH_CMD_LENGTHS as d, PATH_L as e, PATH_M as f, PATH_Q as g, PATH_Z as h };
|