@weasel-js/renderer 0.0.0-stage → 1.9.4

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.
@@ -0,0 +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,CAAA,GAAI,IAAI,CAAA,GAAI,CAAA;AAClB,EAAA,OAAO;AAAA,IACL,CAAA,EAAG,CAAA,GAAI,EAAA,CAAG,CAAA,GAAI,CAAA,GAAI,EAAA,CAAG,CAAA,GAAI,CAAA,GAAI,EAAA,CAAG,CAAA,GAAI,CAAA,GAAI,EAAA,CAAG,CAAA;AAAA,IAC3C,CAAA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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"]}
@@ -0,0 +1,330 @@
1
+ import { TextureHandle, FillStyle, PosedFill, GradientUnits, GradStop, ColorSpace } from '@weasel-js/paint';
2
+ import { Reflection } from '@weasel-js/registry';
3
+ import { GlMat3 } from '@weasel-js/geom';
4
+
5
+ /**
6
+ * Minimal compile/link/lookup wrapper for a GL program. Throws
7
+ * `ShaderCompileError` on compile or link failure with the GL info log
8
+ * embedded in the error message — never returns a half-initialized program.
9
+ *
10
+ * Designed so test code can stub `getShaderParameter` / `getProgramParameter`
11
+ * via the recorder Proxy without further special-casing.
12
+ */
13
+ type Stage = 'vertex' | 'fragment' | 'link';
14
+ /** Thrown when a shader fails to compile or link, carrying which stage failed
15
+ * and the driver's log. */
16
+ declare class ShaderCompileError extends Error {
17
+ readonly stage: Stage;
18
+ readonly log: string;
19
+ constructor(stage: Stage, log: string);
20
+ }
21
+ /** An array uniform a program can be written as a whole: its element type as
22
+ * declared, its declared length, and the location of slot 0. */
23
+ interface UniformArray {
24
+ readonly type: string;
25
+ readonly size: number;
26
+ readonly location: WebGLUniformLocation;
27
+ }
28
+ /** A linked GL program with its uniform and attribute locations cached by name. */
29
+ declare class ShaderProgram {
30
+ private readonly gl;
31
+ readonly handle: WebGLProgram;
32
+ private readonly uniforms;
33
+ private readonly arrays;
34
+ private readonly attributes;
35
+ constructor(gl: WebGL2RenderingContext, vertSrc: string, fragSrc: string);
36
+ private compile;
37
+ lookupUniforms(names: readonly string[]): void;
38
+ /** Record each array's slot-0 location under its bare name. An array the
39
+ * driver optimized away has no location and is left out. */
40
+ lookupUniformArrays(decls: ReadonlyMap<string, {
41
+ type: string;
42
+ size: number;
43
+ }>): void;
44
+ lookupAttributes(names: readonly string[]): void;
45
+ uniform(name: string): WebGLUniformLocation | undefined;
46
+ uniformArray(name: string): UniformArray | undefined;
47
+ attribute(name: string): number | undefined;
48
+ }
49
+
50
+ /**
51
+ * registerProgram — public API for registering custom shader programs.
52
+ *
53
+ * Stores raw GLSL source strings in a module-level registry. GL compilation
54
+ * happens on each WeaselRenderer via WeaselRenderer.registerProgram(), which
55
+ * calls getProgramSource() and compiles the result. This keeps registerProgram
56
+ * GL-context-agnostic — identical pattern to registerFont storing ImageBitmap.
57
+ *
58
+ * Module-level state = source strings only; compiled GL
59
+ * programs live on each renderer's programRegistry (Map<id, ShaderProgram>).
60
+ *
61
+ * Lifecycle: program sources live for the module lifetime. No unregister in v1.
62
+ */
63
+
64
+ /** Opaque handle to a compiled custom shader program. */
65
+ interface ShaderProgramHandle {
66
+ readonly id: string;
67
+ }
68
+ /**
69
+ * A value for one uniform in `ShaderDrawCommand.uniforms`.
70
+ *
71
+ * | TS type | GL call |
72
+ * |-------------------------|--------------------------------------|
73
+ * | number | uniform1f |
74
+ * | [n, n] | uniform2fv |
75
+ * | [n, n, n] | uniform3fv |
76
+ * | [n, n, n, n] | uniform4fv |
77
+ * | Float32Array length 9 | uniformMatrix3fv (column-major) |
78
+ * | Float64Array | as the Float32Array of its values |
79
+ * | Float32Array length 16 | uniformMatrix4fv (column-major) |
80
+ * | TextureHandle | bind to next tex unit + uniform1i |
81
+ *
82
+ * **Array uniforms.** Keyed by an array's bare name (`u_ripples` for
83
+ * `uniform vec3 u_ripples[8]`), a flat `number[]`, `Float32Array`,
84
+ * `Int32Array` or `Uint32Array` fills the array from slot 0 in one
85
+ * `uniform*v` call chosen by the declared element type (`vec3` →
86
+ * `uniform3fv`, `ivec2` → `uniform2iv`, `mat4` → `uniformMatrix4fv`, …).
87
+ * Its length must be a whole number of elements and at most the declared
88
+ * size; a shorter value leaves the remaining slots as they were. Per-slot
89
+ * keys (`u_ripples[2]`) keep working and take the table above.
90
+ */
91
+ type ShaderUniform = number | [number, number] | [number, number, number] | [number, number, number, number] | readonly number[] | Float32Array | Float64Array | Int32Array | Uint32Array | TextureHandle;
92
+ /** A registered program's GLSL source. An empty `vert` means the kit's default vertex shader. */
93
+ interface ProgramSource {
94
+ vert: string;
95
+ frag: string;
96
+ }
97
+ /** Every registered program's GLSL source, keyed by program id. */
98
+ declare const programSourceRegistry: Reflection<ProgramSource>;
99
+ /** @internal Test helper — do not call from product code. */
100
+ declare function _resetProgramRegistryForTests(): void;
101
+ /** The source registered under `id`, or `null` when nothing is. */
102
+ declare function getProgramSource(id: string): ProgramSource | null;
103
+ /**
104
+ * Register a custom shader program by id.
105
+ *
106
+ * Pass an empty string for `vert` to use the kit's default vertex shader
107
+ * (recommended). The kit's vertex shader exposes `v_uv`, `v_screen`, and
108
+ * `v_world` varyings plus `u_bounds` and `u_view` uniforms.
109
+ *
110
+ * **IMPORTANT — Premultiplied alpha:**
111
+ * Your fragment shader MUST output premultiplied alpha:
112
+ * `outColor = vec4(rgb * a, a);` ← correct
113
+ * `outColor = vec4(rgb, a);` ← WRONG — over-brightens translucent regions
114
+ *
115
+ * The renderer uses `gl.blendFunc(ONE, ONE_MINUS_SRC_ALPHA)` to match.
116
+ * Opaque fragments (a=1) are unaffected; only fragments with a < 1 differ.
117
+ *
118
+ * **Re-registration behavior:**
119
+ * - Dev mode (`NODE_ENV !== 'production'`): calling with an existing id and new
120
+ * source replaces it (hot reload). Every renderer that compiled the old source
121
+ * recompiles on its next frame and deletes the program it replaces; a
122
+ * `<Canvas shaders>` naming the id repaints to show it. If the new source fails
123
+ * to compile, the renderer logs the error once and keeps drawing the old one.
124
+ * - Prod mode: calling with an existing id throws.
125
+ *
126
+ * Actual GL compilation and `ShaderCompileError` throwing happen in
127
+ * `WeaselRenderer.registerProgram()`, not here.
128
+ *
129
+ * @experimental API may break before v2.
130
+ */
131
+ declare function registerProgram(id: string, vert: string, frag: string): ShaderProgramHandle;
132
+
133
+ /**
134
+ * Resolve a `units: 'bounds'` gradient into the frame its node is painted in.
135
+ *
136
+ * Node painters bake the pose into their geometry (`pathInPoseFrame`) rather
137
+ * than emitting a per-node transform, so by the time the renderer sees a
138
+ * scene node there is no node-local space left for a gradient to refer to.
139
+ * This is the paint-side counterpart: it maps box-relative gradient geometry
140
+ * onto the same box the path was just projected into, so the two arrive in
141
+ * the renderer in one frame.
142
+ */
143
+
144
+ /** The box a `'bounds'` gradient's normalized geometry is mapped onto —
145
+ * usually a node's bounds. */
146
+ interface FillPoseBox {
147
+ x: number;
148
+ y: number;
149
+ width: number;
150
+ height: number;
151
+ }
152
+ /**
153
+ * Map a `'bounds'` gradient's `0..1` geometry onto `box`, returning it in the
154
+ * box's own frame (`units: 'local'`). Any other fill — solid, pattern, or a
155
+ * gradient in another space — is returned untouched.
156
+ *
157
+ * Radii scale by the box's normalized diagonal, SVG's rule for a percentage
158
+ * radius against `objectBoundingBox`: `sqrt(w² + h²) / sqrt(2)`, which is
159
+ * exactly `w` for a square box. The renderer's radial gradient is circular,
160
+ * so a non-square box cannot make it the ellipse SVG would — this keeps the
161
+ * radius proportionate instead.
162
+ */
163
+ declare function fillInPoseFrame(fill: FillStyle, box: FillPoseBox): PosedFill;
164
+ /**
165
+ * Inverse of {@link fillInPoseFrame}: express a gradient already positioned
166
+ * in `box`'s frame as `0..1` fractions of that box (`units: 'bounds'`), so
167
+ * it follows the node when moved or resized.
168
+ *
169
+ * The importer's counterpart — SVG `userSpaceOnUse` coordinates arrive in
170
+ * page space, and normalizing them here makes an imported gradient behave
171
+ * exactly like one drawn in the app.
172
+ *
173
+ * A zero-width or zero-height box has no frame to normalize against; the
174
+ * fill is returned untouched rather than divided by zero.
175
+ */
176
+ declare function fillToBoundsFrame(fill: FillStyle, box: FillPoseBox): FillStyle;
177
+
178
+ /**
179
+ * The renderer's half of a paint kind: what it takes to draw one.
180
+ *
181
+ * Solids, patterns and the three gradients are branches inside the GL
182
+ * renderer and never come through here. A kind beyond those registers its
183
+ * bind slot, its frame conversions and its shaders, and the renderer consults
184
+ * this registry for any kind it does not recognize. What an editor or a
185
+ * serializer needs of a kind is not the renderer's to know; whoever owns
186
+ * those registers it beside this.
187
+ */
188
+
189
+ /** A compiled GL program. A paint kind gets one from
190
+ * {@link PaintBindContext.program} and hands it back from `bind`. */
191
+ type PaintProgram = ShaderProgram;
192
+ /**
193
+ * The lifetime a paint kind's GPU state belongs to: one renderer on one live
194
+ * context. The object itself is the key — a kind caches textures in a
195
+ * `WeakMap` on it, so two renderers sharing a context never trade them — and
196
+ * `onRelease` is where it frees them.
197
+ */
198
+ interface PaintResources {
199
+ /** Run `release` once, when this lifetime ends: the renderer is disposed, or
200
+ * its context was lost and restored. Free every GL object made under it
201
+ * there. */
202
+ onRelease(release: () => void): void;
203
+ }
204
+ /**
205
+ * The renderer surface a paint kind binds against, narrowed to what a paint
206
+ * needs. The full `DrawContext` is not consumer surface.
207
+ */
208
+ interface PaintBindContext {
209
+ readonly gl: WebGL2RenderingContext;
210
+ /** The group alpha this draw inherits — multiply it into the paint's own. */
211
+ readonly alpha: number;
212
+ /**
213
+ * The compiled program for a `registerProgram` id, compiled against this
214
+ * renderer on first use. `null` when no source is registered under `id` or
215
+ * compilation failed.
216
+ */
217
+ program(id: string): PaintProgram | null;
218
+ /** Send `u_proj` and `u_model`, which every kit vertex shader takes. */
219
+ setProjAndModel(program: PaintProgram): void;
220
+ /**
221
+ * `u_worldInv` for a paint declaring `units` — the inverse of the transform
222
+ * from the paint's space to the frame the geometry arrives in. Paired with
223
+ * the vertex shader's `v_world` varying this is *the* paint-space
224
+ * convention; it is not gradient-specific.
225
+ *
226
+ * `null` when that space has no inverse — a transform or view that flattens
227
+ * an axis. Nothing the paint draws there means anything, so `bind` should
228
+ * return `null` and draw nothing.
229
+ */
230
+ spaceInverse(units: GradientUnits | undefined): GlMat3 | null;
231
+ /**
232
+ * The transform from the space `units` names to device pixels of the target
233
+ * this draw lands in — screen pixels times the pixel ratio on screen, output
234
+ * pixels in a headless render. It is what a paint baking a texture measures
235
+ * its resolution against. `null` where `spaceInverse` is.
236
+ */
237
+ spaceToDevice(units: GradientUnits | undefined): GlMat3 | null;
238
+ /** The largest texture side this context accepts, `MAX_TEXTURE_SIZE`. */
239
+ readonly maxTextureSize: number;
240
+ /** The lifetime GPU state made for this draw belongs to. Stable across the
241
+ * frames of one renderer, so it is the key for a kind's texture cache. */
242
+ readonly resources: PaintResources;
243
+ /**
244
+ * Bake a stop ramp into the frame's ramp atlas, bind that atlas to a texture
245
+ * unit, and return the `v` the ramp's own row sits at — every ramp in a
246
+ * frame shares one texture, so a paint must sample at the returned `v` and
247
+ * not at a constant.
248
+ *
249
+ * `space` is the blend the stops are baked through, defaulting to `'rgb'`.
250
+ * It is part of the atlas key, so the same stops under two spaces take two
251
+ * rows rather than colliding.
252
+ */
253
+ bindRamp(stops: GradStop[], unit: number, space?: ColorSpace): number;
254
+ }
255
+ /**
256
+ * What the renderer needs of one paint kind. Every slot is optional, but
257
+ * `inPoseFrame` and `toBoundsFrame` come as a pair or not at all: a kind that
258
+ * converts one direction and not the other paints correctly once and then
259
+ * drifts on the next resize.
260
+ */
261
+ interface PaintDrawKind {
262
+ id: string;
263
+ /**
264
+ * Render slot: bind program, uniforms and textures for `fill` and return the
265
+ * bound program; `null` declines the paint.
266
+ *
267
+ * Binding is split from drawing on purpose — a caller owning its own stencil
268
+ * state (an inner/outer-aligned stroke, an even-odd fill) must issue its own
269
+ * draw call, and the kit's draw wrapper would clobber that state. Shader
270
+ * output must be premultiplied: `outColor = vec4(rgb * a, a)`.
271
+ *
272
+ * The geometry is not always the node's own. Text below the outline tier
273
+ * paints by drawing a quad over its glyphs' screen box into an offscreen
274
+ * buffer and masking that with glyph coverage, so a paint must come from
275
+ * `v_world` through `spaceInverse`, not from where `a_position` happens to
276
+ * lie.
277
+ */
278
+ bind?(ctx: PaintBindContext, fill: FillStyle): PaintProgram | null;
279
+ /** Bounds frame → the frame the node is painted in. */
280
+ inPoseFrame?(fill: FillStyle, box: FillPoseBox): FillStyle;
281
+ /** The inverse. Required whenever `inPoseFrame` is supplied. */
282
+ toBoundsFrame?(fill: FillStyle, box: FillPoseBox): FillStyle;
283
+ /**
284
+ * Shader programs `bind` looks up through `ctx.program`, keyed by program
285
+ * id; registering the kind registers them. Declaring them here rather than
286
+ * calling `registerProgram` at import keeps a kind loaded by
287
+ * {@link registerPaintDrawKindLoader} free of the shader registry.
288
+ */
289
+ programs?: Readonly<Record<string, ProgramSource>>;
290
+ }
291
+ /** Every registered draw kind, with the overrides each displaced. */
292
+ declare const paintDrawKindRegistry: Reflection<PaintDrawKind>;
293
+ /** Register a kind's draw half. Returns a disposer that removes it.
294
+ * Re-registering an existing id is an override; disposing it uncovers
295
+ * whatever it displaced. */
296
+ declare function registerPaintDrawKind(entry: PaintDrawKind): () => void;
297
+ /** The draw half for `kind`, or `undefined`. A lookup that misses on a kind
298
+ * with a loader starts that load; see {@link registerPaintDrawKindLoader}. */
299
+ declare function getPaintDrawKind(kind: string | undefined): PaintDrawKind | undefined;
300
+ /** Resolves with the draw half of a kind that is loaded on first use. */
301
+ type PaintDrawKindLoader = () => Promise<PaintDrawKind>;
302
+ /**
303
+ * Declare a paint kind that is loaded the first time something looks it up,
304
+ * so its code stays out of the bundle until a paint of it appears — typically
305
+ * `() => import('./myKind').then((m) => m.myKindEntry)`.
306
+ *
307
+ * Until it lands the kind is unregistered and the renderer draws nothing for
308
+ * its paints. Call {@link warmPaintKinds} to load ahead of the first frame
309
+ * instead.
310
+ *
311
+ * A kind that is already registered never calls its loader. Returns a
312
+ * disposer that removes the loader.
313
+ */
314
+ declare function registerPaintDrawKindLoader(id: string, load: PaintDrawKindLoader): () => void;
315
+ /** Is `id` registered, or declared with a loader? */
316
+ declare function isPaintKindKnown(id: string): boolean;
317
+ /**
318
+ * Load paint kinds ahead of their first use, so the first frame that meets
319
+ * one draws it rather than a blank. With no list, loads every kind that has a
320
+ * loader.
321
+ *
322
+ * Resolves once every kind is registered; a kind already registered counts
323
+ * as loaded. Rejects when a load fails, or for a kind that is neither
324
+ * registered nor loadable.
325
+ */
326
+ declare function warmPaintKinds(kinds?: readonly string[]): Promise<void>;
327
+ /** @internal Test helper — do not call from product code. */
328
+ declare function _resetPaintDrawKindsForTests(): void;
329
+
330
+ export { type FillPoseBox as F, type PaintBindContext as P, type ShaderProgramHandle as S, _resetPaintDrawKindsForTests as _, type ShaderUniform as a, ShaderProgram as b, type PaintDrawKind as c, type PaintDrawKindLoader as d, type PaintProgram as e, type PaintResources as f, type ProgramSource as g, ShaderCompileError as h, fillInPoseFrame as i, fillToBoundsFrame as j, getPaintDrawKind as k, getProgramSource as l, isPaintKindKnown as m, programSourceRegistry as n, registerPaintDrawKindLoader as o, paintDrawKindRegistry as p, registerProgram as q, registerPaintDrawKind as r, _resetProgramRegistryForTests as s, warmPaintKinds as w };
@@ -0,0 +1,118 @@
1
+ import { TilePatternSpec, TextureHandle } from '@weasel-js/paint';
2
+
3
+ /**
4
+ * The shapes a built-in tile is made of, as data.
5
+ *
6
+ * One description, two renderers: `patterns-builtin` strokes/fills these to
7
+ * an `OffscreenCanvas` to build the GL texture, and `@weasel-js/svg` maps
8
+ * them to `<pattern>` children. Duplicating the tile drawing in the
9
+ * serializer would let the raster and vector forms drift apart silently.
10
+ */
11
+
12
+ /** One primitive within a pattern tile, in tile-local coordinates. */
13
+ type TileShape = {
14
+ kind: 'line';
15
+ x1: number;
16
+ y1: number;
17
+ x2: number;
18
+ y2: number;
19
+ width: number;
20
+ color: string;
21
+ } | {
22
+ kind: 'circle';
23
+ cx: number;
24
+ cy: number;
25
+ r: number;
26
+ color: string;
27
+ } | {
28
+ kind: 'ellipse';
29
+ cx: number;
30
+ cy: number;
31
+ rx: number;
32
+ ry: number;
33
+ rotation: number;
34
+ color: string;
35
+ } | {
36
+ kind: 'rect';
37
+ x: number;
38
+ y: number;
39
+ width: number;
40
+ height: number;
41
+ color: string;
42
+ };
43
+ /** A built-in tile's shapes plus the edge length they're drawn within. */
44
+ interface TileGeometry {
45
+ size: number;
46
+ shapes: TileShape[];
47
+ }
48
+ /** Defaults per tile kind, matching each factory's signature. */
49
+ declare function tileSize(spec: TilePatternSpec): number;
50
+ /** Resolve a pattern spec to the shapes that make up one tile. Consumers that
51
+ * want to draw a pattern swatch themselves — a picker, an SVG export — read
52
+ * this rather than rasterizing a texture. */
53
+ declare function tileGeometry(spec: TilePatternSpec): TileGeometry;
54
+ /** Draw a tile's shapes to a 2D context — the raster half of the pair. */
55
+ declare function drawTileShapes(oc: CanvasRenderingContext2D, geometry: TileGeometry): void;
56
+
57
+ /**
58
+ * Built-in pattern factories — generic line/dot/scatter textures. Each
59
+ * returns a `TextureHandle` you can wrap in a `FillStyle` of
60
+ * `{ fill: 'pattern', pattern }` and pass to anything that accepts a `FillStyle`
61
+ * (`FillStyle`-aware layers, path fills, etc.).
62
+ * Imported from a subpath so consumers that ship their own catalog can
63
+ * avoid the bundle cost.
64
+ *
65
+ * All factories require an explicit `color` (and `bg` for `chunks`). No
66
+ * defaults are baked in — the caller's design system is the source of truth
67
+ * for palette decisions.
68
+ *
69
+ * Each is a thin wrapper over `tileGeometry`, which describes the tile as
70
+ * shapes so `@weasel-js/svg` can emit the same tile as a `<pattern>`.
71
+ * Prefer naming a tile in a `TilePatternSpec` over calling these directly —
72
+ * a spec serializes, a `TextureHandle` does not.
73
+ */
74
+
75
+ /** Diagonal hatch (forward slash). */
76
+ interface HatchParams {
77
+ color: string;
78
+ size?: number;
79
+ lineWidth?: number;
80
+ }
81
+ /** Build a diagonal-hatch pattern texture. */
82
+ declare function hatch(params: HatchParams): TextureHandle | null;
83
+ /** Diagonal hatch in both directions. */
84
+ interface CrosshatchParams {
85
+ color: string;
86
+ size?: number;
87
+ lineWidth?: number;
88
+ }
89
+ /** Build a crosshatch pattern texture. */
90
+ declare function crosshatch(params: CrosshatchParams): TextureHandle | null;
91
+ /** Regular grid of filled dots. */
92
+ interface DotsParams {
93
+ color: string;
94
+ size?: number;
95
+ radius?: number;
96
+ }
97
+ /** Build a dot-grid pattern texture. */
98
+ declare function dots(params: DotsParams): TextureHandle | null;
99
+ /**
100
+ * Random scatter of small ellipses on top of a solid background. Driven by a
101
+ * seeded PRNG so the same `seed` produces a deterministic tile.
102
+ *
103
+ * Note: the `bg` field is optional — omit it for a transparent background
104
+ * (the scatter shapes draw directly onto whatever sits beneath the overlay).
105
+ */
106
+ interface ChunksParams {
107
+ color: string;
108
+ bg?: string;
109
+ size?: number;
110
+ /** Coverage: `chunks * chunkSize²` per `size²` tile. Range ~[0, 1]. */
111
+ density?: number;
112
+ chunkSize?: number;
113
+ seed?: number;
114
+ }
115
+ /** Build a seeded random-scatter pattern texture. */
116
+ declare function chunks(params: ChunksParams): TextureHandle | null;
117
+
118
+ export { type ChunksParams, type CrosshatchParams, type DotsParams, type HatchParams, type TileGeometry, type TileShape, chunks, crosshatch, dots, drawTileShapes, hatch, tileGeometry, tileSize };
@@ -0,0 +1,28 @@
1
+ import { createTilePattern } from './chunk-2VOBNWBN.js';
2
+ import { tileGeometry, drawTileShapes, tileSize } from './chunk-ORBXHIRB.js';
3
+ export { drawTileShapes, tileGeometry, tileSize } from './chunk-ORBXHIRB.js';
4
+
5
+ // src/patterns/patterns-builtin.ts
6
+ function build(spec) {
7
+ const geometry = tileGeometry(spec);
8
+ return createTilePattern({
9
+ size: tileSize(spec),
10
+ draw: (oc) => drawTileShapes(oc, geometry)
11
+ });
12
+ }
13
+ function hatch(params) {
14
+ return build({ tile: "hatch", ...params });
15
+ }
16
+ function crosshatch(params) {
17
+ return build({ tile: "crosshatch", ...params });
18
+ }
19
+ function dots(params) {
20
+ return build({ tile: "dots", ...params });
21
+ }
22
+ function chunks(params) {
23
+ return build({ tile: "chunks", ...params });
24
+ }
25
+
26
+ export { chunks, crosshatch, dots, hatch };
27
+ //# sourceMappingURL=patterns-builtin.js.map
28
+ //# sourceMappingURL=patterns-builtin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/patterns/patterns-builtin.ts"],"names":[],"mappings":";;;;;AA0BA,SAAS,MAAM,IAAA,EAA6C;AAC1D,EAAA,MAAM,QAAA,GAAW,aAAa,IAAI,CAAA;AAClC,EAAA,OAAO,iBAAA,CAAkB;AAAA,IACvB,IAAA,EAAM,SAAS,IAAI,CAAA;AAAA,IACnB,IAAA,EAAM,CAAC,EAAA,KAAO,cAAA,CAAe,IAAI,QAAQ;AAAA,GAC1C,CAAA;AACH;AAUO,SAAS,MAAM,MAAA,EAA2C;AAC/D,EAAA,OAAO,MAAM,EAAE,IAAA,EAAM,OAAA,EAAS,GAAG,QAAQ,CAAA;AAC3C;AAUO,SAAS,WAAW,MAAA,EAAgD;AACzE,EAAA,OAAO,MAAM,EAAE,IAAA,EAAM,YAAA,EAAc,GAAG,QAAQ,CAAA;AAChD;AAUO,SAAS,KAAK,MAAA,EAA0C;AAC7D,EAAA,OAAO,MAAM,EAAE,IAAA,EAAM,MAAA,EAAQ,GAAG,QAAQ,CAAA;AAC1C;AAoBO,SAAS,OAAO,MAAA,EAA4C;AACjE,EAAA,OAAO,MAAM,EAAE,IAAA,EAAM,QAAA,EAAU,GAAG,QAAQ,CAAA;AAC5C","file":"patterns-builtin.js","sourcesContent":["/**\n * Built-in pattern factories — generic line/dot/scatter textures. Each\n * returns a `TextureHandle` you can wrap in a `FillStyle` of\n * `{ fill: 'pattern', pattern }` and pass to anything that accepts a `FillStyle`\n * (`FillStyle`-aware layers, path fills, etc.).\n * Imported from a subpath so consumers that ship their own catalog can\n * avoid the bundle cost.\n *\n * All factories require an explicit `color` (and `bg` for `chunks`). No\n * defaults are baked in — the caller's design system is the source of truth\n * for palette decisions.\n *\n * Each is a thin wrapper over `tileGeometry`, which describes the tile as\n * shapes so `@weasel-js/svg` can emit the same tile as a `<pattern>`.\n * Prefer naming a tile in a `TilePatternSpec` over calling these directly —\n * a spec serializes, a `TextureHandle` does not.\n */\n\nexport { tileGeometry, tileSize, drawTileShapes } from './tileGeometry';\nexport type { TileShape, TileGeometry } from './tileGeometry';\n\nimport { createTilePattern } from './';\nimport { tileGeometry, drawTileShapes, tileSize } from './tileGeometry';\nimport type { TilePatternSpec } from '@weasel-js/paint';\nimport type { TextureHandle } from '../textures/registerTexture';\n\nfunction build(spec: TilePatternSpec): TextureHandle | null {\n const geometry = tileGeometry(spec);\n return createTilePattern({\n size: tileSize(spec),\n draw: (oc) => drawTileShapes(oc, geometry),\n });\n}\n\n/** Diagonal hatch (forward slash). */\nexport interface HatchParams {\n color: string;\n size?: number;\n lineWidth?: number;\n}\n\n/** Build a diagonal-hatch pattern texture. */\nexport function hatch(params: HatchParams): TextureHandle | null {\n return build({ tile: 'hatch', ...params });\n}\n\n/** Diagonal hatch in both directions. */\nexport interface CrosshatchParams {\n color: string;\n size?: number;\n lineWidth?: number;\n}\n\n/** Build a crosshatch pattern texture. */\nexport function crosshatch(params: CrosshatchParams): TextureHandle | null {\n return build({ tile: 'crosshatch', ...params });\n}\n\n/** Regular grid of filled dots. */\nexport interface DotsParams {\n color: string;\n size?: number;\n radius?: number;\n}\n\n/** Build a dot-grid pattern texture. */\nexport function dots(params: DotsParams): TextureHandle | null {\n return build({ tile: 'dots', ...params });\n}\n\n/**\n * Random scatter of small ellipses on top of a solid background. Driven by a\n * seeded PRNG so the same `seed` produces a deterministic tile.\n *\n * Note: the `bg` field is optional — omit it for a transparent background\n * (the scatter shapes draw directly onto whatever sits beneath the overlay).\n */\nexport interface ChunksParams {\n color: string;\n bg?: string;\n size?: number;\n /** Coverage: `chunks * chunkSize²` per `size²` tile. Range ~[0, 1]. */\n density?: number;\n chunkSize?: number;\n seed?: number;\n}\n\n/** Build a seeded random-scatter pattern texture. */\nexport function chunks(params: ChunksParams): TextureHandle | null {\n return build({ tile: 'chunks', ...params });\n}\n"]}