postcss-sort-media-queries 6.5.0 → 6.6.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/dist/index.cjs CHANGED
@@ -234,36 +234,6 @@ function createSort(configuration) {
234
234
  return sortCSSmq;
235
235
  }
236
236
 
237
- // node_modules/nanoid/index.js
238
- var import_node_crypto = require("node:crypto");
239
-
240
- // node_modules/nanoid/url-alphabet/index.js
241
- var urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
242
-
243
- // node_modules/nanoid/index.js
244
- var POOL_SIZE_MULTIPLIER = 128;
245
- var pool;
246
- var poolOffset;
247
- function fillPool(bytes) {
248
- if (!pool || pool.length < bytes) {
249
- pool = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER);
250
- import_node_crypto.webcrypto.getRandomValues(pool);
251
- poolOffset = 0;
252
- } else if (poolOffset + bytes > pool.length) {
253
- import_node_crypto.webcrypto.getRandomValues(pool);
254
- poolOffset = 0;
255
- }
256
- poolOffset += bytes;
257
- }
258
- function nanoid(size = 21) {
259
- fillPool(size |= 0);
260
- let id = "";
261
- for (let i = poolOffset - size; i < poolOffset; i++) {
262
- id += urlAlphabet[pool[i] & 63];
263
- }
264
- return id;
265
- }
266
-
267
237
  // src/index.js
268
238
  function sortAtRules(queries, options, sortCSSmq) {
269
239
  if (typeof options.sort !== "function") {
@@ -291,28 +261,22 @@ function plugin(options = {}) {
291
261
  postcssPlugin: "postcss-sort-media-queries",
292
262
  // Execute once after the entire tree has been parsed
293
263
  OnceExit(root, { AtRule }) {
294
- let parents = [];
264
+ const parents = /* @__PURE__ */ new Map();
295
265
  root.walkAtRules("media", (atRule) => {
296
- if (!atRule.parent.groupId) {
297
- let groupId = nanoid();
298
- atRule.parent.groupId = groupId;
299
- parents[groupId] = {
266
+ if (!parents.has(atRule.parent)) {
267
+ parents.set(atRule.parent, {
300
268
  parent: atRule.parent,
301
269
  depth: getDepth(atRule.parent)
302
- };
270
+ });
303
271
  }
304
- return;
305
272
  });
306
- if (!parents) {
273
+ if (parents.size === 0) {
307
274
  return;
308
275
  }
309
- parents = Object.fromEntries(
310
- Object.entries(parents).sort(([, a], [, b]) => {
311
- return b.depth - a.depth;
312
- })
313
- );
314
- Object.keys(parents).forEach((groupId) => {
315
- let { parent } = parents[groupId];
276
+ const sortedParents = [...parents.values()].sort((a, b) => {
277
+ return b.depth - a.depth;
278
+ });
279
+ sortedParents.forEach(({ parent }) => {
316
280
  let medias = parent.nodes.filter(
317
281
  (node) => node.type === "atrule" && node.name === "media"
318
282
  );
package/dist/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import createSort from "sort-css-media-queries/create-sort";
2
- import { nanoid } from "nanoid";
3
2
 
4
3
  // PostCSS plugin to sort CSS @media rules according to a configurable order.
5
4
  // The plugin groups top-level and nested media at-rules, merges rules
@@ -46,37 +45,27 @@ function plugin(options = {}) {
46
45
  // Collect parent nodes that contain media at-rules. We separate
47
46
  // top-level (`root`) parents from nested parents so ordering
48
47
  // semantics can be preserved independently.
49
- let parents = [];
48
+ const parents = new Map();
50
49
 
51
50
  // Walk all @media at-rules and group their parents
52
51
  root.walkAtRules("media", (atRule) => {
53
- if (!atRule.parent.groupId) {
54
- let groupId = nanoid();
55
-
56
- atRule.parent.groupId = groupId;
57
-
58
- parents[groupId] = {
52
+ if (!parents.has(atRule.parent)) {
53
+ parents.set(atRule.parent, {
59
54
  parent: atRule.parent,
60
55
  depth: getDepth(atRule.parent),
61
- };
56
+ });
62
57
  }
63
-
64
- return;
65
58
  });
66
59
 
67
- if (!parents) {
60
+ if (parents.size === 0) {
68
61
  return;
69
62
  }
70
63
 
71
- parents = Object.fromEntries(
72
- Object.entries(parents).sort(([, a], [, b]) => {
73
- return b.depth - a.depth;
74
- }),
75
- );
76
-
77
- Object.keys(parents).forEach((groupId) => {
78
- let { parent } = parents[groupId];
64
+ const sortedParents = [...parents.values()].sort((a, b) => {
65
+ return b.depth - a.depth;
66
+ });
79
67
 
68
+ sortedParents.forEach(({ parent }) => {
80
69
  // Filter only @media nodes from the parent's children
81
70
  let medias = parent.nodes.filter(
82
71
  (node) => node.type === "atrule" && node.name === "media",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "postcss-sort-media-queries",
3
3
  "description": "PostCSS plugin for sorting and combining CSS media queries with mobile first / **desktop first methodologies",
4
- "version": "6.5.0",
4
+ "version": "6.6.0",
5
5
  "engines": {
6
6
  "node": ">=20.0.0"
7
7
  },
@@ -68,7 +68,6 @@
68
68
  "vitest": "^4.1.2"
69
69
  },
70
70
  "peerDependencies": {
71
- "nanoid": "^5.1.6",
72
71
  "postcss": "^8.5.6"
73
72
  },
74
73
  "dependencies": {
package/src/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import createSort from "sort-css-media-queries/create-sort";
2
- import { nanoid } from "nanoid";
3
2
 
4
3
  // PostCSS plugin to sort CSS @media rules according to a configurable order.
5
4
  // The plugin groups top-level and nested media at-rules, merges rules
@@ -46,37 +45,27 @@ function plugin(options = {}) {
46
45
  // Collect parent nodes that contain media at-rules. We separate
47
46
  // top-level (`root`) parents from nested parents so ordering
48
47
  // semantics can be preserved independently.
49
- let parents = [];
48
+ const parents = new Map();
50
49
 
51
50
  // Walk all @media at-rules and group their parents
52
51
  root.walkAtRules("media", (atRule) => {
53
- if (!atRule.parent.groupId) {
54
- let groupId = nanoid();
55
-
56
- atRule.parent.groupId = groupId;
57
-
58
- parents[groupId] = {
52
+ if (!parents.has(atRule.parent)) {
53
+ parents.set(atRule.parent, {
59
54
  parent: atRule.parent,
60
55
  depth: getDepth(atRule.parent),
61
- };
56
+ });
62
57
  }
63
-
64
- return;
65
58
  });
66
59
 
67
- if (!parents) {
60
+ if (parents.size === 0) {
68
61
  return;
69
62
  }
70
63
 
71
- parents = Object.fromEntries(
72
- Object.entries(parents).sort(([, a], [, b]) => {
73
- return b.depth - a.depth;
74
- }),
75
- );
76
-
77
- Object.keys(parents).forEach((groupId) => {
78
- let { parent } = parents[groupId];
64
+ const sortedParents = [...parents.values()].sort((a, b) => {
65
+ return b.depth - a.depth;
66
+ });
79
67
 
68
+ sortedParents.forEach(({ parent }) => {
80
69
  // Filter only @media nodes from the parent's children
81
70
  let medias = parent.nodes.filter(
82
71
  (node) => node.type === "atrule" && node.name === "media",