@zag-js/tabs 0.0.0-dev-20230220134212 → 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-4CROPD6E.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-4CROPD6E.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,175 +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
- };
92
- return {
93
- ...dom2,
94
- ...helpers
95
- };
96
- }
97
- function isHTMLElement(v) {
98
- return typeof v === "object" && v?.nodeType === Node.ELEMENT_NODE && typeof v?.nodeName === "string";
99
- }
100
- function isVisible(el) {
101
- if (!isHTMLElement(el))
102
- return false;
103
- return el.offsetWidth > 0 || el.offsetHeight > 0 || el.getClientRects().length > 0;
104
- }
105
-
106
- // ../../utilities/dom/src/focusable.ts
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
-
131
- // ../../utilities/dom/src/keyboard-event.ts
132
- var rtlKeyMap = {
133
- ArrowLeft: "ArrowRight",
134
- ArrowRight: "ArrowLeft"
135
- };
136
- var sameKeyMap = {
137
- Up: "ArrowUp",
138
- Down: "ArrowDown",
139
- Esc: "Escape",
140
- " ": "Space",
141
- ",": "Comma",
142
- Left: "ArrowLeft",
143
- Right: "ArrowRight"
144
- };
145
- function getEventKey(event, options = {}) {
146
- const { dir = "ltr", orientation = "horizontal" } = options;
147
- let { key } = event;
148
- key = sameKeyMap[key] ?? key;
149
- const isRtl = dir === "rtl" && orientation === "horizontal";
150
- if (isRtl && key in rtlKeyMap) {
151
- key = rtlKeyMap[key];
152
- }
153
- return key;
154
- }
155
-
156
- // ../../utilities/dom/src/next-tick.ts
157
- function nextTick(fn) {
158
- const set = /* @__PURE__ */ new Set();
159
- function raf2(fn2) {
160
- const id = globalThis.requestAnimationFrame(fn2);
161
- set.add(() => globalThis.cancelAnimationFrame(id));
162
- }
163
- raf2(() => raf2(fn));
164
- return function cleanup() {
165
- set.forEach(function(fn2) {
166
- fn2();
167
- });
168
- };
169
- }
170
- function raf(fn) {
171
- const id = globalThis.requestAnimationFrame(fn);
172
- return function cleanup() {
173
- globalThis.cancelAnimationFrame(id);
174
- };
175
- }
176
-
177
- // ../../utilities/dom/src/nodelist.ts
178
- function queryAll(root, selector) {
179
- return Array.from(root?.querySelectorAll(selector) ?? []);
180
- }
181
- function itemById(v, id) {
182
- return v.find((node) => node.id === id);
183
- }
184
- function indexOfId(v, id) {
185
- const item = itemById(v, id);
186
- return item ? v.indexOf(item) : -1;
187
- }
188
- function nextById(v, id, loop = true) {
189
- let idx = indexOfId(v, id);
190
- idx = loop ? (idx + 1) % v.length : Math.min(idx + 1, v.length - 1);
191
- return v[idx];
192
- }
193
- function prevById(v, id, loop = true) {
194
- let idx = indexOfId(v, id);
195
- if (idx === -1)
196
- return loop ? v[v.length - 1] : null;
197
- idx = loop ? (idx - 1 + v.length) % v.length : Math.max(0, idx - 1);
198
- return v[idx];
199
- }
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");
200
37
 
201
38
  // src/tabs.dom.ts
