@weasel-js/paint 1.13.0 → 1.14.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
@@ -38,8 +38,9 @@ declare function composePatternTransform(parts: Partial<PatternTransformParts>):
38
38
  declare function decomposePatternTransform(t: PatternTransform | undefined): PatternTransformParts;
39
39
 
40
40
  /**
41
- * The pattern members of `Paint`: the built-in tiles, each its own kind, and
42
- * `texture` for a tile the consumer rasterized itself.
41
+ * The pattern members of `Paint`: the built-in tiles, each its own kind,
42
+ * `image` for a tile that is a picture, and `texture` for a tile the consumer
43
+ * rasterized itself.
43
44
  */
44
45
 
45
46
  /**
@@ -103,24 +104,48 @@ type TileKind = TilePatternSpec['kind'];
103
104
  /** A paint of one of the built-in tiles. Plain data, so it survives
104
105
  * serialization. */
105
106
  type TilePaint = TilePatternSpec & PatternPlacement;
107
+ /**
108
+ * A tile's extent in paint-space units. Either side omitted takes the
109
+ * source's own pixel size on that axis.
110
+ */
111
+ interface TileExtent {
112
+ width?: number;
113
+ height?: number;
114
+ }
115
+ /**
116
+ * A paint that repeats a picture. `src` is anything an `<img>` loads — a URL,
117
+ * a `blob:` URL, or a `data:` URI — and is the paint's whole record of the
118
+ * image, so a paint holding a `data:` URI persists and exports with no
119
+ * storage beside it. Until the image decodes the fill draws nothing.
120
+ */
121
+ type ImagePatternPaint = {
122
+ kind: 'image';
123
+ src: string;
124
+ } & TileExtent & PatternPlacement;
106
125
  /**
107
126
  * A paint of a tile the consumer built itself via `createTilePattern()`. The
108
127
  * handle is a session-scoped registry key, so a paint carrying one cannot be
109
- * persisted or exported; prefer a tile kind.
128
+ * persisted or exported; prefer a tile kind, or `image` for a picture.
110
129
  */
111
130
  type TexturePaint = {
112
131
  kind: 'texture';
113
132
  texture: TextureHandle;
114
- } & PatternPlacement;
133
+ } & TileExtent & PatternPlacement;
115
134
  /** Every paint that repeats a tile. */
116
- type PatternPaint = TilePaint | TexturePaint;
135
+ type PatternPaint = TilePaint | ImagePatternPaint | TexturePaint;
136
+ /** The pattern kinds a renderer cannot draw as they stand: each is resolved
137
+ * to a `texture` paint first. */
138
+ type ResolvablePatternKind = TileKind | 'image';
117
139
  /** The built-in tile kinds, in the order a picker offers them. */
118
140
  declare const TILE_KINDS: readonly TileKind[];
119
141
  /** Whether `kind` names a built-in tile. */
120
142
  declare function isTileKind(kind: string | undefined): kind is TileKind;
121
143
  /** Whether a paint is one of the built-in tiles. */
122
144
  declare function isTilePaint(paint: Paint): paint is TilePaint;
123
- /** Whether a paint repeats a tile: a built-in one or a consumer's texture. */
145
+ /** Whether a paint repeats a picture. */
146
+ declare function isImagePatternPaint(paint: Paint): paint is ImagePatternPaint;
147
+ /** Whether a paint repeats a tile: a built-in one, a picture, or a
148
+ * consumer's texture. */
124
149
  declare function isPatternPaint(paint: Paint): paint is PatternPaint;
125
150
  /** A pattern paint's placement alone, holding only the fields it sets. */
126
151
  declare function patternPlacementOf(paint: PatternPaint): PatternPlacement;
