@zag-js/aria-hidden 0.0.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +2 -5
- package/dist/index.d.ts +3 -7
- package/dist/index.js +23 -14
- package/dist/index.mjs +18 -14
- package/package.json +19 -13
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -7
- package/dist/index.mjs.map +0 -7
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Chakra UI
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -12,11 +12,8 @@ npm i @zag-js/aria-hidden
|
|
|
12
12
|
|
|
13
13
|
## Contribution
|
|
14
14
|
|
|
15
|
-
Yes please! See the
|
|
16
|
-
[contributing guidelines](https://github.com/chakra-ui/zag/blob/main/CONTRIBUTING.md)
|
|
17
|
-
for details.
|
|
15
|
+
Yes please! See the [contributing guidelines](https://github.com/chakra-ui/zag/blob/main/CONTRIBUTING.md) for details.
|
|
18
16
|
|
|
19
17
|
## Licence
|
|
20
18
|
|
|
21
|
-
This project is licensed under the terms of the
|
|
22
|
-
[MIT license](https://github.com/chakra-ui/zag/blob/main/LICENSE).
|
|
19
|
+
This project is licensed under the terms of the [MIT license](https://github.com/chakra-ui/zag/blob/main/LICENSE).
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
root?: HTMLElement;
|
|
5
|
-
};
|
|
6
|
-
export declare function ariaHidden(options: AriaHiddenOptions): () => void;
|
|
7
|
-
//# sourceMappingURL=index.d.ts.map
|
|
1
|
+
declare function ariaHidden(targets: Array<HTMLElement | null>, rootEl?: HTMLElement): (() => void) | undefined;
|
|
2
|
+
|
|
3
|
+
export { ariaHidden };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -22,16 +23,22 @@ __export(src_exports, {
|
|
|
22
23
|
ariaHidden: () => ariaHidden
|
|
23
24
|
});
|
|
24
25
|
module.exports = __toCommonJS(src_exports);
|
|
25
|
-
var
|
|
26
|
-
function
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
var elementCountMap = /* @__PURE__ */ new WeakMap();
|
|
27
|
+
function isLiveRegion(node, win) {
|
|
28
|
+
return node instanceof win.HTMLElement && node.dataset.liveAnnouncer === "true";
|
|
29
|
+
}
|
|
30
|
+
function ariaHidden(targets, rootEl) {
|
|
31
|
+
const exclude = targets.filter(Boolean);
|
|
32
|
+
if (exclude.length === 0)
|
|
33
|
+
return;
|
|
34
|
+
const doc = exclude[0].ownerDocument || document;
|
|
35
|
+
const win = doc.defaultView ?? window;
|
|
30
36
|
const visibleNodes = new Set(exclude);
|
|
31
37
|
const hiddenNodes = /* @__PURE__ */ new Set();
|
|
38
|
+
const root = rootEl ?? doc.body;
|
|
32
39
|
const walker = doc.createTreeWalker(root, NodeFilter.SHOW_ELEMENT, {
|
|
33
40
|
acceptNode(node2) {
|
|
34
|
-
if (node2
|
|
41
|
+
if (isLiveRegion(node2, win)) {
|
|
35
42
|
visibleNodes.add(node2);
|
|
36
43
|
}
|
|
37
44
|
if (visibleNodes.has(node2) || hiddenNodes.has(node2.parentElement)) {
|
|
@@ -47,8 +54,7 @@ function ariaHidden(options) {
|
|
|
47
54
|
}
|
|
48
55
|
});
|
|
49
56
|
const hide = (node2) => {
|
|
50
|
-
|
|
51
|
-
let refCount = (_a2 = map.get(node2)) != null ? _a2 : 0;
|
|
57
|
+
let refCount = elementCountMap.get(node2) ?? 0;
|
|
52
58
|
if (node2.getAttribute("aria-hidden") === "true" && refCount === 0) {
|
|
53
59
|
return;
|
|
54
60
|
}
|
|
@@ -56,7 +62,7 @@ function ariaHidden(options) {
|
|
|
56
62
|
node2.setAttribute("aria-hidden", "true");
|
|
57
63
|
}
|
|
58
64
|
hiddenNodes.add(node2);
|
|
59
|
-
|
|
65
|
+
elementCountMap.set(node2, refCount + 1);
|
|
60
66
|
};
|
|
61
67
|
let node = walker.nextNode();
|
|
62
68
|
while (node != null) {
|
|
@@ -69,7 +75,7 @@ function ariaHidden(options) {
|
|
|
69
75
|
continue;
|
|
70
76
|
if (![...visibleNodes, ...hiddenNodes].some((node2) => node2.contains(change.target))) {
|
|
71
77
|
for (const node2 of change.addedNodes) {
|
|
72
|
-
if (node2
|
|
78
|
+
if (isLiveRegion(node2, win)) {
|
|
73
79
|
visibleNodes.add(node2);
|
|
74
80
|
} else if (node2 instanceof win.Element) {
|
|
75
81
|
hide(node2);
|
|
@@ -82,16 +88,19 @@ function ariaHidden(options) {
|
|
|
82
88
|
return () => {
|
|
83
89
|
observer.disconnect();
|
|
84
90
|
for (let node2 of hiddenNodes) {
|
|
85
|
-
let count =
|
|
91
|
+
let count = elementCountMap.get(node2);
|
|
86
92
|
if (count === 1) {
|
|
87
93
|
node2.removeAttribute("aria-hidden");
|
|
88
|
-
|
|
94
|
+
elementCountMap.delete(node2);
|
|
89
95
|
continue;
|
|
90
96
|
}
|
|
91
97
|
if (count !== void 0) {
|
|
92
|
-
|
|
98
|
+
elementCountMap.set(node2, count - 1);
|
|
93
99
|
}
|
|
94
100
|
}
|
|
95
101
|
};
|
|
96
102
|
}
|
|
97
|
-
|
|
103
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
104
|
+
0 && (module.exports = {
|
|
105
|
+
ariaHidden
|
|
106
|
+
});
|
package/dist/index.mjs
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
var
|
|
3
|
-
function
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
var elementCountMap = /* @__PURE__ */ new WeakMap();
|
|
3
|
+
function isLiveRegion(node, win) {
|
|
4
|
+
return node instanceof win.HTMLElement && node.dataset.liveAnnouncer === "true";
|
|
5
|
+
}
|
|
6
|
+
function ariaHidden(targets, rootEl) {
|
|
7
|
+
const exclude = targets.filter(Boolean);
|
|
8
|
+
if (exclude.length === 0)
|
|
9
|
+
return;
|
|
10
|
+
const doc = exclude[0].ownerDocument || document;
|
|
11
|
+
const win = doc.defaultView ?? window;
|
|
7
12
|
const visibleNodes = new Set(exclude);
|
|
8
13
|
const hiddenNodes = /* @__PURE__ */ new Set();
|
|
14
|
+
const root = rootEl ?? doc.body;
|
|
9
15
|
const walker = doc.createTreeWalker(root, NodeFilter.SHOW_ELEMENT, {
|
|
10
16
|
acceptNode(node2) {
|
|
11
|
-
if (node2
|
|
17
|
+
if (isLiveRegion(node2, win)) {
|
|
12
18
|
visibleNodes.add(node2);
|
|
13
19
|
}
|
|
14
20
|
if (visibleNodes.has(node2) || hiddenNodes.has(node2.parentElement)) {
|
|
@@ -24,8 +30,7 @@ function ariaHidden(options) {
|
|
|
24
30
|
}
|
|
25
31
|
});
|
|
26
32
|
const hide = (node2) => {
|
|
27
|
-
|
|
28
|
-
let refCount = (_a2 = map.get(node2)) != null ? _a2 : 0;
|
|
33
|
+
let refCount = elementCountMap.get(node2) ?? 0;
|
|
29
34
|
if (node2.getAttribute("aria-hidden") === "true" && refCount === 0) {
|
|
30
35
|
return;
|
|
31
36
|
}
|
|
@@ -33,7 +38,7 @@ function ariaHidden(options) {
|
|
|
33
38
|
node2.setAttribute("aria-hidden", "true");
|
|
34
39
|
}
|
|
35
40
|
hiddenNodes.add(node2);
|
|
36
|
-
|
|
41
|
+
elementCountMap.set(node2, refCount + 1);
|
|
37
42
|
};
|
|
38
43
|
let node = walker.nextNode();
|
|
39
44
|
while (node != null) {
|
|
@@ -46,7 +51,7 @@ function ariaHidden(options) {
|
|
|
46
51
|
continue;
|
|
47
52
|
if (![...visibleNodes, ...hiddenNodes].some((node2) => node2.contains(change.target))) {
|
|
48
53
|
for (const node2 of change.addedNodes) {
|
|
49
|
-
if (node2
|
|
54
|
+
if (isLiveRegion(node2, win)) {
|
|
50
55
|
visibleNodes.add(node2);
|
|
51
56
|
} else if (node2 instanceof win.Element) {
|
|
52
57
|
hide(node2);
|
|
@@ -59,14 +64,14 @@ function ariaHidden(options) {
|
|
|
59
64
|
return () => {
|
|
60
65
|
observer.disconnect();
|
|
61
66
|
for (let node2 of hiddenNodes) {
|
|
62
|
-
let count =
|
|
67
|
+
let count = elementCountMap.get(node2);
|
|
63
68
|
if (count === 1) {
|
|
64
69
|
node2.removeAttribute("aria-hidden");
|
|
65
|
-
|
|
70
|
+
elementCountMap.delete(node2);
|
|
66
71
|
continue;
|
|
67
72
|
}
|
|
68
73
|
if (count !== void 0) {
|
|
69
|
-
|
|
74
|
+
elementCountMap.set(node2, count - 1);
|
|
70
75
|
}
|
|
71
76
|
}
|
|
72
77
|
};
|
|
@@ -74,4 +79,3 @@ function ariaHidden(options) {
|
|
|
74
79
|
export {
|
|
75
80
|
ariaHidden
|
|
76
81
|
};
|
|
77
|
-
//# sourceMappingURL=index.mjs.map
|
package/package.json
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/aria-hidden",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Hide targets from screen readers",
|
|
5
|
-
"keywords": [
|
|
5
|
+
"keywords": [
|
|
6
|
+
"js",
|
|
7
|
+
"utils",
|
|
8
|
+
"aria-hidden"
|
|
9
|
+
],
|
|
6
10
|
"author": "Segun Adebayo <sage@adebayosegun.com>",
|
|
7
11
|
"homepage": "https://github.com/chakra-ui/zag#readme",
|
|
8
12
|
"license": "MIT",
|
|
@@ -11,20 +15,22 @@
|
|
|
11
15
|
"types": "dist/index.d.ts",
|
|
12
16
|
"repository": "https://github.com/chakra-ui/zag/tree/main/packages/utilities/aria-hidden",
|
|
13
17
|
"sideEffects": false,
|
|
14
|
-
"files": [
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"start": "yarn zag build --watch",
|
|
18
|
-
"build": "yarn zag build --prod",
|
|
19
|
-
"test": "jest --config ../../../jest.config.js --rootDir tests",
|
|
20
|
-
"lint": "eslint src --ext .ts,.tsx",
|
|
21
|
-
"test:ci": "yarn test --ci --runInBand --updateSnapshot",
|
|
22
|
-
"test:watch": "yarn test --watchAll"
|
|
23
|
-
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist/**/*"
|
|
20
|
+
],
|
|
24
21
|
"publishConfig": {
|
|
25
22
|
"access": "public"
|
|
26
23
|
},
|
|
27
24
|
"bugs": {
|
|
28
25
|
"url": "https://github.com/chakra-ui/zag/issues"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build-fast": "tsup src/index.ts --format=esm,cjs",
|
|
29
|
+
"start": "pnpm build --watch",
|
|
30
|
+
"build": "tsup src/index.ts --format=esm,cjs --dts",
|
|
31
|
+
"test": "jest --config ../../../jest.config.js --rootDir tests",
|
|
32
|
+
"lint": "eslint src --ext .ts,.tsx",
|
|
33
|
+
"test-ci": "pnpm test --ci --runInBand -u",
|
|
34
|
+
"test-watch": "pnpm test --watchAll"
|
|
29
35
|
}
|
|
30
|
-
}
|
|
36
|
+
}
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,oBAAY,iBAAiB,GAAG;IAC9B,OAAO,EAAE,WAAW,EAAE,CAAA;IACtB,QAAQ,EAAE,QAAQ,CAAA;IAClB,IAAI,CAAC,EAAE,WAAW,CAAA;CACnB,CAAA;AAED,wBAAgB,UAAU,CAAC,OAAO,EAAE,iBAAiB,cAiGpD"}
|
package/dist/index.js.map
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["// Credits: https://github.com/adobe/react-spectrum/blob/main/packages/@react-aria/overlays/src/ariaHideOutside.ts\n\nlet map = new WeakMap<Element, number>()\n\nexport type AriaHiddenOptions = {\n exclude: HTMLElement[]\n document: Document\n root?: HTMLElement\n}\n\nexport function ariaHidden(options: AriaHiddenOptions) {\n const { exclude, document: doc, root = doc.body } = options\n const win = doc.defaultView ?? window\n\n const visibleNodes = new Set<Element>(exclude)\n const hiddenNodes = new Set<Element>()\n\n const walker = doc.createTreeWalker(root, NodeFilter.SHOW_ELEMENT, {\n acceptNode(node) {\n // If this node is a live announcer, add it to the set of nodes to keep visible.\n if (node instanceof win.HTMLElement && node.dataset.liveAnnouncer === \"true\") {\n visibleNodes.add(node)\n }\n\n // Skip this node and its children if it is one of the target nodes, or a live announcer.\n // Also skip children of already hidden nodes, as aria-hidden is recursive.\n if (visibleNodes.has(node as Element) || hiddenNodes.has(node.parentElement!)) {\n return NodeFilter.FILTER_REJECT\n }\n\n // VoiceOver on iOS has issues hiding elements with role=\"row\". Hide the cells inside instead.\n // https://bugs.webkit.org/show_bug.cgi?id=222623\n if (node instanceof win.HTMLElement && node.getAttribute(\"role\") === \"row\") {\n return NodeFilter.FILTER_SKIP\n }\n\n // Skip this node but continue to children if one of the targets is inside the node.\n if (exclude.some((target) => node.contains(target))) {\n return NodeFilter.FILTER_SKIP\n }\n\n return NodeFilter.FILTER_ACCEPT\n },\n })\n\n const hide = (node: Element) => {\n let refCount = map.get(node) ?? 0\n\n // If already aria-hidden, and the ref count is zero, then this element\n // was already hidden and there's nothing for us to do.\n if (node.getAttribute(\"aria-hidden\") === \"true\" && refCount === 0) {\n return\n }\n\n if (refCount === 0) {\n node.setAttribute(\"aria-hidden\", \"true\")\n }\n\n hiddenNodes.add(node)\n map.set(node, refCount + 1)\n }\n\n let node = walker.nextNode() as Element\n\n while (node != null) {\n hide(node)\n node = walker.nextNode() as Element\n }\n\n const observer = new win.MutationObserver((changes) => {\n for (let change of changes) {\n if (change.type !== \"childList\" || change.addedNodes.length === 0) continue\n\n // If the parent element of the added nodes is not within one of the targets,\n // and not already inside a hidden node, hide all of the new children.\n if (![...visibleNodes, ...hiddenNodes].some((node) => node.contains(change.target))) {\n //@ts-expect-error\n for (const node of change.addedNodes) {\n if (node instanceof win.HTMLElement && node.dataset.liveAnnouncer === \"true\") {\n visibleNodes.add(node)\n } else if (node instanceof win.Element) {\n hide(node)\n }\n }\n }\n }\n })\n\n observer.observe(root, { childList: true, subtree: true })\n\n return () => {\n observer.disconnect()\n\n for (let node of hiddenNodes) {\n let count = map.get(node)\n\n if (count === 1) {\n node.removeAttribute(\"aria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O,QAAQ,MAAM;AACnB,SAAK,IAAI;AACT,WAAO,OAAO,SAAS;AAAA,EACzB;AAEA,QAAM,WAAW,IAAI,IAAI,iBAAiB,CAAC,YAAY;AACrD,aAAS,UAAU,SAAS;AAC1B,UAAI,OAAO,SAAS,eAAe,OAAO,WAAW,WAAW;AAAG;AAInE,UAAI,CAAC,CAAC,GAAG,cAAc,GAAG,WAAW,EAAE,KAAK,CAAC,UAAS,MAAK,SAAS,OAAO,MAAM,CAAC,GAAG;AAEnF,mBAAW,SAAQ,OAAO,YAAY;AACpC,cAAI,iBAAgB,IAAI,eAAe,MAAK,QAAQ,kBAAkB,QAAQ;AAC5E,yBAAa,IAAI,KAAI;AAAA,UACvB,WAAW,iBAAgB,IAAI,SAAS;AACtC,iBAAK,KAAI;AAAA,UACX;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF,CAAC;AAED,WAAS,QAAQ,MAAM,EAAE,WAAW,MAAM,SAAS,KAAK,CAAC;AAEzD,SAAO,MAAM;AACX,aAAS,WAAW;AAEpB,aAAS,SAAQ,aAAa;AAC5B,UAAI,QAAQ,IAAI,IAAI,KAAI;AAExB,UAAI,UAAU,GAAG;AACf,cAAK,gBAAgB,aAAa;AAClC,YAAI,OAAO,KAAI;AACf;AAAA,MACF;AAEA,UAAI,UAAU,QAAW;AACvB,YAAI,IAAI,OAAM,QAAQ,CAAC;AAAA,MACzB;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
package/dist/index.mjs.map
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["// Credits: https://github.com/adobe/react-spectrum/blob/main/packages/@react-aria/overlays/src/ariaHideOutside.ts\n\nlet map = new WeakMap<Element, number>()\n\nexport type AriaHiddenOptions = {\n exclude: HTMLElement[]\n document: Document\n root?: HTMLElement\n}\n\nexport function ariaHidden(options: AriaHiddenOptions) {\n const { exclude, document: doc, root = doc.body } = options\n const win = doc.defaultView ?? window\n\n const visibleNodes = new Set<Element>(exclude)\n const hiddenNodes = new Set<Element>()\n\n const walker = doc.createTreeWalker(root, NodeFilter.SHOW_ELEMENT, {\n acceptNode(node) {\n // If this node is a live announcer, add it to the set of nodes to keep visible.\n if (node instanceof win.HTMLElement && node.dataset.liveAnnouncer === \"true\") {\n visibleNodes.add(node)\n }\n\n // Skip this node and its children if it is one of the target nodes, or a live announcer.\n // Also skip children of already hidden nodes, as aria-hidden is recursive.\n if (visibleNodes.has(node as Element) || hiddenNodes.has(node.parentElement!)) {\n return NodeFilter.FILTER_REJECT\n }\n\n // VoiceOver on iOS has issues hiding elements with role=\"row\". Hide the cells inside instead.\n // https://bugs.webkit.org/show_bug.cgi?id=222623\n if (node instanceof win.HTMLElement && node.getAttribute(\"role\") === \"row\") {\n return NodeFilter.FILTER_SKIP\n }\n\n // Skip this node but continue to children if one of the targets is inside the node.\n if (exclude.some((target) => node.contains(target))) {\n return NodeFilter.FILTER_SKIP\n }\n\n return NodeFilter.FILTER_ACCEPT\n },\n })\n\n const hide = (node: Element) => {\n let refCount = map.get(node) ?? 0\n\n // If already aria-hidden, and the ref count is zero, then this element\n // was already hidden and there's nothing for us to do.\n if (node.getAttribute(\"aria-hidden\") === \"true\" && refCount === 0) {\n return\n }\n\n if (refCount === 0) {\n node.setAttribute(\"aria-hidden\", \"true\")\n }\n\n hiddenNodes.add(node)\n map.set(node, refCount + 1)\n }\n\n let node = walker.nextNode() as Element\n\n while (node != null) {\n hide(node)\n node = walker.nextNode() as Element\n }\n\n const observer = new win.MutationObserver((changes) => {\n for (let change of changes) {\n if (change.type !== \"childList\" || change.addedNodes.length === 0) continue\n\n // If the parent element of the added nodes is not within one of the targets,\n // and not already inside a hidden node, hide all of the new children.\n if (![...visibleNodes, ...hiddenNodes].some((node) => node.contains(change.target))) {\n //@ts-expect-error\n for (const node of change.addedNodes) {\n if (node instanceof win.HTMLElement && node.dataset.liveAnnouncer === \"true\") {\n visibleNodes.add(node)\n } else if (node instanceof win.Element) {\n hide(node)\n }\n }\n }\n }\n })\n\n observer.observe(root, { childList: true, subtree: true })\n\n return () => {\n observer.disconnect()\n\n for (let node of hiddenNodes) {\n let count = map.get(node)\n\n if (count === 1) {\n node.removeAttribute(\"aria-hidden\")\n map.delete(node)\n continue\n }\n\n if (count !== undefined) {\n map.set(node, count - 1)\n }\n }\n }\n}\n"],
|
|
5
|
-
"mappings": ";AAEA,IAAI,MAAM,oBAAI,QAAyB;AAQhC,oBAAoB,SAA4B;AAVvD;AAWE,QAAM,EAAE,SAAS,UAAU,KAAK,OAAO,IAAI,SAAS;AACpD,QAAM,MAAM,UAAI,gBAAJ,YAAmB;AAE/B,QAAM,eAAe,IAAI,IAAa,OAAO;AAC7C,QAAM,cAAc,oBAAI,IAAa;AAErC,QAAM,SAAS,IAAI,iBAAiB,MAAM,WAAW,cAAc;AAAA,IACjE,WAAW,OAAM;AAEf,UAAI,iBAAgB,IAAI,eAAe,MAAK,QAAQ,kBAAkB,QAAQ;AAC5E,qBAAa,IAAI,KAAI;AAAA,MACvB;AAIA,UAAI,aAAa,IAAI,KAAe,KAAK,YAAY,IAAI,MAAK,aAAc,GAAG;AAC7E,eAAO,WAAW;AAAA,MACpB;AAIA,UAAI,iBAAgB,IAAI,eAAe,MAAK,aAAa,MAAM,MAAM,OAAO;AAC1E,eAAO,WAAW;AAAA,MACpB;AAGA,UAAI,QAAQ,KAAK,CAAC,WAAW,MAAK,SAAS,MAAM,CAAC,GAAG;AACnD,eAAO,WAAW;AAAA,MACpB;AAEA,aAAO,WAAW;AAAA,IACpB;AAAA,EACF,CAAC;AAED,QAAM,OAAO,CAAC,UAAkB;AA7ClC;AA8CI,QAAI,WAAW,WAAI,IAAI,KAAI,MAAZ,aAAiB;AAIhC,QAAI,MAAK,aAAa,aAAa,MAAM,UAAU,aAAa,GAAG;AACjE;AAAA,IACF;AAEA,QAAI,aA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