html2canvas-pro 2.1.0 → 2.1.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/dist/html2canvas-pro.esm.js +21 -7
- package/dist/html2canvas-pro.esm.js.map +1 -1
- package/dist/html2canvas-pro.js +21 -7
- package/dist/html2canvas-pro.js.map +1 -1
- package/dist/html2canvas-pro.min.js +3 -3
- package/dist/lib/core/cache-storage.js +2 -2
- package/dist/lib/core/features.js +2 -2
- package/dist/lib/render/canvas/background-renderer.js +6 -0
- package/dist/lib/render/canvas/canvas-renderer.js +5 -1
- package/dist/lib/render/canvas/foreignobject-renderer.js +5 -1
- package/package.json +3 -11
- package/dist/lib/invariant.js +0 -9
- 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
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { IPropertyIdentValueDescriptor, PropertyDescriptorParsingType } from '../property-descriptor';
|
|
2
|
-
import { Context } from '../../core/context';
|
|
3
|
-
|
|
4
|
-
export const enum WRITING_MODE {
|
|
5
|
-
HORIZONTAL_TB = 0,
|
|
6
|
-
VERTICAL_RL = 1,
|
|
7
|
-
VERTICAL_LR = 2,
|
|
8
|
-
SIDEWAYS_RL = 3,
|
|
9
|
-
SIDEWAYS_LR = 4
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const isVerticalWritingMode = (writingMode: WRITING_MODE): boolean => writingMode !== WRITING_MODE.HORIZONTAL_TB;
|
|
13
|
-
|
|
14
|
-
export const isSidewaysWritingMode = (writingMode: WRITING_MODE): boolean =>
|
|
15
|
-
writingMode === WRITING_MODE.SIDEWAYS_RL || writingMode === WRITING_MODE.SIDEWAYS_LR;
|
|
16
|
-
|
|
17
|
-
export const writingMode: IPropertyIdentValueDescriptor<WRITING_MODE> = {
|
|
18
|
-
name: 'writing-mode',
|
|
19
|
-
initialValue: 'horizontal-tb',
|
|
20
|
-
prefix: false,
|
|
21
|
-
type: PropertyDescriptorParsingType.IDENT_VALUE,
|
|
22
|
-
parse: (_context: Context, writingMode: string): WRITING_MODE => {
|
|
23
|
-
switch (writingMode) {
|
|
24
|
-
case 'vertical-rl':
|
|
25
|
-
return WRITING_MODE.VERTICAL_RL;
|
|
26
|
-
case 'vertical-lr':
|
|
27
|
-
return WRITING_MODE.VERTICAL_LR;
|
|
28
|
-
case 'sideways-rl':
|
|
29
|
-
return WRITING_MODE.SIDEWAYS_RL;
|
|
30
|
-
case 'sideways-lr':
|
|
31
|
-
return WRITING_MODE.SIDEWAYS_LR;
|
|
32
|
-
case 'horizontal-tb':
|
|
33
|
-
default:
|
|
34
|
-
return WRITING_MODE.HORIZONTAL_TB;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { IPropertyValueDescriptor, PropertyDescriptorParsingType } from '../property-descriptor';
|
|
2
|
-
import { CSSValue, isNumberToken } from '../syntax/parser';
|
|
3
|
-
import { TokenType } from '../syntax/tokenizer';
|
|
4
|
-
import { Context } from '../../core/context';
|
|
5
|
-
|
|
6
|
-
interface zIndex {
|
|
7
|
-
order: number;
|
|
8
|
-
auto: boolean;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export const zIndex: IPropertyValueDescriptor<zIndex> = {
|
|
12
|
-
name: 'z-index',
|
|
13
|
-
initialValue: 'auto',
|
|
14
|
-
prefix: false,
|
|
15
|
-
type: PropertyDescriptorParsingType.VALUE,
|
|
16
|
-
parse: (_context: Context, token: CSSValue): zIndex => {
|
|
17
|
-
if (token.type === TokenType.IDENT_TOKEN) {
|
|
18
|
-
return { auto: true, order: 0 };
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
if (isNumberToken(token)) {
|
|
22
|
-
return { auto: false, order: token.number };
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
throw new Error(`Invalid z-index number parsed`);
|
|
26
|
-
}
|
|
27
|
-
};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { deepEqual } from 'assert';
|
|
2
|
-
import { Tokenizer, TokenType } from '../tokenizer';
|
|
3
|
-
|
|
4
|
-
const tokenize = (value: string) => {
|
|
5
|
-
const tokenizer = new Tokenizer();
|
|
6
|
-
tokenizer.write(value);
|
|
7
|
-
return tokenizer.read();
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
describe('tokenizer', () => {
|
|
11
|
-
describe('<ident>', () => {
|
|
12
|
-
it('auto', () => deepEqual(tokenize('auto'), [{ type: TokenType.IDENT_TOKEN, value: 'auto' }]));
|
|
13
|
-
it('url', () => deepEqual(tokenize('url'), [{ type: TokenType.IDENT_TOKEN, value: 'url' }]));
|
|
14
|
-
it('auto test', () =>
|
|
15
|
-
deepEqual(tokenize('auto test'), [
|
|
16
|
-
{ type: TokenType.IDENT_TOKEN, value: 'auto' },
|
|
17
|
-
{ type: TokenType.WHITESPACE_TOKEN },
|
|
18
|
-
{ type: TokenType.IDENT_TOKEN, value: 'test' }
|
|
19
|
-
]));
|
|
20
|
-
});
|
|
21
|
-
describe('<url-token>', () => {
|
|
22
|
-
it('url(test.jpg)', () =>
|
|
23
|
-
deepEqual(tokenize('url(test.jpg)'), [{ type: TokenType.URL_TOKEN, value: 'test.jpg' }]));
|
|
24
|
-
it('url("test.jpg")', () =>
|
|
25
|
-
deepEqual(tokenize('url("test.jpg")'), [{ type: TokenType.URL_TOKEN, value: 'test.jpg' }]));
|
|
26
|
-
it("url('test.jpg')", () =>
|
|
27
|
-
deepEqual(tokenize("url('test.jpg')"), [{ type: TokenType.URL_TOKEN, value: 'test.jpg' }]));
|
|
28
|
-
});
|
|
29
|
-
});
|
package/src/css/syntax/parser.ts
DELETED
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
CSSToken,
|
|
3
|
-
DimensionToken,
|
|
4
|
-
EOF_TOKEN,
|
|
5
|
-
NumberValueToken,
|
|
6
|
-
StringValueToken,
|
|
7
|
-
Tokenizer,
|
|
8
|
-
TokenType
|
|
9
|
-
} from './tokenizer';
|
|
10
|
-
|
|
11
|
-
export type CSSBlockType =
|
|
12
|
-
| TokenType.LEFT_PARENTHESIS_TOKEN
|
|
13
|
-
| TokenType.LEFT_SQUARE_BRACKET_TOKEN
|
|
14
|
-
| TokenType.LEFT_CURLY_BRACKET_TOKEN;
|
|
15
|
-
|
|
16
|
-
export interface CSSBlock {
|
|
17
|
-
type: CSSBlockType;
|
|
18
|
-
values: CSSValue[];
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface CSSFunction {
|
|
22
|
-
type: TokenType.FUNCTION;
|
|
23
|
-
name: string;
|
|
24
|
-
values: CSSValue[];
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export type CSSValue = CSSFunction | CSSToken | CSSBlock;
|
|
28
|
-
|
|
29
|
-
export class Parser {
|
|
30
|
-
private _tokens: CSSToken[];
|
|
31
|
-
|
|
32
|
-
constructor(tokens: CSSToken[]) {
|
|
33
|
-
this._tokens = tokens;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
static create(value: string): Parser {
|
|
37
|
-
const tokenizer = new Tokenizer();
|
|
38
|
-
tokenizer.write(value);
|
|
39
|
-
return new Parser(tokenizer.read());
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
static parseValue(value: string): CSSValue {
|
|
43
|
-
return Parser.create(value).parseComponentValue();
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
static parseValues(value: string): CSSValue[] {
|
|
47
|
-
return Parser.create(value).parseComponentValues();
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
parseComponentValue(): CSSValue {
|
|
51
|
-
let token = this.consumeToken();
|
|
52
|
-
while (token.type === TokenType.WHITESPACE_TOKEN) {
|
|
53
|
-
token = this.consumeToken();
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (token.type === TokenType.EOF_TOKEN) {
|
|
57
|
-
throw new SyntaxError(`Error parsing CSS component value, unexpected EOF`);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
this.reconsumeToken(token);
|
|
61
|
-
const value = this.consumeComponentValue();
|
|
62
|
-
|
|
63
|
-
do {
|
|
64
|
-
token = this.consumeToken();
|
|
65
|
-
} while (token.type === TokenType.WHITESPACE_TOKEN);
|
|
66
|
-
|
|
67
|
-
if (token.type === TokenType.EOF_TOKEN) {
|
|
68
|
-
return value;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
throw new SyntaxError(`Error parsing CSS component value, multiple values found when expecting only one`);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
parseComponentValues(): CSSValue[] {
|
|
75
|
-
const values = [];
|
|
76
|
-
while (true) {
|
|
77
|
-
const value = this.consumeComponentValue();
|
|
78
|
-
if (value.type === TokenType.EOF_TOKEN) {
|
|
79
|
-
return values;
|
|
80
|
-
}
|
|
81
|
-
values.push(value);
|
|
82
|
-
values.push();
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
private consumeComponentValue(): CSSValue {
|
|
87
|
-
const token = this.consumeToken();
|
|
88
|
-
|
|
89
|
-
switch (token.type) {
|
|
90
|
-
case TokenType.LEFT_CURLY_BRACKET_TOKEN:
|
|
91
|
-
case TokenType.LEFT_SQUARE_BRACKET_TOKEN:
|
|
92
|
-
case TokenType.LEFT_PARENTHESIS_TOKEN:
|
|
93
|
-
return this.consumeSimpleBlock(token.type);
|
|
94
|
-
case TokenType.FUNCTION_TOKEN:
|
|
95
|
-
return this.consumeFunction(token);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return token;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
private consumeSimpleBlock(type: CSSBlockType): CSSBlock {
|
|
102
|
-
const block: CSSBlock = { type, values: [] };
|
|
103
|
-
|
|
104
|
-
let token = this.consumeToken();
|
|
105
|
-
while (true) {
|
|
106
|
-
if (token.type === TokenType.EOF_TOKEN || isEndingTokenFor(token, type)) {
|
|
107
|
-
return block;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
this.reconsumeToken(token);
|
|
111
|
-
block.values.push(this.consumeComponentValue());
|
|
112
|
-
token = this.consumeToken();
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
private consumeFunction(functionToken: StringValueToken): CSSFunction {
|
|
117
|
-
const cssFunction: CSSFunction = {
|
|
118
|
-
name: functionToken.value,
|
|
119
|
-
values: [],
|
|
120
|
-
type: TokenType.FUNCTION
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
while (true) {
|
|
124
|
-
const token = this.consumeToken();
|
|
125
|
-
if (token.type === TokenType.EOF_TOKEN || token.type === TokenType.RIGHT_PARENTHESIS_TOKEN) {
|
|
126
|
-
return cssFunction;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
this.reconsumeToken(token);
|
|
130
|
-
cssFunction.values.push(this.consumeComponentValue());
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
private consumeToken(): CSSToken {
|
|
135
|
-
const token = this._tokens.shift();
|
|
136
|
-
return typeof token === 'undefined' ? EOF_TOKEN : token;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
private reconsumeToken(token: CSSToken): void {
|
|
140
|
-
this._tokens.unshift(token);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
export const isDimensionToken = (token: CSSValue): token is DimensionToken => token.type === TokenType.DIMENSION_TOKEN;
|
|
145
|
-
export const isNumberToken = (token: CSSValue): token is NumberValueToken => token.type === TokenType.NUMBER_TOKEN;
|
|
146
|
-
export const isIdentToken = (token: CSSValue): token is StringValueToken => token.type === TokenType.IDENT_TOKEN;
|
|
147
|
-
export const isStringToken = (token: CSSValue): token is StringValueToken => token.type === TokenType.STRING_TOKEN;
|
|
148
|
-
export const isIdentWithValue = (token: CSSValue, value: string): boolean =>
|
|
149
|
-
isIdentToken(token) && token.value === value;
|
|
150
|
-
|
|
151
|
-
export const nonWhiteSpace = (token: CSSValue): boolean => token.type !== TokenType.WHITESPACE_TOKEN;
|
|
152
|
-
export const nonFunctionArgSeparator = (token: CSSValue): boolean =>
|
|
153
|
-
token.type !== TokenType.WHITESPACE_TOKEN && token.type !== TokenType.COMMA_TOKEN;
|
|
154
|
-
|
|
155
|
-
export const parseFunctionArgs = (tokens: CSSValue[]): CSSValue[][] => {
|
|
156
|
-
const args: CSSValue[][] = [];
|
|
157
|
-
let arg: CSSValue[] = [];
|
|
158
|
-
tokens.forEach((token) => {
|
|
159
|
-
if (token.type === TokenType.COMMA_TOKEN) {
|
|
160
|
-
if (arg.length === 0) {
|
|
161
|
-
throw new Error(`Error parsing function args, zero tokens for arg`);
|
|
162
|
-
}
|
|
163
|
-
args.push(arg);
|
|
164
|
-
arg = [];
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
if (token.type !== TokenType.WHITESPACE_TOKEN) {
|
|
169
|
-
arg.push(token);
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
if (arg.length) {
|
|
173
|
-
args.push(arg);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
return args;
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
const isEndingTokenFor = (token: CSSToken, type: CSSBlockType): boolean => {
|
|
180
|
-
if (type === TokenType.LEFT_CURLY_BRACKET_TOKEN && token.type === TokenType.RIGHT_CURLY_BRACKET_TOKEN) {
|
|
181
|
-
return true;
|
|
182
|
-
}
|
|
183
|
-
if (type === TokenType.LEFT_SQUARE_BRACKET_TOKEN && token.type === TokenType.RIGHT_SQUARE_BRACKET_TOKEN) {
|
|
184
|
-
return true;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
return type === TokenType.LEFT_PARENTHESIS_TOKEN && token.type === TokenType.RIGHT_PARENTHESIS_TOKEN;
|
|
188
|
-
};
|