Initial commit
This commit is contained in:
21
node_modules/aria-hidden/LICENSE
generated
vendored
Normal file
21
node_modules/aria-hidden/LICENSE
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2017 Anton Korzunov
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
99
node_modules/aria-hidden/README.md
generated
vendored
Normal file
99
node_modules/aria-hidden/README.md
generated
vendored
Normal file
@ -0,0 +1,99 @@
|
||||
# aria-hidden
|
||||
|
||||
[](https://nodei.co/npm/aria-hidden/)
|
||||
|
||||
Hides from ARIA everything, except provided node(s).
|
||||
|
||||
Helps to isolate modal dialogs and focused task - the content will be not accessible using
|
||||
accessible tools.
|
||||
|
||||
Now with [HTML inert](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/inert) support
|
||||
|
||||
# API
|
||||
|
||||
Just call `hideOthers` with DOM-node you want to keep, and it will _hide_ everything else.
|
||||
`targetNode` could be placed anywhere - its siblings would be hidden, but it and its parents - not.
|
||||
|
||||
> "hidden" in terms or `aria-hidden`
|
||||
|
||||
```js
|
||||
import { hideOthers } from 'aria-hidden';
|
||||
|
||||
const undo = hideOthers(exceptThisDOMnode);
|
||||
// everything else is "aria-hidden"
|
||||
|
||||
// undo changes
|
||||
undo();
|
||||
```
|
||||
|
||||
you also may limit the effect spread by providing top level node as a second parameter
|
||||
|
||||
```js
|
||||
// keep only `anotherNode` node visible in #app
|
||||
// the rest of document will be untouched
|
||||
hideOthers(anotherNode, document.getElementById('app'));
|
||||
```
|
||||
|
||||
> `parentNode` defaults to document.body
|
||||
|
||||
# Inert
|
||||
|
||||
While `aria-hidden` played important role in the past and will play in the future - the main
|
||||
use case always was around isolating content and making elements "transparent" not only for aria, but for
|
||||
user interaction as well.
|
||||
|
||||
This is why you might consider using `inertOthers`
|
||||
|
||||
```tsx
|
||||
import { hideOthers, inertOthers, supportsInert } from 'aria-hidden';
|
||||
|
||||
// focus on element mean "hide others". Ideally disable interactions
|
||||
const focusOnElement = (node) => (supportsInert() ? inertOthers(node) : hideOthers(node));
|
||||
```
|
||||
|
||||
the same function as above is already contructed and exported as
|
||||
|
||||
```tsx
|
||||
import { suppressOthers } from 'aria-hidden';
|
||||
|
||||
suppressOthers([keepThisNode, andThis]);
|
||||
```
|
||||
|
||||
⚠️ Note - inert **will disable any interactions** with _suppressed_ elements ⚠️
|
||||
|
||||
### Suppressing interactivity without inert
|
||||
|
||||
One can `marker`, the third argument to a function, to mark hidden elements.
|
||||
Later one can create a style matching given marker to apply `pointer-events:none`
|
||||
|
||||
```css
|
||||
[hidden-node] {
|
||||
pointer-events: none;
|
||||
}
|
||||
```
|
||||
|
||||
```tsx
|
||||
hideOthers(notThisOne, undefined /*parent = document*/, 'hidden-node');
|
||||
```
|
||||
|
||||
Generally speaking the same can be achieved by addressing `[aria-hidden]` nodes, but
|
||||
not all `aria-hidden` nodes are expected to be non-interactive.
|
||||
Hence, it's better to separate concerns.
|
||||
|
||||
# Inspiration
|
||||
|
||||
Based on [smooth-ui](https://github.com/smooth-code/smooth-ui) modal dialogs.
|
||||
|
||||
# See also
|
||||
|
||||
- [inert](https://github.com/WICG/inert) - The HTML attribute/property to mark parts of the DOM tree as "inert".
|
||||
- [react-focus-lock](https://github.com/theKashey/react-focus-lock) to lock Focus inside modal.
|
||||
- [react-scroll-lock](https://github.com/theKashey/react-scroll-lock) to disable page scroll while modal is opened.
|
||||
|
||||
# Size
|
||||
|
||||
Code is 30 lines long
|
||||
|
||||
# Licence
|
||||
|
||||
MIT
|
||||
29
node_modules/aria-hidden/dist/es2015/index.d.ts
generated
vendored
Normal file
29
node_modules/aria-hidden/dist/es2015/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
export declare type Undo = () => void;
|
||||
/**
|
||||
* Marks everything except given node(or nodes) as aria-hidden
|
||||
* @param {Element | Element[]} originalTarget - elements to keep on the page
|
||||
* @param [parentNode] - top element, defaults to document.body
|
||||
* @param {String} [markerName] - a special attribute to mark every node
|
||||
* @return {Undo} undo command
|
||||
*/
|
||||
export declare const hideOthers: (originalTarget: Element | Element[], parentNode?: HTMLElement, markerName?: string) => Undo;
|
||||
/**
|
||||
* Marks everything except given node(or nodes) as inert
|
||||
* @param {Element | Element[]} originalTarget - elements to keep on the page
|
||||
* @param [parentNode] - top element, defaults to document.body
|
||||
* @param {String} [markerName] - a special attribute to mark every node
|
||||
* @return {Undo} undo command
|
||||
*/
|
||||
export declare const inertOthers: (originalTarget: Element | Element[], parentNode?: HTMLElement, markerName?: string) => Undo;
|
||||
/**
|
||||
* @returns if current browser supports inert
|
||||
*/
|
||||
export declare const supportsInert: () => boolean;
|
||||
/**
|
||||
* Automatic function to "suppress" DOM elements - _hide_ or _inert_ in the best possible way
|
||||
* @param {Element | Element[]} originalTarget - elements to keep on the page
|
||||
* @param [parentNode] - top element, defaults to document.body
|
||||
* @param {String} [markerName] - a special attribute to mark every node
|
||||
* @return {Undo} undo command
|
||||
*/
|
||||
export declare const suppressOthers: (originalTarget: Element | Element[], parentNode?: HTMLElement, markerName?: string) => Undo;
|
||||
166
node_modules/aria-hidden/dist/es2015/index.js
generated
vendored
Normal file
166
node_modules/aria-hidden/dist/es2015/index.js
generated
vendored
Normal file
@ -0,0 +1,166 @@
|
||||
var getDefaultParent = function (originalTarget) {
|
||||
if (typeof document === 'undefined') {
|
||||
return null;
|
||||
}
|
||||
var sampleTarget = Array.isArray(originalTarget) ? originalTarget[0] : originalTarget;
|
||||
return sampleTarget.ownerDocument.body;
|
||||
};
|
||||
var counterMap = new WeakMap();
|
||||
var uncontrolledNodes = new WeakMap();
|
||||
var markerMap = {};
|
||||
var lockCount = 0;
|
||||
var unwrapHost = function (node) {
|
||||
return node && (node.host || unwrapHost(node.parentNode));
|
||||
};
|
||||
var correctTargets = function (parent, targets) {
|
||||
return targets
|
||||
.map(function (target) {
|
||||
if (parent.contains(target)) {
|
||||
return target;
|
||||
}
|
||||
var correctedTarget = unwrapHost(target);
|
||||
if (correctedTarget && parent.contains(correctedTarget)) {
|
||||
return correctedTarget;
|
||||
}
|
||||
console.error('aria-hidden', target, 'in not contained inside', parent, '. Doing nothing');
|
||||
return null;
|
||||
})
|
||||
.filter(function (x) { return Boolean(x); });
|
||||
};
|
||||
/**
|
||||
* Marks everything except given node(or nodes) as aria-hidden
|
||||
* @param {Element | Element[]} originalTarget - elements to keep on the page
|
||||
* @param [parentNode] - top element, defaults to document.body
|
||||
* @param {String} [markerName] - a special attribute to mark every node
|
||||
* @param {String} [controlAttribute] - html Attribute to control
|
||||
* @return {Undo} undo command
|
||||
*/
|
||||
var applyAttributeToOthers = function (originalTarget, parentNode, markerName, controlAttribute) {
|
||||
var targets = correctTargets(parentNode, Array.isArray(originalTarget) ? originalTarget : [originalTarget]);
|
||||
if (!markerMap[markerName]) {
|
||||
markerMap[markerName] = new WeakMap();
|
||||
}
|
||||
var markerCounter = markerMap[markerName];
|
||||
var hiddenNodes = [];
|
||||
var elementsToKeep = new Set();
|
||||
var elementsToStop = new Set(targets);
|
||||
var keep = function (el) {
|
||||
if (!el || elementsToKeep.has(el)) {
|
||||
return;
|
||||
}
|
||||
elementsToKeep.add(el);
|
||||
keep(el.parentNode);
|
||||
};
|
||||
targets.forEach(keep);
|
||||
var deep = function (parent) {
|
||||
if (!parent || elementsToStop.has(parent)) {
|
||||
return;
|
||||
}
|
||||
Array.prototype.forEach.call(parent.children, function (node) {
|
||||
if (elementsToKeep.has(node)) {
|
||||
deep(node);
|
||||
}
|
||||
else {
|
||||
try {
|
||||
var attr = node.getAttribute(controlAttribute);
|
||||
var alreadyHidden = attr !== null && attr !== 'false';
|
||||
var counterValue = (counterMap.get(node) || 0) + 1;
|
||||
var markerValue = (markerCounter.get(node) || 0) + 1;
|
||||
counterMap.set(node, counterValue);
|
||||
markerCounter.set(node, markerValue);
|
||||
hiddenNodes.push(node);
|
||||
if (counterValue === 1 && alreadyHidden) {
|
||||
uncontrolledNodes.set(node, true);
|
||||
}
|
||||
if (markerValue === 1) {
|
||||
node.setAttribute(markerName, 'true');
|
||||
}
|
||||
if (!alreadyHidden) {
|
||||
node.setAttribute(controlAttribute, 'true');
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
console.error('aria-hidden: cannot operate on ', node, e);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
deep(parentNode);
|
||||
elementsToKeep.clear();
|
||||
lockCount++;
|
||||
return function () {
|
||||
hiddenNodes.forEach(function (node) {
|
||||
var counterValue = counterMap.get(node) - 1;
|
||||
var markerValue = markerCounter.get(node) - 1;
|
||||
counterMap.set(node, counterValue);
|
||||
markerCounter.set(node, markerValue);
|
||||
if (!counterValue) {
|
||||
if (!uncontrolledNodes.has(node)) {
|
||||
node.removeAttribute(controlAttribute);
|
||||
}
|
||||
uncontrolledNodes.delete(node);
|
||||
}
|
||||
if (!markerValue) {
|
||||
node.removeAttribute(markerName);
|
||||
}
|
||||
});
|
||||
lockCount--;
|
||||
if (!lockCount) {
|
||||
// clear
|
||||
counterMap = new WeakMap();
|
||||
counterMap = new WeakMap();
|
||||
uncontrolledNodes = new WeakMap();
|
||||
markerMap = {};
|
||||
}
|
||||
};
|
||||
};
|
||||
/**
|
||||
* Marks everything except given node(or nodes) as aria-hidden
|
||||
* @param {Element | Element[]} originalTarget - elements to keep on the page
|
||||
* @param [parentNode] - top element, defaults to document.body
|
||||
* @param {String} [markerName] - a special attribute to mark every node
|
||||
* @return {Undo} undo command
|
||||
*/
|
||||
export var hideOthers = function (originalTarget, parentNode, markerName) {
|
||||
if (markerName === void 0) { markerName = 'data-aria-hidden'; }
|
||||
var targets = Array.from(Array.isArray(originalTarget) ? originalTarget : [originalTarget]);
|
||||
var activeParentNode = parentNode || getDefaultParent(originalTarget);
|
||||
if (!activeParentNode) {
|
||||
return function () { return null; };
|
||||
}
|
||||
// we should not hide ariaLive elements - https://github.com/theKashey/aria-hidden/issues/10
|
||||
targets.push.apply(targets, Array.from(activeParentNode.querySelectorAll('[aria-live]')));
|
||||
return applyAttributeToOthers(targets, activeParentNode, markerName, 'aria-hidden');
|
||||
};
|
||||
/**
|
||||
* Marks everything except given node(or nodes) as inert
|
||||
* @param {Element | Element[]} originalTarget - elements to keep on the page
|
||||
* @param [parentNode] - top element, defaults to document.body
|
||||
* @param {String} [markerName] - a special attribute to mark every node
|
||||
* @return {Undo} undo command
|
||||
*/
|
||||
export var inertOthers = function (originalTarget, parentNode, markerName) {
|
||||
if (markerName === void 0) { markerName = 'data-inert-ed'; }
|
||||
var activeParentNode = parentNode || getDefaultParent(originalTarget);
|
||||
if (!activeParentNode) {
|
||||
return function () { return null; };
|
||||
}
|
||||
return applyAttributeToOthers(originalTarget, activeParentNode, markerName, 'inert');
|
||||
};
|
||||
/**
|
||||
* @returns if current browser supports inert
|
||||
*/
|
||||
export var supportsInert = function () {
|
||||
return typeof HTMLElement !== 'undefined' && HTMLElement.prototype.hasOwnProperty('inert');
|
||||
};
|
||||
/**
|
||||
* Automatic function to "suppress" DOM elements - _hide_ or _inert_ in the best possible way
|
||||
* @param {Element | Element[]} originalTarget - elements to keep on the page
|
||||
* @param [parentNode] - top element, defaults to document.body
|
||||
* @param {String} [markerName] - a special attribute to mark every node
|
||||
* @return {Undo} undo command
|
||||
*/
|
||||
export var suppressOthers = function (originalTarget, parentNode, markerName) {
|
||||
if (markerName === void 0) { markerName = 'data-suppressed'; }
|
||||
return (supportsInert() ? inertOthers : hideOthers)(originalTarget, parentNode, markerName);
|
||||
};
|
||||
29
node_modules/aria-hidden/dist/es2019/index.d.ts
generated
vendored
Normal file
29
node_modules/aria-hidden/dist/es2019/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
export declare type Undo = () => void;
|
||||
/**
|
||||
* Marks everything except given node(or nodes) as aria-hidden
|
||||
* @param {Element | Element[]} originalTarget - elements to keep on the page
|
||||
* @param [parentNode] - top element, defaults to document.body
|
||||
* @param {String} [markerName] - a special attribute to mark every node
|
||||
* @return {Undo} undo command
|
||||
*/
|
||||
export declare const hideOthers: (originalTarget: Element | Element[], parentNode?: HTMLElement, markerName?: string) => Undo;
|
||||
/**
|
||||
* Marks everything except given node(or nodes) as inert
|
||||
* @param {Element | Element[]} originalTarget - elements to keep on the page
|
||||
* @param [parentNode] - top element, defaults to document.body
|
||||
* @param {String} [markerName] - a special attribute to mark every node
|
||||
* @return {Undo} undo command
|
||||
*/
|
||||
export declare const inertOthers: (originalTarget: Element | Element[], parentNode?: HTMLElement, markerName?: string) => Undo;
|
||||
/**
|
||||
* @returns if current browser supports inert
|
||||
*/
|
||||
export declare const supportsInert: () => boolean;
|
||||
/**
|
||||
* Automatic function to "suppress" DOM elements - _hide_ or _inert_ in the best possible way
|
||||
* @param {Element | Element[]} originalTarget - elements to keep on the page
|
||||
* @param [parentNode] - top element, defaults to document.body
|
||||
* @param {String} [markerName] - a special attribute to mark every node
|
||||
* @return {Undo} undo command
|
||||
*/
|
||||
export declare const suppressOthers: (originalTarget: Element | Element[], parentNode?: HTMLElement, markerName?: string) => Undo;
|
||||
155
node_modules/aria-hidden/dist/es2019/index.js
generated
vendored
Normal file
155
node_modules/aria-hidden/dist/es2019/index.js
generated
vendored
Normal file
@ -0,0 +1,155 @@
|
||||
const getDefaultParent = (originalTarget) => {
|
||||
if (typeof document === 'undefined') {
|
||||
return null;
|
||||
}
|
||||
const sampleTarget = Array.isArray(originalTarget) ? originalTarget[0] : originalTarget;
|
||||
return sampleTarget.ownerDocument.body;
|
||||
};
|
||||
let counterMap = new WeakMap();
|
||||
let uncontrolledNodes = new WeakMap();
|
||||
let markerMap = {};
|
||||
let lockCount = 0;
|
||||
const unwrapHost = (node) => node && (node.host || unwrapHost(node.parentNode));
|
||||
const correctTargets = (parent, targets) => targets
|
||||
.map((target) => {
|
||||
if (parent.contains(target)) {
|
||||
return target;
|
||||
}
|
||||
const correctedTarget = unwrapHost(target);
|
||||
if (correctedTarget && parent.contains(correctedTarget)) {
|
||||
return correctedTarget;
|
||||
}
|
||||
console.error('aria-hidden', target, 'in not contained inside', parent, '. Doing nothing');
|
||||
return null;
|
||||
})
|
||||
.filter((x) => Boolean(x));
|
||||
/**
|
||||
* Marks everything except given node(or nodes) as aria-hidden
|
||||
* @param {Element | Element[]} originalTarget - elements to keep on the page
|
||||
* @param [parentNode] - top element, defaults to document.body
|
||||
* @param {String} [markerName] - a special attribute to mark every node
|
||||
* @param {String} [controlAttribute] - html Attribute to control
|
||||
* @return {Undo} undo command
|
||||
*/
|
||||
const applyAttributeToOthers = (originalTarget, parentNode, markerName, controlAttribute) => {
|
||||
const targets = correctTargets(parentNode, Array.isArray(originalTarget) ? originalTarget : [originalTarget]);
|
||||
if (!markerMap[markerName]) {
|
||||
markerMap[markerName] = new WeakMap();
|
||||
}
|
||||
const markerCounter = markerMap[markerName];
|
||||
const hiddenNodes = [];
|
||||
const elementsToKeep = new Set();
|
||||
const elementsToStop = new Set(targets);
|
||||
const keep = (el) => {
|
||||
if (!el || elementsToKeep.has(el)) {
|
||||
return;
|
||||
}
|
||||
elementsToKeep.add(el);
|
||||
keep(el.parentNode);
|
||||
};
|
||||
targets.forEach(keep);
|
||||
const deep = (parent) => {
|
||||
if (!parent || elementsToStop.has(parent)) {
|
||||
return;
|
||||
}
|
||||
Array.prototype.forEach.call(parent.children, (node) => {
|
||||
if (elementsToKeep.has(node)) {
|
||||
deep(node);
|
||||
}
|
||||
else {
|
||||
try {
|
||||
const attr = node.getAttribute(controlAttribute);
|
||||
const alreadyHidden = attr !== null && attr !== 'false';
|
||||
const counterValue = (counterMap.get(node) || 0) + 1;
|
||||
const markerValue = (markerCounter.get(node) || 0) + 1;
|
||||
counterMap.set(node, counterValue);
|
||||
markerCounter.set(node, markerValue);
|
||||
hiddenNodes.push(node);
|
||||
if (counterValue === 1 && alreadyHidden) {
|
||||
uncontrolledNodes.set(node, true);
|
||||
}
|
||||
if (markerValue === 1) {
|
||||
node.setAttribute(markerName, 'true');
|
||||
}
|
||||
if (!alreadyHidden) {
|
||||
node.setAttribute(controlAttribute, 'true');
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
console.error('aria-hidden: cannot operate on ', node, e);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
deep(parentNode);
|
||||
elementsToKeep.clear();
|
||||
lockCount++;
|
||||
return () => {
|
||||
hiddenNodes.forEach((node) => {
|
||||
const counterValue = counterMap.get(node) - 1;
|
||||
const markerValue = markerCounter.get(node) - 1;
|
||||
counterMap.set(node, counterValue);
|
||||
markerCounter.set(node, markerValue);
|
||||
if (!counterValue) {
|
||||
if (!uncontrolledNodes.has(node)) {
|
||||
node.removeAttribute(controlAttribute);
|
||||
}
|
||||
uncontrolledNodes.delete(node);
|
||||
}
|
||||
if (!markerValue) {
|
||||
node.removeAttribute(markerName);
|
||||
}
|
||||
});
|
||||
lockCount--;
|
||||
if (!lockCount) {
|
||||
// clear
|
||||
counterMap = new WeakMap();
|
||||
counterMap = new WeakMap();
|
||||
uncontrolledNodes = new WeakMap();
|
||||
markerMap = {};
|
||||
}
|
||||
};
|
||||
};
|
||||
/**
|
||||
* Marks everything except given node(or nodes) as aria-hidden
|
||||
* @param {Element | Element[]} originalTarget - elements to keep on the page
|
||||
* @param [parentNode] - top element, defaults to document.body
|
||||
* @param {String} [markerName] - a special attribute to mark every node
|
||||
* @return {Undo} undo command
|
||||
*/
|
||||
export const hideOthers = (originalTarget, parentNode, markerName = 'data-aria-hidden') => {
|
||||
const targets = Array.from(Array.isArray(originalTarget) ? originalTarget : [originalTarget]);
|
||||
const activeParentNode = parentNode || getDefaultParent(originalTarget);
|
||||
if (!activeParentNode) {
|
||||
return () => null;
|
||||
}
|
||||
// we should not hide ariaLive elements - https://github.com/theKashey/aria-hidden/issues/10
|
||||
targets.push(...Array.from(activeParentNode.querySelectorAll('[aria-live]')));
|
||||
return applyAttributeToOthers(targets, activeParentNode, markerName, 'aria-hidden');
|
||||
};
|
||||
/**
|
||||
* Marks everything except given node(or nodes) as inert
|
||||
* @param {Element | Element[]} originalTarget - elements to keep on the page
|
||||
* @param [parentNode] - top element, defaults to document.body
|
||||
* @param {String} [markerName] - a special attribute to mark every node
|
||||
* @return {Undo} undo command
|
||||
*/
|
||||
export const inertOthers = (originalTarget, parentNode, markerName = 'data-inert-ed') => {
|
||||
const activeParentNode = parentNode || getDefaultParent(originalTarget);
|
||||
if (!activeParentNode) {
|
||||
return () => null;
|
||||
}
|
||||
return applyAttributeToOthers(originalTarget, activeParentNode, markerName, 'inert');
|
||||
};
|
||||
/**
|
||||
* @returns if current browser supports inert
|
||||
*/
|
||||
export const supportsInert = () => typeof HTMLElement !== 'undefined' && HTMLElement.prototype.hasOwnProperty('inert');
|
||||
/**
|
||||
* Automatic function to "suppress" DOM elements - _hide_ or _inert_ in the best possible way
|
||||
* @param {Element | Element[]} originalTarget - elements to keep on the page
|
||||
* @param [parentNode] - top element, defaults to document.body
|
||||
* @param {String} [markerName] - a special attribute to mark every node
|
||||
* @return {Undo} undo command
|
||||
*/
|
||||
export const suppressOthers = (originalTarget, parentNode, markerName = 'data-suppressed') => (supportsInert() ? inertOthers : hideOthers)(originalTarget, parentNode, markerName);
|
||||
29
node_modules/aria-hidden/dist/es5/index.d.ts
generated
vendored
Normal file
29
node_modules/aria-hidden/dist/es5/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
export declare type Undo = () => void;
|
||||
/**
|
||||
* Marks everything except given node(or nodes) as aria-hidden
|
||||
* @param {Element | Element[]} originalTarget - elements to keep on the page
|
||||
* @param [parentNode] - top element, defaults to document.body
|
||||
* @param {String} [markerName] - a special attribute to mark every node
|
||||
* @return {Undo} undo command
|
||||
*/
|
||||
export declare const hideOthers: (originalTarget: Element | Element[], parentNode?: HTMLElement, markerName?: string) => Undo;
|
||||
/**
|
||||
* Marks everything except given node(or nodes) as inert
|
||||
* @param {Element | Element[]} originalTarget - elements to keep on the page
|
||||
* @param [parentNode] - top element, defaults to document.body
|
||||
* @param {String} [markerName] - a special attribute to mark every node
|
||||
* @return {Undo} undo command
|
||||
*/
|
||||
export declare const inertOthers: (originalTarget: Element | Element[], parentNode?: HTMLElement, markerName?: string) => Undo;
|
||||
/**
|
||||
* @returns if current browser supports inert
|
||||
*/
|
||||
export declare const supportsInert: () => boolean;
|
||||
/**
|
||||
* Automatic function to "suppress" DOM elements - _hide_ or _inert_ in the best possible way
|
||||
* @param {Element | Element[]} originalTarget - elements to keep on the page
|
||||
* @param [parentNode] - top element, defaults to document.body
|
||||
* @param {String} [markerName] - a special attribute to mark every node
|
||||
* @return {Undo} undo command
|
||||
*/
|
||||
export declare const suppressOthers: (originalTarget: Element | Element[], parentNode?: HTMLElement, markerName?: string) => Undo;
|
||||
173
node_modules/aria-hidden/dist/es5/index.js
generated
vendored
Normal file
173
node_modules/aria-hidden/dist/es5/index.js
generated
vendored
Normal file
@ -0,0 +1,173 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.suppressOthers = exports.supportsInert = exports.inertOthers = exports.hideOthers = void 0;
|
||||
var getDefaultParent = function (originalTarget) {
|
||||
if (typeof document === 'undefined') {
|
||||
return null;
|
||||
}
|
||||
var sampleTarget = Array.isArray(originalTarget) ? originalTarget[0] : originalTarget;
|
||||
return sampleTarget.ownerDocument.body;
|
||||
};
|
||||
var counterMap = new WeakMap();
|
||||
var uncontrolledNodes = new WeakMap();
|
||||
var markerMap = {};
|
||||
var lockCount = 0;
|
||||
var unwrapHost = function (node) {
|
||||
return node && (node.host || unwrapHost(node.parentNode));
|
||||
};
|
||||
var correctTargets = function (parent, targets) {
|
||||
return targets
|
||||
.map(function (target) {
|
||||
if (parent.contains(target)) {
|
||||
return target;
|
||||
}
|
||||
var correctedTarget = unwrapHost(target);
|
||||
if (correctedTarget && parent.contains(correctedTarget)) {
|
||||
return correctedTarget;
|
||||
}
|
||||
console.error('aria-hidden', target, 'in not contained inside', parent, '. Doing nothing');
|
||||
return null;
|
||||
})
|
||||
.filter(function (x) { return Boolean(x); });
|
||||
};
|
||||
/**
|
||||
* Marks everything except given node(or nodes) as aria-hidden
|
||||
* @param {Element | Element[]} originalTarget - elements to keep on the page
|
||||
* @param [parentNode] - top element, defaults to document.body
|
||||
* @param {String} [markerName] - a special attribute to mark every node
|
||||
* @param {String} [controlAttribute] - html Attribute to control
|
||||
* @return {Undo} undo command
|
||||
*/
|
||||
var applyAttributeToOthers = function (originalTarget, parentNode, markerName, controlAttribute) {
|
||||
var targets = correctTargets(parentNode, Array.isArray(originalTarget) ? originalTarget : [originalTarget]);
|
||||
if (!markerMap[markerName]) {
|
||||
markerMap[markerName] = new WeakMap();
|
||||
}
|
||||
var markerCounter = markerMap[markerName];
|
||||
var hiddenNodes = [];
|
||||
var elementsToKeep = new Set();
|
||||
var elementsToStop = new Set(targets);
|
||||
var keep = function (el) {
|
||||
if (!el || elementsToKeep.has(el)) {
|
||||
return;
|
||||
}
|
||||
elementsToKeep.add(el);
|
||||
keep(el.parentNode);
|
||||
};
|
||||
targets.forEach(keep);
|
||||
var deep = function (parent) {
|
||||
if (!parent || elementsToStop.has(parent)) {
|
||||
return;
|
||||
}
|
||||
Array.prototype.forEach.call(parent.children, function (node) {
|
||||
if (elementsToKeep.has(node)) {
|
||||
deep(node);
|
||||
}
|
||||
else {
|
||||
try {
|
||||
var attr = node.getAttribute(controlAttribute);
|
||||
var alreadyHidden = attr !== null && attr !== 'false';
|
||||
var counterValue = (counterMap.get(node) || 0) + 1;
|
||||
var markerValue = (markerCounter.get(node) || 0) + 1;
|
||||
counterMap.set(node, counterValue);
|
||||
markerCounter.set(node, markerValue);
|
||||
hiddenNodes.push(node);
|
||||
if (counterValue === 1 && alreadyHidden) {
|
||||
uncontrolledNodes.set(node, true);
|
||||
}
|
||||
if (markerValue === 1) {
|
||||
node.setAttribute(markerName, 'true');
|
||||
}
|
||||
if (!alreadyHidden) {
|
||||
node.setAttribute(controlAttribute, 'true');
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
console.error('aria-hidden: cannot operate on ', node, e);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
deep(parentNode);
|
||||
elementsToKeep.clear();
|
||||
lockCount++;
|
||||
return function () {
|
||||
hiddenNodes.forEach(function (node) {
|
||||
var counterValue = counterMap.get(node) - 1;
|
||||
var markerValue = markerCounter.get(node) - 1;
|
||||
counterMap.set(node, counterValue);
|
||||
markerCounter.set(node, markerValue);
|
||||
if (!counterValue) {
|
||||
if (!uncontrolledNodes.has(node)) {
|
||||
node.removeAttribute(controlAttribute);
|
||||
}
|
||||
uncontrolledNodes.delete(node);
|
||||
}
|
||||
if (!markerValue) {
|
||||
node.removeAttribute(markerName);
|
||||
}
|
||||
});
|
||||
lockCount--;
|
||||
if (!lockCount) {
|
||||
// clear
|
||||
counterMap = new WeakMap();
|
||||
counterMap = new WeakMap();
|
||||
uncontrolledNodes = new WeakMap();
|
||||
markerMap = {};
|
||||
}
|
||||
};
|
||||
};
|
||||
/**
|
||||
* Marks everything except given node(or nodes) as aria-hidden
|
||||
* @param {Element | Element[]} originalTarget - elements to keep on the page
|
||||
* @param [parentNode] - top element, defaults to document.body
|
||||
* @param {String} [markerName] - a special attribute to mark every node
|
||||
* @return {Undo} undo command
|
||||
*/
|
||||
var hideOthers = function (originalTarget, parentNode, markerName) {
|
||||
if (markerName === void 0) { markerName = 'data-aria-hidden'; }
|
||||
var targets = Array.from(Array.isArray(originalTarget) ? originalTarget : [originalTarget]);
|
||||
var activeParentNode = parentNode || getDefaultParent(originalTarget);
|
||||
if (!activeParentNode) {
|
||||
return function () { return null; };
|
||||
}
|
||||
// we should not hide ariaLive elements - https://github.com/theKashey/aria-hidden/issues/10
|
||||
targets.push.apply(targets, Array.from(activeParentNode.querySelectorAll('[aria-live]')));
|
||||
return applyAttributeToOthers(targets, activeParentNode, markerName, 'aria-hidden');
|
||||
};
|
||||
exports.hideOthers = hideOthers;
|
||||
/**
|
||||
* Marks everything except given node(or nodes) as inert
|
||||
* @param {Element | Element[]} originalTarget - elements to keep on the page
|
||||
* @param [parentNode] - top element, defaults to document.body
|
||||
* @param {String} [markerName] - a special attribute to mark every node
|
||||
* @return {Undo} undo command
|
||||
*/
|
||||
var inertOthers = function (originalTarget, parentNode, markerName) {
|
||||
if (markerName === void 0) { markerName = 'data-inert-ed'; }
|
||||
var activeParentNode = parentNode || getDefaultParent(originalTarget);
|
||||
if (!activeParentNode) {
|
||||
return function () { return null; };
|
||||
}
|
||||
return applyAttributeToOthers(originalTarget, activeParentNode, markerName, 'inert');
|
||||
};
|
||||
exports.inertOthers = inertOthers;
|
||||
/**
|
||||
* @returns if current browser supports inert
|
||||
*/
|
||||
var supportsInert = function () {
|
||||
return typeof HTMLElement !== 'undefined' && HTMLElement.prototype.hasOwnProperty('inert');
|
||||
};
|
||||
exports.supportsInert = supportsInert;
|
||||
/**
|
||||
* Automatic function to "suppress" DOM elements - _hide_ or _inert_ in the best possible way
|
||||
* @param {Element | Element[]} originalTarget - elements to keep on the page
|
||||
* @param [parentNode] - top element, defaults to document.body
|
||||
* @param {String} [markerName] - a special attribute to mark every node
|
||||
* @return {Undo} undo command
|
||||
*/
|
||||
var suppressOthers = function (originalTarget, parentNode, markerName) {
|
||||
if (markerName === void 0) { markerName = 'data-suppressed'; }
|
||||
return ((0, exports.supportsInert)() ? exports.inertOthers : exports.hideOthers)(originalTarget, parentNode, markerName);
|
||||
};
|
||||
exports.suppressOthers = suppressOthers;
|
||||
70
node_modules/aria-hidden/package.json
generated
vendored
Normal file
70
node_modules/aria-hidden/package.json
generated
vendored
Normal file
@ -0,0 +1,70 @@
|
||||
{
|
||||
"name": "aria-hidden",
|
||||
"version": "1.2.4",
|
||||
"description": "Cast aria-hidden to everything, except...",
|
||||
"main": "dist/es5/index.js",
|
||||
"sideEffects": false,
|
||||
"scripts": {
|
||||
"test": "jest",
|
||||
"dev": "lib-builder dev",
|
||||
"test:ci": "jest --runInBand --coverage",
|
||||
"build": "lib-builder build && yarn size:report",
|
||||
"prepublish": "yarn build",
|
||||
"release": "yarn build && yarn test",
|
||||
"lint": "lib-builder lint",
|
||||
"format": "lib-builder format",
|
||||
"size": "npx size-limit",
|
||||
"size:report": "npx size-limit --json > .size.json",
|
||||
"update": "lib-builder update",
|
||||
"prepublish-only": "yarn build && yarn changelog",
|
||||
"prepare": "husky install",
|
||||
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
|
||||
"changelog:rewrite": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0"
|
||||
},
|
||||
"author": "Anton Korzunov <thekashey@gmail.com>",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@theuiteam/lib-builder": "^0.2.1",
|
||||
"@size-limit/preset-small-lib": "^2.1.6"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
},
|
||||
"jsnext:main": "dist/es2015/index.js",
|
||||
"module": "dist/es2015/index.js",
|
||||
"types": "dist/es5/index.d.ts",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"keywords": [
|
||||
"DOM",
|
||||
"aria",
|
||||
"hidden",
|
||||
"inert"
|
||||
],
|
||||
"homepage": "https://github.com/theKashey/aria-hidden#readme",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/theKashey/aria-hidden.git"
|
||||
},
|
||||
"dependencies": {
|
||||
"tslib": "^2.0.0"
|
||||
},
|
||||
"module:es2019": "dist/es2019/index.js",
|
||||
"lint-staged": {
|
||||
"*.{ts,tsx}": [
|
||||
"prettier --write",
|
||||
"eslint --fix"
|
||||
],
|
||||
"*.{js,css,json,md}": [
|
||||
"prettier --write"
|
||||
]
|
||||
},
|
||||
"prettier": {
|
||||
"printWidth": 120,
|
||||
"trailingComma": "es5",
|
||||
"tabWidth": 2,
|
||||
"semi": true,
|
||||
"singleQuote": true
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user