Skip to content

Commit a2639ea

Browse files
committed
Add @custom-media support
1 parent b5b5e38 commit a2639ea

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

index.js

+23
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,28 @@ module.exports = function(css, options){
382382
});
383383
}
384384

385+
386+
/**
387+
* Parse custom-media.
388+
*/
389+
390+
function atcustommedia() {
391+
var pos = position();
392+
var m = match(/^@([-\w]+)?custom-media (--[^\s]+) *([^{]+);/);
393+
if (!m) return;
394+
395+
var vendor = trim(m[1]);
396+
var name = trim(m[2]);
397+
var list = trim(m[3]);
398+
399+
return pos({
400+
type: 'custom-media',
401+
vendor: vendor,
402+
name: name,
403+
media: list
404+
});
405+
}
406+
385407
/**
386408
* Parse paged media.
387409
*/
@@ -509,6 +531,7 @@ module.exports = function(css, options){
509531

510532
return atkeyframes()
511533
|| atmedia()
534+
|| atcustommedia()
512535
|| atsupports()
513536
|| atimport()
514537
|| atcharset()

test/cases/custom-media.css

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

test/cases/custom-media.json

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

0 commit comments

Comments
 (0)