@zag-js/tabs 0.52.0 → 0.54.0

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.d.mts CHANGED
@@ -151,11 +151,11 @@ interface MachineApi<T extends PropTypes = PropTypes> {
151
151
  * Returns the state of the trigger with the given props
152
152
  */
153
153
  getTriggerState(props: TriggerProps): TriggerState;
154
- rootProps: T["element"];
155
- listProps: T["element"];
154
+ getRootProps(): T["element"];
155
+ getListProps(): T["element"];
156
156
  getTriggerProps(props: TriggerProps): T["button"];
157
157
  getContentProps(props: ContentProps): T["element"];
158
- indicatorProps: T["element"];
158
+ getIndicatorProps(): T["element"];
159
159
  }
160
160
 
161
161
  declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): MachineApi<T>;
package/dist/index.d.ts CHANGED
@@ -151,11 +151,11 @@ interface MachineApi<T extends PropTypes = PropTypes> {
151
151
  * Returns the state of the trigger with the given props
152
152
  */
153
153
  getTriggerState(props: TriggerProps): TriggerState;
154
- rootProps: T["element"];
155
- listProps: T["element"];
154
+ getRootProps(): T["element"];
155
+ getListProps(): T["element"];
156
156
  getTriggerProps(props: TriggerProps): T["button"];
157
157
  getContentProps(props: ContentProps): T["element"];
158
- indicatorProps: T["element"];
158
+ getIndicatorProps(): T["element"];
159
159
  }
160
160
 
161
161
  declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): MachineApi<T>;
