html2canvas-pro 1.4.3 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +9 -4
  3. package/dist/html2canvas-pro.esm.js +838 -92
  4. package/dist/html2canvas-pro.esm.js.map +1 -1
  5. package/dist/html2canvas-pro.js +839 -93
  6. package/dist/html2canvas-pro.js.map +1 -1
  7. package/dist/html2canvas-pro.min.js +3 -3
  8. package/dist/lib/css/index.js +2 -1
  9. package/dist/lib/css/index.js.map +1 -1
  10. package/dist/lib/css/property-descriptors/__tests__/background-tests.js +3 -3
  11. package/dist/lib/css/property-descriptors/__tests__/background-tests.js.map +1 -1
  12. package/dist/lib/css/types/__tests__/color-tests.js +143 -34
  13. package/dist/lib/css/types/__tests__/color-tests.js.map +1 -1
  14. package/dist/lib/css/types/__tests__/image-tests.js +3 -2
  15. package/dist/lib/css/types/__tests__/image-tests.js.map +1 -1
  16. package/dist/lib/css/types/color-spaces/a98.js +77 -0
  17. package/dist/lib/css/types/color-spaces/a98.js.map +1 -0
  18. package/dist/lib/css/types/color-spaces/p3.js +87 -0
  19. package/dist/lib/css/types/color-spaces/p3.js.map +1 -0
  20. package/dist/lib/css/types/color-spaces/pro-photo.js +82 -0
  21. package/dist/lib/css/types/color-spaces/pro-photo.js.map +1 -0
  22. package/dist/lib/css/types/color-spaces/rec2020.js +85 -0
  23. package/dist/lib/css/types/color-spaces/rec2020.js.map +1 -0
  24. package/dist/lib/css/types/color-spaces/srgb.js +80 -0
  25. package/dist/lib/css/types/color-spaces/srgb.js.map +1 -0
  26. package/dist/lib/css/types/color-utilities.js +347 -0
  27. package/dist/lib/css/types/color-utilities.js.map +1 -0
  28. package/dist/lib/css/types/color.js +191 -107
  29. package/dist/lib/css/types/color.js.map +1 -1
  30. package/dist/lib/dom/replaced-elements/iframe-element-container.js +3 -2
  31. package/dist/lib/dom/replaced-elements/iframe-element-container.js.map +1 -1
  32. package/dist/lib/index.js +3 -2
  33. package/dist/lib/index.js.map +1 -1
  34. package/dist/lib/render/canvas/canvas-renderer.js +21 -21
  35. package/dist/lib/render/canvas/canvas-renderer.js.map +1 -1
  36. package/dist/lib/render/canvas/foreignobject-renderer.js +2 -2
  37. package/dist/lib/render/canvas/foreignobject-renderer.js.map +1 -1
  38. package/dist/types/css/types/color-spaces/a98.d.ts +39 -0
  39. package/dist/types/css/types/color-spaces/p3.d.ts +45 -0
  40. package/dist/types/css/types/color-spaces/pro-photo.d.ts +45 -0
  41. package/dist/types/css/types/color-spaces/rec2020.d.ts +45 -0
  42. package/dist/types/css/types/color-spaces/srgb.d.ts +38 -0
  43. package/dist/types/css/types/color-utilities.d.ts +108 -0
  44. package/dist/types/css/types/color.d.ts +0 -3
  45. package/package.json +1 -1
@@ -1,12 +1,12 @@
1
1
  /*!
2
- * html2canvas-pro 1.4.3 <undefined>
2
+ * html2canvas-pro 1.5.0 <undefined>
3
3
  * Copyright (c) 2024 yorickshan <https://github.com/yorickshan>
4
4
  * Released under MIT License
5
5
  */
6
6
  (function (global, factory) {
7
7
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
8
8
  typeof define === 'function' && define.amd ? define(factory) :
9
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global['html2canvas-pro'] = factory());
9
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.html2canvas = factory());
10
10
  }(this, (function () { 'use strict';
11
11
 
12
12
  /*! *****************************************************************************
@@ -1717,53 +1717,6 @@
1717
1717
  };
1718
1718
  var deg = function (deg) { return (Math.PI * deg) / 180; };
1719
1719
 
1720
- var color$1 = {
1721
- name: 'color',
1722
- parse: function (context, value) {
1723
- if (value.type === 18 /* FUNCTION */) {
1724
- var colorFunction = SUPPORTED_COLOR_FUNCTIONS[value.name];
1725
- if (typeof colorFunction === 'undefined') {
1726
- throw new Error("Attempting to parse an unsupported color function \"" + value.name + "\"");
1727
- }
1728
- return colorFunction(context, value.values);
1729
- }
1730
- if (value.type === 5 /* HASH_TOKEN */) {
1731
- if (value.value.length === 3) {
1732
- var r = value.value.substring(0, 1);
1733
- var g = value.value.substring(1, 2);
1734
- var b = value.value.substring(2, 3);
1735
- return pack(parseInt(r + r, 16), parseInt(g + g, 16), parseInt(b + b, 16), 1);
1736
- }
1737
- if (value.value.length === 4) {
1738
- var r = value.value.substring(0, 1);
1739
- var g = value.value.substring(1, 2);
1740
- var b = value.value.substring(2, 3);
1741
- var a = value.value.substring(3, 4);
1742
- return pack(parseInt(r + r, 16), parseInt(g + g, 16), parseInt(b + b, 16), parseInt(a + a, 16) / 255);
1743
- }
1744
- if (value.value.length === 6) {
1745
- var r = value.value.substring(0, 2);
1746
- var g = value.value.substring(2, 4);
1747
- var b = value.value.substring(4, 6);
1748
- return pack(parseInt(r, 16), parseInt(g, 16), parseInt(b, 16), 1);
1749
- }
1750
- if (value.value.length === 8) {
1751
- var r = value.value.substring(0, 2);
1752
- var g = value.value.substring(2, 4);
1753
- var b = value.value.substring(4, 6);
1754
- var a = value.value.substring(6, 8);
1755
- return pack(parseInt(r, 16), parseInt(g, 16), parseInt(b, 16), parseInt(a, 16) / 255);
1756
- }
1757
- }
1758
- if (value.type === 20 /* IDENT_TOKEN */) {
1759
- var namedColor = COLORS[value.value.toUpperCase()];
1760
- if (typeof namedColor !== 'undefined') {
1761
- return namedColor;
1762
- }
1763
- }
1764
- return COLORS.TRANSPARENT;
1765
- }
1766
- };
1767
1720
  var isTransparent = function (color) { return (0xff & color) === 0; };
1768
1721
  var asString = function (color) {
1769
1722
  var alpha = 0xff & color;
@@ -1785,19 +1738,111 @@
1785
1738
  }
1786
1739
  return 0;
1787
1740
  };
