@tbela99/css-parser 0.2.0 → 0.3.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 CHANGED
@@ -18,6 +18,8 @@ $ npm install @tbela99/css-parser
18
18
  - generate sourcemap
19
19
  - compute css shorthands. see the list below
20
20
  - compute calc() expression
21
+ - inline css variables
22
+ - relative css colors using rgb(), hsl() and hwb()
21
23
  - nested css expansion
22
24
  - remove duplicate properties
23
25
  - flatten @import rules
@@ -344,6 +346,37 @@ result
344
346
 
345
347
  ```
346
348
 
349
+ ### Example 5
350
+
351
+ ### CSS variable inlining and relative color
352
+
353
+ ```javascript
354
+
355
+ import {parse, render} from '@tbela99/css-parser';
356
+
357
+ const css = `
358
+
359
+ :root {
360
+ --color: green;
361
+ }
362
+ ._19_u :focus {
363
+ color: hsl(from var(--color) calc(h * 2) s l);
364
+
365
+ }
366
+ `
367
+
368
+ const prettyPrint = await parse(css, {inlineCssVariables: true}).then(result => render(result.ast, {minify: false}).code);
369
+
370
+ ```
371
+ result
372
+
373
+ ```css
374
+ ._19_u :focus {
375
+ color: navy
376
+ }
377
+
378
+ ```
379
+
347
380
  ## AST
348
381
 
349
382
  ### Comment
@@ -396,24 +429,53 @@ result
396
429
  - [x] decode and replace utf-8 escape sequence
397
430
 
398
431
  ## Computed shorthands properties
432
+
433
+ - ~all~
399
434
  - [x] animation
400
435
  - [x] background
401
436
  - [x] border
437
+ - [ ] border-block-end
438
+ - [ ] border-block-start
402
439
  - [x] border-bottom
403
440
  - [x] border-color
441
+ - [ ] border-image
442
+ - [ ] border-inline-end
443
+ - [ ] border-inline-start
404
444
  - [x] border-left
405
445
  - [x] border-radius
406
446
  - [x] border-right
407
447
  - [x] border-style
408
448
  - [x] border-top
409
449
  - [x] border-width
450
+ - [x] column-rule
451
+ - [x] columns
452
+ - [x] container
453
+ - [ ] contain-intrinsic-size
454
+ - [x] flex
455
+ - [x] flex-flow
410
456
  - [x] font
457
+ - [ ] font-synthesis
458
+ - [ ] font-variant
459
+ - [x] gap
460
+ - [ ] grid
461
+ - [ ] grid-area
462
+ - [ ] grid-column
463
+ - [ ] grid-row
464
+ - [ ] grid-template
411
465
  - [x] inset
412
466
  - [x] list-style
413
467
  - [x] margin
468
+ - [ ] mask
469
+ - [ ] offset
414
470
  - [x] outline
415
471
  - [x] overflow
416
472
  - [x] padding
473
+ - [ ] place-content
474
+ - [ ] place-items
475
+ - [ ] place-self
476
+ - [ ] scroll-margin
477
+ - [ ] scroll-padding
478
+ - [ ] scroll-timeline
417
479
  - [x] text-decoration
418
480
  - [x] text-emphasis
419
481
  - [x] transition
@@ -1,4 +1,26 @@
1
1
  var properties = {
2
+ gap: {
3
+ shorthand: "gap",
4
+ properties: [
5
+ "row-gap",
6
+ "column-gap"
7
+ ],
8
+ types: [
9
+ "Length",
10
+ "Perc"
11
+ ],
12
+ multiple: false,
13
+ separator: null,
14
+ keywords: [
15
+ "normal"
16
+ ]
17
+ },
18
+ "row-gap": {
19
+ shorthand: "gap"
20
+ },
21
+ "column-gap": {
22
+ shorthand: "gap"
23
+ },
2
24
  inset: {
3
25
  shorthand: "inset",
4
26
  properties: [
@@ -232,6 +254,201 @@ var properties = {
232
254
  }
233
255
  };
234
256
  var map = {
257
+ "flex-flow": {
258
+ shorthand: "flex-flow",
259
+ pattern: "flex-direction flex-wrap",
260
+ keywords: [
261
+ ],
262
+ "default": [
263
+ "row",
264
+ "nowrap"
265
+ ],
266
+ properties: {
267
+ "flex-direction": {
268
+ keywords: [
269
+ "row",
270
+ "row-reverse",
271
+ "column",
272
+ "column-reverse"
273
+ ],
274
+ "default": [
275
+ "row"
276
+ ],
277
+ types: [
278
+ ]
279
+ },
280
+ "flex-wrap": {
281
+ keywords: [
282
+ "wrap",
283
+ "nowrap",
284
+ "wrap-reverse"
285
+ ],
286
+ "default": [
287
+ "nowrap"
288
+ ],
289
+ types: [
290
+ ]
291
+ }
292
+ }
293
+ },
294
+ "flex-direction": {
295
+ shorthand: "flex-flow"
296
+ },
297
+ "flex-wrap": {
298
+ shorthand: "flex-flow"
299
+ },
300
+ container: {
301
+ shorthand: "container",
302
+ pattern: "container-name container-type",
303
+ keywords: [
304
+ ],
305
+ "default": [
306
+ ],
307
+ properties: {
308
+ "container-name": {
309
+ required: true,
310
+ multiple: true,
311
+ keywords: [
312
+ "none"
313
+ ],
314
+ "default": [
315
+ "none"
316
+ ],
317
+ types: [
318
+ "Iden",
319
+ "DashedIden"
320
+ ]
321
+ },
322
+ "container-type": {
323
+ previous: "container-name",
324
+ prefix: {
325
+ typ: "Literal",
326
+ val: "/"
327
+ },
328
+ keywords: [
329
+ "size",
330
+ "inline-size",
331
+ "normal"
332
+ ],
333
+ "default": [
334
+ "normal"
335
+ ],
336
+ types: [
337
+ ]
338
+ }
339
+ }
340
+ },
341
+ "container-name": {
342
+ shorthand: "container"
343
+ },
344
+ "container-type": {
345
+ shorthand: "container"
346
+ },
347
+ flex: {
348
+ shorthand: "flex",
349
+ pattern: "flex-grow flex-shrink flex-basis",
350
+ keywords: [
351
+ "auto",
352
+ "none",
353
+ "initial"
354
+ ],
355
+ "default": [
356
+ "0",
357
+ "0 1",
358
+ "0 auto",
359
+ "0 1 auto"
360
+ ],
361
+ properties: {
362
+ "flex-grow": {
363
+ required: true,
364
+ keywords: [
365
+ ],
366
+ "default": [
367
+ "0"
368
+ ],
369
+ types: [
370
+ "Number"
371
+ ]
372
+ },
373
+ "flex-shrink": {
374
+ keywords: [
375
+ ],
376
+ "default": [
377
+ "1"
378
+ ],
379
+ types: [
380
+ "Number"
381
+ ]
382
+ },
383
+ "flex-basis": {
384
+ keywords: [
385
+ "max-content",
386
+ "min-content",
387
+ "fit-content",
388
+ "fit-content",
389
+ "content",
390
+ "auto"
391
+ ],
392
+ "default": [
393
+ "auto"
394
+ ],
395
+ types: [
396
+ "Length",
397
+ "Perc"
398
+ ]
399
+ }
400
+ }
401
+ },
402
+ "flex-grow": {
403
+ shorthand: "flex"
404
+ },
405
+ "flex-shrink": {
406
+ shorthand: "flex"
407
+ },
408
+ "flex-basis": {
409
+ shorthand: "flex"
410
+ },
411
+ columns: {
412
+ shorthand: "columns",
413
+ pattern: "column-count column-width",
414
+ keywords: [
415
+ "auto"
416
+ ],
417
+ "default": [
418
+ "auto",
419
+ "auto auto"
420
+ ],
421
+ properties: {
422
+ "column-count": {
423
+ keywords: [
424
+ "auto"
425
+ ],
426
+ "default": [
427
+ "auto"
428
+ ],
429
+ types: [
430
+ "Number"
431
+ ]
432
+ },
433
+ "column-width": {
434
+ keywords: [
435
+ "auto"
436
+ ],
437
+ "default": [
438
+ "auto"
439
+ ],
440
+ types: [
441
+ "Length"
442
+ ]
443
+ }
444
+ }
445
+ },
446
+ "column-count": {
447
+ shorthand: "columns"
448
+ },
449
+ "column-width": {
450
+ shorthand: "columns"
451
+ },
235
452
  transition: {
236
453
  shorthand: "transition",
237
454
  multiple: true,
@@ -249,6 +466,13 @@ var map = {
249
466
  "none",
250
467
  "normal"
251
468
  ],
469
+ mapping: {
470
+ "cubic-bezier(.25,.1,.25,1)": "ease",
471
+ "cubic-bezier(0,0,1,1)": "linear",
472
+ "cubic-bezier(.42,0,1,1)": "ease-in",
473
+ "cubic-bezier(0,0,.58,1)": "ease-out",
474
+ "cubic-bezier(.42,0,.58,.42)": "ease-in-out"
475
+ },
252
476
  properties: {
253
477
  "transition-property": {
254
478
  keywords: [
@@ -256,6 +480,7 @@ var map = {
256
480
  "all"
257
481
  ],
258
482
  "default": [
483
+ "all"
259
484
  ],
260
485
  types: [
261
486
  "Iden"