@zag-js/tabs 0.0.0-dev-20230221113221 → 0.0.0-dev-20230222120620

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,53 @@
1
+ // src/tabs.dom.ts
2
+ import { createScope, itemById, nextById, prevById, queryAll } from "@zag-js/dom-query";
3
+ import { first, last } from "@zag-js/utils";
4
+ var dom = createScope({
5
+ getRootId: (ctx) => ctx.ids?.root ?? `tabs:${ctx.id}`,
6
+ getTablistId: (ctx) => ctx.ids?.tablist ?? `tabs:${ctx.id}:list`,
7
+ getContentId: (ctx, id) => ctx.ids?.content ?? `tabs:${ctx.id}:content-${id}`,
8
+ getContentGroupId: (ctx) => ctx.ids?.contentGroup ?? `tabs:${ctx.id}:content-group`,
9
+ getTriggerId: (ctx, id) => ctx.ids?.trigger ?? `tabs:${ctx.id}:trigger-${id}`,
10
+ getIndicatorId: (ctx) => `tabs:${ctx.id}:indicator`,
11
+ getTablistEl: (ctx) => dom.getById(ctx, dom.getTablistId(ctx)),
12
+ getContentEl: (ctx, id) => dom.getById(ctx, dom.getContentId(ctx, id)),
13
+ getTriggerEl: (ctx, id) => dom.getById(ctx, dom.getTriggerId(ctx, id)),
14
+ getIndicatorEl: (ctx) => dom.getById(ctx, dom.getIndicatorId(ctx)),
15
+ getElements: (ctx) => {
16
+ const ownerId = CSS.escape(dom.getTablistId(ctx));
17
+ const selector = `[role=tab][data-ownedby='${ownerId}']:not([disabled])`;
18
+ return queryAll(dom.getTablistEl(ctx), selector);
19
+ },
20
+ getFirstEl: (ctx) => first(dom.getElements(ctx)),
21
+ getLastEl: (ctx) => last(dom.getElements(ctx)),
22
+ getNextEl: (ctx, id) => nextById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
23
+ getPrevEl: (ctx, id) => prevById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
24
+ getActiveContentEl: (ctx) => {
25
+ if (!ctx.value)
26
+ return;
27
+ const id = dom.getContentId(ctx, ctx.value);
28
+ return dom.getById(ctx, id);
29
+ },
30
+ getRectById: (ctx, id) => {
31
+ const empty = {
32
+ offsetLeft: 0,
33
+ offsetTop: 0,
34
+ offsetWidth: 0,
35
+ offsetHeight: 0
36
+ };
37
+ const tab = itemById(dom.getElements(ctx), dom.getTriggerId(ctx, id)) ?? empty;
38
+ if (ctx.isVertical) {
39
+ return {
40
+ top: `${tab.offsetTop}px`,
41
+ height: `${tab.offsetHeight}px`
42
+ };
43
+ }
44
+ return {
45
+ left: `${tab.offsetLeft}px`,
46
+ width: `${tab.offsetWidth}px`
47
+ };
48
+ }
49
+ });
50
+
51
+ export {
52
+ dom
53
+ };
@@ -1,73 +1,12 @@
1
1
  import {
2
- dom,
3
- isFrame,
4
- isHTMLElement,
5
- isVisible
6
- } from "./chunk-SDY32WSI.mjs";
2
+ dom
3
+ } from "./chunk-5ZMNIWHF.mjs";
7
4
 
8
5
  // src/tabs.machine.ts
9
6
  import { createMachine, guards } from "@zag-js/core";
10
-
11
- // ../../utilities/core/src/guard.ts
12
- var isArray = (v) => Array.isArray(v);
13
- var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
14
-
15
- // ../../utilities/core/src/object.ts
16
- function compact(obj) {
17
- if (obj === void 0)
18
- return obj;
19
- return Object.fromEntries(
20
- Object.entries(obj).filter(([, value]) => value !== void 0).map(([key, value]) => [key, isObject(value) ? compact(value) : value])
21
- );
22
- }
23
-
24
- // ../../utilities/dom/src/focusable.ts
25
- 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";
26
- var getFocusables = (container, includeContainer = false) => {
27
- if (!container)
28
- return [];
29
- const elements = Array.from(container.querySelectorAll(focusableSelector));
30
- const include = includeContainer == true || includeContainer == "if-empty" && elements.length === 0;
31
- if (include && isHTMLElement(container) && isFocusable(container)) {
32
- elements.unshift(container);
33
- }
34
- const focusableElements = elements.filter(isFocusable);
35
- focusableElements.forEach((element, i) => {
36
- if (isFrame(element) && element.contentDocument) {
37
- const frameBody = element.contentDocument.body;
38
- focusableElements.splice(i, 1, ...getFocusables(frameBody));
39
- }
40
- });
41
- return focusableElements;
42
- };
43
- function isFocusable(element) {
44
- if (!element)
45
- return false;
46
- return element.matches(focusableSelector) && isVisible(element);
47
- }
48
-
49
- // ../../utilities/dom/src/next-tick.ts
50
- function nextTick(fn) {
51
- const set = /* @__PURE__ */ new Set();
52
- function raf2(fn2) {
53
- const id = globalThis.requestAnimationFrame(fn2);
54
- set.add(() => globalThis.cancelAnimationFrame(id));
55
- }
56
- raf2(() => raf2(fn));
57
- return function cleanup() {
58
- set.forEach(function(fn2) {
59
- fn2();
60
- });
61
- };
62
- }
63
- function raf(fn) {
64
- const id = globalThis.requestAnimationFrame(fn);
65
- return function cleanup() {
66
- globalThis.cancelAnimationFrame(id);
67
- };
68
- }
69
-
70
- // src/tabs.machine.ts
7
+ import { nextTick, raf } from "@zag-js/dom-query";
8
+ import { getFocusables } from "@zag-js/tabbable";
9
+ import { compact } from "@zag-js/utils";
71
10
  var { not } = guards;
72
11
  function machine(userContext) {
73
12
  const ctx = compact(userContext);
@@ -3,50 +3,11 @@ import {
3
3
  } from "./chunk-S2KW2DT4.mjs";
4
4
  import {
5
5
  dom
6
- } from "./chunk-SDY32WSI.mjs";
7
-
8
- // ../../utilities/dom/src/attrs.ts
9
- var dataAttr = (guard) => {
10
- return guard ? "" : void 0;
11
- };
12
-
13
- // ../../utilities/dom/src/platform.ts
14
- var isDom = () => typeof window !== "undefined";
15
- function getPlatform() {
16
- const agent = navigator.userAgentData;
17
- return agent?.platform ?? navigator.platform;
18
- }
19
- var pt = (v) => isDom() && v.test(getPlatform());
20
- var vn = (v) => isDom() && v.test(navigator.vendor);
21
- var isSafari = () => isApple() && vn(/apple/i);
22
- var isApple = () => pt(/mac|iphone|ipad|ipod/i);
23
-
24
- // ../../utilities/dom/src/keyboard-event.ts
25
- var rtlKeyMap = {
26
- ArrowLeft: "ArrowRight",
27
- ArrowRight: "ArrowLeft"
28
- };
29
- var sameKeyMap = {
30
- Up: "ArrowUp",
31
- Down: "ArrowDown",
32
- Esc: "Escape",
33
- " ": "Space",
34
- ",": "Comma",
35
- Left: "ArrowLeft",
36
- Right: "ArrowRight"
37
- };
38
- function getEventKey(event, options = {}) {
39
- const { dir = "ltr", orientation = "horizontal" } = options;
40
- let { key } = event;
41
- key = sameKeyMap[key] ?? key;
42
- const isRtl = dir === "rtl" && orientation === "horizontal";
43
- if (isRtl && key in rtlKeyMap) {
44
- key = rtlKeyMap[key];
45
- }
46
- return key;
47
- }
6
+ } from "./chunk-5ZMNIWHF.mjs";
48
7
 
