css-blank-pseudo
Advanced tools
Comparing version 3.0.2 to 3.0.3
125
browser.js
@@ -1,125 +0,2 @@ | ||
(function () { | ||
/* global MutationObserver */ | ||
function cssBlankPseudo(document, opts) { | ||
// configuration | ||
var className = Object(opts).className; | ||
var attr = Object(opts).attr || 'blank'; | ||
var force = Object(opts).force; | ||
try { | ||
document.querySelector(':blank'); | ||
if (!force) { | ||
return; | ||
} | ||
} catch (ignoredError) { | ||
/* do nothing and continue */ | ||
} // observe value changes on <input>, <select>, and <textarea> | ||
var window = (document.ownerDocument || document).defaultView; | ||
observeValueOfHTMLElement(window.HTMLInputElement); | ||
observeValueOfHTMLElement(window.HTMLSelectElement); | ||
observeValueOfHTMLElement(window.HTMLTextAreaElement); | ||
observeSelectedOfHTMLElement(window.HTMLOptionElement); // form control elements selector | ||
var selector = 'INPUT,SELECT,TEXTAREA'; | ||
var selectorRegExp = /^(INPUT|SELECT|TEXTAREA)$/; // conditionally update all form control elements | ||
Array.prototype.forEach.call(document.querySelectorAll(selector), function (node) { | ||
if (node.nodeName === 'SELECT') { | ||
node.addEventListener('change', configureCssBlankAttribute); | ||
} else { | ||
node.addEventListener('input', configureCssBlankAttribute); | ||
} | ||
configureCssBlankAttribute.call(node); | ||
}); // conditionally observe added or unobserve removed form control elements | ||
new MutationObserver(function (mutationsList) { | ||
mutationsList.forEach(function (mutation) { | ||
Array.prototype.forEach.call(mutation.addedNodes || [], function (node) { | ||
if (node.nodeType === 1 && selectorRegExp.test(node.nodeName)) { | ||
if (node.nodeName === 'SELECT') { | ||
node.addEventListener('change', configureCssBlankAttribute); | ||
} else { | ||
node.addEventListener('input', configureCssBlankAttribute); | ||
} | ||
configureCssBlankAttribute.call(node); | ||
} | ||
}); | ||
Array.prototype.forEach.call(mutation.removedNodes || [], function (node) { | ||
if (node.nodeType === 1 && selectorRegExp.test(node.nodeName)) { | ||
if (node.nodeName === 'SELECT') { | ||
node.removeEventListener('change', configureCssBlankAttribute); | ||
} else { | ||
node.removeEventListener('input', configureCssBlankAttribute); | ||
} | ||
} | ||
}); | ||
}); | ||
}).observe(document, { | ||
childList: true, | ||
subtree: true | ||
}); // update a form control element’s css-blank attribute | ||
function configureCssBlankAttribute() { | ||
if (this.value || this.nodeName === 'SELECT' && this.options[this.selectedIndex].value) { | ||
if (attr) { | ||
this.removeAttribute(attr); | ||
} | ||
if (className) { | ||
this.classList.remove(className); | ||
} | ||
this.removeAttribute('blank'); | ||
} else { | ||
if (attr) { | ||
this.setAttribute('blank', attr); | ||
} | ||
if (className) { | ||
this.classList.add(className); | ||
} | ||
} | ||
} // observe changes to the "value" property on an HTML Element | ||
function observeValueOfHTMLElement(HTMLElement) { | ||
var descriptor = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'value'); | ||
var nativeSet = descriptor.set; | ||
descriptor.set = function set(value) { | ||
// eslint-disable-line no-unused-vars | ||
nativeSet.apply(this, arguments); | ||
configureCssBlankAttribute.apply(this); | ||
}; | ||
Object.defineProperty(HTMLElement.prototype, 'value', descriptor); | ||
} // observe changes to the "selected" property on an HTML Element | ||
function observeSelectedOfHTMLElement(HTMLElement) { | ||
var descriptor = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'selected'); | ||
var nativeSet = descriptor.set; | ||
descriptor.set = function set(value) { | ||
// eslint-disable-line no-unused-vars | ||
nativeSet.apply(this, arguments); | ||
var event = document.createEvent('Event'); | ||
event.initEvent('change', true, true); | ||
this.dispatchEvent(event); | ||
}; | ||
Object.defineProperty(HTMLElement.prototype, 'selected', descriptor); | ||
} | ||
} | ||
/* global self */ | ||
self.cssBlankPseudo = cssBlankPseudo; | ||
})(); | ||
self.cssBlankPseudo=function(e,t){var n=Object(t).className,r=Object(t).attr||"blank",o=Object(t).force;try{if(e.querySelector(":blank"),!o)return}catch(e){}var a,i,s,c=(e.ownerDocument||e).defaultView;d(c.HTMLInputElement),d(c.HTMLSelectElement),d(c.HTMLTextAreaElement),a=c.HTMLOptionElement,i=Object.getOwnPropertyDescriptor(a.prototype,"selected"),s=i.set,i.set=function(t){s.apply(this,arguments);var n=e.createEvent("Event");n.initEvent("change",!0,!0),this.dispatchEvent(n)},Object.defineProperty(a.prototype,"selected",i);var l=/^(INPUT|SELECT|TEXTAREA)$/;function p(){this.value||"SELECT"===this.nodeName&&this.options[this.selectedIndex].value?(r&&this.removeAttribute(r),n&&this.classList.remove(n),this.removeAttribute("blank")):(r&&this.setAttribute("blank",r),n&&this.classList.add(n))}function d(e){var t=Object.getOwnPropertyDescriptor(e.prototype,"value"),n=t.set;t.set=function(e){n.apply(this,arguments),p.apply(this)},Object.defineProperty(e.prototype,"value",t)}Array.prototype.forEach.call(e.querySelectorAll("INPUT,SELECT,TEXTAREA"),(function(e){"SELECT"===e.nodeName?e.addEventListener("change",p):e.addEventListener("input",p),p.call(e)})),new MutationObserver((function(e){e.forEach((function(e){Array.prototype.forEach.call(e.addedNodes||[],(function(e){1===e.nodeType&&l.test(e.nodeName)&&("SELECT"===e.nodeName?e.addEventListener("change",p):e.addEventListener("input",p),p.call(e))})),Array.prototype.forEach.call(e.removedNodes||[],(function(e){1===e.nodeType&&l.test(e.nodeName)&&("SELECT"===e.nodeName?e.removeEventListener("change",p):e.removeEventListener("input",p))}))}))})).observe(e,{childList:!0,subtree:!0})}; | ||
//# sourceMappingURL=browser-global.js.map |
# Changes to CSS Blank Pseudo | ||
### 3.0.3 (February 5, 2022) | ||
- Rebuild of browser polyfills | ||
### 3.0.2 (January 2, 2022) | ||
@@ -4,0 +8,0 @@ |
@@ -1,125 +0,2 @@ | ||
(function () { | ||
/* global MutationObserver */ | ||
function cssBlankPseudo(document, opts) { | ||
// configuration | ||
var className = Object(opts).className; | ||
var attr = Object(opts).attr || 'blank'; | ||
var force = Object(opts).force; | ||
try { | ||
document.querySelector(':blank'); | ||
if (!force) { | ||
return; | ||
} | ||
} catch (ignoredError) { | ||
/* do nothing and continue */ | ||
} // observe value changes on <input>, <select>, and <textarea> | ||
var window = (document.ownerDocument || document).defaultView; | ||
observeValueOfHTMLElement(window.HTMLInputElement); | ||
observeValueOfHTMLElement(window.HTMLSelectElement); | ||
observeValueOfHTMLElement(window.HTMLTextAreaElement); | ||
observeSelectedOfHTMLElement(window.HTMLOptionElement); // form control elements selector | ||
var selector = 'INPUT,SELECT,TEXTAREA'; | ||
var selectorRegExp = /^(INPUT|SELECT|TEXTAREA)$/; // conditionally update all form control elements | ||
Array.prototype.forEach.call(document.querySelectorAll(selector), function (node) { | ||
if (node.nodeName === 'SELECT') { | ||
node.addEventListener('change', configureCssBlankAttribute); | ||
} else { | ||
node.addEventListener('input', configureCssBlankAttribute); | ||
} | ||
configureCssBlankAttribute.call(node); | ||
}); // conditionally observe added or unobserve removed form control elements | ||
new MutationObserver(function (mutationsList) { | ||
mutationsList.forEach(function (mutation) { | ||
Array.prototype.forEach.call(mutation.addedNodes || [], function (node) { | ||
if (node.nodeType === 1 && selectorRegExp.test(node.nodeName)) { | ||
if (node.nodeName === 'SELECT') { | ||
node.addEventListener('change', configureCssBlankAttribute); | ||
} else { | ||
node.addEventListener('input', configureCssBlankAttribute); | ||
} | ||
configureCssBlankAttribute.call(node); | ||
} | ||
}); | ||
Array.prototype.forEach.call(mutation.removedNodes || [], function (node) { | ||
if (node.nodeType === 1 && selectorRegExp.test(node.nodeName)) { | ||
if (node.nodeName === 'SELECT') { | ||
node.removeEventListener('change', configureCssBlankAttribute); | ||
} else { | ||
node.removeEventListener('input', configureCssBlankAttribute); | ||
} | ||
} | ||
}); | ||
}); | ||
}).observe(document, { | ||
childList: true, | ||
subtree: true | ||
}); // update a form control element’s css-blank attribute | ||
function configureCssBlankAttribute() { | ||
if (this.value || this.nodeName === 'SELECT' && this.options[this.selectedIndex].value) { | ||
if (attr) { | ||
this.removeAttribute(attr); | ||
} | ||
if (className) { | ||
this.classList.remove(className); | ||
} | ||
this.removeAttribute('blank'); | ||
} else { | ||
if (attr) { | ||
this.setAttribute('blank', attr); | ||
} | ||
if (className) { | ||
this.classList.add(className); | ||
} | ||
} | ||
} // observe changes to the "value" property on an HTML Element | ||
function observeValueOfHTMLElement(HTMLElement) { | ||
var descriptor = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'value'); | ||
var nativeSet = descriptor.set; | ||
descriptor.set = function set(value) { | ||
// eslint-disable-line no-unused-vars | ||
nativeSet.apply(this, arguments); | ||
configureCssBlankAttribute.apply(this); | ||
}; | ||
Object.defineProperty(HTMLElement.prototype, 'value', descriptor); | ||
} // observe changes to the "selected" property on an HTML Element | ||
function observeSelectedOfHTMLElement(HTMLElement) { | ||
var descriptor = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'selected'); | ||
var nativeSet = descriptor.set; | ||
descriptor.set = function set(value) { | ||
// eslint-disable-line no-unused-vars | ||
nativeSet.apply(this, arguments); | ||
var event = document.createEvent('Event'); | ||
event.initEvent('change', true, true); | ||
this.dispatchEvent(event); | ||
}; | ||
Object.defineProperty(HTMLElement.prototype, 'selected', descriptor); | ||
} | ||
} | ||
/* global self */ | ||
self.cssBlankPseudo = cssBlankPseudo; | ||
})(); | ||
self.cssBlankPseudo=function(e,t){var n=Object(t).className,r=Object(t).attr||"blank",o=Object(t).force;try{if(e.querySelector(":blank"),!o)return}catch(e){}var a,i,s,c=(e.ownerDocument||e).defaultView;d(c.HTMLInputElement),d(c.HTMLSelectElement),d(c.HTMLTextAreaElement),a=c.HTMLOptionElement,i=Object.getOwnPropertyDescriptor(a.prototype,"selected"),s=i.set,i.set=function(t){s.apply(this,arguments);var n=e.createEvent("Event");n.initEvent("change",!0,!0),this.dispatchEvent(n)},Object.defineProperty(a.prototype,"selected",i);var l=/^(INPUT|SELECT|TEXTAREA)$/;function p(){this.value||"SELECT"===this.nodeName&&this.options[this.selectedIndex].value?(r&&this.removeAttribute(r),n&&this.classList.remove(n),this.removeAttribute("blank")):(r&&this.setAttribute("blank",r),n&&this.classList.add(n))}function d(e){var t=Object.getOwnPropertyDescriptor(e.prototype,"value"),n=t.set;t.set=function(e){n.apply(this,arguments),p.apply(this)},Object.defineProperty(e.prototype,"value",t)}Array.prototype.forEach.call(e.querySelectorAll("INPUT,SELECT,TEXTAREA"),(function(e){"SELECT"===e.nodeName?e.addEventListener("change",p):e.addEventListener("input",p),p.call(e)})),new MutationObserver((function(e){e.forEach((function(e){Array.prototype.forEach.call(e.addedNodes||[],(function(e){1===e.nodeType&&l.test(e.nodeName)&&("SELECT"===e.nodeName?e.addEventListener("change",p):e.addEventListener("input",p),p.call(e))})),Array.prototype.forEach.call(e.removedNodes||[],(function(e){1===e.nodeType&&l.test(e.nodeName)&&("SELECT"===e.nodeName?e.removeEventListener("change",p):e.removeEventListener("input",p))}))}))})).observe(e,{childList:!0,subtree:!0})}; | ||
//# sourceMappingURL=browser-global.js.map |
{ | ||
"name": "css-blank-pseudo", | ||
"version": "3.0.2", | ||
"version": "3.0.3", | ||
"description": "Style form elements when they are empty", | ||
@@ -43,3 +43,4 @@ "author": "Jonathan Neal <jonathantneal@hotmail.com>", | ||
"stryker": "stryker run --logLevel error", | ||
"test": "postcss-tape --ci && npm run test:exports", | ||
"test": "node .tape.mjs && npm run test:exports", | ||
"test:rewrite-expects": "REWRITE_EXPECTS=true node .tape.mjs", | ||
"cli": "css-blank-pseudo", | ||
@@ -52,10 +53,6 @@ "test:exports": "node ./test/_import.mjs && node ./test/_require.cjs" | ||
"dependencies": { | ||
"postcss-selector-parser": "^6.0.8" | ||
"postcss-selector-parser": "^6.0.9" | ||
}, | ||
"devDependencies": { | ||
"postcss": "^8.3.6", | ||
"postcss-tape": "^6.0.1" | ||
}, | ||
"peerDependencies": { | ||
"postcss": "^8.3" | ||
"postcss": "^8.4" | ||
}, | ||
@@ -62,0 +59,0 @@ "keywords": [ |
# CSS Blank Pseudo [<img src="http://jonathantneal.github.io/js-logo.svg" alt="" width="90" height="90" align="right">][CSS Blank Pseudo] | ||
[![NPM Version][npm-img]][npm-url] | ||
[![Support Chat][git-img]][git-url] | ||
[<img alt="Discord" src="https://shields.io/badge/Discord-5865F2?logo=discord&logoColor=white">][discord] | ||
@@ -98,4 +98,3 @@ [CSS Blank Pseudo] lets you style form elements when they are empty, following | ||
[git-img]: https://img.shields.io/badge/support-chat-blue.svg | ||
[git-url]: https://gitter.im/postcss/postcss | ||
[discord]: https://discord.gg/bUadyRwkJS | ||
[npm-img]: https://img.shields.io/npm/v/css-blank-pseudo.svg | ||
@@ -102,0 +101,0 @@ [npm-url]: https://www.npmjs.com/package/css-blank-pseudo |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
0
127255
365
105