@raystack/apsara 0.49.0 → 0.49.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/dist/components/calendar/range-picker.cjs +19 -18
- package/dist/components/calendar/range-picker.cjs.map +1 -1
- package/dist/components/calendar/range-picker.d.ts +5 -4
- package/dist/components/calendar/range-picker.d.ts.map +1 -1
- package/dist/components/calendar/range-picker.js +19 -18
- package/dist/components/calendar/range-picker.js.map +1 -1
- package/dist/components/color-picker/color-picker-alpha.cjs +15 -0
- package/dist/components/color-picker/color-picker-alpha.cjs.map +1 -0
- package/dist/components/color-picker/color-picker-alpha.d.ts +5 -0
- package/dist/components/color-picker/color-picker-alpha.d.ts.map +1 -0
- package/dist/components/color-picker/color-picker-alpha.js +13 -0
- package/dist/components/color-picker/color-picker-alpha.js.map +1 -0
- package/dist/components/color-picker/color-picker-area.cjs +73 -0
- package/dist/components/color-picker/color-picker-area.cjs.map +1 -0
- package/dist/components/color-picker/color-picker-area.d.ts +4 -0
- package/dist/components/color-picker/color-picker-area.d.ts.map +1 -0
- package/dist/components/color-picker/color-picker-area.js +71 -0
- package/dist/components/color-picker/color-picker-area.js.map +1 -0
- package/dist/components/color-picker/color-picker-hue.cjs +15 -0
- package/dist/components/color-picker/color-picker-hue.cjs.map +1 -0
- package/dist/components/color-picker/color-picker-hue.d.ts +5 -0
- package/dist/components/color-picker/color-picker-hue.d.ts.map +1 -0
- package/dist/components/color-picker/color-picker-hue.js +13 -0
- package/dist/components/color-picker/color-picker-hue.js.map +1 -0
- package/dist/components/color-picker/color-picker-input.cjs +16 -0
- package/dist/components/color-picker/color-picker-input.cjs.map +1 -0
- package/dist/components/color-picker/color-picker-input.d.ts +4 -0
- package/dist/components/color-picker/color-picker-input.d.ts.map +1 -0
- package/dist/components/color-picker/color-picker-input.js +14 -0
- package/dist/components/color-picker/color-picker-input.js.map +1 -0
- package/dist/components/color-picker/color-picker-mode.cjs +16 -0
- package/dist/components/color-picker/color-picker-mode.cjs.map +1 -0
- package/dist/components/color-picker/color-picker-mode.d.ts +8 -0
- package/dist/components/color-picker/color-picker-mode.d.ts.map +1 -0
- package/dist/components/color-picker/color-picker-mode.js +14 -0
- package/dist/components/color-picker/color-picker-mode.js.map +1 -0
- package/dist/components/color-picker/color-picker-root.cjs +53 -0
- package/dist/components/color-picker/color-picker-root.cjs.map +1 -0
- package/dist/components/color-picker/color-picker-root.d.ts +25 -0
- package/dist/components/color-picker/color-picker-root.d.ts.map +1 -0
- package/dist/components/color-picker/color-picker-root.js +50 -0
- package/dist/components/color-picker/color-picker-root.js.map +1 -0
- package/dist/components/color-picker/color-picker.cjs +19 -0
- package/dist/components/color-picker/color-picker.cjs.map +1 -0
- package/dist/components/color-picker/color-picker.js +17 -0
- package/dist/components/color-picker/color-picker.js.map +1 -0
- package/dist/components/color-picker/color-picker.module.css.cjs +8 -0
- package/dist/components/color-picker/color-picker.module.css.cjs.map +1 -0
- package/dist/components/color-picker/color-picker.module.css.js +4 -0
- package/dist/components/color-picker/color-picker.module.css.js.map +1 -0
- package/dist/components/color-picker/index.d.ts +2 -0
- package/dist/components/color-picker/index.d.ts.map +1 -0
- package/dist/components/color-picker/utils.cjs +18 -0
- package/dist/components/color-picker/utils.cjs.map +1 -0
- package/dist/components/color-picker/utils.d.ts +11 -0
- package/dist/components/color-picker/utils.d.ts.map +1 -0
- package/dist/components/color-picker/utils.js +15 -0
- package/dist/components/color-picker/utils.js.map +1 -0
- package/dist/components/filter-chip/filter-chip.cjs +1 -1
- package/dist/components/filter-chip/filter-chip.js +1 -1
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/node_modules/.pnpm/color-convert@3.1.0/node_modules/color-convert/conversions.cjs +986 -0
- package/dist/node_modules/.pnpm/color-convert@3.1.0/node_modules/color-convert/conversions.cjs.map +1 -0
- package/dist/node_modules/.pnpm/color-convert@3.1.0/node_modules/color-convert/conversions.js +982 -0
- package/dist/node_modules/.pnpm/color-convert@3.1.0/node_modules/color-convert/conversions.js.map +1 -0
- package/dist/node_modules/.pnpm/color-convert@3.1.0/node_modules/color-convert/index.cjs +86 -0
- package/dist/node_modules/.pnpm/color-convert@3.1.0/node_modules/color-convert/index.cjs.map +1 -0
- package/dist/node_modules/.pnpm/color-convert@3.1.0/node_modules/color-convert/index.js +82 -0
- package/dist/node_modules/.pnpm/color-convert@3.1.0/node_modules/color-convert/index.js.map +1 -0
- package/dist/node_modules/.pnpm/color-convert@3.1.0/node_modules/color-convert/route.cjs +103 -0
- package/dist/node_modules/.pnpm/color-convert@3.1.0/node_modules/color-convert/route.cjs.map +1 -0
- package/dist/node_modules/.pnpm/color-convert@3.1.0/node_modules/color-convert/route.js +99 -0
- package/dist/node_modules/.pnpm/color-convert@3.1.0/node_modules/color-convert/route.js.map +1 -0
- package/dist/node_modules/.pnpm/color-name@2.0.0/node_modules/color-name/index.cjs +157 -0
- package/dist/node_modules/.pnpm/color-name@2.0.0/node_modules/color-name/index.cjs.map +1 -0
- package/dist/node_modules/.pnpm/color-name@2.0.0/node_modules/color-name/index.js +153 -0
- package/dist/node_modules/.pnpm/color-name@2.0.0/node_modules/color-name/index.js.map +1 -0
- package/dist/node_modules/.pnpm/color-string@2.0.1/node_modules/color-string/index.cjs +235 -0
- package/dist/node_modules/.pnpm/color-string@2.0.1/node_modules/color-string/index.cjs.map +1 -0
- package/dist/node_modules/.pnpm/color-string@2.0.1/node_modules/color-string/index.js +231 -0
- package/dist/node_modules/.pnpm/color-string@2.0.1/node_modules/color-string/index.js.map +1 -0
- package/dist/node_modules/.pnpm/color@5.0.0/node_modules/color/index.cjs +501 -0
- package/dist/node_modules/.pnpm/color@5.0.0/node_modules/color/index.cjs.map +1 -0
- package/dist/node_modules/.pnpm/color@5.0.0/node_modules/color/index.js +497 -0
- package/dist/node_modules/.pnpm/color@5.0.0/node_modules/color/index.js.map +1 -0
- package/dist/style.css +1 -1
- package/package.json +2 -1
|
@@ -0,0 +1,982 @@
|
|
|
1
|
+
import cssKeywords from '../../../color-name@2.0.0/node_modules/color-name/index.js';
|
|
2
|
+
|
|
3
|
+
/* MIT license */
|
|
4
|
+
/* eslint-disable no-mixed-operators */
|
|
5
|
+
|
|
6
|
+
// NOTE: conversions should only return primitive values (i.e. arrays, or
|
|
7
|
+
// values that give correct `typeof` results).
|
|
8
|
+
// do not use box values types (i.e. Number(), String(), etc.)
|
|
9
|
+
|
|
10
|
+
const reverseKeywords = {};
|
|
11
|
+
for (const key of Object.keys(cssKeywords)) {
|
|
12
|
+
reverseKeywords[cssKeywords[key]] = key;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const convert = {
|
|
16
|
+
rgb: {channels: 3, labels: 'rgb'},
|
|
17
|
+
hsl: {channels: 3, labels: 'hsl'},
|
|
18
|
+
hsv: {channels: 3, labels: 'hsv'},
|
|
19
|
+
hwb: {channels: 3, labels: 'hwb'},
|
|
20
|
+
cmyk: {channels: 4, labels: 'cmyk'},
|
|
21
|
+
xyz: {channels: 3, labels: 'xyz'},
|
|
22
|
+
lab: {channels: 3, labels: 'lab'},
|
|
23
|
+
oklab: {channels: 3, labels: ['okl', 'oka', 'okb']},
|
|
24
|
+
lch: {channels: 3, labels: 'lch'},
|
|
25
|
+
oklch: {channels: 3, labels: ['okl', 'okc', 'okh']},
|
|
26
|
+
hex: {channels: 1, labels: ['hex']},
|
|
27
|
+
keyword: {channels: 1, labels: ['keyword']},
|
|
28
|
+
ansi16: {channels: 1, labels: ['ansi16']},
|
|
29
|
+
ansi256: {channels: 1, labels: ['ansi256']},
|
|
30
|
+
hcg: {channels: 3, labels: ['h', 'c', 'g']},
|
|
31
|
+
apple: {channels: 3, labels: ['r16', 'g16', 'b16']},
|
|
32
|
+
gray: {channels: 1, labels: ['gray']},
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// LAB f(t) constant
|
|
36
|
+
const LAB_FT = (6 / 29) ** 3;
|
|
37
|
+
|
|
38
|
+
// SRGB non-linear transform functions
|
|
39
|
+
function srgbNonlinearTransform(c) {
|
|
40
|
+
const cc = c > 0.003_130_8
|
|
41
|
+
? ((1.055 * (c ** (1 / 2.4))) - 0.055)
|
|
42
|
+
: c * 12.92;
|
|
43
|
+
return Math.min(Math.max(0, cc), 1);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function srgbNonlinearTransformInv(c) {
|
|
47
|
+
return c > 0.040_45 ? (((c + 0.055) / 1.055) ** 2.4) : (c / 12.92);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Hide .channels and .labels properties
|
|
51
|
+
for (const model of Object.keys(convert)) {
|
|
52
|
+
if (!('channels' in convert[model])) {
|
|
53
|
+
throw new Error('missing channels property: ' + model);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (!('labels' in convert[model])) {
|
|
57
|
+
throw new Error('missing channel labels property: ' + model);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (convert[model].labels.length !== convert[model].channels) {
|
|
61
|
+
throw new Error('channel and label counts mismatch: ' + model);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const {channels, labels} = convert[model];
|
|
65
|
+
delete convert[model].channels;
|
|
66
|
+
delete convert[model].labels;
|
|
67
|
+
Object.defineProperty(convert[model], 'channels', {value: channels});
|
|
68
|
+
Object.defineProperty(convert[model], 'labels', {value: labels});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
convert.rgb.hsl = function (rgb) {
|
|
72
|
+
const r = rgb[0] / 255;
|
|
73
|
+
const g = rgb[1] / 255;
|
|
74
|
+
const b = rgb[2] / 255;
|
|
75
|
+
const min = Math.min(r, g, b);
|
|
76
|
+
const max = Math.max(r, g, b);
|
|
77
|
+
const delta = max - min;
|
|
78
|
+
let h;
|
|
79
|
+
let s;
|
|
80
|
+
|
|
81
|
+
switch (max) {
|
|
82
|
+
case min: {
|
|
83
|
+
h = 0;
|
|
84
|
+
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
case r: {
|
|
89
|
+
h = (g - b) / delta;
|
|
90
|
+
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
case g: {
|
|
95
|
+
h = 2 + (b - r) / delta;
|
|
96
|
+
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
case b: {
|
|
101
|
+
h = 4 + (r - g) / delta;
|
|
102
|
+
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
// No default
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
h = Math.min(h * 60, 360);
|
|
109
|
+
|
|
110
|
+
if (h < 0) {
|
|
111
|
+
h += 360;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const l = (min + max) / 2;
|
|
115
|
+
|
|
116
|
+
if (max === min) {
|
|
117
|
+
s = 0;
|
|
118
|
+
} else if (l <= 0.5) {
|
|
119
|
+
s = delta / (max + min);
|
|
120
|
+
} else {
|
|
121
|
+
s = delta / (2 - max - min);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return [h, s * 100, l * 100];
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
convert.rgb.hsv = function (rgb) {
|
|
128
|
+
let rdif;
|
|
129
|
+
let gdif;
|
|
130
|
+
let bdif;
|
|
131
|
+
let h;
|
|
132
|
+
let s;
|
|
133
|
+
|
|
134
|
+
const r = rgb[0] / 255;
|
|
135
|
+
const g = rgb[1] / 255;
|
|
136
|
+
const b = rgb[2] / 255;
|
|
137
|
+
const v = Math.max(r, g, b);
|
|
138
|
+
const diff = v - Math.min(r, g, b);
|
|
139
|
+
const diffc = function (c) {
|
|
140
|
+
return (v - c) / 6 / diff + 1 / 2;
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
if (diff === 0) {
|
|
144
|
+
h = 0;
|
|
145
|
+
s = 0;
|
|
146
|
+
} else {
|
|
147
|
+
s = diff / v;
|
|
148
|
+
rdif = diffc(r);
|
|
149
|
+
gdif = diffc(g);
|
|
150
|
+
bdif = diffc(b);
|
|
151
|
+
|
|
152
|
+
switch (v) {
|
|
153
|
+
case r: {
|
|
154
|
+
h = bdif - gdif;
|
|
155
|
+
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
case g: {
|
|
160
|
+
h = (1 / 3) + rdif - bdif;
|
|
161
|
+
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
case b: {
|
|
166
|
+
h = (2 / 3) + gdif - rdif;
|
|
167
|
+
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
// No default
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (h < 0) {
|
|
174
|
+
h += 1;
|
|
175
|
+
} else if (h > 1) {
|
|
176
|
+
h -= 1;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return [
|
|
181
|
+
h * 360,
|
|
182
|
+
s * 100,
|
|
183
|
+
v * 100,
|
|
184
|
+
];
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
convert.rgb.hwb = function (rgb) {
|
|
188
|
+
const r = rgb[0];
|
|
189
|
+
const g = rgb[1];
|
|
190
|
+
let b = rgb[2];
|
|
191
|
+
const h = convert.rgb.hsl(rgb)[0];
|
|
192
|
+
const w = 1 / 255 * Math.min(r, Math.min(g, b));
|
|
193
|
+
|
|
194
|
+
b = 1 - 1 / 255 * Math.max(r, Math.max(g, b));
|
|
195
|
+
|
|
196
|
+
return [h, w * 100, b * 100];
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
convert.rgb.oklab = function (rgb) {
|
|
200
|
+
// Assume sRGB
|
|
201
|
+
const r = srgbNonlinearTransformInv(rgb[0] / 255);
|
|
202
|
+
const g = srgbNonlinearTransformInv(rgb[1] / 255);
|
|
203
|
+
const b = srgbNonlinearTransformInv(rgb[2] / 255);
|
|
204
|
+
|
|
205
|
+
const lp = Math.cbrt(0.412_221_470_8 * r + 0.536_332_536_3 * g + 0.051_445_992_9 * b);
|
|
206
|
+
const mp = Math.cbrt(0.211_903_498_2 * r + 0.680_699_545_1 * g + 0.107_396_956_6 * b);
|
|
207
|
+
const sp = Math.cbrt(0.088_302_461_9 * r + 0.281_718_837_6 * g + 0.629_978_700_5 * b);
|
|
208
|
+
|
|
209
|
+
const l = 0.210_454_255_3 * lp + 0.793_617_785 * mp - 0.004_072_046_8 * sp;
|
|
210
|
+
const aa = 1.977_998_495_1 * lp - 2.428_592_205 * mp + 0.450_593_709_9 * sp;
|
|
211
|
+
const bb = 0.025_904_037_1 * lp + 0.782_771_766_2 * mp - 0.808_675_766 * sp;
|
|
212
|
+
|
|
213
|
+
return [l * 100, aa * 100, bb * 100];
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
convert.rgb.cmyk = function (rgb) {
|
|
217
|
+
const r = rgb[0] / 255;
|
|
218
|
+
const g = rgb[1] / 255;
|
|
219
|
+
const b = rgb[2] / 255;
|
|
220
|
+
|
|
221
|
+
const k = Math.min(1 - r, 1 - g, 1 - b);
|
|
222
|
+
const c = (1 - r - k) / (1 - k) || 0;
|
|
223
|
+
const m = (1 - g - k) / (1 - k) || 0;
|
|
224
|
+
const y = (1 - b - k) / (1 - k) || 0;
|
|
225
|
+
|
|
226
|
+
return [c * 100, m * 100, y * 100, k * 100];
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
function comparativeDistance(x, y) {
|
|
230
|
+
/*
|
|
231
|
+
See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
|
|
232
|
+
*/
|
|
233
|
+
return (
|
|
234
|
+
((x[0] - y[0]) ** 2) +
|
|
235
|
+
((x[1] - y[1]) ** 2) +
|
|
236
|
+
((x[2] - y[2]) ** 2)
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
convert.rgb.keyword = function (rgb) {
|
|
241
|
+
const reversed = reverseKeywords[rgb];
|
|
242
|
+
if (reversed) {
|
|
243
|
+
return reversed;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
let currentClosestDistance = Number.POSITIVE_INFINITY;
|
|
247
|
+
let currentClosestKeyword;
|
|
248
|
+
|
|
249
|
+
for (const keyword of Object.keys(cssKeywords)) {
|
|
250
|
+
const value = cssKeywords[keyword];
|
|
251
|
+
|
|
252
|
+
// Compute comparative distance
|
|
253
|
+
const distance = comparativeDistance(rgb, value);
|
|
254
|
+
|
|
255
|
+
// Check if its less, if so set as closest
|
|
256
|
+
if (distance < currentClosestDistance) {
|
|
257
|
+
currentClosestDistance = distance;
|
|
258
|
+
currentClosestKeyword = keyword;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
return currentClosestKeyword;
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
convert.keyword.rgb = function (keyword) {
|
|
266
|
+
return cssKeywords[keyword];
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
convert.rgb.xyz = function (rgb) {
|
|
270
|
+
// Assume sRGB
|
|
271
|
+
const r = srgbNonlinearTransformInv(rgb[0] / 255);
|
|
272
|
+
const g = srgbNonlinearTransformInv(rgb[1] / 255);
|
|
273
|
+
const b = srgbNonlinearTransformInv(rgb[2] / 255);
|
|
274
|
+
|
|
275
|
+
const x = (r * 0.412_456_4) + (g * 0.357_576_1) + (b * 0.180_437_5);
|
|
276
|
+
const y = (r * 0.212_672_9) + (g * 0.715_152_2) + (b * 0.072_175);
|
|
277
|
+
const z = (r * 0.019_333_9) + (g * 0.119_192) + (b * 0.950_304_1);
|
|
278
|
+
|
|
279
|
+
return [x * 100, y * 100, z * 100];
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
convert.rgb.lab = function (rgb) {
|
|
283
|
+
const xyz = convert.rgb.xyz(rgb);
|
|
284
|
+
let x = xyz[0];
|
|
285
|
+
let y = xyz[1];
|
|
286
|
+
let z = xyz[2];
|
|
287
|
+
|
|
288
|
+
x /= 95.047;
|
|
289
|
+
y /= 100;
|
|
290
|
+
z /= 108.883;
|
|
291
|
+
|
|
292
|
+
x = x > LAB_FT ? (x ** (1 / 3)) : (7.787 * x) + (16 / 116);
|
|
293
|
+
y = y > LAB_FT ? (y ** (1 / 3)) : (7.787 * y) + (16 / 116);
|
|
294
|
+
z = z > LAB_FT ? (z ** (1 / 3)) : (7.787 * z) + (16 / 116);
|
|
295
|
+
|
|
296
|
+
const l = (116 * y) - 16;
|
|
297
|
+
const a = 500 * (x - y);
|
|
298
|
+
const b = 200 * (y - z);
|
|
299
|
+
|
|
300
|
+
return [l, a, b];
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
convert.hsl.rgb = function (hsl) {
|
|
304
|
+
const h = hsl[0] / 360;
|
|
305
|
+
const s = hsl[1] / 100;
|
|
306
|
+
const l = hsl[2] / 100;
|
|
307
|
+
let t3;
|
|
308
|
+
let value;
|
|
309
|
+
|
|
310
|
+
if (s === 0) {
|
|
311
|
+
value = l * 255;
|
|
312
|
+
return [value, value, value];
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
const t2 = l < 0.5 ? l * (1 + s) : l + s - l * s;
|
|
316
|
+
|
|
317
|
+
const t1 = 2 * l - t2;
|
|
318
|
+
|
|
319
|
+
const rgb = [0, 0, 0];
|
|
320
|
+
for (let i = 0; i < 3; i++) {
|
|
321
|
+
t3 = h + 1 / 3 * -(i - 1);
|
|
322
|
+
if (t3 < 0) {
|
|
323
|
+
t3++;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
if (t3 > 1) {
|
|
327
|
+
t3--;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
if (6 * t3 < 1) {
|
|
331
|
+
value = t1 + (t2 - t1) * 6 * t3;
|
|
332
|
+
} else if (2 * t3 < 1) {
|
|
333
|
+
value = t2;
|
|
334
|
+
} else if (3 * t3 < 2) {
|
|
335
|
+
value = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
|
|
336
|
+
} else {
|
|
337
|
+
value = t1;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
rgb[i] = value * 255;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
return rgb;
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
convert.hsl.hsv = function (hsl) {
|
|
347
|
+
const h = hsl[0];
|
|
348
|
+
let s = hsl[1] / 100;
|
|
349
|
+
let l = hsl[2] / 100;
|
|
350
|
+
let smin = s;
|
|
351
|
+
const lmin = Math.max(l, 0.01);
|
|
352
|
+
|
|
353
|
+
l *= 2;
|
|
354
|
+
s *= (l <= 1) ? l : 2 - l;
|
|
355
|
+
smin *= lmin <= 1 ? lmin : 2 - lmin;
|
|
356
|
+
const v = (l + s) / 2;
|
|
357
|
+
const sv = l === 0 ? (2 * smin) / (lmin + smin) : (2 * s) / (l + s);
|
|
358
|
+
|
|
359
|
+
return [h, sv * 100, v * 100];
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
convert.hsv.rgb = function (hsv) {
|
|
363
|
+
const h = hsv[0] / 60;
|
|
364
|
+
const s = hsv[1] / 100;
|
|
365
|
+
let v = hsv[2] / 100;
|
|
366
|
+
const hi = Math.floor(h) % 6;
|
|
367
|
+
|
|
368
|
+
const f = h - Math.floor(h);
|
|
369
|
+
const p = 255 * v * (1 - s);
|
|
370
|
+
const q = 255 * v * (1 - (s * f));
|
|
371
|
+
const t = 255 * v * (1 - (s * (1 - f)));
|
|
372
|
+
v *= 255;
|
|
373
|
+
|
|
374
|
+
switch (hi) {
|
|
375
|
+
case 0: {
|
|
376
|
+
return [v, t, p];
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
case 1: {
|
|
380
|
+
return [q, v, p];
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
case 2: {
|
|
384
|
+
return [p, v, t];
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
case 3: {
|
|
388
|
+
return [p, q, v];
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
case 4: {
|
|
392
|
+
return [t, p, v];
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
case 5: {
|
|
396
|
+
return [v, p, q];
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
};
|
|
400
|
+
|
|
401
|
+
convert.hsv.hsl = function (hsv) {
|
|
402
|
+
const h = hsv[0];
|
|
403
|
+
const s = hsv[1] / 100;
|
|
404
|
+
const v = hsv[2] / 100;
|
|
405
|
+
const vmin = Math.max(v, 0.01);
|
|
406
|
+
let sl;
|
|
407
|
+
let l;
|
|
408
|
+
|
|
409
|
+
l = (2 - s) * v;
|
|
410
|
+
const lmin = (2 - s) * vmin;
|
|
411
|
+
sl = s * vmin;
|
|
412
|
+
sl /= (lmin <= 1) ? lmin : 2 - lmin;
|
|
413
|
+
sl = sl || 0;
|
|
414
|
+
l /= 2;
|
|
415
|
+
|
|
416
|
+
return [h, sl * 100, l * 100];
|
|
417
|
+
};
|
|
418
|
+
|
|
419
|
+
// http://dev.w3.org/csswg/css-color/#hwb-to-rgb
|
|
420
|
+
convert.hwb.rgb = function (hwb) {
|
|
421
|
+
const h = hwb[0] / 360;
|
|
422
|
+
let wh = hwb[1] / 100;
|
|
423
|
+
let bl = hwb[2] / 100;
|
|
424
|
+
const ratio = wh + bl;
|
|
425
|
+
let f;
|
|
426
|
+
|
|
427
|
+
// Wh + bl cant be > 1
|
|
428
|
+
if (ratio > 1) {
|
|
429
|
+
wh /= ratio;
|
|
430
|
+
bl /= ratio;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
const i = Math.floor(6 * h);
|
|
434
|
+
const v = 1 - bl;
|
|
435
|
+
f = 6 * h - i;
|
|
436
|
+
|
|
437
|
+
// eslint-disable-next-line no-bitwise
|
|
438
|
+
if ((i & 0x01) !== 0) {
|
|
439
|
+
f = 1 - f;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
const n = wh + f * (v - wh); // Linear interpolation
|
|
443
|
+
|
|
444
|
+
let r;
|
|
445
|
+
let g;
|
|
446
|
+
let b;
|
|
447
|
+
/* eslint-disable max-statements-per-line,no-multi-spaces, default-case-last */
|
|
448
|
+
switch (i) {
|
|
449
|
+
default:
|
|
450
|
+
case 6:
|
|
451
|
+
case 0: { r = v; g = n; b = wh; break;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
case 1: { r = n; g = v; b = wh; break;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
case 2: { r = wh; g = v; b = n; break;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
case 3: { r = wh; g = n; b = v; break;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
case 4: { r = n; g = wh; b = v; break;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
case 5: { r = v; g = wh; b = n; break;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
/* eslint-enable max-statements-per-line,no-multi-spaces, default-case-last */
|
|
470
|
+
|
|
471
|
+
return [r * 255, g * 255, b * 255];
|
|
472
|
+
};
|
|
473
|
+
|
|
474
|
+
convert.cmyk.rgb = function (cmyk) {
|
|
475
|
+
const c = cmyk[0] / 100;
|
|
476
|
+
const m = cmyk[1] / 100;
|
|
477
|
+
const y = cmyk[2] / 100;
|
|
478
|
+
const k = cmyk[3] / 100;
|
|
479
|
+
|
|
480
|
+
const r = 1 - Math.min(1, c * (1 - k) + k);
|
|
481
|
+
const g = 1 - Math.min(1, m * (1 - k) + k);
|
|
482
|
+
const b = 1 - Math.min(1, y * (1 - k) + k);
|
|
483
|
+
|
|
484
|
+
return [r * 255, g * 255, b * 255];
|
|
485
|
+
};
|
|
486
|
+
|
|
487
|
+
convert.xyz.rgb = function (xyz) {
|
|
488
|
+
const x = xyz[0] / 100;
|
|
489
|
+
const y = xyz[1] / 100;
|
|
490
|
+
const z = xyz[2] / 100;
|
|
491
|
+
let r;
|
|
492
|
+
let g;
|
|
493
|
+
let b;
|
|
494
|
+
|
|
495
|
+
r = (x * 3.240_454_2) + (y * -1.537_138_5) + (z * -0.498_531_4);
|
|
496
|
+
g = (x * -0.969_266) + (y * 1.876_010_8) + (z * 0.041_556);
|
|
497
|
+
b = (x * 0.055_643_4) + (y * -0.204_025_9) + (z * 1.057_225_2);
|
|
498
|
+
|
|
499
|
+
// Assume sRGB
|
|
500
|
+
r = srgbNonlinearTransform(r);
|
|
501
|
+
g = srgbNonlinearTransform(g);
|
|
502
|
+
b = srgbNonlinearTransform(b);
|
|
503
|
+
|
|
504
|
+
return [r * 255, g * 255, b * 255];
|
|
505
|
+
};
|
|
506
|
+
|
|
507
|
+
convert.xyz.lab = function (xyz) {
|
|
508
|
+
let x = xyz[0];
|
|
509
|
+
let y = xyz[1];
|
|
510
|
+
let z = xyz[2];
|
|
511
|
+
|
|
512
|
+
x /= 95.047;
|
|
513
|
+
y /= 100;
|
|
514
|
+
z /= 108.883;
|
|
515
|
+
|
|
516
|
+
x = x > LAB_FT ? (x ** (1 / 3)) : (7.787 * x) + (16 / 116);
|
|
517
|
+
y = y > LAB_FT ? (y ** (1 / 3)) : (7.787 * y) + (16 / 116);
|
|
518
|
+
z = z > LAB_FT ? (z ** (1 / 3)) : (7.787 * z) + (16 / 116);
|
|
519
|
+
|
|
520
|
+
const l = (116 * y) - 16;
|
|
521
|
+
const a = 500 * (x - y);
|
|
522
|
+
const b = 200 * (y - z);
|
|
523
|
+
|
|
524
|
+
return [l, a, b];
|
|
525
|
+
};
|
|
526
|
+
|
|
527
|
+
convert.xyz.oklab = function (xyz) {
|
|
528
|
+
const x = xyz[0] / 100;
|
|
529
|
+
const y = xyz[1] / 100;
|
|
530
|
+
const z = xyz[2] / 100;
|
|
531
|
+
|
|
532
|
+
const lp = Math.cbrt(0.818_933_010_1 * x + 0.361_866_742_4 * y - 0.128_859_713_7 * z);
|
|
533
|
+
const mp = Math.cbrt(0.032_984_543_6 * x + 0.929_311_871_5 * y + 0.036_145_638_7 * z);
|
|
534
|
+
const sp = Math.cbrt(0.048_200_301_8 * x + 0.264_366_269_1 * y + 0.633_851_707 * z);
|
|
535
|
+
|
|
536
|
+
const l = 0.210_454_255_3 * lp + 0.793_617_785 * mp - 0.004_072_046_8 * sp;
|
|
537
|
+
const a = 1.977_998_495_1 * lp - 2.428_592_205 * mp + 0.450_593_709_9 * sp;
|
|
538
|
+
const b = 0.025_904_037_1 * lp + 0.782_771_766_2 * mp - 0.808_675_766 * sp;
|
|
539
|
+
|
|
540
|
+
return [l * 100, a * 100, b * 100];
|
|
541
|
+
};
|
|
542
|
+
|
|
543
|
+
convert.oklab.oklch = function (oklab) {
|
|
544
|
+
return convert.lab.lch(oklab);
|
|
545
|
+
};
|
|
546
|
+
|
|
547
|
+
convert.oklab.xyz = function (oklab) {
|
|
548
|
+
const ll = oklab[0] / 100;
|
|
549
|
+
const a = oklab[1] / 100;
|
|
550
|
+
const b = oklab[2] / 100;
|
|
551
|
+
|
|
552
|
+
const l = (0.999_999_998 * ll + 0.396_337_792 * a + 0.215_803_758 * b) ** 3;
|
|
553
|
+
const m = (1.000_000_008 * ll - 0.105_561_342 * a - 0.063_854_175 * b) ** 3;
|
|
554
|
+
const s = (1.000_000_055 * ll - 0.089_484_182 * a - 1.291_485_538 * b) ** 3;
|
|
555
|
+
|
|
556
|
+
const x = 1.227_013_851 * l - 0.557_799_98 * m + 0.281_256_149 * s;
|
|
557
|
+
const y = -0.040_580_178 * l + 1.112_256_87 * m - 0.071_676_679 * s;
|
|
558
|
+
const z = -0.076_381_285 * l - 0.421_481_978 * m + 1.586_163_22 * s;
|
|
559
|
+
|
|
560
|
+
return [x * 100, y * 100, z * 100];
|
|
561
|
+
};
|
|
562
|
+
|
|
563
|
+
convert.oklab.rgb = function (oklab) {
|
|
564
|
+
const ll = oklab[0] / 100;
|
|
565
|
+
const aa = oklab[1] / 100;
|
|
566
|
+
const bb = oklab[2] / 100;
|
|
567
|
+
|
|
568
|
+
const l = (ll + 0.396_337_777_4 * aa + 0.215_803_757_3 * bb) ** 3;
|
|
569
|
+
const m = (ll - 0.105_561_345_8 * aa - 0.063_854_172_8 * bb) ** 3;
|
|
570
|
+
const s = (ll - 0.089_484_177_5 * aa - 1.291_485_548 * bb) ** 3;
|
|
571
|
+
|
|
572
|
+
// Assume sRGB
|
|
573
|
+
const r = srgbNonlinearTransform(4.076_741_662_1 * l - 3.307_711_591_3 * m + 0.230_969_929_2 * s);
|
|
574
|
+
const g = srgbNonlinearTransform(-1.268_438_004_6 * l + 2.609_757_401_1 * m - 0.341_319_396_5 * s);
|
|
575
|
+
const b = srgbNonlinearTransform(-0.004_196_086_3 * l - 0.703_418_614_7 * m + 1.707_614_701 * s);
|
|
576
|
+
|
|
577
|
+
return [r * 255, g * 255, b * 255];
|
|
578
|
+
};
|
|
579
|
+
|
|
580
|
+
convert.oklch.oklab = function (oklch) {
|
|
581
|
+
return convert.lch.lab(oklch);
|
|
582
|
+
};
|
|
583
|
+
|
|
584
|
+
convert.lab.xyz = function (lab) {
|
|
585
|
+
const l = lab[0];
|
|
586
|
+
const a = lab[1];
|
|
587
|
+
const b = lab[2];
|
|
588
|
+
let x;
|
|
589
|
+
let y;
|
|
590
|
+
let z;
|
|
591
|
+
|
|
592
|
+
y = (l + 16) / 116;
|
|
593
|
+
x = a / 500 + y;
|
|
594
|
+
z = y - b / 200;
|
|
595
|
+
|
|
596
|
+
const y2 = y ** 3;
|
|
597
|
+
const x2 = x ** 3;
|
|
598
|
+
const z2 = z ** 3;
|
|
599
|
+
y = y2 > LAB_FT ? y2 : (y - 16 / 116) / 7.787;
|
|
600
|
+
x = x2 > LAB_FT ? x2 : (x - 16 / 116) / 7.787;
|
|
601
|
+
z = z2 > LAB_FT ? z2 : (z - 16 / 116) / 7.787;
|
|
602
|
+
|
|
603
|
+
// Illuminant D65 XYZ Tristrimulus Values
|
|
604
|
+
// https://en.wikipedia.org/wiki/CIE_1931_color_space
|
|
605
|
+
x *= 95.047;
|
|
606
|
+
y *= 100;
|
|
607
|
+
z *= 108.883;
|
|
608
|
+
|
|
609
|
+
return [x, y, z];
|
|
610
|
+
};
|
|
611
|
+
|
|
612
|
+
convert.lab.lch = function (lab) {
|
|
613
|
+
const l = lab[0];
|
|
614
|
+
const a = lab[1];
|
|
615
|
+
const b = lab[2];
|
|
616
|
+
let h;
|
|
617
|
+
|
|
618
|
+
const hr = Math.atan2(b, a);
|
|
619
|
+
h = hr * 360 / 2 / Math.PI;
|
|
620
|
+
|
|
621
|
+
if (h < 0) {
|
|
622
|
+
h += 360;
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
const c = Math.sqrt(a * a + b * b);
|
|
626
|
+
|
|
627
|
+
return [l, c, h];
|
|
628
|
+
};
|
|
629
|
+
|
|
630
|
+
convert.lch.lab = function (lch) {
|
|
631
|
+
const l = lch[0];
|
|
632
|
+
const c = lch[1];
|
|
633
|
+
const h = lch[2];
|
|
634
|
+
|
|
635
|
+
const hr = h / 360 * 2 * Math.PI;
|
|
636
|
+
const a = c * Math.cos(hr);
|
|
637
|
+
const b = c * Math.sin(hr);
|
|
638
|
+
|
|
639
|
+
return [l, a, b];
|
|
640
|
+
};
|
|
641
|
+
|
|
642
|
+
convert.rgb.ansi16 = function (args, saturation = null) {
|
|
643
|
+
const [r, g, b] = args;
|
|
644
|
+
let value = saturation === null ? convert.rgb.hsv(args)[2] : saturation; // Hsv -> ansi16 optimization
|
|
645
|
+
|
|
646
|
+
value = Math.round(value / 50);
|
|
647
|
+
|
|
648
|
+
if (value === 0) {
|
|
649
|
+
return 30;
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
let ansi = 30
|
|
653
|
+
/* eslint-disable no-bitwise */
|
|
654
|
+
+ ((Math.round(b / 255) << 2)
|
|
655
|
+
| (Math.round(g / 255) << 1)
|
|
656
|
+
| Math.round(r / 255));
|
|
657
|
+
/* eslint-enable no-bitwise */
|
|
658
|
+
|
|
659
|
+
if (value === 2) {
|
|
660
|
+
ansi += 60;
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
return ansi;
|
|
664
|
+
};
|
|
665
|
+
|
|
666
|
+
convert.hsv.ansi16 = function (args) {
|
|
667
|
+
// Optimization here; we already know the value and don't need to get
|
|
668
|
+
// it converted for us.
|
|
669
|
+
return convert.rgb.ansi16(convert.hsv.rgb(args), args[2]);
|
|
670
|
+
};
|
|
671
|
+
|
|
672
|
+
convert.rgb.ansi256 = function (args) {
|
|
673
|
+
const r = args[0];
|
|
674
|
+
const g = args[1];
|
|
675
|
+
const b = args[2];
|
|
676
|
+
|
|
677
|
+
// We use the extended greyscale palette here, with the exception of
|
|
678
|
+
// black and white. normal palette only has 4 greyscale shades.
|
|
679
|
+
// eslint-disable-next-line no-bitwise
|
|
680
|
+
if (r >> 4 === g >> 4 && g >> 4 === b >> 4) {
|
|
681
|
+
if (r < 8) {
|
|
682
|
+
return 16;
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
if (r > 248) {
|
|
686
|
+
return 231;
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
return Math.round(((r - 8) / 247) * 24) + 232;
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
const ansi = 16
|
|
693
|
+
+ (36 * Math.round(r / 255 * 5))
|
|
694
|
+
+ (6 * Math.round(g / 255 * 5))
|
|
695
|
+
+ Math.round(b / 255 * 5);
|
|
696
|
+
|
|
697
|
+
return ansi;
|
|
698
|
+
};
|
|
699
|
+
|
|
700
|
+
convert.ansi16.rgb = function (args) {
|
|
701
|
+
args = args[0];
|
|
702
|
+
|
|
703
|
+
let color = args % 10;
|
|
704
|
+
|
|
705
|
+
// Handle greyscale
|
|
706
|
+
if (color === 0 || color === 7) {
|
|
707
|
+
if (args > 50) {
|
|
708
|
+
color += 3.5;
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
color = color / 10.5 * 255;
|
|
712
|
+
|
|
713
|
+
return [color, color, color];
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
const mult = (Math.trunc(args > 50) + 1) * 0.5;
|
|
717
|
+
/* eslint-disable no-bitwise */
|
|
718
|
+
const r = ((color & 1) * mult) * 255;
|
|
719
|
+
const g = (((color >> 1) & 1) * mult) * 255;
|
|
720
|
+
const b = (((color >> 2) & 1) * mult) * 255;
|
|
721
|
+
/* eslint-enable no-bitwise */
|
|
722
|
+
|
|
723
|
+
return [r, g, b];
|
|
724
|
+
};
|
|
725
|
+
|
|
726
|
+
convert.ansi256.rgb = function (args) {
|
|
727
|
+
args = args[0];
|
|
728
|
+
|
|
729
|
+
// Handle greyscale
|
|
730
|
+
if (args >= 232) {
|
|
731
|
+
const c = (args - 232) * 10 + 8;
|
|
732
|
+
return [c, c, c];
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
args -= 16;
|
|
736
|
+
|
|
737
|
+
let rem;
|
|
738
|
+
const r = Math.floor(args / 36) / 5 * 255;
|
|
739
|
+
const g = Math.floor((rem = args % 36) / 6) / 5 * 255;
|
|
740
|
+
const b = (rem % 6) / 5 * 255;
|
|
741
|
+
|
|
742
|
+
return [r, g, b];
|
|
743
|
+
};
|
|
744
|
+
|
|
745
|
+
convert.rgb.hex = function (args) {
|
|
746
|
+
/* eslint-disable no-bitwise */
|
|
747
|
+
const integer = ((Math.round(args[0]) & 0xFF) << 16)
|
|
748
|
+
+ ((Math.round(args[1]) & 0xFF) << 8)
|
|
749
|
+
+ (Math.round(args[2]) & 0xFF);
|
|
750
|
+
/* eslint-enable no-bitwise */
|
|
751
|
+
|
|
752
|
+
const string = integer.toString(16).toUpperCase();
|
|
753
|
+
return '000000'.slice(string.length) + string;
|
|
754
|
+
};
|
|
755
|
+
|
|
756
|
+
convert.hex.rgb = function (args) {
|
|
757
|
+
const match = args.toString(16).match(/[a-f\d]{6}|[a-f\d]{3}/i);
|
|
758
|
+
if (!match) {
|
|
759
|
+
return [0, 0, 0];
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
let colorString = match[0];
|
|
763
|
+
|
|
764
|
+
if (match[0].length === 3) {
|
|
765
|
+
colorString = [...colorString].map(char => char + char).join('');
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
const integer = Number.parseInt(colorString, 16);
|
|
769
|
+
/* eslint-disable no-bitwise */
|
|
770
|
+
const r = (integer >> 16) & 0xFF;
|
|
771
|
+
const g = (integer >> 8) & 0xFF;
|
|
772
|
+
const b = integer & 0xFF;
|
|
773
|
+
/* eslint-enable no-bitwise */
|
|
774
|
+
|
|
775
|
+
return [r, g, b];
|
|
776
|
+
};
|
|
777
|
+
|
|
778
|
+
convert.rgb.hcg = function (rgb) {
|
|
779
|
+
const r = rgb[0] / 255;
|
|
780
|
+
const g = rgb[1] / 255;
|
|
781
|
+
const b = rgb[2] / 255;
|
|
782
|
+
const max = Math.max(Math.max(r, g), b);
|
|
783
|
+
const min = Math.min(Math.min(r, g), b);
|
|
784
|
+
const chroma = (max - min);
|
|
785
|
+
let hue;
|
|
786
|
+
|
|
787
|
+
const grayscale = chroma < 1 ? min / (1 - chroma) : 0;
|
|
788
|
+
|
|
789
|
+
if (chroma <= 0) {
|
|
790
|
+
hue = 0;
|
|
791
|
+
} else if (max === r) {
|
|
792
|
+
hue = ((g - b) / chroma) % 6;
|
|
793
|
+
} else if (max === g) {
|
|
794
|
+
hue = 2 + (b - r) / chroma;
|
|
795
|
+
} else {
|
|
796
|
+
hue = 4 + (r - g) / chroma;
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
hue /= 6;
|
|
800
|
+
hue %= 1;
|
|
801
|
+
|
|
802
|
+
return [hue * 360, chroma * 100, grayscale * 100];
|
|
803
|
+
};
|
|
804
|
+
|
|
805
|
+
convert.hsl.hcg = function (hsl) {
|
|
806
|
+
const s = hsl[1] / 100;
|
|
807
|
+
const l = hsl[2] / 100;
|
|
808
|
+
|
|
809
|
+
const c = l < 0.5 ? (2 * s * l) : (2 * s * (1 - l));
|
|
810
|
+
|
|
811
|
+
let f = 0;
|
|
812
|
+
if (c < 1) {
|
|
813
|
+
f = (l - 0.5 * c) / (1 - c);
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
return [hsl[0], c * 100, f * 100];
|
|
817
|
+
};
|
|
818
|
+
|
|
819
|
+
convert.hsv.hcg = function (hsv) {
|
|
820
|
+
const s = hsv[1] / 100;
|
|
821
|
+
const v = hsv[2] / 100;
|
|
822
|
+
|
|
823
|
+
const c = s * v;
|
|
824
|
+
let f = 0;
|
|
825
|
+
|
|
826
|
+
if (c < 1) {
|
|
827
|
+
f = (v - c) / (1 - c);
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
return [hsv[0], c * 100, f * 100];
|
|
831
|
+
};
|
|
832
|
+
|
|
833
|
+
convert.hcg.rgb = function (hcg) {
|
|
834
|
+
const h = hcg[0] / 360;
|
|
835
|
+
const c = hcg[1] / 100;
|
|
836
|
+
const g = hcg[2] / 100;
|
|
837
|
+
|
|
838
|
+
if (c === 0) {
|
|
839
|
+
return [g * 255, g * 255, g * 255];
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
const pure = [0, 0, 0];
|
|
843
|
+
const hi = (h % 1) * 6;
|
|
844
|
+
const v = hi % 1;
|
|
845
|
+
const w = 1 - v;
|
|
846
|
+
let mg = 0;
|
|
847
|
+
|
|
848
|
+
/* eslint-disable max-statements-per-line */
|
|
849
|
+
switch (Math.floor(hi)) {
|
|
850
|
+
case 0: {
|
|
851
|
+
pure[0] = 1; pure[1] = v; pure[2] = 0; break;
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
case 1: {
|
|
855
|
+
pure[0] = w; pure[1] = 1; pure[2] = 0; break;
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
case 2: {
|
|
859
|
+
pure[0] = 0; pure[1] = 1; pure[2] = v; break;
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
case 3: {
|
|
863
|
+
pure[0] = 0; pure[1] = w; pure[2] = 1; break;
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
case 4: {
|
|
867
|
+
pure[0] = v; pure[1] = 0; pure[2] = 1; break;
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
default: {
|
|
871
|
+
pure[0] = 1; pure[1] = 0; pure[2] = w;
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
/* eslint-enable max-statements-per-line */
|
|
875
|
+
|
|
876
|
+
mg = (1 - c) * g;
|
|
877
|
+
|
|
878
|
+
return [
|
|
879
|
+
(c * pure[0] + mg) * 255,
|
|
880
|
+
(c * pure[1] + mg) * 255,
|
|
881
|
+
(c * pure[2] + mg) * 255,
|
|
882
|
+
];
|
|
883
|
+
};
|
|
884
|
+
|
|
885
|
+
convert.hcg.hsv = function (hcg) {
|
|
886
|
+
const c = hcg[1] / 100;
|
|
887
|
+
const g = hcg[2] / 100;
|
|
888
|
+
|
|
889
|
+
const v = c + g * (1 - c);
|
|
890
|
+
let f = 0;
|
|
891
|
+
|
|
892
|
+
if (v > 0) {
|
|
893
|
+
f = c / v;
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
return [hcg[0], f * 100, v * 100];
|
|
897
|
+
};
|
|
898
|
+
|
|
899
|
+
convert.hcg.hsl = function (hcg) {
|
|
900
|
+
const c = hcg[1] / 100;
|
|
901
|
+
const g = hcg[2] / 100;
|
|
902
|
+
|
|
903
|
+
const l = g * (1 - c) + 0.5 * c;
|
|
904
|
+
let s = 0;
|
|
905
|
+
|
|
906
|
+
if (l > 0 && l < 0.5) {
|
|
907
|
+
s = c / (2 * l);
|
|
908
|
+
} else if (l >= 0.5 && l < 1) {
|
|
909
|
+
s = c / (2 * (1 - l));
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
return [hcg[0], s * 100, l * 100];
|
|
913
|
+
};
|
|
914
|
+
|
|
915
|
+
convert.hcg.hwb = function (hcg) {
|
|
916
|
+
const c = hcg[1] / 100;
|
|
917
|
+
const g = hcg[2] / 100;
|
|
918
|
+
const v = c + g * (1 - c);
|
|
919
|
+
return [hcg[0], (v - c) * 100, (1 - v) * 100];
|
|
920
|
+
};
|
|
921
|
+
|
|
922
|
+
convert.hwb.hcg = function (hwb) {
|
|
923
|
+
const w = hwb[1] / 100;
|
|
924
|
+
const b = hwb[2] / 100;
|
|
925
|
+
const v = 1 - b;
|
|
926
|
+
const c = v - w;
|
|
927
|
+
let g = 0;
|
|
928
|
+
|
|
929
|
+
if (c < 1) {
|
|
930
|
+
g = (v - c) / (1 - c);
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
return [hwb[0], c * 100, g * 100];
|
|
934
|
+
};
|
|
935
|
+
|
|
936
|
+
convert.apple.rgb = function (apple) {
|
|
937
|
+
return [(apple[0] / 65_535) * 255, (apple[1] / 65_535) * 255, (apple[2] / 65_535) * 255];
|
|
938
|
+
};
|
|
939
|
+
|
|
940
|
+
convert.rgb.apple = function (rgb) {
|
|
941
|
+
return [(rgb[0] / 255) * 65_535, (rgb[1] / 255) * 65_535, (rgb[2] / 255) * 65_535];
|
|
942
|
+
};
|
|
943
|
+
|
|
944
|
+
convert.gray.rgb = function (args) {
|
|
945
|
+
return [args[0] / 100 * 255, args[0] / 100 * 255, args[0] / 100 * 255];
|
|
946
|
+
};
|
|
947
|
+
|
|
948
|
+
convert.gray.hsl = function (args) {
|
|
949
|
+
return [0, 0, args[0]];
|
|
950
|
+
};
|
|
951
|
+
|
|
952
|
+
convert.gray.hsv = convert.gray.hsl;
|
|
953
|
+
|
|
954
|
+
convert.gray.hwb = function (gray) {
|
|
955
|
+
return [0, 100, gray[0]];
|
|
956
|
+
};
|
|
957
|
+
|
|
958
|
+
convert.gray.cmyk = function (gray) {
|
|
959
|
+
return [0, 0, 0, gray[0]];
|
|
960
|
+
};
|
|
961
|
+
|
|
962
|
+
convert.gray.lab = function (gray) {
|
|
963
|
+
return [gray[0], 0, 0];
|
|
964
|
+
};
|
|
965
|
+
|
|
966
|
+
convert.gray.hex = function (gray) {
|
|
967
|
+
/* eslint-disable no-bitwise */
|
|
968
|
+
const value = Math.round(gray[0] / 100 * 255) & 0xFF;
|
|
969
|
+
const integer = (value << 16) + (value << 8) + value;
|
|
970
|
+
/* eslint-enable no-bitwise */
|
|
971
|
+
|
|
972
|
+
const string = integer.toString(16).toUpperCase();
|
|
973
|
+
return '000000'.slice(string.length) + string;
|
|
974
|
+
};
|
|
975
|
+
|
|
976
|
+
convert.rgb.gray = function (rgb) {
|
|
977
|
+
const value = (rgb[0] + rgb[1] + rgb[2]) / 3;
|
|
978
|
+
return [value / 255 * 100];
|
|
979
|
+
};
|
|
980
|
+
|
|
981
|
+
export { convert as default };
|
|
982
|
+
//# sourceMappingURL=conversions.js.map
|