html2canvas-pro 2.4.5 → 2.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/README.md +117 -13
- package/dist/html2canvas-pro.cjs +3425 -1677
- package/dist/html2canvas-pro.cjs.map +1 -1
- package/dist/html2canvas-pro.esm.js +3425 -1677
- package/dist/html2canvas-pro.esm.js.map +1 -1
- package/dist/html2canvas-pro.js +3479 -1731
- package/dist/html2canvas-pro.js.map +1 -1
- package/dist/html2canvas-pro.min.js +5 -5
- package/dist/types/core/cache-storage.d.ts +22 -1
- package/dist/types/core/context.d.ts +10 -1
- package/dist/types/core/logger.d.ts +0 -3
- 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 +17 -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 +17 -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/dom/replaced-elements/input-element-container.d.ts +1 -1
- package/dist/types/options.d.ts +8 -2
- package/dist/types/render/canvas/background-renderer.d.ts +28 -0
- package/dist/types/render/canvas/border-image-renderer.d.ts +50 -1
- package/dist/types/render/canvas/canvas-renderer.d.ts +29 -15
- package/dist/types/render/canvas/effects-renderer.d.ts +8 -0
- package/dist/types/render/canvas/mask-renderer.d.ts +36 -0
- package/dist/types/render/canvas/text-clip-renderer.d.ts +56 -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 +41 -42
- 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/box-shadow-geometry.js +0 -52
- package/dist/lib/render/canvas/box-shadow-painter.js +0 -194
- package/dist/lib/render/canvas/box-shadow-transform.js +0 -42
- package/dist/lib/render/canvas/canvas-path.js +0 -25
- package/dist/lib/render/canvas/canvas-renderer.js +0 -610
- 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,62 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.image = exports.isRepeatingLinearGradient = exports.isRadialGradient = exports.isLinearGradient = void 0;
|
|
4
|
-
exports.isSupportedImage = isSupportedImage;
|
|
5
|
-
const linear_gradient_1 = require("./functions/linear-gradient");
|
|
6
|
-
const _prefix_linear_gradient_1 = require("./functions/-prefix-linear-gradient");
|
|
7
|
-
const _webkit_gradient_1 = require("./functions/-webkit-gradient");
|
|
8
|
-
const radial_gradient_1 = require("./functions/radial-gradient");
|
|
9
|
-
const _prefix_radial_gradient_1 = require("./functions/-prefix-radial-gradient");
|
|
10
|
-
const repeating_linear_gradient_1 = require("./functions/repeating-linear-gradient");
|
|
11
|
-
const isLinearGradient = (background) => {
|
|
12
|
-
return background.type === 1 /* CSSImageType.LINEAR_GRADIENT */;
|
|
13
|
-
};
|
|
14
|
-
exports.isLinearGradient = isLinearGradient;
|
|
15
|
-
const isRadialGradient = (background) => {
|
|
16
|
-
return background.type === 2 /* CSSImageType.RADIAL_GRADIENT */;
|
|
17
|
-
};
|
|
18
|
-
exports.isRadialGradient = isRadialGradient;
|
|
19
|
-
const isRepeatingLinearGradient = (background) => {
|
|
20
|
-
return background.type === 3 /* CSSImageType.REPEATING_LINEAR_GRADIENT */;
|
|
21
|
-
};
|
|
22
|
-
exports.isRepeatingLinearGradient = isRepeatingLinearGradient;
|
|
23
|
-
exports.image = {
|
|
24
|
-
name: 'image',
|
|
25
|
-
parse: (context, value) => {
|
|
26
|
-
if (value.type === 22 /* TokenType.URL_TOKEN */) {
|
|
27
|
-
const image = { url: value.value, type: 0 /* CSSImageType.URL */ };
|
|
28
|
-
context.cache.addImage(value.value);
|
|
29
|
-
return image;
|
|
30
|
-
}
|
|
31
|
-
if (value.type === 18 /* TokenType.FUNCTION */) {
|
|
32
|
-
const imageFunction = SUPPORTED_IMAGE_FUNCTIONS[value.name];
|
|
33
|
-
if (typeof imageFunction === 'undefined') {
|
|
34
|
-
throw new Error(`Attempting to parse an unsupported image function "${value.name}"`);
|
|
35
|
-
}
|
|
36
|
-
return imageFunction(context, value.values);
|
|
37
|
-
}
|
|
38
|
-
throw new Error(`Unsupported image type ${value.type}`);
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
function isSupportedImage(value) {
|
|
42
|
-
return (!(value.type === 20 /* TokenType.IDENT_TOKEN */ && value.value === 'none') &&
|
|
43
|
-
(value.type !== 18 /* TokenType.FUNCTION */ || !!SUPPORTED_IMAGE_FUNCTIONS[value.name]));
|
|
44
|
-
}
|
|
45
|
-
const SUPPORTED_IMAGE_FUNCTIONS = {
|
|
46
|
-
'linear-gradient': linear_gradient_1.linearGradient,
|
|
47
|
-
'-moz-linear-gradient': _prefix_linear_gradient_1.prefixLinearGradient,
|
|
48
|
-
'-ms-linear-gradient': _prefix_linear_gradient_1.prefixLinearGradient,
|
|
49
|
-
'-o-linear-gradient': _prefix_linear_gradient_1.prefixLinearGradient,
|
|
50
|
-
'-webkit-linear-gradient': _prefix_linear_gradient_1.prefixLinearGradient,
|
|
51
|
-
'radial-gradient': radial_gradient_1.radialGradient,
|
|
52
|
-
'-moz-radial-gradient': _prefix_radial_gradient_1.prefixRadialGradient,
|
|
53
|
-
'-ms-radial-gradient': _prefix_radial_gradient_1.prefixRadialGradient,
|
|
54
|
-
'-o-radial-gradient': _prefix_radial_gradient_1.prefixRadialGradient,
|
|
55
|
-
'-webkit-radial-gradient': _prefix_radial_gradient_1.prefixRadialGradient,
|
|
56
|
-
'-webkit-gradient': _webkit_gradient_1.webkitGradient,
|
|
57
|
-
'repeating-linear-gradient': repeating_linear_gradient_1.repeatingLinearGradient,
|
|
58
|
-
'-webkit-repeating-linear-gradient': repeating_linear_gradient_1.repeatingLinearGradient,
|
|
59
|
-
'-moz-repeating-linear-gradient': repeating_linear_gradient_1.repeatingLinearGradient,
|
|
60
|
-
'-ms-repeating-linear-gradient': repeating_linear_gradient_1.repeatingLinearGradient,
|
|
61
|
-
'-o-repeating-linear-gradient': repeating_linear_gradient_1.repeatingLinearGradient
|
|
62
|
-
};
|
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getAbsoluteValue = exports.getAbsoluteValueForTuple = exports.HUNDRED_PERCENT = exports.FIFTY_PERCENT = exports.ZERO_LENGTH = exports.parseLengthPercentageTuple = exports.evaluateCalcToLengthPercentage = exports.parseOptionalCalcOrLength = exports.parseCalcForLengthPercentage = exports.isCalcFunction = exports.isCalcWithPercentage = exports.isLengthPercentage = void 0;
|
|
7
|
-
const tokenizer_1 = require("../syntax/tokenizer");
|
|
8
|
-
const parser_1 = require("../syntax/parser");
|
|
9
|
-
const length_1 = require("./length");
|
|
10
|
-
const safe_eval_1 = __importDefault(require("./safe-eval"));
|
|
11
|
-
const isLengthPercentage = (token) => token.type === 16 /* TokenType.PERCENTAGE_TOKEN */ || (0, length_1.isLength)(token) || (0, exports.isCalcWithPercentage)(token);
|
|
12
|
-
exports.isLengthPercentage = isLengthPercentage;
|
|
13
|
-
/**
|
|
14
|
-
* Check if a token is a CalcWithPercentage deferred token.
|
|
15
|
-
* Accepts CSSValue (structural duck-type check) for use in type guards.
|
|
16
|
-
*/
|
|
17
|
-
const isCalcWithPercentage = (token) => token.type === 17 /* TokenType.NUMBER_TOKEN */ && token._calcPercentage !== undefined;
|
|
18
|
-
exports.isCalcWithPercentage = isCalcWithPercentage;
|
|
19
|
-
/**
|
|
20
|
-
* Check if a token is a calc() function
|
|
21
|
-
*/
|
|
22
|
-
const isCalcFunction = (token) => token.type === 18 /* TokenType.FUNCTION */ && token.name === 'calc';
|
|
23
|
-
exports.isCalcFunction = isCalcFunction;
|
|
24
|
-
/**
|
|
25
|
-
* Parse a calc() token and produce a LengthPercentage.
|
|
26
|
-
*
|
|
27
|
-
* Uses two-point evaluation to extract the percentage coefficient and pixel
|
|
28
|
-
* offset from a calc() expression so it can be resolved later at render time
|
|
29
|
-
* when the container size is known.
|
|
30
|
-
*
|
|
31
|
-
* evaluate(0) → pixelOffset
|
|
32
|
-
* evaluate(100) → percentage + pixelOffset → percentage = evaluate(100) - pixelOffset
|
|
33
|
-
*
|
|
34
|
-
* If the expression has no percentage component, returns a plain NUMBER_TOKEN
|
|
35
|
-
* for backwards compatibility.
|
|
36
|
-
*/
|
|
37
|
-
const parseCalcForLengthPercentage = (calcToken) => {
|
|
38
|
-
const withZero = (0, exports.evaluateCalcToLengthPercentage)(calcToken, 0);
|
|
39
|
-
if (!withZero)
|
|
40
|
-
return null;
|
|
41
|
-
const withHundred = (0, exports.evaluateCalcToLengthPercentage)(calcToken, 100);
|
|
42
|
-
if (!withHundred)
|
|
43
|
-
return null;
|
|
44
|
-
const pixelOffset = withZero.number;
|
|
45
|
-
const percentage = withHundred.number - pixelOffset;
|
|
46
|
-
// If there's no percentage component, return a plain NUMBER_TOKEN
|
|
47
|
-
if (percentage === 0) {
|
|
48
|
-
return withZero;
|
|
49
|
-
}
|
|
50
|
-
return {
|
|
51
|
-
type: 17 /* TokenType.NUMBER_TOKEN */,
|
|
52
|
-
number: pixelOffset,
|
|
53
|
-
flags: tokenizer_1.FLAG_INTEGER,
|
|
54
|
-
_calcPercentage: percentage,
|
|
55
|
-
_calcPixelOffset: pixelOffset
|
|
56
|
-
};
|
|
57
|
-
};
|
|
58
|
-
exports.parseCalcForLengthPercentage = parseCalcForLengthPercentage;
|
|
59
|
-
/**
|
|
60
|
-
* Convenience helper for parsing an optional calc() or length-percentage value.
|
|
61
|
-
* Used by property descriptors that accept both calc() and regular length-percentage tokens.
|
|
62
|
-
* Returns null if the value is neither a calc() function nor a length-percentage token.
|
|
63
|
-
*/
|
|
64
|
-
const parseOptionalCalcOrLength = (value) => {
|
|
65
|
-
if ((0, exports.isCalcFunction)(value)) {
|
|
66
|
-
return (0, exports.parseCalcForLengthPercentage)(value);
|
|
67
|
-
}
|
|
68
|
-
return (0, exports.isLengthPercentage)(value) ? value : null;
|
|
69
|
-
};
|
|
70
|
-
exports.parseOptionalCalcOrLength = parseOptionalCalcOrLength;
|
|
71
|
-
/**
|
|
72
|
-
* Evaluate a calc() expression and convert to LengthPercentage token
|
|
73
|
-
* Supports basic arithmetic: +, -, *, /
|
|
74
|
-
* Note: Percentages in calc() are converted based on a context value
|
|
75
|
-
*/
|
|
76
|
-
const evaluateCalcToLengthPercentage = (calcToken, contextValue = 0) => {
|
|
77
|
-
// Build expression string from tokens
|
|
78
|
-
const buildExpression = (values) => {
|
|
79
|
-
let expression = '';
|
|
80
|
-
for (const value of values) {
|
|
81
|
-
if (value.type === 31 /* TokenType.WHITESPACE_TOKEN */) {
|
|
82
|
-
continue;
|
|
83
|
-
}
|
|
84
|
-
if (value.type === 18 /* TokenType.FUNCTION */) {
|
|
85
|
-
if (value.name === 'calc') {
|
|
86
|
-
const nested = buildExpression(value.values);
|
|
87
|
-
if (nested === null)
|
|
88
|
-
return null;
|
|
89
|
-
expression += `(${nested})`;
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
return null;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
else if (value.type === 17 /* TokenType.NUMBER_TOKEN */) {
|
|
96
|
-
expression += value.number.toString();
|
|
97
|
-
}
|
|
98
|
-
else if (value.type === 15 /* TokenType.DIMENSION_TOKEN */) {
|
|
99
|
-
// Convert units to px
|
|
100
|
-
if (value.unit === 'px') {
|
|
101
|
-
expression += value.number.toString();
|
|
102
|
-
}
|
|
103
|
-
else if (value.unit === 'rem' || value.unit === 'em') {
|
|
104
|
-
expression += (value.number * 16).toString();
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
expression += value.number.toString();
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
else if (value.type === 16 /* TokenType.PERCENTAGE_TOKEN */) {
|
|
111
|
-
// Convert percentage to absolute value based on context
|
|
112
|
-
expression += ((value.number / 100) * contextValue).toString();
|
|
113
|
-
}
|
|
114
|
-
else if (value.type === 6 /* TokenType.DELIM_TOKEN */) {
|
|
115
|
-
const op = value.value;
|
|
116
|
-
if (op === '+' || op === '-' || op === '*' || op === '/') {
|
|
117
|
-
expression += ` ${op} `;
|
|
118
|
-
}
|
|
119
|
-
else if (op === '(') {
|
|
120
|
-
expression += '(';
|
|
121
|
-
}
|
|
122
|
-
else if (op === ')') {
|
|
123
|
-
expression += ')';
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
return expression;
|
|
128
|
-
};
|
|
129
|
-
try {
|
|
130
|
-
const expression = buildExpression(calcToken.values);
|
|
131
|
-
if (expression === null || expression.trim() === '') {
|
|
132
|
-
return null;
|
|
133
|
-
}
|
|
134
|
-
// Evaluate the expression
|
|
135
|
-
// Uses safe arithmetic evaluator instead of new Function() for CodeQL
|
|
136
|
-
const result = (0, safe_eval_1.default)(expression);
|
|
137
|
-
if (typeof result === 'number' && !isNaN(result)) {
|
|
138
|
-
// Return as a number token in px
|
|
139
|
-
return {
|
|
140
|
-
type: 17 /* TokenType.NUMBER_TOKEN */,
|
|
141
|
-
number: result,
|
|
142
|
-
flags: tokenizer_1.FLAG_INTEGER
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
catch (e) {
|
|
147
|
-
return null;
|
|
148
|
-
}
|
|
149
|
-
return null;
|
|
150
|
-
};
|
|
151
|
-
exports.evaluateCalcToLengthPercentage = evaluateCalcToLengthPercentage;
|
|
152
|
-
const parseLengthPercentageTuple = (tokens) => tokens.length > 1 ? [tokens[0], tokens[1]] : [tokens[0]];
|
|
153
|
-
exports.parseLengthPercentageTuple = parseLengthPercentageTuple;
|
|
154
|
-
exports.ZERO_LENGTH = {
|
|
155
|
-
type: 17 /* TokenType.NUMBER_TOKEN */,
|
|
156
|
-
number: 0,
|
|
157
|
-
flags: tokenizer_1.FLAG_INTEGER
|
|
158
|
-
};
|
|
159
|
-
exports.FIFTY_PERCENT = {
|
|
160
|
-
type: 16 /* TokenType.PERCENTAGE_TOKEN */,
|
|
161
|
-
number: 50,
|
|
162
|
-
flags: tokenizer_1.FLAG_INTEGER
|
|
163
|
-
};
|
|
164
|
-
exports.HUNDRED_PERCENT = {
|
|
165
|
-
type: 16 /* TokenType.PERCENTAGE_TOKEN */,
|
|
166
|
-
number: 100,
|
|
167
|
-
flags: tokenizer_1.FLAG_INTEGER
|
|
168
|
-
};
|
|
169
|
-
const getAbsoluteValueForTuple = (tuple, width, height) => {
|
|
170
|
-
const [x, y] = tuple;
|
|
171
|
-
return [(0, exports.getAbsoluteValue)(x, width), (0, exports.getAbsoluteValue)(typeof y !== 'undefined' ? y : x, height)];
|
|
172
|
-
};
|
|
173
|
-
exports.getAbsoluteValueForTuple = getAbsoluteValueForTuple;
|
|
174
|
-
const getAbsoluteValue = (token, parent) => {
|
|
175
|
-
if ((0, exports.isCalcWithPercentage)(token)) {
|
|
176
|
-
return (token._calcPercentage / 100) * parent + token._calcPixelOffset;
|
|
177
|
-
}
|
|
178
|
-
if (token.type === 16 /* TokenType.PERCENTAGE_TOKEN */) {
|
|
179
|
-
return (token.number / 100) * parent;
|
|
180
|
-
}
|
|
181
|
-
if ((0, parser_1.isDimensionToken)(token)) {
|
|
182
|
-
switch (token.unit) {
|
|
183
|
-
case 'rem':
|
|
184
|
-
case 'em':
|
|
185
|
-
// NOTE: Assumes a 16px root font-size for rem/em units. A fully
|
|
186
|
-
// accurate implementation would require access to the element's
|
|
187
|
-
// computed font-size (em) or the root element's font-size (rem),
|
|
188
|
-
// which are not available in this pure-resolution function.
|
|
189
|
-
return 16 * token.number;
|
|
190
|
-
case 'px':
|
|
191
|
-
default:
|
|
192
|
-
return token.number;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
return token.number;
|
|
196
|
-
};
|
|
197
|
-
exports.getAbsoluteValue = getAbsoluteValue;
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Safe arithmetic expression evaluator — replaces `new Function()`.
|
|
4
|
-
*
|
|
5
|
-
* Supports only: numbers, +, -, *, /, parentheses.
|
|
6
|
-
* Does NOT execute arbitrary code. Returns NaN on any illegal token.
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
// Regex that matches a token: number (int or float) | operator | parentheses
|
|
10
|
-
const ARITH_TOKEN_RE = /(\d+(?:\.\d+)?|[+\-*/()])/g;
|
|
11
|
-
const safeEvalArithmetic = (expr) => {
|
|
12
|
-
const tokens = expr.match(ARITH_TOKEN_RE);
|
|
13
|
-
if (!tokens) {
|
|
14
|
-
return NaN;
|
|
15
|
-
}
|
|
16
|
-
// Shunting-yard algorithm: infix → postfix (RPN), then evaluate.
|
|
17
|
-
const output = [];
|
|
18
|
-
const ops = [];
|
|
19
|
-
const precedence = { '+': 1, '-': 1, '*': 2, '/': 2 };
|
|
20
|
-
for (const tok of tokens) {
|
|
21
|
-
if (/^\d+(?:\.\d+)?$/.test(tok)) {
|
|
22
|
-
output.push(parseFloat(tok));
|
|
23
|
-
}
|
|
24
|
-
else if (tok === '(') {
|
|
25
|
-
ops.push(tok);
|
|
26
|
-
}
|
|
27
|
-
else if (tok === ')') {
|
|
28
|
-
while (ops.length && ops[ops.length - 1] !== '(') {
|
|
29
|
-
output.push(ops.pop());
|
|
30
|
-
}
|
|
31
|
-
if (!ops.length)
|
|
32
|
-
return NaN; // mismatched parens
|
|
33
|
-
ops.pop(); // discard '('
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
// operator: + - * /
|
|
37
|
-
while (ops.length && precedence[ops[ops.length - 1]] >= precedence[tok]) {
|
|
38
|
-
output.push(ops.pop());
|
|
39
|
-
}
|
|
40
|
-
ops.push(tok);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
while (ops.length) {
|
|
44
|
-
const op = ops.pop();
|
|
45
|
-
if (op === '(')
|
|
46
|
-
return NaN; // mismatched parens
|
|
47
|
-
output.push(op);
|
|
48
|
-
}
|
|
49
|
-
// Evaluate RPN
|
|
50
|
-
const stack = [];
|
|
51
|
-
for (const item of output) {
|
|
52
|
-
if (typeof item === 'number') {
|
|
53
|
-
stack.push(item);
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
const b = stack.pop();
|
|
57
|
-
const a = stack.pop();
|
|
58
|
-
if (a === undefined || b === undefined)
|
|
59
|
-
return NaN;
|
|
60
|
-
switch (item) {
|
|
61
|
-
case '+':
|
|
62
|
-
stack.push(a + b);
|
|
63
|
-
break;
|
|
64
|
-
case '-':
|
|
65
|
-
stack.push(a - b);
|
|
66
|
-
break;
|
|
67
|
-
case '*':
|
|
68
|
-
stack.push(a * b);
|
|
69
|
-
break;
|
|
70
|
-
case '/':
|
|
71
|
-
stack.push(b === 0 ? NaN : a / b);
|
|
72
|
-
break;
|
|
73
|
-
default:
|
|
74
|
-
return NaN;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
return stack.length === 1 ? stack[0] : NaN;
|
|
79
|
-
};
|
|
80
|
-
exports.default = safeEvalArithmetic;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.time = void 0;
|
|
4
|
-
exports.time = {
|
|
5
|
-
name: 'time',
|
|
6
|
-
parse: (_context, value) => {
|
|
7
|
-
if (value.type === 15 /* TokenType.DIMENSION_TOKEN */) {
|
|
8
|
-
switch (value.unit.toLowerCase()) {
|
|
9
|
-
case 's':
|
|
10
|
-
return 1000 * value.number;
|
|
11
|
-
case 'ms':
|
|
12
|
-
return value.number;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
throw new Error(`Unsupported time type`);
|
|
16
|
-
}
|
|
17
|
-
};
|