css-blank-pseudo 4.1.1 → 5.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 CHANGED
@@ -1,6 +1,12 @@
1
1
  # Changes to CSS Blank Pseudo
2
2
 
3
- ### 4.1.1 (August, 23, 2022)
3
+ ### 5.0.0 (January 24, 2023)
4
+
5
+ - Updated: Support for Node v14+ (major).
6
+ - Fix: Do not throw when a selector is invalid, show a warning instead.
7
+ - Updated: Export and document the plugin options types.
8
+
9
+ ### 4.1.1 (August 23, 2022)
4
10
 
5
11
  - Fix: assign global browser polyfill to `window`, `self` or a blank object.
6
12
 
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # PostCSS Blank Pseudo [<img src="https://postcss.github.io/postcss/logo.svg" alt="PostCSS Logo" width="90" height="90" align="right">][postcss]
1
+ # PostCSS Blank Pseudo [<img src="https://postcss.github.io/postcss/logo.svg" alt="PostCSS Logo" width="90" height="90" align="right">][PostCSS]
2
2
 
3
3
  [<img alt="npm version" src="https://img.shields.io/npm/v/css-blank-pseudo.svg" height="20">][npm-url] [<img alt="CSS Standard Status" src="https://cssdb.org/images/badges/blank-pseudo-class.svg" height="20">][css-url] [<img alt="Build Status" src="https://github.com/csstools/postcss-plugins/workflows/test/badge.svg" height="20">][cli-url] [<img alt="Discord" src="https://shields.io/badge/Discord-5865F2?logo=discord&logoColor=white">][discord]
4
4
 
