toosoon-utils 1.0.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/.prettierrc ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "semi": true,
3
+ "singleQuote": true,
4
+ "printWidth": 120,
5
+ "trailingComma": "none",
6
+ "endOfLine": "auto"
7
+ }
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 TOOSOON
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,147 @@
1
+ /**
2
+ * Normalize hexadecimal string
3
+ *
4
+ * @param {string} hex Hexadecimal string
5
+ * @returns {string} Normalized hexadecimal string
6
+ */
7
+ export declare function normalizeHexString(hex: string): string;
8
+ /**
9
+ * Convert RGB color to hexadecimal
10
+ * Note: rgb values are contained in the interval [0, 1]
11
+ *
12
+ * @param {[number, number, number]} rgb RGB color
13
+ * @returns {number} Hexadecimal color
14
+ */
15
+ export declare function rgbToHex([r, g, b]: [number, number, number]): number;
16
+ /**
17
+ * Convert RGB color to hexadecimal string
18
+ * Note: rgb values are contained in the interval [0, 1]
19
+ *
20
+ * @param {[number, number, number]} rgb RGB color
21
+ * @returns {string} Hexadecimal string
22
+ */
23
+ export declare function rgbToHexString([r, g, b]: [number, number, number]): string;
24
+ /**
25
+ * Convert hexadecimal color to RGB
26
+ * Note: rgb values are contained in the interval [0, 1]
27
+ *
28
+ * @param {(number|string)} hex Hexadecimal color
29
+ * @returns {[number, number, number]} RGB color
30
+ */
31
+ export declare function hexToRgb(hex: number | string): [number, number, number];
32
+ /**
33
+ * Lighten a color
34
+ *
35
+ * @param {string} hex Hexadecimal string
36
+ * @param {number} [amount=0] Amount of the color offset
37
+ * @returns {string} Computed hexadecimal
38
+ */
39
+ export declare function lighten(hex: string, amount?: number): string;
40
+ /**
41
+ * Darken a color
42
+ *
43
+ * @param {string} hex Hexadecimal string
44
+ * @param {number} [amount=0] Amount of the color offset
45
+ * @returns {string} Computed hexadecimal
46
+ */
47
+ export declare function darken(hex: string, amount?: number): string;
48
+ /**
49
+ * Normalize HSL string
50
+ * Note: hsl values are contained in the intervals H: [0, 360], S: [0, 1], L: [0, 1]
51
+ *
52
+ * @param {string} hsl HSL string (format: 'hsl(360, 100%, 100%)')
53
+ * @returns {[number, number, number]} Normalized HSL color
54
+ */
55
+ export declare function normalizeHslString(hsl: string): [number, number, number];
56
+ /**
57
+ * Convert RGB color to HSL color
58
+ * Notes:
59
+ * - rgb values are contained in the interval [0, 1]
60
+ * - hsl values are contained in the intervals H: [0, 360], S: [0, 1], L: [0, 1]
61
+ *
62
+ * @param {[number, number, number]} rgb RGB color
63
+ * @returns {[number, number, number]} HSL color
64
+ */
65
+ export declare function rgbToHsl([r, g, b]: [number, number, number]): [number, number, number];
66
+ /**
67
+ * Convert HSL color to RGB color
68
+ * Notes:
69
+ * - rgb values are contained in the interval [0, 1]
70
+ * - hsl values are contained in the intervals H: [0, 360], S: [0, 1], L: [0, 1]
71
+ *
72
+ * @param {[number, number, number]} hsl HSL color
73
+ * @returns {[number, number, number]} RGB color
74
+ */
75
+ export declare function hslToRgb([h, s, l]: [number, number, number]): [number, number, number];
76
+ /**
77
+ * Convert RGB color to HSB color
78
+ * Notes:
79
+ * - rgb values are contained in the interval [0, 1]
80
+ * - hsb values are contained in the intervals H: [0, 360], S: [0, 1], B: [0, 1]
81
+ *
82
+ * @param {[number, number, number]} rgb RGB color
83
+ * @returns {[number, number, number]} HSB color
84
+ */
85
+ export declare function rgbToHsb([r, g, b]: [number, number, number]): [number, number, number];
86
+ /**
87
+ * Convert HSB color to RGB color
88
+ * Notes:
89
+ * - rgb values are contained in the interval [0, 1]
90
+ * - hsb values are contained in the intervals H: [0, 360], S: [0, 1], B: [0, 1]
91
+ *
92
+ * @param {[number, number, number]} hsb HSB color
93
+ * @returns {[number, number, number]} RGB color
94
+ */
95
+ export declare function hsbToRgb([h, s, b]: [number, number, number]): [number, number, number];
96
+ /**
97
+ * Convert LAB color space to HCL color
98
+ * -> http://www.brucelindbloom.com/index.html?Eqn_Lab_to_LCH.html
99
+ *
100
+ * @param {[number, number, number]} lab LAB color
101
+ * @returns {[number, number, number]} HCL color
102
+ */
103
+ export declare function labToHcl([l, a, b]: [number, number, number]): [number, number, number];
104
+ /**
105
+ * Convert HCL color space color space to LAB color
106
+ * -> http://www.brucelindbloom.com/index.html?Eqn_LCH_to_Lab.html
107
+ *
108
+ * @param {[number, number, number]} hcl HCL color
109
+ * @returns {[number, number, number]} LAB color space
110
+ */
111
+ export declare function hclToLab([h, c, l]: [number, number, number]): [number, number, number];
112
+ /**
113
+ * Converts LAB color to RGB
114
+ *
115
+ * @param {[number, number, number]} lab LAB color
116
+ * @returns {[number, number, number]} RGB color
117
+ */
118
+ export declare function labToRgb([l, a, b]: [number, number, number]): [number, number, number];
119
+ /**
120
+ * Converts RGB color to Lab color
121
+ *
122
+ * @param {[number, number, number]} rgb RGB color
123
+ * @returns {[number, number, number]} LAB color
124
+ */
125
+ export declare function rgbToLab([r, g, b]: [number, number, number]): [number, number, number];
126
+ /**
127
+ * Get the delta from two LAB colors
128
+ *
129
+ * @param {[number, number, number]} labA First LAB color
130
+ * @param {[number, number, number]} labB Second LAB color
131
+ * @returns {number} Delta
132
+ */
133
+ export declare function deltaE(labA: [number, number, number], labB: [number, number, number]): number;
134
+ /**
135
+ * Converts RGB color to HCL color
136
+ *
137
+ * @param {[number, number, number]} rgb RGB color
138
+ * @returns {[number, number, number]} HCL color
139
+ */
140
+ export declare function rgbToHcl([r, g, b]: [number, number, number]): [number, number, number];
141
+ /**
142
+ * Converts HCL color to RGB color
143
+ *
144
+ * @param {[number, number, number]} hcl RGB color
145
+ * @returns {[number, number, number]} RGB color
146
+ */
147
+ export declare function hclToRgb([h, c, l]: [number, number, number]): [number, number, number];
package/lib/colors.js ADDED
@@ -0,0 +1,372 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hclToRgb = exports.rgbToHcl = exports.deltaE = exports.rgbToLab = exports.labToRgb = exports.hclToLab = exports.labToHcl = exports.hsbToRgb = exports.rgbToHsb = exports.hslToRgb = exports.rgbToHsl = exports.normalizeHslString = exports.darken = exports.lighten = exports.hexToRgb = exports.rgbToHexString = exports.rgbToHex = exports.normalizeHexString = void 0;
4
+ var geometry_1 = require("./geometry");
5
+ var maths_1 = require("./maths");
6
+ // ******************************************
7
+ // RGB & Hexadecimal color spaces
8
+ // ******************************************
9
+ /**
10
+ * Normalize hexadecimal string
11
+ *
12
+ * @param {string} hex Hexadecimal string
13
+ * @returns {string} Normalized hexadecimal string
14
+ */
15
+ function normalizeHexString(hex) {
16
+ var match;
17
+ var result = '000000';
18
+ hex = hex.toLocaleLowerCase();
19
+ if ((match = hex.match(/(#|0x)?([a-f0-9]{6})/i))) {
20
+ result = match[2];
21
+ }
22
+ else if ((match = hex.match(/^#?([a-f0-9])([a-f0-9])([a-f0-9])$/i))) {
23
+ result = match[1] + match[1] + match[2] + match[2] + match[3] + match[3];
24
+ }
25
+ else if ((match = hex.match(/rgb\(\s*(\d*)\s*,\s*(\d*)\s*,\s*(\d*)\s*\)/))) {
26
+ result =
27
+ parseInt(match[1]).toString(16).padStart(2, '0') +
28
+ parseInt(match[2]).toString(16).padStart(2, '0') +
29
+ parseInt(match[3]).toString(16).padStart(2, '0');
30
+ }
31
+ return "#".concat(result);
32
+ }
33
+ exports.normalizeHexString = normalizeHexString;
34
+ /**
35
+ * Convert RGB color to hexadecimal
36
+ * Note: rgb values are contained in the interval [0, 1]
37
+ *
38
+ * @param {[number, number, number]} rgb RGB color
39
+ * @returns {number} Hexadecimal color
40
+ */
41
+ function rgbToHex(_a) {
42
+ var r = _a[0], g = _a[1], b = _a[2];
43
+ return ((r * 255) << 16) ^ ((g * 255) << 8) ^ ((b * 255) << 0);
44
+ }
45
+ exports.rgbToHex = rgbToHex;
46
+ /**
47
+ * Convert RGB color to hexadecimal string
48
+ * Note: rgb values are contained in the interval [0, 1]
49
+ *
50
+ * @param {[number, number, number]} rgb RGB color
51
+ * @returns {string} Hexadecimal string
52
+ */
53
+ function rgbToHexString(_a) {
54
+ var r = _a[0], g = _a[1], b = _a[2];
55
+ var red = (0, maths_1.clamp)(Math.round(r * 255), 0, 255);
56
+ var green = (0, maths_1.clamp)(Math.round(g * 255), 0, 255);
57
+ var blue = (0, maths_1.clamp)(Math.round(b * 255), 0, 255);
58
+ var result = (blue | (green << 8) | (red << 16) | (1 << 24)).toString(16).slice(1);
59
+ return "#".concat(result);
60
+ }
61
+ exports.rgbToHexString = rgbToHexString;
62
+ /**
63
+ * Convert hexadecimal color to RGB
64
+ * Note: rgb values are contained in the interval [0, 1]
65
+ *
66
+ * @param {(number|string)} hex Hexadecimal color
67
+ * @returns {[number, number, number]} RGB color
68
+ */
69
+ function hexToRgb(hex) {
70
+ if (typeof hex === 'number') {
71
+ hex = Math.floor(hex);
72
+ }
73
+ else if (typeof hex === 'string') {
74
+ hex = normalizeHexString(hex).replace(/^#/, '');
75
+ hex = parseInt(hex, 16);
76
+ }
77
+ var red = ((hex >> 16) & 255) / 255;
78
+ var green = ((hex >> 8) & 255) / 255;
79
+ var blue = (hex & 255) / 255;
80
+ return [red, green, blue];
81
+ }
82
+ exports.hexToRgb = hexToRgb;
83
+ /**
84
+ * Lighten a color
85
+ *
86
+ * @param {string} hex Hexadecimal string
87
+ * @param {number} [amount=0] Amount of the color offset
88
+ * @returns {string} Computed hexadecimal
89
+ */
90
+ function lighten(hex, amount) {
91
+ if (amount === void 0) { amount = 0; }
92
+ var prefix = '';
93
+ if (hex[0] === '#') {
94
+ hex = hex.slice(1);
95
+ prefix = '#';
96
+ }
97
+ var value = parseInt(hex, 16);
98
+ var r = (value >> 16) + amount;
99
+ r = (0, maths_1.clamp)(r, 0, 255);
100
+ var b = ((value >> 8) & 0x00ff) + amount;
101
+ b = (0, maths_1.clamp)(b, 0, 255);
102
+ var g = (value & 0x0000ff) + amount;
103
+ g = (0, maths_1.clamp)(g, 0, 255);
104
+ var result = g | (b << 8) | (r << 16);
105
+ if (r === 0 && g === 0 && b === 0 && amount !== 0) {
106
+ result = '000000';
107
+ }
108
+ return prefix + result.toString(16);
109
+ }
110
+ exports.lighten = lighten;
111
+ /**
112
+ * Darken a color
113
+ *
114
+ * @param {string} hex Hexadecimal string
115
+ * @param {number} [amount=0] Amount of the color offset
116
+ * @returns {string} Computed hexadecimal
117
+ */
118
+ function darken(hex, amount) {
119
+ if (amount === void 0) { amount = 0; }
120
+ return lighten(hex, -amount);
121
+ }
122
+ exports.darken = darken;
123
+ // ***************************************************
124
+ // RGB & Hue-Saturation-Lightness (HSL) color spaces
125
+ // ***************************************************
126
+ /**
127
+ * Normalize HSL string
128
+ * Note: hsl values are contained in the intervals H: [0, 360], S: [0, 1], L: [0, 1]
129
+ *
130
+ * @param {string} hsl HSL string (format: 'hsl(360, 100%, 100%)')
131
+ * @returns {[number, number, number]} Normalized HSL color
132
+ */
133
+ function normalizeHslString(hsl) {
134
+ var _a, _b;
135
+ var _c = (_b = (_a = hsl.match(/\d+/g)) === null || _a === void 0 ? void 0 : _a.map(Number)) !== null && _b !== void 0 ? _b : [0, 0, 0], hue = _c[0], saturation = _c[1], lightness = _c[2];
136
+ return [hue, saturation / 100, lightness / 100];
137
+ }
138
+ exports.normalizeHslString = normalizeHslString;
139
+ /**
140
+ * Convert RGB color to HSL color
141
+ * Notes:
142
+ * - rgb values are contained in the interval [0, 1]
143
+ * - hsl values are contained in the intervals H: [0, 360], S: [0, 1], L: [0, 1]
144
+ *
145
+ * @param {[number, number, number]} rgb RGB color
146
+ * @returns {[number, number, number]} HSL color
147
+ */
148
+ function rgbToHsl(_a) {
149
+ var r = _a[0], g = _a[1], b = _a[2];
150
+ var l = Math.max(r, g, b);
151
+ var s = l - Math.min(r, g, b);
152
+ var h = s ? (l === r ? (g - b) / s : l === g ? 2 + (b - r) / s : 4 + (r - g) / s) : 0;
153
+ return [
154
+ 60 * h < 0 ? 60 * h + 360 : 60 * h,
155
+ s ? (l <= 0.5 ? s / (2 * l - s) : s / (2 - (2 * l - s))) : 0,
156
+ (2 * l - s) / 2
157
+ ];
158
+ }
159
+ exports.rgbToHsl = rgbToHsl;
160
+ /**
161
+ * Convert HSL color to RGB color
162
+ * Notes:
163
+ * - rgb values are contained in the interval [0, 1]
164
+ * - hsl values are contained in the intervals H: [0, 360], S: [0, 1], L: [0, 1]
165
+ *
166
+ * @param {[number, number, number]} hsl HSL color
167
+ * @returns {[number, number, number]} RGB color
168
+ */
169
+ function hslToRgb(_a) {
170
+ var h = _a[0], s = _a[1], l = _a[2];
171
+ var a = s * Math.min(l, 1 - l);
172
+ var k = function (v) { return (v + h / 30) % 12; };
173
+ var f = function (v) { return l - a * Math.max(-1, Math.min(k(v) - 3, Math.min(9 - k(v), 1))); };
174
+ return [f(0), f(8), f(4)];
175
+ }
176
+ exports.hslToRgb = hslToRgb;
177
+ // ***************************************************
178
+ // RGB & Hue-Saturation-Brightness (HSB) color spaces
179
+ // ***************************************************
180
+ /**
181
+ * Convert RGB color to HSB color
182
+ * Notes:
183
+ * - rgb values are contained in the interval [0, 1]
184
+ * - hsb values are contained in the intervals H: [0, 360], S: [0, 1], B: [0, 1]
185
+ *
186
+ * @param {[number, number, number]} rgb RGB color
187
+ * @returns {[number, number, number]} HSB color
188
+ */
189
+ function rgbToHsb(_a) {
190
+ var r = _a[0], g = _a[1], b = _a[2];
191
+ var max = Math.max(r, g, b);
192
+ var min = Math.min(r, g, b);
193
+ var delta = max - min;
194
+ var h = delta === 0 ? 0 : delta && max === r ? (g - b) / delta : max === g ? 2 + (b - r) / delta : 4 + (r - g) / delta;
195
+ return [60 * (h < 0 ? h + 6 : h), max && delta / max, max];
196
+ }
197
+ exports.rgbToHsb = rgbToHsb;
198
+ /**
199
+ * Convert HSB color to RGB color
200
+ * Notes:
201
+ * - rgb values are contained in the interval [0, 1]
202
+ * - hsb values are contained in the intervals H: [0, 360], S: [0, 1], B: [0, 1]
203
+ *
204
+ * @param {[number, number, number]} hsb HSB color
205
+ * @returns {[number, number, number]} RGB color
206
+ */
207
+ function hsbToRgb(_a) {
208
+ var h = _a[0], s = _a[1], b = _a[2];
209
+ var k = function (v) { return (v + h / 60) % 6; };
210
+ var f = function (v) { return b * (1 - s * Math.max(0, Math.min(k(v), 4 - k(v), 1))); };
211
+ return [f(5), f(3), f(1)];
212
+ }
213
+ exports.hsbToRgb = hsbToRgb;
214
+ // *********************************************
215
+ // LAB & Hue-Chroma-Luminance (HCL) color spaces
216
+ // *********************************************
217
+ /**
218
+ * Convert LAB color space to HCL color
219
+ * -> http://www.brucelindbloom.com/index.html?Eqn_Lab_to_LCH.html
220
+ *
221
+ * @param {[number, number, number]} lab LAB color
222
+ * @returns {[number, number, number]} HCL color
223
+ */
224
+ function labToHcl(_a) {
225
+ var l = _a[0], a = _a[1], b = _a[2];
226
+ var c = Math.sqrt(a * a + b * b);
227
+ var h = abToHue(a, b);
228
+ return [h, c, l];
229
+ }
230
+ exports.labToHcl = labToHcl;
231
+ /**
232
+ * Convert HCL color space color space to LAB color
233
+ * -> http://www.brucelindbloom.com/index.html?Eqn_LCH_to_Lab.html
234
+ *
235
+ * @param {[number, number, number]} hcl HCL color
236
+ * @returns {[number, number, number]} LAB color space
237
+ */
238
+ function hclToLab(_a) {
239
+ var h = _a[0], c = _a[1], l = _a[2];
240
+ var a = c * Math.cos((0, geometry_1.toRadians)(h));
241
+ var b = c * Math.sin((0, geometry_1.toRadians)(h));
242
+ return [l, a, b];
243
+ }
244
+ exports.hclToLab = hclToLab;
245
+ /**
246
+ * Convert A and B of LAB color to Hue of LCH color
247
+ * -> https://stackoverflow.com/questions/53733379/conversion-of-cielab-to-cielchab-not-yielding-correct-result
248
+ *
249
+ * @param {number} a A value of LAB color
250
+ * @param {number} b B value of LAB color
251
+ * @returns {number} Hue value
252
+ */
253
+ function abToHue(a, b) {
254
+ if (a >= 0 && b === 0) {
255
+ return 0;
256
+ }
257
+ if (a < 0 && b === 0) {
258
+ return 180;
259
+ }
260
+ if (a === 0 && b > 0) {
261
+ return 90;
262
+ }
263
+ if (a === 0 && b < 0) {
264
+ return 270;
265
+ }
266
+ var xBias = 0;
267
+ if (a > 0 && b > 0) {
268
+ xBias = 0;
269
+ }
270
+ else if (a < 0) {
271
+ xBias = 180;
272
+ }
273
+ else if (a > 0 && b < 0) {
274
+ xBias = 360;
275
+ }
276
+ return (0, geometry_1.toDegrees)(Math.atan(b / a)) + xBias;
277
+ }
278
+ // ******************************************
279
+ // LAB & RGB color spaces
280
+ // ******************************************
281
+ var f1 = function (v) { return (v * v * v > 0.008856 ? v * v * v : (v - 16 / 116) / 7.787); };
282
+ var f2 = function (v) { return (v > 0.0031308 ? 1.055 * Math.pow(v, 1 / 2.4) - 0.055 : 12.92 * v); };
283
+ var f3 = function (v) { return (v > 0.04045 ? Math.pow((v + 0.055) / 1.055, 2.4) : v / 12.92); };
284
+ var f4 = function (v) { return (v > 0.008856 ? Math.pow(v, 1 / 3) : 7.787 * v + 16 / 116); };
285
+ /**
286
+ * Converts LAB color to RGB
287
+ *
288
+ * @param {[number, number, number]} lab LAB color
289
+ * @returns {[number, number, number]} RGB color
290
+ */
291
+ function labToRgb(_a) {
292
+ var l = _a[0], a = _a[1], b = _a[2];
293
+ var y = (l + 16) / 116;
294
+ var x = a / 500 + y;
295
+ var z = y - b / 200;
296
+ x = 0.95047 * f1(x);
297
+ y = 1.0 * f1(y);
298
+ z = 1.08883 * f1(z);
299
+ return [
300
+ (0, maths_1.clamp)(f2(x * 3.2406 + y * -1.5372 + z * -0.4986)),
301
+ (0, maths_1.clamp)(f2(x * -0.9689 + y * 1.8758 + z * 0.0415)),
302
+ (0, maths_1.clamp)(f2(x * 0.0557 + y * -0.204 + z * 1.057))
303
+ ];
304
+ }
305
+ exports.labToRgb = labToRgb;
306
+ /**
307
+ * Converts RGB color to Lab color
308
+ *
309
+ * @param {[number, number, number]} rgb RGB color
310
+ * @returns {[number, number, number]} LAB color
311
+ */
312
+ function rgbToLab(_a) {
313
+ var r = _a[0], g = _a[1], b = _a[2];
314
+ r = f3(r);
315
+ g = f3(g);
316
+ b = f3(b);
317
+ var x = f4((r * 0.4124 + g * 0.3576 + b * 0.1805) / 0.95047);
318
+ var y = f4((r * 0.2126 + g * 0.7152 + b * 0.0722) / 1);
319
+ var z = f4((r * 0.0193 + g * 0.1192 + b * 0.9505) / 1.08883);
320
+ return [116 * y - 16, 500 * (x - y), 200 * (y - z)];
321
+ }
322
+ exports.rgbToLab = rgbToLab;
323
+ /**
324
+ * Get the delta from two LAB colors
325
+ *
326
+ * @param {[number, number, number]} labA First LAB color
327
+ * @param {[number, number, number]} labB Second LAB color
328
+ * @returns {number} Delta
329
+ */
330
+ function deltaE(labA, labB) {
331
+ var deltaL = labA[0] - labB[0];
332
+ var deltaA = labA[1] - labB[1];
333
+ var deltaB = labA[2] - labB[2];
334
+ var c1 = Math.sqrt(labA[1] * labA[1] + labA[2] * labA[2]);
335
+ var c2 = Math.sqrt(labB[1] * labB[1] + labB[2] * labB[2]);
336
+ var deltaC = c1 - c2;
337
+ var deltaH = deltaA * deltaA + deltaB * deltaB - deltaC * deltaC;
338
+ deltaH = deltaH < 0 ? 0 : Math.sqrt(deltaH);
339
+ var sc = 1.0 + 0.045 * c1;
340
+ var sh = 1.0 + 0.015 * c1;
341
+ var deltaLKlsl = deltaL / 1;
342
+ var deltaCkcsc = deltaC / sc;
343
+ var deltaHkhsh = deltaH / sh;
344
+ var i = deltaLKlsl * deltaLKlsl + deltaCkcsc * deltaCkcsc + deltaHkhsh * deltaHkhsh;
345
+ return i < 0 ? 0 : Math.sqrt(i);
346
+ }
347
+ exports.deltaE = deltaE;
348
+ // *********************************************
349
+ // RGB & Hue-Chroma-Luminance (HCL) color spaces
350
+ // *********************************************
351
+ /**
352
+ * Converts RGB color to HCL color
353
+ *
354
+ * @param {[number, number, number]} rgb RGB color
355
+ * @returns {[number, number, number]} HCL color
356
+ */
357
+ function rgbToHcl(_a) {
358
+ var r = _a[0], g = _a[1], b = _a[2];
359
+ return labToHcl(rgbToLab([r, g, b]));
360
+ }
361
+ exports.rgbToHcl = rgbToHcl;
362
+ /**
363
+ * Converts HCL color to RGB color
364
+ *
365
+ * @param {[number, number, number]} hcl RGB color
366
+ * @returns {[number, number, number]} RGB color
367
+ */
368
+ function hclToRgb(_a) {
369
+ var h = _a[0], c = _a[1], l = _a[2];
370
+ return labToRgb(hclToLab([h, c, l]));
371
+ }
372
+ exports.hclToRgb = hclToRgb;
@@ -0,0 +1,162 @@
1
+ export declare const EPSILON = 1e-10;
2
+ export declare const PI: number;
3
+ export declare const TWO_PI: number;
4
+ export declare const HALF_PI: number;
5
+ export declare const QUARTER_PI: number;
6
+ export declare const W3CX11: {
7
+ aliceblue: string;
8
+ antiquewhite: string;
9
+ aqua: string;
10
+ aquamarine: string;
11
+ azure: string;
12
+ beige: string;
13
+ bisque: string;
14
+ black: string;
15
+ blanchedalmond: string;
16
+ blue: string;
17
+ blueviolet: string;
18
+ brown: string;
19
+ burlywood: string;
20
+ cadetblue: string;
21
+ chartreuse: string;
22
+ chocolate: string;
23
+ coral: string;
24
+ cornflower: string;
25
+ cornflowerblue: string;
26
+ cornsilk: string;
27
+ crimson: string;
28
+ cyan: string;
29
+ darkblue: string;
30
+ darkcyan: string;
31
+ darkgoldenrod: string;
32
+ darkgray: string;
33
+ darkgreen: string;
34
+ darkgrey: string;
35
+ darkkhaki: string;
36
+ darkmagenta: string;
37
+ darkolivegreen: string;
38
+ darkorange: string;
39
+ darkorchid: string;
40
+ darkred: string;
41
+ darksalmon: string;
42
+ darkseagreen: string;
43
+ darkslateblue: string;
44
+ darkslategray: string;
45
+ darkslategrey: string;
46
+ darkturquoise: string;
47
+ darkviolet: string;
48
+ deeppink: string;
49
+ deepskyblue: string;
50
+ dimgray: string;
51
+ dimgrey: string;
52
+ dodgerblue: string;
53
+ firebrick: string;
54
+ floralwhite: string;
55
+ forestgreen: string;
56
+ fuchsia: string;
57
+ gainsboro: string;
58
+ ghostwhite: string;
59
+ gold: string;
60
+ goldenrod: string;
61
+ gray: string;
62
+ green: string;
63
+ greenyellow: string;
64
+ grey: string;
65
+ honeydew: string;
66
+ hotpink: string;
67
+ indianred: string;
68
+ indigo: string;
69
+ ivory: string;
70
+ khaki: string;
71
+ laserlemon: string;
72
+ lavender: string;
73
+ lavenderblush: string;
74
+ lawngreen: string;
75
+ lemonchiffon: string;
76
+ lightblue: string;
77
+ lightcoral: string;
78
+ lightcyan: string;
79
+ lightgoldenrod: string;
80
+ lightgoldenrodyellow: string;
81
+ lightgray: string;
82
+ lightgreen: string;
83
+ lightgrey: string;
84
+ lightpink: string;
85
+ lightsalmon: string;
86
+ lightseagreen: string;
87
+ lightskyblue: string;
88
+ lightslategray: string;
89
+ lightslategrey: string;
90
+ lightsteelblue: string;
91
+ lightyellow: string;
92
+ lime: string;
93
+ limegreen: string;
94
+ linen: string;
95
+ magenta: string;
96
+ maroon: string;
97
+ maroon2: string;
98
+ maroon3: string;
99
+ mediumaquamarine: string;
100
+ mediumblue: string;
101
+ mediumorchid: string;
102
+ mediumpurple: string;
103
+ mediumseagreen: string;
104
+ mediumslateblue: string;
105
+ mediumspringgreen: string;
106
+ mediumturquoise: string;
107
+ mediumvioletred: string;
108
+ midnightblue: string;
109
+ mintcream: string;
110
+ mistyrose: string;
111
+ moccasin: string;
112
+ navajowhite: string;
113
+ navy: string;
114
+ oldlace: string;
115
+ olive: string;
116
+ olivedrab: string;
117
+ orange: string;
118
+ orangered: string;
119
+ orchid: string;
120
+ palegoldenrod: string;
121
+ palegreen: string;
122
+ paleturquoise: string;
123
+ palevioletred: string;
124
+ papayawhip: string;
125
+ peachpuff: string;
126
+ peru: string;
127
+ pink: string;
128
+ plum: string;
129
+ powderblue: string;
130
+ purple: string;
131
+ purple2: string;
132
+ purple3: string;
133
+ rebeccapurple: string;
134
+ red: string;
135
+ rosybrown: string;
136
+ royalblue: string;
137
+ saddlebrown: string;
138
+ salmon: string;
139
+ sandybrown: string;
140
+ seagreen: string;
141
+ seashell: string;
142
+ sienna: string;
143
+ silver: string;
144
+ skyblue: string;
145
+ slateblue: string;
146
+ slategray: string;
147
+ slategrey: string;
148
+ snow: string;
149
+ springgreen: string;
150
+ steelblue: string;
151
+ tan: string;
152
+ teal: string;
153
+ thistle: string;
154
+ tomato: string;
155
+ turquoise: string;
156
+ violet: string;
157
+ wheat: string;
158
+ white: string;
159
+ whitesmoke: string;
160
+ yellow: string;
161
+ yellowgreen: string;
162
+ };