Skip to content

Commit 1071b94

Browse files
committed
Added "range" minMax and maxMin two value comparisons support
https://www.w3.org/TR/mediaqueries-4/#mq-range-context
1 parent 2f56d8c commit 1071b94

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

lib/create-sort.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,21 @@
33
// ----------------------------------------
44

55
const minMaxWidth =
6-
/(!?\(\s*min(-device)?-width)(.|\n)+\(\s*max(-device)?-width|\(\s*width\s*>(=)?(.|\n)+\(\s*width\s*<(=)?/i;
6+
/(!?\(\s*min(-device)?-width)(.|\n)+\(\s*max(-device)?-width|\(\s*width\s*>(=)?(.|\n)+\(\s*width\s*<(=)?|(!?\(.*<(=)?\s*width\s*<(=)?)/i;
77
const minWidth = /\(\s*min(-device)?-width|\(\s*width\s*>(=)?/i;
88
const maxMinWidth =
9-
/(!?\(\s*max(-device)?-width)(.|\n)+\(\s*min(-device)?-width|\(\s*width\s*<(=)?(.|\n)+\(\s*width\s*>(=)?/i;
9+
/(!?\(\s*max(-device)?-width)(.|\n)+\(\s*min(-device)?-width|\(\s*width\s*<(=)?(.|\n)+\(\s*width\s*>(=)?|(!?\(.*>(=)?\s*width\s*>(=)?)/i;
1010
const maxWidth = /\(\s*max(-device)?-width|\(\s*width\s*<(=)?/i;
1111

1212
const isMinWidth = _testQuery(minMaxWidth, maxMinWidth, minWidth);
1313
const isMaxWidth = _testQuery(maxMinWidth, minMaxWidth, maxWidth);
1414

15-
const minMaxHeight = /(!?\(\s*min(-device)?-height)(.|\n)+\(\s*max(-device)?-height/i;
16-
const minHeight = /\(\s*min(-device)?-height/i;
17-
const maxMinHeight = /(!?\(\s*max(-device)?-height)(.|\n)+\(\s*min(-device)?-height/i;
18-
const maxHeight = /\(\s*max(-device)?-height/i;
15+
const minMaxHeight =
16+
/(!?\(\s*min(-device)?-height)(.|\n)+\(\s*max(-device)?-height|\(\s*height\s*>(=)?(.|\n)+\(\s*height\s*<(=)?|(!?\(.*<(=)?\s*height\s*<(=)?)/i;
17+
const minHeight = /\(\s*min(-device)?-height|\(\s*height\s*>(=)?/i;
18+
const maxMinHeight =
19+
/(!?\(\s*max(-device)?-height)(.|\n)+\(\s*min(-device)?-height|\(\s*height\s*<(=)?(.|\n)+\(\s*height\s*>(=)?|(!?\(.*>(=)?\s*height\s*>(=)?)/i;
20+
const maxHeight = /\(\s*max(-device)?-height|\(\s*height\s*<(=)?/i;
1921

2022
const isMinHeight = _testQuery(minMaxHeight, maxMinHeight, minHeight);
2123
const isMaxHeight = _testQuery(maxMinHeight, minMaxHeight, maxHeight);

tests/index.spec.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ test(`multiline #1. mobile-first`, () => {
321321
and (max-width: 47.999em)`,
322322
`@media (min-width: 15em)
323323
and (max-width: 47.999em)`,
324+
`@media (0 < width < 20px)`,
324325
`@media (min-width: 2em)
325326
and (max-width: 47.999em)`,
326327
`@media (min-width: 20em)
@@ -342,10 +343,12 @@ test(`multiline #1. mobile-first`, () => {
342343
`@media (width > 3em)
343344
and (width < 48.999em)`,
344345
`@media (width > 31em)
345-
and (width < 48.999em)`
346+
and (width < 48.999em)`,
347+
`@media (31em < width < 48.999em )`
346348
];
347349

348350
const expectedOrder = [
351+
`@media (0 < width < 20px)`,
349352
`@media (min-width: 2em)
350353
and (max-width: 47.999em)`,
351354
`@media (width > 2em)
@@ -362,6 +365,7 @@ test(`multiline #1. mobile-first`, () => {
362365
and (max-width: 47.999em)`,
363366
`@media (width > 20em)
364367
and (width < 47.999em)`,
368+
`@media (31em < width < 48.999em )`,
365369
`@media (min-width: 31em)
366370
and (max-width: 48.999em)`,
367371
`@media (width > 31em)

0 commit comments

Comments
 (0)