@unocss/preset-mini 0.35.3 → 0.37.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,70 @@ Unocss({
18
18
  })
19
19
  ```
20
20
 
21
+ ## Features
22
+
23
+ ### Dark Mode
24
+
25
+ By default, this preset generates class based dark mode with `dark:` variant.
26
+
27
+ ```html
28
+ <div class="dark:bg-red:10" />
29
+ ```
30
+
31
+ will generate:
32
+
33
+ ```css
34
+ .dark .dark\:bg-red\:10 {
35
+ background-color: rgba(248, 113, 113, 0.1);
36
+ }
37
+ ```
38
+
39
+ To opt-in media query based dark mode, you can use `@dark:` variant:
40
+
41
+ ```html
42
+ <div class="@dark:bg-red:10" />
43
+ ```
44
+
45
+ ```css
46
+ @media (prefers-color-scheme: dark) {
47
+ .\@dark\:bg-red\:10 {
48
+ background-color: rgba(248, 113, 113, 0.1);
49
+ }
50
+ }
51
+ ```
52
+
53
+ Or set globally with the config for `dark:` variant
54
+
55
+ ```ts
56
+ presetMini({
57
+ dark: 'media'
58
+ })
59
+ ```
60
+
61
+ ### CSS @layer
62
+
63
+ [CSS's native @layer](https://developer.mozilla.org/en-US/docs/Web/CSS/@layer) is supported with variant `layer-xx:`
64
+
65
+ ```html
66
+ <div class="layer-foo:p4" />
67
+ <div class="layer-bar:m4" />
68
+ ```
69
+
70
+ will generate:
71
+
72
+ ```css
73
+ @layer foo {
74
+ .layer-foo\:p4 {
75
+ padding: 1rem;
76
+ }
77
+ }
78
+ @layer bar {
79
+ .layer-bar\:m4 {
80
+ margin: 1rem;
81
+ }
82
+ }
83
+ ```
84
+
21
85
  ## License
22
86
 
23
87
  MIT License &copy; 2021-PRESENT [Anthony Fu](https://github.com/antfu)
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const colors = require('./colors.cjs');
4
+ const transform = require('./transform.cjs');
4
5
 
5
6
  const fontFamily = {
6
7
  sans: [
@@ -224,6 +225,12 @@ const maxHeight = {
224
225
  screen: "100vh"
225
226
  };
226
227
 
228
+ const preflightBase = {
229
+ ...transform.transformBase,
230
+ ...transform.boxShadowsBase,
231
+ ...transform.ringBase
232
+ };
233
+
227
234
  const theme = {
228
235
  width,
229
236
  height,
@@ -256,7 +263,8 @@ const theme = {
256
263
  lineWidth,
257
264
  spacing,
258
265
  duration,
259
- ringWidth
266
+ ringWidth,
267
+ preflightBase
260
268
  };
261
269
 
262
270
  exports.baseSize = baseSize;
@@ -275,6 +283,7 @@ exports.lineHeight = lineHeight;
275
283
  exports.lineWidth = lineWidth;
276
284
  exports.maxHeight = maxHeight;
277
285
  exports.maxWidth = maxWidth;
286
+ exports.preflightBase = preflightBase;
278
287
  exports.ringWidth = ringWidth;
279
288
  exports.spacing = spacing;
280
289
  exports.textIndent = textIndent;
@@ -1,4 +1,5 @@
1
1
  import { c as colors } from './colors.mjs';
2
+ import { t as transformBase, b as boxShadowsBase, r as ringBase } from './transform.mjs';
2
3
 
3
4
  const fontFamily = {
4
5
  sans: [
@@ -222,6 +223,12 @@ const maxHeight = {
222
223
  screen: "100vh"
223
224
  };
224
225
 
226
+ const preflightBase = {
227
+ ...transformBase,
228
+ ...boxShadowsBase,
229
+ ...ringBase
230
+ };
231
+
225
232
  const theme = {
226
233
  width,
227
234
  height,
@@ -254,7 +261,8 @@ const theme = {
254
261
  lineWidth,
255
262
  spacing,
256
263
  duration,
257
- ringWidth
264
+ ringWidth,
265
+ preflightBase
258
266
  };
259
267
 
260
- export { fontSize as a, blur as b, textIndent as c, dropShadow as d, textStrokeWidth as e, fontFamily as f, textShadow as g, letterSpacing as h, breakpoints as i, lineWidth as j, duration as k, lineHeight as l, borderRadius as m, boxShadow as n, easing as o, baseSize as p, width as q, ringWidth as r, spacing as s, theme as t, maxWidth as u, verticalBreakpoints as v, wordSpacing as w, height as x, maxHeight as y };
268
+ export { fontSize as a, blur as b, textIndent as c, dropShadow as d, textStrokeWidth as e, fontFamily as f, textShadow as g, letterSpacing as h, breakpoints as i, lineWidth as j, duration as k, lineHeight as l, borderRadius as m, boxShadow as n, easing as o, baseSize as p, width as q, ringWidth as r, spacing as s, theme as t, maxWidth as u, verticalBreakpoints as v, wordSpacing as w, height as x, maxHeight as y, preflightBase as z };
@@ -2,6 +2,7 @@
2
2
 
3
3
  const utilities = require('./utilities.cjs');
4
4
  const core = require('@unocss/core');
5
+ const transform = require('./transform.cjs');
5
6
 
6
7
  const verticalAlignAlias = {
7
8
  "mid": "middle",
@@ -505,146 +506,6 @@ const boxSizing = [
505
506
  ["box-content", { "box-sizing": "content-box" }]
506
507
  ];
507
508
 
508
- const varEmpty = "var(--un-empty,/*!*/ /*!*/)";
509
- const displays = [
510
- ["inline", { display: "inline" }],
511
- ["block", { display: "block" }],
512
- ["inline-block", { display: "inline-block" }],
513
- ["contents", { display: "contents" }],
514
- ["flow-root", { display: "flow-root" }],
515
- ["list-item", { display: "list-item" }],
516
- ["hidden", { display: "none" }],
517
- [/^display-(.+)$/, ([, c]) => ({ display: utilities.handler.bracket.cssvar(c) || c })]
518
- ];
519
- const appearances = [
520
- ["visible", { visibility: "visible" }],
521
- ["invisible", { visibility: "hidden" }],
522
- ["backface-visible", { "backface-visibility": "visible" }],
523
- ["backface-hidden", { "backface-visibility": "hidden" }]
524
- ];
525
- const cursors = [
526
- [/^cursor-(.+)$/, ([, c]) => ({ cursor: utilities.handler.bracket.cssvar(c) || c })]
527
- ];
528
- const pointerEvents = [
529
- ["pointer-events-auto", { "pointer-events": "auto" }],
530
- ["pointer-events-none", { "pointer-events": "none" }]
531
- ];
532
- const resizes = [
533
- ["resize-x", { resize: "horizontal" }],
534
- ["resize-y", { resize: "vertical" }],
535
- ["resize", { resize: "both" }],
536
- ["resize-none", { resize: "none" }]
537
- ];
538
- const userSelects = [
539
- ["select-auto", { "user-select": "auto" }],
540
- ["select-all", { "user-select": "all" }],
541
- ["select-text", { "user-select": "text" }],
542
- ["select-none", { "user-select": "none" }]
543
- ];
544
- const whitespaces = [
545
- [/^(?:whitespace|ws)-(normal|nowrap|pre|pre-line|pre-wrap|break-spaces)$/, ([, v]) => ({ "white-space": v }), { autocomplete: "(whitespace|ws)-(normal|nowrap|pre|pre-line|pre-wrap|break-spaces)" }]
546
- ];
547
- const contents = [
548
- [/^content-(.+)$/, ([, v]) => {
549
- const c = utilities.handler.bracket.cssvar(v);
550
- return { content: c == null ? `"${v}"` : c };
551
- }],
552
- ["content-empty", { content: '""' }],
553
- ["content-none", { content: '""' }]
554
- ];
555
- const breaks = [
556
- ["break-normal", { "overflow-wrap": "normal", "word-break": "normal" }],
557
- ["break-words", { "overflow-wrap": "break-word" }],
558
- ["break-all", { "word-break": "break-all" }]
559
- ];
560
- const textOverflows = [
561
- ["truncate", { "overflow": "hidden", "text-overflow": "ellipsis", "white-space": "nowrap" }],
562
- ["text-ellipsis", { "text-overflow": "ellipsis" }],
563
- ["text-clip", { "text-overflow": "clip" }]
564
- ];
565
- const textTransforms = [
566
- ["case-upper", { "text-transform": "uppercase" }],
567
- ["case-lower", { "text-transform": "lowercase" }],
568
- ["case-capital", { "text-transform": "capitalize" }],
569
- ["case-normal", { "text-transform": "none" }]
570
- ];
571
- const fontStyles = [
572
- ["italic", { "font-style": "italic" }],
573
- ["not-italic", { "font-style": "normal" }],
574
- ["font-italic", { "font-style": "italic" }],
575
- ["font-not-italic", { "font-style": "normal" }],
576
- ["oblique", { "font-style": "oblique" }],
577
- ["not-oblique", { "font-style": "normal" }],
578
- ["font-oblique", { "font-style": "oblique" }],
579
- ["font-not-oblique", { "font-style": "normal" }]
580
- ];
581
- const fontSmoothings = [
582
- ["antialiased", {
583
- "-webkit-font-smoothing": "antialiased",
584
- "-moz-osx-font-smoothing": "grayscale",
585
- "font-smoothing": "grayscale"
586
- }],
587
- ["subpixel-antialiased", {
588
- "-webkit-font-smoothing": "auto",
589
- "-moz-osx-font-smoothing": "auto",
590
- "font-smoothing": "auto"
591
- }]
592
- ];
593
-
594
- const rings = [
595
- [/^ring(?:-(.+))?$/, ([, d], { theme }) => {
596
- const value = theme.ringWidth?.[d || "DEFAULT"] ?? utilities.handler.px(d || "1");
597
- if (value) {
598
- return [
599
- {
600
- [core.CONTROL_SHORTCUT_NO_MERGE]: "",
601
- "--un-ring-inset": varEmpty,
602
- "--un-ring-offset-width": "0px",
603
- "--un-ring-offset-color": "#fff",
604
- "--un-ring-width": "0px",
605
- "--un-ring-color": "rgba(147,197,253,0.5)"
606
- },
607
- {
608
- "--un-ring-width": value,
609
- "--un-ring-offset-shadow": "var(--un-ring-inset) 0 0 0 var(--un-ring-offset-width) var(--un-ring-offset-color)",
610
- "--un-ring-shadow": "var(--un-ring-inset) 0 0 0 calc(var(--un-ring-width) + var(--un-ring-offset-width)) var(--un-ring-color)",
611
- "box-shadow": "var(--un-ring-offset-shadow), var(--un-ring-shadow), var(--un-shadow, 0 0 #0000)"
612
- }
613
- ];
614
- }
615
- }, { autocomplete: "ring-$ringWidth" }],
616
- [/^ring-(?:width-|size-)(.+)$/, ([, d], { theme }) => ({ "--un-ring-width": theme.lineWidth?.[d] ?? utilities.handler.bracket.cssvar.px(d) }), { autocomplete: "ring-(width|size)-$lineWidth" }],
617
- ["ring-offset", { "--un-ring-offset-width": "1px" }],
618
- [/^ring-offset-(?:width-|size-)?(.+)$/, ([, d], { theme }) => ({ "--un-ring-offset-width": theme.lineWidth?.[d] ?? utilities.handler.bracket.cssvar.px(d) }), { autocomplete: "ring-offset-(width|size)-$lineWidth" }],
619
- [/^ring-(.+)$/, utilities.colorResolver("--un-ring-color", "ring"), { autocomplete: "ring-$colors" }],
620
- [/^ring-op(?:acity)?-?(.+)$/, ([, opacity]) => ({ "--un-ring-opacity": utilities.handler.bracket.percent(opacity) }), { autocomplete: "ring-(op|opacity)-<percent>" }],
621
- [/^ring-offset-(.+)$/, utilities.colorResolver("--un-ring-offset-color", "ring-offset"), { autocomplete: "ring-offset-$colors" }],
622
- [/^ring-offset-op(?:acity)?-?(.+)$/, ([, opacity]) => ({ "--un-ring-offset-opacity": utilities.handler.bracket.percent(opacity) }), { autocomplete: "ring-offset-(op|opacity)-<percent>" }],
623
- ["ring-inset", { "--un-ring-inset": "inset" }]
624
- ];
625
-
626
- const boxShadows = [
627
- [/^shadow(?:-(.+))?$/, ([, d], { theme }) => {
628
- const v = theme.boxShadow?.[d || "DEFAULT"];
629
- if (v) {
630
- return [
631
- {
632
- [core.CONTROL_SHORTCUT_NO_MERGE]: "",
633
- "--un-shadow-inset": varEmpty,
634
- "--un-shadow": "0 0 #0000"
635
- },
636
- {
637
- "--un-shadow": utilities.colorableShadows(v, "--un-shadow-color").join(","),
638
- "box-shadow": "var(--un-ring-offset-shadow, 0 0 #0000), var(--un-ring-shadow, 0 0 #0000), var(--un-shadow)"
639
- }
640
- ];
641
- }
642
- }, { autocomplete: "shadow-$boxShadow" }],
643
- [/^shadow-(.+)$/, utilities.colorResolver("--un-shadow-color", "shadow"), { autocomplete: "shadow-$colors" }],
644
- [/^shadow-op(?:acity)?-?(.+)$/, ([, opacity]) => ({ "--un-shadow-opacity": utilities.handler.bracket.percent(opacity) }), { autocomplete: "shadow-(op|opacity)-<percent>" }],
645
- ["shadow-inset", { "--un-shadow-inset": "inset" }]
646
- ];
647
-
648
509
  const sizeMapping = {
649
510
  h: "height",
650
511
  w: "width",
@@ -723,153 +584,6 @@ const margins = [
723
584
  [/^m-?([bi][se])(?:-?(-?.+))?$/, utilities.directionSize("margin")]
724
585
  ];
725
586
 
726
- const transformGpu = {
727
- "--un-transform": [
728
- "translate3d(var(--un-translate-x), var(--un-translate-y), var(--un-translate-z))",
729
- "rotate(var(--un-rotate))",
730
- "rotateX(var(--un-rotate-x))",
731
- "rotateY(var(--un-rotate-y))",
732
- "rotateZ(var(--un-rotate-z))",
733
- "skewX(var(--un-skew-x))",
734
- "skewY(var(--un-skew-y))",
735
- "scaleX(var(--un-scale-x))",
736
- "scaleY(var(--un-scale-y))",
737
- "scaleZ(var(--un-scale-z))"
738
- ].join(" ")
739
- };
740
- const transformCpu = {
741
- "--un-transform": [
742
- "translateX(var(--un-translate-x))",
743
- "translateY(var(--un-translate-y))",
744
- "translateZ(var(--un-translate-z))",
745
- "rotate(var(--un-rotate))",
746
- "rotateX(var(--un-rotate-x))",
747
- "rotateY(var(--un-rotate-y))",
748
- "rotateZ(var(--un-rotate-z))",
749
- "skewX(var(--un-skew-x))",
750
- "skewY(var(--un-skew-y))",
751
- "scaleX(var(--un-scale-x))",
752
- "scaleY(var(--un-scale-y))",
753
- "scaleZ(var(--un-scale-z))"
754
- ].join(" ")
755
- };
756
- const transformBase = {
757
- "--un-rotate": 0,
758
- "--un-rotate-x": 0,
759
- "--un-rotate-y": 0,
760
- "--un-rotate-z": 0,
761
- "--un-scale-x": 1,
762
- "--un-scale-y": 1,
763
- "--un-scale-z": 1,
764
- "--un-skew-x": 0,
765
- "--un-skew-y": 0,
766
- "--un-translate-x": 0,
767
- "--un-translate-y": 0,
768
- "--un-translate-z": 0,
769
- ...transformCpu,
770
- [core.CONTROL_SHORTCUT_NO_MERGE]: "",
771
- [utilities.CONTROL_MINI_NO_NEGATIVE]: ""
772
- };
773
- const transforms = [
774
- [/^(?:transform-)?origin-(.+)$/, ([, s]) => ({ "transform-origin": utilities.positionMap[s] ?? utilities.handler.bracket.cssvar(s) }), { autocomplete: [`transform-origin-(${Object.keys(utilities.positionMap).join("|")})`, `origin-(${Object.keys(utilities.positionMap).join("|")})`] }],
775
- [/^(?:transform-)?perspect(?:ive)?-(.+)$/, ([, s]) => {
776
- const v = utilities.handler.bracket.cssvar.px.numberWithUnit(s);
777
- if (v != null) {
778
- return {
779
- "-webkit-perspective": v,
780
- "perspective": v
781
- };
782
- }
783
- }],
784
- [/^(?:transform-)?perspect(?:ive)?-origin-(.+)$/, ([, s]) => {
785
- const v = utilities.handler.bracket.cssvar(s) ?? (s.length >= 3 ? utilities.positionMap[s] : void 0);
786
- if (v != null) {
787
- return {
788
- "-webkit-perspective-origin": v,
789
- "perspective-origin": v
790
- };
791
- }
792
- }],
793
- [/^(?:transform-)?translate-()(.+)$/, handleTranslate],
794
- [/^(?:transform-)?translate-([xyz])-(.+)$/, handleTranslate],
795
- [/^(?:transform-)?rotate-()(.+)$/, handleRotate],
796
- [/^(?:transform-)?rotate-([xyz])-(.+)$/, handleRotate],
797
- [/^(?:transform-)?skew-([xy])-(.+)$/, handleSkew],
798
- [/^(?:transform-)?scale-()(.+)$/, handleScale],
799
- [/^(?:transform-)?scale-([xyz])-(.+)$/, handleScale],
800
- [/^(?:transform-)?preserve-3d$/, () => ({ "transform-style": "preserve-3d" })],
801
- [/^(?:transform-)?preserve-flat$/, () => ({ "transform-style": "flat" })],
802
- [/^transform$/, () => [
803
- transformBase,
804
- { transform: "var(--un-transform)" }
805
- ]],
806
- ["transform-gpu", transformGpu],
807
- ["transform-cpu", transformCpu],
808
- ["transform-none", { transform: "none" }]
809
- ];
810
- function handleTranslate([, d, b], { theme }) {
811
- const v = theme.spacing?.[b] ?? utilities.handler.bracket.cssvar.fraction.rem(b);
812
- if (v != null) {
813
- return [
814
- transformBase,
815
- [
816
- ...utilities.xyzMap[d].map((i) => [`--un-translate${i}`, v]),
817
- ["transform", "var(--un-transform)"]
818
- ]
819
- ];
820
- }
821
- }
822
- function handleScale([, d, b]) {
823
- const v = utilities.handler.bracket.cssvar.fraction.percent(b);
824
- if (v != null) {
825
- return [
826
- transformBase,
827
- [
828
- ...utilities.xyzMap[d].map((i) => [`--un-scale${i}`, v]),
829
- ["transform", "var(--un-transform)"]
830
- ]
831
- ];
832
- }
833
- }
834
- function handleRotate([, d = "", b]) {
835
- const v = utilities.handler.bracket.cssvar.degree(b);
836
- if (v != null) {
837
- if (d) {
838
- return [
839
- transformBase,
840
- {
841
- "--un-rotate": 0,
842
- [`--un-rotate-${d}`]: v,
843
- "transform": "var(--un-transform)"
844
- }
845
- ];
846
- } else {
847
- return [
848
- transformBase,
849
- {
850
- "--un-rotate-x": 0,
851
- "--un-rotate-y": 0,
852
- "--un-rotate-z": 0,
853
- "--un-rotate": v,
854
- "transform": "var(--un-transform)"
855
- }
856
- ];
857
- }
858
- }
859
- }
860
- function handleSkew([, d, b]) {
861
- const v = utilities.handler.bracket.cssvar.degree(b);
862
- if (v != null) {
863
- return [
864
- transformBase,
865
- {
866
- [`--un-skew-${d}`]: v,
867
- transform: "var(--un-transform)"
868
- }
869
- ];
870
- }
871
- }
872
-
873
587
  const variablesAbbrMap = {
874
588
  backface: "backface-visibility",
875
589
  break: "word-break",
@@ -954,40 +668,40 @@ const rules = [
954
668
  cssProperty,
955
669
  paddings,
956
670
  margins,
957
- displays,
671
+ transform.displays,
958
672
  opacity,
959
673
  bgColors,
960
674
  svgUtilities,
961
675
  borders,
962
- contents,
676
+ transform.contents,
963
677
  fonts,
964
678
  tabSizes,
965
679
  textIndents,
966
- textOverflows,
680
+ transform.textOverflows,
967
681
  textDecorations,
968
682
  textStrokes,
969
683
  textShadows,
970
- textTransforms,
684
+ transform.textTransforms,
971
685
  textAligns,
972
686
  textColors,
973
- fontStyles,
974
- fontSmoothings,
975
- boxShadows,
976
- rings,
687
+ transform.fontStyles,
688
+ transform.fontSmoothings,
689
+ transform.boxShadows,
690
+ transform.rings,
977
691
  flex,
978
692
  grids,
979
693
  gaps,
980
694
  positions,
981
695
  sizes,
982
696
  aspectRatio,
983
- cursors,
984
- appearances,
985
- pointerEvents,
986
- resizes,
697
+ transform.cursors,
698
+ transform.appearances,
699
+ transform.pointerEvents,
700
+ transform.resizes,
987
701
  verticalAligns,
988
- userSelects,
989
- whitespaces,
990
- breaks,
702
+ transform.userSelects,
703
+ transform.whitespaces,
704
+ transform.breaks,
991
705
  overflows,
992
706
  outline,
993
707
  appearance,
@@ -1000,29 +714,21 @@ const rules = [
1000
714
  zIndexes,
1001
715
  boxSizing,
1002
716
  transitions,
1003
- transforms,
717
+ transform.transforms,
1004
718
  willChange,
1005
719
  questionMark
1006
720
  ].flat(1);
1007
721
 
1008
722
  exports.alignments = alignments;
1009
723
  exports.appearance = appearance;
1010
- exports.appearances = appearances;
1011
724
  exports.aspectRatio = aspectRatio;
1012
725
  exports.bgColors = bgColors;
1013
726
  exports.borders = borders;
1014
- exports.boxShadows = boxShadows;
1015
727
  exports.boxSizing = boxSizing;
1016
- exports.breaks = breaks;
1017
- exports.contents = contents;
1018
728
  exports.cssProperty = cssProperty;
1019
729
  exports.cssVariables = cssVariables;
1020
- exports.cursors = cursors;
1021
- exports.displays = displays;
1022
730
  exports.flex = flex;
1023
731
  exports.floats = floats;
1024
- exports.fontSmoothings = fontSmoothings;
1025
- exports.fontStyles = fontStyles;
1026
732
  exports.fonts = fonts;
1027
733
  exports.gaps = gaps;
1028
734
  exports.grids = grids;
@@ -1035,11 +741,8 @@ exports.outline = outline;
1035
741
  exports.overflows = overflows;
1036
742
  exports.paddings = paddings;
1037
743
  exports.placements = placements;
1038
- exports.pointerEvents = pointerEvents;
1039
744
  exports.positions = positions;
1040
745
  exports.questionMark = questionMark;
1041
- exports.resizes = resizes;
1042
- exports.rings = rings;
1043
746
  exports.rules = rules;
1044
747
  exports.sizes = sizes;
1045
748
  exports.svgUtilities = svgUtilities;
@@ -1048,15 +751,9 @@ exports.textAligns = textAligns;
1048
751
  exports.textColors = textColors;
1049
752
  exports.textDecorations = textDecorations;
1050
753
  exports.textIndents = textIndents;
1051
- exports.textOverflows = textOverflows;
1052
754
  exports.textShadows = textShadows;
1053
755
  exports.textStrokes = textStrokes;
1054
- exports.textTransforms = textTransforms;
1055
- exports.transforms = transforms;
1056
756
  exports.transitions = transitions;
1057
- exports.userSelects = userSelects;
1058
- exports.varEmpty = varEmpty;
1059
757
  exports.verticalAligns = verticalAligns;
1060
- exports.whitespaces = whitespaces;
1061
758
  exports.willChange = willChange;
1062
759
  exports.zIndexes = zIndexes;