202
- 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)({
203
42
  getRootId: (ctx) => ctx.ids?.root ?? `tabs:${ctx.id}`,
204
43
  getTablistId: (ctx) => ctx.ids?.tablist ?? `tabs:${ctx.id}:list`,
205
44
  getContentId: (ctx, id) => ctx.ids?.content ?? `tabs:${ctx.id}:content-${id}`,
@@ -213,12 +52,12 @@ var dom = defineDomHelpers({
213
52
  getElements: (ctx) => {
214
53
  const ownerId = CSS.escape(dom.getTablistId(ctx));
215
54
  const selector = `[role=tab][data-ownedby='${ownerId}']:not([disabled])`;
216
- return queryAll(dom.getTablistEl(ctx), selector);
55
+ return (0, import_dom_query.queryAll)(dom.getTablistEl(ctx), selector);
217
56
  },
218
- getFirstEl: (ctx) => first(dom.getElements(ctx)),
219
- getLastEl: (ctx) => last(dom.getElements(ctx)),
220
- getNextEl: (ctx, id) => nextById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
221
- 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),
222
61
  getActiveContentEl: (ctx) => {
223
62
  if (!ctx.value)
224
63
  return;
@@ -232,7 +71,7 @@ var dom = defineDomHelpers({
232
71
  offsetWidth: 0,
233
72
  offsetHeight: 0
234
73
  };
235
- 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;
236
75
  if (ctx.isVertical) {
237
76
  return {
238
77
  top: `${tab.offsetTop}px`,
@@ -264,14 +103,14 @@ function connect(state, send, normalize) {
264
103
  ...parts.root.attrs,
265
104
  id: dom.getRootId(state.context),
266
105
  "data-orientation": state.context.orientation,
267
- "data-focus": dataAttr(isFocused),
106
+ "data-focus": (0, import_dom_query2.dataAttr)(isFocused),
268
107
  dir: state.context.dir
269
108
  }),
270
109
  tablistProps: normalize.element({
271
110
  ...parts.tablist.attrs,
272
111
  id: dom.getTablistId(state.context),
273
112
  role: "tablist",
274
- "data-focus": dataAttr(isFocused),
113
+ "data-focus": (0, import_dom_query2.dataAttr)(isFocused),
275
114
  "aria-orientation": state.context.orientation,
276
115
  "data-orientation": state.context.orientation,
277
116
  "aria-label": translations.tablistLabel,
@@ -299,7 +138,7 @@ function connect(state, send, normalize) {
299
138
  send({ type: "ENTER", value: state.context.focusedValue });
300
139
  }
301
140
  };
302
- let key = getEventKey(event, state.context);
141
+ let key = (0, import_dom_event.getEventKey)(event, state.context);
303
142
  const exec = keyMap[key];
304
143
  if (exec) {
305
144
  event.preventDefault();
@@ -316,11 +155,11 @@ function connect(state, send, normalize) {
316
155
  type: "button",
317
156
  disabled,
318
157
  "data-orientation": state.context.orientation,
319
- "data-disabled": dataAttr(disabled),
158
+ "data-disabled": (0, import_dom_query2.dataAttr)(disabled),
320
159
  "aria-disabled": disabled,
321
160
  "data-value": value,
322
161
  "aria-selected": selected,
323
- "data-selected": dataAttr(selected),
162
+ "data-selected": (0, import_dom_query2.dataAttr)(selected),
324
163
  "aria-controls": dom.getContentId(state.context, value),
325
164
  "data-ownedby": dom.getTablistId(state.context),
326
165
  id: dom.getTriggerId(state.context, value),
@@ -337,7 +176,7 @@ function connect(state, send, normalize) {
337
176
  onClick(event) {
338
177
  if (disabled)
339
178
  return;
340
- if (isSafari()) {
179
+ if ((0, import_dom_query2.isSafari)()) {
341
180
  event.currentTarget.focus();
342
181
  }
343
182
  send({ type: "TAB_CLICK", value });
@@ -381,9 +220,12 @@ function connect(state, send, normalize) {
381
220
 
382
221
  // src/tabs.machine.ts
383
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");
384
226
  var { not } = import_core.guards;
385
227
  function machine(userContext) {
386
- const ctx = compact(userContext);
228
+ const ctx = (0, import_utils2.compact)(userContext);
387
229
  return (0, import_core.createMachine)(
388
230
  {
389
231
  initial: "idle",
@@ -504,31 +346,31 @@ function machine(userContext) {
504
346
  ctx2.onDelete?.({ value: evt.value });
505
347
  },
506
348
  focusFirstTab(ctx2) {
507
- raf(() => dom.getFirstEl(ctx2)?.focus());
349
+ (0, import_dom_query3.raf)(() => dom.getFirstEl(ctx2)?.focus());
508
350
  },
509
351
  focusLastTab(ctx2) {
510
- raf(() => dom.getLastEl(ctx2)?.focus());
352
+ (0, import_dom_query3.raf)(() => dom.getLastEl(ctx2)?.focus());
511
353
  },
512
354
  focusNextTab(ctx2) {
513
355
  if (!ctx2.focusedValue)
514
356
  return;
515
357
  const next = dom.getNextEl(ctx2, ctx2.focusedValue);
516
- raf(() => next?.focus());
358
+ (0, import_dom_query3.raf)(() => next?.focus());
517
359
  },
518
360
  focusPrevTab(ctx2) {
519
361
  if (!ctx2.focusedValue)
520
362
  return;
521
363
  const prev = dom.getPrevEl(ctx2, ctx2.focusedValue);
522
- raf(() => prev?.focus());
364
+ (0, import_dom_query3.raf)(() => prev?.focus());
523
365
  },
524
366
  setIndicatorRect(ctx2) {
525
- nextTick(() => {
367
+ (0, import_dom_query3.nextTick)(() => {
526
368
  if (!ctx2.isIndicatorRendered || !ctx2.value)
527
369
  return;
528
370
  ctx2.indicatorRect = dom.getRectById(ctx2, ctx2.value);
529
371
  if (ctx2.hasMeasuredRect)
530
372
  return;
531
- nextTick(() => {
373
+ (0, import_dom_query3.nextTick)(() => {
532
374
  ctx2.hasMeasuredRect = true;
533
375
  });
534
376
  });
@@ -552,11 +394,11 @@ function machine(userContext) {
552
394
  },
553
395
  // if tab panel contains focusable elements, remove the tabindex attribute
554
396
  setContentTabIndex(ctx2) {
555
- raf(() => {
397
+ (0, import_dom_query3.raf)(() => {
556
398
  const panel = dom.getActiveContentEl(ctx2);
557
399
  if (!panel)
558
400
  return;
559
- const focusables = getFocusables(panel);
401
+ const focusables = (0, import_tabbable.getFocusables)(panel);
560
402
  if (focusables.length > 0) {
561
403
  panel.removeAttribute("tabindex");
562
404
  } else {
package/dist/index.mjs CHANGED
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  connect
3
- } from "./chunk-IVTIBLCN.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-USN6AU56.mjs";
10
- import "./chunk-4CROPD6E.mjs";
9
+ } from "./chunk-JG2VX4ST.mjs";
10
+ import "./chunk-5ZMNIWHF.mjs";
11
11
  export {
12
12
  anatomy,
13
13
  connect,
@@ -23,103 +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
- };
69
- return {
70
- ...dom2,
71
- ...helpers
72
- };
73
- }
74
-
75
- // ../../utilities/dom/src/keyboard-event.ts
76
- var rtlKeyMap = {
77
- ArrowLeft: "ArrowRight",
78
- ArrowRight: "ArrowLeft"
79
- };
80
- var sameKeyMap = {
81
- Up: "ArrowUp",
82
- Down: "ArrowDown",
83
- Esc: "Escape",
84
- " ": "Space",
85
- ",": "Comma",
86
- Left: "ArrowLeft",
87
- Right: "ArrowRight"
88
- };
89
- function getEventKey(event, options = {}) {
90
- const { dir = "ltr", orientation = "horizontal" } = options;
91
- let { key } = event;
92
- key = sameKeyMap[key] ?? key;
93
- const isRtl = dir === "rtl" && orientation === "horizontal";
94
- if (isRtl && key in rtlKeyMap) {
95
- key = rtlKeyMap[key];
96
- }
97
- return key;
98
- }
99
-
100
- // ../../utilities/dom/src/nodelist.ts
101
- function queryAll(root, selector) {
102
- return Array.from(root?.querySelectorAll(selector) ?? []);
103
- }
104
- function itemById(v, id) {
105
- return v.find((node) => node.id === id);
106
- }
107
- function indexOfId(v, id) {
108
- const item = itemById(v, id);
109
- return item ? v.indexOf(item) : -1;
110
- }
111
- function nextById(v, id, loop = true) {
112
- let idx = indexOfId(v, id);
113
- idx = loop ? (idx + 1) % v.length : Math.min(idx + 1, v.length - 1);
114
- return v[idx];
115
- }
116
- function prevById(v, id, loop = true) {
117
- let idx = indexOfId(v, id);
118
- if (idx === -1)
119
- return loop ? v[v.length - 1] : null;
120
- idx = loop ? (idx - 1 + v.length) % v.length : Math.max(0, idx - 1);
121
- return v[idx];
122
- }
26
+ var import_dom_event = require("@zag-js/dom-event");
27
+ var import_dom_query2 = require("@zag-js/dom-query");
123
28
 
124
29
  // src/tabs.anatomy.ts
125
30
  var import_anatomy = require("@zag-js/anatomy");
@@ -127,7 +32,9 @@ var anatomy = (0, import_anatomy.createAnatomy)("tabs").parts("root", "tablist",
127
32
  var parts = anatomy.build();
128
33
 
129
34
  // src/tabs.dom.ts
130
- 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)({
131
38
  getRootId: (ctx) => ctx.ids?.root ?? `tabs:${ctx.id}`,
132
39
  getTablistId: (ctx) => ctx.ids?.tablist ?? `tabs:${ctx.id}:list`,
133
40
  getContentId: (ctx, id) => ctx.ids?.content ?? `tabs:${ctx.id}:content-${id}`,
@@ -141,12 +48,12 @@ var dom = defineDomHelpers({
141
48
  getElements: (ctx) => {
142
49
  const ownerId = CSS.escape(dom.getTablistId(ctx));
143
50
  const selector = `[role=tab][data-ownedby='${ownerId}']:not([disabled])`;
144
- return queryAll(dom.getTablistEl(ctx), selector);
51
+ return (0, import_dom_query.queryAll)(dom.getTablistEl(ctx), selector);
145
52
  },
146
- getFirstEl: (ctx) => first(dom.getElements(ctx)),
147
- getLastEl: (ctx) => last(dom.getElements(ctx)),
148
- getNextEl: (ctx, id) => nextById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
149
- 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),
150
57
  getActiveContentEl: (ctx) => {
151
58
  if (!ctx.value)
152
59
  return;
@@ -160,7 +67,7 @@ var dom = defineDomHelpers({
160
67
  offsetWidth: 0,
161
68
  offsetHeight: 0
162
69
  };
163
- 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;
164
71
  if (ctx.isVertical) {
165
72
  return {
166
73
  top: `${tab.offsetTop}px`,
@@ -192,14 +99,14 @@ function connect(state, send, normalize) {
192
99
  ...parts.root.attrs,
193
100
  id: dom.getRootId(state.context),
194
101
  "data-orientation": state.context.orientation,
195
- "data-focus": dataAttr(isFocused),
102
+ "data-focus": (0, import_dom_query2.dataAttr)(isFocused),
196
103
  dir: state.context.dir
197
104
  }),
198
105
  tablistProps: normalize.element({
199
106
  ...parts.tablist.attrs,
200
107
  id: dom.getTablistId(state.context),
201
108
  role: "tablist",
202
- "data-focus": dataAttr(isFocused),
109
+ "data-focus": (0, import_dom_query2.dataAttr)(isFocused),
203
110
  "aria-orientation": state.context.orientation,
204
111
  "data-orientation": state.context.orientation,
205
112
  "aria-label": translations.tablistLabel,
@@ -227,7 +134,7 @@ function connect(state, send, normalize) {
227
134
  send({ type: "ENTER", value: state.context.focusedValue });
228
135
  }
229
136
  };
230
- let key = getEventKey(event, state.context);
137
+ let key = (0, import_dom_event.getEventKey)(event, state.context);
231
138
  const exec = keyMap[key];
232
139
  if (exec) {
233
140
  event.preventDefault();
@@ -244,11 +151,11 @@ function connect(state, send, normalize) {
244
151
  type: "button",
245
152
  disabled,
246
153
  "data-orientation": state.context.orientation,
247
- "data-disabled": dataAttr(disabled),
154
+ "data-disabled": (0, import_dom_query2.dataAttr)(disabled),
248
155
  "aria-disabled": disabled,
249
156
  "data-value": value,
250
157
  "aria-selected": selected,
251
- "data-selected": dataAttr(selected),
158
+ "data-selected": (0, import_dom_query2.dataAttr)(selected),
252
159
  "aria-controls": dom.getContentId(state.context, value),
253
160
  "data-ownedby": dom.getTablistId(state.context),
254
161
  id: dom.getTriggerId(state.context, value),
@@ -265,7 +172,7 @@ function connect(state, send, normalize) {
265
172
  onClick(event) {
266
173
  if (disabled)
267
174
  return;
268
- if (isSafari()) {
175
+ if ((0, import_dom_query2.isSafari)()) {
269
176
  event.currentTarget.focus();
270
177
  }
271
178
  send({ type: "TAB_CLICK", value });
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  connect
3
- } from "./chunk-IVTIBLCN.mjs";
3
+ } from "./chunk-MMG5KHSN.mjs";
4
4
  import "./chunk-S2KW2DT4.mjs";
5
- import "./chunk-4CROPD6E.mjs";
5
+ import "./chunk-5ZMNIWHF.mjs";
6
6
  export {
7
7
  connect
8
8
  };
@@ -4,20 +4,23 @@ 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 extends HTMLElement = HTMLElement>(ctx: {
22
+ getRootNode?: (() => Document | Node | ShadowRoot) | undefined;
23
+ }, id: string) => T_1;
21
24
  } & {
22
25
  getRootId: (ctx: MachineContext) => string;
23
26
  getTablistId: (ctx: MachineContext) => string;
package/dist/tabs.dom.js CHANGED
@@ -23,65 +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
- };
53
- return {
54
- ...dom2,
55
- ...helpers
56
- };
57
- }
58
-
59
- // ../../utilities/dom/src/nodelist.ts
60
- function queryAll(root, selector) {
61
- return Array.from(root?.querySelectorAll(selector) ?? []);
62
- }
63
- function itemById(v, id) {
64
- return v.find((node) => node.id === id);
65
- }
66
- function indexOfId(v, id) {
67
- const item = itemById(v, id);
68
- return item ? v.indexOf(item) : -1;
69
- }
70
- function nextById(v, id, loop = true) {
71
- let idx = indexOfId(v, id);
72
- idx = loop ? (idx + 1) % v.length : Math.min(idx + 1, v.length - 1);
73
- return v[idx];
74
- }
75
- function prevById(v, id, loop = true) {
76
- let idx = indexOfId(v, id);
77
- if (idx === -1)
78
- return loop ? v[v.length - 1] : null;
79
- idx = loop ? (idx - 1 + v.length) % v.length : Math.max(0, idx - 1);
80
- return v[idx];
81
- }
82
-
83
- // src/tabs.dom.ts
84
- 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)({
85
29
  getRootId: (ctx) => ctx.ids?.root ?? `tabs:${ctx.id}`,
86
30
  getTablistId: (ctx) => ctx.ids?.tablist ?? `tabs:${ctx.id}:list`,
87
31
  getContentId: (ctx, id) => ctx.ids?.content ?? `tabs:${ctx.id}:content-${id}`,
@@ -95,12 +39,12 @@ var dom = defineDomHelpers({
95
39
  getElements: (ctx) => {
96
40
  const ownerId = CSS.escape(dom.getTablistId(ctx));
97
41
  const selector = `[role=tab][data-ownedby='${ownerId}']:not([disabled])`;
98
- return queryAll(dom.getTablistEl(ctx), selector);
42
+ return (0, import_dom_query.queryAll)(dom.getTablistEl(ctx), selector);
99
43
  },
100
- getFirstEl: (ctx) => first(dom.getElements(ctx)),
101
- getLastEl: (ctx) => last(dom.getElements(ctx)),
102
- getNextEl: (ctx, id) => nextById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
103
- 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),
104
48
  getActiveContentEl: (ctx) => {
105
49
  if (!ctx.value)
106
50
  return;
@@ -114,7 +58,7 @@ var dom = defineDomHelpers({
114
58
  offsetWidth: 0,
115
59
  offsetHeight: 0
116
60
  };
117
- 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;
118
62
  if (ctx.isVertical) {
119
63
  return {
120
64
  top: `${tab.offsetTop}px`,
package/dist/tabs.dom.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  dom
3
- } from "./chunk-4CROPD6E.mjs";
3
+ } from "./chunk-5ZMNIWHF.mjs";
4
4
  export {
5
5
  dom
6
6
  };
@@ -24,135 +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
- };
70
- return {
71
- ...dom2,
72
- ...helpers
73
- };
74
- }
75
- function isHTMLElement(v) {
76
- return typeof v === "object" && v?.nodeType === Node.ELEMENT_NODE && typeof v?.nodeName === "string";
77
- }
78
- function isVisible(el) {
79
- if (!isHTMLElement(el))
80
- return false;
81
- return el.offsetWidth > 0 || el.offsetHeight > 0 || el.getClientRects().length > 0;
82
- }
83
-
84
- // ../../utilities/dom/src/focusable.ts
85
- 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";
86
- var getFocusables = (container, includeContainer = false) => {
87
- if (!container)
88
- return [];
89
- const elements = Array.from(container.querySelectorAll(focusableSelector));
90
- const include = includeContainer == true || includeContainer == "if-empty" && elements.length === 0;
91
- if (include && isHTMLElement(container) && isFocusable(container)) {
92
- elements.unshift(container);
93
- }
94
- const focusableElements = elements.filter(isFocusable);
95
- focusableElements.forEach((element, i) => {
96
- if (isFrame(element) && element.contentDocument) {
97
- const frameBody = element.contentDocument.body;
98
- focusableElements.splice(i, 1, ...getFocusables(frameBody));
99
- }
100
- });
101
- return focusableElements;
102
- };
103
- function isFocusable(element) {
104
- if (!element)
105
- return false;
106
- return element.matches(focusableSelector) && isVisible(element);
107
- }
108
-
109
- // ../../utilities/dom/src/next-tick.ts
110
- function nextTick(fn) {
111
- const set = /* @__PURE__ */ new Set();
112
- function raf2(fn2) {
113
- const id = globalThis.requestAnimationFrame(fn2);
114
- set.add(() => globalThis.cancelAnimationFrame(id));
115
- }
116
- raf2(() => raf2(fn));
117
- return function cleanup() {
118
- set.forEach(function(fn2) {
119
- fn2();
120
- });
121
- };
122
- }
123
- function raf(fn) {
124
- const id = globalThis.requestAnimationFrame(fn);
125
- return function cleanup() {
126
- globalThis.cancelAnimationFrame(id);
127
- };
128
- }
129
-
130
- // ../../utilities/dom/src/nodelist.ts
131
- function queryAll(root, selector) {
132
- return Array.from(root?.querySelectorAll(selector) ?? []);
133
- }
134
- function itemById(v, id) {
135
- return v.find((node) => node.id === id);
136
- }
137
- function indexOfId(v, id) {
138
- const item = itemById(v, id);
139
- return item ? v.indexOf(item) : -1;
140
- }
141
- function nextById(v, id, loop = true) {
142
- let idx = indexOfId(v, id);
143
- idx = loop ? (idx + 1) % v.length : Math.min(idx + 1, v.length - 1);
144
- return v[idx];
145
- }
146
- function prevById(v, id, loop = true) {
147
- let idx = indexOfId(v, id);
148
- if (idx === -1)
149
- return loop ? v[v.length - 1] : null;
150
- idx = loop ? (idx - 1 + v.length) % v.length : Math.max(0, idx - 1);
151
- return v[idx];
152
- }
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");
153
30
 
154
31
  // src/tabs.dom.ts
155
- 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)({
156
35
  getRootId: (ctx) => ctx.ids?.root ?? `tabs:${ctx.id}`,
157
36
  getTablistId: (ctx) => ctx.ids?.tablist ?? `tabs:${ctx.id}:list`,
158
37
  getContentId: (ctx, id) => ctx.ids?.content ?? `tabs:${ctx.id}:content-${id}`,
@@ -166,12 +45,12 @@ var dom = defineDomHelpers({
166
45
  getElements: (ctx) => {
167
46
  const ownerId = CSS.escape(dom.getTablistId(ctx));
168
47
  const selector = `[role=tab][data-ownedby='${ownerId}']:not([disabled])`;
169
- return queryAll(dom.getTablistEl(ctx), selector);
48
+ return (0, import_dom_query.queryAll)(dom.getTablistEl(ctx), selector);
170
49
  },
171
- getFirstEl: (ctx) => first(dom.getElements(ctx)),
172
- getLastEl: (ctx) => last(dom.getElements(ctx)),
173
- getNextEl: (ctx, id) => nextById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
174
- 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),
175
54
  getActiveContentEl: (ctx) => {
176
55
  if (!ctx.value)
177
56
  return;
@@ -185,7 +64,7 @@ var dom = defineDomHelpers({
185
64
  offsetWidth: 0,
186
65
  offsetHeight: 0
187
66
  };
188
- 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;
189
68
  if (ctx.isVertical) {
190
69
  return {
191
70
  top: `${tab.offsetTop}px`,
@@ -202,7 +81,7 @@ var dom = defineDomHelpers({
202
81
  // src/tabs.machine.ts
203
82
  var { not } = import_core.guards;
204
83
  function machine(userContext) {
205
- const ctx = compact(userContext);
84
+ const ctx = (0, import_utils2.compact)(userContext);
206
85
  return (0, import_core.createMachine)(
207
86
  {
208
87
  initial: "idle",
@@ -323,31 +202,31 @@ function machine(userContext) {
323
202
  ctx2.onDelete?.({ value: evt.value });
324
203
  },
325
204
  focusFirstTab(ctx2) {
326
- raf(() => dom.getFirstEl(ctx2)?.focus());
205
+ (0, import_dom_query2.raf)(() => dom.getFirstEl(ctx2)?.focus());
327
206
  },
328
207
  focusLastTab(ctx2) {
329
- raf(() => dom.getLastEl(ctx2)?.focus());
208
+ (0, import_dom_query2.raf)(() => dom.getLastEl(ctx2)?.focus());
330
209
  },
331
210
  focusNextTab(ctx2) {
332
211
  if (!ctx2.focusedValue)
333
212
  return;
334
213
  const next = dom.getNextEl(ctx2, ctx2.focusedValue);
335
- raf(() => next?.focus());
214
+ (0, import_dom_query2.raf)(() => next?.focus());
336
215
  },
337
216
  focusPrevTab(ctx2) {
338
217
  if (!ctx2.focusedValue)
339
218
  return;
340
219
  const prev = dom.getPrevEl(ctx2, ctx2.focusedValue);
341
- raf(() => prev?.focus());
220
+ (0, import_dom_query2.raf)(() => prev?.focus());
342
221
  },
343
222
  setIndicatorRect(ctx2) {
344
- nextTick(() => {
223
+ (0, import_dom_query2.nextTick)(() => {
345
224
  if (!ctx2.isIndicatorRendered || !ctx2.value)
346
225
  return;
347
226
  ctx2.indicatorRect = dom.getRectById(ctx2, ctx2.value);
348
227
  if (ctx2.hasMeasuredRect)
349
228
  return;
350
- nextTick(() => {
229
+ (0, import_dom_query2.nextTick)(() => {
351
230
  ctx2.hasMeasuredRect = true;
352
231
  });
353
232
  });
@@ -371,11 +250,11 @@ function machine(userContext) {
371
250
  },
372
251
  // if tab panel contains focusable elements, remove the tabindex attribute
373
252
  setContentTabIndex(ctx2) {
374
- raf(() => {
253
+ (0, import_dom_query2.raf)(() => {
375
254
  const panel = dom.getActiveContentEl(ctx2);
376
255
  if (!panel)
377
256
  return;
378
- const focusables = getFocusables(panel);
257
+ const focusables = (0, import_tabbable.getFocusables)(panel);
379
258
  if (focusables.length > 0) {
380
259
  panel.removeAttribute("tabindex");
381
260
  } else {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  machine
3
- } from "./chunk-USN6AU56.mjs";
4
- import "./chunk-4CROPD6E.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-20230220134212",
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-20230220134212",
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,121 +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
- };
30
- return {
31
- ...dom2,
32
- ...helpers
33
- };
34
- }
35
- function isHTMLElement(v) {
36
- return typeof v === "object" && v?.nodeType === Node.ELEMENT_NODE && typeof v?.nodeName === "string";
37
- }
38
- function isVisible(el) {
39
- if (!isHTMLElement(el))
40
- return false;
41
- return el.offsetWidth > 0 || el.offsetHeight > 0 || el.getClientRects().length > 0;
42
- }
43
-
44
- // ../../utilities/dom/src/nodelist.ts
45
- function queryAll(root, selector) {
46
- return Array.from(root?.querySelectorAll(selector) ?? []);
47
- }
48
- function itemById(v, id) {
49
- return v.find((node) => node.id === id);
50
- }
51
- function indexOfId(v, id) {
52
- const item = itemById(v, id);
53
- return item ? v.indexOf(item) : -1;
54
- }
55
- function nextById(v, id, loop = true) {
56
- let idx = indexOfId(v, id);
57
- idx = loop ? (idx + 1) % v.length : Math.min(idx + 1, v.length - 1);
58
- return v[idx];
59
- }
60
- function prevById(v, id, loop = true) {
61
- let idx = indexOfId(v, id);
62
- if (idx === -1)
63
- return loop ? v[v.length - 1] : null;
64
- idx = loop ? (idx - 1 + v.length) % v.length : Math.max(0, idx - 1);
65
- return v[idx];
66
- }
67
-
68
- // src/tabs.dom.ts
69
- var dom = defineDomHelpers({
70
- getRootId: (ctx) => ctx.ids?.root ?? `tabs:${ctx.id}`,
71
- getTablistId: (ctx) => ctx.ids?.tablist ?? `tabs:${ctx.id}:list`,
72
- getContentId: (ctx, id) => ctx.ids?.content ?? `tabs:${ctx.id}:content-${id}`,
73
- getContentGroupId: (ctx) => ctx.ids?.contentGroup ?? `tabs:${ctx.id}:content-group`,
74
- getTriggerId: (ctx, id) => ctx.ids?.trigger ?? `tabs:${ctx.id}:trigger-${id}`,
75
- getIndicatorId: (ctx) => `tabs:${ctx.id}:indicator`,
76
- getTablistEl: (ctx) => dom.getById(ctx, dom.getTablistId(ctx)),
77
- getContentEl: (ctx, id) => dom.getById(ctx, dom.getContentId(ctx, id)),
78
- getTriggerEl: (ctx, id) => dom.getById(ctx, dom.getTriggerId(ctx, id)),
79
- getIndicatorEl: (ctx) => dom.getById(ctx, dom.getIndicatorId(ctx)),
80
- getElements: (ctx) => {
81
- const ownerId = CSS.escape(dom.getTablistId(ctx));
82
- const selector = `[role=tab][data-ownedby='${ownerId}']:not([disabled])`;
83
- return queryAll(dom.getTablistEl(ctx), selector);
84
- },
85
- getFirstEl: (ctx) => first(dom.getElements(ctx)),
86
- getLastEl: (ctx) => last(dom.getElements(ctx)),
87
- getNextEl: (ctx, id) => nextById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
88
- getPrevEl: (ctx, id) => prevById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
89
- getActiveContentEl: (ctx) => {
90
- if (!ctx.value)
91
- return;
92
- const id = dom.getContentId(ctx, ctx.value);
93
- return dom.getById(ctx, id);
94
- },
95
- getRectById: (ctx, id) => {
96
- const empty = {
97
- offsetLeft: 0,
98
- offsetTop: 0,
99
- offsetWidth: 0,
100
- offsetHeight: 0
101
- };
102
- const tab = itemById(dom.getElements(ctx), dom.getTriggerId(ctx, id)) ?? empty;
103
- if (ctx.isVertical) {
104
- return {
105
- top: `${tab.offsetTop}px`,
106
- height: `${tab.offsetHeight}px`
107
- };
108
- }
109
- return {
110
- left: `${tab.offsetLeft}px`,
111
- width: `${tab.offsetWidth}px`
112
- };
113
- }
114
- });
115
-
116
- export {
117
- isFrame,
118
- isHTMLElement,
119
- isVisible,
120
- dom
121
- };