postcss-sort-media-queries 4.0.0 → 4.1.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/CHANGELOG.md CHANGED
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [4.1.0] 2021-09-13
9
+
10
+ - Add module for browser
11
+
8
12
  ## [4.0.0] 2021-09-13
9
13
 
10
14
  - Add [sort-css-media-queries#configuration-options](https://github.com/dutchenkoOleg/sort-css-media-queries#configuration-options) support
package/browser.js ADDED
@@ -0,0 +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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "postcss-sort-media-queries",
3
- "version": "4.0.0",
3
+ "version": "4.1.0",
4
4
  "description": "PostCSS plugin for combine and sort CSS media queries with mobile first or desktop first methods.",
5
5
  "keywords": [
6
6
  "postcss",