[6a3a178] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | Object.defineProperty(exports, '__esModule', { value: true });
|
---|
| 4 |
|
---|
| 5 | /* Convert between RGB and Hue
|
---|
| 6 | /* ========================================================================== */
|
---|
| 7 |
|
---|
| 8 | function rgb2hue(rgbR, rgbG, rgbB) {
|
---|
| 9 | var fallbackhue = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
---|
| 10 |
|
---|
| 11 | var value = rgb2value(rgbR, rgbG, rgbB);
|
---|
| 12 | var whiteness = rgb2whiteness(rgbR, rgbG, rgbB);
|
---|
| 13 | var delta = value - whiteness;
|
---|
| 14 |
|
---|
| 15 | if (delta) {
|
---|
| 16 | // calculate segment
|
---|
| 17 | var segment = value === rgbR ? (rgbG - rgbB) / delta : value === rgbG ? (rgbB - rgbR) / delta : (rgbR - rgbG) / delta;
|
---|
| 18 |
|
---|
| 19 | // calculate shift
|
---|
| 20 | var shift = value === rgbR ? segment < 0 ? 360 / 60 : 0 / 60 : value === rgbG ? 120 / 60 : 240 / 60;
|
---|
| 21 |
|
---|
| 22 | // calculate hue
|
---|
| 23 | var hue = (segment + shift) * 60;
|
---|
| 24 |
|
---|
| 25 | return hue;
|
---|
| 26 | } else {
|
---|
| 27 | // otherwise return the fallback hue
|
---|
| 28 | return fallbackhue;
|
---|
| 29 | }
|
---|
| 30 | }
|
---|
| 31 |
|
---|
| 32 | function hue2rgb(t1, t2, hue) {
|
---|
| 33 | // calculate the ranged hue
|
---|
| 34 | var rhue = hue < 0 ? hue + 360 : hue > 360 ? hue - 360 : hue;
|
---|
| 35 |
|
---|
| 36 | // calculate the rgb value
|
---|
| 37 | var rgb = rhue * 6 < 360 ? t1 + (t2 - t1) * rhue / 60 : rhue * 2 < 360 ? t2 : rhue * 3 < 720 ? t1 + (t2 - t1) * (240 - rhue) / 60 : t1;
|
---|
| 38 |
|
---|
| 39 | return rgb;
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | /* RGB tooling
|
---|
| 43 | /* ========================================================================== */
|
---|
| 44 |
|
---|
| 45 | function rgb2value(rgbR, rgbG, rgbB) {
|
---|
| 46 | var value = Math.max(rgbR, rgbG, rgbB);
|
---|
| 47 |
|
---|
| 48 | return value;
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | function rgb2whiteness(rgbR, rgbG, rgbB) {
|
---|
| 52 | var whiteness = Math.min(rgbR, rgbG, rgbB);
|
---|
| 53 |
|
---|
| 54 | return whiteness;
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | /* Math matrix
|
---|
| 58 | /* ========================================================================== */
|
---|
| 59 |
|
---|
| 60 | function matrix(params, mats) {
|
---|
| 61 | return mats.map(function (mat) {
|
---|
| 62 | return mat.reduce(function (acc, value, index) {
|
---|
| 63 | return acc + params[index] * value;
|
---|
| 64 | }, 0);
|
---|
| 65 | });
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | /* D50 reference white
|
---|
| 69 | /* ========================================================================== */
|
---|
| 70 |
|
---|
| 71 | var wd50X = 96.42;
|
---|
| 72 | var wd50Y = 100;
|
---|
| 73 | var wd50Z = 82.49;
|
---|
| 74 |
|
---|
| 75 | var epsilon = Math.pow(6, 3) / Math.pow(29, 3);
|
---|
| 76 |
|
---|
| 77 | /* Kappa
|
---|
| 78 | /* ========================================================================== */
|
---|
| 79 |
|
---|
| 80 | var kappa = Math.pow(29, 3) / Math.pow(3, 3);
|
---|
| 81 |
|
---|
| 82 | /* Convert between RGB and HSL
|
---|
| 83 | /* ========================================================================== */
|
---|
| 84 |
|
---|
| 85 | function rgb2hsl(rgbR, rgbG, rgbB, fallbackhue) {
|
---|
| 86 | var hslH = rgb2hue(rgbR, rgbG, rgbB, fallbackhue);
|
---|
| 87 | var hslV = rgb2value(rgbR, rgbG, rgbB);
|
---|
| 88 | var hslW = rgb2whiteness(rgbR, rgbG, rgbB);
|
---|
| 89 |
|
---|
| 90 | // calculate value/whiteness delta
|
---|
| 91 | var hslD = hslV - hslW;
|
---|
| 92 |
|
---|
| 93 | // calculate lightness
|
---|
| 94 | var hslL = (hslV + hslW) / 2;
|
---|
| 95 |
|
---|
| 96 | // calculate saturation
|
---|
| 97 | var hslS = hslD === 0 ? 0 : hslD / (100 - Math.abs(2 * hslL - 100)) * 100;
|
---|
| 98 |
|
---|
| 99 | return [hslH, hslS, hslL];
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | function hsl2rgb(hslH, hslS, hslL) {
|
---|
| 103 | // calcuate t2
|
---|
| 104 | var t2 = hslL <= 50 ? hslL * (hslS + 100) / 100 : hslL + hslS - hslL * hslS / 100;
|
---|
| 105 |
|
---|
| 106 | // calcuate t1
|
---|
| 107 | var t1 = hslL * 2 - t2;
|
---|
| 108 |
|
---|
| 109 | // calculate rgb
|
---|
| 110 | var _ref = [hue2rgb(t1, t2, hslH + 120), hue2rgb(t1, t2, hslH), hue2rgb(t1, t2, hslH - 120)],
|
---|
| 111 | rgbR = _ref[0],
|
---|
| 112 | rgbG = _ref[1],
|
---|
| 113 | rgbB = _ref[2];
|
---|
| 114 |
|
---|
| 115 |
|
---|
| 116 | return [rgbR, rgbG, rgbB];
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | /*
|
---|
| 120 |
|
---|
| 121 | References
|
---|
| 122 | ----------
|
---|
| 123 |
|
---|
| 124 | - https://www.w3.org/TR/css-color-3/#hsl-color
|
---|
| 125 | - https://www.w3.org/TR/css-color-4/#hsl-to-rgb
|
---|
| 126 | - https://www.rapidtables.com/convert/color/rgb-to-hsl.html
|
---|
| 127 | - https://www.rapidtables.com/convert/color/hsl-to-rgb.html
|
---|
| 128 |
|
---|
| 129 | /* ========================================================================== */
|
---|
| 130 |
|
---|
| 131 | var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
|
---|
| 132 |
|
---|
| 133 | /* Convert between RGB and HWB
|
---|
| 134 | /* ========================================================================== */
|
---|
| 135 |
|
---|
| 136 | function rgb2hwb(rgbR, rgbG, rgbB, fallbackhue) {
|
---|
| 137 | var hwbH = rgb2hue(rgbR, rgbG, rgbB, fallbackhue);
|
---|
| 138 | var hwbW = rgb2whiteness(rgbR, rgbG, rgbB);
|
---|
| 139 | var hwbV = rgb2value(rgbR, rgbG, rgbB);
|
---|
| 140 | var hwbB = 100 - hwbV;
|
---|
| 141 |
|
---|
| 142 | return [hwbH, hwbW, hwbB];
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 | function hwb2rgb(hwbH, hwbW, hwbB, fallbackhue) {
|
---|
| 146 | var _hsl2rgb$map = hsl2rgb(hwbH, 100, 50, fallbackhue).map(function (v) {
|
---|
| 147 | return v * (100 - hwbW - hwbB) / 100 + hwbW;
|
---|
| 148 | }),
|
---|
| 149 | _hsl2rgb$map2 = _slicedToArray(_hsl2rgb$map, 3),
|
---|
| 150 | rgbR = _hsl2rgb$map2[0],
|
---|
| 151 | rgbG = _hsl2rgb$map2[1],
|
---|
| 152 | rgbB = _hsl2rgb$map2[2];
|
---|
| 153 |
|
---|
| 154 | return [rgbR, rgbG, rgbB];
|
---|
| 155 | }
|
---|
| 156 |
|
---|
| 157 | /*
|
---|
| 158 |
|
---|
| 159 | References
|
---|
| 160 | ----------
|
---|
| 161 |
|
---|
| 162 | - https://www.w3.org/TR/css-color-4/#hwb-to-rgb
|
---|
| 163 | - http://alvyray.com/Papers/CG/hwb2rgb.htm
|
---|
| 164 |
|
---|
| 165 | /* ========================================================================== */
|
---|
| 166 |
|
---|
| 167 | var _slicedToArray$1 = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
|
---|
| 168 |
|
---|
| 169 | /* Convert between RGB and HSV
|
---|
| 170 | /* ========================================================================== */
|
---|
| 171 |
|
---|
| 172 | function rgb2hsv(rgbR, rgbG, rgbB, fallbackhue) {
|
---|
| 173 | var hsvV = rgb2value(rgbR, rgbG, rgbB);
|
---|
| 174 | var hsvW = rgb2whiteness(rgbR, rgbG, rgbB);
|
---|
| 175 | var hsvH = rgb2hue(rgbR, rgbG, rgbB, fallbackhue);
|
---|
| 176 |
|
---|
| 177 | // calculate saturation
|
---|
| 178 | var hsvS = hsvV === hsvW ? 0 : (hsvV - hsvW) / hsvV * 100;
|
---|
| 179 |
|
---|
| 180 | return [hsvH, hsvS, hsvV];
|
---|
| 181 | }
|
---|
| 182 |
|
---|
| 183 | function hsv2rgb(hsvH, hsvS, hsvV) {
|
---|
| 184 | var rgbI = Math.floor(hsvH / 60);
|
---|
| 185 |
|
---|
| 186 | // calculate rgb parts
|
---|
| 187 | var rgbF = hsvH / 60 - rgbI & 1 ? hsvH / 60 - rgbI : 1 - hsvH / 60 - rgbI;
|
---|
| 188 | var rgbM = hsvV * (100 - hsvS) / 100;
|
---|
| 189 | var rgbN = hsvV * (100 - hsvS * rgbF) / 100;
|
---|
| 190 |
|
---|
| 191 | var _ref = rgbI === 5 ? [hsvV, rgbM, rgbN] : rgbI === 4 ? [rgbN, rgbM, hsvV] : rgbI === 3 ? [rgbM, rgbN, hsvV] : rgbI === 2 ? [rgbM, hsvV, rgbN] : rgbI === 1 ? [rgbN, hsvV, rgbM] : [hsvV, rgbN, rgbM],
|
---|
| 192 | _ref2 = _slicedToArray$1(_ref, 3),
|
---|
| 193 | rgbR = _ref2[0],
|
---|
| 194 | rgbG = _ref2[1],
|
---|
| 195 | rgbB = _ref2[2];
|
---|
| 196 |
|
---|
| 197 | return [rgbR, rgbG, rgbB];
|
---|
| 198 | }
|
---|
| 199 |
|
---|
| 200 | /*
|
---|
| 201 |
|
---|
| 202 | References
|
---|
| 203 | ----------
|
---|
| 204 |
|
---|
| 205 | - http://alvyray.com/Papers/CG/hsv2rgb.htm
|
---|
| 206 |
|
---|
| 207 | /* ========================================================================== */
|
---|
| 208 |
|
---|
| 209 | var _slicedToArray$2 = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
|
---|
| 210 |
|
---|
| 211 | /* Convert between RGB and XYZ
|
---|
| 212 | /* ========================================================================== */
|
---|
| 213 |
|
---|
| 214 | function rgb2xyz(rgbR, rgbG, rgbB) {
|
---|
| 215 | var _map = [rgbR, rgbG, rgbB].map(function (v) {
|
---|
| 216 | return v > 4.045 ? Math.pow((v + 5.5) / 105.5, 2.4) * 100 : v / 12.92;
|
---|
| 217 | }),
|
---|
| 218 | _map2 = _slicedToArray$2(_map, 3),
|
---|
| 219 | lrgbR = _map2[0],
|
---|
| 220 | lrgbB = _map2[1],
|
---|
| 221 | lrgbG = _map2[2];
|
---|
| 222 |
|
---|
| 223 | var _matrix = matrix([lrgbR, lrgbB, lrgbG], [[0.4124564, 0.3575761, 0.1804375], [0.2126729, 0.7151522, 0.0721750], [0.0193339, 0.1191920, 0.9503041]]),
|
---|
| 224 | _matrix2 = _slicedToArray$2(_matrix, 3),
|
---|
| 225 | xyzX = _matrix2[0],
|
---|
| 226 | xyzY = _matrix2[1],
|
---|
| 227 | xyzZ = _matrix2[2];
|
---|
| 228 |
|
---|
| 229 | return [xyzX, xyzY, xyzZ];
|
---|
| 230 | }
|
---|
| 231 |
|
---|
| 232 | function xyz2rgb(xyzX, xyzY, xyzZ) {
|
---|
| 233 | var _matrix3 = matrix([xyzX, xyzY, xyzZ], [[3.2404542, -1.5371385, -0.4985314], [-0.9692660, 1.8760108, 0.0415560], [0.0556434, -0.2040259, 1.0572252]]),
|
---|
| 234 | _matrix4 = _slicedToArray$2(_matrix3, 3),
|
---|
| 235 | lrgbR = _matrix4[0],
|
---|
| 236 | lrgbB = _matrix4[1],
|
---|
| 237 | lrgbG = _matrix4[2];
|
---|
| 238 |
|
---|
| 239 | var _map3 = [lrgbR, lrgbB, lrgbG].map(function (v) {
|
---|
| 240 | return v > 0.31308 ? 1.055 * Math.pow(v / 100, 1 / 2.4) * 100 - 5.5 : 12.92 * v;
|
---|
| 241 | }),
|
---|
| 242 | _map4 = _slicedToArray$2(_map3, 3),
|
---|
| 243 | rgbR = _map4[0],
|
---|
| 244 | rgbG = _map4[1],
|
---|
| 245 | rgbB = _map4[2];
|
---|
| 246 |
|
---|
| 247 | return [rgbR, rgbG, rgbB];
|
---|
| 248 | }
|
---|
| 249 |
|
---|
| 250 | /*
|
---|
| 251 |
|
---|
| 252 | References
|
---|
| 253 | ----------
|
---|
| 254 |
|
---|
| 255 | - https://www.w3.org/TR/css-color-4/#rgb-to-lab
|
---|
| 256 | - https://www.w3.org/TR/css-color-4/#color-conversion-code
|
---|
| 257 |
|
---|
| 258 | /* ========================================================================== */
|
---|
| 259 |
|
---|
| 260 | /* Convert between HSL and HSV
|
---|
| 261 | /* ========================================================================== */
|
---|
| 262 |
|
---|
| 263 | function hsl2hsv(hslH, hslS, hslL) {
|
---|
| 264 | var hsv1 = hslS * (hslL < 50 ? hslL : 100 - hslL) / 100;
|
---|
| 265 | var hsvS = hsv1 === 0 ? 0 : 2 * hsv1 / (hslL + hsv1) * 100;
|
---|
| 266 | var hsvV = hslL + hsv1;
|
---|
| 267 |
|
---|
| 268 | return [hslH, hsvS, hsvV];
|
---|
| 269 | }
|
---|
| 270 |
|
---|
| 271 | function hsv2hsl(hsvH, hsvS, hsvV) {
|
---|
| 272 | var hslL = (200 - hsvS) * hsvV / 100;
|
---|
| 273 |
|
---|
| 274 | var hslS = hslL === 0 || hslL === 200 ? 0 : hsvS * hsvV / 100 / (hslL <= 100 ? hslL : 200 - hslL) * 100,
|
---|
| 275 | hslV = hslL * 5 / 10;
|
---|
| 276 |
|
---|
| 277 |
|
---|
| 278 | return [hsvH, hslS, hslV];
|
---|
| 279 | }
|
---|
| 280 |
|
---|
| 281 | /*
|
---|
| 282 |
|
---|
| 283 | References
|
---|
| 284 | ----------
|
---|
| 285 |
|
---|
| 286 | - https://gist.github.com/defims/0ca2ef8832833186ed396a2f8a204117
|
---|
| 287 |
|
---|
| 288 | /* ========================================================================== */
|
---|
| 289 |
|
---|
| 290 | /* Convert between HWB and HSV
|
---|
| 291 | /* ========================================================================== */
|
---|
| 292 |
|
---|
| 293 | function hwb2hsv(hwbH, hwbW, hwbB) {
|
---|
| 294 | var hsvH = hwbH,
|
---|
| 295 | hsvS = hwbB === 100 ? 0 : 100 - hwbW / (100 - hwbB) * 100,
|
---|
| 296 | hsvV = 100 - hwbB;
|
---|
| 297 |
|
---|
| 298 |
|
---|
| 299 | return [hsvH, hsvS, hsvV];
|
---|
| 300 | }
|
---|
| 301 |
|
---|
| 302 | function hsv2hwb(hsvH, hsvS, hsvV) {
|
---|
| 303 | var hwbH = hsvH,
|
---|
| 304 | hwbW = (100 - hsvS) * hsvV / 100,
|
---|
| 305 | hwbB = 100 - hsvV;
|
---|
| 306 |
|
---|
| 307 |
|
---|
| 308 | return [hwbH, hwbW, hwbB];
|
---|
| 309 | }
|
---|
| 310 |
|
---|
| 311 | /*
|
---|
| 312 |
|
---|
| 313 | References
|
---|
| 314 | ----------
|
---|
| 315 |
|
---|
| 316 | - https://en.wikipedia.org/wiki/HWB_color_model#Converting_to_and_from_HSV
|
---|
| 317 |
|
---|
| 318 | /* ========================================================================== */
|
---|
| 319 |
|
---|
| 320 | var _slicedToArray$3 = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
|
---|
| 321 |
|
---|
| 322 | /* Convert between Lab and XYZ
|
---|
| 323 | /* ========================================================================== */
|
---|
| 324 |
|
---|
| 325 | function lab2xyz(labL, labA, labB) {
|
---|
| 326 | // compute f, starting with the luminance-related term
|
---|
| 327 | var f2 = (labL + 16) / 116;
|
---|
| 328 | var f1 = labA / 500 + f2;
|
---|
| 329 | var f3 = f2 - labB / 200;
|
---|
| 330 |
|
---|
| 331 | // compute pre-scaled XYZ
|
---|
| 332 | var initX = Math.pow(f1, 3) > epsilon ? Math.pow(f1, 3) : (116 * f1 - 16) / kappa,
|
---|
| 333 | initY = labL > kappa * epsilon ? Math.pow((labL + 16) / 116, 3) : labL / kappa,
|
---|
| 334 | initZ = Math.pow(f3, 3) > epsilon ? Math.pow(f3, 3) : (116 * f3 - 16) / kappa;
|
---|
| 335 |
|
---|
| 336 | var _matrix = matrix(
|
---|
| 337 | // compute XYZ by scaling pre-scaled XYZ by reference white
|
---|
| 338 | [initX * wd50X, initY * wd50Y, initZ * wd50Z],
|
---|
| 339 | // calculate D65 XYZ from D50 XYZ
|
---|
| 340 | [[0.9555766, -0.0230393, 0.0631636], [-0.0282895, 1.0099416, 0.0210077], [0.0122982, -0.0204830, 1.3299098]]),
|
---|
| 341 | _matrix2 = _slicedToArray$3(_matrix, 3),
|
---|
| 342 | xyzX = _matrix2[0],
|
---|
| 343 | xyzY = _matrix2[1],
|
---|
| 344 | xyzZ = _matrix2[2];
|
---|
| 345 |
|
---|
| 346 | return [xyzX, xyzY, xyzZ];
|
---|
| 347 | }
|
---|
| 348 |
|
---|
| 349 | function xyz2lab(xyzX, xyzY, xyzZ) {
|
---|
| 350 | // calculate D50 XYZ from D65 XYZ
|
---|
| 351 | var _matrix3 = matrix([xyzX, xyzY, xyzZ], [[1.0478112, 0.0228866, -0.0501270], [0.0295424, 0.9904844, -0.0170491], [-0.0092345, 0.0150436, 0.7521316]]),
|
---|
| 352 | _matrix4 = _slicedToArray$3(_matrix3, 3),
|
---|
| 353 | d50X = _matrix4[0],
|
---|
| 354 | d50Y = _matrix4[1],
|
---|
| 355 | d50Z = _matrix4[2];
|
---|
| 356 |
|
---|
| 357 | // calculate f
|
---|
| 358 |
|
---|
| 359 |
|
---|
| 360 | var _map = [d50X / wd50X, d50Y / wd50Y, d50Z / wd50Z].map(function (value) {
|
---|
| 361 | return value > epsilon ? Math.cbrt(value) : (kappa * value + 16) / 116;
|
---|
| 362 | }),
|
---|
| 363 | _map2 = _slicedToArray$3(_map, 3),
|
---|
| 364 | f1 = _map2[0],
|
---|
| 365 | f2 = _map2[1],
|
---|
| 366 | f3 = _map2[2];
|
---|
| 367 |
|
---|
| 368 | var labL = 116 * f2 - 16,
|
---|
| 369 | labA = 500 * (f1 - f2),
|
---|
| 370 | labB = 200 * (f2 - f3);
|
---|
| 371 |
|
---|
| 372 |
|
---|
| 373 | return [labL, labA, labB];
|
---|
| 374 | }
|
---|
| 375 |
|
---|
| 376 | /*
|
---|
| 377 |
|
---|
| 378 | References
|
---|
| 379 | ----------
|
---|
| 380 |
|
---|
| 381 | - https://www.w3.org/TR/css-color-4/#rgb-to-lab
|
---|
| 382 | - https://www.w3.org/TR/css-color-4/#color-conversion-code
|
---|
| 383 | - https://www.easyrgb.com/en/math.php
|
---|
| 384 |
|
---|
| 385 | /* ========================================================================== */
|
---|
| 386 |
|
---|
| 387 | /* Convert between Lab and XYZ
|
---|
| 388 | /* ========================================================================== */
|
---|
| 389 |
|
---|
| 390 | function lab2lch(labL, labA, labB) {
|
---|
| 391 | var _ref = [Math.sqrt(Math.pow(labA, 2) + Math.pow(labB, 2)), // convert to chroma
|
---|
| 392 | Math.atan2(labB, labA) * 180 / Math.PI // convert to hue, in degrees
|
---|
| 393 | ],
|
---|
| 394 | lchC = _ref[0],
|
---|
| 395 | lchH = _ref[1];
|
---|
| 396 |
|
---|
| 397 |
|
---|
| 398 | return [labL, lchC, lchH];
|
---|
| 399 | }
|
---|
| 400 |
|
---|
| 401 | function lch2lab(lchL, lchC, lchH) {
|
---|
| 402 | // convert to Lab a and b from the polar form
|
---|
| 403 | var labA = lchC * Math.cos(lchH * Math.PI / 180),
|
---|
| 404 | labB = lchC * Math.sin(lchH * Math.PI / 180);
|
---|
| 405 |
|
---|
| 406 |
|
---|
| 407 | return [lchL, labA, labB];
|
---|
| 408 | }
|
---|
| 409 |
|
---|
| 410 | /*
|
---|
| 411 |
|
---|
| 412 | References
|
---|
| 413 | ----------
|
---|
| 414 |
|
---|
| 415 | - https://www.w3.org/TR/css-color-4/#lch-to-lab
|
---|
| 416 | - https://www.w3.org/TR/css-color-4/#color-conversion-code
|
---|
| 417 |
|
---|
| 418 | /* ========================================================================== */
|
---|
| 419 |
|
---|
| 420 | var _slicedToArray$4 = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
|
---|
| 421 |
|
---|
| 422 | /* Convert between RGB and Lab
|
---|
| 423 | /* ========================================================================== */
|
---|
| 424 |
|
---|
| 425 | function rgb2lab(rgbR, rgbG, rgbB) {
|
---|
| 426 | var _rgb2xyz = rgb2xyz(rgbR, rgbG, rgbB),
|
---|
| 427 | _rgb2xyz2 = _slicedToArray$4(_rgb2xyz, 3),
|
---|
| 428 | xyzX = _rgb2xyz2[0],
|
---|
| 429 | xyzY = _rgb2xyz2[1],
|
---|
| 430 | xyzZ = _rgb2xyz2[2];
|
---|
| 431 |
|
---|
| 432 | var _xyz2lab = xyz2lab(xyzX, xyzY, xyzZ),
|
---|
| 433 | _xyz2lab2 = _slicedToArray$4(_xyz2lab, 3),
|
---|
| 434 | labL = _xyz2lab2[0],
|
---|
| 435 | labA = _xyz2lab2[1],
|
---|
| 436 | labB = _xyz2lab2[2];
|
---|
| 437 |
|
---|
| 438 | return [labL, labA, labB];
|
---|
| 439 | }
|
---|
| 440 |
|
---|
| 441 | function lab2rgb(labL, labA, labB) {
|
---|
| 442 | var _lab2xyz = lab2xyz(labL, labA, labB),
|
---|
| 443 | _lab2xyz2 = _slicedToArray$4(_lab2xyz, 3),
|
---|
| 444 | xyzX = _lab2xyz2[0],
|
---|
| 445 | xyzY = _lab2xyz2[1],
|
---|
| 446 | xyzZ = _lab2xyz2[2];
|
---|
| 447 |
|
---|
| 448 | var _xyz2rgb = xyz2rgb(xyzX, xyzY, xyzZ),
|
---|
| 449 | _xyz2rgb2 = _slicedToArray$4(_xyz2rgb, 3),
|
---|
| 450 | rgbR = _xyz2rgb2[0],
|
---|
| 451 | rgbG = _xyz2rgb2[1],
|
---|
| 452 | rgbB = _xyz2rgb2[2];
|
---|
| 453 |
|
---|
| 454 | return [rgbR, rgbG, rgbB];
|
---|
| 455 | }
|
---|
| 456 |
|
---|
| 457 | /* Convert between RGB and LCH
|
---|
| 458 | /* ========================================================================== */
|
---|
| 459 |
|
---|
| 460 | function rgb2lch(rgbR, rgbG, rgbB) {
|
---|
| 461 | var _rgb2xyz3 = rgb2xyz(rgbR, rgbG, rgbB),
|
---|
| 462 | _rgb2xyz4 = _slicedToArray$4(_rgb2xyz3, 3),
|
---|
| 463 | xyzX = _rgb2xyz4[0],
|
---|
| 464 | xyzY = _rgb2xyz4[1],
|
---|
| 465 | xyzZ = _rgb2xyz4[2];
|
---|
| 466 |
|
---|
| 467 | var _xyz2lab3 = xyz2lab(xyzX, xyzY, xyzZ),
|
---|
| 468 | _xyz2lab4 = _slicedToArray$4(_xyz2lab3, 3),
|
---|
| 469 | labL = _xyz2lab4[0],
|
---|
| 470 | labA = _xyz2lab4[1],
|
---|
| 471 | labB = _xyz2lab4[2];
|
---|
| 472 |
|
---|
| 473 | var _lab2lch = lab2lch(labL, labA, labB),
|
---|
| 474 | _lab2lch2 = _slicedToArray$4(_lab2lch, 3),
|
---|
| 475 | lchL = _lab2lch2[0],
|
---|
| 476 | lchC = _lab2lch2[1],
|
---|
| 477 | lchH = _lab2lch2[2];
|
---|
| 478 |
|
---|
| 479 | return [lchL, lchC, lchH];
|
---|
| 480 | }
|
---|
| 481 |
|
---|
| 482 | function lch2rgb(lchL, lchC, lchH) {
|
---|
| 483 | var _lch2lab = lch2lab(lchL, lchC, lchH),
|
---|
| 484 | _lch2lab2 = _slicedToArray$4(_lch2lab, 3),
|
---|
| 485 | labL = _lch2lab2[0],
|
---|
| 486 | labA = _lch2lab2[1],
|
---|
| 487 | labB = _lch2lab2[2];
|
---|
| 488 |
|
---|
| 489 | var _lab2xyz3 = lab2xyz(labL, labA, labB),
|
---|
| 490 | _lab2xyz4 = _slicedToArray$4(_lab2xyz3, 3),
|
---|
| 491 | xyzX = _lab2xyz4[0],
|
---|
| 492 | xyzY = _lab2xyz4[1],
|
---|
| 493 | xyzZ = _lab2xyz4[2];
|
---|
| 494 |
|
---|
| 495 | var _xyz2rgb3 = xyz2rgb(xyzX, xyzY, xyzZ),
|
---|
| 496 | _xyz2rgb4 = _slicedToArray$4(_xyz2rgb3, 3),
|
---|
| 497 | rgbR = _xyz2rgb4[0],
|
---|
| 498 | rgbG = _xyz2rgb4[1],
|
---|
| 499 | rgbB = _xyz2rgb4[2];
|
---|
| 500 |
|
---|
| 501 | return [rgbR, rgbG, rgbB];
|
---|
| 502 | }
|
---|
| 503 |
|
---|
| 504 | /* Convert between HSL and HWB
|
---|
| 505 | /* ========================================================================== */
|
---|
| 506 |
|
---|
| 507 | function hwb2hsl(hwbH, hwbW, hwbB) {
|
---|
| 508 | var _hwb2hsv = hwb2hsv(hwbH, hwbW, hwbB),
|
---|
| 509 | _hwb2hsv2 = _slicedToArray$4(_hwb2hsv, 3),
|
---|
| 510 | hsvH = _hwb2hsv2[0],
|
---|
| 511 | hsvS = _hwb2hsv2[1],
|
---|
| 512 | hsvV = _hwb2hsv2[2];
|
---|
| 513 |
|
---|
| 514 | var _hsv2hsl = hsv2hsl(hsvH, hsvS, hsvV),
|
---|
| 515 | _hsv2hsl2 = _slicedToArray$4(_hsv2hsl, 3),
|
---|
| 516 | hslH = _hsv2hsl2[0],
|
---|
| 517 | hslS = _hsv2hsl2[1],
|
---|
| 518 | hslL = _hsv2hsl2[2];
|
---|
| 519 |
|
---|
| 520 | return [hslH, hslS, hslL];
|
---|
| 521 | }
|
---|
| 522 |
|
---|
| 523 | function hsl2hwb(hslH, hslS, hslL) {
|
---|
| 524 | var _hsl2hsv = hsl2hsv(hslH, hslS, hslL),
|
---|
| 525 | _hsl2hsv2 = _slicedToArray$4(_hsl2hsv, 3),
|
---|
| 526 | hsvS = _hsl2hsv2[1],
|
---|
| 527 | hsvV = _hsl2hsv2[2];
|
---|
| 528 |
|
---|
| 529 | var _hsv2hwb = hsv2hwb(hslH, hsvS, hsvV),
|
---|
| 530 | _hsv2hwb2 = _slicedToArray$4(_hsv2hwb, 3),
|
---|
| 531 | hwbW = _hsv2hwb2[1],
|
---|
| 532 | hwbB = _hsv2hwb2[2];
|
---|
| 533 |
|
---|
| 534 | return [hslH, hwbW, hwbB];
|
---|
| 535 | }
|
---|
| 536 |
|
---|
| 537 | /* Convert between HSL and Lab
|
---|
| 538 | /* ========================================================================== */
|
---|
| 539 |
|
---|
| 540 | function hsl2lab(hslH, hslS, hslL) {
|
---|
| 541 | var _hsl2rgb = hsl2rgb(hslH, hslS, hslL),
|
---|
| 542 | _hsl2rgb2 = _slicedToArray$4(_hsl2rgb, 3),
|
---|
| 543 | rgbR = _hsl2rgb2[0],
|
---|
| 544 | rgbG = _hsl2rgb2[1],
|
---|
| 545 | rgbB = _hsl2rgb2[2];
|
---|
| 546 |
|
---|
| 547 | var _rgb2xyz5 = rgb2xyz(rgbR, rgbG, rgbB),
|
---|
| 548 | _rgb2xyz6 = _slicedToArray$4(_rgb2xyz5, 3),
|
---|
| 549 | xyzX = _rgb2xyz6[0],
|
---|
| 550 | xyzY = _rgb2xyz6[1],
|
---|
| 551 | xyzZ = _rgb2xyz6[2];
|
---|
| 552 |
|
---|
| 553 | var _xyz2lab5 = xyz2lab(xyzX, xyzY, xyzZ),
|
---|
| 554 | _xyz2lab6 = _slicedToArray$4(_xyz2lab5, 3),
|
---|
| 555 | labL = _xyz2lab6[0],
|
---|
| 556 | labA = _xyz2lab6[1],
|
---|
| 557 | labB = _xyz2lab6[2];
|
---|
| 558 |
|
---|
| 559 | return [labL, labA, labB];
|
---|
| 560 | }
|
---|
| 561 |
|
---|
| 562 | function lab2hsl(labL, labA, labB, fallbackhue) {
|
---|
| 563 | var _lab2xyz5 = lab2xyz(labL, labA, labB),
|
---|
| 564 | _lab2xyz6 = _slicedToArray$4(_lab2xyz5, 3),
|
---|
| 565 | xyzX = _lab2xyz6[0],
|
---|
| 566 | xyzY = _lab2xyz6[1],
|
---|
| 567 | xyzZ = _lab2xyz6[2];
|
---|
| 568 |
|
---|
| 569 | var _xyz2rgb5 = xyz2rgb(xyzX, xyzY, xyzZ),
|
---|
| 570 | _xyz2rgb6 = _slicedToArray$4(_xyz2rgb5, 3),
|
---|
| 571 | rgbR = _xyz2rgb6[0],
|
---|
| 572 | rgbG = _xyz2rgb6[1],
|
---|
| 573 | rgbB = _xyz2rgb6[2];
|
---|
| 574 |
|
---|
| 575 | var _rgb2hsl = rgb2hsl(rgbR, rgbG, rgbB, fallbackhue),
|
---|
| 576 | _rgb2hsl2 = _slicedToArray$4(_rgb2hsl, 3),
|
---|
| 577 | hslH = _rgb2hsl2[0],
|
---|
| 578 | hslS = _rgb2hsl2[1],
|
---|
| 579 | hslL = _rgb2hsl2[2];
|
---|
| 580 |
|
---|
| 581 | return [hslH, hslS, hslL];
|
---|
| 582 | }
|
---|
| 583 |
|
---|
| 584 | /* Convert between HSL and LCH
|
---|
| 585 | /* ========================================================================== */
|
---|
| 586 |
|
---|
| 587 | function hsl2lch(hslH, hslS, hslL) {
|
---|
| 588 | var _hsl2rgb3 = hsl2rgb(hslH, hslS, hslL),
|
---|
| 589 | _hsl2rgb4 = _slicedToArray$4(_hsl2rgb3, 3),
|
---|
| 590 | rgbR = _hsl2rgb4[0],
|
---|
| 591 | rgbG = _hsl2rgb4[1],
|
---|
| 592 | rgbB = _hsl2rgb4[2];
|
---|
| 593 |
|
---|
| 594 | var _rgb2xyz7 = rgb2xyz(rgbR, rgbG, rgbB),
|
---|
| 595 | _rgb2xyz8 = _slicedToArray$4(_rgb2xyz7, 3),
|
---|
| 596 | xyzX = _rgb2xyz8[0],
|
---|
| 597 | xyzY = _rgb2xyz8[1],
|
---|
| 598 | xyzZ = _rgb2xyz8[2];
|
---|
| 599 |
|
---|
| 600 | var _xyz2lab7 = xyz2lab(xyzX, xyzY, xyzZ),
|
---|
| 601 | _xyz2lab8 = _slicedToArray$4(_xyz2lab7, 3),
|
---|
| 602 | labL = _xyz2lab8[0],
|
---|
| 603 | labA = _xyz2lab8[1],
|
---|
| 604 | labB = _xyz2lab8[2];
|
---|
| 605 |
|
---|
| 606 | var _lab2lch3 = lab2lch(labL, labA, labB),
|
---|
| 607 | _lab2lch4 = _slicedToArray$4(_lab2lch3, 3),
|
---|
| 608 | lchL = _lab2lch4[0],
|
---|
| 609 | lchC = _lab2lch4[1],
|
---|
| 610 | lchH = _lab2lch4[2];
|
---|
| 611 |
|
---|
| 612 | return [lchL, lchC, lchH];
|
---|
| 613 | }
|
---|
| 614 |
|
---|
| 615 | function lch2hsl(lchL, lchC, lchH, fallbackhue) {
|
---|
| 616 | var _lch2lab3 = lch2lab(lchL, lchC, lchH),
|
---|
| 617 | _lch2lab4 = _slicedToArray$4(_lch2lab3, 3),
|
---|
| 618 | labL = _lch2lab4[0],
|
---|
| 619 | labA = _lch2lab4[1],
|
---|
| 620 | labB = _lch2lab4[2];
|
---|
| 621 |
|
---|
| 622 | var _lab2xyz7 = lab2xyz(labL, labA, labB),
|
---|
| 623 | _lab2xyz8 = _slicedToArray$4(_lab2xyz7, 3),
|
---|
| 624 | xyzX = _lab2xyz8[0],
|
---|
| 625 | xyzY = _lab2xyz8[1],
|
---|
| 626 | xyzZ = _lab2xyz8[2];
|
---|
| 627 |
|
---|
| 628 | var _xyz2rgb7 = xyz2rgb(xyzX, xyzY, xyzZ),
|
---|
| 629 | _xyz2rgb8 = _slicedToArray$4(_xyz2rgb7, 3),
|
---|
| 630 | rgbR = _xyz2rgb8[0],
|
---|
| 631 | rgbG = _xyz2rgb8[1],
|
---|
| 632 | rgbB = _xyz2rgb8[2];
|
---|
| 633 |
|
---|
| 634 | var _rgb2hsl3 = rgb2hsl(rgbR, rgbG, rgbB, fallbackhue),
|
---|
| 635 | _rgb2hsl4 = _slicedToArray$4(_rgb2hsl3, 3),
|
---|
| 636 | hslH = _rgb2hsl4[0],
|
---|
| 637 | hslS = _rgb2hsl4[1],
|
---|
| 638 | hslL = _rgb2hsl4[2];
|
---|
| 639 |
|
---|
| 640 | return [hslH, hslS, hslL];
|
---|
| 641 | }
|
---|
| 642 |
|
---|
| 643 | /* Convert between HSL and XYZ
|
---|
| 644 | /* ========================================================================== */
|
---|
| 645 |
|
---|
| 646 | function hsl2xyz(hslH, hslS, hslL) {
|
---|
| 647 | var _hsl2rgb5 = hsl2rgb(hslH, hslS, hslL),
|
---|
| 648 | _hsl2rgb6 = _slicedToArray$4(_hsl2rgb5, 3),
|
---|
| 649 | rgbR = _hsl2rgb6[0],
|
---|
| 650 | rgbG = _hsl2rgb6[1],
|
---|
| 651 | rgbB = _hsl2rgb6[2];
|
---|
| 652 |
|
---|
| 653 | var _rgb2xyz9 = rgb2xyz(rgbR, rgbG, rgbB),
|
---|
| 654 | _rgb2xyz10 = _slicedToArray$4(_rgb2xyz9, 3),
|
---|
| 655 | xyzX = _rgb2xyz10[0],
|
---|
| 656 | xyzY = _rgb2xyz10[1],
|
---|
| 657 | xyzZ = _rgb2xyz10[2];
|
---|
| 658 |
|
---|
| 659 | return [xyzX, xyzY, xyzZ];
|
---|
| 660 | }
|
---|
| 661 |
|
---|
| 662 | function xyz2hsl(xyzX, xyzY, xyzZ, fallbackhue) {
|
---|
| 663 | var _xyz2rgb9 = xyz2rgb(xyzX, xyzY, xyzZ),
|
---|
| 664 | _xyz2rgb10 = _slicedToArray$4(_xyz2rgb9, 3),
|
---|
| 665 | rgbR = _xyz2rgb10[0],
|
---|
| 666 | rgbG = _xyz2rgb10[1],
|
---|
| 667 | rgbB = _xyz2rgb10[2];
|
---|
| 668 |
|
---|
| 669 | var _rgb2hsl5 = rgb2hsl(rgbR, rgbG, rgbB, fallbackhue),
|
---|
| 670 | _rgb2hsl6 = _slicedToArray$4(_rgb2hsl5, 3),
|
---|
| 671 | hslH = _rgb2hsl6[0],
|
---|
| 672 | hslS = _rgb2hsl6[1],
|
---|
| 673 | hslL = _rgb2hsl6[2];
|
---|
| 674 |
|
---|
| 675 | return [hslH, hslS, hslL];
|
---|
| 676 | }
|
---|
| 677 |
|
---|
| 678 | /* Convert between HWB and Lab
|
---|
| 679 | /* ========================================================================== */
|
---|
| 680 |
|
---|
| 681 | function hwb2lab(hwbH, hwbW, hwbB) {
|
---|
| 682 | var _hwb2rgb = hwb2rgb(hwbH, hwbW, hwbB),
|
---|
| 683 | _hwb2rgb2 = _slicedToArray$4(_hwb2rgb, 3),
|
---|
| 684 | rgbR = _hwb2rgb2[0],
|
---|
| 685 | rgbG = _hwb2rgb2[1],
|
---|
| 686 | rgbB = _hwb2rgb2[2];
|
---|
| 687 |
|
---|
| 688 | var _rgb2xyz11 = rgb2xyz(rgbR, rgbG, rgbB),
|
---|
| 689 | _rgb2xyz12 = _slicedToArray$4(_rgb2xyz11, 3),
|
---|
| 690 | xyzX = _rgb2xyz12[0],
|
---|
| 691 | xyzY = _rgb2xyz12[1],
|
---|
| 692 | xyzZ = _rgb2xyz12[2];
|
---|
| 693 |
|
---|
| 694 | var _xyz2lab9 = xyz2lab(xyzX, xyzY, xyzZ),
|
---|
| 695 | _xyz2lab10 = _slicedToArray$4(_xyz2lab9, 3),
|
---|
| 696 | labL = _xyz2lab10[0],
|
---|
| 697 | labA = _xyz2lab10[1],
|
---|
| 698 | labB = _xyz2lab10[2];
|
---|
| 699 |
|
---|
| 700 | return [labL, labA, labB];
|
---|
| 701 | }
|
---|
| 702 |
|
---|
| 703 | function lab2hwb(labL, labA, labB, fallbackhue) {
|
---|
| 704 | var _lab2xyz9 = lab2xyz(labL, labA, labB),
|
---|
| 705 | _lab2xyz10 = _slicedToArray$4(_lab2xyz9, 3),
|
---|
| 706 | xyzX = _lab2xyz10[0],
|
---|
| 707 | xyzY = _lab2xyz10[1],
|
---|
| 708 | xyzZ = _lab2xyz10[2];
|
---|
| 709 |
|
---|
| 710 | var _xyz2rgb11 = xyz2rgb(xyzX, xyzY, xyzZ),
|
---|
| 711 | _xyz2rgb12 = _slicedToArray$4(_xyz2rgb11, 3),
|
---|
| 712 | rgbR = _xyz2rgb12[0],
|
---|
| 713 | rgbG = _xyz2rgb12[1],
|
---|
| 714 | rgbB = _xyz2rgb12[2];
|
---|
| 715 |
|
---|
| 716 | var _rgb2hwb = rgb2hwb(rgbR, rgbG, rgbB, fallbackhue),
|
---|
| 717 | _rgb2hwb2 = _slicedToArray$4(_rgb2hwb, 3),
|
---|
| 718 | hwbH = _rgb2hwb2[0],
|
---|
| 719 | hwbW = _rgb2hwb2[1],
|
---|
| 720 | hwbB = _rgb2hwb2[2];
|
---|
| 721 |
|
---|
| 722 | return [hwbH, hwbW, hwbB];
|
---|
| 723 | }
|
---|
| 724 |
|
---|
| 725 | /* Convert between HWB and LCH
|
---|
| 726 | /* ========================================================================== */
|
---|
| 727 |
|
---|
| 728 | function hwb2lch(hwbH, hwbW, hwbB) {
|
---|
| 729 | var _hwb2rgb3 = hwb2rgb(hwbH, hwbW, hwbB),
|
---|
| 730 | _hwb2rgb4 = _slicedToArray$4(_hwb2rgb3, 3),
|
---|
| 731 | rgbR = _hwb2rgb4[0],
|
---|
| 732 | rgbG = _hwb2rgb4[1],
|
---|
| 733 | rgbB = _hwb2rgb4[2];
|
---|
| 734 |
|
---|
| 735 | var _rgb2xyz13 = rgb2xyz(rgbR, rgbG, rgbB),
|
---|
| 736 | _rgb2xyz14 = _slicedToArray$4(_rgb2xyz13, 3),
|
---|
| 737 | xyzX = _rgb2xyz14[0],
|
---|
| 738 | xyzY = _rgb2xyz14[1],
|
---|
| 739 | xyzZ = _rgb2xyz14[2];
|
---|
| 740 |
|
---|
| 741 | var _xyz2lab11 = xyz2lab(xyzX, xyzY, xyzZ),
|
---|
| 742 | _xyz2lab12 = _slicedToArray$4(_xyz2lab11, 3),
|
---|
| 743 | labL = _xyz2lab12[0],
|
---|
| 744 | labA = _xyz2lab12[1],
|
---|
| 745 | labB = _xyz2lab12[2];
|
---|
| 746 |
|
---|
| 747 | var _lab2lch5 = lab2lch(labL, labA, labB),
|
---|
| 748 | _lab2lch6 = _slicedToArray$4(_lab2lch5, 3),
|
---|
| 749 | lchL = _lab2lch6[0],
|
---|
| 750 | lchC = _lab2lch6[1],
|
---|
| 751 | lchH = _lab2lch6[2];
|
---|
| 752 |
|
---|
| 753 | return [lchL, lchC, lchH];
|
---|
| 754 | }
|
---|
| 755 |
|
---|
| 756 | function lch2hwb(lchL, lchC, lchH, fallbackhue) {
|
---|
| 757 | var _lch2lab5 = lch2lab(lchL, lchC, lchH),
|
---|
| 758 | _lch2lab6 = _slicedToArray$4(_lch2lab5, 3),
|
---|
| 759 | labL = _lch2lab6[0],
|
---|
| 760 | labA = _lch2lab6[1],
|
---|
| 761 | labB = _lch2lab6[2];
|
---|
| 762 |
|
---|
| 763 | var _lab2xyz11 = lab2xyz(labL, labA, labB),
|
---|
| 764 | _lab2xyz12 = _slicedToArray$4(_lab2xyz11, 3),
|
---|
| 765 | xyzX = _lab2xyz12[0],
|
---|
| 766 | xyzY = _lab2xyz12[1],
|
---|
| 767 | xyzZ = _lab2xyz12[2];
|
---|
| 768 |
|
---|
| 769 | var _xyz2rgb13 = xyz2rgb(xyzX, xyzY, xyzZ),
|
---|
| 770 | _xyz2rgb14 = _slicedToArray$4(_xyz2rgb13, 3),
|
---|
| 771 | rgbR = _xyz2rgb14[0],
|
---|
| 772 | rgbG = _xyz2rgb14[1],
|
---|
| 773 | rgbB = _xyz2rgb14[2];
|
---|
| 774 |
|
---|
| 775 | var _rgb2hwb3 = rgb2hwb(rgbR, rgbG, rgbB, fallbackhue),
|
---|
| 776 | _rgb2hwb4 = _slicedToArray$4(_rgb2hwb3, 3),
|
---|
| 777 | hwbH = _rgb2hwb4[0],
|
---|
| 778 | hwbW = _rgb2hwb4[1],
|
---|
| 779 | hwbB = _rgb2hwb4[2];
|
---|
| 780 |
|
---|
| 781 | return [hwbH, hwbW, hwbB];
|
---|
| 782 | }
|
---|
| 783 |
|
---|
| 784 | /* Convert between HWB and XYZ
|
---|
| 785 | /* ========================================================================== */
|
---|
| 786 |
|
---|
| 787 | function hwb2xyz(hwbH, hwbW, hwbB) {
|
---|
| 788 | var _hwb2rgb5 = hwb2rgb(hwbH, hwbW, hwbB),
|
---|
| 789 | _hwb2rgb6 = _slicedToArray$4(_hwb2rgb5, 3),
|
---|
| 790 | rgbR = _hwb2rgb6[0],
|
---|
| 791 | rgbG = _hwb2rgb6[1],
|
---|
| 792 | rgbB = _hwb2rgb6[2];
|
---|
| 793 |
|
---|
| 794 | var _rgb2xyz15 = rgb2xyz(rgbR, rgbG, rgbB),
|
---|
| 795 | _rgb2xyz16 = _slicedToArray$4(_rgb2xyz15, 3),
|
---|
| 796 | xyzX = _rgb2xyz16[0],
|
---|
| 797 | xyzY = _rgb2xyz16[1],
|
---|
| 798 | xyzZ = _rgb2xyz16[2];
|
---|
| 799 |
|
---|
| 800 | return [xyzX, xyzY, xyzZ];
|
---|
| 801 | }
|
---|
| 802 |
|
---|
| 803 | function xyz2hwb(xyzX, xyzY, xyzZ, fallbackhue) {
|
---|
| 804 | var _xyz2rgb15 = xyz2rgb(xyzX, xyzY, xyzZ),
|
---|
| 805 | _xyz2rgb16 = _slicedToArray$4(_xyz2rgb15, 3),
|
---|
| 806 | rgbR = _xyz2rgb16[0],
|
---|
| 807 | rgbG = _xyz2rgb16[1],
|
---|
| 808 | rgbB = _xyz2rgb16[2];
|
---|
| 809 |
|
---|
| 810 | var _rgb2hwb5 = rgb2hwb(rgbR, rgbG, rgbB, fallbackhue),
|
---|
| 811 | _rgb2hwb6 = _slicedToArray$4(_rgb2hwb5, 3),
|
---|
| 812 | hwbH = _rgb2hwb6[0],
|
---|
| 813 | hwbW = _rgb2hwb6[1],
|
---|
| 814 | hwbB = _rgb2hwb6[2];
|
---|
| 815 |
|
---|
| 816 | return [hwbH, hwbW, hwbB];
|
---|
| 817 | }
|
---|
| 818 |
|
---|
| 819 | /* Convert between HSV and Lab
|
---|
| 820 | /* ========================================================================== */
|
---|
| 821 |
|
---|
| 822 | function hsv2lab(hsvH, hsvS, hsvV) {
|
---|
| 823 | var _hsv2rgb = hsv2rgb(hsvH, hsvS, hsvV),
|
---|
| 824 | _hsv2rgb2 = _slicedToArray$4(_hsv2rgb, 3),
|
---|
| 825 | rgbR = _hsv2rgb2[0],
|
---|
| 826 | rgbG = _hsv2rgb2[1],
|
---|
| 827 | rgbB = _hsv2rgb2[2];
|
---|
| 828 |
|
---|
| 829 | var _rgb2xyz17 = rgb2xyz(rgbR, rgbG, rgbB),
|
---|
| 830 | _rgb2xyz18 = _slicedToArray$4(_rgb2xyz17, 3),
|
---|
| 831 | xyzX = _rgb2xyz18[0],
|
---|
| 832 | xyzY = _rgb2xyz18[1],
|
---|
| 833 | xyzZ = _rgb2xyz18[2];
|
---|
| 834 |
|
---|
| 835 | var _xyz2lab13 = xyz2lab(xyzX, xyzY, xyzZ),
|
---|
| 836 | _xyz2lab14 = _slicedToArray$4(_xyz2lab13, 3),
|
---|
| 837 | labL = _xyz2lab14[0],
|
---|
| 838 | labA = _xyz2lab14[1],
|
---|
| 839 | labB = _xyz2lab14[2];
|
---|
| 840 |
|
---|
| 841 | return [labL, labA, labB];
|
---|
| 842 | }
|
---|
| 843 |
|
---|
| 844 | function lab2hsv(labL, labA, labB, fallbackhue) {
|
---|
| 845 | var _lab2xyz13 = lab2xyz(labL, labA, labB),
|
---|
| 846 | _lab2xyz14 = _slicedToArray$4(_lab2xyz13, 3),
|
---|
| 847 | xyzX = _lab2xyz14[0],
|
---|
| 848 | xyzY = _lab2xyz14[1],
|
---|
| 849 | xyzZ = _lab2xyz14[2];
|
---|
| 850 |
|
---|
| 851 | var _xyz2rgb17 = xyz2rgb(xyzX, xyzY, xyzZ),
|
---|
| 852 | _xyz2rgb18 = _slicedToArray$4(_xyz2rgb17, 3),
|
---|
| 853 | rgbR = _xyz2rgb18[0],
|
---|
| 854 | rgbG = _xyz2rgb18[1],
|
---|
| 855 | rgbB = _xyz2rgb18[2];
|
---|
| 856 |
|
---|
| 857 | var _rgb2hsv = rgb2hsv(rgbR, rgbG, rgbB, fallbackhue),
|
---|
| 858 | _rgb2hsv2 = _slicedToArray$4(_rgb2hsv, 3),
|
---|
| 859 | hsvH = _rgb2hsv2[0],
|
---|
| 860 | hsvS = _rgb2hsv2[1],
|
---|
| 861 | hsvV = _rgb2hsv2[2];
|
---|
| 862 |
|
---|
| 863 | return [hsvH, hsvS, hsvV];
|
---|
| 864 | }
|
---|
| 865 |
|
---|
| 866 | /* Convert between HSV and LCH
|
---|
| 867 | /* ========================================================================== */
|
---|
| 868 |
|
---|
| 869 | function hsv2lch(hsvH, hsvS, hsvV) {
|
---|
| 870 | var _hsv2rgb3 = hsv2rgb(hsvH, hsvS, hsvV),
|
---|
| 871 | _hsv2rgb4 = _slicedToArray$4(_hsv2rgb3, 3),
|
---|
| 872 | rgbR = _hsv2rgb4[0],
|
---|
| 873 | rgbG = _hsv2rgb4[1],
|
---|
| 874 | rgbB = _hsv2rgb4[2];
|
---|
| 875 |
|
---|
| 876 | var _rgb2xyz19 = rgb2xyz(rgbR, rgbG, rgbB),
|
---|
| 877 | _rgb2xyz20 = _slicedToArray$4(_rgb2xyz19, 3),
|
---|
| 878 | xyzX = _rgb2xyz20[0],
|
---|
| 879 | xyzY = _rgb2xyz20[1],
|
---|
| 880 | xyzZ = _rgb2xyz20[2];
|
---|
| 881 |
|
---|
| 882 | var _xyz2lab15 = xyz2lab(xyzX, xyzY, xyzZ),
|
---|
| 883 | _xyz2lab16 = _slicedToArray$4(_xyz2lab15, 3),
|
---|
| 884 | labL = _xyz2lab16[0],
|
---|
| 885 | labA = _xyz2lab16[1],
|
---|
| 886 | labB = _xyz2lab16[2];
|
---|
| 887 |
|
---|
| 888 | var _lab2lch7 = lab2lch(labL, labA, labB),
|
---|
| 889 | _lab2lch8 = _slicedToArray$4(_lab2lch7, 3),
|
---|
| 890 | lchL = _lab2lch8[0],
|
---|
| 891 | lchC = _lab2lch8[1],
|
---|
| 892 | lchH = _lab2lch8[2];
|
---|
| 893 |
|
---|
| 894 | return [lchL, lchC, lchH];
|
---|
| 895 | }
|
---|
| 896 |
|
---|
| 897 | function lch2hsv(lchL, lchC, lchH, fallbackhue) {
|
---|
| 898 | var _lch2lab7 = lch2lab(lchL, lchC, lchH),
|
---|
| 899 | _lch2lab8 = _slicedToArray$4(_lch2lab7, 3),
|
---|
| 900 | labL = _lch2lab8[0],
|
---|
| 901 | labA = _lch2lab8[1],
|
---|
| 902 | labB = _lch2lab8[2];
|
---|
| 903 |
|
---|
| 904 | var _lab2xyz15 = lab2xyz(labL, labA, labB),
|
---|
| 905 | _lab2xyz16 = _slicedToArray$4(_lab2xyz15, 3),
|
---|
| 906 | xyzX = _lab2xyz16[0],
|
---|
| 907 | xyzY = _lab2xyz16[1],
|
---|
| 908 | xyzZ = _lab2xyz16[2];
|
---|
| 909 |
|
---|
| 910 | var _xyz2rgb19 = xyz2rgb(xyzX, xyzY, xyzZ),
|
---|
| 911 | _xyz2rgb20 = _slicedToArray$4(_xyz2rgb19, 3),
|
---|
| 912 | rgbR = _xyz2rgb20[0],
|
---|
| 913 | rgbG = _xyz2rgb20[1],
|
---|
| 914 | rgbB = _xyz2rgb20[2];
|
---|
| 915 |
|
---|
| 916 | var _rgb2hsv3 = rgb2hsv(rgbR, rgbG, rgbB, fallbackhue),
|
---|
| 917 | _rgb2hsv4 = _slicedToArray$4(_rgb2hsv3, 3),
|
---|
| 918 | hsvH = _rgb2hsv4[0],
|
---|
| 919 | hsvS = _rgb2hsv4[1],
|
---|
| 920 | hsvV = _rgb2hsv4[2];
|
---|
| 921 |
|
---|
| 922 | return [hsvH, hsvS, hsvV];
|
---|
| 923 | }
|
---|
| 924 |
|
---|
| 925 | /* Convert between HSV and XYZ
|
---|
| 926 | /* ========================================================================== */
|
---|
| 927 |
|
---|
| 928 | function hsv2xyz(hsvH, hsvS, hsvV) {
|
---|
| 929 | var _hsv2rgb5 = hsv2rgb(hsvH, hsvS, hsvV),
|
---|
| 930 | _hsv2rgb6 = _slicedToArray$4(_hsv2rgb5, 3),
|
---|
| 931 | rgbR = _hsv2rgb6[0],
|
---|
| 932 | rgbG = _hsv2rgb6[1],
|
---|
| 933 | rgbB = _hsv2rgb6[2];
|
---|
| 934 |
|
---|
| 935 | var _rgb2xyz21 = rgb2xyz(rgbR, rgbG, rgbB),
|
---|
| 936 | _rgb2xyz22 = _slicedToArray$4(_rgb2xyz21, 3),
|
---|
| 937 | xyzX = _rgb2xyz22[0],
|
---|
| 938 | xyzY = _rgb2xyz22[1],
|
---|
| 939 | xyzZ = _rgb2xyz22[2];
|
---|
| 940 |
|
---|
| 941 | return [xyzX, xyzY, xyzZ];
|
---|
| 942 | }
|
---|
| 943 |
|
---|
| 944 | function xyz2hsv(xyzX, xyzY, xyzZ, fallbackhue) {
|
---|
| 945 | var _xyz2rgb21 = xyz2rgb(xyzX, xyzY, xyzZ),
|
---|
| 946 | _xyz2rgb22 = _slicedToArray$4(_xyz2rgb21, 3),
|
---|
| 947 | rgbR = _xyz2rgb22[0],
|
---|
| 948 | rgbG = _xyz2rgb22[1],
|
---|
| 949 | rgbB = _xyz2rgb22[2];
|
---|
| 950 |
|
---|
| 951 | var _rgb2hsv5 = rgb2hsv(rgbR, rgbG, rgbB, fallbackhue),
|
---|
| 952 | _rgb2hsv6 = _slicedToArray$4(_rgb2hsv5, 3),
|
---|
| 953 | hsvH = _rgb2hsv6[0],
|
---|
| 954 | hsvS = _rgb2hsv6[1],
|
---|
| 955 | hsvV = _rgb2hsv6[2];
|
---|
| 956 |
|
---|
| 957 | return [hsvH, hsvS, hsvV];
|
---|
| 958 | }
|
---|
| 959 |
|
---|
| 960 | /* Convert between XYZ and LCH
|
---|
| 961 | /* ========================================================================== */
|
---|
| 962 |
|
---|
| 963 | function xyz2lch(xyzX, xyzY, xyzZ) {
|
---|
| 964 | var _xyz2lab17 = xyz2lab(xyzX, xyzY, xyzZ),
|
---|
| 965 | _xyz2lab18 = _slicedToArray$4(_xyz2lab17, 3),
|
---|
| 966 | labL = _xyz2lab18[0],
|
---|
| 967 | labA = _xyz2lab18[1],
|
---|
| 968 | labB = _xyz2lab18[2];
|
---|
| 969 |
|
---|
| 970 | var _lab2lch9 = lab2lch(labL, labA, labB),
|
---|
| 971 | _lab2lch10 = _slicedToArray$4(_lab2lch9, 3),
|
---|
| 972 | lchL = _lab2lch10[0],
|
---|
| 973 | lchC = _lab2lch10[1],
|
---|
| 974 | lchH = _lab2lch10[2];
|
---|
| 975 |
|
---|
| 976 | return [lchL, lchC, lchH];
|
---|
| 977 | }
|
---|
| 978 |
|
---|
| 979 | function lch2xyz(lchL, lchC, lchH) {
|
---|
| 980 | var _lch2lab9 = lch2lab(lchL, lchC, lchH),
|
---|
| 981 | _lch2lab10 = _slicedToArray$4(_lch2lab9, 3),
|
---|
| 982 | labL = _lch2lab10[0],
|
---|
| 983 | labA = _lch2lab10[1],
|
---|
| 984 | labB = _lch2lab10[2];
|
---|
| 985 |
|
---|
| 986 | var _lab2xyz17 = lab2xyz(labL, labA, labB),
|
---|
| 987 | _lab2xyz18 = _slicedToArray$4(_lab2xyz17, 3),
|
---|
| 988 | xyzX = _lab2xyz18[0],
|
---|
| 989 | xyzY = _lab2xyz18[1],
|
---|
| 990 | xyzZ = _lab2xyz18[2];
|
---|
| 991 |
|
---|
| 992 | return [xyzX, xyzY, xyzZ];
|
---|
| 993 | }
|
---|
| 994 |
|
---|
| 995 | var index = {
|
---|
| 996 | rgb2hsl,
|
---|
| 997 | rgb2hwb,
|
---|
| 998 | rgb2lab,
|
---|
| 999 | rgb2lch,
|
---|
| 1000 | rgb2hsv,
|
---|
| 1001 | rgb2xyz,
|
---|
| 1002 |
|
---|
| 1003 | hsl2rgb,
|
---|
| 1004 | hsl2hwb,
|
---|
| 1005 | hsl2lab,
|
---|
| 1006 | hsl2lch,
|
---|
| 1007 | hsl2hsv,
|
---|
| 1008 | hsl2xyz,
|
---|
| 1009 |
|
---|
| 1010 | hwb2rgb,
|
---|
| 1011 | hwb2hsl,
|
---|
| 1012 | hwb2lab,
|
---|
| 1013 | hwb2lch,
|
---|
| 1014 | hwb2hsv,
|
---|
| 1015 | hwb2xyz,
|
---|
| 1016 |
|
---|
| 1017 | lab2rgb,
|
---|
| 1018 | lab2hsl,
|
---|
| 1019 | lab2hwb,
|
---|
| 1020 | lab2lch,
|
---|
| 1021 | lab2hsv,
|
---|
| 1022 | lab2xyz,
|
---|
| 1023 |
|
---|
| 1024 | lch2rgb,
|
---|
| 1025 | lch2hsl,
|
---|
| 1026 | lch2hwb,
|
---|
| 1027 | lch2lab,
|
---|
| 1028 | lch2hsv,
|
---|
| 1029 | lch2xyz,
|
---|
| 1030 |
|
---|
| 1031 | hsv2rgb,
|
---|
| 1032 | hsv2hsl,
|
---|
| 1033 | hsv2hwb,
|
---|
| 1034 | hsv2lab,
|
---|
| 1035 | hsv2lch,
|
---|
| 1036 | hsv2xyz,
|
---|
| 1037 |
|
---|
| 1038 | xyz2rgb,
|
---|
| 1039 | xyz2hsl,
|
---|
| 1040 | xyz2hwb,
|
---|
| 1041 | xyz2lab,
|
---|
| 1042 | xyz2lch,
|
---|
| 1043 | xyz2hsv,
|
---|
| 1044 |
|
---|
| 1045 | rgb2hue
|
---|
| 1046 | };
|
---|
| 1047 |
|
---|
| 1048 | exports.rgb2hsl = rgb2hsl;
|
---|
| 1049 | exports.rgb2hwb = rgb2hwb;
|
---|
| 1050 | exports.rgb2lab = rgb2lab;
|
---|
| 1051 | exports.rgb2lch = rgb2lch;
|
---|
| 1052 | exports.rgb2hsv = rgb2hsv;
|
---|
| 1053 | exports.rgb2xyz = rgb2xyz;
|
---|
| 1054 | exports.hsl2rgb = hsl2rgb;
|
---|
| 1055 | exports.hsl2hwb = hsl2hwb;
|
---|
| 1056 | exports.hsl2lab = hsl2lab;
|
---|
| 1057 | exports.hsl2lch = hsl2lch;
|
---|
| 1058 | exports.hsl2hsv = hsl2hsv;
|
---|
| 1059 | exports.hsl2xyz = hsl2xyz;
|
---|
| 1060 | exports.hwb2rgb = hwb2rgb;
|
---|
| 1061 | exports.hwb2hsl = hwb2hsl;
|
---|
| 1062 | exports.hwb2lab = hwb2lab;
|
---|
| 1063 | exports.hwb2lch = hwb2lch;
|
---|
| 1064 | exports.hwb2hsv = hwb2hsv;
|
---|
| 1065 | exports.hwb2xyz = hwb2xyz;
|
---|
| 1066 | exports.lab2rgb = lab2rgb;
|
---|
| 1067 | exports.lab2hsl = lab2hsl;
|
---|
| 1068 | exports.lab2hwb = lab2hwb;
|
---|
| 1069 | exports.lab2lch = lab2lch;
|
---|
| 1070 | exports.lab2hsv = lab2hsv;
|
---|
| 1071 | exports.lab2xyz = lab2xyz;
|
---|
| 1072 | exports.lch2rgb = lch2rgb;
|
---|
| 1073 | exports.lch2hsl = lch2hsl;
|
---|
| 1074 | exports.lch2hwb = lch2hwb;
|
---|
| 1075 | exports.lch2lab = lch2lab;
|
---|
| 1076 | exports.lch2hsv = lch2hsv;
|
---|
| 1077 | exports.lch2xyz = lch2xyz;
|
---|
| 1078 | exports.hsv2rgb = hsv2rgb;
|
---|
| 1079 | exports.hsv2hsl = hsv2hsl;
|
---|
| 1080 | exports.hsv2hwb = hsv2hwb;
|
---|
| 1081 | exports.hsv2lab = hsv2lab;
|
---|
| 1082 | exports.hsv2lch = hsv2lch;
|
---|
| 1083 | exports.hsv2xyz = hsv2xyz;
|
---|
| 1084 | exports.xyz2rgb = xyz2rgb;
|
---|
| 1085 | exports.xyz2hsl = xyz2hsl;
|
---|
| 1086 | exports.xyz2hwb = xyz2hwb;
|
---|
| 1087 | exports.xyz2lab = xyz2lab;
|
---|
| 1088 | exports.xyz2lch = xyz2lch;
|
---|
| 1089 | exports.xyz2hsv = xyz2hsv;
|
---|
| 1090 | exports.rgb2hue = rgb2hue;
|
---|
| 1091 | exports['default'] = index;
|
---|