@tbela99/css-parser 0.6.0 → 0.7.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/README.md +114 -4
- package/dist/config.json.js +3 -1
- package/dist/index-umd-web.js +53942 -40
- package/dist/index.cjs +53946 -40
- package/dist/index.d.ts +127 -18
- package/dist/lib/ast/expand.js +69 -3
- 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 +239 -11
- package/dist/lib/parser/tokenize.js +26 -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 +1 -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 +1 -0
- package/dist/lib/renderer/color/xyz.js +1 -0
- package/dist/lib/renderer/color/xyzd50.js +1 -0
- package/dist/lib/renderer/render.js +25 -5
- 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 +14 -0
- package/dist/web/index.js +10 -0
- package/package.json +13 -13
- package/jsr.json +0 -29
package/README.md
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
[](https://www.npmjs.com/package/@tbela99/css-parser) [](https://www.npmjs.com/package/@tbela99/css-parser) [](https://jsr.io/@tbela99/css-parser) [](https://github.com/tbela99/css-parser/actions) [](https://www.npmjs.com/package/@tbela99/css-parser)
|
|
2
3
|
|
|
3
4
|
# css-parser
|
|
4
5
|
|
|
@@ -6,9 +7,15 @@ CSS parser and minifier for node and the browser
|
|
|
6
7
|
|
|
7
8
|
## Installation
|
|
8
9
|
|
|
10
|
+
From npm
|
|
9
11
|
```shell
|
|
10
12
|
$ npm install @tbela99/css-parser
|
|
11
13
|
```
|
|
14
|
+
from jsr
|
|
15
|
+
```shell
|
|
16
|
+
$ deno add @tbela99/css-parser
|
|
17
|
+
```
|
|
18
|
+
|
|
12
19
|
|
|
13
20
|
## Features
|
|
14
21
|
|
|
@@ -25,6 +32,7 @@ $ npm install @tbela99/css-parser
|
|
|
25
32
|
- inline css variables
|
|
26
33
|
- remove duplicate properties
|
|
27
34
|
- flatten @import rules
|
|
35
|
+
- partial css validation: only css selector is validated
|
|
28
36
|
|
|
29
37
|
## Playground
|
|
30
38
|
|
|
@@ -145,9 +153,13 @@ Include ParseOptions and RenderOptions
|
|
|
145
153
|
- inlineCssVariables: boolean, optional. replace some css variables with their actual value. they must be declared once in the :root {} or html {} rule.
|
|
146
154
|
- removeEmpty: boolean, optional. remove empty rule lists from the ast.
|
|
147
155
|
|
|
156
|
+
> Minify Options
|
|
157
|
+
|
|
158
|
+
- validation: boolean, optional. enable strict css validation using (mdn data)[https://github.com/mdn/data]. only the selector is validated at this time.
|
|
159
|
+
|
|
148
160
|
> Sourcemap Options
|
|
149
161
|
|
|
150
|
-
- src: string, optional. original css file location to be used with sourcemap.
|
|
162
|
+
- src: string, optional. original css file location to be used with sourcemap, also used to resolve url().
|
|
151
163
|
- sourcemap: boolean, optional. preserve node location data.
|
|
152
164
|
|
|
153
165
|
> Misc Options
|
|
@@ -155,7 +167,7 @@ Include ParseOptions and RenderOptions
|
|
|
155
167
|
- resolveUrls: boolean, optional. resolve css 'url()' according to the parameters 'src' and 'cwd'
|
|
156
168
|
- resolveImport: boolean, optional. replace @import rule by the content of its referenced stylesheet.
|
|
157
169
|
- removeCharset: boolean, optional. remove @charset.
|
|
158
|
-
- cwd: string, optional.
|
|
170
|
+
- cwd: string, optional. destination directory used to resolve url().
|
|
159
171
|
- visitor: VisitorNodeMap, optional. node visitor used to transform the ast.
|
|
160
172
|
- signal: AbortSignal, optional. abort parsing.
|
|
161
173
|
|
|
@@ -179,7 +191,7 @@ Include ParseOptions and RenderOptions
|
|
|
179
191
|
- indent: string, optional. css indention string. uses space character by default.
|
|
180
192
|
- newLine: string, optional. new line character.
|
|
181
193
|
- 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.
|
|
194
|
+
- cwd: string, optional. destination directory used to resolve url().
|
|
183
195
|
|
|
184
196
|
## Parsing
|
|
185
197
|
|
|
@@ -316,6 +328,104 @@ table.colortable {
|
|
|
316
328
|
}
|
|
317
329
|
```
|
|
318
330
|
|
|
331
|
+
### CSS Validation
|
|
332
|
+
|
|
333
|
+
CSS
|
|
334
|
+
|
|
335
|
+
```css
|
|
336
|
+
|
|
337
|
+
#404 {
|
|
338
|
+
--animate-duration: 1s;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
.s, #404 {
|
|
342
|
+
--animate-duration: 1s;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
.s [type="text" {
|
|
346
|
+
--animate-duration: 1s;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
.s [type="text"]] {
|
|
350
|
+
--animate-duration: 1s;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
.s [type="text"] {
|
|
354
|
+
--animate-duration: 1s;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
.s [type="text" i] {
|
|
358
|
+
--animate-duration: 1s;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
.s [type="text" s] {
|
|
362
|
+
--animate-duration: 1s;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
.s [type="text" b] {
|
|
366
|
+
--animate-duration: 1s;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
.s [type="text" b], {
|
|
370
|
+
--animate-duration: 1s;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
.s [type="text" b]+ {
|
|
374
|
+
--animate-duration: 1s;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
.s [type="text" b]+ b {
|
|
378
|
+
--animate-duration: 1s;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
.s [type="text" i]+ b {
|
|
382
|
+
--animate-duration: 1s;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
.s [type="text"())] {
|
|
387
|
+
--animate-duration: 1s;
|
|
388
|
+
}
|
|
389
|
+
.s() {
|
|
390
|
+
--animate-duration: 1s;
|
|
391
|
+
}
|
|
392
|
+
.s:focus {
|
|
393
|
+
--animate-duration: 1s;
|
|
394
|
+
}
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
with validation enabled
|
|
398
|
+
|
|
399
|
+
```javascript
|
|
400
|
+
import {parse, render} from '@tbela99/css-parser';
|
|
401
|
+
const options = {minify: true, validate: true};
|
|
402
|
+
const {code} = await parse(css, options).then(result => render(result.ast, {minify: false}));
|
|
403
|
+
//
|
|
404
|
+
console.debug(code);
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
```css
|
|
408
|
+
.s:is([type=text],[type=text i],[type=text s],[type=text i]+b,:focus) {
|
|
409
|
+
--animate-duration: 1s
|
|
410
|
+
}
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
with validation disabled
|
|
414
|
+
|
|
415
|
+
```javascript
|
|
416
|
+
import {parse, render} from '@tbela99/css-parser';
|
|
417
|
+
const options = {minify: true, validate: false};
|
|
418
|
+
const {code} = await parse(css, options).then(result => render(result.ast, {minify: false}));
|
|
419
|
+
//
|
|
420
|
+
console.debug(code);
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
```css
|
|
424
|
+
.s:is([type=text],[type=text i],[type=text s],[type=text b],[type=text b]+b,[type=text i]+b,:focus) {
|
|
425
|
+
--animate-duration: 1s
|
|
426
|
+
}
|
|
427
|
+
```
|
|
428
|
+
|
|
319
429
|
### Nested CSS Expansion
|
|
320
430
|
|
|
321
431
|
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",
|