css-blank-pseudo 8.0.0 → 8.0.2

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,10 +1,9 @@
1
1
  # Changes to CSS Blank Pseudo
2
2
 
3
- ### 8.0.0
3
+ ### 8.0.2
4
4
 
5
- _January 14, 2026_
5
+ _July 22, 2026_
6
6
 
7
- - Updated: Support for Node `20.19.0` or later (major).
8
- - Removed: `commonjs` API. In supported Node versions `require(esm)` will work without needing to make code changes.
7
+ - Rewritten browser polyfill as ES3
9
8
 
10
9
  [Full CHANGELOG](https://github.com/csstools/postcss-plugins/tree/main/plugins/css-blank-pseudo/CHANGELOG.md)
package/README.md CHANGED
@@ -136,7 +136,7 @@ or
136
136
 
137
137
  ```html
138
138
  <!-- When using a CDN url you will have to manually update the version number -->
139
- <script src="https://unpkg.com/css-blank-pseudo@8.0.0/dist/browser-global.js"></script>
139
+ <script src="https://unpkg.com/css-blank-pseudo@8.0.2/dist/browser-global.js"></script>
140
140
  <script>cssBlankPseudoInit()</script>
141
141
  ```
142
142
 
@@ -1,2 +1,2 @@
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,n=e.target;isFormControlElement(n)&&(("SELECT"===n.nodeName?null!=(t=n.options[n.selectedIndex])&&t.value:n.value)?a(n):i(n))}),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}();
1
+ !function(){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 t={force:!1,replaceWith:"[blank]"};void 0!==e&&"force"in e&&(t.force=e.force),void 0!==e&&"replaceWith"in e&&(t.replaceWith=e.replaceWith);try{if(document.querySelector(":blank"),!t.force)return}catch(f){}var n,o,r,d,a,s,c,i=("."===(n=t.replaceWith)[0]?(o=n.slice(1),r=function remove(e){e.classList.remove(o)},d=function add(e){e.classList.add(o)}):(o=n.slice(1,-1),r=function remove(e){e.removeAttribute(o,"")},d=function add(e){e.setAttribute(o,"")}),function handleInputOrChangeEvent(e){var t=e.target;isFormControlElement(t)&&(("SELECT"===t.nodeName?t.options[t.selectedIndex]&&t.options[t.selectedIndex].value:t.value)?r(t):d(t))}),l=function bindEvents(){document.body&&(document.body.addEventListener("change",i),document.body.addEventListener("input",i))},u=function updateAllCandidates(){for(var e=document.querySelectorAll("input, select, textarea"),t=0;t<e.length;t++)i({target:e[t]})};document.body?l():window.addEventListener("load",l),-1===document.documentElement.className.indexOf("js-blank-pseudo")&&(document.documentElement.className+=" js-blank-pseudo"),observeValueOfHTMLElement(self.HTMLInputElement,i),observeValueOfHTMLElement(self.HTMLSelectElement,i),observeValueOfHTMLElement(self.HTMLTextAreaElement,i),a=self.HTMLOptionElement,s=Object.getOwnPropertyDescriptor(a.prototype,"selected"),c=s.set,s.set=function set(e){c.apply(this,arguments);var t=createNewEvent("change");this.parentElement.dispatchEvent(t)},Object.defineProperty(a.prototype,"selected",s),u(),"undefined"!=typeof self.MutationObserver?new MutationObserver(function(e){for(var t=0;t<e.length;t++)for(var n=e[t],o=0;o<n.addedNodes.length;o++){var r=n.addedNodes[o];1===r.nodeType&&isFormControlElement(r)&&i({target:r})}}).observe(document,{childList:!0,subtree:!0}):(window.addEventListener("load",u),window.addEventListener("DOMContentLoaded",u))}("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","import 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 (_) {}\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);\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","import { 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","_","remove","add","slice","el","classList","removeAttribute","setAttribute","handleInputOrChangeEvent","_element$options$elem","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,KAAM,IAChDD,GAAU,GAIZ,OAAOA,CACR,CCrBA,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,UAA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AAqBA"}
1
+ {"version":3,"file":"browser-global.js","sources":["../src/browser.js","../src/browser-global.js"],"sourcesContent":["// 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\tvar 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\tvar selector;\n\tvar remove;\n\tvar add;\n\n\tif (replaceWith[0] === '.') {\n\t\tselector = replaceWith.slice(1);\n\t\tremove = function remove(el) {\n\t\t\tel.classList.remove(selector);\n\t\t};\n\n\t\tadd = function add(el) {\n\t\t\tel.classList.add(selector);\n\t\t};\n\t} else {\n\t\t// A bit naive\n\t\tselector = replaceWith.slice(1, -1);\n\n\t\tremove = function remove(el) {\n\t\t\tel.removeAttribute(selector, '');\n\t\t};\n\n\t\tadd = function add(el) {\n\t\t\tel.setAttribute(selector, '');\n\t\t};\n\t}\n\n\treturn function handleInputOrChangeEvent(event) {\n\t\tvar element = event.target;\n\t\tif (!isFormControlElement(element)) {\n\t\t\treturn;\n\t\t}\n\n\t\tvar isSelect = element.nodeName === 'SELECT';\n\t\tvar hasValue = isSelect\n\t\t\t? (element.options[element.selectedIndex] && !!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\tvar descriptor = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'selected');\n\tvar 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\tvar 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\tvar descriptor = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'value');\n\tvar 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\tvar 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\ttry {\n\t\tdocument.querySelector(':blank');\n\n\t\tif (!options.force) {\n\t\t\treturn;\n\t\t}\n\t} catch (_) {}\n\n\tvar handler = generateHandler(options.replaceWith);\n\tvar bindEvents = function 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\tvar updateAllCandidates = function updateAllCandidates() {\n\t\tvar elements = document.querySelectorAll('input, select, textarea');\n\n\t\tfor (var i = 0; i < elements.length; i++) {\n\t\t\thandler({ target: elements[i] });\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('js-blank-pseudo') === -1) {\n\t\tdocument.documentElement.className += ' js-blank-pseudo';\n\t}\n\n\tobserveValueOfHTMLElement(self.HTMLInputElement, handler);\n\tobserveValueOfHTMLElement(self.HTMLSelectElement, handler);\n\tobserveValueOfHTMLElement(self.HTMLTextAreaElement, handler);\n\tobserveSelectedOfHTMLElement(self.HTMLOptionElement);\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(function (mutationsList) {\n\t\t\tfor (var j = 0; j < mutationsList.length; j++) {\n\t\t\t\tvar mutation = mutationsList[j];\n\n\t\t\t\tfor (var k = 0; k < mutation.addedNodes.length; k++) {\n\t\t\t\t\tvar node = mutation.addedNodes[k];\n\n\t\t\t\t\tif (node.nodeType === 1 && isFormControlElement(node)) {\n\t\t\t\t\t\thandler({ target: node });\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\twindow.addEventListener('load', updateAllCandidates);\n\t\twindow.addEventListener('DOMContentLoaded', updateAllCandidates);\n\t}\n}\n","import { default as cssBlankPseudoInit } from './browser';\n\n(function (global) {\n\tglobal.cssBlankPseudoInit = cssBlankPseudoInit;\n}('object' === typeof window && window || 'object' === typeof self && self || {}));\n"],"names":["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","querySelector","_","selector","remove","add","slice","el","classList","removeAttribute","setAttribute","handleInputOrChangeEvent","selectedIndex","value","bindEvents","body","addEventListener","updateAllCandidates","elements","querySelectorAll","i","length","window","documentElement","className","indexOf","self","HTMLInputElement","HTMLSelectElement","HTMLTextAreaElement","HTMLOptionElement","parentElement","dispatchEvent","MutationObserver","mutationsList","j","mutation","k","addedNodes","node","nodeType","observe","childList","subtree"],"mappings":"YACA,SAASA,qBAAqBC,GAC7B,MAAyB,UAArBA,EAAQC,UAA6C,WAArBD,EAAQC,UAA8C,aAArBD,EAAQC,QAK9E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SAAU,CAAE+D,WAAW,EAAMC,SAAS,KAEjDrB,OAAON,iBAAiB,OAAQC,GAChCK,OAAON,iBAAiB,mBAAoBC,GAE9C,ECvKE,iBAAoBK,QAAUA,QAAU,iBAAoBI,MAAQA,MAAQ,IADtE9B,mBAAqBA"}
package/dist/browser.cjs CHANGED
@@ -1,2 +1,2 @@
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,l,c,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,n=e.target;isFormControlElement(n)&&(("SELECT"===n.nodeName?null!=(t=n.options[n.selectedIndex])&&t.value:n.value)?a(n):i(n))}),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),l=self.HTMLOptionElement,c=Object.getOwnPropertyDescriptor(l.prototype,"selected"),d=c.set,c.set=function set(e){d.apply(this,arguments);var t=createNewEvent("change");this.parentElement.dispatchEvent(t)},Object.defineProperty(l.prototype,"selected",c),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)}};
1
+ 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)}module.exports=function cssBlankPseudoInit(e){var t={force:!1,replaceWith:"[blank]"};void 0!==e&&"force"in e&&(t.force=e.force),void 0!==e&&"replaceWith"in e&&(t.replaceWith=e.replaceWith);try{if(document.querySelector(":blank"),!t.force)return}catch(v){}var n,o,r,d,a,l,s,c=("."===(n=t.replaceWith)[0]?(o=n.slice(1),r=function remove(e){e.classList.remove(o)},d=function add(e){e.classList.add(o)}):(o=n.slice(1,-1),r=function remove(e){e.removeAttribute(o,"")},d=function add(e){e.setAttribute(o,"")}),function handleInputOrChangeEvent(e){var t=e.target;isFormControlElement(t)&&(("SELECT"===t.nodeName?t.options[t.selectedIndex]&&t.options[t.selectedIndex].value:t.value)?r(t):d(t))}),i=function bindEvents(){document.body&&(document.body.addEventListener("change",c),document.body.addEventListener("input",c))},u=function updateAllCandidates(){for(var e=document.querySelectorAll("input, select, textarea"),t=0;t<e.length;t++)c({target:e[t]})};document.body?i():window.addEventListener("load",i),-1===document.documentElement.className.indexOf("js-blank-pseudo")&&(document.documentElement.className+=" js-blank-pseudo"),observeValueOfHTMLElement(self.HTMLInputElement,c),observeValueOfHTMLElement(self.HTMLSelectElement,c),observeValueOfHTMLElement(self.HTMLTextAreaElement,c),a=self.HTMLOptionElement,l=Object.getOwnPropertyDescriptor(a.prototype,"selected"),s=l.set,l.set=function set(e){s.apply(this,arguments);var t=createNewEvent("change");this.parentElement.dispatchEvent(t)},Object.defineProperty(a.prototype,"selected",l),u(),"undefined"!=typeof self.MutationObserver?new MutationObserver(function(e){for(var t=0;t<e.length;t++)for(var n=e[t],o=0;o<n.addedNodes.length;o++){var r=n.addedNodes[o];1===r.nodeType&&isFormControlElement(r)&&c({target:r})}}).observe(document,{childList:!0,subtree:!0}):(window.addEventListener("load",u),window.addEventListener("DOMContentLoaded",u))};
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","import 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 (_) {}\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);\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","_","remove","add","slice","el","classList","removeAttribute","setAttribute","handleInputOrChangeEvent","_element$options$elem","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,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oBAA1BS,KAAKO,iBAEf,IAAIA,iBAAiB,SAAAC,GACpBA,EAAcf,QAAQ,SAAAgB,GACrBjB,MAAM/B,UAAUgC,QAAQC,KACvBe,EAASC,YAAc,GACvB,SAAAd,GACuB,IAAlBA,EAAKe,UAAkBnE,qBAAqBoD,IAC/CvC,EAAQ,CAAEU,OAAQ6B,GAEpB,EAEF,EACD,GAAGgB,QAAQ5D,SAAU,CAAE6D,WAAW,EAAMC,SAAS,QAC3C,CACN,IAAMC,EAAe,SAAfA,eAAY,OAASxB,GAAqB,EAEhDM,OAAOP,iBAAiB,OAAQyB,GAChClB,OAAOP,iBAAiB,mBAAoByB,EAC7C,CACD"}
1
+ {"version":3,"file":"browser.cjs","sources":["../src/browser.js"],"sourcesContent":["// 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\tvar 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\tvar selector;\n\tvar remove;\n\tvar add;\n\n\tif (replaceWith[0] === '.') {\n\t\tselector = replaceWith.slice(1);\n\t\tremove = function remove(el) {\n\t\t\tel.classList.remove(selector);\n\t\t};\n\n\t\tadd = function add(el) {\n\t\t\tel.classList.add(selector);\n\t\t};\n\t} else {\n\t\t// A bit naive\n\t\tselector = replaceWith.slice(1, -1);\n\n\t\tremove = function remove(el) {\n\t\t\tel.removeAttribute(selector, '');\n\t\t};\n\n\t\tadd = function add(el) {\n\t\t\tel.setAttribute(selector, '');\n\t\t};\n\t}\n\n\treturn function handleInputOrChangeEvent(event) {\n\t\tvar element = event.target;\n\t\tif (!isFormControlElement(element)) {\n\t\t\treturn;\n\t\t}\n\n\t\tvar isSelect = element.nodeName === 'SELECT';\n\t\tvar hasValue = isSelect\n\t\t\t? (element.options[element.selectedIndex] && !!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\tvar descriptor = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'selected');\n\tvar 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\tvar 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\tvar descriptor = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'value');\n\tvar 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\tvar 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\ttry {\n\t\tdocument.querySelector(':blank');\n\n\t\tif (!options.force) {\n\t\t\treturn;\n\t\t}\n\t} catch (_) {}\n\n\tvar handler = generateHandler(options.replaceWith);\n\tvar bindEvents = function 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\tvar updateAllCandidates = function updateAllCandidates() {\n\t\tvar elements = document.querySelectorAll('input, select, textarea');\n\n\t\tfor (var i = 0; i < elements.length; i++) {\n\t\t\thandler({ target: elements[i] });\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('js-blank-pseudo') === -1) {\n\t\tdocument.documentElement.className += ' js-blank-pseudo';\n\t}\n\n\tobserveValueOfHTMLElement(self.HTMLInputElement, handler);\n\tobserveValueOfHTMLElement(self.HTMLSelectElement, handler);\n\tobserveValueOfHTMLElement(self.HTMLTextAreaElement, handler);\n\tobserveSelectedOfHTMLElement(self.HTMLOptionElement);\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(function (mutationsList) {\n\t\t\tfor (var j = 0; j < mutationsList.length; j++) {\n\t\t\t\tvar mutation = mutationsList[j];\n\n\t\t\t\tfor (var k = 0; k < mutation.addedNodes.length; k++) {\n\t\t\t\t\tvar node = mutation.addedNodes[k];\n\n\t\t\t\t\tif (node.nodeType === 1 && isFormControlElement(node)) {\n\t\t\t\t\t\thandler({ target: node });\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\twindow.addEventListener('load', updateAllCandidates);\n\t\twindow.addEventListener('DOMContentLoaded', updateAllCandidates);\n\t}\n}\n"],"names":["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","querySelector","_","selector","remove","add","slice","el","classList","removeAttribute","setAttribute","handleInputOrChangeEvent","selectedIndex","value","bindEvents","body","addEventListener","updateAllCandidates","elements","querySelectorAll","i","length","window","documentElement","className","indexOf","self","HTMLInputElement","HTMLSelectElement","HTMLTextAreaElement","HTMLOptionElement","parentElement","dispatchEvent","MutationObserver","mutationsList","j","mutation","k","addedNodes","node","nodeType","observe","childList","subtree"],"mappings":"AACA,SAASA,qBAAqBC,GAC7B,MAAyB,UAArBA,EAAQC,UAA6C,WAArBD,EAAQC,UAA8C,aAArBD,EAAQC,QAK9E,CAEA,SAASC,eAAeC,GACvB,IAAIC,EASJ,MAPsB,mBAAlB,MACHA,EAAQ,IAAIC,MAAMF,EAAW,CAAEG,SAAS,KAExCF,EAAQG,SAASC,YAAY,UACvBC,UAAUN,GAAW,GAAM,GAG3BC,CACR,CAgEA,SAASM,0BAA0BC,EAAaC,GAC/C,IAAIC,EAAaC,OAAOC,yBAAyBJ,EAAYK,UAAW,SACpEC,EAAYJ,EAAWK,IAE3BL,EAAWK,IAAM,SAASA,MACzBD,EAAUE,MAAMC,KAAMC,WACtBT,EAAQ,CAAEU,OAAQF,MACnB,EAEAN,OAAOS,eAAeZ,EAAYK,UAAW,QAASH,EACvD,gBAEe,SAASW,mBAAmBC,GAE1C,IAAIC,EAAU,CACbC,OAAO,EACPC,YAAa,gBAGM,IAATH,GAAwB,UAAWA,IAC7CC,EAAQC,MAAQF,EAAKE,YAGF,IAATF,GAAwB,gBAAiBA,IACnDC,EAAQE,YAAcH,EAAKG,aAG5B,IAGC,GAFArB,SAASsB,cAAc,WAElBH,EAAQC,MACZ,MAEF,CAAE,MAAOG,GAAI,CAEb,IAjGwBF,EACpBG,EACAC,EACAC,EA4CiCtB,EACjCE,EACAI,EAgDAL,GA5FmB,OALCgB,EAiGMF,EAAQE,aA5FtB,IACfG,EAAWH,EAAYM,MAAM,GAC7BF,EAAS,SAASA,OAAOG,GACxBA,EAAGC,UAAUJ,OAAOD,EACrB,EAEAE,EAAM,SAASA,IAAIE,GAClBA,EAAGC,UAAUH,IAAIF,EAClB,IAGAA,EAAWH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,GAC9B,IAAK,IAAIC,EAAI,EAAGA,EAAID,EAAcb,OAAQc,IAGzC,IAFA,IAAIC,EAAWF,EAAcC,GAEpBE,EAAI,EAAGA,EAAID,EAASE,WAAWjB,OAAQgB,IAAK,CACpD,IAAIE,EAAOH,EAASE,WAAWD,GAET,IAAlBE,EAAKC,UAAkBrE,qBAAqBoE,IAC/CvD,EAAQ,CAAEU,OAAQ6C,GAEpB,CAEF,GAAGE,QAAQ9D,SAAU,CAAE+D,WAAW,EAAMC,SAAS,KAEjDrB,OAAON,iBAAiB,OAAQC,GAChCK,OAAON,iBAAiB,mBAAoBC,GAE9C"}
package/dist/browser.mjs CHANGED
@@ -1,2 +1,2 @@
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,l,c,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,n=e.target;isFormControlElement(n)&&(("SELECT"===n.nodeName?null!=(t=n.options[n.selectedIndex])&&t.value:n.value)?a(n):i(n))}),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),l=self.HTMLOptionElement,c=Object.getOwnPropertyDescriptor(l.prototype,"selected"),d=c.set,c.set=function set(e){d.apply(this,arguments);var t=createNewEvent("change");this.parentElement.dispatchEvent(t)},Object.defineProperty(l.prototype,"selected",c),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};
1
+ 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 t={force:!1,replaceWith:"[blank]"};void 0!==e&&"force"in e&&(t.force=e.force),void 0!==e&&"replaceWith"in e&&(t.replaceWith=e.replaceWith);try{if(document.querySelector(":blank"),!t.force)return}catch(v){}var n,o,r,a,d,s,l,c=("."===(n=t.replaceWith)[0]?(o=n.slice(1),r=function remove(e){e.classList.remove(o)},a=function add(e){e.classList.add(o)}):(o=n.slice(1,-1),r=function remove(e){e.removeAttribute(o,"")},a=function add(e){e.setAttribute(o,"")}),function handleInputOrChangeEvent(e){var t=e.target;isFormControlElement(t)&&(("SELECT"===t.nodeName?t.options[t.selectedIndex]&&t.options[t.selectedIndex].value:t.value)?r(t):a(t))}),i=function bindEvents(){document.body&&(document.body.addEventListener("change",c),document.body.addEventListener("input",c))},u=function updateAllCandidates(){for(var e=document.querySelectorAll("input, select, textarea"),t=0;t<e.length;t++)c({target:e[t]})};document.body?i():window.addEventListener("load",i),-1===document.documentElement.className.indexOf("js-blank-pseudo")&&(document.documentElement.className+=" js-blank-pseudo"),observeValueOfHTMLElement(self.HTMLInputElement,c),observeValueOfHTMLElement(self.HTMLSelectElement,c),observeValueOfHTMLElement(self.HTMLTextAreaElement,c),d=self.HTMLOptionElement,s=Object.getOwnPropertyDescriptor(d.prototype,"selected"),l=s.set,s.set=function set(e){l.apply(this,arguments);var t=createNewEvent("change");this.parentElement.dispatchEvent(t)},Object.defineProperty(d.prototype,"selected",s),u(),"undefined"!=typeof self.MutationObserver?new MutationObserver(function(e){for(var t=0;t<e.length;t++)for(var n=e[t],o=0;o<n.addedNodes.length;o++){var r=n.addedNodes[o];1===r.nodeType&&isFormControlElement(r)&&c({target:r})}}).observe(document,{childList:!0,subtree:!0}):(window.addEventListener("load",u),window.addEventListener("DOMContentLoaded",u))}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","import 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 (_) {}\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);\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","_","remove","add","slice","el","classList","removeAttribute","setAttribute","handleInputOrChangeEvent","_element$options$elem","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,KAAM,IAChDD,GAAU,GAIZ,OAAOA,CACR,CCrBA,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,MACnB,EAEAN,OAAOS,eAAeZ,EAAYK,UAAW,QAASH,EACvD,CAEe,SAASW,mBAAmBC,GAE1C,IAAMC,EAAU,CACfC,OAAO,EACPC,YAAa,WAWd,QARoB,IAATH,GAAwB,UAAWA,IAC7CC,EAAQC,MAAQF,EAAKE,YAGF,IAATF,GAAwB,gBAAiBA,IACnDC,EAAQE,YAAcH,EAAKG,cAGvBpC,mBAAmBkC,EAAQE,aAC/B,MAAM,IAAIC,MAASH,EAAQE,yFAG5B,IAGC,GAFArB,SAASuB,cAAc,WAElBJ,EAAQC,MACZ,MAEF,CAAE,MAAOI,GAAI,CAEb,IA1FwBH,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yBJ,EAAYK,UAAW,YACpEC,EAAYJ,EAAWK,IAE7BL,EAAWK,IAAM,SAASA,IAAIwB,GAC7BzB,EAAUE,MAAMC,KAAMC,WAEtB,IAAMjB,EAAQF,eAAe,UAC7BkB,KAAKwC,cAAcC,cAAczD,EAClC,EAEAU,OAAOS,eAAeZ,EAAYK,UAAW,WAAYH,GA2EzDiC,IAEqC,oBAA1BS,KAAKO,iBAEf,IAAIA,iBAAiB,SAAAC,GACpBA,EAAcf,QAAQ,SAAAgB,GACrBjB,MAAM/B,UAAUgC,QAAQC,KACvBe,EAASC,YAAc,GACvB,SAAAd,GACuB,IAAlBA,EAAKe,UAAkBnE,qBAAqBoD,IAC/CvC,EAAQ,CAAEU,OAAQ6B,GAEpB,EAEF,EACD,GAAGgB,QAAQ5D,SAAU,CAAE6D,WAAW,EAAMC,SAAS,QAC3C,CACN,IAAMC,EAAe,SAAfA,eAAY,OAASxB,GAAqB,EAEhDM,OAAOP,iBAAiB,OAAQyB,GAChClB,OAAOP,iBAAiB,mBAAoByB,EAC7C,CACD"}
1
+ {"version":3,"file":"browser.mjs","sources":["../src/browser.js"],"sourcesContent":["// 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\tvar 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\tvar selector;\n\tvar remove;\n\tvar add;\n\n\tif (replaceWith[0] === '.') {\n\t\tselector = replaceWith.slice(1);\n\t\tremove = function remove(el) {\n\t\t\tel.classList.remove(selector);\n\t\t};\n\n\t\tadd = function add(el) {\n\t\t\tel.classList.add(selector);\n\t\t};\n\t} else {\n\t\t// A bit naive\n\t\tselector = replaceWith.slice(1, -1);\n\n\t\tremove = function remove(el) {\n\t\t\tel.removeAttribute(selector, '');\n\t\t};\n\n\t\tadd = function add(el) {\n\t\t\tel.setAttribute(selector, '');\n\t\t};\n\t}\n\n\treturn function handleInputOrChangeEvent(event) {\n\t\tvar element = event.target;\n\t\tif (!isFormControlElement(element)) {\n\t\t\treturn;\n\t\t}\n\n\t\tvar isSelect = element.nodeName === 'SELECT';\n\t\tvar hasValue = isSelect\n\t\t\t? (element.options[element.selectedIndex] && !!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\tvar descriptor = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'selected');\n\tvar 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\tvar 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\tvar descriptor = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'value');\n\tvar 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\tvar 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\ttry {\n\t\tdocument.querySelector(':blank');\n\n\t\tif (!options.force) {\n\t\t\treturn;\n\t\t}\n\t} catch (_) {}\n\n\tvar handler = generateHandler(options.replaceWith);\n\tvar bindEvents = function 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\tvar updateAllCandidates = function updateAllCandidates() {\n\t\tvar elements = document.querySelectorAll('input, select, textarea');\n\n\t\tfor (var i = 0; i < elements.length; i++) {\n\t\t\thandler({ target: elements[i] });\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('js-blank-pseudo') === -1) {\n\t\tdocument.documentElement.className += ' js-blank-pseudo';\n\t}\n\n\tobserveValueOfHTMLElement(self.HTMLInputElement, handler);\n\tobserveValueOfHTMLElement(self.HTMLSelectElement, handler);\n\tobserveValueOfHTMLElement(self.HTMLTextAreaElement, handler);\n\tobserveSelectedOfHTMLElement(self.HTMLOptionElement);\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(function (mutationsList) {\n\t\t\tfor (var j = 0; j < mutationsList.length; j++) {\n\t\t\t\tvar mutation = mutationsList[j];\n\n\t\t\t\tfor (var k = 0; k < mutation.addedNodes.length; k++) {\n\t\t\t\t\tvar node = mutation.addedNodes[k];\n\n\t\t\t\t\tif (node.nodeType === 1 && isFormControlElement(node)) {\n\t\t\t\t\t\thandler({ target: node });\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\twindow.addEventListener('load', updateAllCandidates);\n\t\twindow.addEventListener('DOMContentLoaded', updateAllCandidates);\n\t}\n}\n"],"names":["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","querySelector","_","selector","remove","add","slice","el","classList","removeAttribute","setAttribute","handleInputOrChangeEvent","selectedIndex","value","bindEvents","body","addEventListener","updateAllCandidates","elements","querySelectorAll","i","length","window","documentElement","className","indexOf","self","HTMLInputElement","HTMLSelectElement","HTMLTextAreaElement","HTMLOptionElement","parentElement","dispatchEvent","MutationObserver","mutationsList","j","mutation","k","addedNodes","node","nodeType","observe","childList","subtree"],"mappings":"AACA,SAASA,qBAAqBC,GAC7B,MAAyB,UAArBA,EAAQC,UAA6C,WAArBD,EAAQC,UAA8C,aAArBD,EAAQC,QAK9E,CAEA,SAASC,eAAeC,GACvB,IAAIC,EASJ,MAPsB,mBAAlB,MACHA,EAAQ,IAAIC,MAAMF,EAAW,CAAEG,SAAS,KAExCF,EAAQG,SAASC,YAAY,UACvBC,UAAUN,GAAW,GAAM,GAG3BC,CACR,CAgEA,SAASM,0BAA0BC,EAAaC,GAC/C,IAAIC,EAAaC,OAAOC,yBAAyBJ,EAAYK,UAAW,SACpEC,EAAYJ,EAAWK,IAE3BL,EAAWK,IAAM,SAASA,MACzBD,EAAUE,MAAMC,KAAMC,WACtBT,EAAQ,CAAEU,OAAQF,MACnB,EAEAN,OAAOS,eAAeZ,EAAYK,UAAW,QAASH,EACvD,CAEe,SAASW,mBAAmBC,GAE1C,IAAIC,EAAU,CACbC,OAAO,EACPC,YAAa,gBAGM,IAATH,GAAwB,UAAWA,IAC7CC,EAAQC,MAAQF,EAAKE,YAGF,IAATF,GAAwB,gBAAiBA,IACnDC,EAAQE,YAAcH,EAAKG,aAG5B,IAGC,GAFArB,SAASsB,cAAc,WAElBH,EAAQC,MACZ,MAEF,CAAE,MAAOG,GAAI,CAEb,IAjGwBF,EACpBG,EACAC,EACAC,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L,EAAWK,IAAM,SAASA,IAAIuB,GAC7BxB,EAAUE,MAAMC,KAAMC,WAEtB,IAAIjB,EAAQF,eAAe,UAC3BkB,KAAKuC,cAAcC,cAAcxD,EAClC,EAEAU,OAAOS,eAAeZ,EAAYK,UAAW,WAAYH,GAsEzDgC,IAEqC,oBAA1BS,KAAKO,iBAEf,IAAIA,iBAAiB,SAAUC,GAC9B,IAAK,IAAIC,EAAI,EAAGA,EAAID,EAAcb,OAAQc,IAGzC,IAFA,IAAIC,EAAWF,EAAcC,GAEpBE,EAAI,EAAGA,EAAID,EAASE,WAAWjB,OAAQgB,IAAK,CACpD,IAAIE,EAAOH,EAASE,WAAWD,GAET,IAAlBE,EAAKC,UAAkBrE,qBAAqBoE,IAC/CvD,EAAQ,CAAEU,OAAQ6C,GAEpB,CAEF,GAAGE,QAAQ9D,SAAU,CAAE+D,WAAW,EAAMC,SAAS,KAEjDrB,OAAON,iBAAiB,OAAQC,GAChCK,OAAON,iBAAiB,mBAAoBC,GAE9C"}
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import e from"postcss-selector-parser";const s=[" ",">","~",":","+","@","#","(",")"];function isValidReplacement(e){let n=!0;for(let t=0,o=s.length;t<o&&n;t++)e.indexOf(s[t])>-1&&(n=!1);return n}const n="js-blank-pseudo",t=":blank",creator=s=>{const o=Object.assign({preserve:!0,replaceWith:"[blank]",disablePolyfillReadyClass:!1},s),r=e().astSync(o.replaceWith);return isValidReplacement(o.replaceWith)?{postcssPlugin:"css-blank-pseudo",prepare(){const s=new WeakSet;return{postcssPlugin:"css-blank-pseudo",Rule(l,{result:a}){if(s.has(l))return;if(!l.selector.toLowerCase().includes(t))return;const i=l.selectors.flatMap(s=>{if(!s.toLowerCase().includes(t))return[s];let i;try{i=e().astSync(s)}catch(e){return l.warn(a,`Failed to parse selector : "${s}" with message: "${e instanceof Error?e.message:e}"`),[s]}if(void 0===i)return[s];let c=!1;if(i.walkPseudos(e=>{e.value.toLowerCase()===t&&(e.nodes&&e.nodes.length||(c=!0,e.replaceWith(r.clone({}))))}),!c)return[s];const d=i.clone();if(!o.disablePolyfillReadyClass){if(i.nodes?.[0]?.nodes?.length)for(let s=0;s<i.nodes[0].nodes.length;s++){const t=i.nodes[0].nodes[s];if("combinator"===t.type||e.isPseudoElement(t)){i.nodes[0].insertBefore(t,e.className({value:n}));break}if(s===i.nodes[0].nodes.length-1){i.nodes[0].append(e.className({value:n}));break}}return i.nodes?.[0]?.nodes&&(d.nodes[0].prepend(e.combinator({value:" "})),d.nodes[0].prepend(e.className({value:n}))),[i.toString(),d.toString()]}return[i.toString()]});i.join(",")!==l.selectors.join(",")&&(s.add(l),l.cloneBefore({selectors:i}),o.preserve||l.remove())}}}}:{postcssPlugin:"css-blank-pseudo",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,creator as"module.exports"};
1
+ import e from"postcss-selector-parser";const s=/[ >~:+@#()]/,n="js-blank-pseudo",t=":blank",creator=o=>{const r=Object.assign({preserve:!0,replaceWith:"[blank]",disablePolyfillReadyClass:!1},o),l=e().astSync(r.replaceWith);return s.test(r.replaceWith)?{postcssPlugin:"css-blank-pseudo",Once(e,{result:s}){e.warn(s,`${r.replaceWith} is not a valid replacement since it can't be applied to single elements.`)}}:{postcssPlugin:"css-blank-pseudo",prepare(){const s=new WeakSet;return{postcssPlugin:"css-blank-pseudo",Rule(o,{result:a}){if(s.has(o))return;if(!o.selector.toLowerCase().includes(t))return;const c=o.selectors.flatMap(s=>{if(!s.toLowerCase().includes(t))return[s];let c;try{c=e().astSync(s)}catch(e){return o.warn(a,`Failed to parse selector : "${s}" with message: "${e instanceof Error?e.message:e}"`),[s]}if(void 0===c)return[s];let i=!1;if(c.walkPseudos(e=>{e.value.toLowerCase()===t&&(e.nodes&&e.nodes.length||(i=!0,e.replaceWith(l.clone({}))))}),!i)return[s];const d=c.clone();if(!r.disablePolyfillReadyClass){if(c.nodes?.[0]?.nodes?.length)for(let s=0;s<c.nodes[0].nodes.length;s++){const t=c.nodes[0].nodes[s];if("combinator"===t.type||e.isPseudoElement(t)){c.nodes[0].insertBefore(t,e.className({value:n}));break}if(s===c.nodes[0].nodes.length-1){c.nodes[0].append(e.className({value:n}));break}}return c.nodes?.[0]?.nodes&&(d.nodes[0].prepend(e.combinator({value:" "})),d.nodes[0].prepend(e.className({value:n}))),[c.toString(),d.toString()]}return[c.toString()]});c.join(",")!==o.selectors.join(",")&&(s.add(o),o.cloneBefore({selectors:c}),r.preserve||o.remove())}}}}};creator.postcss=!0;export{creator as default,creator as"module.exports"};
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": "8.0.0",
4
+ "version": "8.0.2",
5
5
  "contributors": [
6
6
  {
7
7
  "name": "Antonio Laguna",
@@ -53,8 +53,7 @@
53
53
  "dist"
54
54
  ],
55
55
  "dependencies": {
56
- "postcss-selector-parser": "^7.1.1",
57
- "typescript": "^5.9.3"
56
+ "postcss-selector-parser": "^7.1.1"
58
57
  },
59
58
  "peerDependencies": {
60
59
  "postcss": "^8.4"