@zag-js/tabs 1.34.1 → 1.35.1

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,230 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/tabs.connect.ts
31
+ var tabs_connect_exports = {};
32
+ __export(tabs_connect_exports, {
33
+ connect: () => connect
34
+ });
35
+ module.exports = __toCommonJS(tabs_connect_exports);
36
+ var import_dom_query = require("@zag-js/dom-query");
37
+ var import_utils = require("@zag-js/utils");
38
+ var import_tabs = require("./tabs.anatomy.cjs");
39
+ var dom = __toESM(require("./tabs.dom.cjs"));
40
+ function connect(service, normalize) {
41
+ const { state, send, context, prop, scope } = service;
42
+ const translations = prop("translations");
43
+ const focused = state.matches("focused");
44
+ const isVertical = prop("orientation") === "vertical";
45
+ const isHorizontal = prop("orientation") === "horizontal";
46
+ const composite = prop("composite");
47
+ function getTriggerState(props) {
48
+ return {
49
+ selected: context.get("value") === props.value,
50
+ focused: context.get("focusedValue") === props.value,
51
+ disabled: !!props.disabled
52
+ };
53
+ }
54
+ return {
55
+ value: context.get("value"),
56
+ focusedValue: context.get("focusedValue"),
57
+ setValue(value) {
58
+ send({ type: "SET_VALUE", value });
59
+ },
60
+ clearValue() {
61
+ send({ type: "CLEAR_VALUE" });
62
+ },
63
+ setIndicatorRect(value) {
64
+ const id = dom.getTriggerId(scope, value);
65
+ send({ type: "SET_INDICATOR_RECT", id });
66
+ },
67
+ syncTabIndex() {
68
+ send({ type: "SYNC_TAB_INDEX" });
69
+ },
70
+ selectNext(fromValue) {
71
+ send({ type: "TAB_FOCUS", value: fromValue, src: "selectNext" });
72
+ send({ type: "ARROW_NEXT", src: "selectNext" });
73
+ },
74
+ selectPrev(fromValue) {
75
+ send({ type: "TAB_FOCUS", value: fromValue, src: "selectPrev" });
76
+ send({ type: "ARROW_PREV", src: "selectPrev" });
77
+ },
78
+ focus() {
79
+ const value = context.get("value");
80
+ if (!value) return;
81
+ dom.getTriggerEl(scope, value)?.focus();
82
+ },
83
+ getRootProps() {
84
+ return normalize.element({
85
+ ...import_tabs.parts.root.attrs,
86
+ id: dom.getRootId(scope),
87
+ "data-orientation": prop("orientation"),
88
+ "data-focus": (0, import_dom_query.dataAttr)(focused),
89
+ dir: prop("dir")
90
+ });
91
+ },
92
+ getListProps() {
93
+ return normalize.element({
94
+ ...import_tabs.parts.list.attrs,
95
+ id: dom.getListId(scope),
96
+ role: "tablist",
97
+ dir: prop("dir"),
98
+ "data-focus": (0, import_dom_query.dataAttr)(focused),
99
+ "aria-orientation": prop("orientation"),
100
+ "data-orientation": prop("orientation"),
101
+ "aria-label": translations?.listLabel,
102
+ onKeyDown(event) {
103
+ if (event.defaultPrevented) return;
104
+ if ((0, import_dom_query.isComposingEvent)(event)) return;
105
+ if (!(0, import_dom_query.contains)(event.currentTarget, (0, import_dom_query.getEventTarget)(event))) return;
106
+ const keyMap = {
107
+ ArrowDown() {
108
+ if (isHorizontal) return;
109
+ send({ type: "ARROW_NEXT", key: "ArrowDown" });
110
+ },
111
+ ArrowUp() {
112
+ if (isHorizontal) return;
113
+ send({ type: "ARROW_PREV", key: "ArrowUp" });
114
+ },
115
+ ArrowLeft() {
116
+ if (isVertical) return;
117
+ send({ type: "ARROW_PREV", key: "ArrowLeft" });
118
+ },
119
+ ArrowRight() {
120
+ if (isVertical) return;
121
+ send({ type: "ARROW_NEXT", key: "ArrowRight" });
122
+ },
123
+ Home() {
124
+ send({ type: "HOME" });
125
+ },
126
+ End() {
127
+ send({ type: "END" });
128
+ }
129
+ };
130
+ let key = (0, import_dom_query.getEventKey)(event, {
131
+ dir: prop("dir"),
132
+ orientation: prop("orientation")
133
+ });
134
+ const exec = keyMap[key];
135
+ if (exec) {
136
+ event.preventDefault();
137
+ exec(event);
138
+ return;
139
+ }
140
+ }
141
+ });
142
+ },
143
+ getTriggerState,
144
+ getTriggerProps(props) {
145
+ const { value, disabled } = props;
146
+ const triggerState = getTriggerState(props);
147
+ return normalize.button({
148
+ ...import_tabs.parts.trigger.attrs,
149
+ role: "tab",
150
+ type: "button",
151
+ disabled,
152
+ dir: prop("dir"),
153
+ "data-orientation": prop("orientation"),
154
+ "data-disabled": (0, import_dom_query.dataAttr)(disabled),
155
+ "aria-disabled": disabled,
156
+ "data-value": value,
157
+ "aria-selected": triggerState.selected,
158
+ "data-selected": (0, import_dom_query.dataAttr)(triggerState.selected),
159
+ "data-focus": (0, import_dom_query.dataAttr)(triggerState.focused),
160
+ "aria-controls": triggerState.selected ? dom.getContentId(scope, value) : void 0,
161
+ "data-ownedby": dom.getListId(scope),
162
+ "data-ssr": (0, import_dom_query.dataAttr)(context.get("ssr")),
163
+ id: dom.getTriggerId(scope, value),
164
+ tabIndex: triggerState.selected && composite ? 0 : -1,
165
+ onFocus() {
166
+ send({ type: "TAB_FOCUS", value });
167
+ },
168
+ onBlur(event) {
169
+ const target = event.relatedTarget;
170
+ if (target?.getAttribute("role") !== "tab") {
171
+ send({ type: "TAB_BLUR" });
172
+ }
173
+ },
174
+ onClick(event) {
175
+ if (event.defaultPrevented) return;
176
+ if ((0, import_dom_query.isOpeningInNewTab)(event)) return;
177
+ if (disabled) return;
178
+ if ((0, import_dom_query.isSafari)()) {
179
+ event.currentTarget.focus();
180
+ }
181
+ send({ type: "TAB_CLICK", value });
182
+ }
183
+ });
184
+ },
185
+ getContentProps(props) {
186
+ const { value } = props;
187
+ const selected = context.get("value") === value;
188
+ return normalize.element({
189
+ ...import_tabs.parts.content.attrs,
190
+ dir: prop("dir"),
191
+ id: dom.getContentId(scope, value),
192
+ tabIndex: composite ? 0 : -1,
193
+ "aria-labelledby": dom.getTriggerId(scope, value),
194
+ role: "tabpanel",
195
+ "data-ownedby": dom.getListId(scope),
196
+ "data-selected": (0, import_dom_query.dataAttr)(selected),
197
+ "data-orientation": prop("orientation"),
198
+ hidden: !selected
199
+ });
200
+ },
201
+ getIndicatorProps() {
202
+ const rect = context.get("indicatorRect");
203
+ const rectIsEmpty = rect == null || rect.width === 0 && rect.height === 0 && rect.x === 0 && rect.y === 0;
204
+ return normalize.element({
205
+ id: dom.getIndicatorId(scope),
206
+ ...import_tabs.parts.indicator.attrs,
207
+ dir: prop("dir"),
208
+ "data-orientation": prop("orientation"),
209
+ hidden: rectIsEmpty,
210
+ style: {
211
+ "--transition-property": "left, right, top, bottom, width, height",
212
+ "--left": (0, import_utils.toPx)(rect?.x),
213
+ "--top": (0, import_utils.toPx)(rect?.y),
214
+ "--width": (0, import_utils.toPx)(rect?.width),
215
+ "--height": (0, import_utils.toPx)(rect?.height),
216
+ position: "absolute",
217
+ willChange: "var(--transition-property)",
218
+ transitionProperty: "var(--transition-property)",
219
+ transitionDuration: "var(--transition-duration, 150ms)",
220
+ transitionTimingFunction: "var(--transition-timing-function)",
221
+ [isHorizontal ? "left" : "top"]: isHorizontal ? "var(--left)" : "var(--top)"
222
+ }
223
+ });
224
+ }
225
+ };
226
+ }
227
+ // Annotate the CommonJS export names for ESM import in node:
228
+ 0 && (module.exports = {
229
+ connect
230
+ });
@@ -0,0 +1,203 @@
1
+ // src/tabs.connect.ts
2
+ import {
3
+ contains,
4
+ dataAttr,
5
+ getEventKey,
6
+ getEventTarget,
7
+ isComposingEvent,
8
+ isOpeningInNewTab,
9
+ isSafari
10
+ } from "@zag-js/dom-query";
11
+ import { toPx } from "@zag-js/utils";
12
+ import { parts } from "./tabs.anatomy.mjs";
13
+ import * as dom from "./tabs.dom.mjs";
14
+ function connect(service, normalize) {
15
+ const { state, send, context, prop, scope } = service;
16
+ const translations = prop("translations");
17
+ const focused = state.matches("focused");
18
+ const isVertical = prop("orientation") === "vertical";
19
+ const isHorizontal = prop("orientation") === "horizontal";
20
+ const composite = prop("composite");
21
+ function getTriggerState(props) {
22
+ return {
23
+ selected: context.get("value") === props.value,
24
+ focused: context.get("focusedValue") === props.value,
25
+ disabled: !!props.disabled
26
+ };
27
+ }
28
+ return {
29
+ value: context.get("value"),
30
+ focusedValue: context.get("focusedValue"),
31
+ setValue(value) {
32
+ send({ type: "SET_VALUE", value });
33
+ },
34
+ clearValue() {
35
+ send({ type: "CLEAR_VALUE" });
36
+ },
37
+ setIndicatorRect(value) {
38
+ const id = dom.getTriggerId(scope, value);
39
+ send({ type: "SET_INDICATOR_RECT", id });
40
+ },
41
+ syncTabIndex() {
42
+ send({ type: "SYNC_TAB_INDEX" });
43
+ },
44
+ selectNext(fromValue) {
45
+ send({ type: "TAB_FOCUS", value: fromValue, src: "selectNext" });
46
+ send({ type: "ARROW_NEXT", src: "selectNext" });
47
+ },
48
+ selectPrev(fromValue) {
49
+ send({ type: "TAB_FOCUS", value: fromValue, src: "selectPrev" });
50
+ send({ type: "ARROW_PREV", src: "selectPrev" });
51
+ },
52
+ focus() {
53
+ const value = context.get("value");
54
+ if (!value) return;
55
+ dom.getTriggerEl(scope, value)?.focus();
56
+ },
57
+ getRootProps() {
58
+ return normalize.element({
59
+ ...parts.root.attrs,
60
+ id: dom.getRootId(scope),
61
+ "data-orientation": prop("orientation"),
62
+ "data-focus": dataAttr(focused),
63
+ dir: prop("dir")
64
+ });
65
+ },
66
+ getListProps() {
67
+ return normalize.element({
68
+ ...parts.list.attrs,
69
+ id: dom.getListId(scope),
70
+ role: "tablist",
71
+ dir: prop("dir"),
72
+ "data-focus": dataAttr(focused),
73
+ "aria-orientation": prop("orientation"),
74
+ "data-orientation": prop("orientation"),
75
+ "aria-label": translations?.listLabel,
76
+ onKeyDown(event) {
77
+ if (event.defaultPrevented) return;
78
+ if (isComposingEvent(event)) return;
79
+ if (!contains(event.currentTarget, getEventTarget(event))) return;
80
+ const keyMap = {
81
+ ArrowDown() {
82
+ if (isHorizontal) return;
83
+ send({ type: "ARROW_NEXT", key: "ArrowDown" });
84
+ },
85
+ ArrowUp() {
86
+ if (isHorizontal) return;
87
+ send({ type: "ARROW_PREV", key: "ArrowUp" });
88
+ },
89
+ ArrowLeft() {
90
+ if (isVertical) return;
91
+ send({ type: "ARROW_PREV", key: "ArrowLeft" });
92
+ },
93
+ ArrowRight() {
94
+ if (isVertical) return;
95
+ send({ type: "ARROW_NEXT", key: "ArrowRight" });
96
+ },
97
+ Home() {
98
+ send({ type: "HOME" });
99
+ },
100
+ End() {
101
+ send({ type: "END" });
102
+ }
103
+ };
104
+ let key = getEventKey(event, {
105
+ dir: prop("dir"),
106
+ orientation: prop("orientation")
107
+ });
108
+ const exec = keyMap[key];
109
+ if (exec) {
110
+ event.preventDefault();
111
+ exec(event);
112
+ return;
113
+ }
114
+ }
115
+ });
116
+ },
117
+ getTriggerState,
118
+ getTriggerProps(props) {
119
+ const { value, disabled } = props;
120
+ const triggerState = getTriggerState(props);
121
+ return normalize.button({
122
+ ...parts.trigger.attrs,
123
+ role: "tab",
124
+ type: "button",
125
+ disabled,
126
+ dir: prop("dir"),
127
+ "data-orientation": prop("orientation"),
128
+ "data-disabled": dataAttr(disabled),
129
+ "aria-disabled": disabled,
130
+ "data-value": value,
131
+ "aria-selected": triggerState.selected,
132
+ "data-selected": dataAttr(triggerState.selected),
133
+ "data-focus": dataAttr(triggerState.focused),
134
+ "aria-controls": triggerState.selected ? dom.getContentId(scope, value) : void 0,
135
+ "data-ownedby": dom.getListId(scope),
136
+ "data-ssr": dataAttr(context.get("ssr")),
137
+ id: dom.getTriggerId(scope, value),
138
+ tabIndex: triggerState.selected && composite ? 0 : -1,
139
+ onFocus() {
140
+ send({ type: "TAB_FOCUS", value });
141
+ },
142
+ onBlur(event) {
143
+ const target = event.relatedTarget;
144
+ if (target?.getAttribute("role") !== "tab") {
145
+ send({ type: "TAB_BLUR" });
146
+ }
147
+ },
148
+ onClick(event) {
149
+ if (event.defaultPrevented) return;
150
+ if (isOpeningInNewTab(event)) return;
151
+ if (disabled) return;
152
+ if (isSafari()) {
153
+ event.currentTarget.focus();
154
+ }
155
+ send({ type: "TAB_CLICK", value });
156
+ }
157
+ });
158
+ },
159
+ getContentProps(props) {
160
+ const { value } = props;
161
+ const selected = context.get("value") === value;
162
+ return normalize.element({
163
+ ...parts.content.attrs,
164
+ dir: prop("dir"),
165
+ id: dom.getContentId(scope, value),
166
+ tabIndex: composite ? 0 : -1,
167
+ "aria-labelledby": dom.getTriggerId(scope, value),
168
+ role: "tabpanel",
169
+ "data-ownedby": dom.getListId(scope),
170
+ "data-selected": dataAttr(selected),
171
+ "data-orientation": prop("orientation"),
172
+ hidden: !selected
173
+ });
174
+ },
175
+ getIndicatorProps() {
176
+ const rect = context.get("indicatorRect");
177
+ const rectIsEmpty = rect == null || rect.width === 0 && rect.height === 0 && rect.x === 0 && rect.y === 0;
178
+ return normalize.element({
179
+ id: dom.getIndicatorId(scope),
180
+ ...parts.indicator.attrs,
181
+ dir: prop("dir"),
182
+ "data-orientation": prop("orientation"),
183
+ hidden: rectIsEmpty,
184
+ style: {
185
+ "--transition-property": "left, right, top, bottom, width, height",
186
+ "--left": toPx(rect?.x),
187
+ "--top": toPx(rect?.y),
188
+ "--width": toPx(rect?.width),
189
+ "--height": toPx(rect?.height),
190
+ position: "absolute",
191
+ willChange: "var(--transition-property)",
192
+ transitionProperty: "var(--transition-property)",
193
+ transitionDuration: "var(--transition-duration, 150ms)",
194
+ transitionTimingFunction: "var(--transition-timing-function)",
195
+ [isHorizontal ? "left" : "top"]: isHorizontal ? "var(--left)" : "var(--top)"
196
+ }
197
+ });
198
+ }
199
+ };
200
+ }
201
+ export {
202
+ connect
203
+ };
@@ -0,0 +1,36 @@
1
+ import { Scope } from '@zag-js/core';
2
+
3
+ declare const getRootId: (ctx: Scope) => any;
4
+ declare const getListId: (ctx: Scope) => any;
5
+ declare const getContentId: (ctx: Scope, value: string) => any;
6
+ declare const getTriggerId: (ctx: Scope, value: string) => any;
7
+ declare const getIndicatorId: (ctx: Scope) => any;
8
+ declare const getListEl: (ctx: Scope) => HTMLElement | null;
9
+ declare const getContentEl: (ctx: Scope, value: string) => HTMLElement | null;
10
+ declare const getTriggerEl: (ctx: Scope, value: string | null) => HTMLElement | null;
11
+ declare const getIndicatorEl: (ctx: Scope) => HTMLElement | null;
12
+ declare const getElements: (ctx: Scope) => HTMLElement[];
13
+ declare const getFirstTriggerEl: (ctx: Scope) => HTMLElement | undefined;
14
+ declare const getLastTriggerEl: (ctx: Scope) => HTMLElement | undefined;
15
+ declare const getNextTriggerEl: (ctx: Scope, opts: {
16
+ value: string;
17
+ loopFocus?: boolean | undefined;
18
+ }) => HTMLElement;
19
+ declare const getPrevTriggerEl: (ctx: Scope, opts: {
20
+ value: string;
21
+ loopFocus?: boolean | undefined;
22
+ }) => HTMLElement | null;
23
+ declare const getOffsetRect: (el: HTMLElement | undefined) => {
24
+ x: number;
25
+ y: number;
26
+ width: number;
27
+ height: number;
28
+ };
29
+ declare const getRectByValue: (ctx: Scope, value: string) => {
30
+ x: number;
31
+ y: number;
32
+ width: number;
33
+ height: number;
34
+ };
35
+
36
+ export { getContentEl, getContentId, getElements, getFirstTriggerEl, getIndicatorEl, getIndicatorId, getLastTriggerEl, getListEl, getListId, getNextTriggerEl, getOffsetRect, getPrevTriggerEl, getRectByValue, getRootId, getTriggerEl, getTriggerId };
@@ -0,0 +1,36 @@
1
+ import { Scope } from '@zag-js/core';
2
+
3
+ declare const getRootId: (ctx: Scope) => any;
4
+ declare const getListId: (ctx: Scope) => any;
5
+ declare const getContentId: (ctx: Scope, value: string) => any;
6
+ declare const getTriggerId: (ctx: Scope, value: string) => any;
7
+ declare const getIndicatorId: (ctx: Scope) => any;
8
+ declare const getListEl: (ctx: Scope) => HTMLElement | null;
9
+ declare const getContentEl: (ctx: Scope, value: string) => HTMLElement | null;
10
+ declare const getTriggerEl: (ctx: Scope, value: string | null) => HTMLElement | null;
11
+ declare const getIndicatorEl: (ctx: Scope) => HTMLElement | null;
12
+ declare const getElements: (ctx: Scope) => HTMLElement[];
13
+ declare const getFirstTriggerEl: (ctx: Scope) => HTMLElement | undefined;
14
+ declare const getLastTriggerEl: (ctx: Scope) => HTMLElement | undefined;
15
+ declare const getNextTriggerEl: (ctx: Scope, opts: {
16
+ value: string;
17
+ loopFocus?: boolean | undefined;
18
+ }) => HTMLElement;
19
+ declare const getPrevTriggerEl: (ctx: Scope, opts: {
20
+ value: string;
21
+ loopFocus?: boolean | undefined;
22
+ }) => HTMLElement | null;
23
+ declare const getOffsetRect: (el: HTMLElement | undefined) => {
24
+ x: number;
25
+ y: number;
26
+ width: number;
27
+ height: number;
28
+ };
29
+ declare const getRectByValue: (ctx: Scope, value: string) => {
30
+ x: number;
31
+ y: number;
32
+ width: number;
33
+ height: number;
34
+ };
35
+
36
+ export { getContentEl, getContentId, getElements, getFirstTriggerEl, getIndicatorEl, getIndicatorId, getLastTriggerEl, getListEl, getListId, getNextTriggerEl, getOffsetRect, getPrevTriggerEl, getRectByValue, getRootId, getTriggerEl, getTriggerId };
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/tabs.dom.ts
21
+ var tabs_dom_exports = {};
22
+ __export(tabs_dom_exports, {
23
+ getContentEl: () => getContentEl,
24
+ getContentId: () => getContentId,
25
+ getElements: () => getElements,
26
+ getFirstTriggerEl: () => getFirstTriggerEl,
27
+ getIndicatorEl: () => getIndicatorEl,
28
+ getIndicatorId: () => getIndicatorId,
29
+ getLastTriggerEl: () => getLastTriggerEl,
30
+ getListEl: () => getListEl,
31
+ getListId: () => getListId,
32
+ getNextTriggerEl: () => getNextTriggerEl,
33
+ getOffsetRect: () => getOffsetRect,
34
+ getPrevTriggerEl: () => getPrevTriggerEl,
35
+ getRectByValue: () => getRectByValue,
36
+ getRootId: () => getRootId,
37
+ getTriggerEl: () => getTriggerEl,
38
+ getTriggerId: () => getTriggerId
39
+ });
40
+ module.exports = __toCommonJS(tabs_dom_exports);
41
+ var import_dom_query = require("@zag-js/dom-query");
42
+ var import_utils = require("@zag-js/utils");
43
+ var getRootId = (ctx) => ctx.ids?.root ?? `tabs:${ctx.id}`;
44
+ var getListId = (ctx) => ctx.ids?.list ?? `tabs:${ctx.id}:list`;
45
+ var getContentId = (ctx, value) => ctx.ids?.content?.(value) ?? `tabs:${ctx.id}:content-${value}`;
46
+ var getTriggerId = (ctx, value) => ctx.ids?.trigger?.(value) ?? `tabs:${ctx.id}:trigger-${value}`;
47
+ var getIndicatorId = (ctx) => ctx.ids?.indicator ?? `tabs:${ctx.id}:indicator`;
48
+ var getListEl = (ctx) => ctx.getById(getListId(ctx));
49
+ var getContentEl = (ctx, value) => ctx.getById(getContentId(ctx, value));
50
+ var getTriggerEl = (ctx, value) => value != null ? ctx.getById(getTriggerId(ctx, value)) : null;
51
+ var getIndicatorEl = (ctx) => ctx.getById(getIndicatorId(ctx));
52
+ var getElements = (ctx) => {
53
+ const ownerId = CSS.escape(getListId(ctx));
54
+ const selector = `[role=tab][data-ownedby='${ownerId}']:not([disabled])`;
55
+ return (0, import_dom_query.queryAll)(getListEl(ctx), selector);
56
+ };
57
+ var getFirstTriggerEl = (ctx) => (0, import_utils.first)(getElements(ctx));
58
+ var getLastTriggerEl = (ctx) => (0, import_utils.last)(getElements(ctx));
59
+ var getNextTriggerEl = (ctx, opts) => (0, import_dom_query.nextById)(getElements(ctx), getTriggerId(ctx, opts.value), opts.loopFocus);
60
+ var getPrevTriggerEl = (ctx, opts) => (0, import_dom_query.prevById)(getElements(ctx), getTriggerId(ctx, opts.value), opts.loopFocus);
61
+ var getOffsetRect = (el) => ({
62
+ x: el?.offsetLeft ?? 0,
63
+ y: el?.offsetTop ?? 0,
64
+ width: el?.offsetWidth ?? 0,
65
+ height: el?.offsetHeight ?? 0
66
+ });
67
+ var getRectByValue = (ctx, value) => {
68
+ const tab = (0, import_dom_query.itemById)(getElements(ctx), getTriggerId(ctx, value));
69
+ return getOffsetRect(tab);
70
+ };
71
+ // Annotate the CommonJS export names for ESM import in node:
72
+ 0 && (module.exports = {
73
+ getContentEl,
74
+ getContentId,
75
+ getElements,
76
+ getFirstTriggerEl,
77
+ getIndicatorEl,
78
+ getIndicatorId,
79
+ getLastTriggerEl,
80
+ getListEl,
81
+ getListId,
82
+ getNextTriggerEl,
83
+ getOffsetRect,
84
+ getPrevTriggerEl,
85
+ getRectByValue,
86
+ getRootId,
87
+ getTriggerEl,
88
+ getTriggerId
89
+ });
@@ -0,0 +1,49 @@
1
+ // src/tabs.dom.ts
2
+ import { itemById, nextById, prevById, queryAll } from "@zag-js/dom-query";
3
+ import { first, last } from "@zag-js/utils";
4
+ var getRootId = (ctx) => ctx.ids?.root ?? `tabs:${ctx.id}`;
5
+ var getListId = (ctx) => ctx.ids?.list ?? `tabs:${ctx.id}:list`;
6
+ var getContentId = (ctx, value) => ctx.ids?.content?.(value) ?? `tabs:${ctx.id}:content-${value}`;
7
+ var getTriggerId = (ctx, value) => ctx.ids?.trigger?.(value) ?? `tabs:${ctx.id}:trigger-${value}`;
8
+ var getIndicatorId = (ctx) => ctx.ids?.indicator ?? `tabs:${ctx.id}:indicator`;
9
+ var getListEl = (ctx) => ctx.getById(getListId(ctx));
10
+ var getContentEl = (ctx, value) => ctx.getById(getContentId(ctx, value));
11
+ var getTriggerEl = (ctx, value) => value != null ? ctx.getById(getTriggerId(ctx, value)) : null;
12
+ var getIndicatorEl = (ctx) => ctx.getById(getIndicatorId(ctx));
13
+ var getElements = (ctx) => {
14
+ const ownerId = CSS.escape(getListId(ctx));
15
+ const selector = `[role=tab][data-ownedby='${ownerId}']:not([disabled])`;
16
+ return queryAll(getListEl(ctx), selector);
17
+ };
18
+ var getFirstTriggerEl = (ctx) => first(getElements(ctx));
19
+ var getLastTriggerEl = (ctx) => last(getElements(ctx));
20
+ var getNextTriggerEl = (ctx, opts) => nextById(getElements(ctx), getTriggerId(ctx, opts.value), opts.loopFocus);
21
+ var getPrevTriggerEl = (ctx, opts) => prevById(getElements(ctx), getTriggerId(ctx, opts.value), opts.loopFocus);
22
+ var getOffsetRect = (el) => ({
23
+ x: el?.offsetLeft ?? 0,
24
+ y: el?.offsetTop ?? 0,
25
+ width: el?.offsetWidth ?? 0,
26
+ height: el?.offsetHeight ?? 0
27
+ });
28
+ var getRectByValue = (ctx, value) => {
29
+ const tab = itemById(getElements(ctx), getTriggerId(ctx, value));
30
+ return getOffsetRect(tab);
31
+ };
32
+ export {
33
+ getContentEl,
34
+ getContentId,
35
+ getElements,
36
+ getFirstTriggerEl,
37
+ getIndicatorEl,
38
+ getIndicatorId,
39
+ getLastTriggerEl,
40
+ getListEl,
41
+ getListId,
42
+ getNextTriggerEl,
43
+ getOffsetRect,
44
+ getPrevTriggerEl,
45
+ getRectByValue,
46
+ getRootId,
47
+ getTriggerEl,
48
+ getTriggerId
49
+ };
@@ -0,0 +1,7 @@
1
+ import * as _zag_js_core from '@zag-js/core';
2
+ import { TabsSchema } from './tabs.types.mjs';
3
+ import '@zag-js/types';
4
+
5
+ declare const machine: _zag_js_core.Machine<TabsSchema>;
6
+
7
+ export { machine };
@@ -0,0 +1,7 @@
1
+ import * as _zag_js_core from '@zag-js/core';
2
+ import { TabsSchema } from './tabs.types.js';
3
+ import '@zag-js/types';
4
+
5
+ declare const machine: _zag_js_core.Machine<TabsSchema>;
6
+
7
+ export { machine };