wicg-inert
Advanced tools
Comparing version 3.1.1 to 3.1.2
@@ -48,3 +48,3 @@ var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
/** | ||
* @param {!Element} rootElement The Element at the root of the inert subtree. | ||
* @param {!HTMLElement} rootElement The HTMLElement at the root of the inert subtree. | ||
* @param {!InertManager} inertManager The global singleton InertManager object. | ||
@@ -58,3 +58,3 @@ */ | ||
/** @type {!Element} */ | ||
/** @type {!HTMLElement} */ | ||
this._rootElement = rootElement; | ||
@@ -181,3 +181,3 @@ | ||
} | ||
var element = /** @type {!Element} */node; | ||
var element = /** @type {!HTMLElement} */node; | ||
@@ -238,3 +238,3 @@ // If a descendant inert root becomes un-inert, its descendants will still be inert because of | ||
* If a descendant node is found with an `inert` attribute, adopt its managed nodes. | ||
* @param {!Element} node | ||
* @param {!HTMLElement} node | ||
*/ | ||
@@ -269,3 +269,3 @@ | ||
records.forEach(function (record) { | ||
var target = /** @type {!Element} */record.target; | ||
var target = /** @type {!HTMLElement} */record.target; | ||
if (record.type === 'childList') { | ||
@@ -389,3 +389,3 @@ // Manage added nodes | ||
if (this._node && this._node.nodeType === Node.ELEMENT_NODE) { | ||
var element = /** @type {!Element} */this._node; | ||
var element = /** @type {!HTMLElement} */this._node; | ||
if (this._savedTabIndex !== null) { | ||
@@ -438,3 +438,3 @@ element.setAttribute('tabindex', this._savedTabIndex); | ||
} | ||
var element = /** @type {!Element} */this.node; | ||
var element = /** @type {!HTMLElement} */this.node; | ||
if (matches.call(element, _focusableElementsString)) { | ||
@@ -584,3 +584,3 @@ if ( /** @type {!HTMLElement} */element.tabIndex === -1 && this.hasSavedTabIndex) { | ||
* Set whether the given element should be an inert root or not. | ||
* @param {!Element} root | ||
* @param {!HTMLElement} root | ||
* @param {boolean} inert | ||
@@ -736,3 +736,3 @@ */ | ||
} | ||
var target = /** @type {!Element} */record.target; | ||
var target = /** @type {!HTMLElement} */record.target; | ||
var inert = target.hasAttribute('inert'); | ||
@@ -752,3 +752,3 @@ _this.setInert(target, inert); | ||
* @param {!Node} node | ||
* @param {(function (!Element))=} callback Callback to be called for each element traversed, | ||
* @param {(function (!HTMLElement))=} callback Callback to be called for each element traversed, | ||
* before descending into child nodes. | ||
@@ -761,3 +761,3 @@ * @param {?ShadowRoot=} shadowRootAncestor The nearest ShadowRoot ancestor, if any. | ||
if (node.nodeType == Node.ELEMENT_NODE) { | ||
var element = /** @type {!Element} */node; | ||
var element = /** @type {!HTMLElement} */node; | ||
if (callback) { | ||
@@ -827,13 +827,13 @@ callback(element); | ||
if (!Element.prototype.hasOwnProperty('inert')) { | ||
if (!HTMLElement.prototype.hasOwnProperty('inert')) { | ||
/** @type {!InertManager} */ | ||
var inertManager = new InertManager(document); | ||
Object.defineProperty(Element.prototype, 'inert', { | ||
Object.defineProperty(HTMLElement.prototype, 'inert', { | ||
enumerable: true, | ||
/** @this {!Element} */ | ||
/** @this {!HTMLElement} */ | ||
get: function get() { | ||
return this.hasAttribute('inert'); | ||
}, | ||
/** @this {!Element} */ | ||
/** @this {!HTMLElement} */ | ||
set: function set(inert) { | ||
@@ -840,0 +840,0 @@ inertManager.setInert(this, inert); |
@@ -54,3 +54,3 @@ (function (global, factory) { | ||
/** | ||
* @param {!Element} rootElement The Element at the root of the inert subtree. | ||
* @param {!HTMLElement} rootElement The HTMLElement at the root of the inert subtree. | ||
* @param {!InertManager} inertManager The global singleton InertManager object. | ||
@@ -64,3 +64,3 @@ */ | ||
/** @type {!Element} */ | ||
/** @type {!HTMLElement} */ | ||
this._rootElement = rootElement; | ||
@@ -187,3 +187,3 @@ | ||
} | ||
var element = /** @type {!Element} */node; | ||
var element = /** @type {!HTMLElement} */node; | ||
@@ -244,3 +244,3 @@ // If a descendant inert root becomes un-inert, its descendants will still be inert because of | ||
* If a descendant node is found with an `inert` attribute, adopt its managed nodes. | ||
* @param {!Element} node | ||
* @param {!HTMLElement} node | ||
*/ | ||
@@ -275,3 +275,3 @@ | ||
records.forEach(function (record) { | ||
var target = /** @type {!Element} */record.target; | ||
var target = /** @type {!HTMLElement} */record.target; | ||
if (record.type === 'childList') { | ||
@@ -395,3 +395,3 @@ // Manage added nodes | ||
if (this._node && this._node.nodeType === Node.ELEMENT_NODE) { | ||
var element = /** @type {!Element} */this._node; | ||
var element = /** @type {!HTMLElement} */this._node; | ||
if (this._savedTabIndex !== null) { | ||
@@ -444,3 +444,3 @@ element.setAttribute('tabindex', this._savedTabIndex); | ||
} | ||
var element = /** @type {!Element} */this.node; | ||
var element = /** @type {!HTMLElement} */this.node; | ||
if (matches.call(element, _focusableElementsString)) { | ||
@@ -590,3 +590,3 @@ if ( /** @type {!HTMLElement} */element.tabIndex === -1 && this.hasSavedTabIndex) { | ||
* Set whether the given element should be an inert root or not. | ||
* @param {!Element} root | ||
* @param {!HTMLElement} root | ||
* @param {boolean} inert | ||
@@ -742,3 +742,3 @@ */ | ||
} | ||
var target = /** @type {!Element} */record.target; | ||
var target = /** @type {!HTMLElement} */record.target; | ||
var inert = target.hasAttribute('inert'); | ||
@@ -758,3 +758,3 @@ _this.setInert(target, inert); | ||
* @param {!Node} node | ||
* @param {(function (!Element))=} callback Callback to be called for each element traversed, | ||
* @param {(function (!HTMLElement))=} callback Callback to be called for each element traversed, | ||
* before descending into child nodes. | ||
@@ -767,3 +767,3 @@ * @param {?ShadowRoot=} shadowRootAncestor The nearest ShadowRoot ancestor, if any. | ||
if (node.nodeType == Node.ELEMENT_NODE) { | ||
var element = /** @type {!Element} */node; | ||
var element = /** @type {!HTMLElement} */node; | ||
if (callback) { | ||
@@ -833,13 +833,13 @@ callback(element); | ||
if (!Element.prototype.hasOwnProperty('inert')) { | ||
if (!HTMLElement.prototype.hasOwnProperty('inert')) { | ||
/** @type {!InertManager} */ | ||
var inertManager = new InertManager(document); | ||
Object.defineProperty(Element.prototype, 'inert', { | ||
Object.defineProperty(HTMLElement.prototype, 'inert', { | ||
enumerable: true, | ||
/** @this {!Element} */ | ||
/** @this {!HTMLElement} */ | ||
get: function get() { | ||
return this.hasAttribute('inert'); | ||
}, | ||
/** @this {!Element} */ | ||
/** @this {!HTMLElement} */ | ||
set: function set(inert) { | ||
@@ -846,0 +846,0 @@ inertManager.setInert(this, inert); |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t():"function"==typeof define&&define.amd?define("inert",t):t()}(0,function(){"use strict";var u=function(){function i(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(e,t,n){return t&&i(e.prototype,t),n&&i(e,n),e}}();function h(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}!function(){if("undefined"!=typeof window){var o=Array.prototype.slice,r=Element.prototype.matches||Element.prototype.msMatchesSelector,i=["a[href]","area[href]","input:not([disabled])","select:not([disabled])","textarea:not([disabled])","button:not([disabled])","details","summary","iframe","object","embed","[contenteditable]"].join(","),s=function(){function n(e,t){h(this,n),this._inertManager=t,this._rootElement=e,this._managedNodes=new Set,this._rootElement.hasAttribute("aria-hidden")?this._savedAriaHidden=this._rootElement.getAttribute("aria-hidden"):this._savedAriaHidden=null,this._rootElement.setAttribute("aria-hidden","true"),this._makeSubtreeUnfocusable(this._rootElement),this._observer=new MutationObserver(this._onMutation.bind(this)),this._observer.observe(this._rootElement,{attributes:!0,childList:!0,subtree:!0})}return u(n,[{key:"destructor",value:function(){this._observer.disconnect(),this._rootElement&&(null!==this._savedAriaHidden?this._rootElement.setAttribute("aria-hidden",this._savedAriaHidden):this._rootElement.removeAttribute("aria-hidden")),this._managedNodes.forEach(function(e){this._unmanageNode(e.node)},this),this._observer=null,this._rootElement=null,this._managedNodes=null,this._inertManager=null}},{key:"_makeSubtreeUnfocusable",value:function(e){var t=this;l(e,function(e){return t._visitNode(e)});var n=document.activeElement;if(!document.body.contains(e)){for(var i=e,o=void 0;i;){if(i.nodeType===Node.DOCUMENT_FRAGMENT_NODE){o=i;break}i=i.parentNode}o&&(n=o.activeElement)}e.contains(n)&&(n.blur(),n===document.activeElement&&document.body.focus())}},{key:"_visitNode",value:function(e){if(e.nodeType===Node.ELEMENT_NODE){var t=e;t!==this._rootElement&&t.hasAttribute("inert")&&this._adoptInertRoot(t),(r.call(t,i)||t.hasAttribute("tabindex"))&&this._manageNode(t)}}},{key:"_manageNode",value:function(e){var t=this._inertManager.register(e,this);this._managedNodes.add(t)}},{key:"_unmanageNode",value:function(e){var t=this._inertManager.deregister(e,this);t&&this._managedNodes.delete(t)}},{key:"_unmanageSubtree",value:function(e){var t=this;l(e,function(e){return t._unmanageNode(e)})}},{key:"_adoptInertRoot",value:function(e){var t=this._inertManager.getInertRoot(e);t||(this._inertManager.setInert(e,!0),t=this._inertManager.getInertRoot(e)),t.managedNodes.forEach(function(e){this._manageNode(e.node)},this)}},{key:"_onMutation",value:function(e,t){e.forEach(function(e){var t=e.target;if("childList"===e.type)o.call(e.addedNodes).forEach(function(e){this._makeSubtreeUnfocusable(e)},this),o.call(e.removedNodes).forEach(function(e){this._unmanageSubtree(e)},this);else if("attributes"===e.type)if("tabindex"===e.attributeName)this._manageNode(t);else if(t!==this._rootElement&&"inert"===e.attributeName&&t.hasAttribute("inert")){this._adoptInertRoot(t);var n=this._inertManager.getInertRoot(t);this._managedNodes.forEach(function(e){t.contains(e.node)&&n._manageNode(e.node)})}},this)}},{key:"managedNodes",get:function(){return new Set(this._managedNodes)}},{key:"hasSavedAriaHidden",get:function(){return null!==this._savedAriaHidden}},{key:"savedAriaHidden",set:function(e){this._savedAriaHidden=e},get:function(){return this._savedAriaHidden}}]),n}(),a=function(){function n(e,t){h(this,n),this._node=e,this._overrodeFocusMethod=!1,this._inertRoots=new Set([t]),this._savedTabIndex=null,this._destroyed=!1,this.ensureUntabbable()}return u(n,[{key:"destructor",value:function(){if(this._throwIfDestroyed(),this._node&&this._node.nodeType===Node.ELEMENT_NODE){var e=this._node;null!==this._savedTabIndex?e.setAttribute("tabindex",this._savedTabIndex):e.removeAttribute("tabindex"),this._overrodeFocusMethod&&delete e.focus}this._node=null,this._inertRoots=null,this._destroyed=!0}},{key:"_throwIfDestroyed",value:function(){if(this.destroyed)throw new Error("Trying to access destroyed InertNode")}},{key:"ensureUntabbable",value:function(){if(this.node.nodeType===Node.ELEMENT_NODE){var e=this.node;if(r.call(e,i)){if(-1===e.tabIndex&&this.hasSavedTabIndex)return;e.hasAttribute("tabindex")&&(this._savedTabIndex=e.tabIndex),e.setAttribute("tabindex","-1"),e.nodeType===Node.ELEMENT_NODE&&(e.focus=function(){},this._overrodeFocusMethod=!0)}else e.hasAttribute("tabindex")&&(this._savedTabIndex=e.tabIndex,e.removeAttribute("tabindex"))}}},{key:"addInertRoot",value:function(e){this._throwIfDestroyed(),this._inertRoots.add(e)}},{key:"removeInertRoot",value:function(e){this._throwIfDestroyed(),this._inertRoots.delete(e),0===this._inertRoots.size&&this.destructor()}},{key:"destroyed",get:function(){return this._destroyed}},{key:"hasSavedTabIndex",get:function(){return null!==this._savedTabIndex}},{key:"node",get:function(){return this._throwIfDestroyed(),this._node}},{key:"savedTabIndex",set:function(e){this._throwIfDestroyed(),this._savedTabIndex=e},get:function(){return this._throwIfDestroyed(),this._savedTabIndex}}]),n}(),e=function(){function t(e){if(h(this,t),!e)throw new Error("Missing required argument; InertManager needs to wrap a document.");this._document=e,this._managedNodes=new Map,this._inertRoots=new Map,this._observer=new MutationObserver(this._watchForInert.bind(this)),d(e.head||e.body||e.documentElement),"loading"===e.readyState?e.addEventListener("DOMContentLoaded",this._onDocumentLoaded.bind(this)):this._onDocumentLoaded()}return u(t,[{key:"setInert",value:function(e,t){if(t){if(this._inertRoots.has(e))return;var n=new s(e,this);if(e.setAttribute("inert",""),this._inertRoots.set(e,n),!this._document.body.contains(e))for(var i=e.parentNode;i;)11===i.nodeType&&d(i),i=i.parentNode}else{if(!this._inertRoots.has(e))return;this._inertRoots.get(e).destructor(),this._inertRoots.delete(e),e.removeAttribute("inert")}}},{key:"getInertRoot",value:function(e){return this._inertRoots.get(e)}},{key:"register",value:function(e,t){var n=this._managedNodes.get(e);return void 0!==n?n.addInertRoot(t):n=new a(e,t),this._managedNodes.set(e,n),n}},{key:"deregister",value:function(e,t){var n=this._managedNodes.get(e);return n?(n.removeInertRoot(t),n.destroyed&&this._managedNodes.delete(e),n):null}},{key:"_onDocumentLoaded",value:function(){o.call(this._document.querySelectorAll("[inert]")).forEach(function(e){this.setInert(e,!0)},this),this._observer.observe(this._document.body||this._document.documentElement,{attributes:!0,subtree:!0,childList:!0})}},{key:"_watchForInert",value:function(e,t){var i=this;e.forEach(function(e){switch(e.type){case"childList":o.call(e.addedNodes).forEach(function(e){if(e.nodeType===Node.ELEMENT_NODE){var t=o.call(e.querySelectorAll("[inert]"));r.call(e,"[inert]")&&t.unshift(e),t.forEach(function(e){this.setInert(e,!0)},i)}},i);break;case"attributes":if("inert"!==e.attributeName)return;var t=e.target,n=t.hasAttribute("inert");i.setInert(t,n)}},this)}}]),t}();if(!Element.prototype.hasOwnProperty("inert")){var t=new e(document);Object.defineProperty(Element.prototype,"inert",{enumerable:!0,get:function(){return this.hasAttribute("inert")},set:function(e){t.setInert(this,e)}})}}function l(e,t,n){if(e.nodeType==Node.ELEMENT_NODE){var i=e;t&&t(i);var o=i.shadowRoot;if(o)return void l(o,t,o);if("content"==i.localName){for(var r=i,s=r.getDistributedNodes?r.getDistributedNodes():[],a=0;a<s.length;a++)l(s[a],t,n);return}if("slot"==i.localName){for(var d=i,u=d.assignedNodes?d.assignedNodes({flatten:!0}):[],h=0;h<u.length;h++)l(u[h],t,n);return}}for(var c=e.firstChild;null!=c;)l(c,t,n),c=c.nextSibling}function d(e){if(!e.querySelector("style#inert-style, link#inert-style")){var t=document.createElement("style");t.setAttribute("id","inert-style"),t.textContent="\n[inert] {\n pointer-events: none;\n cursor: default;\n}\n\n[inert], [inert] * {\n -webkit-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\n user-select: none;\n}\n",e.appendChild(t)}}}()}); | ||
!function(e){("object"!=typeof exports||"undefined"==typeof module)&&"function"==typeof define&&define.amd?define("inert",e):e()}(function(){"use strict";var o,r,t,i,s,n,e=function(e,t,n){return t&&a(e.prototype,t),n&&a(e,n),e};function a(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}function d(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function u(e,t){d(this,u),this._inertManager=t,this._rootElement=e,this._managedNodes=new Set,this._rootElement.hasAttribute("aria-hidden")?this._savedAriaHidden=this._rootElement.getAttribute("aria-hidden"):this._savedAriaHidden=null,this._rootElement.setAttribute("aria-hidden","true"),this._makeSubtreeUnfocusable(this._rootElement),this._observer=new MutationObserver(this._onMutation.bind(this)),this._observer.observe(this._rootElement,{attributes:!0,childList:!0,subtree:!0})}function h(e,t){d(this,h),this._node=e,this._overrodeFocusMethod=!1,this._inertRoots=new Set([t]),this._savedTabIndex=null,this._destroyed=!1,this.ensureUntabbable()}function l(e){if(d(this,l),!e)throw new Error("Missing required argument; InertManager needs to wrap a document.");this._document=e,this._managedNodes=new Map,this._inertRoots=new Map,this._observer=new MutationObserver(this._watchForInert.bind(this)),_(e.head||e.body||e.documentElement),"loading"===e.readyState?e.addEventListener("DOMContentLoaded",this._onDocumentLoaded.bind(this)):this._onDocumentLoaded()}function c(e,t,n){if(e.nodeType==Node.ELEMENT_NODE){var i=e,o=(t&&t(i),i.shadowRoot);if(o)return void c(o,t,o);if("content"==i.localName){for(var o=i,r=o.getDistributedNodes?o.getDistributedNodes():[],s=0;s<r.length;s++)c(r[s],t,n);return}if("slot"==i.localName){for(var o=i,a=o.assignedNodes?o.assignedNodes({flatten:!0}):[],d=0;d<a.length;d++)c(a[d],t,n);return}}for(var u=e.firstChild;null!=u;)c(u,t,n),u=u.nextSibling}function _(e){var t;e.querySelector("style#inert-style, link#inert-style")||((t=document.createElement("style")).setAttribute("id","inert-style"),t.textContent="\n[inert] {\n pointer-events: none;\n cursor: default;\n}\n\n[inert], [inert] * {\n -webkit-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\n user-select: none;\n}\n",e.appendChild(t))}"undefined"!=typeof window&&(o=Array.prototype.slice,r=Element.prototype.matches||Element.prototype.msMatchesSelector,t=["a[href]","area[href]","input:not([disabled])","select:not([disabled])","textarea:not([disabled])","button:not([disabled])","details","summary","iframe","object","embed","[contenteditable]"].join(","),e(u,[{key:"destructor",value:function(){this._observer.disconnect(),this._rootElement&&(null!==this._savedAriaHidden?this._rootElement.setAttribute("aria-hidden",this._savedAriaHidden):this._rootElement.removeAttribute("aria-hidden")),this._managedNodes.forEach(function(e){this._unmanageNode(e.node)},this),this._observer=null,this._rootElement=null,this._managedNodes=null,this._inertManager=null}},{key:"_makeSubtreeUnfocusable",value:function(e){var t=this,n=(c(e,function(e){return t._visitNode(e)}),document.activeElement);if(!document.body.contains(e)){for(var i=e,o=void 0;i;){if(i.nodeType===Node.DOCUMENT_FRAGMENT_NODE){o=i;break}i=i.parentNode}o&&(n=o.activeElement)}e.contains(n)&&(n.blur(),n===document.activeElement&&document.body.focus())}},{key:"_visitNode",value:function(e){e.nodeType===Node.ELEMENT_NODE&&((e=e)!==this._rootElement&&e.hasAttribute("inert")&&this._adoptInertRoot(e),(r.call(e,t)||e.hasAttribute("tabindex"))&&this._manageNode(e))}},{key:"_manageNode",value:function(e){e=this._inertManager.register(e,this);this._managedNodes.add(e)}},{key:"_unmanageNode",value:function(e){e=this._inertManager.deregister(e,this);e&&this._managedNodes.delete(e)}},{key:"_unmanageSubtree",value:function(e){var t=this;c(e,function(e){return t._unmanageNode(e)})}},{key:"_adoptInertRoot",value:function(e){var t=this._inertManager.getInertRoot(e);t||(this._inertManager.setInert(e,!0),t=this._inertManager.getInertRoot(e)),t.managedNodes.forEach(function(e){this._manageNode(e.node)},this)}},{key:"_onMutation",value:function(e,t){e.forEach(function(e){var t,n=e.target;"childList"===e.type?(o.call(e.addedNodes).forEach(function(e){this._makeSubtreeUnfocusable(e)},this),o.call(e.removedNodes).forEach(function(e){this._unmanageSubtree(e)},this)):"attributes"===e.type&&("tabindex"===e.attributeName?this._manageNode(n):n!==this._rootElement&&"inert"===e.attributeName&&n.hasAttribute("inert")&&(this._adoptInertRoot(n),t=this._inertManager.getInertRoot(n),this._managedNodes.forEach(function(e){n.contains(e.node)&&t._manageNode(e.node)})))},this)}},{key:"managedNodes",get:function(){return new Set(this._managedNodes)}},{key:"hasSavedAriaHidden",get:function(){return null!==this._savedAriaHidden}},{key:"savedAriaHidden",set:function(e){this._savedAriaHidden=e},get:function(){return this._savedAriaHidden}}]),i=u,e(h,[{key:"destructor",value:function(){var e;this._throwIfDestroyed(),this._node&&this._node.nodeType===Node.ELEMENT_NODE&&(e=this._node,null!==this._savedTabIndex?e.setAttribute("tabindex",this._savedTabIndex):e.removeAttribute("tabindex"),this._overrodeFocusMethod&&delete e.focus),this._node=null,this._inertRoots=null,this._destroyed=!0}},{key:"_throwIfDestroyed",value:function(){if(this.destroyed)throw new Error("Trying to access destroyed InertNode")}},{key:"ensureUntabbable",value:function(){var e;this.node.nodeType===Node.ELEMENT_NODE&&(e=this.node,r.call(e,t)?-1===e.tabIndex&&this.hasSavedTabIndex||(e.hasAttribute("tabindex")&&(this._savedTabIndex=e.tabIndex),e.setAttribute("tabindex","-1"),e.nodeType===Node.ELEMENT_NODE&&(e.focus=function(){},this._overrodeFocusMethod=!0)):e.hasAttribute("tabindex")&&(this._savedTabIndex=e.tabIndex,e.removeAttribute("tabindex")))}},{key:"addInertRoot",value:function(e){this._throwIfDestroyed(),this._inertRoots.add(e)}},{key:"removeInertRoot",value:function(e){this._throwIfDestroyed(),this._inertRoots.delete(e),0===this._inertRoots.size&&this.destructor()}},{key:"destroyed",get:function(){return this._destroyed}},{key:"hasSavedTabIndex",get:function(){return null!==this._savedTabIndex}},{key:"node",get:function(){return this._throwIfDestroyed(),this._node}},{key:"savedTabIndex",set:function(e){this._throwIfDestroyed(),this._savedTabIndex=e},get:function(){return this._throwIfDestroyed(),this._savedTabIndex}}]),s=h,e(l,[{key:"setInert",value:function(e,t){if(t){if(!this._inertRoots.has(e)){t=new i(e,this);if(e.setAttribute("inert",""),this._inertRoots.set(e,t),!this._document.body.contains(e))for(var n=e.parentNode;n;)11===n.nodeType&&_(n),n=n.parentNode}}else this._inertRoots.has(e)&&(this._inertRoots.get(e).destructor(),this._inertRoots.delete(e),e.removeAttribute("inert"))}},{key:"getInertRoot",value:function(e){return this._inertRoots.get(e)}},{key:"register",value:function(e,t){var n=this._managedNodes.get(e);return void 0!==n?n.addInertRoot(t):n=new s(e,t),this._managedNodes.set(e,n),n}},{key:"deregister",value:function(e,t){var n=this._managedNodes.get(e);return n?(n.removeInertRoot(t),n.destroyed&&this._managedNodes.delete(e),n):null}},{key:"_onDocumentLoaded",value:function(){o.call(this._document.querySelectorAll("[inert]")).forEach(function(e){this.setInert(e,!0)},this),this._observer.observe(this._document.body||this._document.documentElement,{attributes:!0,subtree:!0,childList:!0})}},{key:"_watchForInert",value:function(e,t){var i=this;e.forEach(function(e){switch(e.type){case"childList":o.call(e.addedNodes).forEach(function(e){var t;e.nodeType===Node.ELEMENT_NODE&&(t=o.call(e.querySelectorAll("[inert]")),r.call(e,"[inert]")&&t.unshift(e),t.forEach(function(e){this.setInert(e,!0)},i))},i);break;case"attributes":if("inert"!==e.attributeName)return;var t=e.target,n=t.hasAttribute("inert");i.setInert(t,n)}},this)}}]),e=l,HTMLElement.prototype.hasOwnProperty("inert")||(n=new e(document),Object.defineProperty(HTMLElement.prototype,"inert",{enumerable:!0,get:function(){return this.hasAttribute("inert")},set:function(e){n.setInert(this,e)}})))}); | ||
//# sourceMappingURL=inert.min.js.map |
@@ -19,3 +19,3 @@ const path = require('path'); | ||
// Can also add additional local browsers like 'Firefox'. | ||
browsers: ['ChromeHeadless'], | ||
browsers: ['FirefoxHeadless'], | ||
// Set this to false to leave the browser open for debugging. | ||
@@ -61,5 +61,3 @@ // You'll probably also need to remove the afterEach block in your tests | ||
// To add more browsers, use: | ||
// https://wiki.saucelabs.com/display/DOCS/Platform+Configurator#/ | ||
// This set of browsers was copied from: | ||
// https://github.com/angular/angular.js/blob/master/karma-shared.conf.js#L42-L116 | ||
// https://docs.saucelabs.com/visual/e2e-testing/supported-browsers/#browser-versions-supported | ||
const customLaunchers = { | ||
@@ -69,71 +67,15 @@ 'SL_Chrome': { | ||
browserName: 'chrome', | ||
version: 'latest', | ||
version: '100', | ||
}, | ||
'SL_Chrome-1': { | ||
base: 'SauceLabs', | ||
browserName: 'chrome', | ||
version: 'latest-1', | ||
}, | ||
'SL_Firefox': { | ||
base: 'SauceLabs', | ||
browserName: 'firefox', | ||
version: 'latest', | ||
version: '100', | ||
}, | ||
'SL_Firefox-1': { | ||
base: 'SauceLabs', | ||
browserName: 'firefox', | ||
version: 'latest-1', | ||
}, | ||
'SL_Safari-1': { | ||
base: 'SauceLabs', | ||
browserName: 'safari', | ||
platform: 'OS X 10.12', | ||
version: 'latest-1', | ||
}, | ||
'SL_Safari': { | ||
base: 'SauceLabs', | ||
browserName: 'safari', | ||
platform: 'OS X 10.13', | ||
version: 'latest', | ||
platform: 'OS X 11.00', | ||
version: '14', | ||
}, | ||
// 'SL_IE_9': { | ||
// base: 'SauceLabs', | ||
// browserName: 'internet explorer', | ||
// platform: 'Windows 2008', | ||
// version: '9', | ||
// }, | ||
// 'SL_IE_10': { | ||
// base: 'SauceLabs', | ||
// browserName: 'internet explorer', | ||
// platform: 'Windows 2012', | ||
// version: '10', | ||
// }, | ||
'SL_IE_11': { | ||
base: 'SauceLabs', | ||
browserName: 'internet explorer', | ||
platform: 'Windows 8.1', | ||
version: '11', | ||
}, | ||
'SL_EDGE': { | ||
base: 'SauceLabs', | ||
browserName: 'microsoftedge', | ||
platform: 'Windows 10', | ||
version: 'latest', | ||
}, | ||
'SL_EDGE-1': { | ||
base: 'SauceLabs', | ||
browserName: 'microsoftedge', | ||
platform: 'Windows 10', | ||
version: 'latest-1', | ||
}, | ||
// 'SL_iOS_10': { | ||
// base: 'SauceLabs', | ||
// browserName: 'iphone', | ||
// version: '10.3', | ||
// }, | ||
// 'SL_iOS_11': { | ||
// base: 'SauceLabs', | ||
// browserName: 'iphone', | ||
// version: '11', | ||
// }, | ||
}; | ||
@@ -154,2 +96,2 @@ | ||
} | ||
}; | ||
}; |
{ | ||
"name": "wicg-inert", | ||
"version": "3.1.1", | ||
"version": "3.1.2", | ||
"description": "A polyfill for the proposed inert API", | ||
@@ -41,3 +41,3 @@ "main": "dist/inert.js", | ||
"husky": "^0.14.3", | ||
"karma": "^3.0.0", | ||
"karma": "^6.3.20", | ||
"karma-chai": "^0.1.0", | ||
@@ -48,4 +48,5 @@ "karma-chrome-launcher": "^2.2.0", | ||
"karma-html2js-preprocessor": "^1.1.0", | ||
"karma-mocha": "^1.3.0", | ||
"karma-mocha": "^2.0.1", | ||
"karma-polyfill": "^1.0.0", | ||
"karma-safari-launcher": "^1.0.0", | ||
"karma-sauce-launcher": "^1.2.0", | ||
@@ -55,7 +56,8 @@ "karma-sourcemap-loader": "^0.3.7", | ||
"lint-staged": "^7.0.0", | ||
"mocha": "^5.0.0", | ||
"mocha": "^10.0.0", | ||
"rollup": "^0.65.0", | ||
"rollup-plugin-babel": "^3.0.4", | ||
"rollup-plugin-uglify": "^4.0.0" | ||
} | ||
}, | ||
"license": "W3C-20150513" | ||
} |
@@ -1,2 +0,2 @@ | ||
[![Build Status](https://travis-ci.org/WICG/inert.svg?branch=master)](https://travis-ci.org/WICG/inert) | ||
[![Build Status](https://travis-ci.org/WICG/inert.svg?branch=main)](https://travis-ci.org/WICG/inert) | ||
@@ -3,0 +3,0 @@ The `inert` attribute/property allows web authors to mark parts of the DOM tree |
@@ -55,3 +55,3 @@ /** | ||
/** | ||
* @param {!Element} rootElement The Element at the root of the inert subtree. | ||
* @param {!HTMLElement} rootElement The HTMLElement at the root of the inert subtree. | ||
* @param {!InertManager} inertManager The global singleton InertManager object. | ||
@@ -63,3 +63,3 @@ */ | ||
/** @type {!Element} */ | ||
/** @type {!HTMLElement} */ | ||
this._rootElement = rootElement; | ||
@@ -189,3 +189,3 @@ | ||
} | ||
const element = /** @type {!Element} */ (node); | ||
const element = /** @type {!HTMLElement} */ (node); | ||
@@ -233,3 +233,3 @@ // If a descendant inert root becomes un-inert, its descendants will still be inert because of | ||
* If a descendant node is found with an `inert` attribute, adopt its managed nodes. | ||
* @param {!Element} node | ||
* @param {!HTMLElement} node | ||
*/ | ||
@@ -258,3 +258,3 @@ _adoptInertRoot(node) { | ||
records.forEach(function(record) { | ||
const target = /** @type {!Element} */ (record.target); | ||
const target = /** @type {!HTMLElement} */ (record.target); | ||
if (record.type === 'childList') { | ||
@@ -342,3 +342,3 @@ // Manage added nodes | ||
if (this._node && this._node.nodeType === Node.ELEMENT_NODE) { | ||
const element = /** @type {!Element} */ (this._node); | ||
const element = /** @type {!HTMLElement} */ (this._node); | ||
if (this._savedTabIndex !== null) { | ||
@@ -407,3 +407,3 @@ element.setAttribute('tabindex', this._savedTabIndex); | ||
} | ||
const element = /** @type {!Element} */ (this.node); | ||
const element = /** @type {!HTMLElement} */ (this.node); | ||
if (matches.call(element, _focusableElementsString)) { | ||
@@ -505,3 +505,3 @@ if (/** @type {!HTMLElement} */ (element).tabIndex === -1 && | ||
* Set whether the given element should be an inert root or not. | ||
* @param {!Element} root | ||
* @param {!HTMLElement} root | ||
* @param {boolean} inert | ||
@@ -635,3 +635,3 @@ */ | ||
} | ||
const target = /** @type {!Element} */ (record.target); | ||
const target = /** @type {!HTMLElement} */ (record.target); | ||
const inert = target.hasAttribute('inert'); | ||
@@ -648,3 +648,3 @@ _this.setInert(target, inert); | ||
* @param {!Node} node | ||
* @param {(function (!Element))=} callback Callback to be called for each element traversed, | ||
* @param {(function (!HTMLElement))=} callback Callback to be called for each element traversed, | ||
* before descending into child nodes. | ||
@@ -655,3 +655,3 @@ * @param {?ShadowRoot=} shadowRootAncestor The nearest ShadowRoot ancestor, if any. | ||
if (node.nodeType == Node.ELEMENT_NODE) { | ||
const element = /** @type {!Element} */ (node); | ||
const element = /** @type {!HTMLElement} */ (node); | ||
if (callback) { | ||
@@ -734,13 +734,13 @@ callback(element); | ||
if (!Element.prototype.hasOwnProperty('inert')) { | ||
if (!HTMLElement.prototype.hasOwnProperty('inert')) { | ||
/** @type {!InertManager} */ | ||
const inertManager = new InertManager(document); | ||
Object.defineProperty(Element.prototype, 'inert', { | ||
Object.defineProperty(HTMLElement.prototype, 'inert', { | ||
enumerable: true, | ||
/** @this {!Element} */ | ||
/** @this {!HTMLElement} */ | ||
get: function() { | ||
return this.hasAttribute('inert'); | ||
}, | ||
/** @this {!Element} */ | ||
/** @this {!HTMLElement} */ | ||
set: function(inert) { | ||
@@ -747,0 +747,0 @@ inertManager.setInert(this, inert); |
@@ -1,5 +0,5 @@ | ||
describe('Element.prototype', function() { | ||
it('should patch the Element prototype', function() { | ||
expect(Element.prototype.hasOwnProperty('inert')).to.be.ok; | ||
describe('HTMLElement.prototype', function() { | ||
it('should patch the HTMLElement prototype', function() { | ||
expect(HTMLElement.prototype.hasOwnProperty('inert')).to.be.ok; | ||
}); | ||
}); |
@@ -17,3 +17,3 @@ /** | ||
* See the files array in karma.conf.js. | ||
* @param {Element} el | ||
* @param {HTMLElement} el | ||
* @return {Boolean} | ||
@@ -20,0 +20,0 @@ */ |
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
180923
35
25
2713