@eslint/css-tree 3.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/LICENSE +20 -0
- package/README.md +194 -0
- package/cjs/convertor/create.cjs +32 -0
- package/cjs/convertor/index.cjs +8 -0
- package/cjs/data-patch.cjs +7 -0
- package/cjs/data.cjs +120 -0
- package/cjs/definition-syntax/SyntaxError.cjs +16 -0
- package/cjs/definition-syntax/generate.cjs +139 -0
- package/cjs/definition-syntax/index.cjs +13 -0
- package/cjs/definition-syntax/parse.cjs +556 -0
- package/cjs/definition-syntax/scanner.cjs +113 -0
- package/cjs/definition-syntax/walk.cjs +57 -0
- package/cjs/generator/create.cjs +102 -0
- package/cjs/generator/index.cjs +8 -0
- package/cjs/generator/sourceMap.cjs +96 -0
- package/cjs/generator/token-before.cjs +170 -0
- package/cjs/index.cjs +65 -0
- package/cjs/lexer/Lexer.cjs +517 -0
- package/cjs/lexer/error.cjs +128 -0
- package/cjs/lexer/generic-an-plus-b.cjs +235 -0
- package/cjs/lexer/generic-const.cjs +12 -0
- package/cjs/lexer/generic-urange.cjs +149 -0
- package/cjs/lexer/generic.cjs +589 -0
- package/cjs/lexer/index.cjs +7 -0
- package/cjs/lexer/match-graph.cjs +530 -0
- package/cjs/lexer/match.cjs +632 -0
- package/cjs/lexer/prepare-tokens.cjs +54 -0
- package/cjs/lexer/search.cjs +65 -0
- package/cjs/lexer/structure.cjs +173 -0
- package/cjs/lexer/trace.cjs +73 -0
- package/cjs/lexer/units.cjs +38 -0
- package/cjs/parser/SyntaxError.cjs +74 -0
- package/cjs/parser/create.cjs +378 -0
- package/cjs/parser/index.cjs +8 -0
- package/cjs/parser/parse-selector.cjs +8 -0
- package/cjs/parser/sequence.cjs +47 -0
- package/cjs/syntax/atrule/container.cjs +32 -0
- package/cjs/syntax/atrule/font-face.cjs +12 -0
- package/cjs/syntax/atrule/import.cjs +101 -0
- package/cjs/syntax/atrule/index.cjs +27 -0
- package/cjs/syntax/atrule/layer.cjs +16 -0
- package/cjs/syntax/atrule/media.cjs +16 -0
- package/cjs/syntax/atrule/nest.cjs +16 -0
- package/cjs/syntax/atrule/page.cjs +16 -0
- package/cjs/syntax/atrule/scope.cjs +16 -0
- package/cjs/syntax/atrule/starting-style.cjs +12 -0
- package/cjs/syntax/atrule/supports.cjs +16 -0
- package/cjs/syntax/config/generator.cjs +9 -0
- package/cjs/syntax/config/lexer.cjs +14 -0
- package/cjs/syntax/config/mix.cjs +126 -0
- package/cjs/syntax/config/parser-selector.cjs +19 -0
- package/cjs/syntax/config/parser.cjs +49 -0
- package/cjs/syntax/config/walker.cjs +9 -0
- package/cjs/syntax/create.cjs +58 -0
- package/cjs/syntax/function/expression.cjs +11 -0
- package/cjs/syntax/function/var.cjs +43 -0
- package/cjs/syntax/index.cjs +14 -0
- package/cjs/syntax/node/AnPlusB.cjs +293 -0
- package/cjs/syntax/node/Atrule.cjs +103 -0
- package/cjs/syntax/node/AtrulePrelude.cjs +52 -0
- package/cjs/syntax/node/AttributeSelector.cjs +148 -0
- package/cjs/syntax/node/Block.cjs +96 -0
- package/cjs/syntax/node/Brackets.cjs +38 -0
- package/cjs/syntax/node/CDC.cjs +26 -0
- package/cjs/syntax/node/CDO.cjs +26 -0
- package/cjs/syntax/node/ClassSelector.cjs +31 -0
- package/cjs/syntax/node/Combinator.cjs +61 -0
- package/cjs/syntax/node/Comment.cjs +40 -0
- package/cjs/syntax/node/Condition.cjs +120 -0
- package/cjs/syntax/node/Declaration.cjs +166 -0
- package/cjs/syntax/node/DeclarationList.cjs +62 -0
- package/cjs/syntax/node/Dimension.cjs +30 -0
- package/cjs/syntax/node/Feature.cjs +101 -0
- package/cjs/syntax/node/FeatureFunction.cjs +67 -0
- package/cjs/syntax/node/FeatureRange.cjs +133 -0
- package/cjs/syntax/node/Function.cjs +45 -0
- package/cjs/syntax/node/GeneralEnclosed.cjs +68 -0
- package/cjs/syntax/node/Hash.cjs +30 -0
- package/cjs/syntax/node/IdSelector.cjs +33 -0
- package/cjs/syntax/node/Identifier.cjs +25 -0
- package/cjs/syntax/node/Layer.cjs +35 -0
- package/cjs/syntax/node/LayerList.cjs +43 -0
- package/cjs/syntax/node/MediaQuery.cjs +100 -0
- package/cjs/syntax/node/MediaQueryList.cjs +41 -0
- package/cjs/syntax/node/NestingSelector.cjs +29 -0
- package/cjs/syntax/node/Nth.cjs +54 -0
- package/cjs/syntax/node/Number.cjs +25 -0
- package/cjs/syntax/node/Operator.cjs +28 -0
- package/cjs/syntax/node/Parentheses.cjs +38 -0
- package/cjs/syntax/node/Percentage.cjs +25 -0
- package/cjs/syntax/node/PseudoClassSelector.cjs +67 -0
- package/cjs/syntax/node/PseudoElementSelector.cjs +69 -0
- package/cjs/syntax/node/Ratio.cjs +71 -0
- package/cjs/syntax/node/Raw.cjs +48 -0
- package/cjs/syntax/node/Rule.cjs +58 -0
- package/cjs/syntax/node/Scope.cjs +69 -0
- package/cjs/syntax/node/Selector.cjs +38 -0
- package/cjs/syntax/node/SelectorList.cjs +43 -0
- package/cjs/syntax/node/String.cjs +26 -0
- package/cjs/syntax/node/StyleSheet.cjs +83 -0
- package/cjs/syntax/node/SupportsDeclaration.cjs +38 -0
- package/cjs/syntax/node/TypeSelector.cjs +59 -0
- package/cjs/syntax/node/UnicodeRange.cjs +158 -0
- package/cjs/syntax/node/Url.cjs +54 -0
- package/cjs/syntax/node/Value.cjs +26 -0
- package/cjs/syntax/node/WhiteSpace.cjs +34 -0
- package/cjs/syntax/node/index-generate.cjs +103 -0
- package/cjs/syntax/node/index-parse-selector.cjs +39 -0
- package/cjs/syntax/node/index-parse.cjs +103 -0
- package/cjs/syntax/node/index.cjs +103 -0
- package/cjs/syntax/pseudo/index.cjs +60 -0
- package/cjs/syntax/pseudo/lang.cjs +37 -0
- package/cjs/syntax/scope/atrulePrelude.cjs +9 -0
- package/cjs/syntax/scope/default.cjs +76 -0
- package/cjs/syntax/scope/index.cjs +11 -0
- package/cjs/syntax/scope/selector.cjs +88 -0
- package/cjs/syntax/scope/value.cjs +29 -0
- package/cjs/tokenizer/OffsetToLocation.cjs +91 -0
- package/cjs/tokenizer/TokenStream.cjs +358 -0
- package/cjs/tokenizer/adopt-buffer.cjs +13 -0
- package/cjs/tokenizer/char-code-definitions.cjs +236 -0
- package/cjs/tokenizer/index.cjs +554 -0
- package/cjs/tokenizer/names.cjs +32 -0
- package/cjs/tokenizer/types.cjs +57 -0
- package/cjs/tokenizer/utils.cjs +261 -0
- package/cjs/utils/List.cjs +473 -0
- package/cjs/utils/clone.cjs +25 -0
- package/cjs/utils/create-custom-error.cjs +18 -0
- package/cjs/utils/ident.cjs +102 -0
- package/cjs/utils/index.cjs +20 -0
- package/cjs/utils/names.cjs +113 -0
- package/cjs/utils/string.cjs +99 -0
- package/cjs/utils/url.cjs +108 -0
- package/cjs/version.cjs +5 -0
- package/cjs/walker/create.cjs +291 -0
- package/cjs/walker/index.cjs +8 -0
- package/data/patch.json +874 -0
- package/dist/csstree.esm.js +12 -0
- package/dist/csstree.js +12 -0
- package/dist/data.cjs +1341 -0
- package/dist/data.js +1341 -0
- package/dist/version.cjs +1 -0
- package/dist/version.js +1 -0
- package/lib/convertor/create.js +28 -0
- package/lib/convertor/index.js +4 -0
- package/lib/data-patch.js +6 -0
- package/lib/data.js +118 -0
- package/lib/definition-syntax/SyntaxError.js +12 -0
- package/lib/definition-syntax/generate.js +135 -0
- package/lib/definition-syntax/index.js +4 -0
- package/lib/definition-syntax/parse.js +552 -0
- package/lib/definition-syntax/scanner.js +109 -0
- package/lib/definition-syntax/walk.js +53 -0
- package/lib/generator/create.js +97 -0
- package/lib/generator/index.js +4 -0
- package/lib/generator/sourceMap.js +92 -0
- package/lib/generator/token-before.js +182 -0
- package/lib/index.d.ts +3016 -0
- package/lib/index.js +30 -0
- package/lib/lexer/Lexer.js +511 -0
- package/lib/lexer/error.js +123 -0
- package/lib/lexer/generic-an-plus-b.js +238 -0
- package/lib/lexer/generic-const.js +8 -0
- package/lib/lexer/generic-urange.js +151 -0
- package/lib/lexer/generic.js +622 -0
- package/lib/lexer/index.js +1 -0
- package/lib/lexer/match-graph.js +527 -0
- package/lib/lexer/match.js +630 -0
- package/lib/lexer/prepare-tokens.js +50 -0
- package/lib/lexer/search.js +61 -0
- package/lib/lexer/structure.js +169 -0
- package/lib/lexer/trace.js +66 -0
- package/lib/lexer/units.js +27 -0
- package/lib/parser/SyntaxError.js +70 -0
- package/lib/parser/create.js +388 -0
- package/lib/parser/index.js +4 -0
- package/lib/parser/parse-selector.js +4 -0
- package/lib/parser/sequence.js +43 -0
- package/lib/syntax/atrule/container.js +28 -0
- package/lib/syntax/atrule/font-face.js +8 -0
- package/lib/syntax/atrule/import.js +104 -0
- package/lib/syntax/atrule/index.js +23 -0
- package/lib/syntax/atrule/layer.js +12 -0
- package/lib/syntax/atrule/media.js +12 -0
- package/lib/syntax/atrule/nest.js +12 -0
- package/lib/syntax/atrule/page.js +12 -0
- package/lib/syntax/atrule/scope.js +12 -0
- package/lib/syntax/atrule/starting-style.js +8 -0
- package/lib/syntax/atrule/supports.js +12 -0
- package/lib/syntax/config/generator.js +5 -0
- package/lib/syntax/config/lexer.js +10 -0
- package/lib/syntax/config/mix.js +122 -0
- package/lib/syntax/config/parser-selector.js +15 -0
- package/lib/syntax/config/parser.js +45 -0
- package/lib/syntax/config/walker.js +5 -0
- package/lib/syntax/create.js +55 -0
- package/lib/syntax/function/expression.js +7 -0
- package/lib/syntax/function/var.js +39 -0
- package/lib/syntax/index.js +10 -0
- package/lib/syntax/node/AnPlusB.js +292 -0
- package/lib/syntax/node/Atrule.js +100 -0
- package/lib/syntax/node/AtrulePrelude.js +47 -0
- package/lib/syntax/node/AttributeSelector.js +147 -0
- package/lib/syntax/node/Block.js +95 -0
- package/lib/syntax/node/Brackets.js +35 -0
- package/lib/syntax/node/CDC.js +19 -0
- package/lib/syntax/node/CDO.js +19 -0
- package/lib/syntax/node/ClassSelector.js +24 -0
- package/lib/syntax/node/Combinator.js +54 -0
- package/lib/syntax/node/Comment.js +33 -0
- package/lib/syntax/node/Condition.js +123 -0
- package/lib/syntax/node/Declaration.js +165 -0
- package/lib/syntax/node/DeclarationList.js +62 -0
- package/lib/syntax/node/Dimension.js +23 -0
- package/lib/syntax/node/Feature.js +103 -0
- package/lib/syntax/node/FeatureFunction.js +63 -0
- package/lib/syntax/node/FeatureRange.js +133 -0
- package/lib/syntax/node/Function.js +41 -0
- package/lib/syntax/node/GeneralEnclosed.js +66 -0
- package/lib/syntax/node/Hash.js +23 -0
- package/lib/syntax/node/IdSelector.js +26 -0
- package/lib/syntax/node/Identifier.js +18 -0
- package/lib/syntax/node/Layer.js +28 -0
- package/lib/syntax/node/LayerList.js +36 -0
- package/lib/syntax/node/MediaQuery.js +102 -0
- package/lib/syntax/node/MediaQueryList.js +34 -0
- package/lib/syntax/node/NestingSelector.js +22 -0
- package/lib/syntax/node/Nth.js +47 -0
- package/lib/syntax/node/Number.js +18 -0
- package/lib/syntax/node/Operator.js +21 -0
- package/lib/syntax/node/Parentheses.js +34 -0
- package/lib/syntax/node/Percentage.js +18 -0
- package/lib/syntax/node/PseudoClassSelector.js +65 -0
- package/lib/syntax/node/PseudoElementSelector.js +66 -0
- package/lib/syntax/node/Ratio.js +68 -0
- package/lib/syntax/node/Raw.js +41 -0
- package/lib/syntax/node/Rule.js +51 -0
- package/lib/syntax/node/Scope.js +66 -0
- package/lib/syntax/node/Selector.js +31 -0
- package/lib/syntax/node/SelectorList.js +35 -0
- package/lib/syntax/node/String.js +19 -0
- package/lib/syntax/node/StyleSheet.js +82 -0
- package/lib/syntax/node/SupportsDeclaration.js +34 -0
- package/lib/syntax/node/TypeSelector.js +52 -0
- package/lib/syntax/node/UnicodeRange.js +156 -0
- package/lib/syntax/node/Url.js +52 -0
- package/lib/syntax/node/Value.js +19 -0
- package/lib/syntax/node/WhiteSpace.js +27 -0
- package/lib/syntax/node/index-generate.js +49 -0
- package/lib/syntax/node/index-parse-selector.js +17 -0
- package/lib/syntax/node/index-parse.js +49 -0
- package/lib/syntax/node/index.js +49 -0
- package/lib/syntax/pseudo/index.js +56 -0
- package/lib/syntax/pseudo/lang.js +33 -0
- package/lib/syntax/scope/atrulePrelude.js +5 -0
- package/lib/syntax/scope/default.js +85 -0
- package/lib/syntax/scope/index.js +3 -0
- package/lib/syntax/scope/selector.js +94 -0
- package/lib/syntax/scope/value.js +25 -0
- package/lib/tokenizer/OffsetToLocation.js +87 -0
- package/lib/tokenizer/TokenStream.js +366 -0
- package/lib/tokenizer/adopt-buffer.js +9 -0
- package/lib/tokenizer/char-code-definitions.js +212 -0
- package/lib/tokenizer/index.js +513 -0
- package/lib/tokenizer/names.js +28 -0
- package/lib/tokenizer/types.js +28 -0
- package/lib/tokenizer/utils.js +254 -0
- package/lib/utils/List.js +469 -0
- package/lib/utils/clone.js +21 -0
- package/lib/utils/create-custom-error.js +14 -0
- package/lib/utils/ident.js +101 -0
- package/lib/utils/index.js +6 -0
- package/lib/utils/names.js +106 -0
- package/lib/utils/string.js +99 -0
- package/lib/utils/url.js +108 -0
- package/lib/version.js +5 -0
- package/lib/walker/create.js +287 -0
- package/lib/walker/index.js +4 -0
- package/package.json +133 -0
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const charCodeDefinitions = require('../tokenizer/char-code-definitions.cjs');
|
|
4
|
+
const types = require('../tokenizer/types.cjs');
|
|
5
|
+
const utils = require('../tokenizer/utils.cjs');
|
|
6
|
+
|
|
7
|
+
const PLUSSIGN = 0x002B; // U+002B PLUS SIGN (+)
|
|
8
|
+
const HYPHENMINUS = 0x002D; // U+002D HYPHEN-MINUS (-)
|
|
9
|
+
const N = 0x006E; // U+006E LATIN SMALL LETTER N (n)
|
|
10
|
+
const DISALLOW_SIGN = true;
|
|
11
|
+
const ALLOW_SIGN = false;
|
|
12
|
+
|
|
13
|
+
function isDelim(token, code) {
|
|
14
|
+
return token !== null && token.type === types.Delim && token.value.charCodeAt(0) === code;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function skipSC(token, offset, getNextToken) {
|
|
18
|
+
while (token !== null && (token.type === types.WhiteSpace || token.type === types.Comment)) {
|
|
19
|
+
token = getNextToken(++offset);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return offset;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function checkInteger(token, valueOffset, disallowSign, offset) {
|
|
26
|
+
if (!token) {
|
|
27
|
+
return 0;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const code = token.value.charCodeAt(valueOffset);
|
|
31
|
+
|
|
32
|
+
if (code === PLUSSIGN || code === HYPHENMINUS) {
|
|
33
|
+
if (disallowSign) {
|
|
34
|
+
// Number sign is not allowed
|
|
35
|
+
return 0;
|
|
36
|
+
}
|
|
37
|
+
valueOffset++;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
for (; valueOffset < token.value.length; valueOffset++) {
|
|
41
|
+
if (!charCodeDefinitions.isDigit(token.value.charCodeAt(valueOffset))) {
|
|
42
|
+
// Integer is expected
|
|
43
|
+
return 0;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return offset + 1;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// ... <signed-integer>
|
|
51
|
+
// ... ['+' | '-'] <signless-integer>
|
|
52
|
+
function consumeB(token, offset_, getNextToken) {
|
|
53
|
+
let sign = false;
|
|
54
|
+
let offset = skipSC(token, offset_, getNextToken);
|
|
55
|
+
|
|
56
|
+
token = getNextToken(offset);
|
|
57
|
+
|
|
58
|
+
if (token === null) {
|
|
59
|
+
return offset_;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (token.type !== types.Number) {
|
|
63
|
+
if (isDelim(token, PLUSSIGN) || isDelim(token, HYPHENMINUS)) {
|
|
64
|
+
sign = true;
|
|
65
|
+
offset = skipSC(getNextToken(++offset), offset, getNextToken);
|
|
66
|
+
token = getNextToken(offset);
|
|
67
|
+
|
|
68
|
+
if (token === null || token.type !== types.Number) {
|
|
69
|
+
return 0;
|
|
70
|
+
}
|
|
71
|
+
} else {
|
|
72
|
+
return offset_;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (!sign) {
|
|
77
|
+
const code = token.value.charCodeAt(0);
|
|
78
|
+
if (code !== PLUSSIGN && code !== HYPHENMINUS) {
|
|
79
|
+
// Number sign is expected
|
|
80
|
+
return 0;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return checkInteger(token, sign ? 0 : 1, sign, offset);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// An+B microsyntax https://www.w3.org/TR/css-syntax-3/#anb
|
|
88
|
+
function anPlusB(token, getNextToken) {
|
|
89
|
+
/* eslint-disable brace-style*/
|
|
90
|
+
let offset = 0;
|
|
91
|
+
|
|
92
|
+
if (!token) {
|
|
93
|
+
return 0;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// <integer>
|
|
97
|
+
if (token.type === types.Number) {
|
|
98
|
+
return checkInteger(token, 0, ALLOW_SIGN, offset); // b
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// -n
|
|
102
|
+
// -n <signed-integer>
|
|
103
|
+
// -n ['+' | '-'] <signless-integer>
|
|
104
|
+
// -n- <signless-integer>
|
|
105
|
+
// <dashndashdigit-ident>
|
|
106
|
+
else if (token.type === types.Ident && token.value.charCodeAt(0) === HYPHENMINUS) {
|
|
107
|
+
// expect 1st char is N
|
|
108
|
+
if (!utils.cmpChar(token.value, 1, N)) {
|
|
109
|
+
return 0;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
switch (token.value.length) {
|
|
113
|
+
// -n
|
|
114
|
+
// -n <signed-integer>
|
|
115
|
+
// -n ['+' | '-'] <signless-integer>
|
|
116
|
+
case 2:
|
|
117
|
+
return consumeB(getNextToken(++offset), offset, getNextToken);
|
|
118
|
+
|
|
119
|
+
// -n- <signless-integer>
|
|
120
|
+
case 3:
|
|
121
|
+
if (token.value.charCodeAt(2) !== HYPHENMINUS) {
|
|
122
|
+
return 0;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
offset = skipSC(getNextToken(++offset), offset, getNextToken);
|
|
126
|
+
token = getNextToken(offset);
|
|
127
|
+
|
|
128
|
+
return checkInteger(token, 0, DISALLOW_SIGN, offset);
|
|
129
|
+
|
|
130
|
+
// <dashndashdigit-ident>
|
|
131
|
+
default:
|
|
132
|
+
if (token.value.charCodeAt(2) !== HYPHENMINUS) {
|
|
133
|
+
return 0;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return checkInteger(token, 3, DISALLOW_SIGN, offset);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// '+'? n
|
|
141
|
+
// '+'? n <signed-integer>
|
|
142
|
+
// '+'? n ['+' | '-'] <signless-integer>
|
|
143
|
+
// '+'? n- <signless-integer>
|
|
144
|
+
// '+'? <ndashdigit-ident>
|
|
145
|
+
else if (token.type === types.Ident || (isDelim(token, PLUSSIGN) && getNextToken(offset + 1).type === types.Ident)) {
|
|
146
|
+
// just ignore a plus
|
|
147
|
+
if (token.type !== types.Ident) {
|
|
148
|
+
token = getNextToken(++offset);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (token === null || !utils.cmpChar(token.value, 0, N)) {
|
|
152
|
+
return 0;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
switch (token.value.length) {
|
|
156
|
+
// '+'? n
|
|
157
|
+
// '+'? n <signed-integer>
|
|
158
|
+
// '+'? n ['+' | '-'] <signless-integer>
|
|
159
|
+
case 1:
|
|
160
|
+
return consumeB(getNextToken(++offset), offset, getNextToken);
|
|
161
|
+
|
|
162
|
+
// '+'? n- <signless-integer>
|
|
163
|
+
case 2:
|
|
164
|
+
if (token.value.charCodeAt(1) !== HYPHENMINUS) {
|
|
165
|
+
return 0;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
offset = skipSC(getNextToken(++offset), offset, getNextToken);
|
|
169
|
+
token = getNextToken(offset);
|
|
170
|
+
|
|
171
|
+
return checkInteger(token, 0, DISALLOW_SIGN, offset);
|
|
172
|
+
|
|
173
|
+
// '+'? <ndashdigit-ident>
|
|
174
|
+
default:
|
|
175
|
+
if (token.value.charCodeAt(1) !== HYPHENMINUS) {
|
|
176
|
+
return 0;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return checkInteger(token, 2, DISALLOW_SIGN, offset);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// <ndashdigit-dimension>
|
|
184
|
+
// <ndash-dimension> <signless-integer>
|
|
185
|
+
// <n-dimension>
|
|
186
|
+
// <n-dimension> <signed-integer>
|
|
187
|
+
// <n-dimension> ['+' | '-'] <signless-integer>
|
|
188
|
+
else if (token.type === types.Dimension) {
|
|
189
|
+
let code = token.value.charCodeAt(0);
|
|
190
|
+
let sign = code === PLUSSIGN || code === HYPHENMINUS ? 1 : 0;
|
|
191
|
+
let i = sign;
|
|
192
|
+
|
|
193
|
+
for (; i < token.value.length; i++) {
|
|
194
|
+
if (!charCodeDefinitions.isDigit(token.value.charCodeAt(i))) {
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (i === sign) {
|
|
200
|
+
// Integer is expected
|
|
201
|
+
return 0;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (!utils.cmpChar(token.value, i, N)) {
|
|
205
|
+
return 0;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// <n-dimension>
|
|
209
|
+
// <n-dimension> <signed-integer>
|
|
210
|
+
// <n-dimension> ['+' | '-'] <signless-integer>
|
|
211
|
+
if (i + 1 === token.value.length) {
|
|
212
|
+
return consumeB(getNextToken(++offset), offset, getNextToken);
|
|
213
|
+
} else {
|
|
214
|
+
if (token.value.charCodeAt(i + 1) !== HYPHENMINUS) {
|
|
215
|
+
return 0;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// <ndash-dimension> <signless-integer>
|
|
219
|
+
if (i + 2 === token.value.length) {
|
|
220
|
+
offset = skipSC(getNextToken(++offset), offset, getNextToken);
|
|
221
|
+
token = getNextToken(offset);
|
|
222
|
+
|
|
223
|
+
return checkInteger(token, 0, DISALLOW_SIGN, offset);
|
|
224
|
+
}
|
|
225
|
+
// <ndashdigit-dimension>
|
|
226
|
+
else {
|
|
227
|
+
return checkInteger(token, i + 2, DISALLOW_SIGN, offset);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
return 0;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
module.exports = anPlusB;
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const charCodeDefinitions = require('../tokenizer/char-code-definitions.cjs');
|
|
4
|
+
const types = require('../tokenizer/types.cjs');
|
|
5
|
+
const utils = require('../tokenizer/utils.cjs');
|
|
6
|
+
|
|
7
|
+
const PLUSSIGN = 0x002B; // U+002B PLUS SIGN (+)
|
|
8
|
+
const HYPHENMINUS = 0x002D; // U+002D HYPHEN-MINUS (-)
|
|
9
|
+
const QUESTIONMARK = 0x003F; // U+003F QUESTION MARK (?)
|
|
10
|
+
const U = 0x0075; // U+0075 LATIN SMALL LETTER U (u)
|
|
11
|
+
|
|
12
|
+
function isDelim(token, code) {
|
|
13
|
+
return token !== null && token.type === types.Delim && token.value.charCodeAt(0) === code;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function startsWith(token, code) {
|
|
17
|
+
return token.value.charCodeAt(0) === code;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function hexSequence(token, offset, allowDash) {
|
|
21
|
+
let hexlen = 0;
|
|
22
|
+
|
|
23
|
+
for (let pos = offset; pos < token.value.length; pos++) {
|
|
24
|
+
const code = token.value.charCodeAt(pos);
|
|
25
|
+
|
|
26
|
+
if (code === HYPHENMINUS && allowDash && hexlen !== 0) {
|
|
27
|
+
hexSequence(token, offset + hexlen + 1, false);
|
|
28
|
+
return 6; // dissallow following question marks
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (!charCodeDefinitions.isHexDigit(code)) {
|
|
32
|
+
return 0; // not a hex digit
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (++hexlen > 6) {
|
|
36
|
+
return 0; // too many hex digits
|
|
37
|
+
} }
|
|
38
|
+
|
|
39
|
+
return hexlen;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function withQuestionMarkSequence(consumed, length, getNextToken) {
|
|
43
|
+
if (!consumed) {
|
|
44
|
+
return 0; // nothing consumed
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
while (isDelim(getNextToken(length), QUESTIONMARK)) {
|
|
48
|
+
if (++consumed > 6) {
|
|
49
|
+
return 0; // too many question marks
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
length++;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return length;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// https://drafts.csswg.org/css-syntax/#urange
|
|
59
|
+
// Informally, the <urange> production has three forms:
|
|
60
|
+
// U+0001
|
|
61
|
+
// Defines a range consisting of a single code point, in this case the code point "1".
|
|
62
|
+
// U+0001-00ff
|
|
63
|
+
// Defines a range of codepoints between the first and the second value, in this case
|
|
64
|
+
// the range between "1" and "ff" (255 in decimal) inclusive.
|
|
65
|
+
// U+00??
|
|
66
|
+
// Defines a range of codepoints where the "?" characters range over all hex digits,
|
|
67
|
+
// in this case defining the same as the value U+0000-00ff.
|
|
68
|
+
// In each form, a maximum of 6 digits is allowed for each hexadecimal number (if you treat "?" as a hexadecimal digit).
|
|
69
|
+
//
|
|
70
|
+
// <urange> =
|
|
71
|
+
// u '+' <ident-token> '?'* |
|
|
72
|
+
// u <dimension-token> '?'* |
|
|
73
|
+
// u <number-token> '?'* |
|
|
74
|
+
// u <number-token> <dimension-token> |
|
|
75
|
+
// u <number-token> <number-token> |
|
|
76
|
+
// u '+' '?'+
|
|
77
|
+
function urange(token, getNextToken) {
|
|
78
|
+
let length = 0;
|
|
79
|
+
|
|
80
|
+
// should start with `u` or `U`
|
|
81
|
+
if (token === null || token.type !== types.Ident || !utils.cmpChar(token.value, 0, U)) {
|
|
82
|
+
return 0;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
token = getNextToken(++length);
|
|
86
|
+
if (token === null) {
|
|
87
|
+
return 0;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// u '+' <ident-token> '?'*
|
|
91
|
+
// u '+' '?'+
|
|
92
|
+
if (isDelim(token, PLUSSIGN)) {
|
|
93
|
+
token = getNextToken(++length);
|
|
94
|
+
if (token === null) {
|
|
95
|
+
return 0;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (token.type === types.Ident) {
|
|
99
|
+
// u '+' <ident-token> '?'*
|
|
100
|
+
return withQuestionMarkSequence(hexSequence(token, 0, true), ++length, getNextToken);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (isDelim(token, QUESTIONMARK)) {
|
|
104
|
+
// u '+' '?'+
|
|
105
|
+
return withQuestionMarkSequence(1, ++length, getNextToken);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Hex digit or question mark is expected
|
|
109
|
+
return 0;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// u <number-token> '?'*
|
|
113
|
+
// u <number-token> <dimension-token>
|
|
114
|
+
// u <number-token> <number-token>
|
|
115
|
+
if (token.type === types.Number) {
|
|
116
|
+
const consumedHexLength = hexSequence(token, 1, true);
|
|
117
|
+
if (consumedHexLength === 0) {
|
|
118
|
+
return 0;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
token = getNextToken(++length);
|
|
122
|
+
if (token === null) {
|
|
123
|
+
// u <number-token> <eof>
|
|
124
|
+
return length;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (token.type === types.Dimension || token.type === types.Number) {
|
|
128
|
+
// u <number-token> <dimension-token>
|
|
129
|
+
// u <number-token> <number-token>
|
|
130
|
+
if (!startsWith(token, HYPHENMINUS) || !hexSequence(token, 1, false)) {
|
|
131
|
+
return 0;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return length + 1;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// u <number-token> '?'*
|
|
138
|
+
return withQuestionMarkSequence(consumedHexLength, length, getNextToken);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// u <dimension-token> '?'*
|
|
142
|
+
if (token.type === types.Dimension) {
|
|
143
|
+
return withQuestionMarkSequence(hexSequence(token, 1, true), ++length, getNextToken);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return 0;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
module.exports = urange;
|