package/dist/index.js CHANGED
@@ -1,2 +1,590 @@
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,rootProps: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}),listProps: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})},indicatorProps: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
+ getRootProps() {
139
+ return 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
+ },
147
+ getListProps() {
148
+ return normalize.element({
149
+ ...parts.list.attrs,
150
+ id: dom.getListId(state.context),
151
+ role: "tablist",
152
+ dir: state.context.dir,
153
+ "data-focus": (0, import_dom_query2.dataAttr)(focused),
154
+ "aria-orientation": state.context.orientation,
155
+ "data-orientation": state.context.orientation,
156
+ "aria-label": translations?.listLabel,
157
+ onKeyDown(event) {
158
+ if (event.defaultPrevented)
159
+ return;
160
+ if (!(0, import_dom_query2.isSelfTarget)(event))
161
+ return;
162
+ if ((0, import_dom_query2.isComposingEvent)(event))
163
+ return;
164
+ const keyMap = {
165
+ ArrowDown() {
166
+ if (isHorizontal)
167
+ return;
168
+ send({ type: "ARROW_NEXT", key: "ArrowDown" });
169
+ },
170
+ ArrowUp() {
171
+ if (isHorizontal)
172
+ return;
173
+ send({ type: "ARROW_PREV", key: "ArrowUp" });
174
+ },
175
+ ArrowLeft() {
176
+ if (isVertical)
177
+ return;
178
+ send({ type: "ARROW_PREV", key: "ArrowLeft" });
179
+ },
180
+ ArrowRight() {
181
+ if (isVertical)
182
+ return;
183
+ send({ type: "ARROW_NEXT", key: "ArrowRight" });
184
+ },
185
+ Home() {
186
+ send("HOME");
187
+ },
188
+ End() {
189
+ send("END");
190
+ },
191
+ Enter() {
192
+ send({ type: "ENTER" });
193
+ }
194
+ };
195
+ let key = (0, import_dom_event.getEventKey)(event, state.context);
196
+ const exec = keyMap[key];
197
+ if (exec) {
198
+ event.preventDefault();
199
+ exec(event);
200
+ }
201
+ }
202
+ });
203
+ },
204
+ getTriggerState,
205
+ getTriggerProps(props2) {
206
+ const { value, disabled } = props2;
207
+ const triggerState = getTriggerState(props2);
208
+ return normalize.button({
209
+ ...parts.trigger.attrs,
210
+ role: "tab",
211
+ type: "button",
212
+ disabled,
213
+ dir: state.context.dir,
214
+ "data-orientation": state.context.orientation,
215
+ "data-disabled": (0, import_dom_query2.dataAttr)(disabled),
216
+ "aria-disabled": disabled,
217
+ "data-value": value,
218
+ "aria-selected": triggerState.selected,
219
+ "data-selected": (0, import_dom_query2.dataAttr)(triggerState.selected),
220
+ "data-focus": (0, import_dom_query2.dataAttr)(triggerState.focused),
221
+ "aria-controls": triggerState.selected ? dom.getContentId(state.context, value) : void 0,
222
+ "data-ownedby": dom.getListId(state.context),
223
+ id: dom.getTriggerId(state.context, value),
224
+ tabIndex: triggerState.selected && composite ? 0 : -1,
225
+ onFocus() {
226
+ send({ type: "TAB_FOCUS", value });
227
+ },
228
+ onBlur(event) {
229
+ const target = event.relatedTarget;
230
+ if (target?.getAttribute("role") !== "tab") {
231
+ send({ type: "TAB_BLUR" });
232
+ }
233
+ },
234
+ onClick(event) {
235
+ if (event.defaultPrevented)
236
+ return;
237
+ if (disabled)
238
+ return;
239
+ if ((0, import_dom_query2.isSafari)()) {
240
+ event.currentTarget.focus();
241
+ }
242
+ send({ type: "TAB_CLICK", value });
243
+ }
244
+ });
245
+ },
246
+ getContentProps(props2) {
247
+ const { value } = props2;
248
+ const selected = state.context.value === value;
249
+ return normalize.element({
250
+ ...parts.content.attrs,
251
+ dir: state.context.dir,
252
+ id: dom.getContentId(state.context, value),
253
+ tabIndex: composite ? 0 : -1,
254
+ "aria-labelledby": dom.getTriggerId(state.context, value),
255
+ role: "tabpanel",
256
+ "data-ownedby": dom.getListId(state.context),
257
+ "data-selected": (0, import_dom_query2.dataAttr)(selected),
258
+ "data-orientation": state.context.orientation,
259
+ hidden: !selected
260
+ });
261
+ },
262
+ getIndicatorProps() {
263
+ return normalize.element({
264
+ id: dom.getIndicatorId(state.context),
265
+ ...parts.indicator.attrs,
266
+ dir: state.context.dir,
267
+ "data-orientation": state.context.orientation,
268
+ style: {
269
+ "--transition-property": "left, right, top, bottom, width, height",
270
+ "--left": indicator.rect?.left,
271
+ "--top": indicator.rect?.top,
272
+ "--width": indicator.rect?.width,
273
+ "--height": indicator.rect?.height,
274
+ position: "absolute",
275
+ willChange: "var(--transition-property)",
276
+ transitionProperty: "var(--transition-property)",
277
+ transitionDuration: indicator.transition ? "var(--transition-duration, 150ms)" : "0ms",
278
+ transitionTimingFunction: "var(--transition-timing-function)",
279
+ [isHorizontal ? "left" : "top"]: isHorizontal ? "var(--left)" : "var(--top)"
280
+ }
281
+ });
282
+ }
283
+ };
284
+ }
285
+
286
+ // src/tabs.machine.ts
287
+ var import_core = require("@zag-js/core");
288
+ var import_dom_event2 = require("@zag-js/dom-event");
289
+ var import_dom_query3 = require("@zag-js/dom-query");
290
+ var import_element_rect = require("@zag-js/element-rect");
291
+ var import_utils2 = require("@zag-js/utils");
292
+ var { not } = import_core.guards;
293
+ function machine(userContext) {
294
+ const ctx = (0, import_utils2.compact)(userContext);
295
+ return (0, import_core.createMachine)(
296
+ {
297
+ initial: "idle",
298
+ context: {
299
+ dir: "ltr",
300
+ orientation: "horizontal",
301
+ activationMode: "automatic",
302
+ value: null,
303
+ loopFocus: true,
304
+ composite: true,
305
+ ...ctx,
306
+ focusedValue: ctx.value ?? null,
307
+ indicatorState: {
308
+ rendered: false,
309
+ transition: false,
310
+ rect: { left: "0px", top: "0px", width: "0px", height: "0px" }
311
+ }
312
+ },
313
+ watch: {
314
+ value: ["allowIndicatorTransition", "syncIndicatorRect", "syncTabIndex", "clickIfLink"],
315
+ dir: ["syncIndicatorRect"],
316
+ orientation: ["syncIndicatorRect"]
317
+ },
318
+ on: {
319
+ SET_VALUE: {
320
+ actions: "setValue"
321
+ },
322
+ CLEAR_VALUE: {
323
+ actions: "clearValue"
324
+ },
325
+ SET_INDICATOR_RECT: {
326
+ actions: "setIndicatorRect"
327
+ },
328
+ SYNC_TAB_INDEX: {
329
+ actions: "syncTabIndex"
330
+ }
331
+ },
332
+ created: ["syncFocusedValue"],
333
+ entry: ["checkRenderedElements", "syncIndicatorRect", "syncTabIndex"],
334
+ exit: ["cleanupObserver"],
335
+ states: {
336
+ idle: {
337
+ on: {
338
+ TAB_FOCUS: {
339
+ target: "focused",
340
+ actions: "setFocusedValue"
341
+ },
342
+ TAB_CLICK: {
343
+ target: "focused",
344
+ actions: ["setFocusedValue", "setValue"]
345
+ }
346
+ }
347
+ },
348
+ focused: {
349
+ on: {
350
+ TAB_CLICK: {
351
+ target: "focused",
352
+ actions: ["setFocusedValue", "setValue"]
353
+ },
354
+ ARROW_PREV: [
355
+ {
356
+ guard: "selectOnFocus",
357
+ actions: ["focusPrevTab", "selectFocusedTab"]
358
+ },
359
+ {
360
+ actions: "focusPrevTab"
361
+ }
362
+ ],
363
+ ARROW_NEXT: [
364
+ {
365
+ guard: "selectOnFocus",
366
+ actions: ["focusNextTab", "selectFocusedTab"]
367
+ },
368
+ {
369
+ actions: "focusNextTab"
370
+ }
371
+ ],
372
+ HOME: [
373
+ {
374
+ guard: "selectOnFocus",
375
+ actions: ["focusFirstTab", "selectFocusedTab"]
376
+ },
377
+ {
378
+ actions: "focusFirstTab"
379
+ }
380
+ ],
381
+ END: [
382
+ {
383
+ guard: "selectOnFocus",
384
+ actions: ["focusLastTab", "selectFocusedTab"]
385
+ },
386
+ {
387
+ actions: "focusLastTab"
388
+ }
389
+ ],
390
+ ENTER: {
391
+ guard: not("selectOnFocus"),
392
+ actions: "selectFocusedTab"
393
+ },
394
+ TAB_FOCUS: {
395
+ actions: ["setFocusedValue"]
396
+ },
397
+ TAB_BLUR: {
398
+ target: "idle",
399
+ actions: "clearFocusedValue"
400
+ }
401
+ }
402
+ }
403
+ }
404
+ },
405
+ {
406
+ guards: {
407
+ selectOnFocus: (ctx2) => ctx2.activationMode === "automatic"
408
+ },
409
+ actions: {
410
+ syncFocusedValue(ctx2) {
411
+ if (ctx2.value != null && ctx2.focusedValue == null) {
412
+ ctx2.focusedValue = ctx2.value;
413
+ }
414
+ },
415
+ selectFocusedTab(ctx2) {
416
+ (0, import_dom_query3.raf)(() => {
417
+ set.value(ctx2, ctx2.focusedValue);
418
+ });
419
+ },
420
+ setFocusedValue(ctx2, evt) {
421
+ if (evt.value == null)
422
+ return;
423
+ set.focusedValue(ctx2, evt.value);
424
+ },
425
+ clearFocusedValue(ctx2) {
426
+ set.focusedValue(ctx2, null);
427
+ },
428
+ setValue(ctx2, evt) {
429
+ set.value(ctx2, evt.value);
430
+ },
431
+ clearValue(ctx2) {
432
+ set.value(ctx2, null);
433
+ },
434
+ focusFirstTab(ctx2) {
435
+ (0, import_dom_query3.raf)(() => {
436
+ dom.getFirstTriggerEl(ctx2)?.focus();
437
+ });
438
+ },
439
+ focusLastTab(ctx2) {
440
+ (0, import_dom_query3.raf)(() => {
441
+ dom.getLastTriggerEl(ctx2)?.focus();
442
+ });
443
+ },
444
+ focusNextTab(ctx2) {
445
+ if (!ctx2.focusedValue)
446
+ return;
447
+ const triggerEl = dom.getNextTriggerEl(ctx2, ctx2.focusedValue);
448
+ (0, import_dom_query3.raf)(() => {
449
+ if (ctx2.composite) {
450
+ triggerEl?.focus();
451
+ } else if (triggerEl?.dataset.value != null) {
452
+ set.focusedValue(ctx2, triggerEl.dataset.value);
453
+ }
454
+ });
455
+ },
456
+ focusPrevTab(ctx2) {
457
+ if (!ctx2.focusedValue)
458
+ return;
459
+ const triggerEl = dom.getPrevTriggerEl(ctx2, ctx2.focusedValue);
460
+ (0, import_dom_query3.raf)(() => {
461
+ if (ctx2.composite) {
462
+ triggerEl?.focus();
463
+ } else if (triggerEl?.dataset.value != null) {
464
+ set.focusedValue(ctx2, triggerEl.dataset.value);
465
+ }
466
+ });
467
+ },
468
+ checkRenderedElements(ctx2) {
469
+ ctx2.indicatorState.rendered = !!dom.getIndicatorEl(ctx2);
470
+ },
471
+ syncTabIndex(ctx2) {
472
+ (0, import_dom_query3.raf)(() => {
473
+ const contentEl = dom.getSelectedContentEl(ctx2);
474
+ if (!contentEl)
475
+ return;
476
+ const focusables = (0, import_dom_query3.getFocusables)(contentEl);
477
+ if (focusables.length > 0) {
478
+ contentEl.removeAttribute("tabindex");
479
+ } else {
480
+ contentEl.setAttribute("tabindex", "0");
481
+ }
482
+ });
483
+ },
484
+ cleanupObserver(ctx2) {
485
+ ctx2.indicatorCleanup?.();
486
+ },
487
+ allowIndicatorTransition(ctx2) {
488
+ ctx2.indicatorState.transition = true;
489
+ },
490
+ setIndicatorRect(ctx2, evt) {
491
+ const value = evt.id ?? ctx2.value;
492
+ if (!ctx2.indicatorState.rendered || !value)
493
+ return;
494
+ const triggerEl = dom.getTriggerEl(ctx2, value);
495
+ if (!triggerEl)
496
+ return;
497
+ ctx2.indicatorState.rect = dom.getRectById(ctx2, value);
498
+ (0, import_dom_query3.nextTick)(() => {
499
+ ctx2.indicatorState.transition = false;
500
+ });
501
+ },
502
+ syncIndicatorRect(ctx2) {
503
+ ctx2.indicatorCleanup?.();
504
+ const value = ctx2.value;
505
+ if (!ctx2.indicatorState.rendered || !value)
506
+ return;
507
+ const triggerEl = dom.getSelectedTriggerEl(ctx2);
508
+ if (!triggerEl)
509
+ return;
510
+ ctx2.indicatorCleanup = (0, import_element_rect.trackElementRect)(triggerEl, {
511
+ getRect(el) {
512
+ return dom.getOffsetRect(el);
513
+ },
514
+ onChange(rect) {
515
+ ctx2.indicatorState.rect = dom.resolveRect(rect);
516
+ (0, import_dom_query3.nextTick)(() => {
517
+ ctx2.indicatorState.transition = false;
518
+ });
519
+ }
520
+ });
521
+ },
522
+ clickIfLink(ctx2) {
523
+ (0, import_dom_event2.clickIfLink)(dom.getSelectedTriggerEl(ctx2));
524
+ }
525
+ }
526
+ }
527
+ );
528
+ }
529
+ var invoke = {
530
+ change: (ctx) => {
531
+ if (ctx.value == null)
532
+ return;
533
+ ctx.onValueChange?.({ value: ctx.value });
534
+ },
535
+ focusChange: (ctx) => {
536
+ if (ctx.focusedValue == null)
537
+ return;
538
+ ctx.onFocusChange?.({ focusedValue: ctx.focusedValue });
539
+ }
540
+ };
541
+ var set = {
542
+ value: (ctx, value) => {
543
+ if ((0, import_utils2.isEqual)(value, ctx.value))
544
+ return;
545
+ ctx.value = value;
546
+ invoke.change(ctx);
547
+ },
548
+ focusedValue: (ctx, value) => {
549
+ if ((0, import_utils2.isEqual)(value, ctx.focusedValue))
550
+ return;
551
+ ctx.focusedValue = value;
552
+ invoke.focusChange(ctx);
553
+ }
554
+ };
555
+
556
+ // src/tabs.props.ts
557
+ var import_types = require("@zag-js/types");
558
+ var import_utils3 = require("@zag-js/utils");
559
+ var props = (0, import_types.createProps)()([
560
+ "activationMode",
561
+ "composite",
562
+ "dir",
563
+ "getRootNode",
564
+ "id",
565
+ "ids",
566
+ "loopFocus",
567
+ "onFocusChange",
568
+ "onValueChange",
569
+ "orientation",
570
+ "translations",
571
+ "value"
572
+ ]);
573
+ var splitProps = (0, import_utils3.createSplitProps)(props);
574
+ var triggerProps = (0, import_types.createProps)()(["disabled", "value"]);
575
+ var splitTriggerProps = (0, import_utils3.createSplitProps)(triggerProps);
576
+ var contentProps = (0, import_types.createProps)()(["value"]);
577
+ var splitContentProps = (0, import_utils3.createSplitProps)(contentProps);
578
+ // Annotate the CommonJS export names for ESM import in node:
579
+ 0 && (module.exports = {
580
+ anatomy,
581
+ connect,
582
+ contentProps,
583
+ machine,
584
+ props,
585
+ splitContentProps,
586
+ splitProps,
587
+ splitTriggerProps,
588
+ triggerProps
589
+ });
2
590
  //# sourceMappingURL=index.js.map