toosoon-utils 2.4.2 → 3.0.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.
- package/README.md +1 -1
- package/lib/classes/_pool.js +50 -22
- package/lib/classes/color-scale.js +76 -55
- package/lib/classes/frame-rate.js +27 -19
- package/lib/colors.js +123 -85
- package/lib/constants.js +9 -6
- package/lib/dom.js +17 -10
- package/lib/files.js +15 -8
- package/lib/functions.js +20 -17
- package/lib/geometry.js +33 -20
- package/lib/maths.js +51 -22
- package/lib/prng.js +60 -36
- package/lib/random.js +55 -26
- package/lib/strings.js +7 -2
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types.js +2 -1
- package/package.json +1 -2
- package/tsconfig.json +1 -3
package/lib/colors.js
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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 = exports.normalizeColor = void 0;
|
|
4
|
+
var constants_1 = require("./constants");
|
|
5
|
+
var geometry_1 = require("./geometry");
|
|
6
|
+
var maths_1 = require("./maths");
|
|
4
7
|
/**
|
|
5
8
|
* Normalize a color representation into RGB
|
|
6
9
|
*
|
|
7
10
|
* @param {ColorRepresentation} color Color representation
|
|
8
11
|
* @returns {[number,number,number]} Normalized RGB color
|
|
9
12
|
*/
|
|
10
|
-
|
|
13
|
+
function normalizeColor(color) {
|
|
14
|
+
var _a;
|
|
11
15
|
if (typeof color === 'string') {
|
|
12
|
-
return hexToRgb(W3CX11[color]
|
|
16
|
+
return hexToRgb((_a = constants_1.W3CX11[color]) !== null && _a !== void 0 ? _a : color);
|
|
13
17
|
}
|
|
14
18
|
else if (typeof color === 'number') {
|
|
15
19
|
return hexToRgb(color);
|
|
@@ -18,6 +22,7 @@ export function normalizeColor(color) {
|
|
|
18
22
|
return color;
|
|
19
23
|
}
|
|
20
24
|
}
|
|
25
|
+
exports.normalizeColor = normalizeColor;
|
|
21
26
|
// ******************************************
|
|
22
27
|
// RGB & Hexadecimal color spaces
|
|
23
28
|
// ******************************************
|
|
@@ -27,9 +32,9 @@ export function normalizeColor(color) {
|
|
|
27
32
|
* @param {string} hex Hexadecimal string
|
|
28
33
|
* @returns {string} Normalized hexadecimal string
|
|
29
34
|
*/
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
35
|
+
function normalizeHexString(hex) {
|
|
36
|
+
var match;
|
|
37
|
+
var result = '000000';
|
|
33
38
|
hex = hex.toLocaleLowerCase();
|
|
34
39
|
if ((match = hex.match(/(#|0x)?([a-f0-9]{6})/i))) {
|
|
35
40
|
result = match[2];
|
|
@@ -43,8 +48,9 @@ export function normalizeHexString(hex) {
|
|
|
43
48
|
parseInt(match[2]).toString(16).padStart(2, '0') +
|
|
44
49
|
parseInt(match[3]).toString(16).padStart(2, '0');
|
|
45
50
|
}
|
|
46
|
-
return
|
|
51
|
+
return "#".concat(result);
|
|
47
52
|
}
|
|
53
|
+
exports.normalizeHexString = normalizeHexString;
|
|
48
54
|
/**
|
|
49
55
|
* Convert RGB to hexadecimal
|
|
50
56
|
* Note: rgb values are contained in the interval [0, 1]
|
|
@@ -52,9 +58,11 @@ export function normalizeHexString(hex) {
|
|
|
52
58
|
* @param {[number, number, number]} rgb RGB color
|
|
53
59
|
* @returns {number} Hexadecimal color
|
|
54
60
|
*/
|
|
55
|
-
|
|
61
|
+
function rgbToHex(_a) {
|
|
62
|
+
var r = _a[0], g = _a[1], b = _a[2];
|
|
56
63
|
return ((r * 255) << 16) ^ ((g * 255) << 8) ^ ((b * 255) << 0);
|
|
57
64
|
}
|
|
65
|
+
exports.rgbToHex = rgbToHex;
|
|
58
66
|
/**
|
|
59
67
|
* Convert RGB to hexadecimal string
|
|
60
68
|
* Note: rgb values are contained in the interval [0, 1]
|
|
@@ -62,13 +70,15 @@ export function rgbToHex([r, g, b]) {
|
|
|
62
70
|
* @param {[number, number, number]} rgb RGB color
|
|
63
71
|
* @returns {string} Hexadecimal string
|
|
64
72
|
*/
|
|
65
|
-
|
|
66
|
-
r =
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
73
|
+
function rgbToHexString(_a) {
|
|
74
|
+
var r = _a[0], g = _a[1], b = _a[2];
|
|
75
|
+
r = (0, maths_1.clamp)(Math.round(r * 255), 0, 255);
|
|
76
|
+
g = (0, maths_1.clamp)(Math.round(g * 255), 0, 255);
|
|
77
|
+
b = (0, maths_1.clamp)(Math.round(b * 255), 0, 255);
|
|
78
|
+
var result = (b | (g << 8) | (r << 16) | (1 << 24)).toString(16).slice(1);
|
|
79
|
+
return "#".concat(result);
|
|
71
80
|
}
|
|
81
|
+
exports.rgbToHexString = rgbToHexString;
|
|
72
82
|
/**
|
|
73
83
|
* Convert hexadecimal to RGB
|
|
74
84
|
* Note: rgb values are contained in the interval [0, 1]
|
|
@@ -76,7 +86,7 @@ export function rgbToHexString([r, g, b]) {
|
|
|
76
86
|
* @param {(number|string)} hex Hexadecimal color
|
|
77
87
|
* @returns {[number, number, number]} RGB color
|
|
78
88
|
*/
|
|
79
|
-
|
|
89
|
+
function hexToRgb(hex) {
|
|
80
90
|
if (typeof hex === 'number') {
|
|
81
91
|
hex = Math.floor(hex);
|
|
82
92
|
}
|
|
@@ -84,11 +94,12 @@ export function hexToRgb(hex) {
|
|
|
84
94
|
hex = normalizeHexString(hex).replace(/^#/, '');
|
|
85
95
|
hex = parseInt(hex, 16);
|
|
86
96
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
97
|
+
var r = ((hex >> 16) & 255) / 255;
|
|
98
|
+
var g = ((hex >> 8) & 255) / 255;
|
|
99
|
+
var b = (hex & 255) / 255;
|
|
90
100
|
return [r, g, b];
|
|
91
101
|
}
|
|
102
|
+
exports.hexToRgb = hexToRgb;
|
|
92
103
|
/**
|
|
93
104
|
* Lighten a color
|
|
94
105
|
*
|
|
@@ -96,22 +107,24 @@ export function hexToRgb(hex) {
|
|
|
96
107
|
* @param {number} [amount=0] Amount of the color offset
|
|
97
108
|
* @returns {string} Computed hexadecimal
|
|
98
109
|
*/
|
|
99
|
-
|
|
100
|
-
|
|
110
|
+
function lighten(hex, amount) {
|
|
111
|
+
if (amount === void 0) { amount = 0; }
|
|
112
|
+
var prefix = '';
|
|
101
113
|
if (hex[0] === '#') {
|
|
102
114
|
hex = hex.slice(1);
|
|
103
115
|
prefix = '#';
|
|
104
116
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
117
|
+
var value = parseInt(hex, 16);
|
|
118
|
+
var r = (0, maths_1.clamp)((value >> 16) + amount, 0, 255);
|
|
119
|
+
var b = (0, maths_1.clamp)(((value >> 8) & 0x00ff) + amount, 0, 255);
|
|
120
|
+
var g = (0, maths_1.clamp)((value & 0x0000ff) + amount, 0, 255);
|
|
121
|
+
var result = g | (b << 8) | (r << 16);
|
|
110
122
|
if (r === 0 && g === 0 && b === 0 && amount !== 0) {
|
|
111
123
|
result = '000000';
|
|
112
124
|
}
|
|
113
125
|
return prefix + result.toString(16);
|
|
114
126
|
}
|
|
127
|
+
exports.lighten = lighten;
|
|
115
128
|
/**
|
|
116
129
|
* Darken a color
|
|
117
130
|
*
|
|
@@ -119,9 +132,11 @@ export function lighten(hex, amount = 0) {
|
|
|
119
132
|
* @param {number} [amount=0] Amount of the color offset
|
|
120
133
|
* @returns {string} Computed hexadecimal
|
|
121
134
|
*/
|
|
122
|
-
|
|
135
|
+
function darken(hex, amount) {
|
|
136
|
+
if (amount === void 0) { amount = 0; }
|
|
123
137
|
return lighten(hex, -amount);
|
|
124
138
|
}
|
|
139
|
+
exports.darken = darken;
|
|
125
140
|
// ***************************************************
|
|
126
141
|
// RGB & Hue-Saturation-Lightness (HSL) color spaces
|
|
127
142
|
// ***************************************************
|
|
@@ -132,10 +147,12 @@ export function darken(hex, amount = 0) {
|
|
|
132
147
|
* @param {string} hsl HSL string (format: 'hsl(360, 100%, 100%)')
|
|
133
148
|
* @returns {[number, number, number]} Normalized HSL color
|
|
134
149
|
*/
|
|
135
|
-
|
|
136
|
-
|
|
150
|
+
function normalizeHslString(hsl) {
|
|
151
|
+
var _a, _b;
|
|
152
|
+
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], h = _c[0], s = _c[1], l = _c[2];
|
|
137
153
|
return [h, s / 100, l / 100];
|
|
138
154
|
}
|
|
155
|
+
exports.normalizeHslString = normalizeHslString;
|
|
139
156
|
/**
|
|
140
157
|
* Convert RGB to HSL
|
|
141
158
|
* Notes:
|
|
@@ -145,16 +162,18 @@ export function normalizeHslString(hsl) {
|
|
|
145
162
|
* @param {[number, number, number]} rgb RGB color
|
|
146
163
|
* @returns {[number, number, number]} HSL color
|
|
147
164
|
*/
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
165
|
+
function rgbToHsl(_a) {
|
|
166
|
+
var r = _a[0], g = _a[1], b = _a[2];
|
|
167
|
+
var l = Math.max(r, g, b);
|
|
168
|
+
var s = l - Math.min(r, g, b);
|
|
169
|
+
var h = s ? (l === r ? (g - b) / s : l === g ? 2 + (b - r) / s : 4 + (r - g) / s) : 0;
|
|
152
170
|
return [
|
|
153
171
|
60 * h < 0 ? 60 * h + 360 : 60 * h,
|
|
154
172
|
s ? (l <= 0.5 ? s / (2 * l - s) : s / (2 - (2 * l - s))) : 0,
|
|
155
173
|
(2 * l - s) / 2
|
|
156
174
|
];
|
|
157
175
|
}
|
|
176
|
+
exports.rgbToHsl = rgbToHsl;
|
|
158
177
|
/**
|
|
159
178
|
* Convert HSL to RGB
|
|
160
179
|
* Notes:
|
|
@@ -164,12 +183,14 @@ export function rgbToHsl([r, g, b]) {
|
|
|
164
183
|
* @param {[number, number, number]} hsl HSL color
|
|
165
184
|
* @returns {[number, number, number]} RGB color
|
|
166
185
|
*/
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
186
|
+
function hslToRgb(_a) {
|
|
187
|
+
var h = _a[0], s = _a[1], l = _a[2];
|
|
188
|
+
var a = s * Math.min(l, 1 - l);
|
|
189
|
+
var k = function (v) { return (v + h / 30) % 12; };
|
|
190
|
+
var f = function (v) { return l - a * Math.max(-1, Math.min(k(v) - 3, Math.min(9 - k(v), 1))); };
|
|
171
191
|
return [f(0), f(8), f(4)];
|
|
172
192
|
}
|
|
193
|
+
exports.hslToRgb = hslToRgb;
|
|
173
194
|
// ***************************************************
|
|
174
195
|
// RGB & Hue-Saturation-Brightness (HSB) color spaces
|
|
175
196
|
// ***************************************************
|
|
@@ -182,13 +203,15 @@ export function hslToRgb([h, s, l]) {
|
|
|
182
203
|
* @param {[number, number, number]} rgb RGB color
|
|
183
204
|
* @returns {[number, number, number]} HSB color
|
|
184
205
|
*/
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
206
|
+
function rgbToHsb(_a) {
|
|
207
|
+
var r = _a[0], g = _a[1], b = _a[2];
|
|
208
|
+
var max = Math.max(r, g, b);
|
|
209
|
+
var min = Math.min(r, g, b);
|
|
210
|
+
var delta = max - min;
|
|
211
|
+
var h = delta === 0 ? 0 : delta && max === r ? (g - b) / delta : max === g ? 2 + (b - r) / delta : 4 + (r - g) / delta;
|
|
190
212
|
return [60 * (h < 0 ? h + 6 : h), max && delta / max, max];
|
|
191
213
|
}
|
|
214
|
+
exports.rgbToHsb = rgbToHsb;
|
|
192
215
|
/**
|
|
193
216
|
* Convert HSB to RGB
|
|
194
217
|
* Notes:
|
|
@@ -198,11 +221,13 @@ export function rgbToHsb([r, g, b]) {
|
|
|
198
221
|
* @param {[number, number, number]} hsb HSB color
|
|
199
222
|
* @returns {[number, number, number]} RGB color
|
|
200
223
|
*/
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
224
|
+
function hsbToRgb(_a) {
|
|
225
|
+
var h = _a[0], s = _a[1], b = _a[2];
|
|
226
|
+
var k = function (v) { return (v + h / 60) % 6; };
|
|
227
|
+
var f = function (v) { return b * (1 - s * Math.max(0, Math.min(k(v), 4 - k(v), 1))); };
|
|
204
228
|
return [f(5), f(3), f(1)];
|
|
205
229
|
}
|
|
230
|
+
exports.hsbToRgb = hsbToRgb;
|
|
206
231
|
// *********************************************
|
|
207
232
|
// LAB & Hue-Chroma-Luminance (HCL) color spaces
|
|
208
233
|
// *********************************************
|
|
@@ -213,11 +238,13 @@ export function hsbToRgb([h, s, b]) {
|
|
|
213
238
|
* @param {[number, number, number]} lab LAB color
|
|
214
239
|
* @returns {[number, number, number]} HCL color
|
|
215
240
|
*/
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
241
|
+
function labToHcl(_a) {
|
|
242
|
+
var l = _a[0], a = _a[1], b = _a[2];
|
|
243
|
+
var c = Math.sqrt(a * a + b * b);
|
|
244
|
+
var h = abToHue(a, b);
|
|
219
245
|
return [h, c, l];
|
|
220
246
|
}
|
|
247
|
+
exports.labToHcl = labToHcl;
|
|
221
248
|
/**
|
|
222
249
|
* Convert HCL to LAB
|
|
223
250
|
* -> http://www.brucelindbloom.com/index.html?Eqn_LCH_to_Lab.html
|
|
@@ -225,11 +252,13 @@ export function labToHcl([l, a, b]) {
|
|
|
225
252
|
* @param {[number, number, number]} hcl HCL color
|
|
226
253
|
* @returns {[number, number, number]} LAB color space
|
|
227
254
|
*/
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
255
|
+
function hclToLab(_a) {
|
|
256
|
+
var h = _a[0], c = _a[1], l = _a[2];
|
|
257
|
+
var a = c * Math.cos((0, geometry_1.toRadians)(h));
|
|
258
|
+
var b = c * Math.sin((0, geometry_1.toRadians)(h));
|
|
231
259
|
return [l, a, b];
|
|
232
260
|
}
|
|
261
|
+
exports.hclToLab = hclToLab;
|
|
233
262
|
/**
|
|
234
263
|
* Convert A and B of LAB to Hue of LCH
|
|
235
264
|
* -> https://stackoverflow.com/questions/53733379/conversion-of-cielab-to-cielchab-not-yielding-correct-result
|
|
@@ -251,7 +280,7 @@ function abToHue(a, b) {
|
|
|
251
280
|
if (a === 0 && b < 0) {
|
|
252
281
|
return 270;
|
|
253
282
|
}
|
|
254
|
-
|
|
283
|
+
var xBias = 0;
|
|
255
284
|
if (a > 0 && b > 0) {
|
|
256
285
|
xBias = 0;
|
|
257
286
|
}
|
|
@@ -261,49 +290,53 @@ function abToHue(a, b) {
|
|
|
261
290
|
else if (a > 0 && b < 0) {
|
|
262
291
|
xBias = 360;
|
|
263
292
|
}
|
|
264
|
-
return toDegrees(Math.atan(b / a)) + xBias;
|
|
293
|
+
return (0, geometry_1.toDegrees)(Math.atan(b / a)) + xBias;
|
|
265
294
|
}
|
|
266
295
|
// ******************************************
|
|
267
296
|
// LAB & RGB color spaces
|
|
268
297
|
// ******************************************
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
298
|
+
var f1 = function (v) { return (v * v * v > 0.008856 ? v * v * v : (v - 16 / 116) / 7.787); };
|
|
299
|
+
var f2 = function (v) { return (v > 0.0031308 ? 1.055 * Math.pow(v, 1 / 2.4) - 0.055 : 12.92 * v); };
|
|
300
|
+
var f3 = function (v) { return (v > 0.04045 ? Math.pow((v + 0.055) / 1.055, 2.4) : v / 12.92); };
|
|
301
|
+
var f4 = function (v) { return (v > 0.008856 ? Math.pow(v, 1 / 3) : 7.787 * v + 16 / 116); };
|
|
273
302
|
/**
|
|
274
303
|
* Converts LAB to RGB
|
|
275
304
|
*
|
|
276
305
|
* @param {[number, number, number]} lab LAB color
|
|
277
306
|
* @returns {[number, number, number]} RGB color
|
|
278
307
|
*/
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
308
|
+
function labToRgb(_a) {
|
|
309
|
+
var l = _a[0], a = _a[1], b = _a[2];
|
|
310
|
+
var y = (l + 16) / 116;
|
|
311
|
+
var x = a / 500 + y;
|
|
312
|
+
var z = y - b / 200;
|
|
283
313
|
x = 0.95047 * f1(x);
|
|
284
314
|
y = 1.0 * f1(y);
|
|
285
315
|
z = 1.08883 * f1(z);
|
|
286
316
|
return [
|
|
287
|
-
clamp(f2(x * 3.2406 + y * -1.5372 + z * -0.4986)),
|
|
288
|
-
clamp(f2(x * -0.9689 + y * 1.8758 + z * 0.0415)),
|
|
289
|
-
clamp(f2(x * 0.0557 + y * -0.204 + z * 1.057))
|
|
317
|
+
(0, maths_1.clamp)(f2(x * 3.2406 + y * -1.5372 + z * -0.4986)),
|
|
318
|
+
(0, maths_1.clamp)(f2(x * -0.9689 + y * 1.8758 + z * 0.0415)),
|
|
319
|
+
(0, maths_1.clamp)(f2(x * 0.0557 + y * -0.204 + z * 1.057))
|
|
290
320
|
];
|
|
291
321
|
}
|
|
322
|
+
exports.labToRgb = labToRgb;
|
|
292
323
|
/**
|
|
293
324
|
* Converts RGB to LAB
|
|
294
325
|
*
|
|
295
326
|
* @param {[number, number, number]} rgb RGB color
|
|
296
327
|
* @returns {[number, number, number]} LAB color
|
|
297
328
|
*/
|
|
298
|
-
|
|
329
|
+
function rgbToLab(_a) {
|
|
330
|
+
var r = _a[0], g = _a[1], b = _a[2];
|
|
299
331
|
r = f3(r);
|
|
300
332
|
g = f3(g);
|
|
301
333
|
b = f3(b);
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
334
|
+
var x = f4((r * 0.4124 + g * 0.3576 + b * 0.1805) / 0.95047);
|
|
335
|
+
var y = f4((r * 0.2126 + g * 0.7152 + b * 0.0722) / 1);
|
|
336
|
+
var z = f4((r * 0.0193 + g * 0.1192 + b * 0.9505) / 1.08883);
|
|
305
337
|
return [116 * y - 16, 500 * (x - y), 200 * (y - z)];
|
|
306
338
|
}
|
|
339
|
+
exports.rgbToLab = rgbToLab;
|
|
307
340
|
/**
|
|
308
341
|
* Get the delta from two LAB colors
|
|
309
342
|
*
|
|
@@ -311,23 +344,24 @@ export function rgbToLab([r, g, b]) {
|
|
|
311
344
|
* @param {[number, number, number]} labB Second LAB color
|
|
312
345
|
* @returns {number} Delta
|
|
313
346
|
*/
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
347
|
+
function deltaE(labA, labB) {
|
|
348
|
+
var deltaL = labA[0] - labB[0];
|
|
349
|
+
var deltaA = labA[1] - labB[1];
|
|
350
|
+
var deltaB = labA[2] - labB[2];
|
|
351
|
+
var c1 = Math.sqrt(labA[1] * labA[1] + labA[2] * labA[2]);
|
|
352
|
+
var c2 = Math.sqrt(labB[1] * labB[1] + labB[2] * labB[2]);
|
|
353
|
+
var deltaC = c1 - c2;
|
|
354
|
+
var deltaH = deltaA * deltaA + deltaB * deltaB - deltaC * deltaC;
|
|
322
355
|
deltaH = deltaH < 0 ? 0 : Math.sqrt(deltaH);
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
356
|
+
var sc = 1.0 + 0.045 * c1;
|
|
357
|
+
var sh = 1.0 + 0.015 * c1;
|
|
358
|
+
var deltaLKlsl = deltaL / 1;
|
|
359
|
+
var deltaCkcsc = deltaC / sc;
|
|
360
|
+
var deltaHkhsh = deltaH / sh;
|
|
361
|
+
var i = deltaLKlsl * deltaLKlsl + deltaCkcsc * deltaCkcsc + deltaHkhsh * deltaHkhsh;
|
|
329
362
|
return i < 0 ? 0 : Math.sqrt(i);
|
|
330
363
|
}
|
|
364
|
+
exports.deltaE = deltaE;
|
|
331
365
|
// *********************************************
|
|
332
366
|
// RGB & Hue-Chroma-Luminance (HCL) color spaces
|
|
333
367
|
// *********************************************
|
|
@@ -337,15 +371,19 @@ export function deltaE(labA, labB) {
|
|
|
337
371
|
* @param {[number, number, number]} rgb RGB color
|
|
338
372
|
* @returns {[number, number, number]} HCL color
|
|
339
373
|
*/
|
|
340
|
-
|
|
374
|
+
function rgbToHcl(_a) {
|
|
375
|
+
var r = _a[0], g = _a[1], b = _a[2];
|
|
341
376
|
return labToHcl(rgbToLab([r, g, b]));
|
|
342
377
|
}
|
|
378
|
+
exports.rgbToHcl = rgbToHcl;
|
|
343
379
|
/**
|
|
344
380
|
* Converts HCL to RGB
|
|
345
381
|
*
|
|
346
382
|
* @param {[number, number, number]} hcl RGB color
|
|
347
383
|
* @returns {[number, number, number]} RGB color
|
|
348
384
|
*/
|
|
349
|
-
|
|
385
|
+
function hclToRgb(_a) {
|
|
386
|
+
var h = _a[0], c = _a[1], l = _a[2];
|
|
350
387
|
return labToRgb(hclToLab([h, c, l]));
|
|
351
388
|
}
|
|
389
|
+
exports.hclToRgb = hclToRgb;
|
package/lib/constants.js
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.W3CX11 = exports.QUARTER_PI = exports.HALF_PI = exports.TWO_PI = exports.PI = exports.EPSILON = void 0;
|
|
1
4
|
// *********************
|
|
2
5
|
// Maths
|
|
3
6
|
// *********************
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
exports.EPSILON = 1e-10;
|
|
8
|
+
exports.PI = Math.PI;
|
|
9
|
+
exports.TWO_PI = Math.PI * 2;
|
|
10
|
+
exports.HALF_PI = Math.PI / 2;
|
|
11
|
+
exports.QUARTER_PI = Math.PI / 4;
|
|
9
12
|
// *********************
|
|
10
13
|
// Colors
|
|
11
14
|
// *********************
|
|
12
15
|
// X11 colors
|
|
13
16
|
// -> https://www.w3.org/TR/css-color-3/#svg-color
|
|
14
|
-
|
|
17
|
+
exports.W3CX11 = {
|
|
15
18
|
aliceblue: 0xf0f8ff,
|
|
16
19
|
antiquewhite: 0xfaebd7,
|
|
17
20
|
aqua: 0x00ffff,
|
package/lib/dom.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.injectStyles = exports.createCanvas = exports.closest = void 0;
|
|
4
|
+
var DOCUMENT_NODE_TYPE = 9;
|
|
2
5
|
/**
|
|
3
6
|
* Find the closest parent that matches a selector
|
|
4
7
|
*
|
|
@@ -6,8 +9,8 @@ const DOCUMENT_NODE_TYPE = 9;
|
|
|
6
9
|
* @param {(Element|string)} selector Selector or parent to match
|
|
7
10
|
* @returns {Element|null}
|
|
8
11
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
12
|
+
function closest(element, selector) {
|
|
13
|
+
var current = element;
|
|
11
14
|
while (current && current.nodeType !== DOCUMENT_NODE_TYPE) {
|
|
12
15
|
if ((typeof selector === 'string' && current.matches(selector)) || current === selector) {
|
|
13
16
|
return current;
|
|
@@ -16,6 +19,7 @@ export function closest(element, selector) {
|
|
|
16
19
|
}
|
|
17
20
|
return current;
|
|
18
21
|
}
|
|
22
|
+
exports.closest = closest;
|
|
19
23
|
/**
|
|
20
24
|
* Create a canvas and 2d context
|
|
21
25
|
*
|
|
@@ -23,24 +27,27 @@ export function closest(element, selector) {
|
|
|
23
27
|
* @param {Number} height Height of the canvas
|
|
24
28
|
* @returns {{ canvas: HTMLCanvasElement, ctx: CanvasRenderingContext2D }}
|
|
25
29
|
*/
|
|
26
|
-
|
|
27
|
-
|
|
30
|
+
function createCanvas(width, height) {
|
|
31
|
+
var _a;
|
|
32
|
+
var canvas = document.createElement('canvas');
|
|
28
33
|
canvas.width = width;
|
|
29
34
|
canvas.height = height;
|
|
30
|
-
|
|
31
|
-
return { canvas, ctx };
|
|
35
|
+
var ctx = (_a = canvas.getContext('2d')) !== null && _a !== void 0 ? _a : new CanvasRenderingContext2D();
|
|
36
|
+
return { canvas: canvas, ctx: ctx };
|
|
32
37
|
}
|
|
38
|
+
exports.createCanvas = createCanvas;
|
|
33
39
|
/**
|
|
34
40
|
* Inject CSS styles in `document.head`
|
|
35
41
|
*
|
|
36
42
|
* @param {string} styles CSS styles to inject
|
|
37
43
|
*/
|
|
38
|
-
|
|
39
|
-
|
|
44
|
+
function injectStyles(styles) {
|
|
45
|
+
var $style = document.createElement('style');
|
|
40
46
|
$style.innerHTML = styles;
|
|
41
|
-
|
|
47
|
+
var $before = document.querySelector('head link[rel=stylesheet], head style');
|
|
42
48
|
if ($before)
|
|
43
49
|
document.head.insertBefore($style, $before);
|
|
44
50
|
else
|
|
45
51
|
document.head.appendChild($style);
|
|
46
52
|
}
|
|
53
|
+
exports.injectStyles = injectStyles;
|
package/lib/files.js
CHANGED
|
@@ -1,32 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.upload = exports.download = void 0;
|
|
1
4
|
/**
|
|
2
5
|
* Download a Blob object into user files
|
|
3
6
|
*
|
|
4
7
|
* @param {Blob} blob Blob object to download
|
|
5
8
|
* @param {string} filename Downloaded file name
|
|
6
9
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
10
|
+
function download(blob, filename) {
|
|
11
|
+
var link = document.createElement('a');
|
|
9
12
|
link.setAttribute('href', URL.createObjectURL(blob));
|
|
10
13
|
link.setAttribute('download', filename);
|
|
11
14
|
document.body.appendChild(link);
|
|
12
15
|
link.click();
|
|
13
16
|
document.body.removeChild(link);
|
|
14
17
|
}
|
|
18
|
+
exports.download = download;
|
|
15
19
|
/**
|
|
16
20
|
* Upload a file from user files
|
|
17
21
|
*
|
|
18
22
|
* @param {Function} onLoad Callback called once the file is loaded
|
|
19
23
|
* @param {string} [accept=''] MIME type the file input should accept
|
|
20
24
|
*/
|
|
21
|
-
|
|
22
|
-
|
|
25
|
+
function upload(onLoad, accept) {
|
|
26
|
+
if (accept === void 0) { accept = ''; }
|
|
27
|
+
var input = document.createElement('input');
|
|
23
28
|
input.setAttribute('type', 'file');
|
|
24
29
|
input.setAttribute('accept', accept);
|
|
25
|
-
input.addEventListener('change', (event)
|
|
26
|
-
|
|
30
|
+
input.addEventListener('change', function (event) {
|
|
31
|
+
var _a, _b;
|
|
32
|
+
var file = (_b = (_a = event.target) === null || _a === void 0 ? void 0 : _a.files) === null || _b === void 0 ? void 0 : _b[0];
|
|
27
33
|
if (file) {
|
|
28
|
-
|
|
29
|
-
fileReader.addEventListener('load', ()
|
|
34
|
+
var fileReader = new FileReader();
|
|
35
|
+
fileReader.addEventListener('load', function () { return onLoad(URL.createObjectURL(file)); });
|
|
30
36
|
fileReader.readAsDataURL(file);
|
|
31
37
|
}
|
|
32
38
|
});
|
|
@@ -34,3 +40,4 @@ export function upload(onLoad, accept = '') {
|
|
|
34
40
|
input.click();
|
|
35
41
|
document.body.removeChild(input);
|
|
36
42
|
}
|
|
43
|
+
exports.upload = upload;
|
package/lib/functions.js
CHANGED
|
@@ -1,52 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.now = exports.defer = exports.wait = exports.noop = void 0;
|
|
1
4
|
/**
|
|
2
5
|
* No-op function
|
|
3
6
|
*/
|
|
4
|
-
|
|
7
|
+
var noop = function () { };
|
|
8
|
+
exports.noop = noop;
|
|
5
9
|
/**
|
|
6
10
|
* Promise wrapped setTimeout
|
|
7
11
|
*
|
|
8
12
|
* @param {number} [timeout=0] Time to wait (in milliseconds)
|
|
9
13
|
* @returns {Promise}
|
|
10
14
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
15
|
+
function wait(timeout) {
|
|
16
|
+
if (timeout === void 0) { timeout = 0; }
|
|
17
|
+
return new Promise(function (resolve) { return setTimeout(resolve, timeout); });
|
|
13
18
|
}
|
|
19
|
+
exports.wait = wait;
|
|
14
20
|
/**
|
|
15
21
|
* Deferred promise implementation
|
|
16
22
|
*
|
|
17
23
|
* @returns {Deferred}
|
|
18
24
|
*/
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
25
|
+
function defer() {
|
|
26
|
+
var resolve;
|
|
27
|
+
var reject;
|
|
28
|
+
var promise = new Promise(function (_resolve, _reject) {
|
|
23
29
|
resolve = _resolve;
|
|
24
30
|
reject = _reject;
|
|
25
31
|
});
|
|
26
|
-
return { promise, resolve, reject };
|
|
32
|
+
return { promise: promise, resolve: resolve, reject: reject };
|
|
27
33
|
}
|
|
28
|
-
|
|
29
|
-
* Polyfill for `now()` functions
|
|
30
|
-
*/
|
|
31
|
-
export let now;
|
|
34
|
+
exports.defer = defer;
|
|
32
35
|
// In node.js, use `process.hrtime`
|
|
33
36
|
if (typeof process !== 'undefined' && process.hrtime) {
|
|
34
|
-
now = function () {
|
|
37
|
+
exports.now = function () {
|
|
35
38
|
// Convert [seconds, nanoseconds] to milliseconds
|
|
36
|
-
|
|
39
|
+
var time = process.hrtime();
|
|
37
40
|
return time[0] * 1000 + time[1] / 1000000;
|
|
38
41
|
};
|
|
39
42
|
}
|
|
40
43
|
// In a browser use `performance` or `Date`
|
|
41
44
|
else if (typeof performance !== 'undefined') {
|
|
42
45
|
// This must be bound, because directly assigning this function leads to an invocation exception in Chrome
|
|
43
|
-
now = performance.now.bind(performance);
|
|
46
|
+
exports.now = performance.now.bind(performance);
|
|
44
47
|
}
|
|
45
48
|
else if (typeof Date.now !== 'undefined') {
|
|
46
|
-
now = Date.now;
|
|
49
|
+
exports.now = Date.now;
|
|
47
50
|
}
|
|
48
51
|
else {
|
|
49
|
-
now = function () {
|
|
52
|
+
exports.now = function () {
|
|
50
53
|
return new Date().getTime();
|
|
51
54
|
};
|
|
52
55
|
}
|