@zag-js/tabs 0.0.0-dev-20240605193509 → 0.0.0-dev-20240605203045

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.
package/dist/index.js CHANGED
@@ -1,2 +1,584 @@
1
- "use strict";var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:true})};var __copyProps=(to,from,except,desc)=>{if(from&&typeof from==="object"||typeof from==="function"){for(let key of __getOwnPropNames(from))if(!__hasOwnProp.call(to,key)&&key!==except)__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable})}return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:true}),mod);var src_exports={};__export(src_exports,{anatomy:()=>anatomy,connect:()=>connect,contentProps:()=>contentProps,machine:()=>machine,props:()=>props,splitContentProps:()=>splitContentProps,splitProps:()=>splitProps,splitTriggerProps:()=>splitTriggerProps,triggerProps:()=>triggerProps});module.exports=__toCommonJS(src_exports);var import_anatomy=require("@zag-js/anatomy");var anatomy=(0,import_anatomy.createAnatomy)("tabs").parts("root","list","trigger","content","indicator");var parts=anatomy.build();var import_dom_event=require("@zag-js/dom-event");var import_dom_query2=require("@zag-js/dom-query");var import_dom_query=require("@zag-js/dom-query");var import_utils=require("@zag-js/utils");var dom=(0,import_dom_query.createScope)({getRootId:ctx=>ctx.ids?.root??`tabs:${ctx.id}`,getListId:ctx=>ctx.ids?.list??`tabs:${ctx.id}:list`,getContentId:(ctx,id)=>ctx.ids?.content??`tabs:${ctx.id}:content-${id}`,getTriggerId:(ctx,id)=>ctx.ids?.trigger??`tabs:${ctx.id}:trigger-${id}`,getIndicatorId:ctx=>ctx.ids?.indicator??`tabs:${ctx.id}:indicator`,getListEl:ctx=>dom.getById(ctx,dom.getListId(ctx)),getContentEl:(ctx,id)=>dom.getById(ctx,dom.getContentId(ctx,id)),getTriggerEl:(ctx,id)=>dom.getById(ctx,dom.getTriggerId(ctx,id)),getIndicatorEl:ctx=>dom.getById(ctx,dom.getIndicatorId(ctx)),getElements:ctx=>{const ownerId=CSS.escape(dom.getListId(ctx));const selector=`[role=tab][data-ownedby='${ownerId}']:not([disabled])`;return(0,import_dom_query.queryAll)(dom.getListEl(ctx),selector)},getFirstTriggerEl:ctx=>(0,import_utils.first)(dom.getElements(ctx)),getLastTriggerEl:ctx=>(0,import_utils.last)(dom.getElements(ctx)),getNextTriggerEl:(ctx,id)=>(0,import_dom_query.nextById)(dom.getElements(ctx),dom.getTriggerId(ctx,id),ctx.loopFocus),getPrevTriggerEl:(ctx,id)=>(0,import_dom_query.prevById)(dom.getElements(ctx),dom.getTriggerId(ctx,id),ctx.loopFocus),getSelectedContentEl:ctx=>{if(!ctx.value)return;return dom.getContentEl(ctx,ctx.value)},getSelectedTriggerEl:ctx=>{if(!ctx.value)return;return dom.getTriggerEl(ctx,ctx.value)},getOffsetRect:el=>{return{left:el?.offsetLeft??0,top:el?.offsetTop??0,width:el?.offsetWidth??0,height:el?.offsetHeight??0}},getRectById:(ctx,id)=>{const tab=(0,import_dom_query.itemById)(dom.getElements(ctx),dom.getTriggerId(ctx,id));return dom.resolveRect(dom.getOffsetRect(tab))},resolveRect:rect=>({width:`${rect.width}px`,height:`${rect.height}px`,left:`${rect.left}px`,top:`${rect.top}px`})});function connect(state,send,normalize){const translations=state.context.translations;const focused=state.matches("focused");const isVertical=state.context.orientation==="vertical";const isHorizontal=state.context.orientation==="horizontal";const composite=state.context.composite;const indicator=state.context.indicatorState;function getTriggerState(props2){return{selected:state.context.value===props2.value,focused:state.context.focusedValue===props2.value,disabled:!!props2.disabled}}return{value:state.context.value,focusedValue:state.context.focusedValue,setValue(value){send({type:"SET_VALUE",value})},clearValue(){send({type:"CLEAR_VALUE"})},setIndicatorRect(value){const id=dom.getTriggerId(state.context,value);send({type:"SET_INDICATOR_RECT",id})},syncTabIndex(){send("SYNC_TAB_INDEX")},selectNext(fromValue){send({type:"TAB_FOCUS",value:fromValue,src:"selectNext"});send({type:"ARROW_NEXT",src:"selectNext"})},selectPrev(fromValue){send({type:"TAB_FOCUS",value:fromValue,src:"selectPrev"});send({type:"ARROW_PREV",src:"selectPrev"})},focus(){dom.getSelectedTriggerEl(state.context)?.focus()},getTriggerState,getRootProps:()=>normalize.element({...parts.root.attrs,id:dom.getRootId(state.context),"data-orientation":state.context.orientation,"data-focus":(0,import_dom_query2.dataAttr)(focused),dir:state.context.dir}),getListProps:()=>normalize.element({...parts.list.attrs,id:dom.getListId(state.context),role:"tablist",dir:state.context.dir,"data-focus":(0,import_dom_query2.dataAttr)(focused),"aria-orientation":state.context.orientation,"data-orientation":state.context.orientation,"aria-label":translations?.listLabel,onKeyDown(event){if(event.defaultPrevented)return;if(!(0,import_dom_query2.isSelfTarget)(event))return;if((0,import_dom_query2.isComposingEvent)(event))return;const keyMap={ArrowDown(){if(isHorizontal)return;send({type:"ARROW_NEXT",key:"ArrowDown"})},ArrowUp(){if(isHorizontal)return;send({type:"ARROW_PREV",key:"ArrowUp"})},ArrowLeft(){if(isVertical)return;send({type:"ARROW_PREV",key:"ArrowLeft"})},ArrowRight(){if(isVertical)return;send({type:"ARROW_NEXT",key:"ArrowRight"})},Home(){send("HOME")},End(){send("END")},Enter(){send({type:"ENTER"})}};let key=(0,import_dom_event.getEventKey)(event,state.context);const exec=keyMap[key];if(exec){event.preventDefault();exec(event)}}}),getTriggerProps(props2){const{value,disabled}=props2;const triggerState=getTriggerState(props2);return normalize.button({...parts.trigger.attrs,role:"tab",type:"button",disabled,dir:state.context.dir,"data-orientation":state.context.orientation,"data-disabled":(0,import_dom_query2.dataAttr)(disabled),"aria-disabled":disabled,"data-value":value,"aria-selected":triggerState.selected,"data-selected":(0,import_dom_query2.dataAttr)(triggerState.selected),"data-focus":(0,import_dom_query2.dataAttr)(triggerState.focused),"aria-controls":triggerState.selected?dom.getContentId(state.context,value):void 0,"data-ownedby":dom.getListId(state.context),id:dom.getTriggerId(state.context,value),tabIndex:triggerState.selected&&composite?0:-1,onFocus(){send({type:"TAB_FOCUS",value})},onBlur(event){const target=event.relatedTarget;if(target?.getAttribute("role")!=="tab"){send({type:"TAB_BLUR"})}},onClick(event){if(event.defaultPrevented)return;if(disabled)return;if((0,import_dom_query2.isSafari)()){event.currentTarget.focus()}send({type:"TAB_CLICK",value})}})},getContentProps(props2){const{value}=props2;const selected=state.context.value===value;return normalize.element({...parts.content.attrs,dir:state.context.dir,id:dom.getContentId(state.context,value),tabIndex:composite?0:-1,"aria-labelledby":dom.getTriggerId(state.context,value),role:"tabpanel","data-ownedby":dom.getListId(state.context),"data-selected":(0,import_dom_query2.dataAttr)(selected),"data-orientation":state.context.orientation,hidden:!selected})},getIndicatorProps:()=>normalize.element({id:dom.getIndicatorId(state.context),...parts.indicator.attrs,dir:state.context.dir,"data-orientation":state.context.orientation,style:{"--transition-property":"left, right, top, bottom, width, height","--left":indicator.rect?.left,"--top":indicator.rect?.top,"--width":indicator.rect?.width,"--height":indicator.rect?.height,position:"absolute",willChange:"var(--transition-property)",transitionProperty:"var(--transition-property)",transitionDuration:indicator.transition?"var(--transition-duration, 150ms)":"0ms",transitionTimingFunction:"var(--transition-timing-function)",[isHorizontal?"left":"top"]:isHorizontal?"var(--left)":"var(--top)"}})}}var import_core=require("@zag-js/core");var import_dom_event2=require("@zag-js/dom-event");var import_dom_query3=require("@zag-js/dom-query");var import_element_rect=require("@zag-js/element-rect");var import_utils2=require("@zag-js/utils");var{not}=import_core.guards;function machine(userContext){const ctx=(0,import_utils2.compact)(userContext);return(0,import_core.createMachine)({initial:"idle",context:{dir:"ltr",orientation:"horizontal",activationMode:"automatic",value:null,loopFocus:true,composite:true,...ctx,focusedValue:ctx.value??null,indicatorState:{rendered:false,transition:false,rect:{left:"0px",top:"0px",width:"0px",height:"0px"}}},watch:{value:["allowIndicatorTransition","syncIndicatorRect","syncTabIndex","clickIfLink"],dir:["syncIndicatorRect"],orientation:["syncIndicatorRect"]},on:{SET_VALUE:{actions:"setValue"},CLEAR_VALUE:{actions:"clearValue"},SET_INDICATOR_RECT:{actions:"setIndicatorRect"},SYNC_TAB_INDEX:{actions:"syncTabIndex"}},created:["syncFocusedValue"],entry:["checkRenderedElements","syncIndicatorRect","syncTabIndex"],exit:["cleanupObserver"],states:{idle:{on:{TAB_FOCUS:{target:"focused",actions:"setFocusedValue"},TAB_CLICK:{target:"focused",actions:["setFocusedValue","setValue"]}}},focused:{on:{TAB_CLICK:{target:"focused",actions:["setFocusedValue","setValue"]},ARROW_PREV:[{guard:"selectOnFocus",actions:["focusPrevTab","selectFocusedTab"]},{actions:"focusPrevTab"}],ARROW_NEXT:[{guard:"selectOnFocus",actions:["focusNextTab","selectFocusedTab"]},{actions:"focusNextTab"}],HOME:[{guard:"selectOnFocus",actions:["focusFirstTab","selectFocusedTab"]},{actions:"focusFirstTab"}],END:[{guard:"selectOnFocus",actions:["focusLastTab","selectFocusedTab"]},{actions:"focusLastTab"}],ENTER:{guard:not("selectOnFocus"),actions:"selectFocusedTab"},TAB_FOCUS:{actions:["setFocusedValue"]},TAB_BLUR:{target:"idle",actions:"clearFocusedValue"}}}}},{guards:{selectOnFocus:ctx2=>ctx2.activationMode==="automatic"},actions:{syncFocusedValue(ctx2){if(ctx2.value!=null&&ctx2.focusedValue==null){ctx2.focusedValue=ctx2.value}},selectFocusedTab(ctx2){(0,import_dom_query3.raf)(()=>{set.value(ctx2,ctx2.focusedValue)})},setFocusedValue(ctx2,evt){if(evt.value==null)return;set.focusedValue(ctx2,evt.value)},clearFocusedValue(ctx2){set.focusedValue(ctx2,null)},setValue(ctx2,evt){set.value(ctx2,evt.value)},clearValue(ctx2){set.value(ctx2,null)},focusFirstTab(ctx2){(0,import_dom_query3.raf)(()=>{dom.getFirstTriggerEl(ctx2)?.focus()})},focusLastTab(ctx2){(0,import_dom_query3.raf)(()=>{dom.getLastTriggerEl(ctx2)?.focus()})},focusNextTab(ctx2){if(!ctx2.focusedValue)return;const triggerEl=dom.getNextTriggerEl(ctx2,ctx2.focusedValue);(0,import_dom_query3.raf)(()=>{if(ctx2.composite){triggerEl?.focus()}else if(triggerEl?.dataset.value!=null){set.focusedValue(ctx2,triggerEl.dataset.value)}})},focusPrevTab(ctx2){if(!ctx2.focusedValue)return;const triggerEl=dom.getPrevTriggerEl(ctx2,ctx2.focusedValue);(0,import_dom_query3.raf)(()=>{if(ctx2.composite){triggerEl?.focus()}else if(triggerEl?.dataset.value!=null){set.focusedValue(ctx2,triggerEl.dataset.value)}})},checkRenderedElements(ctx2){ctx2.indicatorState.rendered=!!dom.getIndicatorEl(ctx2)},syncTabIndex(ctx2){(0,import_dom_query3.raf)(()=>{const contentEl=dom.getSelectedContentEl(ctx2);if(!contentEl)return;const focusables=(0,import_dom_query3.getFocusables)(contentEl);if(focusables.length>0){contentEl.removeAttribute("tabindex")}else{contentEl.setAttribute("tabindex","0")}})},cleanupObserver(ctx2){ctx2.indicatorCleanup?.()},allowIndicatorTransition(ctx2){ctx2.indicatorState.transition=true},setIndicatorRect(ctx2,evt){const value=evt.id??ctx2.value;if(!ctx2.indicatorState.rendered||!value)return;const triggerEl=dom.getTriggerEl(ctx2,value);if(!triggerEl)return;ctx2.indicatorState.rect=dom.getRectById(ctx2,value);(0,import_dom_query3.nextTick)(()=>{ctx2.indicatorState.transition=false})},syncIndicatorRect(ctx2){ctx2.indicatorCleanup?.();const value=ctx2.value;if(!ctx2.indicatorState.rendered||!value)return;const triggerEl=dom.getSelectedTriggerEl(ctx2);if(!triggerEl)return;ctx2.indicatorCleanup=(0,import_element_rect.trackElementRect)(triggerEl,{getRect(el){return dom.getOffsetRect(el)},onChange(rect){ctx2.indicatorState.rect=dom.resolveRect(rect);(0,import_dom_query3.nextTick)(()=>{ctx2.indicatorState.transition=false})}})},clickIfLink(ctx2){(0,import_dom_event2.clickIfLink)(dom.getSelectedTriggerEl(ctx2))}}})}var invoke={change:ctx=>{if(ctx.value==null)return;ctx.onValueChange?.({value:ctx.value})},focusChange:ctx=>{if(ctx.focusedValue==null)return;ctx.onFocusChange?.({focusedValue:ctx.focusedValue})}};var set={value:(ctx,value)=>{if((0,import_utils2.isEqual)(value,ctx.value))return;ctx.value=value;invoke.change(ctx)},focusedValue:(ctx,value)=>{if((0,import_utils2.isEqual)(value,ctx.focusedValue))return;ctx.focusedValue=value;invoke.focusChange(ctx)}};var import_types=require("@zag-js/types");var import_utils3=require("@zag-js/utils");var props=(0,import_types.createProps)()(["activationMode","composite","dir","getRootNode","id","ids","loopFocus","onFocusChange","onValueChange","orientation","translations","value"]);var splitProps=(0,import_utils3.createSplitProps)(props);var triggerProps=(0,import_types.createProps)()(["disabled","value"]);var splitTriggerProps=(0,import_utils3.createSplitProps)(triggerProps);var contentProps=(0,import_types.createProps)()(["value"]);var splitContentProps=(0,import_utils3.createSplitProps)(contentProps);0&&(module.exports={anatomy,connect,contentProps,machine,props,splitContentProps,splitProps,splitTriggerProps,triggerProps});
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/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ anatomy: () => anatomy,
24
+ connect: () => connect,
25
+ contentProps: () => contentProps,
26
+ machine: () => machine,
27
+ props: () => props,
28
+ splitContentProps: () => splitContentProps,
29
+ splitProps: () => splitProps,
30
+ splitTriggerProps: () => splitTriggerProps,
31
+ triggerProps: () => triggerProps
32
+ });
33
+ module.exports = __toCommonJS(src_exports);
34
+
35
+ // src/tabs.anatomy.ts
36
+ var import_anatomy = require("@zag-js/anatomy");
37
+ var anatomy = (0, import_anatomy.createAnatomy)("tabs").parts("root", "list", "trigger", "content", "indicator");
38
+ var parts = anatomy.build();
39
+
40
+ // src/tabs.connect.ts
41
+ var import_dom_event = require("@zag-js/dom-event");
42
+ var import_dom_query2 = require("@zag-js/dom-query");
43
+
44
+ // src/tabs.dom.ts
45
+ var import_dom_query = require("@zag-js/dom-query");
46
+ var import_utils = require("@zag-js/utils");
47
+ var dom = (0, import_dom_query.createScope)({
48
+ getRootId: (ctx) => ctx.ids?.root ?? `tabs:${ctx.id}`,
49
+ getListId: (ctx) => ctx.ids?.list ?? `tabs:${ctx.id}:list`,
50
+ getContentId: (ctx, id) => ctx.ids?.content ?? `tabs:${ctx.id}:content-${id}`,
51
+ getTriggerId: (ctx, id) => ctx.ids?.trigger ?? `tabs:${ctx.id}:trigger-${id}`,
52
+ getIndicatorId: (ctx) => ctx.ids?.indicator ?? `tabs:${ctx.id}:indicator`,
53
+ getListEl: (ctx) => dom.getById(ctx, dom.getListId(ctx)),
54
+ getContentEl: (ctx, id) => dom.getById(ctx, dom.getContentId(ctx, id)),
55
+ getTriggerEl: (ctx, id) => dom.getById(ctx, dom.getTriggerId(ctx, id)),
56
+ getIndicatorEl: (ctx) => dom.getById(ctx, dom.getIndicatorId(ctx)),
57
+ getElements: (ctx) => {
58
+ const ownerId = CSS.escape(dom.getListId(ctx));
59
+ const selector = `[role=tab][data-ownedby='${ownerId}']:not([disabled])`;
60
+ return (0, import_dom_query.queryAll)(dom.getListEl(ctx), selector);
61
+ },
62
+ getFirstTriggerEl: (ctx) => (0, import_utils.first)(dom.getElements(ctx)),
63
+ getLastTriggerEl: (ctx) => (0, import_utils.last)(dom.getElements(ctx)),
64
+ getNextTriggerEl: (ctx, id) => (0, import_dom_query.nextById)(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loopFocus),
65
+ getPrevTriggerEl: (ctx, id) => (0, import_dom_query.prevById)(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loopFocus),
66
+ getSelectedContentEl: (ctx) => {
67
+ if (!ctx.value)
68
+ return;
69
+ return dom.getContentEl(ctx, ctx.value);
70
+ },
71
+ getSelectedTriggerEl: (ctx) => {
72
+ if (!ctx.value)
73
+ return;
74
+ return dom.getTriggerEl(ctx, ctx.value);
75
+ },
76
+ getOffsetRect: (el) => {
77
+ return {
78
+ left: el?.offsetLeft ?? 0,
79
+ top: el?.offsetTop ?? 0,
80
+ width: el?.offsetWidth ?? 0,
81
+ height: el?.offsetHeight ?? 0
82
+ };
83
+ },
84
+ getRectById: (ctx, id) => {
85
+ const tab = (0, import_dom_query.itemById)(dom.getElements(ctx), dom.getTriggerId(ctx, id));
86
+ return dom.resolveRect(dom.getOffsetRect(tab));
87
+ },
88
+ resolveRect: (rect) => ({
89
+ width: `${rect.width}px`,
90
+ height: `${rect.height}px`,
91
+ left: `${rect.left}px`,
92
+ top: `${rect.top}px`
93
+ })
94
+ });
95
+
96
+ // src/tabs.connect.ts
97
+ function connect(state, send, normalize) {
98
+ const translations = state.context.translations;
99
+ const focused = state.matches("focused");
100
+ const isVertical = state.context.orientation === "vertical";
101
+ const isHorizontal = state.context.orientation === "horizontal";
102
+ const composite = state.context.composite;
103
+ const indicator = state.context.indicatorState;
104
+ function getTriggerState(props2) {
105
+ return {
106
+ selected: state.context.value === props2.value,
107
+ focused: state.context.focusedValue === props2.value,
108
+ disabled: !!props2.disabled
109
+ };
110
+ }
111
+ return {
112
+ value: state.context.value,
113
+ focusedValue: state.context.focusedValue,
114
+ setValue(value) {
115
+ send({ type: "SET_VALUE", value });
116
+ },
117
+ clearValue() {
118
+ send({ type: "CLEAR_VALUE" });
119
+ },
120
+ setIndicatorRect(value) {
121
+ const id = dom.getTriggerId(state.context, value);
122
+ send({ type: "SET_INDICATOR_RECT", id });
123
+ },
124
+ syncTabIndex() {
125
+ send("SYNC_TAB_INDEX");
126
+ },
127
+ selectNext(fromValue) {
128
+ send({ type: "TAB_FOCUS", value: fromValue, src: "selectNext" });
129
+ send({ type: "ARROW_NEXT", src: "selectNext" });
130
+ },
131
+ selectPrev(fromValue) {
132
+ send({ type: "TAB_FOCUS", value: fromValue, src: "selectPrev" });
133
+ send({ type: "ARROW_PREV", src: "selectPrev" });
134
+ },
135
+ focus() {
136
+ dom.getSelectedTriggerEl(state.context)?.focus();
137
+ },
138
+ getTriggerState,
139
+ getRootProps: () => normalize.element({
140
+ ...parts.root.attrs,
141
+ id: dom.getRootId(state.context),
142
+ "data-orientation": state.context.orientation,
143
+ "data-focus": (0, import_dom_query2.dataAttr)(focused),
144
+ dir: state.context.dir
145
+ }),
146
+ getListProps: () => normalize.element({
147
+ ...parts.list.attrs,
148
+ id: dom.getListId(state.context),
149
+ role: "tablist",
150
+ dir: state.context.dir,
151
+ "data-focus": (0, import_dom_query2.dataAttr)(focused),
152
+ "aria-orientation": state.context.orientation,
153
+ "data-orientation": state.context.orientation,
154
+ "aria-label": translations?.listLabel,
155
+ onKeyDown(event) {
156
+ if (event.defaultPrevented)
157
+ return;
158
+ if (!(0, import_dom_query2.isSelfTarget)(event))
159
+ return;
160
+ if ((0, import_dom_query2.isComposingEvent)(event))
161
+ return;
162
+ const keyMap = {
163
+ ArrowDown() {
164
+ if (isHorizontal)
165
+ return;
166
+ send({ type: "ARROW_NEXT", key: "ArrowDown" });
167
+ },
168
+ ArrowUp() {
169
+ if (isHorizontal)
170
+ return;
171
+ send({ type: "ARROW_PREV", key: "ArrowUp" });
172
+ },
173
+ ArrowLeft() {
174
+ if (isVertical)
175
+ return;
176
+ send({ type: "ARROW_PREV", key: "ArrowLeft" });
177
+ },
178
+ ArrowRight() {
179
+ if (isVertical)
180
+ return;
181
+ send({ type: "ARROW_NEXT", key: "ArrowRight" });
182
+ },
183
+ Home() {
184
+ send("HOME");
185
+ },
186
+ End() {
187
+ send("END");
188
+ },
189
+ Enter() {
190
+ send({ type: "ENTER" });
191
+ }
192
+ };
193
+ let key = (0, import_dom_event.getEventKey)(event, state.context);
194
+ const exec = keyMap[key];
195
+ if (exec) {
196
+ event.preventDefault();
197
+ exec(event);
198
+ }
199
+ }
200
+ }),
201
+ getTriggerProps(props2) {
202
+ const { value, disabled } = props2;
203
+ const triggerState = getTriggerState(props2);
204
+ return normalize.button({
205
+ ...parts.trigger.attrs,
206
+ role: "tab",
207
+ type: "button",
208
+ disabled,
209
+ dir: state.context.dir,
210
+ "data-orientation": state.context.orientation,
211
+ "data-disabled": (0, import_dom_query2.dataAttr)(disabled),
212
+ "aria-disabled": disabled,
213
+ "data-value": value,
214
+ "aria-selected": triggerState.selected,
215
+ "data-selected": (0, import_dom_query2.dataAttr)(triggerState.selected),
216
+ "data-focus": (0, import_dom_query2.dataAttr)(triggerState.focused),
217
+ "aria-controls": triggerState.selected ? dom.getContentId(state.context, value) : void 0,
218
+ "data-ownedby": dom.getListId(state.context),
219
+ id: dom.getTriggerId(state.context, value),
220
+ tabIndex: triggerState.selected && composite ? 0 : -1,
221
+ onFocus() {
222
+ send({ type: "TAB_FOCUS", value });
223
+ },
224
+ onBlur(event) {
225
+ const target = event.relatedTarget;
226
+ if (target?.getAttribute("role") !== "tab") {
227
+ send({ type: "TAB_BLUR" });
228
+ }
229
+ },
230
+ onClick(event) {
231
+ if (event.defaultPrevented)
232
+ return;
233
+ if (disabled)
234
+ return;
235
+ if ((0, import_dom_query2.isSafari)()) {
236
+ event.currentTarget.focus();
237
+ }
238
+ send({ type: "TAB_CLICK", value });
239
+ }
240
+ });
241
+ },
242
+ getContentProps(props2) {
243
+ const { value } = props2;
244
+ const selected = state.context.value === value;
245
+ return normalize.element({
246
+ ...parts.content.attrs,
247
+ dir: state.context.dir,
248
+ id: dom.getContentId(state.context, value),
249
+ tabIndex: composite ? 0 : -1,
250
+ "aria-labelledby": dom.getTriggerId(state.context, value),
251
+ role: "tabpanel",
252
+ "data-ownedby": dom.getListId(state.context),
253
+ "data-selected": (0, import_dom_query2.dataAttr)(selected),
254
+ "data-orientation": state.context.orientation,
255
+ hidden: !selected
256
+ });
257
+ },
258
+ getIndicatorProps: () => normalize.element({
259
+ id: dom.getIndicatorId(state.context),
260
+ ...parts.indicator.attrs,
261
+ dir: state.context.dir,
262
+ "data-orientation": state.context.orientation,
263
+ style: {
264
+ "--transition-property": "left, right, top, bottom, width, height",
265
+ "--left": indicator.rect?.left,
266
+ "--top": indicator.rect?.top,
267
+ "--width": indicator.rect?.width,
268
+ "--height": indicator.rect?.height,
269
+ position: "absolute",
270
+ willChange: "var(--transition-property)",
271
+ transitionProperty: "var(--transition-property)",
272
+ transitionDuration: indicator.transition ? "var(--transition-duration, 150ms)" : "0ms",
273
+ transitionTimingFunction: "var(--transition-timing-function)",
274
+ [isHorizontal ? "left" : "top"]: isHorizontal ? "var(--left)" : "var(--top)"
275
+ }
276
+ })
277
+ };
278
+ }
279
+
280
+ // src/tabs.machine.ts
281
+ var import_core = require("@zag-js/core");
282
+ var import_dom_event2 = require("@zag-js/dom-event");
283
+ var import_dom_query3 = require("@zag-js/dom-query");
284
+ var import_element_rect = require("@zag-js/element-rect");
285
+ var import_utils2 = require("@zag-js/utils");
286
+ var { not } = import_core.guards;
287
+ function machine(userContext) {
288
+ const ctx = (0, import_utils2.compact)(userContext);
289
+ return (0, import_core.createMachine)(
290
+ {
291
+ initial: "idle",
292
+ context: {
293
+ dir: "ltr",
294
+ orientation: "horizontal",
295
+ activationMode: "automatic",
296
+ value: null,
297
+ loopFocus: true,
298
+ composite: true,
299
+ ...ctx,
300
+ focusedValue: ctx.value ?? null,
301
+ indicatorState: {
302
+ rendered: false,
303
+ transition: false,
304
+ rect: { left: "0px", top: "0px", width: "0px", height: "0px" }
305
+ }
306
+ },
307
+ watch: {
308
+ value: ["allowIndicatorTransition", "syncIndicatorRect", "syncTabIndex", "clickIfLink"],
309
+ dir: ["syncIndicatorRect"],
310
+ orientation: ["syncIndicatorRect"]
311
+ },
312
+ on: {
313
+ SET_VALUE: {
314
+ actions: "setValue"
315
+ },
316
+ CLEAR_VALUE: {
317
+ actions: "clearValue"
318
+ },
319
+ SET_INDICATOR_RECT: {
320
+ actions: "setIndicatorRect"
321
+ },
322
+ SYNC_TAB_INDEX: {
323
+ actions: "syncTabIndex"
324
+ }
325
+ },
326
+ created: ["syncFocusedValue"],
327
+ entry: ["checkRenderedElements", "syncIndicatorRect", "syncTabIndex"],
328
+ exit: ["cleanupObserver"],
329
+ states: {
330
+ idle: {
331
+ on: {
332
+ TAB_FOCUS: {
333
+ target: "focused",
334
+ actions: "setFocusedValue"
335
+ },
336
+ TAB_CLICK: {
337
+ target: "focused",
338
+ actions: ["setFocusedValue", "setValue"]
339
+ }
340
+ }
341
+ },
342
+ focused: {
343
+ on: {
344
+ TAB_CLICK: {
345
+ target: "focused",
346
+ actions: ["setFocusedValue", "setValue"]
347
+ },
348
+ ARROW_PREV: [
349
+ {
350
+ guard: "selectOnFocus",
351
+ actions: ["focusPrevTab", "selectFocusedTab"]
352
+ },
353
+ {
354
+ actions: "focusPrevTab"
355
+ }
356
+ ],
357
+ ARROW_NEXT: [
358
+ {
359
+ guard: "selectOnFocus",
360
+ actions: ["focusNextTab", "selectFocusedTab"]
361
+ },
362
+ {
363
+ actions: "focusNextTab"
364
+ }
365
+ ],
366
+ HOME: [
367
+ {
368
+ guard: "selectOnFocus",
369
+ actions: ["focusFirstTab", "selectFocusedTab"]
370
+ },
371
+ {
372
+ actions: "focusFirstTab"
373
+ }
374
+ ],
375
+ END: [
376
+ {
377
+ guard: "selectOnFocus",
378
+ actions: ["focusLastTab", "selectFocusedTab"]
379
+ },
380
+ {
381
+ actions: "focusLastTab"
382
+ }
383
+ ],
384
+ ENTER: {
385
+ guard: not("selectOnFocus"),
386
+ actions: "selectFocusedTab"
387
+ },
388
+ TAB_FOCUS: {
389
+ actions: ["setFocusedValue"]
390
+ },
391
+ TAB_BLUR: {
392
+ target: "idle",
393
+ actions: "clearFocusedValue"
394
+ }
395
+ }
396
+ }
397
+ }
398
+ },
399
+ {
400
+ guards: {
401
+ selectOnFocus: (ctx2) => ctx2.activationMode === "automatic"
402
+ },
403
+ actions: {
404
+ syncFocusedValue(ctx2) {
405
+ if (ctx2.value != null && ctx2.focusedValue == null) {
406
+ ctx2.focusedValue = ctx2.value;
407
+ }
408
+ },
409
+ selectFocusedTab(ctx2) {
410
+ (0, import_dom_query3.raf)(() => {
411
+ set.value(ctx2, ctx2.focusedValue);
412
+ });
413
+ },
414
+ setFocusedValue(ctx2, evt) {
415
+ if (evt.value == null)
416
+ return;
417
+ set.focusedValue(ctx2, evt.value);
418
+ },
419
+ clearFocusedValue(ctx2) {
420
+ set.focusedValue(ctx2, null);
421
+ },
422
+ setValue(ctx2, evt) {
423
+ set.value(ctx2, evt.value);
424
+ },
425
+ clearValue(ctx2) {
426
+ set.value(ctx2, null);
427
+ },
428
+ focusFirstTab(ctx2) {
429
+ (0, import_dom_query3.raf)(() => {
430
+ dom.getFirstTriggerEl(ctx2)?.focus();
431
+ });
432
+ },
433
+ focusLastTab(ctx2) {
434
+ (0, import_dom_query3.raf)(() => {
435
+ dom.getLastTriggerEl(ctx2)?.focus();
436
+ });
437
+ },
438
+ focusNextTab(ctx2) {
439
+ if (!ctx2.focusedValue)
440
+ return;
441
+ const triggerEl = dom.getNextTriggerEl(ctx2, ctx2.focusedValue);
442
+ (0, import_dom_query3.raf)(() => {
443
+ if (ctx2.composite) {
444
+ triggerEl?.focus();
445
+ } else if (triggerEl?.dataset.value != null) {
446
+ set.focusedValue(ctx2, triggerEl.dataset.value);
447
+ }
448
+ });
449
+ },
450
+ focusPrevTab(ctx2) {
451
+ if (!ctx2.focusedValue)
452
+ return;
453
+ const triggerEl = dom.getPrevTriggerEl(ctx2, ctx2.focusedValue);
454
+ (0, import_dom_query3.raf)(() => {
455
+ if (ctx2.composite) {
456
+ triggerEl?.focus();
457
+ } else if (triggerEl?.dataset.value != null) {
458
+ set.focusedValue(ctx2, triggerEl.dataset.value);
459
+ }
460
+ });
461
+ },
462
+ checkRenderedElements(ctx2) {
463
+ ctx2.indicatorState.rendered = !!dom.getIndicatorEl(ctx2);
464
+ },
465
+ syncTabIndex(ctx2) {
466
+ (0, import_dom_query3.raf)(() => {
467
+ const contentEl = dom.getSelectedContentEl(ctx2);
468
+ if (!contentEl)
469
+ return;
470
+ const focusables = (0, import_dom_query3.getFocusables)(contentEl);
471
+ if (focusables.length > 0) {
472
+ contentEl.removeAttribute("tabindex");
473
+ } else {
474
+ contentEl.setAttribute("tabindex", "0");
475
+ }
476
+ });
477
+ },
478
+ cleanupObserver(ctx2) {
479
+ ctx2.indicatorCleanup?.();
480
+ },
481
+ allowIndicatorTransition(ctx2) {
482
+ ctx2.indicatorState.transition = true;
483
+ },
484
+ setIndicatorRect(ctx2, evt) {
485
+ const value = evt.id ?? ctx2.value;
486
+ if (!ctx2.indicatorState.rendered || !value)
487
+ return;
488
+ const triggerEl = dom.getTriggerEl(ctx2, value);
489
+ if (!triggerEl)
490
+ return;
491
+ ctx2.indicatorState.rect = dom.getRectById(ctx2, value);
492
+ (0, import_dom_query3.nextTick)(() => {
493
+ ctx2.indicatorState.transition = false;
494
+ });
495
+ },
496
+ syncIndicatorRect(ctx2) {
497
+ ctx2.indicatorCleanup?.();
498
+ const value = ctx2.value;
499
+ if (!ctx2.indicatorState.rendered || !value)
500
+ return;
501
+ const triggerEl = dom.getSelectedTriggerEl(ctx2);
502
+ if (!triggerEl)
503
+ return;
504
+ ctx2.indicatorCleanup = (0, import_element_rect.trackElementRect)(triggerEl, {
505
+ getRect(el) {
506
+ return dom.getOffsetRect(el);
507
+ },
508
+ onChange(rect) {
509
+ ctx2.indicatorState.rect = dom.resolveRect(rect);
510
+ (0, import_dom_query3.nextTick)(() => {
511
+ ctx2.indicatorState.transition = false;
512
+ });
513
+ }
514
+ });
515
+ },
516
+ clickIfLink(ctx2) {
517
+ (0, import_dom_event2.clickIfLink)(dom.getSelectedTriggerEl(ctx2));
518
+ }
519
+ }
520
+ }
521
+ );
522
+ }
523
+ var invoke = {
524
+ change: (ctx) => {
525
+ if (ctx.value == null)
526
+ return;
527
+ ctx.onValueChange?.({ value: ctx.value });
528
+ },
529
+ focusChange: (ctx) => {
530
+ if (ctx.focusedValue == null)
531
+ return;
532
+ ctx.onFocusChange?.({ focusedValue: ctx.focusedValue });
533
+ }
534
+ };
535
+ var set = {
536
+ value: (ctx, value) => {
537
+ if ((0, import_utils2.isEqual)(value, ctx.value))
538
+ return;
539
+ ctx.value = value;
540
+ invoke.change(ctx);
541
+ },
542
+ focusedValue: (ctx, value) => {
543
+ if ((0, import_utils2.isEqual)(value, ctx.focusedValue))
544
+ return;
545
+ ctx.focusedValue = value;
546
+ invoke.focusChange(ctx);
547
+ }
548
+ };
549
+
550
+ // src/tabs.props.ts
551
+ var import_types = require("@zag-js/types");
552
+ var import_utils3 = require("@zag-js/utils");
553
+ var props = (0, import_types.createProps)()([
554
+ "activationMode",
555
+ "composite",
556
+ "dir",
557
+ "getRootNode",
558
+ "id",
559
+ "ids",
560
+ "loopFocus",
561
+ "onFocusChange",
562
+ "onValueChange",
563
+ "orientation",
564
+ "translations",
565
+ "value"
566
+ ]);
567
+ var splitProps = (0, import_utils3.createSplitProps)(props);
568
+ var triggerProps = (0, import_types.createProps)()(["disabled", "value"]);
569
+ var splitTriggerProps = (0, import_utils3.createSplitProps)(triggerProps);
570
+ var contentProps = (0, import_types.createProps)()(["value"]);
571
+ var splitContentProps = (0, import_utils3.createSplitProps)(contentProps);
572
+ // Annotate the CommonJS export names for ESM import in node:
573
+ 0 && (module.exports = {
574
+ anatomy,
575
+ connect,
576
+ contentProps,
577
+ machine,
578
+ props,
579
+ splitContentProps,
580
+ splitProps,
581
+ splitTriggerProps,
582
+ triggerProps
583
+ });
2
584
  //# sourceMappingURL=index.js.map