Socket
Socket
Sign inDemoInstall

wicg-inert

Package Overview
Dependencies
Maintainers
2
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wicg-inert - npm Package Compare versions

Comparing version 1.1.4 to 1.1.6

CONTRIBUTING.md

200

dist/inert.js

@@ -55,23 +55,2 @@ (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) {

@@ -102,19 +81,11 @@ if (!(instance instanceof Constructor)) {

/**
*
* Copyright 2016 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* This work is licensed under the W3C Software and Document License
* (http://www.w3.org/Consortium/Legal/2015/copyright-software-and-document).
*/
(function (document) {
// Convenience function for converting NodeLists.
/** @type {function(number,number):Array} */
var slice = Array.prototype.slice;
/** @type {string} */

@@ -161,2 +132,5 @@ var _focusableElementsString = ['a[href]', 'area[href]', 'input:not([disabled])', 'select:not([disabled])', 'textarea:not([disabled])', 'button:not([disabled])', 'iframe', 'object', 'embed', '[contenteditable]'].join(',');

// Make the subtree hidden from assistive technology
if (this._rootElement.hasAttribute('aria-hidden')) {
this._savedAriaHidden = this._rootElement.getAttribute('aria-hidden');
}
this._rootElement.setAttribute('aria-hidden', 'true');

@@ -188,3 +162,9 @@

if (this._rootElement) this._rootElement.removeAttribute('aria-hidden');
if (this._rootElement) {
if (this.hasSavedAriaHidden) {
this._rootElement.setAttribute('aria-hidden', this.savedAriaHidden);
} else {
this._rootElement.removeAttribute('aria-hidden');
}
}
this._rootElement = null;

@@ -241,3 +221,3 @@

var activeElement = document.activeElement;
if (!index$1(document.body, startNode)) {
if (!contains(document.body, startNode)) {
// startNode may be in shadow DOM, so find its nearest shadowRoot to get the activeElement.

@@ -253,5 +233,9 @@ var node = startNode;

}
if (root) activeElement = root.activeElement;
if (root) {
activeElement = root.activeElement;
}
}
if (index$1(startNode, activeElement)) activeElement.blur();
if (contains(startNode, activeElement)) {
activeElement.blur();
}
}

@@ -266,9 +250,15 @@

value: function _visitNode(node) {
if (node.nodeType !== Node.ELEMENT_NODE) return;
if (node.nodeType !== Node.ELEMENT_NODE) {
return;
}
// If a descendant inert root becomes un-inert, its descendants will still be inert because of
// this inert root, so all of its managed nodes need to be adopted by this InertRoot.
if (node !== this._rootElement && node.hasAttribute('inert')) this._adoptInertRoot(node);
if (node !== this._rootElement && node.hasAttribute('inert')) {
this._adoptInertRoot(node);
}
if (index(node, _focusableElementsString) || node.hasAttribute('tabindex')) this._manageNode(node);
if (index(node, _focusableElementsString) || node.hasAttribute('tabindex')) {
this._manageNode(node);
}
}

@@ -297,3 +287,5 @@

var inertNode = this._inertManager.deregister(node, this);
if (inertNode) this._managedNodes.delete(inertNode);
if (inertNode) {
this._managedNodes.delete(inertNode);
}
}

@@ -384,7 +376,9 @@

try {
for (var _iterator4 = Array.from(record.addedNodes)[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
for (var _iterator4 = slice.call(record.addedNodes)[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
var node = _step4.value;
this._makeSubtreeUnfocusable(node);
} // Un-manage removed nodes
}
// Un-manage removed nodes
} catch (err) {

@@ -410,3 +404,3 @@ _didIteratorError4 = true;

try {
for (var _iterator5 = Array.from(record.removedNodes)[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {
for (var _iterator5 = slice.call(record.removedNodes)[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {
var _node = _step5.value;

@@ -447,3 +441,5 @@

if (index$1(target, managedNode.node)) inertSubroot._manageNode(managedNode.node);
if (contains(target, managedNode.node)) {
inertSubroot._manageNode(managedNode.node);
}
}

@@ -487,2 +483,24 @@ } catch (err) {

}
/** @return {boolean} */
}, {
key: 'hasSavedAriaHidden',
get: function get$$1() {
return '_savedAriaHidden' in this;
}
/** @param {string} ariaHidden */
}, {
key: 'savedAriaHidden',
set: function set$$1(ariaHidden) {
this._savedAriaHidden = ariaHidden;
}
/** @return {string} */
,
get: function get$$1() {
return this._savedAriaHidden;
}
}]);

@@ -547,6 +565,12 @@ return InertRoot;

if (this._node) {
if (this.hasSavedTabIndex) this._node.setAttribute('tabindex', this.savedTabIndex);else this._node.removeAttribute('tabindex');
if (this.hasSavedTabIndex) {
this._node.setAttribute('tabindex', this.savedTabIndex);
} else {
this._node.removeAttribute('tabindex');
}
// Use `delete` to restore native focus method.
if (this._overrodeFocusMethod) delete this._node.focus;
if (this._overrodeFocusMethod) {
delete this._node.focus;
}
}

@@ -572,3 +596,5 @@ this._node = null;

value: function _throwIfDestroyed() {
if (this.destroyed) throw new Error('Trying to access destroyed InertNode');
if (this.destroyed) {
throw new Error('Trying to access destroyed InertNode');
}
}

@@ -586,5 +612,9 @@

if (index(node, _focusableElementsString)) {
if (node.tabIndex === -1 && this.hasSavedTabIndex) return;
if (node.tabIndex === -1 && this.hasSavedTabIndex) {
return;
}
if (node.hasAttribute('tabindex')) this._savedTabIndex = node.tabIndex;
if (node.hasAttribute('tabindex')) {
this._savedTabIndex = node.tabIndex;
}
node.setAttribute('tabindex', '-1');

@@ -625,3 +655,5 @@ if (node.nodeType === Node.ELEMENT_NODE) {

this._inertRoots.delete(inertRoot);
if (this._inertRoots.size === 0) this.destructor();
if (this._inertRoots.size === 0) {
this.destructor();
}
}

@@ -685,3 +717,5 @@ }, {

if (!document) throw new Error('Missing required argument; InertManager needs to wrap a document.');
if (!document) {
throw new Error('Missing required argument; InertManager needs to wrap a document.');
}

@@ -731,4 +765,6 @@ /** @type {Document} */

if (inert) {
if (this._inertRoots.has(root)) // element is already inert
if (this._inertRoots.has(root)) {
// element is already inert
return;
}

@@ -740,3 +776,3 @@ var inertRoot = new InertRoot(root, this);

// Ensure inert styles are added there.
if (!index$1(this._document.body, root)) {
if (!contains(this._document.body, root)) {
var parent = root.parentNode;

@@ -751,4 +787,6 @@ while (parent) {

} else {
if (!this._inertRoots.has(root)) // element is already non-inert
if (!this._inertRoots.has(root)) {
// element is already non-inert
return;
}

@@ -815,6 +853,10 @@ var _inertRoot = this._inertRoots.get(root);

var inertNode = this._managedNodes.get(node);
if (!inertNode) return null;
if (!inertNode) {
return null;
}
inertNode.removeInertRoot(inertRoot);
if (inertNode.destroyed) this._managedNodes.delete(node);
if (inertNode.destroyed) {
this._managedNodes.delete(node);
}

@@ -832,3 +874,3 @@ return inertNode;

// Find all inert roots in document and make them actually inert.
var inertElements = Array.from(this._document.querySelectorAll('[inert]'));
var inertElements = slice.call(this._document.querySelectorAll('[inert]'));
var _iteratorNormalCompletion7 = true;

@@ -843,3 +885,5 @@ var _didIteratorError7 = false;

this.setInert(inertElement, true);
} // Comment this out to use programmatic API only.
}
// Comment this out to use programmatic API only.
} catch (err) {

@@ -887,8 +931,12 @@ _didIteratorError7 = true;

try {
for (var _iterator9 = Array.from(record.addedNodes)[Symbol.iterator](), _step9; !(_iteratorNormalCompletion9 = (_step9 = _iterator9.next()).done); _iteratorNormalCompletion9 = true) {
for (var _iterator9 = slice.call(record.addedNodes)[Symbol.iterator](), _step9; !(_iteratorNormalCompletion9 = (_step9 = _iterator9.next()).done); _iteratorNormalCompletion9 = true) {
var node = _step9.value;
if (node.nodeType !== Node.ELEMENT_NODE) continue;
var inertElements = Array.from(node.querySelectorAll('[inert]'));
if (index(node, '[inert]')) inertElements.unshift(node);
if (node.nodeType !== Node.ELEMENT_NODE) {
continue;
}
var inertElements = slice.call(node.querySelectorAll('[inert]'));
if (index(node, '[inert]')) {
inertElements.unshift(node);
}
var _iteratorNormalCompletion10 = true;

@@ -936,3 +984,5 @@ var _didIteratorError10 = false;

case 'attributes':
if (record.attributeName !== 'inert') continue;
if (record.attributeName !== 'inert') {
continue;
}
var target = record.target;

@@ -975,3 +1025,5 @@ var inert = target.hasAttribute('inert');

var element = /** @type {Element} */node;
if (callback) callback(element);
if (callback) {
callback(element);
}

@@ -1038,2 +1090,16 @@ // Descend into node:

/**
* `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 other && (node === other || !!(node.compareDocumentPosition(other) & 16));
}
var inertManager = new InertManager(document);

@@ -1040,0 +1106,0 @@

@@ -1,1 +0,1 @@

!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)});
!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 n=window.Element.prototype,r=n.matches||n.mozMatchesSelector||n.msMatchesSelector||n.oMatchesSelector||n.webkitMatchesSelector;if(!e||1!==e.nodeType)return!1;var i=e.parentNode;if(r)return r.call(e,t);for(var o=i.querySelectorAll(t),a=o.length,s=0;s<a;s++)if(o[s]===e)return!0;return!1}var t=e,n=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();!function(e){function i(e,t,n){if(e.nodeType==Node.ELEMENT_NODE){var r=e;t&&t(r);var o=r.shadowRoot||r.webkitShadowRoot;if(o)return void i(o,t,o);if("content"==r.localName){for(var a=r,s=a.getDistributedNodes?a.getDistributedNodes():[],d=0;d<s.length;d++)i(s[d],t,n);return}if("slot"==r.localName){for(var u=r,l=u.assignedNodes?u.assignedNodes({flatten:!0}):[],h=0;h<l.length;h++)i(l[h],t,n);return}}for(var f=e.firstChild;null!=f;)i(f,t,n),f=f.nextSibling}function o(t){if(!t.querySelector("style#inert-style")){var n=e.createElement("style");n.setAttribute("id","inert-style"),n.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(n)}}function a(e,t){return t&&(e===t||!!(16&e.compareDocumentPosition(t)))}var s=Array.prototype.slice,d=["a[href]","area[href]","input:not([disabled])","select:not([disabled])","textarea:not([disabled])","button:not([disabled])","iframe","object","embed","[contenteditable]"].join(","),u=function(){function o(e,t){n(this,o),this._inertManager=t,this._rootElement=e,this._managedNodes=new Set([]),this._rootElement.hasAttribute("aria-hidden")&&(this._savedAriaHidden=this._rootElement.getAttribute("aria-hidden")),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 r(o,[{key:"destructor",value:function(){this._observer.disconnect(),this._observer=null,this._rootElement&&(this.hasSavedAriaHidden?this._rootElement.setAttribute("aria-hidden",this.savedAriaHidden):this._rootElement.removeAttribute("aria-hidden")),this._rootElement=null;var e=!0,t=!1,n=void 0;try{for(var r,i=this._managedNodes[Symbol.iterator]();!(e=(r=i.next()).done);e=!0){var o=r.value;this._unmanageNode(o.node)}}catch(e){t=!0,n=e}finally{try{!e&&i.return&&i.return()}finally{if(t)throw n}}this._managedNodes=null,this._inertManager=null}},{key:"_makeSubtreeUnfocusable",value:function(t){var n=this;i(t,function(e){return n._visitNode(e)});var r=e.activeElement;if(!a(e.body,t)){for(var o=t,s=void 0;o;){if(o.nodeType===Node.DOCUMENT_FRAGMENT_NODE){s=o;break}o=o.parentNode}s&&(r=s.activeElement)}a(t,r)&&r.blur()}},{key:"_visitNode",value:function(e){e.nodeType===Node.ELEMENT_NODE&&(e!==this._rootElement&&e.hasAttribute("inert")&&this._adoptInertRoot(e),(t(e,d)||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;i(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 n=!0,r=!1,i=void 0;try{for(var o,a=t.managedNodes[Symbol.iterator]();!(n=(o=a.next()).done);n=!0){var s=o.value;this._manageNode(s.node)}}catch(e){r=!0,i=e}finally{try{!n&&a.return&&a.return()}finally{if(r)throw i}}}},{key:"_onMutation",value:function(e,t){var n=!0,r=!1,i=void 0;try{for(var o,d=e[Symbol.iterator]();!(n=(o=d.next()).done);n=!0){var u=o.value,l=u.target;if("childList"===u.type){var h=!0,f=!1,c=void 0;try{for(var v,y=s.call(u.addedNodes)[Symbol.iterator]();!(h=(v=y.next()).done);h=!0){var b=v.value;this._makeSubtreeUnfocusable(b)}}catch(e){f=!0,c=e}finally{try{!h&&y.return&&y.return()}finally{if(f)throw c}}var _=!0,m=!1,g=void 0;try{for(var N,w=s.call(u.removedNodes)[Symbol.iterator]();!(_=(N=w.next()).done);_=!0){var E=N.value;this._unmanageSubtree(E)}}catch(e){m=!0,g=e}finally{try{!_&&w.return&&w.return()}finally{if(m)throw g}}}else if("attributes"===u.type)if("tabindex"===u.attributeName)this._manageNode(l);else if(l!==this._rootElement&&"inert"===u.attributeName&&l.hasAttribute("inert")){this._adoptInertRoot(l);var I=this._inertManager.getInertRoot(l),p=!0,k=!1,x=void 0;try{for(var S,A=this._managedNodes[Symbol.iterator]();!(p=(S=A.next()).done);p=!0){var M=S.value;a(l,M.node)&&I._manageNode(M.node)}}catch(e){k=!0,x=e}finally{try{!p&&A.return&&A.return()}finally{if(k)throw x}}}}}catch(e){r=!0,i=e}finally{try{!n&&d.return&&d.return()}finally{if(r)throw i}}}},{key:"managedNodes",get:function(){return new Set(this._managedNodes)}},{key:"hasSavedAriaHidden",get:function(){return"_savedAriaHidden"in this}},{key:"savedAriaHidden",set:function(e){this._savedAriaHidden=e},get:function(){return this._savedAriaHidden}}]),o}(),l=function(){function e(t,r){n(this,e),this._node=t,this._overrodeFocusMethod=!1,this._inertRoots=new Set([r]),this._destroyed=!1,this.ensureUntabbable()}return r(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,d)){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}(),h=function(){function e(t){if(n(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)),o(t.head||t.body||t.documentElement),"loading"===t.readyState?t.addEventListener("DOMContentLoaded",this._onDocumentLoaded.bind(this)):this._onDocumentLoaded()}return r(e,[{key:"setInert",value:function(e,t){if(t){if(this._inertRoots.has(e))return;var n=new u(e,this);if(e.setAttribute("inert",""),this._inertRoots.set(e,n),!a(this._document.body,e))for(var r=e.parentNode;r;)11===r.nodeType&&o(r),r=r.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.ensureUntabbable()):n=new l(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(){var e=s.call(this._document.querySelectorAll("[inert]")),t=!0,n=!1,r=void 0;try{for(var i,o=e[Symbol.iterator]();!(t=(i=o.next()).done);t=!0){var a=i.value;this.setInert(a,!0)}}catch(e){n=!0,r=e}finally{try{!t&&o.return&&o.return()}finally{if(n)throw r}}this._observer.observe(this._document.body,{attributes:!0,subtree:!0,childList:!0})}},{key:"_watchForInert",value:function(e,n){var r=!0,i=!1,o=void 0;try{for(var a,d=e[Symbol.iterator]();!(r=(a=d.next()).done);r=!0){var u=a.value;switch(u.type){case"childList":var l=!0,h=!1,f=void 0;try{for(var c,v=s.call(u.addedNodes)[Symbol.iterator]();!(l=(c=v.next()).done);l=!0){var y=c.value;if(y.nodeType===Node.ELEMENT_NODE){var b=s.call(y.querySelectorAll("[inert]"));t(y,"[inert]")&&b.unshift(y);var _=!0,m=!1,g=void 0;try{for(var N,w=b[Symbol.iterator]();!(_=(N=w.next()).done);_=!0){var E=N.value;this.setInert(E,!0)}}catch(e){m=!0,g=e}finally{try{!_&&w.return&&w.return()}finally{if(m)throw g}}}}}catch(e){h=!0,f=e}finally{try{!l&&v.return&&v.return()}finally{if(h)throw f}}break;case"attributes":if("inert"!==u.attributeName)continue;var I=u.target,p=I.hasAttribute("inert");this.setInert(I,p)}}}catch(e){i=!0,o=e}finally{try{!r&&d.return&&d.return()}finally{if(i)throw o}}}}]),e}(),f=new h(e);Object.defineProperty(Element.prototype,"inert",{enumerable:!0,get:function(){return this.hasAttribute("inert")},set:function(e){f.setInert(this,e)}})}(document)});
{
"name": "wicg-inert",
"version": "1.1.4",
"version": "1.1.6",
"description": "A polyfill for the proposed inert API",

@@ -10,4 +10,3 @@ "main": "dist/inert.js",

"build": "rollem",
"dev": "rollem --watch",
"prepublish": "npm run test && npm run build"
"dev": "rollem --watch"
},

@@ -29,3 +28,2 @@ "repository": {

],
"license": "Apache-2.0",
"bugs": {

@@ -36,4 +34,3 @@ "url": "https://github.com/WICG/inert/issues"

"dependencies": {
"dom-matches": "^2.0.0",
"node-contains": "^1.0.0"
"dom-matches": "^2.0.0"
},

@@ -44,16 +41,16 @@ "devDependencies": {

"babel-preset-es2015": "^6.13.2",
"chai": "^3.5.0",
"del": "^2.2.2",
"chai": "^4.0.2",
"del": "^3.0.0",
"easy-sauce": "^0.4.1",
"eslint": "^3.13.1",
"eslint-config-google": "^0.7.1",
"eslint": "^4.0.0",
"eslint-config-google": "^0.8.0",
"mocha": "^3.1.2",
"rollem": "^1.11.0",
"rollup": "^0.41.6",
"rollup": "^0.43.0",
"rollup-plugin-babel": "^2.7.1",
"rollup-plugin-commonjs": "^8.0.2",
"rollup-plugin-node-resolve": "^3.0.0",
"rollup-plugin-uglify": "^1.0.1",
"rollup-watch": "^3.2.2",
"whatwg-fetch": "^1.0.0"
"rollup-plugin-uglify": "^2.0.1",
"rollup-watch": "^4.0.0",
"whatwg-fetch": "^2.0.3"
},

@@ -60,0 +57,0 @@ "easySauce": {

@@ -238,6 +238,10 @@ # `inert` attribute

### Install
Using npm:
```
npm install --save wicg-inert
```
Using Bower:
```
bower install --save WICG/inert
```

@@ -244,0 +248,0 @@ ### Legacy Browser Support

@@ -0,1 +1,5 @@

/**
* This work is licensed under the W3C Software and Document License
* (http://www.w3.org/Consortium/Legal/2015/copyright-software-and-document).
*/
const resolve = require('rollup-plugin-node-resolve');

@@ -2,0 +6,0 @@ const commonjs = require('rollup-plugin-commonjs');

/**
*
* Copyright 2016 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* This work is licensed under the W3C Software and Document License
* (http://www.w3.org/Consortium/Legal/2015/copyright-software-and-document).
*/
import matches from 'dom-matches';
import contains from 'node-contains';
(function(document) {
// Convenience function for converting NodeLists.
/** @type {function(number,number):Array} */
const slice = Array.prototype.slice;
/** @type {string} */

@@ -69,2 +60,5 @@ const _focusableElementsString = ['a[href]',

// Make the subtree hidden from assistive technology
if (this._rootElement.hasAttribute('aria-hidden')) {
this._savedAriaHidden = this._rootElement.getAttribute('aria-hidden');
}
this._rootElement.setAttribute('aria-hidden', 'true');

@@ -92,8 +86,14 @@

if (this._rootElement)
this._rootElement.removeAttribute('aria-hidden');
if (this._rootElement) {
if (this.hasSavedAriaHidden) {
this._rootElement.setAttribute('aria-hidden', this.savedAriaHidden);
} else {
this._rootElement.removeAttribute('aria-hidden');
}
}
this._rootElement = null;
for (let inertNode of this._managedNodes)
for (let inertNode of this._managedNodes) {
this._unmanageNode(inertNode.node);
}

@@ -112,2 +112,17 @@ this._managedNodes = null;

/** @return {boolean} */
get hasSavedAriaHidden() {
return '_savedAriaHidden' in this;
}
/** @param {string} ariaHidden */
set savedAriaHidden(ariaHidden) {
this._savedAriaHidden = ariaHidden;
}
/** @return {string} */
get savedAriaHidden() {
return this._savedAriaHidden;
}
/**

@@ -131,7 +146,9 @@ * @param {Node} startNode

}
if (root)
if (root) {
activeElement = root.activeElement;
}
}
if (contains(startNode, activeElement))
if (contains(startNode, activeElement)) {
activeElement.blur();
}
}

@@ -143,12 +160,15 @@

_visitNode(node) {
if (node.nodeType !== Node.ELEMENT_NODE)
if (node.nodeType !== Node.ELEMENT_NODE) {
return;
}
// If a descendant inert root becomes un-inert, its descendants will still be inert because of
// this inert root, so all of its managed nodes need to be adopted by this InertRoot.
if (node !== this._rootElement && node.hasAttribute('inert'))
if (node !== this._rootElement && node.hasAttribute('inert')) {
this._adoptInertRoot(node);
}
if (matches(node, _focusableElementsString) || node.hasAttribute('tabindex'))
if (matches(node, _focusableElementsString) || node.hasAttribute('tabindex')) {
this._manageNode(node);
}
}

@@ -171,4 +191,5 @@

const inertNode = this._inertManager.deregister(node, this);
if (inertNode)
if (inertNode) {
this._managedNodes.delete(inertNode);
}
}

@@ -198,4 +219,5 @@

for (let savedInertNode of inertSubroot.managedNodes)
for (let savedInertNode of inertSubroot.managedNodes) {
this._manageNode(savedInertNode.node);
}
}

@@ -213,8 +235,10 @@

// Manage added nodes
for (let node of Array.from(record.addedNodes))
for (let node of slice.call(record.addedNodes)) {
this._makeSubtreeUnfocusable(node);
}
// Un-manage removed nodes
for (let node of Array.from(record.removedNodes))
for (let node of slice.call(record.removedNodes)) {
this._unmanageSubtree(node);
}
} else if (record.type === 'attributes') {

@@ -232,4 +256,5 @@ if (record.attributeName === 'tabindex') {

for (let managedNode of this._managedNodes) {
if (contains(target, managedNode.node))
if (contains(target, managedNode.node)) {
inertSubroot._manageNode(managedNode.node);
}
}

@@ -289,10 +314,12 @@ }

if (this._node) {
if (this.hasSavedTabIndex)
if (this.hasSavedTabIndex) {
this._node.setAttribute('tabindex', this.savedTabIndex);
else
} else {
this._node.removeAttribute('tabindex');
}
// Use `delete` to restore native focus method.
if (this._overrodeFocusMethod)
if (this._overrodeFocusMethod) {
delete this._node.focus;
}
}

@@ -317,4 +344,5 @@ this._node = null;

_throwIfDestroyed() {
if (this.destroyed)
if (this.destroyed) {
throw new Error('Trying to access destroyed InertNode');
}
}

@@ -349,7 +377,9 @@

if (matches(node, _focusableElementsString)) {
if (node.tabIndex === -1 && this.hasSavedTabIndex)
if (node.tabIndex === -1 && this.hasSavedTabIndex) {
return;
}
if (node.hasAttribute('tabindex'))
if (node.hasAttribute('tabindex')) {
this._savedTabIndex = node.tabIndex;
}
node.setAttribute('tabindex', '-1');

@@ -384,4 +414,5 @@ if (node.nodeType === Node.ELEMENT_NODE) {

this._inertRoots.delete(inertRoot);
if (this._inertRoots.size === 0)
if (this._inertRoots.size === 0) {
this.destructor();
}
}

@@ -404,4 +435,5 @@ }

constructor(document) {
if (!document)
if (!document) {
throw new Error('Missing required argument; InertManager needs to wrap a document.');
}

@@ -448,4 +480,5 @@ /** @type {Document} */

if (inert) {
if (this._inertRoots.has(root)) // element is already inert
if (this._inertRoots.has(root)) { // element is already inert
return;
}

@@ -467,4 +500,5 @@ const inertRoot = new InertRoot(root, this);

} else {
if (!this._inertRoots.has(root)) // element is already non-inert
if (!this._inertRoots.has(root)) { // element is already non-inert
return;
}

@@ -497,3 +531,3 @@ const inertRoot = this._inertRoots.get(root);

let inertNode = this._managedNodes.get(node);
if (inertNode !== undefined) { // node was already in an inert subtree
if (inertNode !== undefined) { // node was already in an inert subtree
inertNode.addInertRoot(inertRoot);

@@ -522,8 +556,10 @@ // Update saved tabindex value if necessary

const inertNode = this._managedNodes.get(node);
if (!inertNode)
if (!inertNode) {
return null;
}
inertNode.removeInertRoot(inertRoot);
if (inertNode.destroyed)
if (inertNode.destroyed) {
this._managedNodes.delete(node);
}

@@ -538,5 +574,6 @@ return inertNode;

// Find all inert roots in document and make them actually inert.
const inertElements = Array.from(this._document.querySelectorAll('[inert]'));
for (let inertElement of inertElements)
const inertElements = slice.call(this._document.querySelectorAll('[inert]'));
for (let inertElement of inertElements) {
this.setInert(inertElement, true);
}

@@ -556,15 +593,19 @@ // Comment this out to use programmatic API only.

case 'childList':
for (let node of Array.from(record.addedNodes)) {
if (node.nodeType !== Node.ELEMENT_NODE)
for (let node of slice.call(record.addedNodes)) {
if (node.nodeType !== Node.ELEMENT_NODE) {
continue;
const inertElements = Array.from(node.querySelectorAll('[inert]'));
if (matches(node, '[inert]'))
}
const inertElements = slice.call(node.querySelectorAll('[inert]'));
if (matches(node, '[inert]')) {
inertElements.unshift(node);
for (let inertElement of inertElements)
}
for (let inertElement of inertElements) {
this.setInert(inertElement, true);
}
}
break;
case 'attributes':
if (record.attributeName !== 'inert')
if (record.attributeName !== 'inert') {
continue;
}
const target = record.target;

@@ -589,4 +630,5 @@ const inert = target.hasAttribute('inert');

const element = /** @type {Element} */ (node);
if (callback)
if (callback) {
callback(element);
}

@@ -666,2 +708,16 @@ // Descend into node:

/**
* `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 other && (node === other || !!(node.compareDocumentPosition(other) & 16) );
}
const inertManager = new InertManager(document);

@@ -668,0 +724,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc