postcss-focus-within 8.0.0 → 9.0.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 +4 -105
- package/README.md +2 -11
- package/dist/browser-global.js.map +1 -1
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.mjs.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +7 -3
- package/dist/index.mjs +1 -1
- package/package.json +14 -31
package/CHANGELOG.md
CHANGED
|
@@ -1,110 +1,9 @@
|
|
|
1
1
|
# Changes to PostCSS Focus Within
|
|
2
2
|
|
|
3
|
-
###
|
|
3
|
+
### 9.0.0
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
_August 3, 2024_
|
|
6
6
|
|
|
7
|
-
-
|
|
7
|
+
- Updated: Support for Node v18+ (major).
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
_February 8, 2023_
|
|
12
|
-
|
|
13
|
-
- Reduce the amount of duplicate fallback CSS.
|
|
14
|
-
|
|
15
|
-
### 7.0.1
|
|
16
|
-
|
|
17
|
-
_January 28, 2023_
|
|
18
|
-
|
|
19
|
-
- Improve `types` declaration in `package.json`
|
|
20
|
-
|
|
21
|
-
### 7.0.0
|
|
22
|
-
|
|
23
|
-
_January 24, 2023_
|
|
24
|
-
|
|
25
|
-
- Updated: Support for Node v14+ (major).
|
|
26
|
-
- Fix: Do not throw when a selector is invalid, show a warning instead.
|
|
27
|
-
|
|
28
|
-
### 6.1.1
|
|
29
|
-
|
|
30
|
-
_August 23, 2022_
|
|
31
|
-
|
|
32
|
-
- Fix: assign global browser polyfill to `window`, `self` or a blank object.
|
|
33
|
-
|
|
34
|
-
### 6.1.0
|
|
35
|
-
|
|
36
|
-
_July 30, 2022_
|
|
37
|
-
|
|
38
|
-
- Added: `disablePolyfillReadyClass` plugin option to prevent `.js-focus-within` from being added.
|
|
39
|
-
|
|
40
|
-
### 6.0.0
|
|
41
|
-
|
|
42
|
-
_July 8, 2022_
|
|
43
|
-
|
|
44
|
-
- Breaking: Changed generated classes so it prepends `.js-focus-within` to the
|
|
45
|
-
generated class so CSS is applied when the polyfill is known to be running.
|
|
46
|
-
- Added: Now bundling browser polyfill.
|
|
47
|
-
|
|
48
|
-
### 5.0.4
|
|
49
|
-
|
|
50
|
-
_February 5, 2022_
|
|
51
|
-
|
|
52
|
-
- Improved `es module` and `commonjs` compatibility
|
|
53
|
-
|
|
54
|
-
### 5.0.3
|
|
55
|
-
|
|
56
|
-
_January 2, 2022_
|
|
57
|
-
|
|
58
|
-
- Removed Sourcemaps from package tarball.
|
|
59
|
-
- Moved CLI to CLI Package. See [announcement](https://github.com/csstools/postcss-plugins/discussions/121).
|
|
60
|
-
|
|
61
|
-
### 5.0.2
|
|
62
|
-
|
|
63
|
-
_December 13, 2021_
|
|
64
|
-
|
|
65
|
-
- Changed: now uses `postcss-selector-parser` for parsing.
|
|
66
|
-
- Updated: documentation
|
|
67
|
-
|
|
68
|
-
### 5.0.1
|
|
69
|
-
|
|
70
|
-
_September 22, 2021_
|
|
71
|
-
|
|
72
|
-
- Added missing `dist` to bundle.
|
|
73
|
-
- Added missing `exports` to `package.json`
|
|
74
|
-
- Added missing `types` to `package.json`
|
|
75
|
-
- Added bundling & testing as prepublish step.
|
|
76
|
-
|
|
77
|
-
### 5.0.0
|
|
78
|
-
|
|
79
|
-
_September 17, 2021_
|
|
80
|
-
|
|
81
|
-
- Updated: Support for PostCS 8+ (major).
|
|
82
|
-
- Updated: Support for Node 12+ (major).
|
|
83
|
-
|
|
84
|
-
### 4.0.0
|
|
85
|
-
|
|
86
|
-
_April 20, 2020_
|
|
87
|
-
|
|
88
|
-
- Fixed: Allow `:focus-within` to appear escaped in a selector
|
|
89
|
-
- Updated: Support for Node 10+
|
|
90
|
-
- Updated: Ownership moved to CSS Tools
|
|
91
|
-
|
|
92
|
-
### 3.0.0
|
|
93
|
-
|
|
94
|
-
_September 17, 2018_
|
|
95
|
-
|
|
96
|
-
- Updated: Support for PostCSS v7+
|
|
97
|
-
- Updated: Support for Node v6+
|
|
98
|
-
|
|
99
|
-
### 2.0.0
|
|
100
|
-
|
|
101
|
-
_April 7, 2018_
|
|
102
|
-
|
|
103
|
-
- Changed: default functionality to preserve the original rule
|
|
104
|
-
- Added: `preserve` option to preserve the original rule using `:focus-within`
|
|
105
|
-
|
|
106
|
-
### 1.0.0
|
|
107
|
-
|
|
108
|
-
_February 17, 2018_
|
|
109
|
-
|
|
110
|
-
- Initial version
|
|
9
|
+
[Full CHANGELOG](https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-focus-within/CHANGELOG.md)
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# PostCSS Focus Within [<img src="https://postcss.github.io/postcss/logo.svg" alt="PostCSS Logo" width="90" height="90" align="right">][PostCSS]
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`npm install postcss-focus-within --save-dev`
|
|
4
4
|
|
|
5
5
|
[PostCSS Focus Within] lets you use the `:focus-within` pseudo-class in CSS,
|
|
6
6
|
following the [Selectors Level 4 specification].
|
|
@@ -49,16 +49,7 @@ postcss([
|
|
|
49
49
|
]).process(YOUR_CSS /*, processOptions */);
|
|
50
50
|
```
|
|
51
51
|
|
|
52
|
-
[PostCSS Focus Within] runs in all Node environments, with special
|
|
53
|
-
instructions for:
|
|
54
52
|
|
|
55
|
-
- [Node](INSTALL.md#node)
|
|
56
|
-
- [PostCSS CLI](INSTALL.md#postcss-cli)
|
|
57
|
-
- [PostCSS Load Config](INSTALL.md#postcss-load-config)
|
|
58
|
-
- [Webpack](INSTALL.md#webpack)
|
|
59
|
-
- [Next.js](INSTALL.md#nextjs)
|
|
60
|
-
- [Gulp](INSTALL.md#gulp)
|
|
61
|
-
- [Grunt](INSTALL.md#grunt)
|
|
62
53
|
|
|
63
54
|
## Options
|
|
64
55
|
|
|
@@ -152,7 +143,7 @@ or
|
|
|
152
143
|
|
|
153
144
|
```html
|
|
154
145
|
<!-- When using a CDN url you will have to manually update the version number -->
|
|
155
|
-
<script src="https://unpkg.com/postcss-focus-within@
|
|
146
|
+
<script src="https://unpkg.com/postcss-focus-within@9.0.0/dist/browser-global.js"></script>
|
|
156
147
|
<script>focusWithinInit()</script>
|
|
157
148
|
```
|
|
158
149
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser-global.js","sources":["../src/is-valid-replacement.mjs","../src/browser.js","../src/browser-global.js"],"sourcesContent":["const INVALID_SELECTOR_CHAR = [\n\t' ', // Can't use child selector\n\t'>', // Can't use direct child selector\n\t'~', // Can't use sibling selector\n\t':', // Can't use pseudo selector\n\t'+', // Can't use adjacent selector\n\t'@', // Can't use at\n\t'#', // Can't use id selector\n\t'(', // Can't use parenthesis\n\t')', // Can't use parenthesis\n];\n\nexport default function isValidReplacement(selector) {\n\tlet isValid = true;\n\n\t// Purposely archaic so it's interoperable in old browsers\n\tfor (let i = 0, length = INVALID_SELECTOR_CHAR.length; i < length && isValid; i++) {\n\t\tif (selector.indexOf(INVALID_SELECTOR_CHAR[i]) > -1) {\n\t\t\tisValid = false;\n\t\t}\n\t}\n\n\treturn isValid;\n}\n","
|
|
1
|
+
{"version":3,"file":"browser-global.js","sources":["../src/is-valid-replacement.mjs","../src/browser.js","../src/browser-global.js"],"sourcesContent":["const INVALID_SELECTOR_CHAR = [\n\t' ', // Can't use child selector\n\t'>', // Can't use direct child selector\n\t'~', // Can't use sibling selector\n\t':', // Can't use pseudo selector\n\t'+', // Can't use adjacent selector\n\t'@', // Can't use at\n\t'#', // Can't use id selector\n\t'(', // Can't use parenthesis\n\t')', // Can't use parenthesis\n];\n\nexport default function isValidReplacement(selector) {\n\tlet isValid = true;\n\n\t// Purposely archaic so it's interoperable in old browsers\n\tfor (let i = 0, length = INVALID_SELECTOR_CHAR.length; i < length && isValid; i++) {\n\t\tif (selector.indexOf(INVALID_SELECTOR_CHAR[i]) > -1) {\n\t\t\tisValid = false;\n\t\t}\n\t}\n\n\treturn isValid;\n}\n","import isValidReplacement from './is-valid-replacement.mjs';\nfunction generateHandler(replaceWith) {\n\tlet selector;\n\tlet remove;\n\tlet add;\n\tconst lastElements = [];\n\n\tif (replaceWith[0] === '.') {\n\t\tselector = replaceWith.slice(1);\n\t\tremove = (el) => el.classList.remove(selector);\n\t\tadd = (el) => el.classList.add(selector);\n\t} else {\n\t\t// A bit naive\n\t\tselector = replaceWith.slice(1, -1);\n\t\tremove = (el) => el.removeAttribute(selector, '');\n\t\tadd = (el) => el.setAttribute(selector, '');\n\t}\n\n\treturn function handleFocusChange() {\n\t\tlastElements.forEach(lastElement => remove(lastElement));\n\t\tlastElements.length = 0;\n\n\t\tlet activeElement = document.activeElement;\n\n\t\t// only add focus if it has not been added and is not the document element\n\t\tif (!/^(#document|HTML|BODY)$/.test(Object(activeElement).nodeName)) {\n\t\t\twhile (activeElement && activeElement.nodeType === 1) {\n\t\t\t\tadd(activeElement);\n\t\t\t\tlastElements.push(activeElement);\n\n\t\t\t\tactiveElement = activeElement.parentNode;\n\t\t\t}\n\t\t}\n\t};\n}\n\nexport default function focusWithin(opts) {\n\t// configuration\n\tconst options = {\n\t\tforce: false,\n\t\treplaceWith: '[focus-within]',\n\t};\n\n\tif (typeof opts !== 'undefined' && 'force' in opts) {\n\t\toptions.force = opts.force;\n\t}\n\n\tif (typeof opts !== 'undefined' && 'replaceWith' in opts) {\n\t\toptions.replaceWith = opts.replaceWith;\n\t}\n\n\tif (!isValidReplacement(options.replaceWith)) {\n\t\tthrow new Error(`${options.replaceWith} is not a valid replacement since it can't be applied to single elements.`);\n\t}\n\n\ttry {\n\t\tdocument.querySelector(':focus-within');\n\n\t\tif (!options.force) {\n\t\t\treturn;\n\t\t}\n\t} catch (_) {}\n\n\tconst handleFocusChange = generateHandler(options.replaceWith);\n\n\tconst initialize = function initializeEventListeners() {\n\t\tif (document.documentElement.className.indexOf('js-focus-within') > -1) {\n\t\t\treturn;\n\t\t}\n\n\t\tdocument.documentElement.className = document.documentElement.className + ' js-focus-within';\n\t\tdocument.addEventListener('focus', handleFocusChange, true);\n\t\tdocument.addEventListener('blur', handleFocusChange, true);\n\t};\n\n\tif (document.readyState === 'complete') {\n\t\tinitialize();\n\t} else {\n\t\tdocument.addEventListener('DOMContentLoaded', initialize);\n\t}\n}\n","import { default as focusWithinInit } from './browser';\n\n(function (global) {\n\tglobal.focusWithinInit = focusWithinInit;\n}('object' === typeof window && window || 'object' === typeof self && self || {}));\n"],"names":["INVALID_SELECTOR_CHAR","isValidReplacement","selector","isValid","i","length","indexOf","focusWithin","opts","options","force","replaceWith","Error","document","querySelector","_","remove","add","lastElements","handleFocusChange","slice","el","classList","removeAttribute","setAttribute","forEach","lastElement","activeElement","test","Object","nodeName","nodeType","push","parentNode","initialize","initializeEventListeners","documentElement","className","addEventListener","readyState","window","self","focusWithinInit"],"mappings":"YAAA,IAAMA,EAAwB,CAC7B,IACA,IACA,IACA,IACA,IACA,IACA,IACA,IACA,KAGc,SAASC,mBAAmBC,GAI1C,IAHA,IAAIC,GAAU,EAGLC,EAAI,EAAGC,EAASL,EAAsBK,OAAQD,EAAIC,GAAUF,EAASC,IACzEF,EAASI,QAAQN,EAAsBI,KAAO,IACjDD,GAAU,GAIZ,OAAOA,CACR,CCae,SAASI,YAAYC,GAEnC,IAAMC,EAAU,CACfC,OAAO,EACPC,YAAa,kBAWd,QARoB,IAATH,GAAwB,UAAWA,IAC7CC,EAAQC,MAAQF,EAAKE,YAGF,IAATF,GAAwB,gBAAiBA,IACnDC,EAAQE,YAAcH,EAAKG,cAGvBV,mBAAmBQ,EAAQE,aAC/B,MAAM,IAAIC,MAASH,EAAQE,yFAG5B,IAGC,GAFAE,SAASC,cAAc,kBAElBL,EAAQC,MACZ,MAEF,CAAE,MAAOK,GAAI,CAEb,IA9DwBJ,EACpBT,EACAc,EACAC,EACEC,EA0DAC,GA9DkBR,EA8DkBF,EAAQE,YA1D5CO,EAAe,GAEE,MAAnBP,EAAY,IACfT,EAAWS,EAAYS,MAAM,GAC7BJ,EAAS,SAATA,OAAUK,GAAE,OAAKA,EAAGC,UAAUN,OAAOd,EAAS,EAC9Ce,EAAM,SAANA,IAAOI,GAAE,OAAKA,EAAGC,UAAUL,IAAIf,EAAS,IAGxCA,EAAWS,EAAYS,MAAM,GAAI,GACjCJ,EAAS,SAATA,OAAUK,GAAE,OAAKA,EAAGE,gBAAgBrB,EAAU,GAAG,EACjDe,EAAM,SAANA,IAAOI,GAAE,OAAKA,EAAGG,aAAatB,EAAU,GAAG,GAGrC,SAASiB,oBACfD,EAAaO,SAAQ,SAAAC,GAAW,OAAIV,EAAOU,MAC3CR,EAAab,OAAS,EAEtB,IAAIsB,EAAgBd,SAASc,cAG7B,IAAK,0BAA0BC,KAAKC,OAAOF,GAAeG,UACzD,KAAOH,GAA4C,IAA3BA,EAAcI,UACrCd,EAAIU,GACJT,EAAac,KAAKL,GAElBA,EAAgBA,EAAcM,aAmC3BC,EAAa,SAASC,2BACvBtB,SAASuB,gBAAgBC,UAAU/B,QAAQ,oBAAsB,IAIrEO,SAASuB,gBAAgBC,UAAYxB,SAASuB,gBAAgBC,UAAY,mBAC1ExB,SAASyB,iBAAiB,QAASnB,GAAmB,GACtDN,SAASyB,iBAAiB,OAAQnB,GAAmB,KAG1B,aAAxBN,SAAS0B,WACZL,IAEArB,SAASyB,iBAAiB,mBAAoBJ,EAEhD,EC5EE,iBAAoBM,QAAUA,QAAU,iBAAoBC,MAAQA,MAAQ,IADtEC,gBAAkBA"}
|
package/dist/browser.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser.cjs","sources":["../src/is-valid-replacement.mjs","../src/browser.js"],"sourcesContent":["const INVALID_SELECTOR_CHAR = [\n\t' ', // Can't use child selector\n\t'>', // Can't use direct child selector\n\t'~', // Can't use sibling selector\n\t':', // Can't use pseudo selector\n\t'+', // Can't use adjacent selector\n\t'@', // Can't use at\n\t'#', // Can't use id selector\n\t'(', // Can't use parenthesis\n\t')', // Can't use parenthesis\n];\n\nexport default function isValidReplacement(selector) {\n\tlet isValid = true;\n\n\t// Purposely archaic so it's interoperable in old browsers\n\tfor (let i = 0, length = INVALID_SELECTOR_CHAR.length; i < length && isValid; i++) {\n\t\tif (selector.indexOf(INVALID_SELECTOR_CHAR[i]) > -1) {\n\t\t\tisValid = false;\n\t\t}\n\t}\n\n\treturn isValid;\n}\n","
|
|
1
|
+
{"version":3,"file":"browser.cjs","sources":["../src/is-valid-replacement.mjs","../src/browser.js"],"sourcesContent":["const INVALID_SELECTOR_CHAR = [\n\t' ', // Can't use child selector\n\t'>', // Can't use direct child selector\n\t'~', // Can't use sibling selector\n\t':', // Can't use pseudo selector\n\t'+', // Can't use adjacent selector\n\t'@', // Can't use at\n\t'#', // Can't use id selector\n\t'(', // Can't use parenthesis\n\t')', // Can't use parenthesis\n];\n\nexport default function isValidReplacement(selector) {\n\tlet isValid = true;\n\n\t// Purposely archaic so it's interoperable in old browsers\n\tfor (let i = 0, length = INVALID_SELECTOR_CHAR.length; i < length && isValid; i++) {\n\t\tif (selector.indexOf(INVALID_SELECTOR_CHAR[i]) > -1) {\n\t\t\tisValid = false;\n\t\t}\n\t}\n\n\treturn isValid;\n}\n","import isValidReplacement from './is-valid-replacement.mjs';\nfunction generateHandler(replaceWith) {\n\tlet selector;\n\tlet remove;\n\tlet add;\n\tconst lastElements = [];\n\n\tif (replaceWith[0] === '.') {\n\t\tselector = replaceWith.slice(1);\n\t\tremove = (el) => el.classList.remove(selector);\n\t\tadd = (el) => el.classList.add(selector);\n\t} else {\n\t\t// A bit naive\n\t\tselector = replaceWith.slice(1, -1);\n\t\tremove = (el) => el.removeAttribute(selector, '');\n\t\tadd = (el) => el.setAttribute(selector, '');\n\t}\n\n\treturn function handleFocusChange() {\n\t\tlastElements.forEach(lastElement => remove(lastElement));\n\t\tlastElements.length = 0;\n\n\t\tlet activeElement = document.activeElement;\n\n\t\t// only add focus if it has not been added and is not the document element\n\t\tif (!/^(#document|HTML|BODY)$/.test(Object(activeElement).nodeName)) {\n\t\t\twhile (activeElement && activeElement.nodeType === 1) {\n\t\t\t\tadd(activeElement);\n\t\t\t\tlastElements.push(activeElement);\n\n\t\t\t\tactiveElement = activeElement.parentNode;\n\t\t\t}\n\t\t}\n\t};\n}\n\nexport default function focusWithin(opts) {\n\t// configuration\n\tconst options = {\n\t\tforce: false,\n\t\treplaceWith: '[focus-within]',\n\t};\n\n\tif (typeof opts !== 'undefined' && 'force' in opts) {\n\t\toptions.force = opts.force;\n\t}\n\n\tif (typeof opts !== 'undefined' && 'replaceWith' in opts) {\n\t\toptions.replaceWith = opts.replaceWith;\n\t}\n\n\tif (!isValidReplacement(options.replaceWith)) {\n\t\tthrow new Error(`${options.replaceWith} is not a valid replacement since it can't be applied to single elements.`);\n\t}\n\n\ttry {\n\t\tdocument.querySelector(':focus-within');\n\n\t\tif (!options.force) {\n\t\t\treturn;\n\t\t}\n\t} catch (_) {}\n\n\tconst handleFocusChange = generateHandler(options.replaceWith);\n\n\tconst initialize = function initializeEventListeners() {\n\t\tif (document.documentElement.className.indexOf('js-focus-within') > -1) {\n\t\t\treturn;\n\t\t}\n\n\t\tdocument.documentElement.className = document.documentElement.className + ' js-focus-within';\n\t\tdocument.addEventListener('focus', handleFocusChange, true);\n\t\tdocument.addEventListener('blur', handleFocusChange, true);\n\t};\n\n\tif (document.readyState === 'complete') {\n\t\tinitialize();\n\t} else {\n\t\tdocument.addEventListener('DOMContentLoaded', initialize);\n\t}\n}\n"],"names":["INVALID_SELECTOR_CHAR","isValidReplacement","selector","isValid","i","length","indexOf","focusWithin","opts","options","force","replaceWith","Error","document","querySelector","_","remove","add","lastElements","handleFocusChange","slice","el","classList","removeAttribute","setAttribute","forEach","lastElement","activeElement","test","Object","nodeName","nodeType","push","parentNode","initialize","initializeEventListeners","documentElement","className","addEventListener","readyState"],"mappings":"AAAA,IAAMA,EAAwB,CAC7B,IACA,IACA,IACA,IACA,IACA,IACA,IACA,IACA,KAGc,SAASC,mBAAmBC,GAI1C,IAHA,IAAIC,GAAU,EAGLC,EAAI,EAAGC,EAASL,EAAsBK,OAAQD,EAAIC,GAAUF,EAASC,IACzEF,EAASI,QAAQN,EAAsBI,KAAO,IACjDD,GAAU,GAIZ,OAAOA,CACR,gBCae,SAASI,YAAYC,GAEnC,IAAMC,EAAU,CACfC,OAAO,EACPC,YAAa,kBAWd,QARoB,IAATH,GAAwB,UAAWA,IAC7CC,EAAQC,MAAQF,EAAKE,YAGF,IAATF,GAAwB,gBAAiBA,IACnDC,EAAQE,YAAcH,EAAKG,cAGvBV,mBAAmBQ,EAAQE,aAC/B,MAAM,IAAIC,MAASH,EAAQE,yFAG5B,IAGC,GAFAE,SAASC,cAAc,kBAElBL,EAAQC,MACZ,MAEF,CAAE,MAAOK,GAAI,CAEb,IA9DwBJ,EACpBT,EACAc,EACAC,EACEC,EA0DAC,GA9DkBR,EA8DkBF,EAAQE,YA1D5CO,EAAe,GAEE,MAAnBP,EAAY,IACfT,EAAWS,EAAYS,MAAM,GAC7BJ,EAAS,SAATA,OAAUK,GAAE,OAAKA,EAAGC,UAAUN,OAAOd,EAAS,EAC9Ce,EAAM,SAANA,IAAOI,GAAE,OAAKA,EAAGC,UAAUL,IAAIf,EAAS,IAGxCA,EAAWS,EAAYS,MAAM,GAAI,GACjCJ,EAAS,SAATA,OAAUK,GAAE,OAAKA,EAAGE,gBAAgBrB,EAAU,GAAG,EACjDe,EAAM,SAANA,IAAOI,GAAE,OAAKA,EAAGG,aAAatB,EAAU,GAAG,GAGrC,SAASiB,oBACfD,EAAaO,SAAQ,SAAAC,GAAW,OAAIV,EAAOU,MAC3CR,EAAab,OAAS,EAEtB,IAAIsB,EAAgBd,SAASc,cAG7B,IAAK,0BAA0BC,KAAKC,OAAOF,GAAeG,UACzD,KAAOH,GAA4C,IAA3BA,EAAcI,UACrCd,EAAIU,GACJT,EAAac,KAAKL,GAElBA,EAAgBA,EAAcM,aAmC3BC,EAAa,SAASC,2BACvBtB,SAASuB,gBAAgBC,UAAU/B,QAAQ,oBAAsB,IAIrEO,SAASuB,gBAAgBC,UAAYxB,SAASuB,gBAAgBC,UAAY,mBAC1ExB,SAASyB,iBAAiB,QAASnB,GAAmB,GACtDN,SAASyB,iBAAiB,OAAQnB,GAAmB,KAG1B,aAAxBN,SAAS0B,WACZL,IAEArB,SAASyB,iBAAiB,mBAAoBJ,EAEhD"}
|
package/dist/browser.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser.mjs","sources":["../src/is-valid-replacement.mjs","../src/browser.js"],"sourcesContent":["const INVALID_SELECTOR_CHAR = [\n\t' ', // Can't use child selector\n\t'>', // Can't use direct child selector\n\t'~', // Can't use sibling selector\n\t':', // Can't use pseudo selector\n\t'+', // Can't use adjacent selector\n\t'@', // Can't use at\n\t'#', // Can't use id selector\n\t'(', // Can't use parenthesis\n\t')', // Can't use parenthesis\n];\n\nexport default function isValidReplacement(selector) {\n\tlet isValid = true;\n\n\t// Purposely archaic so it's interoperable in old browsers\n\tfor (let i = 0, length = INVALID_SELECTOR_CHAR.length; i < length && isValid; i++) {\n\t\tif (selector.indexOf(INVALID_SELECTOR_CHAR[i]) > -1) {\n\t\t\tisValid = false;\n\t\t}\n\t}\n\n\treturn isValid;\n}\n","
|
|
1
|
+
{"version":3,"file":"browser.mjs","sources":["../src/is-valid-replacement.mjs","../src/browser.js"],"sourcesContent":["const INVALID_SELECTOR_CHAR = [\n\t' ', // Can't use child selector\n\t'>', // Can't use direct child selector\n\t'~', // Can't use sibling selector\n\t':', // Can't use pseudo selector\n\t'+', // Can't use adjacent selector\n\t'@', // Can't use at\n\t'#', // Can't use id selector\n\t'(', // Can't use parenthesis\n\t')', // Can't use parenthesis\n];\n\nexport default function isValidReplacement(selector) {\n\tlet isValid = true;\n\n\t// Purposely archaic so it's interoperable in old browsers\n\tfor (let i = 0, length = INVALID_SELECTOR_CHAR.length; i < length && isValid; i++) {\n\t\tif (selector.indexOf(INVALID_SELECTOR_CHAR[i]) > -1) {\n\t\t\tisValid = false;\n\t\t}\n\t}\n\n\treturn isValid;\n}\n","import isValidReplacement from './is-valid-replacement.mjs';\nfunction generateHandler(replaceWith) {\n\tlet selector;\n\tlet remove;\n\tlet add;\n\tconst lastElements = [];\n\n\tif (replaceWith[0] === '.') {\n\t\tselector = replaceWith.slice(1);\n\t\tremove = (el) => el.classList.remove(selector);\n\t\tadd = (el) => el.classList.add(selector);\n\t} else {\n\t\t// A bit naive\n\t\tselector = replaceWith.slice(1, -1);\n\t\tremove = (el) => el.removeAttribute(selector, '');\n\t\tadd = (el) => el.setAttribute(selector, '');\n\t}\n\n\treturn function handleFocusChange() {\n\t\tlastElements.forEach(lastElement => remove(lastElement));\n\t\tlastElements.length = 0;\n\n\t\tlet activeElement = document.activeElement;\n\n\t\t// only add focus if it has not been added and is not the document element\n\t\tif (!/^(#document|HTML|BODY)$/.test(Object(activeElement).nodeName)) {\n\t\t\twhile (activeElement && activeElement.nodeType === 1) {\n\t\t\t\tadd(activeElement);\n\t\t\t\tlastElements.push(activeElement);\n\n\t\t\t\tactiveElement = activeElement.parentNode;\n\t\t\t}\n\t\t}\n\t};\n}\n\nexport default function focusWithin(opts) {\n\t// configuration\n\tconst options = {\n\t\tforce: false,\n\t\treplaceWith: '[focus-within]',\n\t};\n\n\tif (typeof opts !== 'undefined' && 'force' in opts) {\n\t\toptions.force = opts.force;\n\t}\n\n\tif (typeof opts !== 'undefined' && 'replaceWith' in opts) {\n\t\toptions.replaceWith = opts.replaceWith;\n\t}\n\n\tif (!isValidReplacement(options.replaceWith)) {\n\t\tthrow new Error(`${options.replaceWith} is not a valid replacement since it can't be applied to single elements.`);\n\t}\n\n\ttry {\n\t\tdocument.querySelector(':focus-within');\n\n\t\tif (!options.force) {\n\t\t\treturn;\n\t\t}\n\t} catch (_) {}\n\n\tconst handleFocusChange = generateHandler(options.replaceWith);\n\n\tconst initialize = function initializeEventListeners() {\n\t\tif (document.documentElement.className.indexOf('js-focus-within') > -1) {\n\t\t\treturn;\n\t\t}\n\n\t\tdocument.documentElement.className = document.documentElement.className + ' js-focus-within';\n\t\tdocument.addEventListener('focus', handleFocusChange, true);\n\t\tdocument.addEventListener('blur', handleFocusChange, true);\n\t};\n\n\tif (document.readyState === 'complete') {\n\t\tinitialize();\n\t} else {\n\t\tdocument.addEventListener('DOMContentLoaded', initialize);\n\t}\n}\n"],"names":["INVALID_SELECTOR_CHAR","isValidReplacement","selector","isValid","i","length","indexOf","focusWithin","opts","options","force","replaceWith","Error","document","querySelector","_","remove","add","lastElements","handleFocusChange","slice","el","classList","removeAttribute","setAttribute","forEach","lastElement","activeElement","test","Object","nodeName","nodeType","push","parentNode","initialize","initializeEventListeners","documentElement","className","addEventListener","readyState"],"mappings":"AAAA,IAAMA,EAAwB,CAC7B,IACA,IACA,IACA,IACA,IACA,IACA,IACA,IACA,KAGc,SAASC,mBAAmBC,GAI1C,IAHA,IAAIC,GAAU,EAGLC,EAAI,EAAGC,EAASL,EAAsBK,OAAQD,EAAIC,GAAUF,EAASC,IACzEF,EAASI,QAAQN,EAAsBI,KAAO,IACjDD,GAAU,GAIZ,OAAOA,CACR,CCae,SAASI,YAAYC,GAEnC,IAAMC,EAAU,CACfC,OAAO,EACPC,YAAa,kBAWd,QARoB,IAATH,GAAwB,UAAWA,IAC7CC,EAAQC,MAAQF,EAAKE,YAGF,IAATF,GAAwB,gBAAiBA,IACnDC,EAAQE,YAAcH,EAAKG,cAGvBV,mBAAmBQ,EAAQE,aAC/B,MAAM,IAAIC,MAASH,EAAQE,yFAG5B,IAGC,GAFAE,SAASC,cAAc,kBAElBL,EAAQC,MACZ,MAEF,CAAE,MAAOK,GAAI,CAEb,IA9DwBJ,EACpBT,EACAc,EACAC,EACEC,EA0DAC,GA9DkBR,EA8DkBF,EAAQE,YA1D5CO,EAAe,GAEE,MAAnBP,EAAY,IACfT,EAAWS,EAAYS,MAAM,GAC7BJ,EAAS,SAATA,OAAUK,GAAE,OAAKA,EAAGC,UAAUN,OAAOd,EAAS,EAC9Ce,EAAM,SAANA,IAAOI,GAAE,OAAKA,EAAGC,UAAUL,IAAIf,EAAS,IAGxCA,EAAWS,EAAYS,MAAM,GAAI,GACjCJ,EAAS,SAATA,OAAUK,GAAE,OAAKA,EAAGE,gBAAgBrB,EAAU,GAAG,EACjDe,EAAM,SAANA,IAAOI,GAAE,OAAKA,EAAGG,aAAatB,EAAU,GAAG,GAGrC,SAASiB,oBACfD,EAAaO,SAAQ,SAAAC,GAAW,OAAIV,EAAOU,MAC3CR,EAAab,OAAS,EAEtB,IAAIsB,EAAgBd,SAASc,cAG7B,IAAK,0BAA0BC,KAAKC,OAAOF,GAAeG,UACzD,KAAOH,GAA4C,IAA3BA,EAAcI,UACrCd,EAAIU,GACJT,EAAac,KAAKL,GAElBA,EAAgBA,EAAcM,aAmC3BC,EAAa,SAASC,2BACvBtB,SAASuB,gBAAgBC,UAAU/B,QAAQ,oBAAsB,IAIrEO,SAASuB,gBAAgBC,UAAYxB,SAASuB,gBAAgBC,UAAY,mBAC1ExB,SAASyB,iBAAiB,QAASnB,GAAmB,GACtDN,SAASyB,iBAAiB,OAAQnB,GAAmB,KAG1B,aAAxBN,SAAS0B,WACZL,IAEArB,SAASyB,iBAAiB,mBAAoBJ,EAEhD"}
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("postcss-selector-parser");const s=[" ",">","~",":","+","@","#","(",")"];function isValidReplacement(e){let t=!0;for(let n=0,o=s.length;n<o&&t;n++)e.indexOf(s[n])>-1&&(t=!1);return t}const t="js-focus-within",n=":focus-within",creator=s=>{const o=Object.assign({preserve:!0,replaceWith:"[focus-within]",disablePolyfillReadyClass:!1},s),
|
|
1
|
+
"use strict";var e=require("postcss-selector-parser");const s=[" ",">","~",":","+","@","#","(",")"];function isValidReplacement(e){let t=!0;for(let n=0,o=s.length;n<o&&t;n++)e.indexOf(s[n])>-1&&(t=!1);return t}const t="js-focus-within",n=":focus-within",creator=s=>{const o=Object.assign({preserve:!0,replaceWith:"[focus-within]",disablePolyfillReadyClass:!1},s),r=e().astSync(o.replaceWith);return isValidReplacement(o.replaceWith)?{postcssPlugin:"postcss-focus-within",prepare(){const s=new WeakSet;return{postcssPlugin:"postcss-focus-within",Rule(l,{result:i}){if(s.has(l))return;if(!l.selector.toLowerCase().includes(n))return;const a=l.selectors.flatMap((s=>{if(!s.toLowerCase().includes(n))return[s];let a;try{a=e().astSync(s)}catch(e){return l.warn(i,`Failed to parse selector : "${s}" with message: "${e instanceof Error?e.message:e}"`),s}if(void 0===a)return[s];let c=!1;if(a.walkPseudos((e=>{e.value.toLowerCase()===n&&(e.nodes&&e.nodes.length||(c=!0,e.replaceWith(r.clone({}))))})),!c)return[s];const d=a.clone();if(!o.disablePolyfillReadyClass){if(a.nodes?.[0]?.nodes?.length)for(let s=0;s<a.nodes[0].nodes.length;s++){const n=a.nodes[0].nodes[s];if("combinator"===n.type||e.isPseudoElement(n)){a.nodes[0].insertBefore(n,e.className({value:t}));break}if(s===a.nodes[0].nodes.length-1){a.nodes[0].append(e.className({value:t}));break}}return a.nodes?.[0]?.nodes&&(d.nodes[0].prepend(e.combinator({value:" "})),d.nodes[0].prepend(e.className({value:t}))),[a.toString(),d.toString()]}return[a.toString()]}));a.join(",")!==l.selectors.join(",")&&(s.add(l),l.cloneBefore({selectors:a}),o.preserve||l.remove())}}}}:{postcssPlugin:"postcss-focus-within",Once(e,{result:s}){e.warn(s,`${o.replaceWith} is not a valid replacement since it can't be applied to single elements.`)}}};creator.postcss=!0,module.exports=creator;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import type { PluginCreator } from 'postcss';
|
|
2
|
+
|
|
3
|
+
declare const creator: PluginCreator<pluginOptions>;
|
|
4
|
+
export default creator;
|
|
5
|
+
|
|
2
6
|
/** postcss-focus-within plugin options */
|
|
3
|
-
export type pluginOptions = {
|
|
7
|
+
export declare type pluginOptions = {
|
|
4
8
|
/** Preserve the original notation. default: true */
|
|
5
9
|
preserve?: boolean;
|
|
6
10
|
/** The replacement class to be used in the polyfill. default: "[focus-within]" */
|
|
@@ -8,5 +12,5 @@ export type pluginOptions = {
|
|
|
8
12
|
/** Disable the selector prefix that is used to prevent a flash of incorrectly styled content. default: false */
|
|
9
13
|
disablePolyfillReadyClass?: boolean;
|
|
10
14
|
};
|
|
11
|
-
|
|
12
|
-
export
|
|
15
|
+
|
|
16
|
+
export { }
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"postcss-selector-parser";const s=[" ",">","~",":","+","@","#","(",")"];function isValidReplacement(e){let t=!0;for(let n=0,o=s.length;n<o&&t;n++)e.indexOf(s[n])>-1&&(t=!1);return t}const t="js-focus-within",n=":focus-within",creator=s=>{const o=Object.assign({preserve:!0,replaceWith:"[focus-within]",disablePolyfillReadyClass:!1},s),
|
|
1
|
+
import e from"postcss-selector-parser";const s=[" ",">","~",":","+","@","#","(",")"];function isValidReplacement(e){let t=!0;for(let n=0,o=s.length;n<o&&t;n++)e.indexOf(s[n])>-1&&(t=!1);return t}const t="js-focus-within",n=":focus-within",creator=s=>{const o=Object.assign({preserve:!0,replaceWith:"[focus-within]",disablePolyfillReadyClass:!1},s),r=e().astSync(o.replaceWith);return isValidReplacement(o.replaceWith)?{postcssPlugin:"postcss-focus-within",prepare(){const s=new WeakSet;return{postcssPlugin:"postcss-focus-within",Rule(l,{result:i}){if(s.has(l))return;if(!l.selector.toLowerCase().includes(n))return;const a=l.selectors.flatMap((s=>{if(!s.toLowerCase().includes(n))return[s];let a;try{a=e().astSync(s)}catch(e){return l.warn(i,`Failed to parse selector : "${s}" with message: "${e instanceof Error?e.message:e}"`),s}if(void 0===a)return[s];let c=!1;if(a.walkPseudos((e=>{e.value.toLowerCase()===n&&(e.nodes&&e.nodes.length||(c=!0,e.replaceWith(r.clone({}))))})),!c)return[s];const d=a.clone();if(!o.disablePolyfillReadyClass){if(a.nodes?.[0]?.nodes?.length)for(let s=0;s<a.nodes[0].nodes.length;s++){const n=a.nodes[0].nodes[s];if("combinator"===n.type||e.isPseudoElement(n)){a.nodes[0].insertBefore(n,e.className({value:t}));break}if(s===a.nodes[0].nodes.length-1){a.nodes[0].append(e.className({value:t}));break}}return a.nodes?.[0]?.nodes&&(d.nodes[0].prepend(e.combinator({value:" "})),d.nodes[0].prepend(e.className({value:t}))),[a.toString(),d.toString()]}return[a.toString()]}));a.join(",")!==l.selectors.join(",")&&(s.add(l),l.cloneBefore({selectors:a}),o.preserve||l.remove())}}}}:{postcssPlugin:"postcss-focus-within",Once(e,{result:s}){e.warn(s,`${o.replaceWith} is not a valid replacement since it can't be applied to single elements.`)}}};creator.postcss=!0;export{creator as default};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postcss-focus-within",
|
|
3
3
|
"description": "Use the :focus-within pseudo-selector in CSS",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "9.0.0",
|
|
5
5
|
"contributors": [
|
|
6
6
|
{
|
|
7
7
|
"name": "Antonio Laguna",
|
|
@@ -29,17 +29,20 @@
|
|
|
29
29
|
}
|
|
30
30
|
],
|
|
31
31
|
"engines": {
|
|
32
|
-
"node": "
|
|
32
|
+
"node": ">=18"
|
|
33
33
|
},
|
|
34
|
+
"type": "module",
|
|
34
35
|
"main": "dist/index.cjs",
|
|
35
36
|
"module": "dist/index.mjs",
|
|
36
|
-
"types": "dist/index.d.ts",
|
|
37
37
|
"exports": {
|
|
38
38
|
".": {
|
|
39
|
-
"
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
"import": {
|
|
40
|
+
"types": "./dist/index.d.ts",
|
|
41
|
+
"default": "./dist/index.mjs"
|
|
42
|
+
},
|
|
43
|
+
"require": {
|
|
44
|
+
"default": "./dist/index.cjs"
|
|
45
|
+
}
|
|
43
46
|
},
|
|
44
47
|
"./browser": {
|
|
45
48
|
"import": "./dist/browser.mjs",
|
|
@@ -57,27 +60,16 @@
|
|
|
57
60
|
"dist"
|
|
58
61
|
],
|
|
59
62
|
"dependencies": {
|
|
60
|
-
"postcss-selector-parser": "^6.0
|
|
63
|
+
"postcss-selector-parser": "^6.1.0"
|
|
61
64
|
},
|
|
62
65
|
"peerDependencies": {
|
|
63
66
|
"postcss": "^8.4"
|
|
64
67
|
},
|
|
65
|
-
"
|
|
66
|
-
"@csstools/postcss-tape": "*"
|
|
67
|
-
},
|
|
68
|
-
"scripts": {
|
|
69
|
-
"build": "rollup -c ../../rollup/default.mjs",
|
|
70
|
-
"docs": "node ../../.github/bin/generate-docs/install.mjs && node ../../.github/bin/generate-docs/readme.mjs",
|
|
71
|
-
"lint": "node ../../.github/bin/format-package-json.mjs",
|
|
72
|
-
"prepublishOnly": "npm run build && npm run test",
|
|
73
|
-
"test": "node .tape.mjs && node ./test/_import.mjs && node ./test/_require.cjs",
|
|
74
|
-
"test:browser": "node ./test/_browser.mjs",
|
|
75
|
-
"test:rewrite-expects": "REWRITE_EXPECTS=true node .tape.mjs"
|
|
76
|
-
},
|
|
68
|
+
"scripts": {},
|
|
77
69
|
"homepage": "https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-focus-within#readme",
|
|
78
70
|
"repository": {
|
|
79
71
|
"type": "git",
|
|
80
|
-
"url": "https://github.com/csstools/postcss-plugins.git",
|
|
72
|
+
"url": "git+https://github.com/csstools/postcss-plugins.git",
|
|
81
73
|
"directory": "plugins/postcss-focus-within"
|
|
82
74
|
},
|
|
83
75
|
"bugs": "https://github.com/csstools/postcss-plugins/issues",
|
|
@@ -94,14 +86,5 @@
|
|
|
94
86
|
"pseudos",
|
|
95
87
|
"selectors",
|
|
96
88
|
"within"
|
|
97
|
-
]
|
|
98
|
-
"csstools": {
|
|
99
|
-
"cssdbId": "focus-within-pseudo-class",
|
|
100
|
-
"exportName": "postcssFocusWithin",
|
|
101
|
-
"humanReadableName": "PostCSS Focus Within",
|
|
102
|
-
"specUrl": "https://www.w3.org/TR/selectors-4/#the-focus-within-pseudo"
|
|
103
|
-
},
|
|
104
|
-
"volta": {
|
|
105
|
-
"extends": "../../package.json"
|
|
106
|
-
}
|
|
89
|
+
]
|
|
107
90
|
}
|