html2canvas-pro 2.4.4 → 2.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.
- package/README.md +115 -13
- package/dist/html2canvas-pro.cjs +3246 -1601
- package/dist/html2canvas-pro.cjs.map +1 -1
- package/dist/html2canvas-pro.esm.js +3246 -1601
- package/dist/html2canvas-pro.esm.js.map +1 -1
- package/dist/html2canvas-pro.js +3242 -1597
- package/dist/html2canvas-pro.js.map +1 -1
- package/dist/html2canvas-pro.min.js +5 -5
- package/dist/types/core/cache-storage.d.ts +4 -1
- package/dist/types/core/context.d.ts +10 -1
- package/dist/types/core/render-element.d.ts +11 -0
- package/dist/types/core/util.d.ts +6 -0
- package/dist/types/css/index.d.ts +77 -46
- package/dist/types/css/parse.d.ts +15 -0
- package/dist/types/css/property-descriptors/accent-color.d.ts +5 -0
- package/dist/types/css/property-descriptors/backdrop-filter.d.ts +9 -0
- package/dist/types/css/property-descriptors/background-blend-mode.d.ts +16 -16
- package/dist/types/css/property-descriptors/border-image-width.d.ts +36 -0
- package/dist/types/css/property-descriptors/clip-path.d.ts +16 -2
- package/dist/types/css/property-descriptors/isolation.d.ts +6 -0
- package/dist/types/css/property-descriptors/mask.d.ts +25 -0
- package/dist/types/css/property-descriptors/mix-blend-mode.d.ts +16 -16
- package/dist/types/css/property-descriptors/outline.d.ts +15 -0
- package/dist/types/css/property-descriptors/text-emphasis.d.ts +22 -0
- package/dist/types/css/property-descriptors/text-shadow.d.ts +1 -1
- package/dist/types/css/property-descriptors/webkit-box-reflect.d.ts +19 -0
- package/dist/types/css/property-descriptors/webkit-text-fill-color.d.ts +9 -0
- package/dist/types/css/syntax/token-constants.d.ts +1 -1
- package/dist/types/css/types/color-math.d.ts +7 -1
- package/dist/types/css/types/color-spaces/a98.d.ts +2 -1
- package/dist/types/css/types/color-spaces/p3.d.ts +5 -4
- package/dist/types/css/types/color-spaces/pro-photo.d.ts +5 -4
- package/dist/types/css/types/color-spaces/rec2020.d.ts +5 -4
- package/dist/types/css/types/color-spaces/srgb.d.ts +5 -4
- package/dist/types/css/types/color-utilities.d.ts +11 -11
- package/dist/types/css/types/color.d.ts +1 -0
- package/dist/types/css/types/functions/conic-gradient.d.ts +11 -0
- package/dist/types/css/types/functions/image-set.d.ts +11 -0
- package/dist/types/css/types/functions/repeating-radial-gradient.d.ts +8 -0
- package/dist/types/css/types/image.d.ts +15 -2
- package/dist/types/css/types/safe-eval.d.ts +0 -6
- package/dist/types/dom/copy-css-styles.d.ts +8 -0
- package/dist/types/dom/document-cloner.d.ts +3 -13
- package/dist/types/dom/iframe-mount.d.ts +37 -0
- package/dist/types/dom/pseudo-content.d.ts +33 -0
- package/dist/types/dom/replaced-elements/iframe-element-container.d.ts +2 -2
- package/dist/types/options.d.ts +8 -2
- package/dist/types/render/canvas/background-renderer.d.ts +19 -0
- package/dist/types/render/canvas/border-image-renderer.d.ts +50 -1
- package/dist/types/render/canvas/box-shadow-geometry.d.ts +3 -0
- package/dist/types/render/canvas/box-shadow-painter.d.ts +13 -0
- package/dist/types/render/canvas/box-shadow-transform.d.ts +16 -0
- package/dist/types/render/canvas/canvas-renderer.d.ts +21 -15
- package/dist/types/render/canvas/mask-renderer.d.ts +36 -0
- package/dist/types/render/canvas/text-clip-renderer.d.ts +36 -0
- package/dist/types/render/canvas/text-renderer.d.ts +22 -0
- package/dist/types/render/stacking-context.d.ts +4 -1
- package/package.json +39 -40
- package/dist/lib/config.js +0 -49
- package/dist/lib/core/abort-helper.js +0 -20
- package/dist/lib/core/background-parser.js +0 -41
- package/dist/lib/core/bitwise.js +0 -5
- package/dist/lib/core/cache-storage.js +0 -283
- package/dist/lib/core/config-assembler.js +0 -88
- package/dist/lib/core/constants.js +0 -25
- package/dist/lib/core/context.js +0 -19
- package/dist/lib/core/debugger.js +0 -27
- package/dist/lib/core/features.js +0 -190
- package/dist/lib/core/logger.js +0 -56
- package/dist/lib/core/lru-map.js +0 -66
- package/dist/lib/core/origin-checker.js +0 -53
- package/dist/lib/core/performance-monitor.js +0 -185
- package/dist/lib/core/render-element.js +0 -131
- package/dist/lib/core/util.js +0 -4
- package/dist/lib/core/validator.js +0 -500
- package/dist/lib/css/grouped/background-styles.js +0 -36
- package/dist/lib/css/grouped/border-styles.js +0 -75
- package/dist/lib/css/grouped/font-styles.js +0 -93
- package/dist/lib/css/grouped/layout-styles.js +0 -127
- package/dist/lib/css/index.js +0 -339
- package/dist/lib/css/layout/bounds.js +0 -52
- package/dist/lib/css/layout/text.js +0 -133
- package/dist/lib/css/property-descriptor.js +0 -2
- package/dist/lib/css/property-descriptors/background-blend-mode.js +0 -41
- package/dist/lib/css/property-descriptors/background-clip.js +0 -25
- package/dist/lib/css/property-descriptors/background-color.js +0 -10
- package/dist/lib/css/property-descriptors/background-image.js +0 -24
- package/dist/lib/css/property-descriptors/background-origin.js +0 -23
- package/dist/lib/css/property-descriptors/background-position.js +0 -19
- package/dist/lib/css/property-descriptors/background-repeat.js +0 -33
- package/dist/lib/css/property-descriptors/background-size.js +0 -23
- package/dist/lib/css/property-descriptors/border-color.js +0 -14
- package/dist/lib/css/property-descriptors/border-image-repeat.js +0 -42
- package/dist/lib/css/property-descriptors/border-image-slice.js +0 -45
- package/dist/lib/css/property-descriptors/border-image-source.js +0 -22
- package/dist/lib/css/property-descriptors/border-radius.js +0 -15
- package/dist/lib/css/property-descriptors/border-style.js +0 -26
- package/dist/lib/css/property-descriptors/border-width.js +0 -20
- package/dist/lib/css/property-descriptors/box-decoration-break.js +0 -18
- package/dist/lib/css/property-descriptors/box-shadow.js +0 -54
- package/dist/lib/css/property-descriptors/clip-path.js +0 -189
- package/dist/lib/css/property-descriptors/color.js +0 -10
- package/dist/lib/css/property-descriptors/content.js +0 -19
- package/dist/lib/css/property-descriptors/counter-increment.js +0 -35
- package/dist/lib/css/property-descriptors/counter-reset.js +0 -18
- package/dist/lib/css/property-descriptors/direction.js +0 -18
- package/dist/lib/css/property-descriptors/display.js +0 -81
- package/dist/lib/css/property-descriptors/duration.js +0 -14
- package/dist/lib/css/property-descriptors/filter.js +0 -86
- package/dist/lib/css/property-descriptors/float.js +0 -22
- package/dist/lib/css/property-descriptors/font-family.js +0 -47
- package/dist/lib/css/property-descriptors/font-size.js +0 -10
- package/dist/lib/css/property-descriptors/font-style.js +0 -20
- package/dist/lib/css/property-descriptors/font-variant-ligatures.js +0 -34
- package/dist/lib/css/property-descriptors/font-variant.js +0 -13
- package/dist/lib/css/property-descriptors/font-weight.js +0 -25
- package/dist/lib/css/property-descriptors/image-rendering.js +0 -33
- package/dist/lib/css/property-descriptors/letter-spacing.js +0 -21
- package/dist/lib/css/property-descriptors/line-break.js +0 -23
- package/dist/lib/css/property-descriptors/line-height.js +0 -24
- package/dist/lib/css/property-descriptors/list-style-image.js +0 -17
- package/dist/lib/css/property-descriptors/list-style-position.js +0 -18
- package/dist/lib/css/property-descriptors/list-style-type.js +0 -122
- package/dist/lib/css/property-descriptors/margin.js +0 -13
- package/dist/lib/css/property-descriptors/mix-blend-mode.js +0 -31
- package/dist/lib/css/property-descriptors/object-fit.js +0 -28
- package/dist/lib/css/property-descriptors/object-position.js +0 -42
- package/dist/lib/css/property-descriptors/opacity.js +0 -16
- package/dist/lib/css/property-descriptors/overflow-wrap.js +0 -18
- package/dist/lib/css/property-descriptors/overflow.js +0 -27
- package/dist/lib/css/property-descriptors/padding.js +0 -14
- package/dist/lib/css/property-descriptors/paint-order.js +0 -33
- package/dist/lib/css/property-descriptors/position.js +0 -22
- package/dist/lib/css/property-descriptors/quotes.js +0 -41
- package/dist/lib/css/property-descriptors/rotate.js +0 -27
- package/dist/lib/css/property-descriptors/text-align.js +0 -21
- package/dist/lib/css/property-descriptors/text-decoration-color.js +0 -10
- package/dist/lib/css/property-descriptors/text-decoration-line.js +0 -28
- package/dist/lib/css/property-descriptors/text-decoration-style.js +0 -24
- package/dist/lib/css/property-descriptors/text-decoration-thickness.js +0 -26
- package/dist/lib/css/property-descriptors/text-overflow.js +0 -18
- package/dist/lib/css/property-descriptors/text-shadow.js +0 -46
- package/dist/lib/css/property-descriptors/text-transform.js +0 -20
- package/dist/lib/css/property-descriptors/text-underline-offset.js +0 -23
- package/dist/lib/css/property-descriptors/transform-origin.js +0 -24
- package/dist/lib/css/property-descriptors/transform.js +0 -57
- package/dist/lib/css/property-descriptors/visibility.js +0 -20
- package/dist/lib/css/property-descriptors/webkit-line-clamp.js +0 -26
- package/dist/lib/css/property-descriptors/webkit-text-stroke-color.js +0 -10
- package/dist/lib/css/property-descriptors/webkit-text-stroke-width.js +0 -16
- package/dist/lib/css/property-descriptors/white-space.js +0 -32
- package/dist/lib/css/property-descriptors/word-break.js +0 -26
- package/dist/lib/css/property-descriptors/writing-mode.js +0 -28
- package/dist/lib/css/property-descriptors/z-index.js +0 -19
- package/dist/lib/css/property-descriptors/zoom.js +0 -18
- package/dist/lib/css/syntax/parser.js +0 -141
- package/dist/lib/css/syntax/token-constants.js +0 -214
- package/dist/lib/css/syntax/token-singletons.js +0 -36
- package/dist/lib/css/syntax/token-types.js +0 -10
- package/dist/lib/css/syntax/tokenizer.js +0 -502
- package/dist/lib/css/type-descriptor.js +0 -2
- package/dist/lib/css/types/angle.js +0 -80
- package/dist/lib/css/types/color-math.js +0 -25
- package/dist/lib/css/types/color-spaces/a98.js +0 -78
- package/dist/lib/css/types/color-spaces/p3.js +0 -86
- package/dist/lib/css/types/color-spaces/pro-photo.js +0 -83
- package/dist/lib/css/types/color-spaces/rec2020.js +0 -85
- package/dist/lib/css/types/color-spaces/srgb.js +0 -79
- package/dist/lib/css/types/color-utilities.js +0 -342
- package/dist/lib/css/types/color.js +0 -400
- package/dist/lib/css/types/functions/-prefix-linear-gradient.js +0 -32
- package/dist/lib/css/types/functions/-prefix-radial-gradient.js +0 -83
- package/dist/lib/css/types/functions/-webkit-gradient.js +0 -59
- package/dist/lib/css/types/functions/counter.js +0 -367
- package/dist/lib/css/types/functions/gradient.js +0 -163
- package/dist/lib/css/types/functions/linear-gradient.js +0 -27
- package/dist/lib/css/types/functions/radial-gradient.js +0 -90
- package/dist/lib/css/types/functions/repeating-linear-gradient.js +0 -9
- package/dist/lib/css/types/image.js +0 -62
- package/dist/lib/css/types/index.js +0 -2
- package/dist/lib/css/types/length-percentage.js +0 -197
- package/dist/lib/css/types/length.js +0 -5
- package/dist/lib/css/types/safe-eval.js +0 -80
- package/dist/lib/css/types/time.js +0 -17
- package/dist/lib/dom/document-cloner.js +0 -618
- package/dist/lib/dom/dom-normalizer.js +0 -115
- package/dist/lib/dom/element-container.js +0 -71
- package/dist/lib/dom/elements/li-element-container.js +0 -11
- package/dist/lib/dom/elements/ol-element-container.js +0 -12
- package/dist/lib/dom/elements/select-element-container.js +0 -12
- package/dist/lib/dom/elements/textarea-element-container.js +0 -11
- package/dist/lib/dom/node-parser.js +0 -125
- package/dist/lib/dom/node-type-guards.js +0 -81
- package/dist/lib/dom/replaced-elements/canvas-element-container.js +0 -13
- package/dist/lib/dom/replaced-elements/iframe-element-container.js +0 -38
- package/dist/lib/dom/replaced-elements/image-element-container.js +0 -14
- package/dist/lib/dom/replaced-elements/index.js +0 -2
- package/dist/lib/dom/replaced-elements/input-element-container.js +0 -89
- package/dist/lib/dom/replaced-elements/svg-element-container.js +0 -57
- package/dist/lib/dom/slot-cloner.js +0 -176
- package/dist/lib/dom/text-container.js +0 -35
- package/dist/lib/index.js +0 -49
- package/dist/lib/options.js +0 -2
- package/dist/lib/render/background.js +0 -188
- package/dist/lib/render/bezier-curve.js +0 -34
- package/dist/lib/render/border.js +0 -104
- package/dist/lib/render/bound-curves.js +0 -188
- package/dist/lib/render/box-sizing.js +0 -20
- package/dist/lib/render/canvas/background-renderer.js +0 -338
- package/dist/lib/render/canvas/border-image-renderer.js +0 -153
- package/dist/lib/render/canvas/border-renderer.js +0 -184
- package/dist/lib/render/canvas/canvas-path.js +0 -25
- package/dist/lib/render/canvas/canvas-renderer.js +0 -633
- package/dist/lib/render/canvas/content-renderer.js +0 -270
- package/dist/lib/render/canvas/effects-renderer.js +0 -171
- package/dist/lib/render/canvas/filter-surface.js +0 -270
- package/dist/lib/render/canvas/font-utils.js +0 -46
- package/dist/lib/render/canvas/foreignobject-renderer.js +0 -38
- package/dist/lib/render/canvas/surface-bounds.js +0 -64
- package/dist/lib/render/canvas/text/text-decoration-renderer.js +0 -99
- package/dist/lib/render/canvas/text-renderer.js +0 -486
- package/dist/lib/render/effects.js +0 -231
- package/dist/lib/render/font-metrics.js +0 -53
- package/dist/lib/render/object-fit.js +0 -91
- package/dist/lib/render/path.js +0 -26
- package/dist/lib/render/renderer-interface.js +0 -2
- package/dist/lib/render/stacking-context.js +0 -341
- package/dist/lib/render/vector.js +0 -16
|
@@ -1,342 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.convertXyz50 = exports.convertXyz = exports.xyz50FromXYZ = exports.xyzFromXYZ = exports.xyz50ToXYZ = exports.oklabToXyz = exports.oklchToXyz = exports.lchToXyz = exports.labToXyz = exports.hslToXyz = exports.rgbToXyz = exports.hue2rgb = exports.d50toD65 = exports.d65toD50 = exports.extractOkLchComponents = exports.extractLabComponents = exports.extractLchComponents = exports.packHSL = exports.extractHslComponents = exports.packLch = exports.packOkLch = exports.packOkLab = exports.packLab = exports.packXYZ = exports.packSrgbLinear = exports.packSrgb = exports.multiplyMatrices = exports.clamp = exports.isRelativeTransform = exports.getTokenColorValue = exports.pack = exports.asString = exports.isTransparent = void 0;
|
|
4
|
-
const parser_1 = require("../syntax/parser");
|
|
5
|
-
const srgb_1 = require("./color-spaces/srgb");
|
|
6
|
-
const angle_1 = require("./angle");
|
|
7
|
-
const length_percentage_1 = require("./length-percentage");
|
|
8
|
-
const color_math_1 = require("./color-math");
|
|
9
|
-
Object.defineProperty(exports, "clamp", { enumerable: true, get: function () { return color_math_1.clamp; } });
|
|
10
|
-
Object.defineProperty(exports, "multiplyMatrices", { enumerable: true, get: function () { return color_math_1.multiplyMatrices; } });
|
|
11
|
-
const isTransparent = (color) => (0xff & color) === 0;
|
|
12
|
-
exports.isTransparent = isTransparent;
|
|
13
|
-
const asString = (color) => {
|
|
14
|
-
const alpha = 0xff & color;
|
|
15
|
-
const blue = 0xff & (color >> 8);
|
|
16
|
-
const green = 0xff & (color >> 16);
|
|
17
|
-
const red = 0xff & (color >> 24);
|
|
18
|
-
return alpha < 255 ? `rgba(${red},${green},${blue},${alpha / 255})` : `rgb(${red},${green},${blue})`;
|
|
19
|
-
};
|
|
20
|
-
exports.asString = asString;
|
|
21
|
-
const pack = (r, g, b, a) => ((r << 24) | (g << 16) | (b << 8) | (Math.round(a * 255) << 0)) >>> 0;
|
|
22
|
-
exports.pack = pack;
|
|
23
|
-
const getTokenColorValue = (token, i) => {
|
|
24
|
-
if (token.type === 17 /* TokenType.NUMBER_TOKEN */) {
|
|
25
|
-
return token.number;
|
|
26
|
-
}
|
|
27
|
-
if (token.type === 16 /* TokenType.PERCENTAGE_TOKEN */) {
|
|
28
|
-
const max = i === 3 ? 1 : 255;
|
|
29
|
-
return i === 3 ? (token.number / 100) * max : Math.round((token.number / 100) * max);
|
|
30
|
-
}
|
|
31
|
-
return 0;
|
|
32
|
-
};
|
|
33
|
-
exports.getTokenColorValue = getTokenColorValue;
|
|
34
|
-
const isRelativeTransform = (tokens) => (tokens[0].type === 20 /* TokenType.IDENT_TOKEN */ ? tokens[0].value : 'unknown') === 'from';
|
|
35
|
-
exports.isRelativeTransform = isRelativeTransform;
|
|
36
|
-
const packSrgb = (args) => {
|
|
37
|
-
return (0, exports.pack)((0, color_math_1.clamp)(Math.round(args[0] * 255), 0, 255), (0, color_math_1.clamp)(Math.round(args[1] * 255), 0, 255), (0, color_math_1.clamp)(Math.round(args[2] * 255), 0, 255), (0, color_math_1.clamp)(args[3], 0, 1));
|
|
38
|
-
};
|
|
39
|
-
exports.packSrgb = packSrgb;
|
|
40
|
-
const packSrgbLinear = ([r, g, b, a]) => {
|
|
41
|
-
const rgb = (0, srgb_1.srgbLinear2rgb)([r, g, b]);
|
|
42
|
-
return (0, exports.pack)((0, color_math_1.clamp)(Math.round(rgb[0] * 255), 0, 255), (0, color_math_1.clamp)(Math.round(rgb[1] * 255), 0, 255), (0, color_math_1.clamp)(Math.round(rgb[2] * 255), 0, 255), a);
|
|
43
|
-
};
|
|
44
|
-
exports.packSrgbLinear = packSrgbLinear;
|
|
45
|
-
const packXYZ = (args) => {
|
|
46
|
-
const srgb_linear = (0, srgb_1.xyz2rgbLinear)([args[0], args[1], args[2]]);
|
|
47
|
-
return (0, exports.packSrgbLinear)([srgb_linear[0], srgb_linear[1], srgb_linear[2], args[3]]);
|
|
48
|
-
};
|
|
49
|
-
exports.packXYZ = packXYZ;
|
|
50
|
-
const packLab = (_context, args) => {
|
|
51
|
-
if ((0, exports.isRelativeTransform)(args.filter(parser_1.nonFunctionArgSeparator))) {
|
|
52
|
-
throw new Error('Relative color not supported for lab()');
|
|
53
|
-
}
|
|
54
|
-
const [l, a, b, alpha] = (0, exports.extractLabComponents)(args), rgb = (0, srgb_1.srgbLinear2rgb)((0, srgb_1.xyz2rgbLinear)(lab2xyz([l, a, b])));
|
|
55
|
-
return (0, exports.pack)((0, color_math_1.clamp)(Math.round(rgb[0] * 255), 0, 255), (0, color_math_1.clamp)(Math.round(rgb[1] * 255), 0, 255), (0, color_math_1.clamp)(Math.round(rgb[2] * 255), 0, 255), alpha);
|
|
56
|
-
};
|
|
57
|
-
exports.packLab = packLab;
|
|
58
|
-
const packOkLab = (_context, args) => {
|
|
59
|
-
if ((0, exports.isRelativeTransform)(args.filter(parser_1.nonFunctionArgSeparator))) {
|
|
60
|
-
throw new Error('Relative color not supported for oklab()');
|
|
61
|
-
}
|
|
62
|
-
const [l, a, b, alpha] = (0, exports.extractLabComponents)(args), rgb = (0, srgb_1.srgbLinear2rgb)((0, srgb_1.xyz2rgbLinear)(oklab2xyz([l, a, b])));
|
|
63
|
-
return (0, exports.pack)((0, color_math_1.clamp)(Math.round(rgb[0] * 255), 0, 255), (0, color_math_1.clamp)(Math.round(rgb[1] * 255), 0, 255), (0, color_math_1.clamp)(Math.round(rgb[2] * 255), 0, 255), alpha);
|
|
64
|
-
};
|
|
65
|
-
exports.packOkLab = packOkLab;
|
|
66
|
-
const packOkLch = (_context, args) => {
|
|
67
|
-
if ((0, exports.isRelativeTransform)(args.filter(parser_1.nonFunctionArgSeparator))) {
|
|
68
|
-
throw new Error('Relative color not supported for oklch()');
|
|
69
|
-
}
|
|
70
|
-
const [l, c, h, alpha] = (0, exports.extractOkLchComponents)(args), rgb = (0, srgb_1.srgbLinear2rgb)((0, srgb_1.xyz2rgbLinear)(oklab2xyz(lch2lab([l, c, h]))));
|
|
71
|
-
return (0, exports.pack)((0, color_math_1.clamp)(Math.round(rgb[0] * 255), 0, 255), (0, color_math_1.clamp)(Math.round(rgb[1] * 255), 0, 255), (0, color_math_1.clamp)(Math.round(rgb[2] * 255), 0, 255), alpha);
|
|
72
|
-
};
|
|
73
|
-
exports.packOkLch = packOkLch;
|
|
74
|
-
const packLch = (_context, args) => {
|
|
75
|
-
if ((0, exports.isRelativeTransform)(args.filter(parser_1.nonFunctionArgSeparator))) {
|
|
76
|
-
throw new Error('Relative color not supported for lch()');
|
|
77
|
-
}
|
|
78
|
-
const [l, c, h, a] = (0, exports.extractLchComponents)(args), rgb = (0, srgb_1.srgbLinear2rgb)((0, srgb_1.xyz2rgbLinear)(lab2xyz(lch2lab([l, c, h]))));
|
|
79
|
-
return (0, exports.pack)((0, color_math_1.clamp)(Math.round(rgb[0] * 255), 0, 255), (0, color_math_1.clamp)(Math.round(rgb[1] * 255), 0, 255), (0, color_math_1.clamp)(Math.round(rgb[2] * 255), 0, 255), a);
|
|
80
|
-
};
|
|
81
|
-
exports.packLch = packLch;
|
|
82
|
-
const extractHslComponents = (context, args) => {
|
|
83
|
-
const tokens = args.filter(parser_1.nonFunctionArgSeparator), [hue, saturation, lightness, alpha] = tokens, h = (hue.type === 17 /* TokenType.NUMBER_TOKEN */ ? (0, angle_1.deg)(hue.number) : angle_1.angle.parse(context, hue)) / (Math.PI * 2), s = (0, length_percentage_1.isLengthPercentage)(saturation) ? saturation.number / 100 : 0, l = (0, length_percentage_1.isLengthPercentage)(lightness) ? lightness.number / 100 : 0, a = typeof alpha !== 'undefined' && (0, length_percentage_1.isLengthPercentage)(alpha) ? (0, length_percentage_1.getAbsoluteValue)(alpha, 1) : 1;
|
|
84
|
-
return [h, s, l, a];
|
|
85
|
-
};
|
|
86
|
-
exports.extractHslComponents = extractHslComponents;
|
|
87
|
-
const packHSL = (context, args) => {
|
|
88
|
-
if ((0, exports.isRelativeTransform)(args)) {
|
|
89
|
-
throw new Error('Relative color not supported for hsl()');
|
|
90
|
-
}
|
|
91
|
-
const [h, s, l, a] = (0, exports.extractHslComponents)(context, args), rgb = hsl2rgb([h, s, l]);
|
|
92
|
-
return (0, exports.pack)(rgb[0] * 255, rgb[1] * 255, rgb[2] * 255, s === 0 ? 1 : a);
|
|
93
|
-
};
|
|
94
|
-
exports.packHSL = packHSL;
|
|
95
|
-
const extractLchComponents = (args) => {
|
|
96
|
-
const tokens = args.filter(parser_1.nonFunctionArgSeparator), l = (0, length_percentage_1.isLengthPercentage)(tokens[0]) ? tokens[0].number : 0, c = (0, length_percentage_1.isLengthPercentage)(tokens[1]) ? tokens[1].number : 0, h = (0, parser_1.isNumberToken)(tokens[2]) || (0, parser_1.isDimensionToken)(tokens[2]) ? tokens[2].number : 0, a = typeof tokens[4] !== 'undefined' && (0, length_percentage_1.isLengthPercentage)(tokens[4]) ? (0, length_percentage_1.getAbsoluteValue)(tokens[4], 1) : 1;
|
|
97
|
-
return [l, c, h, a];
|
|
98
|
-
};
|
|
99
|
-
exports.extractLchComponents = extractLchComponents;
|
|
100
|
-
const extractLabComponents = (args) => {
|
|
101
|
-
const tokens = args.filter(parser_1.nonFunctionArgSeparator), l = tokens[0].type === 16 /* TokenType.PERCENTAGE_TOKEN */
|
|
102
|
-
? tokens[0].number / 100
|
|
103
|
-
: (0, parser_1.isNumberToken)(tokens[0])
|
|
104
|
-
? tokens[0].number
|
|
105
|
-
: 0, a = tokens[1].type === 16 /* TokenType.PERCENTAGE_TOKEN */
|
|
106
|
-
? tokens[1].number / 100
|
|
107
|
-
: (0, parser_1.isNumberToken)(tokens[1])
|
|
108
|
-
? tokens[1].number
|
|
109
|
-
: 0, b = (0, parser_1.isNumberToken)(tokens[2]) || (0, parser_1.isDimensionToken)(tokens[2]) ? tokens[2].number : 0, alpha = typeof tokens[4] !== 'undefined' && (0, length_percentage_1.isLengthPercentage)(tokens[4]) ? (0, length_percentage_1.getAbsoluteValue)(tokens[4], 1) : 1;
|
|
110
|
-
return [l, a, b, alpha];
|
|
111
|
-
};
|
|
112
|
-
exports.extractLabComponents = extractLabComponents;
|
|
113
|
-
const extractOkLchComponents = (args) => {
|
|
114
|
-
const tokens = args.filter(parser_1.nonFunctionArgSeparator), l = tokens[0].type === 16 /* TokenType.PERCENTAGE_TOKEN */
|
|
115
|
-
? tokens[0].number / 100
|
|
116
|
-
: (0, parser_1.isNumberToken)(tokens[0])
|
|
117
|
-
? tokens[0].number
|
|
118
|
-
: 0, c = tokens[1].type === 16 /* TokenType.PERCENTAGE_TOKEN */
|
|
119
|
-
? tokens[1].number / 100
|
|
120
|
-
: (0, parser_1.isNumberToken)(tokens[1])
|
|
121
|
-
? tokens[1].number
|
|
122
|
-
: 0, h = (0, parser_1.isNumberToken)(tokens[2]) || (0, parser_1.isDimensionToken)(tokens[2]) ? tokens[2].number : 0, a = typeof tokens[4] !== 'undefined' && (0, length_percentage_1.isLengthPercentage)(tokens[4]) ? (0, length_percentage_1.getAbsoluteValue)(tokens[4], 1) : 1;
|
|
123
|
-
return [l, c, h, a];
|
|
124
|
-
};
|
|
125
|
-
exports.extractOkLchComponents = extractOkLchComponents;
|
|
126
|
-
/**
|
|
127
|
-
* Convert D65 to D50
|
|
128
|
-
*
|
|
129
|
-
* @param xyz
|
|
130
|
-
*/
|
|
131
|
-
const d65toD50 = (xyz) => {
|
|
132
|
-
return (0, color_math_1.multiplyMatrices)([
|
|
133
|
-
1.0479297925449969, 0.022946870601609652, -0.05019226628920524, 0.02962780877005599, 0.9904344267538799,
|
|
134
|
-
-0.017073799063418826, -0.009243040646204504, 0.015055191490298152, 0.7518742814281371
|
|
135
|
-
], xyz);
|
|
136
|
-
};
|
|
137
|
-
exports.d65toD50 = d65toD50;
|
|
138
|
-
/**
|
|
139
|
-
* Convert D50 to D65
|
|
140
|
-
*
|
|
141
|
-
* @param xyz
|
|
142
|
-
*/
|
|
143
|
-
const d50toD65 = (xyz) => {
|
|
144
|
-
return (0, color_math_1.multiplyMatrices)([
|
|
145
|
-
0.955473421488075, -0.02309845494876471, 0.06325924320057072, -0.0283697093338637, 1.0099953980813041,
|
|
146
|
-
0.021041441191917323, 0.012314014864481998, -0.020507649298898964, 1.330365926242124
|
|
147
|
-
], xyz);
|
|
148
|
-
};
|
|
149
|
-
exports.d50toD65 = d50toD65;
|
|
150
|
-
const hue2rgb = (t1, t2, hue) => {
|
|
151
|
-
if (hue < 0) {
|
|
152
|
-
hue += 1;
|
|
153
|
-
}
|
|
154
|
-
if (hue >= 1) {
|
|
155
|
-
hue -= 1;
|
|
156
|
-
}
|
|
157
|
-
if (hue < 1 / 6) {
|
|
158
|
-
return (t2 - t1) * hue * 6 + t1;
|
|
159
|
-
}
|
|
160
|
-
else if (hue < 1 / 2) {
|
|
161
|
-
return t2;
|
|
162
|
-
}
|
|
163
|
-
else if (hue < 2 / 3) {
|
|
164
|
-
return (t2 - t1) * 6 * (2 / 3 - hue) + t1;
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
return t1;
|
|
168
|
-
}
|
|
169
|
-
};
|
|
170
|
-
exports.hue2rgb = hue2rgb;
|
|
171
|
-
const hsl2rgb = ([h, s, l]) => {
|
|
172
|
-
if (s === 0) {
|
|
173
|
-
return [l * 255, l * 255, l * 255];
|
|
174
|
-
}
|
|
175
|
-
const t2 = l <= 0.5 ? l * (s + 1) : l + s - l * s, t1 = l * 2 - t2, r = (0, exports.hue2rgb)(t1, t2, h + 1 / 3), g = (0, exports.hue2rgb)(t1, t2, h), b = (0, exports.hue2rgb)(t1, t2, h - 1 / 3);
|
|
176
|
-
return [r, g, b];
|
|
177
|
-
};
|
|
178
|
-
/**
|
|
179
|
-
* Convert lch to OKLab
|
|
180
|
-
*
|
|
181
|
-
* @param l
|
|
182
|
-
* @param c
|
|
183
|
-
* @param h
|
|
184
|
-
*/
|
|
185
|
-
const lch2lab = ([l, c, h]) => {
|
|
186
|
-
if (c < 0) {
|
|
187
|
-
c = 0;
|
|
188
|
-
}
|
|
189
|
-
if (isNaN(h)) {
|
|
190
|
-
h = 0;
|
|
191
|
-
}
|
|
192
|
-
return [l, c * Math.cos((h * Math.PI) / 180), c * Math.sin((h * Math.PI) / 180)];
|
|
193
|
-
};
|
|
194
|
-
/**
|
|
195
|
-
* Convert OKLab to XYZ relative to D65
|
|
196
|
-
*
|
|
197
|
-
* @param lab
|
|
198
|
-
*/
|
|
199
|
-
const oklab2xyz = (lab) => {
|
|
200
|
-
const LMSg = (0, color_math_1.multiplyMatrices)([
|
|
201
|
-
1, 0.3963377773761749, 0.2158037573099136, 1, -0.1055613458156586, -0.0638541728258133, 1,
|
|
202
|
-
-0.0894841775298119, -1.2914855480194092
|
|
203
|
-
], lab), LMS = LMSg.map((val) => val ** 3);
|
|
204
|
-
return (0, color_math_1.multiplyMatrices)([
|
|
205
|
-
1.2268798758459243, -0.5578149944602171, 0.2813910456659647, -0.0405757452148008, 1.112286803280317,
|
|
206
|
-
-0.0717110580655164, -0.0763729366746601, -0.4214933324022432, 1.5869240198367816
|
|
207
|
-
], LMS);
|
|
208
|
-
};
|
|
209
|
-
/**
|
|
210
|
-
* Convert Lab to D50-adapted XYZ
|
|
211
|
-
*
|
|
212
|
-
* @param lab
|
|
213
|
-
*/
|
|
214
|
-
const lab2xyz = (lab) => {
|
|
215
|
-
const fy = (lab[0] + 16) / 116, fx = lab[1] / 500 + fy, fz = fy - lab[2] / 200, k = 24389 / 27, e = 24 / 116, xyz = [
|
|
216
|
-
((fx > e ? fx ** 3 : (116 * fx - 16) / k) * 0.3457) / 0.3585,
|
|
217
|
-
lab[0] > 8 ? fy ** 3 : lab[0] / k,
|
|
218
|
-
((fz > e ? fz ** 3 : (116 * fz - 16) / k) * (1.0 - 0.3457 - 0.3585)) / 0.3585
|
|
219
|
-
];
|
|
220
|
-
return (0, exports.d50toD65)([xyz[0], xyz[1], xyz[2]]);
|
|
221
|
-
};
|
|
222
|
-
/**
|
|
223
|
-
* Convert RGB to XYZ
|
|
224
|
-
*
|
|
225
|
-
* @param _context
|
|
226
|
-
* @param args
|
|
227
|
-
*/
|
|
228
|
-
const rgbToXyz = (_context, args) => {
|
|
229
|
-
const tokens = args.filter(parser_1.nonFunctionArgSeparator);
|
|
230
|
-
if (tokens.length === 3) {
|
|
231
|
-
const [r, g, b] = tokens.map(exports.getTokenColorValue), rgb_linear = (0, srgb_1.rgb2rgbLinear)([r / 255, g / 255, b / 255]), [x, y, z] = (0, srgb_1.rgbLinear2xyz)([rgb_linear[0], rgb_linear[1], rgb_linear[2]]);
|
|
232
|
-
return [x, y, z, 1];
|
|
233
|
-
}
|
|
234
|
-
if (tokens.length === 4) {
|
|
235
|
-
const [r, g, b, a] = tokens.map(exports.getTokenColorValue), rgb_linear = (0, srgb_1.rgb2rgbLinear)([r / 255, g / 255, b / 255]), [x, y, z] = (0, srgb_1.rgbLinear2xyz)([rgb_linear[0], rgb_linear[1], rgb_linear[2]]);
|
|
236
|
-
return [x, y, z, a];
|
|
237
|
-
}
|
|
238
|
-
return [0, 0, 0, 1];
|
|
239
|
-
};
|
|
240
|
-
exports.rgbToXyz = rgbToXyz;
|
|
241
|
-
/**
|
|
242
|
-
* HSL to XYZ
|
|
243
|
-
*
|
|
244
|
-
* @param context
|
|
245
|
-
* @param args
|
|
246
|
-
*/
|
|
247
|
-
const hslToXyz = (context, args) => {
|
|
248
|
-
const [h, s, l, a] = (0, exports.extractHslComponents)(context, args), rgb_linear = (0, srgb_1.rgb2rgbLinear)(hsl2rgb([h, s, l])), [x, y, z] = (0, srgb_1.rgbLinear2xyz)([rgb_linear[0], rgb_linear[1], rgb_linear[2]]);
|
|
249
|
-
return [x, y, z, a];
|
|
250
|
-
};
|
|
251
|
-
exports.hslToXyz = hslToXyz;
|
|
252
|
-
/**
|
|
253
|
-
* LAB to XYZ
|
|
254
|
-
*
|
|
255
|
-
* @param _context
|
|
256
|
-
* @param args
|
|
257
|
-
*/
|
|
258
|
-
const labToXyz = (_context, args) => {
|
|
259
|
-
const [l, a, b, alpha] = (0, exports.extractLabComponents)(args), [x, y, z] = lab2xyz([l, a, b]);
|
|
260
|
-
return [x, y, z, alpha];
|
|
261
|
-
};
|
|
262
|
-
exports.labToXyz = labToXyz;
|
|
263
|
-
/**
|
|
264
|
-
* LCH to XYZ
|
|
265
|
-
*
|
|
266
|
-
* @param _context
|
|
267
|
-
* @param args
|
|
268
|
-
*/
|
|
269
|
-
const lchToXyz = (_context, args) => {
|
|
270
|
-
const [l, c, h, alpha] = (0, exports.extractLchComponents)(args), [x, y, z] = lab2xyz(lch2lab([l, c, h]));
|
|
271
|
-
return [x, y, z, alpha];
|
|
272
|
-
};
|
|
273
|
-
exports.lchToXyz = lchToXyz;
|
|
274
|
-
/**
|
|
275
|
-
* OKLch to XYZ
|
|
276
|
-
*
|
|
277
|
-
* @param _context
|
|
278
|
-
* @param args
|
|
279
|
-
*/
|
|
280
|
-
const oklchToXyz = (_context, args) => {
|
|
281
|
-
const [l, c, h, alpha] = (0, exports.extractOkLchComponents)(args), [x, y, z] = oklab2xyz(lch2lab([l, c, h]));
|
|
282
|
-
return [x, y, z, alpha];
|
|
283
|
-
};
|
|
284
|
-
exports.oklchToXyz = oklchToXyz;
|
|
285
|
-
/**
|
|
286
|
-
* OKLab to XYZ
|
|
287
|
-
*
|
|
288
|
-
* @param _context
|
|
289
|
-
* @param args
|
|
290
|
-
*/
|
|
291
|
-
const oklabToXyz = (_context, args) => {
|
|
292
|
-
const [l, c, h, alpha] = (0, exports.extractLabComponents)(args), [x, y, z] = oklab2xyz([l, c, h]);
|
|
293
|
-
return [x, y, z, alpha];
|
|
294
|
-
};
|
|
295
|
-
exports.oklabToXyz = oklabToXyz;
|
|
296
|
-
/**
|
|
297
|
-
* XYZ-50 to XYZ
|
|
298
|
-
*
|
|
299
|
-
* @param args
|
|
300
|
-
*/
|
|
301
|
-
const xyz50ToXYZ = (args) => {
|
|
302
|
-
return (0, exports.d50toD65)([args[0], args[1], args[2]]);
|
|
303
|
-
};
|
|
304
|
-
exports.xyz50ToXYZ = xyz50ToXYZ;
|
|
305
|
-
/**
|
|
306
|
-
* Does nothing, required for SUPPORTED_COLOR_SPACES_FROM_XYZ in the _color() function
|
|
307
|
-
*
|
|
308
|
-
* @param args
|
|
309
|
-
*/
|
|
310
|
-
const xyzFromXYZ = (args) => {
|
|
311
|
-
return args;
|
|
312
|
-
};
|
|
313
|
-
exports.xyzFromXYZ = xyzFromXYZ;
|
|
314
|
-
/**
|
|
315
|
-
* XYZ-65 to XYZ-50
|
|
316
|
-
*
|
|
317
|
-
* @param args
|
|
318
|
-
*/
|
|
319
|
-
const xyz50FromXYZ = (args) => {
|
|
320
|
-
const [x, y, z] = (0, exports.d65toD50)([args[0], args[2], args[3]]);
|
|
321
|
-
return [x, y, z, args[3]];
|
|
322
|
-
};
|
|
323
|
-
exports.xyz50FromXYZ = xyz50FromXYZ;
|
|
324
|
-
/**
|
|
325
|
-
* Convert XYZ to SRGB and Pack
|
|
326
|
-
*
|
|
327
|
-
* @param args
|
|
328
|
-
*/
|
|
329
|
-
const convertXyz = (args) => {
|
|
330
|
-
return (0, exports.packXYZ)([args[0], args[1], args[2], args[3]]);
|
|
331
|
-
};
|
|
332
|
-
exports.convertXyz = convertXyz;
|
|
333
|
-
/**
|
|
334
|
-
* Convert XYZ-50 to SRGB and Pack
|
|
335
|
-
*
|
|
336
|
-
* @param args
|
|
337
|
-
*/
|
|
338
|
-
const convertXyz50 = (args) => {
|
|
339
|
-
const xyz = (0, exports.xyz50ToXYZ)([args[0], args[1], args[2]]);
|
|
340
|
-
return (0, exports.packXYZ)([xyz[0], xyz[1], xyz[2], args[3]]);
|
|
341
|
-
};
|
|
342
|
-
exports.convertXyz50 = convertXyz50;
|