@tbela99/css-parser 1.6.3 → 1.6.5

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.
Files changed (46) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/README.md +112 -8
  3. package/dist/{lib/data → data}/properties.json.js +296 -29
  4. package/dist/{lib/data → data}/validation.json.js +6 -0
  5. package/dist/index-umd-web.js +962 -744
  6. package/dist/index.cjs +961 -744
  7. package/dist/index.d.ts +24 -6
  8. package/dist/lib/ast/expand.js +1 -1
  9. package/dist/lib/ast/features/calc.js +16 -4
  10. package/dist/lib/ast/features/if.js +2 -2
  11. package/dist/lib/ast/features/inlinecssvariables.js +3 -3
  12. package/dist/lib/ast/features/prefix.js +2 -2
  13. package/dist/lib/ast/features/shorthand.js +8 -6
  14. package/dist/lib/ast/features/transform.js +2 -2
  15. package/dist/lib/ast/math/expression.js +24 -1
  16. package/dist/lib/ast/minify.js +3 -2
  17. package/dist/lib/ast/transform/utils.js +2 -2
  18. package/dist/lib/ast/walk.js +108 -90
  19. package/dist/lib/parser/declaration/list.js +29 -26
  20. package/dist/lib/parser/declaration/map.js +186 -54
  21. package/dist/lib/parser/parse.js +11 -9
  22. package/dist/lib/parser/source.js +2 -2
  23. package/dist/lib/parser/tokenize.js +99 -124
  24. package/dist/lib/parser/utils/config.js +1 -1
  25. package/dist/lib/parser/utils/declaration.js +0 -18
  26. package/dist/lib/parser/utils/hash.js +10 -5
  27. package/dist/lib/parser/utils/selector.js +1 -1
  28. package/dist/lib/{renderer → printer}/render.js +29 -53
  29. package/dist/lib/syntax/color/a98rgb.js +1 -1
  30. package/dist/lib/syntax/color/alpha.js +19 -20
  31. package/dist/lib/syntax/color/color-mix.js +15 -14
  32. package/dist/lib/syntax/color/hex.js +4 -1
  33. package/dist/lib/syntax/color/lch.js +0 -1
  34. package/dist/lib/syntax/color/oklch.js +0 -1
  35. package/dist/lib/syntax/color/relative-color.js +11 -11
  36. package/dist/lib/syntax/color/utils/components.js +0 -20
  37. package/dist/lib/syntax/color/xyzd50.js +0 -17
  38. package/dist/lib/syntax/constants.js +6 -1
  39. package/dist/lib/syntax/syntax.js +2 -2
  40. package/dist/lib/validation/config.js +5 -33
  41. package/dist/lib/validation/match.js +52 -181
  42. package/dist/node.js +3 -3
  43. package/dist/web.js +4 -3
  44. package/package.json +6 -5
  45. /package/dist/lib/{renderer → printer}/sourcemap/lib/codec.js +0 -0
  46. /package/dist/lib/{renderer → printer}/sourcemap/sourcemap.js +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,61 @@
1
1
  # Changelog
2
2
 
3
+ # v1.6.5
4
+
5
+ ## New
6
+
7
+ - [x] Added fine-grained minification parameters:
8
+ - [x] RenderOptions#minifyValues: minify CSS values such as numbers and dimension tokens
9
+ - [x] ParseOptions#minifyAST: minify the AST.
10
+
11
+ ## Improvement
12
+
13
+ ```css
14
+ .footer{
15
+ grid-row:4;
16
+ grid-column:1;
17
+ grid-column-end:2;
18
+ }
19
+ ```
20
+
21
+ is now computed as
22
+
23
+ ```css
24
+ .footer {
25
+ grid-area: 4/1/auto/2
26
+ }
27
+ ```
28
+
29
+ ## Fixes
30
+
31
+ - [x] fix a98-rgb, hwb color color space handling in color-mix()
32
+ - [x] fix percentage handling in relative rgb color
33
+
34
+ ```css
35
+ .c {
36
+ color: rgb(from rgb(20% 40% 60% / 80%) r g b / calc(alpha / 2));
37
+ ```
38
+ is now computed as
39
+
40
+ ```css
41
+ .c {
42
+ color: #3696
43
+ }
44
+ ```
45
+
46
+ # v1.6.4
47
+
48
+ ## New
49
+
50
+ Compute shorthand properties:
51
+ - grid-area
52
+ - grid-row
53
+ - grid-column
54
+
55
+ ## Improvement
56
+
57
+ faster tokenizer and node walker functions.
58
+
3
59
  # v1.6.3
