color-value-tools 1.2.1 → 1.2.2

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 (49) hide show
  1. package/README.md +18 -0
  2. package/dist/cjs/a11y.d.ts +40 -0
  3. package/dist/cjs/a11y.js +253 -0
  4. package/dist/cjs/cache.d.ts +9 -0
  5. package/dist/cjs/cache.js +38 -0
  6. package/dist/cjs/convert/format.d.ts +3 -0
  7. package/dist/cjs/convert/format.js +42 -0
  8. package/dist/cjs/convert/index.d.ts +2 -0
  9. package/dist/cjs/convert/index.js +18 -0
  10. package/dist/cjs/convert/spaces.d.ts +189 -0
  11. package/dist/cjs/convert/spaces.js +556 -0
  12. package/dist/cjs/index.d.ts +6 -397
  13. package/dist/cjs/index.js +20 -1466
  14. package/dist/cjs/internal/named-colors.d.ts +1 -0
  15. package/dist/cjs/internal/named-colors.js +165 -0
  16. package/dist/cjs/internal/transfer.d.ts +2 -0
  17. package/dist/cjs/internal/transfer.js +12 -0
  18. package/dist/cjs/manipulate.d.ts +15 -0
  19. package/dist/cjs/manipulate.js +223 -0
  20. package/dist/cjs/palette.d.ts +40 -0
  21. package/dist/cjs/palette.js +164 -0
  22. package/dist/cjs/parse.d.ts +102 -0
  23. package/dist/cjs/parse.js +257 -0
  24. package/dist/cli/{bin/cli.js → cli.js} +28 -26
  25. package/dist/esm/a11y.d.ts +40 -0
  26. package/dist/esm/a11y.js +237 -0
  27. package/dist/esm/cache.d.ts +9 -0
  28. package/dist/esm/cache.js +31 -0
  29. package/dist/esm/convert/format.d.ts +3 -0
  30. package/dist/esm/convert/format.js +37 -0
  31. package/dist/esm/convert/index.d.ts +2 -0
  32. package/dist/esm/convert/index.js +2 -0
  33. package/dist/esm/convert/spaces.d.ts +189 -0
  34. package/dist/esm/convert/spaces.js +520 -0
  35. package/dist/esm/index.d.ts +6 -0
  36. package/dist/esm/index.js +6 -1368
  37. package/dist/esm/internal/named-colors.d.ts +1 -0
  38. package/dist/esm/internal/named-colors.js +162 -0
  39. package/dist/esm/internal/transfer.d.ts +2 -0
  40. package/dist/esm/internal/transfer.js +8 -0
  41. package/dist/esm/manipulate.d.ts +15 -0
  42. package/dist/esm/manipulate.js +210 -0
  43. package/dist/esm/package.json +3 -1
  44. package/dist/esm/palette.d.ts +40 -0
  45. package/dist/esm/palette.js +145 -0
  46. package/dist/esm/parse.d.ts +102 -0
  47. package/dist/esm/parse.js +241 -0
  48. package/package.json +100 -8
  49. package/dist/cli/src/index.js +0 -1468
