@tbela99/css-parser 0.5.4 → 0.7.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/README.md +108 -5
- package/dist/config.json.js +3 -1
- package/dist/index-umd-web.js +53911 -50
- package/dist/index.cjs +53911 -50
- package/dist/index.d.ts +118 -23
- package/dist/lib/ast/expand.js +8 -2
- package/dist/lib/ast/features/index.js +1 -0
- package/dist/lib/ast/features/prefix.js +118 -0
- package/dist/lib/ast/features/shorthand.js +1 -0
- package/dist/lib/ast/minify.js +44 -10
- package/dist/lib/ast/types.js +16 -1
- package/dist/lib/ast/walk.js +3 -1
- package/dist/lib/parser/declaration/list.js +1 -1
- package/dist/lib/parser/declaration/map.js +9 -4
- package/dist/lib/parser/declaration/set.js +2 -1
- package/dist/lib/parser/parse.js +262 -16
- package/dist/lib/parser/tokenize.js +19 -5
- package/dist/lib/parser/utils/config.js +1 -0
- package/dist/lib/parser/utils/declaration.js +2 -1
- package/dist/lib/parser/utils/syntax.js +10 -0
- package/dist/lib/parser/utils/type.js +1 -0
- package/dist/lib/renderer/color/a98rgb.js +1 -0
- package/dist/lib/renderer/color/color.js +1 -0
- package/dist/lib/renderer/color/colormix.js +3 -2
- package/dist/lib/renderer/color/hex.js +1 -0
- package/dist/lib/renderer/color/hsl.js +1 -0
- package/dist/lib/renderer/color/hwb.js +1 -0
- package/dist/lib/renderer/color/lab.js +1 -0
- package/dist/lib/renderer/color/lch.js +1 -0
- package/dist/lib/renderer/color/oklab.js +1 -0
- package/dist/lib/renderer/color/oklch.js +1 -0
- package/dist/lib/renderer/color/p3.js +1 -0
- package/dist/lib/renderer/color/rec2020.js +1 -0
- package/dist/lib/renderer/color/relativecolor.js +1 -0
- package/dist/lib/renderer/color/rgb.js +1 -0
- package/dist/lib/renderer/color/srgb.js +1 -0
- package/dist/lib/renderer/color/utils/components.js +1 -0
- package/dist/lib/renderer/color/utils/constants.js +6 -1
- package/dist/lib/renderer/color/xyz.js +1 -0
- package/dist/lib/renderer/color/xyzd50.js +1 -0
- package/dist/lib/renderer/render.js +30 -7
- package/dist/lib/syntax/syntax.js +456 -0
- package/dist/lib/validation/config.js +9 -0
- package/dist/lib/validation/config.json.js +52883 -0
- package/dist/lib/validation/parser/parse.js +16 -0
- package/dist/lib/validation/parser/types.js +39 -0
- package/dist/lib/validation/selector.js +459 -0
- package/dist/node/index.js +2 -0
- package/dist/web/index.js +1 -0
- package/dist/web/load.js +1 -0
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ $ npm install @tbela99/css-parser
|
|
|
16
16
|
- fault-tolerant parser, will try to fix invalid tokens according to the CSS syntax module 3 recommendations.
|
|
17
17
|
- fast and efficient minification without unsafe transforms, see [benchmark](https://tbela99.github.io/css-parser/benchmark/index.html)
|
|
18
18
|
- minify colors.
|
|
19
|
-
- support css color level 4 & 5: color(), lab(), lch(), oklab(), oklch(), color-mix() and relative color
|
|
19
|
+
- support css color level 4 & 5: color(), lab(), lch(), oklab(), oklch(), color-mix(), light-dark(), system colors and relative color
|
|
20
20
|
- generate nested css rules
|
|
21
21
|
- convert nested css rules to legacy syntax
|
|
22
22
|
- generate sourcemap
|
|
@@ -25,6 +25,7 @@ $ npm install @tbela99/css-parser
|
|
|
25
25
|
- inline css variables
|
|
26
26
|
- remove duplicate properties
|
|
27
27
|
- flatten @import rules
|
|
28
|
+
- partial css validation: only css selector is validated
|
|
28
29
|
|
|
29
30
|
## Playground
|
|
30
31
|
|
|
@@ -76,7 +77,7 @@ import {transform} from '@tbela99/css-parser/web';
|
|
|
76
77
|
|
|
77
78
|
Javascript module from cdn
|
|
78
79
|
|
|
79
|
-
```
|
|
80
|
+
```html
|
|
80
81
|
|
|
81
82
|
<script type="module">
|
|
82
83
|
|
|
@@ -145,9 +146,13 @@ Include ParseOptions and RenderOptions
|
|
|
145
146
|
- inlineCssVariables: boolean, optional. replace some css variables with their actual value. they must be declared once in the :root {} or html {} rule.
|
|
146
147
|
- removeEmpty: boolean, optional. remove empty rule lists from the ast.
|
|
147
148
|
|
|
149
|
+
> Minify Options
|
|
150
|
+
|
|
151
|
+
- validation: boolean, optional. enable strict css validation using (mdn data)[https://github.com/mdn/data]. only the selector is validated at this time.
|
|
152
|
+
|
|
148
153
|
> Sourcemap Options
|
|
149
154
|
|
|
150
|
-
- src: string, optional. original css file location to be used with sourcemap.
|
|
155
|
+
- src: string, optional. original css file location to be used with sourcemap, also used to resolve url().
|
|
151
156
|
- sourcemap: boolean, optional. preserve node location data.
|
|
152
157
|
|
|
153
158
|
> Misc Options
|
|
@@ -155,7 +160,7 @@ Include ParseOptions and RenderOptions
|
|
|
155
160
|
- resolveUrls: boolean, optional. resolve css 'url()' according to the parameters 'src' and 'cwd'
|
|
156
161
|
- resolveImport: boolean, optional. replace @import rule by the content of its referenced stylesheet.
|
|
157
162
|
- removeCharset: boolean, optional. remove @charset.
|
|
158
|
-
- cwd: string, optional.
|
|
163
|
+
- cwd: string, optional. destination directory used to resolve url().
|
|
159
164
|
- visitor: VisitorNodeMap, optional. node visitor used to transform the ast.
|
|
160
165
|
- signal: AbortSignal, optional. abort parsing.
|
|
161
166
|
|
|
@@ -179,7 +184,7 @@ Include ParseOptions and RenderOptions
|
|
|
179
184
|
- indent: string, optional. css indention string. uses space character by default.
|
|
180
185
|
- newLine: string, optional. new line character.
|
|
181
186
|
- output: string, optional. file where to store css. url() are resolved according to the specified value. no file is created though.
|
|
182
|
-
- cwd: string, optional.
|
|
187
|
+
- cwd: string, optional. destination directory used to resolve url().
|
|
183
188
|
|
|
184
189
|
## Parsing
|
|
185
190
|
|
|
@@ -316,6 +321,104 @@ table.colortable {
|
|
|
316
321
|
}
|
|
317
322
|
```
|
|
318
323
|
|
|
324
|
+
### CSS Validation
|
|
325
|
+
|
|
326
|
+
CSS
|
|
327
|
+
|
|
328
|
+
```css
|
|
329
|
+
|
|
330
|
+
#404 {
|
|
331
|
+
--animate-duration: 1s;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
.s, #404 {
|
|
335
|
+
--animate-duration: 1s;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
.s [type="text" {
|
|
339
|
+
--animate-duration: 1s;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
.s [type="text"]] {
|
|
343
|
+
--animate-duration: 1s;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
.s [type="text"] {
|
|
347
|
+
--animate-duration: 1s;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
.s [type="text" i] {
|
|
351
|
+
--animate-duration: 1s;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
.s [type="text" s] {
|
|
355
|
+
--animate-duration: 1s;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
.s [type="text" b] {
|
|
359
|
+
--animate-duration: 1s;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
.s [type="text" b], {
|
|
363
|
+
--animate-duration: 1s;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
.s [type="text" b]+ {
|
|
367
|
+
--animate-duration: 1s;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
.s [type="text" b]+ b {
|
|
371
|
+
--animate-duration: 1s;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
.s [type="text" i]+ b {
|
|
375
|
+
--animate-duration: 1s;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
.s [type="text"())] {
|
|
380
|
+
--animate-duration: 1s;
|
|
381
|
+
}
|
|
382
|
+
.s() {
|
|
383
|
+
--animate-duration: 1s;
|
|
384
|
+
}
|
|
385
|
+
.s:focus {
|
|
386
|
+
--animate-duration: 1s;
|
|
387
|
+
}
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
with validation enabled
|
|
391
|
+
|
|
392
|
+
```javascript
|
|
393
|
+
import {parse, render} from '@tbela99/css-parser';
|
|
394
|
+
const options = {minify: true, validate: true};
|
|
395
|
+
const {code} = await parse(css, options).then(result => render(result.ast, {minify: false}));
|
|
396
|
+
//
|
|
397
|
+
console.debug(code);
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
```css
|
|
401
|
+
.s:is([type=text],[type=text i],[type=text s],[type=text i]+b,:focus) {
|
|
402
|
+
--animate-duration: 1s
|
|
403
|
+
}
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
with validation disabled
|
|
407
|
+
|
|
408
|
+
```javascript
|
|
409
|
+
import {parse, render} from '@tbela99/css-parser';
|
|
410
|
+
const options = {minify: true, validate: false};
|
|
411
|
+
const {code} = await parse(css, options).then(result => render(result.ast, {minify: false}));
|
|
412
|
+
//
|
|
413
|
+
console.debug(code);
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
```css
|
|
417
|
+
.s:is([type=text],[type=text i],[type=text s],[type=text b],[type=text b]+b,[type=text i]+b,:focus) {
|
|
418
|
+
--animate-duration: 1s
|
|
419
|
+
}
|
|
420
|
+
```
|
|
421
|
+
|
|
319
422
|
### Nested CSS Expansion
|
|
320
423
|
|
|
321
424
|
CSS
|
package/dist/config.json.js
CHANGED
|
@@ -450,7 +450,9 @@ var map = {
|
|
|
450
450
|
transition: {
|
|
451
451
|
shorthand: "transition",
|
|
452
452
|
multiple: true,
|
|
453
|
-
separator:
|
|
453
|
+
separator: {
|
|
454
|
+
typ: "Comma"
|
|
455
|
+
},
|
|
454
456
|
pattern: "transition-property transition-duration transition-timing-function transition-delay transition-behavior",
|
|
455
457
|
keywords: [
|
|
456
458
|
"none",
|