4
60
 
5
61
  ## Fix
package/README.md CHANGED
@@ -61,13 +61,56 @@ A sample result:
61
61
 
62
62
  | File | ligthningcss | CSS Parser |
63
63
  | ------------------------------ | ------------- | ------------- |
64
- | tailwind.css - 2380419 bytes | 1864728 bytes | 1633251 bytes |
65
- | bootstrap-4.css - 200078 bytes | 153616 bytes | 144700 bytes |
66
- | bootstrap-5.css - 205481 bytes | 159987 bytes | 151258 bytes |
64
+ | tailwind.css - 2380419 bytes | 1864728 bytes | 1633188 bytes |
65
+ | bootstrap-4.css - 200078 bytes | 153616 bytes | 144571 bytes |
66
+ | bootstrap-5.css - 205481 bytes | 159987 bytes | 150852 bytes |
67
67
 
68
- On the [complete benchmark suite](https://tbela99.github.io/css-parser/benchmark/index.html), css-parser generated a total output size of 2,204,888 bytes, compared to 2,494,113 bytes for Lightning CSS and larger outputs for all other tested minifiers.
68
+ 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.
69
69
  While some tools prioritize raw execution speed, css-parser focuses on maximizing compression while preserving stylesheet semantics, resulting in consistently smaller production bundles.
70
70
 
71
+ ## Minification performance vs execution speed
72
+
73
+ `css-parser` is designed for maximum minification performance, but the optimal configuration depends on what matters most for your workload.
74
+
75
+ The parser provides settings that let you choose the balance between minification performance and execution speed:
76
+
77
+ - Minification performance: prioritize the quality and efficiency of the minification process, allowing the parser to perform additional work when generating the minimized output.
78
+
79
+ - Execution speed: minimize the amount of work performed during parsing and minification to achieve the fastest possible execution time.
80
+
81
+ However, the available settings allow you to shift the balance toward execution speed when minimizing runtime is more important than performing every available minification optimization.
82
+
83
+ The example below demonstrates a balanced configuration that improves execution speed by disabling advanced minification features.
84
+
85
+ ```ts
86
+
87
+ import {transformSync} from "@tbela99/css-parser";
88
+
89
+ const css = `...`;
90
+
91
+ const result = transformSync({
92
+ input: css,
93
+ minify: false,
94
+ beautify: false,
95
+ removeEmpty: true,
96
+ removeComments: true,
97
+ convertColor: true,
98
+ minifyValues: true,
99
+ });
100
+
101
+ console.debug(result.code);
102
+ console.debug(result.stats);
103
+ ```
104
+
105
+ Performance vs execution speed comparison
106
+
107
+
108
+ | File: tailwind.css | Speed optimization | Minification optimization |
109
+ | --------------------- | ------------------ | ------------------------- |
110
+ | Size: 2,380,419 bytes | 1,890,728 bytes | 1,633,188 bytes |
111
+ | Time | 205.91 ms | 471.89 ms |
112
+ | Size reduction | -20.6% | -31.4% |
113
+
71
114
  ## Playground
72
115
 
73
116
  Try it [online](https://tbela99.github.io/css-parser/playground/)
@@ -171,10 +214,10 @@ Try it [online](https://tbela99.github.io/css-parser/playground/)
171
214
  - [ ] font-variant
172
215
  - [x] gap
173
216
  - [ ] grid
174
- - [ ] grid-area
175
- - [ ] grid-column
176
- - [ ] grid-row
177
- - [ ] grid-template
217
+ - [x] grid-area
218
+ - [x] grid-column
219
+ - [x] grid-row
220
+ - [x] grid-template
178
221
  - [x] inset
179
222
  - [x] list-style
180
223
  - [x] margin
@@ -196,3 +239,64 @@ Try it [online](https://tbela99.github.io/css-parser/playground/)
196
239
  ## Performance
197
240
 
198
241
  - [x] Bundle file referenced by the @import statement.
242
+
243
+ # Architecture
244
+
245
+ ```mermaid
246
+ flowchart TD
247
+ %% --- Transform ---
248
+ Input(["CSS input"])
249
+
250
+
251
+ %% The Grouped Container
252
+ subgraph Group10["Transform step"]
253
+
254
+ transform["transform()/transformSync()"]
255
+
256
+
257
+ %% The Grouped Container
258
+ subgraph Group1 ["Parse step"]
259
+
260
+ %% --- Parse step ---
261
+ parse["parse()/parseSync()"]
262
+ tokenize(["tokenize()"])
263
+ parseNode(["parse and validate token stream"])
264
+ visitors(["visitors"])
265
+ minify(["minify AST"])
266
+ cssModules(["generate CSS module"])
267
+ parseResult["Parse result"]
268
+ end
269
+
270
+ %% The Grouped Container
271
+ subgraph Group2 ["Render step"]
272
+
273
+ %% --- Render step ---
274
+ renderAst(["Render AST"])
275
+ sourcemap([Sourcemap generation])
276
+
277
+ end
278
+
279
+ %% --- Result step ---
280
+ transformResult["Transform result"]
281
+ end
282
+
283
+ %% --- Routing step ---
284
+ Input --> transform
285
+ transform --> parse
286
+ parse --> tokenize
287
+ tokenize --> parseNode
288
+ parseNode -- "Visitors set?" --> visitors
289
+ visitors -- "Minify AST?" --> minify
290
+ minify -- "CSS module?" --> cssModules
291
+ visitors -- "CSS module?" --> cssModules
292
+ cssModules --> parseResult
293
+ parseNode -- "CSS module?" --> cssModules
294
+ parseNode -- "Minify AST?" --> minify
295
+ parseNode --> parseResult
296
+ visitors --> parseResult
297
+ minify --> parseResult
298
+ parseResult --> renderAst
299
+ renderAst -- "Sourcemap?" --> sourcemap
300
+ renderAst --> transformResult
301
+ sourcemap --> transformResult
302
+ ```
@@ -313,35 +313,6 @@ var properties = {
313
313
  "border-left-color": {
314
314
  map: "border",
315
315
  shorthand: "border-color"
316
- },
317
- "grid-row": {
318
- shorthand: "grid-row",
319
- properties: [
320
- "grid-row-start",
321
- "grid-row-end"
322
- ],
323
- types: [
324
- "Iden",
325
- "Number"
326
- ],
327
- multiple: true,
328
- valueSeparator: {
329
- typ: "Literal",
330
- val: "/"
331
- },
332
- "default": [
333
- "auto"
334
- ],
335
- keywords: [
336
- "auto",
337
- "span"
338
- ]
339
- },
340
- "grid-row-start": {
341
- shorthand: "grid-row"
342
- },
343
- "grid-row-end": {
344
- shorthand: "grid-row"
345
316
  }
346
317
  };
347
318
  var map = {
@@ -1607,6 +1578,302 @@ var map = {
1607
1578
  },
1608
1579
  "background-size": {
1609
1580
  shorthand: "background"
1581
+ },
1582
+ "grid-area": {
1583
+ shorthand: "grid-area",
1584
+ pattern: "grid-row-start grid-column-start grid-row-end grid-column-end",
1585
+ keywords: [
1586
+ "auto"
1587
+ ],
1588
+ "default": [
1589
+ "auto"
1590
+ ],
1591
+ multiple: false,
1592
+ expandShorthands: true,
1593
+ separator: {
1594
+ typ: "Literal",
1595
+ val: "/"
1596
+ },
1597
+ mapping: {
1598
+ "auto/auto": "auto",
1599
+ "auto/auto/auto": "auto",
1600
+ "auto/auto/auto/auto": "auto"
1601
+ },
1602
+ expandedProperties: {
1603
+ "grid-row": [
1604
+ "grid-row-start",
1605
+ "grid-row-end"
1606
+ ],
1607
+ "grid-column": [
1608
+ "grid-column-start",
1609
+ "grid-column-end"
1610
+ ]
1611
+ },
1612
+ properties: {
1613
+ "grid-row-start": {
1614
+ map: "grid-area",
1615
+ shorthand: "grid-row",
1616
+ types: [
1617
+ "Iden",
1618
+ "Number"
1619
+ ],
1620
+ "default": [
1621
+ "auto"
1622
+ ],
1623
+ keywords: [
1624
+ "auto"
1625
+ ]
1626
+ },
1627
+ "grid-column-start": {
1628
+ map: "grid-area",
1629
+ shorthand: "grid-column",
1630
+ types: [
1631
+ "Iden",
1632
+ "Number"
1633
+ ],
1634
+ prefix: {
1635
+ typ: "Literal",
1636
+ val: "/"
1637
+ },
1638
+ "default": [
1639
+ "auto"
1640
+ ],
1641
+ keywords: [
1642
+ "auto"
1643
+ ]
1644
+ },
1645
+ "grid-row-end": {
1646
+ map: "grid-area",
1647
+ shorthand: "grid-row",
1648
+ types: [
1649
+ "Iden",
1650
+ "Number"
1651
+ ],
1652
+ prefix: {
1653
+ typ: "Literal",
1654
+ val: "/"
1655
+ },
1656
+ "default": [
1657
+ "auto"
1658
+ ],
1659
+ keywords: [
1660
+ "auto"
1661
+ ]
1662
+ },
1663
+ "grid-column-end": {
1664
+ map: "grid-area",
1665
+ shorthand: "grid-column",
1666
+ types: [
1667
+ "Iden",
1668
+ "Number"
1669
+ ],
1670
+ prefix: {
1671
+ typ: "Literal",
1672
+ val: "/"
1673
+ },
1674
+ "default": [
1675
+ "auto"
1676
+ ],
1677
+ keywords: [
1678
+ "auto"
1679
+ ]
1680
+ }
1681
+ }
1682
+ },
1683
+ "grid-row-start": {
1684
+ shorthand: "grid-row"
1685
+ },
1686
+ "grid-column-start": {
1687
+ shorthand: "grid-column"
1688
+ },
1689
+ "grid-row-end": {
1690
+ shorthand: "grid-row"
1691
+ },
1692
+ "grid-column-end": {
1693
+ shorthand: "grid-column"
1694
+ },
1695
+ "grid-row": {
1696
+ shorthand: "grid-row",
1697
+ map: "grid-area",
1698
+ pattern: "grid-row-start grid-row-end",
1699
+ types: [
1700
+ "Iden",
1701
+ "Number"
1702
+ ],
1703
+ keywords: [
1704
+ "auto"
1705
+ ],
1706
+ "default": [
1707
+ "auto"
1708
+ ],
1709
+ multiple: false,
1710
+ mapping: {
1711
+ "auto auto": "auto",
1712
+ "auto/auto": "auto"
1713
+ },
1714
+ properties: {
1715
+ "grid-row-start": {
1716
+ map: "grid-area",
1717
+ types: [
1718
+ "Iden",
1719
+ "Number"
1720
+ ],
1721
+ "default": [
1722
+ "auto"
1723
+ ],
1724
+ multiple: true,
1725
+ keywords: [
1726
+ "auto"
1727
+ ]
1728
+ },
1729
+ "grid-row-end": {
1730
+ map: "grid-area",
1731
+ types: [
1732
+ "Iden",
1733
+ "Number"
1734
+ ],
1735
+ "default": [
1736
+ "auto"
1737
+ ],
1738
+ prefix: {
1739
+ typ: "Literal",
1740
+ val: "/"
1741
+ },
1742
+ multiple: true,
1743
+ keywords: [
1744
+ "auto"
1745
+ ]
1746
+ }
1747
+ }
1748
+ },
1749
+ "grid-column": {
1750
+ shorthand: "grid-column",
1751
+ map: "grid-area",
1752
+ pattern: "grid-column-start grid-column-end",
1753
+ types: [
1754
+ "Iden",
1755
+ "Number"
1756
+ ],
1757
+ keywords: [
1758
+ "auto"
1759
+ ],
1760
+ "default": [
1761
+ "auto"
1762
+ ],
1763
+ multiple: false,
1764
+ mapping: {
1765
+ "auto/auto": "auto"
1766
+ },
1767
+ properties: {
1768
+ "grid-column-start": {
1769
+ map: "grid-area",
1770
+ types: [
1771
+ "Iden",
1772
+ "Number"
1773
+ ],
1774
+ "default": [
1775
+ "auto"
1776
+ ],
1777
+ multiple: true,
1778
+ keywords: [
1779
+ "auto"
1780
+ ]
1781
+ },
1782
+ "grid-column-end": {
1783
+ map: "grid-area",
1784
+ types: [
1785
+ "Iden",
1786
+ "Number"
1787
+ ],
1788
+ "default": [
1789
+ "auto"
1790
+ ],
1791
+ multiple: true,
1792
+ prefix: {
1793
+ typ: "Literal",
1794
+ val: "/"
1795
+ },
1796
+ keywords: [
1797
+ "auto"
1798
+ ]
1799
+ }
1800
+ }
1801
+ },
1802
+ "grid-template": {
1803
+ shorthand: "grid-template",
1804
+ pattern: "grid-template-areas grid-template-rows grid-template-columns",
1805
+ keywords: [
1806
+ "none"
1807
+ ],
1808
+ "default": [
1809
+ "none"
1810
+ ],
1811
+ multiple: false,
1812
+ mapping: {
1813
+ "none none": "none",
1814
+ "none/none": "none",
1815
+ "none none/none": "none"
1816
+ },
1817
+ properties: {
1818
+ "grid-template-areas": {
1819
+ types: [
1820
+ "String"
1821
+ ],
1822
+ "default": [
1823
+ "none"
1824
+ ],
1825
+ multiple: true,
1826
+ keywords: [
1827
+ "none",
1828
+ "auto"
1829
+ ],
1830
+ mapping: {
1831
+ }
1832
+ },
1833
+ "grid-template-rows": {
1834
+ types: [
1835
+ "Perc",
1836
+ "Iden",
1837
+ "Length",
1838
+ "Flex"
1839
+ ],
1840
+ "default": [
1841
+ "none"
1842
+ ],
1843
+ multiple: true,
1844
+ keywords: [
1845
+ "none"
1846
+ ]
1847
+ },
1848
+ "grid-template-columns": {
1849
+ types: [
1850
+ "Perc",
1851
+ "Iden",
1852
+ "Length",
1853
+ "Flex"
1854
+ ],
1855
+ "default": [
1856
+ "none"
1857
+ ],
1858
+ prefix: {
1859
+ typ: "Literal",
1860
+ val: "/"
1861
+ },
1862
+ multiple: true,
1863
+ keywords: [
1864
+ "none"
1865
+ ]
1866
+ }
1867
+ }
1868
+ },
1869
+ "grid-template-areas": {
1870
+ shorthand: "grid-template"
1871
+ },
1872
+ "grid-template-rows": {
1873
+ shorthand: "grid-template"
1874
+ },
1875
+ "grid-template-columns": {
1876
+ shorthand: "grid-template"
1610
1877
  }
1611
1878
  };
1612
1879
  var property = {
@@ -1577,6 +1577,9 @@ var declarations = {
1577
1577
  scale: {
1578
1578
  syntax: "none | [ <number> | <percentage> ]{1,3}"
1579
1579
  },
1580
+ "scroll-axis-lock": {
1581
+ syntax: "auto | none"
1582
+ },
1580
1583
  "scroll-behavior": {
1581
1584
  syntax: "auto | smooth"
1582
1585
  },
@@ -1982,6 +1985,9 @@ var declarations = {
1982
1985
  "will-change": {
1983
1986
  syntax: "auto | <animateable-feature>#"
1984
1987
  },
1988
+ "window-drag": {
1989
+ syntax: "none | move"
1990
+ },
1985
1991
  "word-break": {
1986
1992
  syntax: "normal | break-all | keep-all | break-word | auto-phrase"
1987
1993
  },