@tbela99/css-parser 2.2.0 → 2.3.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/CHANGELOG.md +29 -0
- package/README.md +24 -9
- package/dist/{lib/ast → ast}/arena-node.js +1 -1
- package/dist/{lib/ast → ast}/arena.js +1 -1
- package/dist/{lib/ast → ast}/cache.js +39 -23
- package/dist/{lib/ast → ast}/features/calc.js +1 -1
- package/dist/{lib/ast → ast}/features/if.js +1 -1
- package/dist/ast/features/index.d.ts +7 -0
- package/dist/{lib/ast → ast}/features/index.js +1 -1
- package/dist/{lib/ast → ast}/features/inlinecssvariables.js +1 -1
- package/dist/{lib/ast → ast}/features/mixin.js +1 -1
- package/dist/{lib/ast → ast}/features/prefix.js +1 -1
- package/dist/{lib/ast → ast}/features/shorthand.js +1 -1
- package/dist/{lib/ast → ast}/features/transform.js +1 -1
- package/dist/{lib/ast → ast}/features/type.js +1 -1
- package/dist/{lib/ast → ast}/math/expression.js +1 -1
- package/dist/{lib/ast → ast}/math/math.js +1 -1
- package/dist/{lib/ast → ast}/minify.js +1 -1
- package/dist/{lib/ast → ast}/mixins/custom-function.js +1 -1
- package/dist/{lib/ast → ast}/mixins/utils.js +1 -1
- package/dist/{lib/ast → ast}/mixins/variables.js +1 -1
- package/dist/{lib/ast → ast}/strings.js +5 -1
- package/dist/{lib/ast → ast}/transform/compute.js +1 -1
- package/dist/{lib/ast → ast}/transform/matrix.js +1 -1
- package/dist/{lib/ast → ast}/transform/minify.js +1 -1
- package/dist/{lib/ast → ast}/transform/perspective.js +1 -1
- package/dist/{lib/ast → ast}/transform/rotate.js +1 -1
- package/dist/{lib/ast → ast}/transform/scale.js +1 -1
- package/dist/{lib/ast → ast}/transform/skew.js +1 -1
- package/dist/{lib/ast → ast}/transform/translate.js +1 -1
- package/dist/{lib/ast → ast}/transform/utils.js +1 -1
- package/dist/{lib/ast → ast}/types.js +1 -1
- package/dist/{lib/ast → ast}/walk.js +1 -1
- package/dist/data/properties.json.js +1 -1
- package/dist/data/validation.json.js +26 -20
- package/dist/{lib/fs → fs}/resolve.js +1 -1
- package/dist/index-umd-web.js +2770 -128
- package/dist/index.d.ts +21 -4
- package/dist/node.js +21 -21
- package/dist/{lib/parser → parser}/declaration/list.js +1 -1
- package/dist/{lib/parser → parser}/declaration/map.js +1 -1
- package/dist/{lib/parser → parser}/declaration/set.js +1 -1
- package/dist/{lib/parser → parser}/input.js +1 -1
- package/dist/{lib/parser → parser}/linesmap.js +1 -1
- package/dist/{lib/parser → parser}/parse.js +20 -21
- package/dist/{lib/parser → parser}/source.js +2 -2
- package/dist/{lib/parser → parser}/tokenize.js +1 -1
- package/dist/{lib/parser → parser}/utils/angle.js +1 -1
- package/dist/{lib/parser → parser}/utils/at-rule-container.js +1 -1
- package/dist/{lib/parser → parser}/utils/at-rule-font-feature-values.js +1 -1
- package/dist/{lib/parser → parser}/utils/at-rule-generic.js +1 -1
- package/dist/{lib/parser → parser}/utils/at-rule-import.js +1 -1
- package/dist/{lib/parser → parser}/utils/at-rule-media.js +1 -1
- package/dist/{lib/parser → parser}/utils/at-rule-support.js +1 -1
- package/dist/{lib/parser → parser}/utils/at-rule-when-else.js +1 -1
- package/dist/{lib/parser → parser}/utils/at-rule.js +1 -1
- package/dist/{lib/parser → parser}/utils/base64.js +1 -1
- package/dist/{lib/parser → parser}/utils/cache.js +1 -1
- package/dist/{lib/parser → parser}/utils/canonical.js +1 -1
- package/dist/{lib/parser → parser}/utils/codes.js +1 -1
- package/dist/{lib/parser → parser}/utils/config.js +2 -2
- package/dist/{lib/parser → parser}/utils/declaration.js +1 -1
- package/dist/{lib/parser → parser}/utils/eq.js +1 -1
- package/dist/{lib/parser → parser}/utils/hash.js +1 -1
- package/dist/{lib/parser → parser}/utils/selector.js +38 -28
- package/dist/{lib/parser → parser}/utils/text.js +1 -1
- package/dist/{lib/parser → parser}/utils/token.js +1 -1
- package/dist/{lib/parser → parser}/utils/type.js +1 -1
- package/dist/{lib/printer/sourcemap → printer}/lib/codec.js +1 -1
- package/dist/{lib/printer → printer}/render.js +184 -23
- package/dist/{lib/printer → printer}/result.js +16 -3
- package/dist/{lib/printer/sourcemap → printer}/sourcemap.js +3 -2
- package/dist/{lib/printer → printer}/writer.js +1 -1
- package/dist/{lib/syntax → syntax}/color/a98rgb.js +1 -1
- package/dist/{lib/syntax → syntax}/color/alpha.js +1 -1
- package/dist/{lib/syntax → syntax}/color/cmyk.js +1 -1
- package/dist/{lib/syntax → syntax}/color/color-mix.js +1 -1
- package/dist/{lib/syntax → syntax}/color/color.js +1 -1
- package/dist/{lib/syntax → syntax}/color/hex.js +1 -1
- package/dist/{lib/syntax → syntax}/color/hsl.js +1 -1
- package/dist/{lib/syntax → syntax}/color/hwb.js +1 -1
- package/dist/{lib/syntax → syntax}/color/lab.js +1 -1
- package/dist/{lib/syntax → syntax}/color/lch.js +1 -1
- package/dist/{lib/syntax → syntax}/color/oklab.js +1 -1
- package/dist/{lib/syntax → syntax}/color/oklch.js +1 -1
- package/dist/{lib/syntax → syntax}/color/p3.js +1 -1
- package/dist/{lib/syntax → syntax}/color/prophotorgb.js +1 -1
- package/dist/{lib/syntax → syntax}/color/rec2020.js +1 -1
- package/dist/{lib/syntax → syntax}/color/relative-color.js +1 -1
- package/dist/{lib/syntax → syntax}/color/rgb.js +1 -1
- package/dist/{lib/syntax → syntax}/color/srgb.js +1 -1
- package/dist/{lib/syntax → syntax}/color/utils/color-type.js +1 -1
- package/dist/{lib/syntax → syntax}/color/utils/colorspace.js +1 -1
- package/dist/{lib/syntax → syntax}/color/utils/components.js +1 -1
- package/dist/{lib/syntax → syntax}/color/utils/distance.js +1 -1
- package/dist/{lib/syntax → syntax}/color/utils/make-color.js +1 -1
- package/dist/{lib/syntax → syntax}/color/utils/matrix.js +1 -1
- package/dist/{lib/syntax → syntax}/color/xyz.js +1 -1
- package/dist/{lib/syntax → syntax}/color/xyzd50.js +1 -1
- package/dist/{lib/syntax → syntax}/constants.js +2 -2
- package/dist/{lib/syntax → syntax}/syntax.js +1 -1
- package/dist/types.js +1 -1
- package/dist/utils/sync.js +3 -3
- package/dist/validation/compiled/builtins.js +32 -0
- package/dist/validation/compiled/runtime.js +705 -0
- package/dist/validation/compiled/syntaxes.js +1620 -0
- package/dist/{lib/validation → validation}/config.js +41 -7
- package/dist/{lib/validation → validation}/first.js +6 -3
- package/dist/{lib/validation → validation}/match.js +87 -14
- package/dist/{lib/validation → validation}/parser/parse.js +1 -1
- package/dist/{lib/validation → validation}/parser/typedef.js +1 -1
- package/dist/{lib/validation → validation}/utils/list.js +1 -1
- package/dist/version.js +2 -2
- package/dist/web.js +23 -23
- package/package.json +4 -2
- package/dist/types.d.ts +0 -21
- package/dist/utils/sync.d.ts +0 -16
- package/dist/version.d.ts +0 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
# v2.3.1
|
|
4
|
+
|
|
5
|
+
- [x] fix deno install
|
|
6
|
+
- [x] document native and wasm builds
|
|
7
|
+
|
|
8
|
+
# v2.3.0
|
|
9
|
+
|
|
10
|
+
## Performance
|
|
11
|
+
|
|
12
|
+
- [x] validation: the syntaxes of the declarations, the types and the functions are compiled at build time into matchers (`npm run syntax-compile`, src/validation/compiled). a value accepted by a compiled matcher is valid, the other values are validated by the interpreter, which reports the errors. the values that contain `var()` or a custom function call are validated by the interpreter. `npm run syntax-verify` checks the compiled matchers against the interpreter
|
|
13
|
+
- [x] selectors: the validated tokens are written back in place instead of emptying the selector and pushing them again (the backing store of the array was released and allocated again for each selector)
|
|
14
|
+
- [x] validation: the validation contexts read a range of the tokens instead of a copy (`slice()`)
|
|
15
|
+
- [x] selectors: the syntax of a selector function (`:name()`) and the rules allowed in an at-rule are looked up once per name, the names are not concatenated for each selector. `:name` and `::name` are interned without creating a string
|
|
16
|
+
- [x] minifier: the size of the rules compared when they are merged is computed from the memoized sizes of their declarations instead of rendering them
|
|
17
|
+
- [x] render memo: the keys are hashed while they are serialized (one pass)
|
|
18
|
+
|
|
19
|
+
## Feature
|
|
20
|
+
|
|
21
|
+
- [x] update to webref/css syntax v8.7.10
|
|
22
|
+
- [x] syntax: `npm run syntax-update` compiles the syntaxes (`npm run syntax-compile`). a type that is referenced but neither defined nor built in fails the build: a definition renamed or removed upstream is reported (src/data/syntax-report.json)
|
|
23
|
+
- [x] visitors: the events are flags, a handler registered with `{type: WalkerEvent.Enter | WalkerEvent.Leave}` is called when the node is entered and when it is left
|
|
24
|
+
|
|
25
|
+
## Bugs
|
|
26
|
+
|
|
27
|
+
- [x] syntax: @webref/css 8.7.10. `<marker-ref>` (removed upstream, still referenced by `marker`, `marker-start`, `marker-mid`, `marker-end`) is defined by the local patch. an at-rule defined with several forms (`@property … { … } | @property … ;`) keeps the form with a block: `@property` rules were dropped
|
|
28
|
+
- [x] validation: a custom function call (`--fn()`) is validated like `var()`: it may be substituted by any value, the declaration that contains it is no longer reported as not valid. `width: --max-plus-x({ 1px, 7px, 2px }, 3px)` -> no error
|
|
29
|
+
- [x] web: `parse()` and `transform()` called with `{file}` lost the source of the file: the css module names lost the file parts (`[name]`, `[folder]`, `[ext]`, `[path]`), the source maps and the relative urls the file path
|
|
30
|
+
- [x] css modules: the case transform options are flags: they are tested with bitwise operators (`(naming & ModuleCaseTransformEnum.IgnoreCase) == 0`, `getKeyName()`)
|
|
31
|
+
|
|
3
32
|
# v2.2.0
|
|
4
33
|
|
|
5
34
|
## Bugs
|
package/README.md
CHANGED
|
@@ -57,7 +57,7 @@ $ deno add @tbela99/css-parser
|
|
|
57
57
|
CSS-Parser can transform these modern CSS features into lower-level CSS syntax:
|
|
58
58
|
* **Nested CSS transpilation** to legacy-compatible syntax.
|
|
59
59
|
* **`if()` function transpilation** for broader browser compatibility.
|
|
60
|
-
* **CSS mixins and custom functions evaluation** the `@apply` rules are replaced by the mixin body, the custom function calls are replaced by their result.
|
|
60
|
+
* **CSS mixins and custom functions evaluation** (experimental, enabled with `{evaluateMixins: true}`) the `@apply` rules are replaced by the mixin body, the custom function calls are replaced by their result, see [syntax lowering](https://tbela99.github.io/css-parser/docs/documents/Guide.Syntax_Lowering.html).
|
|
61
61
|
* **`color-mix()` function conversion** convert new color-mix() syntax to any of the supported colors.
|
|
62
62
|
|
|
63
63
|
## Benchmark
|
|
@@ -111,14 +111,29 @@ console.debug(result.code);
|
|
|
111
111
|
console.debug(result.stats);
|
|
112
112
|
```
|
|
113
113
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
|
114
|
+
Compared with lightningcss and esbuild: the 12 files of the [benchmark](https://tbela99.github.io/css-parser/benchmark/index.html)
|
|
115
|
+
(3.1 MB), total of the median times and of the output sizes (Apple M2, Node.js 27). "Fast settings" are the settings of
|
|
116
|
+
the example above, "default settings" are the defaults (full minification). The
|
|
117
|
+
[native](https://tbela99.github.io/css-parser/docs/documents/Guide.Native_build_%28N-API%29.html) and the
|
|
118
|
+
[WebAssembly](https://tbela99.github.io/css-parser/docs/documents/Guide.WebAssembly_build.html) builds produce the
|
|
119
|
+
same output as the TypeScript library, faster.
|
|
120
|
+
|
|
121
|
+
| Library | Time | Output | Output vs lightningcss |
|
|
122
|
+
|---------|-----:|-------:|-----------------------:|
|
|
123
|
+
| lightningcss | 59.6 ms | 2370 KB | |
|
|
124
|
+
| esbuild | 113.1 ms | 2487 KB | +4.9% |
|
|
125
|
+
| N-API, default settings | 136.7 ms | 2098 KB | **-11.5%** |
|
|
126
|
+
| WebAssembly, default settings | 166.3 ms | 2098 KB | **-11.5%** |
|
|
127
|
+
| TypeScript, default settings | 292.8 ms | 2098 KB | **-11.5%** |
|
|
128
|
+
| N-API, fast settings | 65.9 ms | 2404 KB | +1.4% |
|
|
129
|
+
| WebAssembly, fast settings | 94.1 ms | 2404 KB | +1.4% |
|
|
130
|
+
| TypeScript, fast settings | 176.7 ms | 2404 KB | +1.4% |
|
|
131
|
+
|
|
132
|
+
- With the default settings, the output is 11.5% smaller than lightningcss. Lightningcss is about 2.3 times faster
|
|
133
|
+
than the N-API build.
|
|
134
|
+
- With the fast settings, the N-API build is about as fast as lightningcss, with an output 1.4% larger.
|
|
135
|
+
|
|
136
|
+
See [Performance](https://tbela99.github.io/css-parser/docs/documents/Guide.Performance.html) for the details.
|
|
122
137
|
|
|
123
138
|
## Playground
|
|
124
139
|
|
|
@@ -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.
|
|
5
|
+
Version: 2.3.1
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
/**
|
|
@@ -105,6 +105,8 @@ class StructuralMemo {
|
|
|
105
105
|
* end of the key being looked up in the pool
|
|
106
106
|
*/
|
|
107
107
|
used = 0;
|
|
108
|
+
// hash of the key being serialized, see serialize() and lookup()
|
|
109
|
+
hash = 0x811c9dc5;
|
|
108
110
|
/**
|
|
109
111
|
* @param numericEquality compare the numeric values with `==` semantics (`0` and `-0` are equal) and consider
|
|
110
112
|
* all the `NaN` values equal. the raw bits are compared otherwise
|
|
@@ -130,6 +132,7 @@ class StructuralMemo {
|
|
|
130
132
|
this.growPool(used + 1);
|
|
131
133
|
}
|
|
132
134
|
this.pool[used++] = prefix;
|
|
135
|
+
this.hash = Math.imul(0x811c9dc5 ^ prefix, 0x01000193);
|
|
133
136
|
for (let token = first; token !== 0; token = arena.nextSibling[token]) {
|
|
134
137
|
used = this.serialize(arena, token, used);
|
|
135
138
|
}
|
|
@@ -142,6 +145,7 @@ class StructuralMemo {
|
|
|
142
145
|
* @param token
|
|
143
146
|
*/
|
|
144
147
|
token(arena, token) {
|
|
148
|
+
this.hash = 0x811c9dc5;
|
|
145
149
|
this.used = this.serialize(arena, token, this.poolSize);
|
|
146
150
|
return this.lookup();
|
|
147
151
|
}
|
|
@@ -188,50 +192,63 @@ class StructuralMemo {
|
|
|
188
192
|
const firstToken = arena.firstToken[token];
|
|
189
193
|
const firstChild = arena.firstChild[token];
|
|
190
194
|
let value = arena.numericValue[token];
|
|
191
|
-
// type and color type are 8 bits values
|
|
195
|
+
// type and color type are 8 bits values. the header is computed before its fields are written: the key is
|
|
196
|
+
// hashed while it is written, in order (see lookup())
|
|
192
197
|
let header = arena.dataTypes[token] | (arena.colorType[token] << 8);
|
|
193
|
-
|
|
198
|
+
let hash = this.hash;
|
|
194
199
|
if (name !== 0) {
|
|
195
200
|
header |= 65536 /* Field.Name */;
|
|
196
|
-
buffer[used++] = name;
|
|
197
201
|
}
|
|
198
202
|
if (str !== 0) {
|
|
199
203
|
header |= 131072 /* Field.String */;
|
|
200
|
-
buffer[used++] = str;
|
|
201
204
|
}
|
|
202
205
|
if (unit !== 0) {
|
|
203
206
|
header |= 262144 /* Field.Unit */;
|
|
204
|
-
buffer[used++] = unit;
|
|
205
207
|
}
|
|
206
208
|
if (this.numericEquality) {
|
|
207
209
|
value = normalize(value);
|
|
208
210
|
}
|
|
209
211
|
// 0 is not serialized. -0 is not an integer: its raw bits are serialized
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
header |= 524288 /* Field.Integer */;
|
|
213
|
-
buffer[used++] = value;
|
|
214
|
-
}
|
|
215
|
-
else {
|
|
216
|
-
header |= 1048576 /* Field.Number */;
|
|
217
|
-
f64[0] = value;
|
|
218
|
-
buffer[used++] = bits[0];
|
|
219
|
-
buffer[used++] = bits[1];
|
|
220
|
-
}
|
|
221
|
-
}
|
|
212
|
+
const numeric = value !== 0 || 1 / value < 0 ? ((value | 0) === value && value !== 0 ? 524288 /* Field.Integer */ : 1048576 /* Field.Number */) : 0;
|
|
213
|
+
header |= numeric;
|
|
222
214
|
if (firstToken !== 0) {
|
|
223
215
|
header |= 2097152 /* Field.Tokens */;
|
|
224
216
|
}
|
|
225
217
|
if (firstChild !== 0) {
|
|
226
218
|
header |= 4194304 /* Field.Children */;
|
|
227
219
|
}
|
|
228
|
-
buffer[
|
|
220
|
+
buffer[used++] = header;
|
|
221
|
+
hash = Math.imul(hash ^ header, 0x01000193);
|
|
222
|
+
if (name !== 0) {
|
|
223
|
+
buffer[used++] = name;
|
|
224
|
+
hash = Math.imul(hash ^ name, 0x01000193);
|
|
225
|
+
}
|
|
226
|
+
if (str !== 0) {
|
|
227
|
+
buffer[used++] = str;
|
|
228
|
+
hash = Math.imul(hash ^ str, 0x01000193);
|
|
229
|
+
}
|
|
230
|
+
if (unit !== 0) {
|
|
231
|
+
buffer[used++] = unit;
|
|
232
|
+
hash = Math.imul(hash ^ unit, 0x01000193);
|
|
233
|
+
}
|
|
234
|
+
if (numeric === 524288 /* Field.Integer */) {
|
|
235
|
+
buffer[used++] = value;
|
|
236
|
+
hash = Math.imul(hash ^ value, 0x01000193);
|
|
237
|
+
}
|
|
238
|
+
else if (numeric === 1048576 /* Field.Number */) {
|
|
239
|
+
f64[0] = value;
|
|
240
|
+
buffer[used++] = bits[0];
|
|
241
|
+
buffer[used++] = bits[1];
|
|
242
|
+
hash = Math.imul(Math.imul(hash ^ bits[0], 0x01000193) ^ bits[1], 0x01000193);
|
|
243
|
+
}
|
|
244
|
+
this.hash = hash;
|
|
229
245
|
if (firstToken !== 0) {
|
|
230
246
|
for (let child = firstToken; child !== 0; child = arena.nextSibling[child]) {
|
|
231
247
|
used = this.serialize(arena, child, used);
|
|
232
248
|
}
|
|
233
249
|
buffer = used + 1 > this.poolLength ? this.growPool(used + 1) : this.pool;
|
|
234
250
|
buffer[used++] = End;
|
|
251
|
+
this.hash = Math.imul(this.hash ^ End, 0x01000193);
|
|
235
252
|
}
|
|
236
253
|
if (firstChild !== 0) {
|
|
237
254
|
for (let child = firstChild; child !== 0; child = arena.nextSibling[child]) {
|
|
@@ -239,6 +256,7 @@ class StructuralMemo {
|
|
|
239
256
|
}
|
|
240
257
|
buffer = used + 1 > this.poolLength ? this.growPool(used + 1) : this.pool;
|
|
241
258
|
buffer[used++] = End;
|
|
259
|
+
this.hash = Math.imul(this.hash ^ End, 0x01000193);
|
|
242
260
|
}
|
|
243
261
|
return used;
|
|
244
262
|
}
|
|
@@ -258,10 +276,8 @@ class StructuralMemo {
|
|
|
258
276
|
const pool = this.pool;
|
|
259
277
|
const base = this.poolSize;
|
|
260
278
|
const length = this.used - base;
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
hash = Math.imul(hash ^ pool[i], 0x01000193);
|
|
264
|
-
}
|
|
279
|
+
// the key was hashed while it was serialized: the length is mixed in
|
|
280
|
+
let hash = Math.imul(this.hash ^ length, 0x01000193);
|
|
265
281
|
// the multiplications only propagate the bits upwards: the low bits, used as the table index, are mixed with
|
|
266
282
|
// the high bits (murmur3 finalizer)
|
|
267
283
|
hash ^= hash >>> 16;
|
|
@@ -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.
|
|
5
|
+
Version: 2.3.1
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { hashString, hashRange } from '../parser/utils/codes.js';
|
|
@@ -83,6 +83,10 @@ var StringDerived;
|
|
|
83
83
|
* the kind of a transform function name or of a transform property name (see `transformKind()`)
|
|
84
84
|
*/
|
|
85
85
|
StringDerived[StringDerived["TransformKind"] = 2] = "TransformKind";
|
|
86
|
+
/**
|
|
87
|
+
* true if the rules are allowed in the block of an at-rule (by name, without `@`), see `parseSelector()`
|
|
88
|
+
*/
|
|
89
|
+
StringDerived[StringDerived["AtRuleAcceptsRules"] = 3] = "AtRuleAcceptsRules";
|
|
86
90
|
})(StringDerived || (StringDerived = {}));
|
|
87
91
|
/**
|
|
88
92
|
* string of a range of code units
|