@zag-js/aria-hidden 1.47.0 → 1.48.0

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.
@@ -1,5 +1,3 @@
1
- declare const hideOthers: (originalTarget: Element | Element[], parentNode?: HTMLElement | null, markerName?: string, followControlledElements?: boolean) => VoidFunction | undefined;
2
- declare const inertOthers: (originalTarget: Element | Element[], parentNode?: HTMLElement | null, markerName?: string, followControlledElements?: boolean) => VoidFunction | undefined;
3
- declare const suppressOthers: (originalTarget: Element | Element[], parentNode?: HTMLElement, markerName?: string, followControlledElements?: boolean) => VoidFunction | undefined;
4
-
5
- export { hideOthers, inertOthers, suppressOthers };
1
+ export declare const hideOthers: (originalTarget: Element | Element[], parentNode?: HTMLElement | null, markerName?: string, followControlledElements?: boolean) => VoidFunction | undefined;
2
+ export declare const inertOthers: (originalTarget: Element | Element[], parentNode?: HTMLElement | null, markerName?: string, followControlledElements?: boolean) => VoidFunction | undefined;
3
+ export declare const suppressOthers: (originalTarget: Element | Element[], parentNode?: HTMLElement, markerName?: string, followControlledElements?: boolean) => VoidFunction | undefined;
@@ -1,5 +1,3 @@
1
- declare const hideOthers: (originalTarget: Element | Element[], parentNode?: HTMLElement | null, markerName?: string, followControlledElements?: boolean) => VoidFunction | undefined;
2
- declare const inertOthers: (originalTarget: Element | Element[], parentNode?: HTMLElement | null, markerName?: string, followControlledElements?: boolean) => VoidFunction | undefined;
3
- declare const suppressOthers: (originalTarget: Element | Element[], parentNode?: HTMLElement, markerName?: string, followControlledElements?: boolean) => VoidFunction | undefined;
4
-
5
- export { hideOthers, inertOthers, suppressOthers };
1
+ export declare const hideOthers: (originalTarget: Element | Element[], parentNode?: HTMLElement | null, markerName?: string, followControlledElements?: boolean) => VoidFunction | undefined;
2
+ export declare const inertOthers: (originalTarget: Element | Element[], parentNode?: HTMLElement | null, markerName?: string, followControlledElements?: boolean) => VoidFunction | undefined;
3
+ export declare const suppressOthers: (originalTarget: Element | Element[], parentNode?: HTMLElement, markerName?: string, followControlledElements?: boolean) => VoidFunction | undefined;
@@ -1,61 +1,34 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/aria-hidden.ts
21
- var aria_hidden_exports = {};
22
- __export(aria_hidden_exports, {
23
- hideOthers: () => hideOthers,
24
- inertOthers: () => inertOthers,
25
- suppressOthers: () => suppressOthers
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
26
4
  });
