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