@@ -42,8 +42,13 @@ postcss([
42
42
  [PostCSS Blank Pseudo] runs in all Node environments, with special
43
43
  instructions for:
44
44
 
45
- | [Node](INSTALL.md#node) | [PostCSS CLI](INSTALL.md#postcss-cli) | [Webpack](INSTALL.md#webpack) | [Create React App](INSTALL.md#create-react-app) | [Gulp](INSTALL.md#gulp) | [Grunt](INSTALL.md#grunt) |
46
- | --- | --- | --- | --- | --- | --- |
45
+ - [Node](INSTALL.md#node)
46
+ - [PostCSS CLI](INSTALL.md#postcss-cli)
47
+ - [PostCSS Load Config](INSTALL.md#postcss-load-config)
48
+ - [Webpack](INSTALL.md#webpack)
49
+ - [Next.js](INSTALL.md#nextjs)
50
+ - [Gulp](INSTALL.md#gulp)
51
+ - [Grunt](INSTALL.md#grunt)
47
52
 
48
53
  ## Options
49
54
 
@@ -136,7 +141,7 @@ or
136
141
 
137
142
  ```html
138
143
  <!-- When using a CDN url you will have to manually update the version number -->
139
- <script src="https://unpkg.com/css-blank-pseudo@4.1.1/dist/browser-global.js"></script>
144
+ <script src="https://unpkg.com/css-blank-pseudo@5.0.0/dist/browser-global.js"></script>
140
145
  <script>cssBlankPseudoInit()</script>
141
146
  ```
142
147
 
@@ -180,14 +185,26 @@ Please note that using a class, leverages `classList` under the hood which
180
185
  might not be supported on some old browsers such as IE9, so you may need
181
186
  to polyfill `classList` in those cases.
182
187
 
188
+ ### Using with Next.js
189
+
190
+ Given that Next.js imports packages both on the browser and on the server, you need to make sure that the package is only imported on the browser.
191
+
192
+ As outlined in the [Next.js documentation](https://nextjs.org/docs/advanced-features/dynamic-import#with-external-libraries), you need to load the package with a dynamic import:
193
+
194
+ ```jsx
195
+ useEffect(async () => {
196
+ const cssBlankPseudoInit = (await import('css-blank-pseudo/browser')).default;
197
+ cssBlankPseudoInit();
198
+ }, []);
199
+ ```
200
+
201
+ We recommend you load the polyfill as high up on your Next application as possible, such as your `pages/_app.ts` file.
202
+
183
203
  [cli-url]: https://github.com/csstools/postcss-plugins/actions/workflows/test.yml?query=workflow/test
184
204
  [css-url]: https://cssdb.org/#blank-pseudo-class
185
205
  [discord]: https://discord.gg/bUadyRwkJS
186
206
  [npm-url]: https://www.npmjs.com/package/css-blank-pseudo
187
207
 
188
- [Gulp PostCSS]: https://github.com/postcss/gulp-postcss
189
- [Grunt PostCSS]: https://github.com/nDmitry/grunt-postcss
190
208
  [PostCSS]: https://github.com/postcss/postcss
191
- [PostCSS Loader]: https://github.com/postcss/postcss-loader
192
209
  [PostCSS Blank Pseudo]: https://github.com/csstools/postcss-plugins/tree/main/plugins/css-blank-pseudo
193
210
  [Selectors Level 4]: https://www.w3.org/TR/selectors-4/#blank
@@ -1,2 +1,2 @@
1
- !function(){var e=[" ",">","~",":","+","@","#","(",")"];var t="js-blank-pseudo";function n(e){return"INPUT"===e.nodeName||"SELECT"===e.nodeName||"TEXTAREA"===e.nodeName}function o(e){var t;return"function"==typeof Event?t=new Event(e,{bubbles:!0}):(t=document.createEvent("Event")).initEvent(e,!0,!1),t}function r(e,t){var n=Object.getOwnPropertyDescriptor(e.prototype,"value"),o=n.set;n.set=function(){o.apply(this,arguments),t({target:this})},Object.defineProperty(e.prototype,"value",n)}function c(c){var i={force:!1,replaceWith:"[blank]"};if(void 0!==c&&"force"in c&&(i.force=c.force),void 0!==c&&"replaceWith"in c&&(i.replaceWith=c.replaceWith),!function(t){for(var n=!0,o=0,r=e.length;o<r&&n;o++)t.indexOf(e[o])>-1&&(n=!1);return n}(i.replaceWith))throw new Error(i.replaceWith+" is not a valid replacement since it can't be applied to single elements.");try{if(document.querySelector(":blank"),!i.force)return}catch(e){}var a,d,l,s,u,f,p,v=("."===(a=i.replaceWith)[0]?(d=a.slice(1),l=function(e){return e.classList.remove(d)},s=function(e){return e.classList.add(d)}):(d=a.slice(1,-1),l=function(e){return e.removeAttribute(d,"")},s=function(e){return e.setAttribute(d,"")}),function(e){var t=e.target;n(t)&&(("SELECT"===t.nodeName?t.options[t.selectedIndex].value:t.value)?l(t):s(t))}),m=function(){document.body&&(document.body.addEventListener("change",v),document.body.addEventListener("input",v))},E=function(){Array.prototype.forEach.call(document.querySelectorAll("input, select, textarea"),(function(e){v({target:e})}))};if(document.body?m():window.addEventListener("load",m),-1===document.documentElement.className.indexOf(t)&&(document.documentElement.className+=" js-blank-pseudo"),r(self.HTMLInputElement,v),r(self.HTMLSelectElement,v),r(self.HTMLTextAreaElement,v),u=self.HTMLOptionElement,f=Object.getOwnPropertyDescriptor(u.prototype,"selected"),p=f.set,f.set=function(e){p.apply(this,arguments);var t=o("change");this.parentElement.dispatchEvent(t)},Object.defineProperty(u.prototype,"selected",f),E(),void 0!==self.MutationObserver)new MutationObserver((function(e){e.forEach((function(e){Array.prototype.forEach.call(e.addedNodes||[],(function(e){1===e.nodeType&&n(e)&&v({target:e})}))}))})).observe(document,{childList:!0,subtree:!0});else{var y=function(){return E()};window.addEventListener("load",y),window.addEventListener("DOMContentLoaded",y)}}("object"==typeof window&&window||"object"==typeof self&&self||{}).cssBlankPseudoInit=c}();
1
+ !function(){var e=[" ",">","~",":","+","@","#","(",")"];function isValidReplacement(t){for(var n=!0,o=0,r=e.length;o<r&&n;o++)t.indexOf(e[o])>-1&&(n=!1);return n}var t="js-blank-pseudo";function isFormControlElement(e){return"INPUT"===e.nodeName||"SELECT"===e.nodeName||"TEXTAREA"===e.nodeName}function createNewEvent(e){var t;return"function"==typeof Event?t=new Event(e,{bubbles:!0}):(t=document.createEvent("Event")).initEvent(e,!0,!1),t}function observeValueOfHTMLElement(e,t){var n=Object.getOwnPropertyDescriptor(e.prototype,"value"),o=n.set;n.set=function set(){o.apply(this,arguments),t({target:this})},Object.defineProperty(e.prototype,"value",n)}function cssBlankPseudoInit(e){var n={force:!1,replaceWith:"[blank]"};if(void 0!==e&&"force"in e&&(n.force=e.force),void 0!==e&&"replaceWith"in e&&(n.replaceWith=e.replaceWith),!isValidReplacement(n.replaceWith))throw new Error(n.replaceWith+" is not a valid replacement since it can't be applied to single elements.");try{if(document.querySelector(":blank"),!n.force)return}catch(m){}var o,r,a,i,c,l,d,s=("."===(o=n.replaceWith)[0]?(r=o.slice(1),a=function remove(e){return e.classList.remove(r)},i=function add(e){return e.classList.add(r)}):(r=o.slice(1,-1),a=function remove(e){return e.removeAttribute(r,"")},i=function add(e){return e.setAttribute(r,"")}),function handleInputOrChangeEvent(e){var t=e.target;isFormControlElement(t)&&(("SELECT"===t.nodeName?t.options[t.selectedIndex].value:t.value)?a(t):i(t))}),u=function bindEvents(){document.body&&(document.body.addEventListener("change",s),document.body.addEventListener("input",s))},f=function updateAllCandidates(){Array.prototype.forEach.call(document.querySelectorAll("input, select, textarea"),(function(e){s({target:e})}))};if(document.body?u():window.addEventListener("load",u),-1===document.documentElement.className.indexOf(t)&&(document.documentElement.className+=" "+t),observeValueOfHTMLElement(self.HTMLInputElement,s),observeValueOfHTMLElement(self.HTMLSelectElement,s),observeValueOfHTMLElement(self.HTMLTextAreaElement,s),c=self.HTMLOptionElement,l=Object.getOwnPropertyDescriptor(c.prototype,"selected"),d=l.set,l.set=function set(e){d.apply(this,arguments);var t=createNewEvent("change");this.parentElement.dispatchEvent(t)},Object.defineProperty(c.prototype,"selected",l),f(),"undefined"!=typeof self.MutationObserver)new MutationObserver((function(e){e.forEach((function(e){Array.prototype.forEach.call(e.addedNodes||[],(function(e){1===e.nodeType&&isFormControlElement(e)&&s({target:e})}))}))})).observe(document,{childList:!0,subtree:!0});else{var p=function handleOnLoad(){return f()};window.addEventListener("load",p),window.addEventListener("DOMContentLoaded",p)}}("object"==typeof window&&window||"object"==typeof self&&self||{}).cssBlankPseudoInit=cssBlankPseudoInit}();
2
2
  //# sourceMappingURL=browser-global.js.map
@@ -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","/* global document,window,self,MutationObserver */\nimport isValidReplacement from './is-valid-replacement.mjs';\n\nconst CSS_CLASS_LOADED = 'js-blank-pseudo';\n\n// form control elements selector\nfunction isFormControlElement(element) {\n\tif (element.nodeName === 'INPUT' || element.nodeName === 'SELECT' || element.nodeName === 'TEXTAREA') {\n\t\treturn true;\n\t}\n\n\treturn false;\n}\n\nfunction createNewEvent(eventName) {\n\tlet event;\n\n\tif (typeof(Event) === 'function') {\n\t\tevent = new Event(eventName, { bubbles: true });\n\t} else {\n\t\tevent = document.createEvent('Event');\n\t\tevent.initEvent(eventName, true, false);\n\t}\n\n\treturn event;\n}\n\nfunction generateHandler(replaceWith) {\n\tlet selector;\n\tlet remove;\n\tlet add;\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 handleInputOrChangeEvent(event) {\n\t\tconst element = event.target;\n\t\tif (!isFormControlElement(element)) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst isSelect = element.nodeName === 'SELECT';\n\t\tconst hasValue = isSelect\n\t\t\t? !!element.options[element.selectedIndex].value\n\t\t\t: !!element.value;\n\n\t\tif (hasValue) {\n\t\t\tremove(element);\n\t\t} else {\n\t\t\tadd(element);\n\t\t}\n\t};\n}\n\n// observe changes to the \"selected\" property on an HTML Element\nfunction observeSelectedOfHTMLElement(HTMLElement) {\n\tconst descriptor = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'selected');\n\tconst nativeSet = descriptor.set;\n\n\tdescriptor.set = function set(value) { // eslint-disable-line no-unused-vars\n\t\tnativeSet.apply(this, arguments);\n\n\t\tconst event = createNewEvent('change');\n\t\tthis.parentElement.dispatchEvent(event);\n\t};\n\n\tObject.defineProperty(HTMLElement.prototype, 'selected', descriptor);\n}\n\n// observe changes to the \"value\" property on an HTML Element\nfunction observeValueOfHTMLElement(HTMLElement, handler) {\n\tconst descriptor = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'value');\n\tconst nativeSet = descriptor.set;\n\n\tdescriptor.set = function set() {\n\t\tnativeSet.apply(this, arguments);\n\t\thandler({ target: this });\n\t};\n\n\tObject.defineProperty(HTMLElement.prototype, 'value', descriptor);\n}\n\nexport default function cssBlankPseudoInit(opts) {\n\t// configuration\n\tconst options = {\n\t\tforce: false,\n\t\treplaceWith: '[blank]',\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(':blank');\n\n\t\tif (!options.force) {\n\t\t\treturn;\n\t\t}\n\t} catch (ignoredError) { /* do nothing and continue */ }\n\n\tconst handler = generateHandler(options.replaceWith);\n\tconst bindEvents = () => {\n\t\tif (document.body) {\n\t\t\tdocument.body.addEventListener('change', handler);\n\t\t\tdocument.body.addEventListener('input', handler);\n\t\t}\n\t};\n\tconst updateAllCandidates = () => {\n\t\tArray.prototype.forEach.call(\n\t\t\tdocument.querySelectorAll('input, select, textarea'),\n\t\t\tnode => {\n\t\t\t\thandler({ target: node });\n\t\t\t},\n\t\t);\n\t};\n\n\tif (document.body) {\n\t\tbindEvents();\n\t} else {\n\t\twindow.addEventListener('load', bindEvents);\n\t}\n\n\tif (document.documentElement.className.indexOf(CSS_CLASS_LOADED) === -1) {\n\t\tdocument.documentElement.className += ` ${CSS_CLASS_LOADED}`;\n\t}\n\n\tobserveValueOfHTMLElement(self.HTMLInputElement, handler);\n\tobserveValueOfHTMLElement(self.HTMLSelectElement, handler);\n\tobserveValueOfHTMLElement(self.HTMLTextAreaElement, handler);\n\tobserveSelectedOfHTMLElement(self.HTMLOptionElement, handler);\n\n\t// conditionally update all form control elements\n\tupdateAllCandidates();\n\n\tif (typeof self.MutationObserver !== 'undefined') {\n\t\t// conditionally observe added or unobserve removed form control elements\n\t\tnew MutationObserver(mutationsList => {\n\t\t\tmutationsList.forEach(mutation => {\n\t\t\t\tArray.prototype.forEach.call(\n\t\t\t\t\tmutation.addedNodes || [],\n\t\t\t\t\tnode => {\n\t\t\t\t\t\tif (node.nodeType === 1 && isFormControlElement(node)) {\n\t\t\t\t\t\t\thandler({ target: node });\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t});\n\t\t}).observe(document, { childList: true, subtree: true });\n\t} else {\n\t\tconst handleOnLoad = () => updateAllCandidates();\n\n\t\twindow.addEventListener('load', handleOnLoad);\n\t\twindow.addEventListener('DOMContentLoaded', handleOnLoad);\n\t}\n}\n","/* global self,window */\nimport { default as cssBlankPseudoInit } from './browser';\n\n(function (global) {\n\tglobal.cssBlankPseudoInit = cssBlankPseudoInit;\n}('object' === typeof window && window || 'object' === typeof self && self || {}));\n"],"names":["INVALID_SELECTOR_CHAR","CSS_CLASS_LOADED","isFormControlElement","element","nodeName","createNewEvent","eventName","event","Event","bubbles","document","createEvent","initEvent","observeValueOfHTMLElement","HTMLElement","handler","descriptor","Object","getOwnPropertyDescriptor","prototype","nativeSet","set","apply","this","arguments","target","defineProperty","cssBlankPseudoInit","opts","options","force","replaceWith","selector","isValid","i","length","indexOf","isValidReplacement","Error","querySelector","ignoredError","remove","add","slice","el","classList","removeAttribute","setAttribute","selectedIndex","value","bindEvents","body","addEventListener","updateAllCandidates","Array","forEach","call","querySelectorAll","node","window","documentElement","className","self","HTMLInputElement","HTMLSelectElement","HTMLTextAreaElement","HTMLOptionElement","parentElement","dispatchEvent","MutationObserver","mutationsList","mutation","addedNodes","nodeType","observe","childList","subtree","handleOnLoad"],"mappings":"YAAA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ACpBA,EAAcf,SAAQ,SAAAgB,GACrBjB,MAAMnC,UAAUoC,QAAQC,KACvBe,EAASC,YAAc,IACvB,SAAAd,GACuB,IAAlBA,EAAKe,UAAkBvE,EAAqBwD,IAC/C3C,EAAQ,CAAEU,OAAQiC,SAKtB,IAAEgB,QAAQhE,SAAU,CAAEiE,WAAW,EAAMC,SAAS,QAC3C,CACN,IAAMC,EAAe,WAAA,OAAMxB,KAE3BM,OAAOP,iBAAiB,OAAQyB,GAChClB,OAAOP,iBAAiB,mBAAoByB,EAC5C,CACD,ECtKC,iBAAoBlB,QAAUA,QAAU,iBAAoBG,MAAQA,MAAQ,IADtEnC,mBAAqBA"}
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","/* global document,window,self,MutationObserver */\nimport isValidReplacement from './is-valid-replacement.mjs';\n\nconst CSS_CLASS_LOADED = 'js-blank-pseudo';\n\n// form control elements selector\nfunction isFormControlElement(element) {\n\tif (element.nodeName === 'INPUT' || element.nodeName === 'SELECT' || element.nodeName === 'TEXTAREA') {\n\t\treturn true;\n\t}\n\n\treturn false;\n}\n\nfunction createNewEvent(eventName) {\n\tlet event;\n\n\tif (typeof(Event) === 'function') {\n\t\tevent = new Event(eventName, { bubbles: true });\n\t} else {\n\t\tevent = document.createEvent('Event');\n\t\tevent.initEvent(eventName, true, false);\n\t}\n\n\treturn event;\n}\n\nfunction generateHandler(replaceWith) {\n\tlet selector;\n\tlet remove;\n\tlet add;\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 handleInputOrChangeEvent(event) {\n\t\tconst element = event.target;\n\t\tif (!isFormControlElement(element)) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst isSelect = element.nodeName === 'SELECT';\n\t\tconst hasValue = isSelect\n\t\t\t? !!element.options[element.selectedIndex].value\n\t\t\t: !!element.value;\n\n\t\tif (hasValue) {\n\t\t\tremove(element);\n\t\t} else {\n\t\t\tadd(element);\n\t\t}\n\t};\n}\n\n// observe changes to the \"selected\" property on an HTML Element\nfunction observeSelectedOfHTMLElement(HTMLElement) {\n\tconst descriptor = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'selected');\n\tconst nativeSet = descriptor.set;\n\n\tdescriptor.set = function set(value) { // eslint-disable-line no-unused-vars\n\t\tnativeSet.apply(this, arguments);\n\n\t\tconst event = createNewEvent('change');\n\t\tthis.parentElement.dispatchEvent(event);\n\t};\n\n\tObject.defineProperty(HTMLElement.prototype, 'selected', descriptor);\n}\n\n// observe changes to the \"value\" property on an HTML Element\nfunction observeValueOfHTMLElement(HTMLElement, handler) {\n\tconst descriptor = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'value');\n\tconst nativeSet = descriptor.set;\n\n\tdescriptor.set = function set() {\n\t\tnativeSet.apply(this, arguments);\n\t\thandler({ target: this });\n\t};\n\n\tObject.defineProperty(HTMLElement.prototype, 'value', descriptor);\n}\n\nexport default function cssBlankPseudoInit(opts) {\n\t// configuration\n\tconst options = {\n\t\tforce: false,\n\t\treplaceWith: '[blank]',\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(':blank');\n\n\t\tif (!options.force) {\n\t\t\treturn;\n\t\t}\n\t} catch (ignoredError) { /* do nothing and continue */ }\n\n\tconst handler = generateHandler(options.replaceWith);\n\tconst bindEvents = () => {\n\t\tif (document.body) {\n\t\t\tdocument.body.addEventListener('change', handler);\n\t\t\tdocument.body.addEventListener('input', handler);\n\t\t}\n\t};\n\tconst updateAllCandidates = () => {\n\t\tArray.prototype.forEach.call(\n\t\t\tdocument.querySelectorAll('input, select, textarea'),\n\t\t\tnode => {\n\t\t\t\thandler({ target: node });\n\t\t\t},\n\t\t);\n\t};\n\n\tif (document.body) {\n\t\tbindEvents();\n\t} else {\n\t\twindow.addEventListener('load', bindEvents);\n\t}\n\n\tif (document.documentElement.className.indexOf(CSS_CLASS_LOADED) === -1) {\n\t\tdocument.documentElement.className += ` ${CSS_CLASS_LOADED}`;\n\t}\n\n\tobserveValueOfHTMLElement(self.HTMLInputElement, handler);\n\tobserveValueOfHTMLElement(self.HTMLSelectElement, handler);\n\tobserveValueOfHTMLElement(self.HTMLTextAreaElement, handler);\n\tobserveSelectedOfHTMLElement(self.HTMLOptionElement, handler);\n\n\t// conditionally update all form control elements\n\tupdateAllCandidates();\n\n\tif (typeof self.MutationObserver !== 'undefined') {\n\t\t// conditionally observe added or unobserve removed form control elements\n\t\tnew MutationObserver(mutationsList => {\n\t\t\tmutationsList.forEach(mutation => {\n\t\t\t\tArray.prototype.forEach.call(\n\t\t\t\t\tmutation.addedNodes || [],\n\t\t\t\t\tnode => {\n\t\t\t\t\t\tif (node.nodeType === 1 && isFormControlElement(node)) {\n\t\t\t\t\t\t\thandler({ target: node });\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t});\n\t\t}).observe(document, { childList: true, subtree: true });\n\t} else {\n\t\tconst handleOnLoad = () => updateAllCandidates();\n\n\t\twindow.addEventListener('load', handleOnLoad);\n\t\twindow.addEventListener('DOMContentLoaded', handleOnLoad);\n\t}\n}\n","/* global self,window */\nimport { default as cssBlankPseudoInit } from './browser';\n\n(function (global) {\n\tglobal.cssBlankPseudoInit = cssBlankPseudoInit;\n}('object' === typeof window && window || 'object' === typeof self && self || {}));\n"],"names":["INVALID_SELECTOR_CHAR","isValidReplacement","selector","isValid","i","length","indexOf","CSS_CLASS_LOADED","isFormControlElement","element","nodeName","createNewEvent","eventName","event","Event","bubbles","document","createEvent","initEvent","observeValueOfHTMLElement","HTMLElement","handler","descriptor","Object","getOwnPropertyDescriptor","prototype","nativeSet","set","apply","this","arguments","target","defineProperty","cssBlankPseudoInit","opts","options","force","replaceWith","Error","querySelector","ignoredError","remove","add","slice","el","classList","removeAttribute","setAttribute","handleInputOrChangeEvent","selectedIndex","value","bindEvents","body","addEventListener","updateAllCandidates","Array","forEach","call","querySelectorAll","node","window","documentElement","className","self","HTMLInputElement","HTMLSelectElement","HTMLTextAreaElement","HTMLOptionElement","parentElement","dispatchEvent","MutationObserver","mutationsList","mutation","addedNodes","nodeType","observe","childList","subtree","handleOnLoad"],"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,CCpBA,IAAMI,EAAmB,kBAGzB,S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AQ4B,GAEpB,GAEF,GACD,IAAGgB,QAAQ3D,SAAU,CAAE4D,WAAW,EAAMC,SAAS,QAC3C,CACN,IAAMC,EAAe,SAAfA,eAAY,OAASxB,GAAqB,EAEhDM,OAAOP,iBAAiB,OAAQyB,GAChClB,OAAOP,iBAAiB,mBAAoByB,EAC7C,CACD,ECtKE,iBAAoBlB,QAAUA,QAAU,iBAAoBG,MAAQA,MAAQ,IADtE9B,mBAAqBA"}
package/dist/browser.cjs CHANGED
@@ -1,2 +1,2 @@
1
- var e=[" ",">","~",":","+","@","#","(",")"];function t(e){return"INPUT"===e.nodeName||"SELECT"===e.nodeName||"TEXTAREA"===e.nodeName}function n(e){var t;return"function"==typeof Event?t=new Event(e,{bubbles:!0}):(t=document.createEvent("Event")).initEvent(e,!0,!1),t}function r(e,t){var n=Object.getOwnPropertyDescriptor(e.prototype,"value"),r=n.set;n.set=function(){r.apply(this,arguments),t({target:this})},Object.defineProperty(e.prototype,"value",n)}module.exports=function(o){var c={force:!1,replaceWith:"[blank]"};if(void 0!==o&&"force"in o&&(c.force=o.force),void 0!==o&&"replaceWith"in o&&(c.replaceWith=o.replaceWith),!function(t){for(var n=!0,r=0,o=e.length;r<o&&n;r++)t.indexOf(e[r])>-1&&(n=!1);return n}(c.replaceWith))throw new Error(c.replaceWith+" is not a valid replacement since it can't be applied to single elements.");try{if(document.querySelector(":blank"),!c.force)return}catch(e){}var i,a,d,l,u,s,p,f=("."===(i=c.replaceWith)[0]?(a=i.slice(1),d=function(e){return e.classList.remove(a)},l=function(e){return e.classList.add(a)}):(a=i.slice(1,-1),d=function(e){return e.removeAttribute(a,"")},l=function(e){return e.setAttribute(a,"")}),function(e){var n=e.target;t(n)&&(("SELECT"===n.nodeName?n.options[n.selectedIndex].value:n.value)?d(n):l(n))}),v=function(){document.body&&(document.body.addEventListener("change",f),document.body.addEventListener("input",f))},m=function(){Array.prototype.forEach.call(document.querySelectorAll("input, select, textarea"),(function(e){f({target:e})}))};if(document.body?v():window.addEventListener("load",v),-1===document.documentElement.className.indexOf("js-blank-pseudo")&&(document.documentElement.className+=" js-blank-pseudo"),r(self.HTMLInputElement,f),r(self.HTMLSelectElement,f),r(self.HTMLTextAreaElement,f),u=self.HTMLOptionElement,s=Object.getOwnPropertyDescriptor(u.prototype,"selected"),p=s.set,s.set=function(e){p.apply(this,arguments);var t=n("change");this.parentElement.dispatchEvent(t)},Object.defineProperty(u.prototype,"selected",s),m(),void 0!==self.MutationObserver)new MutationObserver((function(e){e.forEach((function(e){Array.prototype.forEach.call(e.addedNodes||[],(function(e){1===e.nodeType&&t(e)&&f({target:e})}))}))})).observe(document,{childList:!0,subtree:!0});else{var E=function(){return m()};window.addEventListener("load",E),window.addEventListener("DOMContentLoaded",E)}};
1
+ var e=[" ",">","~",":","+","@","#","(",")"];function isValidReplacement(t){for(var n=!0,r=0,o=e.length;r<o&&n;r++)t.indexOf(e[r])>-1&&(n=!1);return n}var t="js-blank-pseudo";function isFormControlElement(e){return"INPUT"===e.nodeName||"SELECT"===e.nodeName||"TEXTAREA"===e.nodeName}function createNewEvent(e){var t;return"function"==typeof Event?t=new Event(e,{bubbles:!0}):(t=document.createEvent("Event")).initEvent(e,!0,!1),t}function observeValueOfHTMLElement(e,t){var n=Object.getOwnPropertyDescriptor(e.prototype,"value"),r=n.set;n.set=function set(){r.apply(this,arguments),t({target:this})},Object.defineProperty(e.prototype,"value",n)}module.exports=function cssBlankPseudoInit(e){var n={force:!1,replaceWith:"[blank]"};if(void 0!==e&&"force"in e&&(n.force=e.force),void 0!==e&&"replaceWith"in e&&(n.replaceWith=e.replaceWith),!isValidReplacement(n.replaceWith))throw new Error(n.replaceWith+" is not a valid replacement since it can't be applied to single elements.");try{if(document.querySelector(":blank"),!n.force)return}catch(m){}var r,o,a,i,c,l,d,s=("."===(r=n.replaceWith)[0]?(o=r.slice(1),a=function remove(e){return e.classList.remove(o)},i=function add(e){return e.classList.add(o)}):(o=r.slice(1,-1),a=function remove(e){return e.removeAttribute(o,"")},i=function add(e){return e.setAttribute(o,"")}),function handleInputOrChangeEvent(e){var t=e.target;isFormControlElement(t)&&(("SELECT"===t.nodeName?t.options[t.selectedIndex].value:t.value)?a(t):i(t))}),u=function bindEvents(){document.body&&(document.body.addEventListener("change",s),document.body.addEventListener("input",s))},f=function updateAllCandidates(){Array.prototype.forEach.call(document.querySelectorAll("input, select, textarea"),(function(e){s({target:e})}))};if(document.body?u():window.addEventListener("load",u),-1===document.documentElement.className.indexOf(t)&&(document.documentElement.className+=" "+t),observeValueOfHTMLElement(self.HTMLInputElement,s),observeValueOfHTMLElement(self.HTMLSelectElement,s),observeValueOfHTMLElement(self.HTMLTextAreaElement,s),c=self.HTMLOptionElement,l=Object.getOwnPropertyDescriptor(c.prototype,"selected"),d=l.set,l.set=function set(e){d.apply(this,arguments);var t=createNewEvent("change");this.parentElement.dispatchEvent(t)},Object.defineProperty(c.prototype,"selected",l),f(),"undefined"!=typeof self.MutationObserver)new MutationObserver((function(e){e.forEach((function(e){Array.prototype.forEach.call(e.addedNodes||[],(function(e){1===e.nodeType&&isFormControlElement(e)&&s({target:e})}))}))})).observe(document,{childList:!0,subtree:!0});else{var p=function handleOnLoad(){return f()};window.addEventListener("load",p),window.addEventListener("DOMContentLoaded",p)}};
2
2
  //# sourceMappingURL=browser.cjs.map
@@ -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","/* global document,window,self,MutationObserver */\nimport isValidReplacement from './is-valid-replacement.mjs';\n\nconst CSS_CLASS_LOADED = 'js-blank-pseudo';\n\n// form control elements selector\nfunction isFormControlElement(element) {\n\tif (element.nodeName === 'INPUT' || element.nodeName === 'SELECT' || element.nodeName === 'TEXTAREA') {\n\t\treturn true;\n\t}\n\n\treturn false;\n}\n\nfunction createNewEvent(eventName) {\n\tlet event;\n\n\tif (typeof(Event) === 'function') {\n\t\tevent = new Event(eventName, { bubbles: true });\n\t} else {\n\t\tevent = document.createEvent('Event');\n\t\tevent.initEvent(eventName, true, false);\n\t}\n\n\treturn event;\n}\n\nfunction generateHandler(replaceWith) {\n\tlet selector;\n\tlet remove;\n\tlet add;\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 handleInputOrChangeEvent(event) {\n\t\tconst element = event.target;\n\t\tif (!isFormControlElement(element)) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst isSelect = element.nodeName === 'SELECT';\n\t\tconst hasValue = isSelect\n\t\t\t? !!element.options[element.selectedIndex].value\n\t\t\t: !!element.value;\n\n\t\tif (hasValue) {\n\t\t\tremove(element);\n\t\t} else {\n\t\t\tadd(element);\n\t\t}\n\t};\n}\n\n// observe changes to the \"selected\" property on an HTML Element\nfunction observeSelectedOfHTMLElement(HTMLElement) {\n\tconst descriptor = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'selected');\n\tconst nativeSet = descriptor.set;\n\n\tdescriptor.set = function set(value) { // eslint-disable-line no-unused-vars\n\t\tnativeSet.apply(this, arguments);\n\n\t\tconst event = createNewEvent('change');\n\t\tthis.parentElement.dispatchEvent(event);\n\t};\n\n\tObject.defineProperty(HTMLElement.prototype, 'selected', descriptor);\n}\n\n// observe changes to the \"value\" property on an HTML Element\nfunction observeValueOfHTMLElement(HTMLElement, handler) {\n\tconst descriptor = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'value');\n\tconst nativeSet = descriptor.set;\n\n\tdescriptor.set = function set() {\n\t\tnativeSet.apply(this, arguments);\n\t\thandler({ target: this });\n\t};\n\n\tObject.defineProperty(HTMLElement.prototype, 'value', descriptor);\n}\n\nexport default function cssBlankPseudoInit(opts) {\n\t// configuration\n\tconst options = {\n\t\tforce: false,\n\t\treplaceWith: '[blank]',\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(':blank');\n\n\t\tif (!options.force) {\n\t\t\treturn;\n\t\t}\n\t} catch (ignoredError) { /* do nothing and continue */ }\n\n\tconst handler = generateHandler(options.replaceWith);\n\tconst bindEvents = () => {\n\t\tif (document.body) {\n\t\t\tdocument.body.addEventListener('change', handler);\n\t\t\tdocument.body.addEventListener('input', handler);\n\t\t}\n\t};\n\tconst updateAllCandidates = () => {\n\t\tArray.prototype.forEach.call(\n\t\t\tdocument.querySelectorAll('input, select, textarea'),\n\t\t\tnode => {\n\t\t\t\thandler({ target: node });\n\t\t\t},\n\t\t);\n\t};\n\n\tif (document.body) {\n\t\tbindEvents();\n\t} else {\n\t\twindow.addEventListener('load', bindEvents);\n\t}\n\n\tif (document.documentElement.className.indexOf(CSS_CLASS_LOADED) === -1) {\n\t\tdocument.documentElement.className += ` ${CSS_CLASS_LOADED}`;\n\t}\n\n\tobserveValueOfHTMLElement(self.HTMLInputElement, handler);\n\tobserveValueOfHTMLElement(self.HTMLSelectElement, handler);\n\tobserveValueOfHTMLElement(self.HTMLTextAreaElement, handler);\n\tobserveSelectedOfHTMLElement(self.HTMLOptionElement, handler);\n\n\t// conditionally update all form control elements\n\tupdateAllCandidates();\n\n\tif (typeof self.MutationObserver !== 'undefined') {\n\t\t// conditionally observe added or unobserve removed form control elements\n\t\tnew MutationObserver(mutationsList => {\n\t\t\tmutationsList.forEach(mutation => {\n\t\t\t\tArray.prototype.forEach.call(\n\t\t\t\t\tmutation.addedNodes || [],\n\t\t\t\t\tnode => {\n\t\t\t\t\t\tif (node.nodeType === 1 && isFormControlElement(node)) {\n\t\t\t\t\t\t\thandler({ target: node });\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t});\n\t\t}).observe(document, { childList: true, subtree: true });\n\t} else {\n\t\tconst handleOnLoad = () => updateAllCandidates();\n\n\t\twindow.addEventListener('load', handleOnLoad);\n\t\twindow.addEventListener('DOMContentLoaded', handleOnLoad);\n\t}\n}\n"],"names":["INVALID_SELECTOR_CHAR","isFormControlElement","element","nodeName","createNewEvent","eventName","event","Event","bubbles","document","createEvent","initEvent","observeValueOfHTMLElement","HTMLElement","handler","descriptor","Object","getOwnPropertyDescriptor","prototype","nativeSet","set","apply","this","arguments","target","defineProperty","opts","options","force","replaceWith","selector","isValid","i","length","indexOf","isValidReplacement","Error","querySelector","ignoredError","remove","add","slice","el","classList","removeAttribute","setAttribute","selectedIndex","value","bindEvents","body","addEventListener","updateAllCandidates","Array","forEach","call","querySelectorAll","node","window","documentElement","className","self","HTMLInputElement","HTMLSelectElement","HTMLTextAreaElement","HTMLOptionElement","parentElement","dispatchEvent","MutationObserver","mutationsList","mutation","addedNodes","nodeType","observe","childList","subtree","handleOnLoad"],"mappings":"AAAA,IAAMA,EAAwB,CAC7B,IACA,IACA,IACA,IACA,IACA,IACA,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,IACvB,SAAAd,GACuB,IAAlBA,EAAKe,UAAkBtE,EAAqBuD,IAC/C1C,EAAQ,CAAEU,OAAQgC,SAKtB,IAAEgB,QAAQ/D,SAAU,CAAEgE,WAAW,EAAMC,SAAS,QAC3C,CACN,IAAMC,EAAe,WAAA,OAAMxB,KAE3BM,OAAOP,iBAAiB,OAAQyB,GAChClB,OAAOP,iBAAiB,mBAAoByB,EAC5C,CACD"}
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","/* global document,window,self,MutationObserver */\nimport isValidReplacement from './is-valid-replacement.mjs';\n\nconst CSS_CLASS_LOADED = 'js-blank-pseudo';\n\n// form control elements selector\nfunction isFormControlElement(element) {\n\tif (element.nodeName === 'INPUT' || element.nodeName === 'SELECT' || element.nodeName === 'TEXTAREA') {\n\t\treturn true;\n\t}\n\n\treturn false;\n}\n\nfunction createNewEvent(eventName) {\n\tlet event;\n\n\tif (typeof(Event) === 'function') {\n\t\tevent = new Event(eventName, { bubbles: true });\n\t} else {\n\t\tevent = document.createEvent('Event');\n\t\tevent.initEvent(eventName, true, false);\n\t}\n\n\treturn event;\n}\n\nfunction generateHandler(replaceWith) {\n\tlet selector;\n\tlet remove;\n\tlet add;\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 handleInputOrChangeEvent(event) {\n\t\tconst element = event.target;\n\t\tif (!isFormControlElement(element)) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst isSelect = element.nodeName === 'SELECT';\n\t\tconst hasValue = isSelect\n\t\t\t? !!element.options[element.selectedIndex].value\n\t\t\t: !!element.value;\n\n\t\tif (hasValue) {\n\t\t\tremove(element);\n\t\t} else {\n\t\t\tadd(element);\n\t\t}\n\t};\n}\n\n// observe changes to the \"selected\" property on an HTML Element\nfunction observeSelectedOfHTMLElement(HTMLElement) {\n\tconst descriptor = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'selected');\n\tconst nativeSet = descriptor.set;\n\n\tdescriptor.set = function set(value) { // eslint-disable-line no-unused-vars\n\t\tnativeSet.apply(this, arguments);\n\n\t\tconst event = createNewEvent('change');\n\t\tthis.parentElement.dispatchEvent(event);\n\t};\n\n\tObject.defineProperty(HTMLElement.prototype, 'selected', descriptor);\n}\n\n// observe changes to the \"value\" property on an HTML Element\nfunction observeValueOfHTMLElement(HTMLElement, handler) {\n\tconst descriptor = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'value');\n\tconst nativeSet = descriptor.set;\n\n\tdescriptor.set = function set() {\n\t\tnativeSet.apply(this, arguments);\n\t\thandler({ target: this });\n\t};\n\n\tObject.defineProperty(HTMLElement.prototype, 'value', descriptor);\n}\n\nexport default function cssBlankPseudoInit(opts) {\n\t// configuration\n\tconst options = {\n\t\tforce: false,\n\t\treplaceWith: '[blank]',\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(':blank');\n\n\t\tif (!options.force) {\n\t\t\treturn;\n\t\t}\n\t} catch (ignoredError) { /* do nothing and continue */ }\n\n\tconst handler = generateHandler(options.replaceWith);\n\tconst bindEvents = () => {\n\t\tif (document.body) {\n\t\t\tdocument.body.addEventListener('change', handler);\n\t\t\tdocument.body.addEventListener('input', handler);\n\t\t}\n\t};\n\tconst updateAllCandidates = () => {\n\t\tArray.prototype.forEach.call(\n\t\t\tdocument.querySelectorAll('input, select, textarea'),\n\t\t\tnode => {\n\t\t\t\thandler({ target: node });\n\t\t\t},\n\t\t);\n\t};\n\n\tif (document.body) {\n\t\tbindEvents();\n\t} else {\n\t\twindow.addEventListener('load', bindEvents);\n\t}\n\n\tif (document.documentElement.className.indexOf(CSS_CLASS_LOADED) === -1) {\n\t\tdocument.documentElement.className += ` ${CSS_CLASS_LOADED}`;\n\t}\n\n\tobserveValueOfHTMLElement(self.HTMLInputElement, handler);\n\tobserveValueOfHTMLElement(self.HTMLSelectElement, handler);\n\tobserveValueOfHTMLElement(self.HTMLTextAreaElement, handler);\n\tobserveSelectedOfHTMLElement(self.HTMLOptionElement, handler);\n\n\t// conditionally update all form control elements\n\tupdateAllCandidates();\n\n\tif (typeof self.MutationObserver !== 'undefined') {\n\t\t// conditionally observe added or unobserve removed form control elements\n\t\tnew MutationObserver(mutationsList => {\n\t\t\tmutationsList.forEach(mutation => {\n\t\t\t\tArray.prototype.forEach.call(\n\t\t\t\t\tmutation.addedNodes || [],\n\t\t\t\t\tnode => {\n\t\t\t\t\t\tif (node.nodeType === 1 && isFormControlElement(node)) {\n\t\t\t\t\t\t\thandler({ target: node });\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t});\n\t\t}).observe(document, { childList: true, subtree: true });\n\t} else {\n\t\tconst handleOnLoad = () => updateAllCandidates();\n\n\t\twindow.addEventListener('load', handleOnLoad);\n\t\twindow.addEventListener('DOMContentLoaded', handleOnLoad);\n\t}\n}\n"],"names":["INVALID_SELECTOR_CHAR","isValidReplacement","selector","isValid","i","length","indexOf","CSS_CLASS_LOADED","isFormControlElement","element","nodeName","createNewEvent","eventName","event","Event","bubbles","document","createEvent","initEvent","observeValueOfHTMLElement","HTMLElement","handler","descriptor","Object","getOwnPropertyDescriptor","prototype","nativeSet","set","apply","this","arguments","target","defineProperty","cssBlankPseudoInit","opts","options","force","replaceWith","Error","querySelector","ignoredError","remove","add","slice","el","classList","removeAttribute","setAttribute","handleInputOrChangeEvent","selectedIndex","value","bindEvents","body","addEventListener","updateAllCandidates","Array","forEach","call","querySelectorAll","node","window","documentElement","className","self","HTMLInputElement","HTMLSelectElement","HTMLTextAreaElement","HTMLOptionElement","parentElement","dispatchEvent","MutationObserver","mutationsList","mutation","addedNodes","nodeType","observe","childList","subtree","handleOnLoad"],"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,CCpBA,IAAMI,EAAmB,kBAGzB,SAASC,qBAAqBC,GAC7B,MAAyB,UAArBA,EAAQC,UAA6C,WAArBD,EAAQC,UAA8C,aAArBD,EAAQC,QAK9E,CAEA,SAASC,eAAeC,GACvB,IAAIC,EASJ,MAPsB,mBAAXC,MACVD,EAAQ,IAAIC,MAAMF,EAAW,CAAEG,SAAS,KAExCF,EAAQG,SAASC,YAAY,UACvBC,UAAUN,GAAW,GAAM,GAG3BC,CACR,CAqDA,SAASM,0BAA0BC,EAAaC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"INPUT"===e.nodeName||"SELECT"===e.nodeName||"TEXTAREA"===e.nodeName}function n(e){var t;return"function"==typeof Event?t=new Event(e,{bubbles:!0}):(t=document.createEvent("Event")).initEvent(e,!0,!1),t}function r(e,t){var n=Object.getOwnPropertyDescriptor(e.prototype,"value"),r=n.set;n.set=function(){r.apply(this,arguments),t({target:this})},Object.defineProperty(e.prototype,"value",n)}function o(o){var c={force:!1,replaceWith:"[blank]"};if(void 0!==o&&"force"in o&&(c.force=o.force),void 0!==o&&"replaceWith"in o&&(c.replaceWith=o.replaceWith),!function(t){for(var n=!0,r=0,o=e.length;r<o&&n;r++)t.indexOf(e[r])>-1&&(n=!1);return n}(c.replaceWith))throw new Error(c.replaceWith+" is not a valid replacement since it can't be applied to single elements.");try{if(document.querySelector(":blank"),!c.force)return}catch(e){}var i,a,d,l,u,s,p,f=("."===(i=c.replaceWith)[0]?(a=i.slice(1),d=function(e){return e.classList.remove(a)},l=function(e){return e.classList.add(a)}):(a=i.slice(1,-1),d=function(e){return e.removeAttribute(a,"")},l=function(e){return e.setAttribute(a,"")}),function(e){var n=e.target;t(n)&&(("SELECT"===n.nodeName?n.options[n.selectedIndex].value:n.value)?d(n):l(n))}),v=function(){document.body&&(document.body.addEventListener("change",f),document.body.addEventListener("input",f))},m=function(){Array.prototype.forEach.call(document.querySelectorAll("input, select, textarea"),(function(e){f({target:e})}))};if(document.body?v():window.addEventListener("load",v),-1===document.documentElement.className.indexOf("js-blank-pseudo")&&(document.documentElement.className+=" js-blank-pseudo"),r(self.HTMLInputElement,f),r(self.HTMLSelectElement,f),r(self.HTMLTextAreaElement,f),u=self.HTMLOptionElement,s=Object.getOwnPropertyDescriptor(u.prototype,"selected"),p=s.set,s.set=function(e){p.apply(this,arguments);var t=n("change");this.parentElement.dispatchEvent(t)},Object.defineProperty(u.prototype,"selected",s),m(),void 0!==self.MutationObserver)new MutationObserver((function(e){e.forEach((function(e){Array.prototype.forEach.call(e.addedNodes||[],(function(e){1===e.nodeType&&t(e)&&f({target:e})}))}))})).observe(document,{childList:!0,subtree:!0});else{var E=function(){return m()};window.addEventListener("load",E),window.addEventListener("DOMContentLoaded",E)}}export{o as default};
1
+ var e=[" ",">","~",":","+","@","#","(",")"];function isValidReplacement(t){for(var n=!0,r=0,o=e.length;r<o&&n;r++)t.indexOf(e[r])>-1&&(n=!1);return n}var t="js-blank-pseudo";function isFormControlElement(e){return"INPUT"===e.nodeName||"SELECT"===e.nodeName||"TEXTAREA"===e.nodeName}function createNewEvent(e){var t;return"function"==typeof Event?t=new Event(e,{bubbles:!0}):(t=document.createEvent("Event")).initEvent(e,!0,!1),t}function observeValueOfHTMLElement(e,t){var n=Object.getOwnPropertyDescriptor(e.prototype,"value"),r=n.set;n.set=function set(){r.apply(this,arguments),t({target:this})},Object.defineProperty(e.prototype,"value",n)}function cssBlankPseudoInit(e){var n={force:!1,replaceWith:"[blank]"};if(void 0!==e&&"force"in e&&(n.force=e.force),void 0!==e&&"replaceWith"in e&&(n.replaceWith=e.replaceWith),!isValidReplacement(n.replaceWith))throw new Error(n.replaceWith+" is not a valid replacement since it can't be applied to single elements.");try{if(document.querySelector(":blank"),!n.force)return}catch(m){}var r,o,a,i,c,l,d,s=("."===(r=n.replaceWith)[0]?(o=r.slice(1),a=function remove(e){return e.classList.remove(o)},i=function add(e){return e.classList.add(o)}):(o=r.slice(1,-1),a=function remove(e){return e.removeAttribute(o,"")},i=function add(e){return e.setAttribute(o,"")}),function handleInputOrChangeEvent(e){var t=e.target;isFormControlElement(t)&&(("SELECT"===t.nodeName?t.options[t.selectedIndex].value:t.value)?a(t):i(t))}),u=function bindEvents(){document.body&&(document.body.addEventListener("change",s),document.body.addEventListener("input",s))},f=function updateAllCandidates(){Array.prototype.forEach.call(document.querySelectorAll("input, select, textarea"),(function(e){s({target:e})}))};if(document.body?u():window.addEventListener("load",u),-1===document.documentElement.className.indexOf(t)&&(document.documentElement.className+=" "+t),observeValueOfHTMLElement(self.HTMLInputElement,s),observeValueOfHTMLElement(self.HTMLSelectElement,s),observeValueOfHTMLElement(self.HTMLTextAreaElement,s),c=self.HTMLOptionElement,l=Object.getOwnPropertyDescriptor(c.prototype,"selected"),d=l.set,l.set=function set(e){d.apply(this,arguments);var t=createNewEvent("change");this.parentElement.dispatchEvent(t)},Object.defineProperty(c.prototype,"selected",l),f(),"undefined"!=typeof self.MutationObserver)new MutationObserver((function(e){e.forEach((function(e){Array.prototype.forEach.call(e.addedNodes||[],(function(e){1===e.nodeType&&isFormControlElement(e)&&s({target:e})}))}))})).observe(document,{childList:!0,subtree:!0});else{var p=function handleOnLoad(){return f()};window.addEventListener("load",p),window.addEventListener("DOMContentLoaded",p)}}export{cssBlankPseudoInit as default};
2
2
  //# sourceMappingURL=browser.mjs.map
@@ -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","/* global document,window,self,MutationObserver */\nimport isValidReplacement from './is-valid-replacement.mjs';\n\nconst CSS_CLASS_LOADED = 'js-blank-pseudo';\n\n// form control elements selector\nfunction isFormControlElement(element) {\n\tif (element.nodeName === 'INPUT' || element.nodeName === 'SELECT' || element.nodeName === 'TEXTAREA') {\n\t\treturn true;\n\t}\n\n\treturn false;\n}\n\nfunction createNewEvent(eventName) {\n\tlet event;\n\n\tif (typeof(Event) === 'function') {\n\t\tevent = new Event(eventName, { bubbles: true });\n\t} else {\n\t\tevent = document.createEvent('Event');\n\t\tevent.initEvent(eventName, true, false);\n\t}\n\n\treturn event;\n}\n\nfunction generateHandler(replaceWith) {\n\tlet selector;\n\tlet remove;\n\tlet add;\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 handleInputOrChangeEvent(event) {\n\t\tconst element = event.target;\n\t\tif (!isFormControlElement(element)) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst isSelect = element.nodeName === 'SELECT';\n\t\tconst hasValue = isSelect\n\t\t\t? !!element.options[element.selectedIndex].value\n\t\t\t: !!element.value;\n\n\t\tif (hasValue) {\n\t\t\tremove(element);\n\t\t} else {\n\t\t\tadd(element);\n\t\t}\n\t};\n}\n\n// observe changes to the \"selected\" property on an HTML Element\nfunction observeSelectedOfHTMLElement(HTMLElement) {\n\tconst descriptor = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'selected');\n\tconst nativeSet = descriptor.set;\n\n\tdescriptor.set = function set(value) { // eslint-disable-line no-unused-vars\n\t\tnativeSet.apply(this, arguments);\n\n\t\tconst event = createNewEvent('change');\n\t\tthis.parentElement.dispatchEvent(event);\n\t};\n\n\tObject.defineProperty(HTMLElement.prototype, 'selected', descriptor);\n}\n\n// observe changes to the \"value\" property on an HTML Element\nfunction observeValueOfHTMLElement(HTMLElement, handler) {\n\tconst descriptor = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'value');\n\tconst nativeSet = descriptor.set;\n\n\tdescriptor.set = function set() {\n\t\tnativeSet.apply(this, arguments);\n\t\thandler({ target: this });\n\t};\n\n\tObject.defineProperty(HTMLElement.prototype, 'value', descriptor);\n}\n\nexport default function cssBlankPseudoInit(opts) {\n\t// configuration\n\tconst options = {\n\t\tforce: false,\n\t\treplaceWith: '[blank]',\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(':blank');\n\n\t\tif (!options.force) {\n\t\t\treturn;\n\t\t}\n\t} catch (ignoredError) { /* do nothing and continue */ }\n\n\tconst handler = generateHandler(options.replaceWith);\n\tconst bindEvents = () => {\n\t\tif (document.body) {\n\t\t\tdocument.body.addEventListener('change', handler);\n\t\t\tdocument.body.addEventListener('input', handler);\n\t\t}\n\t};\n\tconst updateAllCandidates = () => {\n\t\tArray.prototype.forEach.call(\n\t\t\tdocument.querySelectorAll('input, select, textarea'),\n\t\t\tnode => {\n\t\t\t\thandler({ target: node });\n\t\t\t},\n\t\t);\n\t};\n\n\tif (document.body) {\n\t\tbindEvents();\n\t} else {\n\t\twindow.addEventListener('load', bindEvents);\n\t}\n\n\tif (document.documentElement.className.indexOf(CSS_CLASS_LOADED) === -1) {\n\t\tdocument.documentElement.className += ` ${CSS_CLASS_LOADED}`;\n\t}\n\n\tobserveValueOfHTMLElement(self.HTMLInputElement, handler);\n\tobserveValueOfHTMLElement(self.HTMLSelectElement, handler);\n\tobserveValueOfHTMLElement(self.HTMLTextAreaElement, handler);\n\tobserveSelectedOfHTMLElement(self.HTMLOptionElement, handler);\n\n\t// conditionally update all form control elements\n\tupdateAllCandidates();\n\n\tif (typeof self.MutationObserver !== 'undefined') {\n\t\t// conditionally observe added or unobserve removed form control elements\n\t\tnew MutationObserver(mutationsList => {\n\t\t\tmutationsList.forEach(mutation => {\n\t\t\t\tArray.prototype.forEach.call(\n\t\t\t\t\tmutation.addedNodes || [],\n\t\t\t\t\tnode => {\n\t\t\t\t\t\tif (node.nodeType === 1 && isFormControlElement(node)) {\n\t\t\t\t\t\t\thandler({ target: node });\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t});\n\t\t}).observe(document, { childList: true, subtree: true });\n\t} else {\n\t\tconst handleOnLoad = () => updateAllCandidates();\n\n\t\twindow.addEventListener('load', handleOnLoad);\n\t\twindow.addEventListener('DOMContentLoaded', handleOnLoad);\n\t}\n}\n"],"names":["INVALID_SELECTOR_CHAR","isFormControlElement","element","nodeName","createNewEvent","eventName","event","Event","bubbles","document","createEvent","initEvent","observeValueOfHTMLElement","HTMLElement","handler","descriptor","Object","getOwnPropertyDescriptor","prototype","nativeSet","set","apply","this","arguments","target","defineProperty","cssBlankPseudoInit","opts","options","force","replaceWith","selector","isValid","i","length","indexOf","isValidReplacement","Error","querySelector","ignoredError","remove","add","slice","el","classList","removeAttribute","setAttribute","selectedIndex","value","bindEvents","body","addEventListener","updateAllCandidates","Array","forEach","call","querySelectorAll","node","window","documentElement","className","self","HTMLInputElement","HTMLSelectElement","HTMLTextAreaElement","HTMLOptionElement","parentElement","dispatchEvent","MutationObserver","mutationsList","mutation","addedNodes","nodeType","observe","childList","subtree","handleOnLoad"],"mappings":"AAAA,IAAMA,EAAwB,CAC7B,IACA,IACA,IACA,IACA,IACA,IACA,IACA,IACA,KCHD,SAASC,EAAqBC,GAC7B,MAAyB,UAArBA,EAAQC,UAA6C,WAArBD,EAAQC,UAA8C,aAArBD,EAAQC,QAK7E,CAED,SAASC,EAAeC,GACvB,IAAIC,EASJ,MAPsB,mBAAXC,MACVD,EAAQ,IAAIC,MAAMF,EAAW,CAAEG,SAAS,KAExCF,EAAQG,SAASC,YAAY,UACvBC,UAAUN,GAAW,GAAM,GAG3BC,CACP,CAqDD,SAASM,EAA0BC,EAAaC,GAC/C,IAAMC,EAAaC,OAAOC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],"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","/* global document,window,self,MutationObserver */\nimport isValidReplacement from './is-valid-replacement.mjs';\n\nconst CSS_CLASS_LOADED = 'js-blank-pseudo';\n\n// form control elements selector\nfunction isFormControlElement(element) {\n\tif (element.nodeName === 'INPUT' || element.nodeName === 'SELECT' || element.nodeName === 'TEXTAREA') {\n\t\treturn true;\n\t}\n\n\treturn false;\n}\n\nfunction createNewEvent(eventName) {\n\tlet event;\n\n\tif (typeof(Event) === 'function') {\n\t\tevent = new Event(eventName, { bubbles: true });\n\t} else {\n\t\tevent = document.createEvent('Event');\n\t\tevent.initEvent(eventName, true, false);\n\t}\n\n\treturn event;\n}\n\nfunction generateHandler(replaceWith) {\n\tlet selector;\n\tlet remove;\n\tlet add;\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 handleInputOrChangeEvent(event) {\n\t\tconst element = event.target;\n\t\tif (!isFormControlElement(element)) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst isSelect = element.nodeName === 'SELECT';\n\t\tconst hasValue = isSelect\n\t\t\t? !!element.options[element.selectedIndex].value\n\t\t\t: !!element.value;\n\n\t\tif (hasValue) {\n\t\t\tremove(element);\n\t\t} else {\n\t\t\tadd(element);\n\t\t}\n\t};\n}\n\n// observe changes to the \"selected\" property on an HTML Element\nfunction observeSelectedOfHTMLElement(HTMLElement) {\n\tconst descriptor = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'selected');\n\tconst nativeSet = descriptor.set;\n\n\tdescriptor.set = function set(value) { // eslint-disable-line no-unused-vars\n\t\tnativeSet.apply(this, arguments);\n\n\t\tconst event = createNewEvent('change');\n\t\tthis.parentElement.dispatchEvent(event);\n\t};\n\n\tObject.defineProperty(HTMLElement.prototype, 'selected', descriptor);\n}\n\n// observe changes to the \"value\" property on an HTML Element\nfunction observeValueOfHTMLElement(HTMLElement, handler) {\n\tconst descriptor = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'value');\n\tconst nativeSet = descriptor.set;\n\n\tdescriptor.set = function set() {\n\t\tnativeSet.apply(this, arguments);\n\t\thandler({ target: this });\n\t};\n\n\tObject.defineProperty(HTMLElement.prototype, 'value', descriptor);\n}\n\nexport default function cssBlankPseudoInit(opts) {\n\t// configuration\n\tconst options = {\n\t\tforce: false,\n\t\treplaceWith: '[blank]',\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(':blank');\n\n\t\tif (!options.force) {\n\t\t\treturn;\n\t\t}\n\t} catch (ignoredError) { /* do nothing and continue */ }\n\n\tconst handler = generateHandler(options.replaceWith);\n\tconst bindEvents = () => {\n\t\tif (document.body) {\n\t\t\tdocument.body.addEventListener('change', handler);\n\t\t\tdocument.body.addEventListener('input', handler);\n\t\t}\n\t};\n\tconst updateAllCandidates = () => {\n\t\tArray.prototype.forEach.call(\n\t\t\tdocument.querySelectorAll('input, select, textarea'),\n\t\t\tnode => {\n\t\t\t\thandler({ target: node });\n\t\t\t},\n\t\t);\n\t};\n\n\tif (document.body) {\n\t\tbindEvents();\n\t} else {\n\t\twindow.addEventListener('load', bindEvents);\n\t}\n\n\tif (document.documentElement.className.indexOf(CSS_CLASS_LOADED) === -1) {\n\t\tdocument.documentElement.className += ` ${CSS_CLASS_LOADED}`;\n\t}\n\n\tobserveValueOfHTMLElement(self.HTMLInputElement, handler);\n\tobserveValueOfHTMLElement(self.HTMLSelectElement, handler);\n\tobserveValueOfHTMLElement(self.HTMLTextAreaElement, handler);\n\tobserveSelectedOfHTMLElement(self.HTMLOptionElement, handler);\n\n\t// conditionally update all form control elements\n\tupdateAllCandidates();\n\n\tif (typeof self.MutationObserver !== 'undefined') {\n\t\t// conditionally observe added or unobserve removed form control elements\n\t\tnew MutationObserver(mutationsList => {\n\t\t\tmutationsList.forEach(mutation => {\n\t\t\t\tArray.prototype.forEach.call(\n\t\t\t\t\tmutation.addedNodes || [],\n\t\t\t\t\tnode => {\n\t\t\t\t\t\tif (node.nodeType === 1 && isFormControlElement(node)) {\n\t\t\t\t\t\t\thandler({ target: node });\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t});\n\t\t}).observe(document, { childList: true, subtree: true });\n\t} else {\n\t\tconst handleOnLoad = () => updateAllCandidates();\n\n\t\twindow.addEventListener('load', handleOnLoad);\n\t\twindow.addEventListener('DOMContentLoaded', handleOnLoad);\n\t}\n}\n"],"names":["INVALID_SELECTOR_CHAR","isValidReplacement","selector","isValid","i","length","indexOf","CSS_CLASS_LOADED","isFormControlElement","element","nodeName","createNewEvent","eventName","event","Event","bubbles","document","createEvent","initEvent","observeValueOfHTMLElement","HTMLElement","handler","descriptor","Object","getOwnPropertyDescriptor","prototype","nativeSet","set","apply","this","arguments","target","defineProperty","cssBlankPseudoInit","opts","options","force","replaceWith","Error","querySelector","ignoredError","remove","add","slice","el","classList","removeAttribute","setAttribute","handleInputOrChangeEvent","selectedIndex","value","bindEvents","body","addEventListener","updateAllCandidates","Array","forEach","call","querySelectorAll","node","window","documentElement","className","self","HTMLInputElement","HTMLSelectElement","HTMLTextAreaElement","HTMLOptionElement","parentElement","dispatchEvent","MutationObserver","mutationsList","mutation","addedNodes","nodeType","observe","childList","subtree","handleOnLoad"],"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,CCpBA,IAAMI,EAAmB,kBAGzB,SAASC,qBAAqBC,GAC7B,MAAyB,UAArBA,EAAQC,UAA6C,WAArBD,EAAQC,UAA8C,aAArBD,EAAQC,QAK9E,CAEA,SAASC,eAAeC,GACvB,IAAIC,EASJ,MAPsB,mBAAXC,MACVD,EAAQ,IAAIC,MAAMF,EAAW,CAAEG,SAAS,KAExCF,EAAQG,SAASC,YAAY,UACvBC,UAAUN,GAAW,GAAM,GAG3BC,CACR,CAqDA,SAASM,0BAA0BC,EAAaC,GAC/C,IAAMC,EAAaC,OAAOC,yBAAyBJ,EAAYK,UAAW,SACpEC,EAAYJ,EAAWK,IAE7BL,EAAWK,IAAM,SAASA,MACzBD,EAAUE,MAAMC,KAAMC,WACtBT,EAAQ,CAAEU,OAAQF,QAGnBN,OAAOS,eAAeZ,EAAYK,UAAW,QAASH,EACvD,CAEe,SAASW,mBAAmBC,GAE1C,IAAMC,EAAU,CACfC,OAAO,EACPC,YAAa,WAWd,QARoB,IAATH,GAAwB,UAAWA,IAC7CC,EAAQC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iBvD,GAG3CY,0BAA0B4C,KAAKC,iBAAkB3C,GACjDF,0BAA0B4C,KAAKE,kBAAmB5C,GAClDF,0BAA0B4C,KAAKG,oBAAqB7C,GAlFfD,EAmFR2C,KAAKI,kBAlF5B7C,EAAaC,OAAOC,yBAAyBJ,EAAYK,UAAW,YACpEC,EAAYJ,EAAWK,IAE7BL,EAAWK,IAAM,SAASA,IAAIuB,GAC7BxB,EAAUE,MAAMC,KAAMC,WAEtB,IAAMjB,EAAQF,eAAe,UAC7BkB,KAAKuC,cAAcC,cAAcxD,IAGlCU,OAAOS,eAAeZ,EAAYK,UAAW,WAAYH,GA2EzDgC,IAEqC,oBAA1BS,KAAKO,iBAEf,IAAIA,kBAAiB,SAAAC,GACpBA,EAAcf,SAAQ,SAAAgB,GACrBjB,MAAM9B,UAAU+B,QAAQC,KACvBe,EAASC,YAAc,IACvB,SAAAd,GACuB,IAAlBA,EAAKe,UAAkBlE,qBAAqBmD,IAC/CtC,EAAQ,CAAEU,OAAQ4B,GAEpB,GAEF,GACD,IAAGgB,QAAQ3D,SAAU,CAAE4D,WAAW,EAAMC,SAAS,QAC3C,CACN,IAAMC,EAAe,SAAfA,eAAY,OAASxB,GAAqB,EAEhDM,OAAOP,iBAAiB,OAAQyB,GAChClB,OAAOP,iBAAiB,mBAAoByB,EAC7C,CACD"}
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=e(require("postcss-selector-parser"));const l=[" ",">","~",":","+","@","#","(",")"];const n=e=>{const n=Object.assign({preserve:!0,replaceWith:"[blank]",disablePolyfillReadyClass:!1},e),t=s.default().astSync(n.replaceWith);return function(e){let s=!0;for(let n=0,t=l.length;n<t&&s;n++)e.indexOf(l[n])>-1&&(s=!1);return s}(n.replaceWith)?{postcssPlugin:"css-blank-pseudo",Rule(e,{result:l}){if(!e.selector.toLowerCase().includes(":blank"))return;const o=e.selectors.flatMap((o=>{if(!o.toLowerCase().includes(":blank"))return[o];let a;try{a=s.default().astSync(o)}catch(s){return e.warn(l,`Failed to parse selector : ${o}`),o}if(void 0===a)return[o];let r=!1;if(a.walkPseudos((e=>{":blank"===e.value.toLowerCase()&&(e.nodes&&e.nodes.length||(r=!0,e.replaceWith(t.clone({}))))})),!r)return[o];const d=a.clone();if(!n.disablePolyfillReadyClass){var u,c,i,p,f;if(null!=(u=a.nodes)&&null!=(c=u[0])&&null!=(i=c.nodes)&&i.length)for(let e=0;e<a.nodes[0].nodes.length;e++){const l=a.nodes[0].nodes[e];if("combinator"===l.type||s.default.isPseudoElement(l)){a.nodes[0].insertBefore(l,s.default.className({value:"js-blank-pseudo"}));break}if(e===a.nodes[0].nodes.length-1){a.nodes[0].append(s.default.className({value:"js-blank-pseudo"}));break}}null!=(p=a.nodes)&&null!=(f=p[0])&&f.nodes&&(d.nodes[0].prepend(s.default.combinator({value:" "})),d.nodes[0].prepend(s.default.className({value:"js-blank-pseudo"})))}return[a.toString(),d.toString()]}));o.join(",")!==e.selectors.join(",")&&(e.cloneBefore({selectors:o}),n.preserve||e.remove())}}:{postcssPlugin:"css-blank-pseudo",Once:(e,{result:s})=>{e.warn(s,`${n.replaceWith} is not a valid replacement since it can't be applied to single elements.`)}}};n.postcss=!0,module.exports=n;
1
+ "use strict";var e=require("postcss-selector-parser");const s=[" ",">","~",":","+","@","#","(",")"];function isValidReplacement(e){let n=!0;for(let l=0,t=s.length;l<t&&n;l++)e.indexOf(s[l])>-1&&(n=!1);return n}const n="js-blank-pseudo",l=":blank",creator=s=>{const t=Object.assign({preserve:!0,replaceWith:"[blank]",disablePolyfillReadyClass:!1},s),o=e().astSync(t.replaceWith);return isValidReplacement(t.replaceWith)?{postcssPlugin:"css-blank-pseudo",Rule(s,{result:r}){if(!s.selector.toLowerCase().includes(l))return;const a=s.selectors.flatMap((a=>{if(!a.toLowerCase().includes(l))return[a];let i;try{i=e().astSync(a)}catch(e){return s.warn(r,`Failed to parse selector : "${a}" with message: "${e.message}"`),[a]}if(void 0===i)return[a];let c=!1;if(i.walkPseudos((e=>{e.value.toLowerCase()===l&&(e.nodes&&e.nodes.length||(c=!0,e.replaceWith(o.clone({}))))})),!c)return[a];const d=i.clone();if(!t.disablePolyfillReadyClass){var u,p,f,m,b;if(null!=(u=i.nodes)&&null!=(p=u[0])&&null!=(f=p.nodes)&&f.length)for(let s=0;s<i.nodes[0].nodes.length;s++){const l=i.nodes[0].nodes[s];if("combinator"===l.type||e.isPseudoElement(l)){i.nodes[0].insertBefore(l,e.className({value:n}));break}if(s===i.nodes[0].nodes.length-1){i.nodes[0].append(e.className({value:n}));break}}null!=(m=i.nodes)&&null!=(b=m[0])&&b.nodes&&(d.nodes[0].prepend(e.combinator({value:" "})),d.nodes[0].prepend(e.className({value:n})))}return[i.toString(),d.toString()]}));a.join(",")!==s.selectors.join(",")&&(s.cloneBefore({selectors:a}),t.preserve||s.remove())}}:{postcssPlugin:"css-blank-pseudo",Once:(e,{result:s})=>{e.warn(s,`${t.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,7 +1,11 @@
1
1
  import type { PluginCreator } from 'postcss';
2
- declare type pluginOptions = {
2
+ /** css-blank-pseudo plugin options */
3
+ export type pluginOptions = {
4
+ /** Preserve the original notation. default: true */
3
5
  preserve?: boolean;
6
+ /** Replacement for ":blank". default: "[blank]" */
4
7
  replaceWith?: string;
8
+ /** Do not inject "js-blank-pseudo" before each selector with "[blank]". default: false */
5
9
  disablePolyfillReadyClass?: boolean;
6
10
  };
7
11
  declare const creator: PluginCreator<pluginOptions>;
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import e from"postcss-selector-parser";const s=[" ",">","~",":","+","@","#","(",")"];const n=n=>{const l=Object.assign({preserve:!0,replaceWith:"[blank]",disablePolyfillReadyClass:!1},n),o=e().astSync(l.replaceWith);return function(e){let n=!0;for(let l=0,o=s.length;l<o&&n;l++)e.indexOf(s[l])>-1&&(n=!1);return n}(l.replaceWith)?{postcssPlugin:"css-blank-pseudo",Rule(s,{result:n}){if(!s.selector.toLowerCase().includes(":blank"))return;const t=s.selectors.flatMap((t=>{if(!t.toLowerCase().includes(":blank"))return[t];let r;try{r=e().astSync(t)}catch(e){return s.warn(n,`Failed to parse selector : ${t}`),t}if(void 0===r)return[t];let a=!1;if(r.walkPseudos((e=>{":blank"===e.value.toLowerCase()&&(e.nodes&&e.nodes.length||(a=!0,e.replaceWith(o.clone({}))))})),!a)return[t];const c=r.clone();if(!l.disablePolyfillReadyClass){var i,d,u,p,f;if(null!=(i=r.nodes)&&null!=(d=i[0])&&null!=(u=d.nodes)&&u.length)for(let s=0;s<r.nodes[0].nodes.length;s++){const n=r.nodes[0].nodes[s];if("combinator"===n.type||e.isPseudoElement(n)){r.nodes[0].insertBefore(n,e.className({value:"js-blank-pseudo"}));break}if(s===r.nodes[0].nodes.length-1){r.nodes[0].append(e.className({value:"js-blank-pseudo"}));break}}null!=(p=r.nodes)&&null!=(f=p[0])&&f.nodes&&(c.nodes[0].prepend(e.combinator({value:" "})),c.nodes[0].prepend(e.className({value:"js-blank-pseudo"})))}return[r.toString(),c.toString()]}));t.join(",")!==s.selectors.join(",")&&(s.cloneBefore({selectors:t}),l.preserve||s.remove())}}:{postcssPlugin:"css-blank-pseudo",Once:(e,{result:s})=>{e.warn(s,`${l.replaceWith} is not a valid replacement since it can't be applied to single elements.`)}}};n.postcss=!0;export{n as default};
1
+ import e from"postcss-selector-parser";const s=[" ",">","~",":","+","@","#","(",")"];function isValidReplacement(e){let n=!0;for(let l=0,t=s.length;l<t&&n;l++)e.indexOf(s[l])>-1&&(n=!1);return n}const n="js-blank-pseudo",l=":blank",creator=s=>{const t=Object.assign({preserve:!0,replaceWith:"[blank]",disablePolyfillReadyClass:!1},s),o=e().astSync(t.replaceWith);return isValidReplacement(t.replaceWith)?{postcssPlugin:"css-blank-pseudo",Rule(s,{result:a}){if(!s.selector.toLowerCase().includes(l))return;const r=s.selectors.flatMap((r=>{if(!r.toLowerCase().includes(l))return[r];let i;try{i=e().astSync(r)}catch(e){return s.warn(a,`Failed to parse selector : "${r}" with message: "${e.message}"`),[r]}if(void 0===i)return[r];let c=!1;if(i.walkPseudos((e=>{e.value.toLowerCase()===l&&(e.nodes&&e.nodes.length||(c=!0,e.replaceWith(o.clone({}))))})),!c)return[r];const d=i.clone();if(!t.disablePolyfillReadyClass){var u,p,f,m,b;if(null!=(u=i.nodes)&&null!=(p=u[0])&&null!=(f=p.nodes)&&f.length)for(let s=0;s<i.nodes[0].nodes.length;s++){const l=i.nodes[0].nodes[s];if("combinator"===l.type||e.isPseudoElement(l)){i.nodes[0].insertBefore(l,e.className({value:n}));break}if(s===i.nodes[0].nodes.length-1){i.nodes[0].append(e.className({value:n}));break}}null!=(m=i.nodes)&&null!=(b=m[0])&&b.nodes&&(d.nodes[0].prepend(e.combinator({value:" "})),d.nodes[0].prepend(e.className({value:n})))}return[i.toString(),d.toString()]}));r.join(",")!==s.selectors.join(",")&&(s.cloneBefore({selectors:r}),t.preserve||s.remove())}}:{postcssPlugin:"css-blank-pseudo",Once:(e,{result:s})=>{e.warn(s,`${t.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": "css-blank-pseudo",
3
3
  "description": "Style form elements when they are empty",
4
- "version": "4.1.1",
4
+ "version": "5.0.0",
5
5
  "contributors": [
6
6
  {
7
7
  "name": "Antonio Laguna",
@@ -23,7 +23,7 @@
23
23
  "url": "https://opencollective.com/csstools"
24
24
  },
25
25
  "engines": {
26
- "node": "^12 || ^14 || >=16"
26
+ "node": "^14 || ^16 || >=18"
27
27
  },
28
28
  "main": "dist/index.cjs",
29
29
  "module": "dist/index.mjs",
@@ -53,14 +53,15 @@
53
53
  "postcss-selector-parser": "^6.0.10"
54
54
  },
55
55
  "peerDependencies": {
56
- "postcss": "^8.2"
56
+ "postcss": "^8.4"
57
57
  },
58
58
  "devDependencies": {
59
- "puppeteer": "^16.0.0"
59
+ "puppeteer": "^19.5.2"
60
60
  },
61
61
  "scripts": {
62
- "build": "rollup -c ../../rollup/default.js",
63
- "clean": "node -e \"fs.rmSync('./dist', { recursive: true, force: true });\"",
62
+ "prebuild": "npm run clean",
63
+ "build": "rollup -c ../../rollup/default.mjs",
64
+ "clean": "node -e \"fs.rmSync('./dist', { recursive: true, force: true }); fs.mkdirSync('./dist');\"",
64
65
  "docs": "node ../../.github/bin/generate-docs/install.mjs && node ../../.github/bin/generate-docs/readme.mjs",
65
66
  "lint": "npm run lint:eslint && npm run lint:package-json",
66
67
  "lint:eslint": "eslint ./src --ext .js --ext .ts --ext .mjs --no-error-on-unmatched-pattern",