27
- module.exports = __toCommonJS(aria_hidden_exports);
28
- var import_walk_tree_outside = require("./walk-tree-outside.js");
29
- var getParentNode = (originalTarget) => {
30
- const target = Array.isArray(originalTarget) ? originalTarget[0] : originalTarget;
31
- return target.ownerDocument.body;
5
+ const require_walk_tree_outside = require("./walk-tree-outside.js");
6
+ // src/aria-hidden.ts
7
+ const getParentNode = (originalTarget) => {
8
+ return (Array.isArray(originalTarget) ? originalTarget[0] : originalTarget).ownerDocument.body;
32
9
  };
33
- var hideOthers = (originalTarget, parentNode = getParentNode(originalTarget), markerName = "data-aria-hidden", followControlledElements = true) => {
34
- if (!parentNode) return;
35
- return (0, import_walk_tree_outside.walkTreeOutside)(originalTarget, {
36
- parentNode,
37
- markerName,
38
- attribute: "aria-hidden",
39
- followControlledElements
40
- });
10
+ const hideOthers = (originalTarget, parentNode = getParentNode(originalTarget), markerName = "data-aria-hidden", followControlledElements = true) => {
11
+ if (!parentNode) return;
12
+ return require_walk_tree_outside.walkTreeOutside(originalTarget, {
13
+ parentNode,
14
+ markerName,
15
+ attribute: "aria-hidden",
16
+ followControlledElements
17
+ });
41
18
  };
42
- var inertOthers = (originalTarget, parentNode = getParentNode(originalTarget), markerName = "data-inerted", followControlledElements = true) => {
43
- if (!parentNode) return;
44
- return (0, import_walk_tree_outside.walkTreeOutside)(originalTarget, {
45
- parentNode,
46
- markerName,
47
- attribute: "inert",
48
- followControlledElements
49
- });
19
+ const inertOthers = (originalTarget, parentNode = getParentNode(originalTarget), markerName = "data-inerted", followControlledElements = true) => {
20
+ if (!parentNode) return;
21
+ return require_walk_tree_outside.walkTreeOutside(originalTarget, {
22
+ parentNode,
23
+ markerName,
24
+ attribute: "inert",
25
+ followControlledElements
26
+ });
50
27
  };
51
- var supportsInert = () => typeof HTMLElement !== "undefined" && HTMLElement.prototype.hasOwnProperty("inert");
52
- var suppressOthers = (originalTarget, parentNode, markerName = "data-suppressed", followControlledElements = true) => {
53
- const fn = supportsInert() ? inertOthers : hideOthers;
54
- return fn(originalTarget, parentNode, markerName, followControlledElements);
28
+ const supportsInert = () => typeof HTMLElement !== "undefined" && HTMLElement.prototype.hasOwnProperty("inert");
29
+ const suppressOthers = (originalTarget, parentNode, markerName = "data-suppressed", followControlledElements = true) => {
30
+ return (supportsInert() ? inertOthers : hideOthers)(originalTarget, parentNode, markerName, followControlledElements);
55
31
  };
56
- // Annotate the CommonJS export names for ESM import in node:
57
- 0 && (module.exports = {
58
- hideOthers,
59
- inertOthers,
60
- suppressOthers
61
- });
32
+ exports.hideOthers = hideOthers;
33
+ exports.inertOthers = inertOthers;
34
+ exports.suppressOthers = suppressOthers;
@@ -1,34 +1,28 @@
1
- // src/aria-hidden.ts
2
1
  import { walkTreeOutside } from "./walk-tree-outside.mjs";
3
- var getParentNode = (originalTarget) => {
4
- const target = Array.isArray(originalTarget) ? originalTarget[0] : originalTarget;
5
- return target.ownerDocument.body;
6
- };
7
- var hideOthers = (originalTarget, parentNode = getParentNode(originalTarget), markerName = "data-aria-hidden", followControlledElements = true) => {
8
- if (!parentNode) return;
9
- return walkTreeOutside(originalTarget, {
10
- parentNode,
11
- markerName,
12
- attribute: "aria-hidden",
13
- followControlledElements
14
- });
2
+ // src/aria-hidden.ts
3
+ const getParentNode = (originalTarget) => {
4
+ return (Array.isArray(originalTarget) ? originalTarget[0] : originalTarget).ownerDocument.body;
15
5
  };
16
- var inertOthers = (originalTarget, parentNode = getParentNode(originalTarget), markerName = "data-inerted", followControlledElements = true) => {
17
- if (!parentNode) return;
18
- return walkTreeOutside(originalTarget, {
19
- parentNode,
20
- markerName,
21
- attribute: "inert",
22
- followControlledElements
23
- });
6
+ const hideOthers = (originalTarget, parentNode = getParentNode(originalTarget), markerName = "data-aria-hidden", followControlledElements = true) => {
7
+ if (!parentNode) return;
8
+ return walkTreeOutside(originalTarget, {
9
+ parentNode,
10
+ markerName,
11
+ attribute: "aria-hidden",
12
+ followControlledElements
13
+ });
24
14
  };
25
- var supportsInert = () => typeof HTMLElement !== "undefined" && HTMLElement.prototype.hasOwnProperty("inert");
26
- var suppressOthers = (originalTarget, parentNode, markerName = "data-suppressed", followControlledElements = true) => {
27
- const fn = supportsInert() ? inertOthers : hideOthers;
28
- return fn(originalTarget, parentNode, markerName, followControlledElements);
15
+ const inertOthers = (originalTarget, parentNode = getParentNode(originalTarget), markerName = "data-inerted", followControlledElements = true) => {
16
+ if (!parentNode) return;
17
+ return walkTreeOutside(originalTarget, {
18
+ parentNode,
19
+ markerName,
20
+ attribute: "inert",
21
+ followControlledElements
22
+ });
29
23
  };
30
- export {
31
- hideOthers,
32
- inertOthers,
33
- suppressOthers
24
+ const supportsInert = () => typeof HTMLElement !== "undefined" && HTMLElement.prototype.hasOwnProperty("inert");
25
+ const suppressOthers = (originalTarget, parentNode, markerName = "data-suppressed", followControlledElements = true) => {
26
+ return (supportsInert() ? inertOthers : hideOthers)(originalTarget, parentNode, markerName, followControlledElements);
34
27
  };
28
+ export { hideOthers, inertOthers, suppressOthers };
package/dist/index.d.mts CHANGED
@@ -2,8 +2,7 @@ type MaybeElement = HTMLElement | null;
2
2
  type Targets = Array<MaybeElement>;
3
3
  type TargetsOrFn = Targets | (() => Targets);
4
4
  type Options = {
5
- defer?: boolean | undefined;
5
+ defer?: boolean | undefined;
6
6
  };
7
- declare function ariaHidden(targetsOrFn: TargetsOrFn, options?: Options): () => void;
8
-
9
- export { ariaHidden };
7
+ export declare function ariaHidden(targetsOrFn: TargetsOrFn, options?: Options): () => void;
8
+ export {};
package/dist/index.d.ts CHANGED
@@ -2,8 +2,7 @@ type MaybeElement = HTMLElement | null;
2
2
  type Targets = Array<MaybeElement>;
3
3
  type TargetsOrFn = Targets | (() => Targets);
4
4
  type Options = {
5
- defer?: boolean | undefined;
5
+ defer?: boolean | undefined;
6
6
  };
7
- declare function ariaHidden(targetsOrFn: TargetsOrFn, options?: Options): () => void;
8
-
9
- export { ariaHidden };
7
+ export declare function ariaHidden(targetsOrFn: TargetsOrFn, options?: Options): () => void;
8
+ export {};
package/dist/index.js CHANGED
@@ -1,50 +1,24 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/index.ts
21
- var index_exports = {};
22
- __export(index_exports, {
23
- ariaHidden: () => ariaHidden
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
24
4
  });
25
- module.exports = __toCommonJS(index_exports);
26
- var import_aria_hidden = require("./aria-hidden.js");
27
- var raf = (fn) => {
28
- const frameId = requestAnimationFrame(() => fn());
29
- return () => cancelAnimationFrame(frameId);
5
+ const require_aria_hidden = require("./aria-hidden.js");
6
+ // src/index.ts
7
+ const raf = (fn) => {
8
+ const frameId = requestAnimationFrame(() => fn());
9
+ return () => cancelAnimationFrame(frameId);
30
10
  };
31
11
  function ariaHidden(targetsOrFn, options = {}) {
32
- const { defer = true } = options;
33
- const func = defer ? raf : (v) => v();
34
- const cleanups = [];
35
- cleanups.push(
36
- func(() => {
37
- const targets = typeof targetsOrFn === "function" ? targetsOrFn() : targetsOrFn;
38
- const elements = targets.filter(Boolean);
39
- if (elements.length === 0) return;
40
- cleanups.push((0, import_aria_hidden.hideOthers)(elements));
41
- })
42
- );
43
- return () => {
44
- cleanups.forEach((fn) => fn?.());
45
- };
12
+ const { defer = true } = options;
13
+ const func = defer ? raf : (v) => v();
14
+ const cleanups = [];
15
+ cleanups.push(func(() => {
16
+ const elements = (typeof targetsOrFn === "function" ? targetsOrFn() : targetsOrFn).filter(Boolean);
17
+ if (elements.length === 0) return;
18
+ cleanups.push(require_aria_hidden.hideOthers(elements));
19
+ }));
20
+ return () => {
21
+ cleanups.forEach((fn) => fn?.());
22
+ };
46
23
  }
47
- // Annotate the CommonJS export names for ESM import in node:
48
- 0 && (module.exports = {
49
- ariaHidden
50
- });
24
+ exports.ariaHidden = ariaHidden;
package/dist/index.mjs CHANGED
@@ -1,25 +1,20 @@
1
- // src/index.ts
2
1
  import { hideOthers } from "./aria-hidden.mjs";
3
- var raf = (fn) => {
4
- const frameId = requestAnimationFrame(() => fn());
5
- return () => cancelAnimationFrame(frameId);
2
+ // src/index.ts
3
+ const raf = (fn) => {
4
+ const frameId = requestAnimationFrame(() => fn());
5
+ return () => cancelAnimationFrame(frameId);
6
6
  };
7
7
  function ariaHidden(targetsOrFn, options = {}) {
8
- const { defer = true } = options;
9
- const func = defer ? raf : (v) => v();
10
- const cleanups = [];
11
- cleanups.push(
12
- func(() => {
13
- const targets = typeof targetsOrFn === "function" ? targetsOrFn() : targetsOrFn;
14
- const elements = targets.filter(Boolean);
15
- if (elements.length === 0) return;
16
- cleanups.push(hideOthers(elements));
17
- })
18
- );
19
- return () => {
20
- cleanups.forEach((fn) => fn?.());
21
- };
8
+ const { defer = true } = options;
9
+ const func = defer ? raf : (v) => v();
10
+ const cleanups = [];
11
+ cleanups.push(func(() => {
12
+ const elements = (typeof targetsOrFn === "function" ? targetsOrFn() : targetsOrFn).filter(Boolean);
13
+ if (elements.length === 0) return;
14
+ cleanups.push(hideOthers(elements));
15
+ }));
16
+ return () => {
17
+ cleanups.forEach((fn) => fn?.());
18
+ };
22
19
  }
23
- export {
24
- ariaHidden
25
- };
20
+ export { ariaHidden };
@@ -1,9 +1,8 @@
1
1
  interface WalkTreeOutsideOptions {
2
- parentNode: HTMLElement;
3
- markerName: string;
4
- attribute: "aria-hidden" | "inert";
5
- followControlledElements?: boolean;
2
+ parentNode: HTMLElement;
3
+ markerName: string;
4
+ attribute: "aria-hidden" | "inert";
5
+ followControlledElements?: boolean;
6
6
  }
7
- declare const walkTreeOutside: (originalTarget: Element | Element[], props: WalkTreeOutsideOptions) => VoidFunction;
8
-
9
- export { walkTreeOutside };
7
+ export declare const walkTreeOutside: (originalTarget: Element | Element[], props: WalkTreeOutsideOptions) => VoidFunction;
8
+ export {};
@@ -1,9 +1,8 @@
1
1
  interface WalkTreeOutsideOptions {
2
- parentNode: HTMLElement;
3
- markerName: string;
4
- attribute: "aria-hidden" | "inert";
5
- followControlledElements?: boolean;
2
+ parentNode: HTMLElement;
3
+ markerName: string;
4
+ attribute: "aria-hidden" | "inert";
5
+ followControlledElements?: boolean;
6
6
  }
7
- declare const walkTreeOutside: (originalTarget: Element | Element[], props: WalkTreeOutsideOptions) => VoidFunction;
8
-
9
- export { walkTreeOutside };
7
+ export declare const walkTreeOutside: (originalTarget: Element | Element[], props: WalkTreeOutsideOptions) => VoidFunction;
8
+ export {};
@@ -1,199 +1,164 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/walk-tree-outside.ts
21
- var walk_tree_outside_exports = {};
22
- __export(walk_tree_outside_exports, {
23
- walkTreeOutside: () => walkTreeOutside
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
24
4
  });
25
- module.exports = __toCommonJS(walk_tree_outside_exports);
26
- var import_dom_query = require("@zag-js/dom-query");
27
- var counterMap = /* @__PURE__ */ new WeakMap();
28
- var uncontrolledNodes = /* @__PURE__ */ new WeakMap();
29
- var markerMap = {};
30
- var lockCount = 0;
31
- var unwrapHost = (node) => node && (node.host || unwrapHost(node.parentNode));
32
- var correctTargets = (parent, targets) => targets.map((target) => {
33
- if (parent.contains(target)) return target;
34
- const correctedTarget = unwrapHost(target);
35
- if (correctedTarget && parent.contains(correctedTarget)) {
36
- return correctedTarget;
37
- }
38
- console.error("[zag-js > ariaHidden] target", target, "in not contained inside", parent, ". Doing nothing");
39
- return null;
5
+ let _zag_js_dom_query = require("@zag-js/dom-query");
6
+ // src/walk-tree-outside.ts
7
+ let counterMap = /* @__PURE__ */ new WeakMap();
8
+ let uncontrolledNodes = /* @__PURE__ */ new WeakMap();
9
+ let markerMap = {};
10
+ let lockCount = 0;
11
+ const unwrapHost = (node) => node && (node.host || unwrapHost(node.parentNode));
12
+ const correctTargets = (parent, targets) => targets.map((target) => {
13
+ if (parent.contains(target)) return target;
14
+ const correctedTarget = unwrapHost(target);
15
+ if (correctedTarget && parent.contains(correctedTarget)) return correctedTarget;
16
+ console.error("[zag-js > ariaHidden] target", target, "in not contained inside", parent, ". Doing nothing");
17
+ return null;
40
18
  }).filter((x) => Boolean(x));
41
- var ignoreableNodes = /* @__PURE__ */ new Set(["script", "output", "status", "next-route-announcer"]);
42
- var isIgnoredNode = (node) => {
43
- if (ignoreableNodes.has(node.localName)) return true;
44
- if (node.role === "status") return true;
45
- if (node.hasAttribute("aria-live")) return true;
46
- return node.matches("[data-live-announcer]");
19
+ const ignoreableNodes = /* @__PURE__ */ new Set([
20
+ "script",
21
+ "output",
22
+ "status",
23
+ "next-route-announcer"
24
+ ]);
25
+ const isIgnoredNode = (node) => {
26
+ if (ignoreableNodes.has(node.localName)) return true;
27
+ if (node.role === "status") return true;
28
+ if (node.hasAttribute("aria-live")) return true;
29
+ return node.matches("[data-live-announcer]");
47
30
  };
48
- var applyAttributeToOthers = (allTargets, props) => {
49
- const { parentNode, markerName, attribute, followControlledElements = true } = props;
50
- const attributeValue = attribute === "aria-hidden" ? "true" : "";
51
- const targets = allTargets.filter((target) => parentNode.contains(target));
52
- if (!targets.length) return () => {
53
- };
54
- markerMap[markerName] || (markerMap[markerName] = /* @__PURE__ */ new WeakMap());
55
- const markerCounter = markerMap[markerName];
56
- const hiddenNodes = [];
57
- const elementsToKeep = /* @__PURE__ */ new Set();
58
- const elementsToStop = new Set(targets);
59
- const keep = (el) => {
60
- if (!el || elementsToKeep.has(el)) return;
61
- elementsToKeep.add(el);
62
- keep(el.parentNode);
63
- };
64
- targets.forEach((target) => {
65
- keep(target);
66
- if (followControlledElements && (0, import_dom_query.isHTMLElement)(target)) {
67
- (0, import_dom_query.findControlledElements)(target, (controlledElement) => {
68
- keep(controlledElement);
69
- elementsToStop.add(controlledElement);
70
- });
71
- }
72
- });
73
- const deep = (parent) => {
74
- if (!parent || elementsToStop.has(parent)) {
75
- return;
76
- }
77
- Array.prototype.forEach.call(parent.children, (node) => {
78
- if (elementsToKeep.has(node)) {
79
- deep(node);
80
- } else {
81
- try {
82
- if (isIgnoredNode(node)) return;
83
- const alreadyHidden = attribute === "aria-hidden" ? node.getAttribute(attribute) === "true" : node.hasAttribute(attribute);
84
- const counterValue = (counterMap.get(node) || 0) + 1;
85
- const markerValue = (markerCounter.get(node) || 0) + 1;
86
- counterMap.set(node, counterValue);
87
- markerCounter.set(node, markerValue);
88
- hiddenNodes.push(node);
89
- if (counterValue === 1 && alreadyHidden) {
90
- uncontrolledNodes.set(node, true);
91
- }
92
- if (markerValue === 1) {
93
- node.setAttribute(markerName, "");
94
- }
95
- if (!alreadyHidden) {
96
- node.setAttribute(attribute, attributeValue);
97
- }
98
- } catch (e) {
99
- console.error("[zag-js > ariaHidden] cannot operate on ", node, e);
100
- }
101
- }
102
- });
103
- };
104
- deep(parentNode);
105
- elementsToKeep.clear();
106
- lockCount++;
107
- return () => {
108
- hiddenNodes.forEach((node) => {
109
- const counterValue = counterMap.get(node) - 1;
110
- const markerValue = markerCounter.get(node) - 1;
111
- counterMap.set(node, counterValue);
112
- markerCounter.set(node, markerValue);
113
- if (!counterValue) {
114
- if (!uncontrolledNodes.has(node)) {
115
- node.removeAttribute(attribute);
116
- }
117
- uncontrolledNodes.delete(node);
118
- }
119
- if (!markerValue) {
120
- node.removeAttribute(markerName);
121
- }
122
- });
123
- lockCount--;
124
- if (!lockCount) {
125
- counterMap = /* @__PURE__ */ new WeakMap();
126
- uncontrolledNodes = /* @__PURE__ */ new WeakMap();
127
- markerMap = {};
128
- }
129
- };
31
+ const applyAttributeToOthers = (allTargets, props) => {
32
+ var _markerMap;
33
+ const { parentNode, markerName, attribute, followControlledElements = true } = props;
34
+ const attributeValue = attribute === "aria-hidden" ? "true" : "";
35
+ const targets = allTargets.filter((target) => parentNode.contains(target));
36
+ if (!targets.length) return () => {};
37
+ (_markerMap = markerMap)[markerName] || (_markerMap[markerName] = /* @__PURE__ */ new WeakMap());
38
+ const markerCounter = markerMap[markerName];
39
+ const hiddenNodes = [];
40
+ const elementsToKeep = /* @__PURE__ */ new Set();
41
+ const elementsToStop = new Set(targets);
42
+ const keep = (el) => {
43
+ if (!el || elementsToKeep.has(el)) return;
44
+ elementsToKeep.add(el);
45
+ keep(el.parentNode);
46
+ };
47
+ targets.forEach((target) => {
48
+ keep(target);
49
+ if (followControlledElements && (0, _zag_js_dom_query.isHTMLElement)(target)) (0, _zag_js_dom_query.findControlledElements)(target, (controlledElement) => {
50
+ keep(controlledElement);
51
+ elementsToStop.add(controlledElement);
52
+ });
53
+ });
54
+ const deep = (parent) => {
55
+ if (!parent || elementsToStop.has(parent)) return;
56
+ Array.prototype.forEach.call(parent.children, (node) => {
57
+ if (elementsToKeep.has(node)) deep(node);
58
+ else try {
59
+ if (isIgnoredNode(node)) return;
60
+ const alreadyHidden = attribute === "aria-hidden" ? node.getAttribute(attribute) === "true" : node.hasAttribute(attribute);
61
+ const counterValue = (counterMap.get(node) || 0) + 1;
62
+ const markerValue = (markerCounter.get(node) || 0) + 1;
63
+ counterMap.set(node, counterValue);
64
+ markerCounter.set(node, markerValue);
65
+ hiddenNodes.push(node);
66
+ if (counterValue === 1 && alreadyHidden) uncontrolledNodes.set(node, true);
67
+ if (markerValue === 1) node.setAttribute(markerName, "");
68
+ if (!alreadyHidden) node.setAttribute(attribute, attributeValue);
69
+ } catch (e) {
70
+ console.error("[zag-js > ariaHidden] cannot operate on ", node, e);
71
+ }
72
+ });
73
+ };
74
+ deep(parentNode);
75
+ elementsToKeep.clear();
76
+ lockCount++;
77
+ return () => {
78
+ hiddenNodes.forEach((node) => {
79
+ const counterValue = counterMap.get(node) - 1;
80
+ const markerValue = markerCounter.get(node) - 1;
81
+ counterMap.set(node, counterValue);
82
+ markerCounter.set(node, markerValue);
83
+ if (!counterValue) {
84
+ if (!uncontrolledNodes.has(node)) node.removeAttribute(attribute);
85
+ uncontrolledNodes.delete(node);
86
+ }
87
+ if (!markerValue) node.removeAttribute(markerName);
88
+ });
89
+ lockCount--;
90
+ if (!lockCount) {
91
+ counterMap = /* @__PURE__ */ new WeakMap();
92
+ uncontrolledNodes = /* @__PURE__ */ new WeakMap();
93
+ markerMap = {};
94
+ }
95
+ };
130
96
  };
131
97
  function createLockStack() {
132
- const locks = [];
133
- return {
134
- add(lock) {
135
- locks[locks.length - 1]?.pause();
136
- locks.push(lock);
137
- lock.resume();
138
- },
139
- remove(lock) {
140
- const index = locks.indexOf(lock);
141
- if (index === -1) return;
142
- const isTop = index === locks.length - 1;
143
- locks.splice(index, 1);
144
- if (!isTop) return;
145
- lock.pause();
146
- locks[locks.length - 1]?.resume();
147
- }
148
- };
98
+ const locks = [];
99
+ return {
100
+ add(lock) {
101
+ locks[locks.length - 1]?.pause();
102
+ locks.push(lock);
103
+ lock.resume();
104
+ },
105
+ remove(lock) {
106
+ const index = locks.indexOf(lock);
107
+ if (index === -1) return;
108
+ const isTop = index === locks.length - 1;
109
+ locks.splice(index, 1);
110
+ if (!isTop) return;
111
+ lock.pause();
112
+ locks[locks.length - 1]?.resume();
113
+ }
114
+ };
149
115
  }
150
- var lockStacks = /* @__PURE__ */ new WeakMap();
151
- var getLockStack = (doc) => {
152
- let stack = lockStacks.get(doc);
153
- if (!stack) {
154
- stack = createLockStack();
155
- lockStacks.set(doc, stack);
156
- }
157
- return stack;
116
+ const lockStacks = /* @__PURE__ */ new WeakMap();
117
+ const getLockStack = (doc) => {
118
+ let stack = lockStacks.get(doc);
119
+ if (!stack) {
120
+ stack = createLockStack();
121
+ lockStacks.set(doc, stack);
122
+ }
123
+ return stack;
158
124
  };
159
- var walkTreeOutside = (originalTarget, props) => {
160
- const { parentNode, attribute, followControlledElements = true } = props;
161
- const targets = correctTargets(parentNode, Array.isArray(originalTarget) ? originalTarget : [originalTarget]);
162
- if (!targets.length) return () => {
163
- };
164
- const hiddenSelector = attribute === "aria-hidden" ? '[aria-hidden="true"]' : "[inert]";
165
- let undo;
166
- let observer;
167
- const apply = () => {
168
- const prevUndo = undo;
169
- undo = applyAttributeToOthers(targets, props);
170
- prevUndo?.();
171
- };
172
- const release = () => {
173
- undo?.();
174
- undo = void 0;
175
- };
176
- const lock = {
177
- pause() {
178
- observer?.disconnect();
179
- observer = void 0;
180
- release();
181
- },
182
- resume() {
183
- apply();
184
- if (!followControlledElements) return;
185
- const win = (0, import_dom_query.getWindow)(parentNode);
186
- observer = new win.MutationObserver((records) => {
187
- if (records.some(({ target }) => (0, import_dom_query.isElement)(target) && !target.closest(hiddenSelector))) apply();
188
- });
189
- observer.observe(parentNode, { attributes: true, attributeFilter: ["aria-expanded"], subtree: true });
190
- }
191
- };
192
- const lockStack = getLockStack(parentNode.ownerDocument);
193
- lockStack.add(lock);
194
- return () => lockStack.remove(lock);
125
+ const walkTreeOutside = (originalTarget, props) => {
126
+ const { parentNode, attribute, followControlledElements = true } = props;
127
+ const targets = correctTargets(parentNode, Array.isArray(originalTarget) ? originalTarget : [originalTarget]);
128
+ if (!targets.length) return () => {};
129
+ const hiddenSelector = attribute === "aria-hidden" ? "[aria-hidden=\"true\"]" : "[inert]";
130
+ let undo;
131
+ let observer;
132
+ const apply = () => {
133
+ const prevUndo = undo;
134
+ undo = applyAttributeToOthers(targets, props);
135
+ prevUndo?.();
136
+ };
137
+ const release = () => {
138
+ undo?.();
139
+ undo = void 0;
140
+ };
141
+ const lock = {
142
+ pause() {
143
+ observer?.disconnect();
144
+ observer = void 0;
145
+ release();
146
+ },
147
+ resume() {
148
+ apply();
149
+ if (!followControlledElements) return;
150
+ observer = new ((0, _zag_js_dom_query.getWindow)(parentNode)).MutationObserver((records) => {
151
+ if (records.some(({ target }) => (0, _zag_js_dom_query.isElement)(target) && !target.closest(hiddenSelector))) apply();
152
+ });
153
+ observer.observe(parentNode, {
154
+ attributes: true,
155
+ attributeFilter: ["aria-expanded"],
156
+ subtree: true
157
+ });
158
+ }
159
+ };
160
+ const lockStack = getLockStack(parentNode.ownerDocument);
161
+ lockStack.add(lock);
162
+ return () => lockStack.remove(lock);
195
163
  };
196
- // Annotate the CommonJS export names for ESM import in node:
197
- 0 && (module.exports = {
198
- walkTreeOutside
199
- });
164
+ exports.walkTreeOutside = walkTreeOutside;
@@ -1,174 +1,160 @@
1
- // src/walk-tree-outside.ts
2
1
  import { findControlledElements, getWindow, isElement, isHTMLElement } from "@zag-js/dom-query";
3
- var counterMap = /* @__PURE__ */ new WeakMap();
4
- var uncontrolledNodes = /* @__PURE__ */ new WeakMap();
5
- var markerMap = {};
6
- var lockCount = 0;
7
- var unwrapHost = (node) => node && (node.host || unwrapHost(node.parentNode));
8
- var correctTargets = (parent, targets) => targets.map((target) => {
9
- if (parent.contains(target)) return target;
10
- const correctedTarget = unwrapHost(target);
11
- if (correctedTarget && parent.contains(correctedTarget)) {
12
- return correctedTarget;
13
- }
14
- console.error("[zag-js > ariaHidden] target", target, "in not contained inside", parent, ". Doing nothing");
15
- return null;
2
+ // src/walk-tree-outside.ts
3
+ let counterMap = /* @__PURE__ */ new WeakMap();
4
+ let uncontrolledNodes = /* @__PURE__ */ new WeakMap();
5
+ let markerMap = {};
6
+ let lockCount = 0;
7
+ const unwrapHost = (node) => node && (node.host || unwrapHost(node.parentNode));
8
+ const correctTargets = (parent, targets) => targets.map((target) => {
9
+ if (parent.contains(target)) return target;
10
+ const correctedTarget = unwrapHost(target);
11
+ if (correctedTarget && parent.contains(correctedTarget)) return correctedTarget;
12
+ console.error("[zag-js > ariaHidden] target", target, "in not contained inside", parent, ". Doing nothing");
13
+ return null;
16
14
  }).filter((x) => Boolean(x));
17
- var ignoreableNodes = /* @__PURE__ */ new Set(["script", "output", "status", "next-route-announcer"]);
18
- var isIgnoredNode = (node) => {
19
- if (ignoreableNodes.has(node.localName)) return true;
20
- if (node.role === "status") return true;
21
- if (node.hasAttribute("aria-live")) return true;
22
- return node.matches("[data-live-announcer]");
15
+ const ignoreableNodes = /* @__PURE__ */ new Set([
16
+ "script",
17
+ "output",
18
+ "status",
19
+ "next-route-announcer"
20
+ ]);
21
+ const isIgnoredNode = (node) => {
22
+ if (ignoreableNodes.has(node.localName)) return true;
23
+ if (node.role === "status") return true;
24
+ if (node.hasAttribute("aria-live")) return true;
25
+ return node.matches("[data-live-announcer]");
23
26
  };
24
- var applyAttributeToOthers = (allTargets, props) => {
25
- const { parentNode, markerName, attribute, followControlledElements = true } = props;
26
- const attributeValue = attribute === "aria-hidden" ? "true" : "";
27
- const targets = allTargets.filter((target) => parentNode.contains(target));
28
- if (!targets.length) return () => {
29
- };
30
- markerMap[markerName] || (markerMap[markerName] = /* @__PURE__ */ new WeakMap());
31
- const markerCounter = markerMap[markerName];
32
- const hiddenNodes = [];
33
- const elementsToKeep = /* @__PURE__ */ new Set();
34
- const elementsToStop = new Set(targets);
35
- const keep = (el) => {
36
- if (!el || elementsToKeep.has(el)) return;
37
- elementsToKeep.add(el);
38
- keep(el.parentNode);
39
- };
40
- targets.forEach((target) => {
41
- keep(target);
42
- if (followControlledElements && isHTMLElement(target)) {
43
- findControlledElements(target, (controlledElement) => {
44
- keep(controlledElement);
45
- elementsToStop.add(controlledElement);
46
- });
47
- }
48
- });
49
- const deep = (parent) => {
50
- if (!parent || elementsToStop.has(parent)) {
51
- return;
52
- }
53
- Array.prototype.forEach.call(parent.children, (node) => {
54
- if (elementsToKeep.has(node)) {
55
- deep(node);
56
- } else {
57
- try {
58
- if (isIgnoredNode(node)) return;
59
- const alreadyHidden = attribute === "aria-hidden" ? node.getAttribute(attribute) === "true" : node.hasAttribute(attribute);
60
- const counterValue = (counterMap.get(node) || 0) + 1;
61
- const markerValue = (markerCounter.get(node) || 0) + 1;
62
- counterMap.set(node, counterValue);
63
- markerCounter.set(node, markerValue);
64
- hiddenNodes.push(node);
65
- if (counterValue === 1 && alreadyHidden) {
66
- uncontrolledNodes.set(node, true);
67
- }
68
- if (markerValue === 1) {
69
- node.setAttribute(markerName, "");
70
- }
71
- if (!alreadyHidden) {
72
- node.setAttribute(attribute, attributeValue);
73
- }
74
- } catch (e) {
75
- console.error("[zag-js > ariaHidden] cannot operate on ", node, e);
76
- }
77
- }
78
- });
79
- };
80
- deep(parentNode);
81
- elementsToKeep.clear();
82
- lockCount++;
83
- return () => {
84
- hiddenNodes.forEach((node) => {
85
- const counterValue = counterMap.get(node) - 1;
86
- const markerValue = markerCounter.get(node) - 1;
87
- counterMap.set(node, counterValue);
88
- markerCounter.set(node, markerValue);
89
- if (!counterValue) {
90
- if (!uncontrolledNodes.has(node)) {
91
- node.removeAttribute(attribute);
92
- }
93
- uncontrolledNodes.delete(node);
94
- }
95
- if (!markerValue) {
96
- node.removeAttribute(markerName);
97
- }
98
- });
99
- lockCount--;
100
- if (!lockCount) {
101
- counterMap = /* @__PURE__ */ new WeakMap();
102
- uncontrolledNodes = /* @__PURE__ */ new WeakMap();
103
- markerMap = {};
104
- }
105
- };
27
+ const applyAttributeToOthers = (allTargets, props) => {
28
+ var _markerMap;
29
+ const { parentNode, markerName, attribute, followControlledElements = true } = props;
30
+ const attributeValue = attribute === "aria-hidden" ? "true" : "";
31
+ const targets = allTargets.filter((target) => parentNode.contains(target));
32
+ if (!targets.length) return () => {};
33
+ (_markerMap = markerMap)[markerName] || (_markerMap[markerName] = /* @__PURE__ */ new WeakMap());
34
+ const markerCounter = markerMap[markerName];
35
+ const hiddenNodes = [];
36
+ const elementsToKeep = /* @__PURE__ */ new Set();
37
+ const elementsToStop = new Set(targets);
38
+ const keep = (el) => {
39
+ if (!el || elementsToKeep.has(el)) return;
40
+ elementsToKeep.add(el);
41
+ keep(el.parentNode);
42
+ };
43
+ targets.forEach((target) => {
44
+ keep(target);
45
+ if (followControlledElements && isHTMLElement(target)) findControlledElements(target, (controlledElement) => {
46
+ keep(controlledElement);
47
+ elementsToStop.add(controlledElement);
48
+ });
49
+ });
50
+ const deep = (parent) => {
51
+ if (!parent || elementsToStop.has(parent)) return;
52
+ Array.prototype.forEach.call(parent.children, (node) => {
53
+ if (elementsToKeep.has(node)) deep(node);
54
+ else try {
55
+ if (isIgnoredNode(node)) return;
56
+ const alreadyHidden = attribute === "aria-hidden" ? node.getAttribute(attribute) === "true" : node.hasAttribute(attribute);
57
+ const counterValue = (counterMap.get(node) || 0) + 1;
58
+ const markerValue = (markerCounter.get(node) || 0) + 1;
59
+ counterMap.set(node, counterValue);
60
+ markerCounter.set(node, markerValue);
61
+ hiddenNodes.push(node);
62
+ if (counterValue === 1 && alreadyHidden) uncontrolledNodes.set(node, true);
63
+ if (markerValue === 1) node.setAttribute(markerName, "");
64
+ if (!alreadyHidden) node.setAttribute(attribute, attributeValue);
65
+ } catch (e) {
66
+ console.error("[zag-js > ariaHidden] cannot operate on ", node, e);
67
+ }
68
+ });
69
+ };
70
+ deep(parentNode);
71
+ elementsToKeep.clear();
72
+ lockCount++;
73
+ return () => {
74
+ hiddenNodes.forEach((node) => {
75
+ const counterValue = counterMap.get(node) - 1;
76
+ const markerValue = markerCounter.get(node) - 1;
77
+ counterMap.set(node, counterValue);
78
+ markerCounter.set(node, markerValue);
79
+ if (!counterValue) {
80
+ if (!uncontrolledNodes.has(node)) node.removeAttribute(attribute);
81
+ uncontrolledNodes.delete(node);
82
+ }
83
+ if (!markerValue) node.removeAttribute(markerName);
84
+ });
85
+ lockCount--;
86
+ if (!lockCount) {
87
+ counterMap = /* @__PURE__ */ new WeakMap();
88
+ uncontrolledNodes = /* @__PURE__ */ new WeakMap();
89
+ markerMap = {};
90
+ }
91
+ };
106
92
  };
107
93
  function createLockStack() {
108
- const locks = [];
109
- return {
110
- add(lock) {
111
- locks[locks.length - 1]?.pause();
112
- locks.push(lock);
113
- lock.resume();
114
- },
115
- remove(lock) {
116
- const index = locks.indexOf(lock);
117
- if (index === -1) return;
118
- const isTop = index === locks.length - 1;
119
- locks.splice(index, 1);
120
- if (!isTop) return;
121
- lock.pause();
122
- locks[locks.length - 1]?.resume();
123
- }
124
- };
94
+ const locks = [];
95
+ return {
96
+ add(lock) {
97
+ locks[locks.length - 1]?.pause();
98
+ locks.push(lock);
99
+ lock.resume();
100
+ },
101
+ remove(lock) {
102
+ const index = locks.indexOf(lock);
103
+ if (index === -1) return;
104
+ const isTop = index === locks.length - 1;
105
+ locks.splice(index, 1);
106
+ if (!isTop) return;
107
+ lock.pause();
108
+ locks[locks.length - 1]?.resume();
109
+ }
110
+ };
125
111
  }
126
- var lockStacks = /* @__PURE__ */ new WeakMap();
127
- var getLockStack = (doc) => {
128
- let stack = lockStacks.get(doc);
129
- if (!stack) {
130
- stack = createLockStack();
131
- lockStacks.set(doc, stack);
132
- }
133
- return stack;
134
- };
135
- var walkTreeOutside = (originalTarget, props) => {
136
- const { parentNode, attribute, followControlledElements = true } = props;
137
- const targets = correctTargets(parentNode, Array.isArray(originalTarget) ? originalTarget : [originalTarget]);
138
- if (!targets.length) return () => {
139
- };
140
- const hiddenSelector = attribute === "aria-hidden" ? '[aria-hidden="true"]' : "[inert]";
141
- let undo;
142
- let observer;
143
- const apply = () => {
144
- const prevUndo = undo;
145
- undo = applyAttributeToOthers(targets, props);
146
- prevUndo?.();
147
- };
148
- const release = () => {
149
- undo?.();
150
- undo = void 0;
151
- };
152
- const lock = {
153
- pause() {
154
- observer?.disconnect();
155
- observer = void 0;
156
- release();
157
- },
158
- resume() {
159
- apply();
160
- if (!followControlledElements) return;
161
- const win = getWindow(parentNode);
162
- observer = new win.MutationObserver((records) => {
163
- if (records.some(({ target }) => isElement(target) && !target.closest(hiddenSelector))) apply();
164
- });
165
- observer.observe(parentNode, { attributes: true, attributeFilter: ["aria-expanded"], subtree: true });
166
- }
167
- };
168
- const lockStack = getLockStack(parentNode.ownerDocument);
169
- lockStack.add(lock);
170
- return () => lockStack.remove(lock);
112
+ const lockStacks = /* @__PURE__ */ new WeakMap();
113
+ const getLockStack = (doc) => {
114
+ let stack = lockStacks.get(doc);
115
+ if (!stack) {
116
+ stack = createLockStack();
117
+ lockStacks.set(doc, stack);
118
+ }
119
+ return stack;
171
120
  };
172
- export {
173
- walkTreeOutside
121
+ const walkTreeOutside = (originalTarget, props) => {
122
+ const { parentNode, attribute, followControlledElements = true } = props;
123
+ const targets = correctTargets(parentNode, Array.isArray(originalTarget) ? originalTarget : [originalTarget]);
124
+ if (!targets.length) return () => {};
125
+ const hiddenSelector = attribute === "aria-hidden" ? "[aria-hidden=\"true\"]" : "[inert]";
126
+ let undo;
127
+ let observer;
128
+ const apply = () => {
129
+ const prevUndo = undo;
130
+ undo = applyAttributeToOthers(targets, props);
131
+ prevUndo?.();
132
+ };
133
+ const release = () => {
134
+ undo?.();
135
+ undo = void 0;
136
+ };
137
+ const lock = {
138
+ pause() {
139
+ observer?.disconnect();
140
+ observer = void 0;
141
+ release();
142
+ },
143
+ resume() {
144
+ apply();
145
+ if (!followControlledElements) return;
146
+ observer = new (getWindow(parentNode)).MutationObserver((records) => {
147
+ if (records.some(({ target }) => isElement(target) && !target.closest(hiddenSelector))) apply();
148
+ });
149
+ observer.observe(parentNode, {
150
+ attributes: true,
151
+ attributeFilter: ["aria-expanded"],
152
+ subtree: true
153
+ });
154
+ }
155
+ };
156
+ const lockStack = getLockStack(parentNode.ownerDocument);
157
+ lockStack.add(lock);
158
+ return () => lockStack.remove(lock);
174
159
  };
160
+ export { walkTreeOutside };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/aria-hidden",
3
- "version": "1.47.0",
3
+ "version": "1.48.0",
4
4
  "description": "Hide targets from screen readers",
5
5
  "keywords": [
6
6
  "js",
@@ -27,7 +27,7 @@
27
27
  "clean-package": "../../../clean-package.config.json",
28
28
  "main": "dist/index.js",
29
29
  "dependencies": {
30
- "@zag-js/dom-query": "1.47.0"
30
+ "@zag-js/dom-query": "1.48.0"
31
31
  },
32
32
  "devDependencies": {
33
33
  "clean-package": "2.2.0"
@@ -48,9 +48,9 @@
48
48
  "./package.json": "./package.json"
49
49
  },
50
50
  "scripts": {
51
- "build": "tsup",
51
+ "build": "tsdown",
52
52
  "test": "vitest",
53
- "lint": "eslint src",
53
+ "lint": "oxlint src",
54
54
  "test-ci": "pnpm test --ci --runInBand -u",
55
55
  "test-watch": "pnpm test --watchAll"
56
56
  }