Skip to content

Commit 02235f9

Browse files
committed
Merge pull request #88 from reworkcss/better-at-rules
Add `@custom-media` support
2 parents f5b90ae + 02b448d commit 02235f9

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

index.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,23 @@ module.exports = function(css, options){
381381
});
382382
}
383383

384+
385+
/**
386+
* Parse custom-media.
387+
*/
388+
389+
function atcustommedia() {
390+
var pos = position();
391+
var m = match(/^@custom-media (--[^\s]+) *([^{]+);/);
392+
if (!m) return;
393+
394+
return pos({
395+
type: 'custom-media',
396+
name: trim(m[1]),
397+
media: trim(m[2])
398+
});
399+
}
400+
384401
/**
385402
* Parse paged media.
386403
*/
@@ -508,6 +525,7 @@ module.exports = function(css, options){
508525

509526
return atkeyframes()
510527
|| atmedia()
528+
|| atcustommedia()
511529
|| atsupports()
512530
|| atimport()
513531
|| atcharset()

test/cases/custom-media.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@custom-media --narrow-window (max-width: 30em);

test/cases/custom-media.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"type": "stylesheet",
3+
"stylesheet": {
4+
"rules": [
5+
{
6+
"type": "custom-media",
7+
"name": "--narrow-window",
8+
"media": "(max-width: 30em)",
9+
"position": {
10+
"start": {
11+
"line": 1,
12+
"column": 1
13+
},
14+
"end": {
15+
"line": 1,
16+
"column": 49
17+
},
18+
"source": "custom-media.css"
19+
}
20+
}
21+
]
22+
}
23+
}

0 commit comments

Comments
 (0)