@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-gamut.js ADDED
@@ -0,0 +1,72 @@
1
+ import { m as b, a4 as k, R as u } from "./color-SZxckS9U.js";
2
+ const e = (t) => t <= 31308e-7 ? t * 12.92 : 1.055 * Math.pow(t, 1 / 2.4) - 0.055, i = (t, o, n) => [
3
+ 3.2404542 * t - 1.5371385 * o - 0.4985314 * n,
4
+ -0.969266 * t + 1.8760108 * o + 0.041556 * n,
5
+ 0.0556434 * t - 0.2040259 * o + 1.0572252 * n
6
+ ], d = 0.95047, _ = 1, M = 1.08883, T = 6 / 29, D = 3 * T ** 2, m = (t, o, n) => {
7
+ const s = (c) => c > T ? c ** 3 : D * (c - 0.13793103448275862), a = (t + 16) / 116, r = o / 500 + a, l = a - n / 200;
8
+ return [d * s(r), _ * s(a), M * s(l)];
9
+ }, f = (t, o, n) => {
10
+ const s = t + 0.3963377774 * o + 0.2158037573 * n, a = t - 0.1055613458 * o - 0.0638541728 * n, r = t - 0.0894841775 * o - 1.291485548 * n, l = s * s * s, c = a * a * a, h = r * r * r;
11
+ return [
12
+ 4.0767416621 * l - 3.3077115913 * c + 0.2309699292 * h,
13
+ -1.2684380046 * l + 2.6097574011 * c - 0.3413193965 * h,
14
+ -0.0041960863 * l - 0.7034186147 * c + 1.707614701 * h
15
+ ];
16
+ }, I = (t, o, n) => {
17
+ const s = n * Math.PI / 180;
18
+ return [t, o * Math.cos(s), o * Math.sin(s)];
19
+ }, S = (t, o, n) => {
20
+ const s = n * Math.PI / 180;
21
+ return [t, o * Math.cos(s), o * Math.sin(s)];
22
+ }, x = (t) => {
23
+ switch (t.space) {
24
+ case "rgb":
25
+ return [t.r, t.g, t.b, t.alpha];
26
+ case "rgb8":
27
+ return [t.r / 255, t.g / 255, t.b / 255, t.alpha];
28
+ case "oklab": {
29
+ const [o, n, s] = f(t.l, t.a, t.b);
30
+ return [e(o), e(n), e(s), t.alpha];
31
+ }
32
+ case "oklch": {
33
+ const [o, n, s] = I(t.l, t.c, t.h), [a, r, l] = f(o, n, s);
34
+ return [e(a), e(r), e(l), t.alpha];
35
+ }
36
+ case "lab": {
37
+ const [o, n, s] = m(t.l, t.a, t.b), [a, r, l] = i(o, n, s);
38
+ return [e(a), e(r), e(l), t.alpha];
39
+ }
40
+ case "lch": {
41
+ const [o, n, s] = S(t.l, t.c, t.h), [a, r, l] = m(o, n, s), [c, h, g] = i(a, r, l);
42
+ return [e(c), e(h), e(g), t.alpha];
43
+ }
44
+ default: {
45
+ const o = b(t, "rgb8");
46
+ return [o.r / 255, o.g / 255, o.b / 255, o.alpha];
47
+ }
48
+ }
49
+ }, p = (t, o = 2e-3) => {
50
+ const [n, s, a] = x(t);
51
+ return n >= -o && n <= 1 + o && s >= -o && s <= 1 + o && a >= -o && a <= 1 + o;
52
+ }, z = (t) => {
53
+ if (p(t)) return t;
54
+ const o = t.space, n = b(t, "rgb8"), s = k(n.r, n.g, n.b, n.alpha);
55
+ return b(s, o);
56
+ }, G = (t) => {
57
+ if (p(t)) return t;
58
+ const o = t.space, n = b(t, "oklch");
59
+ let s = 0, a = n.c;
60
+ const r = 1e-4;
61
+ for (let c = 0; c < 50 && a - s > r; c++) {
62
+ const h = (s + a) / 2, g = u(n.l, h, n.h, n.alpha);
63
+ p(g) ? s = h : a = h;
64
+ }
65
+ const l = u(n.l, s, n.h, n.alpha);
66
+ return b(l, o);
67
+ };
68
+ export {
69
+ z as clampToGamut,
70
+ G as clampToGamutOklch,
71
+ p as isInGamut
72
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./number.cjs"),n=require("./color-D7FAmkht.cjs"),t=(o,e)=>{const a=o.space,r=n.convertColor(o,"oklch"),l=n.oklcha(r.l,r.c,s.wrapCircular(r.h+e,360),r.alpha);return n.convertColor(l,a)},c=o=>t(o,180),i=(o,e=30)=>[o,t(o,e),t(o,-e)],u=o=>[o,t(o,120),t(o,240)],m=o=>[o,t(o,150),t(o,210)],p=o=>[o,t(o,90),t(o,180),t(o,270)];exports.analogous=i;exports.complement=c;exports.splitComplementary=m;exports.tetradic=p;exports.triadic=u;
@@ -0,0 +1,81 @@
1
+ import { Color } from './color';
2
+ /**
3
+ * Returns the complementary color by rotating the hue
4
+ * 180 degrees in OKLCH space.
5
+ *
6
+ * @param c - Any color value
7
+ * @returns The complementary color in the same color
8
+ * space as the input
9
+ * @example
10
+ * ```ts
11
+ * const red = rgba(1, 0, 0, 1)
12
+ * const cyan = complement(red)
13
+ * ```
14
+ * @public
15
+ */
16
+ export declare const complement: (c: Color) => Color;
17
+ /**
18
+ * Returns an analogous color scheme consisting of the
19
+ * original color and two neighbors at the given angle
20
+ * offset.
21
+ *
22
+ * @param c - Any color value
23
+ * @param angle - The hue offset in degrees (default 30)
24
+ * @returns A triple of [original, +angle, -angle] in
25
+ * the same color space as the input
26
+ * @example
27
+ * ```ts
28
+ * const red = rgba(1, 0, 0, 1)
29
+ * const [base, warm, cool] = analogous(red)
30
+ * ```
31
+ * @public
32
+ */
33
+ export declare const analogous: (c: Color, angle?: number) => [Color, Color, Color];
34
+ /**
35
+ * Returns a triadic color scheme consisting of the
36
+ * original color and two colors evenly spaced at 120
37
+ * degree intervals.
38
+ *
39
+ * @param c - Any color value
40
+ * @returns A triple of [original, +120, +240] in the
41
+ * same color space as the input
42
+ * @example
43
+ * ```ts
44
+ * const red = rgba(1, 0, 0, 1)
45
+ * const [a, b, c] = triadic(red)
46
+ * ```
47
+ * @public
48
+ */
49
+ export declare const triadic: (c: Color) => [Color, Color, Color];
50
+ /**
51
+ * Returns a split-complementary color scheme consisting
52
+ * of the original color and two colors adjacent to its
53
+ * complement at 150 and 210 degree offsets.
54
+ *
55
+ * @param c - Any color value
56
+ * @returns A triple of [original, +150, +210] in the
57
+ * same color space as the input
58
+ * @example
59
+ * ```ts
60
+ * const red = rgba(1, 0, 0, 1)
61
+ * const [base, left, right] = splitComplementary(red)
62
+ * ```
63
+ * @public
64
+ */
65
+ export declare const splitComplementary: (c: Color) => [Color, Color, Color];
66
+ /**
67
+ * Returns a tetradic (rectangular) color scheme
68
+ * consisting of the original color and three colors
69
+ * evenly spaced at 90 degree intervals.
70
+ *
71
+ * @param c - Any color value
72
+ * @returns A quadruple of [original, +90, +180, +270]
73
+ * in the same color space as the input
74
+ * @example
75
+ * ```ts
76
+ * const red = rgba(1, 0, 0, 1)
77
+ * const [a, b, c, d] = tetradic(red)
78
+ * ```
79
+ * @public
80
+ */
81
+ export declare const tetradic: (c: Color) => [Color, Color, Color, Color];
@@ -0,0 +1,35 @@
1
+ import { wrapCircular as l } from "./number.js";
2
+ import { m as n, R as i } from "./color-SZxckS9U.js";
3
+ const t = (o, r) => {
4
+ const s = o.space, a = n(o, "oklch"), e = i(
5
+ a.l,
6
+ a.c,
7
+ l(a.h + r, 360),
8
+ a.alpha
9
+ );
10
+ return n(e, s);
11
+ }, c = (o) => t(o, 180), h = (o, r = 30) => [
12
+ o,
13
+ t(o, r),
14
+ t(o, -r)
15
+ ], u = (o) => [
16
+ o,
17
+ t(o, 120),
18
+ t(o, 240)
19
+ ], d = (o) => [
20
+ o,
21
+ t(o, 150),
22
+ t(o, 210)
23
+ ], k = (o) => [
24
+ o,
25
+ t(o, 90),
26
+ t(o, 180),
27
+ t(o, 270)
28
+ ];
29
+ export {
30
+ h as analogous,
31
+ c as complement,
32
+ d as splitComplementary,
33
+ k as tetradic,
34
+ u as triadic
35
+ };
package/color-hsl.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("./error.cjs");require("./number.cjs");const r=require("./color-D7FAmkht.cjs");exports.canParseHsl=r.canParseHsl;exports.hslaToHslString=r.hslaToHslString;exports.hslaToRgb8a=r.hslaToRgb8a;exports.parseHsl=r.parseHsl;exports.rgb8aToHsla=r.rgb8aToHsla;
package/color-hsl.d.ts ADDED
@@ -0,0 +1,81 @@
1
+ import { RGB8A, HSLA } from './color';
2
+ /**
3
+ * Returns `true` if the string can be parsed as an `hsl()` or `hsla()` color.
4
+ *
5
+ * Supports both legacy comma-separated and modern space-separated syntax.
6
+ *
7
+ * @param s - The string to test.
8
+ * @returns `true` if the string is a valid HSL functional notation.
9
+ * @public
10
+ * @example
11
+ * ```ts
12
+ * canParseHsl('hsl(0, 100%, 50%)') // true
13
+ * canParseHsl('hsl(120 50% 50% / 0.5)') // true
14
+ * canParseHsl('#ff0000') // false
15
+ * ```
16
+ */
17
+ export declare const canParseHsl: (s: string) => boolean;
18
+ /**
19
+ * Parses an `hsl()` or `hsla()` color string into an HSLA color.
20
+ *
21
+ * Supports both legacy comma-separated and modern space-separated syntax.
22
+ *
23
+ * @param s - The string to parse.
24
+ * @returns An HSLA color.
25
+ * @throws ParsingError if the string is not a valid HSL color.
26
+ * @public
27
+ * @example
28
+ * ```ts
29
+ * parseHsl('hsl(0, 100%, 50%)') // hsla(0, 100, 50)
30
+ * parseHsl('hsla(120, 50%, 75%, 0.8)') // hsla(120, 50, 75, 0.8)
31
+ * parseHsl('hsl(240 100% 50% / 50%)') // hsla(240, 100, 50, 0.5)
32
+ * ```
33
+ */
34
+ export declare const parseHsl: (s: string) => HSLA;
35
+ /**
36
+ * Converts an RGB8A color to an HSLA color using the standard min/max/delta
37
+ * algorithm.
38
+ *
39
+ * @param c - The RGB8A color to convert.
40
+ * @returns The equivalent HSLA color.
41
+ * @public
42
+ * @example
43
+ * ```ts
44
+ * rgb8aToHsla(rgb8a(255, 0, 0)) // hsla(0, 100, 50)
45
+ * rgb8aToHsla(rgb8a(0, 128, 0)) // hsla(120, 100, ~25.1)
46
+ * rgb8aToHsla(rgb8a(0, 0, 0)) // hsla(0, 0, 0)
47
+ * ```
48
+ */
49
+ export declare const rgb8aToHsla: (c: RGB8A) => HSLA;
50
+ /**
51
+ * Converts an HSLA color to an RGB8A color using sector-based hue-to-RGB
52
+ * conversion.
53
+ *
54
+ * @param c - The HSLA color to convert.
55
+ * @returns The equivalent RGB8A color.
56
+ * @public
57
+ * @example
58
+ * ```ts
59
+ * hslaToRgb8a(hsla(0, 100, 50)) // rgb8a(255, 0, 0)
60
+ * hslaToRgb8a(hsla(120, 100, 50)) // rgb8a(0, 255, 0)
61
+ * hslaToRgb8a(hsla(240, 100, 50)) // rgb8a(0, 0, 255)
62
+ * ```
63
+ */
64
+ export declare const hslaToRgb8a: (c: HSLA) => RGB8A;
65
+ /**
66
+ * Serializes an HSLA color to an `hsl()` or `hsla()` CSS string.
67
+ *
68
+ * Produces `hsl(h, s%, l%)` when alpha is 1, or `hsla(h, s%, l%, alpha)`
69
+ * otherwise. Hue, saturation, and lightness are rounded to two decimal
70
+ * places for readability.
71
+ *
72
+ * @param c - The HSLA color to serialize.
73
+ * @returns A CSS color string.
74
+ * @public
75
+ * @example
76
+ * ```ts
77
+ * hslaToHslString(hsla(0, 100, 50)) // 'hsl(0, 100%, 50%)'
78
+ * hslaToHslString(hsla(120, 50, 75, 0.5)) // 'hsla(120, 50%, 75%, 0.5)'
79
+ * ```
80
+ */
81
+ export declare const hslaToHslString: (c: HSLA) => string;
package/color-hsl.js ADDED
@@ -0,0 +1,10 @@
1
+ import "./error.js";
2
+ import "./number.js";
3
+ import { b as l, p, r as t, X as H, a6 as b } from "./color-SZxckS9U.js";
4
+ export {
5
+ l as canParseHsl,
6
+ p as hslaToHslString,
7
+ t as hslaToRgb8a,
8
+ H as parseHsl,
9
+ b as rgb8aToHsla
10
+ };
package/color-hsv.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("./error.cjs");require("./number.cjs");const s=require("./color-D7FAmkht.cjs");exports.canParseHsv=s.canParseHsv;exports.hslaToHsva=s.hslaToHsva;exports.hsvaToHsla=s.hsvaToHsla;exports.hsvaToHsvString=s.hsvaToHsvString;exports.hsvaToRgb8a=s.hsvaToRgb8a;exports.parseHsv=s.parseHsv;exports.rgb8aToHsva=s.rgb8aToHsva;
package/color-hsv.d.ts ADDED
@@ -0,0 +1,116 @@
1
+ import { RGB8A, HSVA, HSLA } from './color';
2
+ /**
3
+ * Returns `true` if the string can be parsed as an `hsv()` or `hsva()` color.
4
+ *
5
+ * This is a non-standard format commonly used in design tools such as Figma
6
+ * and Sketch. Supports both legacy comma-separated and modern
7
+ * space-separated syntax.
8
+ *
9
+ * @param s - The string to test.
10
+ * @returns `true` if the string is a valid HSV functional notation.
11
+ * @public
12
+ * @example
13
+ * ```ts
14
+ * canParseHsv('hsv(0, 100%, 100%)') // true
15
+ * canParseHsv('hsv(120 50% 80% / 0.5)') // true
16
+ * canParseHsv('hsl(0, 100%, 50%)') // false
17
+ * ```
18
+ */
19
+ export declare const canParseHsv: (s: string) => boolean;
20
+ /**
21
+ * Parses an `hsv()` or `hsva()` color string into an HSVA color.
22
+ *
23
+ * Supports both legacy comma-separated and modern space-separated syntax.
24
+ *
25
+ * @param s - The string to parse.
26
+ * @returns An HSVA color.
27
+ * @throws ParsingError if the string is not a valid HSV color.
28
+ * @public
29
+ * @example
30
+ * ```ts
31
+ * parseHsv('hsv(0, 100%, 100%)') // hsva(0, 100, 100)
32
+ * parseHsv('hsva(120, 50%, 80%, 0.5)') // hsva(120, 50, 80, 0.5)
33
+ * parseHsv('hsv(240 25% 90% / 50%)') // hsva(240, 25, 90, 0.5)
34
+ * ```
35
+ */
36
+ export declare const parseHsv: (s: string) => HSVA;
37
+ /**
38
+ * Converts an RGB8A color to an HSVA color.
39
+ *
40
+ * Uses the standard RGB-to-HSV algorithm where Value is the maximum channel
41
+ * and Saturation is the ratio of chroma to Value.
42
+ *
43
+ * @param c - The RGB8A color to convert.
44
+ * @returns An HSVA color.
45
+ * @public
46
+ * @example
47
+ * ```ts
48
+ * rgb8aToHsva(rgb8a(255, 0, 0)) // hsva(0, 100, 100)
49
+ * rgb8aToHsva(rgb8a(0, 0, 0)) // hsva(0, 0, 0)
50
+ * rgb8aToHsva(rgb8a(128, 128, 128)) // hsva(0, 0, ~50.2)
51
+ * ```
52
+ */
53
+ export declare const rgb8aToHsva: (c: RGB8A) => HSVA;
54
+ /**
55
+ * Converts an HSVA color to an RGB8A color.
56
+ *
57
+ * Uses the standard HSV-to-RGB algorithm with chroma, hue sectors, and an
58
+ * offset to produce final channel values.
59
+ *
60
+ * @param c - The HSVA color to convert.
61
+ * @returns An RGB8A color.
62
+ * @public
63
+ * @example
64
+ * ```ts
65
+ * hsvaToRgb8a(hsva(0, 100, 100)) // rgb8a(255, 0, 0)
66
+ * hsvaToRgb8a(hsva(120, 100, 100)) // rgb8a(0, 255, 0)
67
+ * hsvaToRgb8a(hsva(0, 0, 0)) // rgb8a(0, 0, 0)
68
+ * ```
69
+ */
70
+ export declare const hsvaToRgb8a: (c: HSVA) => RGB8A;
71
+ /**
72
+ * Converts an HSLA color to an HSVA color using a direct formula that
73
+ * avoids an intermediate RGB conversion.
74
+ *
75
+ * @param c - The HSLA color to convert.
76
+ * @returns An HSVA color.
77
+ * @public
78
+ * @example
79
+ * ```ts
80
+ * hslaToHsva(hsla(0, 100, 50)) // hsva(0, 100, 100)
81
+ * hslaToHsva(hsla(0, 0, 0)) // hsva(0, 0, 0)
82
+ * hslaToHsva(hsla(120, 50, 75)) // hsva(120, ~33.3, ~87.5)
83
+ * ```
84
+ */
85
+ export declare const hslaToHsva: (c: HSLA) => HSVA;
86
+ /**
87
+ * Converts an HSVA color to an HSLA color using a direct formula that
88
+ * avoids an intermediate RGB conversion.
89
+ *
90
+ * @param c - The HSVA color to convert.
91
+ * @returns An HSLA color.
92
+ * @public
93
+ * @example
94
+ * ```ts
95
+ * hsvaToHsla(hsva(0, 100, 100)) // hsla(0, 100, 50)
96
+ * hsvaToHsla(hsva(0, 0, 0)) // hsla(0, 0, 0)
97
+ * hsvaToHsla(hsva(120, 50, 80)) // hsla(120, ~47.1, 60)
98
+ * ```
99
+ */
100
+ export declare const hsvaToHsla: (c: HSVA) => HSLA;
101
+ /**
102
+ * Serializes an HSVA color to an `hsv()` or `hsva()` string.
103
+ *
104
+ * Produces `hsv(h, s%, v%)` when alpha is 1, or `hsva(h, s%, v%, a)`
105
+ * otherwise.
106
+ *
107
+ * @param c - The HSVA color to serialize.
108
+ * @returns An HSV color string.
109
+ * @public
110
+ * @example
111
+ * ```ts
112
+ * hsvaToHsvString(hsva(0, 100, 100)) // 'hsv(0, 100%, 100%)'
113
+ * hsvaToHsvString(hsva(120, 50, 80, 0.5)) // 'hsva(120, 50%, 80%, 0.5)'
114
+ * ```
115
+ */
116
+ export declare const hsvaToHsvString: (c: HSVA) => string;
package/color-hsv.js ADDED
@@ -0,0 +1,12 @@
1
+ import "./error.js";
2
+ import "./number.js";
3
+ import { d as r, q as H, t, u as T, v as h, Y as p, a7 as e } from "./color-SZxckS9U.js";
4
+ export {
5
+ r as canParseHsv,
6
+ H as hslaToHsva,
7
+ t as hsvaToHsla,
8
+ T as hsvaToHsvString,
9
+ h as hsvaToRgb8a,
10
+ p as parseHsv,
11
+ e as rgb8aToHsva
12
+ };
package/color-hwb.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("./error.cjs");require("./number.cjs");const b=require("./color-D7FAmkht.cjs");exports.canParseHwb=b.canParseHwb;exports.hwbaToHwbString=b.hwbaToHwbString;exports.hwbaToRgb8a=b.hwbaToRgb8a;exports.parseHwb=b.parseHwb;exports.rgb8aToHwba=b.rgb8aToHwba;
package/color-hwb.d.ts ADDED
@@ -0,0 +1,88 @@
1
+ import { RGB8A, HWBA } from './color';
2
+ /**
3
+ * Returns `true` if the string can be parsed as an `hwb()` CSS Level 4 color.
4
+ *
5
+ * Only the modern space-separated syntax is supported:
6
+ * `hwb(h w% b%)` or `hwb(h w% b% / alpha)`.
7
+ *
8
+ * @param s - The string to test.
9
+ * @returns `true` if the string is a valid HWB functional notation.
10
+ * @public
11
+ * @example
12
+ * ```ts
13
+ * canParseHwb('hwb(0 0% 0%)') // true
14
+ * canParseHwb('hwb(180 20% 30% / 0.5)') // true
15
+ * canParseHwb('rgb(255, 0, 0)') // false
16
+ * ```
17
+ */
18
+ export declare const canParseHwb: (s: string) => boolean;
19
+ /**
20
+ * Parses an `hwb()` CSS Level 4 color string into an HWBA color.
21
+ *
22
+ * Only the modern space-separated syntax is supported:
23
+ * `hwb(h w% b%)` or `hwb(h w% b% / alpha)`.
24
+ *
25
+ * @param s - The string to parse.
26
+ * @returns An HWBA color.
27
+ * @throws ParsingError if the string is not a valid HWB color.
28
+ * @public
29
+ * @example
30
+ * ```ts
31
+ * parseHwb('hwb(0 0% 0%)') // hwba(0, 0, 0)
32
+ * parseHwb('hwb(180 20% 30%)') // hwba(180, 20, 30)
33
+ * parseHwb('hwb(90 10% 20% / 0.5)') // hwba(90, 10, 20, 0.5)
34
+ * ```
35
+ */
36
+ export declare const parseHwb: (s: string) => HWBA;
37
+ /**
38
+ * Converts an RGB8A color to an HWBA color.
39
+ *
40
+ * The conversion derives hue, whiteness, and blackness from the RGB channels.
41
+ * Whiteness is the minimum channel value and blackness is one minus the maximum
42
+ * channel value.
43
+ *
44
+ * @param c - The RGB8A color to convert.
45
+ * @returns An HWBA color.
46
+ * @public
47
+ * @example
48
+ * ```ts
49
+ * rgb8aToHwba(rgb8a(255, 0, 0)) // hwba(0, 0, 0)
50
+ * rgb8aToHwba(rgb8a(0, 0, 0)) // hwba(0, 0, 100)
51
+ * rgb8aToHwba(rgb8a(255, 255, 255)) // hwba(0, 100, 0)
52
+ * ```
53
+ */
54
+ export declare const rgb8aToHwba: (c: RGB8A) => HWBA;
55
+ /**
56
+ * Converts an HWBA color to an RGB8A color.
57
+ *
58
+ * When whiteness plus blackness exceed 100%, they are proportionally scaled
59
+ * so that their sum equals 100%. The pure hue color is then blended between
60
+ * white and black according to the whiteness and blackness values.
61
+ *
62
+ * @param c - The HWBA color to convert.
63
+ * @returns An RGB8A color.
64
+ * @public
65
+ * @example
66
+ * ```ts
67
+ * hwbaToRgb8a(hwba(0, 0, 0)) // rgb8a(255, 0, 0)
68
+ * hwbaToRgb8a(hwba(0, 100, 0)) // rgb8a(255, 255, 255)
69
+ * hwbaToRgb8a(hwba(0, 0, 100)) // rgb8a(0, 0, 0)
70
+ * ```
71
+ */
72
+ export declare const hwbaToRgb8a: (c: HWBA) => RGB8A;
73
+ /**
74
+ * Serializes an HWBA color to a CSS `hwb()` string.
75
+ *
76
+ * Produces `hwb(h w% b%)` when alpha is 1, or `hwb(h w% b% / alpha)`
77
+ * otherwise.
78
+ *
79
+ * @param c - The HWBA color to serialize.
80
+ * @returns A CSS `hwb()` color string.
81
+ * @public
82
+ * @example
83
+ * ```ts
84
+ * hwbaToHwbString(hwba(0, 0, 0)) // 'hwb(0 0% 0%)'
85
+ * hwbaToHwbString(hwba(180, 20, 30, 0.5)) // 'hwb(180 20% 30% / 0.5)'
86
+ * ```
87
+ */
88
+ export declare const hwbaToHwbString: (c: HWBA) => string;
package/color-hwb.js ADDED
@@ -0,0 +1,10 @@
1
+ import "./error.js";
2
+ import "./number.js";
3
+ import { e as s, x as w, y as e, Z as p, a8 as t } from "./color-SZxckS9U.js";
4
+ export {
5
+ s as canParseHwb,
6
+ w as hwbaToHwbString,
7
+ e as hwbaToRgb8a,
8
+ p as parseHwb,
9
+ t as rgb8aToHwba
10
+ };
package/color-lab.cjs ADDED
@@ -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.canParseLab=a.canParseLab;exports.canParseLch=a.canParseLch;exports.labaToLabString=a.labaToLabString;exports.labaToRgb8a=a.labaToRgb8a;exports.lchaToLchString=a.lchaToLchString;exports.lchaToRgb8a=a.lchaToRgb8a;exports.parseLab=a.parseLab;exports.parseLch=a.parseLch;exports.rgb8aToLaba=a.rgb8aToLaba;exports.rgb8aToLcha=a.rgb8aToLcha;
package/color-lab.d.ts ADDED
@@ -0,0 +1,161 @@
1
+ import { RGB8A, LABA, LCHA } from './color';
2
+ /**
3
+ * Returns `true` if the string can be parsed as a `lab()` color.
4
+ *
5
+ * @param s - The string to test.
6
+ * @returns `true` if the string is a valid LAB functional notation.
7
+ * @public
8
+ * @example
9
+ * ```ts
10
+ * canParseLab('lab(50 -20 30)') // true
11
+ * canParseLab('lab(50% -20 30 / 0.5)') // true
12
+ * canParseLab('#ff0000') // false
13
+ * ```
14
+ */
15
+ export declare const canParseLab: (s: string) => boolean;
16
+ /**
17
+ * Parses a `lab()` color string into a LABA color.
18
+ *
19
+ * Supports `lab(L a b)` and `lab(L a b / alpha)` syntax. The lightness
20
+ * value can be a percentage (0–100%) or a plain number (0–100). The `a`
21
+ * and `b` axes accept any number, including negatives.
22
+ *
23
+ * @param s - The string to parse.
24
+ * @returns A LABA color.
25
+ * @throws ParsingError if the string is not a valid LAB color.
26
+ * @public
27
+ * @example
28
+ * ```ts
29
+ * parseLab('lab(50 -20 30)') // laba(50, -20, 30)
30
+ * parseLab('lab(50% -20 30 / 0.5)') // laba(50, -20, 30, 0.5)
31
+ * ```
32
+ */
33
+ export declare const parseLab: (s: string) => LABA;
34
+ /**
35
+ * Returns `true` if the string can be parsed as an `lch()` color.
36
+ *
37
+ * @param s - The string to test.
38
+ * @returns `true` if the string is a valid LCH functional notation.
39
+ * @public
40
+ * @example
41
+ * ```ts
42
+ * canParseLch('lch(50 36 326)') // true
43
+ * canParseLch('lch(50% 36 326 / 0.8)') // true
44
+ * canParseLch('rgb(0,0,0)') // false
45
+ * ```
46
+ */
47
+ export declare const canParseLch: (s: string) => boolean;
48
+ /**
49
+ * Parses an `lch()` color string into a LCHA color.
50
+ *
51
+ * Supports `lch(L C H)` and `lch(L C H / alpha)` syntax. The lightness
52
+ * value can be a percentage (0–100%) or a plain number (0–100). Chroma
53
+ * must be non-negative, and hue is an angle in degrees.
54
+ *
55
+ * @param s - The string to parse.
56
+ * @returns A LCHA color.
57
+ * @throws ParsingError if the string is not a valid LCH color.
58
+ * @public
59
+ * @example
60
+ * ```ts
61
+ * parseLch('lch(50 36 326)') // lcha(50, 36, 326)
62
+ * parseLch('lch(75% 40 120 / 50%)') // lcha(75, 40, 120, 0.5)
63
+ * ```
64
+ */
65
+ export declare const parseLch: (s: string) => LCHA;
66
+ /**
67
+ * Converts an RGB8A color to a LABA color through the CIE XYZ intermediate
68
+ * color space.
69
+ *
70
+ * @param c - The RGB8A color to convert.
71
+ * @returns The equivalent LABA color.
72
+ * @public
73
+ * @example
74
+ * ```ts
75
+ * rgb8aToLaba(rgb8a(255, 0, 0)) // laba(~53.23, ~80.11, ~67.22)
76
+ * rgb8aToLaba(rgb8a(0, 0, 0)) // laba(0, 0, 0)
77
+ * ```
78
+ */
79
+ export declare const rgb8aToLaba: (c: RGB8A) => LABA;
80
+ /**
81
+ * Converts a LABA color to an RGB8A color through the CIE XYZ intermediate
82
+ * color space.
83
+ *
84
+ * Channel values are clamped to the sRGB gamut before rounding.
85
+ *
86
+ * @param c - The LABA color to convert.
87
+ * @returns The equivalent RGB8A color.
88
+ * @public
89
+ * @example
90
+ * ```ts
91
+ * labaToRgb8a(laba(53.23, 80.11, 67.22)) // rgb8a(~255, ~0, ~0)
92
+ * labaToRgb8a(laba(0, 0, 0)) // rgb8a(0, 0, 0)
93
+ * ```
94
+ */
95
+ export declare const labaToRgb8a: (c: LABA) => RGB8A;
96
+ /**
97
+ * Converts an RGB8A color to a LCHA color by converting to LABA first and
98
+ * then applying the polar (cylindrical) transformation.
99
+ *
100
+ * @param c - The RGB8A color to convert.
101
+ * @returns The equivalent LCHA color.
102
+ * @public
103
+ * @example
104
+ * ```ts
105
+ * rgb8aToLcha(rgb8a(255, 0, 0)) // lcha(~53.23, ~104.55, ~40.0)
106
+ * rgb8aToLcha(rgb8a(0, 0, 0)) // lcha(0, 0, 0)
107
+ * ```
108
+ */
109
+ export declare const rgb8aToLcha: (c: RGB8A) => LCHA;
110
+ /**
111
+ * Converts a LCHA color to an RGB8A color by converting from polar
112
+ * coordinates to rectangular LAB and then to RGB8A.
113
+ *
114
+ * @param c - The LCHA color to convert.
115
+ * @returns The equivalent RGB8A color.
116
+ * @public
117
+ * @example
118
+ * ```ts
119
+ * lchaToRgb8a(lcha(53.23, 104.55, 40.0)) // rgb8a(~255, ~0, ~0)
120
+ * lchaToRgb8a(lcha(0, 0, 0)) // rgb8a(0, 0, 0)
121
+ * ```
122
+ */
123
+ export declare const lchaToRgb8a: (c: LCHA) => RGB8A;
124
+ /**
125
+ * Serializes a LABA color to a `lab()` CSS string.
126
+ *
127
+ * Produces `lab(L a b)` when alpha is 1, or `lab(L a b / alpha)` otherwise.
128
+ * Lightness is rounded to 2 decimal places; `a` and `b` axes are rounded
129
+ * to 4 decimal places.
130
+ *
131
+ * @param c - The LABA color to serialize.
132
+ * @returns A CSS `lab()` color string.
133
+ * @public
134
+ * @example
135
+ * ```ts
136
+ * labaToLabString(laba(50, -20, 30))
137
+ * // 'lab(50 -20 30)'
138
+ * labaToLabString(laba(50, -20, 30, 0.5))
139
+ * // 'lab(50 -20 30 / 0.5)'
140
+ * ```
141
+ */
142
+ export declare const labaToLabString: (c: LABA) => string;
143
+ /**
144
+ * Serializes a LCHA color to an `lch()` CSS string.
145
+ *
146
+ * Produces `lch(L C H)` when alpha is 1, or `lch(L C H / alpha)` otherwise.
147
+ * Lightness is rounded to 2 decimal places; chroma and hue are rounded to
148
+ * 4 decimal places.
149
+ *
150
+ * @param c - The LCHA color to serialize.
151
+ * @returns A CSS `lch()` color string.
152
+ * @public
153
+ * @example
154
+ * ```ts
155
+ * lchaToLchString(lcha(50, 36, 326))
156
+ * // 'lch(50 36 326)'
157
+ * lchaToLchString(lcha(50, 36, 326, 0.8))
158
+ * // 'lch(50 36 326 / 0.8)'
159
+ * ```
160
+ */
161
+ export declare const lchaToLchString: (c: LCHA) => string;