html2canvas-pro 2.1.1 → 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 -10540
- package/dist/html2canvas-pro.esm.js.map +1 -1
- package/dist/html2canvas-pro.js +10869 -11185
- 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 +1 -38
- package/dist/lib/core/constants.js +25 -0
- package/dist/lib/core/context.js +1 -0
- package/dist/lib/core/features.js +1 -0
- 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 +165 -32
- package/dist/lib/render/canvas/border-image-renderer.js +153 -0
- package/dist/lib/render/canvas/canvas-renderer.js +34 -189
- 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/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 +5 -10
- package/dist/lib/dom/replaced-elements/pseudo-elements.js +0 -0
- package/dist/types/dom/replaced-elements/pseudo-elements.d.ts +0 -0
|
@@ -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;
|