@weasel-js/core 1.3.0 → 1.4.0-pre.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.
@@ -1,190 +0,0 @@
1
- import { M as Mat3 } from './DrawCommand-BnZyQaDc.js';
2
- import { P as Path } from './path-JEV2c5If.js';
3
- import { Stroke } from '@weasel-js/paint';
4
-
5
- /**
6
- * Minimal compile/link/lookup wrapper for a GL program. Throws
7
- * `ShaderCompileError` on compile or link failure with the GL info log
8
- * embedded in the error message — never returns a half-initialized program.
9
- *
10
- * Designed so test code can stub `getShaderParameter` / `getProgramParameter`
11
- * via the recorder Proxy without further special-casing.
12
- */
13
- type Stage = 'vertex' | 'fragment' | 'link';
14
- /** Thrown when a shader fails to compile or link, carrying which stage failed
15
- * and the driver's log. */
16
- declare class ShaderCompileError extends Error {
17
- readonly stage: Stage;
18
- readonly log: string;
19
- constructor(stage: Stage, log: string);
20
- }
21
- declare class ShaderProgram {
22
- private readonly gl;
23
- readonly handle: WebGLProgram;
24
- private readonly uniforms;
25
- private readonly attributes;
26
- constructor(gl: WebGL2RenderingContext, vertSrc: string, fragSrc: string);
27
- private compile;
28
- lookupUniforms(names: readonly string[]): void;
29
- lookupAttributes(names: readonly string[]): void;
30
- uniform(name: string): WebGLUniformLocation | undefined;
31
- attribute(name: string): number | undefined;
32
- }
33
-
34
- /**
35
- * A tessellated representation of a Path, ready to upload to GL.
36
- *
37
- * - `vertices` is interleaved x,y in path-local coordinates (`Float32Array`
38
- * of length `2 * vertexCount`).
39
- * - `indices` are triangle indices into `vertices` (`Uint32Array`, length
40
- * `3 * triangleCount`).
41
- * - `requiresStencil` is set for paths whose fillRule is `'evenodd'` and
42
- * whose triangulation is a *naive* per-contour fan rather than a clean
43
- * inside/outside triangulation. The renderer must use a stencil
44
- * two-pass when this flag is true. Single-contour paths and `'nonzero'`
45
- * multi-contour paths leave it false.
46
- * - `anchorA` / `anchorB` / `anchorT` parameterize each mesh vertex by
47
- * the two consecutive path anchors it lies between and the arc-length
48
- * fraction along that segment (0 = at A, 1 = at B). Vertices that fall
49
- * exactly on an anchor set A === B and t = 0. Used at draw time when
50
- * the DrawCommand supplies per-anchor colors so the renderer can lerp
51
- * per mesh vertex. Optional — emitted by the path tessellators; absent
52
- * on meshes built by other paths (e.g. text glyphs).
53
- */
54
- interface Mesh {
55
- readonly vertices: Float32Array;
56
- readonly indices: Uint32Array;
57
- readonly requiresStencil?: boolean;
58
- readonly anchorA?: Uint32Array;
59
- readonly anchorB?: Uint32Array;
60
- readonly anchorT?: Float32Array;
61
- }
62
-
63
- /**
64
- * GL texture upload cache for ImageBitmap objects.
65
- *
66
- * Key: ImageBitmap (or pattern source object) identity (WeakMap) — lets GC
67
- * reclaim unreferenced bitmaps. The GL textures are NOT freed when the source
68
- * is gc'd; deferred to v2.
69
- *
70
- * Wrapping is set once at upload time per the `repetition` parameter:
71
- * - undefined / 'no-repeat' → CLAMP_TO_EDGE
72
- * - 'repeat' → REPEAT (both axes)
73
- * - 'repeat-x' → REPEAT on S, CLAMP on T
74
- * - 'repeat-y' → CLAMP on S, REPEAT on T
75
- *
76
- * Convention §2: texels stored straight; shader premultiplies.
77
- */
78
- type PatternRepetition = 'repeat' | 'repeat-x' | 'repeat-y' | 'no-repeat';
79
- /** MIN_FILTER strategy for uploaded textures. */
80
- type ImageMinification = 'linear' | 'mipmap';
81
- type TexSource = ImageBitmap | ImageData | HTMLCanvasElement | HTMLImageElement;
82
- declare class GLImageCache {
83
- private readonly gl;
84
- private readonly minification;
85
- private readonly map;
86
- /** `minification` selects the MIN_FILTER strategy for uploaded textures.
87
- * `'linear'` (default) is the screen path's existing behavior. `'mipmap'`
88
- * generates mipmaps and filters LINEAR_MIPMAP_LINEAR — required for
89
- * quality minification when a large source bitmap is drawn small (the
90
- * headless print/export path); bilinear-only minification undersamples
91
- * and produces moiré. */
92
- constructor(gl: WebGL2RenderingContext, minification?: ImageMinification);
93
- upload(key: object, source: TexSource, repetition?: PatternRepetition): WebGLTexture;
94
- bind(key: object, unit: number): void;
95
- }
96
-
97
- /**
98
- * Uniform-grid sprite sheet layout — frame index to the source rect an
99
- * `ImageDrawCommand` samples. Pure arithmetic over the grid description; it
100
- * never touches the bitmap.
101
- */
102
- /** A sprite sheet's grid. `margin` and `spacing` follow the Tiled / Aseprite
103
- * tileset convention, so a sheet exported from either describes itself here. */
104
- interface SpriteSheet {
105
- frameWidth: number;
106
- frameHeight: number;
107
- columns: number;
108
- /** Empty pixels around the whole grid. Default 0. */
109
- margin?: number;
110
- /** Empty pixels between adjacent cells — the gutter that keeps linear
111
- * sampling off the neighboring frame. Default 0. */
112
- spacing?: number;
113
- }
114
- /**
115
- * Row-major source rect for frame `index`, counting from 0 at the top-left.
116
- *
117
- * `index` is not range-checked and does not wrap: past the last cell this
118
- * returns a rect below the sheet, which draws as an edge smear. Wrapping is
119
- * the animation's business (`frameRect(sheet, tick % count)`) — a sheet does
120
- * not know how many of its cells are filled.
121
- */
122
- declare function frameRect(sheet: SpriteSheet, index: number): {
123
- x: number;
124
- y: number;
125
- w: number;
126
- h: number;
127
- };
128
-
129
- /**
130
- * View → Mat3 helper for layer `draw` implementations on world-space layers.
131
- *
132
- * The kit's main package ships a `View` type at
133
- * `src/core/viewport/view.ts`; we re-declare a structurally compatible
134
- * shape here to avoid a runtime cross-package import. Exported as
135
- * `ViewLike` from the package barrel.
136
- */
137
-
138
- /** A weasel View — `{x, y, scale: {x, y}}`. Local type to avoid a cross-package import. */
139
- interface View {
140
- x: number;
141
- y: number;
142
- scale: {
143
- x: number;
144
- y: number;
145
- };
146
- }
147
- /**
148
- * Build the world→screen transform matrix for a `View`.
149
- * Use as the `transform` field of a `kind: 'group'` DrawCommand to wrap
150
- * world-space content emitted from a layer `draw` implementation.
151
- *
152
- * Mapping: `screen = (world − {view.x, view.y}) × {view.scale.x, view.scale.y}`.
153
- *
154
- * Column-major layout (matches `mat3.identity()`):
155
- * `[scale.x, 0, 0, 0, scale.y, 0, -view.x*scale.x, -view.y*scale.y, 1]`.
156
- */
157
- declare function viewToMat3(view: View): Mat3;
158
-
159
- /** Options for stroke tessellation. */
160
- interface StrokeOptions {
161
- flattenTolerance?: number;
162
- /**
163
- * Shorten each open subpath by this much at its start / end, in the same
164
- * world units as the path. Stroke markers use this so a filled head is not
165
- * speared by its own line; the caller resolves the distance, because this
166
- * layer knows nothing about the marker registry.
167
- */
168
- startInset?: number;
169
- endInset?: number;
170
- }
171
- /** Resolve a stroke width to world units. A number is already world units;
172
- * `{ px }` is screen pixels divided by the accumulated scale, so it holds its
173
- * on-screen thickness as the view zooms. */
174
- declare function resolveStrokeWidth(width: number | {
175
- px: number;
176
- }, scale: number): number;
177
- /**
178
- * Build a triangle-mesh ribbon from a stroked Path.
179
- *
180
- * Supports:
181
- * - cap: 'butt' | 'round' | 'square'
182
- * - join: 'miter' | 'round' | 'bevel'
183
- * - center alignment directly; RectPath inner/outer alignment via a
184
- * pre-shifted rect; PolygonPath inner/outer alignment via stencil at the
185
- * renderer level
186
- * - dash splitting
187
- */
188
- declare function tessellateStroke(path: Path, stroke: Stroke, opts?: StrokeOptions): Mesh;
189
-
190
- export { GLImageCache as G, type ImageMinification as I, type Mesh as M, ShaderProgram as S, type View as V, ShaderCompileError as a, type SpriteSheet as b, type StrokeOptions as c, frameRect as f, resolveStrokeWidth as r, tessellateStroke as t, viewToMat3 as v };