wicg-inert
Advanced tools
Comparing version 1.1.1 to 1.1.2
@@ -1,8 +0,80 @@ | ||
'use strict'; | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(factory()); | ||
}(this, (function () { 'use strict'; | ||
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; }; }(); | ||
/** | ||
* Determine if a DOM element matches a CSS selector | ||
* | ||
* @param {Element} elem | ||
* @param {String} selector | ||
* @return {Boolean} | ||
* @api public | ||
*/ | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function matches(elem, selector) { | ||
// Vendor-specific implementations of `Element.prototype.matches()`. | ||
var proto = window.Element.prototype; | ||
var nativeMatches = proto.matches || | ||
proto.mozMatchesSelector || | ||
proto.msMatchesSelector || | ||
proto.oMatchesSelector || | ||
proto.webkitMatchesSelector; | ||
if (!elem || elem.nodeType !== 1) { | ||
return false; | ||
} | ||
var parentElem = elem.parentNode; | ||
// use native 'matches' | ||
if (nativeMatches) { | ||
return nativeMatches.call(elem, selector); | ||
} | ||
// native support for `matches` is missing and a fallback is required | ||
var nodes = parentElem.querySelectorAll(selector); | ||
var len = nodes.length; | ||
for (var i = 0; i < len; i++) { | ||
if (nodes[i] === elem) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
/** | ||
* Expose `matches` | ||
*/ | ||
var index = matches; | ||
var classCallCheck = function (instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
}; | ||
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; | ||
}; | ||
}(); | ||
/** | ||
* | ||
@@ -25,3 +97,2 @@ * Copyright 2016 Google Inc. All rights reserved. | ||
(function (document) { | ||
/** @type {string} */ | ||
@@ -53,3 +124,3 @@ var _focusableElementsString = ['a[href]', 'area[href]', 'input:not([disabled])', 'select:not([disabled])', 'textarea:not([disabled])', 'button:not([disabled])', 'iframe', 'object', 'embed', '[contenteditable]'].join(','); | ||
function InertRoot(rootElement, inertManager) { | ||
_classCallCheck(this, InertRoot); | ||
classCallCheck(this, InertRoot); | ||
@@ -77,4 +148,4 @@ /** @type {InertManager} */ | ||
// - any removals from the subtree: remove them from this inert root's managed nodes | ||
// - attribute changes: if `tabindex` is added, or removed from an intrinsically focusable element, | ||
// make that node a managed node. | ||
// - attribute changes: if `tabindex` is added, or removed from an intrinsically focusable | ||
// element, make that node a managed node. | ||
this._observer = new MutationObserver(this._onMutation.bind(this)); | ||
@@ -90,3 +161,3 @@ this._observer.observe(this._rootElement, { attributes: true, childList: true, subtree: true }); | ||
_createClass(InertRoot, [{ | ||
createClass(InertRoot, [{ | ||
key: 'destructor', | ||
@@ -145,3 +216,3 @@ value: function destructor() { | ||
composedTreeWalk(startNode, function (node) { | ||
_this._visitNode(node); | ||
return _this._visitNode(node); | ||
}); | ||
@@ -175,7 +246,7 @@ | ||
// 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 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.matches(_focusableElementsString) || node.hasAttribute('tabindex')) this._manageNode(node); | ||
if (index(node, _focusableElementsString) || node.hasAttribute('tabindex')) this._manageNode(node); | ||
} | ||
@@ -218,3 +289,3 @@ | ||
composedTreeWalk(startNode, function (node) { | ||
_this2._unmanageNode(node); | ||
return _this2._unmanageNode(node); | ||
}); | ||
@@ -388,7 +459,6 @@ } | ||
key: 'managedNodes', | ||
get: function get() { | ||
get: function get$$1() { | ||
return new Set(this._managedNodes); | ||
} | ||
}]); | ||
return InertRoot; | ||
@@ -419,3 +489,3 @@ }(); | ||
function InertNode(node, inertRoot) { | ||
_classCallCheck(this, InertNode); | ||
classCallCheck(this, InertNode); | ||
@@ -447,3 +517,3 @@ /** @type {Node} */ | ||
_createClass(InertNode, [{ | ||
createClass(InertNode, [{ | ||
key: 'destructor', | ||
@@ -472,4 +542,9 @@ value: function destructor() { | ||
key: '_throwIfDestroyed', | ||
/** | ||
* Throw if user tries to access destroyed InertNode. | ||
*/ | ||
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'); | ||
} | ||
@@ -486,3 +561,3 @@ | ||
var node = this.node; | ||
if (node.matches(_focusableElementsString)) { | ||
if (index(node, _focusableElementsString)) { | ||
if (node.tabIndex === -1 && this.hasSavedTabIndex) return; | ||
@@ -530,3 +605,3 @@ | ||
key: 'destroyed', | ||
get: function get() { | ||
get: function get$$1() { | ||
return this._destroyed; | ||
@@ -536,3 +611,3 @@ } | ||
key: 'hasSavedTabIndex', | ||
get: function get() { | ||
get: function get$$1() { | ||
return '_savedTabIndex' in this; | ||
@@ -545,3 +620,3 @@ } | ||
key: 'node', | ||
get: function get() { | ||
get: function get$$1() { | ||
this._throwIfDestroyed(); | ||
@@ -555,3 +630,3 @@ return this._node; | ||
key: 'savedTabIndex', | ||
set: function set(tabIndex) { | ||
set: function set$$1(tabIndex) { | ||
this._throwIfDestroyed(); | ||
@@ -563,3 +638,3 @@ this._savedTabIndex = tabIndex; | ||
, | ||
get: function get() { | ||
get: function get$$1() { | ||
this._throwIfDestroyed(); | ||
@@ -569,3 +644,2 @@ return this._savedTabIndex; | ||
}]); | ||
return InertNode; | ||
@@ -590,3 +664,3 @@ }(); | ||
function InertManager(document) { | ||
_classCallCheck(this, InertManager); | ||
classCallCheck(this, InertManager); | ||
@@ -634,3 +708,3 @@ if (!document) throw new Error('Missing required argument; InertManager needs to wrap a document.'); | ||
_createClass(InertManager, [{ | ||
createClass(InertManager, [{ | ||
key: 'setInert', | ||
@@ -794,3 +868,3 @@ value: function setInert(root, inert) { | ||
var inertElements = Array.from(node.querySelectorAll('[inert]')); | ||
if (node.matches('[inert]')) inertElements.unshift(node); | ||
if (index(node, '[inert]')) inertElements.unshift(node); | ||
var _iteratorNormalCompletion10 = true; | ||
@@ -861,3 +935,2 @@ var _didIteratorError10 = false; | ||
}]); | ||
return InertManager; | ||
@@ -936,3 +1009,3 @@ }(); | ||
style.setAttribute('id', 'inert-style'); | ||
style.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"; | ||
style.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'; | ||
node.appendChild(style); | ||
@@ -945,9 +1018,11 @@ } | ||
enumerable: true, | ||
get: function get() { | ||
get: function get$$1() { | ||
return this.hasAttribute('inert'); | ||
}, | ||
set: function set(inert) { | ||
set: function set$$1(inert) { | ||
inertManager.setInert(this, inert); | ||
} | ||
}); | ||
})(document); | ||
})(document); | ||
}))); |
{ | ||
"name": "wicg-inert", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "A polyfill for the proposed inert API", | ||
"main": "dist/inert.js", | ||
"scripts": { | ||
"test": "gulp && easy-sauce" | ||
"lint": "eslint src/*.js", | ||
"test": "npm run lint && npm run build && easy-sauce", | ||
"build": "rollup -c", | ||
"dev": "rollup -c -w", | ||
"prepublish": "npm run test && npm run build" | ||
}, | ||
@@ -29,3 +33,7 @@ "repository": { | ||
"homepage": "https://github.com/WICG/inert#readme", | ||
"dependencies": { | ||
"dom-matches": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
"babel-plugin-external-helpers": "^6.22.0", | ||
"babel-polyfill": "^6.13.0", | ||
@@ -36,12 +44,13 @@ "babel-preset-es2015": "^6.13.2", | ||
"easy-sauce": "^0.4.1", | ||
"gulp": "gulpjs/gulp#4.0", | ||
"gulp-babel": "^6.1.2", | ||
"gulp-rename": "^1.2.2", | ||
"gulp-sourcemaps": "^2.2.0", | ||
"gulp-uglify": "^2.0.0", | ||
"eslint": "^3.13.1", | ||
"eslint-config-google": "^0.7.1", | ||
"mocha": "^3.1.2", | ||
"rollup": "^0.41.6", | ||
"rollup-plugin-babel": "^2.7.1", | ||
"rollup-plugin-commonjs": "^8.0.2", | ||
"rollup-plugin-node-resolve": "^3.0.0", | ||
"rollup-watch": "^3.2.2", | ||
"whatwg-fetch": "^1.0.0" | ||
}, | ||
"easySauce": { | ||
"service": "sauce-connect", | ||
"username": "robdodson_inert", | ||
@@ -48,0 +57,0 @@ "key": "a844aee9-d3ec-4566-94e3-dba3d0c30248", |
@@ -18,4 +18,5 @@ /** | ||
import matches from 'dom-matches'; | ||
(function(document) { | ||
/** @type {string} */ | ||
@@ -76,6 +77,6 @@ const _focusableElementsString = ['a[href]', | ||
// - any removals from the subtree: remove them from this inert root's managed nodes | ||
// - attribute changes: if `tabindex` is added, or removed from an intrinsically focusable element, | ||
// make that node a managed node. | ||
// - attribute changes: if `tabindex` is added, or removed from an intrinsically focusable | ||
// element, make that node a managed node. | ||
this._observer = new MutationObserver(this._onMutation.bind(this)); | ||
this._observer.observe(this._rootElement, { attributes: true, childList: true, subtree: true }); | ||
this._observer.observe(this._rootElement, {attributes: true, childList: true, subtree: true}); | ||
} | ||
@@ -114,3 +115,3 @@ | ||
_makeSubtreeUnfocusable(startNode) { | ||
composedTreeWalk(startNode, (node) => { this._visitNode(node); }); | ||
composedTreeWalk(startNode, (node) => this._visitNode(node)); | ||
@@ -130,3 +131,3 @@ let activeElement = document.activeElement; | ||
if (root) | ||
activeElement = root.activeElement | ||
activeElement = root.activeElement; | ||
} | ||
@@ -144,8 +145,8 @@ if (startNode.contains(activeElement)) | ||
// 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 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.matches(_focusableElementsString) || node.hasAttribute('tabindex')) | ||
if (matches(node, _focusableElementsString) || node.hasAttribute('tabindex')) | ||
this._manageNode(node); | ||
@@ -178,3 +179,3 @@ } | ||
_unmanageSubtree(startNode) { | ||
composedTreeWalk(startNode, (node) => { this._unmanageNode(node); }); | ||
composedTreeWalk(startNode, (node) => this._unmanageNode(node)); | ||
} | ||
@@ -307,5 +308,8 @@ | ||
/** | ||
* Throw if user tries to access destroyed InertNode. | ||
*/ | ||
_throwIfDestroyed() { | ||
if (this.destroyed) | ||
throw new Error("Trying to access destroyed InertNode"); | ||
throw new Error('Trying to access destroyed InertNode'); | ||
} | ||
@@ -339,3 +343,3 @@ | ||
const node = this.node; | ||
if (node.matches(_focusableElementsString)) { | ||
if (matches(node, _focusableElementsString)) { | ||
if (node.tabIndex === -1 && this.hasSavedTabIndex) | ||
@@ -528,3 +532,3 @@ return; | ||
// Comment this out to use programmatic API only. | ||
this._observer.observe(this._document.body, { attributes: true, subtree: true, childList: true }); | ||
this._observer.observe(this._document.body, {attributes: true, subtree: true, childList: true}); | ||
} | ||
@@ -545,3 +549,3 @@ | ||
const inertElements = Array.from(node.querySelectorAll('[inert]')); | ||
if (node.matches('[inert]')) | ||
if (matches(node, '[inert]')) | ||
inertElements.unshift(node); | ||
@@ -575,3 +579,3 @@ for (let inertElement of inertElements) | ||
if (callback) | ||
callback(element) | ||
callback(element); | ||
@@ -609,3 +613,3 @@ // Descend into node: | ||
const distributedNodes = slot.assignedNodes ? | ||
slot.assignedNodes({ flatten: true }) : []; | ||
slot.assignedNodes({flatten: true}) : []; | ||
for (let i = 0; i < distributedNodes.length; i++) { | ||
@@ -637,14 +641,14 @@ composedTreeWalk(distributedNodes[i], callback, shadowRootAncestor); | ||
style.setAttribute('id', 'inert-style'); | ||
style.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"; | ||
style.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'; | ||
node.appendChild(style); | ||
@@ -657,6 +661,9 @@ } | ||
enumerable: true, | ||
get: function() { return this.hasAttribute('inert'); }, | ||
set: function(inert) { inertManager.setInert(this, inert) } | ||
get: function() { | ||
return this.hasAttribute('inert'); | ||
}, | ||
set: function(inert) { | ||
inertManager.setInert(this, inert); | ||
}, | ||
}); | ||
})(document); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18
1791
97539
1
15
+ Addeddom-matches@^2.0.0
+ Addeddom-matches@2.0.0(transitive)