@zag-js/popover 0.2.5 → 0.2.6

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.
@@ -0,0 +1,23 @@
1
+ import { PropTypes, NormalizeProps } from '@zag-js/types';
2
+ import { State, Send } from './popover.types.js';
3
+ import '@zag-js/core';
4
+ import '@zag-js/dismissable';
5
+ import '@zag-js/popper';
6
+
7
+ declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): {
8
+ portalled: boolean;
9
+ isOpen: boolean;
10
+ open(): void;
11
+ close(): void;
12
+ arrowProps: T["element"];
13
+ arrowTipProps: T["element"];
14
+ anchorProps: T["element"];
15
+ triggerProps: T["button"];
16
+ positionerProps: T["element"];
17
+ contentProps: T["element"];
18
+ titleProps: T["element"];
19
+ descriptionProps: T["element"];
20
+ closeTriggerProps: T["button"];
21
+ };
22
+
23
+ export { connect };
@@ -0,0 +1,317 @@
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/popover.connect.ts
21
+ var popover_connect_exports = {};
22
+ __export(popover_connect_exports, {
23
+ connect: () => connect
24
+ });
25
+ module.exports = __toCommonJS(popover_connect_exports);
26
+
27
+ // ../../utilities/dom/src/attrs.ts
28
+ var dataAttr = (guard) => {
29
+ return guard ? "" : void 0;
30
+ };
31
+
32
+ // ../../utilities/core/src/functions.ts
33
+ var runIfFn = (v, ...a) => {
34
+ const res = typeof v === "function" ? v(...a) : v;
35
+ return res != null ? res : void 0;
36
+ };
37
+
38
+ // ../../utilities/dom/src/query.ts
39
+ function isDocument(el) {
40
+ return el.nodeType === Node.DOCUMENT_NODE;
41
+ }
42
+ function isWindow(value) {
43
+ return (value == null ? void 0 : value.toString()) === "[object Window]";
44
+ }
45
+ function isFrame(element) {
46
+ return element.localName === "iframe";
47
+ }
48
+ function getDocument(el) {
49
+ var _a;
50
+ if (isWindow(el))
51
+ return el.document;
52
+ if (isDocument(el))
53
+ return el;
54
+ return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
55
+ }
56
+ function defineDomHelpers(helpers) {
57
+ const dom2 = {
58
+ getRootNode: (ctx) => {
59
+ var _a, _b;
60
+ return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
61
+ },
62
+ getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
63
+ getWin: (ctx) => {
64
+ var _a;
65
+ return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
66
+ },
67
+ getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
68
+ getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id),
69
+ createEmitter: (ctx, target) => {
70
+ const win = dom2.getWin(ctx);
71
+ return function emit(evt, detail, options) {
72
+ const { bubbles = true, cancelable, composed = true } = options != null ? options : {};
73
+ const eventName = `zag:${evt}`;
74
+ const init = { bubbles, cancelable, composed, detail };
75
+ const event = new win.CustomEvent(eventName, init);
76
+ target.dispatchEvent(event);
77
+ };
78
+ },
79
+ createListener: (target) => {
80
+ return function listen(evt, handler) {
81
+ const eventName = `zag:${evt}`;
82
+ const listener = (e) => handler(e);
83
+ target.addEventListener(eventName, listener);
84
+ return () => target.removeEventListener(eventName, listener);
85
+ };
86
+ }
87
+ };
88
+ return {
89
+ ...dom2,
90
+ ...helpers
91
+ };
92
+ }
93
+ function isHTMLElement(v) {
94
+ return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string";
95
+ }
96
+ function isVisible(el) {
97
+ if (!isHTMLElement(el))
98
+ return false;
99
+ return el.offsetWidth > 0 || el.offsetHeight > 0 || el.getClientRects().length > 0;
100
+ }
101
+
102
+ // ../../utilities/dom/src/focusable.ts
103
+ function hasNegativeTabIndex(element) {
104
+ const tabIndex = parseInt(element.getAttribute("tabindex") || "0", 10);
105
+ return tabIndex < 0;
106
+ }
107
+ var focusableSelector = "input:not([type='hidden']):not([disabled]), select:not([disabled]), textarea:not([disabled]), a[href], button:not([disabled]), [tabindex], iframe, object, embed, area[href], audio[controls], video[controls], [contenteditable]:not([contenteditable='false']), details > summary:first-of-type";
108
+ var getFocusables = (container, includeContainer = false) => {
109
+ if (!container)
110
+ return [];
111
+ const elements = Array.from(container.querySelectorAll(focusableSelector));
112
+ const include = includeContainer == true || includeContainer == "if-empty" && elements.length === 0;
113
+ if (include && isHTMLElement(container) && isFocusable(container)) {
114
+ elements.unshift(container);
115
+ }
116
+ const focusableElements = elements.filter(isFocusable);
117
+ focusableElements.forEach((element, i) => {
118
+ if (isFrame(element) && element.contentDocument) {
119
+ const frameBody = element.contentDocument.body;
120
+ focusableElements.splice(i, 1, ...getFocusables(frameBody));
121
+ }
122
+ });
123
+ return focusableElements;
124
+ };
125
+ function isFocusable(element) {
126
+ if (!element)
127
+ return false;
128
+ return element.matches(focusableSelector) && isVisible(element);
129
+ }
130
+ function getTabbables(container, includeContainer) {
131
+ if (!container)
132
+ return [];
133
+ const elements = Array.from(container.querySelectorAll(focusableSelector));
134
+ const tabbableElements = elements.filter(isTabbable);
135
+ if (includeContainer && isTabbable(container)) {
136
+ tabbableElements.unshift(container);
137
+ }
138
+ tabbableElements.forEach((element, i) => {
139
+ if (isFrame(element) && element.contentDocument) {
140
+ const frameBody = element.contentDocument.body;
141
+ const allFrameTabbable = getTabbables(frameBody);
142
+ tabbableElements.splice(i, 1, ...allFrameTabbable);
143
+ }
144
+ });
145
+ if (!tabbableElements.length && includeContainer) {
146
+ return elements;
147
+ }
148
+ return tabbableElements;
149
+ }
150
+ function isTabbable(el) {
151
+ return isFocusable(el) && !hasNegativeTabIndex(el);
152
+ }
153
+ function getFirstTabbable(container, includeContainer) {
154
+ const [first] = getTabbables(container, includeContainer);
155
+ return first || null;
156
+ }
157
+ function getLastTabbable(container, includeContainer) {
158
+ const elements = getTabbables(container, includeContainer);
159
+ return elements[elements.length - 1] || null;
160
+ }
161
+
162
+ // src/popover.connect.ts
163
+ var import_popper = require("@zag-js/popper");
164
+
165
+ // src/popover.dom.ts
166
+ var dom = defineDomHelpers({
167
+ getActiveEl: (ctx) => dom.getDoc(ctx).activeElement,
168
+ getAnchorId: (ctx) => {
169
+ var _a, _b;
170
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.anchor) != null ? _b : `popover:${ctx.id}:anchor`;
171
+ },
172
+ getTriggerId: (ctx) => {
173
+ var _a, _b;
174
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.trigger) != null ? _b : `popover:${ctx.id}:trigger`;
175
+ },
176
+ getContentId: (ctx) => {
177
+ var _a, _b;
178
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.content) != null ? _b : `popover:${ctx.id}:content`;
179
+ },
180
+ getPositionerId: (ctx) => `popover:${ctx.id}:popper`,
181
+ getArrowId: (ctx) => `popover:${ctx.id}:arrow`,
182
+ getTitleId: (ctx) => {
183
+ var _a, _b;
184
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.title) != null ? _b : `popover:${ctx.id}:title`;
185
+ },
186
+ getDescriptionId: (ctx) => {
187
+ var _a, _b;
188
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.description) != null ? _b : `popover:${ctx.id}:desc`;
189
+ },
190
+ getCloseTriggerId: (ctx) => {
191
+ var _a, _b;
192
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.closeTrigger) != null ? _b : `popover:${ctx.id}:close`;
193
+ },
194
+ getAnchorEl: (ctx) => dom.getById(ctx, dom.getAnchorId(ctx)),
195
+ getTriggerEl: (ctx) => dom.getById(ctx, dom.getTriggerId(ctx)),
196
+ getContentEl: (ctx) => dom.getById(ctx, dom.getContentId(ctx)),
197
+ getPositionerEl: (ctx) => dom.getById(ctx, dom.getPositionerId(ctx)),
198
+ getTitleEl: (ctx) => dom.getById(ctx, dom.getTitleId(ctx)),
199
+ getDescriptionEl: (ctx) => dom.getById(ctx, dom.getDescriptionId(ctx)),
200
+ getFocusableEls: (ctx) => getFocusables(dom.getContentEl(ctx)),
201
+ getFirstFocusableEl: (ctx) => dom.getFocusableEls(ctx)[0],
202
+ getDocTabbableEls: (ctx) => getTabbables(dom.getDoc(ctx).body),
203
+ getTabbableEls: (ctx) => getTabbables(dom.getContentEl(ctx), "if-empty"),
204
+ getFirstTabbableEl: (ctx) => getFirstTabbable(dom.getContentEl(ctx), "if-empty"),
205
+ getLastTabbableEl: (ctx) => getLastTabbable(dom.getContentEl(ctx), "if-empty"),
206
+ getInitialFocusEl: (ctx) => {
207
+ let el = runIfFn(ctx.initialFocusEl);
208
+ if (!el && ctx.autoFocus)
209
+ el = dom.getFirstFocusableEl(ctx);
210
+ if (!el)
211
+ el = dom.getContentEl(ctx);
212
+ return el;
213
+ }
214
+ });
215
+
216
+ // src/popover.anatomy.ts
217
+ var import_anatomy = require("@zag-js/anatomy");
218
+ var anatomy = (0, import_anatomy.createAnatomy)("popover").parts(
219
+ "arrow",
220
+ "arrowTip",
221
+ "anchor",
222
+ "trigger",
223
+ "positioner",
224
+ "content",
225
+ "title",
226
+ "description",
227
+ "closeTrigger"
228
+ );
229
+ var parts = anatomy.build();
230
+
231
+ // src/popover.connect.ts
232
+ function connect(state, send, normalize) {
233
+ const isOpen = state.matches("open");
234
+ const currentPlacement = state.context.currentPlacement;
235
+ const portalled = state.context.currentPortalled;
236
+ const rendered = state.context.renderedElements;
237
+ const popperStyles = (0, import_popper.getPlacementStyles)({
238
+ measured: !!state.context.isPlacementComplete,
239
+ placement: currentPlacement
240
+ });
241
+ return {
242
+ portalled,
243
+ isOpen,
244
+ open() {
245
+ send("OPEN");
246
+ },
247
+ close() {
248
+ send("CLOSE");
249
+ },
250
+ arrowProps: normalize.element({
251
+ id: dom.getArrowId(state.context),
252
+ ...parts.arrow.attrs,
253
+ style: popperStyles.arrow
254
+ }),
255
+ arrowTipProps: normalize.element({
256
+ ...parts.arrowTip.attrs,
257
+ style: popperStyles.arrowTip
258
+ }),
259
+ anchorProps: normalize.element({
260
+ ...parts.anchor.attrs,
261
+ id: dom.getAnchorId(state.context)
262
+ }),
263
+ triggerProps: normalize.button({
264
+ ...parts.trigger.attrs,
265
+ type: "button",
266
+ "data-placement": currentPlacement,
267
+ id: dom.getTriggerId(state.context),
268
+ "aria-haspopup": "dialog",
269
+ "aria-expanded": isOpen,
270
+ "data-expanded": dataAttr(isOpen),
271
+ "aria-controls": dom.getContentId(state.context),
272
+ onClick() {
273
+ send("TOGGLE");
274
+ },
275
+ onBlur(event) {
276
+ send({ type: "TRIGGER_BLUR", target: event.relatedTarget });
277
+ }
278
+ }),
279
+ positionerProps: normalize.element({
280
+ id: dom.getPositionerId(state.context),
281
+ ...parts.positioner.attrs,
282
+ style: popperStyles.floating
283
+ }),
284
+ contentProps: normalize.element({
285
+ ...parts.content.attrs,
286
+ id: dom.getContentId(state.context),
287
+ tabIndex: -1,
288
+ role: "dialog",
289
+ hidden: !isOpen,
290
+ "data-expanded": dataAttr(isOpen),
291
+ "aria-labelledby": rendered.title ? dom.getTitleId(state.context) : void 0,
292
+ "aria-describedby": rendered.description ? dom.getDescriptionId(state.context) : void 0,
293
+ "data-placement": currentPlacement
294
+ }),
295
+ titleProps: normalize.element({
296
+ ...parts.title.attrs,
297
+ id: dom.getTitleId(state.context)
298
+ }),
299
+ descriptionProps: normalize.element({
300
+ ...parts.description.attrs,
301
+ id: dom.getDescriptionId(state.context)
302
+ }),
303
+ closeTriggerProps: normalize.button({
304
+ ...parts.closeTrigger.attrs,
305
+ id: dom.getCloseTriggerId(state.context),
306
+ type: "button",
307
+ "aria-label": "close",
308
+ onClick() {
309
+ send("REQUEST_CLOSE");
310
+ }
311
+ })
312
+ };
313
+ }
314
+ // Annotate the CommonJS export names for ESM import in node:
315
+ 0 && (module.exports = {
316
+ connect
317
+ });
@@ -0,0 +1,8 @@
1
+ import {
2
+ connect
3
+ } from "./chunk-B4ONYBLM.mjs";
4
+ import "./chunk-KTOPDXGV.mjs";
5
+ import "./chunk-3IPU3K2L.mjs";
6
+ export {
7
+ connect
8
+ };
@@ -0,0 +1,52 @@
1
+ import { MachineContext } from './popover.types.js';
2
+ import '@zag-js/core';
3
+ import '@zag-js/dismissable';
4
+ import '@zag-js/popper';
5
+ import '@zag-js/types';
6
+
7
+ declare const dom: {
8
+ getRootNode: (ctx: {
9
+ getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
10
+ }) => Document | ShadowRoot;
11
+ getDoc: (ctx: {
12
+ getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
13
+ }) => Document;
14
+ getWin: (ctx: {
15
+ getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
16
+ }) => Window & typeof globalThis;
17
+ getActiveElement: (ctx: {
18
+ getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
19
+ }) => HTMLElement | null;
20
+ getById: <T = HTMLElement>(ctx: {
21
+ getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
22
+ }, id: string) => T | null;
23
+ createEmitter: (ctx: {
24
+ getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
25
+ }, target: HTMLElement) => (evt: string, detail: Record<string, any>, options?: EventInit | undefined) => void;
26
+ createListener: (target: HTMLElement) => <T_1 = any>(evt: string, handler: (e: CustomEvent<T_1>) => void) => () => void;
27
+ } & {
28
+ getActiveEl: (ctx: MachineContext) => Element | null;
29
+ getAnchorId: (ctx: MachineContext) => string;
30
+ getTriggerId: (ctx: MachineContext) => string;
31
+ getContentId: (ctx: MachineContext) => string;
32
+ getPositionerId: (ctx: MachineContext) => string;
33
+ getArrowId: (ctx: MachineContext) => string;
34
+ getTitleId: (ctx: MachineContext) => string;
35
+ getDescriptionId: (ctx: MachineContext) => string;
36
+ getCloseTriggerId: (ctx: MachineContext) => string;
37
+ getAnchorEl: (ctx: MachineContext) => HTMLElement | null;
38
+ getTriggerEl: (ctx: MachineContext) => HTMLElement | null;
39
+ getContentEl: (ctx: MachineContext) => HTMLElement | null;
40
+ getPositionerEl: (ctx: MachineContext) => HTMLElement | null;
41
+ getTitleEl: (ctx: MachineContext) => HTMLElement | null;
42
+ getDescriptionEl: (ctx: MachineContext) => HTMLElement | null;
43
+ getFocusableEls: (ctx: MachineContext) => HTMLElement[];
44
+ getFirstFocusableEl: (ctx: MachineContext) => HTMLElement;
45
+ getDocTabbableEls: (ctx: MachineContext) => HTMLElement[];
46
+ getTabbableEls: (ctx: MachineContext) => HTMLElement[];
47
+ getFirstTabbableEl: (ctx: MachineContext) => HTMLElement;
48
+ getLastTabbableEl: (ctx: MachineContext) => HTMLElement;
49
+ getInitialFocusEl: (ctx: MachineContext) => HTMLElement | null;
50
+ };
51
+
52
+ export { dom };
@@ -0,0 +1,210 @@
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/popover.dom.ts
21
+ var popover_dom_exports = {};
22
+ __export(popover_dom_exports, {
23
+ dom: () => dom
24
+ });
25
+ module.exports = __toCommonJS(popover_dom_exports);
26
+
27
+ // ../../utilities/core/src/functions.ts
28
+ var runIfFn = (v, ...a) => {
29
+ const res = typeof v === "function" ? v(...a) : v;
30
+ return res != null ? res : void 0;
31
+ };
32
+
33
+ // ../../utilities/dom/src/query.ts
34
+ function isDocument(el) {
35
+ return el.nodeType === Node.DOCUMENT_NODE;
36
+ }
37
+ function isWindow(value) {
38
+ return (value == null ? void 0 : value.toString()) === "[object Window]";
39
+ }
40
+ function isFrame(element) {
41
+ return element.localName === "iframe";
42
+ }
43
+ function getDocument(el) {
44
+ var _a;
45
+ if (isWindow(el))
46
+ return el.document;
47
+ if (isDocument(el))
48
+ return el;
49
+ return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
50
+ }
51
+ function defineDomHelpers(helpers) {
52
+ const dom2 = {
53
+ getRootNode: (ctx) => {
54
+ var _a, _b;
55
+ return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
56
+ },
57
+ getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
58
+ getWin: (ctx) => {
59
+ var _a;
60
+ return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
61
+ },
62
+ getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
63
+ getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id),
64
+ createEmitter: (ctx, target) => {
65
+ const win = dom2.getWin(ctx);
66
+ return function emit(evt, detail, options) {
67
+ const { bubbles = true, cancelable, composed = true } = options != null ? options : {};
68
+ const eventName = `zag:${evt}`;
69
+ const init = { bubbles, cancelable, composed, detail };
70
+ const event = new win.CustomEvent(eventName, init);
71
+ target.dispatchEvent(event);
72
+ };
73
+ },
74
+ createListener: (target) => {
75
+ return function listen(evt, handler) {
76
+ const eventName = `zag:${evt}`;
77
+ const listener = (e) => handler(e);
78
+ target.addEventListener(eventName, listener);
79
+ return () => target.removeEventListener(eventName, listener);
80
+ };
81
+ }
82
+ };
83
+ return {
84
+ ...dom2,
85
+ ...helpers
86
+ };
87
+ }
88
+ function isHTMLElement(v) {
89
+ return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string";
90
+ }
91
+ function isVisible(el) {
92
+ if (!isHTMLElement(el))
93
+ return false;
94
+ return el.offsetWidth > 0 || el.offsetHeight > 0 || el.getClientRects().length > 0;
95
+ }
96
+
97
+ // ../../utilities/dom/src/focusable.ts
98
+ function hasNegativeTabIndex(element) {
99
+ const tabIndex = parseInt(element.getAttribute("tabindex") || "0", 10);
100
+ return tabIndex < 0;
101
+ }
102
+ var focusableSelector = "input:not([type='hidden']):not([disabled]), select:not([disabled]), textarea:not([disabled]), a[href], button:not([disabled]), [tabindex], iframe, object, embed, area[href], audio[controls], video[controls], [contenteditable]:not([contenteditable='false']), details > summary:first-of-type";
103
+ var getFocusables = (container, includeContainer = false) => {
104
+ if (!container)
105
+ return [];
106
+ const elements = Array.from(container.querySelectorAll(focusableSelector));
107
+ const include = includeContainer == true || includeContainer == "if-empty" && elements.length === 0;
108
+ if (include && isHTMLElement(container) && isFocusable(container)) {
109
+ elements.unshift(container);
110
+ }
111
+ const focusableElements = elements.filter(isFocusable);
112
+ focusableElements.forEach((element, i) => {
113
+ if (isFrame(element) && element.contentDocument) {
114
+ const frameBody = element.contentDocument.body;
115
+ focusableElements.splice(i, 1, ...getFocusables(frameBody));
116
+ }
117
+ });
118
+ return focusableElements;
119
+ };
120
+ function isFocusable(element) {
121
+ if (!element)
122
+ return false;
123
+ return element.matches(focusableSelector) && isVisible(element);
124
+ }
125
+ function getTabbables(container, includeContainer) {
126
+ if (!container)
127
+ return [];
128
+ const elements = Array.from(container.querySelectorAll(focusableSelector));
129
+ const tabbableElements = elements.filter(isTabbable);
130
+ if (includeContainer && isTabbable(container)) {
131
+ tabbableElements.unshift(container);
132
+ }
133
+ tabbableElements.forEach((element, i) => {
134
+ if (isFrame(element) && element.contentDocument) {
135
+ const frameBody = element.contentDocument.body;
136
+ const allFrameTabbable = getTabbables(frameBody);
137
+ tabbableElements.splice(i, 1, ...allFrameTabbable);
138
+ }
139
+ });
140
+ if (!tabbableElements.length && includeContainer) {
141
+ return elements;
142
+ }
143
+ return tabbableElements;
144
+ }
145
+ function isTabbable(el) {
146
+ return isFocusable(el) && !hasNegativeTabIndex(el);
147
+ }
148
+ function getFirstTabbable(container, includeContainer) {
149
+ const [first] = getTabbables(container, includeContainer);
150
+ return first || null;
151
+ }
152
+ function getLastTabbable(container, includeContainer) {
153
+ const elements = getTabbables(container, includeContainer);
154
+ return elements[elements.length - 1] || null;
155
+ }
156
+
157
+ // src/popover.dom.ts
158
+ var dom = defineDomHelpers({
159
+ getActiveEl: (ctx) => dom.getDoc(ctx).activeElement,
160
+ getAnchorId: (ctx) => {
161
+ var _a, _b;
162
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.anchor) != null ? _b : `popover:${ctx.id}:anchor`;
163
+ },
164
+ getTriggerId: (ctx) => {
165
+ var _a, _b;
166
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.trigger) != null ? _b : `popover:${ctx.id}:trigger`;
167
+ },
168
+ getContentId: (ctx) => {
169
+ var _a, _b;
170
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.content) != null ? _b : `popover:${ctx.id}:content`;
171
+ },
172
+ getPositionerId: (ctx) => `popover:${ctx.id}:popper`,
173
+ getArrowId: (ctx) => `popover:${ctx.id}:arrow`,
174
+ getTitleId: (ctx) => {
175
+ var _a, _b;
176
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.title) != null ? _b : `popover:${ctx.id}:title`;
177
+ },
178
+ getDescriptionId: (ctx) => {
179
+ var _a, _b;
180
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.description) != null ? _b : `popover:${ctx.id}:desc`;
181
+ },
182
+ getCloseTriggerId: (ctx) => {
183
+ var _a, _b;
184
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.closeTrigger) != null ? _b : `popover:${ctx.id}:close`;
185
+ },
186
+ getAnchorEl: (ctx) => dom.getById(ctx, dom.getAnchorId(ctx)),
187
+ getTriggerEl: (ctx) => dom.getById(ctx, dom.getTriggerId(ctx)),
188
+ getContentEl: (ctx) => dom.getById(ctx, dom.getContentId(ctx)),
189
+ getPositionerEl: (ctx) => dom.getById(ctx, dom.getPositionerId(ctx)),
190
+ getTitleEl: (ctx) => dom.getById(ctx, dom.getTitleId(ctx)),
191
+ getDescriptionEl: (ctx) => dom.getById(ctx, dom.getDescriptionId(ctx)),
192
+ getFocusableEls: (ctx) => getFocusables(dom.getContentEl(ctx)),
193
+ getFirstFocusableEl: (ctx) => dom.getFocusableEls(ctx)[0],
194
+ getDocTabbableEls: (ctx) => getTabbables(dom.getDoc(ctx).body),
195
+ getTabbableEls: (ctx) => getTabbables(dom.getContentEl(ctx), "if-empty"),
196
+ getFirstTabbableEl: (ctx) => getFirstTabbable(dom.getContentEl(ctx), "if-empty"),
197
+ getLastTabbableEl: (ctx) => getLastTabbable(dom.getContentEl(ctx), "if-empty"),
198
+ getInitialFocusEl: (ctx) => {
199
+ let el = runIfFn(ctx.initialFocusEl);
200
+ if (!el && ctx.autoFocus)
201
+ el = dom.getFirstFocusableEl(ctx);
202
+ if (!el)
203
+ el = dom.getContentEl(ctx);
204
+ return el;
205
+ }
206
+ });
207
+ // Annotate the CommonJS export names for ESM import in node:
208
+ 0 && (module.exports = {
209
+ dom
210
+ });
@@ -0,0 +1,6 @@
1
+ import {
2
+ dom
3
+ } from "./chunk-3IPU3K2L.mjs";
4
+ export {
5
+ dom
6
+ };
@@ -0,0 +1,9 @@
1
+ import * as _zag_js_core from '@zag-js/core';
2
+ import { UserDefinedContext, MachineContext, MachineState } from './popover.types.js';
3
+ import '@zag-js/dismissable';
4
+ import '@zag-js/popper';
5
+ import '@zag-js/types';
6
+
7
+ declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
8
+
9
+ export { machine };