postcss-custom-supports 0.1.3 → 0.1.4
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/index.js +38 -29
- package/package.json +4 -1
package/index.js
CHANGED
|
@@ -17,37 +17,46 @@ const creator = (opts = {}) => {
|
|
|
17
17
|
|
|
18
18
|
return {
|
|
19
19
|
postcssPlugin: 'postcss-custom-supports',
|
|
20
|
-
|
|
20
|
+
// prepare() gives us per-process state isolation: a fresh Map per file.
|
|
21
|
+
// Collection runs as a typed AtRule visitor (joins the main walk for free),
|
|
22
|
+
// and replacement defers to OnceExit so all definitions — including ones
|
|
23
|
+
// declared after their first reference — are resolved before rewriting.
|
|
24
|
+
prepare() {
|
|
21
25
|
const customs = new Map();
|
|
22
26
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
27
|
+
return {
|
|
28
|
+
AtRule: {
|
|
29
|
+
'custom-supports': (rule, { result }) => {
|
|
30
|
+
const match = rule.params.match(DEFINITION_RE);
|
|
31
|
+
if (!match) {
|
|
32
|
+
rule.warn(result, `Invalid @custom-supports declaration: "${rule.params}"`);
|
|
33
|
+
if (!preserve) rule.remove();
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const [, name, condition] = match;
|
|
38
|
+
if (customs.has(name)) {
|
|
39
|
+
rule.warn(result, `@custom-supports ${name} is redefined; the last definition wins`);
|
|
40
|
+
}
|
|
41
|
+
customs.set(name, condition.trim());
|
|
42
|
+
|
|
43
|
+
if (!preserve) rule.remove();
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
OnceExit(root, { result }) {
|
|
47
|
+
root.walkAtRules('supports', rule => {
|
|
48
|
+
rule.params = rule.params.replace(REFERENCE_RE, token => {
|
|
49
|
+
const name = token.slice(1, -1);
|
|
50
|
+
const value = customs.get(name);
|
|
51
|
+
if (value === undefined) {
|
|
52
|
+
rule.warn(result, `Unknown @custom-supports reference: ${name}`);
|
|
53
|
+
return token;
|
|
54
|
+
}
|
|
55
|
+
return `(${value})`;
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
},
|
|
59
|
+
};
|
|
51
60
|
},
|
|
52
61
|
};
|
|
53
62
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postcss-custom-supports",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "PostCSS plugin that mirrors @custom-media for @supports queries, letting you alias verbose or experimental feature-detection conditions behind a custom name.",
|
|
5
5
|
"author": "Chloe Burroughs <chloe@pfr.wtf>",
|
|
6
6
|
"repository": {
|
|
@@ -29,6 +29,9 @@
|
|
|
29
29
|
"peerDependencies": {
|
|
30
30
|
"postcss": "^8.4.0"
|
|
31
31
|
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"postcss": "^8.4.0"
|
|
34
|
+
},
|
|
32
35
|
"engines": {
|
|
33
36
|
"node": ">=18.0.0"
|
|
34
37
|
},
|