@tempots/std 0.27.0 → 0.28.1

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.
Files changed (54) hide show
  1. package/color-D7FAmkht.cjs +1 -0
  2. package/color-SZxckS9U.js +522 -0
  3. package/color-adjust.cjs +1 -0
  4. package/color-adjust.d.ts +148 -0
  5. package/color-adjust.js +47 -0
  6. package/color-channel.cjs +1 -0
  7. package/color-channel.d.ts +118 -0
  8. package/color-channel.js +75 -0
  9. package/color-contrast.cjs +1 -0
  10. package/color-contrast.d.ts +96 -0
  11. package/color-contrast.js +22 -0
  12. package/color-distance.cjs +1 -0
  13. package/color-distance.d.ts +41 -0
  14. package/color-distance.js +25 -0
  15. package/color-gamut.cjs +1 -0
  16. package/color-gamut.d.ts +59 -0
  17. package/color-gamut.js +72 -0
  18. package/color-harmony.cjs +1 -0
  19. package/color-harmony.d.ts +81 -0
  20. package/color-harmony.js +35 -0
  21. package/color-hsl.cjs +1 -0
  22. package/color-hsl.d.ts +81 -0
  23. package/color-hsl.js +10 -0
  24. package/color-hsv.cjs +1 -0
  25. package/color-hsv.d.ts +116 -0
  26. package/color-hsv.js +12 -0
  27. package/color-hwb.cjs +1 -0
  28. package/color-hwb.d.ts +88 -0
  29. package/color-hwb.js +10 -0
  30. package/color-lab.cjs +1 -0
  31. package/color-lab.d.ts +161 -0
  32. package/color-lab.js +15 -0
  33. package/color-mix.cjs +1 -0
  34. package/color-mix.d.ts +50 -0
  35. package/color-mix.js +101 -0
  36. package/color-named.cjs +1 -0
  37. package/color-named.d.ts +8 -0
  38. package/color-named.js +153 -0
  39. package/color-oklab.cjs +1 -0
  40. package/color-oklab.d.ts +141 -0
  41. package/color-oklab.js +15 -0
  42. package/color-rgb.cjs +1 -0
  43. package/color-rgb.d.ts +119 -0
  44. package/color-rgb.js +14 -0
  45. package/color-utils.cjs +1 -0
  46. package/color-utils.d.ts +57 -0
  47. package/color-utils.js +54 -0
  48. package/color.cjs +1 -0
  49. package/color.d.ts +466 -0
  50. package/color.js +33 -0
  51. package/index.cjs +1 -1
  52. package/index.d.ts +16 -0
  53. package/index.js +383 -267
  54. package/package.json +113 -1
