@tbela99/css-parser 2.0.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/CHANGELOG.md +86 -1
- package/README.md +15 -7
- package/architecture.png +0 -0
- package/dist/{src/data → data}/properties.json.js +86 -2
- package/dist/{src/data → data}/validation.json.js +4848 -3750
- package/dist/index-umd-web.js +18234 -9498
- package/dist/index.d.ts +1251 -373
- package/dist/{src/lib → lib}/ast/arena-node.js +119 -57
- package/dist/{src/lib → lib}/ast/arena.js +1034 -655
- package/dist/{src/lib → lib}/ast/cache.js +36 -31
- package/dist/{src/lib → lib}/ast/features/calc.js +37 -27
- package/dist/{src/lib → lib}/ast/features/if.js +24 -19
- package/dist/{src/lib → lib}/ast/features/index.js +3 -2
- package/dist/{src/lib → lib}/ast/features/inlinecssvariables.js +42 -23
- package/dist/lib/ast/features/mixin.js +953 -0
- package/dist/{src/lib → lib}/ast/features/prefix.js +82 -69
- package/dist/lib/ast/features/shorthand.js +129 -0
- package/dist/lib/ast/features/transform.js +188 -0
- package/dist/{src/lib → lib}/ast/features/type.js +2 -2
- package/dist/{src/lib → lib}/ast/math/expression.js +150 -150
- package/dist/{src/lib → lib}/ast/math/math.js +8 -8
- package/dist/{src/lib → lib}/ast/minify.js +932 -354
- package/dist/lib/ast/mixins/custom-function.js +393 -0
- package/dist/lib/ast/mixins/utils.js +53 -0
- package/dist/lib/ast/mixins/variables.js +678 -0
- package/dist/lib/ast/strings.js +906 -0
- package/dist/lib/ast/transform/compute.js +560 -0
- package/dist/lib/ast/transform/matrix.js +67 -0
- package/dist/lib/ast/transform/minify.js +325 -0
- package/dist/lib/ast/transform/perspective.js +24 -0
- package/dist/{src/lib → lib}/ast/transform/rotate.js +16 -7
- package/dist/lib/ast/transform/scale.js +43 -0
- package/dist/lib/ast/transform/skew.js +38 -0
- package/dist/lib/ast/transform/translate.js +56 -0
- package/dist/lib/ast/transform/utils.js +390 -0
- package/dist/{src/lib → lib}/ast/types.js +7 -15
- package/dist/{src/lib → lib}/ast/walk.js +19 -19
- package/dist/{src/lib → lib}/fs/resolve.js +15 -15
- package/dist/{src/lib → lib}/parser/declaration/list.js +55 -26
- package/dist/{src/lib → lib}/parser/declaration/map.js +85 -72
- package/dist/{src/lib → lib}/parser/declaration/set.js +32 -27
- package/dist/lib/parser/input.js +85 -0
- package/dist/{src/lib → lib}/parser/linesmap.js +3 -16
- package/dist/{src/lib → lib}/parser/parse.js +852 -619
- package/dist/lib/parser/source.js +71 -0
- package/dist/{src/lib → lib}/parser/tokenize.js +886 -722
- package/dist/{src/lib → lib}/parser/utils/angle.js +3 -3
- package/dist/{src/lib → lib}/parser/utils/at-rule-container.js +68 -35
- package/dist/{src/lib → lib}/parser/utils/at-rule-font-feature-values.js +3 -3
- package/dist/{src/lib → lib}/parser/utils/at-rule-generic.js +31 -13
- package/dist/{src/lib → lib}/parser/utils/at-rule-import.js +29 -16
- package/dist/{src/lib → lib}/parser/utils/at-rule-media.js +77 -58
- package/dist/{src/lib → lib}/parser/utils/at-rule-support.js +18 -20
- package/dist/{src/lib → lib}/parser/utils/at-rule-when-else.js +9 -8
- package/dist/{src/lib → lib}/parser/utils/at-rule.js +3 -3
- package/dist/{src/lib → lib}/parser/utils/base64.js +2 -2
- package/dist/lib/parser/utils/cache.js +53 -0
- package/dist/lib/parser/utils/canonical.js +78 -0
- package/dist/lib/parser/utils/codes.js +93 -0
- package/dist/{src/lib → lib}/parser/utils/config.js +2 -2
- package/dist/{src/lib → lib}/parser/utils/declaration.js +67 -49
- package/dist/{src/lib → lib}/parser/utils/eq.js +14 -14
- package/dist/{src/lib → lib}/parser/utils/hash.js +4 -4
- package/dist/lib/parser/utils/selector.js +720 -0
- package/dist/{src/lib → lib}/parser/utils/text.js +2 -2
- package/dist/{src/lib → lib}/parser/utils/token.js +2 -2
- package/dist/{src/lib → lib}/parser/utils/type.js +11 -9
- package/dist/{src/lib → lib}/printer/render.js +536 -243
- package/dist/lib/printer/result.js +148 -0
- package/dist/{src/lib → lib}/printer/sourcemap/lib/codec.js +5 -8
- package/dist/{src/lib → lib}/printer/sourcemap/sourcemap.js +13 -13
- package/dist/lib/printer/writer.js +252 -0
- package/dist/{src/lib → lib}/syntax/color/a98rgb.js +6 -6
- package/dist/{src/lib → lib}/syntax/color/alpha.js +12 -11
- package/dist/{src/lib → lib}/syntax/color/cmyk.js +11 -6
- package/dist/{src/lib → lib}/syntax/color/color-mix.js +78 -67
- package/dist/{src/lib → lib}/syntax/color/color.js +52 -47
- package/dist/{src/lib → lib}/syntax/color/hex.js +17 -17
- package/dist/{src/lib → lib}/syntax/color/hsl.js +8 -8
- package/dist/{src/lib → lib}/syntax/color/hwb.js +6 -7
- package/dist/{src/lib → lib}/syntax/color/lab.js +8 -8
- package/dist/{src/lib → lib}/syntax/color/lch.js +12 -11
- package/dist/{src/lib → lib}/syntax/color/oklab.js +9 -9
- package/dist/{src/lib → lib}/syntax/color/oklch.js +5 -5
- package/dist/{src/lib → lib}/syntax/color/p3.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/prophotorgb.js +4 -4
- package/dist/{src/lib → lib}/syntax/color/rec2020.js +3 -3
- package/dist/{src/lib → lib}/syntax/color/relative-color.js +41 -34
- package/dist/{src/lib → lib}/syntax/color/rgb.js +17 -17
- package/dist/{src/lib → lib}/syntax/color/srgb.js +20 -20
- package/dist/{src/lib → lib}/syntax/color/utils/color-type.js +6 -4
- package/dist/{src/lib → lib}/syntax/color/utils/colorspace.js +12 -14
- package/dist/{src/lib → lib}/syntax/color/utils/components.js +13 -13
- package/dist/{src/lib → lib}/syntax/color/utils/distance.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/utils/make-color.js +6 -4
- package/dist/{src/lib → lib}/syntax/color/utils/matrix.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/xyz.js +5 -10
- package/dist/{src/lib → lib}/syntax/color/xyzd50.js +3 -3
- package/dist/{src/lib → lib}/syntax/constants.js +30 -3
- package/dist/{src/lib → lib}/syntax/syntax.js +151 -116
- package/dist/lib/validation/config.js +173 -0
- package/dist/lib/validation/first.js +571 -0
- package/dist/{src/lib → lib}/validation/match.js +1256 -579
- package/dist/{src/lib → lib}/validation/parser/parse.js +85 -59
- package/dist/{src/lib → lib}/validation/parser/typedef.js +6 -2
- package/dist/{src/lib → lib}/validation/utils/list.js +3 -19
- package/dist/{src/node.js → node.js} +92 -80
- package/dist/{src/types.js → types.js} +2 -2
- package/dist/{src/utils → utils}/sync.js +13 -8
- package/dist/version.d.ts +4 -0
- package/dist/version.js +13 -0
- package/dist/{src/web.js → web.js} +80 -75
- package/package.json +13 -13
- package/dist/package.json.js +0 -10
- package/dist/src/lib/ast/features/shorthand.js +0 -87
- package/dist/src/lib/ast/features/transform.js +0 -85
- package/dist/src/lib/ast/transform/compute.js +0 -358
- package/dist/src/lib/ast/transform/matrix.js +0 -88
- package/dist/src/lib/ast/transform/minify.js +0 -267
- package/dist/src/lib/ast/transform/perspective.js +0 -16
- package/dist/src/lib/ast/transform/scale.js +0 -39
- package/dist/src/lib/ast/transform/skew.js +0 -30
- package/dist/src/lib/ast/transform/translate.js +0 -39
- package/dist/src/lib/ast/transform/utils.js +0 -287
- package/dist/src/lib/parser/source.js +0 -127
- package/dist/src/lib/parser/utils/cache.js +0 -54
- package/dist/src/lib/parser/utils/selector.js +0 -440
- package/dist/src/lib/validation/config.js +0 -120
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/*
|
|
2
|
-
CSS parser, minifier and validator for node and the browser
|
|
2
|
+
CSS parser, minifier and validator for node, deno, bun and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version: 2.0
|
|
5
|
+
Version: 2.2.0
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { PropertySet } from './set.js';
|
|
9
9
|
import { getConfig } from '../utils/config.js';
|
|
10
10
|
import { PropertyMap } from './map.js';
|
|
11
|
-
import {
|
|
11
|
+
import { EnumToken, EnumAstNodeStatus } from '../../ast/types.js';
|
|
12
12
|
import { getParsedSyntax } from '../../validation/config.js';
|
|
13
13
|
import { ValidationSyntaxGroupEnum } from '../../validation/parser/typedef.js';
|
|
14
14
|
import { isValidDeclarationValue } from '../../validation/match.js';
|
|
@@ -74,6 +74,20 @@ class DeclarationMemo {
|
|
|
74
74
|
return key;
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* true if the value of a declaration contains var(), env() or if()
|
|
79
|
+
* @param arena
|
|
80
|
+
* @param declaration
|
|
81
|
+
*/
|
|
82
|
+
function hasWildCardFunction(arena, declaration) {
|
|
83
|
+
for (const token of arena.tokens(declaration)) {
|
|
84
|
+
if (arena.dataTypes[token] === EnumToken.WildCardFunctionTokenType ||
|
|
85
|
+
arena.dataTypes[token] === EnumToken.WildCardFunctionTokenDefType) {
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
77
91
|
/**
|
|
78
92
|
* Represents a list of property declarations, compute shorthand and remove duplicate declarations.
|
|
79
93
|
*/
|
|
@@ -94,28 +108,24 @@ class PropertyList {
|
|
|
94
108
|
* keys shared by the lists that use the same arena
|
|
95
109
|
*/
|
|
96
110
|
memo;
|
|
111
|
+
/**
|
|
112
|
+
* syntaxes of the descriptors of the at-rule that contains the declarations: `result` in `@function`. the
|
|
113
|
+
* declarations that are not validated are validated with them
|
|
114
|
+
*/
|
|
115
|
+
descriptors;
|
|
97
116
|
/**
|
|
98
117
|
*
|
|
99
118
|
* @param arena
|
|
100
119
|
* @param options
|
|
101
120
|
* @param memo keys shared by the lists that use the same arena
|
|
121
|
+
* @param descriptors syntaxes of the descriptors of the at-rule that contains the declarations
|
|
102
122
|
*/
|
|
103
|
-
constructor(arena, options = {}, memo = null) {
|
|
123
|
+
constructor(arena, options = {}, memo = null, descriptors = null) {
|
|
104
124
|
this.arena = arena;
|
|
105
125
|
this.options = options;
|
|
106
126
|
this.declarations = new Map();
|
|
107
127
|
this.memo = memo ?? new DeclarationMemo();
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* add declarations
|
|
111
|
-
* @param declarations node ids
|
|
112
|
-
* @returns
|
|
113
|
-
*/
|
|
114
|
-
add(declarations) {
|
|
115
|
-
for (const declaration of declarations) {
|
|
116
|
-
this.addDeclaration(declaration);
|
|
117
|
-
}
|
|
118
|
-
return this;
|
|
128
|
+
this.descriptors = descriptors;
|
|
119
129
|
}
|
|
120
130
|
/**
|
|
121
131
|
* add a declaration
|
|
@@ -126,9 +136,9 @@ class PropertyList {
|
|
|
126
136
|
let syntaxRules = null;
|
|
127
137
|
const arena = this.arena;
|
|
128
138
|
name =
|
|
129
|
-
arena.dataTypes[declaration]
|
|
139
|
+
arena.dataTypes[declaration] !== EnumToken.DeclarationNodeType
|
|
130
140
|
? null
|
|
131
|
-
: arena.
|
|
141
|
+
: arena.resolveString(arena.name[declaration]);
|
|
132
142
|
// do not compute shorthand for invalid declarations
|
|
133
143
|
if (name == null) {
|
|
134
144
|
this.declarations.set(this.memo.key(arena, declaration), declaration);
|
|
@@ -159,7 +169,9 @@ class PropertyList {
|
|
|
159
169
|
return this;
|
|
160
170
|
}
|
|
161
171
|
if (arena.flags[declaration] & EnumAstNodeStatus.Unvalidated) {
|
|
162
|
-
syntaxRules =
|
|
172
|
+
syntaxRules =
|
|
173
|
+
this.descriptors?.[lowercase(name)] ??
|
|
174
|
+
getParsedSyntax(ValidationSyntaxGroupEnum.Declarations, lowercase(name));
|
|
163
175
|
if (syntaxRules != null) {
|
|
164
176
|
arena.flags[declaration] |=
|
|
165
177
|
(isValidDeclarationValue(arena, syntaxRules, declaration, this.options)
|
|
@@ -198,20 +210,28 @@ class PropertyList {
|
|
|
198
210
|
// @ts-ignore
|
|
199
211
|
shorthand = config.property[propertyName];
|
|
200
212
|
}
|
|
213
|
+
// the value of a shorthand that contains var(), env() or if() cannot be expanded: the longhands that follow
|
|
214
|
+
// it are not merged into it. `background: var(--bg); background-clip: text`
|
|
215
|
+
if (shorthand === name &&
|
|
216
|
+
(shortHandType === "map" || shortHandType === "set") &&
|
|
217
|
+
hasWildCardFunction(arena, declaration)) {
|
|
218
|
+
this.declarations.set(this.memo.key(arena, declaration), declaration);
|
|
219
|
+
return this;
|
|
220
|
+
}
|
|
201
221
|
if (this.declarations.has(shorthand)) {
|
|
202
222
|
let existing = this.declarations.get(shorthand);
|
|
203
223
|
if (existing instanceof PropertySet || existing instanceof PropertyMap) {
|
|
204
224
|
existing = existing.declarations.get(name);
|
|
205
225
|
}
|
|
206
226
|
if (existing != null &&
|
|
207
|
-
typeof existing
|
|
227
|
+
typeof existing === "number" &&
|
|
208
228
|
arena.flags[existing] & EnumAstNodeStatus.ImportantDeclaration &&
|
|
209
|
-
arena.flags[declaration] &
|
|
229
|
+
(arena.flags[declaration] & EnumAstNodeStatus.ImportantDeclaration) == 0) {
|
|
210
230
|
return this;
|
|
211
231
|
}
|
|
212
232
|
}
|
|
213
233
|
// @ts-ignore
|
|
214
|
-
if (shortHandType
|
|
234
|
+
if (shortHandType === "map") {
|
|
215
235
|
let owner = this;
|
|
216
236
|
const mapName =
|
|
217
237
|
// @ts-ignore
|
|
@@ -225,8 +245,9 @@ class PropertyList {
|
|
|
225
245
|
owner = this.declarations.get(mapName);
|
|
226
246
|
}
|
|
227
247
|
else if (!this.declarations.has(shorthand)) {
|
|
248
|
+
this.declarations.set(shorthand,
|
|
228
249
|
// @ts-ignore
|
|
229
|
-
|
|
250
|
+
new PropertyMap(arena, config.map[shorthand], this.memo));
|
|
230
251
|
}
|
|
231
252
|
if (owner == this) {
|
|
232
253
|
// @ts-ignore
|
|
@@ -243,7 +264,7 @@ class PropertyList {
|
|
|
243
264
|
}
|
|
244
265
|
}
|
|
245
266
|
// @ts-ignore
|
|
246
|
-
else if (shortHandType
|
|
267
|
+
else if (shortHandType === "set") {
|
|
247
268
|
// @ts-ignore
|
|
248
269
|
if (!this.declarations.has(shorthand)) {
|
|
249
270
|
// @ts-ignore
|
|
@@ -260,6 +281,14 @@ class PropertyList {
|
|
|
260
281
|
if (shorthand != null) {
|
|
261
282
|
this.mapValues(declaration, shorthand);
|
|
262
283
|
}
|
|
284
|
+
const existing = this.declarations.get(propertyName);
|
|
285
|
+
// a previous declaration with the same name takes precedence when it is !important and the new one is not
|
|
286
|
+
if (existing != null &&
|
|
287
|
+
typeof existing === "number" &&
|
|
288
|
+
arena.flags[existing] & EnumAstNodeStatus.ImportantDeclaration &&
|
|
289
|
+
(arena.flags[declaration] & EnumAstNodeStatus.ImportantDeclaration) == 0) {
|
|
290
|
+
return this;
|
|
291
|
+
}
|
|
263
292
|
this.declarations.set(propertyName, declaration);
|
|
264
293
|
}
|
|
265
294
|
return this;
|
|
@@ -293,7 +322,7 @@ class PropertyList {
|
|
|
293
322
|
default: {
|
|
294
323
|
for (const v of set) {
|
|
295
324
|
if (arena.dataTypes[v] === EnumToken.IdenTokenType) {
|
|
296
|
-
const value = arena.
|
|
325
|
+
const value = arena.resolveString(arena.stringValue[v]).toLowerCase();
|
|
297
326
|
if (value === pattern || new RegExp(`(^|\|)${pattern}(\||$)`).test(value)) {
|
|
298
327
|
val.push(v);
|
|
299
328
|
set.delete(v);
|
|
@@ -317,14 +346,14 @@ class PropertyList {
|
|
|
317
346
|
}
|
|
318
347
|
for (const val of declarationValues) {
|
|
319
348
|
if (arena.dataTypes[val] === EnumToken.IdenTokenType) {
|
|
320
|
-
name = arena.
|
|
349
|
+
name = arena.resolveString(arena.stringValue[val]).toLowerCase();
|
|
321
350
|
if (mapping.mapping[name] != null) {
|
|
322
351
|
const typ = EnumToken[mapping.mapping[name].typ];
|
|
323
352
|
arena.resetToken(val, typ, mapping.mapping[name].val);
|
|
324
353
|
}
|
|
325
354
|
}
|
|
326
355
|
}
|
|
327
|
-
if (values
|
|
356
|
+
if (values !== declarationValues) {
|
|
328
357
|
arena.setTokenList(declaration, values);
|
|
329
358
|
}
|
|
330
359
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/*
|
|
2
|
-
CSS parser, minifier and validator for node and the browser
|
|
2
|
+
CSS parser, minifier and validator for node, deno, bun and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version: 2.0
|
|
5
|
+
Version: 2.2.0
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { eqToken } from '../utils/eq.js';
|
|
@@ -40,8 +40,8 @@ function configToken(arena, config) {
|
|
|
40
40
|
*/
|
|
41
41
|
function matchConfigToken(arena, token, config) {
|
|
42
42
|
return (config != null &&
|
|
43
|
-
arena.dataTypes[token]
|
|
44
|
-
(config.val == null || arena.
|
|
43
|
+
arena.dataTypes[token] === configType(config) &&
|
|
44
|
+
(config.val == null || arena.resolveString(arena.stringValue[token]) === config.val));
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
47
47
|
* map of declarations that can be merged into a single shorthand declaration.
|
|
@@ -78,16 +78,13 @@ class PropertyMap {
|
|
|
78
78
|
this.pattern = config.pattern.split(/\s/);
|
|
79
79
|
}
|
|
80
80
|
/**
|
|
81
|
-
*
|
|
82
|
-
* @param
|
|
81
|
+
*
|
|
82
|
+
* @param declaration
|
|
83
83
|
*/
|
|
84
|
-
parse(value) {
|
|
85
|
-
return this.memo == null ? parseString(this.arena, value) : this.memo.parse(this.arena, value);
|
|
86
|
-
}
|
|
87
84
|
add(declaration) {
|
|
88
85
|
const arena = this.arena;
|
|
89
|
-
const nam = arena.
|
|
90
|
-
if (nam
|
|
86
|
+
const nam = arena.resolveString(arena.name[declaration]);
|
|
87
|
+
if (nam === this.config.shorthand) {
|
|
91
88
|
this.declarations.clear();
|
|
92
89
|
this.declarations.set(nam, declaration);
|
|
93
90
|
this.matchTypes(declaration);
|
|
@@ -111,13 +108,13 @@ class PropertyMap {
|
|
|
111
108
|
// let current: number = 0;
|
|
112
109
|
const props = this.config.properties[property];
|
|
113
110
|
for (let i = 0; i < acc.length; i++) {
|
|
114
|
-
if (arena.dataTypes[acc[i]]
|
|
115
|
-
arena.dataTypes[acc[i]]
|
|
111
|
+
if (arena.dataTypes[acc[i]] === EnumToken.CommentTokenType ||
|
|
112
|
+
arena.dataTypes[acc[i]] === EnumToken.WhitespaceTokenType) {
|
|
116
113
|
acc.splice(i, 1);
|
|
117
114
|
i--;
|
|
118
115
|
continue;
|
|
119
116
|
}
|
|
120
|
-
if (this.propertyNames.get(acc[i])
|
|
117
|
+
if (this.propertyNames.get(acc[i]) === property || matchType(arena, acc[i], props)) {
|
|
121
118
|
if ("prefix" in props && props.previous != null && !(props.previous in tokens)) {
|
|
122
119
|
return acc;
|
|
123
120
|
}
|
|
@@ -125,7 +122,7 @@ class PropertyMap {
|
|
|
125
122
|
tokens[property] = [[acc[i]]];
|
|
126
123
|
}
|
|
127
124
|
else {
|
|
128
|
-
if (current
|
|
125
|
+
if (current === tokens[property].length) {
|
|
129
126
|
tokens[property].push([acc[i]]);
|
|
130
127
|
}
|
|
131
128
|
else {
|
|
@@ -157,12 +154,14 @@ class PropertyMap {
|
|
|
157
154
|
// default
|
|
158
155
|
if (props.default.length > 0) {
|
|
159
156
|
// inlined: this.parse(props.default[0])
|
|
160
|
-
const defaults = this.memo == null
|
|
157
|
+
const defaults = this.memo == null
|
|
158
|
+
? parseString(this.arena, props.default[0])
|
|
159
|
+
: this.memo.parse(this.arena, props.default[0]);
|
|
161
160
|
if (!(property in tokens)) {
|
|
162
161
|
tokens[property] = [[...defaults]];
|
|
163
162
|
}
|
|
164
163
|
else {
|
|
165
|
-
if (current
|
|
164
|
+
if (current === tokens[property].length) {
|
|
166
165
|
tokens[property].push([]);
|
|
167
166
|
for (let i = 0; i < defaults.length; i++) {
|
|
168
167
|
tokens[property][current].push(defaults[i]);
|
|
@@ -179,7 +178,7 @@ class PropertyMap {
|
|
|
179
178
|
return acc;
|
|
180
179
|
}, val[current]));
|
|
181
180
|
}
|
|
182
|
-
if (values.length
|
|
181
|
+
if (values.length === 0) {
|
|
183
182
|
this.declarations = Object.entries(tokens).reduce((acc, curr) => {
|
|
184
183
|
acc.set(curr[0], arena.createDeclaration(EnumToken.DeclarationNodeType, curr[0], curr[1].reduce((acc, curr) => {
|
|
185
184
|
if (acc.length > 0) {
|
|
@@ -240,23 +239,25 @@ class PropertyMap {
|
|
|
240
239
|
for (const value of declarations.values()) {
|
|
241
240
|
if (value instanceof PropertyMap) {
|
|
242
241
|
for (const [k, v] of value.declarations) {
|
|
243
|
-
if (k
|
|
242
|
+
if (k === value.config.shorthand) {
|
|
244
243
|
const values = arena.tokens(v);
|
|
245
244
|
for (const [key] of Object.entries(value.config.properties)) {
|
|
246
245
|
mapped[key] = arena.clone(v);
|
|
247
246
|
const mappedValues = [];
|
|
248
247
|
for (let i = 0; i < values.length; i++) {
|
|
249
|
-
if (key
|
|
248
|
+
if (key === value.propertyNames.get(values[i])) {
|
|
250
249
|
if (mappedValues.length > 0) {
|
|
251
250
|
mappedValues.push(arena.createToken(EnumToken.WhitespaceTokenType));
|
|
252
251
|
}
|
|
253
252
|
mappedValues.push(value.take(values[i]));
|
|
254
253
|
}
|
|
255
254
|
}
|
|
256
|
-
if (mappedValues.length
|
|
255
|
+
if (mappedValues.length === 0) {
|
|
257
256
|
mappedValues.push(
|
|
258
257
|
// inlined: this.parse((value as PropertyMap).config.properties[key].default[0])
|
|
259
|
-
...(this.memo == null
|
|
258
|
+
...(this.memo == null
|
|
259
|
+
? parseString(this.arena, value.config.properties[key].default[0])
|
|
260
|
+
: this.memo.parse(this.arena, value.config.properties[key].default[0])));
|
|
260
261
|
}
|
|
261
262
|
arena.setTokenList(mapped[key], mappedValues);
|
|
262
263
|
}
|
|
@@ -269,7 +270,7 @@ class PropertyMap {
|
|
|
269
270
|
else {
|
|
270
271
|
// a property set has no name
|
|
271
272
|
key =
|
|
272
|
-
value instanceof PropertySet ? "undefined" : arena.
|
|
273
|
+
value instanceof PropertySet ? "undefined" : arena.resolveString(arena.name[value]);
|
|
273
274
|
mapped[key] = value;
|
|
274
275
|
}
|
|
275
276
|
}
|
|
@@ -324,7 +325,7 @@ class PropertyMap {
|
|
|
324
325
|
if (!cache.has(t)) {
|
|
325
326
|
cache.set(t, renderValue(arena, t, { minify: true }));
|
|
326
327
|
}
|
|
327
|
-
if (arena.dataTypes[t]
|
|
328
|
+
if (arena.dataTypes[t] === typ && separator === cache.get(t)) {
|
|
328
329
|
this.removeDefaults(map, value);
|
|
329
330
|
value = [];
|
|
330
331
|
values.push(value);
|
|
@@ -350,19 +351,20 @@ class PropertyMap {
|
|
|
350
351
|
acc.push(configToken(arena, sep));
|
|
351
352
|
}
|
|
352
353
|
for (const cr of curr) {
|
|
353
|
-
if (arena.dataTypes[cr]
|
|
354
|
+
if (arena.dataTypes[cr] === EnumToken.WhitespaceTokenType &&
|
|
354
355
|
acc.length > 0 &&
|
|
355
|
-
arena.dataTypes[acc[acc.length - 1]]
|
|
356
|
+
arena.dataTypes[acc[acc.length - 1]] === EnumToken.WhitespaceTokenType) {
|
|
356
357
|
continue;
|
|
357
358
|
}
|
|
358
359
|
acc.push(cr);
|
|
359
360
|
}
|
|
360
361
|
return acc;
|
|
361
362
|
}, []);
|
|
362
|
-
while (result.length > 0 &&
|
|
363
|
+
while (result.length > 0 &&
|
|
364
|
+
arena.dataTypes[result[result.length - 1]] === EnumToken.WhitespaceTokenType) {
|
|
363
365
|
result.pop();
|
|
364
366
|
}
|
|
365
|
-
while (result.length > 0 && arena.dataTypes[result[0]]
|
|
367
|
+
while (result.length > 0 && arena.dataTypes[result[0]] === EnumToken.WhitespaceTokenType) {
|
|
366
368
|
result.shift();
|
|
367
369
|
}
|
|
368
370
|
arena.setTokenList(declaration, result);
|
|
@@ -385,20 +387,22 @@ class PropertyMap {
|
|
|
385
387
|
for (const declaration of values) {
|
|
386
388
|
dec = removeDefaults(declaration);
|
|
387
389
|
for (const t of arena.tokens(dec)) {
|
|
388
|
-
if (arena.dataTypes[t]
|
|
390
|
+
if (arena.dataTypes[t] === EnumToken.ImportantTokenType) {
|
|
389
391
|
isImportant = true;
|
|
390
392
|
}
|
|
391
|
-
if (filtered.length
|
|
392
|
-
arena.dataTypes[t]
|
|
393
|
-
arena.dataTypes[t]
|
|
393
|
+
if (filtered.length === 0 &&
|
|
394
|
+
arena.dataTypes[t] !== EnumToken.WhitespaceTokenType &&
|
|
395
|
+
arena.dataTypes[t] !== EnumToken.ImportantTokenType) {
|
|
394
396
|
filtered.push(dec);
|
|
395
397
|
}
|
|
396
398
|
}
|
|
397
399
|
}
|
|
398
|
-
if (filtered.length
|
|
400
|
+
if (filtered.length === 0 && this.config.default.length > 0) {
|
|
399
401
|
filtered.push(arena.createDeclaration(EnumToken.DeclarationNodeType, this.config.shorthand,
|
|
400
402
|
// inlined: this.parse(this.config.default[0])
|
|
401
|
-
this.memo == null
|
|
403
|
+
this.memo == null
|
|
404
|
+
? parseString(this.arena, this.config.default[0])
|
|
405
|
+
: this.memo.parse(this.arena, this.config.default[0]), null, null));
|
|
402
406
|
if (isImportant) {
|
|
403
407
|
arena.appendToken(filtered[0], arena.createToken(EnumToken.ImportantTokenType));
|
|
404
408
|
}
|
|
@@ -409,8 +413,8 @@ class PropertyMap {
|
|
|
409
413
|
if (declaration instanceof PropertySet || declaration instanceof PropertyMap) {
|
|
410
414
|
continue;
|
|
411
415
|
}
|
|
412
|
-
const nam = arena.
|
|
413
|
-
const config = nam
|
|
416
|
+
const nam = arena.resolveString(arena.name[declaration]);
|
|
417
|
+
const config = nam === this.config.shorthand ? this.config : (propertiesMapping[nam] ?? this.config);
|
|
414
418
|
if (!("mapping" in config)) {
|
|
415
419
|
continue;
|
|
416
420
|
}
|
|
@@ -419,12 +423,14 @@ class PropertyMap {
|
|
|
419
423
|
for (const [key, val] of Object.entries(config.mapping)) {
|
|
420
424
|
// inlined: this.parse(key)
|
|
421
425
|
const keys = this.memo == null ? parseString(this.arena, key) : this.memo.parse(this.arena, key);
|
|
422
|
-
if (keys.length
|
|
426
|
+
if (keys.length !== declarationValues.length) {
|
|
423
427
|
continue;
|
|
424
428
|
}
|
|
425
429
|
if (keys.every((k, index) => eqToken(arena, k, declarationValues[index]))) {
|
|
426
430
|
// inlined: this.parse(val as string)
|
|
427
|
-
arena.setTokenList(declaration, this.memo == null
|
|
431
|
+
arena.setTokenList(declaration, this.memo == null
|
|
432
|
+
? parseString(this.arena, val)
|
|
433
|
+
: this.memo.parse(this.arena, val));
|
|
428
434
|
break;
|
|
429
435
|
}
|
|
430
436
|
}
|
|
@@ -455,27 +461,27 @@ class PropertyMap {
|
|
|
455
461
|
for (const val of arena.tokens(declaration)) {
|
|
456
462
|
if (matchConfigToken(arena, val, separator)) {
|
|
457
463
|
current++;
|
|
458
|
-
if (tokens[curr[0]].length
|
|
464
|
+
if (tokens[curr[0]].length === current) {
|
|
459
465
|
tokens[curr[0]].push([]);
|
|
460
466
|
}
|
|
461
467
|
continue;
|
|
462
468
|
}
|
|
463
469
|
const valType = arena.dataTypes[val];
|
|
464
|
-
if (valType
|
|
470
|
+
if (valType === EnumToken.WhitespaceTokenType || valType === EnumToken.CommentTokenType) {
|
|
465
471
|
continue;
|
|
466
472
|
}
|
|
467
473
|
if (props.multiple &&
|
|
468
474
|
props.separator != null &&
|
|
469
475
|
configType(props.separator) === valType &&
|
|
470
476
|
(valType === EnumToken.CommaTokenType ||
|
|
471
|
-
props.separator.val
|
|
477
|
+
props.separator.val === arena.resolveString(arena.stringValue[val]))) {
|
|
472
478
|
continue;
|
|
473
479
|
}
|
|
474
480
|
match = matchType(arena, val, curr[1]);
|
|
475
481
|
if (isShorthand) {
|
|
476
482
|
isShorthand = match;
|
|
477
483
|
}
|
|
478
|
-
if (this.propertyNames.get(val)
|
|
484
|
+
if (this.propertyNames.get(val) === property || match) {
|
|
479
485
|
if (!(curr[0] in tokens)) {
|
|
480
486
|
tokens[curr[0]] = [[]];
|
|
481
487
|
}
|
|
@@ -494,7 +500,7 @@ class PropertyMap {
|
|
|
494
500
|
return acc;
|
|
495
501
|
}, []);
|
|
496
502
|
// grid-template
|
|
497
|
-
if (this.config.shorthand
|
|
503
|
+
if (this.config.shorthand === "grid-template" && patterns.length === Object.keys(tokens).length) {
|
|
498
504
|
const k = tokens[patterns[0]][0].length;
|
|
499
505
|
const l = tokens[patterns[1]][0].length;
|
|
500
506
|
const j = k < l ? k : l;
|
|
@@ -537,12 +543,12 @@ class PropertyMap {
|
|
|
537
543
|
!Object.values(tokens).every((v) =>
|
|
538
544
|
// `v` holds token groups: only single token groups were type checked by the former
|
|
539
545
|
// `arena.dataTypes[group]` lookup (the group is converted to a string key)
|
|
540
|
-
v.filter((t) => t.length
|
|
546
|
+
v.filter((t) => t.length !== 1 || arena.dataTypes[t[0]] !== EnumToken.CommentTokenType).length === count)) {
|
|
541
547
|
// @ts-ignore
|
|
542
548
|
iterable = declarations.values();
|
|
543
549
|
}
|
|
544
550
|
else if (hasMapping) {
|
|
545
|
-
if (patterns.length
|
|
551
|
+
if (patterns.length === Object.keys(tokens).length) {
|
|
546
552
|
const declaration = arena.clone(declarations.get(patterns[0]));
|
|
547
553
|
const declarationValues = arena.tokens(declaration);
|
|
548
554
|
arena.name[declaration] = arena.internString(this.config.shorthand);
|
|
@@ -574,7 +580,7 @@ class PropertyMap {
|
|
|
574
580
|
.reduce((acc, curr) => {
|
|
575
581
|
const props = propertiesMapping[curr[0]];
|
|
576
582
|
for (let i = 0; i < curr[1].length; i++) {
|
|
577
|
-
if (acc.length
|
|
583
|
+
if (acc.length === i) {
|
|
578
584
|
acc.push([]);
|
|
579
585
|
}
|
|
580
586
|
// if (acc[acc.length - 1].length > 0) {
|
|
@@ -614,8 +620,8 @@ class PropertyMap {
|
|
|
614
620
|
EnumToken.CommentTokenType,
|
|
615
621
|
EnumToken.IdenTokenType,
|
|
616
622
|
].includes(arena.dataTypes[v]) ||
|
|
617
|
-
(arena.dataTypes[v]
|
|
618
|
-
!propertiesMapping[curr[0]].default.includes(arena.
|
|
623
|
+
(arena.dataTypes[v] === EnumToken.IdenTokenType &&
|
|
624
|
+
!propertiesMapping[curr[0]].default.includes(arena.resolveString(arena.stringValue[v])))) {
|
|
619
625
|
doFilterDefault = false;
|
|
620
626
|
break;
|
|
621
627
|
}
|
|
@@ -623,13 +629,13 @@ class PropertyMap {
|
|
|
623
629
|
}
|
|
624
630
|
// remove default values
|
|
625
631
|
const filtered = values.filter((val) => {
|
|
626
|
-
if (arena.dataTypes[val]
|
|
627
|
-
arena.dataTypes[val]
|
|
632
|
+
if (arena.dataTypes[val] === EnumToken.WhitespaceTokenType ||
|
|
633
|
+
arena.dataTypes[val] === EnumToken.CommentTokenType) {
|
|
628
634
|
return false;
|
|
629
635
|
}
|
|
630
636
|
return (!doFilterDefault ||
|
|
631
|
-
!(arena.dataTypes[val]
|
|
632
|
-
props.default.includes(arena.
|
|
637
|
+
!(arena.dataTypes[val] === EnumToken.IdenTokenType &&
|
|
638
|
+
props.default.includes(arena.resolveString(arena.stringValue[val]))));
|
|
633
639
|
});
|
|
634
640
|
if (filtered.length > 0 ||
|
|
635
641
|
!(this.requiredCount == requiredCount && propertiesMapping[curr[0]].required)) {
|
|
@@ -643,15 +649,17 @@ class PropertyMap {
|
|
|
643
649
|
values.length <= props.constraints.mapping.max) {
|
|
644
650
|
let i = values.length;
|
|
645
651
|
while (i--) {
|
|
646
|
-
if (arena.dataTypes[values[i]]
|
|
652
|
+
if (arena.dataTypes[values[i]] === EnumToken.IdenTokenType &&
|
|
647
653
|
// @ts-expect-error
|
|
648
|
-
arena.
|
|
649
|
-
// inlined: this.parse(props.mapping[arena.
|
|
654
|
+
arena.resolveString(arena.stringValue[values[i]]) in props.mapping) {
|
|
655
|
+
// inlined: this.parse(props.mapping[arena.resolveString(arena.stringValue[values[i]])])
|
|
650
656
|
values.splice(i, 1, ...(this.memo == null
|
|
651
|
-
?
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
657
|
+
? parseString(this.arena,
|
|
658
|
+
// @ts-ignore
|
|
659
|
+
props.mapping[arena.resolveString(arena.stringValue[values[i]])])
|
|
660
|
+
: this.memo.parse(this.arena,
|
|
661
|
+
// @ts-ignore
|
|
662
|
+
props.mapping[arena.resolveString(arena.stringValue[values[i]])])));
|
|
655
663
|
}
|
|
656
664
|
}
|
|
657
665
|
}
|
|
@@ -679,10 +687,12 @@ class PropertyMap {
|
|
|
679
687
|
if (acc.length > 0) {
|
|
680
688
|
acc.push(configToken(arena, separator));
|
|
681
689
|
}
|
|
682
|
-
if (curr.length
|
|
690
|
+
if (curr.length === 0 && this.config.default.length > 0) {
|
|
683
691
|
curr.push(
|
|
684
692
|
// inlined: this.parse(this.config.default[0])
|
|
685
|
-
...(this.memo == null
|
|
693
|
+
...(this.memo == null
|
|
694
|
+
? parseString(this.arena, this.config.default[0])
|
|
695
|
+
: this.memo.parse(this.arena, this.config.default[0])).reduce((acc, curr) => {
|
|
686
696
|
if (acc.length > 0) {
|
|
687
697
|
acc.push(arena.createToken(EnumToken.WhitespaceTokenType));
|
|
688
698
|
}
|
|
@@ -710,12 +720,15 @@ class PropertyMap {
|
|
|
710
720
|
this.config.mapping[val]));
|
|
711
721
|
}
|
|
712
722
|
}
|
|
713
|
-
if (values.length
|
|
714
|
-
arena.stringValue[values[0]]
|
|
715
|
-
this.config.default.includes(arena.
|
|
716
|
-
this.config.default[0]
|
|
723
|
+
if (values.length === 1 &&
|
|
724
|
+
arena.stringValue[values[0]] !== 0 &&
|
|
725
|
+
this.config.default.includes(arena.resolveString(arena.stringValue[values[0]]).toLowerCase()) &&
|
|
726
|
+
this.config.default[0] !== arena.resolveString(arena.stringValue[values[0]]).toLowerCase()) {
|
|
717
727
|
// inlined: this.parse(this.config.default[0])
|
|
718
|
-
values =
|
|
728
|
+
values =
|
|
729
|
+
this.memo == null
|
|
730
|
+
? parseString(this.arena, this.config.default[0])
|
|
731
|
+
: this.memo.parse(this.arena, this.config.default[0]);
|
|
719
732
|
}
|
|
720
733
|
iterable = [
|
|
721
734
|
arena.createDeclaration(EnumToken.DeclarationNodeType, this.config.shorthand, values, null, null),
|
|
@@ -742,7 +755,7 @@ class PropertyMap {
|
|
|
742
755
|
iterable = iterators.pop();
|
|
743
756
|
v = iterable.next();
|
|
744
757
|
}
|
|
745
|
-
if (v.done && iterators.length
|
|
758
|
+
if (v.done && iterators.length === 0) {
|
|
746
759
|
break;
|
|
747
760
|
}
|
|
748
761
|
}
|
|
@@ -756,7 +769,7 @@ class PropertyMap {
|
|
|
756
769
|
* @param token
|
|
757
770
|
*/
|
|
758
771
|
take(token) {
|
|
759
|
-
if (this.arena.parents[token]
|
|
772
|
+
if (this.arena.parents[token] === 0) {
|
|
760
773
|
return token;
|
|
761
774
|
}
|
|
762
775
|
const clone = this.arena.clone(token, true);
|
|
@@ -797,10 +810,10 @@ class PropertyMap {
|
|
|
797
810
|
if (map.has(key)) {
|
|
798
811
|
for (const v of val) {
|
|
799
812
|
// missing
|
|
800
|
-
if (map.get(v)
|
|
813
|
+
if (map.get(v) === 1) {
|
|
801
814
|
let i = declarationValues.length;
|
|
802
815
|
while (i--) {
|
|
803
|
-
if (this.propertyNames.get(declarationValues[i])
|
|
816
|
+
if (this.propertyNames.get(declarationValues[i]) === key) {
|
|
804
817
|
const val = arena.clone(declarationValues[i], true);
|
|
805
818
|
this.propertyNames.set(val, v);
|
|
806
819
|
declarationValues.splice(i, 0, val, arena.createToken(EnumToken.WhitespaceTokenType));
|
|
@@ -823,14 +836,14 @@ class PropertyMap {
|
|
|
823
836
|
continue;
|
|
824
837
|
}
|
|
825
838
|
const v = val.value.join(" ");
|
|
826
|
-
if (config.default.includes(v) || (value.length
|
|
839
|
+
if (config.default.includes(v) || (value.length === 1 && this.config.default.includes(v))) {
|
|
827
840
|
for (const token of value) {
|
|
828
841
|
if (val.t.includes(token)) {
|
|
829
842
|
let index = value.indexOf(token);
|
|
830
843
|
value.splice(index, 1);
|
|
831
844
|
if (config.prefix != null) {
|
|
832
845
|
while (index-- > 0) {
|
|
833
|
-
if (this.arena.dataTypes[value[index]]
|
|
846
|
+
if (this.arena.dataTypes[value[index]] === EnumToken.WhitespaceTokenType) {
|
|
834
847
|
continue;
|
|
835
848
|
}
|
|
836
849
|
if (matchConfigToken(this.arena, value[index], config.prefix)) {
|