@@ -0,0 +1 @@
1
+ export declare const NAMED_COLORS: Record<string, string>;
@@ -0,0 +1,165 @@
1
+ "use strict";
2
+ // CSS named colors (CSS Color Module Level 4).
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.NAMED_COLORS = void 0;
5
+ exports.NAMED_COLORS = {
6
+ aliceblue: '#f0f8ff',
7
+ antiquewhite: '#faebd7',
8
+ aqua: '#00ffff',
9
+ aquamarine: '#7fffd4',
10
+ azure: '#f0ffff',
11
+ beige: '#f5f5dc',
12
+ bisque: '#ffe4c4',
13
+ black: '#000000',
14
+ blanchedalmond: '#ffebcd',
15
+ blue: '#0000ff',
16
+ blueviolet: '#8a2be2',
17
+ brown: '#a52a2a',
18
+ burlywood: '#deb887',
19
+ cadetblue: '#5f9ea0',
20
+ chartreuse: '#7fff00',
21
+ chocolate: '#d2691e',
22
+ coral: '#ff7f50',
23
+ cornflowerblue: '#6495ed',
24
+ cornsilk: '#fff8dc',
25
+ crimson: '#dc143c',
26
+ cyan: '#00ffff',
27
+ darkblue: '#00008b',
28
+ darkcyan: '#008b8b',
29
+ darkgoldenrod: '#b8860b',
30
+ darkgray: '#a9a9a9',
31
+ darkgreen: '#006400',
32
+ darkgrey: '#a9a9a9',
33
+ darkkhaki: '#bdb76b',
34
+ darkmagenta: '#8b008b',
35
+ darkolivegreen: '#556b2f',
36
+ darkorange: '#ff8c00',
37
+ darkorchid: '#9932cc',
38
+ darkred: '#8b0000',
39
+ darksalmon: '#e9967a',
40
+ darkseagreen: '#8fbc8f',
41
+ darkslateblue: '#483d8b',
42
+ darkslategray: '#2f4f4f',
43
+ darkslategrey: '#2f4f4f',
44
+ darkturquoise: '#00ced1',
45
+ darkviolet: '#9400d3',
46
+ deeppink: '#ff1493',
47
+ deepskyblue: '#00bfff',
48
+ dimgray: '#696969',
49
+ dimgrey: '#696969',
50
+ dodgerblue: '#1e90ff',
51
+ firebrick: '#b22222',
52
+ floralwhite: '#fffaf0',
53
+ forestgreen: '#228b22',
54
+ fuchsia: '#ff00ff',
55
+ gainsboro: '#dcdcdc',
56
+ ghostwhite: '#f8f8ff',
57
+ gold: '#ffd700',
58
+ goldenrod: '#daa520',
59
+ gray: '#808080',
60
+ green: '#008000',
61
+ greenyellow: '#adff2f',
62
+ grey: '#808080',
63
+ honeydew: '#f0fff0',
64
+ hotpink: '#ff69b4',
65
+ indianred: '#cd5c5c',
66
+ indigo: '#4b0082',
67
+ ivory: '#fffff0',
68
+ khaki: '#f0e68c',
69
+ lavender: '#e6e6fa',
70
+ lavenderblush: '#fff0f5',
71
+ lawngreen: '#7cfc00',
72
+ lemonchiffon: '#fffacd',
73
+ lightblue: '#add8e6',
74
+ lightcoral: '#f08080',
75
+ lightcyan: '#e0ffff',
76
+ lightgoldenrodyellow: '#fafad2',
77
+ lightgray: '#d3d3d3',
78
+ lightgreen: '#90ee90',
79
+ lightgrey: '#d3d3d3',
80
+ lightpink: '#ffb6c1',
81
+ lightsalmon: '#ffa07a',
82
+ lightseagreen: '#20b2aa',
83
+ lightskyblue: '#87cefa',
84
+ lightslategray: '#778899',
85
+ lightslategrey: '#778899',
86
+ lightsteelblue: '#b0c4de',
87
+ lightyellow: '#ffffe0',
88
+ lime: '#00ff00',
89
+ limegreen: '#32cd32',
90
+ linen: '#faf0e6',
91
+ magenta: '#ff00ff',
92
+ maroon: '#800000',
93
+ mediumaquamarine: '#66cdaa',
94
+ mediumblue: '#0000cd',
95
+ mediumorchid: '#ba55d3',
96
+ mediumpurple: '#9370db',
97
+ mediumseagreen: '#3cb371',
98
+ mediumslateblue: '#7b68ee',
99
+ mediumspringgreen: '#00fa9a',
100
+ mediumturquoise: '#48d1cc',
101
+ mediumvioletred: '#c71585',
102
+ midnightblue: '#191970',
103
+ mintcream: '#f5fffa',
104
+ mistyrose: '#ffe4e1',
105
+ moccasin: '#ffe4b5',
106
+ navajowhite: '#ffdead',
107
+ navy: '#000080',
108
+ oldlace: '#fdf5e6',
109
+ olive: '#808000',
110
+ olivedrab: '#6b8e23',
111
+ orange: '#ffa500',
112
+ orangered: '#ff4500',
113
+ orchid: '#da70d6',
114
+ palegoldenrod: '#eee8aa',
115
+ palegreen: '#98fb98',
116
+ paleturquoise: '#afeeee',
117
+ palevioletred: '#db7093',
118
+ papayawhip: '#ffefd5',
119
+ peachpuff: '#ffdab9',
120
+ peru: '#cd853f',
121
+ pink: '#ffc0cb',
122
+ plum: '#dda0dd',
123
+ powderblue: '#b0e0e6',
124
+ purple: '#800080',
125
+ rebeccapurple: '#663399',
126
+ red: '#ff0000',
127
+ rosybrown: '#bc8f8f',
128
+ royalblue: '#4169e1',
129
+ saddlebrown: '#8b4513',
130
+ salmon: '#fa8072',
131
+ sandybrown: '#f4a460',
132
+ seagreen: '#2e8b57',
133
+ seashell: '#fff5ee',
134
+ sienna: '#a0522d',
135
+ silver: '#c0c0c0',
136
+ skyblue: '#87ceeb',
137
+ slateblue: '#6a5acd',
138
+ slategray: '#708090',
139
+ slategrey: '#708090',
140
+ snow: '#fffafa',
141
+ springgreen: '#00ff7f',
142
+ steelblue: '#4682b4',
143
+ tan: '#d2b48c',
144
+ teal: '#008080',
145
+ thistle: '#d8bfd8',
146
+ tomato: '#ff6347',
147
+ turquoise: '#40e0d0',
148
+ violet: '#ee82ee',
149
+ wheat: '#f5deb3',
150
+ white: '#ffffff',
151
+ whitesmoke: '#f5f5f5',
152
+ yellow: '#ffff00',
153
+ yellowgreen: '#9acd32',
154
+ // 'transparent' is the only CSS-wide keyword with an actual fixed color (fully
155
+ // transparent black) — normalizeColor() special-cases it before ever reaching
156
+ // this table (see the `str === 'transparent'` check), so this entry only
157
+ // matters for getColorType()/toNearestNamedColor(), which read the table
158
+ // directly. 'currentcolor'/'inherit'/'initial'/'unset' are deliberately NOT
159
+ // listed here: none of them has a color value of their own (they only resolve
160
+ // to one given surrounding DOM/CSSOM context this library never has access
161
+ // to), so treating them as resolvable named colors would mean fabricating an
162
+ // arbitrary RGB value with no way for a caller to tell it apart from a real
163
+ // one — see normalizeColor()'s `type: 'unknown'` fallback for these instead.
164
+ transparent: 'transparent',
165
+ };
@@ -0,0 +1,2 @@
1
+ export declare function srgbChanToLinear(v: number): number;
2
+ export declare function linearChanToSrgb(v: number): number;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.srgbChanToLinear = srgbChanToLinear;
4
+ exports.linearChanToSrgb = linearChanToSrgb;
5
+ // sRGB transfer functions (operate on 0-1 values)
6
+ function srgbChanToLinear(v) {
7
+ return v <= 0.04045 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4);
8
+ }
9
+ function linearChanToSrgb(v) {
10
+ const t = v <= 0.0031308 ? 12.92 * v : 1.055 * Math.pow(v, 1 / 2.4) - 0.055;
11
+ return Math.max(0, Math.min(1, t));
12
+ }
@@ -0,0 +1,15 @@
1
+ export declare function adjustHexBrightness(hex: string, offsetPercent: number): string;
2
+ export declare function rotateHue(hex: string, degrees: number): string;
3
+ export declare function lighten(color: string, amount: number): string;
4
+ export declare function darken(color: string, amount: number): string;
5
+ export declare function saturate(color: string, amount: number): string;
6
+ export declare function desaturate(color: string, amount: number): string;
7
+ export declare function setAlpha(color: string, alpha: number): string;
8
+ export declare function getAlpha(color: string): number;
9
+ export declare function invertColor(color: string): string;
10
+ export declare function grayscale(color: string): string;
11
+ export declare function mixColors(c1: string, c2: string, t: number, opts?: {
12
+ mode?: 'rgb' | 'hsl' | 'lab' | 'lch' | 'oklab' | 'oklch';
13
+ format?: 'hex' | 'rgb' | 'rgba' | 'hsl';
14
+ hueInterpolation?: 'shorter' | 'longer' | 'increasing' | 'decreasing';
15
+ }): string;
@@ -0,0 +1,223 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.adjustHexBrightness = adjustHexBrightness;
4
+ exports.rotateHue = rotateHue;
5
+ exports.lighten = lighten;
6
+ exports.darken = darken;
7
+ exports.saturate = saturate;
8
+ exports.desaturate = desaturate;
9
+ exports.setAlpha = setAlpha;
10
+ exports.getAlpha = getAlpha;
11
+ exports.invertColor = invertColor;
12
+ exports.grayscale = grayscale;
13
+ exports.mixColors = mixColors;
14
+ // Adjusting and mixing colors.
15
+ const parse_js_1 = require("./parse.js");
16
+ const spaces_js_1 = require("./convert/spaces.js");
17
+ function adjustHexBrightness(hex, offsetPercent) {
18
+ const normalizedHex = (0, spaces_js_1.normalizeHex)(hex);
19
+ const p = Math.max(-100, Math.min(100, offsetPercent)) / 100;
20
+ const r = parseInt(normalizedHex.slice(1, 3), 16);
21
+ const g = parseInt(normalizedHex.slice(3, 5), 16);
22
+ const b = parseInt(normalizedHex.slice(5, 7), 16);
23
+ const adjustChannel = (channel) => {
24
+ if (p > 0)
25
+ return Math.min(255, Math.floor(channel + (255 - channel) * p));
26
+ else if (p < 0)
27
+ return Math.max(0, Math.floor(channel * (1 + p)));
28
+ return channel;
29
+ };
30
+ const newR = adjustChannel(r);
31
+ const newG = adjustChannel(g);
32
+ const newB = adjustChannel(b);
33
+ return `#${newR.toString(16).padStart(2, '0')}${newG.toString(16).padStart(2, '0')}${newB.toString(16).padStart(2, '0')}`;
34
+ }
35
+ function rotateHue(hex, degrees) {
36
+ const [h, s, l] = (0, spaces_js_1.hexToHsl)(hex);
37
+ const newH = (((h + degrees) % 360) + 360) % 360;
38
+ return (0, spaces_js_1.hslToHex)(newH, s, l);
39
+ }
40
+ function lighten(color, amount) {
41
+ var _a, _b, _c;
42
+ const n = (0, parse_js_1.normalizeColor)(color);
43
+ const h = (_a = n.h) !== null && _a !== void 0 ? _a : 0;
44
+ const s = (_b = n.s) !== null && _b !== void 0 ? _b : 0;
45
+ const l = Math.min(100, ((_c = n.l) !== null && _c !== void 0 ? _c : 0) + amount);
46
+ return (0, spaces_js_1.hslToHex)(h, s, l);
47
+ }
48
+ function darken(color, amount) {
49
+ var _a, _b, _c;
50
+ const n = (0, parse_js_1.normalizeColor)(color);
51
+ const h = (_a = n.h) !== null && _a !== void 0 ? _a : 0;
52
+ const s = (_b = n.s) !== null && _b !== void 0 ? _b : 0;
53
+ const l = Math.max(0, ((_c = n.l) !== null && _c !== void 0 ? _c : 0) - amount);
54
+ return (0, spaces_js_1.hslToHex)(h, s, l);
55
+ }
56
+ function saturate(color, amount) {
57
+ var _a, _b, _c;
58
+ const n = (0, parse_js_1.normalizeColor)(color);
59
+ const h = (_a = n.h) !== null && _a !== void 0 ? _a : 0;
60
+ const s = Math.min(100, ((_b = n.s) !== null && _b !== void 0 ? _b : 0) + amount);
61
+ const l = (_c = n.l) !== null && _c !== void 0 ? _c : 0;
62
+ return (0, spaces_js_1.hslToHex)(h, s, l);
63
+ }
64
+ function desaturate(color, amount) {
65
+ var _a, _b, _c;
66
+ const n = (0, parse_js_1.normalizeColor)(color);
67
+ const h = (_a = n.h) !== null && _a !== void 0 ? _a : 0;
68
+ const s = Math.max(0, ((_b = n.s) !== null && _b !== void 0 ? _b : 0) - amount);
69
+ const l = (_c = n.l) !== null && _c !== void 0 ? _c : 0;
70
+ return (0, spaces_js_1.hslToHex)(h, s, l);
71
+ }
72
+ function setAlpha(color, alpha) {
73
+ var _a, _b, _c;
74
+ const n = (0, parse_js_1.normalizeColor)(color);
75
+ const r = (_a = n.r) !== null && _a !== void 0 ? _a : 0;
76
+ const g = (_b = n.g) !== null && _b !== void 0 ? _b : 0;
77
+ const b = (_c = n.b) !== null && _c !== void 0 ? _c : 0;
78
+ const a = Math.max(0, Math.min(1, alpha));
79
+ return `rgba(${r}, ${g}, ${b}, ${+a.toFixed(3)})`;
80
+ }
81
+ function getAlpha(color) {
82
+ var _a;
83
+ const n = (0, parse_js_1.normalizeColor)(color);
84
+ return (_a = n.a) !== null && _a !== void 0 ? _a : 1;
85
+ }
86
+ function invertColor(color) {
87
+ var _a, _b, _c;
88
+ const n = (0, parse_js_1.normalizeColor)(color);
89
+ const r = 255 - ((_a = n.r) !== null && _a !== void 0 ? _a : 0);
90
+ const g = 255 - ((_b = n.g) !== null && _b !== void 0 ? _b : 0);
91
+ const b = 255 - ((_c = n.b) !== null && _c !== void 0 ? _c : 0);
92
+ return (0, spaces_js_1.rgbToHex)({ r, g, b });
93
+ }
94
+ function grayscale(color) {
95
+ var _a, _b, _c;
96
+ const n = (0, parse_js_1.normalizeColor)(color);
97
+ const r = (_a = n.r) !== null && _a !== void 0 ? _a : 0;
98
+ const g = (_b = n.g) !== null && _b !== void 0 ? _b : 0;
99
+ const b = (_c = n.b) !== null && _c !== void 0 ? _c : 0;
100
+ // Perceptual luminance weights (ITU-R BT.709)
101
+ const gray = Math.round(0.2126 * r + 0.7152 * g + 0.0722 * b);
102
+ return (0, spaces_js_1.rgbToHex)({ r: gray, g: gray, b: gray });
103
+ }
104
+ function _lerpHue(h1, h2, t, mode = 'shorter') {
105
+ let d = h2 - h1;
106
+ if (mode === 'shorter') {
107
+ if (d > 180)
108
+ d -= 360;
109
+ else if (d < -180)
110
+ d += 360;
111
+ }
112
+ else if (mode === 'longer') {
113
+ if (d > 0 && d < 180)
114
+ d -= 360;
115
+ else if (d < 0 && d > -180)
116
+ d += 360;
117
+ }
118
+ else if (mode === 'increasing') {
119
+ if (d < 0)
120
+ d += 360;
121
+ }
122
+ else if (mode === 'decreasing') {
123
+ if (d > 0)
124
+ d -= 360;
125
+ }
126
+ return h1 + d * t;
127
+ }
128
+ function _formatMixResult(r, g, b, a, out) {
129
+ if (out === 'hex')
130
+ return (0, spaces_js_1.rgbToHex)({ r: Math.round(r), g: Math.round(g), b: Math.round(b) });
131
+ if (out === 'rgba')
132
+ return (0, spaces_js_1.rgbToRgbaString)({ r: Math.round(r), g: Math.round(g), b: Math.round(b) }, a);
133
+ if (out === 'rgb')
134
+ return `rgb(${Math.round(r)}, ${Math.round(g)}, ${Math.round(b)})`;
135
+ if (out === 'hsl') {
136
+ const [hh, ss, ll] = (0, spaces_js_1.rgbToHsl)({ r: Math.round(r), g: Math.round(g), b: Math.round(b) });
137
+ return `hsl(${hh}, ${ss}%, ${ll}%)`;
138
+ }
139
+ return (0, spaces_js_1.rgbToHex)({ r: Math.round(r), g: Math.round(g), b: Math.round(b) });
140
+ }
141
+ function mixColors(c1, c2, t, opts) {
142
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35;
143
+ const o1 = (0, parse_js_1.normalizeColor)(c1);
144
+ const o2 = (0, parse_js_1.normalizeColor)(c2);
145
+ t = Math.max(0, Math.min(1, t));
146
+ const mode = (opts === null || opts === void 0 ? void 0 : opts.mode) || 'rgb';
147
+ const out = (opts === null || opts === void 0 ? void 0 : opts.format) || 'hex';
148
+ const hueMode = (_a = opts === null || opts === void 0 ? void 0 : opts.hueInterpolation) !== null && _a !== void 0 ? _a : 'shorter';
149
+ let r = 0, g = 0, b = 0, a = 1;
150
+ if (mode === 'hsl') {
151
+ const h1 = (_b = o1.h) !== null && _b !== void 0 ? _b : (0, spaces_js_1.rgbToHsl)({ r: (_c = o1.r) !== null && _c !== void 0 ? _c : 0, g: (_d = o1.g) !== null && _d !== void 0 ? _d : 0, b: (_e = o1.b) !== null && _e !== void 0 ? _e : 0 })[0];
152
+ const s1 = (_f = o1.s) !== null && _f !== void 0 ? _f : 0;
153
+ const l1 = (_g = o1.l) !== null && _g !== void 0 ? _g : 0;
154
+ const h2 = (_h = o2.h) !== null && _h !== void 0 ? _h : (0, spaces_js_1.rgbToHsl)({ r: (_j = o2.r) !== null && _j !== void 0 ? _j : 0, g: (_k = o2.g) !== null && _k !== void 0 ? _k : 0, b: (_l = o2.b) !== null && _l !== void 0 ? _l : 0 })[0];
155
+ const s2 = (_m = o2.s) !== null && _m !== void 0 ? _m : 0;
156
+ const l2 = (_o = o2.l) !== null && _o !== void 0 ? _o : 0;
157
+ const ih = _lerpHue(h1, h2, t, hueMode);
158
+ const rgb = (0, spaces_js_1.hslToRgb)(ih, s1 + (s2 - s1) * t, l1 + (l2 - l1) * t);
159
+ r = rgb.r;
160
+ g = rgb.g;
161
+ b = rgb.b;
162
+ a = ((_p = o1.a) !== null && _p !== void 0 ? _p : 1) + (((_q = o2.a) !== null && _q !== void 0 ? _q : 1) - ((_r = o1.a) !== null && _r !== void 0 ? _r : 1)) * t;
163
+ }
164
+ else if (mode === 'lab') {
165
+ const lab1 = (0, spaces_js_1.rgbToLab)({ r: (_s = o1.r) !== null && _s !== void 0 ? _s : 0, g: (_t = o1.g) !== null && _t !== void 0 ? _t : 0, b: (_u = o1.b) !== null && _u !== void 0 ? _u : 0 });
166
+ const lab2 = (0, spaces_js_1.rgbToLab)({ r: (_v = o2.r) !== null && _v !== void 0 ? _v : 0, g: (_w = o2.g) !== null && _w !== void 0 ? _w : 0, b: (_x = o2.b) !== null && _x !== void 0 ? _x : 0 });
167
+ const mixed = (0, spaces_js_1.labToRgb)({
168
+ L: lab1.L + (lab2.L - lab1.L) * t,
169
+ a: lab1.a + (lab2.a - lab1.a) * t,
170
+ b: lab1.b + (lab2.b - lab1.b) * t,
171
+ });
172
+ r = mixed.r;
173
+ g = mixed.g;
174
+ b = mixed.b;
175
+ a = ((_y = o1.a) !== null && _y !== void 0 ? _y : 1) + (((_z = o2.a) !== null && _z !== void 0 ? _z : 1) - ((_0 = o1.a) !== null && _0 !== void 0 ? _0 : 1)) * t;
176
+ }
177
+ else if (mode === 'lch') {
178
+ const lch1 = (0, spaces_js_1.rgbToLch)({ r: (_1 = o1.r) !== null && _1 !== void 0 ? _1 : 0, g: (_2 = o1.g) !== null && _2 !== void 0 ? _2 : 0, b: (_3 = o1.b) !== null && _3 !== void 0 ? _3 : 0 });
179
+ const lch2 = (0, spaces_js_1.rgbToLch)({ r: (_4 = o2.r) !== null && _4 !== void 0 ? _4 : 0, g: (_5 = o2.g) !== null && _5 !== void 0 ? _5 : 0, b: (_6 = o2.b) !== null && _6 !== void 0 ? _6 : 0 });
180
+ const mixed = (0, spaces_js_1.lchToRgb)({
181
+ L: lch1.L + (lch2.L - lch1.L) * t,
182
+ C: lch1.C + (lch2.C - lch1.C) * t,
183
+ H: _lerpHue(lch1.H, lch2.H, t, hueMode),
184
+ });
185
+ r = mixed.r;
186
+ g = mixed.g;
187
+ b = mixed.b;
188
+ a = ((_7 = o1.a) !== null && _7 !== void 0 ? _7 : 1) + (((_8 = o2.a) !== null && _8 !== void 0 ? _8 : 1) - ((_9 = o1.a) !== null && _9 !== void 0 ? _9 : 1)) * t;
189
+ }
190
+ else if (mode === 'oklab') {
191
+ const ok1 = (0, spaces_js_1.rgbToOklab)({ r: (_10 = o1.r) !== null && _10 !== void 0 ? _10 : 0, g: (_11 = o1.g) !== null && _11 !== void 0 ? _11 : 0, b: (_12 = o1.b) !== null && _12 !== void 0 ? _12 : 0 });
192
+ const ok2 = (0, spaces_js_1.rgbToOklab)({ r: (_13 = o2.r) !== null && _13 !== void 0 ? _13 : 0, g: (_14 = o2.g) !== null && _14 !== void 0 ? _14 : 0, b: (_15 = o2.b) !== null && _15 !== void 0 ? _15 : 0 });
193
+ const mixed = (0, spaces_js_1.oklabToRgb)({
194
+ L: ok1.L + (ok2.L - ok1.L) * t,
195
+ a: ok1.a + (ok2.a - ok1.a) * t,
196
+ b: ok1.b + (ok2.b - ok1.b) * t,
197
+ });
198
+ r = mixed.r;
199
+ g = mixed.g;
200
+ b = mixed.b;
201
+ a = ((_16 = o1.a) !== null && _16 !== void 0 ? _16 : 1) + (((_17 = o2.a) !== null && _17 !== void 0 ? _17 : 1) - ((_18 = o1.a) !== null && _18 !== void 0 ? _18 : 1)) * t;
202
+ }
203
+ else if (mode === 'oklch') {
204
+ const ok1 = (0, spaces_js_1.rgbToOklch)({ r: (_19 = o1.r) !== null && _19 !== void 0 ? _19 : 0, g: (_20 = o1.g) !== null && _20 !== void 0 ? _20 : 0, b: (_21 = o1.b) !== null && _21 !== void 0 ? _21 : 0 });
205
+ const ok2 = (0, spaces_js_1.rgbToOklch)({ r: (_22 = o2.r) !== null && _22 !== void 0 ? _22 : 0, g: (_23 = o2.g) !== null && _23 !== void 0 ? _23 : 0, b: (_24 = o2.b) !== null && _24 !== void 0 ? _24 : 0 });
206
+ const mixed = (0, spaces_js_1.oklchToRgb)({
207
+ L: ok1.L + (ok2.L - ok1.L) * t,
208
+ C: ok1.C + (ok2.C - ok1.C) * t,
209
+ H: _lerpHue(ok1.H, ok2.H, t, hueMode),
210
+ });
211
+ r = mixed.r;
212
+ g = mixed.g;
213
+ b = mixed.b;
214
+ a = ((_25 = o1.a) !== null && _25 !== void 0 ? _25 : 1) + (((_26 = o2.a) !== null && _26 !== void 0 ? _26 : 1) - ((_27 = o1.a) !== null && _27 !== void 0 ? _27 : 1)) * t;
215
+ }
216
+ else {
217
+ r = ((_28 = o1.r) !== null && _28 !== void 0 ? _28 : 0) * (1 - t) + ((_29 = o2.r) !== null && _29 !== void 0 ? _29 : 0) * t;
218
+ g = ((_30 = o1.g) !== null && _30 !== void 0 ? _30 : 0) * (1 - t) + ((_31 = o2.g) !== null && _31 !== void 0 ? _31 : 0) * t;
219
+ b = ((_32 = o1.b) !== null && _32 !== void 0 ? _32 : 0) * (1 - t) + ((_33 = o2.b) !== null && _33 !== void 0 ? _33 : 0) * t;
220
+ a = ((_34 = o1.a) !== null && _34 !== void 0 ? _34 : 1) * (1 - t) + ((_35 = o2.a) !== null && _35 !== void 0 ? _35 : 1) * t;
221
+ }
222
+ return _formatMixResult(r, g, b, a, out);
223
+ }
@@ -0,0 +1,40 @@
1
+ export declare function complement(color: string): string;
2
+ export declare function triadic(color: string): [string, string, string];
3
+ export declare function analogous(color: string, angle?: number): [string, string, string];
4
+ export declare function splitComplementary(color: string): [string, string, string];
5
+ export declare function tetradic(color: string): [string, string, string, string];
6
+ export declare function colorShades(color: string, steps?: number): string[];
7
+ export declare function monochromatic(color: string, steps?: number): string[];
8
+ export declare function randomColor(options?: {
9
+ hRange?: [number, number];
10
+ sRange?: [number, number];
11
+ lRange?: [number, number];
12
+ }): string;
13
+ export declare function interpolateColors(color1: string, color2: string, steps: number, options?: {
14
+ space?: 'rgb' | 'hsl' | 'lab' | 'lch' | 'oklab' | 'oklch';
15
+ format?: 'hex' | 'rgb' | 'rgba' | 'hsl';
16
+ hueInterpolation?: 'shorter' | 'longer' | 'increasing' | 'decreasing';
17
+ }): string[];
18
+ export declare function createColorScale(anchors: string[] | Array<{
19
+ color: string;
20
+ position?: number;
21
+ }>, steps: number, options?: {
22
+ space?: 'rgb' | 'hsl' | 'oklab' | 'oklch';
23
+ format?: 'hex' | 'rgb' | 'hsl';
24
+ }): string[];
25
+ export declare function midpointColor(color1: string, color2: string, options?: {
26
+ space?: 'lab' | 'lch' | 'oklab' | 'oklch';
27
+ }): string;
28
+ export declare function tints(color: string, steps?: number): string[];
29
+ export declare function shades(color: string, steps?: number): string[];
30
+ export declare function tones(color: string, steps?: number, gray?: string): string[];
31
+ export declare function generateGradientColors(start: string, end: string, steps: number, options?: {
32
+ mode?: 'rgb' | 'hsl' | 'oklab' | 'oklch';
33
+ format?: 'hex' | 'rgb' | 'hsl';
34
+ }): Generator<string>;
35
+ export declare function generateTints(color: string, steps: number, options?: {
36
+ format?: 'hex' | 'rgb' | 'hsl';
37
+ }): Generator<string>;
38
+ export declare function generateShades(color: string, steps: number, options?: {
39
+ format?: 'hex' | 'rgb' | 'hsl';
40
+ }): Generator<string>;
@@ -0,0 +1,164 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.complement = complement;
4
+ exports.triadic = triadic;
5
+ exports.analogous = analogous;
6
+ exports.splitComplementary = splitComplementary;
7
+ exports.tetradic = tetradic;
8
+ exports.colorShades = colorShades;
9
+ exports.monochromatic = monochromatic;
10
+ exports.randomColor = randomColor;
11
+ exports.interpolateColors = interpolateColors;
12
+ exports.createColorScale = createColorScale;
13
+ exports.midpointColor = midpointColor;
14
+ exports.tints = tints;
15
+ exports.shades = shades;
16
+ exports.tones = tones;
17
+ exports.generateGradientColors = generateGradientColors;
18
+ exports.generateTints = generateTints;
19
+ exports.generateShades = generateShades;
20
+ // Harmonies, scales, tints/shades and color generators.
21
+ const parse_js_1 = require("./parse.js");
22
+ const spaces_js_1 = require("./convert/spaces.js");
23
+ const manipulate_js_1 = require("./manipulate.js");
24
+ function complement(color) {
25
+ var _a;
26
+ return (0, manipulate_js_1.rotateHue)((_a = (0, parse_js_1.normalizeColor)(color).hex) !== null && _a !== void 0 ? _a : '#000000', 180);
27
+ }
28
+ function triadic(color) {
29
+ var _a;
30
+ const hex = (_a = (0, parse_js_1.normalizeColor)(color).hex) !== null && _a !== void 0 ? _a : '#000000';
31
+ return [hex, (0, manipulate_js_1.rotateHue)(hex, 120), (0, manipulate_js_1.rotateHue)(hex, 240)];
32
+ }
33
+ function analogous(color, angle = 30) {
34
+ var _a;
35
+ const hex = (_a = (0, parse_js_1.normalizeColor)(color).hex) !== null && _a !== void 0 ? _a : '#000000';
36
+ return [(0, manipulate_js_1.rotateHue)(hex, -angle), hex, (0, manipulate_js_1.rotateHue)(hex, angle)];
37
+ }
38
+ function splitComplementary(color) {
39
+ var _a;
40
+ const hex = (_a = (0, parse_js_1.normalizeColor)(color).hex) !== null && _a !== void 0 ? _a : '#000000';
41
+ return [hex, (0, manipulate_js_1.rotateHue)(hex, 150), (0, manipulate_js_1.rotateHue)(hex, 210)];
42
+ }
43
+ function tetradic(color) {
44
+ var _a;
45
+ const hex = (_a = (0, parse_js_1.normalizeColor)(color).hex) !== null && _a !== void 0 ? _a : '#000000';
46
+ return [hex, (0, manipulate_js_1.rotateHue)(hex, 90), (0, manipulate_js_1.rotateHue)(hex, 180), (0, manipulate_js_1.rotateHue)(hex, 270)];
47
+ }
48
+ function colorShades(color, steps = 9) {
49
+ var _a, _b, _c;
50
+ const n = (0, parse_js_1.normalizeColor)(color);
51
+ const h = (_a = n.h) !== null && _a !== void 0 ? _a : 0;
52
+ const s = (_b = n.s) !== null && _b !== void 0 ? _b : 0;
53
+ // steps - 1 === 0 below would otherwise divide by zero (NaN lightness, then
54
+ // a literal "#NaNNaNNaN" hex string) — a single shade is just the color's
55
+ // own lightness, same idea as interpolateColors() returning the midpoint
56
+ // for a 2-color, 1-step request.
57
+ if (steps <= 1)
58
+ return steps === 1 ? [(0, spaces_js_1.hslToHex)(h, s, (_c = n.l) !== null && _c !== void 0 ? _c : 50)] : [];
59
+ const result = [];
60
+ for (let i = 0; i < steps; i++) {
61
+ const l = Math.round(100 - (i / (steps - 1)) * 100);
62
+ result.push((0, spaces_js_1.hslToHex)(h, s, l));
63
+ }
64
+ return result;
65
+ }
66
+ function monochromatic(color, steps = 5) {
67
+ var _a, _b, _c;
68
+ const n = (0, parse_js_1.normalizeColor)(color);
69
+ const h = (_a = n.h) !== null && _a !== void 0 ? _a : 0;
70
+ const l = (_b = n.l) !== null && _b !== void 0 ? _b : 50;
71
+ // Same steps === 1 divide-by-zero guard as colorShades() above.
72
+ if (steps <= 1)
73
+ return steps === 1 ? [(0, spaces_js_1.hslToHex)(h, (_c = n.s) !== null && _c !== void 0 ? _c : 0, l)] : [];
74
+ const result = [];
75
+ for (let i = 0; i < steps; i++) {
76
+ const s = Math.round((i / (steps - 1)) * 100);
77
+ result.push((0, spaces_js_1.hslToHex)(h, s, l));
78
+ }
79
+ return result;
80
+ }
81
+ function randomColor(options) {
82
+ var _a, _b, _c;
83
+ const [hMin, hMax] = (_a = options === null || options === void 0 ? void 0 : options.hRange) !== null && _a !== void 0 ? _a : [0, 360];
84
+ const [sMin, sMax] = (_b = options === null || options === void 0 ? void 0 : options.sRange) !== null && _b !== void 0 ? _b : [40, 90];
85
+ const [lMin, lMax] = (_c = options === null || options === void 0 ? void 0 : options.lRange) !== null && _c !== void 0 ? _c : [30, 70];
86
+ const h = Math.floor(Math.random() * (hMax - hMin)) + hMin;
87
+ const s = Math.floor(Math.random() * (sMax - sMin)) + sMin;
88
+ const l = Math.floor(Math.random() * (lMax - lMin)) + lMin;
89
+ return (0, spaces_js_1.hslToHex)(h, s, l);
90
+ }
91
+ // ─── Interpolation ─────────────────────────────────────────────────
92
+ function interpolateColors(color1, color2, steps, options) {
93
+ if (steps < 2)
94
+ return steps === 1 ? [(0, manipulate_js_1.mixColors)(color1, color2, 0.5, options)] : [];
95
+ const result = [];
96
+ for (let i = 0; i < steps; i++) {
97
+ result.push((0, manipulate_js_1.mixColors)(color1, color2, i / (steps - 1), options));
98
+ }
99
+ return result;
100
+ }
101
+ function createColorScale(anchors, steps, options) {
102
+ const normalized = anchors.map((a, i, arr) => {
103
+ var _a;
104
+ return ({
105
+ color: typeof a === 'string' ? a : a.color,
106
+ position: typeof a === 'string'
107
+ ? i / Math.max(arr.length - 1, 1)
108
+ : ((_a = a.position) !== null && _a !== void 0 ? _a : i / Math.max(arr.length - 1, 1)),
109
+ });
110
+ });
111
+ normalized.sort((a, b) => a.position - b.position);
112
+ const result = [];
113
+ for (let i = 0; i < steps; i++) {
114
+ const t = steps === 1 ? 0 : i / (steps - 1);
115
+ let lo = normalized[0], hi = normalized[normalized.length - 1];
116
+ for (let j = 0; j < normalized.length - 1; j++) {
117
+ if (t >= normalized[j].position && t <= normalized[j + 1].position) {
118
+ lo = normalized[j];
119
+ hi = normalized[j + 1];
120
+ break;
121
+ }
122
+ }
123
+ const span = hi.position - lo.position;
124
+ const localT = span === 0 ? 0 : (t - lo.position) / span;
125
+ result.push((0, manipulate_js_1.mixColors)(lo.color, hi.color, localT, options));
126
+ }
127
+ return result;
128
+ }
129
+ function midpointColor(color1, color2, options) {
130
+ var _a;
131
+ return (0, manipulate_js_1.mixColors)(color1, color2, 0.5, { mode: (_a = options === null || options === void 0 ? void 0 : options.space) !== null && _a !== void 0 ? _a : 'oklab' });
132
+ }
133
+ // ─── Tints / Shades / Tones ───────────────────────────────────────
134
+ function tints(color, steps = 5) {
135
+ return interpolateColors(color, '#ffffff', steps, { space: 'oklab' });
136
+ }
137
+ function shades(color, steps = 5) {
138
+ return interpolateColors(color, '#000000', steps, { space: 'oklab' });
139
+ }
140
+ function tones(color, steps = 5, gray = '#808080') {
141
+ return interpolateColors(color, gray, steps, { space: 'oklab' });
142
+ }
143
+ // ─── Generator functions ────────────────────────────────────────
144
+ function* generateGradientColors(start, end, steps, options) {
145
+ for (let i = 0; i < steps; i++) {
146
+ yield (0, manipulate_js_1.mixColors)(start, end, steps === 1 ? 0 : i / (steps - 1), options);
147
+ }
148
+ }
149
+ function* generateTints(color, steps, options) {
150
+ for (let i = 0; i < steps; i++) {
151
+ yield (0, manipulate_js_1.mixColors)(color, '#ffffff', steps === 1 ? 0 : i / (steps - 1), {
152
+ mode: 'oklab',
153
+ ...options,
154
+ });
155
+ }
156
+ }
157
+ function* generateShades(color, steps, options) {
158
+ for (let i = 0; i < steps; i++) {
159
+ yield (0, manipulate_js_1.mixColors)(color, '#000000', steps === 1 ? 0 : i / (steps - 1), {
160
+ mode: 'oklab',
161
+ ...options,
162
+ });
163
+ }
164
+ }