@tbela99/css-parser 2.3.0 → 2.3.2
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 +43 -0
- package/README.md +66 -21
- package/architecture.png +0 -0
- package/dist/ast/arena-node.js +32 -3
- package/dist/ast/arena.js +88 -10
- package/dist/ast/cache.js +1 -1
- package/dist/ast/features/calc.js +1 -1
- package/dist/ast/features/if.js +1 -1
- package/dist/ast/features/index.js +1 -1
- package/dist/ast/features/inlinecssvariables.js +1 -1
- package/dist/ast/features/mixin.js +1 -1
- package/dist/ast/features/prefix.js +1 -1
- package/dist/ast/features/shorthand.js +1 -1
- package/dist/ast/features/transform.js +1 -1
- package/dist/ast/features/type.js +1 -1
- package/dist/ast/math/expression.js +1 -1
- package/dist/ast/math/math.js +1 -1
- package/dist/ast/minify.js +131 -36
- package/dist/ast/mixins/custom-function.js +1 -1
- package/dist/ast/mixins/utils.js +1 -1
- package/dist/ast/mixins/variables.js +1 -1
- package/dist/ast/strings.js +26 -1
- package/dist/ast/transform/compute.js +6 -2
- package/dist/ast/transform/matrix.js +1 -1
- package/dist/ast/transform/minify.js +1 -1
- package/dist/ast/transform/perspective.js +1 -1
- package/dist/ast/transform/rotate.js +1 -1
- package/dist/ast/transform/scale.js +1 -1
- package/dist/ast/transform/skew.js +1 -1
- package/dist/ast/transform/translate.js +1 -1
- package/dist/ast/transform/utils.js +1 -1
- package/dist/ast/types.js +22 -2
- package/dist/ast/walk.js +1 -1
- package/dist/data/properties.json.js +1 -1
- package/dist/data/validation.json.js +1 -1
- package/dist/fs/resolve.js +1 -1
- package/dist/index-umd-web.js +1099 -295
- package/dist/index.d.ts +612 -688
- package/dist/node.js +14 -8
- package/dist/parser/declaration/list.js +8 -5
- package/dist/parser/declaration/map.js +1 -1
- package/dist/parser/declaration/set.js +1 -1
- package/dist/parser/input.js +62 -4
- package/dist/parser/linesmap.js +1 -1
- package/dist/parser/parse.js +121 -13
- package/dist/parser/source.js +1 -1
- package/dist/parser/tokenize.js +161 -19
- package/dist/parser/utils/angle.js +1 -1
- package/dist/parser/utils/at-rule-container.js +1 -1
- package/dist/parser/utils/at-rule-font-feature-values.js +1 -1
- package/dist/parser/utils/at-rule-generic.js +1 -1
- package/dist/parser/utils/at-rule-import.js +1 -1
- package/dist/parser/utils/at-rule-media.js +42 -2
- package/dist/parser/utils/at-rule-support.js +1 -1
- package/dist/parser/utils/at-rule-when-else.js +1 -1
- package/dist/parser/utils/at-rule.js +1 -1
- package/dist/parser/utils/base64.js +1 -1
- package/dist/parser/utils/cache.js +1 -1
- package/dist/parser/utils/canonical.js +1 -1
- package/dist/parser/utils/codes.js +1 -1
- package/dist/parser/utils/config.js +1 -1
- package/dist/parser/utils/declaration.js +1 -1
- package/dist/parser/utils/eq.js +1 -1
- package/dist/parser/utils/hash.js +1 -1
- package/dist/parser/utils/selector.js +98 -6
- package/dist/parser/utils/text.js +1 -1
- package/dist/parser/utils/token.js +1 -1
- package/dist/parser/utils/type.js +1 -1
- package/dist/printer/lib/codec.js +1 -1
- package/dist/printer/render.js +5 -7
- package/dist/printer/result.js +18 -3
- package/dist/printer/sourcemap.js +1 -1
- package/dist/printer/writer.js +1 -1
- package/dist/syntax/color/a98rgb.js +1 -1
- package/dist/syntax/color/alpha.js +1 -1
- package/dist/syntax/color/cmyk.js +1 -1
- package/dist/syntax/color/color-mix.js +1 -1
- package/dist/syntax/color/color.js +1 -1
- package/dist/syntax/color/hex.js +1 -1
- package/dist/syntax/color/hsl.js +12 -4
- package/dist/syntax/color/hwb.js +9 -3
- package/dist/syntax/color/lab.js +1 -1
- package/dist/syntax/color/lch.js +1 -1
- package/dist/syntax/color/oklab.js +1 -1
- package/dist/syntax/color/oklch.js +2 -2
- package/dist/syntax/color/p3.js +1 -1
- package/dist/syntax/color/prophotorgb.js +1 -1
- package/dist/syntax/color/rec2020.js +1 -1
- package/dist/syntax/color/relative-color.js +1 -1
- package/dist/syntax/color/rgb.js +1 -1
- package/dist/syntax/color/srgb.js +3 -2
- package/dist/syntax/color/utils/color-type.js +1 -1
- package/dist/syntax/color/utils/colorspace.js +1 -1
- package/dist/syntax/color/utils/components.js +1 -1
- package/dist/syntax/color/utils/distance.js +1 -1
- package/dist/syntax/color/utils/make-color.js +1 -1
- package/dist/syntax/color/utils/matrix.js +1 -1
- package/dist/syntax/color/xyz.js +1 -1
- package/dist/syntax/color/xyzd50.js +1 -1
- package/dist/syntax/constants.js +2 -2
- package/dist/syntax/syntax.js +1 -1
- package/dist/types.js +1 -1
- package/dist/utils/sync.js +1 -1
- package/dist/validation/compiled/builtins.js +1 -1
- package/dist/validation/compiled/runtime.js +1 -1
- package/dist/validation/compiled/syntaxes.js +1 -1
- package/dist/validation/config.js +1 -1
- package/dist/validation/first.js +1 -1
- package/dist/validation/match.js +77 -4
- package/dist/validation/parser/parse.js +1 -1
- package/dist/validation/parser/typedef.js +4 -1
- package/dist/validation/utils/list.js +1 -1
- package/dist/version.js +2 -2
- package/dist/web.js +13 -6
- package/package.json +15 -6
package/dist/validation/match.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
CSS parser, minifier and validator for node, deno, bun and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version: 2.3.
|
|
5
|
+
Version: 2.3.2
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { TokenField } from '../ast/arena.js';
|
|
@@ -116,6 +116,71 @@ function trimArray(arena, tokens) {
|
|
|
116
116
|
}
|
|
117
117
|
return tokens;
|
|
118
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* true if the token is a simple selector without arguments: a type (`a`), an id (`#a`), a class (`.a`), a
|
|
121
|
+
* pseudo-class (`:hover`) or a pseudo-element (`::before`)
|
|
122
|
+
* @param type
|
|
123
|
+
*/
|
|
124
|
+
function isSimpleSelectorToken(type) {
|
|
125
|
+
return (type === EnumToken.ClassSelectorTokenType ||
|
|
126
|
+
type === EnumToken.IdenTokenType ||
|
|
127
|
+
type === EnumToken.PseudoElementTokenType ||
|
|
128
|
+
type === EnumToken.PseudoClassTokenType ||
|
|
129
|
+
type === EnumToken.HashTokenType);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* match a selector made of simple selectors (see {@link isSimpleSelectorToken}), separated by whitespace (the
|
|
133
|
+
* descendant combinator) and by commas: `.a:hover`, `.a .b`, `.a, #b`. such a selector is valid: the whitespace
|
|
134
|
+
* around the commas is removed, the tokens are the tokens produced by {@link matchSelectorSyntax}. the tokens of
|
|
135
|
+
* another selector are not changed
|
|
136
|
+
* @param arena
|
|
137
|
+
* @param tokens
|
|
138
|
+
* @returns true if the selector is made of simple selectors
|
|
139
|
+
*/
|
|
140
|
+
function matchSimpleSelector(arena, tokens) {
|
|
141
|
+
const length = tokens.length;
|
|
142
|
+
// a simple selector is expected: at the start of the selector and after a comma
|
|
143
|
+
let expected = true;
|
|
144
|
+
let commaWhitespace = false;
|
|
145
|
+
for (let i = 0; i < length; i++) {
|
|
146
|
+
const type = arena.dataTypes[tokens[i]];
|
|
147
|
+
if (isSimpleSelectorToken(type)) {
|
|
148
|
+
expected = false;
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
if (type === EnumToken.WhitespaceTokenType) {
|
|
152
|
+
// leading whitespace
|
|
153
|
+
if (i === 0) {
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
// whitespace after a comma or before a comma
|
|
157
|
+
if (expected || arena.dataTypes[tokens[i + 1]] === EnumToken.CommaTokenType) {
|
|
158
|
+
commaWhitespace = true;
|
|
159
|
+
}
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
if (type !== EnumToken.CommaTokenType || expected) {
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
expected = true;
|
|
166
|
+
}
|
|
167
|
+
if (expected) {
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
if (commaWhitespace) {
|
|
171
|
+
let write = 0;
|
|
172
|
+
for (let i = 0; i < length; i++) {
|
|
173
|
+
if (arena.dataTypes[tokens[i]] === EnumToken.WhitespaceTokenType &&
|
|
174
|
+
(arena.dataTypes[tokens[i - 1]] === EnumToken.CommaTokenType ||
|
|
175
|
+
arena.dataTypes[tokens[i + 1]] === EnumToken.CommaTokenType)) {
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
tokens[write++] = tokens[i];
|
|
179
|
+
}
|
|
180
|
+
tokens.length = write;
|
|
181
|
+
}
|
|
182
|
+
return true;
|
|
183
|
+
}
|
|
119
184
|
/**
|
|
120
185
|
*
|
|
121
186
|
* @param featureName
|
|
@@ -1517,8 +1582,12 @@ function isInRange(arena, token, syntax) {
|
|
|
1517
1582
|
* @param token
|
|
1518
1583
|
*/
|
|
1519
1584
|
function functionSyntax(arena, token) {
|
|
1585
|
+
const previousSyntaxArena = syntaxArena;
|
|
1520
1586
|
syntaxArena = arena;
|
|
1521
|
-
|
|
1587
|
+
const syntax = arena.stringDerived(arena.stringValue[token], 0 /* StringDerived.FunctionSyntax */, computeFunctionSyntax);
|
|
1588
|
+
// the arena is not kept after the parse: the previous arena is restored (a nested call)
|
|
1589
|
+
syntaxArena = previousSyntaxArena;
|
|
1590
|
+
return syntax;
|
|
1522
1591
|
}
|
|
1523
1592
|
/**
|
|
1524
1593
|
* the arena of the function names read by {@link computeFunctionSyntax} and {@link computeSelectorFunctionSyntax}:
|
|
@@ -1545,8 +1614,12 @@ function computeSelectorFunctionSyntax(id) {
|
|
|
1545
1614
|
* @param token
|
|
1546
1615
|
*/
|
|
1547
1616
|
function selectorFunctionSyntax(arena, token) {
|
|
1617
|
+
const previousSyntaxArena = syntaxArena;
|
|
1548
1618
|
syntaxArena = arena;
|
|
1549
|
-
|
|
1619
|
+
const syntax = arena.stringDerived(arena.stringValue[token], 1 /* StringDerived.SelectorFunctionSyntax */, computeSelectorFunctionSyntax);
|
|
1620
|
+
// the arena is not kept after the parse: the previous arena is restored (a nested call)
|
|
1621
|
+
syntaxArena = previousSyntaxArena;
|
|
1622
|
+
return syntax;
|
|
1550
1623
|
}
|
|
1551
1624
|
/**
|
|
1552
1625
|
* the wildcard functions being matched with a syntax, see {@link matchWildCardFunction}
|
|
@@ -3176,4 +3249,4 @@ function matchRepeatableSyntax(arena, syntax, context, options) {
|
|
|
3176
3249
|
};
|
|
3177
3250
|
}
|
|
3178
3251
|
|
|
3179
|
-
export { ValidationTokenContext, createValidationContext, funcTypes, getMFInfo, isCssWideKeyword, isMFValue, isValidDeclarationValue, matchAllSyntaxes, matchDeclarationSyntax, matchOccurenceSyntax, matchProperty, matchSelectorSyntax, selectorFunctionSyntax, trimArray };
|
|
3252
|
+
export { ValidationTokenContext, createValidationContext, funcTypes, getMFInfo, isCssWideKeyword, isMFValue, isValidDeclarationValue, matchAllSyntaxes, matchDeclarationSyntax, matchOccurenceSyntax, matchProperty, matchSelectorSyntax, matchSimpleSelector, selectorFunctionSyntax, trimArray };
|
|
@@ -2,9 +2,12 @@
|
|
|
2
2
|
CSS parser, minifier and validator for node, deno, bun and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version: 2.3.
|
|
5
|
+
Version: 2.3.2
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
|
+
/**
|
|
9
|
+
* type of a validation token: a node of the parsed value definition syntax, see {@link parseSyntax}
|
|
10
|
+
*/
|
|
8
11
|
var ValidationTokenEnum;
|
|
9
12
|
(function (ValidationTokenEnum) {
|
|
10
13
|
ValidationTokenEnum[ValidationTokenEnum["Root"] = 0] = "Root";
|
package/dist/version.js
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
CSS parser, minifier and validator for node, deno, bun and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version: 2.3.
|
|
5
|
+
Version: 2.3.2
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
/**
|
|
9
9
|
* Version number
|
|
10
10
|
*/
|
|
11
|
-
const version = "2.3.
|
|
11
|
+
const version = "2.3.2";
|
|
12
12
|
|
|
13
13
|
export { version };
|
package/dist/web.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
CSS parser, minifier and validator for node, deno, bun and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version: 2.3.
|
|
5
|
+
Version: 2.3.2
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { doParse, doParseSync } from './parser/parse.js';
|
|
@@ -11,9 +11,9 @@ import { doRender } from './printer/render.js';
|
|
|
11
11
|
export { renderValue } from './printer/render.js';
|
|
12
12
|
import { TransformResult, RenderResult } from './printer/result.js';
|
|
13
13
|
import { ModuleScopeEnumOptions } from './ast/types.js';
|
|
14
|
-
export { ColorType, EnumAstNodeStatus, EnumToken, ModuleCaseTransformEnum, WalkerEvent, WalkerOptionEnum } from './ast/types.js';
|
|
14
|
+
export { ColorType, EnumAstNodeStatus, EnumToken, MergeRulesEnum, ModuleCaseTransformEnum, WalkerEvent, WalkerOptionEnum } from './ast/types.js';
|
|
15
15
|
import { createParseInfo, Tokenizer } from './parser/tokenize.js';
|
|
16
|
-
import { isCssInput } from './parser/input.js';
|
|
16
|
+
import { setStreamSize, responseSize, isCssInput } from './parser/input.js';
|
|
17
17
|
import { matchUrl, resolve, dirname } from './fs/resolve.js';
|
|
18
18
|
import { ResponseType } from './types.js';
|
|
19
19
|
import { SourceFile } from './parser/source.js';
|
|
@@ -25,6 +25,8 @@ export { Arena, AstArena, TokenField, arenaColumns } from './ast/arena.js';
|
|
|
25
25
|
export { ARENA, ARENAID, AstArenaNode } from './ast/arena-node.js';
|
|
26
26
|
export { PropertyList } from './parser/declaration/list.js';
|
|
27
27
|
export { SourceMap } from './printer/sourcemap.js';
|
|
28
|
+
export { ValidationTokenEnum } from './validation/parser/typedef.js';
|
|
29
|
+
export { LOC } from './syntax/constants.js';
|
|
28
30
|
export { FeatureWalkMode } from './ast/features/type.js';
|
|
29
31
|
export { parseSyntax } from './validation/parser/parse.js';
|
|
30
32
|
export { version } from './version.js';
|
|
@@ -69,7 +71,10 @@ async function load(url, currentDirectory = ".", responseType = false) {
|
|
|
69
71
|
if (responseType === ResponseType.JSON) {
|
|
70
72
|
return response.json();
|
|
71
73
|
}
|
|
72
|
-
|
|
74
|
+
// the size of the body: the parser allocates its buffers once
|
|
75
|
+
return responseType === ResponseType.ReadableStream
|
|
76
|
+
? setStreamSize(response.body, responseSize(response))
|
|
77
|
+
: response.text();
|
|
73
78
|
});
|
|
74
79
|
}
|
|
75
80
|
/**
|
|
@@ -206,7 +211,8 @@ function transformSync(...args) {
|
|
|
206
211
|
validateSyncArguments(options);
|
|
207
212
|
}
|
|
208
213
|
// the options of the caller are not modified: they may be reused
|
|
209
|
-
|
|
214
|
+
// the fast mode sets the default value of minify (see fastModeOptions)
|
|
215
|
+
options = { ...(options?.fastMode ? null : { minify: true }), removeEmpty: true, removeCharset: true, ...options };
|
|
210
216
|
const startTime = performance.now();
|
|
211
217
|
const parseResult = parseSyncInput(stream, options);
|
|
212
218
|
let mapping = null;
|
|
@@ -353,7 +359,8 @@ async function transform(...args) {
|
|
|
353
359
|
stream = input;
|
|
354
360
|
}
|
|
355
361
|
}
|
|
356
|
-
|
|
362
|
+
// the fast mode sets the default value of minify (see fastModeOptions)
|
|
363
|
+
options = { ...(options?.fastMode ? null : { minify: true }), removeEmpty: true, removeCharset: true, ...options };
|
|
357
364
|
const startTime = performance.now();
|
|
358
365
|
return parseInput(stream, options).then((parseResult) => {
|
|
359
366
|
let mapping = null;
|
package/package.json
CHANGED
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tbela99/css-parser",
|
|
3
3
|
"description": "CSS parser, minifier and validator for node, deno, bun and the browser",
|
|
4
|
-
"version": "2.3.
|
|
4
|
+
"version": "2.3.2",
|
|
5
5
|
"exports": {
|
|
6
|
-
".":
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
".": {
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"default": "./dist/node.js"
|
|
9
|
+
},
|
|
10
|
+
"./node": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"default": "./dist/node.js"
|
|
13
|
+
},
|
|
14
|
+
"./web": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"default": "./dist/web.js"
|
|
17
|
+
}
|
|
9
18
|
},
|
|
10
19
|
"type": "module",
|
|
11
20
|
"typings": "dist/index.d.ts",
|
|
@@ -69,7 +78,7 @@
|
|
|
69
78
|
"@types/chai": "^5.2.3",
|
|
70
79
|
"@types/chai-as-promised": "^8.0.2",
|
|
71
80
|
"@types/mocha": "^10.0.10",
|
|
72
|
-
"@types/node": "^26.6.
|
|
81
|
+
"@types/node": "^26.6.11",
|
|
73
82
|
"@types/web": "^0.0.367",
|
|
74
83
|
"@typescript/typescript6": "^6.0.2",
|
|
75
84
|
"@web/test-runner": "^1.0.1",
|
|
@@ -80,7 +89,7 @@
|
|
|
80
89
|
"markdown-it-task-lists": "^2.1.1",
|
|
81
90
|
"mocha": "^12.0.3",
|
|
82
91
|
"playwright": "^1.65.1",
|
|
83
|
-
"rollup": "^4.68.
|
|
92
|
+
"rollup": "^4.68.8",
|
|
84
93
|
"rollup-plugin-dts": "^6.5.1",
|
|
85
94
|
"rollup-plugin-version-injector": "^1.3.3",
|
|
86
95
|
"superc8": "^12.7.0",
|