@tbela99/css-parser 0.6.0 → 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.
Files changed (51) hide show
  1. package/README.md +106 -3
  2. package/dist/config.json.js +3 -1
  3. package/dist/index-umd-web.js +53876 -50
  4. package/dist/index.cjs +53876 -50
  5. package/dist/index.d.ts +113 -18
  6. package/dist/lib/ast/expand.js +8 -2
  7. package/dist/lib/ast/features/index.js +1 -0
  8. package/dist/lib/ast/features/prefix.js +118 -0
  9. package/dist/lib/ast/features/shorthand.js +1 -0
  10. package/dist/lib/ast/minify.js +44 -10
  11. package/dist/lib/ast/types.js +16 -1
  12. package/dist/lib/ast/walk.js +3 -1
  13. package/dist/lib/parser/declaration/list.js +1 -1
  14. package/dist/lib/parser/declaration/map.js +9 -4
  15. package/dist/lib/parser/declaration/set.js +2 -1
  16. package/dist/lib/parser/parse.js +239 -11
  17. package/dist/lib/parser/tokenize.js +19 -5
  18. package/dist/lib/parser/utils/config.js +1 -0
  19. package/dist/lib/parser/utils/declaration.js +2 -1
  20. package/dist/lib/parser/utils/syntax.js +1 -0
  21. package/dist/lib/parser/utils/type.js +1 -0
  22. package/dist/lib/renderer/color/a98rgb.js +1 -0
  23. package/dist/lib/renderer/color/color.js +1 -0
  24. package/dist/lib/renderer/color/colormix.js +3 -2
  25. package/dist/lib/renderer/color/hex.js +1 -0
  26. package/dist/lib/renderer/color/hsl.js +1 -0
  27. package/dist/lib/renderer/color/hwb.js +1 -0
  28. package/dist/lib/renderer/color/lab.js +1 -0
  29. package/dist/lib/renderer/color/lch.js +1 -0
  30. package/dist/lib/renderer/color/oklab.js +1 -0
  31. package/dist/lib/renderer/color/oklch.js +1 -0
  32. package/dist/lib/renderer/color/p3.js +1 -0
  33. package/dist/lib/renderer/color/rec2020.js +1 -0
  34. package/dist/lib/renderer/color/relativecolor.js +1 -0
  35. package/dist/lib/renderer/color/rgb.js +1 -0
  36. package/dist/lib/renderer/color/srgb.js +1 -0
  37. package/dist/lib/renderer/color/utils/components.js +1 -0
  38. package/dist/lib/renderer/color/utils/constants.js +1 -0
  39. package/dist/lib/renderer/color/xyz.js +1 -0
  40. package/dist/lib/renderer/color/xyzd50.js +1 -0
  41. package/dist/lib/renderer/render.js +25 -5
  42. package/dist/lib/syntax/syntax.js +456 -0
  43. package/dist/lib/validation/config.js +9 -0
  44. package/dist/lib/validation/config.json.js +52883 -0
  45. package/dist/lib/validation/parser/parse.js +16 -0
  46. package/dist/lib/validation/parser/types.js +39 -0
  47. package/dist/lib/validation/selector.js +459 -0
  48. package/dist/node/index.js +1 -0
  49. package/dist/web/index.js +1 -0
  50. package/package.json +1 -1
  51. package/jsr.json +0 -29
package/README.md CHANGED
@@ -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
 
@@ -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. the current working directory. when specified url() are resolved using this value
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. value used as current working directory. when output is not provided, urls are resolved according to this value.
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
@@ -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",