postcss-focus-within 5.0.0 → 5.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/dist/index.cjs +38 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.mjs +36 -0
- package/package.json +29 -8
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const selectorRegExp = /(?<!\\):focus-within([^\w-]|$)/gi;
|
|
4
|
+
|
|
5
|
+
const plugin = opts => {
|
|
6
|
+
const replaceWith = String(Object(opts).replaceWith || '[focus-within]');
|
|
7
|
+
const preserve = Boolean('preserve' in Object(opts) ? opts.preserve : true);
|
|
8
|
+
return {
|
|
9
|
+
postcssPlugin: 'postcss-focus-within',
|
|
10
|
+
Rule: rule => {
|
|
11
|
+
var _rule$prev;
|
|
12
|
+
|
|
13
|
+
if (!selectorRegExp.test(rule.selector)) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const selector = rule.selector.replace(selectorRegExp, ($0, $1) => `${replaceWith}${$1}`); // Check is the rule is processed yet
|
|
18
|
+
|
|
19
|
+
if (preserve && ((_rule$prev = rule.prev()) === null || _rule$prev === void 0 ? void 0 : _rule$prev.selector) === selector) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const clone = rule.clone({
|
|
24
|
+
selector
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
if (preserve) {
|
|
28
|
+
rule.before(clone);
|
|
29
|
+
} else {
|
|
30
|
+
rule.replaceWith(clone);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
plugin.postcss = true;
|
|
37
|
+
|
|
38
|
+
module.exports = plugin;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type PluginOptions = {
|
|
2
|
+
/** Defines whether the original selector should remain. */
|
|
3
|
+
preserve?: boolean
|
|
4
|
+
/** Defines the selector to replace `:focus-within`. */
|
|
5
|
+
replaceWith?: string
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export type Plugin = {
|
|
9
|
+
(pluginOptions?: PluginOptions): {
|
|
10
|
+
postcssPlugin: 'postcss-focus-within'
|
|
11
|
+
}
|
|
12
|
+
postcss: true
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
declare const plugin: Plugin
|
|
16
|
+
|
|
17
|
+
export default plugin
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const selectorRegExp = /(?<!\\):focus-within([^\w-]|$)/gi;
|
|
2
|
+
|
|
3
|
+
const plugin = opts => {
|
|
4
|
+
const replaceWith = String(Object(opts).replaceWith || '[focus-within]');
|
|
5
|
+
const preserve = Boolean('preserve' in Object(opts) ? opts.preserve : true);
|
|
6
|
+
return {
|
|
7
|
+
postcssPlugin: 'postcss-focus-within',
|
|
8
|
+
Rule: rule => {
|
|
9
|
+
var _rule$prev;
|
|
10
|
+
|
|
11
|
+
if (!selectorRegExp.test(rule.selector)) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const selector = rule.selector.replace(selectorRegExp, ($0, $1) => `${replaceWith}${$1}`); // Check is the rule is processed yet
|
|
16
|
+
|
|
17
|
+
if (preserve && ((_rule$prev = rule.prev()) === null || _rule$prev === void 0 ? void 0 : _rule$prev.selector) === selector) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const clone = rule.clone({
|
|
22
|
+
selector
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
if (preserve) {
|
|
26
|
+
rule.before(clone);
|
|
27
|
+
} else {
|
|
28
|
+
rule.replaceWith(clone);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
plugin.postcss = true;
|
|
35
|
+
|
|
36
|
+
export { plugin as default };
|
package/package.json
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postcss-focus-within",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.1",
|
|
4
4
|
"description": "Use the :focus-within pseudo-selector in CSS",
|
|
5
5
|
"author": "Jonathan Neal <jonathantneal@hotmail.com>",
|
|
6
6
|
"license": "CC0-1.0",
|
|
7
7
|
"repository": "csstools/postcss-focus-within",
|
|
8
8
|
"homepage": "https://github.com/csstools/postcss-focus-within#readme",
|
|
9
9
|
"bugs": "https://github.com/csstools/postcss-focus-within/issues",
|
|
10
|
-
"main": "dist/index.cjs
|
|
11
|
-
"module": "dist/index.
|
|
10
|
+
"main": "dist/index.cjs",
|
|
11
|
+
"module": "dist/index.mjs",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"import": "./dist/index.mjs",
|
|
16
|
+
"require": "./dist/index.cjs",
|
|
17
|
+
"types": "./dist/index.d.ts"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
12
20
|
"files": [
|
|
13
21
|
"dist"
|
|
14
22
|
],
|
|
@@ -17,6 +25,7 @@
|
|
|
17
25
|
"build:watch": "npx rollup -c .rollup.js --watch",
|
|
18
26
|
"lint": "npx eslint --cache src",
|
|
19
27
|
"lint:fix": "npx eslint --cache --fix",
|
|
28
|
+
"prepublishOnly": "npm test",
|
|
20
29
|
"pretest": "npm install && npm run build",
|
|
21
30
|
"test": "npm run lint && npm run tape",
|
|
22
31
|
"tape": "npx postcss-tape"
|
|
@@ -34,8 +43,9 @@
|
|
|
34
43
|
"postcss": "8.3.6",
|
|
35
44
|
"postcss-tape": "6.0.1",
|
|
36
45
|
"pre-commit": "1.2.2",
|
|
37
|
-
"rollup": "2.
|
|
38
|
-
"rollup-plugin-babel": "4.4.0"
|
|
46
|
+
"rollup": "2.57.0",
|
|
47
|
+
"rollup-plugin-babel": "4.4.0",
|
|
48
|
+
"rollup-plugin-copy": "^3.4.0"
|
|
39
49
|
},
|
|
40
50
|
"babel": {
|
|
41
51
|
"presets": [
|
|
@@ -61,16 +71,27 @@
|
|
|
61
71
|
"rollup": {
|
|
62
72
|
"input": "src/index.js",
|
|
63
73
|
"plugins": [
|
|
64
|
-
"rollup-plugin-babel"
|
|
74
|
+
"rollup-plugin-babel",
|
|
75
|
+
[
|
|
76
|
+
"rollup-plugin-copy",
|
|
77
|
+
{
|
|
78
|
+
"targets": [
|
|
79
|
+
{
|
|
80
|
+
"src": "./src/index.d.ts",
|
|
81
|
+
"dest": "./dist"
|
|
82
|
+
}
|
|
83
|
+
]
|
|
84
|
+
}
|
|
85
|
+
]
|
|
65
86
|
],
|
|
66
87
|
"output": [
|
|
67
88
|
{
|
|
68
89
|
"exports": "default",
|
|
69
|
-
"file": "dist/index.cjs
|
|
90
|
+
"file": "dist/index.cjs",
|
|
70
91
|
"format": "cjs"
|
|
71
92
|
},
|
|
72
93
|
{
|
|
73
|
-
"file": "dist/index.
|
|
94
|
+
"file": "dist/index.mjs",
|
|
74
95
|
"format": "esm"
|
|
75
96
|
}
|
|
76
97
|
]
|