@@ -283,8 +308,8 @@ declare function widestHalfWidth(width: number, vertexWidths: readonly VertexWid
283
308
  * equivalent to `{ kind: 'solid', color: '#abc' }`. Every other paint names
284
309
  * its kind.
285
310
  *
286
- * A pattern is one of the built-in tile kinds or a `texture`; see
287
- * `PatternPaint`.
311
+ * A pattern is one of the built-in tile kinds, an `image`, or a `texture`;
312
+ * see `PatternPaint`.
288
313
  *
289
314
  * `interpolate` on a gradient names the space its stops blend through, and
290
315
  * defaults to `'rgb'`. `'oklab'` spaces the blend perceptually; `'oklch'`
@@ -377,7 +402,7 @@ type StrokeAlign = 'center' | 'inner' | 'outer';
377
402
  * The kit's built-in marker vocabulary, open on the string the way
378
403
  * `PaintKind` is so a consumer's registered key typechecks.
379
404
  */
380
- type KitMarkerKey = 'arrow' | 'arrow-open' | 'arrow-concave' | 'diamond' | 'diamond-hollow' | 'circle' | 'square' | 'bar';
405
+ type KitMarkerKey = 'arrow' | 'arrow-open' | 'arrow-concave' | 'triangle-hollow' | 'diamond' | 'diamond-hollow' | 'circle' | 'square' | 'bar' | 'dot' | 'crow-one' | 'crow-many' | 'crow-zero-one' | 'crow-one-many' | 'crow-zero-many';
381
406
  /** A marker shape's key: a built-in {@link KitMarkerKey} or a consumer-registered name. */
382
407
  type MarkerKey = KitMarkerKey | (string & {});
383
408
  /**
@@ -453,7 +478,9 @@ interface Stroke {
453
478
  * along the line (SVG's `auto-start-reverse`, as the only behavior). */
454
479
  markerStart?: MarkerRef;
455
480
  /** Marker at every interior authored vertex, on the bisector of the
456
- * incoming and outgoing directions. Never insets the stroke. */
481
+ * incoming and outgoing directions. Never insets the stroke. The head's
482
+ * anchor sits on the vertex, so a terminator such as `diamond` trails
483
+ * back from it; `dot` is the built-in centered on its vertex. */
457
484
  markerMid?: MarkerRef;
458
485
  /** Marker at the last vertex of each open subpath. */
459
486
  markerEnd?: MarkerRef;
@@ -597,8 +624,8 @@ interface Region {
597
624
  /**
598
625
  * The paint a draw command takes: `Paint` and `Stroke` narrowed to what a
599
626
  * renderer can draw as it stands. A node's own paint may name its box
600
- * (`units: 'bounds'`) or a tile by kind; a command has neither a node nor a
601
- * rasterizer, so both are resolved before one is built.
627
+ * (`units: 'bounds'`), a tile by kind, or an image by `src`; a command has no
628
+ * node, rasterizer or decoder, so all of these are resolved before one is built.
602
629
  */
603
630
 
604
631
  /** The spaces a draw command's paint can name. `'bounds'` is not one: it means
@@ -611,12 +638,13 @@ type InCommandUnits<F> = F extends {
611
638
  units?: CommandPaintUnits;
612
639
  } : F;
613
640
  /** A `Paint` placed in a frame a command can name. Its pattern may still
614
- * be a tile kind. */
641
+ * be a tile kind or an image. */
615
642
  type PosedPaint = InCommandUnits<Paint>;
616
643
  /** A `Paint` a renderer can draw as it stands: no paint is in `'bounds'`
617
- * units, and a pattern is a registered `texture` rather than a tile kind. */
644
+ * units, and a pattern is a registered `texture` rather than a tile kind or
645
+ * an image. */
618
646
  type CommandPaint = Exclude<PosedPaint, {
619
- kind: TileKind;
647
+ kind: ResolvablePatternKind;
620
648
  }>;
621
649
  /** The solid member of `Paint`: a color and an opacity. */
622
650
  type SolidPaint = Extract<Paint, {
@@ -771,13 +799,18 @@ declare function parseColor(input: string): [number, number, number, number];
771
799
  declare function resolveColor(input: string): readonly [number, number, number, number];
772
800
  /** Same as `parseColor` but returns integer 0..255 components. */
773
801
  declare function parseColorToRgba255(input: string): [number, number, number, number];
802
+ /** The hex form {@link normalizeHex} writes: `'rgb'` drops alpha, `'rgba'` always writes it (`ff` when none was named). */
803
+ type HexForm = 'rgb' | 'rgba';
774
804
  /**
775
- * Canonicalize a hex color string to lowercase `#rrggbb` or `#rrggbbaa`.
805
+ * Canonicalize a hex color string to lowercase `#rrggbb` or `#rrggbbaa`: the
806
+ * latter when `form` is `'rgba'`, or with no `form`, when the input names an alpha.
776
807
  *
777
808
  * Accepts: `#rgb`, `#rgba`, `#rrggbb`, `#rrggbbaa`, with or without the
778
809
  * leading `#`, any case. Throws on other inputs.
779
810
  */
780
- declare function normalizeHex(input: string): string;
811
+ declare function normalizeHex(input: string, form?: HexForm): string;
812
+ /** {@link normalizeHex}, undefined where it would throw. */
813
+ declare function tryNormalizeHex(input: string, form?: HexForm): string | undefined;
781
814
  /**
782
815
  * Parse a hex color into [r, g, b, a] with 0..1 components. Accepts the same
783
816
  * forms as `normalizeHex`, including a missing leading `#`.
@@ -938,4 +971,4 @@ declare function cssColorLiteral(css: string): ColorLiteral;
938
971
  /** `#rrggbb` or `#rrggbbaa` as an `srgb` literal; `null` for anything else. */
939
972
  declare function hexToColorLiteral(hex: string): ColorLiteral | null;
940
973
 
941
- export { type ColorFn, type ColorFnContext, type ColorInterpolationSpace, type ColorLiteral, type ColorRef, type ColorSeqFn, type ColorSource, type ColorSpace, type CommandFill, type CommandPaint, type CommandPaintUnits, type CommandStroke, type ExternalColors, type Fill, type GradStop, type GradientKind, type GradientPaint, type HalfWidths, type HueInterpolation, INHERIT, type InCommandUnits, type Inherit, type KitMarkerKey, MAX_DASH_RUNS, type MarkerKey, type MarkerRef, type OklchDeg, type Paint, type PaintUnits, type PaintedFill, type PaintedStroke, type Palette, type PaletteEntry, type PatternPaint, type PatternPlacement, type PatternTransform, type PatternTransformParts, type PosedPaint, type Region, type ResolvedGradientStop, STROKE_DASH_RATIOS, type ScreenLength, type SolidPaint, type Stroke, type StrokeAlign, type StrokeDashStyle, type StrokeNib, TILE_KINDS, type TextureHandle, type TexturePaint, type TileKind, type TilePaint, type TilePatternSpec, type VertexWidth, type VertexWidthSides, alignedStrokeRect, colorLiteralToCss, colorLiteralToHex, composePatternTransform, contrastLineColor, contrastRatio, cssColorLiteral, dashForStrokeStyle, dashPattern, decomposePatternTransform, fillHasInk, gradientForBounds, gradientGeometry, hexToColorLiteral, hexToOklchDeg, hexToRgbBytes, hexToRgba, hslToSrgb, interpolateSrgb, isGradientPaint, isPatternPaint, isSolidPaint, isTileKind, isTilePaint, lerpColorArray, lerpFill, lerpOklab, lerpOklch, lerpPaint, lerpStroke, linearSrgbToOklab, linearToSrgb, mixOklab, normalizeHex, oklabToLinearSrgb, oklabToOklch, oklabToSrgbU8, oklchDegToHex, oklchToOklab, paintKey, parseColor, parseColorToRgba255, parseHexBytes, patternPlacementOf, resolveColor, resolveFill, resolveGradientStops, resolvePaletteColor, resolvePaletteColors, resolveScreenLength, resolveStroke, rgbaToHex, sampleGradientStops, sampleResolvedStops, scaleVertexWidth, srgbFloatToOklab, srgbToHsl, srgbToLinear, srgbU8ToOklab, strokeDashStyleOf, strokeHasInk, strokeKey, tileSpecOf, vertexHalfWidths, vertexWidthFromSides, wcagLevels, widestHalfWidth, withGradientKind };
974
+ export { type ColorFn, type ColorFnContext, type ColorInterpolationSpace, type ColorLiteral, type ColorRef, type ColorSeqFn, type ColorSource, type ColorSpace, type CommandFill, type CommandPaint, type CommandPaintUnits, type CommandStroke, type ExternalColors, type Fill, type GradStop, type GradientKind, type GradientPaint, type HalfWidths, type HexForm, type HueInterpolation, INHERIT, type ImagePatternPaint, type InCommandUnits, type Inherit, type KitMarkerKey, MAX_DASH_RUNS, type MarkerKey, type MarkerRef, type OklchDeg, type Paint, type PaintUnits, type PaintedFill, type PaintedStroke, type Palette, type PaletteEntry, type PatternPaint, type PatternPlacement, type PatternTransform, type PatternTransformParts, type PosedPaint, type Region, type ResolvablePatternKind, type ResolvedGradientStop, STROKE_DASH_RATIOS, type ScreenLength, type SolidPaint, type Stroke, type StrokeAlign, type StrokeDashStyle, type StrokeNib, TILE_KINDS, type TextureHandle, type TexturePaint, type TileExtent, type TileKind, type TilePaint, type TilePatternSpec, type VertexWidth, type VertexWidthSides, alignedStrokeRect, colorLiteralToCss, colorLiteralToHex, composePatternTransform, contrastLineColor, contrastRatio, cssColorLiteral, dashForStrokeStyle, dashPattern, decomposePatternTransform, fillHasInk, gradientForBounds, gradientGeometry, hexToColorLiteral, hexToOklchDeg, hexToRgbBytes, hexToRgba, hslToSrgb, interpolateSrgb, isGradientPaint, isImagePatternPaint, isPatternPaint, isSolidPaint, isTileKind, isTilePaint, lerpColorArray, lerpFill, lerpOklab, lerpOklch, lerpPaint, lerpStroke, linearSrgbToOklab, linearToSrgb, mixOklab, normalizeHex, oklabToLinearSrgb, oklabToOklch, oklabToSrgbU8, oklchDegToHex, oklchToOklab, paintKey, parseColor, parseColorToRgba255, parseHexBytes, patternPlacementOf, resolveColor, resolveFill, resolveGradientStops, resolvePaletteColor, resolvePaletteColors, resolveScreenLength, resolveStroke, rgbaToHex, sampleGradientStops, sampleResolvedStops, scaleVertexWidth, srgbFloatToOklab, srgbToHsl, srgbToLinear, srgbU8ToOklab, strokeDashStyleOf, strokeHasInk, strokeKey, tileSpecOf, tryNormalizeHex, vertexHalfWidths, vertexWidthFromSides, wcagLevels, widestHalfWidth, withGradientKind };
package/dist/index.js CHANGED
@@ -70,8 +70,11 @@ function isTileKind(kind) {
70
70
  function isTilePaint(paint) {
71
71
  return isTileKind(paint.kind);
72
72
  }
73
+ function isImagePatternPaint(paint) {
74
+ return paint.kind === "image";
75
+ }
73
76
  function isPatternPaint(paint) {
74
- return paint.kind === "texture" || isTileKind(paint.kind);
77
+ return paint.kind === "texture" || paint.kind === "image" || isTileKind(paint.kind);
75
78
  }
76
79
  function patternPlacementOf(paint) {
77
80
  const { units, origin, transform, opacity } = paint;
@@ -529,14 +532,19 @@ function parseColorToRgba255(input) {
529
532
  Math.round(a * 255)
530
533
  ];
531
534
  }
532
- function normalizeHex(input) {
535
+ function normalizeHex(input, form) {
536
+ const hex = tryNormalizeHex(input, form);
537
+ if (hex === void 0) throw new Error(`normalizeHex: invalid hex "${input}"`);
538
+ return hex;
539
+ }
540
+ function tryNormalizeHex(input, form) {
533
541
  const trimmed = input.trim();
534
542
  const hashed = trimmed.startsWith("#") ? trimmed : `#${trimmed}`;
535
543
  const bytes = parseHexBytes(hashed);
536
- if (!bytes) throw new Error(`normalizeHex: invalid hex "${input}"`);
544
+ if (!bytes) return void 0;
537
545
  const digits = bytes.map((n) => n.toString(16).padStart(2, "0")).join("");
538
- const namesAlpha = hashed.length === 5 || hashed.length === 9;
539
- return `#${namesAlpha ? digits : digits.slice(0, 6)}`;
546
+ const alpha = form ? form === "rgba" : hashed.length === 5 || hashed.length === 9;
547
+ return `#${alpha ? digits : digits.slice(0, 6)}`;
540
548
  }
541
549
  function hexToRgba(input) {
542
550
  return parseHex(normalizeHex(input));
@@ -1130,6 +1138,6 @@ function hexToColorLiteral(hex) {
1130
1138
  return hex.length === 9 ? { space: "srgb", coords, alpha: a } : { space: "srgb", coords };
1131
1139
  }
1132
1140
 
1133
- export { INHERIT, MAX_DASH_RUNS, STROKE_DASH_RATIOS, TILE_KINDS, alignedStrokeRect, colorLiteralToCss, colorLiteralToHex, composePatternTransform, contrastLineColor, contrastRatio, cssColorLiteral, dashForStrokeStyle, dashPattern, decomposePatternTransform, fillHasInk, gradientForBounds, gradientGeometry, hexToColorLiteral, hexToOklchDeg, hexToRgbBytes, hexToRgba, hslToSrgb, interpolateSrgb, isGradientPaint, isPatternPaint, isSolidPaint, isTileKind, isTilePaint, lerpColorArray, lerpFill, lerpOklab, lerpOklch, lerpPaint, lerpStroke, linearSrgbToOklab, linearToSrgb, mixOklab, normalizeHex, oklabToLinearSrgb, oklabToOklch, oklabToSrgbU8, oklchDegToHex, oklchToOklab, paintKey, parseColor, parseColorToRgba255, parseHexBytes, patternPlacementOf, resolveColor, resolveFill, resolveGradientStops, resolvePaletteColor, resolvePaletteColors, resolveScreenLength, resolveStroke, rgbaToHex, sampleGradientStops, sampleResolvedStops, scaleVertexWidth, srgbFloatToOklab, srgbToHsl, srgbToLinear, srgbU8ToOklab, strokeDashStyleOf, strokeHasInk, strokeKey, tileSpecOf, vertexHalfWidths, vertexWidthFromSides, wcagLevels, widestHalfWidth, withGradientKind };
1141
+ export { INHERIT, MAX_DASH_RUNS, STROKE_DASH_RATIOS, TILE_KINDS, alignedStrokeRect, colorLiteralToCss, colorLiteralToHex, composePatternTransform, contrastLineColor, contrastRatio, cssColorLiteral, dashForStrokeStyle, dashPattern, decomposePatternTransform, fillHasInk, gradientForBounds, gradientGeometry, hexToColorLiteral, hexToOklchDeg, hexToRgbBytes, hexToRgba, hslToSrgb, interpolateSrgb, isGradientPaint, isImagePatternPaint, isPatternPaint, isSolidPaint, isTileKind, isTilePaint, lerpColorArray, lerpFill, lerpOklab, lerpOklch, lerpPaint, lerpStroke, linearSrgbToOklab, linearToSrgb, mixOklab, normalizeHex, oklabToLinearSrgb, oklabToOklch, oklabToSrgbU8, oklchDegToHex, oklchToOklab, paintKey, parseColor, parseColorToRgba255, parseHexBytes, patternPlacementOf, resolveColor, resolveFill, resolveGradientStops, resolvePaletteColor, resolvePaletteColors, resolveScreenLength, resolveStroke, rgbaToHex, sampleGradientStops, sampleResolvedStops, scaleVertexWidth, srgbFloatToOklab, srgbToHsl, srgbToLinear, srgbU8ToOklab, strokeDashStyleOf, strokeHasInk, strokeKey, tileSpecOf, tryNormalizeHex, vertexHalfWidths, vertexWidthFromSides, wcagLevels, widestHalfWidth, withGradientKind };
1134
1142
  //# sourceMappingURL=index.js.map
1135
1143
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/commandPaint.ts","../src/resolvePaint.ts","../src/paintKey.ts","../src/patternPaint.ts","../src/patternTransform.ts","../src/vertexWidth.ts","../src/paint.ts","../src/hex.ts","../src/colorSpaces.ts","../src/color.ts","../src/contrast.ts","../src/gradient.ts","../src/lerpPaint.ts","../src/palette.ts"],"names":["L","C","h","s","l","parts","n","clamp01","hex2"],"mappings":";AAgCO,SAAS,aAAa,KAAA,EAAsD;AACjF,EAAA,OAAO,SAAS,IAAA,KAAS,KAAA,CAAM,IAAA,KAAS,MAAA,IAAa,MAAM,IAAA,KAAS,OAAA,CAAA;AACtE;;;AC/BO,IAAM,OAAA,GAAU;AAchB,SAAS,WAAA,CACd,IAAA,EACA,SAAA,GAAgC,IAAA,EACZ;AACpB,EAAA,IAAI,IAAA,KAAS,SAAS,OAAO,SAAA;AAC7B,EAAA,OAAO,IAAA,EAAM,KAAA,IAAS,IAAA,GAAO,IAAA,GAAQ,IAAA;AACvC;AAIO,SAAS,aAAA,CACd,MAAA,EACA,SAAA,GAAkC,IAAA,EACZ;AACtB,EAAA,IAAI,MAAA,KAAW,SAAS,OAAO,SAAA;AAC/B,EAAA,OAAO,MAAA,EAAQ,KAAA,IAAS,IAAA,GAAO,IAAA,GAAQ,MAAA;AACzC;;;ACrBA,SAAS,UAAU,KAAA,EAAwB;AACzC,EAAA,IAAI,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,EAAG,OAAO,CAAA,CAAA,EAAI,KAAA,CAAM,GAAA,CAAI,SAAS,CAAA,CAAE,IAAA,CAAK,GAAG,CAAC,CAAA,CAAA,CAAA;AACnE,EAAA,IAAI,OAAO,UAAU,QAAA,IAAY,KAAA,KAAU,MAAM,OAAO,IAAA,CAAK,SAAA,CAAU,KAAK,CAAA,IAAK,MAAA;AACjF,EAAA,MAAM,MAA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AO;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,GAAA,CAAI,MAAA,KAAW,CAAA,GAAI,EAAE,KAAA,EAAO,MAAA,EAAQ,MAAA,EAAQ,KAAA,EAAO,CAAA,EAAE,GAAI,EAAE,KAAA,EAAO,QAAQ,MAAA,EAAO;AAC1F","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'`) or a tile by kind; a command has neither a node nor a\n * rasterizer, so both are resolved before one is built.\n */\n\nimport type { Fill, Paint, PaintUnits, Stroke } from './paint';\nimport type { TileKind } 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. */\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. */\nexport type CommandPaint = Exclude<PosedPaint, { kind: TileKind }>;\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","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: a stroke whose\n * base width is 0 can still draw through its per-vertex widths. */\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 { 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:${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/** 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. */\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","/**\n * The pattern members of `Paint`: the built-in tiles, each its own kind, and\n * `texture` for a tile the consumer 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 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.\n */\nexport type TexturePaint = { kind: 'texture'; texture: TextureHandle } & PatternPlacement;\n\n/** Every paint that repeats a tile. */\nexport type PatternPaint = TilePaint | TexturePaint;\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 tile: a built-in one or a consumer's texture. */\nexport function isPatternPaint(paint: Paint): paint is PatternPaint {\n return paint.kind === 'texture' || 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';\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 or a `texture`; see\n * `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'\n | 'diamond' | 'diamond-hollow'\n | 'circle' | 'square' | 'bar';\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 /** 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. */\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. 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 * 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 return {\n x: rect.x - d,\n y: rect.y - d,\n width: rect.width + 2 * d,\n height: rect.height + 2 * d,\n };\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 * 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","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/** 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","// sRGB ↔ OKLab conversion. Reference: https://bottosson.github.io/posts/oklab/\n\nimport { hexToRgbBytes } from './hex';\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/**\n * `color-mix(in oklab, 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\n * lends the result its opacity and none of its color.\n */\nexport function mixOklab(\n a: readonly [number, number, number, number],\n b: readonly [number, number, number, number],\n p: number,\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 const la = srgbFloatToOklab(a[0], a[1], a[2]);\n const lb = srgbFloatToOklab(b[0], b[1], b[2]);\n const mix = (i: number) => (la[i] * a[3] * p + lb[i] * b[3] * (1 - p)) / alpha;\n const [r, g, bl] = oklabToSrgbU8(mix(0), mix(1), mix(2));\n return [r / 255, g / 255, bl / 255, alpha];\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 TWO_PI = Math.PI * 2;\n // Shortest-arc delta in [-π, π].\n let dh = h2 - h1;\n while (dh > Math.PI) dh -= TWO_PI;\n while (dh < -Math.PI) dh += TWO_PI;\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\nconst hex2 = (v: number): string => Math.max(0, Math.min(255, Math.round(v))).toString(16).padStart(2, '0');\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 `#${hex2(r)}${hex2(g)}${hex2(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/** 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/** An endpoint with less chroma (OKLCH) or saturation (HSL) than this has no\n * hue of its own. */\nconst ACHROMATIC_EPS = 1e-4;\n\nfunction lerpHueDeg(h1: number, h2: number, t: number, method: HueInterpolation): number {\n let dh = (((h2 - h1) % 360) + 360) % 360;\n if (method === 'shorter') {\n if (dh > 180) dh -= 360;\n } else if (dh > 0 && dh < 180) {\n dh -= 360;\n }\n return (((h1 + dh * t) % 360) + 360) % 360;\n}\n\ntype Polar = readonly [radius: number, hueDeg: number, axis: number];\n\nfunction lerpPolar(a: Polar, b: Polar, t: number, method: HueInterpolation): [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, t, 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 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);\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);\n return hslToSrgb(h, s, l);\n }\n }\n}\n","import { hslToSrgb, linearToSrgb, oklabToLinearSrgb, oklchToOklab } from './colorSpaces';\nimport { 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 const named = NAMED_COLORS[lower];\n if (named !== undefined) return named;\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\nconst RESOLVE_COLOR_CACHE_CAP = 1024;\nconst resolveColorCache = new Map<string, readonly [number, number, number, number]>();\n\n/** Cached `parseColor`. Use this from renderer hot paths (per-frame draw\n * callbacks, gradient ramp builds). The cache is capped at ~1024 entries and\n * cleared wholesale on overflow. */\nexport function resolveColor(input: string): readonly [number, number, number, number] {\n const hit = resolveColorCache.get(input);\n if (hit) return hit;\n if (resolveColorCache.size >= RESOLVE_COLOR_CACHE_CAP) {\n resolveColorCache.clear();\n }\n const parsed = parseColor(input);\n const frozen = parsed as readonly [number, number, number, number];\n resolveColorCache.set(input, frozen);\n return frozen;\n}\n\n/** @internal Test-only: drops the resolveColor memoization cache so tests\n * can assert behavior in isolation. Never call from production code. */\nexport function __resetResolveColorCache(): void {\n resolveColorCache.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/**\n * Canonicalize a hex color string to lowercase `#rrggbb` or `#rrggbbaa`.\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): string {\n const trimmed = input.trim();\n const hashed = trimmed.startsWith('#') ? trimmed : `#${trimmed}`;\n const bytes = parseHexBytes(hashed);\n if (!bytes) throw new Error(`normalizeHex: invalid hex \"${input}\"`);\n const digits = bytes.map((n) => n.toString(16).padStart(2, '0')).join('');\n const namesAlpha = hashed.length === 5 || hashed.length === 9;\n return `#${namesAlpha ? 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) => Math.max(0, Math.min(255, Math.round(n * 255))).toString(16).padStart(2, '0');\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\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 if (tok.endsWith('%')) {\n const n = Number(tok.slice(0, -1));\n if (!Number.isFinite(n)) return null;\n return clamp01(n / 100);\n }\n const n = Number(tok);\n if (!Number.isFinite(n)) return null;\n return clamp01(n / max);\n}\n\n/** Alpha may be a number 0..1 or a percent. */\nfunction parseAlpha(tok: string | null): number {\n if (tok === null) return 1;\n if (tok.endsWith('%')) {\n const n = Number(tok.slice(0, -1));\n return Number.isFinite(n) ? clamp01(n / 100) : 1;\n }\n const n = Number(tok);\n return Number.isFinite(n) ? clamp01(n) : 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 if (r === null || g === null || b === null) return null;\n return [r, g, b, parseAlpha(channels.alpha)];\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 if (h === null || sat === null || lit === null) return null;\n const [r, g, b] = hslToSrgb(h, sat, lit);\n return [r, g, b, parseAlpha(channels.alpha)];\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 if (rgb.some((c) => c === 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), parseAlpha(channels.alpha)];\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 = Number(channels.rgb[1]);\n if (L === null || !Number.isFinite(second)) return null;\n let A = second;\n let B = Number(channels.rgb[2]);\n if (lch !== null) {\n const h = parseHue(channels.rgb[2]);\n if (h === null) return null;\n [, A, B] = oklchToOklab(L, second, h * (Math.PI / 180));\n } else if (!Number.isFinite(B)) return null;\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, parseAlpha(channels.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 let n: number;\n if (tok.endsWith('deg')) n = Number(tok.slice(0, -3));\n else if (tok.endsWith('grad')) n = Number(tok.slice(0, -4)) * 0.9; // 400grad = 360deg\n else if (tok.endsWith('rad')) n = Number(tok.slice(0, -3)) * (180 / Math.PI);\n else if (tok.endsWith('turn')) n = Number(tok.slice(0, -4)) * 360;\n else n = Number(tok);\n if (!Number.isFinite(n)) return null;\n return ((n % 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 if (tok.endsWith('%')) {\n const n = Number(tok.slice(0, -1));\n return Number.isFinite(n) ? clamp01(n / 100) : null;\n }\n const n = Number(tok);\n return Number.isFinite(n) ? clamp01(n) : null;\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 { parseColor } from './color';\nimport { oklabToSrgbU8, srgbToLinear, srgbU8ToOklab } from './colorSpaces';\nimport { parseHexBytes } from './hex';\n\nconst hex2 = (v: number): string => Math.max(0, Math.min(255, Math.round(v))).toString(16).padStart(2, '0');\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 `#${hex2(r)}${hex2(g)}${hex2(b)}`;\n}\n\nconst luminance = (r: number, g: number, b: number): number =>\n 0.2126 * srgbToLinear(r) + 0.7152 * srgbToLinear(g) + 0.0722 * srgbToLinear(b);\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 = luminance(a * fg[0] + (1 - a) * bg[0], a * fg[1] + (1 - a) * bg[1], a * fg[2] + (1 - a) * bg[2]);\n const lb = luminance(bg[0], bg[1], bg[2]);\n return (Math.max(lf, lb) + 0.05) / (Math.min(lf, lb) + 0.05);\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.\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 for an empty list.\n */\nexport function sampleGradientStops(\n stops: readonly GradStop[], t: number, space: ColorSpace = 'rgb',\n): string {\n if (stops.length === 0) return 'rgba(0,0,0,0)';\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 { mixOklab } from './colorSpaces';\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 if (paint.kind !== undefined && paint.kind !== 'solid') return null;\n return rgbaOf((paint as { color: string }).color, paint.opacity);\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\nfunction lerpStops(a: readonly GradStop[], b: readonly GradStop[], t: number): GradStop[] {\n return a.map((stop, i) => {\n const other = b[i]!;\n return {\n offset: lerp(stop.offset, other.offset, t),\n color: (solidOf(mixColor(rgbaOf(stop.color, 1), rgbaOf(other.color, 1), t)) as { color: string; opacity?: number })\n .color,\n };\n });\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, ...rest } = near;\n void _p; void _w; void _vc; void _vw;\n return {\n ...rest,\n ...(paint === undefined ? {} : { paint }),\n ...(width === undefined ? {} : { width }),\n };\n}\n","import { parseColor } from './color';\nimport { oklabToSrgbU8, oklchToOklab } from './colorSpaces';\nimport { 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. `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\nconst hex2 = (v: number): string => Math.max(0, Math.min(255, Math.round(v))).toString(16).padStart(2, '0');\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(hex2).join('')}${a < 1 ? hex2(a * 255) : ''}`;\n}\n\n/**\n * A literal as a CSS color: hex where `colorLiteralToHex` has one, else\n * `color(<space> …)`, which is the form CSS gives every predefined space.\n * `null` for fewer than three coordinates.\n */\nexport function colorLiteralToCss(color: ColorLiteral): string | null {\n if (color.coords.length < 3) return null;\n const hex = colorLiteralToHex(color);\n if (hex) return hex;\n const a = color.alpha ?? 1;\n return `color(${color.space} ${color.coords.join(' ')}${a < 1 ? ` / ${a}` : ''})`;\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 hex.length === 9 ? { space: 'srgb', coords, alpha: a } : { space: 'srgb', coords };\n}\n"]}
1
+ {"version":3,"sources":["../src/commandPaint.ts","../src/resolvePaint.ts","../src/paintKey.ts","../src/patternPaint.ts","../src/patternTransform.ts","../src/vertexWidth.ts","../src/paint.ts","../src/hex.ts","../src/colorSpaces.ts","../src/color.ts","../src/contrast.ts","../src/gradient.ts","../src/lerpPaint.ts","../src/palette.ts"],"names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A,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,GAAA,CAAI,MAAA,KAAW,CAAA,GAAI,EAAE,KAAA,EAAO,MAAA,EAAQ,MAAA,EAAQ,KAAA,EAAO,CAAA,EAAE,GAAI,EAAE,KAAA,EAAO,QAAQ,MAAA,EAAO;AAC1F","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","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: a stroke whose\n * base width is 0 can still draw through its per-vertex widths. */\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 { 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:${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/** 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. */\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","/**\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';\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 /** 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. 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 * 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 return {\n x: rect.x - d,\n y: rect.y - d,\n width: rect.width + 2 * d,\n height: rect.height + 2 * d,\n };\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 * 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","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/** 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","// sRGB ↔ OKLab conversion. Reference: https://bottosson.github.io/posts/oklab/\n\nimport { hexToRgbBytes } from './hex';\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/**\n * `color-mix(in oklab, 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\n * lends the result its opacity and none of its color.\n */\nexport function mixOklab(\n a: readonly [number, number, number, number],\n b: readonly [number, number, number, number],\n p: number,\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 const la = srgbFloatToOklab(a[0], a[1], a[2]);\n const lb = srgbFloatToOklab(b[0], b[1], b[2]);\n const mix = (i: number) => (la[i] * a[3] * p + lb[i] * b[3] * (1 - p)) / alpha;\n const [r, g, bl] = oklabToSrgbU8(mix(0), mix(1), mix(2));\n return [r / 255, g / 255, bl / 255, alpha];\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 TWO_PI = Math.PI * 2;\n // Shortest-arc delta in [-π, π].\n let dh = h2 - h1;\n while (dh > Math.PI) dh -= TWO_PI;\n while (dh < -Math.PI) dh += TWO_PI;\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\nconst hex2 = (v: number): string => Math.max(0, Math.min(255, Math.round(v))).toString(16).padStart(2, '0');\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 `#${hex2(r)}${hex2(g)}${hex2(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/** 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/** An endpoint with less chroma (OKLCH) or saturation (HSL) than this has no\n * hue of its own. */\nconst ACHROMATIC_EPS = 1e-4;\n\nfunction lerpHueDeg(h1: number, h2: number, t: number, method: HueInterpolation): number {\n let dh = (((h2 - h1) % 360) + 360) % 360;\n if (method === 'shorter') {\n if (dh > 180) dh -= 360;\n } else if (dh > 0 && dh < 180) {\n dh -= 360;\n }\n return (((h1 + dh * t) % 360) + 360) % 360;\n}\n\ntype Polar = readonly [radius: number, hueDeg: number, axis: number];\n\nfunction lerpPolar(a: Polar, b: Polar, t: number, method: HueInterpolation): [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, t, 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 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);\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);\n return hslToSrgb(h, s, l);\n }\n }\n}\n","import { hslToSrgb, linearToSrgb, oklabToLinearSrgb, oklchToOklab } from './colorSpaces';\nimport { 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 const named = NAMED_COLORS[lower];\n if (named !== undefined) return named;\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\nconst RESOLVE_COLOR_CACHE_CAP = 1024;\nconst resolveColorCache = new Map<string, readonly [number, number, number, number]>();\n\n/** Cached `parseColor`. Use this from renderer hot paths (per-frame draw\n * callbacks, gradient ramp builds). The cache is capped at ~1024 entries and\n * cleared wholesale on overflow. */\nexport function resolveColor(input: string): readonly [number, number, number, number] {\n const hit = resolveColorCache.get(input);\n if (hit) return hit;\n if (resolveColorCache.size >= RESOLVE_COLOR_CACHE_CAP) {\n resolveColorCache.clear();\n }\n const parsed = parseColor(input);\n const frozen = parsed as readonly [number, number, number, number];\n resolveColorCache.set(input, frozen);\n return frozen;\n}\n\n/** @internal Test-only: drops the resolveColor memoization cache so tests\n * can assert behavior in isolation. Never call from production code. */\nexport function __resetResolveColorCache(): void {\n resolveColorCache.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((n) => n.toString(16).padStart(2, '0')).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) => Math.max(0, Math.min(255, Math.round(n * 255))).toString(16).padStart(2, '0');\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\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 if (tok.endsWith('%')) {\n const n = Number(tok.slice(0, -1));\n if (!Number.isFinite(n)) return null;\n return clamp01(n / 100);\n }\n const n = Number(tok);\n if (!Number.isFinite(n)) return null;\n return clamp01(n / max);\n}\n\n/** Alpha may be a number 0..1 or a percent. */\nfunction parseAlpha(tok: string | null): number {\n if (tok === null) return 1;\n if (tok.endsWith('%')) {\n const n = Number(tok.slice(0, -1));\n return Number.isFinite(n) ? clamp01(n / 100) : 1;\n }\n const n = Number(tok);\n return Number.isFinite(n) ? clamp01(n) : 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 if (r === null || g === null || b === null) return null;\n return [r, g, b, parseAlpha(channels.alpha)];\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 if (h === null || sat === null || lit === null) return null;\n const [r, g, b] = hslToSrgb(h, sat, lit);\n return [r, g, b, parseAlpha(channels.alpha)];\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 if (rgb.some((c) => c === 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), parseAlpha(channels.alpha)];\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 = Number(channels.rgb[1]);\n if (L === null || !Number.isFinite(second)) return null;\n let A = second;\n let B = Number(channels.rgb[2]);\n if (lch !== null) {\n const h = parseHue(channels.rgb[2]);\n if (h === null) return null;\n [, A, B] = oklchToOklab(L, second, h * (Math.PI / 180));\n } else if (!Number.isFinite(B)) return null;\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, parseAlpha(channels.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 let n: number;\n if (tok.endsWith('deg')) n = Number(tok.slice(0, -3));\n else if (tok.endsWith('grad')) n = Number(tok.slice(0, -4)) * 0.9; // 400grad = 360deg\n else if (tok.endsWith('rad')) n = Number(tok.slice(0, -3)) * (180 / Math.PI);\n else if (tok.endsWith('turn')) n = Number(tok.slice(0, -4)) * 360;\n else n = Number(tok);\n if (!Number.isFinite(n)) return null;\n return ((n % 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 if (tok.endsWith('%')) {\n const n = Number(tok.slice(0, -1));\n return Number.isFinite(n) ? clamp01(n / 100) : null;\n }\n const n = Number(tok);\n return Number.isFinite(n) ? clamp01(n) : null;\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 { parseColor } from './color';\nimport { oklabToSrgbU8, srgbToLinear, srgbU8ToOklab } from './colorSpaces';\nimport { parseHexBytes } from './hex';\n\nconst hex2 = (v: number): string => Math.max(0, Math.min(255, Math.round(v))).toString(16).padStart(2, '0');\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 `#${hex2(r)}${hex2(g)}${hex2(b)}`;\n}\n\nconst luminance = (r: number, g: number, b: number): number =>\n 0.2126 * srgbToLinear(r) + 0.7152 * srgbToLinear(g) + 0.0722 * srgbToLinear(b);\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 = luminance(a * fg[0] + (1 - a) * bg[0], a * fg[1] + (1 - a) * bg[1], a * fg[2] + (1 - a) * bg[2]);\n const lb = luminance(bg[0], bg[1], bg[2]);\n return (Math.max(lf, lb) + 0.05) / (Math.min(lf, lb) + 0.05);\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.\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 for an empty list.\n */\nexport function sampleGradientStops(\n stops: readonly GradStop[], t: number, space: ColorSpace = 'rgb',\n): string {\n if (stops.length === 0) return 'rgba(0,0,0,0)';\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 { mixOklab } from './colorSpaces';\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 if (paint.kind !== undefined && paint.kind !== 'solid') return null;\n return rgbaOf((paint as { color: string }).color, paint.opacity);\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\nfunction lerpStops(a: readonly GradStop[], b: readonly GradStop[], t: number): GradStop[] {\n return a.map((stop, i) => {\n const other = b[i]!;\n return {\n offset: lerp(stop.offset, other.offset, t),\n color: (solidOf(mixColor(rgbaOf(stop.color, 1), rgbaOf(other.color, 1), t)) as { color: string; opacity?: number })\n .color,\n };\n });\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, ...rest } = near;\n void _p; void _w; void _vc; void _vw;\n return {\n ...rest,\n ...(paint === undefined ? {} : { paint }),\n ...(width === undefined ? {} : { width }),\n };\n}\n","import { parseColor } from './color';\nimport { oklabToSrgbU8, oklchToOklab } from './colorSpaces';\nimport { 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. `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\nconst hex2 = (v: number): string => Math.max(0, Math.min(255, Math.round(v))).toString(16).padStart(2, '0');\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(hex2).join('')}${a < 1 ? hex2(a * 255) : ''}`;\n}\n\n/**\n * A literal as a CSS color: hex where `colorLiteralToHex` has one, else\n * `color(<space> …)`, which is the form CSS gives every predefined space.\n * `null` for fewer than three coordinates.\n */\nexport function colorLiteralToCss(color: ColorLiteral): string | null {\n if (color.coords.length < 3) return null;\n const hex = colorLiteralToHex(color);\n if (hex) return hex;\n const a = color.alpha ?? 1;\n return `color(${color.space} ${color.coords.join(' ')}${a < 1 ? ` / ${a}` : ''})`;\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 hex.length === 9 ? { 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.13.0",
3
+ "version": "1.14.0",
4
4
  "description": "Paint vocabulary for weasel: Paint, Stroke, gradients, dashes. Plain data, no renderer.",
5
5
  "license": "MIT",
6
6
  "type": "module",