49
8
  // src/tabs.connect.ts
9
+ import { getEventKey } from "@zag-js/dom-event";
10
+ import { dataAttr, isSafari } from "@zag-js/dom-query";
50
11
  function connect(state, send, normalize) {
51
12
  const translations = state.context.translations;
52
13
  const isFocused = state.matches("focused");
package/dist/index.js CHANGED
@@ -31,181 +31,14 @@ var import_anatomy = require("@zag-js/anatomy");
31
31
  var anatomy = (0, import_anatomy.createAnatomy)("tabs").parts("root", "tablist", "trigger", "contentGroup", "content", "indicator");
32
32
  var parts = anatomy.build();
33
33
 
34
- // ../../utilities/dom/src/attrs.ts
35
- var dataAttr = (guard) => {
36
- return guard ? "" : void 0;
37
- };
38
-
39
- // ../../utilities/core/src/array.ts
40
- var first = (v) => v[0];
41
- var last = (v) => v[v.length - 1];
42
-
43
- // ../../utilities/core/src/guard.ts
44
- var isArray = (v) => Array.isArray(v);
45
- var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
46
-
47
- // ../../utilities/core/src/object.ts
48
- function compact(obj) {
49
- if (obj === void 0)
50
- return obj;
51
- return Object.fromEntries(
52
- Object.entries(obj).filter(([, value]) => value !== void 0).map(([key, value]) => [key, isObject(value) ? compact(value) : value])
53
- );
54
- }
55
-
56
- // ../../utilities/dom/src/platform.ts
57
- var isDom = () => typeof window !== "undefined";
58
- function getPlatform() {
59
- const agent = navigator.userAgentData;
60
- return agent?.platform ?? navigator.platform;
61
- }
62
- var pt = (v) => isDom() && v.test(getPlatform());
63
- var vn = (v) => isDom() && v.test(navigator.vendor);
64
- var isSafari = () => isApple() && vn(/apple/i);
65
- var isApple = () => pt(/mac|iphone|ipad|ipod/i);
66
-
67
- // ../../utilities/dom/src/query.ts
68
- function isDocument(el) {
69
- return el.nodeType === Node.DOCUMENT_NODE;
70
- }
71
- function isWindow(value) {
72
- return value?.toString() === "[object Window]";
73
- }
74
- function isFrame(element) {
75
- return element.localName === "iframe";
76
- }
77
- function getDocument(el) {
78
- if (isWindow(el))
79
- return el.document;
80
- if (isDocument(el))
81
- return el;
82
- return el?.ownerDocument ?? document;
83
- }
84
- function defineDomHelpers(helpers) {
85
- const dom2 = {
86
- getRootNode: (ctx) => ctx.getRootNode?.() ?? document,
87
- getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
88
- getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
89
- getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
90
- getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id),
91
- queryById: (ctx, id) => {
92
- const el = dom2.getById(ctx, id);
93
- if (!el)
94
- throw new Error(`Element with id "${id}" not found.`);
95
- return el;
96
- }
97
- };
98
- return {
99
- ...dom2,
100
- ...helpers
101
- };
102
- }
103
- function isHTMLElement(v) {
104
- return typeof v === "object" && v?.nodeType === Node.ELEMENT_NODE && typeof v?.nodeName === "string";
105
- }
106
- function isVisible(el) {
107
- if (!isHTMLElement(el))
108
- return false;
109
- return el.offsetWidth > 0 || el.offsetHeight > 0 || el.getClientRects().length > 0;
110
- }
111
-
112
- // ../../utilities/dom/src/focusable.ts
113
- 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";
114
- var getFocusables = (container, includeContainer = false) => {
115
- if (!container)
116
- return [];
117
- const elements = Array.from(container.querySelectorAll(focusableSelector));
118
- const include = includeContainer == true || includeContainer == "if-empty" && elements.length === 0;
119
- if (include && isHTMLElement(container) && isFocusable(container)) {
120
- elements.unshift(container);
121
- }
122
- const focusableElements = elements.filter(isFocusable);
123
- focusableElements.forEach((element, i) => {
124
- if (isFrame(element) && element.contentDocument) {
125
- const frameBody = element.contentDocument.body;
126
- focusableElements.splice(i, 1, ...getFocusables(frameBody));
127
- }
128
- });
129
- return focusableElements;
130
- };
131
- function isFocusable(element) {
132
- if (!element)
133
- return false;
134
- return element.matches(focusableSelector) && isVisible(element);
135
- }
136
-
137
- // ../../utilities/dom/src/keyboard-event.ts
138
- var rtlKeyMap = {
139
- ArrowLeft: "ArrowRight",
140
- ArrowRight: "ArrowLeft"
141
- };
142
- var sameKeyMap = {
143
- Up: "ArrowUp",
144
- Down: "ArrowDown",
145
- Esc: "Escape",
146
- " ": "Space",
147
- ",": "Comma",
148
- Left: "ArrowLeft",
149
- Right: "ArrowRight"
150
- };
151
- function getEventKey(event, options = {}) {
152
- const { dir = "ltr", orientation = "horizontal" } = options;
153
- let { key } = event;
154
- key = sameKeyMap[key] ?? key;
155
- const isRtl = dir === "rtl" && orientation === "horizontal";
156
- if (isRtl && key in rtlKeyMap) {
157
- key = rtlKeyMap[key];
158
- }
159
- return key;
160
- }
161
-
162
- // ../../utilities/dom/src/next-tick.ts
163
- function nextTick(fn) {
164
- const set = /* @__PURE__ */ new Set();
165
- function raf2(fn2) {
166
- const id = globalThis.requestAnimationFrame(fn2);
167
- set.add(() => globalThis.cancelAnimationFrame(id));
168
- }
169
- raf2(() => raf2(fn));
170
- return function cleanup() {
171
- set.forEach(function(fn2) {
172
- fn2();
173
- });
174
- };
175
- }
176
- function raf(fn) {
177
- const id = globalThis.requestAnimationFrame(fn);
178
- return function cleanup() {
179
- globalThis.cancelAnimationFrame(id);
180
- };
181
- }
182
-
183
- // ../../utilities/dom/src/nodelist.ts
184
- function queryAll(root, selector) {
185
- return Array.from(root?.querySelectorAll(selector) ?? []);
186
- }
187
- function itemById(v, id) {
188
- return v.find((node) => node.id === id);
189
- }
190
- function indexOfId(v, id) {
191
- const item = itemById(v, id);
192
- return item ? v.indexOf(item) : -1;
193
- }
194
- function nextById(v, id, loop = true) {
195
- let idx = indexOfId(v, id);
196
- idx = loop ? (idx + 1) % v.length : Math.min(idx + 1, v.length - 1);
197
- return v[idx];
198
- }
199
- function prevById(v, id, loop = true) {
200
- let idx = indexOfId(v, id);
201
- if (idx === -1)
202
- return loop ? v[v.length - 1] : null;
203
- idx = loop ? (idx - 1 + v.length) % v.length : Math.max(0, idx - 1);
204
- return v[idx];
205
- }
34
+ // src/tabs.connect.ts
35
+ var import_dom_event = require("@zag-js/dom-event");
36
+ var import_dom_query2 = require("@zag-js/dom-query");
206
37
 