1788
- var rgb = function (_context, args) {
1789
- var tokens = args.filter(nonFunctionArgSeparator);
1790
- if (tokens.length === 3) {
1791
- var _a = tokens.map(getTokenColorValue), r = _a[0], g = _a[1], b = _a[2];
1792
- return pack(r, g, b, 1);
1741
+ var isRelativeTransform = function (tokens) {
1742
+ return (tokens[0].type === 20 /* IDENT_TOKEN */ ? tokens[0].value : 'unknown') === 'from';
1743
+ };
1744
+ var clamp = function (value, min, max) {
1745
+ return Math.min(Math.max(value, min), max);
1746
+ };
1747
+ var multiplyMatrices = function (A, B) {
1748
+ return [
1749
+ A[0] * B[0] + A[1] * B[1] + A[2] * B[2],
1750
+ A[3] * B[0] + A[4] * B[1] + A[5] * B[2],
1751
+ A[6] * B[0] + A[7] * B[1] + A[8] * B[2]
1752
+ ];
1753
+ };
1754
+ var packSrgb = function (args) {
1755
+ return pack(clamp(Math.round(args[0] * 255), 0, 255), clamp(Math.round(args[1] * 255), 0, 255), clamp(Math.round(args[2] * 255), 0, 255), clamp(args[3], 0, 1));
1756
+ };
1757
+ var packSrgbLinear = function (_a) {
1758
+ var r = _a[0], g = _a[1], b = _a[2], a = _a[3];
1759
+ var rgb = srgbLinear2rgb([r, g, b]);
1760
+ return pack(clamp(Math.round(rgb[0] * 255), 0, 255), clamp(Math.round(rgb[1] * 255), 0, 255), clamp(Math.round(rgb[2] * 255), 0, 255), a);
1761
+ };
1762
+ var packXYZ = function (args) {
1763
+ var srgb_linear = xyz2rgbLinear([args[0], args[1], args[2]]);
1764
+ return packSrgbLinear([srgb_linear[0], srgb_linear[1], srgb_linear[2], args[3]]);
1765
+ };
1766
+ var packLab = function (_context, args) {
1767
+ if (isRelativeTransform(args.filter(nonFunctionArgSeparator))) {
1768
+ throw new Error('Relative color not supported for lab()');
1793
1769
  }
1794
- if (tokens.length === 4) {
1795
- var _b = tokens.map(getTokenColorValue), r = _b[0], g = _b[1], b = _b[2], a = _b[3];
1796
- return pack(r, g, b, a);
1770
+ var _a = extractLabComponents(args), l = _a[0], a = _a[1], b = _a[2], alpha = _a[3], rgb = srgbLinear2rgb(xyz2rgbLinear(lab2xyz([l, a, b])));
1771
+ return pack(clamp(Math.round(rgb[0] * 255), 0, 255), clamp(Math.round(rgb[1] * 255), 0, 255), clamp(Math.round(rgb[2] * 255), 0, 255), alpha);
1772
+ };
1773
+ var packOkLab = function (_context, args) {
1774
+ if (isRelativeTransform(args.filter(nonFunctionArgSeparator))) {
1775
+ throw new Error('Relative color not supported for oklab()');
1797
1776
  }
1798
- return 0;
1777
+ var _a = extractLabComponents(args), l = _a[0], a = _a[1], b = _a[2], alpha = _a[3], rgb = srgbLinear2rgb(xyz2rgbLinear(oklab2xyz([l, a, b])));
1778
+ return pack(clamp(Math.round(rgb[0] * 255), 0, 255), clamp(Math.round(rgb[1] * 255), 0, 255), clamp(Math.round(rgb[2] * 255), 0, 255), alpha);
1779
+ };
1780
+ var packOkLch = function (_context, args) {
1781
+ if (isRelativeTransform(args.filter(nonFunctionArgSeparator))) {
1782
+ throw new Error('Relative color not supported for oklch()');
1783
+ }
1784
+ var _a = extractOkLchComponents(args), l = _a[0], c = _a[1], h = _a[2], alpha = _a[3], rgb = srgbLinear2rgb(xyz2rgbLinear(oklab2xyz(lch2lab([l, c, h]))));
1785
+ return pack(clamp(Math.round(rgb[0] * 255), 0, 255), clamp(Math.round(rgb[1] * 255), 0, 255), clamp(Math.round(rgb[2] * 255), 0, 255), alpha);
1786
+ };
1787
+ var packLch = function (_context, args) {
1788
+ if (isRelativeTransform(args.filter(nonFunctionArgSeparator))) {
1789
+ throw new Error('Relative color not supported for lch()');
1790
+ }
1791
+ var _a = extractLchComponents(args), l = _a[0], c = _a[1], h = _a[2], a = _a[3], rgb = srgbLinear2rgb(xyz2rgbLinear(lab2xyz(lch2lab([l, c, h]))));
1792
+ return pack(clamp(Math.round(rgb[0] * 255), 0, 255), clamp(Math.round(rgb[1] * 255), 0, 255), clamp(Math.round(rgb[2] * 255), 0, 255), a);
1793
+ };
1794
+ var extractHslComponents = function (context, args) {
1795
+ var tokens = args.filter(nonFunctionArgSeparator), hue = tokens[0], saturation = tokens[1], lightness = tokens[2], alpha = tokens[3], h = (hue.type === 17 /* NUMBER_TOKEN */ ? deg(hue.number) : angle.parse(context, hue)) / (Math.PI * 2), s = isLengthPercentage(saturation) ? saturation.number / 100 : 0, l = isLengthPercentage(lightness) ? lightness.number / 100 : 0, a = typeof alpha !== 'undefined' && isLengthPercentage(alpha) ? getAbsoluteValue(alpha, 1) : 1;
1796
+ return [h, s, l, a];
1797
+ };
1798
+ var packHSL = function (context, args) {
1799
+ if (isRelativeTransform(args)) {
1800
+ throw new Error('Relative color not supported for hsl()');
1801
+ }
1802
+ var _a = extractHslComponents(context, args), h = _a[0], s = _a[1], l = _a[2], a = _a[3], rgb = hsl2rgb([h, s, l]);
1803
+ return pack(rgb[0] * 255, rgb[1] * 255, rgb[2] * 255, s === 0 ? 1 : a);
1804
+ };
1805
+ var extractLchComponents = function (args) {
1806
+ var tokens = args.filter(nonFunctionArgSeparator), l = isLengthPercentage(tokens[0]) ? tokens[0].number : 0, c = isLengthPercentage(tokens[1]) ? tokens[1].number : 0, h = isNumberToken(tokens[2]) || isDimensionToken(tokens[2]) ? tokens[2].number : 0, a = typeof tokens[4] !== 'undefined' && isLengthPercentage(tokens[4]) ? getAbsoluteValue(tokens[4], 1) : 1;
1807
+ return [l, c, h, a];
1808
+ };
1809
+ var extractLabComponents = function (args) {
1810
+ var tokens = args.filter(nonFunctionArgSeparator),
1811
+ // eslint-disable-next-line prettier/prettier
1812
+ l = tokens[0].type === 16 /* PERCENTAGE_TOKEN */ ? tokens[0].number / 100 : (isNumberToken(tokens[0]) ? tokens[0].number : 0),
1813
+ // eslint-disable-next-line prettier/prettier
1814
+ a = tokens[1].type === 16 /* PERCENTAGE_TOKEN */ ? tokens[1].number / 100 : (isNumberToken(tokens[1]) ? tokens[1].number : 0), b = isNumberToken(tokens[2]) || isDimensionToken(tokens[2]) ? tokens[2].number : 0, alpha = typeof tokens[4] !== 'undefined' && isLengthPercentage(tokens[4]) ? getAbsoluteValue(tokens[4], 1) : 1;
1815
+ return [l, a, b, alpha];
1816
+ };
1817
+ var extractOkLchComponents = function (args) {
1818
+ var tokens = args.filter(nonFunctionArgSeparator),
1819
+ // eslint-disable-next-line prettier/prettier
1820
+ l = tokens[0].type === 16 /* PERCENTAGE_TOKEN */ ? tokens[0].number / 100 : isNumberToken(tokens[0]) ? tokens[0].number : 0,
1821
+ // eslint-disable-next-line prettier/prettier
1822
+ c = tokens[1].type === 16 /* PERCENTAGE_TOKEN */ ? tokens[1].number / 100 : isNumberToken(tokens[1]) ? tokens[1].number : 0, h = isNumberToken(tokens[2]) || isDimensionToken(tokens[2]) ? tokens[2].number : 0, a = typeof tokens[4] !== 'undefined' && isLengthPercentage(tokens[4]) ? getAbsoluteValue(tokens[4], 1) : 1;
1823
+ return [l, c, h, a];
1824
+ };
1825
+ /**
1826
+ * Convert D65 to D50
1827
+ *
1828
+ * @param xyz
1829
+ */
1830
+ var d65toD50 = function (xyz) {
1831
+ return multiplyMatrices(
1832
+ // eslint-disable-next-line prettier/prettier
1833
+ [1.0479297925449969, 0.022946870601609652, -0.05019226628920524, 0.02962780877005599, 0.9904344267538799, -0.017073799063418826, -0.009243040646204504, 0.015055191490298152, 0.7518742814281371], xyz);
1799
1834
  };
1800
- function hue2rgb(t1, t2, hue) {
1835
+ /**
1836
+ * Convert D50 to D65
1837
+ *
1838
+ * @param xyz
1839
+ */
1840
+ var d50toD65 = function (xyz) {
1841
+ return multiplyMatrices(
1842
+ // eslint-disable-next-line prettier/prettier
1843
+ [0.955473421488075, -0.02309845494876471, 0.06325924320057072, -0.0283697093338637, 1.0099953980813041, 0.021041441191917323, 0.012314014864481998, -0.020507649298898964, 1.330365926242124], xyz);
1844
+ };
1845
+ var hue2rgb = function (t1, t2, hue) {
1801
1846
  if (hue < 0) {
1802
1847
  hue += 1;
1803
1848
  }
@@ -1816,48 +1861,749 @@
1816
1861
  else {
1817
1862
  return t1;
1818
1863
  }
1819
- }
1820
- var hsl = function (context, args) {
1821
- var tokens = args.filter(nonFunctionArgSeparator);
1822
- var hue = tokens[0], saturation = tokens[1], lightness = tokens[2], alpha = tokens[3];
1823
- var h = (hue.type === 17 /* NUMBER_TOKEN */ ? deg(hue.number) : angle.parse(context, hue)) / (Math.PI * 2);
1824
- var s = isLengthPercentage(saturation) ? saturation.number / 100 : 0;
1825
- var l = isLengthPercentage(lightness) ? lightness.number / 100 : 0;
1826
- var a = typeof alpha !== 'undefined' && isLengthPercentage(alpha) ? getAbsoluteValue(alpha, 1) : 1;
1864
+ };
1865
+ var hsl2rgb = function (_a) {
1866
+ var h = _a[0], s = _a[1], l = _a[2];
1827
1867
  if (s === 0) {
1828
- return pack(l * 255, l * 255, l * 255, 1);
1868
+ return [l * 255, l * 255, l * 255];
1829
1869
  }
1830
- var t2 = l <= 0.5 ? l * (s + 1) : l + s - l * s;
1831
- var t1 = l * 2 - t2;
1832
- var r = hue2rgb(t1, t2, h + 1 / 3);
1833
- var g = hue2rgb(t1, t2, h);
1834
- var b = hue2rgb(t1, t2, h - 1 / 3);
1835
- return pack(r * 255, g * 255, b * 255, a);
1870
+ var t2 = l <= 0.5 ? l * (s + 1) : l + s - l * s, t1 = l * 2 - t2, r = hue2rgb(t1, t2, h + 1 / 3), g = hue2rgb(t1, t2, h), b = hue2rgb(t1, t2, h - 1 / 3);
1871
+ return [r, g, b];
1836
1872
  };
1837
- var clamp = function (value, min, max) { return Math.min(Math.max(value, min), max); };
1838
- var oklch = function (context, args) {
1873
+ /**
1874
+ * Convert lch to OKLab
1875
+ *
1876
+ * @param l
1877
+ * @param c
1878
+ * @param h
1879
+ */
1880
+ var lch2lab = function (_a) {
1881
+ var l = _a[0], c = _a[1], h = _a[2];
1882
+ if (c < 0) {
1883
+ c = 0;
1884
+ }
1885
+ if (isNaN(h)) {
1886
+ h = 0;
1887
+ }
1888
+ return [l, c * Math.cos((h * Math.PI) / 180), c * Math.sin((h * Math.PI) / 180)];
1889
+ };
1890
+ /**
1891
+ * Convert OKLab to XYZ relative to D65
1892
+ *
1893
+ * @param lab
1894
+ */
1895
+ var oklab2xyz = function (lab) {
1896
+ var LMSg = multiplyMatrices(
1897
+ // eslint-disable-next-line prettier/prettier
1898
+ [1, 0.3963377773761749, 0.2158037573099136, 1, -0.1055613458156586, -0.0638541728258133, 1, -0.0894841775298119, -1.2914855480194092], lab), LMS = LMSg.map(function (val) { return Math.pow(val, 3); });
1899
+ return multiplyMatrices(
1900
+ // eslint-disable-next-line prettier/prettier
1901
+ [1.2268798758459243, -0.5578149944602171, 0.2813910456659647, -0.0405757452148008, 1.112286803280317, -0.0717110580655164, -0.0763729366746601, -0.4214933324022432, 1.5869240198367816], LMS);
1902
+ };
1903
+ /**
1904
+ * Convert Lab to D50-adapted XYZ
1905
+ *
1906
+ * @param lab
1907
+ */
1908
+ var lab2xyz = function (lab) {
1909
+ var fy = (lab[0] + 16) / 116, fx = lab[1] / 500 + fy, fz = fy - lab[2] / 200, k = 24389 / 27, e = 24 / 116, xyz = [
1910
+ ((fx > e ? Math.pow(fx, 3) : (116 * fx - 16) / k) * 0.3457) / 0.3585,
1911
+ lab[0] > 8 ? Math.pow(fy, 3) : lab[0] / k,
1912
+ ((fz > e ? Math.pow(fz, 3) : (116 * fz - 16) / k) * (1.0 - 0.3457 - 0.3585)) / 0.3585
1913
+ ];
1914
+ return d50toD65([xyz[0], xyz[1], xyz[2]]);
1915
+ };
1916
+ /**
1917
+ * Convert RGB to XYZ
1918
+ *
1919
+ * @param _context
1920
+ * @param args
1921
+ */
1922
+ var rgbToXyz = function (_context, args) {
1839
1923
  var tokens = args.filter(nonFunctionArgSeparator);
1840
- var lightness = tokens[0], chroma = tokens[1], hue = tokens[2], alpha = tokens[3];
1841
- var l = isLengthPercentage(lightness) ? lightness.number / 100 : 0;
1842
- var c = isLengthPercentage(chroma) ? chroma.number / 100 : 0;
1843
- var h = hue.type === 17 /* NUMBER_TOKEN */ ? deg(hue.number) : angle.parse(context, hue);
1844
- var a = typeof alpha !== 'undefined' && isLengthPercentage(alpha) ? getAbsoluteValue(alpha, 1) : 1;
1845
- var hrad = h / (Math.PI * 180);
1846
- var lr = l * 255;
1847
- var cr = c * 128;
1848
- var x = cr * Math.cos(hrad);
1849
- var y = cr * Math.sin(hrad);
1850
- var r = lr + x;
1851
- var g = lr - x * 0.57735 - y * 1.1547;
1852
- var b = lr + y * 1.73205;
1853
- return pack(clamp(r, 0, 255), clamp(g, 0, 255), clamp(b, 0, 255), a);
1924
+ if (tokens.length === 3) {
1925
+ var _a = tokens.map(getTokenColorValue), r = _a[0], g = _a[1], b = _a[2], rgb_linear = rgb2rgbLinear([r / 255, g / 255, b / 255]), _b = rgbLinear2xyz([rgb_linear[0], rgb_linear[1], rgb_linear[2]]), x = _b[0], y = _b[1], z = _b[2];
1926
+ return [x, y, z, 1];
1927
+ }
1928
+ if (tokens.length === 4) {
1929
+ var _c = tokens.map(getTokenColorValue), r = _c[0], g = _c[1], b = _c[2], a = _c[3], rgb_linear = rgb2rgbLinear([r / 255, g / 255, b / 255]), _d = rgbLinear2xyz([rgb_linear[0], rgb_linear[1], rgb_linear[2]]), x = _d[0], y = _d[1], z = _d[2];
1930
+ return [x, y, z, a];
1931
+ }
1932
+ return [0, 0, 0, 1];
1933
+ };
1934
+ /**
1935
+ * HSL to XYZ
1936
+ *
1937
+ * @param context
1938
+ * @param args
1939
+ */
1940
+ var hslToXyz = function (context, args) {
1941
+ var _a = extractHslComponents(context, args), h = _a[0], s = _a[1], l = _a[2], a = _a[3], rgb_linear = rgb2rgbLinear(hsl2rgb([h, s, l])), _b = rgbLinear2xyz([rgb_linear[0], rgb_linear[1], rgb_linear[2]]), x = _b[0], y = _b[1], z = _b[2];
1942
+ return [x, y, z, a];
1943
+ };
1944
+ /**
1945
+ * LAB to XYZ
1946
+ *
1947
+ * @param _context
1948
+ * @param args
1949
+ */
1950
+ var labToXyz = function (_context, args) {
1951
+ var _a = extractLabComponents(args), l = _a[0], a = _a[1], b = _a[2], alpha = _a[3], _b = lab2xyz([l, a, b]), x = _b[0], y = _b[1], z = _b[2];
1952
+ return [x, y, z, alpha];
1953
+ };
1954
+ /**
1955
+ * LCH to XYZ
1956
+ *
1957
+ * @param _context
1958
+ * @param args
1959
+ */
1960
+ var lchToXyz = function (_context, args) {
1961
+ var _a = extractLchComponents(args), l = _a[0], c = _a[1], h = _a[2], alpha = _a[3], _b = lab2xyz(lch2lab([l, c, h])), x = _b[0], y = _b[1], z = _b[2];
1962
+ return [x, y, z, alpha];
1963
+ };
1964
+ /**
1965
+ * OKLch to XYZ
1966
+ *
1967
+ * @param _context
1968
+ * @param args
1969
+ */
1970
+ var oklchToXyz = function (_context, args) {
1971
+ var _a = extractOkLchComponents(args), l = _a[0], c = _a[1], h = _a[2], alpha = _a[3], _b = oklab2xyz(lch2lab([l, c, h])), x = _b[0], y = _b[1], z = _b[2];
1972
+ return [x, y, z, alpha];
1973
+ };
1974
+ /**
1975
+ * OKLab to XYZ
1976
+ *
1977
+ * @param _context
1978
+ * @param args
1979
+ */
1980
+ var oklabToXyz = function (_context, args) {
1981
+ var _a = extractLabComponents(args), l = _a[0], c = _a[1], h = _a[2], alpha = _a[3], _b = oklab2xyz([l, c, h]), x = _b[0], y = _b[1], z = _b[2];
1982
+ return [x, y, z, alpha];
1983
+ };
1984
+ /**
1985
+ * XYZ-50 to XYZ
1986
+ *
1987
+ * @param args
1988
+ */
1989
+ var xyz50ToXYZ = function (args) {
1990
+ return d50toD65([args[0], args[1], args[2]]);
1991
+ };
1992
+ /**
1993
+ * Does nothing, required for SUPPORTED_COLOR_SPACES_FROM_XYZ in the _color() function
1994
+ *
1995
+ * @param args
1996
+ */
1997
+ var xyzFromXYZ = function (args) {
1998
+ return args;
1999
+ };
2000
+ /**
2001
+ * XYZ-65 to XYZ-50
2002
+ *
2003
+ * @param args
2004
+ */
2005
+ var xyz50FromXYZ = function (args) {
2006
+ var _a = d65toD50([args[0], args[2], args[3]]), x = _a[0], y = _a[1], z = _a[2];
2007
+ return [x, y, z, args[3]];
2008
+ };
2009
+ /**
2010
+ * Convert XYZ to SRGB and Pack
2011
+ *
2012
+ * @param args
2013
+ */
2014
+ var convertXyz = function (args) {
2015
+ return packXYZ([args[0], args[1], args[2], args[3]]);
2016
+ };
2017
+ /**
2018
+ * Convert XYZ-50 to SRGB and Pack
2019
+ *
2020
+ * @param args
2021
+ */
2022
+ var convertXyz50 = function (args) {
2023
+ var xyz = xyz50ToXYZ([args[0], args[1], args[2]]);
2024
+ return packXYZ([xyz[0], xyz[1], xyz[2], args[3]]);
2025
+ };
2026
+
2027
+ /**
2028
+ * SRGB related functions
2029
+ */
2030
+ /**
2031
+ * Convert XYZ to linear-light sRGB
2032
+ *
2033
+ * @param xyz
2034
+ */
2035
+ var xyz2rgbLinear = function (xyz) {
2036
+ return multiplyMatrices(
2037
+ // eslint-disable-next-line prettier/prettier
2038
+ [3.2409699419045226, -1.537383177570094, -0.4986107602930034, -0.9692436362808796, 1.8759675015077202, 0.04155505740717559, 0.05563007969699366, -0.20397695888897652, 1.0569715142428786], xyz);
2039
+ };
2040
+ /**
2041
+ * Convert XYZ to linear-light sRGB
2042
+ *
2043
+ * @param xyz
2044
+ */
2045
+ var rgbLinear2xyz = function (xyz) {
2046
+ return multiplyMatrices(
2047
+ // eslint-disable-next-line prettier/prettier
2048
+ [0.41239079926595934, 0.357584339383878, 0.1804807884018343, 0.21263900587151027, 0.715168678767756, 0.07219231536073371, 0.01933081871559182, 0.11919477979462598, 0.9505321522496607], xyz);
2049
+ };
2050
+ /**
2051
+ * Convert sRGB to RGB
2052
+ *
2053
+ * @param rgb
2054
+ */
2055
+ var srgbLinear2rgb = function (rgb) {
2056
+ return rgb.map(function (c) {
2057
+ var sign = c < 0 ? -1 : 1, abs = Math.abs(c);
2058
+ // eslint-disable-next-line prettier/prettier
2059
+ return abs > 0.0031308 ? sign * (1.055 * (Math.pow(abs, (1 / 2.4))) - 0.055) : (12.92 * c);
2060
+ });
2061
+ };
2062
+ /**
2063
+ * Convert RGB to sRGB
2064
+ *
2065
+ * @param rgb
2066
+ */
2067
+ var rgb2rgbLinear = function (rgb) {
2068
+ return rgb.map(function (c) {
2069
+ var sign = c < 0 ? -1 : 1, abs = Math.abs(c);
2070
+ // eslint-disable-next-line prettier/prettier
2071
+ return abs <= 0.04045 ? c / 12.92 : sign * (Math.pow(((abs + 0.055) / 1.055), 2.4));
2072
+ });
2073
+ };
2074
+ /**
2075
+ * XYZ to SRGB
2076
+ *
2077
+ * @param args
2078
+ */
2079
+ var srgbFromXYZ = function (args) {
2080
+ var _a = srgbLinear2rgb(xyz2rgbLinear([args[0], args[1], args[2]])), r = _a[0], g = _a[1], b = _a[2];
2081
+ return [r, g, b, args[3]];
2082
+ };
2083
+ /**
2084
+ * XYZ to SRGB-Linear
2085
+ * @param args
2086
+ */
2087
+ var srgbLinearFromXYZ = function (args) {
2088
+ var _a = xyz2rgbLinear([args[0], args[1], args[2]]), r = _a[0], g = _a[1], b = _a[2];
2089
+ return [
2090
+ clamp(Math.round(r * 255), 0, 255),
2091
+ clamp(Math.round(g * 255), 0, 255),
2092
+ clamp(Math.round(b * 255), 0, 255),
2093
+ args[3]
2094
+ ];
2095
+ };
2096
+
2097
+ /**
2098
+ * Display-P3 related functions
2099
+ */
2100
+ /**
2101
+ * Convert P3 Linear to xyz
2102
+ *
2103
+ * @param p3l
2104
+ */
2105
+ var p3LinearToXyz = function (p3l) {
2106
+ return multiplyMatrices(
2107
+ // eslint-disable-next-line prettier/prettier
2108
+ [0.4865709486482162, 0.26566769316909306, 0.1982172852343625, 0.2289745640697488, 0.6917385218365064, 0.079286914093745, 0.0, 0.04511338185890264, 1.043944368900976
2109
+ ], p3l);
2110
+ };
2111
+ /**
2112
+ * Convert XYZ to P3 Linear
2113
+ *
2114
+ * @param xyz
2115
+ */
2116
+ var xyzToP3Linear = function (xyz) {
2117
+ return multiplyMatrices(
2118
+ // eslint-disable-next-line prettier/prettier
2119
+ [2.493496911941425, -0.9313836179191239, -0.40271078445071684, -0.8294889695615747, 1.7626640603183463, 0.023624685841943577, 0.03584583024378447, -0.07617238926804182, 0.9568845240076872], xyz);
2120
+ };
2121
+ /**
2122
+ * Convert P3 to P3 linear
2123
+ *
2124
+ * @param p3
2125
+ */
2126
+ var p32p3Linear = function (p3) {
2127
+ return p3.map(function (c) {
2128
+ var sign = c < 0 ? -1 : 1, abs = c * sign;
2129
+ if (abs <= 0.04045) {
2130
+ return c / 12.92;
2131
+ }
2132
+ // eslint-disable-next-line prettier/prettier
2133
+ return sign * (Math.pow(((c + 0.055) / 1.055), 2.4)) || 0;
2134
+ });
2135
+ };
2136
+ /**
2137
+ * Convert P3 Linear to P3
2138
+ *
2139
+ * @param p3l
2140
+ */
2141
+ var p3Linear2p3 = function (p3l) {
2142
+ return srgbLinear2rgb(p3l);
2143
+ };
2144
+ /**
2145
+ * Convert P3 to XYZ
2146
+ *
2147
+ * @param args
2148
+ */
2149
+ var p3ToXYZ = function (args) {
2150
+ var p3_linear = p32p3Linear([args[0], args[1], args[2]]);
2151
+ return p3LinearToXyz([p3_linear[0], p3_linear[1], p3_linear[2]]);
2152
+ };
2153
+ /**
2154
+ * Convert XYZ to P3
2155
+ *
2156
+ * @param args
2157
+ */
2158
+ var p3FromXYZ = function (args) {
2159
+ var _a = p3Linear2p3(xyzToP3Linear([args[0], args[1], args[2]])), r = _a[0], g = _a[1], b = _a[2];
2160
+ return [r, g, b, args[3]];
2161
+ };
2162
+ /**
2163
+ * Convert P3 to SRGB and Pack
2164
+ *
2165
+ * @param args
2166
+ */
2167
+ var convertP3 = function (args) {
2168
+ var xyz = p3ToXYZ([args[0], args[1], args[2]]);
2169
+ return packXYZ([xyz[0], xyz[1], xyz[2], args[3]]);
2170
+ };
2171
+
2172
+ /**
2173
+ * A98-RGB related functions
2174
+ */
2175
+ /**
2176
+ * Convert XYZ to a98 linear
2177
+ *
2178
+ * @param xyz
2179
+ */
2180
+ var xyz2a98Linear = function (xyz) {
2181
+ return multiplyMatrices(
2182
+ // eslint-disable-next-line prettier/prettier
2183
+ [2.0415879038107465, -0.5650069742788596, -0.34473135077832956, -0.9692436362808795, 1.8759675015077202, 0.04155505740717557, 0.013444280632031142, -0.11836239223101838, 1.0151749943912054], xyz);
2184
+ };
2185
+ /**
2186
+ * Convert XYZ to a98 linear
2187
+ *
2188
+ * @param a98
2189
+ */
2190
+ var a98Linear2xyz = function (a98) {
2191
+ return multiplyMatrices(
2192
+ // eslint-disable-next-line prettier/prettier
2193
+ [0.5766690429101305, 0.1855582379065463, 0.1882286462349947, 0.29734497525053605, 0.6273635662554661, 0.0752914584939978, 0.02703136138641234, 0.07068885253582723, 0.9913375368376388], a98);
2194
+ };
2195
+ /**
2196
+ * Convert A98 RGB to rgb linear
2197
+ *
2198
+ * @param rgb
2199
+ */
2200
+ var a982a98Linear = function (rgb) {
2201
+ var mapped = rgb.map(function (c) {
2202
+ var sign = c < 0 ? -1 : 1, abs = Math.abs(c);
2203
+ return sign * Math.pow(abs, (563 / 256));
2204
+ });
2205
+ return [mapped[0], mapped[1], mapped[2]];
2206
+ };
2207
+ /**
2208
+ * Convert A98 RGB Linear to A98
2209
+ *
2210
+ * @param rgb
2211
+ */
2212
+ var a98Linear2a98 = function (rgb) {
2213
+ var mapped = rgb.map(function (c) {
2214
+ var sign = c < 0 ? -1 : 1, abs = Math.abs(c);
2215
+ return sign * Math.pow(abs, (256 / 563));
2216
+ });
2217
+ return [mapped[0], mapped[1], mapped[2]];
2218
+ };
2219
+ /**
2220
+ * Convert XYZ to A98
2221
+ *
2222
+ * @param args
2223
+ */
2224
+ var a98FromXYZ = function (args) {
2225
+ var _a = a98Linear2a98(xyz2a98Linear([args[0], args[1], args[2]])), r = _a[0], g = _a[1], b = _a[2];
2226
+ return [r, g, b, args[3]];
2227
+ };
2228
+ /**
2229
+ * Convert A98 to XYZ and Pack
2230
+ *
2231
+ * @param args
2232
+ */
2233
+ var convertA98rgb = function (args) {
2234
+ var srgb_linear = xyz2rgbLinear(a98Linear2xyz(a982a98Linear([args[0], args[1], args[2]])));
2235
+ return packSrgbLinear([srgb_linear[0], srgb_linear[1], srgb_linear[2], args[3]]);
2236
+ };
2237
+
2238
+ /**
2239
+ * Pro Photo related functions
2240
+ */
2241
+ /**
2242
+ * Convert linear-light display-p3 to XYZ D65
2243
+ *
2244
+ * @param p3
2245
+ */
2246
+ var proPhotoLinearToXyz = function (p3) {
2247
+ return multiplyMatrices(
2248
+ // eslint-disable-next-line prettier/prettier
2249
+ [0.79776664490064230, 0.13518129740053308, 0.03134773412839220, 0.28807482881940130, 0.71183523424187300, 0.00008993693872564, 0.0, 0.0, 0.82510460251046020], p3);
2250
+ };
2251
+ /**
2252
+ * Convert XYZ D65 to linear-light display-p3
2253
+ *
2254
+ * @param xyz
2255
+ */
2256
+ var xyzToProPhotoLinear = function (xyz) {
2257
+ return multiplyMatrices(
2258
+ // eslint-disable-next-line prettier/prettier
2259
+ [1.34578688164715830, -0.25557208737979464, -0.05110186497554526, -0.54463070512490190, 1.50824774284514680, 0.02052744743642139, 0.0, 0.0, 1.21196754563894520], xyz);
2260
+ };
2261
+ /**
2262
+ * Convert Pro-Photo to Pro-Photo Linear
2263
+ *
2264
+ * @param p3
2265
+ */
2266
+ var proPhotoToProPhotoLinear = function (p3) {
2267
+ return p3.map(function (c) {
2268
+ return c < 16 / 512 ? c / 16 : Math.pow(c, 1.8);
2269
+ });
2270
+ };
2271
+ /**
2272
+ * Convert Pro-Photo Linear to Pro-Photo
2273
+ *
2274
+ * @param p3
2275
+ */
2276
+ var proPhotoLinearToProPhoto = function (p3) {
2277
+ return p3.map(function (c) {
2278
+ return c > 1 / 512 ? Math.pow(c, (1 / 1.8)) : c * 16;
2279
+ });
2280
+ };
2281
+ /**
2282
+ * Convert Pro-Photo to XYZ
2283
+ *
2284
+ * @param args
2285
+ */
2286
+ var proPhotoToXYZ = function (args) {
2287
+ var prophoto_linear = proPhotoToProPhotoLinear([args[0], args[1], args[2]]);
2288
+ return d50toD65(proPhotoLinearToXyz([prophoto_linear[0], prophoto_linear[1], prophoto_linear[2]]));
2289
+ };
2290
+ /**
2291
+ * Convert XYZ to Pro-Photo
2292
+ *
2293
+ * @param args
2294
+ */
2295
+ var proPhotoFromXYZ = function (args) {
2296
+ var _a = proPhotoLinearToProPhoto(xyzToProPhotoLinear(d65toD50([args[0], args[1], args[2]]))), r = _a[0], g = _a[1], b = _a[2];
2297
+ return [r, g, b, args[3]];
2298
+ };
2299
+ /**
2300
+ * Convert Pro-Photo to XYZ and Pack
2301
+ *
2302
+ * @param args
2303
+ */
2304
+ var convertProPhoto = function (args) {
2305
+ var xyz = proPhotoToXYZ([args[0], args[1], args[2]]);
2306
+ return packXYZ([xyz[0], xyz[1], xyz[2], args[3]]);
2307
+ };
2308
+
2309
+ /**
2310
+ * REC2020 related functions
2311
+ */
2312
+ var _a = 1.09929682680944;
2313
+ var _b = 0.018053968510807;
2314
+ /**
2315
+ * Convert rec2020 to rec2020 linear
2316
+ *
2317
+ * @param rgb
2318
+ */
2319
+ var rec20202rec2020Linear = function (rgb) {
2320
+ return rgb.map(function (c) {
2321
+ return c < _b * 4.5 ? c / 4.5 : Math.pow((c + _a - 1) / _a, 1 / 0.45);
2322
+ });
2323
+ };
2324
+ /**
2325
+ * Convert rec2020 linear to rec2020
2326
+ *
2327
+ * @param rgb
2328
+ */
2329
+ var rec2020Linear2rec2020 = function (rgb) {
2330
+ return rgb.map(function (c) {
2331
+ return c >= _b ? _a * Math.pow(c, 0.45) - (_a - 1) : 4.5 * c;
2332
+ });
2333
+ };
2334
+ /**
2335
+ * Convert rec2020 linear to XYZ D65
2336
+ *
2337
+ * @param rec
2338
+ */
2339
+ var rec2020LinearToXyz = function (rec) {
2340
+ return multiplyMatrices(
2341
+ // eslint-disable-next-line prettier/prettier
2342
+ [0.6369580483012914, 0.14461690358620832, 0.1688809751641721, 0.2627002120112671, 0.6779980715188708, 0.05930171646986196, 0.0, 0.028072693049087428, 1.060985057710791
2343
+ ], rec);
2344
+ };
2345
+ /**
2346
+ * Convert XYZ D65 to rec2020 linear
2347
+ *
2348
+ * @param xyz
2349
+ */
2350
+ var xyzToRec2020Linear = function (xyz) {
2351
+ return multiplyMatrices(
2352
+ // eslint-disable-next-line prettier/prettier
2353
+ [1.716651187971268, -0.355670783776392, -0.253366281373660, -0.666684351832489, 1.616481236634939, 0.0157685458139111, 0.017639857445311, -0.042770613257809, 0.942103121235474], xyz);
2354
+ };
2355
+ /**
2356
+ * Convert Rec2020 to XYZ
2357
+ *
2358
+ * @param args
2359
+ */
2360
+ var rec2020ToXYZ = function (args) {
2361
+ var rec2020_linear = rec20202rec2020Linear([args[0], args[1], args[2]]);
2362
+ return rec2020LinearToXyz([rec2020_linear[0], rec2020_linear[1], rec2020_linear[2]]);
2363
+ };
2364
+ /**
2365
+ * Convert XYZ to Rec2020
2366
+ *
2367
+ * @param args
2368
+ */
2369
+ var rec2020FromXYZ = function (args) {
2370
+ var _c = rec2020Linear2rec2020(xyzToRec2020Linear([args[0], args[1], args[2]])), r = _c[0], g = _c[1], b = _c[2];
2371
+ return [r, g, b, args[3]];
2372
+ };
2373
+ /**
2374
+ * Convert Rec2020 to SRGB and Pack
2375
+ *
2376
+ * @param args
2377
+ */
2378
+ var convertRec2020 = function (args) {
2379
+ var xyz = rec2020ToXYZ([args[0], args[1], args[2]]);
2380
+ return packXYZ([xyz[0], xyz[1], xyz[2], args[3]]);
2381
+ };
2382
+
2383
+ var color$1 = {
2384
+ name: 'color',
2385
+ parse: function (context, value) {
2386
+ if (value.type === 18 /* FUNCTION */) {
2387
+ var colorFunction = SUPPORTED_COLOR_FUNCTIONS[value.name];
2388
+ if (typeof colorFunction === 'undefined') {
2389
+ throw new Error("Attempting to parse an unsupported color function \"" + value.name + "\"");
2390
+ }
2391
+ return colorFunction(context, value.values);
2392
+ }
2393
+ if (value.type === 5 /* HASH_TOKEN */) {
2394
+ var _a = hash2rgb(value), r = _a[0], g = _a[1], b = _a[2], a = _a[3];
2395
+ return pack(r, g, b, a);
2396
+ }
2397
+ if (value.type === 20 /* IDENT_TOKEN */) {
2398
+ var namedColor = COLORS[value.value.toUpperCase()];
2399
+ if (typeof namedColor !== 'undefined') {
2400
+ return namedColor;
2401
+ }
2402
+ }
2403
+ return COLORS.TRANSPARENT;
2404
+ }
2405
+ };
2406
+ var hash2rgb = function (token) {
2407
+ if (token.value.length === 3) {
2408
+ var r = token.value.substring(0, 1);
2409
+ var g = token.value.substring(1, 2);
2410
+ var b = token.value.substring(2, 3);
2411
+ return [parseInt(r + r, 16), parseInt(g + g, 16), parseInt(b + b, 16), 1];
2412
+ }
2413
+ if (token.value.length === 4) {
2414
+ var r = token.value.substring(0, 1);
2415
+ var g = token.value.substring(1, 2);
2416
+ var b = token.value.substring(2, 3);
2417
+ var a = token.value.substring(3, 4);
2418
+ return [parseInt(r + r, 16), parseInt(g + g, 16), parseInt(b + b, 16), parseInt(a + a, 16) / 255];
2419
+ }
2420
+ if (token.value.length === 6) {
2421
+ var r = token.value.substring(0, 2);
2422
+ var g = token.value.substring(2, 4);
2423
+ var b = token.value.substring(4, 6);
2424
+ return [parseInt(r, 16), parseInt(g, 16), parseInt(b, 16), 1];
2425
+ }
2426
+ if (token.value.length === 8) {
2427
+ var r = token.value.substring(0, 2);
2428
+ var g = token.value.substring(2, 4);
2429
+ var b = token.value.substring(4, 6);
2430
+ var a = token.value.substring(6, 8);
2431
+ return [parseInt(r, 16), parseInt(g, 16), parseInt(b, 16), parseInt(a, 16) / 255];
2432
+ }
2433
+ return [0, 0, 0, 1];
2434
+ };
2435
+ var rgb = function (_context, args) {
2436
+ var tokens = args.filter(nonFunctionArgSeparator);
2437
+ if (isRelativeTransform(tokens)) {
2438
+ throw new Error('Relative color not supported for rgb()');
2439
+ }
2440
+ if (tokens.length === 3) {
2441
+ var _a = tokens.map(getTokenColorValue), r = _a[0], g = _a[1], b = _a[2];
2442
+ return pack(r, g, b, 1);
2443
+ }
2444
+ if (tokens.length === 4) {
2445
+ var _b = tokens.map(getTokenColorValue), r = _b[0], g = _b[1], b = _b[2], a = _b[3];
2446
+ return pack(r, g, b, a);
2447
+ }
2448
+ return 0;
2449
+ };
2450
+ /**
2451
+ * Handle the CSS color() function
2452
+ *
2453
+ * @param context
2454
+ * @param args
2455
+ */
2456
+ var _color = function (context, args) {
2457
+ var tokens = args.filter(nonFunctionArgSeparator), token_1_value = tokens[0].type === 20 /* IDENT_TOKEN */ ? tokens[0].value : 'unknown', is_absolute = !isRelativeTransform(tokens);
2458
+ if (is_absolute) {
2459
+ var color_space = token_1_value, colorSpaceFunction = SUPPORTED_COLOR_SPACES_ABSOLUTE[color_space];
2460
+ if (typeof colorSpaceFunction === 'undefined') {
2461
+ throw new Error("Attempting to parse an unsupported color space \"" + color_space + "\" for color() function");
2462
+ }
2463
+ var c1 = isNumberToken(tokens[1]) ? tokens[1].number : 0, c2 = isNumberToken(tokens[2]) ? tokens[2].number : 0, c3 = isNumberToken(tokens[3]) ? tokens[3].number : 0, a = tokens.length > 4 &&
2464
+ tokens[4].type === 6 /* DELIM_TOKEN */ &&
2465
+ tokens[4].value === '/' &&
2466
+ isNumberToken(tokens[5])
2467
+ ? tokens[5].number
2468
+ : 1;
2469
+ return colorSpaceFunction([c1, c2, c3, a]);
2470
+ }
2471
+ else {
2472
+ var extractComponent = function (color, token) {
2473
+ if (isNumberToken(token)) {
2474
+ return token.number;
2475
+ }
2476
+ var posFromVal = function (value) {
2477
+ return value === 'r' || value === 'x' ? 0 : value === 'g' || value === 'y' ? 1 : 2;
2478
+ };
2479
+ if (isIdentToken(token)) {
2480
+ var position = posFromVal(token.value);
2481
+ return color[position];
2482
+ }
2483
+ var parseCalc = function (args) {
2484
+ var parts = args.filter(nonFunctionArgSeparator);
2485
+ var expression = '(';
2486
+ for (var _i = 0, parts_1 = parts; _i < parts_1.length; _i++) {
2487
+ var part = parts_1[_i];
2488
+ expression +=
2489
+ part.type === 18 /* FUNCTION */ && part.name === 'calc'
2490
+ ? parseCalc(part.values)
2491
+ : isNumberToken(part)
2492
+ ? part.number
2493
+ : part.type === 6 /* DELIM_TOKEN */ || isIdentToken(part)
2494
+ ? part.value
2495
+ : '';
2496
+ }
2497
+ expression += ')';
2498
+ return expression;
2499
+ };
2500
+ if (token.type === 18 /* FUNCTION */) {
2501
+ var args_1 = token.values.filter(nonFunctionArgSeparator);
2502
+ if (token.name === 'calc') {
2503
+ var expression = parseCalc(args_1)
2504
+ .replace(/r|x/, color[0].toString())
2505
+ .replace(/g|y/, color[1].toString())
2506
+ .replace(/b|z/, color[2].toString());
2507
+ return eval(expression);
2508
+ }
2509
+ }
2510
+ return null;
2511
+ };
2512
+ var from_colorspace = tokens[1].type === 18 /* FUNCTION */
2513
+ ? tokens[1].name
2514
+ : isIdentToken(tokens[1]) || tokens[1].type === 5 /* HASH_TOKEN */
2515
+ ? 'rgb'
2516
+ : 'unknown', to_colorspace = isIdentToken(tokens[2]) ? tokens[2].value : 'unknown';
2517
+ var from = tokens[1].type === 18 /* FUNCTION */ ? tokens[1].values : isIdentToken(tokens[1]) ? [tokens[1]] : [];
2518
+ if (isIdentToken(tokens[1])) {
2519
+ var named_color = COLORS[tokens[1].value.toUpperCase()];
2520
+ if (typeof named_color === 'undefined') {
2521
+ throw new Error("Attempting to use unknown color in relative color 'from'");
2522
+ }
2523
+ else {
2524
+ var _c = parseColor(context, tokens[1].value), alpha = 0xff & _c, blue = 0xff & (_c >> 8), green = 0xff & (_c >> 16), red = 0xff & (_c >> 24);
2525
+ from = [
2526
+ { type: 17 /* NUMBER_TOKEN */, number: red, flags: 1 },
2527
+ { type: 17 /* NUMBER_TOKEN */, number: green, flags: 1 },
2528
+ { type: 17 /* NUMBER_TOKEN */, number: blue, flags: 1 },
2529
+ { type: 17 /* NUMBER_TOKEN */, number: alpha > 1 ? alpha / 255 : alpha, flags: 1 }
2530
+ ];
2531
+ }
2532
+ }
2533
+ else if (tokens[1].type === 5 /* HASH_TOKEN */) {
2534
+ var _a = hash2rgb(tokens[1]), red = _a[0], green = _a[1], blue = _a[2], alpha = _a[3];
2535
+ from = [
2536
+ { type: 17 /* NUMBER_TOKEN */, number: red, flags: 1 },
2537
+ { type: 17 /* NUMBER_TOKEN */, number: green, flags: 1 },
2538
+ { type: 17 /* NUMBER_TOKEN */, number: blue, flags: 1 },
2539
+ { type: 17 /* NUMBER_TOKEN */, number: alpha > 1 ? alpha / 255 : alpha, flags: 1 }
2540
+ ];
2541
+ }
2542
+ if (from.length === 0) {
2543
+ throw new Error("Attempting to use unknown color in relative color 'from'");
2544
+ }
2545
+ if (to_colorspace === 'unknown') {
2546
+ throw new Error("Attempting to use unknown colorspace in relative color 'to'");
2547
+ }
2548
+ var fromColorToXyz = SUPPORTED_COLOR_SPACES_TO_XYZ[from_colorspace], toColorFromXyz = SUPPORTED_COLOR_SPACES_FROM_XYZ[to_colorspace], toColorPack = SUPPORTED_COLOR_SPACES_ABSOLUTE[to_colorspace];
2549
+ if (typeof fromColorToXyz === 'undefined') {
2550
+ throw new Error("Attempting to parse an unsupported color space \"" + from_colorspace + "\" for color() function");
2551
+ }
2552
+ if (typeof toColorFromXyz === 'undefined') {
2553
+ throw new Error("Attempting to parse an unsupported color space \"" + to_colorspace + "\" for color() function");
2554
+ }
2555
+ var from_color = fromColorToXyz(context, from), from_final_colorspace = toColorFromXyz(from_color), c1 = extractComponent(from_final_colorspace, tokens[3]), c2 = extractComponent(from_final_colorspace, tokens[4]), c3 = extractComponent(from_final_colorspace, tokens[5]), a = tokens.length > 6 &&
2556
+ tokens[6].type === 6 /* DELIM_TOKEN */ &&
2557
+ tokens[6].value === '/' &&
2558
+ isNumberToken(tokens[7])
2559
+ ? tokens[7].number
2560
+ : 1;
2561
+ if (c1 === null || c2 === null || c3 === null) {
2562
+ throw new Error("Invalid relative color in color() function");
2563
+ }
2564
+ return toColorPack([c1, c2, c3, a]);
2565
+ }
2566
+ };
2567
+ var SUPPORTED_COLOR_SPACES_ABSOLUTE = {
2568
+ srgb: packSrgb,
2569
+ 'srgb-linear': packSrgbLinear,
2570
+ 'display-p3': convertP3,
2571
+ 'a98-rgb': convertA98rgb,
2572
+ 'prophoto-rgb': convertProPhoto,
2573
+ xyz: convertXyz,
2574
+ 'xyz-d50': convertXyz50,
2575
+ 'xyz-d65': convertXyz,
2576
+ rec2020: convertRec2020
2577
+ };
2578
+ var SUPPORTED_COLOR_SPACES_TO_XYZ = {
2579
+ rgb: rgbToXyz,
2580
+ hsl: hslToXyz,
2581
+ lab: labToXyz,
2582
+ lch: lchToXyz,
2583
+ oklab: oklabToXyz,
2584
+ oklch: oklchToXyz
2585
+ };
2586
+ var SUPPORTED_COLOR_SPACES_FROM_XYZ = {
2587
+ srgb: srgbFromXYZ,
2588
+ 'srgb-linear': srgbLinearFromXYZ,
2589
+ 'display-p3': p3FromXYZ,
2590
+ 'a98-rgb': a98FromXYZ,
2591
+ 'prophoto-rgb': proPhotoFromXYZ,
2592
+ xyz: xyzFromXYZ,
2593
+ 'xyz-d50': xyz50FromXYZ,
2594
+ 'xyz-d65': xyzFromXYZ,
2595
+ rec2020: rec2020FromXYZ
1854
2596
  };
1855
2597
  var SUPPORTED_COLOR_FUNCTIONS = {
1856
- hsl: hsl,
1857
- hsla: hsl,
2598
+ hsl: packHSL,
2599
+ hsla: packHSL,
1858
2600
  rgb: rgb,
1859
2601
  rgba: rgb,
1860
- oklch: oklch
2602
+ lch: packLch,
2603
+ oklch: packOkLch,
2604
+ oklab: packOkLab,
2605
+ lab: packLab,
2606
+ color: _color
1861
2607
  };
1862
2608
  var parseColor = function (context, value) {
1863
2609
  return color$1.parse(context, Parser.create(value).parseComponentValue());