wicg-inert
Advanced tools
Comparing version 1.1.3 to 1.1.4
@@ -55,2 +55,23 @@ (function (global, factory) { | ||
/** | ||
* Module exports. | ||
*/ | ||
var index$1 = contains; | ||
/** | ||
* `Node#contains()` polyfill. | ||
* | ||
* See: http://compatibility.shwups-cms.ch/en/polyfills/?&id=1 | ||
* | ||
* @param {Node} node | ||
* @param {Node} other | ||
* @return {Boolean} | ||
* @public | ||
*/ | ||
function contains (node, other) { | ||
return node === other || !!(node.compareDocumentPosition(other) & 16); | ||
} | ||
var classCallCheck = function (instance, Constructor) { | ||
@@ -217,3 +238,3 @@ if (!(instance instanceof Constructor)) { | ||
var activeElement = document.activeElement; | ||
if (!document.body.contains(startNode)) { | ||
if (!index$1(document.body, startNode)) { | ||
// startNode may be in shadow DOM, so find its nearest shadowRoot to get the activeElement. | ||
@@ -231,3 +252,3 @@ var node = startNode; | ||
} | ||
if (startNode.contains(activeElement)) activeElement.blur(); | ||
if (index$1(startNode, activeElement)) activeElement.blur(); | ||
} | ||
@@ -419,3 +440,3 @@ | ||
if (target.contains(managedNode.node)) inertSubroot._manageNode(managedNode.node); | ||
if (index$1(target, managedNode.node)) inertSubroot._manageNode(managedNode.node); | ||
} | ||
@@ -705,3 +726,3 @@ } catch (err) { | ||
// Ensure inert styles are added there. | ||
if (!this._document.body.contains(root)) { | ||
if (!index$1(this._document.body, root)) { | ||
var parent = root.parentNode; | ||
@@ -708,0 +729,0 @@ while (parent) { |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t():"function"==typeof define&&define.amd?define(t):t()}(this,function(){"use strict";function e(e,t){var r=window.Element.prototype,n=r.matches||r.mozMatchesSelector||r.msMatchesSelector||r.oMatchesSelector||r.webkitMatchesSelector;if(!e||1!==e.nodeType)return!1;var o=e.parentNode;if(n)return n.call(e,t);for(var i=o.querySelectorAll(t),a=i.length,s=0;s<a;s++)if(i[s]===e)return!0;return!1}var t=e,r=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},n=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();!function(e){function o(e,t,r){if(e.nodeType==Node.ELEMENT_NODE){var n=e;t&&t(n);var i=n.shadowRoot||n.webkitShadowRoot;if(i)return void o(i,t,i);if("content"==n.localName){for(var a=n,s=a.getDistributedNodes?a.getDistributedNodes():[],d=0;d<s.length;d++)o(s[d],t,r);return}if("slot"==n.localName){for(var u=n,l=u.assignedNodes?u.assignedNodes({flatten:!0}):[],h=0;h<l.length;h++)o(l[h],t,r);return}}for(var f=e.firstChild;null!=f;)o(f,t,r),f=f.nextSibling}function i(t){if(!t.querySelector("style#inert-style")){var r=e.createElement("style");r.setAttribute("id","inert-style"),r.textContent="\n[inert] {\n pointer-events: none;\n cursor: default;\n}\n\n[inert], [inert] * {\n user-select: none;\n -webkit-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\n}\n",t.appendChild(r)}}var a=["a[href]","area[href]","input:not([disabled])","select:not([disabled])","textarea:not([disabled])","button:not([disabled])","iframe","object","embed","[contenteditable]"].join(","),s=function(){function i(e,t){r(this,i),this._inertManager=t,this._rootElement=e,this._managedNodes=new Set([]),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 n(i,[{key:"destructor",value:function(){this._observer.disconnect(),this._observer=null,this._rootElement&&this._rootElement.removeAttribute("aria-hidden"),this._rootElement=null;var e=!0,t=!1,r=void 0;try{for(var n,o=this._managedNodes[Symbol.iterator]();!(e=(n=o.next()).done);e=!0){var i=n.value;this._unmanageNode(i.node)}}catch(e){t=!0,r=e}finally{try{!e&&o.return&&o.return()}finally{if(t)throw r}}this._managedNodes=null,this._inertManager=null}},{key:"_makeSubtreeUnfocusable",value:function(t){var r=this;o(t,function(e){return r._visitNode(e)});var n=e.activeElement;if(!e.body.contains(t)){for(var i=t,a=void 0;i;){if(i.nodeType===Node.DOCUMENT_FRAGMENT_NODE){a=i;break}i=i.parentNode}a&&(n=a.activeElement)}t.contains(n)&&n.blur()}},{key:"_visitNode",value:function(e){e.nodeType===Node.ELEMENT_NODE&&(e!==this._rootElement&&e.hasAttribute("inert")&&this._adoptInertRoot(e),(t(e,a)||e.hasAttribute("tabindex"))&&this._manageNode(e))}},{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;o(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));var r=!0,n=!1,o=void 0;try{for(var i,a=t.managedNodes[Symbol.iterator]();!(r=(i=a.next()).done);r=!0){var s=i.value;this._manageNode(s.node)}}catch(e){n=!0,o=e}finally{try{!r&&a.return&&a.return()}finally{if(n)throw o}}}},{key:"_onMutation",value:function(e,t){var r=!0,n=!1,o=void 0;try{for(var i,a=e[Symbol.iterator]();!(r=(i=a.next()).done);r=!0){var s=i.value,d=s.target;if("childList"===s.type){var u=!0,l=!1,h=void 0;try{for(var f,c=Array.from(s.addedNodes)[Symbol.iterator]();!(u=(f=c.next()).done);u=!0){var v=f.value;this._makeSubtreeUnfocusable(v)}}catch(e){l=!0,h=e}finally{try{!u&&c.return&&c.return()}finally{if(l)throw h}}var y=!0,b=!1,_=void 0;try{for(var m,g=Array.from(s.removedNodes)[Symbol.iterator]();!(y=(m=g.next()).done);y=!0){var N=m.value;this._unmanageSubtree(N)}}catch(e){b=!0,_=e}finally{try{!y&&g.return&&g.return()}finally{if(b)throw _}}}else if("attributes"===s.type)if("tabindex"===s.attributeName)this._manageNode(d);else if(d!==this._rootElement&&"inert"===s.attributeName&&d.hasAttribute("inert")){this._adoptInertRoot(d);var w=this._inertManager.getInertRoot(d),I=!0,E=!1,p=void 0;try{for(var x,k=this._managedNodes[Symbol.iterator]();!(I=(x=k.next()).done);I=!0){var S=x.value;d.contains(S.node)&&w._manageNode(S.node)}}catch(e){E=!0,p=e}finally{try{!I&&k.return&&k.return()}finally{if(E)throw p}}}}}catch(e){n=!0,o=e}finally{try{!r&&a.return&&a.return()}finally{if(n)throw o}}}},{key:"managedNodes",get:function(){return new Set(this._managedNodes)}}]),i}(),d=function(){function e(t,n){r(this,e),this._node=t,this._overrodeFocusMethod=!1,this._inertRoots=new Set([n]),this._destroyed=!1,this.ensureUntabbable()}return n(e,[{key:"destructor",value:function(){this._throwIfDestroyed(),this._node&&(this.hasSavedTabIndex?this._node.setAttribute("tabindex",this.savedTabIndex):this._node.removeAttribute("tabindex"),this._overrodeFocusMethod&&delete this._node.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;if(t(e,a)){if(e.tabIndex===-1&&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"_savedTabIndex"in this}},{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}}]),e}(),u=function(){function e(t){if(r(this,e),!t)throw new Error("Missing required argument; InertManager needs to wrap a document.");this._document=t,this._managedNodes=new Map,this._inertRoots=new Map,this._observer=new MutationObserver(this._watchForInert.bind(this)),i(t.head||t.body||t.documentElement),"loading"===t.readyState?t.addEventListener("DOMContentLoaded",this._onDocumentLoaded.bind(this)):this._onDocumentLoaded()}return n(e,[{key:"setInert",value:function(e,t){if(t){if(this._inertRoots.has(e))return;var r=new s(e,this);if(e.setAttribute("inert",""),this._inertRoots.set(e,r),!this._document.body.contains(e))for(var n=e.parentNode;n;)11===n.nodeType&&i(n),n=n.parentNode}else{if(!this._inertRoots.has(e))return;var o=this._inertRoots.get(e);o.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 r=this._managedNodes.get(e);return void 0!==r?(r.addInertRoot(t),r.ensureUntabbable()):r=new d(e,t),this._managedNodes.set(e,r),r}},{key:"deregister",value:function(e,t){var r=this._managedNodes.get(e);return r?(r.removeInertRoot(t),r.destroyed&&this._managedNodes.delete(e),r):null}},{key:"_onDocumentLoaded",value:function(){var e=Array.from(this._document.querySelectorAll("[inert]")),t=!0,r=!1,n=void 0;try{for(var o,i=e[Symbol.iterator]();!(t=(o=i.next()).done);t=!0){var a=o.value;this.setInert(a,!0)}}catch(e){r=!0,n=e}finally{try{!t&&i.return&&i.return()}finally{if(r)throw n}}this._observer.observe(this._document.body,{attributes:!0,subtree:!0,childList:!0})}},{key:"_watchForInert",value:function(e,r){var n=!0,o=!1,i=void 0;try{for(var a,s=e[Symbol.iterator]();!(n=(a=s.next()).done);n=!0){var d=a.value;switch(d.type){case"childList":var u=!0,l=!1,h=void 0;try{for(var f,c=Array.from(d.addedNodes)[Symbol.iterator]();!(u=(f=c.next()).done);u=!0){var v=f.value;if(v.nodeType===Node.ELEMENT_NODE){var y=Array.from(v.querySelectorAll("[inert]"));t(v,"[inert]")&&y.unshift(v);var b=!0,_=!1,m=void 0;try{for(var g,N=y[Symbol.iterator]();!(b=(g=N.next()).done);b=!0){var w=g.value;this.setInert(w,!0)}}catch(e){_=!0,m=e}finally{try{!b&&N.return&&N.return()}finally{if(_)throw m}}}}}catch(e){l=!0,h=e}finally{try{!u&&c.return&&c.return()}finally{if(l)throw h}}break;case"attributes":if("inert"!==d.attributeName)continue;var I=d.target,E=I.hasAttribute("inert");this.setInert(I,E)}}}catch(e){o=!0,i=e}finally{try{!n&&s.return&&s.return()}finally{if(o)throw i}}}}]),e}(),l=new u(e);Object.defineProperty(Element.prototype,"inert",{enumerable:!0,get:function(){return this.hasAttribute("inert")},set:function(e){l.setInert(this,e)}})}(document)}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t():"function"==typeof define&&define.amd?define(t):t()}(0,function(){"use strict";function e(e,t){var r=window.Element.prototype,n=r.matches||r.mozMatchesSelector||r.msMatchesSelector||r.oMatchesSelector||r.webkitMatchesSelector;if(!e||1!==e.nodeType)return!1;var o=e.parentNode;if(n)return n.call(e,t);for(var i=o.querySelectorAll(t),a=i.length,s=0;s<a;s++)if(i[s]===e)return!0;return!1}function t(e,t){return e===t||!!(16&e.compareDocumentPosition(t))}var r=e,n=t,o=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},i=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();!function(e){function t(e,r,n){if(e.nodeType==Node.ELEMENT_NODE){var o=e;r&&r(o);var i=o.shadowRoot||o.webkitShadowRoot;if(i)return void t(i,r,i);if("content"==o.localName){for(var a=o,s=a.getDistributedNodes?a.getDistributedNodes():[],d=0;d<s.length;d++)t(s[d],r,n);return}if("slot"==o.localName){for(var u=o,l=u.assignedNodes?u.assignedNodes({flatten:!0}):[],h=0;h<l.length;h++)t(l[h],r,n);return}}for(var f=e.firstChild;null!=f;)t(f,r,n),f=f.nextSibling}function a(t){if(!t.querySelector("style#inert-style")){var r=e.createElement("style");r.setAttribute("id","inert-style"),r.textContent="\n[inert] {\n pointer-events: none;\n cursor: default;\n}\n\n[inert], [inert] * {\n user-select: none;\n -webkit-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\n}\n",t.appendChild(r)}}var s=["a[href]","area[href]","input:not([disabled])","select:not([disabled])","textarea:not([disabled])","button:not([disabled])","iframe","object","embed","[contenteditable]"].join(","),d=function(){function a(e,t){o(this,a),this._inertManager=t,this._rootElement=e,this._managedNodes=new Set([]),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 i(a,[{key:"destructor",value:function(){this._observer.disconnect(),this._observer=null,this._rootElement&&this._rootElement.removeAttribute("aria-hidden"),this._rootElement=null;var e=!0,t=!1,r=void 0;try{for(var n,o=this._managedNodes[Symbol.iterator]();!(e=(n=o.next()).done);e=!0){var i=n.value;this._unmanageNode(i.node)}}catch(e){t=!0,r=e}finally{try{!e&&o.return&&o.return()}finally{if(t)throw r}}this._managedNodes=null,this._inertManager=null}},{key:"_makeSubtreeUnfocusable",value:function(r){var o=this;t(r,function(e){return o._visitNode(e)});var i=e.activeElement;if(!n(e.body,r)){for(var a=r,s=void 0;a;){if(a.nodeType===Node.DOCUMENT_FRAGMENT_NODE){s=a;break}a=a.parentNode}s&&(i=s.activeElement)}n(r,i)&&i.blur()}},{key:"_visitNode",value:function(e){e.nodeType===Node.ELEMENT_NODE&&(e!==this._rootElement&&e.hasAttribute("inert")&&this._adoptInertRoot(e),(r(e,s)||e.hasAttribute("tabindex"))&&this._manageNode(e))}},{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 r=this;t(e,function(e){return r._unmanageNode(e)})}},{key:"_adoptInertRoot",value:function(e){var t=this._inertManager.getInertRoot(e);t||(this._inertManager.setInert(e,!0),t=this._inertManager.getInertRoot(e));var r=!0,n=!1,o=void 0;try{for(var i,a=t.managedNodes[Symbol.iterator]();!(r=(i=a.next()).done);r=!0){var s=i.value;this._manageNode(s.node)}}catch(e){n=!0,o=e}finally{try{!r&&a.return&&a.return()}finally{if(n)throw o}}}},{key:"_onMutation",value:function(e,t){var r=!0,o=!1,i=void 0;try{for(var a,s=e[Symbol.iterator]();!(r=(a=s.next()).done);r=!0){var d=a.value,u=d.target;if("childList"===d.type){var l=!0,h=!1,f=void 0;try{for(var c,v=Array.from(d.addedNodes)[Symbol.iterator]();!(l=(c=v.next()).done);l=!0){var y=c.value;this._makeSubtreeUnfocusable(y)}}catch(e){h=!0,f=e}finally{try{!l&&v.return&&v.return()}finally{if(h)throw f}}var b=!0,_=!1,m=void 0;try{for(var g,N=Array.from(d.removedNodes)[Symbol.iterator]();!(b=(g=N.next()).done);b=!0){var w=g.value;this._unmanageSubtree(w)}}catch(e){_=!0,m=e}finally{try{!b&&N.return&&N.return()}finally{if(_)throw m}}}else if("attributes"===d.type)if("tabindex"===d.attributeName)this._manageNode(u);else if(u!==this._rootElement&&"inert"===d.attributeName&&u.hasAttribute("inert")){this._adoptInertRoot(u);var I=this._inertManager.getInertRoot(u),p=!0,E=!1,x=void 0;try{for(var k,S=this._managedNodes[Symbol.iterator]();!(p=(k=S.next()).done);p=!0){var M=k.value;n(u,M.node)&&I._manageNode(M.node)}}catch(e){E=!0,x=e}finally{try{!p&&S.return&&S.return()}finally{if(E)throw x}}}}}catch(e){o=!0,i=e}finally{try{!r&&s.return&&s.return()}finally{if(o)throw i}}}},{key:"managedNodes",get:function(){return new Set(this._managedNodes)}}]),a}(),u=function(){function e(t,r){o(this,e),this._node=t,this._overrodeFocusMethod=!1,this._inertRoots=new Set([r]),this._destroyed=!1,this.ensureUntabbable()}return i(e,[{key:"destructor",value:function(){this._throwIfDestroyed(),this._node&&(this.hasSavedTabIndex?this._node.setAttribute("tabindex",this.savedTabIndex):this._node.removeAttribute("tabindex"),this._overrodeFocusMethod&&delete this._node.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;if(r(e,s)){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"_savedTabIndex"in this}},{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}}]),e}(),l=function(){function e(t){if(o(this,e),!t)throw new Error("Missing required argument; InertManager needs to wrap a document.");this._document=t,this._managedNodes=new Map,this._inertRoots=new Map,this._observer=new MutationObserver(this._watchForInert.bind(this)),a(t.head||t.body||t.documentElement),"loading"===t.readyState?t.addEventListener("DOMContentLoaded",this._onDocumentLoaded.bind(this)):this._onDocumentLoaded()}return i(e,[{key:"setInert",value:function(e,t){if(t){if(this._inertRoots.has(e))return;var r=new d(e,this);if(e.setAttribute("inert",""),this._inertRoots.set(e,r),!n(this._document.body,e))for(var o=e.parentNode;o;)11===o.nodeType&&a(o),o=o.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 r=this._managedNodes.get(e);return void 0!==r?(r.addInertRoot(t),r.ensureUntabbable()):r=new u(e,t),this._managedNodes.set(e,r),r}},{key:"deregister",value:function(e,t){var r=this._managedNodes.get(e);return r?(r.removeInertRoot(t),r.destroyed&&this._managedNodes.delete(e),r):null}},{key:"_onDocumentLoaded",value:function(){var e=Array.from(this._document.querySelectorAll("[inert]")),t=!0,r=!1,n=void 0;try{for(var o,i=e[Symbol.iterator]();!(t=(o=i.next()).done);t=!0){var a=o.value;this.setInert(a,!0)}}catch(e){r=!0,n=e}finally{try{!t&&i.return&&i.return()}finally{if(r)throw n}}this._observer.observe(this._document.body,{attributes:!0,subtree:!0,childList:!0})}},{key:"_watchForInert",value:function(e,t){var n=!0,o=!1,i=void 0;try{for(var a,s=e[Symbol.iterator]();!(n=(a=s.next()).done);n=!0){var d=a.value;switch(d.type){case"childList":var u=!0,l=!1,h=void 0;try{for(var f,c=Array.from(d.addedNodes)[Symbol.iterator]();!(u=(f=c.next()).done);u=!0){var v=f.value;if(v.nodeType===Node.ELEMENT_NODE){var y=Array.from(v.querySelectorAll("[inert]"));r(v,"[inert]")&&y.unshift(v);var b=!0,_=!1,m=void 0;try{for(var g,N=y[Symbol.iterator]();!(b=(g=N.next()).done);b=!0){var w=g.value;this.setInert(w,!0)}}catch(e){_=!0,m=e}finally{try{!b&&N.return&&N.return()}finally{if(_)throw m}}}}}catch(e){l=!0,h=e}finally{try{!u&&c.return&&c.return()}finally{if(l)throw h}}break;case"attributes":if("inert"!==d.attributeName)continue;var I=d.target,p=I.hasAttribute("inert");this.setInert(I,p)}}}catch(e){o=!0,i=e}finally{try{!n&&s.return&&s.return()}finally{if(o)throw i}}}}]),e}(),h=new l(e);Object.defineProperty(Element.prototype,"inert",{enumerable:!0,get:function(){return this.hasAttribute("inert")},set:function(e){h.setInert(this,e)}})}(document)}); |
{ | ||
"name": "wicg-inert", | ||
"version": "1.1.3", | ||
"version": "1.1.4", | ||
"description": "A polyfill for the proposed inert API", | ||
@@ -10,3 +10,4 @@ "main": "dist/inert.js", | ||
"build": "rollem", | ||
"dev": "rollem --watch" | ||
"dev": "rollem --watch", | ||
"prepublish": "npm run test && npm run build" | ||
}, | ||
@@ -34,3 +35,4 @@ "repository": { | ||
"dependencies": { | ||
"dom-matches": "^2.0.0" | ||
"dom-matches": "^2.0.0", | ||
"node-contains": "^1.0.0" | ||
}, | ||
@@ -61,2 +63,3 @@ "devDependencies": { | ||
"port": "8080", | ||
"service": "sauce-connect", | ||
"platforms": [ | ||
@@ -63,0 +66,0 @@ [ |
@@ -19,2 +19,3 @@ /** | ||
import matches from 'dom-matches'; | ||
import contains from 'node-contains'; | ||
@@ -117,3 +118,3 @@ (function(document) { | ||
let activeElement = document.activeElement; | ||
if (!document.body.contains(startNode)) { | ||
if (!contains(document.body, startNode)) { | ||
// startNode may be in shadow DOM, so find its nearest shadowRoot to get the activeElement. | ||
@@ -132,3 +133,3 @@ let node = startNode; | ||
} | ||
if (startNode.contains(activeElement)) | ||
if (contains(startNode, activeElement)) | ||
activeElement.blur(); | ||
@@ -226,3 +227,3 @@ } | ||
for (let managedNode of this._managedNodes) { | ||
if (target.contains(managedNode.node)) | ||
if (contains(target, managedNode.node)) | ||
inertSubroot._manageNode(managedNode.node); | ||
@@ -445,3 +446,3 @@ } | ||
// Ensure inert styles are added there. | ||
if (!this._document.body.contains(root)) { | ||
if (!contains(this._document.body, root)) { | ||
let parent = root.parentNode; | ||
@@ -448,0 +449,0 @@ while (parent) { |
@@ -17,3 +17,13 @@ /** | ||
*/ | ||
/* eslint-disable no-unused-vars */ | ||
/** | ||
* The FixtureLoader class takes a URL, loads its contents, and inserts them into the DOM. | ||
* It also provides a `destroy` method to clean out the page contents. | ||
*/ | ||
class Fixture { | ||
/** | ||
* Setup initial state. | ||
*/ | ||
constructor() { | ||
@@ -23,4 +33,8 @@ this._fixture = undefined; | ||
load(url, callback) { | ||
// Add a <div id="fixture"> to the body | ||
/** | ||
* Load the given URL and stick its contents into a `<div id="fixture">`. | ||
* @param {*} url | ||
* @return {Promise} | ||
*/ | ||
load(url) { | ||
this._fixture = document.createElement('div'); | ||
@@ -31,6 +45,6 @@ this._fixture.id = 'fixture'; | ||
// Fetch template and insert in #fixture | ||
const promise = new Promise((resolve, reject) => { | ||
return new Promise((resolve, reject) => { | ||
fetch(url) | ||
.then((response) => { | ||
return response.text() | ||
return response.text(); | ||
}).then((html) => { | ||
@@ -43,13 +57,7 @@ this._fixture.innerHTML = html; | ||
}); | ||
// Use this promise instead of immediately triggering the callback | ||
// in order to wait till the next microtask and give any Mutation Observers | ||
// a chance to run | ||
promise | ||
.then(callback) | ||
.catch((err) => { | ||
callback(err) | ||
}); | ||
} | ||
/** | ||
* Remove the current fixture and delete it. | ||
*/ | ||
destroy() { | ||
@@ -56,0 +64,0 @@ document.body.removeChild(this._fixture); |
@@ -19,4 +19,6 @@ /** | ||
const expect = chai.expect; | ||
const fixture = new Fixture(); | ||
const fixtureLoader = new Fixture(); | ||
/* eslint-disable require-jsdoc */ | ||
function isUnfocusable(el) { | ||
@@ -35,3 +37,3 @@ var oldActiveElement = document.activeElement; | ||
describe('Basic', function() { | ||
/* eslint-disable no-invalid-this */ | ||
this.timeout(10000); | ||
@@ -46,8 +48,8 @@ | ||
describe('children of declaratively inert parent', function() { | ||
beforeEach(function(done) { | ||
fixture.load('fixtures/basic.html', done); | ||
beforeEach(function() { | ||
return fixtureLoader.load('fixtures/basic.html'); | ||
}); | ||
afterEach(function() { | ||
fixture.destroy(); | ||
fixtureLoader.destroy(); | ||
}); | ||
@@ -71,3 +73,4 @@ | ||
it('programmatically setting inert to false should remove attribute and un-inert content', function() { | ||
it('programmatically setting inert to false should remove attribute and un-inert content', | ||
function() { | ||
const inertContainer = document.querySelector('[inert]'); | ||
@@ -136,4 +139,6 @@ expect(inertContainer.hasAttribute('inert')).to.equal(true); | ||
} | ||
let fixture, host; | ||
let fixture; | ||
let host; | ||
beforeEach(function() { | ||
@@ -147,6 +152,2 @@ fixture = document.querySelector('#fixture'); | ||
afterEach(function() { | ||
fixture.removeChild(host); | ||
}); | ||
it('should apply inside shadow trees', function() { | ||
@@ -186,4 +187,6 @@ const shadowButton = document.createElement('button'); | ||
} | ||
let fixture, host; | ||
let fixture; | ||
let host; | ||
beforeEach(function() { | ||
@@ -195,10 +198,6 @@ fixture = document.querySelector('#fixture'); | ||
host.attachShadow({ | ||
mode: 'open' | ||
mode: 'open', | ||
}); | ||
}); | ||
afterEach(function() { | ||
fixture.removeChild(host); | ||
}); | ||
it('should apply inside shadow trees', function() { | ||
@@ -220,4 +219,4 @@ const shadowButton = document.createElement('button'); | ||
Promise.resolve().then(() => { | ||
expect(getComputedStyle(shadowButton).pointerEvents).to.equal('none'); | ||
done(); | ||
expect(getComputedStyle(shadowButton).pointerEvents).to.equal('none'); | ||
done(); | ||
}); | ||
@@ -239,8 +238,8 @@ }); | ||
describe('nested inert regions', function() { | ||
beforeEach(function(done) { | ||
fixture.load('fixtures/nested.html', done); | ||
beforeEach(function() { | ||
return fixtureLoader.load('fixtures/nested.html'); | ||
}); | ||
afterEach(function() { | ||
fixture.destroy(); | ||
fixtureLoader.destroy(); | ||
}); | ||
@@ -252,3 +251,3 @@ | ||
const outerFakeButton = document.querySelector('#outer-fake-button'); | ||
expect(isUnfocusable(outerButton)).to.equal(true); | ||
expect(isUnfocusable(outerFakeButton)).to.equal(true); | ||
@@ -267,3 +266,3 @@ const innerButton = document.querySelector('#inner-button'); | ||
const outerFakeButton = document.querySelector('#outer-fake-button'); | ||
expect(isUnfocusable(outerButton)).to.equal(true); | ||
expect(isUnfocusable(outerFakeButton)).to.equal(true); | ||
@@ -282,3 +281,3 @@ const innerButton = document.querySelector('#inner-button'); | ||
const outerFakeButton = document.querySelector('#outer-fake-button'); | ||
expect(isUnfocusable(outerButton)).to.equal(false); | ||
expect(isUnfocusable(outerFakeButton)).to.equal(false); | ||
@@ -313,8 +312,8 @@ const innerButton = document.querySelector('#inner-button'); | ||
describe('reapply existing tabindex', function() { | ||
beforeEach(function(done) { | ||
fixture.load('fixtures/tabindex.html', done); | ||
beforeEach(function() { | ||
return fixtureLoader.load('fixtures/tabindex.html'); | ||
}); | ||
afterEach(function() { | ||
fixture.destroy(); | ||
fixtureLoader.destroy(); | ||
}); | ||
@@ -342,3 +341,3 @@ | ||
for (let el of Array.from(container.children)) { | ||
let tabindex = tabindexes.get(el) | ||
let tabindex = tabindexes.get(el); | ||
if (tabindex) { | ||
@@ -351,5 +350,4 @@ expect(el.hasAttribute('tabindex')).to.equal(true); | ||
} | ||
}); | ||
}); | ||
}); |
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
107611
1864
2
+ Addednode-contains@^1.0.0
+ Addednode-contains@1.0.0(transitive)