@magic/css 0.7.52 → 0.7.53
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 +152 -46
- package/package.json +6 -6
- package/src/parse/index.mjs +12 -0
package/README.md
CHANGED
|
@@ -25,11 +25,11 @@ parse/stringify/write css in js
|
|
|
25
25
|
[snyk-url]: https://snyk.io/test/github/magic/css
|
|
26
26
|
|
|
27
27
|
##### installation:
|
|
28
|
+
|
|
28
29
|
```javascript
|
|
29
30
|
npm install --save-exact @magic/css
|
|
30
31
|
```
|
|
31
32
|
|
|
32
|
-
|
|
33
33
|
#### usage:
|
|
34
34
|
|
|
35
35
|
##### cli:
|
|
@@ -68,12 +68,13 @@ mcss full --in ./styles --out ./css
|
|
|
68
68
|
#### library:
|
|
69
69
|
|
|
70
70
|
##### init
|
|
71
|
+
|
|
71
72
|
```javascript
|
|
72
73
|
import css from '@magic/css'
|
|
73
74
|
```
|
|
74
75
|
|
|
75
|
-
|
|
76
76
|
##### all in one
|
|
77
|
+
|
|
77
78
|
```javascript
|
|
78
79
|
import css from '@magic/css'
|
|
79
80
|
|
|
@@ -113,6 +114,7 @@ Object {
|
|
|
113
114
|
```
|
|
114
115
|
|
|
115
116
|
##### styles
|
|
117
|
+
|
|
116
118
|
```javascript
|
|
117
119
|
const style = {
|
|
118
120
|
'.className': {
|
|
@@ -125,6 +127,7 @@ await css.stringify(style)
|
|
|
125
127
|
```
|
|
126
128
|
|
|
127
129
|
##### hover/active etc
|
|
130
|
+
|
|
128
131
|
```javascript
|
|
129
132
|
const style = {
|
|
130
133
|
div: {
|
|
@@ -142,7 +145,9 @@ await css.stringify(style)
|
|
|
142
145
|
```
|
|
143
146
|
|
|
144
147
|
##### nesting / suffix
|
|
148
|
+
|
|
145
149
|
to suffix some of the selectors, add a & to any of them except the first one
|
|
150
|
+
|
|
146
151
|
```javascript
|
|
147
152
|
const style = {
|
|
148
153
|
div: {
|
|
@@ -159,6 +164,7 @@ await css.stringify(style)
|
|
|
159
164
|
|
|
160
165
|
if you add the & at the start of the string,
|
|
161
166
|
all of the selectors will have it applied
|
|
167
|
+
|
|
162
168
|
```javascript
|
|
163
169
|
const style = {
|
|
164
170
|
div: {
|
|
@@ -177,6 +183,7 @@ await css.stringify(style)
|
|
|
177
183
|
|
|
178
184
|
to prefix the parent of the selector using the child selectors,
|
|
179
185
|
add a & at the end of any selectors but the last one.
|
|
186
|
+
|
|
180
187
|
```javascript
|
|
181
188
|
const style = {
|
|
182
189
|
'.class': {
|
|
@@ -191,8 +198,8 @@ await css.stringify(style)
|
|
|
191
198
|
// p.class, .class:hover { color: orange; }
|
|
192
199
|
```
|
|
193
200
|
|
|
194
|
-
|
|
195
201
|
##### prefix all without space
|
|
202
|
+
|
|
196
203
|
if the & is at the end of a selector,
|
|
197
204
|
the & will be applied to each of them.
|
|
198
205
|
|
|
@@ -211,6 +218,7 @@ await css.stringify(style)
|
|
|
211
218
|
```
|
|
212
219
|
|
|
213
220
|
##### prefix with space
|
|
221
|
+
|
|
214
222
|
to prefix the parent with a space, use a double && instead of a single &
|
|
215
223
|
|
|
216
224
|
```javascript
|
|
@@ -228,6 +236,7 @@ await css.stringify(style)
|
|
|
228
236
|
```
|
|
229
237
|
|
|
230
238
|
##### prefix all with space
|
|
239
|
+
|
|
231
240
|
if the && is at the end of a selector,
|
|
232
241
|
the && will be applied to each of them.
|
|
233
242
|
|
|
@@ -245,8 +254,8 @@ await css.stringify(style)
|
|
|
245
254
|
// div .class, p .class { color: orange; }
|
|
246
255
|
```
|
|
247
256
|
|
|
248
|
-
|
|
249
257
|
##### parse
|
|
258
|
+
|
|
250
259
|
```javascript
|
|
251
260
|
const style = {
|
|
252
261
|
'.className': {
|
|
@@ -262,6 +271,7 @@ css.parse(style)
|
|
|
262
271
|
```
|
|
263
272
|
|
|
264
273
|
##### stringify
|
|
274
|
+
|
|
265
275
|
```javascript
|
|
266
276
|
const style = {
|
|
267
277
|
'.className': {
|
|
@@ -271,13 +281,14 @@ const style = {
|
|
|
271
281
|
},
|
|
272
282
|
}
|
|
273
283
|
|
|
274
|
-
await css.stringify(
|
|
275
|
-
|
|
276
|
-
// minified string
|
|
284
|
+
await css.stringify(
|
|
285
|
+
style,
|
|
286
|
+
) // minified string
|
|
277
287
|
`.className #id{color:white;}`
|
|
278
288
|
```
|
|
279
289
|
|
|
280
290
|
##### write to filesystem
|
|
291
|
+
|
|
281
292
|
```javascript
|
|
282
293
|
const style = {
|
|
283
294
|
'.className': {
|
|
@@ -287,7 +298,6 @@ const style = {
|
|
|
287
298
|
},
|
|
288
299
|
}
|
|
289
300
|
|
|
290
|
-
|
|
291
301
|
// writes styles to ./out.css
|
|
292
302
|
await css.write(style)
|
|
293
303
|
|
|
@@ -296,18 +306,32 @@ await css.write(style, { OUTFILE: './outfile.css' })
|
|
|
296
306
|
```
|
|
297
307
|
|
|
298
308
|
##### media queries
|
|
309
|
+
|
|
310
|
+
Mediaqueries can use the vars.widths object to determine appropriate breakpoint sizes.
|
|
311
|
+
|
|
312
|
+
Default widths:
|
|
313
|
+
|
|
314
|
+
```javascript
|
|
315
|
+
opts.widths = {
|
|
316
|
+
tablet: '500px',
|
|
317
|
+
laptop: '900px',
|
|
318
|
+
desktop: '1200px',
|
|
319
|
+
agency: '1600px',
|
|
320
|
+
}
|
|
321
|
+
```
|
|
322
|
+
|
|
299
323
|
```javascript
|
|
300
324
|
const style = {
|
|
301
|
-
|
|
325
|
+
[`@media screen and (min-width: ${vars.widths?.tablet || '500px'})`]: {
|
|
302
326
|
'#id': {
|
|
303
327
|
color: opts.textColor,
|
|
304
328
|
},
|
|
305
329
|
},
|
|
306
330
|
}
|
|
307
331
|
|
|
308
|
-
await css.stringify(
|
|
309
|
-
|
|
310
|
-
// css string
|
|
332
|
+
await css.stringify(
|
|
333
|
+
style,
|
|
334
|
+
) // css string
|
|
311
335
|
`
|
|
312
336
|
@media screen and (min-width: 500px) {
|
|
313
337
|
#id {
|
|
@@ -318,6 +342,7 @@ await css.stringify(style)
|
|
|
318
342
|
```
|
|
319
343
|
|
|
320
344
|
##### webfonts
|
|
345
|
+
|
|
321
346
|
```javascript
|
|
322
347
|
const style = {
|
|
323
348
|
'@font-face': {
|
|
@@ -328,9 +353,9 @@ const style = {
|
|
|
328
353
|
},
|
|
329
354
|
}
|
|
330
355
|
|
|
331
|
-
await css.stringify(
|
|
332
|
-
|
|
333
|
-
// css string
|
|
356
|
+
await css.stringify(
|
|
357
|
+
style,
|
|
358
|
+
) // css string
|
|
334
359
|
`
|
|
335
360
|
@font-face {
|
|
336
361
|
font-family: "font-name";
|
|
@@ -345,228 +370,309 @@ await css.stringify(style)
|
|
|
345
370
|
}
|
|
346
371
|
`
|
|
347
372
|
// ... repeated for all styles and weights that were defined
|
|
348
|
-
|
|
349
373
|
```
|
|
350
374
|
|
|
351
375
|
### CHANGELOG:
|
|
376
|
+
|
|
352
377
|
#### 0.1.0
|
|
378
|
+
|
|
353
379
|
return classes and ids as well
|
|
354
380
|
|
|
355
381
|
#### 0.2.0:
|
|
382
|
+
|
|
356
383
|
Added media queries
|
|
357
384
|
|
|
358
385
|
#### 0.3.0:
|
|
359
|
-
|
|
360
|
-
|
|
386
|
+
|
|
387
|
+
- returns a promise! no longer sync.
|
|
388
|
+
- autoprefixer and postcss added
|
|
361
389
|
|
|
362
390
|
### 0.4.0:
|
|
391
|
+
|
|
363
392
|
supports @font-face declarations
|
|
364
393
|
|
|
365
394
|
#### 0.4.1
|
|
395
|
+
|
|
366
396
|
added fontDir option to font-face declarations
|
|
367
397
|
|
|
368
398
|
#### 0.4.2
|
|
399
|
+
|
|
369
400
|
update deps to fix security issues
|
|
370
401
|
|
|
371
402
|
#### 0.4.3
|
|
403
|
+
|
|
372
404
|
added @keyframes for animations
|
|
373
405
|
|
|
374
406
|
#### 0.4.4
|
|
407
|
+
|
|
375
408
|
css.parse now converts deep arrays into one object before parsing
|
|
376
409
|
|
|
377
410
|
#### 0.4.5
|
|
378
|
-
|
|
379
|
-
|
|
411
|
+
|
|
412
|
+
- css.stringify now makes a bit nicer mediaquery and keyframe lines.
|
|
413
|
+
- css.parse should now order media queries to the end of the css
|
|
380
414
|
|
|
381
415
|
#### 0.4.6
|
|
416
|
+
|
|
382
417
|
css.parse does a better job of keeping order of incoming objects intact
|
|
383
418
|
|
|
384
419
|
#### 0.4.7
|
|
385
|
-
|
|
420
|
+
|
|
421
|
+
- FIX: multiple parent selectors 'h1,h2,h3' that should get appended
|
|
386
422
|
with a &:hover etc now correctly append the suffix to every parent
|
|
387
|
-
|
|
423
|
+
- FEATURE: & can be at the end of a selector,
|
|
388
424
|
in which case the selector gets prepended to it's parent.
|
|
389
425
|
|
|
390
426
|
#### 0.5.0
|
|
427
|
+
|
|
391
428
|
FIX: css gets returned in almost the same order it got passed in.
|
|
392
429
|
turns out that javascript objects do not make this as easy as hoped.
|
|
393
430
|
|
|
394
431
|
#### 0.6.0
|
|
432
|
+
|
|
395
433
|
use esmodules
|
|
396
434
|
|
|
397
435
|
#### 0.7.0
|
|
436
|
+
|
|
398
437
|
update @magic/types to not break if es modules get passed into the styles
|
|
399
438
|
|
|
400
439
|
#### 0.7.1
|
|
401
|
-
|
|
402
|
-
|
|
440
|
+
|
|
441
|
+
- update @magic/deep to use ecmascript module version
|
|
442
|
+
- update postcss, autoprefixer
|
|
403
443
|
|
|
404
444
|
#### 0.7.2
|
|
445
|
+
|
|
405
446
|
update dependencies
|
|
406
447
|
|
|
407
448
|
#### 0.7.3
|
|
449
|
+
|
|
408
450
|
update dependencies
|
|
409
451
|
|
|
410
452
|
#### 0.7.4
|
|
453
|
+
|
|
411
454
|
add @magic/log to dependencies
|
|
412
455
|
|
|
413
456
|
#### 0.7.5
|
|
457
|
+
|
|
414
458
|
update autoprefixer
|
|
415
459
|
|
|
416
460
|
#### 0.7.6
|
|
461
|
+
|
|
417
462
|
update postcss
|
|
418
463
|
|
|
419
464
|
#### 0.7.7
|
|
465
|
+
|
|
420
466
|
update postcss
|
|
421
467
|
|
|
422
468
|
#### 0.7.8
|
|
469
|
+
|
|
423
470
|
update @magic/deep
|
|
424
471
|
|
|
425
472
|
#### 0.7.9
|
|
473
|
+
|
|
426
474
|
require node >= 13.5.0
|
|
427
475
|
|
|
428
476
|
#### 0.7.10
|
|
477
|
+
|
|
429
478
|
update postcss
|
|
430
479
|
|
|
431
480
|
##### 0.7.11
|
|
481
|
+
|
|
432
482
|
update autoprefixer
|
|
433
483
|
|
|
434
484
|
##### 0.7.12
|
|
485
|
+
|
|
435
486
|
update postcss
|
|
436
487
|
|
|
437
488
|
##### 0.7.13
|
|
438
|
-
|
|
439
|
-
|
|
489
|
+
|
|
490
|
+
- bump required node version to 14.2.0
|
|
491
|
+
- write is async now
|
|
440
492
|
|
|
441
493
|
##### 0.7.14
|
|
442
|
-
|
|
494
|
+
|
|
495
|
+
- update autoprefixer, dependencies
|
|
443
496
|
|
|
444
497
|
##### 0.7.15
|
|
445
|
-
|
|
498
|
+
|
|
499
|
+
- update dependencies
|
|
446
500
|
|
|
447
501
|
##### 0.7.16
|
|
502
|
+
|
|
448
503
|
update autoprefixer
|
|
449
504
|
|
|
450
505
|
##### 0.7.17
|
|
506
|
+
|
|
451
507
|
update autoprefixer
|
|
452
508
|
|
|
453
509
|
##### 0.7.18
|
|
454
|
-
|
|
455
|
-
|
|
510
|
+
|
|
511
|
+
- move no-spy to devdeps
|
|
512
|
+
- update dependencies
|
|
456
513
|
|
|
457
514
|
##### 0.7.19
|
|
515
|
+
|
|
458
516
|
update autoprefixer
|
|
459
517
|
|
|
460
518
|
##### 0.7.20
|
|
519
|
+
|
|
461
520
|
update dependencies
|
|
462
521
|
|
|
463
522
|
##### 0.7.21
|
|
523
|
+
|
|
464
524
|
update dependencies
|
|
465
525
|
|
|
466
526
|
##### 0.7.22
|
|
527
|
+
|
|
467
528
|
update dependencies
|
|
468
529
|
|
|
469
530
|
##### 0.7.23
|
|
531
|
+
|
|
470
532
|
update dependencies
|
|
471
533
|
|
|
472
534
|
##### 0.7.24
|
|
535
|
+
|
|
473
536
|
update dependencies
|
|
474
537
|
|
|
475
538
|
##### 0.7.25
|
|
539
|
+
|
|
476
540
|
update dependencies
|
|
477
541
|
|
|
478
542
|
##### 0.7.26
|
|
543
|
+
|
|
479
544
|
update dependencies
|
|
480
545
|
|
|
481
546
|
##### 0.7.27
|
|
547
|
+
|
|
482
548
|
update dependencies
|
|
483
549
|
simplify font-face handling
|
|
484
550
|
|
|
485
551
|
##### 0.7.28
|
|
486
|
-
|
|
487
|
-
|
|
552
|
+
|
|
553
|
+
- bump required node version to 14.15.4
|
|
554
|
+
- update dependencies
|
|
488
555
|
|
|
489
556
|
##### 0.7.29
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
557
|
+
|
|
558
|
+
- font-face handles non-array weights, types and styles
|
|
559
|
+
- font-face uses woff and woff2 as default font types
|
|
560
|
+
- font-face uses weight 400 and styles 'normal' as defaults
|
|
493
561
|
|
|
494
562
|
##### 0.7.30
|
|
563
|
+
|
|
495
564
|
update dependencies
|
|
496
565
|
|
|
497
566
|
##### 0.7.31
|
|
567
|
+
|
|
498
568
|
update dependencies (@magic/fs)
|
|
499
569
|
|
|
500
570
|
##### 0.7.32
|
|
501
|
-
|
|
502
|
-
|
|
571
|
+
|
|
572
|
+
- update dependencies
|
|
573
|
+
- css.selectors returns arrays instead of strings
|
|
503
574
|
|
|
504
575
|
##### 0.7.33
|
|
576
|
+
|
|
505
577
|
update dependencies
|
|
506
578
|
|
|
507
579
|
##### 0.7.34
|
|
580
|
+
|
|
508
581
|
update dependency autoprefixer
|
|
509
582
|
|
|
510
583
|
##### 0.7.35
|
|
584
|
+
|
|
511
585
|
update dependency @magic/fs
|
|
512
586
|
|
|
513
587
|
##### 0.7.36
|
|
588
|
+
|
|
514
589
|
remove local implementation of camel2kebab, use @magic/cases instead
|
|
515
590
|
|
|
516
591
|
#### 0.7.37
|
|
592
|
+
|
|
517
593
|
update dependencies
|
|
518
594
|
|
|
519
595
|
#### 0.7.38
|
|
596
|
+
|
|
520
597
|
**FIX**: update @magic/cases, which fixes overflow-x and other css props that end with an uppercase character
|
|
521
598
|
overflowX is output as overflowx in earlier versions, the regex expected lowercase characters after the uppercase char
|
|
522
599
|
|
|
523
600
|
#### 0.7.39
|
|
601
|
+
|
|
524
602
|
update dependencies
|
|
525
603
|
|
|
526
604
|
#### 0.7.40
|
|
605
|
+
|
|
527
606
|
update dependencies
|
|
528
607
|
|
|
529
608
|
#### 0.7.41
|
|
609
|
+
|
|
530
610
|
update dependencies
|
|
531
611
|
|
|
532
612
|
#### 0.7.42
|
|
613
|
+
|
|
533
614
|
update dependencies
|
|
534
615
|
|
|
535
616
|
#### 0.7.43
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
617
|
+
|
|
618
|
+
- update dependencies
|
|
619
|
+
- added font v2 to allow handling of local() fonts (see https://magic.github.io/css/#styles-webfonts)
|
|
620
|
+
- woff2 files are placed before woff files
|
|
621
|
+
- use single quotes in output css
|
|
622
|
+
- add cli
|
|
541
623
|
|
|
542
624
|
#### 0.7.44
|
|
543
|
-
|
|
544
|
-
|
|
625
|
+
|
|
626
|
+
- css props can be arrays to provide css overloads `{ color: ['green', 'red'] }` turns into `color: green; color: red;`
|
|
627
|
+
- update dependencies
|
|
545
628
|
|
|
546
629
|
#### 0.7.45
|
|
630
|
+
|
|
547
631
|
update dependencies
|
|
548
632
|
|
|
549
633
|
#### 0.7.46
|
|
634
|
+
|
|
550
635
|
update dependencies
|
|
551
636
|
|
|
552
637
|
#### 0.7.47
|
|
638
|
+
|
|
553
639
|
update dependencies
|
|
554
640
|
|
|
555
641
|
#### 0.7.48
|
|
642
|
+
|
|
556
643
|
update dependencies
|
|
557
644
|
|
|
558
645
|
#### 0.7.49
|
|
646
|
+
|
|
559
647
|
update dependencies
|
|
560
648
|
|
|
561
649
|
#### 0.7.50
|
|
650
|
+
|
|
562
651
|
update dependencies
|
|
563
652
|
|
|
564
653
|
#### 0.7.51
|
|
654
|
+
|
|
565
655
|
update dependencies
|
|
566
656
|
|
|
567
657
|
#### 0.7.52
|
|
658
|
+
|
|
568
659
|
update dependencies
|
|
569
660
|
|
|
570
|
-
#### 0.7.53
|
|
571
|
-
|
|
661
|
+
#### 0.7.53
|
|
662
|
+
|
|
663
|
+
- update dependencies
|
|
664
|
+
- update docs to reflect usage of vars.widths.{tablet|laptop|desktop}
|
|
665
|
+
- add defaults for opts.widths, to make sure we can use media queries at all times.
|
|
572
666
|
|
|
667
|
+
```javascript
|
|
668
|
+
opts.widths = {
|
|
669
|
+
tablet: '500px',
|
|
670
|
+
laptop: '900px',
|
|
671
|
+
desktop: '1200px',
|
|
672
|
+
agency: '1600px',
|
|
673
|
+
}
|
|
674
|
+
```
|
|
675
|
+
|
|
676
|
+
#### 0.7.54 - unreleased
|
|
677
|
+
|
|
678
|
+
...
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@magic/css",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.53",
|
|
4
4
|
"author": "Wizards & Witches",
|
|
5
5
|
"description": "css in js",
|
|
6
6
|
"license": "AGPL-3.0",
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
"@magic/fs": "0.0.27",
|
|
43
43
|
"@magic/log": "0.1.17",
|
|
44
44
|
"@magic/types": "0.1.22",
|
|
45
|
-
"autoprefixer": "10.4.
|
|
46
|
-
"postcss": "8.4.
|
|
45
|
+
"autoprefixer": "10.4.13",
|
|
46
|
+
"postcss": "8.4.20"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@magic-modules/git-badges": "0.0.12",
|
|
@@ -51,9 +51,9 @@
|
|
|
51
51
|
"@magic-modules/no-spy": "0.0.7",
|
|
52
52
|
"@magic-modules/pre": "0.0.11",
|
|
53
53
|
"@magic-themes/docs": "0.0.14",
|
|
54
|
-
"@magic/core": "0.0.
|
|
55
|
-
"@magic/format": "0.0.
|
|
56
|
-
"@magic/test": "0.2.
|
|
54
|
+
"@magic/core": "0.0.144",
|
|
55
|
+
"@magic/format": "0.0.48",
|
|
56
|
+
"@magic/test": "0.2.14"
|
|
57
57
|
},
|
|
58
58
|
"keywords": [
|
|
59
59
|
"css-in-js",
|
package/src/parse/index.mjs
CHANGED
|
@@ -99,6 +99,18 @@ const flat = a => {
|
|
|
99
99
|
* parse the styles css object into an array of key-value pairs.
|
|
100
100
|
*/
|
|
101
101
|
const parse = (styles, opts = {}) => {
|
|
102
|
+
const defaultWidths = {
|
|
103
|
+
tablet: '500px',
|
|
104
|
+
laptop: '900px',
|
|
105
|
+
desktop: '1200px',
|
|
106
|
+
agency: '1600px',
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
opts.widths = {
|
|
110
|
+
...defaultWidths,
|
|
111
|
+
...opts.widths,
|
|
112
|
+
}
|
|
113
|
+
|
|
102
114
|
// first check if the user sent us a function that resolves to a css object
|
|
103
115
|
if (is.function(styles)) {
|
|
104
116
|
styles = styles(opts)
|