source: imaps-frontend/node_modules/html2canvas/dist/lib/css/syntax/parser.js

main
Last change on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 5 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 5.7 KB
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.parseFunctionArgs = exports.nonFunctionArgSeparator = exports.nonWhiteSpace = exports.isIdentWithValue = exports.isStringToken = exports.isIdentToken = exports.isNumberToken = exports.isDimensionToken = exports.Parser = void 0;
4var tokenizer_1 = require("./tokenizer");
5var Parser = /** @class */ (function () {
6 function Parser(tokens) {
7 this._tokens = tokens;
8 }
9 Parser.create = function (value) {
10 var tokenizer = new tokenizer_1.Tokenizer();
11 tokenizer.write(value);
12 return new Parser(tokenizer.read());
13 };
14 Parser.parseValue = function (value) {
15 return Parser.create(value).parseComponentValue();
16 };
17 Parser.parseValues = function (value) {
18 return Parser.create(value).parseComponentValues();
19 };
20 Parser.prototype.parseComponentValue = function () {
21 var token = this.consumeToken();
22 while (token.type === 31 /* WHITESPACE_TOKEN */) {
23 token = this.consumeToken();
24 }
25 if (token.type === 32 /* EOF_TOKEN */) {
26 throw new SyntaxError("Error parsing CSS component value, unexpected EOF");
27 }
28 this.reconsumeToken(token);
29 var value = this.consumeComponentValue();
30 do {
31 token = this.consumeToken();
32 } while (token.type === 31 /* WHITESPACE_TOKEN */);
33 if (token.type === 32 /* EOF_TOKEN */) {
34 return value;
35 }
36 throw new SyntaxError("Error parsing CSS component value, multiple values found when expecting only one");
37 };
38 Parser.prototype.parseComponentValues = function () {
39 var values = [];
40 while (true) {
41 var value = this.consumeComponentValue();
42 if (value.type === 32 /* EOF_TOKEN */) {
43 return values;
44 }
45 values.push(value);
46 values.push();
47 }
48 };
49 Parser.prototype.consumeComponentValue = function () {
50 var token = this.consumeToken();
51 switch (token.type) {
52 case 11 /* LEFT_CURLY_BRACKET_TOKEN */:
53 case 28 /* LEFT_SQUARE_BRACKET_TOKEN */:
54 case 2 /* LEFT_PARENTHESIS_TOKEN */:
55 return this.consumeSimpleBlock(token.type);
56 case 19 /* FUNCTION_TOKEN */:
57 return this.consumeFunction(token);
58 }
59 return token;
60 };
61 Parser.prototype.consumeSimpleBlock = function (type) {
62 var block = { type: type, values: [] };
63 var token = this.consumeToken();
64 while (true) {
65 if (token.type === 32 /* EOF_TOKEN */ || isEndingTokenFor(token, type)) {
66 return block;
67 }
68 this.reconsumeToken(token);
69 block.values.push(this.consumeComponentValue());
70 token = this.consumeToken();
71 }
72 };
73 Parser.prototype.consumeFunction = function (functionToken) {
74 var cssFunction = {
75 name: functionToken.value,
76 values: [],
77 type: 18 /* FUNCTION */
78 };
79 while (true) {
80 var token = this.consumeToken();
81 if (token.type === 32 /* EOF_TOKEN */ || token.type === 3 /* RIGHT_PARENTHESIS_TOKEN */) {
82 return cssFunction;
83 }
84 this.reconsumeToken(token);
85 cssFunction.values.push(this.consumeComponentValue());
86 }
87 };
88 Parser.prototype.consumeToken = function () {
89 var token = this._tokens.shift();
90 return typeof token === 'undefined' ? tokenizer_1.EOF_TOKEN : token;
91 };
92 Parser.prototype.reconsumeToken = function (token) {
93 this._tokens.unshift(token);
94 };
95 return Parser;
96}());
97exports.Parser = Parser;
98var isDimensionToken = function (token) { return token.type === 15 /* DIMENSION_TOKEN */; };
99exports.isDimensionToken = isDimensionToken;
100var isNumberToken = function (token) { return token.type === 17 /* NUMBER_TOKEN */; };
101exports.isNumberToken = isNumberToken;
102var isIdentToken = function (token) { return token.type === 20 /* IDENT_TOKEN */; };
103exports.isIdentToken = isIdentToken;
104var isStringToken = function (token) { return token.type === 0 /* STRING_TOKEN */; };
105exports.isStringToken = isStringToken;
106var isIdentWithValue = function (token, value) {
107 return exports.isIdentToken(token) && token.value === value;
108};
109exports.isIdentWithValue = isIdentWithValue;
110var nonWhiteSpace = function (token) { return token.type !== 31 /* WHITESPACE_TOKEN */; };
111exports.nonWhiteSpace = nonWhiteSpace;
112var nonFunctionArgSeparator = function (token) {
113 return token.type !== 31 /* WHITESPACE_TOKEN */ && token.type !== 4 /* COMMA_TOKEN */;
114};
115exports.nonFunctionArgSeparator = nonFunctionArgSeparator;
116var parseFunctionArgs = function (tokens) {
117 var args = [];
118 var arg = [];
119 tokens.forEach(function (token) {
120 if (token.type === 4 /* COMMA_TOKEN */) {
121 if (arg.length === 0) {
122 throw new Error("Error parsing function args, zero tokens for arg");
123 }
124 args.push(arg);
125 arg = [];
126 return;
127 }
128 if (token.type !== 31 /* WHITESPACE_TOKEN */) {
129 arg.push(token);
130 }
131 });
132 if (arg.length) {
133 args.push(arg);
134 }
135 return args;
136};
137exports.parseFunctionArgs = parseFunctionArgs;
138var isEndingTokenFor = function (token, type) {
139 if (type === 11 /* LEFT_CURLY_BRACKET_TOKEN */ && token.type === 12 /* RIGHT_CURLY_BRACKET_TOKEN */) {
140 return true;
141 }
142 if (type === 28 /* LEFT_SQUARE_BRACKET_TOKEN */ && token.type === 29 /* RIGHT_SQUARE_BRACKET_TOKEN */) {
143 return true;
144 }
145 return type === 2 /* LEFT_PARENTHESIS_TOKEN */ && token.type === 3 /* RIGHT_PARENTHESIS_TOKEN */;
146};
147//# sourceMappingURL=parser.js.map
Note: See TracBrowser for help on using the repository browser.