Debian Codegraph @

plugins/postcss-media-minmax/test/browser/basic.html

raw
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <title>CSS Media Queries 4</title>
5 <style>
6 target {
7 color: red;
8 }
9 </style>
10 </head>
11 <body>
12 <target class="first"></target>
13 <target class="second"></target>
14
15 <div id="log"></div>
16 <script type="module">
17 window.addEventListener('click', () => {
18 window.runTest();
19 });
20
21 window.runTest = async function runTest() {
22 function assert_equals(actual, expected, message) {
23 if (actual != expected) {
24 log.innerHTML = message + ": expected " + expected + ", got " + actual;
25 throw new Error(message + ": expected " + expected + ", got " + actual);
26 }
27 }
28
29 // In all test cases, the rule specified as "color: green" should win.
30 var testCases = [
31 // width feature
32 {
33 title: '1000px is width',
34 style: `
35 @media (1000px = width) {
36 target {
37 color: green;
38 }
39 }
40 `,
41 },
42 {
43 title: 'Width is 1000px',
44 style: `
45 @media (width = 1000px) {
46 target {
47 color: green;
48 }
49 }
50 `,
51 },
52 {
53 title: 'Width greater than 1000px',
54 style: `
55 target {
56 color: green;
57 }
58
59 @media (width > 1000px) {
60 target {
61 color: red;
62 }
63 }
64 `,
65 },
66 {
67 title: '1000px less than width',
68 style: `
69 target {
70 color: green;
71 }
72
73 @media (1000px < width) {
74 target {
75 color: red;
76 }
77 }
78 `,
79 },
80 {
81 title: 'Width greater than 999px',
82 style: `
83 @media (width > 999px) {
84 target {
85 color: green;
86 }
87 }
88 `,
89 },
90 {
91 title: '999px less than width',
92 style: `
93 @media (999px < width) {
94 target {
95 color: green;
96 }
97 }
98 `,
99 },
100 {
101 title: 'Width less than 1001px',
102 style: `
103 @media (width < 1001px) {
104 target {
105 color: green;
106 }
107 }
108 `,
109 },
110 {
111 title: '1001px greater than width',
112 style: `
113 @media (1001px > width) {
114 target {
115 color: green;
116 }
117 }
118 `,
119 },
120 {
121 title: 'Width greater than or equal to 1000px',
122 style: `
123 @media (width >= 1000px) {
124 target {
125 color: green;
126 }
127 }
128 `,
129 },
130 {
131 title: '1000px less than or equal to width',
132 style: `
133 @media (1000px <= width) {
134 target {
135 color: green;
136 }
137 }
138 `,
139 },
140 {
141 title: 'Width greater than or equal to 999px',
142 style: `
143 @media (width >= 999px) {
144 target {
145 color: green;
146 }
147 }
148 `,
149 },
150 {
151 title: '999px less than or equal to width',
152 style: `
153 @media (999px <= width) {
154 target {
155 color: green;
156 }
157 }
158 `,
159 },
160 {
161 title: 'Width less than or equal to 1001px',
162 style: `
163 @media (width <= 1001px) {
164 target {
165 color: green;
166 }
167 }
168 `,
169 },
170 {
171 title: '1001px greater than or equal to width',
172 style: `
173 @media (1001px >= width) {
174 target {
175 color: green;
176 }
177 }
178 `,
179 },
180 {
181 title: '999px < width < 1001px',
182 style: `
183 @media (999px < width < 1001px) {
184 target {
185 color: green;
186 }
187 }
188 `,
189 },
190 {
191 title: '1000px < width < 1500px',
192 style: `
193 target {
194 color: green;
195 }
196
197 @media (1000px < width < 1500px) {
198 target {
199 color: red;
200 }
201 }
202 `,
203 },
204 {
205 title: '500px < width < 1000px',
206 style: `
207 target {
208 color: green;
209 }
210
211 @media (500px < width < 1000px) {
212 target {
213 color: red;
214 }
215 }
216 `,
217 },
218 {
219 title: '1000px <= width <= 1500px',
220 style: `
221 @media (1000px <= width <= 1500px) {
222 target {
223 color: green;
224 }
225 }
226 `,
227 },
228 {
229 title: '500px <= width <= 1000px',
230 style: `
231 @media (500px <= width <= 1000px) {
232 target {
233 color: green;
234 }
235 }
236 `,
237 },
238 {
239 title: 'width > 0',
240 style: `
241 @media (width > 0) {
242 target {
243 color: green;
244 }
245 }
246 `,
247 },
248 {
249 title: 'width >= 0',
250 style: `
251 @media (width >= 0) {
252 target {
253 color: green;
254 }
255 }
256 `,
257 },
258
259
260 // width feature with calc
261 {
262 title: 'calc(500px * 2) is width',
263 style: `
264 @media (calc(500px * 2) = width) {
265 target {
266 color: green;
267 }
268 }
269 `,
270 },
271 {
272 title: 'Width is calc(500px * 2)',
273 style: `
274 @media (width = calc(500px * 2)) {
275 target {
276 color: green;
277 }
278 }
279 `,
280 },
281 {
282 title: 'Width greater than calc(500px * 2)',
283 style: `
284 target {
285 color: green;
286 }
287
288 @media (width > calc(500px * 2)) {
289 target {
290 color: red;
291 }
292 }
293 `,
294 },
295 {
296 title: 'calc(500px * 2) less than width',
297 style: `
298 target {
299 color: green;
300 }
301
302 @media (calc(500px * 2) < width) {
303 target {
304 color: red;
305 }
306 }
307 `,
308 },
309 {
310 title: 'Width greater than calc(1000px - 1px)',
311 style: `
312 @media (width > calc(1000px - 1px)) {
313 target {
314 color: green;
315 }
316 }
317 `,
318 },
319 {
320 title: 'calc(1000px - 1px) less than width',
321 style: `
322 @media (calc(1000px - 1px) < width) {
323 target {
324 color: green;
325 }
326 }
327 `,
328 },
329 {
330 title: 'Width less than calc(1000px + 1px)',
331 style: `
332 @media (width < calc(1000px + 1px)) {
333 target {
334 color: green;
335 }
336 }
337 `,
338 },
339 {
340 title: 'calc(1000px + 1px) greater than width',
341 style: `
342 @media (calc(1000px + 1px) > width) {
343 target {
344 color: green;
345 }
346 }
347 `,
348 },
349 {
350 title: 'Width greater than or equal to calc(500px * 2)',
351 style: `
352 @media (width >= calc(500px * 2)) {
353 target {
354 color: green;
355 }
356 }
357 `,
358 },
359 {
360 title: 'calc(500px * 2) less than or equal to width',
361 style: `
362 @media (calc(500px * 2) <= width) {
363 target {
364 color: green;
365 }
366 }
367 `,
368 },
369 {
370 title: 'Width greater than or equal to calc(1000px - 1px)',
371 style: `
372 @media (width >= calc(1000px - 1px)) {
373 target {
374 color: green;
375 }
376 }
377 `,
378 },
379 {
380 title: 'calc(1000px - 1px) less than or equal to width',
381 style: `
382 @media (calc(1000px - 1px) <= width) {
383 target {
384 color: green;
385 }
386 }
387 `,
388 },
389 {
390 title: 'Width less than or equal to calc(1000px + 1px)',
391 style: `
392 @media (width <= calc(1000px + 1px)) {
393 target {
394 color: green;
395 }
396 }
397 `,
398 },
399 {
400 title: 'calc(1000px + 1px) greater than or equal to width',
401 style: `
402 @media (calc(1000px + 1px) >= width) {
403 target {
404 color: green;
405 }
406 }
407 `,
408 },
409 {
410 title: 'calc(1000px - 1px) < width < calc(1000px + 1px)',
411 style: `
412 @media (calc(1000px - 1px) < width < calc(1000px + 1px)) {
413 target {
414 color: green;
415 }
416 }
417 `,
418 },
419 {
420 title: 'calc(500px * 2) < width < 1500px',
421 style: `
422 target {
423 color: green;
424 }
425
426 @media (calc(500px * 2) < width < 1500px) {
427 target {
428 color: red;
429 }
430 }
431 `,
432 },
433 {
434 title: 'calc(1000px / 2) < width < calc(500px * 2)',
435 style: `
436 target {
437 color: green;
438 }
439
440 @media (calc(1000px / 2) < width < calc(500px * 2)) {
441 target {
442 color: red;
443 }
444 }
445 `,
446 },
447 {
448 title: 'calc(500px * 2) <= width <= calc(3000px / 2)',
449 style: `
450 @media (calc(500px * 2) <= width <= calc(3000px / 2)) {
451 target {
452 color: green;
453 }
454 }
455 `,
456 },
457 {
458 title: 'calc(1000px / 2) <= width <= calc(500px * 2)',
459 style: `
460 @media (calc(1000px / 2) <= width <= calc(500px * 2)) {
461 target {
462 color: green;
463 }
464 }
465 `,
466 },
467 {
468 title: 'width > calc(1999px / 2)',
469 style: `
470 @media (width > calc(1999px / 2)) {
471 target {
472 color: green;
473 }
474 }
475 `,
476 },
477 {
478 title: 'width < calc(2001px / 2)',
479 style: `
480 @media (width < calc(2001px / 2)) {
481 target {
482 color: green;
483 }
484 }
485 `,
486 },
487
488 // width feature in rem
489 {
490 title: '62.5rem is width',
491 style: `
492 @media (62.5rem = width) {
493 target {
494 color: green;
495 }
496 }
497 `,
498 },
499 {
500 title: 'Width is 62.5rem',
501 style: `
502 @media (width = 62.5rem) {
503 target {
504 color: green;
505 }
506 }
507 `,
508 },
509 {
510 title: 'Width greater than 62.5rem',
511 style: `
512 target {
513 color: green;
514 }
515
516 @media (width > 62.5rem) {
517 target {
518 color: red;
519 }
520 }
521 `,
522 },
523 {
524 title: '62.5rem less than width',
525 style: `
526 target {
527 color: green;
528 }
529
530 @media (62.5rem < width) {
531 target {
532 color: red;
533 }
534 }
535 `,
536 },
537 {
538 title: 'Width greater than 62.4375rem',
539 style: `
540 @media (width > 62.4375rem) {
541 target {
542 color: green;
543 }
544 }
545 `,
546 },
547 {
548 title: '62.4375rem less than width',
549 style: `
550 @media (62.4375rem < width) {
551 target {
552 color: green;
553 }
554 }
555 `,
556 },
557 {
558 title: 'Width less than 62.5625rem',
559 style: `
560 @media (width < 62.5625rem) {
561 target {
562 color: green;
563 }
564 }
565 `,
566 },
567 {
568 title: '62.5625rem greater than width',
569 style: `
570 @media (62.5625rem > width) {
571 target {
572 color: green;
573 }
574 }
575 `,
576 },
577 {
578 title: 'Width greater than or equal to 62.5rem',
579 style: `
580 @media (width >= 62.5rem) {
581 target {
582 color: green;
583 }
584 }
585 `,
586 },
587 {
588 title: '62.5rem less than or equal to width',
589 style: `
590 @media (62.5rem <= width) {
591 target {
592 color: green;
593 }
594 }
595 `,
596 },
597 {
598 title: 'Width greater than or equal to 62.4375rem',
599 style: `
600 @media (width >= 62.4375rem) {
601 target {
602 color: green;
603 }
604 }
605 `,
606 },
607 {
608 title: '62.4375rem less than or equal to width',
609 style: `
610 @media (62.4375rem <= width) {
611 target {
612 color: green;
613 }
614 }
615 `,
616 },
617 {
618 title: 'Width less than or equal to 62.5625rem',
619 style: `
620 @media (width <= 62.5625rem) {
621 target {
622 color: green;
623 }
624 }
625 `,
626 },
627 {
628 title: '62.5625rem greater than or equal to width',
629 style: `
630 @media (62.5625rem >= width) {
631 target {
632 color: green;
633 }
634 }
635 `,
636 },
637 {
638 title: '62.4375rem < width < 62.5625rem',
639 style: `
640 @media (62.4375rem < width < 62.5625rem) {
641 target {
642 color: green;
643 }
644 }
645 `,
646 },
647 {
648 title: '62.5rem < width < 93.75rem',
649 style: `
650 target {
651 color: green;
652 }
653
654 @media (62.5rem < width < 93.75rem) {
655 target {
656 color: red;
657 }
658 }
659 `,
660 },
661 {
662 title: '500px < width < 62.5rem',
663 style: `
664 target {
665 color: green;
666 }
667
668 @media (500px < width < 62.5rem) {
669 target {
670 color: red;
671 }
672 }
673 `,
674 },
675 {
676 title: '62.5rem <= width <= 93.75rem',
677 style: `
678 @media (62.5rem <= width <= 93.75rem) {
679 target {
680 color: green;
681 }
682 }
683 `,
684 },
685 {
686 title: '500px <= width <= 62.5rem',
687 style: `
688 @media (500px <= width <= 62.5rem) {
689 target {
690 color: green;
691 }
692 }
693 `,
694 },
695
696
697 // height feature
698 {
699 title: '500px is height',
700 style: `
701 @media (500px = height) {
702 target {
703 color: green;
704 }
705 }
706 `,
707 },
708 {
709 title: 'Height is 500px',
710 style: `
711 @media (height = 500px) {
712 target {
713 color: green;
714 }
715 }
716 `,
717 },
718 {
719 title: 'Height greater than 500px',
720 style: `
721 target {
722 color: green;
723 }
724
725 @media (height > 500px) {
726 target {
727 color: red;
728 }
729 }
730 `,
731 },
732 {
733 title: '500px less than height',
734 style: `
735 target {
736 color: green;
737 }
738
739 @media (500px < height) {
740 target {
741 color: red;
742 }
743 }
744 `,
745 },
746 {
747 title: 'Height greater than 499px',
748 style: `
749 @media (height > 499px) {
750 target {
751 color: green;
752 }
753 }
754 `,
755 },
756 {
757 title: '499px less than height',
758 style: `
759 @media (499px < height) {
760 target {
761 color: green;
762 }
763 }
764 `,
765 },
766 {
767 title: 'Height less than 501px',
768 style: `
769 @media (height < 501px) {
770 target {
771 color: green;
772 }
773 }
774 `,
775 },
776 {
777 title: '501px greater than height',
778 style: `
779 @media (501px > height) {
780 target {
781 color: green;
782 }
783 }
784 `,
785 },
786
787 // aspect-ratio feature
788 {
789 title: '2 / 1 = aspect-ratio',
790 style: `
791 @media (2 / 1 = aspect-ratio) {
792 target {
793 color: green;
794 }
795 }
796 `,
797 },
798 {
799 title: 'aspect-ratio = 2 / 1',
800 style: `
801 @media (aspect-ratio = 2 / 1) {
802 target {
803 color: green;
804 }
805 }
806 `,
807 },
808 {
809 title: 'aspect-ratio > 199 / 100',
810 style: `
811 @media (aspect-ratio > 199 / 100) {
812 target {
813 color: green;
814 }
815 }
816 `,
817 },
818 {
819 title: 'aspect-ratio > 1.99 / 1',
820 style: `
821 @media (aspect-ratio > 1.99 / 1) {
822 target {
823 color: green;
824 }
825 }
826 `,
827 },
828 {
829 title: 'aspect-ratio < 201 / 100',
830 style: `
831 @media (aspect-ratio < 201 / 100) {
832 target {
833 color: green;
834 }
835 }
836 `,
837 },
838 {
839 title: 'aspect-ratio < 2.01 / 1',
840 style: `
841 @media (aspect-ratio < 2.01 / 1) {
842 target {
843 color: green;
844 }
845 }
846 `,
847 },
848 {
849 title: 'aspect-ratio >= 2 / 1',
850 style: `
851 @media (aspect-ratio >= 2 / 1) {
852 target {
853 color: green;
854 }
855 }
856 `,
857 },
858 {
859 title: 'aspect-ratio <= 2 / 1',
860 style: `
861 @media (aspect-ratio <= 2 / 1) {
862 target {
863 color: green;
864 }
865 }
866 `,
867 },
868 {
869 title: 'aspect-ratio > 2 / 1',
870 style: `
871 target {
872 color: green;
873 }
874
875 @media (aspect-ratio > 2 / 1) {
876 target {
877 color: red;
878 }
879 }
880 `,
881 },
882 {
883 title: 'aspect-ratio < 2 / 1',
884 style: `
885 target {
886 color: green;
887 }
888
889 @media (aspect-ratio < 2 / 1) {
890 target {
891 color: red;
892 }
893 }
894 `,
895 },
896
897 {
898 title: 'calc(1 + 1) / 1 = aspect-ratio',
899 style: `
900 @media (calc(1 + 1) / 1 = aspect-ratio) {
901 target {
902 color: green;
903 }
904 }
905 `,
906 },
907 {
908 title: 'aspect-ratio = calc(1 + 1) / 1',
909 style: `
910 @media (aspect-ratio = calc(1 + 1) / 1) {
911 target {
912 color: green;
913 }
914 }
915 `,
916 },
917 {
918 title: 'aspect-ratio > calc(200 - 1) / 100',
919 style: `
920 @media (aspect-ratio > calc(200 - 1) / 100) {
921 target {
922 color: green;
923 }
924 }
925 `,
926 },
927 {
928 title: 'aspect-ratio < calc(200 + 1) / 100',
929 style: `
930 @media (aspect-ratio < calc(200 + 1) / 100) {
931 target {
932 color: green;
933 }
934 }
935 `,
936 },
937 {
938 title: 'aspect-ratio >= calc(1 + 1) / 1',
939 style: `
940 @media (aspect-ratio >= calc(1 + 1) / 1) {
941 target {
942 color: green;
943 }
944 }
945 `,
946 },
947 {
948 title: 'aspect-ratio <= calc(1 + 1) / 1',
949 style: `
950 @media (aspect-ratio <= calc(1 + 1) / 1) {
951 target {
952 color: green;
953 }
954 }
955 `,
956 },
957 {
958 title: 'aspect-ratio > calc(1 + 1) / 1',
959 style: `
960 target {
961 color: green;
962 }
963
964 @media (aspect-ratio > calc(1 + 1) / 1) {
965 target {
966 color: red;
967 }
968 }
969 `,
970 },
971 {
972 title: 'aspect-ratio < calc(1 + 1) / 1',
973 style: `
974 target {
975 color: green;
976 }
977
978 @media (aspect-ratio < calc(1 + 1) / 1) {
979 target {
980 color: red;
981 }
982 }
983 `,
984 },
985
986
987 // color feature
988 {
989 title: 'color > 2',
990 style: `
991 @media (color > 2) {
992 target {
993 color: green;
994 }
995 }
996 `,
997 },
998 {
999 title: 'color >= 2',
1000 style: `
1001 @media (color >= 2) {
1002 target {
1003 color: green;
1004 }
1005 }
1006 `,
1007 },
1008 {
1009 title: 'color < 100',
1010 style: `
1011 @media (color < 100) {
1012 target {
1013 color: green;
1014 }
1015 }
1016 `,
1017 },
1018 {
1019 title: 'color <= 100',
1020 style: `
1021 @media (color <= 100) {
1022 target {
1023 color: green;
1024 }
1025 }
1026 `,
1027 },
1028 {
1029 title: 'color = 100',
1030 style: `
1031 target {
1032 color: green;
1033 }
1034
1035 @media (color = 100) {
1036 target {
1037 color: red;
1038 }
1039 }
1040 `,
1041 },
1042 {
1043 title: 'color = 1',
1044 style: `
1045 target {
1046 color: green;
1047 }
1048
1049 @media (color = 1) {
1050 target {
1051 color: red;
1052 }
1053 }
1054 `,
1055 },
1056
1057
1058 // resolution feature
1059 {
1060 title: 'resolution > 191dpi',
1061 style: `
1062 @media (resolution > 191dpi) {
1063 target {
1064 color: green;
1065 }
1066 }
1067 `,
1068 },
1069 {
1070 title: 'resolution >= 192dpi',
1071 style: `
1072 @media (resolution >= 192dpi) {
1073 target {
1074 color: green;
1075 }
1076 }
1077 `,
1078 },
1079 {
1080 title: 'resolution = 192dpi',
1081 style: `
1082 @media (resolution = 192dpi) {
1083 target {
1084 color: green;
1085 }
1086 }
1087 `,
1088 },
1089 {
1090 title: 'resolution < 193dpi',
1091 style: `
1092 @media (resolution < 193dpi) {
1093 target {
1094 color: green;
1095 }
1096 }
1097 `,
1098 },
1099 {
1100 title: 'resolution <= 192dpi',
1101 style: `
1102 @media (resolution <= 192dpi) {
1103 target {
1104 color: green;
1105 }
1106 }
1107 `,
1108 },
1109
1110 {
1111 title: 'resolution > 1dppx',
1112 style: `
1113 @media (resolution > 1dppx) {
1114 target {
1115 color: green;
1116 }
1117 }
1118 `,
1119 },
1120 {
1121 title: 'resolution >= 2dppx',
1122 style: `
1123 @media (resolution >= 2dppx) {
1124 target {
1125 color: green;
1126 }
1127 }
1128 `,
1129 },
1130 {
1131 title: 'resolution = 2dppx',
1132 style: `
1133 @media (resolution = 2dppx) {
1134 target {
1135 color: green;
1136 }
1137 }
1138 `,
1139 },
1140 {
1141 title: 'resolution < 3dppx',
1142 style: `
1143 @media (resolution < 3dppx) {
1144 target {
1145 color: green;
1146 }
1147 }
1148 `,
1149 },
1150 {
1151 title: 'resolution <= 2dppx',
1152 style: `
1153 @media (resolution <= 2dppx) {
1154 target {
1155 color: green;
1156 }
1157 }
1158 `,
1159 },
1160
1161 ];
1162
1163 for (let testCase of testCases) {
1164 // Native
1165 {
1166 const styleElement = document.createElement('style');
1167 styleElement.textContent = testCase['style'];
1168 document.head.append(styleElement);
1169
1170 var targets = document.querySelectorAll('target');
1171 for (let target of targets) {
1172 assert_equals(
1173 window.getComputedStyle(target).color,
1174 'rgb(0, 128, 0)',
1175 testCase['title'] + ", target '" + target.classList[0] + "'"
1176 );
1177 }
1178
1179 styleElement.remove();
1180 }
1181
1182 // Fallback
1183 {
1184 const styleElement = document.createElement('style');
1185
1186 const testCaseStyle = await (fetch(`/test/styles.css`, {
1187 method: 'POST',
1188 body: testCase['style'],
1189 }).then((response) => response.text()));
1190
1191 if (testCaseStyle === testCase['style']) {
1192 throw new Error(`Fallback failed for "${testCase['title']}"`);
1193 }
1194
1195 styleElement.textContent = testCaseStyle;
1196 document.head.append(styleElement);
1197
1198 var targets = document.querySelectorAll('target');
1199 for (let target of targets) {
1200 assert_equals(
1201 window.getComputedStyle(target).color,
1202 'rgb(0, 128, 0)',
1203 testCase['title'] + ", target '" + target.classList[0] + "'"
1204 );
1205 }
1206
1207 styleElement.remove();
1208 }
1209 }
1210
1211 return true;
1212 }
1213 </script>
1214 </body>
1215
1216 </html>