postcss-sort-media-queries 5.1.0 → 5.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -0
- package/browser.js +54 -54
- package/index.js +36 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
- [sort](#sort)
|
|
30
30
|
- [Custom sort function](#custom-sort-function)
|
|
31
31
|
- [Sort configuration](#sort-configuration)
|
|
32
|
+
- [Only Top Level](#only-top-level)
|
|
32
33
|
- [Changelog](#changelog)
|
|
33
34
|
- [License](#license)
|
|
34
35
|
- [Other PostCSS plugins](#other-postcss-plugins)
|
|
@@ -236,6 +237,18 @@ postcss([
|
|
|
236
237
|
|
|
237
238
|
Or alternatively create a `sort-css-mq.config.json` file in the root of your project. Or add property `sortCssMQ: {}` in your `package.json`.
|
|
238
239
|
|
|
240
|
+
### Only Top Level
|
|
241
|
+
|
|
242
|
+
Sort only top level media queries to prevent eject nested media queries from parent node
|
|
243
|
+
|
|
244
|
+
```js
|
|
245
|
+
postcss([
|
|
246
|
+
sortMediaQueries({
|
|
247
|
+
onlyTopLevel: true,
|
|
248
|
+
})
|
|
249
|
+
]).process(css);
|
|
250
|
+
```
|
|
251
|
+
|
|
239
252
|
---
|
|
240
253
|
|
|
241
254
|
## Changelog
|
package/browser.js
CHANGED
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
function sortAtRules(queries, sort, sortCSSmq) {
|
|
2
|
-
if (typeof sort !== 'function') {
|
|
3
|
-
sort = sort === 'desktop-first' ? sortCSSmq.desktopFirst : sortCSSmq
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
return queries.sort(sort)
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
module.exports = (opts = {}) => {
|
|
10
|
-
|
|
11
|
-
opts = Object.assign(
|
|
12
|
-
{
|
|
13
|
-
sort: 'mobile-first',
|
|
14
|
-
configuration: {
|
|
15
|
-
unitlessMqAlwaysFirst: false,
|
|
16
|
-
},
|
|
17
|
-
},
|
|
18
|
-
opts
|
|
19
|
-
)
|
|
20
|
-
|
|
21
|
-
const createSort = require('sort-css-media-queries/lib/create-sort');
|
|
22
|
-
const sortCSSmq = createSort(opts.configuration);
|
|
23
|
-
|
|
24
|
-
return {
|
|
25
|
-
postcssPlugin: 'postcss-sort-media-queries',
|
|
26
|
-
OnceExit(root, { AtRule }) {
|
|
27
|
-
|
|
28
|
-
let atRules = [];
|
|
29
|
-
|
|
30
|
-
root.walkAtRules('media', atRule => {
|
|
31
|
-
let query = atRule.params
|
|
32
|
-
|
|
33
|
-
if (!atRules[query]) {
|
|
34
|
-
atRules[query] = new AtRule({
|
|
35
|
-
name: atRule.name,
|
|
36
|
-
params: atRule.params,
|
|
37
|
-
source: atRule.source
|
|
38
|
-
})
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
atRule.nodes.forEach(node => {
|
|
42
|
-
atRules[query].append(node.clone())
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
atRule.remove()
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
sortAtRules(Object.keys(atRules), opts.sort, sortCSSmq).forEach(query => {
|
|
49
|
-
root.append(atRules[query])
|
|
50
|
-
})
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
module.exports.postcss = true
|
|
1
|
+
function sortAtRules(queries, sort, sortCSSmq) {
|
|
2
|
+
if (typeof sort !== 'function') {
|
|
3
|
+
sort = sort === 'desktop-first' ? sortCSSmq.desktopFirst : sortCSSmq
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
return queries.sort(sort)
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
module.exports = (opts = {}) => {
|
|
10
|
+
|
|
11
|
+
opts = Object.assign(
|
|
12
|
+
{
|
|
13
|
+
sort: 'mobile-first',
|
|
14
|
+
configuration: {
|
|
15
|
+
unitlessMqAlwaysFirst: false,
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
opts
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
const createSort = require('sort-css-media-queries/lib/create-sort');
|
|
22
|
+
const sortCSSmq = createSort(opts.configuration);
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
postcssPlugin: 'postcss-sort-media-queries',
|
|
26
|
+
OnceExit(root, { AtRule }) {
|
|
27
|
+
|
|
28
|
+
let atRules = [];
|
|
29
|
+
|
|
30
|
+
root.walkAtRules('media', atRule => {
|
|
31
|
+
let query = atRule.params
|
|
32
|
+
|
|
33
|
+
if (!atRules[query]) {
|
|
34
|
+
atRules[query] = new AtRule({
|
|
35
|
+
name: atRule.name,
|
|
36
|
+
params: atRule.params,
|
|
37
|
+
source: atRule.source
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
atRule.nodes.forEach(node => {
|
|
42
|
+
atRules[query].append(node.clone())
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
atRule.remove()
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
sortAtRules(Object.keys(atRules), opts.sort, sortCSSmq).forEach(query => {
|
|
49
|
+
root.append(atRules[query])
|
|
50
|
+
})
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
module.exports.postcss = true
|
package/index.js
CHANGED
|
@@ -12,6 +12,7 @@ module.exports = (opts = {}) => {
|
|
|
12
12
|
{
|
|
13
13
|
sort: 'mobile-first',
|
|
14
14
|
configuration: false,
|
|
15
|
+
onlyTopLevel: false,
|
|
15
16
|
},
|
|
16
17
|
opts
|
|
17
18
|
)
|
|
@@ -26,26 +27,48 @@ module.exports = (opts = {}) => {
|
|
|
26
27
|
let atRules = [];
|
|
27
28
|
|
|
28
29
|
root.walkAtRules('media', atRule => {
|
|
29
|
-
|
|
30
|
+
if (opts.onlyTopLevel && atRule.parent.type === 'root') {
|
|
31
|
+
let query = atRule.params
|
|
30
32
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
if (!atRules[query]) {
|
|
34
|
+
atRules[query] = new AtRule({
|
|
35
|
+
name: atRule.name,
|
|
36
|
+
params: atRule.params,
|
|
37
|
+
source: atRule.source
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
atRule.nodes.forEach(node => {
|
|
42
|
+
atRules[query].append(node.clone())
|
|
36
43
|
})
|
|
44
|
+
|
|
45
|
+
atRule.remove()
|
|
37
46
|
}
|
|
38
47
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
})
|
|
48
|
+
if (!opts.onlyTopLevel) {
|
|
49
|
+
let query = atRule.params
|
|
42
50
|
|
|
43
|
-
|
|
44
|
-
|
|
51
|
+
if (!atRules[query]) {
|
|
52
|
+
atRules[query] = new AtRule({
|
|
53
|
+
name: atRule.name,
|
|
54
|
+
params: atRule.params,
|
|
55
|
+
source: atRule.source
|
|
56
|
+
})
|
|
57
|
+
}
|
|
45
58
|
|
|
46
|
-
|
|
47
|
-
|
|
59
|
+
atRule.nodes.forEach(node => {
|
|
60
|
+
atRules[query].append(node.clone())
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
atRule.remove()
|
|
64
|
+
}
|
|
48
65
|
})
|
|
66
|
+
|
|
67
|
+
if (atRules) {
|
|
68
|
+
sortAtRules(Object.keys(atRules), opts.sort, sortCSSmq).forEach(query => {
|
|
69
|
+
root.append(atRules[query])
|
|
70
|
+
})
|
|
71
|
+
}
|
|
49
72
|
}
|
|
50
73
|
}
|
|
51
74
|
}
|
package/package.json
CHANGED