207
38
  // src/tabs.dom.ts
208
- var dom = defineDomHelpers({
39
+ var import_dom_query = require("@zag-js/dom-query");
40
+ var import_utils = require("@zag-js/utils");
41
+ var dom = (0, import_dom_query.createScope)({
209
42
  getRootId: (ctx) => ctx.ids?.root ?? `tabs:${ctx.id}`,
210
43
  getTablistId: (ctx) => ctx.ids?.tablist ?? `tabs:${ctx.id}:list`,
211
44
  getContentId: (ctx, id) => ctx.ids?.content ?? `tabs:${ctx.id}:content-${id}`,
@@ -219,12 +52,12 @@ var dom = defineDomHelpers({
219
52
  getElements: (ctx) => {
220
53
  const ownerId = CSS.escape(dom.getTablistId(ctx));
221
54
  const selector = `[role=tab][data-ownedby='${ownerId}']:not([disabled])`;
222
- return queryAll(dom.getTablistEl(ctx), selector);
55
+ return (0, import_dom_query.queryAll)(dom.getTablistEl(ctx), selector);
223
56
  },
224
- getFirstEl: (ctx) => first(dom.getElements(ctx)),
225
- getLastEl: (ctx) => last(dom.getElements(ctx)),
226
- getNextEl: (ctx, id) => nextById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
227
- getPrevEl: (ctx, id) => prevById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
57
+ getFirstEl: (ctx) => (0, import_utils.first)(dom.getElements(ctx)),
58
+ getLastEl: (ctx) => (0, import_utils.last)(dom.getElements(ctx)),
59
+ getNextEl: (ctx, id) => (0, import_dom_query.nextById)(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
60
+ getPrevEl: (ctx, id) => (0, import_dom_query.prevById)(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
228
61
  getActiveContentEl: (ctx) => {
229
62
  if (!ctx.value)
230
63
  return;
@@ -238,7 +71,7 @@ var dom = defineDomHelpers({
238
71
  offsetWidth: 0,
239
72
  offsetHeight: 0
240
73
  };
241
- const tab = itemById(dom.getElements(ctx), dom.getTriggerId(ctx, id)) ?? empty;
74
+ const tab = (0, import_dom_query.itemById)(dom.getElements(ctx), dom.getTriggerId(ctx, id)) ?? empty;
242
75
  if (ctx.isVertical) {
243
76
  return {
244
77
  top: `${tab.offsetTop}px`,
@@ -270,14 +103,14 @@ function connect(state, send, normalize) {
270
103
  ...parts.root.attrs,
271
104
  id: dom.getRootId(state.context),
272
105
  "data-orientation": state.context.orientation,
273
- "data-focus": dataAttr(isFocused),
106
+ "data-focus": (0, import_dom_query2.dataAttr)(isFocused),
274
107
  dir: state.context.dir
275
108
  }),
276
109
  tablistProps: normalize.element({
277
110
  ...parts.tablist.attrs,
278
111
  id: dom.getTablistId(state.context),
279
112
  role: "tablist",
280
- "data-focus": dataAttr(isFocused),
113
+ "data-focus": (0, import_dom_query2.dataAttr)(isFocused),
281
114
  "aria-orientation": state.context.orientation,
282
115
  "data-orientation": state.context.orientation,
283
116
  "aria-label": translations.tablistLabel,
@@ -305,7 +138,7 @@ function connect(state, send, normalize) {
305
138
  send({ type: "ENTER", value: state.context.focusedValue });
306
139
  }
307
140
  };
308
- let key = getEventKey(event, state.context);
141
+ let key = (0, import_dom_event.getEventKey)(event, state.context);
309
142
  const exec = keyMap[key];
310
143
  if (exec) {
311
144
  event.preventDefault();
@@ -322,11 +155,11 @@ function connect(state, send, normalize) {
322
155
  type: "button",
323
156
  disabled,
324
157
  "data-orientation": state.context.orientation,
325
- "data-disabled": dataAttr(disabled),
158
+ "data-disabled": (0, import_dom_query2.dataAttr)(disabled),
326
159
  "aria-disabled": disabled,
327
160
  "data-value": value,
328
161
  "aria-selected": selected,
329
- "data-selected": dataAttr(selected),
162
+ "data-selected": (0, import_dom_query2.dataAttr)(selected),
330
163
  "aria-controls": dom.getContentId(state.context, value),
331
164
  "data-ownedby": dom.getTablistId(state.context),
332
165
  id: dom.getTriggerId(state.context, value),
@@ -343,7 +176,7 @@ function connect(state, send, normalize) {
343
176
  onClick(event) {
344
177
  if (disabled)
345
178
  return;
346
- if (isSafari()) {
179
+ if ((0, import_dom_query2.isSafari)()) {
347
180
  event.currentTarget.focus();
348
181
  }
349
182
  send({ type: "TAB_CLICK", value });
@@ -387,9 +220,12 @@ function connect(state, send, normalize) {
387
220
 
388
221
  // src/tabs.machine.ts
389
222
  var import_core = require("@zag-js/core");
223
+ var import_dom_query3 = require("@zag-js/dom-query");
224
+ var import_tabbable = require("@zag-js/tabbable");
225
+ var import_utils2 = require("@zag-js/utils");
390
226
  var { not } = import_core.guards;
391
227
  function machine(userContext) {
392
- const ctx = compact(userContext);
228
+ const ctx = (0, import_utils2.compact)(userContext);
393
229
  return (0, import_core.createMachine)(
394
230
  {
395
231
  initial: "idle",
@@ -510,31 +346,31 @@ function machine(userContext) {
510
346
  ctx2.onDelete?.({ value: evt.value });
511
347
  },
512
348
  focusFirstTab(ctx2) {
513
- raf(() => dom.getFirstEl(ctx2)?.focus());
349
+ (0, import_dom_query3.raf)(() => dom.getFirstEl(ctx2)?.focus());
514
350
  },
515
351
  focusLastTab(ctx2) {
516
- raf(() => dom.getLastEl(ctx2)?.focus());
352
+ (0, import_dom_query3.raf)(() => dom.getLastEl(ctx2)?.focus());
517
353
  },
518
354
  focusNextTab(ctx2) {
519
355
  if (!ctx2.focusedValue)
520
356
  return;
521
357
  const next = dom.getNextEl(ctx2, ctx2.focusedValue);
522
- raf(() => next?.focus());
358
+ (0, import_dom_query3.raf)(() => next?.focus());
523
359
  },
524
360
  focusPrevTab(ctx2) {
525
361
  if (!ctx2.focusedValue)
526
362
  return;
527
363
  const prev = dom.getPrevEl(ctx2, ctx2.focusedValue);
528
- raf(() => prev?.focus());
364
+ (0, import_dom_query3.raf)(() => prev?.focus());
529
365
  },
530
366
  setIndicatorRect(ctx2) {
531
- nextTick(() => {
367
+ (0, import_dom_query3.nextTick)(() => {
532
368
  if (!ctx2.isIndicatorRendered || !ctx2.value)
533
369
  return;
534
370
  ctx2.indicatorRect = dom.getRectById(ctx2, ctx2.value);
535
371
  if (ctx2.hasMeasuredRect)
536
372
  return;
537
- nextTick(() => {
373
+ (0, import_dom_query3.nextTick)(() => {
538
374
  ctx2.hasMeasuredRect = true;
539
375
  });
540
376
  });
@@ -558,11 +394,11 @@ function machine(userContext) {
558
394
  },
559
395
  // if tab panel contains focusable elements, remove the tabindex attribute
560
396
  setContentTabIndex(ctx2) {
561
- raf(() => {
397
+ (0, import_dom_query3.raf)(() => {
562
398
  const panel = dom.getActiveContentEl(ctx2);
563
399
  if (!panel)
564
400
  return;
565
- const focusables = getFocusables(panel);
401
+ const focusables = (0, import_tabbable.getFocusables)(panel);
566
402
  if (focusables.length > 0) {
567
403
  panel.removeAttribute("tabindex");
568
404
  } else {
package/dist/index.mjs CHANGED
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  connect
3
- } from "./chunk-M5VIW7LC.mjs";
3
+ } from "./chunk-MMG5KHSN.mjs";
4
4
  import {
5
5
  anatomy
6
6
  } from "./chunk-S2KW2DT4.mjs";
7
7
  import {
8
8
  machine
9
- } from "./chunk-ZMHFFJLR.mjs";
10
- import "./chunk-SDY32WSI.mjs";
9
+ } from "./chunk-JG2VX4ST.mjs";
10
+ import "./chunk-5ZMNIWHF.mjs";
11
11
  export {
12
12
  anatomy,
13
13
  connect,
@@ -23,109 +23,8 @@ __export(tabs_connect_exports, {
23
23
  connect: () => connect
24
24
  });
25
25
  module.exports = __toCommonJS(tabs_connect_exports);
26
-
27
- // ../../utilities/dom/src/attrs.ts
28
- var dataAttr = (guard) => {
29
- return guard ? "" : void 0;
30
- };
31
-
32
- // ../../utilities/core/src/array.ts
33
- var first = (v) => v[0];
34
- var last = (v) => v[v.length - 1];
35
-
36
- // ../../utilities/dom/src/platform.ts
37
- var isDom = () => typeof window !== "undefined";
38
- function getPlatform() {
39
- const agent = navigator.userAgentData;
40
- return agent?.platform ?? navigator.platform;
41
- }
42
- var pt = (v) => isDom() && v.test(getPlatform());
43
- var vn = (v) => isDom() && v.test(navigator.vendor);
44
- var isSafari = () => isApple() && vn(/apple/i);
45
- var isApple = () => pt(/mac|iphone|ipad|ipod/i);
46
-
47
- // ../../utilities/dom/src/query.ts
48
- function isDocument(el) {
49
- return el.nodeType === Node.DOCUMENT_NODE;
50
- }
51
- function isWindow(value) {
52
- return value?.toString() === "[object Window]";
53
- }
54
- function getDocument(el) {
55
- if (isWindow(el))
56
- return el.document;
57
- if (isDocument(el))
58
- return el;
59
- return el?.ownerDocument ?? document;
60
- }
61
- function defineDomHelpers(helpers) {
62
- const dom2 = {
63
- getRootNode: (ctx) => ctx.getRootNode?.() ?? document,
64
- getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
65
- getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
66
- getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
67
- getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id),
68
- queryById: (ctx, id) => {
69
- const el = dom2.getById(ctx, id);
70
- if (!el)
71
- throw new Error(`Element with id "${id}" not found.`);
72
- return el;
73
- }
74
- };
75
- return {
76
- ...dom2,
77
- ...helpers
78
- };
79
- }
80
-
81
- // ../../utilities/dom/src/keyboard-event.ts
82
- var rtlKeyMap = {
83
- ArrowLeft: "ArrowRight",
84
- ArrowRight: "ArrowLeft"
85
- };
86
- var sameKeyMap = {
87
- Up: "ArrowUp",
88
- Down: "ArrowDown",
89
- Esc: "Escape",
90
- " ": "Space",
91
- ",": "Comma",
92
- Left: "ArrowLeft",
93
- Right: "ArrowRight"
94
- };
95
- function getEventKey(event, options = {}) {
96
- const { dir = "ltr", orientation = "horizontal" } = options;
97
- let { key } = event;
98
- key = sameKeyMap[key] ?? key;
99
- const isRtl = dir === "rtl" && orientation === "horizontal";
100
- if (isRtl && key in rtlKeyMap) {
101
- key = rtlKeyMap[key];
102
- }
103
- return key;
104
- }
105
-
106
- // ../../utilities/dom/src/nodelist.ts
107
- function queryAll(root, selector) {
108
- return Array.from(root?.querySelectorAll(selector) ?? []);
109
- }
110
- function itemById(v, id) {
111
- return v.find((node) => node.id === id);
112
- }
113
- function indexOfId(v, id) {
114
- const item = itemById(v, id);
115
- return item ? v.indexOf(item) : -1;
116
- }
117
- function nextById(v, id, loop = true) {
118
- let idx = indexOfId(v, id);
119
- idx = loop ? (idx + 1) % v.length : Math.min(idx + 1, v.length - 1);
120
- return v[idx];
121
- }
122
- function prevById(v, id, loop = true) {
123
- let idx = indexOfId(v, id);
124
- if (idx === -1)
125
- return loop ? v[v.length - 1] : null;
126
- idx = loop ? (idx - 1 + v.length) % v.length : Math.max(0, idx - 1);
127
- return v[idx];
128
- }
26
+ var import_dom_event = require("@zag-js/dom-event");
27
+ var import_dom_query2 = require("@zag-js/dom-query");
129
28
 
130
29
  // src/tabs.anatomy.ts
131
30
  var import_anatomy = require("@zag-js/anatomy");
@@ -133,7 +32,9 @@ var anatomy = (0, import_anatomy.createAnatomy)("tabs").parts("root", "tablist",
133
32
  var parts = anatomy.build();
134
33
 
135
34
  // src/tabs.dom.ts
136
- var dom = defineDomHelpers({
35
+ var import_dom_query = require("@zag-js/dom-query");
36
+ var import_utils = require("@zag-js/utils");
37
+ var dom = (0, import_dom_query.createScope)({
137
38
  getRootId: (ctx) => ctx.ids?.root ?? `tabs:${ctx.id}`,
138
39
  getTablistId: (ctx) => ctx.ids?.tablist ?? `tabs:${ctx.id}:list`,
139
40
  getContentId: (ctx, id) => ctx.ids?.content ?? `tabs:${ctx.id}:content-${id}`,
@@ -147,12 +48,12 @@ var dom = defineDomHelpers({
147
48
  getElements: (ctx) => {
148
49
  const ownerId = CSS.escape(dom.getTablistId(ctx));
149
50
  const selector = `[role=tab][data-ownedby='${ownerId}']:not([disabled])`;
150
- return queryAll(dom.getTablistEl(ctx), selector);
51
+ return (0, import_dom_query.queryAll)(dom.getTablistEl(ctx), selector);
151
52
  },
152
- getFirstEl: (ctx) => first(dom.getElements(ctx)),
153
- getLastEl: (ctx) => last(dom.getElements(ctx)),
154
- getNextEl: (ctx, id) => nextById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
155
- getPrevEl: (ctx, id) => prevById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
53
+ getFirstEl: (ctx) => (0, import_utils.first)(dom.getElements(ctx)),
54
+ getLastEl: (ctx) => (0, import_utils.last)(dom.getElements(ctx)),
55
+ getNextEl: (ctx, id) => (0, import_dom_query.nextById)(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
56
+ getPrevEl: (ctx, id) => (0, import_dom_query.prevById)(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
156
57
  getActiveContentEl: (ctx) => {
157
58
  if (!ctx.value)
158
59
  return;
@@ -166,7 +67,7 @@ var dom = defineDomHelpers({
166
67
  offsetWidth: 0,
167
68
  offsetHeight: 0
168
69
  };
169
- const tab = itemById(dom.getElements(ctx), dom.getTriggerId(ctx, id)) ?? empty;
70
+ const tab = (0, import_dom_query.itemById)(dom.getElements(ctx), dom.getTriggerId(ctx, id)) ?? empty;
170
71
  if (ctx.isVertical) {
171
72
  return {
172
73
  top: `${tab.offsetTop}px`,
@@ -198,14 +99,14 @@ function connect(state, send, normalize) {
198
99
  ...parts.root.attrs,
199
100
  id: dom.getRootId(state.context),
200
101
  "data-orientation": state.context.orientation,
201
- "data-focus": dataAttr(isFocused),
102
+ "data-focus": (0, import_dom_query2.dataAttr)(isFocused),
202
103
  dir: state.context.dir
203
104
  }),
204
105
  tablistProps: normalize.element({
205
106
  ...parts.tablist.attrs,
206
107
  id: dom.getTablistId(state.context),
207
108
  role: "tablist",
208
- "data-focus": dataAttr(isFocused),
109
+ "data-focus": (0, import_dom_query2.dataAttr)(isFocused),
209
110
  "aria-orientation": state.context.orientation,
210
111
  "data-orientation": state.context.orientation,
211
112
  "aria-label": translations.tablistLabel,
@@ -233,7 +134,7 @@ function connect(state, send, normalize) {
233
134
  send({ type: "ENTER", value: state.context.focusedValue });
234
135
  }
235
136
  };
236
- let key = getEventKey(event, state.context);
137
+ let key = (0, import_dom_event.getEventKey)(event, state.context);
237
138
  const exec = keyMap[key];
238
139
  if (exec) {
239
140
  event.preventDefault();
@@ -250,11 +151,11 @@ function connect(state, send, normalize) {
250
151
  type: "button",
251
152
  disabled,
252
153
  "data-orientation": state.context.orientation,
253
- "data-disabled": dataAttr(disabled),
154
+ "data-disabled": (0, import_dom_query2.dataAttr)(disabled),
254
155
  "aria-disabled": disabled,
255
156
  "data-value": value,
256
157
  "aria-selected": selected,
257
- "data-selected": dataAttr(selected),
158
+ "data-selected": (0, import_dom_query2.dataAttr)(selected),
258
159
  "aria-controls": dom.getContentId(state.context, value),
259
160
  "data-ownedby": dom.getTablistId(state.context),
260
161
  id: dom.getTriggerId(state.context, value),
@@ -271,7 +172,7 @@ function connect(state, send, normalize) {
271
172
  onClick(event) {
272
173
  if (disabled)
273
174
  return;
274
- if (isSafari()) {
175
+ if ((0, import_dom_query2.isSafari)()) {
275
176
  event.currentTarget.focus();
276
177
  }
277
178
  send({ type: "TAB_CLICK", value });
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  connect
3
- } from "./chunk-M5VIW7LC.mjs";
3
+ } from "./chunk-MMG5KHSN.mjs";
4
4
  import "./chunk-S2KW2DT4.mjs";
5
- import "./chunk-SDY32WSI.mjs";
5
+ import "./chunk-5ZMNIWHF.mjs";
6
6
  export {
7
7
  connect
8
8
  };
@@ -4,22 +4,22 @@ import '@zag-js/types';
4
4
 
5
5
  declare const dom: {
6
6
  getRootNode: (ctx: {
7
- getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
7
+ getRootNode?: (() => Document | Node | ShadowRoot) | undefined;
8
8
  }) => Document | ShadowRoot;
9
9
  getDoc: (ctx: {
10
- getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
10
+ getRootNode?: (() => Document | Node | ShadowRoot) | undefined;
11
11
  }) => Document;
12
12
  getWin: (ctx: {
13
- getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
13
+ getRootNode?: (() => Document | Node | ShadowRoot) | undefined;
14
14
  }) => Window & typeof globalThis;
15
15
  getActiveElement: (ctx: {
16
- getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
16
+ getRootNode?: (() => Document | Node | ShadowRoot) | undefined;
17
17
  }) => HTMLElement | null;
18
- getById: <T = HTMLElement>(ctx: {
19
- getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
18
+ getById: <T extends HTMLElement = HTMLElement>(ctx: {
19
+ getRootNode?: (() => Document | Node | ShadowRoot) | undefined;
20
20
  }, id: string) => T | null;
21
- queryById: <T_1 = HTMLElement>(ctx: {
22
- getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
21
+ queryById: <T_1 extends HTMLElement = HTMLElement>(ctx: {
22
+ getRootNode?: (() => Document | Node | ShadowRoot) | undefined;
23
23
  }, id: string) => T_1;
24
24
  } & {
25
25
  getRootId: (ctx: MachineContext) => string;
package/dist/tabs.dom.js CHANGED
@@ -23,71 +23,9 @@ __export(tabs_dom_exports, {
23
23
  dom: () => dom
24
24
  });
25
25
  module.exports = __toCommonJS(tabs_dom_exports);
26
-
27
- // ../../utilities/core/src/array.ts
28
- var first = (v) => v[0];
29
- var last = (v) => v[v.length - 1];
30
-
31
- // ../../utilities/dom/src/query.ts
32
- function isDocument(el) {
33
- return el.nodeType === Node.DOCUMENT_NODE;
34
- }
35
- function isWindow(value) {
36
- return value?.toString() === "[object Window]";
37
- }
38
- function getDocument(el) {
39
- if (isWindow(el))
40
- return el.document;
41
- if (isDocument(el))
42
- return el;
43
- return el?.ownerDocument ?? document;
44
- }
45
- function defineDomHelpers(helpers) {
46
- const dom2 = {
47
- getRootNode: (ctx) => ctx.getRootNode?.() ?? document,
48
- getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
49
- getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
50
- getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
51
- getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id),
52
- queryById: (ctx, id) => {
53
- const el = dom2.getById(ctx, id);
54
- if (!el)
55
- throw new Error(`Element with id "${id}" not found.`);
56
- return el;
57
- }
58
- };
59
- return {
60
- ...dom2,
61
- ...helpers
62
- };
63
- }
64
-
65
- // ../../utilities/dom/src/nodelist.ts
66
- function queryAll(root, selector) {
67
- return Array.from(root?.querySelectorAll(selector) ?? []);
68
- }
69
- function itemById(v, id) {
70
- return v.find((node) => node.id === id);
71
- }
72
- function indexOfId(v, id) {
73
- const item = itemById(v, id);
74
- return item ? v.indexOf(item) : -1;
75
- }
76
- function nextById(v, id, loop = true) {
77
- let idx = indexOfId(v, id);
78
- idx = loop ? (idx + 1) % v.length : Math.min(idx + 1, v.length - 1);
79
- return v[idx];
80
- }
81
- function prevById(v, id, loop = true) {
82
- let idx = indexOfId(v, id);
83
- if (idx === -1)
84
- return loop ? v[v.length - 1] : null;
85
- idx = loop ? (idx - 1 + v.length) % v.length : Math.max(0, idx - 1);
86
- return v[idx];
87
- }
88
-
89
- // src/tabs.dom.ts
90
- var dom = defineDomHelpers({
26
+ var import_dom_query = require("@zag-js/dom-query");
27
+ var import_utils = require("@zag-js/utils");
28
+ var dom = (0, import_dom_query.createScope)({
91
29
  getRootId: (ctx) => ctx.ids?.root ?? `tabs:${ctx.id}`,
92
30
  getTablistId: (ctx) => ctx.ids?.tablist ?? `tabs:${ctx.id}:list`,
93
31
  getContentId: (ctx, id) => ctx.ids?.content ?? `tabs:${ctx.id}:content-${id}`,
@@ -101,12 +39,12 @@ var dom = defineDomHelpers({
101
39
  getElements: (ctx) => {
102
40
  const ownerId = CSS.escape(dom.getTablistId(ctx));
103
41
  const selector = `[role=tab][data-ownedby='${ownerId}']:not([disabled])`;
104
- return queryAll(dom.getTablistEl(ctx), selector);
42
+ return (0, import_dom_query.queryAll)(dom.getTablistEl(ctx), selector);
105
43
  },
106
- getFirstEl: (ctx) => first(dom.getElements(ctx)),
107
- getLastEl: (ctx) => last(dom.getElements(ctx)),
108
- getNextEl: (ctx, id) => nextById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
109
- getPrevEl: (ctx, id) => prevById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
44
+ getFirstEl: (ctx) => (0, import_utils.first)(dom.getElements(ctx)),
45
+ getLastEl: (ctx) => (0, import_utils.last)(dom.getElements(ctx)),
46
+ getNextEl: (ctx, id) => (0, import_dom_query.nextById)(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
47
+ getPrevEl: (ctx, id) => (0, import_dom_query.prevById)(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
110
48
  getActiveContentEl: (ctx) => {
111
49
  if (!ctx.value)
112
50
  return;
@@ -120,7 +58,7 @@ var dom = defineDomHelpers({
120
58
  offsetWidth: 0,
121
59
  offsetHeight: 0
122
60
  };
123
- const tab = itemById(dom.getElements(ctx), dom.getTriggerId(ctx, id)) ?? empty;
61
+ const tab = (0, import_dom_query.itemById)(dom.getElements(ctx), dom.getTriggerId(ctx, id)) ?? empty;
124
62
  if (ctx.isVertical) {
125
63
  return {
126
64
  top: `${tab.offsetTop}px`,
package/dist/tabs.dom.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  dom
3
- } from "./chunk-SDY32WSI.mjs";
3
+ } from "./chunk-5ZMNIWHF.mjs";
4
4
  export {
5
5
  dom
6
6
  };
@@ -24,141 +24,14 @@ __export(tabs_machine_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(tabs_machine_exports);
26
26
  var import_core = require("@zag-js/core");
27
-
28
- // ../../utilities/core/src/array.ts
29
- var first = (v) => v[0];
30
- var last = (v) => v[v.length - 1];
31
-
32
- // ../../utilities/core/src/guard.ts
33
- var isArray = (v) => Array.isArray(v);
34
- var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
35
-
36
- // ../../utilities/core/src/object.ts
37
- function compact(obj) {
38
- if (obj === void 0)
39
- return obj;
40
- return Object.fromEntries(
41
- Object.entries(obj).filter(([, value]) => value !== void 0).map(([key, value]) => [key, isObject(value) ? compact(value) : value])
42
- );
43
- }
44
-
45
- // ../../utilities/dom/src/query.ts
46
- function isDocument(el) {
47
- return el.nodeType === Node.DOCUMENT_NODE;
48
- }
49
- function isWindow(value) {
50
- return value?.toString() === "[object Window]";
51
- }
52
- function isFrame(element) {
53
- return element.localName === "iframe";
54
- }
55
- function getDocument(el) {
56
- if (isWindow(el))
57
- return el.document;
58
- if (isDocument(el))
59
- return el;
60
- return el?.ownerDocument ?? document;
61
- }
62
- function defineDomHelpers(helpers) {
63
- const dom2 = {
64
- getRootNode: (ctx) => ctx.getRootNode?.() ?? document,
65
- getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
66
- getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
67
- getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
68
- getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id),
69
- queryById: (ctx, id) => {
70
- const el = dom2.getById(ctx, id);
71
- if (!el)
72
- throw new Error(`Element with id "${id}" not found.`);
73
- return el;
74
- }
75
- };
76
- return {
77
- ...dom2,
78
- ...helpers
79
- };
80
- }
81
- function isHTMLElement(v) {
82
- return typeof v === "object" && v?.nodeType === Node.ELEMENT_NODE && typeof v?.nodeName === "string";
83
- }
84
- function isVisible(el) {
85
- if (!isHTMLElement(el))
86
- return false;
87
- return el.offsetWidth > 0 || el.offsetHeight > 0 || el.getClientRects().length > 0;
88
- }
89
-
90
- // ../../utilities/dom/src/focusable.ts
91
- 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";
92
- var getFocusables = (container, includeContainer = false) => {
93
- if (!container)
94
- return [];
95
- const elements = Array.from(container.querySelectorAll(focusableSelector));
96
- const include = includeContainer == true || includeContainer == "if-empty" && elements.length === 0;
97
- if (include && isHTMLElement(container) && isFocusable(container)) {
98
- elements.unshift(container);
99
- }
100
- const focusableElements = elements.filter(isFocusable);
101
- focusableElements.forEach((element, i) => {
102
- if (isFrame(element) && element.contentDocument) {
103
- const frameBody = element.contentDocument.body;
104
- focusableElements.splice(i, 1, ...getFocusables(frameBody));
105
- }
106
- });
107
- return focusableElements;
108
- };
109
- function isFocusable(element) {
110
- if (!element)
111
- return false;
112
- return element.matches(focusableSelector) && isVisible(element);
113
- }
114
-
115
- // ../../utilities/dom/src/next-tick.ts
116
- function nextTick(fn) {
117
- const set = /* @__PURE__ */ new Set();
118
- function raf2(fn2) {
119
- const id = globalThis.requestAnimationFrame(fn2);
120
- set.add(() => globalThis.cancelAnimationFrame(id));
121
- }
122
- raf2(() => raf2(fn));
123
- return function cleanup() {
124
- set.forEach(function(fn2) {
125
- fn2();
126
- });
127
- };
128
- }
129
- function raf(fn) {
130
- const id = globalThis.requestAnimationFrame(fn);
131
- return function cleanup() {
132
- globalThis.cancelAnimationFrame(id);
133
- };
134
- }
135
-
136
- // ../../utilities/dom/src/nodelist.ts
137
- function queryAll(root, selector) {
138
- return Array.from(root?.querySelectorAll(selector) ?? []);
139
- }
140
- function itemById(v, id) {
141
- return v.find((node) => node.id === id);
142
- }
143
- function indexOfId(v, id) {
144
- const item = itemById(v, id);
145
- return item ? v.indexOf(item) : -1;
146
- }
147
- function nextById(v, id, loop = true) {
148
- let idx = indexOfId(v, id);
149
- idx = loop ? (idx + 1) % v.length : Math.min(idx + 1, v.length - 1);
150
- return v[idx];
151
- }
152
- function prevById(v, id, loop = true) {
153
- let idx = indexOfId(v, id);
154
- if (idx === -1)
155
- return loop ? v[v.length - 1] : null;
156
- idx = loop ? (idx - 1 + v.length) % v.length : Math.max(0, idx - 1);
157
- return v[idx];
158
- }
27
+ var import_dom_query2 = require("@zag-js/dom-query");
28
+ var import_tabbable = require("@zag-js/tabbable");
29
+ var import_utils2 = require("@zag-js/utils");
159
30
 
160
31
  // src/tabs.dom.ts
161
- var dom = defineDomHelpers({
32
+ var import_dom_query = require("@zag-js/dom-query");
33
+ var import_utils = require("@zag-js/utils");
34
+ var dom = (0, import_dom_query.createScope)({
162
35
  getRootId: (ctx) => ctx.ids?.root ?? `tabs:${ctx.id}`,
163
36
  getTablistId: (ctx) => ctx.ids?.tablist ?? `tabs:${ctx.id}:list`,
164
37
  getContentId: (ctx, id) => ctx.ids?.content ?? `tabs:${ctx.id}:content-${id}`,
@@ -172,12 +45,12 @@ var dom = defineDomHelpers({
172
45
  getElements: (ctx) => {
173
46
  const ownerId = CSS.escape(dom.getTablistId(ctx));
174
47
  const selector = `[role=tab][data-ownedby='${ownerId}']:not([disabled])`;
175
- return queryAll(dom.getTablistEl(ctx), selector);
48
+ return (0, import_dom_query.queryAll)(dom.getTablistEl(ctx), selector);
176
49
  },
177
- getFirstEl: (ctx) => first(dom.getElements(ctx)),
178
- getLastEl: (ctx) => last(dom.getElements(ctx)),
179
- getNextEl: (ctx, id) => nextById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
180
- getPrevEl: (ctx, id) => prevById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
50
+ getFirstEl: (ctx) => (0, import_utils.first)(dom.getElements(ctx)),
51
+ getLastEl: (ctx) => (0, import_utils.last)(dom.getElements(ctx)),
52
+ getNextEl: (ctx, id) => (0, import_dom_query.nextById)(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
53
+ getPrevEl: (ctx, id) => (0, import_dom_query.prevById)(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
181
54
  getActiveContentEl: (ctx) => {
182
55
  if (!ctx.value)
183
56
  return;
@@ -191,7 +64,7 @@ var dom = defineDomHelpers({
191
64
  offsetWidth: 0,
192
65
  offsetHeight: 0
193
66
  };
194
- const tab = itemById(dom.getElements(ctx), dom.getTriggerId(ctx, id)) ?? empty;
67
+ const tab = (0, import_dom_query.itemById)(dom.getElements(ctx), dom.getTriggerId(ctx, id)) ?? empty;
195
68
  if (ctx.isVertical) {
196
69
  return {
197
70
  top: `${tab.offsetTop}px`,
@@ -208,7 +81,7 @@ var dom = defineDomHelpers({
208
81
  // src/tabs.machine.ts
209
82
  var { not } = import_core.guards;
210
83
  function machine(userContext) {
211
- const ctx = compact(userContext);
84
+ const ctx = (0, import_utils2.compact)(userContext);
212
85
  return (0, import_core.createMachine)(
213
86
  {
214
87
  initial: "idle",
@@ -329,31 +202,31 @@ function machine(userContext) {
329
202
  ctx2.onDelete?.({ value: evt.value });
330
203
  },
331
204
  focusFirstTab(ctx2) {
332
- raf(() => dom.getFirstEl(ctx2)?.focus());
205
+ (0, import_dom_query2.raf)(() => dom.getFirstEl(ctx2)?.focus());
333
206
  },
334
207
  focusLastTab(ctx2) {
335
- raf(() => dom.getLastEl(ctx2)?.focus());
208
+ (0, import_dom_query2.raf)(() => dom.getLastEl(ctx2)?.focus());
336
209
  },
337
210
  focusNextTab(ctx2) {
338
211
  if (!ctx2.focusedValue)
339
212
  return;
340
213
  const next = dom.getNextEl(ctx2, ctx2.focusedValue);
341
- raf(() => next?.focus());
214
+ (0, import_dom_query2.raf)(() => next?.focus());
342
215
  },
343
216
  focusPrevTab(ctx2) {
344
217
  if (!ctx2.focusedValue)
345
218
  return;
346
219
  const prev = dom.getPrevEl(ctx2, ctx2.focusedValue);
347
- raf(() => prev?.focus());
220
+ (0, import_dom_query2.raf)(() => prev?.focus());
348
221
  },
349
222
  setIndicatorRect(ctx2) {
350
- nextTick(() => {
223
+ (0, import_dom_query2.nextTick)(() => {
351
224
  if (!ctx2.isIndicatorRendered || !ctx2.value)
352
225
  return;
353
226
  ctx2.indicatorRect = dom.getRectById(ctx2, ctx2.value);
354
227
  if (ctx2.hasMeasuredRect)
355
228
  return;
356
- nextTick(() => {
229
+ (0, import_dom_query2.nextTick)(() => {
357
230
  ctx2.hasMeasuredRect = true;
358
231
  });
359
232
  });
@@ -377,11 +250,11 @@ function machine(userContext) {
377
250
  },
378
251
  // if tab panel contains focusable elements, remove the tabindex attribute
379
252
  setContentTabIndex(ctx2) {
380
- raf(() => {
253
+ (0, import_dom_query2.raf)(() => {
381
254
  const panel = dom.getActiveContentEl(ctx2);
382
255
  if (!panel)
383
256
  return;
384
- const focusables = getFocusables(panel);
257
+ const focusables = (0, import_tabbable.getFocusables)(panel);
385
258
  if (focusables.length > 0) {
386
259
  panel.removeAttribute("tabindex");
387
260
  } else {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  machine
3
- } from "./chunk-ZMHFFJLR.mjs";
4
- import "./chunk-SDY32WSI.mjs";
3
+ } from "./chunk-JG2VX4ST.mjs";
4
+ import "./chunk-5ZMNIWHF.mjs";
5
5
  export {
6
6
  machine
7
7
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/tabs",
3
- "version": "0.0.0-dev-20230221113221",
3
+ "version": "0.0.0-dev-20230222120620",
4
4
  "description": "Core logic for the tabs widget implemented as a state machine",
5
5
  "keywords": [
6
6
  "js",
@@ -27,13 +27,15 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "@zag-js/anatomy": "0.1.4",
30
- "@zag-js/core": "0.0.0-dev-20230221113221",
30
+ "@zag-js/dom-query": "0.0.0-dev-20230222120620",
31
+ "@zag-js/dom-event": "0.0.0-dev-20230222120620",
32
+ "@zag-js/tabbable": "0.0.0-dev-20230222120620",
33
+ "@zag-js/utils": "0.3.3",
34
+ "@zag-js/core": "0.0.0-dev-20230222120620",
31
35
  "@zag-js/types": "0.3.4"
32
36
  },
33
37
  "devDependencies": {
34
- "clean-package": "2.2.0",
35
- "@zag-js/dom-utils": "0.2.4",
36
- "@zag-js/utils": "0.3.3"
38
+ "clean-package": "2.2.0"
37
39
  },
38
40
  "clean-package": "../../../clean-package.config.json",
39
41
  "main": "dist/index.js",
@@ -1,127 +0,0 @@
1
- // ../../utilities/core/src/array.ts
2
- var first = (v) => v[0];
3
- var last = (v) => v[v.length - 1];
4
-
5
- // ../../utilities/dom/src/query.ts
6
- function isDocument(el) {
7
- return el.nodeType === Node.DOCUMENT_NODE;
8
- }
9
- function isWindow(value) {
10
- return value?.toString() === "[object Window]";
11
- }
12
- function isFrame(element) {
13
- return element.localName === "iframe";
14
- }
15
- function getDocument(el) {
16
- if (isWindow(el))
17
- return el.document;
18
- if (isDocument(el))
19
- return el;
20
- return el?.ownerDocument ?? document;
21
- }
22
- function defineDomHelpers(helpers) {
23
- const dom2 = {
24
- getRootNode: (ctx) => ctx.getRootNode?.() ?? document,
25
- getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
26
- getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
27
- getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
28
- getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id),
29
- queryById: (ctx, id) => {
30
- const el = dom2.getById(ctx, id);
31
- if (!el)
32
- throw new Error(`Element with id "${id}" not found.`);
33
- return el;
34
- }
35
- };
36
- return {
37
- ...dom2,
38
- ...helpers
39
- };
40
- }
41
- function isHTMLElement(v) {
42
- return typeof v === "object" && v?.nodeType === Node.ELEMENT_NODE && typeof v?.nodeName === "string";
43
- }
44
- function isVisible(el) {
45
- if (!isHTMLElement(el))
46
- return false;
47
- return el.offsetWidth > 0 || el.offsetHeight > 0 || el.getClientRects().length > 0;
48
- }
49
-
50
- // ../../utilities/dom/src/nodelist.ts
51
- function queryAll(root, selector) {
52
- return Array.from(root?.querySelectorAll(selector) ?? []);
53
- }
54
- function itemById(v, id) {
55
- return v.find((node) => node.id === id);
56
- }
57
- function indexOfId(v, id) {
58
- const item = itemById(v, id);
59
- return item ? v.indexOf(item) : -1;
60
- }
61
- function nextById(v, id, loop = true) {
62
- let idx = indexOfId(v, id);
63
- idx = loop ? (idx + 1) % v.length : Math.min(idx + 1, v.length - 1);
64
- return v[idx];
65
- }
66
- function prevById(v, id, loop = true) {
67
- let idx = indexOfId(v, id);
68
- if (idx === -1)
69
- return loop ? v[v.length - 1] : null;
70
- idx = loop ? (idx - 1 + v.length) % v.length : Math.max(0, idx - 1);
71
- return v[idx];
72
- }
73
-
74
- // src/tabs.dom.ts
75
- var dom = defineDomHelpers({
76
- getRootId: (ctx) => ctx.ids?.root ?? `tabs:${ctx.id}`,
77
- getTablistId: (ctx) => ctx.ids?.tablist ?? `tabs:${ctx.id}:list`,
78
- getContentId: (ctx, id) => ctx.ids?.content ?? `tabs:${ctx.id}:content-${id}`,
79
- getContentGroupId: (ctx) => ctx.ids?.contentGroup ?? `tabs:${ctx.id}:content-group`,
80
- getTriggerId: (ctx, id) => ctx.ids?.trigger ?? `tabs:${ctx.id}:trigger-${id}`,
81
- getIndicatorId: (ctx) => `tabs:${ctx.id}:indicator`,
82
- getTablistEl: (ctx) => dom.getById(ctx, dom.getTablistId(ctx)),
83
- getContentEl: (ctx, id) => dom.getById(ctx, dom.getContentId(ctx, id)),
84
- getTriggerEl: (ctx, id) => dom.getById(ctx, dom.getTriggerId(ctx, id)),
85
- getIndicatorEl: (ctx) => dom.getById(ctx, dom.getIndicatorId(ctx)),
86
- getElements: (ctx) => {
87
- const ownerId = CSS.escape(dom.getTablistId(ctx));
88
- const selector = `[role=tab][data-ownedby='${ownerId}']:not([disabled])`;
89
- return queryAll(dom.getTablistEl(ctx), selector);
90
- },
91
- getFirstEl: (ctx) => first(dom.getElements(ctx)),
92
- getLastEl: (ctx) => last(dom.getElements(ctx)),
93
- getNextEl: (ctx, id) => nextById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
94
- getPrevEl: (ctx, id) => prevById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
95
- getActiveContentEl: (ctx) => {
96
- if (!ctx.value)
97
- return;
98
- const id = dom.getContentId(ctx, ctx.value);
99
- return dom.getById(ctx, id);
100
- },
101
- getRectById: (ctx, id) => {
102
- const empty = {
103
- offsetLeft: 0,
104
- offsetTop: 0,
105
- offsetWidth: 0,
106
- offsetHeight: 0
107
- };
108
- const tab = itemById(dom.getElements(ctx), dom.getTriggerId(ctx, id)) ?? empty;
109
- if (ctx.isVertical) {
110
- return {
111
- top: `${tab.offsetTop}px`,
112
- height: `${tab.offsetHeight}px`
113
- };
114
- }
115
- return {
116
- left: `${tab.offsetLeft}px`,
117
- width: `${tab.offsetWidth}px`
118
- };
119
- }
120
- });
121
-
122
- export {
123
- isFrame,
124
- isHTMLElement,
125
- isVisible,
126
- dom
127
- };