html2canvas-pro 2.1.0 → 2.2.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/dist/html2canvas-pro.esm.js +10226 -10526
- package/dist/html2canvas-pro.esm.js.map +1 -1
- package/dist/html2canvas-pro.js +10869 -11171
- package/dist/html2canvas-pro.js.map +1 -1
- package/dist/html2canvas-pro.min.js +8 -8
- package/dist/lib/config.js +0 -22
- package/dist/lib/core/cache-storage.js +3 -40
- package/dist/lib/core/constants.js +25 -0
- package/dist/lib/core/context.js +1 -0
- package/dist/lib/core/features.js +3 -2
- package/dist/lib/core/validator.js +3 -3
- package/dist/lib/css/grouped/background-styles.js +36 -0
- package/dist/lib/css/grouped/border-styles.js +75 -0
- package/dist/lib/css/grouped/font-styles.js +93 -0
- package/dist/lib/css/grouped/layout-styles.js +127 -0
- package/dist/lib/css/index.js +74 -46
- package/dist/lib/css/layout/text.js +7 -6
- package/dist/lib/css/property-descriptors/background-blend-mode.js +41 -0
- package/dist/lib/css/property-descriptors/border-image-repeat.js +42 -0
- package/dist/lib/css/property-descriptors/border-image-slice.js +45 -0
- package/dist/lib/css/property-descriptors/border-image-source.js +21 -0
- package/dist/lib/css/property-descriptors/border-radius.js +1 -1
- package/dist/lib/css/property-descriptors/box-decoration-break.js +18 -0
- package/dist/lib/css/property-descriptors/counter-increment.js +17 -12
- package/dist/lib/css/property-descriptors/counter-reset.js +4 -12
- package/dist/lib/css/property-descriptors/filter.js +76 -0
- package/dist/lib/css/property-descriptors/font-variant-ligatures.js +34 -0
- package/dist/lib/css/property-descriptors/object-fit.js +1 -1
- package/dist/lib/css/property-descriptors/object-position.js +42 -0
- package/dist/lib/css/property-descriptors/visibility.js +1 -1
- package/dist/lib/css/property-descriptors/zoom.js +18 -0
- package/dist/lib/css/syntax/parser.js +0 -1
- package/dist/lib/css/types/color.js +5 -1
- package/dist/lib/css/types/functions/repeating-linear-gradient.js +9 -0
- package/dist/lib/css/types/image.js +12 -2
- package/dist/lib/css/types/length-percentage.js +6 -2
- package/dist/lib/css/types/safe-eval.js +80 -0
- package/dist/lib/dom/document-cloner.js +23 -163
- package/dist/lib/dom/slot-cloner.js +176 -0
- package/dist/lib/index.js +1 -17
- package/dist/lib/render/canvas/background-renderer.js +169 -30
- package/dist/lib/render/canvas/border-image-renderer.js +153 -0
- package/dist/lib/render/canvas/canvas-renderer.js +39 -190
- package/dist/lib/render/canvas/content-renderer.js +202 -0
- package/dist/lib/render/canvas/effects-renderer.js +3 -0
- package/dist/lib/render/canvas/foreignobject-renderer.js +5 -1
- package/dist/lib/render/canvas/text/text-decoration-renderer.js +99 -0
- package/dist/lib/render/canvas/text-renderer.js +100 -224
- package/dist/lib/render/effects.js +38 -3
- package/dist/lib/render/object-fit.js +19 -15
- package/dist/lib/render/stacking-context.js +11 -0
- package/dist/types/config.d.ts +0 -10
- package/dist/types/core/cache-storage.d.ts +0 -24
- package/dist/types/core/constants.d.ts +22 -0
- package/dist/types/core/context.d.ts +3 -0
- package/dist/types/core/performance-monitor.d.ts +4 -4
- package/dist/types/core/validator.d.ts +6 -8
- package/dist/types/css/grouped/background-styles.d.ts +16 -0
- package/dist/types/css/grouped/border-styles.d.ts +31 -0
- package/dist/types/css/grouped/font-styles.d.ts +35 -0
- package/dist/types/css/grouped/layout-styles.d.ts +46 -0
- package/dist/types/css/index.d.ts +30 -0
- package/dist/types/css/property-descriptors/background-blend-mode.d.ts +23 -0
- package/dist/types/css/property-descriptors/border-image-repeat.d.ts +12 -0
- package/dist/types/css/property-descriptors/border-image-slice.d.ts +10 -0
- package/dist/types/css/property-descriptors/border-image-source.d.ts +4 -0
- package/dist/types/css/property-descriptors/box-decoration-break.d.ts +6 -0
- package/dist/types/css/property-descriptors/counter-increment.d.ts +3 -0
- package/dist/types/css/property-descriptors/filter.d.ts +3 -0
- package/dist/types/css/property-descriptors/font-variant-ligatures.d.ts +14 -0
- package/dist/types/css/property-descriptors/object-position.d.ts +4 -0
- package/dist/types/css/property-descriptors/zoom.d.ts +3 -0
- package/dist/types/css/types/functions/repeating-linear-gradient.d.ts +4 -0
- package/dist/types/css/types/image.d.ts +4 -2
- package/dist/types/css/types/safe-eval.d.ts +8 -0
- package/dist/types/dom/document-cloner.d.ts +3 -44
- package/dist/types/dom/slot-cloner.d.ts +66 -0
- package/dist/types/index.d.ts +3 -7
- package/dist/types/options.d.ts +11 -0
- package/dist/types/render/canvas/background-renderer.d.ts +23 -0
- package/dist/types/render/canvas/border-image-renderer.d.ts +18 -0
- package/dist/types/render/canvas/canvas-renderer.d.ts +1 -0
- package/dist/types/render/canvas/content-renderer.d.ts +44 -0
- package/dist/types/render/canvas/text/text-decoration-renderer.d.ts +18 -0
- package/dist/types/render/canvas/text-renderer.d.ts +12 -1
- package/dist/types/render/effects.d.ts +12 -2
- package/dist/types/render/object-fit.d.ts +2 -1
- package/dist/types/render/renderer-interface.d.ts +11 -9
- package/package.json +7 -20
- package/dist/lib/dom/replaced-elements/pseudo-elements.js +0 -0
- package/dist/lib/invariant.js +0 -9
- package/dist/types/dom/replaced-elements/pseudo-elements.d.ts +0 -0
- package/dist/types/invariant.d.ts +0 -1
- package/src/__tests__/index.ts +0 -99
- package/src/config.ts +0 -107
- package/src/core/__mocks__/cache-storage.ts +0 -1
- package/src/core/__mocks__/context.ts +0 -19
- package/src/core/__mocks__/features.ts +0 -8
- package/src/core/__mocks__/logger.ts +0 -17
- package/src/core/__tests__/cache-storage.test.ts +0 -205
- package/src/core/__tests__/cache-storage.ts +0 -278
- package/src/core/__tests__/logger.ts +0 -29
- package/src/core/__tests__/validator.ts +0 -359
- package/src/core/bitwise.ts +0 -1
- package/src/core/cache-storage.ts +0 -315
- package/src/core/context.ts +0 -31
- package/src/core/debugger.ts +0 -32
- package/src/core/features.ts +0 -222
- package/src/core/logger.ts +0 -64
- package/src/core/origin-checker.ts +0 -57
- package/src/core/performance-monitor.ts +0 -241
- package/src/core/render-element.ts +0 -272
- package/src/core/util.ts +0 -1
- package/src/core/validator.ts +0 -593
- package/src/css/index.ts +0 -427
- package/src/css/layout/__mocks__/bounds.ts +0 -6
- package/src/css/layout/bounds.ts +0 -79
- package/src/css/layout/text.ts +0 -161
- package/src/css/property-descriptor.ts +0 -49
- package/src/css/property-descriptors/__tests__/background-tests.ts +0 -65
- package/src/css/property-descriptors/__tests__/clip-path.test.ts +0 -280
- package/src/css/property-descriptors/__tests__/font-family.ts +0 -25
- package/src/css/property-descriptors/__tests__/image-rendering-integration.test.ts +0 -153
- package/src/css/property-descriptors/__tests__/image-rendering-performance.test.ts +0 -175
- package/src/css/property-descriptors/__tests__/image-rendering.test.ts +0 -72
- package/src/css/property-descriptors/__tests__/paint-order.ts +0 -87
- package/src/css/property-descriptors/__tests__/text-shadow.ts +0 -94
- package/src/css/property-descriptors/__tests__/transform-tests.ts +0 -18
- package/src/css/property-descriptors/background-clip.ts +0 -30
- package/src/css/property-descriptors/background-color.ts +0 -9
- package/src/css/property-descriptors/background-image.ts +0 -27
- package/src/css/property-descriptors/background-origin.ts +0 -31
- package/src/css/property-descriptors/background-position.ts +0 -38
- package/src/css/property-descriptors/background-repeat.ts +0 -44
- package/src/css/property-descriptors/background-size.ts +0 -27
- package/src/css/property-descriptors/border-color.ts +0 -13
- package/src/css/property-descriptors/border-radius.ts +0 -19
- package/src/css/property-descriptors/border-style.ts +0 -34
- package/src/css/property-descriptors/border-width.ts +0 -20
- package/src/css/property-descriptors/box-shadow.ts +0 -60
- package/src/css/property-descriptors/clip-path.ts +0 -271
- package/src/css/property-descriptors/color.ts +0 -9
- package/src/css/property-descriptors/content.ts +0 -26
- package/src/css/property-descriptors/counter-increment.ts +0 -43
- package/src/css/property-descriptors/counter-reset.ts +0 -36
- package/src/css/property-descriptors/direction.ts +0 -23
- package/src/css/property-descriptors/display.ts +0 -117
- package/src/css/property-descriptors/duration.ts +0 -14
- package/src/css/property-descriptors/float.ts +0 -29
- package/src/css/property-descriptors/font-family.ts +0 -38
- package/src/css/property-descriptors/font-size.ts +0 -9
- package/src/css/property-descriptors/font-style.ts +0 -25
- package/src/css/property-descriptors/font-variant.ts +0 -12
- package/src/css/property-descriptors/font-weight.ts +0 -26
- package/src/css/property-descriptors/image-rendering.ts +0 -33
- package/src/css/property-descriptors/letter-spacing.ts +0 -25
- package/src/css/property-descriptors/line-break.ts +0 -22
- package/src/css/property-descriptors/line-height.ts +0 -22
- package/src/css/property-descriptors/list-style-image.ts +0 -19
- package/src/css/property-descriptors/list-style-position.ts +0 -22
- package/src/css/property-descriptors/list-style-type.ts +0 -179
- package/src/css/property-descriptors/margin.ts +0 -13
- package/src/css/property-descriptors/mix-blend-mode.ts +0 -35
- package/src/css/property-descriptors/object-fit.ts +0 -39
- package/src/css/property-descriptors/opacity.ts +0 -15
- package/src/css/property-descriptors/overflow-wrap.ts +0 -22
- package/src/css/property-descriptors/overflow.ts +0 -34
- package/src/css/property-descriptors/padding.ts +0 -14
- package/src/css/property-descriptors/paint-order.ts +0 -42
- package/src/css/property-descriptors/position.ts +0 -30
- package/src/css/property-descriptors/quotes.ts +0 -57
- package/src/css/property-descriptors/rotate.ts +0 -34
- package/src/css/property-descriptors/text-align.ts +0 -26
- package/src/css/property-descriptors/text-decoration-color.ts +0 -9
- package/src/css/property-descriptors/text-decoration-line.ts +0 -38
- package/src/css/property-descriptors/text-decoration-style.ts +0 -32
- package/src/css/property-descriptors/text-decoration-thickness.ts +0 -30
- package/src/css/property-descriptors/text-overflow.ts +0 -23
- package/src/css/property-descriptors/text-shadow.ts +0 -52
- package/src/css/property-descriptors/text-transform.ts +0 -27
- package/src/css/property-descriptors/text-underline-offset.ts +0 -27
- package/src/css/property-descriptors/transform-origin.ts +0 -29
- package/src/css/property-descriptors/transform.ts +0 -74
- package/src/css/property-descriptors/visibility.ts +0 -25
- package/src/css/property-descriptors/webkit-line-clamp.ts +0 -30
- package/src/css/property-descriptors/webkit-text-stroke-color.ts +0 -8
- package/src/css/property-descriptors/webkit-text-stroke-width.ts +0 -15
- package/src/css/property-descriptors/word-break.ts +0 -25
- package/src/css/property-descriptors/writing-mode.ts +0 -37
- package/src/css/property-descriptors/z-index.ts +0 -27
- package/src/css/syntax/__tests__/tokernizer-tests.ts +0 -29
- package/src/css/syntax/parser.ts +0 -188
- package/src/css/syntax/tokenizer.ts +0 -822
- package/src/css/type-descriptor.ts +0 -7
- package/src/css/types/__tests__/color-tests.ts +0 -147
- package/src/css/types/__tests__/image-tests.ts +0 -239
- package/src/css/types/angle.ts +0 -86
- package/src/css/types/color-math.ts +0 -22
- package/src/css/types/color-spaces/a98.ts +0 -86
- package/src/css/types/color-spaces/p3.ts +0 -92
- package/src/css/types/color-spaces/pro-photo.ts +0 -87
- package/src/css/types/color-spaces/rec2020.ts +0 -90
- package/src/css/types/color-spaces/srgb.ts +0 -87
- package/src/css/types/color-utilities.ts +0 -452
- package/src/css/types/color.ts +0 -485
- package/src/css/types/functions/-prefix-linear-gradient.ts +0 -35
- package/src/css/types/functions/-prefix-radial-gradient.ts +0 -106
- package/src/css/types/functions/-webkit-gradient.ts +0 -69
- package/src/css/types/functions/__tests__/radial-gradient.ts +0 -69
- package/src/css/types/functions/counter.ts +0 -511
- package/src/css/types/functions/gradient.ts +0 -206
- package/src/css/types/functions/linear-gradient.ts +0 -28
- package/src/css/types/functions/radial-gradient.ts +0 -101
- package/src/css/types/image.ts +0 -120
- package/src/css/types/index.ts +0 -1
- package/src/css/types/length-percentage.ts +0 -137
- package/src/css/types/length.ts +0 -7
- package/src/css/types/time.ts +0 -20
- package/src/dom/__mocks__/document-cloner.ts +0 -22
- package/src/dom/__tests__/dom-normalizer.test.ts +0 -133
- package/src/dom/__tests__/element-container.test.ts +0 -129
- package/src/dom/document-cloner.ts +0 -929
- package/src/dom/dom-normalizer.ts +0 -133
- package/src/dom/element-container.ts +0 -75
- package/src/dom/elements/li-element-container.ts +0 -10
- package/src/dom/elements/ol-element-container.ts +0 -12
- package/src/dom/elements/select-element-container.ts +0 -10
- package/src/dom/elements/textarea-element-container.ts +0 -9
- package/src/dom/node-parser.ts +0 -177
- package/src/dom/node-type-guards.ts +0 -70
- package/src/dom/replaced-elements/canvas-element-container.ts +0 -15
- package/src/dom/replaced-elements/iframe-element-container.ts +0 -55
- package/src/dom/replaced-elements/image-element-container.ts +0 -16
- package/src/dom/replaced-elements/index.ts +0 -5
- package/src/dom/replaced-elements/input-element-container.ts +0 -105
- package/src/dom/replaced-elements/pseudo-elements.ts +0 -0
- package/src/dom/replaced-elements/svg-element-container.ts +0 -23
- package/src/dom/text-container.ts +0 -42
- package/src/global.d.ts +0 -19
- package/src/index.ts +0 -82
- package/src/invariant.ts +0 -5
- package/src/options.ts +0 -55
- package/src/render/__tests__/object-fit.test.ts +0 -85
- package/src/render/background.ts +0 -298
- package/src/render/bezier-curve.ts +0 -47
- package/src/render/border.ts +0 -165
- package/src/render/bound-curves.ts +0 -388
- package/src/render/box-sizing.ts +0 -31
- package/src/render/canvas/__tests__/background-renderer.test.ts +0 -72
- package/src/render/canvas/__tests__/border-renderer.test.ts +0 -24
- package/src/render/canvas/__tests__/effects-renderer.test.ts +0 -32
- package/src/render/canvas/__tests__/text-renderer.test.ts +0 -471
- package/src/render/canvas/background-renderer.ts +0 -271
- package/src/render/canvas/border-renderer.ts +0 -224
- package/src/render/canvas/canvas-path.ts +0 -31
- package/src/render/canvas/canvas-renderer.ts +0 -641
- package/src/render/canvas/effects-renderer.ts +0 -130
- package/src/render/canvas/foreignobject-renderer.ts +0 -53
- package/src/render/canvas/text-renderer.ts +0 -700
- package/src/render/effects.ts +0 -75
- package/src/render/font-metrics.ts +0 -72
- package/src/render/object-fit.ts +0 -100
- package/src/render/path.ts +0 -37
- package/src/render/renderer-interface.ts +0 -28
- package/src/render/stacking-context.ts +0 -386
- package/src/render/vector.ts +0 -19
|
@@ -76,18 +76,19 @@ const createRange = (node, offset, length) => {
|
|
|
76
76
|
};
|
|
77
77
|
const segmentGraphemes = (value) => {
|
|
78
78
|
if (features_1.FEATURES.SUPPORT_NATIVE_TEXT_SEGMENTATION) {
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
// Intl.Segmenter is TC39 Stage 4 but not yet in TS lib types
|
|
80
|
+
const Segmenter = Intl;
|
|
81
|
+
const seg = new Segmenter.Segmenter(void 0, { granularity: 'grapheme' });
|
|
82
|
+
return Array.from(seg.segment(value)).map((s) => s.segment);
|
|
81
83
|
}
|
|
82
84
|
return (0, text_segmentation_1.splitGraphemes)(value);
|
|
83
85
|
};
|
|
84
86
|
exports.segmentGraphemes = segmentGraphemes;
|
|
85
87
|
const segmentWords = (value, styles) => {
|
|
86
88
|
if (features_1.FEATURES.SUPPORT_NATIVE_TEXT_SEGMENTATION) {
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
return Array.from(segmenter.segment(value)).map((segment) => segment.segment);
|
|
89
|
+
const Segmenter = Intl;
|
|
90
|
+
const seg = new Segmenter.Segmenter(void 0, { granularity: 'word' });
|
|
91
|
+
return Array.from(seg.segment(value)).map((s) => s.segment);
|
|
91
92
|
}
|
|
92
93
|
return breakWords(value, styles);
|
|
93
94
|
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.backgroundBlendMode = exports.MIX_BLEND_MODE = void 0;
|
|
4
|
+
const parser_1 = require("../syntax/parser");
|
|
5
|
+
exports.MIX_BLEND_MODE = {
|
|
6
|
+
NORMAL: 'normal',
|
|
7
|
+
MULTIPLY: 'multiply',
|
|
8
|
+
SCREEN: 'screen',
|
|
9
|
+
OVERLAY: 'overlay',
|
|
10
|
+
DARKEN: 'darken',
|
|
11
|
+
LIGHTEN: 'lighten',
|
|
12
|
+
COLOR_DODGE: 'color-dodge',
|
|
13
|
+
COLOR_BURN: 'color-burn',
|
|
14
|
+
HARD_LIGHT: 'hard-light',
|
|
15
|
+
SOFT_LIGHT: 'soft-light',
|
|
16
|
+
DIFFERENCE: 'difference',
|
|
17
|
+
EXCLUSION: 'exclusion',
|
|
18
|
+
HUE: 'hue',
|
|
19
|
+
SATURATION: 'saturation',
|
|
20
|
+
COLOR: 'color',
|
|
21
|
+
LUMINOSITY: 'luminosity'
|
|
22
|
+
};
|
|
23
|
+
const VALID_VALUES = new Set(Object.values(exports.MIX_BLEND_MODE));
|
|
24
|
+
exports.backgroundBlendMode = {
|
|
25
|
+
name: 'background-blend-mode',
|
|
26
|
+
initialValue: 'normal',
|
|
27
|
+
prefix: false,
|
|
28
|
+
type: 1 /* PropertyDescriptorParsingType.LIST */,
|
|
29
|
+
parse: (_context, tokens) => {
|
|
30
|
+
const modes = [];
|
|
31
|
+
const filtered = tokens.filter(parser_1.nonFunctionArgSeparator);
|
|
32
|
+
for (const token of filtered) {
|
|
33
|
+
if ((0, parser_1.isIdentToken)(token)) {
|
|
34
|
+
if (VALID_VALUES.has(token.value)) {
|
|
35
|
+
modes.push(token.value);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return modes.length > 0 ? modes : ['normal'];
|
|
40
|
+
}
|
|
41
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.borderImageRepeat = exports.BORDER_IMAGE_REPEAT = void 0;
|
|
4
|
+
const parser_1 = require("../syntax/parser");
|
|
5
|
+
var BORDER_IMAGE_REPEAT;
|
|
6
|
+
(function (BORDER_IMAGE_REPEAT) {
|
|
7
|
+
BORDER_IMAGE_REPEAT[BORDER_IMAGE_REPEAT["STRETCH"] = 0] = "STRETCH";
|
|
8
|
+
BORDER_IMAGE_REPEAT[BORDER_IMAGE_REPEAT["REPEAT"] = 1] = "REPEAT";
|
|
9
|
+
BORDER_IMAGE_REPEAT[BORDER_IMAGE_REPEAT["ROUND"] = 2] = "ROUND";
|
|
10
|
+
BORDER_IMAGE_REPEAT[BORDER_IMAGE_REPEAT["SPACE"] = 3] = "SPACE";
|
|
11
|
+
})(BORDER_IMAGE_REPEAT || (exports.BORDER_IMAGE_REPEAT = BORDER_IMAGE_REPEAT = {}));
|
|
12
|
+
const parseRepeatValue = (value) => {
|
|
13
|
+
switch (value) {
|
|
14
|
+
case 'repeat':
|
|
15
|
+
return BORDER_IMAGE_REPEAT.REPEAT;
|
|
16
|
+
case 'round':
|
|
17
|
+
return BORDER_IMAGE_REPEAT.ROUND;
|
|
18
|
+
case 'space':
|
|
19
|
+
return BORDER_IMAGE_REPEAT.SPACE;
|
|
20
|
+
case 'stretch':
|
|
21
|
+
default:
|
|
22
|
+
return BORDER_IMAGE_REPEAT.STRETCH;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
exports.borderImageRepeat = {
|
|
26
|
+
name: 'border-image-repeat',
|
|
27
|
+
initialValue: 'stretch',
|
|
28
|
+
prefix: false,
|
|
29
|
+
type: 1 /* PropertyDescriptorParsingType.LIST */,
|
|
30
|
+
parse: (_context, tokens) => {
|
|
31
|
+
const filtered = tokens.filter(parser_1.nonWhiteSpace);
|
|
32
|
+
const values = [];
|
|
33
|
+
for (const token of filtered) {
|
|
34
|
+
if ((0, parser_1.isIdentToken)(token)) {
|
|
35
|
+
values.push(parseRepeatValue(token.value));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const horizontal = values[0] ?? BORDER_IMAGE_REPEAT.STRETCH;
|
|
39
|
+
const vertical = values[1] ?? horizontal;
|
|
40
|
+
return { horizontal, vertical };
|
|
41
|
+
}
|
|
42
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.borderImageSlice = void 0;
|
|
4
|
+
const parser_1 = require("../syntax/parser");
|
|
5
|
+
const fillSides = (sides) => {
|
|
6
|
+
const result = [...sides];
|
|
7
|
+
if (result.length === 1) {
|
|
8
|
+
result.push(result[0], result[0], result[0]);
|
|
9
|
+
}
|
|
10
|
+
else if (result.length === 2) {
|
|
11
|
+
result.push(result[0], result[1]);
|
|
12
|
+
}
|
|
13
|
+
else if (result.length === 3) {
|
|
14
|
+
result.push(result[1]);
|
|
15
|
+
}
|
|
16
|
+
return result.slice(0, 4);
|
|
17
|
+
};
|
|
18
|
+
exports.borderImageSlice = {
|
|
19
|
+
name: 'border-image-slice',
|
|
20
|
+
initialValue: '100%',
|
|
21
|
+
prefix: false,
|
|
22
|
+
type: 1 /* PropertyDescriptorParsingType.LIST */,
|
|
23
|
+
parse: (_context, tokens) => {
|
|
24
|
+
const filtered = tokens.filter(parser_1.nonWhiteSpace);
|
|
25
|
+
const values = [];
|
|
26
|
+
let fill = false;
|
|
27
|
+
let unit = 'percent';
|
|
28
|
+
for (const token of filtered) {
|
|
29
|
+
if ((0, parser_1.isIdentToken)(token) && token.value === 'fill') {
|
|
30
|
+
fill = true;
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
if (token.type === 17 /* TokenType.NUMBER_TOKEN */) {
|
|
34
|
+
values.push(token.number);
|
|
35
|
+
unit = 'number';
|
|
36
|
+
}
|
|
37
|
+
else if (token.type === 16 /* TokenType.PERCENTAGE_TOKEN */) {
|
|
38
|
+
values.push(token.number);
|
|
39
|
+
unit = 'percent';
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const [top, right, bottom, left] = fillSides(values.length > 0 ? values : [100]);
|
|
43
|
+
return { top, right, bottom, left, fill, unit };
|
|
44
|
+
}
|
|
45
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.borderImageSource = void 0;
|
|
4
|
+
const parser_1 = require("../syntax/parser");
|
|
5
|
+
const image_1 = require("../types/image");
|
|
6
|
+
exports.borderImageSource = {
|
|
7
|
+
name: 'border-image-source',
|
|
8
|
+
initialValue: 'none',
|
|
9
|
+
prefix: false,
|
|
10
|
+
type: 1 /* PropertyDescriptorParsingType.LIST */,
|
|
11
|
+
parse: (context, tokens) => {
|
|
12
|
+
if (tokens.length === 0) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
const filtered = tokens.filter((t) => (0, parser_1.nonFunctionArgSeparator)(t) && (0, image_1.isSupportedImage)(t));
|
|
16
|
+
if (filtered.length === 0) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
return image_1.image.parse(context, filtered[0]);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.borderBottomLeftRadius = exports.borderBottomRightRadius = exports.borderTopRightRadius = exports.borderTopLeftRadius = void 0;
|
|
4
4
|
const length_percentage_1 = require("../types/length-percentage");
|
|
5
5
|
const borderRadiusForSide = (side) => ({
|
|
6
|
-
name: `border
|
|
6
|
+
name: `border-${side}-radius`,
|
|
7
7
|
initialValue: '0 0',
|
|
8
8
|
prefix: false,
|
|
9
9
|
type: 1 /* PropertyDescriptorParsingType.LIST */,
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.boxDecorationBreak = void 0;
|
|
4
|
+
exports.boxDecorationBreak = {
|
|
5
|
+
name: 'box-decoration-break',
|
|
6
|
+
initialValue: 'slice',
|
|
7
|
+
prefix: false,
|
|
8
|
+
type: 2 /* PropertyDescriptorParsingType.IDENT_VALUE */,
|
|
9
|
+
parse: (_context, token) => {
|
|
10
|
+
switch (token) {
|
|
11
|
+
case 'clone':
|
|
12
|
+
return 1 /* BOX_DECORATION_BREAK.CLONE */;
|
|
13
|
+
case 'slice':
|
|
14
|
+
default:
|
|
15
|
+
return 0 /* BOX_DECORATION_BREAK.SLICE */;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
};
|
|
@@ -1,7 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.counterIncrement = void 0;
|
|
3
|
+
exports.counterIncrement = exports.parseCounterValue = void 0;
|
|
4
4
|
const parser_1 = require("../syntax/parser");
|
|
5
|
+
/** Shared counter-ID parsing: returns next number or a fallback default. */
|
|
6
|
+
const parseCounterValue = (tokens, defaultNumber) => {
|
|
7
|
+
const entries = [];
|
|
8
|
+
const filtered = tokens.filter(parser_1.nonWhiteSpace);
|
|
9
|
+
for (let i = 0; i < filtered.length; i++) {
|
|
10
|
+
const counter = filtered[i];
|
|
11
|
+
const next = filtered[i + 1];
|
|
12
|
+
if (counter.type === 20 /* TokenType.IDENT_TOKEN */) {
|
|
13
|
+
const num = next && (0, parser_1.isNumberToken)(next) ? next.number : defaultNumber;
|
|
14
|
+
entries.push([counter.value, num]);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return entries;
|
|
18
|
+
};
|
|
19
|
+
exports.parseCounterValue = parseCounterValue;
|
|
5
20
|
exports.counterIncrement = {
|
|
6
21
|
name: 'counter-increment',
|
|
7
22
|
initialValue: 'none',
|
|
@@ -15,16 +30,6 @@ exports.counterIncrement = {
|
|
|
15
30
|
if (first.type === 20 /* TokenType.IDENT_TOKEN */ && first.value === 'none') {
|
|
16
31
|
return null;
|
|
17
32
|
}
|
|
18
|
-
|
|
19
|
-
const filtered = tokens.filter(parser_1.nonWhiteSpace);
|
|
20
|
-
for (let i = 0; i < filtered.length; i++) {
|
|
21
|
-
const counter = filtered[i];
|
|
22
|
-
const next = filtered[i + 1];
|
|
23
|
-
if (counter.type === 20 /* TokenType.IDENT_TOKEN */) {
|
|
24
|
-
const increment = next && (0, parser_1.isNumberToken)(next) ? next.number : 1;
|
|
25
|
-
increments.push({ counter: counter.value, increment });
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return increments;
|
|
33
|
+
return (0, exports.parseCounterValue)(tokens, 1).map(([counter, increment]) => ({ counter, increment }));
|
|
29
34
|
}
|
|
30
35
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.counterReset = void 0;
|
|
4
|
-
const
|
|
4
|
+
const counter_increment_1 = require("./counter-increment");
|
|
5
5
|
exports.counterReset = {
|
|
6
6
|
name: 'counter-reset',
|
|
7
7
|
initialValue: 'none',
|
|
@@ -11,16 +11,8 @@ exports.counterReset = {
|
|
|
11
11
|
if (tokens.length === 0) {
|
|
12
12
|
return [];
|
|
13
13
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const counter = filtered[i];
|
|
18
|
-
const next = filtered[i + 1];
|
|
19
|
-
if ((0, parser_1.isIdentToken)(counter) && counter.value !== 'none') {
|
|
20
|
-
const reset = next && (0, parser_1.isNumberToken)(next) ? next.number : 0;
|
|
21
|
-
resets.push({ counter: counter.value, reset });
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return resets;
|
|
14
|
+
return (0, counter_increment_1.parseCounterValue)(tokens, 0)
|
|
15
|
+
.filter(([counter]) => counter !== 'none')
|
|
16
|
+
.map(([counter, reset]) => ({ counter, reset }));
|
|
25
17
|
}
|
|
26
18
|
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.filter = void 0;
|
|
4
|
+
exports.filter = {
|
|
5
|
+
name: 'filter',
|
|
6
|
+
initialValue: 'none',
|
|
7
|
+
prefix: false,
|
|
8
|
+
type: 1 /* PropertyDescriptorParsingType.LIST */,
|
|
9
|
+
parse: (_context, tokens) => {
|
|
10
|
+
if (tokens.length === 1 && tokens[0].type === 20 /* TokenType.IDENT_TOKEN */ && tokens[0].value === 'none') {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
const parts = [];
|
|
14
|
+
for (const token of tokens) {
|
|
15
|
+
if (token.type === 18 /* TokenType.FUNCTION */) {
|
|
16
|
+
const fn = token;
|
|
17
|
+
// Reconstruct the function string from its name + values
|
|
18
|
+
const renderedArgs = renderFilterArgs(fn.values);
|
|
19
|
+
// Canvas API supports the same CSS filter string format
|
|
20
|
+
switch (fn.name) {
|
|
21
|
+
case 'blur':
|
|
22
|
+
parts.push(`blur(${renderedArgs}px)`);
|
|
23
|
+
break;
|
|
24
|
+
case 'brightness':
|
|
25
|
+
case 'contrast':
|
|
26
|
+
case 'invert':
|
|
27
|
+
case 'opacity':
|
|
28
|
+
case 'saturate':
|
|
29
|
+
case 'sepia':
|
|
30
|
+
parts.push(`${fn.name}(${renderedArgs})`);
|
|
31
|
+
break;
|
|
32
|
+
case 'grayscale':
|
|
33
|
+
parts.push(`grayscale(${renderedArgs})`);
|
|
34
|
+
break;
|
|
35
|
+
case 'hue-rotate':
|
|
36
|
+
parts.push(`hue-rotate(${renderedArgs}deg)`);
|
|
37
|
+
break;
|
|
38
|
+
case 'drop-shadow':
|
|
39
|
+
parts.push(`drop-shadow(${renderedArgs})`);
|
|
40
|
+
break;
|
|
41
|
+
default:
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return parts.length > 0 ? parts.join(' ') : null;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Render filter function arguments back into a CSS string suitable for Canvas API.
|
|
51
|
+
* Canvas 2D `ctx.filter` accepts the same CSS filter function strings.
|
|
52
|
+
*/
|
|
53
|
+
const renderFilterArgs = (values) => {
|
|
54
|
+
const parts = [];
|
|
55
|
+
for (const v of values) {
|
|
56
|
+
if (v.type === 31 /* TokenType.WHITESPACE_TOKEN */) {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if (v.type === 15 /* TokenType.DIMENSION_TOKEN */) {
|
|
60
|
+
parts.push(`${v.number}${v.unit}`);
|
|
61
|
+
}
|
|
62
|
+
else if (v.type === 17 /* TokenType.NUMBER_TOKEN */) {
|
|
63
|
+
parts.push(`${v.number}`);
|
|
64
|
+
}
|
|
65
|
+
else if (v.type === 16 /* TokenType.PERCENTAGE_TOKEN */) {
|
|
66
|
+
parts.push(`${v.number}%`);
|
|
67
|
+
}
|
|
68
|
+
else if (v.type === 20 /* TokenType.IDENT_TOKEN */) {
|
|
69
|
+
parts.push(v.value);
|
|
70
|
+
}
|
|
71
|
+
else if (v.type === 5 /* TokenType.HASH_TOKEN */) {
|
|
72
|
+
parts.push(`#${v.value}`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return parts.join(' ');
|
|
76
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fontVariantLigatures = void 0;
|
|
4
|
+
exports.fontVariantLigatures = {
|
|
5
|
+
name: 'font-variant-ligatures',
|
|
6
|
+
initialValue: 'normal',
|
|
7
|
+
prefix: false,
|
|
8
|
+
type: 2 /* PropertyDescriptorParsingType.IDENT_VALUE */,
|
|
9
|
+
parse: (_context, value) => {
|
|
10
|
+
switch (value) {
|
|
11
|
+
case 'none':
|
|
12
|
+
return 1 /* FONT_VARIANT_LIGATURES.NONE */;
|
|
13
|
+
case 'common-ligatures':
|
|
14
|
+
return 2 /* FONT_VARIANT_LIGATURES.COMMON_LIGATURES */;
|
|
15
|
+
case 'no-common-ligatures':
|
|
16
|
+
return 3 /* FONT_VARIANT_LIGATURES.NO_COMMON_LIGATURES */;
|
|
17
|
+
case 'discretionary-ligatures':
|
|
18
|
+
return 4 /* FONT_VARIANT_LIGATURES.DISCRETIONARY_LIGATURES */;
|
|
19
|
+
case 'no-discretionary-ligatures':
|
|
20
|
+
return 5 /* FONT_VARIANT_LIGATURES.NO_DISCRETIONARY_LIGATURES */;
|
|
21
|
+
case 'historical-ligatures':
|
|
22
|
+
return 6 /* FONT_VARIANT_LIGATURES.HISTORICAL_LIGATURES */;
|
|
23
|
+
case 'no-historical-ligatures':
|
|
24
|
+
return 7 /* FONT_VARIANT_LIGATURES.NO_HISTORICAL_LIGATURES */;
|
|
25
|
+
case 'contextual':
|
|
26
|
+
return 8 /* FONT_VARIANT_LIGATURES.CONTEXTUAL */;
|
|
27
|
+
case 'no-contextual':
|
|
28
|
+
return 9 /* FONT_VARIANT_LIGATURES.NO_CONTEXTUAL */;
|
|
29
|
+
case 'normal':
|
|
30
|
+
default:
|
|
31
|
+
return 0 /* FONT_VARIANT_LIGATURES.NORMAL */;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.objectFit = void 0;
|
|
4
4
|
const parser_1 = require("../syntax/parser");
|
|
5
5
|
exports.objectFit = {
|
|
6
|
-
name: '
|
|
6
|
+
name: 'object-fit',
|
|
7
7
|
initialValue: 'fill',
|
|
8
8
|
prefix: false,
|
|
9
9
|
type: 1 /* PropertyDescriptorParsingType.LIST */,
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.objectPosition = void 0;
|
|
4
|
+
const parser_1 = require("../syntax/parser");
|
|
5
|
+
const length_percentage_1 = require("../types/length-percentage");
|
|
6
|
+
exports.objectPosition = {
|
|
7
|
+
name: 'object-position',
|
|
8
|
+
initialValue: '50% 50%',
|
|
9
|
+
prefix: false,
|
|
10
|
+
type: 1 /* PropertyDescriptorParsingType.LIST */,
|
|
11
|
+
parse: (_context, tokens) => {
|
|
12
|
+
const result = [];
|
|
13
|
+
let i = 0;
|
|
14
|
+
while (i < tokens.length && result.length < 2) {
|
|
15
|
+
const token = tokens[i];
|
|
16
|
+
if ((0, parser_1.isIdentToken)(token)) {
|
|
17
|
+
switch (token.value) {
|
|
18
|
+
case 'left':
|
|
19
|
+
case 'top':
|
|
20
|
+
result.push(length_percentage_1.ZERO_LENGTH);
|
|
21
|
+
break;
|
|
22
|
+
case 'center':
|
|
23
|
+
result.push(length_percentage_1.FIFTY_PERCENT);
|
|
24
|
+
break;
|
|
25
|
+
case 'right':
|
|
26
|
+
case 'bottom':
|
|
27
|
+
result.push(length_percentage_1.HUNDRED_PERCENT);
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
else if ((0, length_percentage_1.isLengthPercentage)(token)) {
|
|
32
|
+
result.push(token);
|
|
33
|
+
}
|
|
34
|
+
i++;
|
|
35
|
+
}
|
|
36
|
+
// Fill to 2 values with defaults
|
|
37
|
+
while (result.length < 2) {
|
|
38
|
+
result.push(length_percentage_1.FIFTY_PERCENT);
|
|
39
|
+
}
|
|
40
|
+
return [result[0], result[1]];
|
|
41
|
+
}
|
|
42
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.zoom = void 0;
|
|
4
|
+
exports.zoom = {
|
|
5
|
+
name: 'zoom',
|
|
6
|
+
initialValue: '1',
|
|
7
|
+
type: 0 /* PropertyDescriptorParsingType.VALUE */,
|
|
8
|
+
prefix: false,
|
|
9
|
+
parse: (_context, token) => {
|
|
10
|
+
if (token.type === 16 /* TokenType.PERCENTAGE_TOKEN */) {
|
|
11
|
+
return Math.max(0, token.number / 100);
|
|
12
|
+
}
|
|
13
|
+
if (token.type === 17 /* TokenType.NUMBER_TOKEN */) {
|
|
14
|
+
return Math.max(0, token.number);
|
|
15
|
+
}
|
|
16
|
+
return 1;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.COLORS = exports.parseColor = exports.color = void 0;
|
|
4
7
|
const parser_1 = require("../syntax/parser");
|
|
8
|
+
const safe_eval_1 = __importDefault(require("./safe-eval"));
|
|
5
9
|
const srgb_1 = require("./color-spaces/srgb");
|
|
6
10
|
const color_utilities_1 = require("./color-utilities");
|
|
7
11
|
const p3_1 = require("./color-spaces/p3");
|
|
@@ -140,7 +144,7 @@ const _color = (context, args) => {
|
|
|
140
144
|
.replace(/r|x/, color[0].toString())
|
|
141
145
|
.replace(/g|y/, color[1].toString())
|
|
142
146
|
.replace(/b|z/, color[2].toString());
|
|
143
|
-
return
|
|
147
|
+
return (0, safe_eval_1.default)(expression);
|
|
144
148
|
}
|
|
145
149
|
}
|
|
146
150
|
return null;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.repeatingLinearGradient = void 0;
|
|
4
|
+
const linear_gradient_1 = require("./linear-gradient");
|
|
5
|
+
const repeatingLinearGradient = (context, tokens) => {
|
|
6
|
+
const gradient = (0, linear_gradient_1.linearGradient)(context, tokens);
|
|
7
|
+
return { ...gradient, type: 3 /* CSSImageType.REPEATING_LINEAR_GRADIENT */ };
|
|
8
|
+
};
|
|
9
|
+
exports.repeatingLinearGradient = repeatingLinearGradient;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.image = exports.isRadialGradient = exports.isLinearGradient = void 0;
|
|
3
|
+
exports.image = exports.isRepeatingLinearGradient = exports.isRadialGradient = exports.isLinearGradient = void 0;
|
|
4
4
|
exports.isSupportedImage = isSupportedImage;
|
|
5
5
|
const linear_gradient_1 = require("./functions/linear-gradient");
|
|
6
6
|
const _prefix_linear_gradient_1 = require("./functions/-prefix-linear-gradient");
|
|
7
7
|
const _webkit_gradient_1 = require("./functions/-webkit-gradient");
|
|
8
8
|
const radial_gradient_1 = require("./functions/radial-gradient");
|
|
9
9
|
const _prefix_radial_gradient_1 = require("./functions/-prefix-radial-gradient");
|
|
10
|
+
const repeating_linear_gradient_1 = require("./functions/repeating-linear-gradient");
|
|
10
11
|
const isLinearGradient = (background) => {
|
|
11
12
|
return background.type === 1 /* CSSImageType.LINEAR_GRADIENT */;
|
|
12
13
|
};
|
|
@@ -15,6 +16,10 @@ const isRadialGradient = (background) => {
|
|
|
15
16
|
return background.type === 2 /* CSSImageType.RADIAL_GRADIENT */;
|
|
16
17
|
};
|
|
17
18
|
exports.isRadialGradient = isRadialGradient;
|
|
19
|
+
const isRepeatingLinearGradient = (background) => {
|
|
20
|
+
return background.type === 3 /* CSSImageType.REPEATING_LINEAR_GRADIENT */;
|
|
21
|
+
};
|
|
22
|
+
exports.isRepeatingLinearGradient = isRepeatingLinearGradient;
|
|
18
23
|
exports.image = {
|
|
19
24
|
name: 'image',
|
|
20
25
|
parse: (context, value) => {
|
|
@@ -48,5 +53,10 @@ const SUPPORTED_IMAGE_FUNCTIONS = {
|
|
|
48
53
|
'-ms-radial-gradient': _prefix_radial_gradient_1.prefixRadialGradient,
|
|
49
54
|
'-o-radial-gradient': _prefix_radial_gradient_1.prefixRadialGradient,
|
|
50
55
|
'-webkit-radial-gradient': _prefix_radial_gradient_1.prefixRadialGradient,
|
|
51
|
-
'-webkit-gradient': _webkit_gradient_1.webkitGradient
|
|
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
|
|
52
62
|
};
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.getAbsoluteValue = exports.getAbsoluteValueForTuple = exports.HUNDRED_PERCENT = exports.FIFTY_PERCENT = exports.ZERO_LENGTH = exports.parseLengthPercentageTuple = exports.evaluateCalcToLengthPercentage = exports.isCalcFunction = exports.isLengthPercentage = void 0;
|
|
4
7
|
const tokenizer_1 = require("../syntax/tokenizer");
|
|
5
8
|
const parser_1 = require("../syntax/parser");
|
|
6
9
|
const length_1 = require("./length");
|
|
10
|
+
const safe_eval_1 = __importDefault(require("./safe-eval"));
|
|
7
11
|
const isLengthPercentage = (token) => token.type === 16 /* TokenType.PERCENTAGE_TOKEN */ || (0, length_1.isLength)(token);
|
|
8
12
|
exports.isLengthPercentage = isLengthPercentage;
|
|
9
13
|
/**
|
|
@@ -75,8 +79,8 @@ const evaluateCalcToLengthPercentage = (calcToken, contextValue = 0) => {
|
|
|
75
79
|
return null;
|
|
76
80
|
}
|
|
77
81
|
// Evaluate the expression
|
|
78
|
-
//
|
|
79
|
-
const result =
|
|
82
|
+
// Uses safe arithmetic evaluator instead of new Function() for CodeQL
|
|
83
|
+
const result = (0, safe_eval_1.default)(expression);
|
|
80
84
|
if (typeof result === 'number' && !isNaN(result)) {
|
|
81
85
|
// Return as a number token in px
|
|
82
86
|
return {
|
|
@@ -0,0 +1,80 @@
|
|
|
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;
|