File tree Expand file tree Collapse file tree 4 files changed +98
-4
lines changed
apps/builder/app/shared/tailwind Expand file tree Collapse file tree 4 files changed +98
-4
lines changed Original file line number Diff line number Diff line change @@ -511,6 +511,65 @@ describe("extract breakpoints", () => {
511
511
)
512
512
) ;
513
513
} ) ;
514
+
515
+ test ( "adapt max-* breakpoints" , async ( ) => {
516
+ expect (
517
+ await generateFragmentFromTailwind (
518
+ renderTemplate (
519
+ < ws . element
520
+ ws :tag = "div"
521
+ class = "max-sm:opacity-10 max-md:opacity-20 max-lg:opacity-30 max-xl:opacity-40 max-2xl:opacity-50 opacity-60"
522
+ > </ ws . element >
523
+ )
524
+ )
525
+ ) . toEqual (
526
+ renderTemplate (
527
+ < ws . element
528
+ ws :tag = "div"
529
+ ws :style = { css `
530
+ @media (min-width : 1440px ) {
531
+ opacity : 0.6 ;
532
+ }
533
+ @media (min-width : 1280px ) {
534
+ opacity : 0.5 ;
535
+ }
536
+ opacity : 0.4 ;
537
+ @media (max-width : 991px ) {
538
+ opacity : 0.3 ;
539
+ }
540
+ @media (max-width : 767px ) {
541
+ opacity : 0.2 ;
542
+ }
543
+ @media (max-width : 479px ) {
544
+ opacity : 0.1 ;
545
+ }
546
+ ` }
547
+ > </ ws . element >
548
+ )
549
+ ) ;
550
+ } ) ;
551
+
552
+ test ( "ignore composite breakpoints" , async ( ) => {
553
+ expect (
554
+ await generateFragmentFromTailwind (
555
+ renderTemplate (
556
+ < ws . element
557
+ ws :tag = "div"
558
+ class = "opacity-10 md:max-xl:flex"
559
+ > </ ws . element >
560
+ )
561
+ )
562
+ ) . toEqual (
563
+ renderTemplate (
564
+ < ws . element
565
+ ws :tag = "div"
566
+ ws :style = { css `
567
+ opacity : 0.1 ;
568
+ ` }
569
+ > </ ws . element >
570
+ )
571
+ ) ;
572
+ } ) ;
514
573
} ) ;
515
574
516
575
test ( "generate space without display property" , async ( ) => {
Original file line number Diff line number Diff line change @@ -27,11 +27,13 @@ const availableBreakpoints = [
27
27
] ;
28
28
29
29
const tailwindToWebstudioMappings : Record < number , undefined | number > = {
30
- 639 : 479 ,
30
+ 639.9 : 479 ,
31
31
640 : 480 ,
32
- 1023 : 991 ,
32
+ 767.9 : 767 ,
33
+ 1023.9 : 991 ,
33
34
1024 : 992 ,
34
- 1535 : 1439 ,
35
+ 1279.9 : 1279 ,
36
+ 1535.9 : 1439 ,
35
37
1536 : 1440 ,
36
38
} ;
37
39
@@ -120,8 +122,10 @@ const rangesToBreakpoints = (ranges: Range[]) => {
120
122
const adaptBreakpoints = (
121
123
parsedStyles : Omit < ParsedStyleDecl , "selector" > [ ]
122
124
) => {
125
+ const newStyles : typeof parsedStyles = [ ] ;
123
126
const breakpointGroups = new Map < string , Breakpoint [ ] > ( ) ;
124
127
for ( const styleDecl of parsedStyles ) {
128
+ newStyles . push ( styleDecl ) ;
125
129
const mediaQuery = styleDecl . breakpoint
126
130
? parseMediaQuery ( styleDecl . breakpoint )
127
131
: undefined ;
@@ -155,13 +159,14 @@ const adaptBreakpoints = (
155
159
breakpointsByKey . set ( breakpoint . key , breakpoint ) ;
156
160
}
157
161
}
158
- for ( const styleDecl of parsedStyles ) {
162
+ for ( const styleDecl of newStyles ) {
159
163
const styleDeclKey = `${ styleDecl . breakpoint ?? "" } :${ styleDecl . property } :${ styleDecl . state ?? "" } ` ;
160
164
const breakpoint = breakpointsByKey . get ( styleDeclKey ) ;
161
165
if ( breakpoint ) {
162
166
styleDecl . breakpoint = serializeBreakpoint ( breakpoint ) ;
163
167
}
164
168
}
169
+ return newStyles ;
165
170
} ;
166
171
167
172
const createUnoGenerator = async ( ) => {
Original file line number Diff line number Diff line change @@ -714,6 +714,30 @@ test("ignore unsupported media queries", () => {
714
714
] ) ;
715
715
} ) ;
716
716
717
+ test ( "ignore nested media queries" , ( ) => {
718
+ expect (
719
+ parseCss ( `
720
+ @media (min-width: 768px) {
721
+ a {
722
+ color: green;
723
+ }
724
+ @media (max-width: 1024px) {
725
+ a {
726
+ color: red;
727
+ }
728
+ }
729
+ }
730
+ ` )
731
+ ) . toEqual ( [
732
+ {
733
+ breakpoint : "(min-width:768px)" ,
734
+ selector : "a" ,
735
+ property : "color" ,
736
+ value : { type : "keyword" , value : "green" } ,
737
+ } ,
738
+ ] ) ;
739
+ } ) ;
740
+
717
741
test ( "ignore unsupported at rules" , ( ) => {
718
742
expect (
719
743
parseCss ( `
Original file line number Diff line number Diff line change @@ -103,6 +103,12 @@ export const parseCss = (css: string): ParsedStyleDecl[] => {
103
103
}
104
104
105
105
csstree . walk ( ast , function ( node ) {
106
+ // forbid nested at rules
107
+ if ( node . type === "Atrule" && this . atrule ) {
108
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
109
+ // @ts -ignore https://github.com/csstree/csstree/blob/v2.3.1/docs/traversal.md
110
+ return this . break ;
111
+ }
106
112
if ( node . type !== "Declaration" || this . rule ?. prelude . type === undefined ) {
107
113
return ;
108
114
}
You can’t perform that action at this time.
0 commit comments