@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
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,90 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
# v2.2.0
|
|
4
|
+
|
|
5
|
+
## Bugs
|
|
6
|
+
|
|
7
|
+
- [x] minifier: the universal selector was removed before a combinator: `.foo *+.x` became `.foo +.x`, `.a * .b` became `.a .b`, `*|*` became `|*`
|
|
8
|
+
- [x] minifier: the selectors factored with `:is()` lost the descendant combinator: `.foo .a,.foo .b` became `.foo:is(.a,.b)` instead of `.foo :is(.a,.b)`
|
|
9
|
+
- [x] minifier: the declarations of a rule were moved across an `@apply` rule, an empty contents block was removed: `@apply --mixin {}`
|
|
10
|
+
- [x] minifier: the unit of the `initial-value` of `@property` was removed: `initial-value: 0deg` became `initial-value: 0`, which is not a valid `<angle>`
|
|
11
|
+
- [x] minifier: there is no early return in a `@function`: the `result` that precedes the conditional rules is moved after them. `result: 16px; @media (...) { result: 20px }` -> `@media (...) { result: 20px } result: 16px`
|
|
12
|
+
- [x] minifier: the conditional rules of a `@function` were removed when they were placed before the last `result`: they are never removed
|
|
13
|
+
- [x] minifier: the `result` descriptors of a `@function` were only deduplicated with `{validation: true}`: `@function --mypi() { result: 3; result: 3.14; }` -> `@function --mypi(){result:3.14}`
|
|
14
|
+
- [x] an empty `@function` or `@mixin` was removed with `removeEmpty`, and a `@function` with an empty result (`result: ;`) was dropped: they are valid definitions
|
|
15
|
+
- [x] a declaration that is not `!important` no longer overrides a previous `!important` declaration of the same property: `.a{color:red !important;color:blue}` -> `.a{color:red!important}`
|
|
16
|
+
- [x] minifier: the merge of two rules is kept only when the output is smaller (or has the same size and removes a rule). the merge of a rule into a rule that keeps some declarations repeated the selector of that rule: `html{margin:0}body,div,...{margin:0;font:inherit}` became `html,body,div,...{margin:0}body,div,...{font:inherit}`. the minified output
|
|
17
|
+
- [x] minifier: `text-emphasis` declarations threw `Cannot read properties of undefined (reading 'includes')` (`text-emphasis-color` has no keyword)
|
|
18
|
+
- [x] `parse()`, `parseSync()`, `transform()`, `transformSync()` and `render()` no longer modify the options object of the caller: a reused options object kept the source and the code units of the first input, and its validation (sync api) traversed them at every call. the sync api options check only traverses the plain objects and the arrays of `blueprint.css` was larger than the output of the fast mode (`minify: false`)
|
|
19
|
+
|
|
20
|
+
## Feature
|
|
21
|
+
- [x] experimental: evaluate css mixins with `{evaluateMixins: true}`: the `@apply` rules are replaced by the mixin body, the private variables (`@private`, mixin arguments, custom properties of the rule) are substituted https://drafts.csswg.org/css-mixins-1/#mixin-rule
|
|
22
|
+
- [x] minification: `@apply --mixin()` is minified to `@apply --mixin`
|
|
23
|
+
- [x] the evaluated mixins and the mixins that are not referenced are replaced with a comment, they are kept with `{keepMixins: true}`
|
|
24
|
+
- [x] a mixin can be defined in a cascade layer or a conditional group rule that is not nested in a style rule
|
|
25
|
+
- [x] custom functions: a call that is not evaluated makes the declaration, the custom function and the mixin that contain it fail, they are not evaluated
|
|
26
|
+
- [x] custom functions that contain conditional rules (`@media`, `@supports`, `@container`, `@when`, `@else`) are not evaluated
|
|
27
|
+
- [x] mixins and custom functions: a definition located in a rule or an at-rule is only visible inside of it, it hides the definitions with the same name of the outer scopes. a reference that does not see a definition is not evaluated
|
|
28
|
+
- [x] mixins: `@contents` is replaced with a copy of the contents block of the `@apply` rule, or with its default contents. `@result` is supported
|
|
29
|
+
- [x] mixins: the value of a typed argument is computed on the element the mixin is applied to, using a registered custom property (`@property`) when a descendant references it
|
|
30
|
+
- [x] evaluate the custom functions with `{evaluateMixins: true}`: the custom function calls (`--fn(1px)`) are replaced by the result of the function
|
|
31
|
+
- [x] the rules that apply a mixin are not merged
|
|
32
|
+
- [x] mixins and custom functions: a value that is not valid is left as is. a mixin that is not valid is ignored and left as is
|
|
33
|
+
- [x] custom functions: a `@function` rule whose parameters contain the same name more than once is invalid, it is dropped when `{evaluateMixins: true}`. the custom functions see the custom properties of the call site. the css-wide keywords of the local variables: `initial` is the value of the parameter, `inherit` and `unset` the value of the calling context. the invalid declarations are not evaluated
|
|
34
|
+
- [x] shorthand properties `padding-inline`, `padding-block`, `margin-inline` and `margin-block`: `.a{margin-inline-start:auto;margin-inline-end:auto}` -> `.a{margin-inline:auto}`
|
|
35
|
+
- [x] `RenderResult` and `TransformResult` are classes. the generated css is accumulated as UTF-8 bytes in `result.write` (`Uint8Array`), `result.code` is a getter that decodes the bytes once, when it is first read.
|
|
36
|
+
|
|
37
|
+
## Performance
|
|
38
|
+
- [x] avoid temporary strings allocation
|
|
39
|
+
- [x] faster css transform minification
|
|
40
|
+
|
|
41
|
+
## Validation
|
|
42
|
+
- [x] rewrite validation to reduce execution time
|
|
43
|
+
|
|
44
|
+
# v2.1.0
|
|
45
|
+
|
|
46
|
+
## Bugs
|
|
47
|
+
|
|
48
|
+
- [x] do not strip unit from dash ident #180
|
|
49
|
+
- [x] deduplicate important rule #180
|
|
50
|
+
- [x] incorrectly parsing keyframe rule 0% as literal token #180
|
|
51
|
+
|
|
52
|
+
## Feature
|
|
53
|
+
|
|
54
|
+
- [x] now accepting arraybuffer as input data: transformSync(arraybuffer);
|
|
55
|
+
- [ ] renamed 'word-wrap' to 'overflow-wrap', 'grid-gap' to 'gap', 'grid-row-gap' to 'row-gap', 'grid-column-gap' to 'column-gap', 'font-stretch' to 'font-width'.
|
|
56
|
+
|
|
57
|
+
## Validation
|
|
58
|
+
- [x] switching syntax definitions source from mdn-data to webref/css
|
|
59
|
+
- [x] the validation syntaxes are generated from the CSS definitions of [W3C webref](https://github.com/w3c/webref) instead of mdn-data (deprecated): `npm run syntax-update` runs `scripts/webref.ts`, `scripts/validation.ts` is removed
|
|
60
|
+
- [x] the units are listed in `scripts/local-patch.json`: `@webref/css` does not list them
|
|
61
|
+
- [x] a function or a type defined differently for different scopes keeps its definitions: the scoped definition is inlined in the syntax of its scope (`clip: rect( <top>, <right>, <bottom>, <left> ) | auto`, the `<basic-shape>` `rect()` is the shared definition)
|
|
62
|
+
- [x] a group is no longer matched when the value ends before its mandatory parts: `cubic-bezier(.4,0,.2)`, `[ <a> && <b> ]` with `<a>` only
|
|
63
|
+
- [x] the range of a numeric type is checked when it is the last token: `grid-row: 0`, `width: -10px`
|
|
64
|
+
- [x] `<x>#? , <y>` (`background`) leaves the last item to `<y>`, a list item must match all the tokens before the next comma, `var()` may be a part of a syntax (`var(--color) 65%` in a gradient)
|
|
65
|
+
- [x] the longhands that follow a shorthand that contains `var()` are not merged into it: `border: var(--b); border-color: red`
|
|
66
|
+
- [x] a value is invalid when the tokens are not all consumed by the syntax: `color: red blue`, `width: 10px 20px`
|
|
67
|
+
- [x] `:` is parsed as a colon (`ValidationTokenEnum.Colon`, matches `EnumToken.ColonTokenType`) in the validation syntaxes: `<ident-token> : <declaration-value>?`, `name: <value>`
|
|
68
|
+
- [x] a media feature length may be the number `0`: `@when media(width > 0)`
|
|
69
|
+
- [x] the `||` syntaxes are matched in the order that matches the most tokens: `transition: .2s ease-in-out transform`
|
|
70
|
+
- [x] the `&&` syntaxes are matched in any order, the optional syntaxes may be omitted: `[ <ident> && <length> ]` matches `thin 10px` and `10px thin`, `box-shadow: 0 0 red`
|
|
71
|
+
- [x] new length units: `rex`, `rcap`, `rch`, `ric`, `lvmin`, `svmax`. the unit functions (`isLengthUnit()`, `isFrequencyUnit()`, ...) are case-insensitive (`Q`, `Hz`, `kHz`)
|
|
72
|
+
- [x] `length2Px()` converts `in` (96px) and `pc` (16px) correctly, the units are case-insensitive
|
|
73
|
+
- [x] a number followed by `!important` is no longer dropped: `margin: 8px 0 0!important`
|
|
74
|
+
- [x] the `!important` longhands are not merged into a shorthand (the minifier threw an error): `column-gap: 16px !important; row-gap: 40px !important`
|
|
75
|
+
- [x] new token type `EnumToken.UniCodeRange`: `U+0025-00FF`, `U+4??` are read as a single token and rendered as they are. `u+a` is a selector in a rule prelude
|
|
76
|
+
- [x] `unicode-range` is validated (the validation threw an error)
|
|
77
|
+
- [x] the units are rendered in their canonical spelling: `20hz` is rendered `20Hz`, `2q` `2Q`, `6DB` `6dB`
|
|
78
|
+
- [x] the numbers with an exponent are parsed: `1.5e2!important`, `1e-3`, `1e+3`, `1.5e2px`
|
|
79
|
+
- [x] `<resolution>`, `<frequency>`, `<decibel>` and `<semitones>` are validated (the validation threw an error): `image-resolution`, `image-set()`, `voice-pitch`, `voice-volume`
|
|
80
|
+
- [x] the line endings are LF
|
|
81
|
+
- [x] `npm run syntax-update` prints a summary of the changes between the previous and the new syntax file (added, removed and changed declarations, types and functions, selectors, at-rules, descriptors, media features, units and languages) and appends it to `SYNTAX-CHANGES.md`, ignored by git
|
|
82
|
+
- [x] `npm run syntax-update` reports the removed definitions grouped by origin, with the url of the file that provided them: legacy mdn-data, mdn-data patch (csstree), `local-patch.json` or removed from webref. the origins are saved in `src/data/validation.origins.json`
|
|
83
|
+
- [x] the syntaxes are generated from the consolidated css definitions of `@webref/css`, pulled from a versioned url (`https://cdn.jsdelivr.net/npm/@webref/css@8.7.8/css.json`, updated manually: a new version may introduce breaking changes): the definitions of the latest level of a spec are used, the extensions and the descriptors defined by other specs are merged
|
|
84
|
+
- [x] the renamed properties (the legacy name aliases that are not vendor prefixed) are removed from the syntax file and reported as renamed, the parser renames them: `font-stretch` -> `font-width`, `grid-gap` -> `gap`, `grid-row-gap` -> `row-gap`, `grid-column-gap` -> `column-gap`, `word-wrap` -> `overflow-wrap`. `renamedStandardProperties` is updated manually: the report flags the renamed properties it does not contain
|
|
85
|
+
- [x] the at-rule descriptors defined by another spec are merged: `@font-face/size-adjust`
|
|
86
|
+
- [x] the value types are stored without their angle brackets (`types.color` for `<color>`)
|
|
87
|
+
|
|
3
88
|
# v2.0.1
|
|
4
89
|
|
|
5
90
|
rename file due to firefox blocking it
|
|
@@ -34,7 +119,7 @@ see the [migration guide](./files/migration.md)
|
|
|
34
119
|
- [x] removed `getNodeProperty()` and `setNodeProperty()`: use the arena methods (`arena.getState()`, `arena.setState()`, `arena.getErrors()`, ...) or the object view properties (`arena.toObject(id).state = ...`)
|
|
35
120
|
- [x] `WalkerEvent` and `WalkerOptionEnum` are declared with the other enums (they are still exported by the package)
|
|
36
121
|
|
|
37
|
-
performance
|
|
122
|
+
## performance
|
|
38
123
|
|
|
39
124
|
- [x] the parser recycles the tokens that are not attached to the tree (whitespace, `:`, `;`, `{`, `}`, ...): the arena allocates about half the nodes. `arena.recycle(id)` reuses the id of a detached leaf node
|
|
40
125
|
- [x] the initial arena capacity is one node for every 4 bytes of css
|
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@ A zero-allocation, high-performance CSS processing engine for Node.js and the br
|
|
|
9
9
|
Every stylesheet is fully parsed into a structured AST, with token values represented as typed data. This provides a reliable semantic foundation for custom transformations, plugin development, and advanced stylesheet analysis without relying on raw string manipulation.
|
|
10
10
|
|
|
11
11
|
> [!NOTE]
|
|
12
|
-
> Version 2.0 has been rewritten to use arena memory for AST nodes and tokens, improving memory usage and performance. On the Tailwind CSS parsing and validation workload, runtime is
|
|
12
|
+
> Version 2.2.0 has been rewritten to use arena memory for AST nodes and tokens, improving memory usage and performance. On the Tailwind CSS parsing and validation workload, runtime is **59% faster than v1.8.2** while using less memory.<br>
|
|
13
13
|
This major release also introduces breaking changes and removes deprecated features. See the [migration guide](https://tbela99.github.io/css-parser/docs/documents/Guide.Migration.html) for details.
|
|
14
14
|
|
|
15
15
|
## Installation
|
|
@@ -30,7 +30,7 @@ $ deno add @tbela99/css-parser
|
|
|
30
30
|
|
|
31
31
|
* **Zero dependencies** — lightweight and easy to integrate into any project.
|
|
32
32
|
* **All-in-one CSS parsing solution** covering parsing, validation, transformation, minification, and AST manipulation.
|
|
33
|
-
* **Standards-based CSS validation** powered by
|
|
33
|
+
* **Standards-based CSS validation** powered by the W3C specification definitions ([@webref/css](https://github.com/w3c/webref/tree/main/packages/css)).
|
|
34
34
|
* **Full CSS Modules support** for modern component-based workflows.
|
|
35
35
|
* **Fault-tolerant parsing** that follows the CSS Syntax Module Level 3 specification and always produces a complete, structured parse result.
|
|
36
36
|
* **Typed tokens and AST** — parsed CSS is exposed as strongly typed tokens and nodes so plugins and transforms can operate on semantic structures.
|
|
@@ -45,6 +45,9 @@ $ deno add @tbela99/css-parser
|
|
|
45
45
|
* **CSS variable inlining** where values can be safely resolved.
|
|
46
46
|
* **Duplicate declaration removal** to eliminate redundant rules.
|
|
47
47
|
* **`@import` flattening** to produce self-contained stylesheets.
|
|
48
|
+
* **Vendor prefix cleanup** to modernize generated CSS.
|
|
49
|
+
* **Binary input** — the css can be a string, an `ArrayBuffer` or an `ArrayBufferView` (utf-8 bytes, `Uint8Array`, `Buffer`): an ASCII buffer is tokenized without copy.
|
|
50
|
+
* **Experimental**: evaluate @mixin and @function
|
|
48
51
|
* **51.5kb** once minified and gzipped.
|
|
49
52
|
|
|
50
53
|
## Vendor prefix removal
|
|
@@ -54,6 +57,7 @@ $ deno add @tbela99/css-parser
|
|
|
54
57
|
CSS-Parser can transform these modern CSS features into lower-level CSS syntax:
|
|
55
58
|
* **Nested CSS transpilation** to legacy-compatible syntax.
|
|
56
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.
|
|
57
61
|
* **`color-mix()` function conversion** convert new color-mix() syntax to any of the supported colors.
|
|
58
62
|
|
|
59
63
|
## Benchmark
|
|
@@ -66,9 +70,9 @@ A sample result:
|
|
|
66
70
|
|
|
67
71
|
| File | ligthningcss | CSS Parser |
|
|
68
72
|
| ------------------------------ | ------------- | ------------- |
|
|
69
|
-
| tailwind.css - 2380419 bytes | 1864728 bytes |
|
|
70
|
-
| bootstrap-4.css - 200078 bytes | 153616 bytes |
|
|
71
|
-
| bootstrap-5.css - 205481 bytes | 159987 bytes |
|
|
73
|
+
| tailwind.css - 2380419 bytes | 1864728 bytes | 1624148 bytes |
|
|
74
|
+
| bootstrap-4.css - 200078 bytes | 153616 bytes | 144391 bytes |
|
|
75
|
+
| bootstrap-5.css - 205481 bytes | 159987 bytes | 150764 bytes |
|
|
72
76
|
|
|
73
77
|
On the [complete benchmark suite](https://tbela99.github.io/css-parser/benchmark/index.html), css-parser generated a total output size of 2,158,698 bytes, compared to 2,494,113 bytes for Lightning CSS and larger outputs for all other tested minifiers.
|
|
74
78
|
While some tools prioritize raw execution speed, css-parser focuses on maximizing compression while preserving stylesheet semantics, resulting in consistently smaller production bundles.
|
|
@@ -113,8 +117,8 @@ Performance vs execution speed comparison
|
|
|
113
117
|
| File: tailwind.css | Speed optimization | Minification optimization |
|
|
114
118
|
| --------------------- | ------------------ | ------------------------- |
|
|
115
119
|
| Size: 2,380,419 bytes | 1,890,835 bytes | 1,633,188 bytes |
|
|
116
|
-
| Time |
|
|
117
|
-
| Size reduction | -20.
|
|
120
|
+
| Time | 109.07 ms | 191.85 ms |
|
|
121
|
+
| Size reduction | -20.7% | -31.8% |
|
|
118
122
|
|
|
119
123
|
## Playground
|
|
120
124
|
|
|
@@ -320,11 +324,15 @@ See [Ast Manipulation](https://tbela99.github.io/css-parser/docs/documents/Guide
|
|
|
320
324
|
- [x] inset
|
|
321
325
|
- [x] list-style
|
|
322
326
|
- [x] margin
|
|
327
|
+
- [x] margin-block
|
|
328
|
+
- [x] margin-inline
|
|
323
329
|
- [ ] mask
|
|
324
330
|
- [ ] offset
|
|
325
331
|
- [x] outline
|
|
326
332
|
- [x] overflow
|
|
327
333
|
- [x] padding
|
|
334
|
+
- [x] padding-block
|
|
335
|
+
- [x] padding-inline
|
|
328
336
|
- [ ] place-content
|
|
329
337
|
- [ ] place-items
|
|
330
338
|
- [ ] place-self
|
package/architecture.png
CHANGED
|
Binary file
|
|
@@ -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
|
var properties = {
|
|
@@ -88,6 +88,50 @@ var properties = {
|
|
|
88
88
|
"margin-left": {
|
|
89
89
|
shorthand: "margin"
|
|
90
90
|
},
|
|
91
|
+
"margin-inline": {
|
|
92
|
+
shorthand: "margin-inline",
|
|
93
|
+
properties: [
|
|
94
|
+
"margin-inline-start",
|
|
95
|
+
"margin-inline-end"
|
|
96
|
+
],
|
|
97
|
+
types: [
|
|
98
|
+
"Length",
|
|
99
|
+
"Perc"
|
|
100
|
+
],
|
|
101
|
+
multiple: false,
|
|
102
|
+
separator: null,
|
|
103
|
+
keywords: [
|
|
104
|
+
"auto"
|
|
105
|
+
]
|
|
106
|
+
},
|
|
107
|
+
"margin-inline-start": {
|
|
108
|
+
shorthand: "margin-inline"
|
|
109
|
+
},
|
|
110
|
+
"margin-inline-end": {
|
|
111
|
+
shorthand: "margin-inline"
|
|
112
|
+
},
|
|
113
|
+
"margin-block": {
|
|
114
|
+
shorthand: "margin-block",
|
|
115
|
+
properties: [
|
|
116
|
+
"margin-block-start",
|
|
117
|
+
"margin-block-end"
|
|
118
|
+
],
|
|
119
|
+
types: [
|
|
120
|
+
"Length",
|
|
121
|
+
"Perc"
|
|
122
|
+
],
|
|
123
|
+
multiple: false,
|
|
124
|
+
separator: null,
|
|
125
|
+
keywords: [
|
|
126
|
+
"auto"
|
|
127
|
+
]
|
|
128
|
+
},
|
|
129
|
+
"margin-block-start": {
|
|
130
|
+
shorthand: "margin-block"
|
|
131
|
+
},
|
|
132
|
+
"margin-block-end": {
|
|
133
|
+
shorthand: "margin-block"
|
|
134
|
+
},
|
|
91
135
|
padding: {
|
|
92
136
|
shorthand: "padding",
|
|
93
137
|
properties: [
|
|
@@ -115,6 +159,44 @@ var properties = {
|
|
|
115
159
|
"padding-left": {
|
|
116
160
|
shorthand: "padding"
|
|
117
161
|
},
|
|
162
|
+
"padding-inline": {
|
|
163
|
+
shorthand: "padding-inline",
|
|
164
|
+
properties: [
|
|
165
|
+
"padding-inline-start",
|
|
166
|
+
"padding-inline-end"
|
|
167
|
+
],
|
|
168
|
+
types: [
|
|
169
|
+
"Length",
|
|
170
|
+
"Perc"
|
|
171
|
+
],
|
|
172
|
+
keywords: [
|
|
173
|
+
]
|
|
174
|
+
},
|
|
175
|
+
"padding-inline-start": {
|
|
176
|
+
shorthand: "padding-inline"
|
|
177
|
+
},
|
|
178
|
+
"padding-inline-end": {
|
|
179
|
+
shorthand: "padding-inline"
|
|
180
|
+
},
|
|
181
|
+
"padding-block": {
|
|
182
|
+
shorthand: "padding-block",
|
|
183
|
+
properties: [
|
|
184
|
+
"padding-block-start",
|
|
185
|
+
"padding-block-end"
|
|
186
|
+
],
|
|
187
|
+
types: [
|
|
188
|
+
"Length",
|
|
189
|
+
"Perc"
|
|
190
|
+
],
|
|
191
|
+
keywords: [
|
|
192
|
+
]
|
|
193
|
+
},
|
|
194
|
+
"padding-block-start": {
|
|
195
|
+
shorthand: "padding-block"
|
|
196
|
+
},
|
|
197
|
+
"padding-block-end": {
|
|
198
|
+
shorthand: "padding-block"
|
|
199
|
+
},
|
|
118
200
|
"scroll-margin": {
|
|
119
201
|
shorthand: "scroll-margin",
|
|
120
202
|
properties: [
|
|
@@ -872,6 +954,8 @@ var map = {
|
|
|
872
954
|
]
|
|
873
955
|
},
|
|
874
956
|
"text-emphasis-color": {
|
|
957
|
+
keywords: [
|
|
958
|
+
],
|
|
875
959
|
"default": [
|
|
876
960
|
"currentcolor"
|
|
877
961
|
],
|