postcss-nested 7.0.2 → 8.0.1
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/LICENSE +1 -1
- package/README.md +5 -7
- package/index.d.ts +3 -3
- package/index.js +68 -63
- package/package.json +15 -10
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
|
-
Copyright 2014 Andrey Sitnik <andrey@sitnik.
|
|
3
|
+
Copyright 2014 Andrey Sitnik <andrey@sitnik.es>
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
6
|
this software and associated documentation files (the "Software"), to deal in
|
package/README.md
CHANGED
|
@@ -69,10 +69,11 @@ Alternatives:
|
|
|
69
69
|
- See also [`postcss-nesting`], which implements [CSSWG draft].
|
|
70
70
|
- [`postcss-nested-props`] for nested properties like `font-size`.
|
|
71
71
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
<img src="https://cdn.evilmartians.com/badges/logo-no-label.svg" alt="" width="22" height="16" /> PostCSS Nested is built by <b><a href="https://evilmartians.com/">Evil Martians</a></b>, an American design and engineering consultancy for <b>developer tools, AI, and cybersecurity startups</b>.
|
|
75
|
+
|
|
76
|
+
---
|
|
76
77
|
|
|
77
78
|
[`postcss-current-selector`]: https://github.com/komlev/postcss-current-selector
|
|
78
79
|
[`postcss-nested-ancestors`]: https://github.com/toomuchdesign/postcss-nested-ancestors
|
|
@@ -80,6 +81,3 @@ Alternatives:
|
|
|
80
81
|
[`postcss-nesting`]: https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-nesting
|
|
81
82
|
[CSSWG draft]: https://drafts.csswg.org/css-nesting-1/
|
|
82
83
|
[PostCSS]: https://github.com/postcss/postcss
|
|
83
|
-
|
|
84
|
-
## Docs
|
|
85
|
-
Read full docs **[here](https://github.com/postcss/postcss-nested#readme)**.
|
package/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Original definitions (@types/postcss-nested)
|
|
2
2
|
// by Maxim Vorontsov <https://github.com/VorontsovMaxim>
|
|
3
3
|
|
|
4
|
-
import { PluginCreator } from 'postcss'
|
|
4
|
+
import type { PluginCreator } from 'postcss'
|
|
5
5
|
|
|
6
6
|
declare namespace nested {
|
|
7
7
|
interface Options {
|
|
@@ -36,6 +36,6 @@ declare namespace nested {
|
|
|
36
36
|
type Nested = PluginCreator<Options>
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
declare
|
|
39
|
+
declare let nested: nested.Nested
|
|
40
40
|
|
|
41
|
-
export
|
|
41
|
+
export default nested
|
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { AtRule, Rule } from 'postcss'
|
|
2
|
+
import parser from 'postcss-selector-parser'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Run a selector string through postcss-selector-parser
|
|
@@ -91,8 +91,7 @@ function breakOut(child, currentNode) {
|
|
|
91
91
|
|
|
92
92
|
if (child.parent.toString().match(regexp)) {
|
|
93
93
|
currentNode.after(child).after(prevNode)
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
94
|
+
} else {
|
|
96
95
|
currentNode.after(child)
|
|
97
96
|
}
|
|
98
97
|
|
|
@@ -110,7 +109,7 @@ function createFnAtruleChilds(bubble) {
|
|
|
110
109
|
} else if (child.type === 'atrule' && child.nodes) {
|
|
111
110
|
if (bubble[child.name]) {
|
|
112
111
|
atruleChilds(rule, child, mergeSels)
|
|
113
|
-
} else if (atrule[
|
|
112
|
+
} else if (atrule[ROOT_RULE_MERGE_SEL] !== false) {
|
|
114
113
|
children.push(child)
|
|
115
114
|
}
|
|
116
115
|
} else {
|
|
@@ -136,15 +135,15 @@ function pickDeclarations(selector, declarations, after) {
|
|
|
136
135
|
after.after(parent)
|
|
137
136
|
return parent
|
|
138
137
|
}
|
|
139
|
-
function pickAndClearDeclarations(
|
|
138
|
+
function pickAndClearDeclarations(
|
|
139
|
+
ruleSelector,
|
|
140
|
+
declarations,
|
|
141
|
+
after,
|
|
142
|
+
clear = true
|
|
143
|
+
) {
|
|
140
144
|
if (!declarations.length) return [after, declarations]
|
|
141
|
-
|
|
142
145
|
after = pickDeclarations(ruleSelector, declarations, after)
|
|
143
|
-
|
|
144
|
-
if (clear) {
|
|
145
|
-
declarations = []
|
|
146
|
-
}
|
|
147
|
-
|
|
146
|
+
if (clear) declarations = []
|
|
148
147
|
return [after, declarations]
|
|
149
148
|
}
|
|
150
149
|
|
|
@@ -203,7 +202,7 @@ function getAncestorRules(leaf) {
|
|
|
203
202
|
}
|
|
204
203
|
|
|
205
204
|
function unwrapRootRule(rule) {
|
|
206
|
-
let escapes = rule[
|
|
205
|
+
let escapes = rule[ROOT_RULE_ESCAPES]
|
|
207
206
|
|
|
208
207
|
if (!escapes) {
|
|
209
208
|
rule.after(rule.nodes)
|
|
@@ -225,7 +224,7 @@ function unwrapRootRule(rule) {
|
|
|
225
224
|
} else {
|
|
226
225
|
let oldClone = clone
|
|
227
226
|
clone = parent.clone({ nodes: [] })
|
|
228
|
-
oldClone
|
|
227
|
+
if (oldClone) clone.append(oldClone)
|
|
229
228
|
breakoutLeaf = breakoutLeaf || clone
|
|
230
229
|
}
|
|
231
230
|
})
|
|
@@ -245,26 +244,29 @@ function unwrapRootRule(rule) {
|
|
|
245
244
|
lineage.slice(0, topEscapedIdx + 1).forEach((parent, i, arr) => {
|
|
246
245
|
let oldRoot = restRoot
|
|
247
246
|
restRoot = parent.clone({ nodes: [] })
|
|
248
|
-
oldRoot
|
|
247
|
+
if (oldRoot) restRoot.append(oldRoot)
|
|
249
248
|
|
|
250
249
|
let nextSibs = []
|
|
251
|
-
let
|
|
252
|
-
let next =
|
|
250
|
+
let child = arr[i - 1] || rule
|
|
251
|
+
let next = child.next()
|
|
253
252
|
while (next) {
|
|
254
253
|
nextSibs.push(next)
|
|
255
254
|
next = next.next()
|
|
256
255
|
}
|
|
257
256
|
restRoot.append(nextSibs)
|
|
258
257
|
})
|
|
259
|
-
|
|
258
|
+
if (restRoot) {
|
|
259
|
+
let insert = breakoutRoot || nodes[nodes.length - 1]
|
|
260
|
+
insert.after(restRoot)
|
|
261
|
+
}
|
|
260
262
|
}
|
|
261
263
|
}
|
|
262
264
|
|
|
263
265
|
rule.remove()
|
|
264
266
|
}
|
|
265
267
|
|
|
266
|
-
const
|
|
267
|
-
const
|
|
268
|
+
const ROOT_RULE_MERGE_SEL = Symbol('rootRuleMergeSel')
|
|
269
|
+
const ROOT_RULE_ESCAPES = Symbol('rootRuleEscapes')
|
|
268
270
|
|
|
269
271
|
function normalizeRootRule(rule) {
|
|
270
272
|
let { params } = rule
|
|
@@ -279,13 +281,13 @@ function normalizeRootRule(rule) {
|
|
|
279
281
|
rule.removeAll()
|
|
280
282
|
rule.append(selectorBlock)
|
|
281
283
|
}
|
|
282
|
-
rule[
|
|
283
|
-
rule[
|
|
284
|
+
rule[ROOT_RULE_ESCAPES] = escapes
|
|
285
|
+
rule[ROOT_RULE_MERGE_SEL] = escapes ? !escapes('all') : type === 'noop'
|
|
284
286
|
}
|
|
285
287
|
|
|
286
|
-
const
|
|
288
|
+
const HAS_ROOT_RULE = Symbol('hasRootRule')
|
|
287
289
|
|
|
288
|
-
|
|
290
|
+
let nested = (opts = {}) => {
|
|
289
291
|
let bubble = atruleNames(
|
|
290
292
|
['media', 'supports', 'layer', 'container', 'starting-style'],
|
|
291
293
|
opts.bubble
|
|
@@ -308,17 +310,17 @@ module.exports = (opts = {}) => {
|
|
|
308
310
|
Once(root) {
|
|
309
311
|
root.walkAtRules(rootRuleName, node => {
|
|
310
312
|
normalizeRootRule(node)
|
|
311
|
-
root[
|
|
313
|
+
root[HAS_ROOT_RULE] = true
|
|
312
314
|
})
|
|
313
315
|
},
|
|
314
316
|
|
|
315
317
|
postcssPlugin: 'postcss-nested',
|
|
316
318
|
|
|
317
319
|
RootExit(root) {
|
|
318
|
-
if (!root[
|
|
320
|
+
if (!root[HAS_ROOT_RULE]) return
|
|
319
321
|
|
|
320
322
|
root.walkAtRules(rootRuleName, unwrapRootRule)
|
|
321
|
-
root[
|
|
323
|
+
root[HAS_ROOT_RULE] = false
|
|
322
324
|
},
|
|
323
325
|
|
|
324
326
|
Rule(rule) {
|
|
@@ -328,44 +330,45 @@ module.exports = (opts = {}) => {
|
|
|
328
330
|
let declarations = []
|
|
329
331
|
|
|
330
332
|
rule.each(child => {
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
after = breakOut(child, after)
|
|
344
|
-
} else if (unwrap[child.name]) {
|
|
345
|
-
copyDeclarations = true
|
|
346
|
-
unwrapped = true
|
|
347
|
-
atruleChilds(rule, child, false)
|
|
348
|
-
after = breakOut(child, after)
|
|
349
|
-
} else if (copyDeclarations) {
|
|
350
|
-
declarations.push(child)
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
break
|
|
354
|
-
case 'decl':
|
|
355
|
-
if (copyDeclarations) {
|
|
356
|
-
declarations.push(child)
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
break
|
|
360
|
-
case 'rule':
|
|
361
|
-
[after, declarations] = pickAndClearDeclarations(rule.selector, declarations, after)
|
|
362
|
-
|
|
333
|
+
if (child.type === 'atrule') {
|
|
334
|
+
;[after, declarations] = pickAndClearDeclarations(
|
|
335
|
+
rule.selector,
|
|
336
|
+
declarations,
|
|
337
|
+
after
|
|
338
|
+
)
|
|
339
|
+
|
|
340
|
+
if (child.name === rootRuleName) {
|
|
341
|
+
unwrapped = true
|
|
342
|
+
atruleChilds(rule, child, true, child[ROOT_RULE_MERGE_SEL])
|
|
343
|
+
after = breakOut(child, after)
|
|
344
|
+
} else if (bubble[child.name]) {
|
|
363
345
|
copyDeclarations = true
|
|
364
346
|
unwrapped = true
|
|
365
|
-
|
|
347
|
+
atruleChilds(rule, child, true)
|
|
366
348
|
after = breakOut(child, after)
|
|
367
|
-
|
|
368
|
-
|
|
349
|
+
} else if (unwrap[child.name]) {
|
|
350
|
+
copyDeclarations = true
|
|
351
|
+
unwrapped = true
|
|
352
|
+
atruleChilds(rule, child, false)
|
|
353
|
+
after = breakOut(child, after)
|
|
354
|
+
} else if (copyDeclarations) {
|
|
355
|
+
declarations.push(child)
|
|
356
|
+
}
|
|
357
|
+
} else if (child.type === 'decl') {
|
|
358
|
+
if (copyDeclarations) {
|
|
359
|
+
declarations.push(child)
|
|
360
|
+
}
|
|
361
|
+
} else if (child.type === 'rule') {
|
|
362
|
+
;[after, declarations] = pickAndClearDeclarations(
|
|
363
|
+
rule.selector,
|
|
364
|
+
declarations,
|
|
365
|
+
after
|
|
366
|
+
)
|
|
367
|
+
|
|
368
|
+
copyDeclarations = true
|
|
369
|
+
unwrapped = true
|
|
370
|
+
child.selectors = mergeSelectors(rule, child)
|
|
371
|
+
after = breakOut(child, after)
|
|
369
372
|
}
|
|
370
373
|
})
|
|
371
374
|
|
|
@@ -378,4 +381,6 @@ module.exports = (opts = {}) => {
|
|
|
378
381
|
}
|
|
379
382
|
}
|
|
380
383
|
}
|
|
381
|
-
|
|
384
|
+
nested.postcss = true
|
|
385
|
+
|
|
386
|
+
export default nested
|
package/package.json
CHANGED
|
@@ -1,20 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postcss-nested",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.1",
|
|
4
4
|
"description": "PostCSS plugin to unwrap nested rules like how Sass does it",
|
|
5
5
|
"keywords": [
|
|
6
|
-
"postcss",
|
|
7
6
|
"css",
|
|
7
|
+
"nested",
|
|
8
|
+
"postcss",
|
|
8
9
|
"postcss-plugin",
|
|
9
|
-
"sass"
|
|
10
|
-
"nested"
|
|
10
|
+
"sass"
|
|
11
11
|
],
|
|
12
|
-
"author": "Andrey Sitnik <andrey@sitnik.ru>",
|
|
13
12
|
"license": "MIT",
|
|
13
|
+
"author": "Andrey Sitnik <andrey@sitnik.es>",
|
|
14
14
|
"repository": "postcss/postcss-nested",
|
|
15
|
-
"engines": {
|
|
16
|
-
"node": ">=18.0"
|
|
17
|
-
},
|
|
18
15
|
"funding": [
|
|
19
16
|
{
|
|
20
17
|
"type": "opencollective",
|
|
@@ -25,10 +22,18 @@
|
|
|
25
22
|
"url": "https://github.com/sponsors/ai"
|
|
26
23
|
}
|
|
27
24
|
],
|
|
25
|
+
"type": "module",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": "./index.js",
|
|
28
|
+
"./package.json": "./package.json"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"postcss-selector-parser": "^7.1.4"
|
|
32
|
+
},
|
|
28
33
|
"peerDependencies": {
|
|
29
34
|
"postcss": "^8.2.14"
|
|
30
35
|
},
|
|
31
|
-
"
|
|
32
|
-
"
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": "^22.0.0 || ^24.0.0 || >= 26.0.0"
|
|
33
38
|
}
|
|
34
39
|
}
|