@weasel-js/renderer 1.9.4 → 1.10.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/dist/mesh.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { GradientUnits, ColorSpace, FillStyle, GradStop } from '@weasel-js/paint';
2
- import { c as PaintDrawKind } from './paintKinds-B2vEy9A4.js';
1
+ import { PaintUnits, ColorSpace, Paint, GradStop } from '@weasel-js/paint';
2
+ import { c as PaintDrawKind } from './paintKinds-BmPAT51k.js';
3
3
  import '@weasel-js/registry';
4
4
  import '@weasel-js/geom';
5
5
 
@@ -8,14 +8,8 @@ import '@weasel-js/geom';
8
8
  * pure geometry.
9
9
  *
10
10
  * A patch is a curved quadrilateral: four cubic Bézier edges and a color at
11
- * each corner. The interior is what the edges imply — a Coons patch reads it
12
- * off the boundary alone; a tensor patch adds four interior control points
13
- * that pull it around. Both evaluate at a `(u, v)` in the unit square, which
14
- * is what lets the renderer subdivide a patch into as many triangles as it
15
- * wants without the patch knowing.
16
- *
17
- * Nothing here touches GL, a color string, or a scene. `evalPatch` is the
18
- * whole contract.
11
+ * each corner. A Coons patch reads its interior off the boundary alone; a
12
+ * tensor patch adds four interior control points that pull it around.
19
13
  */
20
14
  /** A point in the patch's own space. */
