@weasel-js/paint 1.18.2 → 1.19.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/index.d.ts CHANGED
@@ -31,8 +31,9 @@ interface PatternTransformParts {
31
31
  /** `R(rotation) · K(skewX) · S(scaleX, scaleY)`. Omitted parts are identity. */
32
32
  declare function composePatternTransform(parts: Partial<PatternTransformParts>): PatternTransform;
33
33
  /**
34
- * Inverse of {@link composePatternTransform}. Any 2×2 matrix decomposes this
35
- * way; a reflection comes back as a negative `scaleY`. `undefined` reads as the
34
+ * Inverse of {@link composePatternTransform}. Any invertible 2×2 matrix decomposes
35
+ * this way; a reflection comes back as a negative `scaleY`. A singular one whose
36
+ * second column is a nonzero multiple of its first comes back without that column. `undefined` reads as the
36
37
  * identity, which is what an absent `transform` means.
37
38
  */
38
39
  declare function decomposePatternTransform(t: PatternTransform | undefined): PatternTransformParts;
@@ -230,11 +231,6 @@ declare function hexToOklchDeg(hex: string): OklchDeg;
230
231
  declare function srgbToLinear(c: number): number;
231
232
  /** Linear-light channel to sRGB encoding (0..1). Unclamped. */
232
233
  declare function linearToSrgb(c: number): number;
233
- /** HSL to sRGB. Hue in degrees, saturation, lightness and output all 0..1. */
234
- declare function hslToSrgb(h: number, s: number, l: number): [number, number, number];
235
- /** sRGB (0..1) to HSL: `[hue°, saturation, lightness]`, hue in 0..360. An
236
- * achromatic color reports hue 0 and saturation 0. */
237
- declare function srgbToHsl(r: number, g: number, b: number): [number, number, number];
238
234
  /**
239
235
  * The space a color interpolation runs in, spelled as CSS `color-mix()` spells
240
236
  * them. `'srgb'` and `'srgb-linear'` blend gamma-encoded and linear-light
@@ -766,6 +762,12 @@ declare function alignedStrokeRect(rect: {
766
762
  height: number;
767
763
  };
768
764
 
765
+ /** HSL to sRGB. Hue in degrees, any number of turns; saturation, lightness and output all 0..1. */
766
+ declare function hslToSrgb(h: number, s: number, l: number): [number, number, number];
767
+ /** sRGB (0..1) to HSL: `[hue°, saturation, lightness]`, hue in 0..360. An
768
+ * achromatic color reports hue 0 and saturation 0. */
769
+ declare function srgbToHsl(r: number, g: number, b: number): [number, number, number];
770
+
769
771
  type Rgba = readonly [number, number, number, number];
770
772
  /**
771
773
  * `color-mix(in <space>, a p%, b)` for two 0..1 sRGBA colors, `p` as 0..1. The
@@ -860,7 +862,7 @@ declare function rgbaHex(rgba: ArrayLike<number>): string | null;
860
862
  * percent alpha; commas or modern space-separated `R G B / A` syntax
861
863
  * - `hsl()` / `hsla()` with hue as a unitless number (deg) or with `deg`,
862
864
  * `rad`, `grad`, `turn` units; saturation/lightness as percent (or
863
- * unitless in the modern syntax); same alpha rules and separator rules
865
+ * unitless 0..100, as CSS Color 4 reads it); same alpha rules and separator rules
864
866
  * as `rgb()`
865
867
  * - The 148 CSS named colors plus `transparent`
866
868
  * - `color(srgb …)` and `color(srgb-linear …)`; `oklab()` and `oklch()`, clamped into sRGB
package/dist/index.js CHANGED
@@ -31,6 +31,9 @@ function lerpHueDeg(h1, h2, t, method = "shorter") {
31
31
  }
32
32
  var wrapDeg = (h) => (h % 360 + 360) % 360;
33
33
 
34
+ // src/lerp.ts
35
+ var lerp = (a, b, t) => t === 1 ? b : a + (b - a) * t;
36
+
34
37
  // src/hex.ts
35
38
  var HEX = /^#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
36
39
  function parseHexBytes(input) {
@@ -53,6 +56,37 @@ function rgbaHex(rgba) {
53
56
  return `#${byteHex(rgba[0])}${byteHex(rgba[1])}${byteHex(rgba[2])}`;
54
57
  }
55
58
 
59
+ // src/hsl.ts
60
+ function hslToSrgb(h, s, l) {
61
+ if (s === 0) return [l, l, l];
62
+ const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
63
+ const p = 2 * l - q;
64
+ const turn = h / 360;
65
+ const hk = turn >= 0 && turn < 1 ? turn : turn - Math.floor(turn);
66
+ return [hueToChannel(p, q, hk + 1 / 3), hueToChannel(p, q, hk), hueToChannel(p, q, hk - 1 / 3)];
67
+ }
68
+ function hueToChannel(p, q, t) {
69
+ if (t < 0) t += 1;
70
+ if (t > 1) t -= 1;
71
+ if (t < 1 / 6) return p + (q - p) * 6 * t;
72
+ if (t < 1 / 2) return q;
73
+ if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
74
+ return p;
75
+ }
76
+ function srgbToHsl(r, g, b) {
77
+ const max = Math.max(r, g, b);
78
+ const min = Math.min(r, g, b);
79
+ const l = (max + min) / 2;
80
+ const d = max - min;
81
+ if (d === 0) return [0, 0, l];
82
+ const s = Math.min(1, d / (1 - Math.abs(2 * l - 1)));
83
+ let h;
84
+ if (max === r) h = (g - b) / d % 6;
85
+ else if (max === g) h = (b - r) / d + 2;
86
+ else h = (r - g) / d + 4;
87
+ return [(h * 60 % 360 + 360) % 360, s, l];
88
+ }
89
+
56
90
  // src/shortArc.ts
57
91
  var TWO_PI = Math.PI * 2;
58
92
  function shortArc(dh) {
@@ -132,9 +166,9 @@ function oklabToSrgbU8(L, A, B) {
132
166
  }
133
167
  function lerpOklab(from, to, t) {
134
168
  return [
135
- from[0] + (to[0] - from[0]) * t,
136
- from[1] + (to[1] - from[1]) * t,
137
- from[2] + (to[2] - from[2]) * t
169
+ lerp(from[0], to[0], t),
170
+ lerp(from[1], to[1], t),
171
+ lerp(from[2], to[2], t)
138
172
  ];
139
173
  }
140
174
  function oklabToOklch(L, A, B) {
@@ -153,8 +187,8 @@ function lerpOklch(from, to, t) {
153
187
  const h2 = C2 < C_EPS ? h1Raw : h2Raw;
154
188
  const dh = shortArc(h2 - h1);
155
189
  return [
156
- L1 + (L2 - L1) * t,
157
- C1 + (C2 - C1) * t,
190
+ lerp(L1, L2, t),
191
+ lerp(C1, C2, t),
158
192
  h1 + dh * t
159
193
  ];
160
194
  }
@@ -170,7 +204,7 @@ function lerpColorArray(from, to, t, space = "rgb") {
170
204
  const n = from.length / 4;
171
205
  if (space === "rgb") {
172
206
  for (let i = 0; i < from.length; i++) {
173
- out[i] = from[i] + (to[i] - from[i]) * t;
207
+ out[i] = lerp(from[i], to[i], t);
174
208
  }
175
209
  return out;
176
210
  }
@@ -187,7 +221,7 @@ function lerpColorArray(from, to, t, space = "rgb") {
187
221
  out[k] = u2f(r);
188
222
  out[k + 1] = u2f(g);
189
223
  out[k + 2] = u2f(b);
190
- out[k + 3] = from[k + 3] + (to[k + 3] - from[k + 3]) * t;
224
+ out[k + 3] = lerp(from[k + 3], to[k + 3], t);
191
225
  }
192
226
  return out;
193
227
  }
@@ -200,7 +234,7 @@ function lerpColorArray(from, to, t, space = "rgb") {
200
234
  out[k] = u2f(r);
201
235
  out[k + 1] = u2f(g);
202
236
  out[k + 2] = u2f(b);
203
- out[k + 3] = from[k + 3] + (to[k + 3] - from[k + 3]) * t;
237
+ out[k + 3] = lerp(from[k + 3], to[k + 3], t);
204
238
  }
205
239
  return out;
206
240
  }
@@ -224,44 +258,16 @@ function linearToSrgb(c) {
224
258
  const v = a <= 31308e-7 ? a * 12.92 : 1.055 * Math.pow(a, 1 / 2.4) - 0.055;
225
259
  return c < 0 ? -v : v;
226
260
  }
227
- function hslToSrgb(h, s, l) {
228
- if (s === 0) return [l, l, l];
229
- const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
230
- const p = 2 * l - q;
231
- const hk = h / 360;
232
- return [hueToChannel(p, q, hk + 1 / 3), hueToChannel(p, q, hk), hueToChannel(p, q, hk - 1 / 3)];
233
- }
234
- function hueToChannel(p, q, t) {
235
- if (t < 0) t += 1;
236
- if (t > 1) t -= 1;
237
- if (t < 1 / 6) return p + (q - p) * 6 * t;
238
- if (t < 1 / 2) return q;
239
- if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
240
- return p;
241
- }
242
- function srgbToHsl(r, g, b) {
243
- const max = Math.max(r, g, b);
244
- const min = Math.min(r, g, b);
245
- const l = (max + min) / 2;
246
- const d = max - min;
247
- if (d === 0) return [0, 0, l];
248
- const s = d / (1 - Math.abs(2 * l - 1));
249
- let h;
250
- if (max === r) h = (g - b) / d % 6;
251
- else if (max === g) h = (b - r) / d + 2;
252
- else h = (r - g) / d + 4;
253
- return [(h * 60 % 360 + 360) % 360, s, l];
254
- }
255
261
  var ACHROMATIC_EPS = 1e-4;
256
262
  function lerpPolar(a, b, t, method, hueT) {
257
263
  const h1 = a[0] < ACHROMATIC_EPS ? b[1] : a[1];
258
264
  const h2 = b[0] < ACHROMATIC_EPS ? a[1] : b[1];
259
- return [a[0] + (b[0] - a[0]) * t, lerpHueDeg(h1, h2, hueT, method), a[2] + (b[2] - a[2]) * t];
265
+ return [lerp(a[0], b[0], t), lerpHueDeg(h1, h2, hueT, method), lerp(a[2], b[2], t)];
260
266
  }
261
267
  var lerp3 = (a, b, t) => [
262
- a[0] + (b[0] - a[0]) * t,
263
- a[1] + (b[1] - a[1]) * t,
264
- a[2] + (b[2] - a[2]) * t
268
+ lerp(a[0], b[0], t),
269
+ lerp(a[1], b[1], t),
270
+ lerp(a[2], b[2], t)
265
271
  ];
266
272
  var clamp01 = (v) => v < 0 ? 0 : v > 1 ? 1 : v;
267
273
  var srgbToOklabFloat = (c) => linearSrgbToOklab(srgbToLinear(c[0]), srgbToLinear(c[1]), srgbToLinear(c[2]));
@@ -433,8 +439,8 @@ function parseHslFunction(s) {
433
439
  const channels = splitChannels(body);
434
440
  if (!channels) return null;
435
441
  const h = parseHue(channels.rgb[0]);
436
- const sat = parsePercentOrNumber(channels.rgb[1]);
437
- const lit = parsePercentOrNumber(channels.rgb[2]);
442
+ const sat = parseChannel(channels.rgb[1], 100);
443
+ const lit = parseChannel(channels.rgb[2], 100);
438
444
  const a = parseAlpha(channels.alpha);
439
445
  if (h === null || sat === null || lit === null || a === null) return null;
440
446
  const [r, g, b] = hslToSrgb(h, sat, lit);
@@ -463,7 +469,7 @@ function parseOkFunction(s) {
463
469
  const third = lch !== null ? parseHue(channels.rgb[2]) : cssNumber(channels.rgb[2]);
464
470
  const alpha = parseAlpha(channels.alpha);
465
471
  if (L === null || second === null || third === null || alpha === null) return null;
466
- const [, A, B] = lch !== null ? oklchToOklab(L, second, third * (Math.PI / 180)) : [L, second, third];
472
+ const [, A, B] = lch !== null ? oklchToOklab(L, Math.max(0, second), third * (Math.PI / 180)) : [L, second, third];
467
473
  const [r, g, b] = oklabToLinearSrgb(L, A, B).map((c) => clamp012(linearToSrgb(c)));
468
474
  return [r, g, b, alpha];
469
475
  }
@@ -674,7 +680,7 @@ function paintKey(paint) {
674
680
  function solidColorKey(color, opacity) {
675
681
  try {
676
682
  const [r, g, b, a] = parseColor(color);
677
- return `${r},${g},${b},${a * opacity}`;
683
+ return a * opacity === 0 ? "clear" : `${r},${g},${b},${a * opacity}`;
678
684
  } catch {
679
685
  return `text:${color}:${opacity}`;
680
686
  }
@@ -840,7 +846,9 @@ function dashPhase(pattern, phase) {
840
846
  const cycle = pattern.reduce((a, b) => a + b, 0) * (pattern.length % 2 + 1);
841
847
  if (!(cycle > 0)) return 0;
842
848
  const wrapped = phase % cycle;
843
- return wrapped < 0 ? wrapped + cycle : wrapped;
849
+ if (wrapped >= 0) return wrapped;
850
+ const up = wrapped + cycle;
851
+ return up < cycle ? up : 0;
844
852
  }
845
853
  function scaledDash(stroke, k) {
846
854
  if (stroke.dash === void 0 && stroke.dashOffset === void 0) return stroke;
@@ -1028,7 +1036,6 @@ function solidOf(rgba) {
1028
1036
  function solidRgba(paint) {
1029
1037
  return isSolidPaint(paint) ? rgbaOf(paint.color, paint.opacity) : null;
1030
1038
  }
1031
- var lerp = (a, b, t) => a + (b - a) * t;
1032
1039
  function lerpPaint(a, b, t) {
1033
1040
  if (a === void 0 && b === void 0) return void 0;
1034
1041
  if (a === void 0 || b === void 0) {
@@ -1106,7 +1113,7 @@ function lerpStroke(a, b, t) {
1106
1113
  const width = lerpWidth(a == null ? zero(b) : a.width, b == null ? zero(a) : b.width, t);
1107
1114
  const { paint: _p, width: _w, vertexColors: _vc, vertexWidths: _vw, dashOffset: _o, ...rest } = near;
1108
1115
  const from = a?.dashOffset, to = b?.dashOffset;
1109
- const dashOffset = from === void 0 && to === void 0 ? void 0 : (from ?? 0) + ((to ?? 0) - (from ?? 0)) * t;
1116
+ const dashOffset = from === void 0 && to === void 0 ? void 0 : lerp(from ?? 0, to ?? 0, t);
1110
1117
  return {
1111
1118
  ...rest,
1112
1119
  ...paint === void 0 ? {} : { paint },
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/commandPaint.ts","../src/strokeTrim.ts","../src/hue.ts","../src/hex.ts","../src/shortArc.ts","../src/colorSpaces.ts","../src/color.ts","../src/resolvePaint.ts","../src/paintKey.ts","../src/alignedStrokeRect.ts","../src/patternPaint.ts","../src/patternTransform.ts","../src/vertexWidth.ts","../src/paint.ts","../src/mix.ts","../src/contrast.ts","../src/gradient.ts","../src/lerpPaint.ts","../src/palette.ts"],"names":["L","C","h","s","l","parts","clamp01"],"mappings":";AAiCO,SAAS,aAAa,KAAA,EAAsD;AACjF,EAAA,OAAO,SAAS,IAAA,KAAS,KAAA,CAAM,IAAA,KAAS,MAAA,IAAa,MAAM,IAAA,KAAS,OAAA,CAAA;AACtE;;;AChBO,SAAS,cAAc,IAAA,EAAsC;AAClE,EAAA,IAAI,IAAA,KAAS,QAAW,OAAO,EAAA;AAC/B,EAAA,OAAO,CAAA,KAAA,EAAQ,KAAA,CAAM,IAAA,CAAK,KAAA,IAAS,CAAC,CAAC,CAAA,CAAA,EAAI,KAAA,CAAM,IAAA,CAAK,OAAO,CAAC,CAAC,CAAA,CAAA,EAAI,IAAA,CAAK,QAAQ,QAAQ,CAAA,CAAA,CAAA;AACxF;AAEA,SAAS,MAAM,EAAA,EAAoB;AACjC,EAAA,IAAI,OAAO,EAAA,KAAO,QAAA,EAAU,OAAO,OAAO,EAAE,CAAA;AAC5C,EAAA,IAAI,QAAA,IAAY,EAAA,EAAI,OAAO,CAAA,CAAA,EAAI,GAAG,MAAM,CAAA,CAAA;AACxC,EAAA,IAAI,QAAA,IAA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AS,kBAAkB,GAAA,EAAkC;AAClE,EAAA,MAAM,KAAA,GAAQ,IAAI,MAAA,KAAW,CAAA,IAAK,IAAI,MAAA,KAAW,CAAA,GAAI,aAAA,CAAc,GAAG,CAAA,GAAI,IAAA;AAC1E,EAAA,IAAI,CAAC,OAAO,OAAO,IAAA;AACnB,EAAA,MAAM,CAAC,CAAA,EAAG,CAAA,EAAG,CAAA,EAAG,CAAC,CAAA,GAAI,KAAA,CAAM,GAAA,CAAI,CAAC,CAAA,KAAM,CAAA,GAAI,GAAG,CAAA;AAC7C,EAAA,MAAM,MAAA,GAAS,CAAC,CAAA,EAAG,CAAA,EAAG,CAAC,CAAA;AACvB,EAAA,OAAO,CAAA,GAAI,CAAA,GAAI,EAAE,KAAA,EAAO,MAAA,EAAQ,MAAA,EAAQ,KAAA,EAAO,CAAA,EAAE,GAAI,EAAE,KAAA,EAAO,MAAA,EAAQ,MAAA,EAAO;AAC/E","file":"index.js","sourcesContent":["/**\n * The paint a draw command takes: `Paint` and `Stroke` narrowed to what a\n * renderer can draw as it stands. A node's own paint may name its box\n * (`units: 'bounds'`), a tile by kind, or an image by `src`; a command has no\n * node, rasterizer or decoder, so all of these are resolved before one is built.\n */\n\nimport type { Fill, Paint, PaintUnits, Stroke } from './paint';\nimport type { ResolvablePatternKind } from './patternPaint';\n\n/** The spaces a draw command's paint can name. `'bounds'` is not one: it means\n * a node's box, and a command has no node. */\nexport type CommandPaintUnits = Exclude<PaintUnits, 'bounds'>;\n\n/** `F` with `'bounds'` units ruled out, where `F` is a paint that has units. */\nexport type InCommandUnits<F> = F extends { units?: PaintUnits }\n ? Omit<F, 'units'> & { units?: CommandPaintUnits }\n : F;\n\n/** A `Paint` placed in a frame a command can name. Its pattern may still\n * be a tile kind or an image. */\nexport type PosedPaint = InCommandUnits<Paint>;\n\n/** A `Paint` a renderer can draw as it stands: no paint is in `'bounds'`\n * units, and a pattern is a registered `texture` rather than a tile kind or\n * an image. */\nexport type CommandPaint = Exclude<PosedPaint, { kind: ResolvablePatternKind }>;\n\n/** The solid member of `Paint`: a color and an opacity. */\nexport type SolidPaint = Extract<Paint, { kind?: 'solid' }>;\n\n/** Whether a paint is the solid member. A tile paint carries a `color` too, so\n * the presence of one does not answer this. */\nexport function isSolidPaint(paint: Paint | null | undefined): paint is SolidPaint {\n return paint != null && (paint.kind === undefined || paint.kind === 'solid');\n}\n\n/** A `Fill` whose paint is a {@link CommandPaint}. */\nexport interface CommandFill extends Omit<Fill, 'paint'> {\n paint?: CommandPaint;\n}\n\n/** A `Stroke` whose paint is a {@link CommandPaint}. */\nexport type CommandStroke = Omit<Stroke, 'paint'> & { paint?: CommandPaint };\n","/**\n * Where along a path a {@link StrokeTrim} edge sits. A bare number is a\n * fraction of the whole path; the object forms name an absolute distance, an\n * anchor (vertex) index, or a subpath index.\n */\nexport type TrimAt = number | { length: number } | { anchor: number } | { subpath: number };\n\n/** What a fractional trim edge advances by: arc length, or anchor by anchor. */\nexport type TrimPace = 'length' | 'anchor';\n\n/** The stretch of a path a stroke draws, so a path can be drawn on in pen order. */\nexport interface StrokeTrim {\n start?: TrimAt;\n end?: TrimAt;\n pace?: TrimPace;\n}\n\n/** A stable string per trim value, `''` for no trim; for cache and equality keys. An omitted\n * edge keys as its default, so `{ end: 0.5 }` and `{ start: 0, end: 0.5 }` share one. */\nexport function strokeTrimKey(trim: StrokeTrim | undefined): string {\n if (trim === undefined) return '';\n return `trim(${atKey(trim.start ?? 0)},${atKey(trim.end ?? 1)},${trim.pace ?? 'length'})`;\n}\n\nfunction atKey(at: TrimAt): string {\n if (typeof at === 'number') return String(at);\n if ('length' in at) return `l${at.length}`;\n if ('anchor' in at) return `a${at.anchor}`;\n return `s${at.subpath}`;\n}\n","/** Which way a polar space's hue goes between two endpoints, as CSS\n * `hue-interpolation-method`: the arc of at most 180°, or the other one. */\nexport type HueInterpolation = 'shorter' | 'longer';\n\n/** The hue `t` of the way from `h1` to `h2`, in degrees, along the arc `method` names, in [0, 360). Both hues are\n * taken into [0, 360) first, and a half turn keeps the sign of `h2 - h1`, as CSS's fixup does: 180° to 0° passes\n * 90°. Equal hues stay put under `longer`, where CSS would go a full turn. */\nexport function lerpHueDeg(h1: number, h2: number, t: number, method: HueInterpolation = 'shorter'): number {\n const a = wrapDeg(h1);\n let dh = wrapDeg(h2) - a;\n if (method === 'shorter') {\n if (dh > 180) dh -= 360;\n else if (dh < -180) dh += 360;\n } else if (dh > 0 && dh < 180) {\n dh -= 360;\n } else if (dh < 0 && dh > -180) {\n dh += 360;\n }\n return wrapDeg(a + dh * t);\n}\n\nconst wrapDeg = (h: number): number => ((h % 360) + 360) % 360;\n","const HEX = /^#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;\n\n/**\n * The kit's one hex color reader: `#rgb`, `#rgba`, `#rrggbb`, or `#rrggbbaa`,\n * in any case, as four 0..255 channels with alpha last (255 when the color\n * names none). `null` for anything else, a missing `#` included.\n */\nexport function parseHexBytes(input: string): [number, number, number, number] | null {\n if (!HEX.test(input)) return null;\n const digits = input.slice(1);\n const long = digits.length <= 4 ? digits.replace(/./g, '$&$&') : digits;\n const byte = (i: number): number => Number.parseInt(long.slice(i, i + 2), 16);\n return [byte(0), byte(2), byte(4), long.length === 8 ? byte(6) : 255];\n}\n\n/** The kit's one hex color writer: a 0..255 channel as two hex digits, rounded and clamped; NaN as 0. */\nexport function byteHex(v: number): string {\n return (Math.max(0, Math.min(255, Math.round(v))) || 0).toString(16).padStart(2, '0');\n}\n\n/** A hex color's red, green, and blue as 0..255, its alpha dropped. Throws on anything {@link parseHexBytes} does not read. */\nexport function hexToRgbBytes(input: string): [number, number, number] {\n const bytes = parseHexBytes(input);\n if (!bytes) throw new Error(`not a hex color: \"${input}\"`);\n return [bytes[0], bytes[1], bytes[2]];\n}\n\n/** An RGBA pixel's bytes as `#rrggbb`, or `null` where it is fully transparent: the color a\n * sampler reports for what is drawn at a point. Alpha is dropped, not composited. */\nexport function rgbaHex(rgba: ArrayLike<number>): string | null {\n if (rgba[3] === 0) return null;\n return `#${byteHex(rgba[0])}${byteHex(rgba[1])}${byteHex(rgba[2])}`;\n}\n","const TWO_PI = Math.PI * 2;\n\n/** `dh` radians as the shorter arc, in [-π, π]: a half turn keeps its sign. NaN for NaN and ±∞.\n * geom's `wrapAngle(dh, 'sign')`, kept here because paint does not depend on geom. */\nexport function shortArc(dh: number): number {\n const r = dh % TWO_PI;\n return r > Math.PI ? r - TWO_PI : r < -Math.PI ? r + TWO_PI : r;\n}\n","// sRGB ↔ OKLab conversion. Reference: https://bottosson.github.io/posts/oklab/\n\nimport { lerpHueDeg, type HueInterpolation } from './hue';\nimport { byteHex, hexToRgbBytes } from './hex';\nimport { shortArc } from './shortArc';\n\nconst SRGB_TO_LINEAR: Float64Array = (() => {\n const lut = new Float64Array(256);\n for (let i = 0; i < 256; i++) {\n const c = i / 255;\n lut[i] = c <= 0.04045 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);\n }\n return lut;\n})();\n\nfunction linearToSrgbByte(c: number): number {\n if (c <= 0) return 0;\n if (c >= 1) return 255;\n const v = c <= 0.0031308 ? c * 12.92 : 1.055 * Math.pow(c, 1 / 2.4) - 0.055;\n return Math.round(v * 255);\n}\n\n/** 0..1 float channel to the 8-bit index the LUTs are cut for. Rounds and\n * clamps; `& 0xff` would truncate, and wrap anything out of range. */\nconst f2u = (v: number): number => Math.max(0, Math.min(255, Math.round(v * 255)));\n\n/**\n * Convert a 0..1 float sRGB triple to OKLab — the renderer's own color space,\n * and what a caller holding a `resolveColor` result has. Rounds into the u8\n * grid the way every other float→u8 crossing in this file does, rather than\n * leaving each caller to pick a convention.\n */\nexport function srgbFloatToOklab(r: number, g: number, b: number): [number, number, number] {\n return srgbU8ToOklab(f2u(r), f2u(g), f2u(b));\n}\n\n/** Convert an 8-bit sRGB triple to OKLab. Channels are indices into a 256-entry\n * LUT: pass integers, or `srgbFloatToOklab` for 0..1 floats. */\nexport function srgbU8ToOklab(r: number, g: number, b: number): [number, number, number] {\n return linearSrgbToOklab(SRGB_TO_LINEAR[r & 0xff], SRGB_TO_LINEAR[g & 0xff], SRGB_TO_LINEAR[b & 0xff]);\n}\n\n/** Linear-light sRGB (0..1 floats, unclamped) to OKLab. */\nexport function linearSrgbToOklab(rl: number, gl: number, bl: number): [number, number, number] {\n const l = 0.4122214708 * rl + 0.5363325363 * gl + 0.0514459929 * bl;\n const m = 0.2119034982 * rl + 0.6806995451 * gl + 0.1073969566 * bl;\n const s = 0.0883024619 * rl + 0.2817188376 * gl + 0.6299787005 * bl;\n const lp = Math.cbrt(l);\n const mp = Math.cbrt(m);\n const sp = Math.cbrt(s);\n return [\n 0.2104542553 * lp + 0.7936177850 * mp - 0.0040720468 * sp,\n 1.9779984951 * lp - 2.4285922050 * mp + 0.4505937099 * sp,\n 0.0259040371 * lp + 0.7827717662 * mp - 0.8086757660 * sp,\n ];\n}\n\n/** OKLab to linear-light sRGB. Not gamut-clipped: out-of-gamut colors come\n * back with channels outside 0..1. */\nexport function oklabToLinearSrgb(L: number, A: number, B: number): [number, number, number] {\n const lp = L + 0.3963377774 * A + 0.2158037573 * B;\n const mp = L - 0.1055613458 * A - 0.0638541728 * B;\n const sp = L - 0.0894841775 * A - 1.2914855480 * B;\n const l = lp * lp * lp;\n const m = mp * mp * mp;\n const s = sp * sp * sp;\n return [\n +4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s,\n -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s,\n -0.0041960863 * l - 0.7034186147 * m + 1.7076147010 * s,\n ];\n}\n\nfunction inGamut(rl: number, gl: number, bl: number): boolean {\n // Small epsilon absorbs float-roundtrip noise on pure-primary colors.\n const eps = 1e-6;\n return (\n rl >= -eps && rl <= 1 + eps &&\n gl >= -eps && gl <= 1 + eps &&\n bl >= -eps && bl <= 1 + eps\n );\n}\n\nfunction clipToGamut(L: number, A: number, B: number): [number, number, number] {\n let [rl, gl, bl] = oklabToLinearSrgb(L, A, B);\n if (inGamut(rl, gl, bl)) return [rl, gl, bl];\n let lo = 0;\n let hi = 1;\n // 5 iterations → ~3% chroma precision; sufficient for u8 output.\n for (let i = 0; i < 5; i++) {\n const t = (lo + hi) / 2;\n [rl, gl, bl] = oklabToLinearSrgb(L, A * t, B * t);\n if (inGamut(rl, gl, bl)) lo = t; else hi = t;\n }\n [rl, gl, bl] = oklabToLinearSrgb(L, A * lo, B * lo);\n return [rl, gl, bl];\n}\n\n/** Convert OKLab back to an 8-bit sRGB triple, clamped into gamut. */\nexport function oklabToSrgbU8(L: number, A: number, B: number): [number, number, number] {\n const [rl, gl, bl] = clipToGamut(L, A, B);\n return [linearToSrgbByte(rl), linearToSrgbByte(gl), linearToSrgbByte(bl)];\n}\n\n/** Blend two 8-bit sRGB colors through OKLab. Perceptually even, and it does\n * not pass through the muddy midpoints an sRGB blend produces between\n * complementary hues. */\nexport function lerpOklab(\n from: readonly [number, number, number],\n to: readonly [number, number, number],\n t: number,\n): [number, number, number] {\n return [\n from[0] + (to[0] - from[0]) * t,\n from[1] + (to[1] - from[1]) * t,\n from[2] + (to[2] - from[2]) * t,\n ];\n}\n\n/** Convert OKLab (L, a, b) to OKLCh (L, C, h). h is in radians, range [-π, π]. */\nexport function oklabToOklch(L: number, A: number, B: number): [number, number, number] {\n const C = Math.hypot(A, B);\n const h = Math.atan2(B, A);\n return [L, C, h];\n}\n\n/** Convert OKLCh (L, C, h) to OKLab (L, a, b). h is in radians. */\nexport function oklchToOklab(L: number, C: number, h: number): [number, number, number] {\n return [L, C * Math.cos(h), C * Math.sin(h)];\n}\n\n/** Lerp OKLCh values with shortest-arc hue interpolation. Lightness and\n * chroma lerp linearly. When chroma is near zero on either endpoint, hue\n * is taken from the other endpoint (avoids hue snap-from-undefined).\n * h inputs are in radians. */\nexport function lerpOklch(\n from: readonly [number, number, number],\n to: readonly [number, number, number],\n t: number,\n): [number, number, number] {\n const [L1, C1, h1Raw] = from;\n const [L2, C2, h2Raw] = to;\n const C_EPS = 1e-4;\n // When one endpoint is near-achromatic, take hue from the other endpoint\n // to avoid spurious arc rotation through undefined hue space.\n const h1 = C1 < C_EPS ? h2Raw : h1Raw;\n const h2 = C2 < C_EPS ? h1Raw : h2Raw;\n const dh = shortArc(h2 - h1);\n return [\n L1 + (L2 - L1) * t,\n C1 + (C2 - C1) * t,\n h1 + dh * t,\n ];\n}\n\n/** Which space a color blend is computed in. `'rgb'` is cheapest; `'oklab'`\n * is perceptually even; `'oklch'` additionally travels around the hue wheel\n * rather than through it. */\nexport type ColorSpace = 'rgb' | 'oklab' | 'oklch';\n\nconst u2f = (v: number): number => v / 255;\n\n/** Lerp a flat RGBA color array `from` toward `to`. Inputs are 0..1\n * floats (the renderer's color space); outputs are 0..1 floats too.\n * Alpha is always linearly lerped; RGB channels are lerped in the\n * requested color space. OKLab / OKLCh paths bounce through u8 because\n * the gamma-correction LUT and gamut-clip routines are byte-keyed —\n * the round-trip is lossy at <1% per channel, well under the visible\n * threshold for these animations. */\nexport function lerpColorArray(\n from: readonly number[],\n to: readonly number[],\n t: number,\n space: ColorSpace = 'rgb',\n): number[] {\n if (from.length !== to.length) {\n throw new Error(`lerpColorArray: length mismatch (from=${from.length}, to=${to.length})`);\n }\n if (from.length % 4 !== 0) {\n throw new Error(`lerpColorArray: length ${from.length} not divisible by 4`);\n }\n const out = new Array<number>(from.length);\n const n = from.length / 4;\n if (space === 'rgb') {\n // Pure float lerp — no rounding (which previously discretized 0..1\n // inputs to 0/1, giving the cycle its 'choppy 8-corner' look).\n for (let i = 0; i < from.length; i++) {\n out[i] = from[i] + (to[i] - from[i]) * t;\n }\n return out;\n }\n if (space === 'oklch') {\n for (let i = 0; i < n; i++) {\n const k = i * 4;\n const fLab = srgbU8ToOklab(f2u(from[k]), f2u(from[k + 1]), f2u(from[k + 2]));\n const tLab = srgbU8ToOklab(f2u(to[k]), f2u(to[k + 1]), f2u(to[k + 2]));\n const fLch = oklabToOklch(fLab[0], fLab[1], fLab[2]);\n const tLch = oklabToOklch(tLab[0], tLab[1], tLab[2]);\n const midLch = lerpOklch(fLch, tLch, t);\n const midLab = oklchToOklab(midLch[0], midLch[1], midLch[2]);\n const [r, g, b] = oklabToSrgbU8(midLab[0], midLab[1], midLab[2]);\n out[k] = u2f(r);\n out[k + 1] = u2f(g);\n out[k + 2] = u2f(b);\n out[k + 3] = from[k + 3] + (to[k + 3] - from[k + 3]) * t;\n }\n return out;\n }\n for (let i = 0; i < n; i++) {\n const k = i * 4;\n const fLab = srgbU8ToOklab(f2u(from[k]), f2u(from[k + 1]), f2u(from[k + 2]));\n const tLab = srgbU8ToOklab(f2u(to[k]), f2u(to[k + 1]), f2u(to[k + 2]));\n const mid = lerpOklab(fLab, tLab, t);\n const [r, g, b] = oklabToSrgbU8(mid[0], mid[1], mid[2]);\n out[k] = u2f(r);\n out[k + 1] = u2f(g);\n out[k + 2] = u2f(b);\n out[k + 3] = from[k + 3] + (to[k + 3] - from[k + 3]) * t;\n }\n return out;\n}\n\n// ---------------------------------------------------------------------------\n// OKLCh in degrees\n// ---------------------------------------------------------------------------\n\n/**\n * OKLCh with the hue in **degrees**, and `#rrggbb` on the other side.\n *\n * The helpers above take radians, because that is what the math wants. Every\n * consumer that authors colors — a theme ramp, a palette generator — wants\n * degrees and a hex string, and two packages independently built the same\n * wrapper before this existed.\n */\nexport interface OklchDeg {\n readonly L: number;\n readonly C: number;\n /** 0..360. */\n readonly H: number;\n}\n\n/**\n * OKLCh (hue in degrees) to `#rrggbb`. Over-saturated requests come back at\n * the gamut boundary: `oklabToSrgbU8` clips chroma at constant lightness, which\n * is what lets a caller find a hue's ceiling by asking for far more than exists.\n */\nexport function oklchDegToHex(L: number, C: number, hueDeg: number): string {\n const [l, a, b] = oklchToOklab(L, C, (hueDeg * Math.PI) / 180);\n const [r, g, bl] = oklabToSrgbU8(l, a, b);\n return `#${byteHex(r)}${byteHex(g)}${byteHex(bl)}`;\n}\n\n/** A hex color (`#rgb`, `#rgba`, `#rrggbb`, or `#rrggbbaa`, alpha ignored) to\n * OKLCh with the hue wrapped into 0..360. Throws on anything else. */\nexport function hexToOklchDeg(hex: string): OklchDeg {\n const [L, A, B] = srgbU8ToOklab(...hexToRgbBytes(hex));\n const [l, c, h] = oklabToOklch(L, A, B);\n return { L: l, C: c, H: ((((h * 180) / Math.PI) % 360) + 360) % 360 };\n}\n\n// ---------------------------------------------------------------------------\n// Float sRGB transfer, HSL, and interpolation across spaces\n// ---------------------------------------------------------------------------\n\n/** sRGB-encoded channel (0..1) to linear light. Unclamped; odd-symmetric\n * below zero, as CSS `srgb-linear` extends it. */\nexport function srgbToLinear(c: number): number {\n const a = Math.abs(c);\n const v = a <= 0.04045 ? a / 12.92 : Math.pow((a + 0.055) / 1.055, 2.4);\n return c < 0 ? -v : v;\n}\n\n/** Linear-light channel to sRGB encoding (0..1). Unclamped. */\nexport function linearToSrgb(c: number): number {\n const a = Math.abs(c);\n const v = a <= 0.0031308 ? a * 12.92 : 1.055 * Math.pow(a, 1 / 2.4) - 0.055;\n return c < 0 ? -v : v;\n}\n\n/** HSL to sRGB. Hue in degrees, saturation, lightness and output all 0..1. */\nexport function hslToSrgb(h: number, s: number, l: number): [number, number, number] {\n if (s === 0) return [l, l, l];\n const q = l < 0.5 ? l * (1 + s) : l + s - l * s;\n const p = 2 * l - q;\n const hk = h / 360;\n return [hueToChannel(p, q, hk + 1 / 3), hueToChannel(p, q, hk), hueToChannel(p, q, hk - 1 / 3)];\n}\n\nfunction hueToChannel(p: number, q: number, t: number): number {\n if (t < 0) t += 1;\n if (t > 1) t -= 1;\n if (t < 1 / 6) return p + (q - p) * 6 * t;\n if (t < 1 / 2) return q;\n if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;\n return p;\n}\n\n/** sRGB (0..1) to HSL: `[hue°, saturation, lightness]`, hue in 0..360. An\n * achromatic color reports hue 0 and saturation 0. */\nexport function srgbToHsl(r: number, g: number, b: number): [number, number, number] {\n const max = Math.max(r, g, b);\n const min = Math.min(r, g, b);\n const l = (max + min) / 2;\n const d = max - min;\n if (d === 0) return [0, 0, l];\n const s = d / (1 - Math.abs(2 * l - 1));\n let h: number;\n if (max === r) h = ((g - b) / d) % 6;\n else if (max === g) h = (b - r) / d + 2;\n else h = (r - g) / d + 4;\n return [(((h * 60) % 360) + 360) % 360, s, l];\n}\n\n/**\n * The space a color interpolation runs in, spelled as CSS `color-mix()` spells\n * them. `'srgb'` and `'srgb-linear'` blend gamma-encoded and linear-light\n * channels; `'oklab'` blends perceptual coordinates; `'oklch'` and `'hsl'` are\n * polar, so their hue travels around the wheel rather than through it.\n *\n * Distinct from {@link ColorSpace}, the gradient and animation vocabulary,\n * which keeps its `'rgb'` spelling and its byte-precision paths.\n */\nexport type ColorInterpolationSpace = 'oklch' | 'oklab' | 'hsl' | 'srgb' | 'srgb-linear';\n\n/** An endpoint with less chroma (OKLCH) or saturation (HSL) than this has no\n * hue of its own. */\nconst ACHROMATIC_EPS = 1e-4;\n\ntype Polar = readonly [radius: number, hueDeg: number, axis: number];\n\nfunction lerpPolar(a: Polar, b: Polar, t: number, method: HueInterpolation, hueT: number): [number, number, number] {\n const h1 = a[0] < ACHROMATIC_EPS ? b[1] : a[1];\n const h2 = b[0] < ACHROMATIC_EPS ? a[1] : b[1];\n return [a[0] + (b[0] - a[0]) * t, lerpHueDeg(h1, h2, hueT, method), a[2] + (b[2] - a[2]) * t];\n}\n\ntype Rgb = readonly [number, number, number];\n\nconst lerp3 = (a: Rgb, b: Rgb, t: number): [number, number, number] => [\n a[0] + (b[0] - a[0]) * t,\n a[1] + (b[1] - a[1]) * t,\n a[2] + (b[2] - a[2]) * t,\n];\n\nconst clamp01 = (v: number): number => (v < 0 ? 0 : v > 1 ? 1 : v);\n\nconst srgbToOklabFloat = (c: Rgb): [number, number, number] =>\n linearSrgbToOklab(srgbToLinear(c[0]), srgbToLinear(c[1]), srgbToLinear(c[2]));\n\nfunction oklabToSrgbClipped(L: number, A: number, B: number): [number, number, number] {\n const [rl, gl, bl] = clipToGamut(L, A, B);\n return [clamp01(linearToSrgb(rl)), clamp01(linearToSrgb(gl)), clamp01(linearToSrgb(bl))];\n}\n\n/**\n * Interpolate between two sRGB colors (0..1 floats) in `space`, at `t` in 0..1.\n * Float precision throughout, with no byte round-trip. The result is sRGB;\n * only OKLab and OKLCH blends can leave gamut, and those come back\n * chroma-clipped at constant OKLab lightness.\n *\n * `hue` applies to the polar spaces only. An endpoint with no chroma (OKLCH)\n * or no saturation (HSL) borrows the other endpoint's hue, so a ramp to white\n * or black holds its hue instead of sweeping from red.\n */\nexport function interpolateSrgb(\n from: readonly [number, number, number],\n to: readonly [number, number, number],\n t: number,\n space: ColorInterpolationSpace = 'oklch',\n hue: HueInterpolation = 'shorter',\n): [number, number, number] {\n return interpolateSrgbSplit(from, to, t, t, space, hue);\n}\n\n/** {@link interpolateSrgb} with the hue of a polar space at `hueT` and everything else at `t`, as a premultiplied mix needs. */\nexport function interpolateSrgbSplit(\n from: Rgb,\n to: Rgb,\n t: number,\n hueT: number,\n space: ColorInterpolationSpace,\n hue: HueInterpolation,\n): [number, number, number] {\n switch (space) {\n case 'srgb':\n return lerp3(from, to, t);\n case 'srgb-linear': {\n const lin = (c: Rgb): Rgb => [srgbToLinear(c[0]), srgbToLinear(c[1]), srgbToLinear(c[2])];\n const [r, g, b] = lerp3(lin(from), lin(to), t);\n return [linearToSrgb(r), linearToSrgb(g), linearToSrgb(b)];\n }\n case 'oklab': {\n const [L, A, B] = lerp3(srgbToOklabFloat(from), srgbToOklabFloat(to), t);\n return oklabToSrgbClipped(L, A, B);\n }\n case 'oklch': {\n const polar = (c: Rgb): Polar => {\n const [L, C, h] = oklabToOklch(...srgbToOklabFloat(c));\n return [C, (((h * 180) / Math.PI) % 360 + 360) % 360, L];\n };\n const [C, H, L] = lerpPolar(polar(from), polar(to), t, hue, hueT);\n const [l, a, b] = oklchToOklab(L, C, (H * Math.PI) / 180);\n return oklabToSrgbClipped(l, a, b);\n }\n case 'hsl': {\n const polar = (c: Rgb): Polar => {\n const [h, s, l] = srgbToHsl(c[0], c[1], c[2]);\n return [s, h, l];\n };\n const [s, h, l] = lerpPolar(polar(from), polar(to), t, hue, hueT);\n return hslToSrgb(h, s, l);\n }\n }\n}\n","import { hslToSrgb, linearToSrgb, oklabToLinearSrgb, oklchToOklab } from './colorSpaces';\nimport { byteHex, parseHexBytes } from './hex';\n\n/**\n * Parse a CSS color string into [r, g, b, a] with 0..1 components.\n *\n * Supported forms:\n * - Hex: `#rgb`, `#rgba`, `#rrggbb`, `#rrggbbaa` (any case)\n * - `rgb()` / `rgba()` with integer, float, or percent R/G/B; number or\n * percent alpha; commas or modern space-separated `R G B / A` syntax\n * - `hsl()` / `hsla()` with hue as a unitless number (deg) or with `deg`,\n * `rad`, `grad`, `turn` units; saturation/lightness as percent (or\n * unitless in the modern syntax); same alpha rules and separator rules\n * as `rgb()`\n * - The 148 CSS named colors plus `transparent`\n * - `color(srgb …)` and `color(srgb-linear …)`; `oklab()` and `oklch()`, clamped into sRGB\n *\n * Not supported: `lab()`, `lch()`, other `color()` spaces, `currentColor`, system\n * colors. Throws on anything unrecognized.\n *\n * Results are cached by input-string identity. Callers MUST treat the\n * returned tuple as read-only — mutation would corrupt the cache.\n */\nexport function parseColor(input: string): [number, number, number, number] {\n const cached = CACHE.get(input);\n if (cached !== undefined) return cached;\n const result = parseColorUncached(input);\n if (CACHE.size >= CACHE_MAX) CACHE.clear();\n CACHE.set(input, result);\n return result;\n}\n\nconst CACHE = new Map<string, [number, number, number, number]>();\nconst CACHE_MAX = 1024;\n\nfunction parseColorUncached(input: string): [number, number, number, number] {\n const s = input.trim();\n if (s.startsWith('#')) return parseHex(s);\n\n const lower = s.toLowerCase();\n\n if (Object.hasOwn(NAMED_COLORS, lower)) return NAMED_COLORS[lower]!;\n\n if (lower.startsWith('rgb')) {\n const parsed = parseRgbFunction(lower);\n if (parsed) return parsed;\n }\n if (lower.startsWith('hsl')) {\n const parsed = parseHslFunction(lower);\n if (parsed) return parsed;\n }\n if (lower.startsWith('color(')) {\n const parsed = parseColorFunction(lower);\n if (parsed) return parsed;\n }\n if (lower.startsWith('ok')) {\n const parsed = parseOkFunction(lower);\n if (parsed) return parsed;\n }\n\n throw new Error(`parseColor: unrecognized color \"${input}\"`);\n}\n\n/** `parseColor`, typed read-only: the form for renderer hot paths (per-frame\n * draw callbacks, gradient ramp builds), which share its cache. */\nexport function resolveColor(input: string): readonly [number, number, number, number] {\n return parseColor(input);\n}\n\n/** @internal Test-only: drops the color cache so tests can assert behavior in\n * isolation. Never call from production code. */\nexport function __resetResolveColorCache(): void {\n CACHE.clear();\n}\n\n/** Same as `parseColor` but returns integer 0..255 components. */\nexport function parseColorToRgba255(input: string): [number, number, number, number] {\n const [r, g, b, a] = parseColor(input);\n return [\n Math.round(r * 255),\n Math.round(g * 255),\n Math.round(b * 255),\n Math.round(a * 255),\n ];\n}\n\n/** The hex form {@link normalizeHex} writes: `'rgb'` drops alpha, `'rgba'` always writes it (`ff` when none was named). */\nexport type HexForm = 'rgb' | 'rgba';\n\n/**\n * Canonicalize a hex color string to lowercase `#rrggbb` or `#rrggbbaa`: the\n * latter when `form` is `'rgba'`, or with no `form`, when the input names an alpha.\n *\n * Accepts: `#rgb`, `#rgba`, `#rrggbb`, `#rrggbbaa`, with or without the\n * leading `#`, any case. Throws on other inputs.\n */\nexport function normalizeHex(input: string, form?: HexForm): string {\n const hex = tryNormalizeHex(input, form);\n if (hex === undefined) throw new Error(`normalizeHex: invalid hex \"${input}\"`);\n return hex;\n}\n\n/** {@link normalizeHex}, undefined where it would throw. */\nexport function tryNormalizeHex(input: string, form?: HexForm): string | undefined {\n const trimmed = input.trim();\n const hashed = trimmed.startsWith('#') ? trimmed : `#${trimmed}`;\n const bytes = parseHexBytes(hashed);\n if (!bytes) return undefined;\n const digits = bytes.map(byteHex).join('');\n const alpha = form ? form === 'rgba' : hashed.length === 5 || hashed.length === 9;\n return `#${alpha ? digits : digits.slice(0, 6)}`;\n}\n\n/**\n * Parse a hex color into [r, g, b, a] with 0..1 components. Accepts the same\n * forms as `normalizeHex`, including a missing leading `#`.\n */\nexport function hexToRgba(input: string): [number, number, number, number] {\n return parseHex(normalizeHex(input));\n}\n\n/**\n * Format [r, g, b, a] (0..1 components) as a hex string. Emits `#rrggbb` when\n * alpha is exactly 1 (or omitted), otherwise `#rrggbbaa`.\n */\nexport function rgbaToHex(rgba: readonly [number, number, number, number] | readonly [number, number, number]): string {\n const [r, g, b] = rgba;\n const a = rgba.length === 4 ? rgba[3] : 1;\n const f = (n: number) => byteHex(n * 255);\n const base = `#${f(r)}${f(g)}${f(b)}`;\n return a >= 1 ? base : `${base}${f(a)}`;\n}\n\nfunction parseHex(s: string): [number, number, number, number] {\n const bytes = parseHexBytes(s);\n if (!bytes) throw new Error(`parseColor: invalid hex \"${s}\"`);\n return [bytes[0] / 255, bytes[1] / 255, bytes[2] / 255, bytes[3] / 255];\n}\n\n/** Match `name( body )` and return the trimmed body, or null. */\nfunction unwrapFn(s: string, name: string): string | null {\n if (!s.startsWith(name + '(') || !s.endsWith(')')) return null;\n return s.slice(name.length + 1, -1).trim();\n}\n\n/**\n * Split a function body into the value tokens (3 channels + optional alpha).\n * Supports both legacy `r, g, b[, a]` and modern `r g b[ / a]` separators.\n * Returns null if the token count is wrong.\n */\nfunction splitChannels(body: string): { rgb: [string, string, string]; alpha: string | null } | null {\n if (body.includes(',')) {\n const parts = body.split(',').map((p) => p.trim());\n if (parts.length !== 3 && parts.length !== 4) return null;\n return {\n rgb: [parts[0], parts[1], parts[2]],\n alpha: parts.length === 4 ? parts[3] : null,\n };\n }\n // Modern syntax: whitespace-separated, with optional `/ alpha` tail.\n const slash = body.indexOf('/');\n const head = (slash === -1 ? body : body.slice(0, slash)).trim();\n const alpha = slash === -1 ? null : body.slice(slash + 1).trim();\n const parts = head.split(/\\s+/);\n if (parts.length !== 3) return null;\n if (alpha !== null && alpha === '') return null;\n return { rgb: [parts[0], parts[1], parts[2]], alpha };\n}\n\nconst CSS_NUMBER = /^[+-]?(?:\\d+\\.?\\d*|\\.\\d+)(?:e[+-]?\\d+)?$/;\n\n/** A CSS `<number>` token, or null: `Number` alone reads `''` as 0 and accepts `0x10`. */\nfunction cssNumber(tok: string): number | null {\n if (!CSS_NUMBER.test(tok)) return null;\n const n = Number(tok);\n return Number.isFinite(n) ? n : null;\n}\n\n/** Parse a channel value: integer, float, or percent. Returns 0..1 (with `max` as the integer scale). */\nfunction parseChannel(tok: string, max: number): number | null {\n const percent = tok.endsWith('%');\n const n = cssNumber(percent ? tok.slice(0, -1) : tok);\n return n === null ? null : clamp01(n / (percent ? 100 : max));\n}\n\n/** Alpha may be a number 0..1 or a percent; absent is opaque. */\nfunction parseAlpha(tok: string | null): number | null {\n return tok === null ? 1 : parseChannel(tok, 1);\n}\n\nfunction parseRgbFunction(s: string): [number, number, number, number] | null {\n const body = unwrapFn(s, 'rgba') ?? unwrapFn(s, 'rgb');\n if (body === null) return null;\n const channels = splitChannels(body);\n if (!channels) return null;\n const r = parseChannel(channels.rgb[0], 255);\n const g = parseChannel(channels.rgb[1], 255);\n const b = parseChannel(channels.rgb[2], 255);\n const a = parseAlpha(channels.alpha);\n if (r === null || g === null || b === null || a === null) return null;\n return [r, g, b, a];\n}\n\nfunction parseHslFunction(s: string): [number, number, number, number] | null {\n const body = unwrapFn(s, 'hsla') ?? unwrapFn(s, 'hsl');\n if (body === null) return null;\n const channels = splitChannels(body);\n if (!channels) return null;\n const h = parseHue(channels.rgb[0]);\n const sat = parsePercentOrNumber(channels.rgb[1]);\n const lit = parsePercentOrNumber(channels.rgb[2]);\n const a = parseAlpha(channels.alpha);\n if (h === null || sat === null || lit === null || a === null) return null;\n const [r, g, b] = hslToSrgb(h, sat, lit);\n return [r, g, b, a];\n}\n\n/** `color(srgb …)` or `color(srgb-linear …)`, channels as numbers 0..1 or percents. */\nfunction parseColorFunction(s: string): [number, number, number, number] | null {\n const body = unwrapFn(s, 'color');\n const space = body?.match(/^(srgb-linear|srgb)\\s+/);\n if (!body || !space || body.includes(',')) return null;\n const channels = splitChannels(body.slice(space[0].length));\n if (!channels) return null;\n const rgb = channels.rgb.map((tok) => parseChannel(tok, 1));\n const a = parseAlpha(channels.alpha);\n if (rgb.some((c) => c === null) || a === null) return null;\n const [r, g, b] = (space[1] === 'srgb' ? rgb : rgb.map((c) => linearToSrgb(c as number))) as number[];\n return [clamp01(r as number), clamp01(g as number), clamp01(b as number), a];\n}\n\n/** `oklab(L a b)` or `oklch(L C h)`, clamped into sRGB. L is 0..1 or a percent; a, b and C are numbers. */\nfunction parseOkFunction(s: string): [number, number, number, number] | null {\n const lch = unwrapFn(s, 'oklch');\n const body = lch ?? unwrapFn(s, 'oklab');\n if (body === null || body.includes(',')) return null;\n const channels = splitChannels(body);\n if (!channels) return null;\n const L = parsePercentOrNumber(channels.rgb[0]);\n const second = cssNumber(channels.rgb[1]);\n const third = lch !== null ? parseHue(channels.rgb[2]) : cssNumber(channels.rgb[2]);\n const alpha = parseAlpha(channels.alpha);\n if (L === null || second === null || third === null || alpha === null) return null;\n const [, A, B] = lch !== null ? oklchToOklab(L, second, third * (Math.PI / 180)) : [L, second, third];\n const [r, g, b] = oklabToLinearSrgb(L, A, B).map((c) => clamp01(linearToSrgb(c)));\n return [r as number, g as number, b as number, alpha];\n}\n\n/** Parse a hue token:`<number>`, `<number>deg`, `<number>rad`, `<number>grad`, `<number>turn`. Returns degrees 0..360 (modulo). */\nfunction parseHue(tok: string): number | null {\n const unit = /(deg|grad|rad|turn)$/.exec(tok)?.[1];\n const n = cssNumber(unit === undefined ? tok : tok.slice(0, -unit.length));\n if (n === null) return null;\n // 400grad = 360deg\n const deg = unit === 'grad' ? n * 0.9 : unit === 'rad' ? n * (180 / Math.PI) : unit === 'turn' ? n * 360 : n;\n return ((deg % 360) + 360) % 360;\n}\n\n/** Saturation/lightness may be percent (CSS Color 3) or unitless number 0..1 (modern). */\nfunction parsePercentOrNumber(tok: string): number | null {\n return parseChannel(tok, 1);\n}\n\nfunction clamp01(n: number): number {\n return n < 0 ? 0 : n > 1 ? 1 : n;\n}\n\n// CSS Color Module Level 4 named colors. Stored as already-resolved tuples so\n// lookup is O(1) and avoids a second parse hop.\nconst NAMED_COLORS: Record<string, [number, number, number, number]> = (() => {\n const hex: Record<string, number> = {\n aliceblue: 0xf0f8ff, antiquewhite: 0xfaebd7, aqua: 0x00ffff, aquamarine: 0x7fffd4,\n azure: 0xf0ffff, beige: 0xf5f5dc, bisque: 0xffe4c4, black: 0x000000,\n blanchedalmond: 0xffebcd, blue: 0x0000ff, blueviolet: 0x8a2be2, brown: 0xa52a2a,\n burlywood: 0xdeb887, cadetblue: 0x5f9ea0, chartreuse: 0x7fff00, chocolate: 0xd2691e,\n coral: 0xff7f50, cornflowerblue: 0x6495ed, cornsilk: 0xfff8dc, crimson: 0xdc143c,\n cyan: 0x00ffff, darkblue: 0x00008b, darkcyan: 0x008b8b, darkgoldenrod: 0xb8860b,\n darkgray: 0xa9a9a9, darkgreen: 0x006400, darkgrey: 0xa9a9a9, darkkhaki: 0xbdb76b,\n darkmagenta: 0x8b008b, darkolivegreen: 0x556b2f, darkorange: 0xff8c00, darkorchid: 0x9932cc,\n darkred: 0x8b0000, darksalmon: 0xe9967a, darkseagreen: 0x8fbc8f, darkslateblue: 0x483d8b,\n darkslategray: 0x2f4f4f, darkslategrey: 0x2f4f4f, darkturquoise: 0x00ced1, darkviolet: 0x9400d3,\n deeppink: 0xff1493, deepskyblue: 0x00bfff, dimgray: 0x696969, dimgrey: 0x696969,\n dodgerblue: 0x1e90ff, firebrick: 0xb22222, floralwhite: 0xfffaf0, forestgreen: 0x228b22,\n fuchsia: 0xff00ff, gainsboro: 0xdcdcdc, ghostwhite: 0xf8f8ff, gold: 0xffd700,\n goldenrod: 0xdaa520, gray: 0x808080, green: 0x008000, greenyellow: 0xadff2f,\n grey: 0x808080, honeydew: 0xf0fff0, hotpink: 0xff69b4, indianred: 0xcd5c5c,\n indigo: 0x4b0082, ivory: 0xfffff0, khaki: 0xf0e68c, lavender: 0xe6e6fa,\n lavenderblush: 0xfff0f5, lawngreen: 0x7cfc00, lemonchiffon: 0xfffacd, lightblue: 0xadd8e6,\n lightcoral: 0xf08080, lightcyan: 0xe0ffff, lightgoldenrodyellow: 0xfafad2, lightgray: 0xd3d3d3,\n lightgreen: 0x90ee90, lightgrey: 0xd3d3d3, lightpink: 0xffb6c1, lightsalmon: 0xffa07a,\n lightseagreen: 0x20b2aa, lightskyblue: 0x87cefa, lightslategray: 0x778899, lightslategrey: 0x778899,\n lightsteelblue: 0xb0c4de, lightyellow: 0xffffe0, lime: 0x00ff00, limegreen: 0x32cd32,\n linen: 0xfaf0e6, magenta: 0xff00ff, maroon: 0x800000, mediumaquamarine: 0x66cdaa,\n mediumblue: 0x0000cd, mediumorchid: 0xba55d3, mediumpurple: 0x9370db, mediumseagreen: 0x3cb371,\n mediumslateblue: 0x7b68ee, mediumspringgreen: 0x00fa9a, mediumturquoise: 0x48d1cc, mediumvioletred: 0xc71585,\n midnightblue: 0x191970, mintcream: 0xf5fffa, mistyrose: 0xffe4e1, moccasin: 0xffe4b5,\n navajowhite: 0xffdead, navy: 0x000080, oldlace: 0xfdf5e6, olive: 0x808000,\n olivedrab: 0x6b8e23, orange: 0xffa500, orangered: 0xff4500, orchid: 0xda70d6,\n palegoldenrod: 0xeee8aa, palegreen: 0x98fb98, paleturquoise: 0xafeeee, palevioletred: 0xdb7093,\n papayawhip: 0xffefd5, peachpuff: 0xffdab9, peru: 0xcd853f, pink: 0xffc0cb,\n plum: 0xdda0dd, powderblue: 0xb0e0e6, purple: 0x800080, rebeccapurple: 0x663399,\n red: 0xff0000, rosybrown: 0xbc8f8f, royalblue: 0x4169e1, saddlebrown: 0x8b4513,\n salmon: 0xfa8072, sandybrown: 0xf4a460, seagreen: 0x2e8b57, seashell: 0xfff5ee,\n sienna: 0xa0522d, silver: 0xc0c0c0, skyblue: 0x87ceeb, slateblue: 0x6a5acd,\n slategray: 0x708090, slategrey: 0x708090, snow: 0xfffafa, springgreen: 0x00ff7f,\n steelblue: 0x4682b4, tan: 0xd2b48c, teal: 0x008080, thistle: 0xd8bfd8,\n tomato: 0xff6347, turquoise: 0x40e0d0, violet: 0xee82ee, wheat: 0xf5deb3,\n white: 0xffffff, whitesmoke: 0xf5f5f5, yellow: 0xffff00, yellowgreen: 0x9acd32,\n };\n const out: Record<string, [number, number, number, number]> = {\n transparent: [0, 0, 0, 0],\n };\n for (const name in hex) {\n const n = hex[name];\n out[name] = [((n >> 16) & 0xff) / 255, ((n >> 8) & 0xff) / 255, (n & 0xff) / 255, 1];\n }\n return out;\n})();\n","import type { Fill, Paint, Stroke } from './paint';\n\n/** A fill or stroke field holding this takes its holder's source's, whole. */\nexport const INHERIT = 'inherit';\n/** The type of {@link INHERIT}. */\nexport type Inherit = typeof INHERIT;\n\n/** A fill that paints. */\nexport type PaintedFill = Fill & { paint: Paint };\n/** A stroke that paints. */\nexport type PaintedStroke = Stroke & { paint: Paint };\n\n/**\n * What a fill field means: the fill it paints, or `null` for none. Absent,\n * `null` and a record with no `paint` are all none; a paint with alpha 0 is a\n * paint. {@link INHERIT} is `inherited`, which the caller resolves first.\n */\nexport function resolveFill(\n fill: Fill | Inherit | null | undefined,\n inherited: PaintedFill | null = null,\n): PaintedFill | null {\n if (fill === INHERIT) return inherited;\n return fill?.paint == null ? null : (fill as PaintedFill);\n}\n\n/** {@link resolveFill} for a stroke. Width is not consulted here, though a\n * stroke with no width draws nothing, whatever its per-vertex widths:\n * `strokeHasInk` answers both. */\nexport function resolveStroke(\n stroke: Stroke | Inherit | null | undefined,\n inherited: PaintedStroke | null = null,\n): PaintedStroke | null {\n if (stroke === INHERIT) return inherited;\n return stroke?.paint == null ? null : (stroke as PaintedStroke);\n}\n","/**\n * Paint identity as a string: paints with equal keys draw the same, however\n * they were built. Paint is plain data, so the comparison is structural.\n */\n\nimport { parseColor } from './color';\nimport { isSolidPaint } from './commandPaint';\nimport type { Fill, Paint, Stroke } from './paint';\nimport { resolveFill, resolveStroke, type PaintedFill, type PaintedStroke } from './resolvePaint';\n\n/** `value` as JSON with every object's keys sorted and its `undefined`\n * fields dropped, so field order and an explicit `undefined` cannot tell\n * two equal values apart. */\nfunction canonical(value: unknown): string {\n if (Array.isArray(value)) return `[${value.map(canonical).join(',')}]`;\n if (typeof value !== 'object' || value === null) return JSON.stringify(value) ?? 'null';\n const fields = Object.keys(value).sort()\n .filter((k) => (value as Record<string, unknown>)[k] !== undefined)\n .map((k) => `${JSON.stringify(k)}:${canonical((value as Record<string, unknown>)[k])}`);\n return `{${fields.join(',')}}`;\n}\n\nconst structuralKeys = new WeakMap<object, string>();\nconst strokeShapeKeys = new WeakMap<object, string>();\n\n/**\n * A key two paints share only if they draw the same. No paint at all is\n * `'none'`. Two solids that draw the same always share one. A gradient or\n * pattern keys by its fields as written, so one that spells out a default\n * (`opacity: 1`, `units`) keys apart from one that omits it: that splits a\n * group, where merging two that differ would draw one with the other's paint.\n *\n * A gradient or pattern is read once: changed in place after its first use,\n * it keeps the key it had. A solid is read on every call.\n */\nexport function paintKey(paint: Paint | null | undefined): string {\n if (paint == null) return 'none';\n if (isSolidPaint(paint)) return `solid:${solidColorKey(paint.color, paint.opacity ?? 1)}`;\n let key = structuralKeys.get(paint);\n if (key === undefined) {\n key = canonical(paint);\n structuralKeys.set(paint, key);\n }\n return key;\n}\n\n/** A solid's color by its channels with `opacity` folded into its alpha, as a renderer draws it, so `#fff` and\n * `white` key as one; a color `parseColor` cannot read keys as its own text. */\nfunction solidColorKey(color: string, opacity: number): string {\n try {\n const [r, g, b, a] = parseColor(color);\n return `${r},${g},${b},${a * opacity}`;\n } catch {\n return `text:${color}:${opacity}`;\n }\n}\n\n/** Whether a fill puts ink down: it does not when it is absent or holds no paint. */\nexport function fillHasInk(fill: Fill | null | undefined): fill is PaintedFill {\n return resolveFill(fill) !== null;\n}\n\n/** Whether a stroke puts ink down: it does not when it is absent, holds no\n * paint, or has no width — whatever its per-vertex widths. */\nexport function strokeHasInk(stroke: Stroke | null | undefined): stroke is PaintedStroke {\n const painted = resolveStroke(stroke);\n if (painted === null) return false;\n const width = painted.width ?? 1;\n return (typeof width === 'number' ? width : width.px) > 0;\n}\n\n/**\n * A key two strokes share only if they draw the same ribbon over the same\n * geometry. Every stroke that puts no ink down is `'none'`. A `{ px }` width\n * keys apart from the equal world-unit number, which is a different ribbon.\n *\n * Everything but the paint is read once: a stroke whose width, dash, or other\n * shape is changed in place keeps the key it had. Its paint is keyed on every\n * call, as {@link paintKey} keys it.\n */\nexport function strokeKey(stroke: Stroke | null | undefined): string {\n if (!strokeHasInk(stroke)) return 'none';\n let shape = strokeShapeKeys.get(stroke);\n if (shape === undefined) {\n const { paint: _paint, width, join, cap, miterLimit, align, dash, ...rest } = stroke;\n shape = canonical({\n ...rest,\n width: width ?? 1,\n join: join ?? 'miter',\n cap: cap ?? 'butt',\n miterLimit: miterLimit ?? 4,\n align: align ?? 'center',\n dash: dash ?? [],\n });\n strokeShapeKeys.set(stroke, shape);\n }\n return `${shape}|${paintKey(stroke.paint)}`;\n}\n","import type { StrokeAlign } from './paint';\n\n/**\n * Whether {@link alignedStrokeRect} draws `align` on `rect`: always, but for an\n * inner stroke at least as wide as the rect's narrower side, which covers the\n * whole rect where the shifted rect would turn inside out and draw outside it.\n */\nexport function alignedStrokeRectHolds(\n rect: { width: number; height: number },\n align: StrokeAlign,\n width = 1,\n): boolean {\n return align !== 'inner' || width < Math.min(Math.abs(rect.width), Math.abs(rect.height));\n}\n\n/**\n * Inflate (positive) or deflate (negative) a rect to honor `align` when\n * stroking it: the returned rect's center-aligned stroke coincides with the\n * requested inner/outer-aligned stroke of the original. `width` is the\n * stroke width (defaults to 1 to match canvas).\n */\nexport function alignedStrokeRect(\n rect: { x: number; y: number; width: number; height: number },\n align: StrokeAlign,\n width = 1,\n): { x: number; y: number; width: number; height: number } {\n if (align === 'center') return rect;\n // For 'inner', shift inward by width/2 so the stroke's outer edge coincides\n // with the geometric edge. For 'outer', shift outward.\n const sign = align === 'inner' ? -1 : 1;\n const d = (sign * width) / 2;\n // A negative extent runs its axis backward, so the shift does too.\n const dx = rect.width < 0 ? -d : d;\n const dy = rect.height < 0 ? -d : d;\n return {\n x: rect.x - dx,\n y: rect.y - dy,\n width: rect.width + 2 * dx,\n height: rect.height + 2 * dy,\n };\n}\n","/**\n * The pattern members of `Paint`: the built-in tiles, each its own kind,\n * `image` for a tile that is a picture, and `texture` for a tile the consumer\n * rasterized itself.\n */\n\nimport type { Paint, PaintUnits } from './paint';\nimport type { PatternTransform } from './patternTransform';\nimport type { TextureHandle } from './texture';\n\n/**\n * Where a pattern's tile sits, shared by every pattern kind.\n *\n * `units` names the space the tile's origin and scale live in, not the space\n * of any geometry (a pattern has none). Under `'bounds'` the tile anchors to\n * the painted node's box, so the pattern travels with the node and a resize\n * reveals more tiles rather than stretching them; `fillInPoseFrame` resolves\n * that to a `'local'` paint with an explicit `origin` before the renderer\n * sees it.\n *\n * `transform` rotates, scales or skews the tile about `origin` (SVG's\n * `patternTransform`, less its translation). See `PatternTransform`.\n */\nexport interface PatternPlacement {\n units?: PaintUnits;\n origin?: { x: number; y: number };\n transform?: PatternTransform;\n opacity?: number;\n}\n\n/**\n * A built-in tile, described as plain data: what a tile paint says about the\n * tile itself, apart from where it sits. `resolvePatternSpec()` turns one into\n * a `TextureHandle` at paint time, memoized so identical specs share a texture.\n *\n * `size` is the tile's edge length, and doubles as its extent in paint\n * space — a bigger `size` rasterizes a bigger tile rather than magnifying\n * a small one, which is why there is no separate scale field.\n */\nexport type TilePatternSpec =\n | { kind: 'hatch'; color: string; size?: number; lineWidth?: number }\n | { kind: 'crosshatch'; color: string; size?: number; lineWidth?: number }\n | { kind: 'dots'; color: string; size?: number; radius?: number }\n | {\n kind: 'chunks';\n color: string;\n /** Omit for a transparent tile background. */\n bg?: string;\n size?: number;\n density?: number;\n chunkSize?: number;\n seed?: number;\n };\n\n/** The built-in tile kinds. */\nexport type TileKind = TilePatternSpec['kind'];\n\n/** A paint of one of the built-in tiles. Plain data, so it survives\n * serialization. */\nexport type TilePaint = TilePatternSpec & PatternPlacement;\n\n/**\n * A tile's extent in paint-space units. Either side omitted takes the\n * source's own pixel size on that axis.\n */\nexport interface TileExtent {\n width?: number;\n height?: number;\n}\n\n/**\n * A paint that repeats a picture. `src` is anything an `<img>` loads — a URL,\n * a `blob:` URL, or a `data:` URI — and is the paint's whole record of the\n * image, so a paint holding a `data:` URI persists and exports with no\n * storage beside it. Until the image decodes the fill draws nothing.\n */\nexport type ImagePatternPaint = { kind: 'image'; src: string } & TileExtent & PatternPlacement;\n\n/**\n * A paint of a tile the consumer built itself via `createTilePattern()`. The\n * handle is a session-scoped registry key, so a paint carrying one cannot be\n * persisted or exported; prefer a tile kind, or `image` for a picture.\n */\nexport type TexturePaint = { kind: 'texture'; texture: TextureHandle } & TileExtent & PatternPlacement;\n\n/** Every paint that repeats a tile. */\nexport type PatternPaint = TilePaint | ImagePatternPaint | TexturePaint;\n\n/** The pattern kinds a renderer cannot draw as they stand: each is resolved\n * to a `texture` paint first. */\nexport type ResolvablePatternKind = TileKind | 'image';\n\n/** The built-in tile kinds, in the order a picker offers them. */\nexport const TILE_KINDS: readonly TileKind[] = ['hatch', 'crosshatch', 'dots', 'chunks'];\n\nconst TILE_KIND_SET: ReadonlySet<string> = new Set(TILE_KINDS);\n\n/** Whether `kind` names a built-in tile. */\nexport function isTileKind(kind: string | undefined): kind is TileKind {\n return kind !== undefined && TILE_KIND_SET.has(kind);\n}\n\n/** Whether a paint is one of the built-in tiles. */\nexport function isTilePaint(paint: Paint): paint is TilePaint {\n return isTileKind(paint.kind);\n}\n\n/** Whether a paint repeats a picture. */\nexport function isImagePatternPaint(paint: Paint): paint is ImagePatternPaint {\n return paint.kind === 'image';\n}\n\n/** Whether a paint repeats a tile: a built-in one, a picture, or a\n * consumer's texture. */\nexport function isPatternPaint(paint: Paint): paint is PatternPaint {\n return paint.kind === 'texture' || paint.kind === 'image' || isTileKind(paint.kind);\n}\n\n/** A pattern paint's placement alone, holding only the fields it sets. */\nexport function patternPlacementOf(paint: PatternPaint): PatternPlacement {\n const { units, origin, transform, opacity } = paint;\n return {\n ...(units !== undefined ? { units } : {}),\n ...(origin !== undefined ? { origin } : {}),\n ...(transform !== undefined ? { transform } : {}),\n ...(opacity !== undefined ? { opacity } : {}),\n };\n}\n\n/** A tile paint's description of the tile alone, its placement left behind. */\nexport function tileSpecOf(paint: TilePaint): TilePatternSpec {\n const { units: _units, origin: _origin, transform: _transform, opacity: _opacity, ...spec } = paint;\n return spec;\n}\n","/**\n * A pattern tile's linear map into paint space: `[a, b, c, d]`, the first\n * four entries of SVG's `matrix(a b c d e f)`. A tile point `(u, v)` lands at\n * `origin + (a·u + c·v, b·u + d·v)`. Translation is the paint's `origin`, so\n * it has no slot here.\n */\nexport type PatternTransform = readonly [a: number, b: number, c: number, d: number];\n\n/**\n * A {@link PatternTransform} as the parts an editor shows. Angles are radians.\n * Applied in the order scale, then skew, then rotation — rotation outermost,\n * so turning a skewed tile turns it whole.\n */\nexport interface PatternTransformParts {\n rotation: number;\n scaleX: number;\n scaleY: number;\n /** Shear of the tile's y axis toward x, as SVG `skewX()`. */\n skewX: number;\n}\n\n/** `R(rotation) · K(skewX) · S(scaleX, scaleY)`. Omitted parts are identity. */\nexport function composePatternTransform(parts: Partial<PatternTransformParts>): PatternTransform {\n const { rotation = 0, scaleX = 1, scaleY = 1, skewX = 0 } = parts;\n const cos = Math.cos(rotation);\n const sin = Math.sin(rotation);\n const shear = Math.tan(skewX) * scaleY;\n return [\n cos * scaleX,\n sin * scaleX,\n cos * shear - sin * scaleY,\n sin * shear + cos * scaleY,\n ];\n}\n\n/**\n * Inverse of {@link composePatternTransform}. Any 2×2 matrix decomposes this\n * way; a reflection comes back as a negative `scaleY`. `undefined` reads as the\n * identity, which is what an absent `transform` means.\n */\nexport function decomposePatternTransform(t: PatternTransform | undefined): PatternTransformParts {\n if (!t) return { rotation: 0, scaleX: 1, scaleY: 1, skewX: 0 };\n const [a, b, c, d] = t;\n const scaleX = Math.hypot(a, b);\n const rotation = scaleX === 0 ? 0 : Math.atan2(b, a);\n const cos = Math.cos(rotation);\n const sin = Math.sin(rotation);\n const shear = c * cos + d * sin;\n const scaleY = d * cos - c * sin;\n const skewX = scaleY === 0 ? 0 : Math.atan(shear / scaleY);\n return { rotation, scaleX, scaleY, skewX };\n}\n","/**\n * One anchor's entry in `Stroke.vertexWidths`, and the one function every\n * reader resolves it through.\n */\n\n/**\n * The stroke's width at one anchor: a number is the full width, centered on\n * the path; a pair is the distance from the path to each edge on its own.\n * `right` is the side the normal `(−dy, dx)` of the path's direction points\n * to, the right-hand side walking the path on a y-down screen: a path running\n * in +x has its right edge below it. Writers keep a pair only while its sides\n * differ (see {@link vertexWidthFromSides}).\n */\nexport type VertexWidth = number | VertexWidthSides;\n\n/** A {@link VertexWidth} whose edges sit at different distances from the path. */\nexport interface VertexWidthSides {\n readonly left: number;\n readonly right: number;\n}\n\n/** How far each edge of a stroke sits from its path at one point. */\nexport interface HalfWidths {\n left: number;\n right: number;\n}\n\nconst usable = (v: unknown): v is number => typeof v === 'number' && Number.isFinite(v) && v >= 0;\n\n/**\n * The distance from the path to each edge for one `vertexWidths` entry. A\n * missing, non-finite, or negative value — a whole entry, or one side of a\n * pair — takes half of `fallback`, the stroke's own width; zero is a real zero.\n */\nexport function vertexHalfWidths(entry: VertexWidth | null | undefined, fallback: number): HalfWidths {\n const half = fallback / 2;\n if (typeof entry === 'number') return usable(entry) ? { left: entry / 2, right: entry / 2 } : { left: half, right: half };\n if (entry == null || typeof entry !== 'object') return { left: half, right: half };\n return { left: usable(entry.left) ? entry.left : half, right: usable(entry.right) ? entry.right : half };\n}\n\n/** The entry for edges `left` and `right` from the path: a number when they\n * are equal, a pair otherwise. */\nexport function vertexWidthFromSides(left: number, right: number): VertexWidth {\n return Math.abs(left - right) <= 1e-9 * Math.max(1, Math.abs(left), Math.abs(right)) ? left + right : { left, right };\n}\n\n/** `entry` with every length in it multiplied by `k`; an unset one stays unset. */\nexport function scaleVertexWidth(entry: VertexWidth, k: number): VertexWidth {\n return typeof entry === 'number' ? entry * k : { left: entry.left * k, right: entry.right * k };\n}\n\n/** The farthest any edge of a stroke of `width` sits from its path. A nib\n * only ever narrows a stroke, so this bounds one with a nib too. */\nexport function widestHalfWidth(width: number, vertexWidths: readonly VertexWidth[] | undefined): number {\n let widest = width / 2;\n if (vertexWidths) {\n for (const entry of vertexWidths) {\n const { left, right } = vertexHalfWidths(entry, width);\n widest = Math.max(widest, left, right);\n }\n }\n return widest;\n}\n","/**\n * Paint and Stroke types — the unified shape for \"what color or texture\n * paints these pixels,\" modeled on SVG's paint-server concept.\n */\n\nimport type { PatternPaint } from './patternPaint';\nimport type { ColorSpace } from './colorSpaces';\nimport type { VertexWidth } from './vertexWidth';\nimport type { StrokeTrim } from './strokeTrim';\n\n/**\n * Color/texture strategy for fills (and, via `Stroke.paint`, strokes).\n *\n * `kind` is optional and defaults to `'solid'` — `{ color: '#abc' }` is\n * equivalent to `{ kind: 'solid', color: '#abc' }`. Every other paint names\n * its kind.\n *\n * A pattern is one of the built-in tile kinds, an `image`, or a `texture`;\n * see `PatternPaint`.\n *\n * `interpolate` on a gradient names the space its stops blend through, and\n * defaults to `'rgb'`. `'oklab'` spaces the blend perceptually; `'oklch'`\n * additionally travels around the hue wheel, so red to blue stays saturated\n * instead of passing through a muddy purple. Alpha is linear in every space.\n */\nexport type Paint =\n | { kind?: 'solid'; color: string; opacity?: number }\n | PatternPaint\n | { kind: 'linear-gradient'; from: { x: number; y: number }; to: { x: number; y: number }; stops: GradStop[]; units?: PaintUnits; interpolate?: ColorSpace; opacity?: number }\n | { kind: 'radial-gradient'; center: { x: number; y: number }; radius: number; stops: GradStop[]; units?: PaintUnits; interpolate?: ColorSpace; opacity?: number }\n | { kind: 'conic-gradient'; center: { x: number; y: number }; angle: number; stops: GradStop[]; units?: PaintUnits; interpolate?: ColorSpace; opacity?: number };\n\n/**\n * Which coordinate space a gradient's geometry (`from`/`to`, `center`,\n * `radius`) is expressed in. SVG's `gradientUnits`, plus an option for\n * paints that are themselves viewport furniture. Defaults to `'screen'`.\n *\n * - `'bounds'`: fractions of the painted node's bounding box, `0..1` on each\n * axis — SVG `objectBoundingBox`. The paint follows the node through moves,\n * resizes and rotation.\n * - `'local'`: the coordinate space the geometry was handed to the renderer\n * in — the enclosing group's frame.\n * - `'world'`: scene coordinates. The paint stays put under pan and zoom\n * while the geometry moves through it. SVG `userSpaceOnUse`. Requires the\n * renderer to have been handed a view matrix; falls back to `'screen'`\n * when it has not.\n * - `'screen'`: CSS pixels of the drawing surface. For overlays and\n * viewport-fixed washes that should not move with the content at all.\n */\nexport type PaintUnits = 'bounds' | 'local' | 'world' | 'screen';\n\n/** A single color stop within a gradient. `offset` is in 0..1. */\nexport interface GradStop {\n offset: number;\n color: string;\n}\n\n/** The gradient members of `Paint`, as one type. What a gradient editor\n * edits, and what the gradient-specific helpers accept. */\nexport type GradientPaint = Extract<\n Paint,\n { kind: 'linear-gradient' | 'radial-gradient' | 'conic-gradient' }\n>;\n\n/** `GradientPaint['kind']` — the three gradient discriminants on their own. */\nexport type GradientKind = GradientPaint['kind'];\n\n/**\n * Where a stroke sits relative to the geometric edge it strokes.\n *\n * - `'center'` (default): half the stroke width sits inside the geometry,\n * half outside.\n * - `'inner'`: the entire stroke lies inside the geometry.\n * - `'outer'`: the entire stroke lies outside the geometry.\n *\n * Mirrors the (proposed) SVG `stroke-alignment` property.\n */\nexport type StrokeAlign = 'center' | 'inner' | 'outer';\n\n/**\n * The kit's built-in marker vocabulary, open on the string the way\n * `PaintKind` is so a consumer's registered key typechecks.\n */\nexport type KitMarkerKey =\n | 'arrow' | 'arrow-open' | 'arrow-concave' | 'triangle-hollow'\n | 'diamond' | 'diamond-hollow'\n | 'circle' | 'square' | 'bar' | 'dot'\n | 'crow-one' | 'crow-many' | 'crow-zero-one' | 'crow-one-many' | 'crow-zero-many';\n/** A marker shape's key: a built-in {@link KitMarkerKey} or a consumer-registered name. */\nexport type MarkerKey = KitMarkerKey | (string & {});\n\n/**\n * A marker on one end (or every interior vertex) of a stroke.\n *\n * `size` is the length of one marker unit, and replaces the stroke width\n * rather than multiplying it: a bare number is world units, however wide the\n * line. Omitted, one unit is the resolved stroke width — SVG's\n * `markerUnits=\"strokeWidth\"`; given, it is `userSpaceOnUse`. A `{ px }` size\n * holds its screen size through a zoom, as a `{ px }` stroke width does.\n */\nexport type MarkerRef = MarkerKey | { key: MarkerKey; size?: ScreenLength };\n\n/**\n * A length the author states either in world units (a plain number) or in\n * screen pixels (`{ px }`), resolved against the accumulated transform scale\n * wherever it is consumed — so a `{ px }` length holds its on-screen size as\n * the view zooms, with no call-site arithmetic.\n */\nexport type ScreenLength = number | { px: number };\n\n/**\n * Resolve a {@link ScreenLength} to world units. A non-finite or zero scale\n * has no world to divide into, so the pixel count passes through unchanged\n * rather than becoming `Infinity`.\n */\nexport function resolveScreenLength(value: ScreenLength, scale: number): number {\n if (typeof value === 'number') return value;\n if (!Number.isFinite(scale) || scale === 0) return value.px;\n return value.px / scale;\n}\n\n/**\n * Fill style: the paint laid inside an outline. `Stroke`'s sibling, and the\n * same shape: a record holding a `paint`, with room for what belongs to the\n * fill rather than to the paint.\n *\n * A fill or stroke field holds one of three things (decided 2026-10-21):\n *\n * | State | Spelling |\n * |---------|--------------------------------------------|\n * | a paint | a record with a `paint` |\n * | none | absent, `null`, or a record with no `paint` |\n * | inherit | `INHERIT` (`'inherit'`), where the field allows it: the source's field, whole |\n *\n * Absent is none everywhere: no reader turns it into a default color, so\n * whatever makes a node writes the paint it wants. A paint with alpha 0 or\n * the color `transparent` is a paint, invisible but still grabbable.\n * `resolveFill` and `resolveStroke` are the one reading of a field.\n *\n * A node's own fill or stroke inherits from its nearest enclosing container's,\n * walking on past a container that inherits too, and is none at the root.\n * Inheritance happens only where a field says `'inherit'`, never because one\n * is absent.\n */\nexport interface Fill {\n /** Omitted, the fill paints nothing. */\n paint?: Paint;\n}\n\n/** Stroke style: a Paint plus structural line parameters. */\nexport interface Stroke {\n /** Omitted, the stroke paints nothing and keeps its width and dash for\n * the next paint. The three states a field holds are under {@link Fill}. */\n paint?: Paint;\n /** World units, or `{ px }` for screen pixels — resolved against the\n * accumulated transform at draw time, so it holds its on-screen thickness\n * as the view zooms, in every direction even when one axis is zoomed more\n * than the other. */\n width?: ScreenLength;\n /** Per `CanvasRenderingContext2D.setLineDash` — empty/omitted = solid. In\n * the width's units: world, or screen pixels on a `{ px }` stroke, as SVG's\n * `non-scaling-stroke` measures them. */\n dash?: number[];\n /** How far into `dash` each subpath starts, in the dash's units: SVG's\n * `stroke-dashoffset` and Canvas2D's `lineDashOffset`. Negative starts\n * before the pattern's beginning; a non-finite one reads as 0. */\n dashOffset?: number;\n /** The stretch of the path drawn; omitted, all of it. See {@link StrokeTrim}. */\n trim?: StrokeTrim;\n /** Marker at the first vertex of each open subpath, rotated to point back\n * along the line (SVG's `auto-start-reverse`, as the only behavior). */\n markerStart?: MarkerRef;\n /** Marker at every interior authored vertex, on the bisector of the\n * incoming and outgoing directions. Never insets the stroke. The head's\n * anchor sits on the vertex, so a terminator such as `diamond` trails\n * back from it; `dot` is the built-in centered on its vertex. */\n markerMid?: MarkerRef;\n /** Marker at the last vertex of each open subpath. */\n markerEnd?: MarkerRef;\n cap?: 'butt' | 'round' | 'square';\n join?: 'miter' | 'round' | 'bevel';\n /**\n * Miter join fallback threshold. When the miter length exceeds\n * `miterLimit * width / 2`, the join falls back to a bevel. Default 4,\n * matching SVG — which is also what the kit's own serializer implies when\n * it omits the attribute for an unset field. Canvas2D's 10 lets an acute\n * corner throw a spike four times the half-width.\n */\n miterLimit?: number;\n /** Where the stroke sits relative to the geometric edge. Default `'center'`. */\n align?: StrokeAlign;\n /**\n * Per-anchor RGBA, flat (length = 4 × countPathAnchors(path)). Each\n * value in 0..1. Arc-length interpolated across the tessellated ribbon\n * between consecutive anchors. When set, `paint` is still required —\n * its `opacity` (and color, as a placeholder) flow through the shader.\n */\n vertexColors?: number[];\n /**\n * Per-anchor stroke width (length = `countPathAnchors(path)`). When set,\n * the tessellator interpolates each edge's distance from the path along\n * each segment to produce a tapered ribbon. An entry is a full width\n * centered on the path, or a `{ left, right }` pair giving each edge its own\n * distance — see {@link VertexWidth}, and read one through\n * `vertexHalfWidths`. Entries are world units, even on a `{ px }` stroke.\n * `width` is used as the fallback for any anchor whose entry, or side of\n * one, is missing, negative, or non-finite; a stroke whose `width` is 0\n * draws nothing, whatever these say. Pair with `pressureToWidth` to\n * derive widths from stylus input.\n *\n * Joins between adjacent segments whose widths differ by more than\n * `varyingWidthJoinThreshold` (default 1.5×) are forced to bevel\n * regardless of the `join` setting — miter math is unstable when widths\n * vary across the corner.\n */\n vertexWidths?: VertexWidth[];\n /**\n * Max width ratio (greater / lesser) at which a non-bevel join is\n * preserved when `vertexWidths` causes adjacent segments to differ.\n * Beyond this ratio the join falls back to bevel. Default 1.5. Ignored\n * when `vertexWidths` is absent.\n */\n varyingWidthJoinThreshold?: number;\n /**\n * A broad nib: the stroke is as wide as `width` moving across the nib and\n * `ratio` of that moving along it, an elliptical pen's width in between.\n * Multiplies `vertexWidths` where both are set.\n */\n nib?: StrokeNib;\n}\n\n/** A pen whose mark depends on the direction it moves, as a calligraphy\n * pen's does. */\nexport interface StrokeNib {\n /** The nib's edge, in radians counterclockwise from the +x axis on screen\n * (y down), as the measure readout reads angles. */\n angle: number;\n /** Thinnest over widest, 0..1: the width moving along the nib, as a\n * fraction of the width moving across it. */\n ratio: number;\n}\n\n/**\n * The named line styles a `Stroke.dash` array reads as.\n *\n * `custom` is what an imported array that matches no preset reads as — it is\n * reportable, not authorable: there is no array it maps back to.\n */\nexport type StrokeDashStyle = 'solid' | 'dashed' | 'dotted' | 'custom';\n\n/**\n * Dash and gap lengths of the presets, **as multiples of the stroke width**.\n *\n * SVG dash lengths are absolute, so a fixed pattern is a different style at\n * every width: `[6, 3]` is dots on a hairline and a railroad on a 20px\n * stroke. Scaling by the width is what makes \"dashed\" one style.\n */\nexport const STROKE_DASH_RATIOS = {\n dashed: [3, 2],\n dotted: [1, 2],\n} as const satisfies Record<'dashed' | 'dotted', readonly [number, number]>;\n\n/** `width` as a plain number — a `{ px }` width is read at scale 1, matching\n * what an unresolved stroke reaching the tessellator gets. */\nfunction dashWidth(width: number | { px: number } | undefined): number {\n const w = typeof width === 'object' ? width.px : (width ?? 1);\n return Number.isFinite(w) && w > 0 ? w : 1;\n}\n\n/**\n * The `Stroke.dash` array for a named style at `width`, or `undefined` for\n * `solid` — which is stored as no dash at all, not as an empty pattern.\n *\n * `custom` has no array of its own and returns `undefined`; a caller that\n * offers it as a choice should refuse the choice rather than call this.\n */\nexport function dashForStrokeStyle(\n style: StrokeDashStyle,\n width: number | { px: number } | undefined,\n): number[] | undefined {\n if (style !== 'dashed' && style !== 'dotted') return undefined;\n const w = dashWidth(width);\n return STROKE_DASH_RATIOS[style].map((r) => r * w);\n}\n\n/**\n * The most dash and gap runs {@link dashPattern} lets a pattern cut one line\n * into. Past it a pattern is too fine to see as dashes, and walking it would\n * cost work without bound.\n */\nexport const MAX_DASH_RUNS = 100_000;\n\n/**\n * What a `Stroke.dash` array draws, decided once for every reader of it: the\n * array itself when it is a pattern that advances along the line, `'solid'`\n * when it is absent, empty, has a negative entry or sums to zero (as SVG\n * reads those), and `'non-finite'` when any entry is NaN or infinite, which\n * draws no stroke at all. Given the `length` of the path it strokes, a pattern\n * that would cut it into more than {@link MAX_DASH_RUNS} runs is `'solid'` too.\n */\nexport function dashPattern(\n dash: readonly number[] | undefined,\n length?: number,\n): readonly number[] | 'solid' | 'non-finite' {\n if (dash === undefined || dash.length === 0) return 'solid';\n if (!dash.every(Number.isFinite)) return 'non-finite';\n if (dash.some((v) => v < 0) || !dash.some((v) => v > 0)) return 'solid';\n if (length !== undefined) {\n const period = dash.reduce((a, b) => a + b, 0);\n if ((length / period) * dash.length > MAX_DASH_RUNS) return 'solid';\n }\n return dash;\n}\n\n/**\n * Where in `pattern` (one {@link dashPattern} returned) a line starts that sits\n * `phase` along it: `phase` wrapped into one cycle, `0` up to but not including\n * the period — twice the sum for an odd-length pattern, whose dashes and gaps\n * swap each pass. Negative and non-finite phases are read as SVG reads them.\n */\nexport function dashPhase(pattern: readonly number[], phase: number): number {\n if (!Number.isFinite(phase) || phase === 0) return 0;\n const cycle = pattern.reduce((a, b) => a + b, 0) * (pattern.length % 2 + 1);\n if (!(cycle > 0)) return 0;\n const wrapped = phase % cycle;\n return wrapped < 0 ? wrapped + cycle : wrapped;\n}\n\n/** `stroke`'s dash and dash offset, each length multiplied by `k`: the two move together. */\nexport function scaledDash<T extends Pick<Stroke, 'dash' | 'dashOffset'>>(stroke: T, k: number): T {\n if (stroke.dash === undefined && stroke.dashOffset === undefined) return stroke;\n return {\n ...stroke,\n ...(stroke.dash ? { dash: stroke.dash.map((d) => d * k) } : {}),\n ...(stroke.dashOffset !== undefined ? { dashOffset: stroke.dashOffset * k } : {}),\n };\n}\n\n/**\n * The style a stored `dash` reads as at `width`: `solid` wherever\n * {@link dashPattern} draws it solid, and `custom` for an array matching\n * neither preset, a non-finite one included.\n */\nexport function strokeDashStyleOf(\n dash: readonly number[] | undefined,\n width: number | { px: number } | undefined,\n): StrokeDashStyle {\n const pattern = dashPattern(dash);\n if (pattern === 'solid') return 'solid';\n if (pattern === 'non-finite') return 'custom';\n const w = dashWidth(width);\n for (const style of ['dashed', 'dotted'] as const) {\n const preset = STROKE_DASH_RATIOS[style];\n // Tolerance is relative to the width: the presets are multiples of it, and\n // a round-tripped array carries the serializer's decimal trimming.\n if (pattern.length === preset.length && preset.every((r, i) => Math.abs(pattern[i] - r * w) <= w * 1e-3)) {\n return style;\n }\n }\n return 'custom';\n}\n\n/** Region a fill is clipped to. */\nexport interface Region {\n x: number;\n y: number;\n w: number;\n h: number;\n shape: 'rectangle' | 'circle';\n}\n","import { interpolateSrgbSplit, type ColorInterpolationSpace } from './colorSpaces';\nimport type { HueInterpolation } from './hue';\n\ntype Rgba = readonly [number, number, number, number];\n\n/**\n * `color-mix(in <space>, a p%, b)` for two 0..1 sRGBA colors, `p` as 0..1. The\n * channels mix premultiplied by alpha, as CSS does, so a transparent side lends\n * the result its opacity and none of its color; a polar space's hue is not\n * premultiplied, as in CSS. Out-of-gamut results come back chroma-clipped.\n */\nexport function mixRgba(\n a: Rgba,\n b: Rgba,\n p: number,\n space: ColorInterpolationSpace = 'oklch',\n hue: HueInterpolation = 'shorter',\n): [number, number, number, number] {\n const alpha = a[3] * p + b[3] * (1 - p);\n if (alpha === 0) return [0, 0, 0, 0];\n // Premultiplying each side and dividing by the mixed alpha is a plain lerp at this parameter.\n const t = (b[3] * (1 - p)) / alpha;\n const [r, g, bl] = interpolateSrgbSplit([a[0], a[1], a[2]], [b[0], b[1], b[2]], t, 1 - p, space, hue);\n return [r, g, bl, alpha];\n}\n\n/** {@link mixRgba} in OKLab. */\nexport function mixOklab(a: Rgba, b: Rgba, p: number): [number, number, number, number] {\n return mixRgba(a, b, p, 'oklab');\n}\n\n/**\n * The weighted mix of any number of 0..1 sRGBA colors, premultiplied as\n * {@link mixRgba} mixes two. Weights need not sum to 1; a color weighing\n * nothing contributes nothing. Throws on an empty list.\n */\nexport function mixRgbaWeighted(\n members: readonly { readonly color: Rgba; readonly weight: number }[],\n space: ColorInterpolationSpace = 'oklch',\n hue: HueInterpolation = 'shorter',\n): [number, number, number, number] {\n if (members.length === 0) throw new Error('mixRgbaWeighted: no colors');\n let mixed: [number, number, number, number] = [...members[0]!.color];\n let total = members[0]!.weight;\n for (const { color, weight } of members.slice(1)) {\n total += weight;\n if (total > 0) mixed = mixRgba(color, mixed, weight / total, space, hue);\n }\n return mixed;\n}\n","import { parseColor } from './color';\nimport { oklabToSrgbU8, srgbToLinear, srgbU8ToOklab } from './colorSpaces';\nimport { byteHex, parseHexBytes } from './hex';\n\n/**\n * A line color that reads against `background` — a grid, a rule, a guide\n * drawn over a surface whose color the document chooses, where theme tokens\n * would be keyed to the chrome instead.\n *\n * The line is the background moved `strength` in OKLab lightness (0..1) away\n * from its nearer end: darker over light, lighter over dark, with its hue and\n * chroma kept. Returns `#rrggbb`; the background's alpha is ignored. A color\n * that is not hex comes back as black at `strength` alpha.\n */\nexport function contrastLineColor(background: string, strength: number): string {\n const rgb = parseHexBytes(background.trim());\n if (!rgb) return `rgba(0, 0, 0, ${strength})`;\n const [L, A, B] = srgbU8ToOklab(rgb[0], rgb[1], rgb[2]);\n const next = L > 0.5 ? Math.max(0, L - strength) : Math.min(1, L + strength);\n const [r, g, b] = oklabToSrgbU8(next, A, B);\n return `#${byteHex(r)}${byteHex(g)}${byteHex(b)}`;\n}\n\n/** WCAG 2.x relative luminance of an sRGB color, channels 0..1: 0 for black, 1 for white. */\nexport function relativeLuminance(r: number, g: number, b: number): number {\n return 0.2126 * srgbToLinear(r) + 0.7152 * srgbToLinear(g) + 0.0722 * srgbToLinear(b);\n}\n\n/** The WCAG 2.x contrast ratio of two {@link relativeLuminance}s, in either order: 1 up to 21. */\nexport function luminanceContrast(a: number, b: number): number {\n return (Math.max(a, b) + 0.05) / (Math.min(a, b) + 0.05);\n}\n\n/**\n * The WCAG 2.x contrast ratio of `foreground` text on `background`: 1 for two\n * equal colors up to 21 for black on white, whichever is the lighter. A\n * translucent foreground is laid over the background first; the background's\n * own alpha is ignored. `null` for a color {@link parseColor} cannot read.\n */\nexport function contrastRatio(foreground: string, background: string): number | null {\n let fg: [number, number, number, number];\n let bg: [number, number, number, number];\n try {\n fg = parseColor(foreground);\n bg = parseColor(background);\n } catch {\n return null;\n }\n const a = fg[3];\n const lf = relativeLuminance(a * fg[0] + (1 - a) * bg[0], a * fg[1] + (1 - a) * bg[1], a * fg[2] + (1 - a) * bg[2]);\n return luminanceContrast(lf, relativeLuminance(bg[0], bg[1], bg[2]));\n}\n\n/** Whether `ratio` passes WCAG AA and AAA: 4.5 and 7, or 3 and 4.5 for large text. */\nexport function wcagLevels(ratio: number, largeText: boolean): { aa: boolean; aaa: boolean } {\n return { aa: ratio >= (largeText ? 3 : 4.5), aaa: ratio >= (largeText ? 4.5 : 7) };\n}\n","/**\n * Gradient helpers shared by renderers, editors and exporters: reading a\n * color out of a stop list, and moving a gradient between its three kinds.\n */\n\nimport { resolveColor, rgbaToHex } from './color';\nimport { lerpColorArray, type ColorSpace } from './colorSpaces';\nimport type { Paint, GradStop, GradientPaint, GradientKind } from './paint';\n\n/** A stop with its color already parsed to 0..1 RGBA. */\nexport interface ResolvedGradientStop {\n offset: number;\n rgba: readonly [number, number, number, number];\n}\n\n/** Narrow a paint to the gradient members of `Paint`. */\nexport function isGradientPaint(fill: Paint | null | undefined): fill is GradientPaint {\n if (fill == null) return false;\n return fill.kind === 'linear-gradient'\n || fill.kind === 'radial-gradient'\n || fill.kind === 'conic-gradient';\n}\n\n/**\n * Sort a stop list by offset and parse each color to 0..1 RGBA, so a caller\n * sampling many positions parses each color once. Colors go through\n * `resolveColor`, so any CSS color the kit understands is a legal stop, not\n * just hex.\n */\nexport function resolveGradientStops(stops: readonly GradStop[]): ResolvedGradientStop[] {\n return [...stops]\n .sort((a, b) => a.offset - b.offset)\n .map((s) => ({ offset: s.offset, rgba: resolveColor(s.color) }));\n}\n\n/**\n * RGBA (0..1) at position `t` along resolved stops: flat extension past\n * either end, interpolation between neighbors in `space`, alpha included.\n * The single definition of what a stop list means; a second implementation\n * is a gradient that paints differently from its own swatch.\n *\n * `space` is a gradient's `interpolate`. Alpha is linear in every space —\n * only the color channels travel through OKLab or OKLCh. Returns transparent\n * black for an empty list; a NaN `t` reads as the first stop.\n */\nexport function sampleResolvedStops(\n stops: readonly ResolvedGradientStop[], t: number, space: ColorSpace = 'rgb',\n): readonly [number, number, number, number] {\n if (stops.length === 0) return TRANSPARENT;\n const first = stops[0];\n const last = stops[stops.length - 1];\n if (!(t > first.offset)) return first.rgba;\n if (t >= last.offset) return last.rgba;\n\n for (let i = 0; i < stops.length - 1; i++) {\n const lo = stops[i];\n const hi = stops[i + 1];\n if (t < lo.offset || t > hi.offset) continue;\n const span = hi.offset - lo.offset;\n // Coincident stops are a hard color break: take the later one.\n if (span <= 0) return hi.rgba;\n const f = (t - lo.offset) / span;\n const [r, g, b, a] = lerpColorArray(lo.rgba, hi.rgba, f, space);\n return [r, g, b, a];\n }\n return last.rgba;\n}\n\nconst TRANSPARENT: readonly [number, number, number, number] = [0, 0, 0, 0];\n\n/**\n * Color at position `t` (0..1) along a stop list, as a hex string — the same\n * sampling the GL ramp texture bakes, so an editor track and the painted\n * gradient cannot disagree.\n *\n * Returns transparent black (`#00000000`) for an empty list.\n */\nexport function sampleGradientStops(\n stops: readonly GradStop[], t: number, space: ColorSpace = 'rgb',\n): string {\n return rgbaToHex(sampleResolvedStops(resolveGradientStops(stops), t, space));\n}\n\n/**\n * Retarget a gradient to a different kind, preserving stops, `units` and\n * `opacity`. Linear carries a segment; radial and conic carry a center.\n * Converting between them keeps the center fixed and reads the radius /\n * angle off the segment.\n *\n * Lossy in both directions: a radial gradient stores no angle, so a round\n * trip through one leaves the segment horizontal; a conic stores no radius,\n * so a round trip through one resets the segment's length. An editor that\n * wants a kind switch to be undoable should keep the original paint rather\n * than converting back.\n */\nexport function withGradientKind(fill: GradientPaint, kind: GradientKind): GradientPaint {\n if (fill.kind === kind) return fill;\n const common = {\n stops: fill.stops, units: fill.units,\n interpolate: fill.interpolate, opacity: fill.opacity,\n };\n const { center, radius, angle } = gradientGeometry(fill);\n\n if (kind === 'linear-gradient') {\n const dx = Math.cos(angle) * radius;\n const dy = Math.sin(angle) * radius;\n return {\n kind: 'linear-gradient',\n from: { x: center.x - dx, y: center.y - dy },\n to: { x: center.x + dx, y: center.y + dy },\n ...common,\n };\n }\n if (kind === 'radial-gradient') {\n return { kind: 'radial-gradient', center, radius, ...common };\n }\n return { kind: 'conic-gradient', center, angle, ...common };\n}\n\n/**\n * Center / radius / angle for any gradient kind. For a linear gradient the\n * center is the segment midpoint, the radius is half its length, and the\n * angle is its direction.\n */\nexport function gradientGeometry(fill: GradientPaint): {\n center: { x: number; y: number };\n radius: number;\n angle: number;\n} {\n if (fill.kind === 'linear-gradient') {\n const dx = fill.to.x - fill.from.x;\n const dy = fill.to.y - fill.from.y;\n return {\n center: { x: (fill.from.x + fill.to.x) / 2, y: (fill.from.y + fill.to.y) / 2 },\n radius: Math.hypot(dx, dy) / 2,\n angle: Math.atan2(dy, dx),\n };\n }\n if (fill.kind === 'radial-gradient') {\n return { center: fill.center, radius: fill.radius, angle: 0 };\n }\n return { center: fill.center, radius: conicArmRadius(fill.units), angle: fill.angle };\n}\n\n/**\n * Conic gradients carry no radius, but converting one to a linear or radial\n * gradient needs a non-zero length to build from. Unit-dependent: `'bounds'`\n * geometry runs `0..1` across the box, so a pixel-flavored default there\n * means fifty times it.\n */\nfunction conicArmRadius(units: GradientPaint['units']): number {\n return units === 'bounds' ? 0.5 : 50;\n}\n\n/**\n * A gradient spanning a box left edge to right edge through its vertical\n * center (linear) or filling it (radial / conic) — a starting geometry when\n * only the shape's bounds are known.\n */\nexport function gradientForBounds(\n kind: GradientKind,\n bounds: { x: number; y: number; width: number; height: number },\n stops: GradStop[],\n units?: GradientPaint['units'],\n): GradientPaint {\n const center = { x: bounds.x + bounds.width / 2, y: bounds.y + bounds.height / 2 };\n if (kind === 'linear-gradient') {\n return {\n kind: 'linear-gradient',\n from: { x: bounds.x, y: center.y },\n to: { x: bounds.x + bounds.width, y: center.y },\n stops,\n units,\n };\n }\n if (kind === 'radial-gradient') {\n return {\n kind: 'radial-gradient',\n center,\n radius: Math.max(bounds.width, bounds.height) / 2,\n stops,\n units,\n };\n }\n return { kind: 'conic-gradient', center, angle: 0, stops, units };\n}\n","/**\n * Interpolating paint: the colors between two fills or two strokes, as a\n * blend of two shapes steps from one to the other. Colors travel through\n * OKLab, so the middle of a red-to-green run is a clear yellow rather than a\n * muddy brown.\n */\nimport { parseColor, rgbaToHex } from './color';\nimport { isSolidPaint } from './commandPaint';\nimport { mixOklab } from './mix';\nimport { isGradientPaint } from './gradient';\nimport type { Fill, GradStop, GradientPaint, Paint, ScreenLength, Stroke } from './paint';\n\ntype Rgba = [number, number, number, number];\n\n/** A solid color's channels, its own alpha and `opacity` folded together. */\nfunction rgbaOf(color: string, opacity: number | undefined): Rgba {\n const [r, g, b, a] = parseColor(color);\n return [r, g, b, a * (opacity ?? 1)];\n}\n\n/** `t` of the way from `a` to `b`, through OKLab. */\nfunction mixColor(a: Rgba, b: Rgba, t: number): Rgba {\n return mixOklab(a, b, 1 - t);\n}\n\nfunction solidOf(rgba: Rgba): Paint {\n const color = rgbaToHex([rgba[0], rgba[1], rgba[2]]);\n return rgba[3] >= 1 ? { color } : { color, opacity: rgba[3] };\n}\n\n/** A solid paint's color, or `null` for any other kind. */\nfunction solidRgba(paint: Paint): Rgba | null {\n return isSolidPaint(paint) ? rgbaOf(paint.color, paint.opacity) : null;\n}\n\nconst lerp = (a: number, b: number, t: number): number => a + (b - a) * t;\n\n/**\n * The paint `t` of the way from `a` to `b`.\n *\n * Two solids mix through OKLab; a missing side is the other's color fully\n * transparent, so a paint fades in or out. Two gradients of one kind with as\n * many stops interpolate their geometry and every stop. Anything else — a\n * pattern, two unlike gradients — holds `a` until halfway and `b` after.\n */\nexport function lerpPaint(a: Paint | undefined, b: Paint | undefined, t: number): Paint | undefined {\n if (a === undefined && b === undefined) return undefined;\n if (a === undefined || b === undefined) {\n const only = (a ?? b)!;\n const rgba = solidRgba(only);\n if (rgba === null) return t < 0.5 ? a : b;\n const clear: Rgba = [rgba[0], rgba[1], rgba[2], 0];\n return solidOf(a === undefined ? mixColor(clear, rgba, t) : mixColor(rgba, clear, t));\n }\n const sa = solidRgba(a);\n const sb = solidRgba(b);\n if (sa !== null && sb !== null) return solidOf(mixColor(sa, sb, t));\n if (isGradientPaint(a) && isGradientPaint(b)) {\n const mixed = lerpGradient(a, b, t);\n if (mixed !== null) return mixed;\n }\n return t < 0.5 ? a : b;\n}\n\nconst byOffset = (stops: readonly GradStop[]): GradStop[] => [...stops].sort((p, q) => p.offset - q.offset);\n\n/** Stops paired in offset order, as a ramp reads them, not in the order each list holds them. */\nfunction lerpStops(a: readonly GradStop[], b: readonly GradStop[], t: number): GradStop[] {\n const to = byOffset(b);\n return byOffset(a).map((stop, i) => {\n const other = to[i]!;\n return { offset: lerp(stop.offset, other.offset, t), color: mixStopColor(stop.color, other.color, t) };\n });\n}\n\n/** A stop's color `t` of the way from `a` to `b`, alpha included. Where both\n * are clear the color still travels, since a ramp blends toward it. */\nfunction mixStopColor(a: string, b: string, t: number): string {\n if (a === b) return a;\n const ca = rgbaOf(a, 1), cb = rgbaOf(b, 1);\n const mixed = mixColor(ca, cb, t);\n if (mixed[3] > 0) return rgbaToHex(mixed);\n const [r, g, bl] = mixColor([ca[0], ca[1], ca[2], 1], [cb[0], cb[1], cb[2], 1], t);\n return rgbaToHex([r, g, bl, 0]);\n}\n\nfunction lerpGradient(a: GradientPaint, b: GradientPaint, t: number): Paint | null {\n if (a.kind !== b.kind || a.stops.length !== b.stops.length) return null;\n if ((a.units ?? 'screen') !== (b.units ?? 'screen')) return null;\n const pt = (p: { x: number; y: number }, q: { x: number; y: number }) => ({ x: lerp(p.x, q.x, t), y: lerp(p.y, q.y, t) });\n const stops = lerpStops(a.stops, b.stops, t);\n const opacity = a.opacity === undefined && b.opacity === undefined\n ? undefined\n : lerp(a.opacity ?? 1, b.opacity ?? 1, t);\n const near = t < 0.5 ? a : b;\n const common = {\n stops,\n ...(near.units === undefined ? {} : { units: near.units }),\n ...(near.interpolate === undefined ? {} : { interpolate: near.interpolate }),\n ...(opacity === undefined ? {} : { opacity }),\n };\n if (a.kind === 'linear-gradient' && b.kind === 'linear-gradient') {\n return { kind: 'linear-gradient', from: pt(a.from, b.from), to: pt(a.to, b.to), ...common };\n }\n if (a.kind === 'radial-gradient' && b.kind === 'radial-gradient') {\n return { kind: 'radial-gradient', center: pt(a.center, b.center), radius: lerp(a.radius, b.radius, t), ...common };\n }\n if (a.kind === 'conic-gradient' && b.kind === 'conic-gradient') {\n return { kind: 'conic-gradient', center: pt(a.center, b.center), angle: lerp(a.angle, b.angle, t), ...common };\n }\n return null;\n}\n\n/**\n * The fill `t` of the way from `a` to `b`. A `null` or missing side fades:\n * its paint is the other's color made transparent. Both absent answers\n * whichever side `t` is nearer.\n */\nexport function lerpFill(a: Fill | null | undefined, b: Fill | null | undefined, t: number): Fill | null | undefined {\n if (a == null && b == null) return t < 0.5 ? a : b;\n const paint = lerpPaint(a?.paint, b?.paint, t);\n return paint === undefined ? {} : { paint };\n}\n\nfunction lerpWidth(a: ScreenLength | undefined, b: ScreenLength | undefined, t: number): ScreenLength | undefined {\n if (a === undefined && b === undefined) return undefined;\n if (typeof a === 'object' && typeof b === 'object') return { px: lerp(a.px, b.px, t) };\n if (typeof a !== 'object' && typeof b !== 'object') return lerp(a ?? 1, b ?? 1, t);\n return t < 0.5 ? a : b;\n}\n\n/**\n * The stroke `t` of the way from `a` to `b`: width and paint interpolate, and\n * every other field is the nearer side's. A `null` or missing side is a\n * stroke of no width in the other's color made transparent, so a stroke\n * thins and fades in or out.\n */\nexport function lerpStroke(a: Stroke | null | undefined, b: Stroke | null | undefined, t: number): Stroke | null | undefined {\n if (a == null && b == null) return t < 0.5 ? a : b;\n const near = (t < 0.5 ? a : b) ?? (a ?? b)!;\n const paint = lerpPaint(a?.paint, b?.paint, t);\n const zero = (s: Stroke): ScreenLength => (typeof s.width === 'object' ? { px: 0 } : 0);\n const width = lerpWidth(a == null ? zero(b!) : a.width, b == null ? zero(a!) : b.width, t);\n const { paint: _p, width: _w, vertexColors: _vc, vertexWidths: _vw, dashOffset: _o, ...rest } = near;\n void _p; void _w; void _vc; void _vw; void _o;\n // An offset slides the pattern, so it moves smoothly where the dash itself snaps.\n const from = a?.dashOffset, to = b?.dashOffset;\n const dashOffset = from === undefined && to === undefined ? undefined : (from ?? 0) + ((to ?? 0) - (from ?? 0)) * t;\n return {\n ...rest,\n ...(paint === undefined ? {} : { paint }),\n ...(width === undefined ? {} : { width }),\n ...(dashOffset === undefined ? {} : { dashOffset }),\n };\n}\n","import { parseColor } from './color';\nimport { oklabToSrgbU8, oklchToOklab } from './colorSpaces';\nimport { byteHex, parseHexBytes } from './hex';\n\n/**\n * A color given directly. `coords` are in the order CSS Color 4 uses for\n * `space` — `srgb` as 0..1 r, g, b; `oklab` as L, a, b; `oklch` as L, C and a\n * hue in degrees; `hsl` as a hue in degrees and 0..100 saturation and lightness. `space` is open: a palette may carry colors in spaces the kit\n * cannot convert, and `colorLiteralToHex` answers `null` for those.\n */\nexport interface ColorLiteral {\n readonly space: string;\n readonly coords: readonly number[];\n /** 0..1. Omitted means opaque. */\n readonly alpha?: number;\n}\n\n/** A color named rather than given: a palette entry, or whatever the resolver's\n * `external` callback answers to. `index` picks from a sequence entry; a\n * single-color entry answers only to 0. */\nexport interface ColorRef {\n readonly ref: string;\n readonly index?: number;\n}\n\n/** What a {@link ColorFn} or {@link ColorSeqFn} is handed. */\nexport interface ColorFnContext {\n /** Resolve any source against the same palette and external lookup. */\n resolve(source: ColorSource): ColorLiteral | null;\n}\n\n/** A color computed at resolve time — typically derived from another entry. */\nexport type ColorFn = (ctx: ColorFnContext) => ColorSource | null | undefined;\n\n/** Anything that resolves to a color: a literal, a named reference, or a function computing one. */\nexport type ColorSource = ColorLiteral | ColorRef | ColorFn;\n\n/** A sequence of colors, read lazily, so it may be endless. A factory rather\n * than an iterable because a generator object can be iterated only once:\n * pass the `function*` itself. */\nexport type ColorSeqFn = (ctx: ColorFnContext) => Iterable<ColorSource>;\n\n/** A named palette slot holding either one color (`color`) or a sequence (`colors`) that refs index into. */\nexport type PaletteEntry =\n | { readonly name: string; readonly color: ColorSource }\n | { readonly name: string; readonly colors: ColorSeqFn };\n\n/** A set of named colors that {@link ColorRef}s resolve against. When two entries share a name, the first wins. */\nexport interface Palette {\n readonly entries: readonly PaletteEntry[];\n}\n\n/** Answers a ref the palette has no entry for. */\nexport type ExternalColors = (ref: ColorRef) => ColorSource | null | undefined;\n\ntype Visit = (s: ColorSource | null | undefined, visiting: ReadonlySet<string>) => ColorLiteral | null;\n\nfunction nth<T>(items: Iterable<T>, n: number): T | undefined {\n if (!Number.isInteger(n) || n < 0) return undefined;\n let i = 0;\n for (const item of items) if (i++ === n) return item;\n return undefined;\n}\n\nconst refKey = (name: string, index: number): string => `${index}:${name}`;\n\nfunction resolver(palette: Palette, external?: ExternalColors) {\n const byName = new Map<string, PaletteEntry>();\n for (const e of palette.entries) if (!byName.has(e.name)) byName.set(e.name, e);\n\n const ctx = (visiting: ReadonlySet<string>): ColorFnContext => ({ resolve: (s) => visit(s, visiting) });\n\n const visit: Visit = (s, visiting) => {\n if (s == null) return null;\n if (typeof s === 'function') return visit(s(ctx(visiting)), visiting);\n if ('space' in s) return s;\n const index = s.index ?? 0;\n const key = refKey(s.ref, index);\n if (visiting.has(key)) return null;\n const next = new Set(visiting).add(key);\n const entry = byName.get(s.ref);\n if (!entry) return visit(external?.(s), next);\n if ('color' in entry) return index === 0 ? visit(entry.color, next) : null;\n return visit(nth(entry.colors(ctx(next)), index), next);\n };\n\n return { byName, ctx, visit };\n}\n\n/**\n * Resolve `source` to a literal. A ref names a palette entry first, then goes\n * to `external`; whatever either answers is resolved in turn. A name nothing\n * answers, an index past a sequence's end, or a chain that comes back to a ref\n * it is already resolving gives `null`.\n */\nexport function resolvePaletteColor(\n palette: Palette,\n source: ColorSource,\n external?: ExternalColors,\n): ColorLiteral | null {\n return resolver(palette, external).visit(source, new Set());\n}\n\n/**\n * Every color under `name`, resolved lazily in order — one for a single-color\n * entry, as many as the sequence yields for a `colors` entry, nothing for a\n * name the palette lacks. Stop early to read an endless sequence.\n */\nexport function* resolvePaletteColors(\n palette: Palette,\n name: string,\n external?: ExternalColors,\n): Generator<ColorLiteral | null> {\n const { byName, ctx, visit } = resolver(palette, external);\n const entry = byName.get(name);\n if (!entry) return;\n if ('color' in entry) {\n yield visit(entry.color, new Set([refKey(name, 0)]));\n return;\n }\n let i = 0;\n for (const item of entry.colors(ctx(new Set()))) {\n yield visit(item, new Set([refKey(name, i++)]));\n }\n}\n\n/** `#rrggbb`, or `#rrggbbaa` below full opacity. `null` for a space the kit\n * cannot convert, or fewer than three coordinates. */\nexport function colorLiteralToHex(color: ColorLiteral): string | null {\n const [x, y, z] = color.coords;\n if (z === undefined) return null;\n let rgb: readonly number[];\n switch (color.space) {\n case 'srgb':\n rgb = [x * 255, y * 255, z * 255];\n break;\n case 'oklab':\n rgb = oklabToSrgbU8(x, y, z);\n break;\n case 'oklch':\n rgb = oklabToSrgbU8(...oklchToOklab(x, y, (z * Math.PI) / 180));\n break;\n default:\n return null;\n }\n const a = color.alpha ?? 1;\n return `#${rgb.map(byteHex).join('')}${a < 1 ? byteHex(a * 255) : ''}`;\n}\n\n/** Spaces CSS spells as a function of their own, with the coordinates it writes as percentages. */\nconst FUNCTIONAL_SPACES: Readonly<Record<string, readonly number[]>> = { hsl: [1, 2], hwb: [1, 2], lab: [], lch: [], oklab: [], oklch: [] };\n/** Spaces CSS reaches only through `color()`. */\nconst PREDEFINED_SPACES = new Set(['srgb', 'srgb-linear', 'display-p3', 'a98-rgb', 'prophoto-rgb', 'rec2020', 'xyz', 'xyz-d50', 'xyz-d65']);\n\n/**\n * Three coordinates in `space` written the way CSS writes that space, with\n * nothing converted: `hsl()`, `hwb()`, `lab()`, `lch()`, `oklab()` and `oklch()`\n * as their own functions, the predefined spaces through `color()`. `hsl` and\n * `hwb` take their second and third coordinates as 0..100. `'none'` is CSS's\n * missing component. `null` for a space CSS has no notation for, or a count\n * other than three.\n */\nexport function cssColorNotation(space: string, coords: readonly (number | 'none')[], alpha = 1): string | null {\n if (coords.length !== 3) return null;\n const slash = alpha < 1 ? ` / ${alpha}` : '';\n const percent = Object.hasOwn(FUNCTIONAL_SPACES, space) ? FUNCTIONAL_SPACES[space] : undefined;\n if (percent) return `${space}(${coords.map((c, i) => (c !== 'none' && percent.includes(i) ? `${c}%` : c)).join(' ')}${slash})`;\n if (PREDEFINED_SPACES.has(space)) return `color(${space} ${coords.join(' ')}${slash})`;\n return null;\n}\n\n/**\n * A literal as a CSS color: hex where `colorLiteralToHex` has one, else\n * {@link cssColorNotation}. `null` for fewer than three coordinates, or a\n * space CSS has no notation for.\n */\nexport function colorLiteralToCss(color: ColorLiteral): string | null {\n if (color.coords.length < 3) return null;\n return colorLiteralToHex(color) ?? cssColorNotation(color.space, color.coords.slice(0, 3), color.alpha);\n}\n\n/** Any color string `parseColor` reads, as an `srgb` literal. Throws, as it does, on one it cannot. */\nexport function cssColorLiteral(css: string): ColorLiteral {\n const [r, g, b, a] = parseColor(css);\n const coords = [r, g, b];\n return a < 1 ? { space: 'srgb', coords, alpha: a } : { space: 'srgb', coords };\n}\n\n/** `#rrggbb` or `#rrggbbaa` as an `srgb` literal; `null` for anything else. */\nexport function hexToColorLiteral(hex: string): ColorLiteral | null {\n const bytes = hex.length === 7 || hex.length === 9 ? parseHexBytes(hex) : null;\n if (!bytes) return null;\n const [r, g, b, a] = bytes.map((v) => v / 255);\n const coords = [r, g, b];\n return a < 1 ? { space: 'srgb', coords, alpha: a } : { space: 'srgb', coords };\n}\n"]}
1
+ {"version":3,"sources":["../src/commandPaint.ts","../src/strokeTrim.ts","../src/hue.ts","../src/lerp.ts","../src/hex.ts","../src/hsl.ts","../src/shortArc.ts","../src/colorSpaces.ts","../src/color.ts","../src/resolvePaint.ts","../src/paintKey.ts","../src/alignedStrokeRect.ts","../src/patternPaint.ts","../src/patternTransform.ts","../src/vertexWidth.ts","../src/paint.ts","../src/mix.ts","../src/contrast.ts","../src/gradient.ts","../src/lerpPaint.ts","../src/palette.ts"],"names":["L","C","h","s","l","parts","clamp01"],"mappings":";AAiCO,SAAS,aAAa,KAAA,EAAsD;AACjF,EAAA,OAAO,SAAS,IAAA,KAAS,KAAA,CAAM,IAAA,KAAS,MAAA,IAAa,MAAM,IAAA,KAAS,OAAA,CAAA;AACtE;;;AChBO,SAAS,cAAc,IAAA,EAAsC;AAClE,EAAA,IAAI,IAAA,KAAS,QAAW,OAAO,EAAA;AAC/B,EAAA,OAAO,CAAA,KAAA,EAAQ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,EAAO,KAAA,CAAM,MAAA,CAAO,KAAA,CAAM,CAAA,EAAG,CAAC,CAAA,EAAG,MAAM,KAAK,CAAA;AACxG;AAGO,SAAS,gBAAgB,GAAA,EAA2B;AACzD,EAAA,MAAM,CAAC,CAAA,EAAG,CAAA,EAAG,GAAG,CAAC,CAAA,GAAI,WAAW,GAAG,CAAA;AACnC,EAAA,MAAM,MAAA,GAAS,CAAC,CAAA,EAAG,CAAA,EAAG,CAAC,CAAA;AACvB,EAAA,OAAO,CAAA,GAAI,CAAA,GAAI,EAAE,KAAA,EAAO,MAAA,EAAQ,MAAA,EAAQ,KAAA,EAAO,CAAA,EAAE,GAAI,EAAE,KAAA,EAAO,MAAA,EAAQ,MAAA,EAAO;AAC/E;AAGO,SAAS,kBAAkB,GAAA,EAAkC;AAClE,EAAA,MAAM,KAAA,GAAQ,IAAI,MAAA,KAAW,CAAA,IAAK,IAAI,MAAA,KAAW,CAAA,GAAI,aAAA,CAAc,GAAG,CAAA,GAAI,IAAA;AAC1E,EAAA,IAAI,CAAC,OAAO,OAAO,IAAA;AACnB,EAAA,MAAM,CAAC,CAAA,EAAG,CAAA,EAAG,CAAA,EAAG,CAAC,CAAA,GAAI,KAAA,CAAM,GAAA,CAAI,CAAC,CAAA,KAAM,CAAA,GAAI,GAAG,CAAA;AAC7C,EAAA,MAAM,MAAA,GAAS,CAAC,CAAA,EAAG,CAAA,EAAG,CAAC,CAAA;AACvB,EAAA,OAAO,CAAA,GAAI,CAAA,GAAI,EAAE,KAAA,EAAO,MAAA,EAAQ,MAAA,EAAQ,KAAA,EAAO,CAAA,EAAE,GAAI,EAAE,KAAA,EAAO,MAAA,EAAQ,MAAA,EAAO;AAC/E","file":"index.js","sourcesContent":["/**\n * The paint a draw command takes: `Paint` and `Stroke` narrowed to what a\n * renderer can draw as it stands. A node's own paint may name its box\n * (`units: 'bounds'`), a tile by kind, or an image by `src`; a command has no\n * node, rasterizer or decoder, so all of these are resolved before one is built.\n */\n\nimport type { Fill, Paint, PaintUnits, Stroke } from './paint';\nimport type { ResolvablePatternKind } from './patternPaint';\n\n/** The spaces a draw command's paint can name. `'bounds'` is not one: it means\n * a node's box, and a command has no node. */\nexport type CommandPaintUnits = Exclude<PaintUnits, 'bounds'>;\n\n/** `F` with `'bounds'` units ruled out, where `F` is a paint that has units. */\nexport type InCommandUnits<F> = F extends { units?: PaintUnits }\n ? Omit<F, 'units'> & { units?: CommandPaintUnits }\n : F;\n\n/** A `Paint` placed in a frame a command can name. Its pattern may still\n * be a tile kind or an image. */\nexport type PosedPaint = InCommandUnits<Paint>;\n\n/** A `Paint` a renderer can draw as it stands: no paint is in `'bounds'`\n * units, and a pattern is a registered `texture` rather than a tile kind or\n * an image. */\nexport type CommandPaint = Exclude<PosedPaint, { kind: ResolvablePatternKind }>;\n\n/** The solid member of `Paint`: a color and an opacity. */\nexport type SolidPaint = Extract<Paint, { kind?: 'solid' }>;\n\n/** Whether a paint is the solid member. A tile paint carries a `color` too, so\n * the presence of one does not answer this. */\nexport function isSolidPaint(paint: Paint | null | undefined): paint is SolidPaint {\n return paint != null && (paint.kind === undefined || paint.kind === 'solid');\n}\n\n/** A `Fill` whose paint is a {@link CommandPaint}. */\nexport interface CommandFill extends Omit<Fill, 'paint'> {\n paint?: CommandPaint;\n}\n\n/** A `Stroke` whose paint is a {@link CommandPaint}. */\nexport type CommandStroke = Omit<Stroke, 'paint'> & { paint?: CommandPaint };\n","/**\n * Where along a path a {@link StrokeTrim} edge sits. A bare number is a\n * fraction of the whole path; the object forms name an absolute distance, an\n * anchor (vertex) index, or a subpath index.\n */\nexport type TrimAt = number | { length: number } | { anchor: number } | { subpath: number };\n\n/** What a fractional trim edge advances by: arc length, or anchor by anchor. */\nexport type TrimPace = 'length' | 'anchor';\n\n/** The stretch of a path a stroke draws, so a path can be drawn on in pen order. */\nexport interface StrokeTrim {\n start?: TrimAt;\n end?: TrimAt;\n pace?: TrimPace;\n}\n\n/** A stable string per trim value, `''` for no trim; for cache and equality keys. An omitted\n * edge keys as its default, so `{ end: 0.5 }` and `{ start: 0, end: 0.5 }` share one. */\nexport function strokeTrimKey(trim: StrokeTrim | undefined): string {\n if (trim === undefined) return '';\n return `trim(${atKey(trim.start ?? 0)},${atKey(trim.end ?? 1)},${trim.pace ?? 'length'})`;\n}\n\nfunction atKey(at: TrimAt): string {\n if (typeof at === 'number') return String(at);\n if ('length' in at) return `l${at.length}`;\n if ('anchor' in at) return `a${at.anchor}`;\n return `s${at.subpath}`;\n}\n","/** Which way a polar space's hue goes between two endpoints, as CSS\n * `hue-interpolation-method`: the arc of at most 180°, or the other one. */\nexport type HueInterpolation = 'shorter' | 'longer';\n\n/** The hue `t` of the way from `h1` to `h2`, in degrees, along the arc `method` names, in [0, 360). Both hues are\n * taken into [0, 360) first, and a half turn keeps the sign of `h2 - h1`, as CSS's fixup does: 180° to 0° passes\n * 90°. Equal hues stay put under `longer`, where CSS would go a full turn. */\nexport function lerpHueDeg(h1: number, h2: number, t: number, method: HueInterpolation = 'shorter'): number {\n const a = wrapDeg(h1);\n let dh = wrapDeg(h2) - a;\n if (method === 'shorter') {\n if (dh > 180) dh -= 360;\n else if (dh < -180) dh += 360;\n } else if (dh > 0 && dh < 180) {\n dh -= 360;\n } else if (dh < 0 && dh > -180) {\n dh += 360;\n }\n return wrapDeg(a + dh * t);\n}\n\nconst wrapDeg = (h: number): number => ((h % 360) + 360) % 360;\n","/** `a + (b - a) * t`, which can miss `b` by an ulp at `t = 1`, so that end is `b` itself. */\nexport const lerp = (a: number, b: number, t: number): number => (t === 1 ? b : a + (b - a) * t);\n","const HEX = /^#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;\n\n/**\n * The kit's one hex color reader: `#rgb`, `#rgba`, `#rrggbb`, or `#rrggbbaa`,\n * in any case, as four 0..255 channels with alpha last (255 when the color\n * names none). `null` for anything else, a missing `#` included.\n */\nexport function parseHexBytes(input: string): [number, number, number, number] | null {\n if (!HEX.test(input)) return null;\n const digits = input.slice(1);\n const long = digits.length <= 4 ? digits.replace(/./g, '$&$&') : digits;\n const byte = (i: number): number => Number.parseInt(long.slice(i, i + 2), 16);\n return [byte(0), byte(2), byte(4), long.length === 8 ? byte(6) : 255];\n}\n\n/** The kit's one hex color writer: a 0..255 channel as two hex digits, rounded and clamped; NaN as 0. */\nexport function byteHex(v: number): string {\n return (Math.max(0, Math.min(255, Math.round(v))) || 0).toString(16).padStart(2, '0');\n}\n\n/** A hex color's red, green, and blue as 0..255, its alpha dropped. Throws on anything {@link parseHexBytes} does not read. */\nexport function hexToRgbBytes(input: string): [number, number, number] {\n const bytes = parseHexBytes(input);\n if (!bytes) throw new Error(`not a hex color: \"${input}\"`);\n return [bytes[0], bytes[1], bytes[2]];\n}\n\n/** An RGBA pixel's bytes as `#rrggbb`, or `null` where it is fully transparent: the color a\n * sampler reports for what is drawn at a point. Alpha is dropped, not composited. */\nexport function rgbaHex(rgba: ArrayLike<number>): string | null {\n if (rgba[3] === 0) return null;\n return `#${byteHex(rgba[0])}${byteHex(rgba[1])}${byteHex(rgba[2])}`;\n}\n","// HSL, the polar form of gamma-encoded sRGB that CSS `hsl()` writes.\n\n/** HSL to sRGB. Hue in degrees, any number of turns; saturation, lightness and output all 0..1. */\nexport function hslToSrgb(h: number, s: number, l: number): [number, number, number] {\n if (s === 0) return [l, l, l];\n const q = l < 0.5 ? l * (1 + s) : l + s - l * s;\n const p = 2 * l - q;\n const turn = h / 360;\n const hk = turn >= 0 && turn < 1 ? turn : turn - Math.floor(turn);\n return [hueToChannel(p, q, hk + 1 / 3), hueToChannel(p, q, hk), hueToChannel(p, q, hk - 1 / 3)];\n}\n\nfunction hueToChannel(p: number, q: number, t: number): number {\n if (t < 0) t += 1;\n if (t > 1) t -= 1;\n if (t < 1 / 6) return p + (q - p) * 6 * t;\n if (t < 1 / 2) return q;\n if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;\n return p;\n}\n\n/** sRGB (0..1) to HSL: `[hue°, saturation, lightness]`, hue in 0..360. An\n * achromatic color reports hue 0 and saturation 0. */\nexport function srgbToHsl(r: number, g: number, b: number): [number, number, number] {\n const max = Math.max(r, g, b);\n const min = Math.min(r, g, b);\n const l = (max + min) / 2;\n const d = max - min;\n if (d === 0) return [0, 0, l];\n // Near white or black the denominator cancels to 0, or below d, while d does not.\n const s = Math.min(1, d / (1 - Math.abs(2 * l - 1)));\n let h: number;\n if (max === r) h = ((g - b) / d) % 6;\n else if (max === g) h = (b - r) / d + 2;\n else h = (r - g) / d + 4;\n return [(((h * 60) % 360) + 360) % 360, s, l];\n}\n","const TWO_PI = Math.PI * 2;\n\n/** `dh` radians as the shorter arc, in [-π, π]: a half turn keeps its sign. NaN for NaN and ±∞.\n * geom's `wrapAngle(dh, 'sign')`, kept here because paint does not depend on geom. */\nexport function shortArc(dh: number): number {\n const r = dh % TWO_PI;\n return r > Math.PI ? r - TWO_PI : r < -Math.PI ? r + TWO_PI : r;\n}\n","// sRGB ↔ OKLab conversion. Reference: https://bottosson.github.io/posts/oklab/\n\nimport { lerpHueDeg, type HueInterpolation } from './hue';\nimport { lerp } from './lerp';\nimport { byteHex, hexToRgbBytes } from './hex';\nimport { hslToSrgb, srgbToHsl } from './hsl';\nimport { shortArc } from './shortArc';\n\nconst SRGB_TO_LINEAR: Float64Array = (() => {\n const lut = new Float64Array(256);\n for (let i = 0; i < 256; i++) {\n const c = i / 255;\n lut[i] = c <= 0.04045 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);\n }\n return lut;\n})();\n\nfunction linearToSrgbByte(c: number): number {\n if (c <= 0) return 0;\n if (c >= 1) return 255;\n const v = c <= 0.0031308 ? c * 12.92 : 1.055 * Math.pow(c, 1 / 2.4) - 0.055;\n return Math.round(v * 255);\n}\n\n/** 0..1 float channel to the 8-bit index the LUTs are cut for. Rounds and\n * clamps; `& 0xff` would truncate, and wrap anything out of range. */\nconst f2u = (v: number): number => Math.max(0, Math.min(255, Math.round(v * 255)));\n\n/**\n * Convert a 0..1 float sRGB triple to OKLab — the renderer's own color space,\n * and what a caller holding a `resolveColor` result has. Rounds into the u8\n * grid the way every other float→u8 crossing in this file does, rather than\n * leaving each caller to pick a convention.\n */\nexport function srgbFloatToOklab(r: number, g: number, b: number): [number, number, number] {\n return srgbU8ToOklab(f2u(r), f2u(g), f2u(b));\n}\n\n/** Convert an 8-bit sRGB triple to OKLab. Channels are indices into a 256-entry\n * LUT: pass integers, or `srgbFloatToOklab` for 0..1 floats. */\nexport function srgbU8ToOklab(r: number, g: number, b: number): [number, number, number] {\n return linearSrgbToOklab(SRGB_TO_LINEAR[r & 0xff], SRGB_TO_LINEAR[g & 0xff], SRGB_TO_LINEAR[b & 0xff]);\n}\n\n/** Linear-light sRGB (0..1 floats, unclamped) to OKLab. */\nexport function linearSrgbToOklab(rl: number, gl: number, bl: number): [number, number, number] {\n const l = 0.4122214708 * rl + 0.5363325363 * gl + 0.0514459929 * bl;\n const m = 0.2119034982 * rl + 0.6806995451 * gl + 0.1073969566 * bl;\n const s = 0.0883024619 * rl + 0.2817188376 * gl + 0.6299787005 * bl;\n const lp = Math.cbrt(l);\n const mp = Math.cbrt(m);\n const sp = Math.cbrt(s);\n return [\n 0.2104542553 * lp + 0.7936177850 * mp - 0.0040720468 * sp,\n 1.9779984951 * lp - 2.4285922050 * mp + 0.4505937099 * sp,\n 0.0259040371 * lp + 0.7827717662 * mp - 0.8086757660 * sp,\n ];\n}\n\n/** OKLab to linear-light sRGB. Not gamut-clipped: out-of-gamut colors come\n * back with channels outside 0..1. */\nexport function oklabToLinearSrgb(L: number, A: number, B: number): [number, number, number] {\n const lp = L + 0.3963377774 * A + 0.2158037573 * B;\n const mp = L - 0.1055613458 * A - 0.0638541728 * B;\n const sp = L - 0.0894841775 * A - 1.2914855480 * B;\n const l = lp * lp * lp;\n const m = mp * mp * mp;\n const s = sp * sp * sp;\n return [\n +4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s,\n -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s,\n -0.0041960863 * l - 0.7034186147 * m + 1.7076147010 * s,\n ];\n}\n\nfunction inGamut(rl: number, gl: number, bl: number): boolean {\n // Small epsilon absorbs float-roundtrip noise on pure-primary colors.\n const eps = 1e-6;\n return (\n rl >= -eps && rl <= 1 + eps &&\n gl >= -eps && gl <= 1 + eps &&\n bl >= -eps && bl <= 1 + eps\n );\n}\n\nfunction clipToGamut(L: number, A: number, B: number): [number, number, number] {\n let [rl, gl, bl] = oklabToLinearSrgb(L, A, B);\n if (inGamut(rl, gl, bl)) return [rl, gl, bl];\n let lo = 0;\n let hi = 1;\n // 5 iterations → ~3% chroma precision; sufficient for u8 output.\n for (let i = 0; i < 5; i++) {\n const t = (lo + hi) / 2;\n [rl, gl, bl] = oklabToLinearSrgb(L, A * t, B * t);\n if (inGamut(rl, gl, bl)) lo = t; else hi = t;\n }\n [rl, gl, bl] = oklabToLinearSrgb(L, A * lo, B * lo);\n return [rl, gl, bl];\n}\n\n/** Convert OKLab back to an 8-bit sRGB triple, clamped into gamut. */\nexport function oklabToSrgbU8(L: number, A: number, B: number): [number, number, number] {\n const [rl, gl, bl] = clipToGamut(L, A, B);\n return [linearToSrgbByte(rl), linearToSrgbByte(gl), linearToSrgbByte(bl)];\n}\n\n/** Blend two 8-bit sRGB colors through OKLab. Perceptually even, and it does\n * not pass through the muddy midpoints an sRGB blend produces between\n * complementary hues. */\nexport function lerpOklab(\n from: readonly [number, number, number],\n to: readonly [number, number, number],\n t: number,\n): [number, number, number] {\n return [\n lerp(from[0], to[0], t),\n lerp(from[1], to[1], t),\n lerp(from[2], to[2], t),\n ];\n}\n\n/** Convert OKLab (L, a, b) to OKLCh (L, C, h). h is in radians, range [-π, π]. */\nexport function oklabToOklch(L: number, A: number, B: number): [number, number, number] {\n const C = Math.hypot(A, B);\n const h = Math.atan2(B, A);\n return [L, C, h];\n}\n\n/** Convert OKLCh (L, C, h) to OKLab (L, a, b). h is in radians. */\nexport function oklchToOklab(L: number, C: number, h: number): [number, number, number] {\n return [L, C * Math.cos(h), C * Math.sin(h)];\n}\n\n/** Lerp OKLCh values with shortest-arc hue interpolation. Lightness and\n * chroma lerp linearly. When chroma is near zero on either endpoint, hue\n * is taken from the other endpoint (avoids hue snap-from-undefined).\n * h inputs are in radians. */\nexport function lerpOklch(\n from: readonly [number, number, number],\n to: readonly [number, number, number],\n t: number,\n): [number, number, number] {\n const [L1, C1, h1Raw] = from;\n const [L2, C2, h2Raw] = to;\n const C_EPS = 1e-4;\n // When one endpoint is near-achromatic, take hue from the other endpoint\n // to avoid spurious arc rotation through undefined hue space.\n const h1 = C1 < C_EPS ? h2Raw : h1Raw;\n const h2 = C2 < C_EPS ? h1Raw : h2Raw;\n const dh = shortArc(h2 - h1);\n return [\n lerp(L1, L2, t),\n lerp(C1, C2, t),\n h1 + dh * t,\n ];\n}\n\n/** Which space a color blend is computed in. `'rgb'` is cheapest; `'oklab'`\n * is perceptually even; `'oklch'` additionally travels around the hue wheel\n * rather than through it. */\nexport type ColorSpace = 'rgb' | 'oklab' | 'oklch';\n\nconst u2f = (v: number): number => v / 255;\n\n/** Lerp a flat RGBA color array `from` toward `to`. Inputs are 0..1\n * floats (the renderer's color space); outputs are 0..1 floats too.\n * Alpha is always linearly lerped; RGB channels are lerped in the\n * requested color space. OKLab / OKLCh paths bounce through u8 because\n * the gamma-correction LUT and gamut-clip routines are byte-keyed —\n * the round-trip is lossy at <1% per channel, well under the visible\n * threshold for these animations. */\nexport function lerpColorArray(\n from: readonly number[],\n to: readonly number[],\n t: number,\n space: ColorSpace = 'rgb',\n): number[] {\n if (from.length !== to.length) {\n throw new Error(`lerpColorArray: length mismatch (from=${from.length}, to=${to.length})`);\n }\n if (from.length % 4 !== 0) {\n throw new Error(`lerpColorArray: length ${from.length} not divisible by 4`);\n }\n const out = new Array<number>(from.length);\n const n = from.length / 4;\n if (space === 'rgb') {\n // Pure float lerp — no rounding (which previously discretized 0..1\n // inputs to 0/1, giving the cycle its 'choppy 8-corner' look).\n for (let i = 0; i < from.length; i++) {\n out[i] = lerp(from[i], to[i], t);\n }\n return out;\n }\n if (space === 'oklch') {\n for (let i = 0; i < n; i++) {\n const k = i * 4;\n const fLab = srgbU8ToOklab(f2u(from[k]), f2u(from[k + 1]), f2u(from[k + 2]));\n const tLab = srgbU8ToOklab(f2u(to[k]), f2u(to[k + 1]), f2u(to[k + 2]));\n const fLch = oklabToOklch(fLab[0], fLab[1], fLab[2]);\n const tLch = oklabToOklch(tLab[0], tLab[1], tLab[2]);\n const midLch = lerpOklch(fLch, tLch, t);\n const midLab = oklchToOklab(midLch[0], midLch[1], midLch[2]);\n const [r, g, b] = oklabToSrgbU8(midLab[0], midLab[1], midLab[2]);\n out[k] = u2f(r);\n out[k + 1] = u2f(g);\n out[k + 2] = u2f(b);\n out[k + 3] = lerp(from[k + 3], to[k + 3], t);\n }\n return out;\n }\n for (let i = 0; i < n; i++) {\n const k = i * 4;\n const fLab = srgbU8ToOklab(f2u(from[k]), f2u(from[k + 1]), f2u(from[k + 2]));\n const tLab = srgbU8ToOklab(f2u(to[k]), f2u(to[k + 1]), f2u(to[k + 2]));\n const mid = lerpOklab(fLab, tLab, t);\n const [r, g, b] = oklabToSrgbU8(mid[0], mid[1], mid[2]);\n out[k] = u2f(r);\n out[k + 1] = u2f(g);\n out[k + 2] = u2f(b);\n out[k + 3] = lerp(from[k + 3], to[k + 3], t);\n }\n return out;\n}\n\n// ---------------------------------------------------------------------------\n// OKLCh in degrees\n// ---------------------------------------------------------------------------\n\n/**\n * OKLCh with the hue in **degrees**, and `#rrggbb` on the other side.\n *\n * The helpers above take radians, because that is what the math wants. Every\n * consumer that authors colors — a theme ramp, a palette generator — wants\n * degrees and a hex string, and two packages independently built the same\n * wrapper before this existed.\n */\nexport interface OklchDeg {\n readonly L: number;\n readonly C: number;\n /** 0..360. */\n readonly H: number;\n}\n\n/**\n * OKLCh (hue in degrees) to `#rrggbb`. Over-saturated requests come back at\n * the gamut boundary: `oklabToSrgbU8` clips chroma at constant lightness, which\n * is what lets a caller find a hue's ceiling by asking for far more than exists.\n */\nexport function oklchDegToHex(L: number, C: number, hueDeg: number): string {\n const [l, a, b] = oklchToOklab(L, C, (hueDeg * Math.PI) / 180);\n const [r, g, bl] = oklabToSrgbU8(l, a, b);\n return `#${byteHex(r)}${byteHex(g)}${byteHex(bl)}`;\n}\n\n/** A hex color (`#rgb`, `#rgba`, `#rrggbb`, or `#rrggbbaa`, alpha ignored) to\n * OKLCh with the hue wrapped into 0..360. Throws on anything else. */\nexport function hexToOklchDeg(hex: string): OklchDeg {\n const [L, A, B] = srgbU8ToOklab(...hexToRgbBytes(hex));\n const [l, c, h] = oklabToOklch(L, A, B);\n return { L: l, C: c, H: ((((h * 180) / Math.PI) % 360) + 360) % 360 };\n}\n\n// ---------------------------------------------------------------------------\n// Float sRGB transfer and interpolation across spaces\n// ---------------------------------------------------------------------------\n\n/** sRGB-encoded channel (0..1) to linear light. Unclamped; odd-symmetric\n * below zero, as CSS `srgb-linear` extends it. */\nexport function srgbToLinear(c: number): number {\n const a = Math.abs(c);\n const v = a <= 0.04045 ? a / 12.92 : Math.pow((a + 0.055) / 1.055, 2.4);\n return c < 0 ? -v : v;\n}\n\n/** Linear-light channel to sRGB encoding (0..1). Unclamped. */\nexport function linearToSrgb(c: number): number {\n const a = Math.abs(c);\n const v = a <= 0.0031308 ? a * 12.92 : 1.055 * Math.pow(a, 1 / 2.4) - 0.055;\n return c < 0 ? -v : v;\n}\n\n/**\n * The space a color interpolation runs in, spelled as CSS `color-mix()` spells\n * them. `'srgb'` and `'srgb-linear'` blend gamma-encoded and linear-light\n * channels; `'oklab'` blends perceptual coordinates; `'oklch'` and `'hsl'` are\n * polar, so their hue travels around the wheel rather than through it.\n *\n * Distinct from {@link ColorSpace}, the gradient and animation vocabulary,\n * which keeps its `'rgb'` spelling and its byte-precision paths.\n */\nexport type ColorInterpolationSpace = 'oklch' | 'oklab' | 'hsl' | 'srgb' | 'srgb-linear';\n\n/** An endpoint with less chroma (OKLCH) or saturation (HSL) than this has no\n * hue of its own. */\nconst ACHROMATIC_EPS = 1e-4;\n\ntype Polar = readonly [radius: number, hueDeg: number, axis: number];\n\nfunction lerpPolar(a: Polar, b: Polar, t: number, method: HueInterpolation, hueT: number): [number, number, number] {\n const h1 = a[0] < ACHROMATIC_EPS ? b[1] : a[1];\n const h2 = b[0] < ACHROMATIC_EPS ? a[1] : b[1];\n return [lerp(a[0], b[0], t), lerpHueDeg(h1, h2, hueT, method), lerp(a[2], b[2], t)];\n}\n\ntype Rgb = readonly [number, number, number];\n\nconst lerp3 = (a: Rgb, b: Rgb, t: number): [number, number, number] => [\n lerp(a[0], b[0], t),\n lerp(a[1], b[1], t),\n lerp(a[2], b[2], t),\n];\n\nconst clamp01 = (v: number): number => (v < 0 ? 0 : v > 1 ? 1 : v);\n\nconst srgbToOklabFloat = (c: Rgb): [number, number, number] =>\n linearSrgbToOklab(srgbToLinear(c[0]), srgbToLinear(c[1]), srgbToLinear(c[2]));\n\nfunction oklabToSrgbClipped(L: number, A: number, B: number): [number, number, number] {\n const [rl, gl, bl] = clipToGamut(L, A, B);\n return [clamp01(linearToSrgb(rl)), clamp01(linearToSrgb(gl)), clamp01(linearToSrgb(bl))];\n}\n\n/**\n * Interpolate between two sRGB colors (0..1 floats) in `space`, at `t` in 0..1.\n * Float precision throughout, with no byte round-trip. The result is sRGB;\n * only OKLab and OKLCH blends can leave gamut, and those come back\n * chroma-clipped at constant OKLab lightness.\n *\n * `hue` applies to the polar spaces only. An endpoint with no chroma (OKLCH)\n * or no saturation (HSL) borrows the other endpoint's hue, so a ramp to white\n * or black holds its hue instead of sweeping from red.\n */\nexport function interpolateSrgb(\n from: readonly [number, number, number],\n to: readonly [number, number, number],\n t: number,\n space: ColorInterpolationSpace = 'oklch',\n hue: HueInterpolation = 'shorter',\n): [number, number, number] {\n return interpolateSrgbSplit(from, to, t, t, space, hue);\n}\n\n/** {@link interpolateSrgb} with the hue of a polar space at `hueT` and everything else at `t`, as a premultiplied mix needs. */\nexport function interpolateSrgbSplit(\n from: Rgb,\n to: Rgb,\n t: number,\n hueT: number,\n space: ColorInterpolationSpace,\n hue: HueInterpolation,\n): [number, number, number] {\n switch (space) {\n case 'srgb':\n return lerp3(from, to, t);\n case 'srgb-linear': {\n const lin = (c: Rgb): Rgb => [srgbToLinear(c[0]), srgbToLinear(c[1]), srgbToLinear(c[2])];\n const [r, g, b] = lerp3(lin(from), lin(to), t);\n return [linearToSrgb(r), linearToSrgb(g), linearToSrgb(b)];\n }\n case 'oklab': {\n const [L, A, B] = lerp3(srgbToOklabFloat(from), srgbToOklabFloat(to), t);\n return oklabToSrgbClipped(L, A, B);\n }\n case 'oklch': {\n const polar = (c: Rgb): Polar => {\n const [L, C, h] = oklabToOklch(...srgbToOklabFloat(c));\n return [C, (((h * 180) / Math.PI) % 360 + 360) % 360, L];\n };\n const [C, H, L] = lerpPolar(polar(from), polar(to), t, hue, hueT);\n const [l, a, b] = oklchToOklab(L, C, (H * Math.PI) / 180);\n return oklabToSrgbClipped(l, a, b);\n }\n case 'hsl': {\n const polar = (c: Rgb): Polar => {\n const [h, s, l] = srgbToHsl(c[0], c[1], c[2]);\n return [s, h, l];\n };\n const [s, h, l] = lerpPolar(polar(from), polar(to), t, hue, hueT);\n return hslToSrgb(h, s, l);\n }\n }\n}\n","import { linearToSrgb, oklabToLinearSrgb, oklchToOklab } from './colorSpaces';\nimport { hslToSrgb } from './hsl';\nimport { byteHex, parseHexBytes } from './hex';\n\n/**\n * Parse a CSS color string into [r, g, b, a] with 0..1 components.\n *\n * Supported forms:\n * - Hex: `#rgb`, `#rgba`, `#rrggbb`, `#rrggbbaa` (any case)\n * - `rgb()` / `rgba()` with integer, float, or percent R/G/B; number or\n * percent alpha; commas or modern space-separated `R G B / A` syntax\n * - `hsl()` / `hsla()` with hue as a unitless number (deg) or with `deg`,\n * `rad`, `grad`, `turn` units; saturation/lightness as percent (or\n * unitless 0..100, as CSS Color 4 reads it); same alpha rules and separator rules\n * as `rgb()`\n * - The 148 CSS named colors plus `transparent`\n * - `color(srgb …)` and `color(srgb-linear …)`; `oklab()` and `oklch()`, clamped into sRGB\n *\n * Not supported: `lab()`, `lch()`, other `color()` spaces, `currentColor`, system\n * colors. Throws on anything unrecognized.\n *\n * Results are cached by input-string identity. Callers MUST treat the\n * returned tuple as read-only — mutation would corrupt the cache.\n */\nexport function parseColor(input: string): [number, number, number, number] {\n const cached = CACHE.get(input);\n if (cached !== undefined) return cached;\n const result = parseColorUncached(input);\n if (CACHE.size >= CACHE_MAX) CACHE.clear();\n CACHE.set(input, result);\n return result;\n}\n\nconst CACHE = new Map<string, [number, number, number, number]>();\nconst CACHE_MAX = 1024;\n\nfunction parseColorUncached(input: string): [number, number, number, number] {\n const s = input.trim();\n if (s.startsWith('#')) return parseHex(s);\n\n const lower = s.toLowerCase();\n\n if (Object.hasOwn(NAMED_COLORS, lower)) return NAMED_COLORS[lower]!;\n\n if (lower.startsWith('rgb')) {\n const parsed = parseRgbFunction(lower);\n if (parsed) return parsed;\n }\n if (lower.startsWith('hsl')) {\n const parsed = parseHslFunction(lower);\n if (parsed) return parsed;\n }\n if (lower.startsWith('color(')) {\n const parsed = parseColorFunction(lower);\n if (parsed) return parsed;\n }\n if (lower.startsWith('ok')) {\n const parsed = parseOkFunction(lower);\n if (parsed) return parsed;\n }\n\n throw new Error(`parseColor: unrecognized color \"${input}\"`);\n}\n\n/** `parseColor`, typed read-only: the form for renderer hot paths (per-frame\n * draw callbacks, gradient ramp builds), which share its cache. */\nexport function resolveColor(input: string): readonly [number, number, number, number] {\n return parseColor(input);\n}\n\n/** @internal Test-only: drops the color cache so tests can assert behavior in\n * isolation. Never call from production code. */\nexport function __resetResolveColorCache(): void {\n CACHE.clear();\n}\n\n/** Same as `parseColor` but returns integer 0..255 components. */\nexport function parseColorToRgba255(input: string): [number, number, number, number] {\n const [r, g, b, a] = parseColor(input);\n return [\n Math.round(r * 255),\n Math.round(g * 255),\n Math.round(b * 255),\n Math.round(a * 255),\n ];\n}\n\n/** The hex form {@link normalizeHex} writes: `'rgb'` drops alpha, `'rgba'` always writes it (`ff` when none was named). */\nexport type HexForm = 'rgb' | 'rgba';\n\n/**\n * Canonicalize a hex color string to lowercase `#rrggbb` or `#rrggbbaa`: the\n * latter when `form` is `'rgba'`, or with no `form`, when the input names an alpha.\n *\n * Accepts: `#rgb`, `#rgba`, `#rrggbb`, `#rrggbbaa`, with or without the\n * leading `#`, any case. Throws on other inputs.\n */\nexport function normalizeHex(input: string, form?: HexForm): string {\n const hex = tryNormalizeHex(input, form);\n if (hex === undefined) throw new Error(`normalizeHex: invalid hex \"${input}\"`);\n return hex;\n}\n\n/** {@link normalizeHex}, undefined where it would throw. */\nexport function tryNormalizeHex(input: string, form?: HexForm): string | undefined {\n const trimmed = input.trim();\n const hashed = trimmed.startsWith('#') ? trimmed : `#${trimmed}`;\n const bytes = parseHexBytes(hashed);\n if (!bytes) return undefined;\n const digits = bytes.map(byteHex).join('');\n const alpha = form ? form === 'rgba' : hashed.length === 5 || hashed.length === 9;\n return `#${alpha ? digits : digits.slice(0, 6)}`;\n}\n\n/**\n * Parse a hex color into [r, g, b, a] with 0..1 components. Accepts the same\n * forms as `normalizeHex`, including a missing leading `#`.\n */\nexport function hexToRgba(input: string): [number, number, number, number] {\n return parseHex(normalizeHex(input));\n}\n\n/**\n * Format [r, g, b, a] (0..1 components) as a hex string. Emits `#rrggbb` when\n * alpha is exactly 1 (or omitted), otherwise `#rrggbbaa`.\n */\nexport function rgbaToHex(rgba: readonly [number, number, number, number] | readonly [number, number, number]): string {\n const [r, g, b] = rgba;\n const a = rgba.length === 4 ? rgba[3] : 1;\n const f = (n: number) => byteHex(n * 255);\n const base = `#${f(r)}${f(g)}${f(b)}`;\n return a >= 1 ? base : `${base}${f(a)}`;\n}\n\nfunction parseHex(s: string): [number, number, number, number] {\n const bytes = parseHexBytes(s);\n if (!bytes) throw new Error(`parseColor: invalid hex \"${s}\"`);\n return [bytes[0] / 255, bytes[1] / 255, bytes[2] / 255, bytes[3] / 255];\n}\n\n/** Match `name( body )` and return the trimmed body, or null. */\nfunction unwrapFn(s: string, name: string): string | null {\n if (!s.startsWith(name + '(') || !s.endsWith(')')) return null;\n return s.slice(name.length + 1, -1).trim();\n}\n\n/**\n * Split a function body into the value tokens (3 channels + optional alpha).\n * Supports both legacy `r, g, b[, a]` and modern `r g b[ / a]` separators.\n * Returns null if the token count is wrong.\n */\nfunction splitChannels(body: string): { rgb: [string, string, string]; alpha: string | null } | null {\n if (body.includes(',')) {\n const parts = body.split(',').map((p) => p.trim());\n if (parts.length !== 3 && parts.length !== 4) return null;\n return {\n rgb: [parts[0], parts[1], parts[2]],\n alpha: parts.length === 4 ? parts[3] : null,\n };\n }\n // Modern syntax: whitespace-separated, with optional `/ alpha` tail.\n const slash = body.indexOf('/');\n const head = (slash === -1 ? body : body.slice(0, slash)).trim();\n const alpha = slash === -1 ? null : body.slice(slash + 1).trim();\n const parts = head.split(/\\s+/);\n if (parts.length !== 3) return null;\n if (alpha !== null && alpha === '') return null;\n return { rgb: [parts[0], parts[1], parts[2]], alpha };\n}\n\nconst CSS_NUMBER = /^[+-]?(?:\\d+\\.?\\d*|\\.\\d+)(?:e[+-]?\\d+)?$/;\n\n/** A CSS `<number>` token, or null: `Number` alone reads `''` as 0 and accepts `0x10`. */\nfunction cssNumber(tok: string): number | null {\n if (!CSS_NUMBER.test(tok)) return null;\n const n = Number(tok);\n return Number.isFinite(n) ? n : null;\n}\n\n/** Parse a channel value: integer, float, or percent. Returns 0..1 (with `max` as the integer scale). */\nfunction parseChannel(tok: string, max: number): number | null {\n const percent = tok.endsWith('%');\n const n = cssNumber(percent ? tok.slice(0, -1) : tok);\n return n === null ? null : clamp01(n / (percent ? 100 : max));\n}\n\n/** Alpha may be a number 0..1 or a percent; absent is opaque. */\nfunction parseAlpha(tok: string | null): number | null {\n return tok === null ? 1 : parseChannel(tok, 1);\n}\n\nfunction parseRgbFunction(s: string): [number, number, number, number] | null {\n const body = unwrapFn(s, 'rgba') ?? unwrapFn(s, 'rgb');\n if (body === null) return null;\n const channels = splitChannels(body);\n if (!channels) return null;\n const r = parseChannel(channels.rgb[0], 255);\n const g = parseChannel(channels.rgb[1], 255);\n const b = parseChannel(channels.rgb[2], 255);\n const a = parseAlpha(channels.alpha);\n if (r === null || g === null || b === null || a === null) return null;\n return [r, g, b, a];\n}\n\nfunction parseHslFunction(s: string): [number, number, number, number] | null {\n const body = unwrapFn(s, 'hsla') ?? unwrapFn(s, 'hsl');\n if (body === null) return null;\n const channels = splitChannels(body);\n if (!channels) return null;\n const h = parseHue(channels.rgb[0]);\n // CSS Color 4 reads a unitless saturation or lightness on the percent scale: 50 is 50%.\n const sat = parseChannel(channels.rgb[1], 100);\n const lit = parseChannel(channels.rgb[2], 100);\n const a = parseAlpha(channels.alpha);\n if (h === null || sat === null || lit === null || a === null) return null;\n const [r, g, b] = hslToSrgb(h, sat, lit);\n return [r, g, b, a];\n}\n\n/** `color(srgb …)` or `color(srgb-linear …)`, channels as numbers 0..1 or percents. */\nfunction parseColorFunction(s: string): [number, number, number, number] | null {\n const body = unwrapFn(s, 'color');\n const space = body?.match(/^(srgb-linear|srgb)\\s+/);\n if (!body || !space || body.includes(',')) return null;\n const channels = splitChannels(body.slice(space[0].length));\n if (!channels) return null;\n const rgb = channels.rgb.map((tok) => parseChannel(tok, 1));\n const a = parseAlpha(channels.alpha);\n if (rgb.some((c) => c === null) || a === null) return null;\n const [r, g, b] = (space[1] === 'srgb' ? rgb : rgb.map((c) => linearToSrgb(c as number))) as number[];\n return [clamp01(r as number), clamp01(g as number), clamp01(b as number), a];\n}\n\n/** `oklab(L a b)` or `oklch(L C h)`, clamped into sRGB. L is 0..1 or a percent; a, b and C are numbers. */\nfunction parseOkFunction(s: string): [number, number, number, number] | null {\n const lch = unwrapFn(s, 'oklch');\n const body = lch ?? unwrapFn(s, 'oklab');\n if (body === null || body.includes(',')) return null;\n const channels = splitChannels(body);\n if (!channels) return null;\n const L = parsePercentOrNumber(channels.rgb[0]);\n const second = cssNumber(channels.rgb[1]);\n const third = lch !== null ? parseHue(channels.rgb[2]) : cssNumber(channels.rgb[2]);\n const alpha = parseAlpha(channels.alpha);\n if (L === null || second === null || third === null || alpha === null) return null;\n // CSS clamps a negative chroma to 0 rather than turning the hue half a turn.\n const [, A, B] = lch !== null ? oklchToOklab(L, Math.max(0, second), third * (Math.PI / 180)) : [L, second, third];\n const [r, g, b] = oklabToLinearSrgb(L, A, B).map((c) => clamp01(linearToSrgb(c)));\n return [r as number, g as number, b as number, alpha];\n}\n\n/** Parse a hue token:`<number>`, `<number>deg`, `<number>rad`, `<number>grad`, `<number>turn`. Returns degrees 0..360 (modulo). */\nfunction parseHue(tok: string): number | null {\n const unit = /(deg|grad|rad|turn)$/.exec(tok)?.[1];\n const n = cssNumber(unit === undefined ? tok : tok.slice(0, -unit.length));\n if (n === null) return null;\n // 400grad = 360deg\n const deg = unit === 'grad' ? n * 0.9 : unit === 'rad' ? n * (180 / Math.PI) : unit === 'turn' ? n * 360 : n;\n return ((deg % 360) + 360) % 360;\n}\n\n/** An OKLab lightness: a percent or a unitless number 0..1. */\nfunction parsePercentOrNumber(tok: string): number | null {\n return parseChannel(tok, 1);\n}\n\nfunction clamp01(n: number): number {\n return n < 0 ? 0 : n > 1 ? 1 : n;\n}\n\n// CSS Color Module Level 4 named colors. Stored as already-resolved tuples so\n// lookup is O(1) and avoids a second parse hop.\nconst NAMED_COLORS: Record<string, [number, number, number, number]> = (() => {\n const hex: Record<string, number> = {\n aliceblue: 0xf0f8ff, antiquewhite: 0xfaebd7, aqua: 0x00ffff, aquamarine: 0x7fffd4,\n azure: 0xf0ffff, beige: 0xf5f5dc, bisque: 0xffe4c4, black: 0x000000,\n blanchedalmond: 0xffebcd, blue: 0x0000ff, blueviolet: 0x8a2be2, brown: 0xa52a2a,\n burlywood: 0xdeb887, cadetblue: 0x5f9ea0, chartreuse: 0x7fff00, chocolate: 0xd2691e,\n coral: 0xff7f50, cornflowerblue: 0x6495ed, cornsilk: 0xfff8dc, crimson: 0xdc143c,\n cyan: 0x00ffff, darkblue: 0x00008b, darkcyan: 0x008b8b, darkgoldenrod: 0xb8860b,\n darkgray: 0xa9a9a9, darkgreen: 0x006400, darkgrey: 0xa9a9a9, darkkhaki: 0xbdb76b,\n darkmagenta: 0x8b008b, darkolivegreen: 0x556b2f, darkorange: 0xff8c00, darkorchid: 0x9932cc,\n darkred: 0x8b0000, darksalmon: 0xe9967a, darkseagreen: 0x8fbc8f, darkslateblue: 0x483d8b,\n darkslategray: 0x2f4f4f, darkslategrey: 0x2f4f4f, darkturquoise: 0x00ced1, darkviolet: 0x9400d3,\n deeppink: 0xff1493, deepskyblue: 0x00bfff, dimgray: 0x696969, dimgrey: 0x696969,\n dodgerblue: 0x1e90ff, firebrick: 0xb22222, floralwhite: 0xfffaf0, forestgreen: 0x228b22,\n fuchsia: 0xff00ff, gainsboro: 0xdcdcdc, ghostwhite: 0xf8f8ff, gold: 0xffd700,\n goldenrod: 0xdaa520, gray: 0x808080, green: 0x008000, greenyellow: 0xadff2f,\n grey: 0x808080, honeydew: 0xf0fff0, hotpink: 0xff69b4, indianred: 0xcd5c5c,\n indigo: 0x4b0082, ivory: 0xfffff0, khaki: 0xf0e68c, lavender: 0xe6e6fa,\n lavenderblush: 0xfff0f5, lawngreen: 0x7cfc00, lemonchiffon: 0xfffacd, lightblue: 0xadd8e6,\n lightcoral: 0xf08080, lightcyan: 0xe0ffff, lightgoldenrodyellow: 0xfafad2, lightgray: 0xd3d3d3,\n lightgreen: 0x90ee90, lightgrey: 0xd3d3d3, lightpink: 0xffb6c1, lightsalmon: 0xffa07a,\n lightseagreen: 0x20b2aa, lightskyblue: 0x87cefa, lightslategray: 0x778899, lightslategrey: 0x778899,\n lightsteelblue: 0xb0c4de, lightyellow: 0xffffe0, lime: 0x00ff00, limegreen: 0x32cd32,\n linen: 0xfaf0e6, magenta: 0xff00ff, maroon: 0x800000, mediumaquamarine: 0x66cdaa,\n mediumblue: 0x0000cd, mediumorchid: 0xba55d3, mediumpurple: 0x9370db, mediumseagreen: 0x3cb371,\n mediumslateblue: 0x7b68ee, mediumspringgreen: 0x00fa9a, mediumturquoise: 0x48d1cc, mediumvioletred: 0xc71585,\n midnightblue: 0x191970, mintcream: 0xf5fffa, mistyrose: 0xffe4e1, moccasin: 0xffe4b5,\n navajowhite: 0xffdead, navy: 0x000080, oldlace: 0xfdf5e6, olive: 0x808000,\n olivedrab: 0x6b8e23, orange: 0xffa500, orangered: 0xff4500, orchid: 0xda70d6,\n palegoldenrod: 0xeee8aa, palegreen: 0x98fb98, paleturquoise: 0xafeeee, palevioletred: 0xdb7093,\n papayawhip: 0xffefd5, peachpuff: 0xffdab9, peru: 0xcd853f, pink: 0xffc0cb,\n plum: 0xdda0dd, powderblue: 0xb0e0e6, purple: 0x800080, rebeccapurple: 0x663399,\n red: 0xff0000, rosybrown: 0xbc8f8f, royalblue: 0x4169e1, saddlebrown: 0x8b4513,\n salmon: 0xfa8072, sandybrown: 0xf4a460, seagreen: 0x2e8b57, seashell: 0xfff5ee,\n sienna: 0xa0522d, silver: 0xc0c0c0, skyblue: 0x87ceeb, slateblue: 0x6a5acd,\n slategray: 0x708090, slategrey: 0x708090, snow: 0xfffafa, springgreen: 0x00ff7f,\n steelblue: 0x4682b4, tan: 0xd2b48c, teal: 0x008080, thistle: 0xd8bfd8,\n tomato: 0xff6347, turquoise: 0x40e0d0, violet: 0xee82ee, wheat: 0xf5deb3,\n white: 0xffffff, whitesmoke: 0xf5f5f5, yellow: 0xffff00, yellowgreen: 0x9acd32,\n };\n const out: Record<string, [number, number, number, number]> = {\n transparent: [0, 0, 0, 0],\n };\n for (const name in hex) {\n const n = hex[name];\n out[name] = [((n >> 16) & 0xff) / 255, ((n >> 8) & 0xff) / 255, (n & 0xff) / 255, 1];\n }\n return out;\n})();\n","import type { Fill, Paint, Stroke } from './paint';\n\n/** A fill or stroke field holding this takes its holder's source's, whole. */\nexport const INHERIT = 'inherit';\n/** The type of {@link INHERIT}. */\nexport type Inherit = typeof INHERIT;\n\n/** A fill that paints. */\nexport type PaintedFill = Fill & { paint: Paint };\n/** A stroke that paints. */\nexport type PaintedStroke = Stroke & { paint: Paint };\n\n/**\n * What a fill field means: the fill it paints, or `null` for none. Absent,\n * `null` and a record with no `paint` are all none; a paint with alpha 0 is a\n * paint. {@link INHERIT} is `inherited`, which the caller resolves first.\n */\nexport function resolveFill(\n fill: Fill | Inherit | null | undefined,\n inherited: PaintedFill | null = null,\n): PaintedFill | null {\n if (fill === INHERIT) return inherited;\n return fill?.paint == null ? null : (fill as PaintedFill);\n}\n\n/** {@link resolveFill} for a stroke. Width is not consulted here, though a\n * stroke with no width draws nothing, whatever its per-vertex widths:\n * `strokeHasInk` answers both. */\nexport function resolveStroke(\n stroke: Stroke | Inherit | null | undefined,\n inherited: PaintedStroke | null = null,\n): PaintedStroke | null {\n if (stroke === INHERIT) return inherited;\n return stroke?.paint == null ? null : (stroke as PaintedStroke);\n}\n","/**\n * Paint identity as a string: paints with equal keys draw the same, however\n * they were built. Paint is plain data, so the comparison is structural.\n */\n\nimport { parseColor } from './color';\nimport { isSolidPaint } from './commandPaint';\nimport type { Fill, Paint, Stroke } from './paint';\nimport { resolveFill, resolveStroke, type PaintedFill, type PaintedStroke } from './resolvePaint';\n\n/** `value` as JSON with every object's keys sorted and its `undefined`\n * fields dropped, so field order and an explicit `undefined` cannot tell\n * two equal values apart. */\nfunction canonical(value: unknown): string {\n if (Array.isArray(value)) return `[${value.map(canonical).join(',')}]`;\n if (typeof value !== 'object' || value === null) return JSON.stringify(value) ?? 'null';\n const fields = Object.keys(value).sort()\n .filter((k) => (value as Record<string, unknown>)[k] !== undefined)\n .map((k) => `${JSON.stringify(k)}:${canonical((value as Record<string, unknown>)[k])}`);\n return `{${fields.join(',')}}`;\n}\n\nconst structuralKeys = new WeakMap<object, string>();\nconst strokeShapeKeys = new WeakMap<object, string>();\n\n/**\n * A key two paints share only if they draw the same. No paint at all is\n * `'none'`. Two solids that draw the same always share one. A gradient or\n * pattern keys by its fields as written, so one that spells out a default\n * (`opacity: 1`, `units`) keys apart from one that omits it: that splits a\n * group, where merging two that differ would draw one with the other's paint.\n *\n * A gradient or pattern is read once: changed in place after its first use,\n * it keeps the key it had. A solid is read on every call.\n */\nexport function paintKey(paint: Paint | null | undefined): string {\n if (paint == null) return 'none';\n if (isSolidPaint(paint)) return `solid:${solidColorKey(paint.color, paint.opacity ?? 1)}`;\n let key = structuralKeys.get(paint);\n if (key === undefined) {\n key = canonical(paint);\n structuralKeys.set(paint, key);\n }\n return key;\n}\n\n/** A solid's color by its channels with `opacity` folded into its alpha, as a renderer draws it, so `#fff` and\n * `white` key as one, and every fully transparent solid as one; a color `parseColor` cannot read keys as its own text. */\nfunction solidColorKey(color: string, opacity: number): string {\n try {\n const [r, g, b, a] = parseColor(color);\n return a * opacity === 0 ? 'clear' : `${r},${g},${b},${a * opacity}`;\n } catch {\n return `text:${color}:${opacity}`;\n }\n}\n\n/** Whether a fill puts ink down: it does not when it is absent or holds no paint. */\nexport function fillHasInk(fill: Fill | null | undefined): fill is PaintedFill {\n return resolveFill(fill) !== null;\n}\n\n/** Whether a stroke puts ink down: it does not when it is absent, holds no\n * paint, or has no width — whatever its per-vertex widths. */\nexport function strokeHasInk(stroke: Stroke | null | undefined): stroke is PaintedStroke {\n const painted = resolveStroke(stroke);\n if (painted === null) return false;\n const width = painted.width ?? 1;\n return (typeof width === 'number' ? width : width.px) > 0;\n}\n\n/**\n * A key two strokes share only if they draw the same ribbon over the same\n * geometry. Every stroke that puts no ink down is `'none'`. A `{ px }` width\n * keys apart from the equal world-unit number, which is a different ribbon.\n *\n * Everything but the paint is read once: a stroke whose width, dash, or other\n * shape is changed in place keeps the key it had. Its paint is keyed on every\n * call, as {@link paintKey} keys it.\n */\nexport function strokeKey(stroke: Stroke | null | undefined): string {\n if (!strokeHasInk(stroke)) return 'none';\n let shape = strokeShapeKeys.get(stroke);\n if (shape === undefined) {\n const { paint: _paint, width, join, cap, miterLimit, align, dash, ...rest } = stroke;\n shape = canonical({\n ...rest,\n width: width ?? 1,\n join: join ?? 'miter',\n cap: cap ?? 'butt',\n miterLimit: miterLimit ?? 4,\n align: align ?? 'center',\n dash: dash ?? [],\n });\n strokeShapeKeys.set(stroke, shape);\n }\n return `${shape}|${paintKey(stroke.paint)}`;\n}\n","import type { StrokeAlign } from './paint';\n\n/**\n * Whether {@link alignedStrokeRect} draws `align` on `rect`: always, but for an\n * inner stroke at least as wide as the rect's narrower side, which covers the\n * whole rect where the shifted rect would turn inside out and draw outside it.\n */\nexport function alignedStrokeRectHolds(\n rect: { width: number; height: number },\n align: StrokeAlign,\n width = 1,\n): boolean {\n return align !== 'inner' || width < Math.min(Math.abs(rect.width), Math.abs(rect.height));\n}\n\n/**\n * Inflate (positive) or deflate (negative) a rect to honor `align` when\n * stroking it: the returned rect's center-aligned stroke coincides with the\n * requested inner/outer-aligned stroke of the original. `width` is the\n * stroke width (defaults to 1 to match canvas).\n */\nexport function alignedStrokeRect(\n rect: { x: number; y: number; width: number; height: number },\n align: StrokeAlign,\n width = 1,\n): { x: number; y: number; width: number; height: number } {\n if (align === 'center') return rect;\n // For 'inner', shift inward by width/2 so the stroke's outer edge coincides\n // with the geometric edge. For 'outer', shift outward.\n const sign = align === 'inner' ? -1 : 1;\n const d = (sign * width) / 2;\n // A negative extent runs its axis backward, so the shift does too.\n const dx = rect.width < 0 ? -d : d;\n const dy = rect.height < 0 ? -d : d;\n return {\n x: rect.x - dx,\n y: rect.y - dy,\n width: rect.width + 2 * dx,\n height: rect.height + 2 * dy,\n };\n}\n","/**\n * The pattern members of `Paint`: the built-in tiles, each its own kind,\n * `image` for a tile that is a picture, and `texture` for a tile the consumer\n * rasterized itself.\n */\n\nimport type { Paint, PaintUnits } from './paint';\nimport type { PatternTransform } from './patternTransform';\nimport type { TextureHandle } from './texture';\n\n/**\n * Where a pattern's tile sits, shared by every pattern kind.\n *\n * `units` names the space the tile's origin and scale live in, not the space\n * of any geometry (a pattern has none). Under `'bounds'` the tile anchors to\n * the painted node's box, so the pattern travels with the node and a resize\n * reveals more tiles rather than stretching them; `fillInPoseFrame` resolves\n * that to a `'local'` paint with an explicit `origin` before the renderer\n * sees it.\n *\n * `transform` rotates, scales or skews the tile about `origin` (SVG's\n * `patternTransform`, less its translation). See `PatternTransform`.\n */\nexport interface PatternPlacement {\n units?: PaintUnits;\n origin?: { x: number; y: number };\n transform?: PatternTransform;\n opacity?: number;\n}\n\n/**\n * A built-in tile, described as plain data: what a tile paint says about the\n * tile itself, apart from where it sits. `resolvePatternSpec()` turns one into\n * a `TextureHandle` at paint time, memoized so identical specs share a texture.\n *\n * `size` is the tile's edge length, and doubles as its extent in paint\n * space — a bigger `size` rasterizes a bigger tile rather than magnifying\n * a small one, which is why there is no separate scale field.\n */\nexport type TilePatternSpec =\n | { kind: 'hatch'; color: string; size?: number; lineWidth?: number }\n | { kind: 'crosshatch'; color: string; size?: number; lineWidth?: number }\n | { kind: 'dots'; color: string; size?: number; radius?: number }\n | {\n kind: 'chunks';\n color: string;\n /** Omit for a transparent tile background. */\n bg?: string;\n size?: number;\n density?: number;\n chunkSize?: number;\n seed?: number;\n };\n\n/** The built-in tile kinds. */\nexport type TileKind = TilePatternSpec['kind'];\n\n/** A paint of one of the built-in tiles. Plain data, so it survives\n * serialization. */\nexport type TilePaint = TilePatternSpec & PatternPlacement;\n\n/**\n * A tile's extent in paint-space units. Either side omitted takes the\n * source's own pixel size on that axis.\n */\nexport interface TileExtent {\n width?: number;\n height?: number;\n}\n\n/**\n * A paint that repeats a picture. `src` is anything an `<img>` loads — a URL,\n * a `blob:` URL, or a `data:` URI — and is the paint's whole record of the\n * image, so a paint holding a `data:` URI persists and exports with no\n * storage beside it. Until the image decodes the fill draws nothing.\n */\nexport type ImagePatternPaint = { kind: 'image'; src: string } & TileExtent & PatternPlacement;\n\n/**\n * A paint of a tile the consumer built itself via `createTilePattern()`. The\n * handle is a session-scoped registry key, so a paint carrying one cannot be\n * persisted or exported; prefer a tile kind, or `image` for a picture.\n */\nexport type TexturePaint = { kind: 'texture'; texture: TextureHandle } & TileExtent & PatternPlacement;\n\n/** Every paint that repeats a tile. */\nexport type PatternPaint = TilePaint | ImagePatternPaint | TexturePaint;\n\n/** The pattern kinds a renderer cannot draw as they stand: each is resolved\n * to a `texture` paint first. */\nexport type ResolvablePatternKind = TileKind | 'image';\n\n/** The built-in tile kinds, in the order a picker offers them. */\nexport const TILE_KINDS: readonly TileKind[] = ['hatch', 'crosshatch', 'dots', 'chunks'];\n\nconst TILE_KIND_SET: ReadonlySet<string> = new Set(TILE_KINDS);\n\n/** Whether `kind` names a built-in tile. */\nexport function isTileKind(kind: string | undefined): kind is TileKind {\n return kind !== undefined && TILE_KIND_SET.has(kind);\n}\n\n/** Whether a paint is one of the built-in tiles. */\nexport function isTilePaint(paint: Paint): paint is TilePaint {\n return isTileKind(paint.kind);\n}\n\n/** Whether a paint repeats a picture. */\nexport function isImagePatternPaint(paint: Paint): paint is ImagePatternPaint {\n return paint.kind === 'image';\n}\n\n/** Whether a paint repeats a tile: a built-in one, a picture, or a\n * consumer's texture. */\nexport function isPatternPaint(paint: Paint): paint is PatternPaint {\n return paint.kind === 'texture' || paint.kind === 'image' || isTileKind(paint.kind);\n}\n\n/** A pattern paint's placement alone, holding only the fields it sets. */\nexport function patternPlacementOf(paint: PatternPaint): PatternPlacement {\n const { units, origin, transform, opacity } = paint;\n return {\n ...(units !== undefined ? { units } : {}),\n ...(origin !== undefined ? { origin } : {}),\n ...(transform !== undefined ? { transform } : {}),\n ...(opacity !== undefined ? { opacity } : {}),\n };\n}\n\n/** A tile paint's description of the tile alone, its placement left behind. */\nexport function tileSpecOf(paint: TilePaint): TilePatternSpec {\n const { units: _units, origin: _origin, transform: _transform, opacity: _opacity, ...spec } = paint;\n return spec;\n}\n","/**\n * A pattern tile's linear map into paint space: `[a, b, c, d]`, the first\n * four entries of SVG's `matrix(a b c d e f)`. A tile point `(u, v)` lands at\n * `origin + (a·u + c·v, b·u + d·v)`. Translation is the paint's `origin`, so\n * it has no slot here.\n */\nexport type PatternTransform = readonly [a: number, b: number, c: number, d: number];\n\n/**\n * A {@link PatternTransform} as the parts an editor shows. Angles are radians.\n * Applied in the order scale, then skew, then rotation — rotation outermost,\n * so turning a skewed tile turns it whole.\n */\nexport interface PatternTransformParts {\n rotation: number;\n scaleX: number;\n scaleY: number;\n /** Shear of the tile's y axis toward x, as SVG `skewX()`. */\n skewX: number;\n}\n\n/** `R(rotation) · K(skewX) · S(scaleX, scaleY)`. Omitted parts are identity. */\nexport function composePatternTransform(parts: Partial<PatternTransformParts>): PatternTransform {\n const { rotation = 0, scaleX = 1, scaleY = 1, skewX = 0 } = parts;\n const cos = Math.cos(rotation);\n const sin = Math.sin(rotation);\n const shear = Math.tan(skewX) * scaleY;\n return [\n cos * scaleX,\n sin * scaleX,\n cos * shear - sin * scaleY,\n sin * shear + cos * scaleY,\n ];\n}\n\n/**\n * Inverse of {@link composePatternTransform}. Any invertible 2×2 matrix decomposes\n * this way; a reflection comes back as a negative `scaleY`. A singular one whose\n * second column is a nonzero multiple of its first comes back without that column. `undefined` reads as the\n * identity, which is what an absent `transform` means.\n */\nexport function decomposePatternTransform(t: PatternTransform | undefined): PatternTransformParts {\n if (!t) return { rotation: 0, scaleX: 1, scaleY: 1, skewX: 0 };\n const [a, b, c, d] = t;\n const scaleX = Math.hypot(a, b);\n const rotation = scaleX === 0 ? 0 : Math.atan2(b, a);\n const cos = Math.cos(rotation);\n const sin = Math.sin(rotation);\n const shear = c * cos + d * sin;\n const scaleY = d * cos - c * sin;\n const skewX = scaleY === 0 ? 0 : Math.atan(shear / scaleY);\n return { rotation, scaleX, scaleY, skewX };\n}\n","/**\n * One anchor's entry in `Stroke.vertexWidths`, and the one function every\n * reader resolves it through.\n */\n\n/**\n * The stroke's width at one anchor: a number is the full width, centered on\n * the path; a pair is the distance from the path to each edge on its own.\n * `right` is the side the normal `(−dy, dx)` of the path's direction points\n * to, the right-hand side walking the path on a y-down screen: a path running\n * in +x has its right edge below it. Writers keep a pair only while its sides\n * differ (see {@link vertexWidthFromSides}).\n */\nexport type VertexWidth = number | VertexWidthSides;\n\n/** A {@link VertexWidth} whose edges sit at different distances from the path. */\nexport interface VertexWidthSides {\n readonly left: number;\n readonly right: number;\n}\n\n/** How far each edge of a stroke sits from its path at one point. */\nexport interface HalfWidths {\n left: number;\n right: number;\n}\n\nconst usable = (v: unknown): v is number => typeof v === 'number' && Number.isFinite(v) && v >= 0;\n\n/**\n * The distance from the path to each edge for one `vertexWidths` entry. A\n * missing, non-finite, or negative value — a whole entry, or one side of a\n * pair — takes half of `fallback`, the stroke's own width; zero is a real zero.\n */\nexport function vertexHalfWidths(entry: VertexWidth | null | undefined, fallback: number): HalfWidths {\n const half = fallback / 2;\n if (typeof entry === 'number') return usable(entry) ? { left: entry / 2, right: entry / 2 } : { left: half, right: half };\n if (entry == null || typeof entry !== 'object') return { left: half, right: half };\n return { left: usable(entry.left) ? entry.left : half, right: usable(entry.right) ? entry.right : half };\n}\n\n/** The entry for edges `left` and `right` from the path: a number when they\n * are equal, a pair otherwise. */\nexport function vertexWidthFromSides(left: number, right: number): VertexWidth {\n return Math.abs(left - right) <= 1e-9 * Math.max(1, Math.abs(left), Math.abs(right)) ? left + right : { left, right };\n}\n\n/** `entry` with every length in it multiplied by `k`; an unset one stays unset. */\nexport function scaleVertexWidth(entry: VertexWidth, k: number): VertexWidth {\n return typeof entry === 'number' ? entry * k : { left: entry.left * k, right: entry.right * k };\n}\n\n/** The farthest any edge of a stroke of `width` sits from its path. A nib\n * only ever narrows a stroke, so this bounds one with a nib too. */\nexport function widestHalfWidth(width: number, vertexWidths: readonly VertexWidth[] | undefined): number {\n let widest = width / 2;\n if (vertexWidths) {\n for (const entry of vertexWidths) {\n const { left, right } = vertexHalfWidths(entry, width);\n widest = Math.max(widest, left, right);\n }\n }\n return widest;\n}\n","/**\n * Paint and Stroke types — the unified shape for \"what color or texture\n * paints these pixels,\" modeled on SVG's paint-server concept.\n */\n\nimport type { PatternPaint } from './patternPaint';\nimport type { ColorSpace } from './colorSpaces';\nimport type { VertexWidth } from './vertexWidth';\nimport type { StrokeTrim } from './strokeTrim';\n\n/**\n * Color/texture strategy for fills (and, via `Stroke.paint`, strokes).\n *\n * `kind` is optional and defaults to `'solid'` — `{ color: '#abc' }` is\n * equivalent to `{ kind: 'solid', color: '#abc' }`. Every other paint names\n * its kind.\n *\n * A pattern is one of the built-in tile kinds, an `image`, or a `texture`;\n * see `PatternPaint`.\n *\n * `interpolate` on a gradient names the space its stops blend through, and\n * defaults to `'rgb'`. `'oklab'` spaces the blend perceptually; `'oklch'`\n * additionally travels around the hue wheel, so red to blue stays saturated\n * instead of passing through a muddy purple. Alpha is linear in every space.\n */\nexport type Paint =\n | { kind?: 'solid'; color: string; opacity?: number }\n | PatternPaint\n | { kind: 'linear-gradient'; from: { x: number; y: number }; to: { x: number; y: number }; stops: GradStop[]; units?: PaintUnits; interpolate?: ColorSpace; opacity?: number }\n | { kind: 'radial-gradient'; center: { x: number; y: number }; radius: number; stops: GradStop[]; units?: PaintUnits; interpolate?: ColorSpace; opacity?: number }\n | { kind: 'conic-gradient'; center: { x: number; y: number }; angle: number; stops: GradStop[]; units?: PaintUnits; interpolate?: ColorSpace; opacity?: number };\n\n/**\n * Which coordinate space a gradient's geometry (`from`/`to`, `center`,\n * `radius`) is expressed in. SVG's `gradientUnits`, plus an option for\n * paints that are themselves viewport furniture. Defaults to `'screen'`.\n *\n * - `'bounds'`: fractions of the painted node's bounding box, `0..1` on each\n * axis — SVG `objectBoundingBox`. The paint follows the node through moves,\n * resizes and rotation.\n * - `'local'`: the coordinate space the geometry was handed to the renderer\n * in — the enclosing group's frame.\n * - `'world'`: scene coordinates. The paint stays put under pan and zoom\n * while the geometry moves through it. SVG `userSpaceOnUse`. Requires the\n * renderer to have been handed a view matrix; falls back to `'screen'`\n * when it has not.\n * - `'screen'`: CSS pixels of the drawing surface. For overlays and\n * viewport-fixed washes that should not move with the content at all.\n */\nexport type PaintUnits = 'bounds' | 'local' | 'world' | 'screen';\n\n/** A single color stop within a gradient. `offset` is in 0..1. */\nexport interface GradStop {\n offset: number;\n color: string;\n}\n\n/** The gradient members of `Paint`, as one type. What a gradient editor\n * edits, and what the gradient-specific helpers accept. */\nexport type GradientPaint = Extract<\n Paint,\n { kind: 'linear-gradient' | 'radial-gradient' | 'conic-gradient' }\n>;\n\n/** `GradientPaint['kind']` — the three gradient discriminants on their own. */\nexport type GradientKind = GradientPaint['kind'];\n\n/**\n * Where a stroke sits relative to the geometric edge it strokes.\n *\n * - `'center'` (default): half the stroke width sits inside the geometry,\n * half outside.\n * - `'inner'`: the entire stroke lies inside the geometry.\n * - `'outer'`: the entire stroke lies outside the geometry.\n *\n * Mirrors the (proposed) SVG `stroke-alignment` property.\n */\nexport type StrokeAlign = 'center' | 'inner' | 'outer';\n\n/**\n * The kit's built-in marker vocabulary, open on the string the way\n * `PaintKind` is so a consumer's registered key typechecks.\n */\nexport type KitMarkerKey =\n | 'arrow' | 'arrow-open' | 'arrow-concave' | 'triangle-hollow'\n | 'diamond' | 'diamond-hollow'\n | 'circle' | 'square' | 'bar' | 'dot'\n | 'crow-one' | 'crow-many' | 'crow-zero-one' | 'crow-one-many' | 'crow-zero-many';\n/** A marker shape's key: a built-in {@link KitMarkerKey} or a consumer-registered name. */\nexport type MarkerKey = KitMarkerKey | (string & {});\n\n/**\n * A marker on one end (or every interior vertex) of a stroke.\n *\n * `size` is the length of one marker unit, and replaces the stroke width\n * rather than multiplying it: a bare number is world units, however wide the\n * line. Omitted, one unit is the resolved stroke width — SVG's\n * `markerUnits=\"strokeWidth\"`; given, it is `userSpaceOnUse`. A `{ px }` size\n * holds its screen size through a zoom, as a `{ px }` stroke width does.\n */\nexport type MarkerRef = MarkerKey | { key: MarkerKey; size?: ScreenLength };\n\n/**\n * A length the author states either in world units (a plain number) or in\n * screen pixels (`{ px }`), resolved against the accumulated transform scale\n * wherever it is consumed — so a `{ px }` length holds its on-screen size as\n * the view zooms, with no call-site arithmetic.\n */\nexport type ScreenLength = number | { px: number };\n\n/**\n * Resolve a {@link ScreenLength} to world units. A non-finite or zero scale\n * has no world to divide into, so the pixel count passes through unchanged\n * rather than becoming `Infinity`.\n */\nexport function resolveScreenLength(value: ScreenLength, scale: number): number {\n if (typeof value === 'number') return value;\n if (!Number.isFinite(scale) || scale === 0) return value.px;\n return value.px / scale;\n}\n\n/**\n * Fill style: the paint laid inside an outline. `Stroke`'s sibling, and the\n * same shape: a record holding a `paint`, with room for what belongs to the\n * fill rather than to the paint.\n *\n * A fill or stroke field holds one of three things (decided 2026-10-21):\n *\n * | State | Spelling |\n * |---------|--------------------------------------------|\n * | a paint | a record with a `paint` |\n * | none | absent, `null`, or a record with no `paint` |\n * | inherit | `INHERIT` (`'inherit'`), where the field allows it: the source's field, whole |\n *\n * Absent is none everywhere: no reader turns it into a default color, so\n * whatever makes a node writes the paint it wants. A paint with alpha 0 or\n * the color `transparent` is a paint, invisible but still grabbable.\n * `resolveFill` and `resolveStroke` are the one reading of a field.\n *\n * A node's own fill or stroke inherits from its nearest enclosing container's,\n * walking on past a container that inherits too, and is none at the root.\n * Inheritance happens only where a field says `'inherit'`, never because one\n * is absent.\n */\nexport interface Fill {\n /** Omitted, the fill paints nothing. */\n paint?: Paint;\n}\n\n/** Stroke style: a Paint plus structural line parameters. */\nexport interface Stroke {\n /** Omitted, the stroke paints nothing and keeps its width and dash for\n * the next paint. The three states a field holds are under {@link Fill}. */\n paint?: Paint;\n /** World units, or `{ px }` for screen pixels — resolved against the\n * accumulated transform at draw time, so it holds its on-screen thickness\n * as the view zooms, in every direction even when one axis is zoomed more\n * than the other. */\n width?: ScreenLength;\n /** Per `CanvasRenderingContext2D.setLineDash` — empty/omitted = solid. In\n * the width's units: world, or screen pixels on a `{ px }` stroke, as SVG's\n * `non-scaling-stroke` measures them. */\n dash?: number[];\n /** How far into `dash` each subpath starts, in the dash's units: SVG's\n * `stroke-dashoffset` and Canvas2D's `lineDashOffset`. Negative starts\n * before the pattern's beginning; a non-finite one reads as 0. */\n dashOffset?: number;\n /** The stretch of the path drawn; omitted, all of it. See {@link StrokeTrim}. */\n trim?: StrokeTrim;\n /** Marker at the first vertex of each open subpath, rotated to point back\n * along the line (SVG's `auto-start-reverse`, as the only behavior). */\n markerStart?: MarkerRef;\n /** Marker at every interior authored vertex, on the bisector of the\n * incoming and outgoing directions. Never insets the stroke. The head's\n * anchor sits on the vertex, so a terminator such as `diamond` trails\n * back from it; `dot` is the built-in centered on its vertex. */\n markerMid?: MarkerRef;\n /** Marker at the last vertex of each open subpath. */\n markerEnd?: MarkerRef;\n cap?: 'butt' | 'round' | 'square';\n join?: 'miter' | 'round' | 'bevel';\n /**\n * Miter join fallback threshold. When the miter length exceeds\n * `miterLimit * width / 2`, the join falls back to a bevel. Default 4,\n * matching SVG — which is also what the kit's own serializer implies when\n * it omits the attribute for an unset field. Canvas2D's 10 lets an acute\n * corner throw a spike four times the half-width.\n */\n miterLimit?: number;\n /** Where the stroke sits relative to the geometric edge. Default `'center'`. */\n align?: StrokeAlign;\n /**\n * Per-anchor RGBA, flat (length = 4 × countPathAnchors(path)). Each\n * value in 0..1. Arc-length interpolated across the tessellated ribbon\n * between consecutive anchors. When set, `paint` is still required —\n * its `opacity` (and color, as a placeholder) flow through the shader.\n */\n vertexColors?: number[];\n /**\n * Per-anchor stroke width (length = `countPathAnchors(path)`). When set,\n * the tessellator interpolates each edge's distance from the path along\n * each segment to produce a tapered ribbon. An entry is a full width\n * centered on the path, or a `{ left, right }` pair giving each edge its own\n * distance — see {@link VertexWidth}, and read one through\n * `vertexHalfWidths`. Entries are world units, even on a `{ px }` stroke.\n * `width` is used as the fallback for any anchor whose entry, or side of\n * one, is missing, negative, or non-finite; a stroke whose `width` is 0\n * draws nothing, whatever these say. Pair with `pressureToWidth` to\n * derive widths from stylus input.\n *\n * Joins between adjacent segments whose widths differ by more than\n * `varyingWidthJoinThreshold` (default 1.5×) are forced to bevel\n * regardless of the `join` setting — miter math is unstable when widths\n * vary across the corner.\n */\n vertexWidths?: VertexWidth[];\n /**\n * Max width ratio (greater / lesser) at which a non-bevel join is\n * preserved when `vertexWidths` causes adjacent segments to differ.\n * Beyond this ratio the join falls back to bevel. Default 1.5. Ignored\n * when `vertexWidths` is absent.\n */\n varyingWidthJoinThreshold?: number;\n /**\n * A broad nib: the stroke is as wide as `width` moving across the nib and\n * `ratio` of that moving along it, an elliptical pen's width in between.\n * Multiplies `vertexWidths` where both are set.\n */\n nib?: StrokeNib;\n}\n\n/** A pen whose mark depends on the direction it moves, as a calligraphy\n * pen's does. */\nexport interface StrokeNib {\n /** The nib's edge, in radians counterclockwise from the +x axis on screen\n * (y down), as the measure readout reads angles. */\n angle: number;\n /** Thinnest over widest, 0..1: the width moving along the nib, as a\n * fraction of the width moving across it. */\n ratio: number;\n}\n\n/**\n * The named line styles a `Stroke.dash` array reads as.\n *\n * `custom` is what an imported array that matches no preset reads as — it is\n * reportable, not authorable: there is no array it maps back to.\n */\nexport type StrokeDashStyle = 'solid' | 'dashed' | 'dotted' | 'custom';\n\n/**\n * Dash and gap lengths of the presets, **as multiples of the stroke width**.\n *\n * SVG dash lengths are absolute, so a fixed pattern is a different style at\n * every width: `[6, 3]` is dots on a hairline and a railroad on a 20px\n * stroke. Scaling by the width is what makes \"dashed\" one style.\n */\nexport const STROKE_DASH_RATIOS = {\n dashed: [3, 2],\n dotted: [1, 2],\n} as const satisfies Record<'dashed' | 'dotted', readonly [number, number]>;\n\n/** `width` as a plain number — a `{ px }` width is read at scale 1, matching\n * what an unresolved stroke reaching the tessellator gets. */\nfunction dashWidth(width: number | { px: number } | undefined): number {\n const w = typeof width === 'object' ? width.px : (width ?? 1);\n return Number.isFinite(w) && w > 0 ? w : 1;\n}\n\n/**\n * The `Stroke.dash` array for a named style at `width`, or `undefined` for\n * `solid` — which is stored as no dash at all, not as an empty pattern.\n *\n * `custom` has no array of its own and returns `undefined`; a caller that\n * offers it as a choice should refuse the choice rather than call this.\n */\nexport function dashForStrokeStyle(\n style: StrokeDashStyle,\n width: number | { px: number } | undefined,\n): number[] | undefined {\n if (style !== 'dashed' && style !== 'dotted') return undefined;\n const w = dashWidth(width);\n return STROKE_DASH_RATIOS[style].map((r) => r * w);\n}\n\n/**\n * The most dash and gap runs {@link dashPattern} lets a pattern cut one line\n * into. Past it a pattern is too fine to see as dashes, and walking it would\n * cost work without bound.\n */\nexport const MAX_DASH_RUNS = 100_000;\n\n/**\n * What a `Stroke.dash` array draws, decided once for every reader of it: the\n * array itself when it is a pattern that advances along the line, `'solid'`\n * when it is absent, empty, has a negative entry or sums to zero (as SVG\n * reads those), and `'non-finite'` when any entry is NaN or infinite, which\n * draws no stroke at all. Given the `length` of the path it strokes, a pattern\n * that would cut it into more than {@link MAX_DASH_RUNS} runs is `'solid'` too.\n */\nexport function dashPattern(\n dash: readonly number[] | undefined,\n length?: number,\n): readonly number[] | 'solid' | 'non-finite' {\n if (dash === undefined || dash.length === 0) return 'solid';\n if (!dash.every(Number.isFinite)) return 'non-finite';\n if (dash.some((v) => v < 0) || !dash.some((v) => v > 0)) return 'solid';\n if (length !== undefined) {\n const period = dash.reduce((a, b) => a + b, 0);\n if ((length / period) * dash.length > MAX_DASH_RUNS) return 'solid';\n }\n return dash;\n}\n\n/**\n * Where in `pattern` (one {@link dashPattern} returned) a line starts that sits\n * `phase` along it: `phase` wrapped into one cycle, `0` up to but not including\n * the period — twice the sum for an odd-length pattern, whose dashes and gaps\n * swap each pass. Negative and non-finite phases are read as SVG reads them.\n */\nexport function dashPhase(pattern: readonly number[], phase: number): number {\n if (!Number.isFinite(phase) || phase === 0) return 0;\n const cycle = pattern.reduce((a, b) => a + b, 0) * (pattern.length % 2 + 1);\n if (!(cycle > 0)) return 0;\n const wrapped = phase % cycle;\n if (wrapped >= 0) return wrapped;\n // A phase just below 0 wraps to the cycle itself once rounded, which is 0 again.\n const up = wrapped + cycle;\n return up < cycle ? up : 0;\n}\n\n/** `stroke`'s dash and dash offset, each length multiplied by `k`: the two move together. */\nexport function scaledDash<T extends Pick<Stroke, 'dash' | 'dashOffset'>>(stroke: T, k: number): T {\n if (stroke.dash === undefined && stroke.dashOffset === undefined) return stroke;\n return {\n ...stroke,\n ...(stroke.dash ? { dash: stroke.dash.map((d) => d * k) } : {}),\n ...(stroke.dashOffset !== undefined ? { dashOffset: stroke.dashOffset * k } : {}),\n };\n}\n\n/**\n * The style a stored `dash` reads as at `width`: `solid` wherever\n * {@link dashPattern} draws it solid, and `custom` for an array matching\n * neither preset, a non-finite one included.\n */\nexport function strokeDashStyleOf(\n dash: readonly number[] | undefined,\n width: number | { px: number } | undefined,\n): StrokeDashStyle {\n const pattern = dashPattern(dash);\n if (pattern === 'solid') return 'solid';\n if (pattern === 'non-finite') return 'custom';\n const w = dashWidth(width);\n for (const style of ['dashed', 'dotted'] as const) {\n const preset = STROKE_DASH_RATIOS[style];\n // Tolerance is relative to the width: the presets are multiples of it, and\n // a round-tripped array carries the serializer's decimal trimming.\n if (pattern.length === preset.length && preset.every((r, i) => Math.abs(pattern[i] - r * w) <= w * 1e-3)) {\n return style;\n }\n }\n return 'custom';\n}\n\n/** Region a fill is clipped to. */\nexport interface Region {\n x: number;\n y: number;\n w: number;\n h: number;\n shape: 'rectangle' | 'circle';\n}\n","import { interpolateSrgbSplit, type ColorInterpolationSpace } from './colorSpaces';\nimport type { HueInterpolation } from './hue';\n\ntype Rgba = readonly [number, number, number, number];\n\n/**\n * `color-mix(in <space>, a p%, b)` for two 0..1 sRGBA colors, `p` as 0..1. The\n * channels mix premultiplied by alpha, as CSS does, so a transparent side lends\n * the result its opacity and none of its color; a polar space's hue is not\n * premultiplied, as in CSS. Out-of-gamut results come back chroma-clipped.\n */\nexport function mixRgba(\n a: Rgba,\n b: Rgba,\n p: number,\n space: ColorInterpolationSpace = 'oklch',\n hue: HueInterpolation = 'shorter',\n): [number, number, number, number] {\n const alpha = a[3] * p + b[3] * (1 - p);\n if (alpha === 0) return [0, 0, 0, 0];\n // Premultiplying each side and dividing by the mixed alpha is a plain lerp at this parameter.\n const t = (b[3] * (1 - p)) / alpha;\n const [r, g, bl] = interpolateSrgbSplit([a[0], a[1], a[2]], [b[0], b[1], b[2]], t, 1 - p, space, hue);\n return [r, g, bl, alpha];\n}\n\n/** {@link mixRgba} in OKLab. */\nexport function mixOklab(a: Rgba, b: Rgba, p: number): [number, number, number, number] {\n return mixRgba(a, b, p, 'oklab');\n}\n\n/**\n * The weighted mix of any number of 0..1 sRGBA colors, premultiplied as\n * {@link mixRgba} mixes two. Weights need not sum to 1; a color weighing\n * nothing contributes nothing. Throws on an empty list.\n */\nexport function mixRgbaWeighted(\n members: readonly { readonly color: Rgba; readonly weight: number }[],\n space: ColorInterpolationSpace = 'oklch',\n hue: HueInterpolation = 'shorter',\n): [number, number, number, number] {\n if (members.length === 0) throw new Error('mixRgbaWeighted: no colors');\n let mixed: [number, number, number, number] = [...members[0]!.color];\n let total = members[0]!.weight;\n for (const { color, weight } of members.slice(1)) {\n total += weight;\n if (total > 0) mixed = mixRgba(color, mixed, weight / total, space, hue);\n }\n return mixed;\n}\n","import { parseColor } from './color';\nimport { oklabToSrgbU8, srgbToLinear, srgbU8ToOklab } from './colorSpaces';\nimport { byteHex, parseHexBytes } from './hex';\n\n/**\n * A line color that reads against `background` — a grid, a rule, a guide\n * drawn over a surface whose color the document chooses, where theme tokens\n * would be keyed to the chrome instead.\n *\n * The line is the background moved `strength` in OKLab lightness (0..1) away\n * from its nearer end: darker over light, lighter over dark, with its hue and\n * chroma kept. Returns `#rrggbb`; the background's alpha is ignored. A color\n * that is not hex comes back as black at `strength` alpha.\n */\nexport function contrastLineColor(background: string, strength: number): string {\n const rgb = parseHexBytes(background.trim());\n if (!rgb) return `rgba(0, 0, 0, ${strength})`;\n const [L, A, B] = srgbU8ToOklab(rgb[0], rgb[1], rgb[2]);\n const next = L > 0.5 ? Math.max(0, L - strength) : Math.min(1, L + strength);\n const [r, g, b] = oklabToSrgbU8(next, A, B);\n return `#${byteHex(r)}${byteHex(g)}${byteHex(b)}`;\n}\n\n/** WCAG 2.x relative luminance of an sRGB color, channels 0..1: 0 for black, 1 for white. */\nexport function relativeLuminance(r: number, g: number, b: number): number {\n return 0.2126 * srgbToLinear(r) + 0.7152 * srgbToLinear(g) + 0.0722 * srgbToLinear(b);\n}\n\n/** The WCAG 2.x contrast ratio of two {@link relativeLuminance}s, in either order: 1 up to 21. */\nexport function luminanceContrast(a: number, b: number): number {\n return (Math.max(a, b) + 0.05) / (Math.min(a, b) + 0.05);\n}\n\n/**\n * The WCAG 2.x contrast ratio of `foreground` text on `background`: 1 for two\n * equal colors up to 21 for black on white, whichever is the lighter. A\n * translucent foreground is laid over the background first; the background's\n * own alpha is ignored. `null` for a color {@link parseColor} cannot read.\n */\nexport function contrastRatio(foreground: string, background: string): number | null {\n let fg: [number, number, number, number];\n let bg: [number, number, number, number];\n try {\n fg = parseColor(foreground);\n bg = parseColor(background);\n } catch {\n return null;\n }\n const a = fg[3];\n const lf = relativeLuminance(a * fg[0] + (1 - a) * bg[0], a * fg[1] + (1 - a) * bg[1], a * fg[2] + (1 - a) * bg[2]);\n return luminanceContrast(lf, relativeLuminance(bg[0], bg[1], bg[2]));\n}\n\n/** Whether `ratio` passes WCAG AA and AAA: 4.5 and 7, or 3 and 4.5 for large text. */\nexport function wcagLevels(ratio: number, largeText: boolean): { aa: boolean; aaa: boolean } {\n return { aa: ratio >= (largeText ? 3 : 4.5), aaa: ratio >= (largeText ? 4.5 : 7) };\n}\n","/**\n * Gradient helpers shared by renderers, editors and exporters: reading a\n * color out of a stop list, and moving a gradient between its three kinds.\n */\n\nimport { resolveColor, rgbaToHex } from './color';\nimport { lerpColorArray, type ColorSpace } from './colorSpaces';\nimport type { Paint, GradStop, GradientPaint, GradientKind } from './paint';\n\n/** A stop with its color already parsed to 0..1 RGBA. */\nexport interface ResolvedGradientStop {\n offset: number;\n rgba: readonly [number, number, number, number];\n}\n\n/** Narrow a paint to the gradient members of `Paint`. */\nexport function isGradientPaint(fill: Paint | null | undefined): fill is GradientPaint {\n if (fill == null) return false;\n return fill.kind === 'linear-gradient'\n || fill.kind === 'radial-gradient'\n || fill.kind === 'conic-gradient';\n}\n\n/**\n * Sort a stop list by offset and parse each color to 0..1 RGBA, so a caller\n * sampling many positions parses each color once. Colors go through\n * `resolveColor`, so any CSS color the kit understands is a legal stop, not\n * just hex.\n */\nexport function resolveGradientStops(stops: readonly GradStop[]): ResolvedGradientStop[] {\n return [...stops]\n .sort((a, b) => a.offset - b.offset)\n .map((s) => ({ offset: s.offset, rgba: resolveColor(s.color) }));\n}\n\n/**\n * RGBA (0..1) at position `t` along resolved stops: flat extension past\n * either end, interpolation between neighbors in `space`, alpha included.\n * The single definition of what a stop list means; a second implementation\n * is a gradient that paints differently from its own swatch.\n *\n * `space` is a gradient's `interpolate`. Alpha is linear in every space —\n * only the color channels travel through OKLab or OKLCh. Returns transparent\n * black for an empty list; a NaN `t` reads as the first stop.\n */\nexport function sampleResolvedStops(\n stops: readonly ResolvedGradientStop[], t: number, space: ColorSpace = 'rgb',\n): readonly [number, number, number, number] {\n if (stops.length === 0) return TRANSPARENT;\n const first = stops[0];\n const last = stops[stops.length - 1];\n if (!(t > first.offset)) return first.rgba;\n if (t >= last.offset) return last.rgba;\n\n for (let i = 0; i < stops.length - 1; i++) {\n const lo = stops[i];\n const hi = stops[i + 1];\n if (t < lo.offset || t > hi.offset) continue;\n const span = hi.offset - lo.offset;\n // Coincident stops are a hard color break: take the later one.\n if (span <= 0) return hi.rgba;\n const f = (t - lo.offset) / span;\n const [r, g, b, a] = lerpColorArray(lo.rgba, hi.rgba, f, space);\n return [r, g, b, a];\n }\n return last.rgba;\n}\n\nconst TRANSPARENT: readonly [number, number, number, number] = [0, 0, 0, 0];\n\n/**\n * Color at position `t` (0..1) along a stop list, as a hex string — the same\n * sampling the GL ramp texture bakes, so an editor track and the painted\n * gradient cannot disagree.\n *\n * Returns transparent black (`#00000000`) for an empty list.\n */\nexport function sampleGradientStops(\n stops: readonly GradStop[], t: number, space: ColorSpace = 'rgb',\n): string {\n return rgbaToHex(sampleResolvedStops(resolveGradientStops(stops), t, space));\n}\n\n/**\n * Retarget a gradient to a different kind, preserving stops, `units` and\n * `opacity`. Linear carries a segment; radial and conic carry a center.\n * Converting between them keeps the center fixed and reads the radius /\n * angle off the segment.\n *\n * Lossy in both directions: a radial gradient stores no angle, so a round\n * trip through one leaves the segment horizontal; a conic stores no radius,\n * so a round trip through one resets the segment's length. An editor that\n * wants a kind switch to be undoable should keep the original paint rather\n * than converting back.\n */\nexport function withGradientKind(fill: GradientPaint, kind: GradientKind): GradientPaint {\n if (fill.kind === kind) return fill;\n const common = {\n stops: fill.stops, units: fill.units,\n interpolate: fill.interpolate, opacity: fill.opacity,\n };\n const { center, radius, angle } = gradientGeometry(fill);\n\n if (kind === 'linear-gradient') {\n const dx = Math.cos(angle) * radius;\n const dy = Math.sin(angle) * radius;\n return {\n kind: 'linear-gradient',\n from: { x: center.x - dx, y: center.y - dy },\n to: { x: center.x + dx, y: center.y + dy },\n ...common,\n };\n }\n if (kind === 'radial-gradient') {\n return { kind: 'radial-gradient', center, radius, ...common };\n }\n return { kind: 'conic-gradient', center, angle, ...common };\n}\n\n/**\n * Center / radius / angle for any gradient kind. For a linear gradient the\n * center is the segment midpoint, the radius is half its length, and the\n * angle is its direction.\n */\nexport function gradientGeometry(fill: GradientPaint): {\n center: { x: number; y: number };\n radius: number;\n angle: number;\n} {\n if (fill.kind === 'linear-gradient') {\n const dx = fill.to.x - fill.from.x;\n const dy = fill.to.y - fill.from.y;\n return {\n center: { x: (fill.from.x + fill.to.x) / 2, y: (fill.from.y + fill.to.y) / 2 },\n radius: Math.hypot(dx, dy) / 2,\n angle: Math.atan2(dy, dx),\n };\n }\n if (fill.kind === 'radial-gradient') {\n return { center: fill.center, radius: fill.radius, angle: 0 };\n }\n return { center: fill.center, radius: conicArmRadius(fill.units), angle: fill.angle };\n}\n\n/**\n * Conic gradients carry no radius, but converting one to a linear or radial\n * gradient needs a non-zero length to build from. Unit-dependent: `'bounds'`\n * geometry runs `0..1` across the box, so a pixel-flavored default there\n * means fifty times it.\n */\nfunction conicArmRadius(units: GradientPaint['units']): number {\n return units === 'bounds' ? 0.5 : 50;\n}\n\n/**\n * A gradient spanning a box left edge to right edge through its vertical\n * center (linear) or filling it (radial / conic) — a starting geometry when\n * only the shape's bounds are known.\n */\nexport function gradientForBounds(\n kind: GradientKind,\n bounds: { x: number; y: number; width: number; height: number },\n stops: GradStop[],\n units?: GradientPaint['units'],\n): GradientPaint {\n const center = { x: bounds.x + bounds.width / 2, y: bounds.y + bounds.height / 2 };\n if (kind === 'linear-gradient') {\n return {\n kind: 'linear-gradient',\n from: { x: bounds.x, y: center.y },\n to: { x: bounds.x + bounds.width, y: center.y },\n stops,\n units,\n };\n }\n if (kind === 'radial-gradient') {\n return {\n kind: 'radial-gradient',\n center,\n radius: Math.max(bounds.width, bounds.height) / 2,\n stops,\n units,\n };\n }\n return { kind: 'conic-gradient', center, angle: 0, stops, units };\n}\n","/**\n * Interpolating paint: the colors between two fills or two strokes, as a\n * blend of two shapes steps from one to the other. Colors travel through\n * OKLab, so the middle of a red-to-green run is a clear yellow rather than a\n * muddy brown.\n */\nimport { parseColor, rgbaToHex } from './color';\nimport { isSolidPaint } from './commandPaint';\nimport { mixOklab } from './mix';\nimport { isGradientPaint } from './gradient';\nimport { lerp } from './lerp';\nimport type { Fill, GradStop, GradientPaint, Paint, ScreenLength, Stroke } from './paint';\n\ntype Rgba = [number, number, number, number];\n\n/** A solid color's channels, its own alpha and `opacity` folded together. */\nfunction rgbaOf(color: string, opacity: number | undefined): Rgba {\n const [r, g, b, a] = parseColor(color);\n return [r, g, b, a * (opacity ?? 1)];\n}\n\n/** `t` of the way from `a` to `b`, through OKLab. */\nfunction mixColor(a: Rgba, b: Rgba, t: number): Rgba {\n return mixOklab(a, b, 1 - t);\n}\n\nfunction solidOf(rgba: Rgba): Paint {\n const color = rgbaToHex([rgba[0], rgba[1], rgba[2]]);\n return rgba[3] >= 1 ? { color } : { color, opacity: rgba[3] };\n}\n\n/** A solid paint's color, or `null` for any other kind. */\nfunction solidRgba(paint: Paint): Rgba | null {\n return isSolidPaint(paint) ? rgbaOf(paint.color, paint.opacity) : null;\n}\n\n/**\n * The paint `t` of the way from `a` to `b`.\n *\n * Two solids mix through OKLab; a missing side is the other's color fully\n * transparent, so a paint fades in or out. Two gradients of one kind with as\n * many stops interpolate their geometry and every stop. Anything else — a\n * pattern, two unlike gradients — holds `a` until halfway and `b` after.\n */\nexport function lerpPaint(a: Paint | undefined, b: Paint | undefined, t: number): Paint | undefined {\n if (a === undefined && b === undefined) return undefined;\n if (a === undefined || b === undefined) {\n const only = (a ?? b)!;\n const rgba = solidRgba(only);\n if (rgba === null) return t < 0.5 ? a : b;\n const clear: Rgba = [rgba[0], rgba[1], rgba[2], 0];\n return solidOf(a === undefined ? mixColor(clear, rgba, t) : mixColor(rgba, clear, t));\n }\n const sa = solidRgba(a);\n const sb = solidRgba(b);\n if (sa !== null && sb !== null) return solidOf(mixColor(sa, sb, t));\n if (isGradientPaint(a) && isGradientPaint(b)) {\n const mixed = lerpGradient(a, b, t);\n if (mixed !== null) return mixed;\n }\n return t < 0.5 ? a : b;\n}\n\nconst byOffset = (stops: readonly GradStop[]): GradStop[] => [...stops].sort((p, q) => p.offset - q.offset);\n\n/** Stops paired in offset order, as a ramp reads them, not in the order each list holds them. */\nfunction lerpStops(a: readonly GradStop[], b: readonly GradStop[], t: number): GradStop[] {\n const to = byOffset(b);\n return byOffset(a).map((stop, i) => {\n const other = to[i]!;\n return { offset: lerp(stop.offset, other.offset, t), color: mixStopColor(stop.color, other.color, t) };\n });\n}\n\n/** A stop's color `t` of the way from `a` to `b`, alpha included. Where both\n * are clear the color still travels, since a ramp blends toward it. */\nfunction mixStopColor(a: string, b: string, t: number): string {\n if (a === b) return a;\n const ca = rgbaOf(a, 1), cb = rgbaOf(b, 1);\n const mixed = mixColor(ca, cb, t);\n if (mixed[3] > 0) return rgbaToHex(mixed);\n const [r, g, bl] = mixColor([ca[0], ca[1], ca[2], 1], [cb[0], cb[1], cb[2], 1], t);\n return rgbaToHex([r, g, bl, 0]);\n}\n\nfunction lerpGradient(a: GradientPaint, b: GradientPaint, t: number): Paint | null {\n if (a.kind !== b.kind || a.stops.length !== b.stops.length) return null;\n if ((a.units ?? 'screen') !== (b.units ?? 'screen')) return null;\n const pt = (p: { x: number; y: number }, q: { x: number; y: number }) => ({ x: lerp(p.x, q.x, t), y: lerp(p.y, q.y, t) });\n const stops = lerpStops(a.stops, b.stops, t);\n const opacity = a.opacity === undefined && b.opacity === undefined\n ? undefined\n : lerp(a.opacity ?? 1, b.opacity ?? 1, t);\n const near = t < 0.5 ? a : b;\n const common = {\n stops,\n ...(near.units === undefined ? {} : { units: near.units }),\n ...(near.interpolate === undefined ? {} : { interpolate: near.interpolate }),\n ...(opacity === undefined ? {} : { opacity }),\n };\n if (a.kind === 'linear-gradient' && b.kind === 'linear-gradient') {\n return { kind: 'linear-gradient', from: pt(a.from, b.from), to: pt(a.to, b.to), ...common };\n }\n if (a.kind === 'radial-gradient' && b.kind === 'radial-gradient') {\n return { kind: 'radial-gradient', center: pt(a.center, b.center), radius: lerp(a.radius, b.radius, t), ...common };\n }\n if (a.kind === 'conic-gradient' && b.kind === 'conic-gradient') {\n return { kind: 'conic-gradient', center: pt(a.center, b.center), angle: lerp(a.angle, b.angle, t), ...common };\n }\n return null;\n}\n\n/**\n * The fill `t` of the way from `a` to `b`. A `null` or missing side fades:\n * its paint is the other's color made transparent. Both absent answers\n * whichever side `t` is nearer.\n */\nexport function lerpFill(a: Fill | null | undefined, b: Fill | null | undefined, t: number): Fill | null | undefined {\n if (a == null && b == null) return t < 0.5 ? a : b;\n const paint = lerpPaint(a?.paint, b?.paint, t);\n return paint === undefined ? {} : { paint };\n}\n\nfunction lerpWidth(a: ScreenLength | undefined, b: ScreenLength | undefined, t: number): ScreenLength | undefined {\n if (a === undefined && b === undefined) return undefined;\n if (typeof a === 'object' && typeof b === 'object') return { px: lerp(a.px, b.px, t) };\n if (typeof a !== 'object' && typeof b !== 'object') return lerp(a ?? 1, b ?? 1, t);\n return t < 0.5 ? a : b;\n}\n\n/**\n * The stroke `t` of the way from `a` to `b`: width and paint interpolate, and\n * every other field is the nearer side's. A `null` or missing side is a\n * stroke of no width in the other's color made transparent, so a stroke\n * thins and fades in or out.\n */\nexport function lerpStroke(a: Stroke | null | undefined, b: Stroke | null | undefined, t: number): Stroke | null | undefined {\n if (a == null && b == null) return t < 0.5 ? a : b;\n const near = (t < 0.5 ? a : b) ?? (a ?? b)!;\n const paint = lerpPaint(a?.paint, b?.paint, t);\n const zero = (s: Stroke): ScreenLength => (typeof s.width === 'object' ? { px: 0 } : 0);\n const width = lerpWidth(a == null ? zero(b!) : a.width, b == null ? zero(a!) : b.width, t);\n const { paint: _p, width: _w, vertexColors: _vc, vertexWidths: _vw, dashOffset: _o, ...rest } = near;\n void _p; void _w; void _vc; void _vw; void _o;\n // An offset slides the pattern, so it moves smoothly where the dash itself snaps.\n const from = a?.dashOffset, to = b?.dashOffset;\n const dashOffset = from === undefined && to === undefined ? undefined : lerp(from ?? 0, to ?? 0, t);\n return {\n ...rest,\n ...(paint === undefined ? {} : { paint }),\n ...(width === undefined ? {} : { width }),\n ...(dashOffset === undefined ? {} : { dashOffset }),\n };\n}\n","import { parseColor } from './color';\nimport { oklabToSrgbU8, oklchToOklab } from './colorSpaces';\nimport { byteHex, parseHexBytes } from './hex';\n\n/**\n * A color given directly. `coords` are in the order CSS Color 4 uses for\n * `space` — `srgb` as 0..1 r, g, b; `oklab` as L, a, b; `oklch` as L, C and a\n * hue in degrees; `hsl` as a hue in degrees and 0..100 saturation and lightness. `space` is open: a palette may carry colors in spaces the kit\n * cannot convert, and `colorLiteralToHex` answers `null` for those.\n */\nexport interface ColorLiteral {\n readonly space: string;\n readonly coords: readonly number[];\n /** 0..1. Omitted means opaque. */\n readonly alpha?: number;\n}\n\n/** A color named rather than given: a palette entry, or whatever the resolver's\n * `external` callback answers to. `index` picks from a sequence entry; a\n * single-color entry answers only to 0. */\nexport interface ColorRef {\n readonly ref: string;\n readonly index?: number;\n}\n\n/** What a {@link ColorFn} or {@link ColorSeqFn} is handed. */\nexport interface ColorFnContext {\n /** Resolve any source against the same palette and external lookup. */\n resolve(source: ColorSource): ColorLiteral | null;\n}\n\n/** A color computed at resolve time — typically derived from another entry. */\nexport type ColorFn = (ctx: ColorFnContext) => ColorSource | null | undefined;\n\n/** Anything that resolves to a color: a literal, a named reference, or a function computing one. */\nexport type ColorSource = ColorLiteral | ColorRef | ColorFn;\n\n/** A sequence of colors, read lazily, so it may be endless. A factory rather\n * than an iterable because a generator object can be iterated only once:\n * pass the `function*` itself. */\nexport type ColorSeqFn = (ctx: ColorFnContext) => Iterable<ColorSource>;\n\n/** A named palette slot holding either one color (`color`) or a sequence (`colors`) that refs index into. */\nexport type PaletteEntry =\n | { readonly name: string; readonly color: ColorSource }\n | { readonly name: string; readonly colors: ColorSeqFn };\n\n/** A set of named colors that {@link ColorRef}s resolve against. When two entries share a name, the first wins. */\nexport interface Palette {\n readonly entries: readonly PaletteEntry[];\n}\n\n/** Answers a ref the palette has no entry for. */\nexport type ExternalColors = (ref: ColorRef) => ColorSource | null | undefined;\n\ntype Visit = (s: ColorSource | null | undefined, visiting: ReadonlySet<string>) => ColorLiteral | null;\n\nfunction nth<T>(items: Iterable<T>, n: number): T | undefined {\n if (!Number.isInteger(n) || n < 0) return undefined;\n let i = 0;\n for (const item of items) if (i++ === n) return item;\n return undefined;\n}\n\nconst refKey = (name: string, index: number): string => `${index}:${name}`;\n\nfunction resolver(palette: Palette, external?: ExternalColors) {\n const byName = new Map<string, PaletteEntry>();\n for (const e of palette.entries) if (!byName.has(e.name)) byName.set(e.name, e);\n\n const ctx = (visiting: ReadonlySet<string>): ColorFnContext => ({ resolve: (s) => visit(s, visiting) });\n\n const visit: Visit = (s, visiting) => {\n if (s == null) return null;\n if (typeof s === 'function') return visit(s(ctx(visiting)), visiting);\n if ('space' in s) return s;\n const index = s.index ?? 0;\n const key = refKey(s.ref, index);\n if (visiting.has(key)) return null;\n const next = new Set(visiting).add(key);\n const entry = byName.get(s.ref);\n if (!entry) return visit(external?.(s), next);\n if ('color' in entry) return index === 0 ? visit(entry.color, next) : null;\n return visit(nth(entry.colors(ctx(next)), index), next);\n };\n\n return { byName, ctx, visit };\n}\n\n/**\n * Resolve `source` to a literal. A ref names a palette entry first, then goes\n * to `external`; whatever either answers is resolved in turn. A name nothing\n * answers, an index past a sequence's end, or a chain that comes back to a ref\n * it is already resolving gives `null`.\n */\nexport function resolvePaletteColor(\n palette: Palette,\n source: ColorSource,\n external?: ExternalColors,\n): ColorLiteral | null {\n return resolver(palette, external).visit(source, new Set());\n}\n\n/**\n * Every color under `name`, resolved lazily in order — one for a single-color\n * entry, as many as the sequence yields for a `colors` entry, nothing for a\n * name the palette lacks. Stop early to read an endless sequence.\n */\nexport function* resolvePaletteColors(\n palette: Palette,\n name: string,\n external?: ExternalColors,\n): Generator<ColorLiteral | null> {\n const { byName, ctx, visit } = resolver(palette, external);\n const entry = byName.get(name);\n if (!entry) return;\n if ('color' in entry) {\n yield visit(entry.color, new Set([refKey(name, 0)]));\n return;\n }\n let i = 0;\n for (const item of entry.colors(ctx(new Set()))) {\n yield visit(item, new Set([refKey(name, i++)]));\n }\n}\n\n/** `#rrggbb`, or `#rrggbbaa` below full opacity. `null` for a space the kit\n * cannot convert, or fewer than three coordinates. */\nexport function colorLiteralToHex(color: ColorLiteral): string | null {\n const [x, y, z] = color.coords;\n if (z === undefined) return null;\n let rgb: readonly number[];\n switch (color.space) {\n case 'srgb':\n rgb = [x * 255, y * 255, z * 255];\n break;\n case 'oklab':\n rgb = oklabToSrgbU8(x, y, z);\n break;\n case 'oklch':\n rgb = oklabToSrgbU8(...oklchToOklab(x, y, (z * Math.PI) / 180));\n break;\n default:\n return null;\n }\n const a = color.alpha ?? 1;\n return `#${rgb.map(byteHex).join('')}${a < 1 ? byteHex(a * 255) : ''}`;\n}\n\n/** Spaces CSS spells as a function of their own, with the coordinates it writes as percentages. */\nconst FUNCTIONAL_SPACES: Readonly<Record<string, readonly number[]>> = { hsl: [1, 2], hwb: [1, 2], lab: [], lch: [], oklab: [], oklch: [] };\n/** Spaces CSS reaches only through `color()`. */\nconst PREDEFINED_SPACES = new Set(['srgb', 'srgb-linear', 'display-p3', 'a98-rgb', 'prophoto-rgb', 'rec2020', 'xyz', 'xyz-d50', 'xyz-d65']);\n\n/**\n * Three coordinates in `space` written the way CSS writes that space, with\n * nothing converted: `hsl()`, `hwb()`, `lab()`, `lch()`, `oklab()` and `oklch()`\n * as their own functions, the predefined spaces through `color()`. `hsl` and\n * `hwb` take their second and third coordinates as 0..100. `'none'` is CSS's\n * missing component. `null` for a space CSS has no notation for, or a count\n * other than three.\n */\nexport function cssColorNotation(space: string, coords: readonly (number | 'none')[], alpha = 1): string | null {\n if (coords.length !== 3) return null;\n const slash = alpha < 1 ? ` / ${alpha}` : '';\n const percent = Object.hasOwn(FUNCTIONAL_SPACES, space) ? FUNCTIONAL_SPACES[space] : undefined;\n if (percent) return `${space}(${coords.map((c, i) => (c !== 'none' && percent.includes(i) ? `${c}%` : c)).join(' ')}${slash})`;\n if (PREDEFINED_SPACES.has(space)) return `color(${space} ${coords.join(' ')}${slash})`;\n return null;\n}\n\n/**\n * A literal as a CSS color: hex where `colorLiteralToHex` has one, else\n * {@link cssColorNotation}. `null` for fewer than three coordinates, or a\n * space CSS has no notation for.\n */\nexport function colorLiteralToCss(color: ColorLiteral): string | null {\n if (color.coords.length < 3) return null;\n return colorLiteralToHex(color) ?? cssColorNotation(color.space, color.coords.slice(0, 3), color.alpha);\n}\n\n/** Any color string `parseColor` reads, as an `srgb` literal. Throws, as it does, on one it cannot. */\nexport function cssColorLiteral(css: string): ColorLiteral {\n const [r, g, b, a] = parseColor(css);\n const coords = [r, g, b];\n return a < 1 ? { space: 'srgb', coords, alpha: a } : { space: 'srgb', coords };\n}\n\n/** `#rrggbb` or `#rrggbbaa` as an `srgb` literal; `null` for anything else. */\nexport function hexToColorLiteral(hex: string): ColorLiteral | null {\n const bytes = hex.length === 7 || hex.length === 9 ? parseHexBytes(hex) : null;\n if (!bytes) return null;\n const [r, g, b, a] = bytes.map((v) => v / 255);\n const coords = [r, g, b];\n return a < 1 ? { space: 'srgb', coords, alpha: a } : { space: 'srgb', coords };\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weasel-js/paint",
3
- "version": "1.18.2",
3
+ "version": "1.19.0",
4
4
  "description": "Paint vocabulary for weasel: Paint, Stroke, gradients, dashes. Plain data, no renderer.",
5
5
  "weasel": {
6
6
  "tier": "base"