@zag-js/dismissable 2.0.0-next.3 → 2.0.0-next.4

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,212 +1,222 @@
1
- // src/layer-stack.ts
2
1
  import { contains, nextTick } from "@zag-js/dom-query";
3
2
  import { isEqual } from "@zag-js/utils";
4
- var LAYER_REQUEST_DISMISS_EVENT = "layer:request-dismiss";
5
- var layerId = 0;
3
+ // src/layer-stack.ts
4
+ const LAYER_REQUEST_DISMISS_EVENT = "layer:request-dismiss";
5
+ let layerId = 0;
6
+ let cancelClosingAncestors;
7
+ /** Resolved on read, so a layer's blocking can change without re-registering it. */
6
8
  function isPointerBlocking(layer) {
7
- const value = layer.pointerBlocking;
8
- return typeof value === "function" ? value() : !!value;
9
+ const value = layer.pointerBlocking;
10
+ return typeof value === "function" ? value() : !!value;
11
+ }
12
+ function indexById(layers) {
13
+ const byId = /* @__PURE__ */ new Map();
14
+ for (const layer of layers) if (layer.id && !byId.has(layer.id)) byId.set(layer.id, layer);
15
+ return byId;
9
16
  }
10
- var layerStack = {
11
- layers: [],
12
- branches: [],
13
- recentlyRemoved: /* @__PURE__ */ new Set(),
14
- pendingReattach: /* @__PURE__ */ new Map(),
15
- count() {
16
- return this.layers.length;
17
- },
18
- pointerBlockingLayers() {
19
- return this.layers.filter(isPointerBlocking);
20
- },
21
- topMostPointerBlockingLayer() {
22
- return [...this.pointerBlockingLayers()].slice(-1)[0];
23
- },
24
- hasPointerBlockingLayer() {
25
- return this.pointerBlockingLayers().length > 0;
26
- },
27
- isBelowPointerBlockingLayer(node) {
28
- const index = this.indexOf(node);
29
- const highestBlockingIndex = this.topMostPointerBlockingLayer() ? this.indexOf(this.topMostPointerBlockingLayer()?.node) : -1;
30
- return index < highestBlockingIndex;
31
- },
32
- isTopMost(node) {
33
- const layer = this.layers[this.count() - 1];
34
- return layer?.node === node;
35
- },
36
- layerFor(node) {
37
- return this.layers.find((layer) => layer.node === node);
38
- },
39
- /** The most recently added layer in the same group, if any. */
40
- peerFor(group) {
41
- for (let i = this.count() - 1; i >= 0; i--) {
42
- if (this.layers[i].group === group) return this.layers[i];
43
- }
44
- return void 0;
45
- },
46
- isDescendantOf(layer, ancestorId) {
47
- if (!ancestorId) return false;
48
- const seen = /* @__PURE__ */ new Set();
49
- let parentId = layer.parentId;
50
- while (parentId && !seen.has(parentId)) {
51
- if (parentId === ancestorId) return true;
52
- seen.add(parentId);
53
- parentId = this.layers.find((l) => l.id === parentId)?.parentId;
54
- }
55
- return false;
56
- },
57
- depthOf(layer) {
58
- const seen = /* @__PURE__ */ new Set();
59
- let depth = 0;
60
- let parentId = layer.parentId;
61
- while (parentId && !seen.has(parentId)) {
62
- depth++;
63
- seen.add(parentId);
64
- parentId = this.layers.find((l) => l.id === parentId)?.parentId;
65
- }
66
- return depth;
67
- },
68
- /** Descendants, shallowest first, so a cascade dismisses parents before their own children. */
69
- getNestedLayers(node) {
70
- const id = this.layerFor(node)?.id;
71
- if (!id) return [];
72
- return this.layers.filter((layer) => this.isDescendantOf(layer, id)).sort((a, b) => this.depthOf(a) - this.depthOf(b));
73
- },
74
- getLayersByType(type) {
75
- return this.layers.filter((layer) => layer.type === type);
76
- },
77
- getNestedLayersByType(node, type) {
78
- return this.getNestedLayers(node).filter((layer) => layer.type === type);
79
- },
80
- getParentLayerOfType(node, type) {
81
- const seen = /* @__PURE__ */ new Set();
82
- let parentId = this.layerFor(node)?.parentId;
83
- while (parentId && !seen.has(parentId)) {
84
- const parent = this.layers.find((l) => l.id === parentId);
85
- if (!parent) return void 0;
86
- if (parent.type === type) return parent;
87
- seen.add(parentId);
88
- parentId = parent.parentId;
89
- }
90
- return void 0;
91
- },
92
- countNestedLayersOfType(node, type) {
93
- return this.getNestedLayersByType(node, type).length;
94
- },
95
- isInNestedLayer(node, target) {
96
- const inNested = this.getNestedLayers(node).some((layer) => contains(layer.node, target));
97
- if (inNested) return true;
98
- if (this.recentlyRemoved.size > 0) return true;
99
- return false;
100
- },
101
- isInBranch(target) {
102
- return Array.from(this.branches).some((branch) => contains(branch, target));
103
- },
104
- add(layer) {
105
- const existingIndex = this.indexOf(layer.node);
106
- const existing = existingIndex !== -1 ? this.layers[existingIndex] : void 0;
107
- const pending = this.pendingReattach.get(layer.node);
108
- if (existing) {
109
- layer.id ?? (layer.id = existing.id);
110
- layer.parentId = existing.parentId;
111
- } else if (pending) {
112
- layer.id ?? (layer.id = pending.id);
113
- layer.parentId = pending.parentId;
114
- } else {
115
- layer.id ?? (layer.id = `layer-${++layerId}`);
116
- const peer = layer.group ? this.peerFor(layer.group) : void 0;
117
- layer.parentId = peer ? peer.parentId : layer.parentId ?? this.layers[this.count() - 1]?.id;
118
- }
119
- if (existingIndex !== -1) {
120
- this.layers.splice(existingIndex, 1);
121
- }
122
- if (pending) {
123
- this.pendingReattach.delete(layer.node);
124
- this.layers.splice(Math.min(pending.index, this.count()), 0, layer);
125
- } else {
126
- this.layers.push(layer);
127
- }
128
- this.syncLayers();
129
- },
130
- addBranch(node) {
131
- this.branches.push(node);
132
- },
133
- remove(node, options) {
134
- const index = this.indexOf(node);
135
- if (index < 0) return;
136
- const layer = this.layers[index];
137
- if (options?.reattach) {
138
- this.pendingReattach.set(node, { id: layer.id, parentId: layer.parentId, index });
139
- } else {
140
- this.recentlyRemoved.add(node);
141
- nextTick(() => this.recentlyRemoved.delete(node));
142
- this.getNestedLayers(node).forEach((nested) => layerStack.dismiss(nested.node, node));
143
- }
144
- this.layers.splice(index, 1);
145
- if (layer.snapshot) {
146
- publishSnapshot(layer, { ...layer.snapshot, active: false, blocked: false });
147
- }
148
- this.syncLayers();
149
- },
150
- removeBranch(node) {
151
- const index = this.branches.indexOf(node);
152
- if (index >= 0) this.branches.splice(index, 1);
153
- },
154
- syncLayers() {
155
- this.layers.forEach((layer, index) => {
156
- const parentOfSameType = layerStack.getParentLayerOfType(layer.node, layer.type);
157
- const nestedCount = layerStack.countNestedLayersOfType(layer.node, layer.type);
158
- const snapshot = {
159
- active: true,
160
- type: layer.type,
161
- index,
162
- nested: parentOfSameType != null,
163
- hasNested: nestedCount > 0,
164
- nestedCount,
165
- blocked: layerStack.isBelowPointerBlockingLayer(layer.node)
166
- };
167
- if (!isEqual(layer.snapshot, snapshot)) {
168
- publishSnapshot(layer, snapshot);
169
- }
170
- });
171
- },
172
- indexOf(node) {
173
- return this.layers.findIndex((layer) => layer.node === node);
174
- },
175
- dismiss(node, parent) {
176
- const index = this.indexOf(node);
177
- if (index === -1) return;
178
- const layer = this.layers[index];
179
- addListenerOnce(node, LAYER_REQUEST_DISMISS_EVENT, (event) => {
180
- layer.requestDismiss?.(event);
181
- if (!event.defaultPrevented) {
182
- layer?.dismiss();
183
- }
184
- });
185
- fireCustomEvent(node, LAYER_REQUEST_DISMISS_EVENT, {
186
- originalLayer: node,
187
- targetLayer: parent,
188
- originalIndex: index,
189
- targetIndex: parent ? this.indexOf(parent) : -1
190
- });
191
- this.syncLayers();
192
- },
193
- clear() {
194
- this.remove(this.layers[0].node);
195
- }
17
+ /** Ancestor ids, nearest first. Stops at a cycle. */
18
+ function* ancestorIds(layer, byId) {
19
+ const seen = /* @__PURE__ */ new Set();
20
+ let parentId = layer.parentId;
21
+ while (parentId && !seen.has(parentId)) {
22
+ seen.add(parentId);
23
+ yield parentId;
24
+ parentId = byId.get(parentId)?.parentId;
25
+ }
26
+ }
27
+ const layerStack = {
28
+ layers: [],
29
+ branches: [],
30
+ /** Ids of layers whose descendant just closed. */
31
+ closingAncestors: /* @__PURE__ */ new Set(),
32
+ /** Descendants queued to close with their ancestor. A new layer can't nest in them. */
33
+ dismissing: /* @__PURE__ */ new WeakSet(),
34
+ pendingReattach: /* @__PURE__ */ new Map(),
35
+ count() {
36
+ return this.layers.length;
37
+ },
38
+ topMostPointerBlockingIndex() {
39
+ for (let i = this.count() - 1; i >= 0; i--) if (isPointerBlocking(this.layers[i])) return i;
40
+ return -1;
41
+ },
42
+ topMostPointerBlockingLayer() {
43
+ return this.layers[this.topMostPointerBlockingIndex()];
44
+ },
45
+ hasPointerBlockingLayer() {
46
+ return this.topMostPointerBlockingIndex() !== -1;
47
+ },
48
+ isBelowPointerBlockingLayer(node) {
49
+ return this.indexOf(node) < this.topMostPointerBlockingIndex();
50
+ },
51
+ isTopMost(node) {
52
+ return this.layers[this.count() - 1]?.node === node;
53
+ },
54
+ layerFor(node) {
55
+ return this.layers.find((layer) => layer.node === node);
56
+ },
57
+ parentFor(layer) {
58
+ const origins = layer.origins?.filter(Boolean);
59
+ for (let i = this.count() - 1; i >= 0; i--) {
60
+ const candidate = this.layers[i];
61
+ if (this.dismissing.has(candidate.node)) continue;
62
+ if (!origins || origins.some((origin) => contains(candidate.node, origin))) return candidate;
63
+ }
64
+ },
65
+ /** Top-level layers that opened from inside the new layer become its children. */
66
+ adopt(layer) {
67
+ if (!layer.origins) return [];
68
+ const adopted = this.layers.filter((other) => !other.parentId && other.origins?.some((origin) => origin && origin !== layer.node && contains(layer.node, origin)));
69
+ adopted.forEach((child) => child.parentId = layer.id);
70
+ return adopted;
71
+ },
72
+ /** The most recently added layer in the same group, if any. */
73
+ peerFor(group) {
74
+ for (let i = this.count() - 1; i >= 0; i--) if (this.layers[i].group === group) return this.layers[i];
75
+ },
76
+ /** Descendants, shallowest first, so a cascade dismisses parents before their own children. */
77
+ getNestedLayers(node) {
78
+ const id = this.layerFor(node)?.id;
79
+ if (!id) return [];
80
+ const byId = indexById(this.layers);
81
+ const depth = /* @__PURE__ */ new Map();
82
+ for (const layer of this.layers) {
83
+ let level = 0;
84
+ for (const ancestorId of ancestorIds(layer, byId)) {
85
+ level++;
86
+ if (ancestorId !== id) continue;
87
+ depth.set(layer, level);
88
+ break;
89
+ }
90
+ }
91
+ return [...depth.keys()].sort((a, b) => depth.get(a) - depth.get(b));
92
+ },
93
+ isInNestedLayer(node, target) {
94
+ return this.getNestedLayers(node).some((layer) => contains(layer.node, target));
95
+ },
96
+ /** Focus leaving a closing descendant shouldn't dismiss its ancestors. */
97
+ isClosingAncestor(node) {
98
+ const id = this.layerFor(node)?.id;
99
+ return !!id && this.closingAncestors.has(id);
100
+ },
101
+ isInBranch(target) {
102
+ return Array.from(this.branches).some((branch) => contains(branch, target));
103
+ },
104
+ add(layer) {
105
+ const existingIndex = this.indexOf(layer.node);
106
+ const existing = existingIndex !== -1 ? this.layers[existingIndex] : void 0;
107
+ const pending = this.pendingReattach.get(layer.node);
108
+ if (existing) {
109
+ layer.id ?? (layer.id = existing.id);
110
+ layer.parentId = existing.parentId;
111
+ } else if (pending) {
112
+ layer.id ?? (layer.id = pending.id);
113
+ layer.parentId = pending.parentId;
114
+ } else {
115
+ layer.id ?? (layer.id = `layer-${++layerId}`);
116
+ const peer = layer.group ? this.peerFor(layer.group) : void 0;
117
+ layer.parentId = peer ? peer.parentId : layer.parentId ?? this.parentFor(layer)?.id;
118
+ }
119
+ const adopted = existing || pending ? [] : this.adopt(layer);
120
+ if (existing) this.layers[existingIndex] = layer;
121
+ else if (pending) {
122
+ this.pendingReattach.delete(layer.node);
123
+ this.layers.splice(Math.min(pending.index, this.count()), 0, layer);
124
+ } else if (adopted.length) this.layers.splice(this.indexOf(adopted[0].node), 0, layer);
125
+ else this.layers.push(layer);
126
+ this.syncLayers();
127
+ },
128
+ addBranch(node) {
129
+ this.branches.push(node);
130
+ },
131
+ remove(node, options) {
132
+ const index = this.indexOf(node);
133
+ if (index < 0) return;
134
+ const layer = this.layers[index];
135
+ if (options?.reattach) this.pendingReattach.set(node, {
136
+ id: layer.id,
137
+ parentId: layer.parentId,
138
+ index
139
+ });
140
+ else {
141
+ for (const id of ancestorIds(layer, indexById(this.layers))) this.closingAncestors.add(id);
142
+ cancelClosingAncestors?.();
143
+ cancelClosingAncestors = nextTick(() => {
144
+ cancelClosingAncestors = void 0;
145
+ this.closingAncestors.clear();
146
+ });
147
+ this.dismissing.delete(node);
148
+ const nested = this.getNestedLayers(node);
149
+ nested.forEach((layer) => this.dismissing.add(layer.node));
150
+ if (nested.length) queueMicrotask(() => nested.forEach((layer) => this.dismiss(layer.node, node)));
151
+ for (const child of this.layers) if (child.parentId === layer.id) child.parentId = layer.parentId;
152
+ }
153
+ this.layers.splice(index, 1);
154
+ if (layer.snapshot) publishSnapshot(layer, {
155
+ ...layer.snapshot,
156
+ active: false,
157
+ blocked: false
158
+ });
159
+ this.syncLayers();
160
+ },
161
+ removeBranch(node) {
162
+ const index = this.branches.indexOf(node);
163
+ if (index >= 0) this.branches.splice(index, 1);
164
+ },
165
+ syncLayers() {
166
+ const byId = indexById(this.layers);
167
+ const nestedCounts = /* @__PURE__ */ new Map();
168
+ const nestedInSameType = /* @__PURE__ */ new Set();
169
+ for (const layer of this.layers) for (const parentId of ancestorIds(layer, byId)) {
170
+ const parent = byId.get(parentId);
171
+ if (!parent) break;
172
+ if (parent.type !== layer.type) continue;
173
+ nestedCounts.set(parentId, (nestedCounts.get(parentId) ?? 0) + 1);
174
+ nestedInSameType.add(layer);
175
+ }
176
+ const highestBlockingIndex = this.topMostPointerBlockingIndex();
177
+ this.layers.forEach((layer, index) => {
178
+ const nestedCount = nestedCounts.get(layer.id) ?? 0;
179
+ const snapshot = {
180
+ active: true,
181
+ type: layer.type,
182
+ index,
183
+ nested: nestedInSameType.has(layer),
184
+ hasNested: nestedCount > 0,
185
+ nestedCount,
186
+ blocked: index < highestBlockingIndex
187
+ };
188
+ if (!isEqual(layer.snapshot, snapshot)) publishSnapshot(layer, snapshot);
189
+ });
190
+ },
191
+ indexOf(node) {
192
+ return this.layers.findIndex((layer) => layer.node === node);
193
+ },
194
+ dismiss(node, parent) {
195
+ const index = this.indexOf(node);
196
+ if (index === -1) return;
197
+ const layer = this.layers[index];
198
+ const event = fireCustomEvent(node, LAYER_REQUEST_DISMISS_EVENT, {
199
+ originalLayer: node,
200
+ targetLayer: parent,
201
+ originalIndex: index,
202
+ targetIndex: parent ? this.indexOf(parent) : -1
203
+ });
204
+ layer.requestDismiss?.(event);
205
+ if (event.defaultPrevented) this.dismissing.delete(node);
206
+ else layer.dismiss();
207
+ }
196
208
  };
197
209
  function publishSnapshot(layer, snapshot) {
198
- layer.snapshot = snapshot;
199
- layer.onLayerChange?.(snapshot);
210
+ layer.snapshot = snapshot;
211
+ layer.onLayerChange?.(snapshot);
200
212
  }
201
213
  function fireCustomEvent(el, type, detail) {
202
- const win = el.ownerDocument.defaultView || window;
203
- const event = new win.CustomEvent(type, { cancelable: true, bubbles: true, detail });
204
- return el.dispatchEvent(event);
205
- }
206
- function addListenerOnce(el, type, callback) {
207
- el.addEventListener(type, callback, { once: true });
214
+ const event = new (el.ownerDocument.defaultView || window).CustomEvent(type, {
215
+ cancelable: true,
216
+ bubbles: true,
217
+ detail
218
+ });
219
+ el.dispatchEvent(event);
220
+ return event;
208
221
  }
209
- export {
210
- isPointerBlocking,
211
- layerStack
212
- };
222
+ export { isPointerBlocking, layerStack };
@@ -2,7 +2,5 @@
2
2
  * Re-derives pointer blocking from the stack. Needed after a layer's `pointerBlocking` getter
3
3
  * changes value, since nothing was added or removed to trigger the usual sync.
4
4
  */
5
- declare function syncPointerEvents(node: HTMLElement): void;
6
- declare function disablePointerEventsOutside(node: HTMLElement, persistentElements?: Array<() => Element | null>): () => void;
7
-
8
- export { disablePointerEventsOutside, syncPointerEvents };
5
+ export declare function syncPointerEvents(node: HTMLElement): void;
6
+ export declare function disablePointerEventsOutside(node: HTMLElement, persistentElements?: Array<() => Element | null>): () => void;
@@ -2,7 +2,5 @@
2
2
  * Re-derives pointer blocking from the stack. Needed after a layer's `pointerBlocking` getter
3
3
  * changes value, since nothing was added or removed to trigger the usual sync.
4
4
  */
5
- declare function syncPointerEvents(node: HTMLElement): void;
6
- declare function disablePointerEventsOutside(node: HTMLElement, persistentElements?: Array<() => Element | null>): () => void;
7
-
8
- export { disablePointerEventsOutside, syncPointerEvents };
5
+ export declare function syncPointerEvents(node: HTMLElement): void;
6
+ export declare function disablePointerEventsOutside(node: HTMLElement, persistentElements?: Array<() => Element | null>): () => void;
@@ -1,82 +1,60 @@
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/pointer-event-outside.ts
21
- var pointer_event_outside_exports = {};
22
- __export(pointer_event_outside_exports, {
23
- disablePointerEventsOutside: () => disablePointerEventsOutside,
24
- syncPointerEvents: () => syncPointerEvents
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
25
4
  });
26
- module.exports = __toCommonJS(pointer_event_outside_exports);
27
- var import_dom_query = require("@zag-js/dom-query");
28
- var import_layer_stack = require("./layer-stack.js");
29
- var originalBodyPointerEvents = /* @__PURE__ */ new WeakMap();
5
+ const require_layer_stack = require("./layer-stack.js");
6
+ let _zag_js_dom_query = require("@zag-js/dom-query");
7
+ // src/pointer-event-outside.ts
8
+ const originalBodyPointerEvents = /* @__PURE__ */ new WeakMap();
9
+ const scheduled = /* @__PURE__ */ new WeakSet();
10
+ /** Applies or restores body blocking from the current stack state, once per microtask. */
30
11
  function syncBodyPointerEvents(doc) {
31
- const body = doc.body;
32
- if (!body) return;
33
- const shouldBlock = import_layer_stack.layerStack.hasPointerBlockingLayer();
34
- if (shouldBlock === body.hasAttribute("data-inert")) return;
35
- if (shouldBlock) {
36
- originalBodyPointerEvents.set(body, body.style.pointerEvents);
37
- queueMicrotask(() => {
38
- if (!import_layer_stack.layerStack.hasPointerBlockingLayer()) return;
39
- body.style.pointerEvents = "none";
40
- body.setAttribute("data-inert", "");
41
- });
42
- return;
43
- }
44
- queueMicrotask(() => {
45
- if (import_layer_stack.layerStack.hasPointerBlockingLayer()) return;
46
- const original = originalBodyPointerEvents.get(body);
47
- if (original !== void 0) {
48
- body.style.pointerEvents = original;
49
- originalBodyPointerEvents.delete(body);
50
- }
51
- body.removeAttribute("data-inert");
52
- if (body.style.length === 0) body.removeAttribute("style");
53
- });
12
+ if (scheduled.has(doc)) return;
13
+ scheduled.add(doc);
14
+ queueMicrotask(() => {
15
+ scheduled.delete(doc);
16
+ const body = doc.body;
17
+ if (!body) return;
18
+ const shouldBlock = require_layer_stack.layerStack.hasPointerBlockingLayer();
19
+ if (shouldBlock === body.hasAttribute("data-inert")) return;
20
+ if (shouldBlock) {
21
+ originalBodyPointerEvents.set(body, body.style.pointerEvents);
22
+ body.style.pointerEvents = "none";
23
+ body.setAttribute("data-inert", "");
24
+ return;
25
+ }
26
+ const original = originalBodyPointerEvents.get(body);
27
+ if (original !== void 0) {
28
+ body.style.pointerEvents = original;
29
+ originalBodyPointerEvents.delete(body);
30
+ }
31
+ body.removeAttribute("data-inert");
32
+ if (body.style.length === 0) body.removeAttribute("style");
33
+ });
54
34
  }
35
+ /**
36
+ * Re-derives pointer blocking from the stack. Needed after a layer's `pointerBlocking` getter
37
+ * changes value, since nothing was added or removed to trigger the usual sync.
38
+ */
55
39
  function syncPointerEvents(node) {
56
- syncBodyPointerEvents((0, import_dom_query.getDocument)(node));
40
+ syncBodyPointerEvents((0, _zag_js_dom_query.getDocument)(node));
57
41
  }
58
42
  function disablePointerEventsOutside(node, persistentElements) {
59
- const doc = (0, import_dom_query.getDocument)(node);
60
- const cleanups = [];
61
- syncBodyPointerEvents(doc);
62
- persistentElements?.forEach((el) => {
63
- const [promise, abort] = (0, import_dom_query.waitForElement)(
64
- () => {
65
- const node2 = el();
66
- return (0, import_dom_query.isHTMLElement)(node2) ? node2 : null;
67
- },
68
- { timeout: 1e3 }
69
- );
70
- promise.then((el2) => cleanups.push((0, import_dom_query.setStyle)(el2, { pointerEvents: "auto" })));
71
- cleanups.push(abort);
72
- });
73
- return () => {
74
- syncBodyPointerEvents(doc);
75
- cleanups.forEach((fn) => fn());
76
- };
43
+ const doc = (0, _zag_js_dom_query.getDocument)(node);
44
+ const cleanups = [];
45
+ syncBodyPointerEvents(doc);
46
+ persistentElements?.forEach((el) => {
47
+ const [promise, abort] = (0, _zag_js_dom_query.waitForElement)(() => {
48
+ const node = el();
49
+ return (0, _zag_js_dom_query.isHTMLElement)(node) ? node : null;
50
+ }, { timeout: 1e3 });
51
+ promise.then((el) => cleanups.push((0, _zag_js_dom_query.setStyle)(el, { pointerEvents: "auto" })));
52
+ cleanups.push(abort);
53
+ });
54
+ return () => {
55
+ syncBodyPointerEvents(doc);
56
+ cleanups.forEach((fn) => fn());
57
+ };
77
58
  }
78
- // Annotate the CommonJS export names for ESM import in node:
79
- 0 && (module.exports = {
80
- disablePointerEventsOutside,
81
- syncPointerEvents
82
- });
59
+ exports.disablePointerEventsOutside = disablePointerEventsOutside;
60
+ exports.syncPointerEvents = syncPointerEvents;