21
15
  interface MeshPoint {
@@ -29,14 +23,10 @@ interface MeshPoint {
29
23
  * leaving it, corner 1, its two, and so on — twelve points, ending with the
30
24
  * two controls that return to corner 0. A tensor patch appends its four
31
25
  * interior points, in the order `(1,1)`, `(1,2)`, `(2,2)`, `(2,1)` of the
32
- * bicubic control net, which is PDF's own order.
33
- *
34
- * Twelve points is a Coons patch and sixteen is a tensor patch; there is no
35
- * flag, because the count already says which it is.
26
+ * bicubic control net, which is PDF's own order. Twelve points is a Coons
27
+ * patch and sixteen is a tensor patch.
36
28
  *
37
- * `colors` are the corner colors in the same walk order, as whatever color
38
- * form the caller resolves — the renderer hands premultiplied RGBA in, the
39
- * serializer hands CSS strings.
29
+ * `colors` are the corner colors in the same walk order.
40
30
  */
41
31
  interface MeshPatch<TColor = string> {
42
32
  points: readonly MeshPoint[];
@@ -59,14 +49,10 @@ declare function isValidPatch(patch: MeshPatch<unknown>): boolean;
59
49
  declare function evalPatch(patch: MeshPatch<unknown>, u: number, v: number): MeshPoint;
60
50
  /**
61
51
  * The four corner weights at `(u, v)` — bilinear, in the corner walk order.
62
- *
63
- * Color is separate from position on purpose: it interpolates in whatever
64
- * space the caller chose, which is not a thing the surface can do for it.
65
52
  */
66
53
  declare function cornerWeights(u: number, v: number): [number, number, number, number];
67
- /** Axis-aligned bounds of a patch, sampled on a grid. Control points alone
68
- * bound a Bézier but not tightly, and a mesh paint is baked into a texture
69
- * sized from this — a loose box wastes texels on every side. */
54
+ /** Axis-aligned bounds of a patch, sampled on a grid: control points alone
55
+ * bound a Bézier but not tightly. */
70
56
  declare function patchBounds(patch: MeshPatch<unknown>, steps?: number): {
71
57
  x: number;
72
58
  y: number;
@@ -76,20 +62,11 @@ declare function patchBounds(patch: MeshPatch<unknown>, steps?: number): {
76
62
 
77
63
  /**
78
64
  * The `mesh-gradient` paint kind — PDF's shading types 6 and 7 as a registered
79
- * paint.
80
- *
81
- * A mesh gradient is a set of curved quadrilateral patches, each with a color
82
- * at every corner. It is the paint SVG tried to standardize as
83
- * `<meshgradient>` and abandoned, and the one PDF has had since 1993; what it
84
- * buys over the three gradients is a color field that bends, so a highlight
85
- * can follow a form instead of running straight across it.
65
+ * paint: a set of curved quadrilateral patches, each with a color at every
66
+ * corner.
86
67
  *
87
- * This is a registered kind rather than a sixth branch in the renderer, and
88
- * deliberately: it uses only the slots `registerPaintKind` gives a consumer, so
89
- * whatever it can do, a consumer's own kind can do too. Its one concession is
90
- * living in this package, because that is where the shader registry is.
91
- *
92
- * `docs/proposals/2026-09-17-paint-kinds-beyond-svg.md` is the design.
68
+ * It uses only the slots `registerPaintKind` gives a consumer, so whatever it
69
+ * can do, a consumer's own kind can do too.
93
70
  */
94
71
 
95
72
  /**
@@ -100,38 +77,36 @@ declare function patchBounds(patch: MeshPatch<unknown>, steps?: number): {
100
77
  * node's box, which is what lets the paint survive a resize.
101
78
  *
102
79
  * `interpolate` is the space corner colors blend through, matching the three
103
- * gradients. It is more visible here than there: a mesh blends in two
104
- * directions at once, so an sRGB blend's muddy middle covers area rather than
105
- * a line.
80
+ * gradients.
106
81
  */
107
- interface MeshGradientFill {
108
- fill: 'mesh-gradient';
82
+ interface MeshGradientPaint {
83
+ kind: 'mesh-gradient';
109
84
  patches: MeshPatch[];
110
- units?: GradientUnits;
85
+ units?: PaintUnits;
111
86
  interpolate?: ColorSpace;
112
87
  opacity?: number;
113
88
  }
114
- /** The kind's id, as `FillStyle['fill']` carries it. */
89
+ /** The kind's id, as `Paint['fill']` carries it. */
115
90
  declare const MESH_GRADIENT_KIND = "mesh-gradient";
116
91
  /** A mesh paint, narrowed. */
117
- declare function isMeshGradientFill(fill: FillStyle | null | undefined): fill is FillStyle & MeshGradientFill;
92
+ declare function isMeshGradientPaint(fill: Paint | null | undefined): fill is Paint & MeshGradientPaint;
118
93
  /** A one-patch square covering the unit box, its four corners four readings of
119
94
  * `color` — a mesh seeded from a solid has to show *something* curved, or
120
95
  * switching kind looks like nothing happened. */
121
- declare function seedMeshPatch(color: string): MeshGradientFill;
96
+ declare function seedMeshPatch(color: string): MeshGradientPaint;
122
97
  /**
123
98
  * A stop list as a mesh: one full-height band per gap between neighboring
124
99
  * stops, colored left to right. The bands blend exactly the way the ramp
125
100
  * does, so a horizontal gradient survives the switch unchanged. A zero-width
126
101
  * gap is a hard break and gets no band.
127
102
  */
128
- declare function meshFromStops(stops: readonly GradStop[]): MeshGradientFill;
103
+ declare function meshFromStops(stops: readonly GradStop[]): MeshGradientPaint;
129
104
  /**
130
105
  * A mesh read as a stop list: every patch's top edge — corner 0 to corner 1 —
131
106
  * placed by its `x` across the mesh's horizontal extent. The inverse of
132
107
  * `meshFromStops`, and for any other mesh the ramp across its top.
133
108
  */
134
- declare function meshStops(mesh: MeshGradientFill): GradStop[];
109
+ declare function meshStops(mesh: MeshGradientPaint): GradStop[];
135
110
  /** The kind's draw half, shader program included. Core adds the editor's
136
111
  * slots and registers the whole entry. */
137
112
  declare const meshDrawKind: PaintDrawKind;
@@ -145,21 +120,15 @@ declare const meshDrawKind: PaintDrawKind;
145
120
  * `@weasel-js/svg` puts the paint fallback color beside the reference, so a
146
121
  * foreign renderer paints flat instead of nothing.
147
122
  */
148
- declare function meshGradientXml(id: string, mesh: MeshGradientFill): string;
123
+ declare function meshGradientXml(id: string, mesh: MeshGradientPaint): string;
149
124
 
150
125
  /**
151
- * A mesh paint baked into one RGBA bitmap.
152
- *
153
- * A patch is a surface over `(u, v)`, but a paint has to answer "what color is
154
- * this fragment", which is the inverse question — and inverting a bicubic is
155
- * Newton iteration per fragment. Every renderer that draws these instead
156
- * subdivides the patch into small quads and rasterizes them forward, which is
157
- * what this does, once per paint, into a texture the shader then samples. The
158
- * cost is a texture and a resolution; the gain is that the paint composes with
159
- * every fill the renderer already knows how to draw, clipping included.
126
+ * A mesh paint baked into one RGBA bitmap: each patch is subdivided into small
127
+ * quads and rasterized forward, once per paint, into a texture the shader then
128
+ * samples. Inverting a bicubic per fragment would be Newton iteration.
160
129
  *
161
- * The bitmap is straight (non-premultiplied) RGBA, matching the ramp atlas;
162
- * the fragment shader premultiplies.
130
+ * The bitmap is straight (non-premultiplied) RGBA; the fragment shader
131
+ * premultiplies.
163
132
  */
164
133
 
165
134
  /** Texels on a side of a bake when the caller names no size. The renderer
@@ -185,10 +154,8 @@ interface BakedMesh {
185
154
  /** The union of every patch's bounds, or `null` when nothing is drawable. */
186
155
  declare function meshBounds(patches: readonly MeshPatch[]): MeshBox | null;
187
156
  /**
188
- * Rasterize `patches` into a square bitmap covering their union.
189
- *
190
- * Returns `null` when no patch is drawable, which is the caller's cue to paint
191
- * nothing rather than a blank square.
157
+ * Rasterize `patches` into a square bitmap covering their union, or `null`
158
+ * when no patch is drawable.
192
159
  */
193
160
  declare function bakeMesh(patches: readonly MeshPatch[], space?: ColorSpace, size?: number): BakedMesh | null;
194
161
 
@@ -252,14 +219,14 @@ interface MeshHandle {
252
219
  * edge controls, then a tensor patch's interior. Coincident points of one
253
220
  * kind merge into one handle. A patch that cannot be evaluated has none.
254
221
  */
255
- declare function meshHandles(mesh: MeshGradientFill): MeshHandle[];
222
+ declare function meshHandles(mesh: MeshGradientPaint): MeshHandle[];
256
223
  /**
257
224
  * `mesh` with `handle` moved to `to`. A corner carries its edge controls
258
225
  * and interior neighbor along by the same offset, the way a path editor's
259
226
  * anchor carries its handles; a control or interior point moves alone.
260
227
  * Returns a new paint; `mesh` is not modified.
261
228
  */
262
- declare function moveMeshHandle(mesh: MeshGradientFill, handle: MeshHandle, to: MeshPoint): MeshGradientFill;
229
+ declare function moveMeshHandle(mesh: MeshGradientPaint, handle: MeshHandle, to: MeshPoint): MeshGradientPaint;
263
230
  /** The lines an editor draws under the handles, as control polygons. */
264
231
  interface MeshGuides {
265
232
  /** Every patch edge as its four cubic control points, from the corner it
@@ -269,6 +236,6 @@ interface MeshGuides {
269
236
  arms: [MeshPoint, MeshPoint][];
270
237
  }
271
238
  /** The guides for `mesh`'s valid patches. Shared edges appear once per patch. */
272
- declare function meshGuides(mesh: MeshGradientFill): MeshGuides;
239
+ declare function meshGuides(mesh: MeshGradientPaint): MeshGuides;
273
240
 
274
- export { type BakedMesh, MESH_BAKE_MAX, MESH_BAKE_MIN, MESH_BAKE_SIZE, MESH_GRADIENT_KIND, type MeshBox, type MeshGradientFill, type MeshGuides, type MeshHandle, type MeshHandleKind, type MeshPatch, type MeshPoint, type MeshPointRef, bakeMesh, cornerWeights, evalPatch, isMeshGradientFill, isTensorPatch, isValidPatch, meshBakeSize, meshBounds, meshDrawKind, meshFromStops, meshGradientXml, meshGuides, meshHandles, meshStops, moveMeshHandle, patchBounds, patchCorner, seedMeshPatch };
241
+ export { type BakedMesh, MESH_BAKE_MAX, MESH_BAKE_MIN, MESH_BAKE_SIZE, MESH_GRADIENT_KIND, type MeshBox, type MeshGradientPaint, type MeshGuides, type MeshHandle, type MeshHandleKind, type MeshPatch, type MeshPoint, type MeshPointRef, bakeMesh, cornerWeights, evalPatch, isMeshGradientPaint, isTensorPatch, isValidPatch, meshBakeSize, meshBounds, meshDrawKind, meshFromStops, meshGradientXml, meshGuides, meshHandles, meshStops, moveMeshHandle, patchBounds, patchCorner, seedMeshPatch };
package/dist/mesh.js CHANGED
@@ -309,8 +309,8 @@ void main() {
309
309
 
310
310
  // src/meshPaint/meshPaint.ts
311
311
  var MESH_GRADIENT_KIND = "mesh-gradient";
312
- function isMeshGradientFill(fill) {
313
- return fill != null && fill.fill === MESH_GRADIENT_KIND;
312
+ function isMeshGradientPaint(fill) {
313
+ return fill != null && fill.kind === MESH_GRADIENT_KIND;
314
314
  }
315
315
  function asMesh(fill) {
316
316
  return fill;
@@ -350,7 +350,7 @@ function seedMeshPatch(color) {
350
350
  );
351
351
  }
352
352
  return {
353
- fill: MESH_GRADIENT_KIND,
353
+ kind: MESH_GRADIENT_KIND,
354
354
  patches: [{
355
355
  points,
356
356
  colors: [
@@ -383,7 +383,7 @@ function meshFromStops(stops) {
383
383
  const b = sorted[i + 1];
384
384
  if (b.offset > a.offset) patches.push(bandPatch(a.offset, b.offset, a.color, b.color));
385
385
  }
386
- return { fill: MESH_GRADIENT_KIND, patches, units: "bounds" };
386
+ return { kind: MESH_GRADIENT_KIND, patches, units: "bounds" };
387
387
  }
388
388
  function meshStops(mesh) {
389
389
  const valid = mesh.patches.filter(isValidPatch);
@@ -598,6 +598,6 @@ function meshGuides(mesh) {
598
598
  return { edges, arms };
599
599
  }
600
600
 
601
- export { MESH_BAKE_MAX, MESH_BAKE_MIN, MESH_BAKE_SIZE, MESH_GRADIENT_KIND, bakeMesh, cornerWeights, evalPatch, isMeshGradientFill, isTensorPatch, isValidPatch, meshBakeSize, meshBounds, meshDrawKind, meshFromStops, meshGradientXml, meshGuides, meshHandles, meshStops, moveMeshHandle, patchBounds, patchCorner, seedMeshPatch };
601
+ export { MESH_BAKE_MAX, MESH_BAKE_MIN, MESH_BAKE_SIZE, MESH_GRADIENT_KIND, bakeMesh, cornerWeights, evalPatch, isMeshGradientPaint, isTensorPatch, isValidPatch, meshBakeSize, meshBounds, meshDrawKind, meshFromStops, meshGradientXml, meshGuides, meshHandles, meshStops, moveMeshHandle, patchBounds, patchCorner, seedMeshPatch };
602
602
  //# sourceMappingURL=mesh.js.map
603
603
  //# sourceMappingURL=mesh.js.map
package/dist/mesh.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/meshPaint/surface.ts","../src/meshPaint/bake.ts","../src/meshPaint/bakeCache.ts","../src/meshPaint/meshShader.ts","../src/meshPaint/meshPaint.ts","../src/meshPaint/handles.ts"],"names":["resolveColor"],"mappings":";;;;;;AA2CO,SAAS,WAAA,CAAY,OAA2B,CAAA,EAAsB;AAC3E,EAAA,OAAO,KAAA,CAAM,MAAA,CAAA,CAAQ,CAAA,GAAI,CAAA,IAAK,CAAC,CAAA;AACjC;AAGO,SAAS,cAAc,KAAA,EAAoC;AAChE,EAAA,OAAO,KAAA,CAAM,OAAO,MAAA,IAAU,EAAA;AAChC;AAIO,SAAS,aAAa,KAAA,EAAoC;AAC/D,EAAA,OAAO,MAAM,MAAA,CAAO,MAAA,KAAW,EAAA,IAAM,KAAA,CAAM,OAAO,MAAA,KAAW,EAAA;AAC/D;AAEA,SAAS,MAAA,CAAO,EAAA,EAAe,EAAA,EAAe,EAAA,EAAe,IAAe,CAAA,EAAsB;AAChG,EAAA,MAAM,IAAI,CAAA,GAAI,CAAA;AACd,EAAA,MAAM,CAAA,GAAI,IAAI,CAAA,GAAI,CAAA;AAClB,EAAA,MAAM,CAAA,GAAI,CAAA,GAAI,CAAA,GAAI,CAAA,GAAI,CAAA;AACtB,EAAA,MAAM,CAAA,GAAI,CAAA,GAAI,CAAA,GAAI,CAAA,GAAI,CAAA;AACtB,EAAA,MAAM,CA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,IAAI,KAAA,CAAM,MAAA;AAChB,IAAA,KAAA,IAAS,CAAA,GAAI,CAAA,EAAG,CAAA,GAAI,CAAA,EAAG,CAAA,EAAA,EAAK;AAC1B,MAAA,MAAM,SAAS,CAAA,GAAI,CAAA;AACnB,MAAA,KAAA,CAAM,KAAK,CAAC,CAAA,CAAE,MAAM,CAAA,EAAG,CAAA,CAAE,SAAS,CAAC,CAAA,EAAG,CAAA,CAAE,MAAA,GAAS,CAAC,CAAA,EAAG,CAAA,CAAA,CAAG,SAAS,CAAA,IAAK,EAAE,CAAC,CAAC,CAAA;AAC1E,MAAA,KAAA,MAAW,OAAA,IAAW,SAAA,CAAU,KAAA,EAAO,MAAM,GAAG,IAAA,CAAK,IAAA,CAAK,CAAC,CAAA,CAAE,MAAM,CAAA,EAAG,CAAA,CAAE,OAAO,CAAC,CAAC,CAAA;AAAA,IACnF;AAAA,EACF;AACA,EAAA,OAAO,EAAE,OAAO,IAAA,EAAK;AACvB","file":"mesh.js","sourcesContent":["/**\n * Coons and tensor-product patch surfaces — PDF's shading types 6 and 7, as\n * pure geometry.\n *\n * A patch is a curved quadrilateral: four cubic Bézier edges and a color at\n * each corner. The interior is what the edges imply — a Coons patch reads it\n * off the boundary alone; a tensor patch adds four interior control points\n * that pull it around. Both evaluate at a `(u, v)` in the unit square, which\n * is what lets the renderer subdivide a patch into as many triangles as it\n * wants without the patch knowing.\n *\n * Nothing here touches GL, a color string, or a scene. `evalPatch` is the\n * whole contract.\n */\n\n/** A point in the patch's own space. */\nexport interface MeshPoint {\n x: number;\n y: number;\n}\n\n/**\n * One patch.\n *\n * `points` walks the boundary: corner 0, the two control points of the edge\n * leaving it, corner 1, its two, and so on — twelve points, ending with the\n * two controls that return to corner 0. A tensor patch appends its four\n * interior points, in the order `(1,1)`, `(1,2)`, `(2,2)`, `(2,1)` of the\n * bicubic control net, which is PDF's own order.\n *\n * Twelve points is a Coons patch and sixteen is a tensor patch; there is no\n * flag, because the count already says which it is.\n *\n * `colors` are the corner colors in the same walk order, as whatever color\n * form the caller resolves — the renderer hands premultiplied RGBA in, the\n * serializer hands CSS strings.\n */\nexport interface MeshPatch<TColor = string> {\n points: readonly MeshPoint[];\n colors: readonly [TColor, TColor, TColor, TColor];\n}\n\n/** Corner `i` of the boundary walk. */\nexport function patchCorner(patch: MeshPatch<unknown>, i: number): MeshPoint {\n return patch.points[(i & 3) * 3];\n}\n\n/** `true` when the patch carries the four interior points a tensor patch adds. */\nexport function isTensorPatch(patch: MeshPatch<unknown>): boolean {\n return patch.points.length >= 16;\n}\n\n/** A patch is twelve boundary points, or sixteen with the interior. Anything\n * else cannot be evaluated, and saying so here beats painting nonsense. */\nexport function isValidPatch(patch: MeshPatch<unknown>): boolean {\n return patch.points.length === 12 || patch.points.length === 16;\n}\n\nfunction bezier(p0: MeshPoint, p1: MeshPoint, p2: MeshPoint, p3: MeshPoint, t: number): MeshPoint {\n const s = 1 - t;\n const a = s * s * s;\n const b = 3 * s * s * t;\n const c = 3 * s * t * t;\n const d = t * t * t;\n return {\n x: a * p0.x + b * p1.x + c * p2.x + d * p3.x,\n y: a * p0.y + b * p1.y + c * p2.y + d * p3.y,\n };\n}\n\n/** The edge leaving corner `i`, as its four control points. */\nfunction edge(patch: MeshPatch<unknown>, i: number): [MeshPoint, MeshPoint, MeshPoint, MeshPoint] {\n const p = patch.points;\n const a = (i & 3) * 3;\n return [p[a], p[a + 1], p[a + 2], p[((i + 1) & 3) * 3]];\n}\n\n/**\n * The patch surface at `(u, v)`, both in `0..1`.\n *\n * `u` runs along the edge leaving corner 0 and `v` along the edge leaving\n * corner 1, so `(0,0)` is corner 0, `(1,0)` corner 1, `(1,1)` corner 2 and\n * `(0,1)` corner 3 — the same walk `colors` is in.\n */\nexport function evalPatch(patch: MeshPatch<unknown>, u: number, v: number): MeshPoint {\n return isTensorPatch(patch) ? evalTensor(patch, u, v) : evalCoons(patch, u, v);\n}\n\nfunction evalCoons(patch: MeshPatch<unknown>, u: number, v: number): MeshPoint {\n const [b0, b1, b2, b3] = edge(patch, 0); // corner 0 → 1, along u at v=0\n const [r0, r1, r2, r3] = edge(patch, 1); // corner 1 → 2, along v at u=1\n const [t0, t1, t2, t3] = edge(patch, 2); // corner 2 → 3, along u at v=1\n const [l0, l1, l2, l3] = edge(patch, 3); // corner 3 → 0, along v at u=0\n\n const bottom = bezier(b0, b1, b2, b3, u);\n const top = bezier(t0, t1, t2, t3, 1 - u); // walks 2 → 3, so reverse it\n const right = bezier(r0, r1, r2, r3, v);\n const left = bezier(l0, l1, l2, l3, 1 - v); // walks 3 → 0, so reverse it\n\n const c0 = patchCorner(patch, 0);\n const c1 = patchCorner(patch, 1);\n const c2 = patchCorner(patch, 2);\n const c3 = patchCorner(patch, 3);\n\n // The Coons construction: the two ruled surfaces between opposite edges,\n // minus the bilinear surface through the corners they both already carry.\n const ruledU = (a: number, b: number): number => (1 - v) * a + v * b;\n const ruledV = (a: number, b: number): number => (1 - u) * a + u * b;\n const corner = (k0: number, k1: number, k2: number, k3: number): number =>\n (1 - u) * (1 - v) * k0 + u * (1 - v) * k1 + u * v * k2 + (1 - u) * v * k3;\n\n return {\n x: ruledU(bottom.x, top.x) + ruledV(left.x, right.x)\n - corner(c0.x, c1.x, c2.x, c3.x),\n y: ruledU(bottom.y, top.y) + ruledV(left.y, right.y)\n - corner(c0.y, c1.y, c2.y, c3.y),\n };\n}\n\n/** The bicubic control net a tensor patch's sixteen points make, as\n * `net[i][j]` with `i` along `u` and `j` along `v`. */\nfunction tensorNet(patch: MeshPatch<unknown>): MeshPoint[][] {\n const p = patch.points;\n // Boundary, read off the same walk; interior from the four trailing points.\n return [\n [p[0], p[11], p[10], p[9]],\n [p[1], p[12], p[13], p[8]],\n [p[2], p[15], p[14], p[7]],\n [p[3], p[4], p[5], p[6]],\n ];\n}\n\nconst BERNSTEIN = (t: number): [number, number, number, number] => {\n const s = 1 - t;\n return [s * s * s, 3 * s * s * t, 3 * s * t * t, t * t * t];\n};\n\nfunction evalTensor(patch: MeshPatch<unknown>, u: number, v: number): MeshPoint {\n const net = tensorNet(patch);\n const bu = BERNSTEIN(u);\n const bv = BERNSTEIN(v);\n let x = 0;\n let y = 0;\n for (let i = 0; i < 4; i++) {\n for (let j = 0; j < 4; j++) {\n const w = bu[i] * bv[j];\n x += w * net[i][j].x;\n y += w * net[i][j].y;\n }\n }\n return { x, y };\n}\n\n/**\n * The four corner weights at `(u, v)` — bilinear, in the corner walk order.\n *\n * Color is separate from position on purpose: it interpolates in whatever\n * space the caller chose, which is not a thing the surface can do for it.\n */\nexport function cornerWeights(u: number, v: number): [number, number, number, number] {\n return [(1 - u) * (1 - v), u * (1 - v), u * v, (1 - u) * v];\n}\n\n/** Axis-aligned bounds of a patch, sampled on a grid. Control points alone\n * bound a Bézier but not tightly, and a mesh paint is baked into a texture\n * sized from this — a loose box wastes texels on every side. */\nexport function patchBounds(\n patch: MeshPatch<unknown>, steps = 8,\n): { x: number; y: number; width: number; height: number } {\n let minX = Infinity;\n let minY = Infinity;\n let maxX = -Infinity;\n let maxY = -Infinity;\n for (let i = 0; i <= steps; i++) {\n for (let j = 0; j <= steps; j++) {\n const p = evalPatch(patch, i / steps, j / steps);\n if (p.x < minX) minX = p.x;\n if (p.y < minY) minY = p.y;\n if (p.x > maxX) maxX = p.x;\n if (p.y > maxY) maxY = p.y;\n }\n }\n return { x: minX, y: minY, width: maxX - minX, height: maxY - minY };\n}\n","/**\n * A mesh paint baked into one RGBA bitmap.\n *\n * A patch is a surface over `(u, v)`, but a paint has to answer \"what color is\n * this fragment\", which is the inverse question — and inverting a bicubic is\n * Newton iteration per fragment. Every renderer that draws these instead\n * subdivides the patch into small quads and rasterizes them forward, which is\n * what this does, once per paint, into a texture the shader then samples. The\n * cost is a texture and a resolution; the gain is that the paint composes with\n * every fill the renderer already knows how to draw, clipping included.\n *\n * The bitmap is straight (non-premultiplied) RGBA, matching the ramp atlas;\n * the fragment shader premultiplies.\n */\n\nimport { resolveColor } from '@weasel-js/paint';\nimport { lerpColorArray, type ColorSpace } from '@weasel-js/paint';\nimport { evalPatch, isValidPatch, patchBounds, type MeshPatch } from './surface';\n\n/** Texels on a side of a bake when the caller names no size. The renderer\n * sizes each bake from how large the paint draws — see `meshBakeSize`. */\nexport const MESH_BAKE_SIZE = 256;\n\n/** Texels a rasterized cell spans at most. The rasterizer interpolates color\n * linearly inside a cell and draws a curved edge as its chord, so this is\n * what keeps a perceptual blend perceptual and an edge curved at any size. */\nconst TEXELS_PER_CELL = 10;\n\n/** Quads per patch on a side, never fewer than 24. */\nfunction gridFor(size: number): number {\n return Math.max(24, Math.ceil(size / TEXELS_PER_CELL));\n}\n\n/** The box a bake covers, in the paint's own space. */\nexport interface MeshBox {\n x: number;\n y: number;\n width: number;\n height: number;\n}\n\n/** The bitmap `bakeMesh` produces, and the paint-space box it covers. */\nexport interface BakedMesh {\n /** `size` × `size` texels, straight RGBA. */\n pixels: Uint8ClampedArray;\n /** Texels on a side; `MESH_BAKE_SIZE` unless the caller asked otherwise. */\n size: number;\n /** Where the bitmap sits in paint space, which is what the shader maps a\n * fragment through. */\n box: MeshBox;\n}\n\n/** The union of every patch's bounds, or `null` when nothing is drawable. */\nexport function meshBounds(patches: readonly MeshPatch[]): MeshBox | null {\n let minX = Infinity;\n let minY = Infinity;\n let maxX = -Infinity;\n let maxY = -Infinity;\n for (const patch of patches) {\n if (!isValidPatch(patch)) continue;\n const b = patchBounds(patch);\n minX = Math.min(minX, b.x);\n minY = Math.min(minY, b.y);\n maxX = Math.max(maxX, b.x + b.width);\n maxY = Math.max(maxY, b.y + b.height);\n }\n if (!Number.isFinite(minX) || maxX <= minX || maxY <= minY) return null;\n return { x: minX, y: minY, width: maxX - minX, height: maxY - minY };\n}\n\ntype Rgba = readonly [number, number, number, number];\n\n/**\n * Corner colors blended at `(u, v)` in `space`.\n *\n * Bilinear as three lerps rather than four weights, because a perceptual space\n * has a midpoint between two colors and no meaningful four-way mix — OKLCh's\n * hue in particular is an arc, which only two endpoints define.\n */\nfunction colorAt(corners: Rgba[], u: number, v: number, space: ColorSpace): number[] {\n const bottom = lerpColorArray(corners[0], corners[1], u, space);\n const top = lerpColorArray(corners[3], corners[2], u, space);\n return lerpColorArray(bottom, top, v, space);\n}\n\n/**\n * Rasterize `patches` into a square bitmap covering their union.\n *\n * Returns `null` when no patch is drawable, which is the caller's cue to paint\n * nothing rather than a blank square.\n */\nexport function bakeMesh(\n patches: readonly MeshPatch[],\n space: ColorSpace = 'rgb',\n size: number = MESH_BAKE_SIZE,\n): BakedMesh | null {\n const box = meshBounds(patches);\n if (!box) return null;\n\n const pixels = new Uint8ClampedArray(size * size * 4);\n const grid = gridFor(size);\n // The box maps onto texel *centers*, not texel edges: a corner of the mesh\n // lands at the center of the corner texel, so the outermost row and column\n // are covered rather than half-missed by a rasterizer testing centers.\n const toTexel = (p: { x: number; y: number }): { x: number; y: number } => ({\n x: ((p.x - box.x) / box.width) * (size - 1) + 0.5,\n y: ((p.y - box.y) / box.height) * (size - 1) + 0.5,\n });\n\n for (const patch of patches) {\n if (!isValidPatch(patch)) continue;\n const corners = patch.colors.map((c) => resolveColor(c)) as Rgba[];\n\n for (let i = 0; i < grid; i++) {\n for (let j = 0; j < grid; j++) {\n const u0 = i / grid;\n const u1 = (i + 1) / grid;\n const v0 = j / grid;\n const v1 = (j + 1) / grid;\n const quad = [\n { at: toTexel(evalPatch(patch, u0, v0)), color: colorAt(corners, u0, v0, space) },\n { at: toTexel(evalPatch(patch, u1, v0)), color: colorAt(corners, u1, v0, space) },\n { at: toTexel(evalPatch(patch, u1, v1)), color: colorAt(corners, u1, v1, space) },\n { at: toTexel(evalPatch(patch, u0, v1)), color: colorAt(corners, u0, v1, space) },\n ];\n fillTriangle(pixels, size, quad[0], quad[1], quad[2]);\n fillTriangle(pixels, size, quad[0], quad[2], quad[3]);\n }\n }\n }\n\n return { pixels, size, box };\n}\n\ninterface Vertex {\n at: { x: number; y: number };\n color: number[];\n}\n\nconst EDGE_EPS = 1e-6;\n\n/**\n * One triangle, barycentric, colors interpolated across it.\n *\n * Neighboring cells share an edge, so a pixel exactly on one is claimed by\n * both — harmless here because both carry the same color there, and cheaper\n * than a fill rule.\n */\nfunction fillTriangle(\n pixels: Uint8ClampedArray, size: number, a: Vertex, b: Vertex, c: Vertex,\n): void {\n const minX = Math.max(0, Math.floor(Math.min(a.at.x, b.at.x, c.at.x)));\n const maxX = Math.min(size - 1, Math.ceil(Math.max(a.at.x, b.at.x, c.at.x)));\n const minY = Math.max(0, Math.floor(Math.min(a.at.y, b.at.y, c.at.y)));\n const maxY = Math.min(size - 1, Math.ceil(Math.max(a.at.y, b.at.y, c.at.y)));\n if (maxX < minX || maxY < minY) return;\n\n const area = (b.at.x - a.at.x) * (c.at.y - a.at.y) - (c.at.x - a.at.x) * (b.at.y - a.at.y);\n // A degenerate cell — a patch collapsed to a line — covers nothing.\n if (Math.abs(area) < 1e-9) return;\n\n for (let y = minY; y <= maxY; y++) {\n for (let x = minX; x <= maxX; x++) {\n const px = x + 0.5;\n const py = y + 0.5;\n const w0 = ((b.at.x - px) * (c.at.y - py) - (c.at.x - px) * (b.at.y - py)) / area;\n const w1 = ((c.at.x - px) * (a.at.y - py) - (a.at.x - px) * (c.at.y - py)) / area;\n const w2 = 1 - w0 - w1;\n // An edge texel's center sits exactly on the boundary, where rounding\n // can put it a hair outside; the epsilon is what keeps the border row\n // from dropping out.\n if (w0 < -EDGE_EPS || w1 < -EDGE_EPS || w2 < -EDGE_EPS) continue;\n const k = (y * size + x) * 4;\n for (let ch = 0; ch < 4; ch++) {\n pixels[k + ch] = (w0 * a.color[ch] + w1 * b.color[ch] + w2 * c.color[ch]) * 255;\n }\n }\n }\n}\n","/**\n * How large a mesh bake is, and the bounded cache the bakes live in.\n *\n * A gradient's ramp is one-dimensional, so 256 texels cover it at any size. A\n * mesh's bake is two-dimensional and is stretched over whatever the paint\n * covers, so a fixed size shows its texels once the paint draws large. The\n * bake is sized from the device pixels it covers instead, in power-of-two\n * buckets so a zoom inside one bucket reuses the bake it already has.\n */\n\nimport { MESH_BAKE_SIZE } from './bake';\n\n/** The smallest bake: below this a texture costs more in bookkeeping than in\n * bytes. */\nexport const MESH_BAKE_MIN = 32;\n\n/** The largest bake, whatever the context allows: 16 MiB of RGBA, and a bake\n * that already takes a noticeable moment on the CPU. */\nexport const MESH_BAKE_MAX = 2048;\n\n/** Bytes of baked texture one renderer keeps before evicting the least\n * recently drawn. */\nexport const MESH_BAKE_CACHE_BYTES = 64 * 1024 * 1024;\n\n/** Bakes one renderer keeps, however small, so a scene of many tiny meshes\n * cannot hold thousands of GL textures. */\nexport const MESH_BAKE_CACHE_ENTRIES = 256;\n\n/**\n * The bake side for a paint drawn `devicePx` device pixels across, on a\n * context accepting `maxTextureSize`: the next power of two at or above it,\n * clamped to `[MESH_BAKE_MIN, MESH_BAKE_MAX]` and to the context. A size that\n * cannot be measured gets `MESH_BAKE_SIZE`.\n */\nexport function meshBakeSize(devicePx: number, maxTextureSize: number): number {\n const ceiling = Math.min(MESH_BAKE_MAX, floorPow2(maxTextureSize));\n if (Number.isNaN(devicePx)) return Math.min(MESH_BAKE_SIZE, ceiling);\n if (devicePx <= MESH_BAKE_MIN) return Math.min(MESH_BAKE_MIN, ceiling);\n if (devicePx >= ceiling) return ceiling;\n return Math.min(ceiling, 2 ** Math.ceil(Math.log2(devicePx)));\n}\n\nfunction floorPow2(n: number): number {\n if (!(n >= 1)) return MESH_BAKE_MIN;\n if (!Number.isFinite(n)) return MESH_BAKE_MAX;\n return 2 ** Math.floor(Math.log2(n));\n}\n\ninterface Entry<T> {\n value: T;\n size: number;\n /** The paint's own bucket map, which is what eviction removes it from. */\n bySize: Map<number, Entry<T>>;\n}\n\n/**\n * Bakes keyed by paint and bake size, least recently used first out.\n *\n * The paint is held weakly, so a paint nobody draws any more does not pin its\n * key; its texture stays until eviction reaches it, which the bounds keep\n * finite. `free` runs for every value that leaves, by eviction, replacement or\n * `clear`.\n */\nexport class MeshBakeCache<T> {\n private readonly byPaint = new WeakMap<object, Map<number, Entry<T>>>();\n /** Insertion order is recency: a hit is deleted and re-added. */\n private readonly order = new Set<Entry<T>>();\n private held = 0;\n\n constructor(\n private readonly free: (value: T) => void,\n private readonly budgetBytes: number = MESH_BAKE_CACHE_BYTES,\n private readonly maxEntries: number = MESH_BAKE_CACHE_ENTRIES,\n ) {}\n\n /** Bytes the held bakes occupy, as RGBA8. */\n get bytes(): number { return this.held; }\n\n /** Bakes held. */\n get size(): number { return this.order.size; }\n\n get(paint: object, size: number): T | undefined {\n const entry = this.byPaint.get(paint)?.get(size);\n if (!entry) return undefined;\n this.order.delete(entry);\n this.order.add(entry);\n return entry.value;\n }\n\n set(paint: object, size: number, value: T): void {\n let bySize = this.byPaint.get(paint);\n if (!bySize) {\n bySize = new Map();\n this.byPaint.set(paint, bySize);\n }\n const old = bySize.get(size);\n if (old) this.drop(old);\n const entry: Entry<T> = { value, size, bySize };\n bySize.set(size, entry);\n this.order.add(entry);\n this.held += size * size * 4;\n this.evict(entry);\n }\n\n /** Free every bake. The cache stays usable. */\n clear(): void {\n for (const entry of [...this.order]) this.drop(entry);\n }\n\n /** Oldest first until both bounds hold, never evicting `keep` — the bake\n * the caller is about to draw. */\n private evict(keep: Entry<T>): void {\n for (const entry of this.order) {\n if (this.held <= this.budgetBytes && this.order.size <= this.maxEntries) return;\n if (entry !== keep) this.drop(entry);\n }\n }\n\n private drop(entry: Entry<T>): void {\n if (!this.order.delete(entry)) return;\n entry.bySize.delete(entry.size);\n this.held -= entry.size * entry.size * 4;\n this.free(entry.value);\n }\n}\n","/**\n * GLSL ES 3.0 sources for the mesh-gradient paint.\n *\n * The vertex stage is the pattern/gradient one: a path fill mesh carries\n * `a_position` only, so paint-space coordinates come back per fragment from\n * the screen position through `u_worldInv`. The fragment stage is a clamped\n * texture read of the baked mesh, with everything outside the bake's box\n * transparent — a mesh covers the area its patches cover, not the whole shape\n * it is filling, and a clamped read would otherwise smear its border colors\n * across the rest.\n *\n * `u_meshOrigin` / `u_meshSize` are the bake's box in paint space, and the\n * bake maps that box onto texel *centers*, which is the half-texel the uv\n * rescale accounts for.\n *\n * Output convention §2: PREMULTIPLIED alpha.\n */\n\n/** The id this program is registered under. */\nexport const MESH_PROGRAM_ID = 'kit:mesh-gradient';\n\nexport const MESH_VERT_SRC = /* glsl */ `#version 300 es\nin vec2 a_position;\nuniform mat3 u_proj;\nuniform mat3 u_model;\nuniform mat3 u_worldInv;\nout vec2 v_world;\nvoid main() {\n vec3 screen = u_model * vec3(a_position, 1.0);\n vec3 clip = u_proj * vec3(screen.xy, 1.0);\n gl_Position = vec4(clip.xy, 0.0, 1.0);\n vec3 world = u_worldInv * vec3(screen.xy, 1.0);\n v_world = world.xy;\n}\n`;\n\nexport const MESH_FRAG_SRC = /* glsl */ `#version 300 es\nprecision highp float;\nin vec2 v_world;\nuniform sampler2D u_sampler;\nuniform vec2 u_meshOrigin;\nuniform vec2 u_meshSize;\nuniform float u_opacity;\nuniform float u_alpha;\nout vec4 outColor;\nvoid main() {\n vec2 t =(v_world - u_meshOrigin) / max(u_meshSize, vec2(0.0001));\n if (t.x < 0.0 || t.x > 1.0 || t.y < 0.0 || t.y > 1.0) {\n outColor = vec4(0.0);\n return;\n }\n vec2 texels = vec2(textureSize(u_sampler, 0));\n vec2 uv = (t * (texels - 1.0) + 0.5) / texels;\n vec4 texel = texture(u_sampler, uv);\n float a = texel.a * u_opacity * u_alpha;\n outColor = vec4(texel.rgb * a, a);\n}\n`;\n\nexport const MESH_UNIFORMS = [\n 'u_proj', 'u_model', 'u_worldInv', 'u_sampler',\n 'u_meshOrigin', 'u_meshSize', 'u_opacity', 'u_alpha',\n] as const;\n\nexport const MESH_ATTRIBUTES = ['a_position'] as const;\n","/**\n * The `mesh-gradient` paint kind — PDF's shading types 6 and 7 as a registered\n * paint.\n *\n * A mesh gradient is a set of curved quadrilateral patches, each with a color\n * at every corner. It is the paint SVG tried to standardize as\n * `<meshgradient>` and abandoned, and the one PDF has had since 1993; what it\n * buys over the three gradients is a color field that bends, so a highlight\n * can follow a form instead of running straight across it.\n *\n * This is a registered kind rather than a sixth branch in the renderer, and\n * deliberately: it uses only the slots `registerPaintKind` gives a consumer, so\n * whatever it can do, a consumer's own kind can do too. Its one concession is\n * living in this package, because that is where the shader registry is.\n *\n * `docs/proposals/2026-09-17-paint-kinds-beyond-svg.md` is the design.\n */\n\nimport type { GradStop } from '@weasel-js/paint';\nimport type { PaintBindContext, PaintDrawKind, PaintProgram, PaintResources } from '../paintKinds';\nimport { resolveColor, rgbaToHex } from '@weasel-js/paint';\nimport { mat3 } from '@weasel-js/geom';\nimport { oklabToOklch, oklabToSrgbU8, oklchToOklab, srgbFloatToOklab } from '@weasel-js/paint';\nimport type { ColorSpace, FillStyle, GradientUnits } from '@weasel-js/paint';\nimport type { FillPoseBox } from '../fillInPoseFrame';\nimport { bakeMesh, meshBounds, type MeshBox } from './bake';\nimport { MeshBakeCache, meshBakeSize } from './bakeCache';\nimport { isValidPatch, type MeshPatch, type MeshPoint } from './surface';\nimport { MESH_FRAG_SRC, MESH_PROGRAM_ID, MESH_VERT_SRC } from './meshShader';\n\nexport type { MeshPatch, MeshPoint } from './surface';\n\n/**\n * A mesh gradient paint.\n *\n * `patches` are in the space `units` names, the same way a gradient's\n * geometry is — under `'bounds'` every point is a fraction of the painted\n * node's box, which is what lets the paint survive a resize.\n *\n * `interpolate` is the space corner colors blend through, matching the three\n * gradients. It is more visible here than there: a mesh blends in two\n * directions at once, so an sRGB blend's muddy middle covers area rather than\n * a line.\n */\nexport interface MeshGradientFill {\n fill: 'mesh-gradient';\n patches: MeshPatch[];\n units?: GradientUnits;\n interpolate?: ColorSpace;\n opacity?: number;\n}\n\n/** The kind's id, as `FillStyle['fill']` carries it. */\nexport const MESH_GRADIENT_KIND = 'mesh-gradient';\n\n/** A mesh paint, narrowed. */\nexport function isMeshGradientFill(fill: FillStyle | null | undefined): fill is FillStyle & MeshGradientFill {\n // `FillStyle`'s discriminant stays closed over the built-in kinds — see\n // `asPaint` — so a registered kind reads it widened.\n return fill != null && (fill.fill as string | undefined) === MESH_GRADIENT_KIND;\n}\n\nfunction asMesh(fill: FillStyle): MeshGradientFill {\n return fill as unknown as MeshGradientFill;\n}\n\n// `asPaint`'s cast, kept local: this module must import nothing from the\n// registry, whose state the lazy kind's self-contained copy would duplicate.\nfunction asFill(mesh: MeshGradientFill): FillStyle {\n return mesh as unknown as FillStyle;\n}\n\n/**\n * `color` moved in OKLCh — lightness, chroma and hue by the given deltas, with\n * its alpha kept. The seed's corners come from one color, and they have to\n * differ enough to read as a mesh rather than as a flat fill.\n */\nfunction shifted(color: string, dL: number, cScale: number, dHueDeg: number): string {\n const [r, g, b, a] = resolveColor(color);\n const [L, A, B] = srgbFloatToOklab(r, g, b);\n const [, C, h] = oklabToOklch(L, A, B);\n const [nL, nA, nB] = oklchToOklab(\n Math.min(1, Math.max(0, L + dL)),\n Math.max(0, C * cScale),\n h + (dHueDeg * Math.PI) / 180,\n );\n const [nr, ng, nb] = oklabToSrgbU8(nL, nA, nB);\n return rgbaToHex([nr / 255, ng / 255, nb / 255, a]);\n}\n\n/** A one-patch square covering the unit box, its four corners four readings of\n * `color` — a mesh seeded from a solid has to show *something* curved, or\n * switching kind looks like nothing happened. */\nexport function seedMeshPatch(color: string): MeshGradientFill {\n const corners: MeshPoint[] = [\n { x: 0, y: 0 }, { x: 1, y: 0 }, { x: 1, y: 1 }, { x: 0, y: 1 },\n ];\n const points: MeshPoint[] = [];\n for (let i = 0; i < 4; i++) {\n const a = corners[i];\n const b = corners[(i + 1) % 4];\n // Bow each edge outward by an eighth, so the seed is a patch and not a\n // rectangle wearing one's clothes.\n const nx = (b.y - a.y) * 0.125;\n const ny = -(b.x - a.x) * 0.125;\n points.push(\n a,\n { x: a.x + (b.x - a.x) / 3 + nx, y: a.y + (b.y - a.y) / 3 + ny },\n { x: a.x + (2 * (b.x - a.x)) / 3 + nx, y: a.y + (2 * (b.y - a.y)) / 3 + ny },\n );\n }\n return {\n fill: MESH_GRADIENT_KIND,\n patches: [{\n points,\n colors: [\n color,\n shifted(color, 0.14, 0.85, 0),\n shifted(color, -0.06, 1.1, 38),\n shifted(color, -0.16, 1.0, -22),\n ],\n }],\n units: 'bounds',\n };\n}\n\n/** The straight-edged patch covering `[x0, x1] × [0, 1]`, in walk order. */\nfunction bandPatch(x0: number, x1: number, left: string, right: string): MeshPatch {\n const corners: MeshPoint[] = [{ x: x0, y: 0 }, { x: x1, y: 0 }, { x: x1, y: 1 }, { x: x0, y: 1 }];\n const points: MeshPoint[] = [];\n for (let i = 0; i < 4; i++) {\n const a = corners[i];\n const b = corners[(i + 1) % 4];\n points.push(a, { x: a.x + (b.x - a.x) / 3, y: a.y + (b.y - a.y) / 3 }, { x: a.x + (2 * (b.x - a.x)) / 3, y: a.y + (2 * (b.y - a.y)) / 3 });\n }\n return { points, colors: [left, right, right, left] };\n}\n\n/**\n * A stop list as a mesh: one full-height band per gap between neighboring\n * stops, colored left to right. The bands blend exactly the way the ramp\n * does, so a horizontal gradient survives the switch unchanged. A zero-width\n * gap is a hard break and gets no band.\n */\nexport function meshFromStops(stops: readonly GradStop[]): MeshGradientFill {\n const sorted = [...stops].sort((a, b) => a.offset - b.offset);\n if (sorted.length === 1) sorted.push({ offset: 1, color: sorted[0].color });\n if (sorted.length === 0) return seedMeshPatch('#000000ff');\n const patches: MeshPatch[] = [];\n for (let i = 0; i < sorted.length - 1; i++) {\n const a = sorted[i];\n const b = sorted[i + 1];\n if (b.offset > a.offset) patches.push(bandPatch(a.offset, b.offset, a.color, b.color));\n }\n return { fill: MESH_GRADIENT_KIND, patches, units: 'bounds' };\n}\n\n/**\n * A mesh read as a stop list: every patch's top edge — corner 0 to corner 1 —\n * placed by its `x` across the mesh's horizontal extent. The inverse of\n * `meshFromStops`, and for any other mesh the ramp across its top.\n */\nexport function meshStops(mesh: MeshGradientFill): GradStop[] {\n const valid = mesh.patches.filter(isValidPatch);\n if (valid.length === 0) return [];\n const xs = valid.flatMap((p) => [p.points[0].x, p.points[3].x]);\n const lo = Math.min(...xs);\n const span = Math.max(...xs) - lo;\n const offsetOf = (x: number) => (span > 0 ? (x - lo) / span : 0);\n const stops: GradStop[] = [];\n for (const patch of valid) {\n for (const [point, color] of [[patch.points[0], patch.colors[0]], [patch.points[3], patch.colors[1]]] as const) {\n const offset = offsetOf(point.x);\n if (!stops.some((s) => s.offset === offset && s.color === color)) stops.push({ offset, color });\n }\n }\n return stops.sort((a, b) => a.offset - b.offset);\n}\n\n/** Every patch mapped through `move`. */\nfunction mapPatches(mesh: MeshGradientFill, move: (p: MeshPoint) => MeshPoint): MeshPatch[] {\n return mesh.patches.map((patch) => ({ ...patch, points: patch.points.map(move) }));\n}\n\n// ─── The bake cache ─────────────────────────────────────────────────────────\n//\n// A kind owns its own GPU state; the registry hands it a `gl` and a resource\n// lifetime. One cache per lifetime, so two renderers — or one renderer past a\n// context restore — never trade textures, and the lifetime's end frees them.\n\ninterface CachedBake {\n texture: WebGLTexture;\n /** Where the mesh being bound sits in paint space. The texels are shared by\n * every pose-frame copy of one paint; the box is each copy's own. */\n box: MeshBox;\n}\n\n/** The paint a pose-frame copy was made from. A copy is rebuilt whenever its\n * node's pose changes, and bakes the same texels as its source. */\nconst BAKE_SOURCE = new WeakMap<object, object>();\n\nconst CACHES = new WeakMap<PaintResources, MeshBakeCache<WebGLTexture>>();\n\nfunction cacheFor(ctx: PaintBindContext): MeshBakeCache<WebGLTexture> {\n let cache = CACHES.get(ctx.resources);\n if (!cache) {\n const gl = ctx.gl;\n const made = new MeshBakeCache<WebGLTexture>((texture) => gl.deleteTexture(texture));\n ctx.resources.onRelease(() => {\n made.clear();\n CACHES.delete(ctx.resources);\n });\n CACHES.set(ctx.resources, made);\n cache = made;\n }\n return cache;\n}\n\n/** Device pixels the larger side of `box` covers when drawn in `units`. */\nfunction devicePixelsOf(ctx: PaintBindContext, mesh: MeshGradientFill, box: MeshBox): number {\n const m = ctx.spaceToDevice(mesh.units);\n if (!m) return Number.NaN;\n return Math.max(box.width * Math.hypot(m[0], m[1]), box.height * Math.hypot(m[3], m[4]));\n}\n\nfunction bakeFor(ctx: PaintBindContext, mesh: MeshGradientFill): CachedBake | null {\n const box = meshBounds(mesh.patches);\n if (!box) return null;\n const size = meshBakeSize(devicePixelsOf(ctx, mesh, box), ctx.maxTextureSize);\n\n const cache = cacheFor(ctx);\n const key = BAKE_SOURCE.get(mesh) ?? mesh;\n const hit = cache.get(key, size);\n if (hit) return { texture: hit, box };\n\n const baked = bakeMesh(mesh.patches, mesh.interpolate ?? 'rgb', size);\n if (!baked) return null;\n\n const gl = ctx.gl;\n const texture = gl.createTexture();\n if (!texture) return null;\n gl.bindTexture(gl.TEXTURE_2D, texture);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);\n gl.texImage2D(\n gl.TEXTURE_2D, 0, gl.RGBA,\n baked.size, baked.size, 0,\n gl.RGBA, gl.UNSIGNED_BYTE, baked.pixels,\n );\n gl.bindTexture(gl.TEXTURE_2D, null);\n\n cache.set(key, size, texture);\n return { texture, box };\n}\n\nfunction bindMesh(ctx: PaintBindContext, fill: FillStyle): PaintProgram | null {\n const mesh = asMesh(fill);\n if (!mesh.patches.some(isValidPatch)) return null;\n\n const inverse = ctx.spaceInverse(mesh.units);\n if (!inverse) return null;\n\n const program = ctx.program(MESH_PROGRAM_ID);\n if (!program) return null;\n\n const entry = bakeFor(ctx, mesh);\n if (!entry) return null;\n\n const gl = ctx.gl;\n gl.useProgram(program.handle);\n ctx.setProjAndModel(program);\n gl.uniformMatrix3fv(program.uniform('u_worldInv')!, false, mat3.toUniform(inverse));\n\n gl.activeTexture(gl.TEXTURE0);\n gl.bindTexture(gl.TEXTURE_2D, entry.texture);\n gl.uniform1i(program.uniform('u_sampler')!, 0);\n\n const { box } = entry;\n gl.uniform2f(program.uniform('u_meshOrigin')!, box.x, box.y);\n gl.uniform2f(program.uniform('u_meshSize')!, box.width, box.height);\n gl.uniform1f(program.uniform('u_opacity')!, mesh.opacity ?? 1);\n gl.uniform1f(program.uniform('u_alpha')!, ctx.alpha);\n return program;\n}\n\n/** The kind's draw half, shader program included. Core adds the editor's\n * slots and registers the whole entry. */\nexport const meshDrawKind: PaintDrawKind = {\n id: MESH_GRADIENT_KIND,\n programs: { [MESH_PROGRAM_ID]: { vert: MESH_VERT_SRC, frag: MESH_FRAG_SRC } },\n bind: bindMesh,\n inPoseFrame: (fill, box: FillPoseBox) => {\n const mesh = asMesh(fill);\n if (mesh.units !== 'bounds') return fill;\n const posed = asFill({\n ...mesh,\n patches: mapPatches(mesh, (p) => ({\n x: box.x + p.x * box.width,\n y: box.y + p.y * box.height,\n })),\n units: 'local' as const,\n });\n BAKE_SOURCE.set(posed, fill);\n return posed;\n },\n toBoundsFrame: (fill, box: FillPoseBox) => {\n const mesh = asMesh(fill);\n if (mesh.units === 'bounds' || box.width === 0 || box.height === 0) return fill;\n return asFill({\n ...mesh,\n patches: mapPatches(mesh, (p) => ({\n x: (p.x - box.x) / box.width,\n y: (p.y - box.y) / box.height,\n })),\n units: 'bounds' as const,\n });\n },\n};\n\n/**\n * The `<defs>` entry for a mesh paint, in weasel's own namespace.\n *\n * Not SVG's abandoned `<meshgradient>`: that vocabulary only reaches Coons\n * patches, shares patch edges implicitly — a reader that gets the sharing\n * wrong tears the surface rather than failing outright — and has exactly one\n * implementation in the world. Ours writes every patch's points in full.\n * `@weasel-js/svg` puts the paint fallback color beside the reference, so a\n * foreign renderer paints flat instead of nothing.\n */\nexport function meshGradientXml(id: string, mesh: MeshGradientFill): string {\n const P = 'wzl';\n const units = mesh.units === 'bounds' ? 'objectBoundingBox' : 'userSpaceOnUse';\n const space = mesh.interpolate && mesh.interpolate !== 'rgb'\n ? ` interpolate=\"${mesh.interpolate}\"` : '';\n const patches = mesh.patches.map((patch) => {\n const points = patch.points.map((p) => `${trim(p.x)},${trim(p.y)}`).join(' ');\n const colors = patch.colors.join(' ');\n return `<${P}:patch points=\"${points}\" colors=\"${colors}\"/>`;\n }).join('');\n return (\n `<${P}:meshGradient id=\"${id}\" gradientUnits=\"${units}\"${space}>` +\n `${patches}</${P}:meshGradient>`\n );\n}\n\n/** Short decimals, matching what `@weasel-js/svg` writes elsewhere. */\nfunction trim(n: number): string {\n return Number.isInteger(n) ? String(n) : String(Number(n.toFixed(4)));\n}\n","/**\n * The draggable points of a mesh paint, as pure geometry — what an on-canvas\n * editor lists, and what moving one of them does to the paint.\n *\n * Nothing here knows a frame: the handles are in whatever space the mesh's\n * points are, so a caller resolves a `'bounds'` mesh onto its box first\n * (`fillInPoseFrame`) and normalizes the result back (`fillToBoundsFrame`).\n */\n\nimport type { MeshGradientFill } from './meshPaint';\nimport { isTensorPatch, isValidPatch, type MeshPatch, type MeshPoint } from './surface';\n\n/** What a handle moves: a patch corner, one of the two controls of an edge,\n * or one of a tensor patch's four interior points. */\nexport type MeshHandleKind = 'corner' | 'control' | 'interior';\n\n/** One stored point: `patches[patch].points[index]`. */\nexport interface MeshPointRef {\n patch: number;\n index: number;\n}\n\n/**\n * One draggable point.\n *\n * Patches store their points in full rather than sharing edges, so two\n * patches that meet each carry a copy of the corner and controls they meet\n * at. Those copies are one handle, with a `ref` per copy — dragging one of\n * them alone would tear the surface open along the seam.\n */\nexport interface MeshHandle {\n /** Stable while the handle moves: its first ref, as `\"patch:index\"`. */\n id: string;\n kind: MeshHandleKind;\n at: MeshPoint;\n refs: readonly MeshPointRef[];\n}\n\n/** Corner `k`'s interior neighbor in the tensor net. PDF's trailing four walk\n * the net as (1,1) (1,2) (2,2) (2,1), which puts corner 1's at index 15 and\n * corner 3's at 13 — the transpose of the obvious reading. */\nconst INTERIOR_OF_CORNER = [12, 15, 14, 13] as const;\n\nfunction kindOf(index: number): MeshHandleKind {\n if (index >= 12) return 'interior';\n return index % 3 === 0 ? 'corner' : 'control';\n}\n\nfunction near(a: number, b: number): boolean {\n return Math.abs(a - b) <= 1e-9 * Math.max(1, Math.abs(a), Math.abs(b));\n}\n\nfunction same(a: MeshPoint, b: MeshPoint): boolean {\n return near(a.x, b.x) && near(a.y, b.y);\n}\n\n/**\n * Every draggable point of `mesh`, in walk order: each patch's corners and\n * edge controls, then a tensor patch's interior. Coincident points of one\n * kind merge into one handle. A patch that cannot be evaluated has none.\n */\nexport function meshHandles(mesh: MeshGradientFill): MeshHandle[] {\n const handles: { id: string; kind: MeshHandleKind; at: MeshPoint; refs: MeshPointRef[] }[] = [];\n mesh.patches.forEach((patch, p) => {\n if (!isValidPatch(patch)) return;\n patch.points.forEach((at, index) => {\n const kind = kindOf(index);\n const twin = handles.find((h) => h.kind === kind && same(h.at, at));\n if (twin) twin.refs.push({ patch: p, index });\n else handles.push({ id: `${p}:${index}`, kind, at, refs: [{ patch: p, index }] });\n });\n });\n return handles;\n}\n\n/** The points a corner carries: the controls of the two edges it joins, and\n * its interior neighbor when the patch has one. */\nfunction carriedBy(patch: MeshPatch, corner: number): number[] {\n const k = corner / 3;\n const carried = [corner + 1, (corner + 11) % 12];\n if (isTensorPatch(patch)) carried.push(INTERIOR_OF_CORNER[k]);\n return carried;\n}\n\n/**\n * `mesh` with `handle` moved to `to`. A corner carries its edge controls\n * and interior neighbor along by the same offset, the way a path editor's\n * anchor carries its handles; a control or interior point moves alone.\n * Returns a new paint; `mesh` is not modified.\n */\nexport function moveMeshHandle(\n mesh: MeshGradientFill, handle: MeshHandle, to: MeshPoint,\n): MeshGradientFill {\n const dx = to.x - handle.at.x;\n const dy = to.y - handle.at.y;\n const placed = new Map<string, MeshPoint>();\n for (const { patch, index } of handle.refs) {\n placed.set(`${patch}:${index}`, to);\n }\n if (handle.kind === 'corner') {\n for (const { patch, index } of handle.refs) {\n for (const carried of carriedBy(mesh.patches[patch], index)) {\n const key = `${patch}:${carried}`;\n if (placed.has(key)) continue;\n const from = mesh.patches[patch].points[carried];\n placed.set(key, { x: from.x + dx, y: from.y + dy });\n }\n }\n }\n return {\n ...mesh,\n patches: mesh.patches.map((patch, p) => ({\n ...patch,\n points: patch.points.map((point, i) => placed.get(`${p}:${i}`) ?? point),\n })),\n };\n}\n\n/** The lines an editor draws under the handles, as control polygons. */\nexport interface MeshGuides {\n /** Every patch edge as its four cubic control points, from the corner it\n * leaves to the corner it reaches. */\n edges: [MeshPoint, MeshPoint, MeshPoint, MeshPoint][];\n /** Corner to each point it carries — an edge control or interior point. */\n arms: [MeshPoint, MeshPoint][];\n}\n\n/** The guides for `mesh`'s valid patches. Shared edges appear once per patch. */\nexport function meshGuides(mesh: MeshGradientFill): MeshGuides {\n const edges: MeshGuides['edges'] = [];\n const arms: MeshGuides['arms'] = [];\n for (const patch of mesh.patches) {\n if (!isValidPatch(patch)) continue;\n const p = patch.points;\n for (let k = 0; k < 4; k++) {\n const corner = k * 3;\n edges.push([p[corner], p[corner + 1], p[corner + 2], p[(corner + 3) % 12]]);\n for (const carried of carriedBy(patch, corner)) arms.push([p[corner], p[carried]]);\n }\n }\n return { edges, arms };\n}\n"]}
1
+ {"version":3,"sources":["../src/meshPaint/surface.ts","../src/meshPaint/bake.ts","../src/meshPaint/bakeCache.ts","../src/meshPaint/meshShader.ts","../src/meshPaint/meshPaint.ts","../src/meshPaint/handles.ts"],"names":["resolveColor"],"mappings":";;;;;;AAiCO,SAAS,WAAA,CAAY,OAA2B,CAAA,EAAsB;AAC3E,EAAA,OAAO,KAAA,CAAM,MAAA,CAAA,CAAQ,CAAA,GAAI,CAAA,IAAK,CAAC,CAAA;AACjC;AAGO,SAAS,cAAc,KAAA,EAAoC;AAChE,EAAA,OAAO,KAAA,CAAM,OAAO,MAAA,IAAU,EAAA;AAChC;AAIO,SAAS,aAAa,KAAA,EAAoC;AAC/D,EAAA,OAAO,MAAM,MAAA,CAAO,MAA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,CAAM,MAAA,CAAO,GAAA,CAAI,CAAC,KAAA,EAAO,CAAA,KAAM,MAAA,CAAO,GAAA,CAAI,GAAG,CAAC,CAAA,CAAA,EAAI,CAAC,CAAA,CAAE,KAAK,KAAK;AAAA,KACzE,CAAE;AAAA,GACJ;AACF;AAYO,SAAS,WAAW,IAAA,EAAqC;AAC9D,EAAA,MAAM,QAA6B,EAAC;AACpC,EAAA,MAAM,OAA2B,EAAC;AAClC,EAAA,KAAA,MAAW,KAAA,IAAS,KAAK,OAAA,EAAS;AAChC,IAAA,IAAI,CAAC,YAAA,CAAa,KAAK,CAAA,EAAG;AAC1B,IAAA,MAAM,IAAI,KAAA,CAAM,MAAA;AAChB,IAAA,KAAA,IAAS,CAAA,GAAI,CAAA,EAAG,CAAA,GAAI,CAAA,EAAG,CAAA,EAAA,EAAK;AAC1B,MAAA,MAAM,SAAS,CAAA,GAAI,CAAA;AACnB,MAAA,KAAA,CAAM,KAAK,CAAC,CAAA,CAAE,MAAM,CAAA,EAAG,CAAA,CAAE,SAAS,CAAC,CAAA,EAAG,CAAA,CAAE,MAAA,GAAS,CAAC,CAAA,EAAG,CAAA,CAAA,CAAG,SAAS,CAAA,IAAK,EAAE,CAAC,CAAC,CAAA;AAC1E,MAAA,KAAA,MAAW,OAAA,IAAW,SAAA,CAAU,KAAA,EAAO,MAAM,GAAG,IAAA,CAAK,IAAA,CAAK,CAAC,CAAA,CAAE,MAAM,CAAA,EAAG,CAAA,CAAE,OAAO,CAAC,CAAC,CAAA;AAAA,IACnF;AAAA,EACF;AACA,EAAA,OAAO,EAAE,OAAO,IAAA,EAAK;AACvB","file":"mesh.js","sourcesContent":["/**\n * Coons and tensor-product patch surfaces — PDF's shading types 6 and 7, as\n * pure geometry.\n *\n * A patch is a curved quadrilateral: four cubic Bézier edges and a color at\n * each corner. A Coons patch reads its interior off the boundary alone; a\n * tensor patch adds four interior control points that pull it around.\n */\n\n/** A point in the patch's own space. */\nexport interface MeshPoint {\n x: number;\n y: number;\n}\n\n/**\n * One patch.\n *\n * `points` walks the boundary: corner 0, the two control points of the edge\n * leaving it, corner 1, its two, and so on — twelve points, ending with the\n * two controls that return to corner 0. A tensor patch appends its four\n * interior points, in the order `(1,1)`, `(1,2)`, `(2,2)`, `(2,1)` of the\n * bicubic control net, which is PDF's own order. Twelve points is a Coons\n * patch and sixteen is a tensor patch.\n *\n * `colors` are the corner colors in the same walk order.\n */\nexport interface MeshPatch<TColor = string> {\n points: readonly MeshPoint[];\n colors: readonly [TColor, TColor, TColor, TColor];\n}\n\n/** Corner `i` of the boundary walk. */\nexport function patchCorner(patch: MeshPatch<unknown>, i: number): MeshPoint {\n return patch.points[(i & 3) * 3];\n}\n\n/** `true` when the patch carries the four interior points a tensor patch adds. */\nexport function isTensorPatch(patch: MeshPatch<unknown>): boolean {\n return patch.points.length >= 16;\n}\n\n/** A patch is twelve boundary points, or sixteen with the interior. Anything\n * else cannot be evaluated, and saying so here beats painting nonsense. */\nexport function isValidPatch(patch: MeshPatch<unknown>): boolean {\n return patch.points.length === 12 || patch.points.length === 16;\n}\n\nfunction bezier(p0: MeshPoint, p1: MeshPoint, p2: MeshPoint, p3: MeshPoint, t: number): MeshPoint {\n const s = 1 - t;\n const a = s * s * s;\n const b = 3 * s * s * t;\n const c = 3 * s * t * t;\n const d = t * t * t;\n return {\n x: a * p0.x + b * p1.x + c * p2.x + d * p3.x,\n y: a * p0.y + b * p1.y + c * p2.y + d * p3.y,\n };\n}\n\n/** The edge leaving corner `i`, as its four control points. */\nfunction edge(patch: MeshPatch<unknown>, i: number): [MeshPoint, MeshPoint, MeshPoint, MeshPoint] {\n const p = patch.points;\n const a = (i & 3) * 3;\n return [p[a], p[a + 1], p[a + 2], p[((i + 1) & 3) * 3]];\n}\n\n/**\n * The patch surface at `(u, v)`, both in `0..1`.\n *\n * `u` runs along the edge leaving corner 0 and `v` along the edge leaving\n * corner 1, so `(0,0)` is corner 0, `(1,0)` corner 1, `(1,1)` corner 2 and\n * `(0,1)` corner 3 — the same walk `colors` is in.\n */\nexport function evalPatch(patch: MeshPatch<unknown>, u: number, v: number): MeshPoint {\n return isTensorPatch(patch) ? evalTensor(patch, u, v) : evalCoons(patch, u, v);\n}\n\nfunction evalCoons(patch: MeshPatch<unknown>, u: number, v: number): MeshPoint {\n const [b0, b1, b2, b3] = edge(patch, 0); // corner 0 → 1, along u at v=0\n const [r0, r1, r2, r3] = edge(patch, 1); // corner 1 → 2, along v at u=1\n const [t0, t1, t2, t3] = edge(patch, 2); // corner 2 → 3, along u at v=1\n const [l0, l1, l2, l3] = edge(patch, 3); // corner 3 → 0, along v at u=0\n\n const bottom = bezier(b0, b1, b2, b3, u);\n const top = bezier(t0, t1, t2, t3, 1 - u); // walks 2 → 3, so reverse it\n const right = bezier(r0, r1, r2, r3, v);\n const left = bezier(l0, l1, l2, l3, 1 - v); // walks 3 → 0, so reverse it\n\n const c0 = patchCorner(patch, 0);\n const c1 = patchCorner(patch, 1);\n const c2 = patchCorner(patch, 2);\n const c3 = patchCorner(patch, 3);\n\n // The Coons construction: the two ruled surfaces between opposite edges,\n // minus the bilinear surface through the corners they both already carry.\n const ruledU = (a: number, b: number): number => (1 - v) * a + v * b;\n const ruledV = (a: number, b: number): number => (1 - u) * a + u * b;\n const corner = (k0: number, k1: number, k2: number, k3: number): number =>\n (1 - u) * (1 - v) * k0 + u * (1 - v) * k1 + u * v * k2 + (1 - u) * v * k3;\n\n return {\n x: ruledU(bottom.x, top.x) + ruledV(left.x, right.x)\n - corner(c0.x, c1.x, c2.x, c3.x),\n y: ruledU(bottom.y, top.y) + ruledV(left.y, right.y)\n - corner(c0.y, c1.y, c2.y, c3.y),\n };\n}\n\n/** The bicubic control net a tensor patch's sixteen points make, as\n * `net[i][j]` with `i` along `u` and `j` along `v`. */\nfunction tensorNet(patch: MeshPatch<unknown>): MeshPoint[][] {\n const p = patch.points;\n // Boundary, read off the same walk; interior from the four trailing points.\n return [\n [p[0], p[11], p[10], p[9]],\n [p[1], p[12], p[13], p[8]],\n [p[2], p[15], p[14], p[7]],\n [p[3], p[4], p[5], p[6]],\n ];\n}\n\nconst BERNSTEIN = (t: number): [number, number, number, number] => {\n const s = 1 - t;\n return [s * s * s, 3 * s * s * t, 3 * s * t * t, t * t * t];\n};\n\nfunction evalTensor(patch: MeshPatch<unknown>, u: number, v: number): MeshPoint {\n const net = tensorNet(patch);\n const bu = BERNSTEIN(u);\n const bv = BERNSTEIN(v);\n let x = 0;\n let y = 0;\n for (let i = 0; i < 4; i++) {\n for (let j = 0; j < 4; j++) {\n const w = bu[i] * bv[j];\n x += w * net[i][j].x;\n y += w * net[i][j].y;\n }\n }\n return { x, y };\n}\n\n/**\n * The four corner weights at `(u, v)` — bilinear, in the corner walk order.\n */\nexport function cornerWeights(u: number, v: number): [number, number, number, number] {\n return [(1 - u) * (1 - v), u * (1 - v), u * v, (1 - u) * v];\n}\n\n/** Axis-aligned bounds of a patch, sampled on a grid: control points alone\n * bound a Bézier but not tightly. */\nexport function patchBounds(\n patch: MeshPatch<unknown>, steps = 8,\n): { x: number; y: number; width: number; height: number } {\n let minX = Infinity;\n let minY = Infinity;\n let maxX = -Infinity;\n let maxY = -Infinity;\n for (let i = 0; i <= steps; i++) {\n for (let j = 0; j <= steps; j++) {\n const p = evalPatch(patch, i / steps, j / steps);\n if (p.x < minX) minX = p.x;\n if (p.y < minY) minY = p.y;\n if (p.x > maxX) maxX = p.x;\n if (p.y > maxY) maxY = p.y;\n }\n }\n return { x: minX, y: minY, width: maxX - minX, height: maxY - minY };\n}\n","/**\n * A mesh paint baked into one RGBA bitmap: each patch is subdivided into small\n * quads and rasterized forward, once per paint, into a texture the shader then\n * samples. Inverting a bicubic per fragment would be Newton iteration.\n *\n * The bitmap is straight (non-premultiplied) RGBA; the fragment shader\n * premultiplies.\n */\n\nimport { resolveColor } from '@weasel-js/paint';\nimport { lerpColorArray, type ColorSpace } from '@weasel-js/paint';\nimport { evalPatch, isValidPatch, patchBounds, type MeshPatch } from './surface';\n\n/** Texels on a side of a bake when the caller names no size. The renderer\n * sizes each bake from how large the paint draws — see `meshBakeSize`. */\nexport const MESH_BAKE_SIZE = 256;\n\n/** Texels a rasterized cell spans at most. The rasterizer interpolates color\n * linearly inside a cell and draws a curved edge as its chord, so this is\n * what keeps a perceptual blend perceptual and an edge curved at any size. */\nconst TEXELS_PER_CELL = 10;\n\n/** Quads per patch on a side, never fewer than 24. */\nfunction gridFor(size: number): number {\n return Math.max(24, Math.ceil(size / TEXELS_PER_CELL));\n}\n\n/** The box a bake covers, in the paint's own space. */\nexport interface MeshBox {\n x: number;\n y: number;\n width: number;\n height: number;\n}\n\n/** The bitmap `bakeMesh` produces, and the paint-space box it covers. */\nexport interface BakedMesh {\n /** `size` × `size` texels, straight RGBA. */\n pixels: Uint8ClampedArray;\n /** Texels on a side; `MESH_BAKE_SIZE` unless the caller asked otherwise. */\n size: number;\n /** Where the bitmap sits in paint space, which is what the shader maps a\n * fragment through. */\n box: MeshBox;\n}\n\n/** The union of every patch's bounds, or `null` when nothing is drawable. */\nexport function meshBounds(patches: readonly MeshPatch[]): MeshBox | null {\n let minX = Infinity;\n let minY = Infinity;\n let maxX = -Infinity;\n let maxY = -Infinity;\n for (const patch of patches) {\n if (!isValidPatch(patch)) continue;\n const b = patchBounds(patch);\n minX = Math.min(minX, b.x);\n minY = Math.min(minY, b.y);\n maxX = Math.max(maxX, b.x + b.width);\n maxY = Math.max(maxY, b.y + b.height);\n }\n if (!Number.isFinite(minX) || maxX <= minX || maxY <= minY) return null;\n return { x: minX, y: minY, width: maxX - minX, height: maxY - minY };\n}\n\ntype Rgba = readonly [number, number, number, number];\n\n/**\n * Corner colors blended at `(u, v)` in `space`. Three lerps rather than four\n * weights, because a perceptual space has no meaningful four-way mix — OKLCh's\n * hue is an arc, which only two endpoints define.\n */\nfunction colorAt(corners: Rgba[], u: number, v: number, space: ColorSpace): number[] {\n const bottom = lerpColorArray(corners[0], corners[1], u, space);\n const top = lerpColorArray(corners[3], corners[2], u, space);\n return lerpColorArray(bottom, top, v, space);\n}\n\n/**\n * Rasterize `patches` into a square bitmap covering their union, or `null`\n * when no patch is drawable.\n */\nexport function bakeMesh(\n patches: readonly MeshPatch[],\n space: ColorSpace = 'rgb',\n size: number = MESH_BAKE_SIZE,\n): BakedMesh | null {\n const box = meshBounds(patches);\n if (!box) return null;\n\n const pixels = new Uint8ClampedArray(size * size * 4);\n const grid = gridFor(size);\n // The box maps onto texel *centers*, not texel edges: a corner of the mesh\n // lands at the center of the corner texel, so the outermost row and column\n // are covered rather than half-missed by a rasterizer testing centers.\n const toTexel = (p: { x: number; y: number }): { x: number; y: number } => ({\n x: ((p.x - box.x) / box.width) * (size - 1) + 0.5,\n y: ((p.y - box.y) / box.height) * (size - 1) + 0.5,\n });\n\n for (const patch of patches) {\n if (!isValidPatch(patch)) continue;\n const corners = patch.colors.map((c) => resolveColor(c)) as Rgba[];\n\n for (let i = 0; i < grid; i++) {\n for (let j = 0; j < grid; j++) {\n const u0 = i / grid;\n const u1 = (i + 1) / grid;\n const v0 = j / grid;\n const v1 = (j + 1) / grid;\n const quad = [\n { at: toTexel(evalPatch(patch, u0, v0)), color: colorAt(corners, u0, v0, space) },\n { at: toTexel(evalPatch(patch, u1, v0)), color: colorAt(corners, u1, v0, space) },\n { at: toTexel(evalPatch(patch, u1, v1)), color: colorAt(corners, u1, v1, space) },\n { at: toTexel(evalPatch(patch, u0, v1)), color: colorAt(corners, u0, v1, space) },\n ];\n fillTriangle(pixels, size, quad[0], quad[1], quad[2]);\n fillTriangle(pixels, size, quad[0], quad[2], quad[3]);\n }\n }\n }\n\n return { pixels, size, box };\n}\n\ninterface Vertex {\n at: { x: number; y: number };\n color: number[];\n}\n\nconst EDGE_EPS = 1e-6;\n\n/**\n * One triangle, barycentric, colors interpolated across it. A pixel exactly on\n * an edge two cells share is claimed by both — harmless, because both carry\n * the same color there.\n */\nfunction fillTriangle(\n pixels: Uint8ClampedArray, size: number, a: Vertex, b: Vertex, c: Vertex,\n): void {\n const minX = Math.max(0, Math.floor(Math.min(a.at.x, b.at.x, c.at.x)));\n const maxX = Math.min(size - 1, Math.ceil(Math.max(a.at.x, b.at.x, c.at.x)));\n const minY = Math.max(0, Math.floor(Math.min(a.at.y, b.at.y, c.at.y)));\n const maxY = Math.min(size - 1, Math.ceil(Math.max(a.at.y, b.at.y, c.at.y)));\n if (maxX < minX || maxY < minY) return;\n\n const area = (b.at.x - a.at.x) * (c.at.y - a.at.y) - (c.at.x - a.at.x) * (b.at.y - a.at.y);\n // A degenerate cell — a patch collapsed to a line — covers nothing.\n if (Math.abs(area) < 1e-9) return;\n\n for (let y = minY; y <= maxY; y++) {\n for (let x = minX; x <= maxX; x++) {\n const px = x + 0.5;\n const py = y + 0.5;\n const w0 = ((b.at.x - px) * (c.at.y - py) - (c.at.x - px) * (b.at.y - py)) / area;\n const w1 = ((c.at.x - px) * (a.at.y - py) - (a.at.x - px) * (c.at.y - py)) / area;\n const w2 = 1 - w0 - w1;\n // An edge texel's center sits exactly on the boundary, where rounding\n // can put it a hair outside; the epsilon is what keeps the border row\n // from dropping out.\n if (w0 < -EDGE_EPS || w1 < -EDGE_EPS || w2 < -EDGE_EPS) continue;\n const k = (y * size + x) * 4;\n for (let ch = 0; ch < 4; ch++) {\n pixels[k + ch] = (w0 * a.color[ch] + w1 * b.color[ch] + w2 * c.color[ch]) * 255;\n }\n }\n }\n}\n","/**\n * How large a mesh bake is, and the bounded cache the bakes live in.\n *\n * A gradient's ramp is one-dimensional, so 256 texels cover it at any size. A\n * mesh's bake is two-dimensional and is stretched over whatever the paint\n * covers, so a fixed size shows its texels once the paint draws large. The\n * bake is sized from the device pixels it covers instead, in power-of-two\n * buckets so a zoom inside one bucket reuses the bake it already has.\n */\n\nimport { MESH_BAKE_SIZE } from './bake';\n\n/** The smallest bake: below this a texture costs more in bookkeeping than in\n * bytes. */\nexport const MESH_BAKE_MIN = 32;\n\n/** The largest bake, whatever the context allows: 16 MiB of RGBA, and a bake\n * that already takes a noticeable moment on the CPU. */\nexport const MESH_BAKE_MAX = 2048;\n\n/** Bytes of baked texture one renderer keeps before evicting the least\n * recently drawn. */\nexport const MESH_BAKE_CACHE_BYTES = 64 * 1024 * 1024;\n\n/** Bakes one renderer keeps, however small, so a scene of many tiny meshes\n * cannot hold thousands of GL textures. */\nexport const MESH_BAKE_CACHE_ENTRIES = 256;\n\n/**\n * The bake side for a paint drawn `devicePx` device pixels across, on a\n * context accepting `maxTextureSize`: the next power of two at or above it,\n * clamped to `[MESH_BAKE_MIN, MESH_BAKE_MAX]` and to the context. A size that\n * cannot be measured gets `MESH_BAKE_SIZE`.\n */\nexport function meshBakeSize(devicePx: number, maxTextureSize: number): number {\n const ceiling = Math.min(MESH_BAKE_MAX, floorPow2(maxTextureSize));\n if (Number.isNaN(devicePx)) return Math.min(MESH_BAKE_SIZE, ceiling);\n if (devicePx <= MESH_BAKE_MIN) return Math.min(MESH_BAKE_MIN, ceiling);\n if (devicePx >= ceiling) return ceiling;\n return Math.min(ceiling, 2 ** Math.ceil(Math.log2(devicePx)));\n}\n\nfunction floorPow2(n: number): number {\n if (!(n >= 1)) return MESH_BAKE_MIN;\n if (!Number.isFinite(n)) return MESH_BAKE_MAX;\n return 2 ** Math.floor(Math.log2(n));\n}\n\ninterface Entry<T> {\n value: T;\n size: number;\n /** The paint's own bucket map, which is what eviction removes it from. */\n bySize: Map<number, Entry<T>>;\n}\n\n/**\n * Bakes keyed by paint and bake size, least recently used first out.\n *\n * The paint is held weakly, so a paint nobody draws any more does not pin its\n * key; its texture stays until eviction reaches it, which the bounds keep\n * finite. `free` runs for every value that leaves, by eviction, replacement or\n * `clear`.\n */\nexport class MeshBakeCache<T> {\n private readonly byPaint = new WeakMap<object, Map<number, Entry<T>>>();\n /** Insertion order is recency: a hit is deleted and re-added. */\n private readonly order = new Set<Entry<T>>();\n private held = 0;\n\n constructor(\n private readonly free: (value: T) => void,\n private readonly budgetBytes: number = MESH_BAKE_CACHE_BYTES,\n private readonly maxEntries: number = MESH_BAKE_CACHE_ENTRIES,\n ) {}\n\n /** Bytes the held bakes occupy, as RGBA8. */\n get bytes(): number { return this.held; }\n\n /** Bakes held. */\n get size(): number { return this.order.size; }\n\n get(paint: object, size: number): T | undefined {\n const entry = this.byPaint.get(paint)?.get(size);\n if (!entry) return undefined;\n this.order.delete(entry);\n this.order.add(entry);\n return entry.value;\n }\n\n set(paint: object, size: number, value: T): void {\n let bySize = this.byPaint.get(paint);\n if (!bySize) {\n bySize = new Map();\n this.byPaint.set(paint, bySize);\n }\n const old = bySize.get(size);\n if (old) this.drop(old);\n const entry: Entry<T> = { value, size, bySize };\n bySize.set(size, entry);\n this.order.add(entry);\n this.held += size * size * 4;\n this.evict(entry);\n }\n\n /** Free every bake. The cache stays usable. */\n clear(): void {\n for (const entry of [...this.order]) this.drop(entry);\n }\n\n /** Oldest first until both bounds hold, never evicting `keep` — the bake\n * the caller is about to draw. */\n private evict(keep: Entry<T>): void {\n for (const entry of this.order) {\n if (this.held <= this.budgetBytes && this.order.size <= this.maxEntries) return;\n if (entry !== keep) this.drop(entry);\n }\n }\n\n private drop(entry: Entry<T>): void {\n if (!this.order.delete(entry)) return;\n entry.bySize.delete(entry.size);\n this.held -= entry.size * entry.size * 4;\n this.free(entry.value);\n }\n}\n","/**\n * GLSL ES 3.0 sources for the mesh-gradient paint.\n *\n * Everything outside the bake's box is transparent: a mesh covers the area its\n * patches cover, not the whole shape it is filling, and a clamped read would\n * otherwise smear its border colors across the rest.\n *\n * `u_meshOrigin` / `u_meshSize` are the bake's box in paint space, and the\n * bake maps that box onto texel *centers*, which is the half-texel the uv\n * rescale accounts for. Output is PREMULTIPLIED alpha.\n */\n\n/** The id this program is registered under. */\nexport const MESH_PROGRAM_ID = 'kit:mesh-gradient';\n\nexport const MESH_VERT_SRC = /* glsl */ `#version 300 es\nin vec2 a_position;\nuniform mat3 u_proj;\nuniform mat3 u_model;\nuniform mat3 u_worldInv;\nout vec2 v_world;\nvoid main() {\n vec3 screen = u_model * vec3(a_position, 1.0);\n vec3 clip = u_proj * vec3(screen.xy, 1.0);\n gl_Position = vec4(clip.xy, 0.0, 1.0);\n vec3 world = u_worldInv * vec3(screen.xy, 1.0);\n v_world = world.xy;\n}\n`;\n\nexport const MESH_FRAG_SRC = /* glsl */ `#version 300 es\nprecision highp float;\nin vec2 v_world;\nuniform sampler2D u_sampler;\nuniform vec2 u_meshOrigin;\nuniform vec2 u_meshSize;\nuniform float u_opacity;\nuniform float u_alpha;\nout vec4 outColor;\nvoid main() {\n vec2 t =(v_world - u_meshOrigin) / max(u_meshSize, vec2(0.0001));\n if (t.x < 0.0 || t.x > 1.0 || t.y < 0.0 || t.y > 1.0) {\n outColor = vec4(0.0);\n return;\n }\n vec2 texels = vec2(textureSize(u_sampler, 0));\n vec2 uv = (t * (texels - 1.0) + 0.5) / texels;\n vec4 texel = texture(u_sampler, uv);\n float a = texel.a * u_opacity * u_alpha;\n outColor = vec4(texel.rgb * a, a);\n}\n`;\n\nexport const MESH_UNIFORMS = [\n 'u_proj', 'u_model', 'u_worldInv', 'u_sampler',\n 'u_meshOrigin', 'u_meshSize', 'u_opacity', 'u_alpha',\n] as const;\n\nexport const MESH_ATTRIBUTES = ['a_position'] as const;\n","/**\n * The `mesh-gradient` paint kind — PDF's shading types 6 and 7 as a registered\n * paint: a set of curved quadrilateral patches, each with a color at every\n * corner.\n *\n * It uses only the slots `registerPaintKind` gives a consumer, so whatever it\n * can do, a consumer's own kind can do too.\n */\n\nimport type { GradStop } from '@weasel-js/paint';\nimport type { PaintBindContext, PaintDrawKind, PaintProgram, PaintResources } from '../paintKinds';\nimport { resolveColor, rgbaToHex } from '@weasel-js/paint';\nimport { mat3 } from '@weasel-js/geom';\nimport { oklabToOklch, oklabToSrgbU8, oklchToOklab, srgbFloatToOklab } from '@weasel-js/paint';\nimport type { ColorSpace, Paint, PaintUnits } from '@weasel-js/paint';\nimport type { FillPoseBox } from '../fillInPoseFrame';\nimport { bakeMesh, meshBounds, type MeshBox } from './bake';\nimport { MeshBakeCache, meshBakeSize } from './bakeCache';\nimport { isValidPatch, type MeshPatch, type MeshPoint } from './surface';\nimport { MESH_FRAG_SRC, MESH_PROGRAM_ID, MESH_VERT_SRC } from './meshShader';\n\nexport type { MeshPatch, MeshPoint } from './surface';\n\n/**\n * A mesh gradient paint.\n *\n * `patches` are in the space `units` names, the same way a gradient's\n * geometry is — under `'bounds'` every point is a fraction of the painted\n * node's box, which is what lets the paint survive a resize.\n *\n * `interpolate` is the space corner colors blend through, matching the three\n * gradients.\n */\nexport interface MeshGradientPaint {\n kind: 'mesh-gradient';\n patches: MeshPatch[];\n units?: PaintUnits;\n interpolate?: ColorSpace;\n opacity?: number;\n}\n\n/** The kind's id, as `Paint['fill']` carries it. */\nexport const MESH_GRADIENT_KIND = 'mesh-gradient';\n\n/** A mesh paint, narrowed. */\nexport function isMeshGradientPaint(fill: Paint | null | undefined): fill is Paint & MeshGradientPaint {\n // `Paint`'s discriminant stays closed over the built-in kinds — see\n // `asPaint` — so a registered kind reads it widened.\n return fill != null && (fill.kind as string | undefined) === MESH_GRADIENT_KIND;\n}\n\nfunction asMesh(fill: Paint): MeshGradientPaint {\n return fill as unknown as MeshGradientPaint;\n}\n\n// `asPaint`'s cast, kept local: this module must import nothing from the\n// registry, whose state the lazy kind's self-contained copy would duplicate.\nfunction asFill(mesh: MeshGradientPaint): Paint {\n return mesh as unknown as Paint;\n}\n\n/**\n * `color` moved in OKLCh — lightness, chroma and hue by the given deltas, with\n * its alpha kept. The seed's corners come from one color, and they have to\n * differ enough to read as a mesh rather than as a flat fill.\n */\nfunction shifted(color: string, dL: number, cScale: number, dHueDeg: number): string {\n const [r, g, b, a] = resolveColor(color);\n const [L, A, B] = srgbFloatToOklab(r, g, b);\n const [, C, h] = oklabToOklch(L, A, B);\n const [nL, nA, nB] = oklchToOklab(\n Math.min(1, Math.max(0, L + dL)),\n Math.max(0, C * cScale),\n h + (dHueDeg * Math.PI) / 180,\n );\n const [nr, ng, nb] = oklabToSrgbU8(nL, nA, nB);\n return rgbaToHex([nr / 255, ng / 255, nb / 255, a]);\n}\n\n/** A one-patch square covering the unit box, its four corners four readings of\n * `color` — a mesh seeded from a solid has to show *something* curved, or\n * switching kind looks like nothing happened. */\nexport function seedMeshPatch(color: string): MeshGradientPaint {\n const corners: MeshPoint[] = [\n { x: 0, y: 0 }, { x: 1, y: 0 }, { x: 1, y: 1 }, { x: 0, y: 1 },\n ];\n const points: MeshPoint[] = [];\n for (let i = 0; i < 4; i++) {\n const a = corners[i];\n const b = corners[(i + 1) % 4];\n // Bow each edge outward by an eighth, so the seed is a patch and not a\n // rectangle wearing one's clothes.\n const nx = (b.y - a.y) * 0.125;\n const ny = -(b.x - a.x) * 0.125;\n points.push(\n a,\n { x: a.x + (b.x - a.x) / 3 + nx, y: a.y + (b.y - a.y) / 3 + ny },\n { x: a.x + (2 * (b.x - a.x)) / 3 + nx, y: a.y + (2 * (b.y - a.y)) / 3 + ny },\n );\n }\n return {\n kind: MESH_GRADIENT_KIND,\n patches: [{\n points,\n colors: [\n color,\n shifted(color, 0.14, 0.85, 0),\n shifted(color, -0.06, 1.1, 38),\n shifted(color, -0.16, 1.0, -22),\n ],\n }],\n units: 'bounds',\n };\n}\n\n/** The straight-edged patch covering `[x0, x1] × [0, 1]`, in walk order. */\nfunction bandPatch(x0: number, x1: number, left: string, right: string): MeshPatch {\n const corners: MeshPoint[] = [{ x: x0, y: 0 }, { x: x1, y: 0 }, { x: x1, y: 1 }, { x: x0, y: 1 }];\n const points: MeshPoint[] = [];\n for (let i = 0; i < 4; i++) {\n const a = corners[i];\n const b = corners[(i + 1) % 4];\n points.push(a, { x: a.x + (b.x - a.x) / 3, y: a.y + (b.y - a.y) / 3 }, { x: a.x + (2 * (b.x - a.x)) / 3, y: a.y + (2 * (b.y - a.y)) / 3 });\n }\n return { points, colors: [left, right, right, left] };\n}\n\n/**\n * A stop list as a mesh: one full-height band per gap between neighboring\n * stops, colored left to right. The bands blend exactly the way the ramp\n * does, so a horizontal gradient survives the switch unchanged. A zero-width\n * gap is a hard break and gets no band.\n */\nexport function meshFromStops(stops: readonly GradStop[]): MeshGradientPaint {\n const sorted = [...stops].sort((a, b) => a.offset - b.offset);\n if (sorted.length === 1) sorted.push({ offset: 1, color: sorted[0].color });\n if (sorted.length === 0) return seedMeshPatch('#000000ff');\n const patches: MeshPatch[] = [];\n for (let i = 0; i < sorted.length - 1; i++) {\n const a = sorted[i];\n const b = sorted[i + 1];\n if (b.offset > a.offset) patches.push(bandPatch(a.offset, b.offset, a.color, b.color));\n }\n return { kind: MESH_GRADIENT_KIND, patches, units: 'bounds' };\n}\n\n/**\n * A mesh read as a stop list: every patch's top edge — corner 0 to corner 1 —\n * placed by its `x` across the mesh's horizontal extent. The inverse of\n * `meshFromStops`, and for any other mesh the ramp across its top.\n */\nexport function meshStops(mesh: MeshGradientPaint): GradStop[] {\n const valid = mesh.patches.filter(isValidPatch);\n if (valid.length === 0) return [];\n const xs = valid.flatMap((p) => [p.points[0].x, p.points[3].x]);\n const lo = Math.min(...xs);\n const span = Math.max(...xs) - lo;\n const offsetOf = (x: number) => (span > 0 ? (x - lo) / span : 0);\n const stops: GradStop[] = [];\n for (const patch of valid) {\n for (const [point, color] of [[patch.points[0], patch.colors[0]], [patch.points[3], patch.colors[1]]] as const) {\n const offset = offsetOf(point.x);\n if (!stops.some((s) => s.offset === offset && s.color === color)) stops.push({ offset, color });\n }\n }\n return stops.sort((a, b) => a.offset - b.offset);\n}\n\n/** Every patch mapped through `move`. */\nfunction mapPatches(mesh: MeshGradientPaint, move: (p: MeshPoint) => MeshPoint): MeshPatch[] {\n return mesh.patches.map((patch) => ({ ...patch, points: patch.points.map(move) }));\n}\n\n// ─── The bake cache ─────────────────────────────────────────────────────────\n//\n// A kind owns its own GPU state; the registry hands it a `gl` and a resource\n// lifetime. One cache per lifetime, so two renderers — or one renderer past a\n// context restore — never trade textures, and the lifetime's end frees them.\n\ninterface CachedBake {\n texture: WebGLTexture;\n /** Where the mesh being bound sits in paint space. The texels are shared by\n * every pose-frame copy of one paint; the box is each copy's own. */\n box: MeshBox;\n}\n\n/** The paint a pose-frame copy was made from. A copy is rebuilt whenever its\n * node's pose changes, and bakes the same texels as its source. */\nconst BAKE_SOURCE = new WeakMap<object, object>();\n\nconst CACHES = new WeakMap<PaintResources, MeshBakeCache<WebGLTexture>>();\n\nfunction cacheFor(ctx: PaintBindContext): MeshBakeCache<WebGLTexture> {\n let cache = CACHES.get(ctx.resources);\n if (!cache) {\n const gl = ctx.gl;\n const made = new MeshBakeCache<WebGLTexture>((texture) => gl.deleteTexture(texture));\n ctx.resources.onRelease(() => {\n made.clear();\n CACHES.delete(ctx.resources);\n });\n CACHES.set(ctx.resources, made);\n cache = made;\n }\n return cache;\n}\n\n/** Device pixels the larger side of `box` covers when drawn in `units`. */\nfunction devicePixelsOf(ctx: PaintBindContext, mesh: MeshGradientPaint, box: MeshBox): number {\n const m = ctx.spaceToDevice(mesh.units);\n if (!m) return Number.NaN;\n return Math.max(box.width * Math.hypot(m[0], m[1]), box.height * Math.hypot(m[3], m[4]));\n}\n\nfunction bakeFor(ctx: PaintBindContext, mesh: MeshGradientPaint): CachedBake | null {\n const box = meshBounds(mesh.patches);\n if (!box) return null;\n const size = meshBakeSize(devicePixelsOf(ctx, mesh, box), ctx.maxTextureSize);\n\n const cache = cacheFor(ctx);\n const key = BAKE_SOURCE.get(mesh) ?? mesh;\n const hit = cache.get(key, size);\n if (hit) return { texture: hit, box };\n\n const baked = bakeMesh(mesh.patches, mesh.interpolate ?? 'rgb', size);\n if (!baked) return null;\n\n const gl = ctx.gl;\n const texture = gl.createTexture();\n if (!texture) return null;\n gl.bindTexture(gl.TEXTURE_2D, texture);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);\n gl.texImage2D(\n gl.TEXTURE_2D, 0, gl.RGBA,\n baked.size, baked.size, 0,\n gl.RGBA, gl.UNSIGNED_BYTE, baked.pixels,\n );\n gl.bindTexture(gl.TEXTURE_2D, null);\n\n cache.set(key, size, texture);\n return { texture, box };\n}\n\nfunction bindMesh(ctx: PaintBindContext, fill: Paint): PaintProgram | null {\n const mesh = asMesh(fill);\n if (!mesh.patches.some(isValidPatch)) return null;\n\n const inverse = ctx.spaceInverse(mesh.units);\n if (!inverse) return null;\n\n const program = ctx.program(MESH_PROGRAM_ID);\n if (!program) return null;\n\n const entry = bakeFor(ctx, mesh);\n if (!entry) return null;\n\n const gl = ctx.gl;\n gl.useProgram(program.handle);\n ctx.setProjAndModel(program);\n gl.uniformMatrix3fv(program.uniform('u_worldInv')!, false, mat3.toUniform(inverse));\n\n gl.activeTexture(gl.TEXTURE0);\n gl.bindTexture(gl.TEXTURE_2D, entry.texture);\n gl.uniform1i(program.uniform('u_sampler')!, 0);\n\n const { box } = entry;\n gl.uniform2f(program.uniform('u_meshOrigin')!, box.x, box.y);\n gl.uniform2f(program.uniform('u_meshSize')!, box.width, box.height);\n gl.uniform1f(program.uniform('u_opacity')!, mesh.opacity ?? 1);\n gl.uniform1f(program.uniform('u_alpha')!, ctx.alpha);\n return program;\n}\n\n/** The kind's draw half, shader program included. Core adds the editor's\n * slots and registers the whole entry. */\nexport const meshDrawKind: PaintDrawKind = {\n id: MESH_GRADIENT_KIND,\n programs: { [MESH_PROGRAM_ID]: { vert: MESH_VERT_SRC, frag: MESH_FRAG_SRC } },\n bind: bindMesh,\n inPoseFrame: (fill, box: FillPoseBox) => {\n const mesh = asMesh(fill);\n if (mesh.units !== 'bounds') return fill;\n const posed = asFill({\n ...mesh,\n patches: mapPatches(mesh, (p) => ({\n x: box.x + p.x * box.width,\n y: box.y + p.y * box.height,\n })),\n units: 'local' as const,\n });\n BAKE_SOURCE.set(posed, fill);\n return posed;\n },\n toBoundsFrame: (fill, box: FillPoseBox) => {\n const mesh = asMesh(fill);\n if (mesh.units === 'bounds' || box.width === 0 || box.height === 0) return fill;\n return asFill({\n ...mesh,\n patches: mapPatches(mesh, (p) => ({\n x: (p.x - box.x) / box.width,\n y: (p.y - box.y) / box.height,\n })),\n units: 'bounds' as const,\n });\n },\n};\n\n/**\n * The `<defs>` entry for a mesh paint, in weasel's own namespace.\n *\n * Not SVG's abandoned `<meshgradient>`: that vocabulary only reaches Coons\n * patches, shares patch edges implicitly — a reader that gets the sharing\n * wrong tears the surface rather than failing outright — and has exactly one\n * implementation in the world. Ours writes every patch's points in full.\n * `@weasel-js/svg` puts the paint fallback color beside the reference, so a\n * foreign renderer paints flat instead of nothing.\n */\nexport function meshGradientXml(id: string, mesh: MeshGradientPaint): string {\n const P = 'wzl';\n const units = mesh.units === 'bounds' ? 'objectBoundingBox' : 'userSpaceOnUse';\n const space = mesh.interpolate && mesh.interpolate !== 'rgb'\n ? ` interpolate=\"${mesh.interpolate}\"` : '';\n const patches = mesh.patches.map((patch) => {\n const points = patch.points.map((p) => `${trim(p.x)},${trim(p.y)}`).join(' ');\n const colors = patch.colors.join(' ');\n return `<${P}:patch points=\"${points}\" colors=\"${colors}\"/>`;\n }).join('');\n return (\n `<${P}:meshGradient id=\"${id}\" gradientUnits=\"${units}\"${space}>` +\n `${patches}</${P}:meshGradient>`\n );\n}\n\n/** Short decimals, matching what `@weasel-js/svg` writes elsewhere. */\nfunction trim(n: number): string {\n return Number.isInteger(n) ? String(n) : String(Number(n.toFixed(4)));\n}\n","/**\n * The draggable points of a mesh paint, as pure geometry — what an on-canvas\n * editor lists, and what moving one of them does to the paint.\n *\n * Nothing here knows a frame: the handles are in whatever space the mesh's\n * points are, so a caller resolves a `'bounds'` mesh onto its box first\n * (`fillInPoseFrame`) and normalizes the result back (`fillToBoundsFrame`).\n */\n\nimport type { MeshGradientPaint } from './meshPaint';\nimport { isTensorPatch, isValidPatch, type MeshPatch, type MeshPoint } from './surface';\n\n/** What a handle moves: a patch corner, one of the two controls of an edge,\n * or one of a tensor patch's four interior points. */\nexport type MeshHandleKind = 'corner' | 'control' | 'interior';\n\n/** One stored point: `patches[patch].points[index]`. */\nexport interface MeshPointRef {\n patch: number;\n index: number;\n}\n\n/**\n * One draggable point.\n *\n * Patches store their points in full rather than sharing edges, so two\n * patches that meet each carry a copy of the corner and controls they meet\n * at. Those copies are one handle, with a `ref` per copy — dragging one of\n * them alone would tear the surface open along the seam.\n */\nexport interface MeshHandle {\n /** Stable while the handle moves: its first ref, as `\"patch:index\"`. */\n id: string;\n kind: MeshHandleKind;\n at: MeshPoint;\n refs: readonly MeshPointRef[];\n}\n\n/** Corner `k`'s interior neighbor in the tensor net. PDF's trailing four walk\n * the net as (1,1) (1,2) (2,2) (2,1), which puts corner 1's at index 15 and\n * corner 3's at 13 — the transpose of the obvious reading. */\nconst INTERIOR_OF_CORNER = [12, 15, 14, 13] as const;\n\nfunction kindOf(index: number): MeshHandleKind {\n if (index >= 12) return 'interior';\n return index % 3 === 0 ? 'corner' : 'control';\n}\n\nfunction near(a: number, b: number): boolean {\n return Math.abs(a - b) <= 1e-9 * Math.max(1, Math.abs(a), Math.abs(b));\n}\n\nfunction same(a: MeshPoint, b: MeshPoint): boolean {\n return near(a.x, b.x) && near(a.y, b.y);\n}\n\n/**\n * Every draggable point of `mesh`, in walk order: each patch's corners and\n * edge controls, then a tensor patch's interior. Coincident points of one\n * kind merge into one handle. A patch that cannot be evaluated has none.\n */\nexport function meshHandles(mesh: MeshGradientPaint): MeshHandle[] {\n const handles: { id: string; kind: MeshHandleKind; at: MeshPoint; refs: MeshPointRef[] }[] = [];\n mesh.patches.forEach((patch, p) => {\n if (!isValidPatch(patch)) return;\n patch.points.forEach((at, index) => {\n const kind = kindOf(index);\n const twin = handles.find((h) => h.kind === kind && same(h.at, at));\n if (twin) twin.refs.push({ patch: p, index });\n else handles.push({ id: `${p}:${index}`, kind, at, refs: [{ patch: p, index }] });\n });\n });\n return handles;\n}\n\n/** The points a corner carries: the controls of the two edges it joins, and\n * its interior neighbor when the patch has one. */\nfunction carriedBy(patch: MeshPatch, corner: number): number[] {\n const k = corner / 3;\n const carried = [corner + 1, (corner + 11) % 12];\n if (isTensorPatch(patch)) carried.push(INTERIOR_OF_CORNER[k]);\n return carried;\n}\n\n/**\n * `mesh` with `handle` moved to `to`. A corner carries its edge controls\n * and interior neighbor along by the same offset, the way a path editor's\n * anchor carries its handles; a control or interior point moves alone.\n * Returns a new paint; `mesh` is not modified.\n */\nexport function moveMeshHandle(\n mesh: MeshGradientPaint, handle: MeshHandle, to: MeshPoint,\n): MeshGradientPaint {\n const dx = to.x - handle.at.x;\n const dy = to.y - handle.at.y;\n const placed = new Map<string, MeshPoint>();\n for (const { patch, index } of handle.refs) {\n placed.set(`${patch}:${index}`, to);\n }\n if (handle.kind === 'corner') {\n for (const { patch, index } of handle.refs) {\n for (const carried of carriedBy(mesh.patches[patch], index)) {\n const key = `${patch}:${carried}`;\n if (placed.has(key)) continue;\n const from = mesh.patches[patch].points[carried];\n placed.set(key, { x: from.x + dx, y: from.y + dy });\n }\n }\n }\n return {\n ...mesh,\n patches: mesh.patches.map((patch, p) => ({\n ...patch,\n points: patch.points.map((point, i) => placed.get(`${p}:${i}`) ?? point),\n })),\n };\n}\n\n/** The lines an editor draws under the handles, as control polygons. */\nexport interface MeshGuides {\n /** Every patch edge as its four cubic control points, from the corner it\n * leaves to the corner it reaches. */\n edges: [MeshPoint, MeshPoint, MeshPoint, MeshPoint][];\n /** Corner to each point it carries — an edge control or interior point. */\n arms: [MeshPoint, MeshPoint][];\n}\n\n/** The guides for `mesh`'s valid patches. Shared edges appear once per patch. */\nexport function meshGuides(mesh: MeshGradientPaint): MeshGuides {\n const edges: MeshGuides['edges'] = [];\n const arms: MeshGuides['arms'] = [];\n for (const patch of mesh.patches) {\n if (!isValidPatch(patch)) continue;\n const p = patch.points;\n for (let k = 0; k < 4; k++) {\n const corner = k * 3;\n edges.push([p[corner], p[corner + 1], p[corner + 2], p[(corner + 3) % 12]]);\n for (const carried of carriedBy(patch, corner)) arms.push([p[corner], p[carried]]);\n }\n }\n return { edges, arms };\n}\n"]}