package/color-lab.js ADDED
@@ -0,0 +1,15 @@
1
+ import "./error.js";
2
+ import "./number.js";
3
+ import { f as o, g as c, J as L, K as g, M as h, N as T, _ as e, $ as p, a9 as t, aa as i } from "./color-SZxckS9U.js";
4
+ export {
5
+ o as canParseLab,
6
+ c as canParseLch,
7
+ L as labaToLabString,
8
+ g as labaToRgb8a,
9
+ h as lchaToLchString,
10
+ T as lchaToRgb8a,
11
+ e as parseLab,
12
+ p as parseLch,
13
+ t as rgb8aToLaba,
14
+ i as rgb8aToLcha
15
+ };
package/color-mix.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./color-D7FAmkht.cjs"),p=require("./number.cjs"),r=p.interpolate,b=p.interpolateAngle,i=(e,t,l,h)=>{const n=s.convertColor(e,h),c=s.convertColor(t,h);switch(h){case"rgb":{const a=n,o=c;return s.rgba(r(a.r,o.r,l),r(a.g,o.g,l),r(a.b,o.b,l),r(a.alpha,o.alpha,l))}case"rgb8":{const a=n,o=c;return s.rgb8a(Math.round(r(a.r,o.r,l)),Math.round(r(a.g,o.g,l)),Math.round(r(a.b,o.b,l)),r(a.alpha,o.alpha,l))}case"hsl":{const a=n,o=c;return s.hsla(b(a.h,o.h,l),r(a.s,o.s,l),r(a.l,o.l,l),r(a.alpha,o.alpha,l))}case"hsv":{const a=n,o=c;return s.hsva(b(a.h,o.h,l),r(a.s,o.s,l),r(a.v,o.v,l),r(a.alpha,o.alpha,l))}case"hwb":{const a=n,o=c;return s.hwba(b(a.h,o.h,l),r(a.w,o.w,l),r(a.b,o.b,l),r(a.alpha,o.alpha,l))}case"lab":{const a=n,o=c;return s.laba(r(a.l,o.l,l),r(a.a,o.a,l),r(a.b,o.b,l),r(a.alpha,o.alpha,l))}case"lch":{const a=n,o=c;return s.lcha(r(a.l,o.l,l),r(a.c,o.c,l),b(a.h,o.h,l),r(a.alpha,o.alpha,l))}case"oklab":{const a=n,o=c;return s.oklaba(r(a.l,o.l,l),r(a.a,o.a,l),r(a.b,o.b,l),r(a.alpha,o.alpha,l))}case"oklch":{const a=n,o=c;return s.oklcha(r(a.l,o.l,l),r(a.c,o.c,l),b(a.h,o.h,l),r(a.alpha,o.alpha,l))}}},u=(e,t,l=.5,h="oklch")=>i(e,t,l,h),g=(e,t,l,h="oklch")=>{if(l<2)return[u(e,t,.5,h)];const n=[];for(let c=0;c<l;c++){const a=c/(l-1);n.push(u(e,t,a,h))}return n};exports.interpolateColors=g;exports.mixColors=u;
package/color-mix.d.ts ADDED
@@ -0,0 +1,50 @@
1
+ import { Color, ColorSpace } from './color';
2
+ /**
3
+ * Blends two colors together in the specified color space.
4
+ *
5
+ * Converts both colors to the target space, linearly
6
+ * interpolates each channel (using shortest-path hue
7
+ * interpolation for polar spaces), and returns the result
8
+ * in the target space.
9
+ *
10
+ * @param a - The first color.
11
+ * @param b - The second color.
12
+ * @param t - The blend factor (0 = fully `a`, 1 = fully `b`).
13
+ * Defaults to 0.5.
14
+ * @param space - The color space to blend in.
15
+ * Defaults to `'oklch'`.
16
+ * @returns The blended color in the specified space.
17
+ * @public
18
+ * @example
19
+ * ```ts
20
+ * import { rgb8a } from './color'
21
+ * mixColors(rgb8a(255, 0, 0), rgb8a(0, 0, 255))
22
+ * // blended in oklch at t=0.5
23
+ * mixColors(rgb8a(255, 0, 0), rgb8a(0, 0, 255), 0.25, 'lab')
24
+ * // 25% blend in LAB space
25
+ * ```
26
+ */
27
+ export declare const mixColors: (a: Color, b: Color, t?: number, space?: ColorSpace) => Color;
28
+ /**
29
+ * Generates an array of evenly spaced colors between two
30
+ * endpoints (inclusive).
31
+ *
32
+ * If `steps` is less than 2, returns a single-element array
33
+ * containing the midpoint blend of `a` and `b`.
34
+ *
35
+ * @param a - The start color.
36
+ * @param b - The end color.
37
+ * @param steps - The number of colors to generate (inclusive
38
+ * of both endpoints).
39
+ * @param space - The color space to interpolate in.
40
+ * Defaults to `'oklch'`.
41
+ * @returns An array of interpolated colors.
42
+ * @public
43
+ * @example
44
+ * ```ts
45
+ * import { rgb8a } from './color'
46
+ * interpolateColors(rgb8a(255, 0, 0), rgb8a(0, 0, 255), 5)
47
+ * // [red, ..., blue] — 5 evenly spaced colors in oklch
48
+ * ```
49
+ */
50
+ export declare const interpolateColors: (a: Color, b: Color, steps: number, space?: ColorSpace) => Color[];
package/color-mix.js ADDED
@@ -0,0 +1,101 @@
1
+ import { m as b, R as u, O as x, L as i, I as g, w as y, s as m, o as k, a4 as w, af as f } from "./color-SZxckS9U.js";
2
+ import { interpolate as v, interpolateAngle as d } from "./number.js";
3
+ const l = v, p = d, C = (h, e, s, n) => {
4
+ const c = b(h, n), r = b(e, n);
5
+ switch (n) {
6
+ case "rgb": {
7
+ const a = c, o = r;
8
+ return f(
9
+ l(a.r, o.r, s),
10
+ l(a.g, o.g, s),
11
+ l(a.b, o.b, s),
12
+ l(a.alpha, o.alpha, s)
13
+ );
14
+ }
15
+ case "rgb8": {
16
+ const a = c, o = r;
17
+ return w(
18
+ Math.round(l(a.r, o.r, s)),
19
+ Math.round(l(a.g, o.g, s)),
20
+ Math.round(l(a.b, o.b, s)),
21
+ l(a.alpha, o.alpha, s)
22
+ );
23
+ }
24
+ case "hsl": {
25
+ const a = c, o = r;
26
+ return k(
27
+ p(a.h, o.h, s),
28
+ l(a.s, o.s, s),
29
+ l(a.l, o.l, s),
30
+ l(a.alpha, o.alpha, s)
31
+ );
32
+ }
33
+ case "hsv": {
34
+ const a = c, o = r;
35
+ return m(
36
+ p(a.h, o.h, s),
37
+ l(a.s, o.s, s),
38
+ l(a.v, o.v, s),
39
+ l(a.alpha, o.alpha, s)
40
+ );
41
+ }
42
+ case "hwb": {
43
+ const a = c, o = r;
44
+ return y(
45
+ p(a.h, o.h, s),
46
+ l(a.w, o.w, s),
47
+ l(a.b, o.b, s),
48
+ l(a.alpha, o.alpha, s)
49
+ );
50
+ }
51
+ case "lab": {
52
+ const a = c, o = r;
53
+ return g(
54
+ l(a.l, o.l, s),
55
+ l(a.a, o.a, s),
56
+ l(a.b, o.b, s),
57
+ l(a.alpha, o.alpha, s)
58
+ );
59
+ }
60
+ case "lch": {
61
+ const a = c, o = r;
62
+ return i(
63
+ l(a.l, o.l, s),
64
+ l(a.c, o.c, s),
65
+ p(a.h, o.h, s),
66
+ l(a.alpha, o.alpha, s)
67
+ );
68
+ }
69
+ case "oklab": {
70
+ const a = c, o = r;
71
+ return x(
72
+ l(a.l, o.l, s),
73
+ l(a.a, o.a, s),
74
+ l(a.b, o.b, s),
75
+ l(a.alpha, o.alpha, s)
76
+ );
77
+ }
78
+ case "oklch": {
79
+ const a = c, o = r;
80
+ return u(
81
+ l(a.l, o.l, s),
82
+ l(a.c, o.c, s),
83
+ p(a.h, o.h, s),
84
+ l(a.alpha, o.alpha, s)
85
+ );
86
+ }
87
+ }
88
+ }, t = (h, e, s = 0.5, n = "oklch") => C(h, e, s, n), A = (h, e, s, n = "oklch") => {
89
+ if (s < 2)
90
+ return [t(h, e, 0.5, n)];
91
+ const c = [];
92
+ for (let r = 0; r < s; r++) {
93
+ const a = r / (s - 1);
94
+ c.push(t(h, e, a, n));
95
+ }
96
+ return c;
97
+ };
98
+ export {
99
+ A as interpolateColors,
100
+ t as mixColors
101
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e={aliceblue:[240,248,255],antiquewhite:[250,235,215],aqua:[0,255,255],aquamarine:[127,255,212],azure:[240,255,255],beige:[245,245,220],bisque:[255,228,196],black:[0,0,0],blanchedalmond:[255,235,205],blue:[0,0,255],blueviolet:[138,43,226],brown:[165,42,42],burlywood:[222,184,135],cadetblue:[95,158,160],chartreuse:[127,255,0],chocolate:[210,105,30],coral:[255,127,80],cornflowerblue:[100,149,237],cornsilk:[255,248,220],crimson:[220,20,60],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgoldenrod:[184,134,11],darkgray:[169,169,169],darkgreen:[0,100,0],darkgrey:[169,169,169],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkseagreen:[143,188,143],darkslateblue:[72,61,139],darkslategray:[47,79,79],darkslategrey:[47,79,79],darkturquoise:[0,206,209],darkviolet:[148,0,211],deeppink:[255,20,147],deepskyblue:[0,191,255],dimgray:[105,105,105],dimgrey:[105,105,105],dodgerblue:[30,144,255],firebrick:[178,34,34],floralwhite:[255,250,240],forestgreen:[34,139,34],fuchsia:[255,0,255],gainsboro:[220,220,220],ghostwhite:[248,248,255],gold:[255,215,0],goldenrod:[218,165,32],gray:[128,128,128],green:[0,128,0],greenyellow:[173,255,47],grey:[128,128,128],honeydew:[240,255,240],hotpink:[255,105,180],indianred:[205,92,92],indigo:[75,0,130],ivory:[255,255,240],khaki:[240,230,140],lavender:[230,230,250],lavenderblush:[255,240,245],lawngreen:[124,252,0],lemonchiffon:[255,250,205],lightblue:[173,216,230],lightcoral:[240,128,128],lightcyan:[224,255,255],lightgoldenrodyellow:[250,250,210],lightgray:[211,211,211],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightsalmon:[255,160,122],lightseagreen:[32,178,170],lightskyblue:[135,206,250],lightslategray:[119,136,153],lightslategrey:[119,136,153],lightsteelblue:[176,196,222],lightyellow:[255,255,224],lime:[0,255,0],limegreen:[50,205,50],linen:[250,240,230],magenta:[255,0,255],maroon:[128,0,0],mediumaquamarine:[102,205,170],mediumblue:[0,0,205],mediumorchid:[186,85,211],mediumpurple:[147,112,219],mediumseagreen:[60,179,113],mediumslateblue:[123,104,238],mediumspringgreen:[0,250,154],mediumturquoise:[72,209,204],mediumvioletred:[199,21,133],midnightblue:[25,25,112],mintcream:[245,255,250],mistyrose:[255,228,225],moccasin:[255,228,181],navajowhite:[255,222,173],navy:[0,0,128],oldlace:[253,245,230],olive:[128,128,0],olivedrab:[107,142,35],orange:[255,165,0],orangered:[255,69,0],orchid:[218,112,214],palegoldenrod:[238,232,170],palegreen:[152,251,152],paleturquoise:[175,238,238],palevioletred:[219,112,147],papayawhip:[255,239,213],peachpuff:[255,218,185],peru:[205,133,63],pink:[255,192,203],plum:[221,160,221],powderblue:[176,224,230],purple:[128,0,128],rebeccapurple:[102,51,153],red:[255,0,0],rosybrown:[188,143,143],royalblue:[65,105,225],saddlebrown:[139,69,19],salmon:[250,128,114],sandybrown:[244,164,96],seagreen:[46,139,87],seashell:[255,245,238],sienna:[160,82,45],silver:[192,192,192],skyblue:[135,206,235],slateblue:[106,90,205],slategray:[112,128,144],slategrey:[112,128,144],snow:[255,250,250],springgreen:[0,255,127],steelblue:[70,130,180],tan:[210,180,140],teal:[0,128,128],thistle:[216,191,216],tomato:[255,99,71],turquoise:[64,224,208],violet:[238,130,238],wheat:[245,222,179],white:[255,255,255],whitesmoke:[245,245,245],yellow:[255,255,0],yellowgreen:[154,205,50]};exports.NAMED_COLORS=e;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * CSS named colors map.
3
+ *
4
+ * Contains all 148 CSS named colors as lowercase keys mapped to `[r, g, b]` tuples.
5
+ *
6
+ * @public
7
+ */
8
+ export declare const NAMED_COLORS: Record<string, readonly [number, number, number]>;
package/color-named.js ADDED
@@ -0,0 +1,153 @@
1
+ const e = {
2
+ aliceblue: [240, 248, 255],
3
+ antiquewhite: [250, 235, 215],
4
+ aqua: [0, 255, 255],
5
+ aquamarine: [127, 255, 212],
6
+ azure: [240, 255, 255],
7
+ beige: [245, 245, 220],
8
+ bisque: [255, 228, 196],
9
+ black: [0, 0, 0],
10
+ blanchedalmond: [255, 235, 205],
11
+ blue: [0, 0, 255],
12
+ blueviolet: [138, 43, 226],
13
+ brown: [165, 42, 42],
14
+ burlywood: [222, 184, 135],
15
+ cadetblue: [95, 158, 160],
16
+ chartreuse: [127, 255, 0],
17
+ chocolate: [210, 105, 30],
18
+ coral: [255, 127, 80],
19
+ cornflowerblue: [100, 149, 237],
20
+ cornsilk: [255, 248, 220],
21
+ crimson: [220, 20, 60],
22
+ cyan: [0, 255, 255],
23
+ darkblue: [0, 0, 139],
24
+ darkcyan: [0, 139, 139],
25
+ darkgoldenrod: [184, 134, 11],
26
+ darkgray: [169, 169, 169],
27
+ darkgreen: [0, 100, 0],
28
+ darkgrey: [169, 169, 169],
29
+ darkkhaki: [189, 183, 107],
30
+ darkmagenta: [139, 0, 139],
31
+ darkolivegreen: [85, 107, 47],
32
+ darkorange: [255, 140, 0],
33
+ darkorchid: [153, 50, 204],
34
+ darkred: [139, 0, 0],
35
+ darksalmon: [233, 150, 122],
36
+ darkseagreen: [143, 188, 143],
37
+ darkslateblue: [72, 61, 139],
38
+ darkslategray: [47, 79, 79],
39
+ darkslategrey: [47, 79, 79],
40
+ darkturquoise: [0, 206, 209],
41
+ darkviolet: [148, 0, 211],
42
+ deeppink: [255, 20, 147],
43
+ deepskyblue: [0, 191, 255],
44
+ dimgray: [105, 105, 105],
45
+ dimgrey: [105, 105, 105],
46
+ dodgerblue: [30, 144, 255],
47
+ firebrick: [178, 34, 34],
48
+ floralwhite: [255, 250, 240],
49
+ forestgreen: [34, 139, 34],
50
+ fuchsia: [255, 0, 255],
51
+ gainsboro: [220, 220, 220],
52
+ ghostwhite: [248, 248, 255],
53
+ gold: [255, 215, 0],
54
+ goldenrod: [218, 165, 32],
55
+ gray: [128, 128, 128],
56
+ green: [0, 128, 0],
57
+ greenyellow: [173, 255, 47],
58
+ grey: [128, 128, 128],
59
+ honeydew: [240, 255, 240],
60
+ hotpink: [255, 105, 180],
61
+ indianred: [205, 92, 92],
62
+ indigo: [75, 0, 130],
63
+ ivory: [255, 255, 240],
64
+ khaki: [240, 230, 140],
65
+ lavender: [230, 230, 250],
66
+ lavenderblush: [255, 240, 245],
67
+ lawngreen: [124, 252, 0],
68
+ lemonchiffon: [255, 250, 205],
69
+ lightblue: [173, 216, 230],
70
+ lightcoral: [240, 128, 128],
71
+ lightcyan: [224, 255, 255],
72
+ lightgoldenrodyellow: [250, 250, 210],
73
+ lightgray: [211, 211, 211],
74
+ lightgreen: [144, 238, 144],
75
+ lightgrey: [211, 211, 211],
76
+ lightpink: [255, 182, 193],
77
+ lightsalmon: [255, 160, 122],
78
+ lightseagreen: [32, 178, 170],
79
+ lightskyblue: [135, 206, 250],
80
+ lightslategray: [119, 136, 153],
81
+ lightslategrey: [119, 136, 153],
82
+ lightsteelblue: [176, 196, 222],
83
+ lightyellow: [255, 255, 224],
84
+ lime: [0, 255, 0],
85
+ limegreen: [50, 205, 50],
86
+ linen: [250, 240, 230],
87
+ magenta: [255, 0, 255],
88
+ maroon: [128, 0, 0],
89
+ mediumaquamarine: [102, 205, 170],
90
+ mediumblue: [0, 0, 205],
91
+ mediumorchid: [186, 85, 211],
92
+ mediumpurple: [147, 112, 219],
93
+ mediumseagreen: [60, 179, 113],
94
+ mediumslateblue: [123, 104, 238],
95
+ mediumspringgreen: [0, 250, 154],
96
+ mediumturquoise: [72, 209, 204],
97
+ mediumvioletred: [199, 21, 133],
98
+ midnightblue: [25, 25, 112],
99
+ mintcream: [245, 255, 250],
100
+ mistyrose: [255, 228, 225],
101
+ moccasin: [255, 228, 181],
102
+ navajowhite: [255, 222, 173],
103
+ navy: [0, 0, 128],
104
+ oldlace: [253, 245, 230],
105
+ olive: [128, 128, 0],
106
+ olivedrab: [107, 142, 35],
107
+ orange: [255, 165, 0],
108
+ orangered: [255, 69, 0],
109
+ orchid: [218, 112, 214],
110
+ palegoldenrod: [238, 232, 170],
111
+ palegreen: [152, 251, 152],
112
+ paleturquoise: [175, 238, 238],
113
+ palevioletred: [219, 112, 147],
114
+ papayawhip: [255, 239, 213],
115
+ peachpuff: [255, 218, 185],
116
+ peru: [205, 133, 63],
117
+ pink: [255, 192, 203],
118
+ plum: [221, 160, 221],
119
+ powderblue: [176, 224, 230],
120
+ purple: [128, 0, 128],
121
+ rebeccapurple: [102, 51, 153],
122
+ red: [255, 0, 0],
123
+ rosybrown: [188, 143, 143],
124
+ royalblue: [65, 105, 225],
125
+ saddlebrown: [139, 69, 19],
126
+ salmon: [250, 128, 114],
127
+ sandybrown: [244, 164, 96],
128
+ seagreen: [46, 139, 87],
129
+ seashell: [255, 245, 238],
130
+ sienna: [160, 82, 45],
131
+ silver: [192, 192, 192],
132
+ skyblue: [135, 206, 235],
133
+ slateblue: [106, 90, 205],
134
+ slategray: [112, 128, 144],
135
+ slategrey: [112, 128, 144],
136
+ snow: [255, 250, 250],
137
+ springgreen: [0, 255, 127],
138
+ steelblue: [70, 130, 180],
139
+ tan: [210, 180, 140],
140
+ teal: [0, 128, 128],
141
+ thistle: [216, 191, 216],
142
+ tomato: [255, 99, 71],
143
+ turquoise: [64, 224, 208],
144
+ violet: [238, 130, 238],
145
+ wheat: [245, 222, 179],
146
+ white: [255, 255, 255],
147
+ whitesmoke: [245, 245, 245],
148
+ yellow: [255, 255, 0],
149
+ yellowgreen: [154, 205, 50]
150
+ };
151
+ export {
152
+ e as NAMED_COLORS
153
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("./error.cjs");require("./number.cjs");const a=require("./color-D7FAmkht.cjs");exports.canParseOklab=a.canParseOklab;exports.canParseOklch=a.canParseOklch;exports.oklabaToOklabString=a.oklabaToOklabString;exports.oklabaToRgb8a=a.oklabaToRgb8a;exports.oklchaToOklchString=a.oklchaToOklchString;exports.oklchaToRgb8a=a.oklchaToRgb8a;exports.parseOklab=a.parseOklab;exports.parseOklch=a.parseOklch;exports.rgb8aToOklaba=a.rgb8aToOklaba;exports.rgb8aToOklcha=a.rgb8aToOklcha;
@@ -0,0 +1,141 @@
1
+ import { RGB8A, OKLABA, OKLCHA } from './color';
2
+ /**
3
+ * Returns `true` if the string can be parsed as an `oklab()` color.
4
+ *
5
+ * @param s - The string to test.
6
+ * @returns `true` if the string matches the `oklab()` format.
7
+ * @public
8
+ * @example
9
+ * ```ts
10
+ * canParseOklab('oklab(0.5 -0.1 0.1)') // true
11
+ * canParseOklab('red') // false
12
+ * ```
13
+ */
14
+ export declare const canParseOklab: (s: string) => boolean;
15
+ /**
16
+ * Parses an `oklab()` color string into an OKLABA color.
17
+ *
18
+ * L may be a percentage (0–100% mapped to 0–1) or a decimal (0–1). The `a`
19
+ * and `b` channels are decimals that may be negative.
20
+ *
21
+ * @param s - The string to parse.
22
+ * @returns An OKLABA color.
23
+ * @throws ParsingError if the string is not a valid OKLAB color.
24
+ * @public
25
+ * @example
26
+ * ```ts
27
+ * parseOklab('oklab(0.5 -0.1 0.1)') // oklaba(0.5, -0.1, 0.1)
28
+ * parseOklab('oklab(50% -0.1 0.1 / 0.8)') // oklaba(0.5, -0.1, 0.1, 0.8)
29
+ * ```
30
+ */
31
+ export declare const parseOklab: (s: string) => OKLABA;
32
+ /**
33
+ * Returns `true` if the string can be parsed as an `oklch()` color.
34
+ *
35
+ * @param s - The string to test.
36
+ * @returns `true` if the string matches the `oklch()` format.
37
+ * @public
38
+ * @example
39
+ * ```ts
40
+ * canParseOklch('oklch(0.5 0.15 326)') // true
41
+ * canParseOklch('red') // false
42
+ * ```
43
+ */
44
+ export declare const canParseOklch: (s: string) => boolean;
45
+ /**
46
+ * Parses an `oklch()` color string into an OKLCHA color.
47
+ *
48
+ * L may be a percentage (0–100% mapped to 0–1) or a decimal (0–1). C is a
49
+ * non-negative decimal and H is an angle in degrees.
50
+ *
51
+ * @param s - The string to parse.
52
+ * @returns An OKLCHA color.
53
+ * @throws ParsingError if the string is not a valid OKLCH color.
54
+ * @public
55
+ * @example
56
+ * ```ts
57
+ * parseOklch('oklch(0.5 0.15 326)') // oklcha(0.5, 0.15, 326)
58
+ * parseOklch('oklch(50% 0.15 326 / 0.8)') // oklcha(0.5, 0.15, 326, 0.8)
59
+ * ```
60
+ */
61
+ export declare const parseOklch: (s: string) => OKLCHA;
62
+ /**
63
+ * Converts an RGB8A color to an OKLABA color.
64
+ *
65
+ * @param c - The RGB8A color to convert.
66
+ * @returns The equivalent OKLABA color.
67
+ * @public
68
+ * @example
69
+ * ```ts
70
+ * rgb8aToOklaba(rgb8a(255, 0, 0)) // oklaba(~0.628, ~0.225, ~0.126)
71
+ * ```
72
+ */
73
+ export declare const rgb8aToOklaba: (c: RGB8A) => OKLABA;
74
+ /**
75
+ * Converts an OKLABA color to an RGB8A color.
76
+ *
77
+ * @param c - The OKLABA color to convert.
78
+ * @returns The equivalent RGB8A color with channels clamped to 0–255.
79
+ * @public
80
+ * @example
81
+ * ```ts
82
+ * oklabaToRgb8a(oklaba(0.628, 0.225, 0.126)) // rgb8a(~255, ~0, ~0)
83
+ * ```
84
+ */
85
+ export declare const oklabaToRgb8a: (c: OKLABA) => RGB8A;
86
+ /**
87
+ * Converts an RGB8A color to an OKLCHA color.
88
+ *
89
+ * @param c - The RGB8A color to convert.
90
+ * @returns The equivalent OKLCHA color.
91
+ * @public
92
+ * @example
93
+ * ```ts
94
+ * rgb8aToOklcha(rgb8a(255, 0, 0)) // oklcha(~0.628, ~0.258, ~29.2)
95
+ * ```
96
+ */
97
+ export declare const rgb8aToOklcha: (c: RGB8A) => OKLCHA;
98
+ /**
99
+ * Converts an OKLCHA color to an RGB8A color.
100
+ *
101
+ * @param c - The OKLCHA color to convert.
102
+ * @returns The equivalent RGB8A color with channels clamped to 0–255.
103
+ * @public
104
+ * @example
105
+ * ```ts
106
+ * oklchaToRgb8a(oklcha(0.628, 0.258, 29.2)) // rgb8a(~255, ~0, ~0)
107
+ * ```
108
+ */
109
+ export declare const oklchaToRgb8a: (c: OKLCHA) => RGB8A;
110
+ /**
111
+ * Serializes an OKLABA color to a CSS `oklab()` string.
112
+ *
113
+ * Produces `oklab(L a b)` when alpha is 1, or `oklab(L a b / alpha)`
114
+ * otherwise. Values are rounded to 5 decimal places.
115
+ *
116
+ * @param c - The OKLABA color to serialize.
117
+ * @returns A CSS `oklab()` color string.
118
+ * @public
119
+ * @example
120
+ * ```ts
121
+ * oklabaToOklabString(oklaba(0.5, -0.1, 0.1)) // 'oklab(0.5 -0.1 0.1)'
122
+ * oklabaToOklabString(oklaba(0.5, -0.1, 0.1, 0.8)) // 'oklab(0.5 -0.1 0.1 / 0.8)'
123
+ * ```
124
+ */
125
+ export declare const oklabaToOklabString: (c: OKLABA) => string;
126
+ /**
127
+ * Serializes an OKLCHA color to a CSS `oklch()` string.
128
+ *
129
+ * Produces `oklch(L C H)` when alpha is 1, or `oklch(L C H / alpha)`
130
+ * otherwise. L and C are rounded to 5 decimal places, H to 2.
131
+ *
132
+ * @param c - The OKLCHA color to serialize.
133
+ * @returns A CSS `oklch()` color string.
134
+ * @public
135
+ * @example
136
+ * ```ts
137
+ * oklchaToOklchString(oklcha(0.5, 0.15, 326)) // 'oklch(0.5 0.15 326)'
138
+ * oklchaToOklchString(oklcha(0.5, 0.15, 326, 0.8)) // 'oklch(0.5 0.15 326 / 0.8)'
139
+ * ```
140
+ */
141
+ export declare const oklchaToOklchString: (c: OKLCHA) => string;
package/color-oklab.js ADDED
@@ -0,0 +1,15 @@
1
+ import "./error.js";
2
+ import "./number.js";
3
+ import { i as l, j as r, P as b, Q as c, S as O, T, a1 as g, a2 as h, ab as e, ac as i } from "./color-SZxckS9U.js";
4
+ export {
5
+ l as canParseOklab,
6
+ r as canParseOklch,
7
+ b as oklabaToOklabString,
8
+ c as oklabaToRgb8a,
9
+ O as oklchaToOklchString,
10
+ T as oklchaToRgb8a,
11
+ g as parseOklab,
12
+ h as parseOklch,
13
+ e as rgb8aToOklaba,
14
+ i as rgb8aToOklcha
15
+ };
package/color-rgb.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("./error.cjs");require("./number.cjs");const e=require("./color-D7FAmkht.cjs");require("./color-named.cjs");exports.canParseHex=e.canParseHex;exports.canParseNamedColor=e.canParseNamedColor;exports.canParseRgb=e.canParseRgb;exports.parseHex=e.parseHex;exports.parseNamedColor=e.parseNamedColor;exports.parseRgb=e.parseRgb;exports.rgb8aToHexString=e.rgb8aToHexString;exports.rgb8aToRgbString=e.rgb8aToRgbString;
package/color-rgb.d.ts ADDED
@@ -0,0 +1,119 @@
1
+ import { RGB8A } from './color';
2
+ /**
3
+ * Returns `true` if the string can be parsed as a hex color.
4
+ *
5
+ * @param s - The string to test.
6
+ * @returns `true` if the string is a valid hex color.
7
+ * @public
8
+ * @example
9
+ * ```ts
10
+ * canParseHex('#ff0000') // true
11
+ * canParseHex('#f00') // true
12
+ * canParseHex('red') // false
13
+ * ```
14
+ */
15
+ export declare const canParseHex: (s: string) => boolean;
16
+ /**
17
+ * Parses a hex color string into an RGB8A color.
18
+ *
19
+ * Supports `#RGB`, `#RGBA`, `#RRGGBB`, and `#RRGGBBAA` formats.
20
+ *
21
+ * @param s - The hex string to parse.
22
+ * @returns An RGB8A color.
23
+ * @throws ParsingError if the string is not a valid hex color.
24
+ * @public
25
+ * @example
26
+ * ```ts
27
+ * parseHex('#ff0000') // rgb8a(255, 0, 0)
28
+ * parseHex('#f00') // rgb8a(255, 0, 0)
29
+ * parseHex('#ff000080') // rgb8a(255, 0, 0, ~0.502)
30
+ * ```
31
+ */
32
+ export declare const parseHex: (s: string) => RGB8A;
33
+ /**
34
+ * Returns `true` if the string can be parsed as an `rgb()` or `rgba()` color.
35
+ *
36
+ * @param s - The string to test.
37
+ * @returns `true` if the string is a valid RGB functional notation.
38
+ * @public
39
+ * @example
40
+ * ```ts
41
+ * canParseRgb('rgb(255, 0, 0)') // true
42
+ * canParseRgb('rgb(255 0 0 / 0.5)') // true
43
+ * canParseRgb('#ff0000') // false
44
+ * ```
45
+ */
46
+ export declare const canParseRgb: (s: string) => boolean;
47
+ /**
48
+ * Parses an `rgb()` or `rgba()` color string into an RGB8A color.
49
+ *
50
+ * Supports both legacy comma-separated and modern space-separated syntax.
51
+ *
52
+ * @param s - The string to parse.
53
+ * @returns An RGB8A color.
54
+ * @throws ParsingError if the string is not a valid RGB color.
55
+ * @public
56
+ * @example
57
+ * ```ts
58
+ * parseRgb('rgb(255, 0, 0)') // rgb8a(255, 0, 0)
59
+ * parseRgb('rgba(255, 0, 0, 0.5)') // rgb8a(255, 0, 0, 0.5)
60
+ * parseRgb('rgb(255 0 0 / 50%)') // rgb8a(255, 0, 0, 0.5)
61
+ * ```
62
+ */
63
+ export declare const parseRgb: (s: string) => RGB8A;
64
+ /**
65
+ * Returns `true` if the string is a recognized CSS named color.
66
+ *
67
+ * @param s - The string to test (case-insensitive).
68
+ * @returns `true` if the string is a named color.
69
+ * @public
70
+ * @example
71
+ * ```ts
72
+ * canParseNamedColor('red') // true
73
+ * canParseNamedColor('Red') // true
74
+ * canParseNamedColor('notacolor') // false
75
+ * ```
76
+ */
77
+ export declare const canParseNamedColor: (s: string) => boolean;
78
+ /**
79
+ * Parses a CSS named color string into an RGB8A color.
80
+ *
81
+ * @param s - The named color string (case-insensitive).
82
+ * @returns An RGB8A color.
83
+ * @throws ParsingError if the string is not a recognized named color.
84
+ * @public
85
+ * @example
86
+ * ```ts
87
+ * parseNamedColor('red') // rgb8a(255, 0, 0)
88
+ * parseNamedColor('cornflowerblue') // rgb8a(100, 149, 237)
89
+ * ```
90
+ */
91
+ export declare const parseNamedColor: (s: string) => RGB8A;
92
+ /**
93
+ * Serializes an RGB8A color to a hex string.
94
+ *
95
+ * Produces `#rrggbb` when alpha is 1, or `#rrggbbaa` otherwise.
96
+ *
97
+ * @param c - The RGB8A color to serialize.
98
+ * @returns A hex color string.
99
+ * @public
100
+ * @example
101
+ * ```ts
102
+ * rgb8aToHexString(rgb8a(255, 0, 0)) // '#ff0000'
103
+ * rgb8aToHexString(rgb8a(255, 0, 0, 0.5)) // '#ff000080'
104
+ * ```
105
+ */
106
+ export declare const rgb8aToHexString: (c: RGB8A) => string;
107
+ /**
108
+ * Serializes an RGB8A color to an `rgb()` or `rgba()` CSS string.
109
+ *
110
+ * @param c - The RGB8A color to serialize.
111
+ * @returns A CSS color string.
112
+ * @public
113
+ * @example
114
+ * ```ts
115
+ * rgb8aToRgbString(rgb8a(255, 0, 0)) // 'rgb(255, 0, 0)'
116
+ * rgb8aToRgbString(rgb8a(255, 0, 0, 0.5)) // 'rgba(255, 0, 0, 0.5)'
117
+ * ```
118
+ */
119
+ export declare const rgb8aToRgbString: (c: RGB8A) => string;
package/color-rgb.js ADDED
@@ -0,0 +1,14 @@
1
+ import "./error.js";
2
+ import "./number.js";
3
+ import { a as g, h as p, k as m, W as t, a0 as b, a3 as i, a5 as n, ad as x } from "./color-SZxckS9U.js";
4
+ import "./color-named.js";
5
+ export {
6
+ g as canParseHex,
7
+ p as canParseNamedColor,
8
+ m as canParseRgb,
9
+ t as parseHex,
10
+ b as parseNamedColor,
11
+ i as parseRgb,
12
+ n as rgb8aToHexString,
13
+ x as rgb8aToRgbString
14
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./number.cjs"),o=require("./random.cjs"),a=require("./color-D7FAmkht.cjs"),c=require("./color-named.cjs"),b=require("./color-distance.cjs"),i=(l,e,t=1)=>{const r=a.convertColor(l,"lab"),n=a.convertColor(e,"lab");return s.nearEqual(r.l,n.l,t)&&s.nearEqual(r.a,n.a,t)&&s.nearEqual(r.b,n.b,t)&&s.nearEqual(r.alpha,n.alpha,.01)},h=(l="rgb8")=>{switch(l){case"rgb":return a.rgba(o.randomFloat(0,1),o.randomFloat(0,1),o.randomFloat(0,1));case"rgb8":return a.rgb8a(Math.round(o.randomFloat(0,255)),Math.round(o.randomFloat(0,255)),Math.round(o.randomFloat(0,255)));case"hsl":return a.hsla(o.randomFloat(0,360),o.randomFloat(0,100),o.randomFloat(0,100));case"hsv":return a.hsva(o.randomFloat(0,360),o.randomFloat(0,100),o.randomFloat(0,100));case"hwb":return a.hwba(o.randomFloat(0,360),o.randomFloat(0,100),o.randomFloat(0,100));case"lab":return a.laba(o.randomFloat(0,100),o.randomFloat(-125,125),o.randomFloat(-125,125));case"lch":return a.lcha(o.randomFloat(0,100),o.randomFloat(0,150),o.randomFloat(0,360));case"oklab":return a.oklaba(o.randomFloat(0,1),o.randomFloat(-.4,.4),o.randomFloat(-.4,.4));case"oklch":return a.oklcha(o.randomFloat(0,1),o.randomFloat(0,.4),o.randomFloat(0,360))}},q=l=>{let e="",t=1/0;for(const r of Object.keys(c.NAMED_COLORS)){const[n,m,u]=c.NAMED_COLORS[r],F=a.rgb8a(n,m,u),d=b.colorDistanceSimple(l,F);d<t&&(t=d,e=r)}return e};exports.closestNamedColor=q;exports.equalColors=i;exports.randomColor=h;