@zag-js/tabs 0.0.0-dev-20220413091534 → 0.0.0-dev-20220415160434

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.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export { connect } from "./tabs.connect";
2
2
  export { machine } from "./tabs.machine";
3
3
  export type { MachineContext, MachineState } from "./tabs.types";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AACxC,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA"}
package/dist/index.js CHANGED
@@ -1,2 +1,591 @@
1
- var $=Object.defineProperty;var Nt=Object.getOwnPropertyDescriptor;var Wt=Object.getOwnPropertyNames;var Ft=Object.prototype.hasOwnProperty;var jt=(t,e)=>{for(var n in e)$(t,n,{get:e[n],enumerable:!0})},Bt=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of Wt(e))!Ft.call(t,a)&&a!==n&&$(t,a,{get:()=>e[a],enumerable:!(r=Nt(e,a))||r.enumerable});return t};var Ht=t=>Bt($({},"__esModule",{value:!0}),t);var be={};jt(be,{connect:()=>gt,machine:()=>Vt});module.exports=Ht(be);var V=t=>t?"":void 0;var et=new WeakMap;function _t(t){var e;if(!t)return{};let n=et.get(t);return n||(n=((e=t?.ownerDocument.defaultView)!=null?e:window).getComputedStyle(t),et.set(t,n)),n}function L(t){let e=new Set;function n(r){let a=globalThis.requestAnimationFrame(r);e.add(()=>globalThis.cancelAnimationFrame(a))}return n(()=>n(t)),function(){e.forEach(function(r){r()})}}var we=(()=>{let t=0;return()=>(t++,t.toString(36))})();function it(t){return typeof t=="object"&&t?.nodeType===Node.ELEMENT_NODE&&typeof t?.nodeName=="string"}var zt=t=>t?.getAttribute("disabled")!=null||!!(t!=null&&t.getAttribute("aria-disabled"));var rt=["input:not([disabled]):not([type=hidden])","select:not([disabled])","textarea:not([disabled])","button:not([disabled])","embed","iframe","object","a[href]","area[href]","[tabindex]","audio[controls]","video[controls]","*[tabindex]:not([aria-disabled])","[contenteditable]:not([contenteditable=false])","details > summary:first-of-type"].join(",");function ot(t,e){let n=_t(t);if(!t||n.getPropertyValue("visibility")==="hidden")return!0;for(;t;){if(e!=null&&t===e)return!1;if(n.getPropertyValue("display")==="none")return!0;t=t.parentElement}return!1}var st=(t,e=!1)=>{if(!t)return[];let n=Array.from(t.querySelectorAll(rt));return e&&it(t)&&n.unshift(t),n.filter(r=>Kt(r)&&!ot(r))},Kt=t=>!it(t)||ot(t)||zt(t)?!1:t?.matches(rt);var nt={ArrowLeft:"ArrowRight",ArrowRight:"ArrowLeft",Home:"End",End:"Home"},$t={Up:"ArrowUp",Down:"ArrowDown",Esc:"Escape"," ":"Space",",":"Comma",Left:"ArrowLeft",Right:"ArrowRight"};function at(t,e={}){var n;let{dir:r="ltr",orientation:a="horizontal"}=e,{key:u}=t;return u=(n=$t[u])!=null?n:u,r==="rtl"&&a==="horizontal"&&u in nt&&(u=nt[u]),u}function lt(t,e){var n;return Array.from((n=t?.querySelectorAll(e))!=null?n:[])}function q(t,e){return t.find(n=>n.id===e)}function ut(t,e){let n=q(t,e);return n?t.indexOf(n):-1}function ct(t,e,n=!0){let r=ut(t,e);return r=n?(r+1)%t.length:Math.min(r+1,t.length-1),t[r]}function dt(t,e,n=!0){let r=ut(t,e);return r===-1?n?t[t.length-1]:null:(r=n?(r-1+t.length)%t.length:Math.max(0,r-1),t[r])}function qt(t){return{button:t,label:t,input:t,output:t,element:t}}var ht=qt(t=>t);var ft=t=>t[0],pt=t=>t[t.length-1];var Te=(()=>{let t=0;return()=>(t++,t.toString(36))})();var Ut=t=>Gt()&&t.test(navigator.userAgent);var Gt=()=>typeof window<"u";var vt=()=>Ut(/^((?!chrome|android).)*safari/i);var p={getDoc:t=>{var e;return(e=t.doc)!=null?e:document},getRootId:t=>{var e,n;return(n=(e=t.ids)==null?void 0:e.root)!=null?n:`tabs-${t.uid}`},getTriggerGroupId:t=>{var e,n;return(n=(e=t.ids)==null?void 0:e.triggerGroup)!=null?n:`tabs-${t.uid}-trigger-group`},getContentId:(t,e)=>{var n,r;return(r=(n=t.ids)==null?void 0:n.content)!=null?r:`tabs-${t.uid}-content-${e}`},getContentGroupId:t=>{var e,n;return(n=(e=t.ids)==null?void 0:e.contentGroup)!=null?n:`tabs-${t.uid}-content-group`},getTriggerId:(t,e)=>{var n,r;return(r=(n=t.ids)==null?void 0:n.trigger)!=null?r:`tabs-${t.uid}-trigger-${e}`},getIndicatorId:t=>`tabs-${t.uid}-indicator`,getTriggerGroupEl:t=>p.getDoc(t).getElementById(p.getTriggerGroupId(t)),getContentEl:(t,e)=>p.getDoc(t).getElementById(p.getContentId(t,e)),getTriggerEl:(t,e)=>p.getDoc(t).getElementById(p.getTriggerId(t,e)),getIndicatorEl:t=>p.getDoc(t).getElementById(p.getIndicatorId(t)),getElements:t=>{let n=`[role=tab][data-ownedby='${CSS.escape(p.getTriggerGroupId(t))}']:not([disabled])`;return lt(p.getTriggerGroupEl(t),n)},getFirstEl:t=>ft(p.getElements(t)),getLastEl:t=>pt(p.getElements(t)),getNextEl:(t,e)=>ct(p.getElements(t),p.getTriggerId(t,e),t.loop),getPrevEl:(t,e)=>dt(p.getElements(t),p.getTriggerId(t,e),t.loop),getRectById:(t,e)=>{var a;let n={offsetLeft:0,offsetTop:0,offsetWidth:0,offsetHeight:0},r=(a=q(p.getElements(t),p.getTriggerId(t,e)))!=null?a:n;return t.isVertical?{top:`${r.offsetTop}px`,height:`${r.offsetHeight}px`}:{left:`${r.offsetLeft}px`,width:`${r.offsetWidth}px`}},getActiveContentEl:t=>{if(!t.value)return;let e=p.getContentId(t,t.value);return p.getDoc(t).getElementById(e)}};function gt(t,e,n=ht){let r=t.context.messages,a=t.matches("focused");return{value:t.context.value,focusedValue:t.context.focusedValue,previousValues:Array.from(t.context.previousValues),setValue(u){e({type:"SET_VALUE",value:u})},rootProps:n.element({"data-part":"root",id:p.getRootId(t.context),"data-orientation":t.context.orientation,"data-focus":V(a),dir:t.context.dir}),triggerGroupProps:n.element({"data-part":"trigger-group",id:p.getTriggerGroupId(t.context),role:"tablist","data-focus":V(a),"aria-orientation":t.context.orientation,"data-orientation":t.context.orientation,"aria-label":r.tablistLabel,onKeyDown(u){let g={ArrowDown(){e("ARROW_DOWN")},ArrowUp(){e("ARROW_UP")},ArrowLeft(){e("ARROW_LEFT")},ArrowRight(){e("ARROW_RIGHT")},Home(){e("HOME")},End(){e("END")},Enter(){e({type:"ENTER",value:t.context.focusedValue})}},m=at(u,t.context),y=g[m];y&&(u.preventDefault(),y(u))}}),getTriggerProps(u){let{value:g,disabled:m}=u,y=t.context.value===g;return n.button({"data-part":"trigger",role:"tab",type:"button",disabled:m,"data-orientation":t.context.orientation,"data-disabled":V(m),"aria-disabled":m,"data-value":g,"aria-selected":y,"data-selected":V(y),"aria-controls":p.getContentId(t.context,g),"data-ownedby":p.getTriggerGroupId(t.context),id:p.getTriggerId(t.context,g),tabIndex:y?0:-1,onFocus(){e({type:"TAB_FOCUS",value:g})},onBlur(b){let E=b.relatedTarget;(E==null?void 0:E.getAttribute("role"))!=="tab"&&e({type:"TAB_BLUR"})},onClick(b){m||(vt()&&b.currentTarget.focus(),e({type:"TAB_CLICK",value:g}))}})},contentGroupProps:n.element({"data-part":"content-group",id:p.getContentGroupId(t.context),"data-orientation":t.context.orientation}),getContentProps({value:u}){let g=t.context.value===u;return n.element({"data-part":"content",id:p.getContentId(t.context,u),tabIndex:0,"aria-labelledby":p.getTriggerId(t.context,u),role:"tabpanel","data-ownedby":p.getTriggerGroupId(t.context),hidden:!g})},getDeleteButtonProps({value:u,disabled:g}){var m;return n.button({"data-part":"delete-button",type:"button",tabIndex:-1,"aria-label":(m=r.deleteLabel)==null?void 0:m.call(r,u),disabled:g,onClick(){e({type:"DELETE",value:u})}})},indicatorProps:n.element({id:p.getIndicatorId(t.context),"data-part":"indicator","data-orientation":t.context.orientation,style:{"--transition-duration":"200ms","--transition-property":"left, right, top, bottom, width, height",position:"absolute",willChange:"var(--transition-property)",transitionProperty:"var(--transition-property)",transitionDuration:t.context.hasMeasuredRect?"var(--transition-duration)":"0ms",transitionTimingFunction:"var(--transition-timing-function)",...t.context.indicatorRect}})}}var K={},We=Symbol(),Fe=Symbol(),Yt=Symbol(),mt=Object.getPrototypeOf,X=new WeakMap,Xt=t=>t&&(X.has(t)?X.get(t):mt(t)===Object.prototype||mt(t)===Array.prototype),Jt=t=>Xt(t)&&t[Yt]||null,yt=(t,e=!0)=>{X.set(t,e)},Lt=Symbol(),A=Symbol(),H=Symbol(),Zt=Symbol(),D=Symbol(),bt=Symbol(),Z=new WeakSet;function _(t){return Z.add(t),t}var z=t=>typeof t=="object"&&t!==null,Qt=t=>z(t)&&!Z.has(t)&&(Array.isArray(t)||!(Symbol.iterator in t))&&!(t instanceof WeakMap)&&!(t instanceof WeakSet)&&!(t instanceof Error)&&!(t instanceof Number)&&!(t instanceof Date)&&!(t instanceof String)&&!(t instanceof RegExp)&&!(t instanceof ArrayBuffer),Et=new WeakMap,wt=1,xt=new WeakMap;function Q(t={}){if(!z(t))throw new Error("object required");let e=Et.get(t);if(e)return e;let n=wt,r=new Set,a=(f,h=++wt)=>{n!==h&&(n=h,r.forEach(i=>i(f,h)))},u=new Map,g=f=>{let h=u.get(f);return h||(h=(i,o)=>{let s=[...i];s[1]=[f,...s[1]],a(s,o)},u.set(f,h)),h},m=f=>{let h=u.get(f);return u.delete(f),h},y=(f,h)=>{let i=xt.get(h);if(i?.[0]===n)return i[1];let o=Array.isArray(f)?[]:Object.create(Object.getPrototypeOf(f));return yt(o,!0),xt.set(h,[n,o]),Reflect.ownKeys(f).forEach(s=>{let l=Reflect.get(f,s,h);if(Z.has(l))yt(l,!1),o[s]=l;else if(l instanceof Promise)if(D in l)o[s]=l[D];else{let d=l[bt]||l;Object.defineProperty(o,s,{get(){if(D in l)return l[D];throw d}})}else l?.[A]?o[s]=l[H]:o[s]=l}),Object.freeze(o),o},b=Array.isArray(t)?[]:Object.create(Object.getPrototypeOf(t)),E={get(f,h,i){return h===Lt?n:h===A?r:h===H?y(f,i):h===Zt?E:Reflect.get(f,h,i)},deleteProperty(f,h){let i=Reflect.get(f,h),o=i?.[A];o&&o.delete(m(h));let s=Reflect.deleteProperty(f,h);return s&&a(["delete",[h],i]),s},is:Object.is,canProxy:Qt,set(f,h,i,o){var s;let l=Reflect.get(f,h,o);if(this.is(l,i))return!0;let d=l?.[A];d&&d.delete(m(h)),z(i)&&(i=Jt(i)||i);let c;return(s=Object.getOwnPropertyDescriptor(f,h))!=null&&s.set?c=i:i instanceof Promise?c=i.then(v=>(c[D]=v,a(["resolve",[h],v]),v)).catch(v=>{c[bt]=v,a(["reject",[h],v])}):i?.[A]?(c=i,c[A].add(g(h))):this.canProxy(i)?(c=Q(i),c[A].add(g(h))):c=i,Reflect.set(f,h,c,o),a(["set",[h],i,l]),!0}},T=new Proxy(b,E);return Et.set(t,T),Reflect.ownKeys(t).forEach(f=>{let h=Object.getOwnPropertyDescriptor(t,f);h.get||h.set?Object.defineProperty(b,f,h):T[f]=t[f]}),T}function St(t){return z(t)?t[Lt]:void 0}function tt(t,e,n){(K.env&&K.env.MODE)!=="production"&&!t?.[A]&&console.warn("Please use proxy object");let r,a=[],u=g=>{if(a.push(g),n){e(a.splice(0));return}r||(r=Promise.resolve().then(()=>{r=void 0,e(a.splice(0))}))};return t[A].add(u),()=>{t[A].delete(u)}}function te(t){return(K.env&&K.env.MODE)!=="production"&&!t?.[H]&&console.warn("Please use proxy object"),t[H]}function ee(t){for(;t.length>0;)t.pop();return t}var Tt=(t,...e)=>(typeof t=="function"?t(...e):t)??void 0,C=t=>t,At=()=>{};var ne=(()=>{let t=0;return()=>(t++,t.toString(36))})(),M=t=>Array.isArray(t),W=t=>!(t==null||typeof t!="object"||M(t)),ie=t=>typeof t=="number"&&!Number.isNaN(t),S=t=>typeof t=="string",P=t=>typeof t=="function";function U(...t){let e=t.length===1?t[0]:t[1],n=t.length===2?t[0]:!0}function G(...t){let e=t.length===1?t[0]:t[1],n=t.length===2?t[0]:!0}function re(t){return W(t)&&t.predicate!=null}function Y(t,e){return(n,r)=>re(t)?t.predicate(e??{})(n,r):t}function oe(...t){return{predicate:e=>(n,r)=>t.map(a=>{var u;return S(a)?!!((u=e[a])!=null&&u.call(e,n,r)):P(a)?a(n,r):a.predicate(e)(n,r)}).some(Boolean)}}function se(...t){return{predicate:e=>(n,r)=>t.map(a=>{var u;return S(a)?!!((u=e[a])!=null&&u.call(e,n,r)):P(a)?a(n,r):a.predicate(e)(n,r)}).every(Boolean)}}function ae(t){return{predicate:e=>(n,r)=>{var a;return S(t)?!((a=e[t])!=null&&a.call(e,n,r)):P(t)?!t(n,r):!t.predicate(e)(n,r)}}}var kt={or:oe,and:se,not:ae};function le(t){return W(t)&&t.predicate!=null}var ue=()=>!0;function It(t,e){return t=t??ue,(n,r)=>{if(S(t)){let a=e?.[t];return P(a)?a(n,r):a}return le(t)?t.predicate(e??{})(n,r):t?.(n,r)}}function N(t){var e,n,r;if(Array.isArray(t)){for(n=Array(e=t.length);e--;)n[e]=(r=t[e])&&typeof r=="object"?N(r):r;return n}if(Object.prototype.toString.call(t)==="[object Object]"){n={};for(e in t)e==="__proto__"?Object.defineProperty(n,e,{value:N(t[e]),configurable:!0,enumerable:!0,writable:!0}):n[e]=(r=t[e])&&typeof r=="object"?N(r):r;return n}return t}function Ct(t,e,n,r){return tt(t,a=>{a.some(u=>u[1][0]===e)&&n(t[e])},r)}var je=Symbol(),I=new WeakMap,F=new WeakMap,Mt=(t,e)=>{let n=I.get(t);n&&(n[0].forEach(r=>{let{d:a}=r;t!==a&&Mt(a)}),++n[2],e&&n[3].add(e))},ce=(t,e)=>{let n=I.get(t);return n?.[2]?(n[3].add(e),!0):!1},J=t=>{let e=I.get(t);e&&(--e[2],e[2]||(e[3].forEach(n=>n()),e[3].clear()),e[0].forEach(n=>{let{d:r}=n;t!==r&&J(r)}))},de=t=>{let{s:e,d:n}=t,r=F.get(n);r||(r=[new Set],F.set(t.d,r)),r[0].add(t);let a=I.get(e);if(!a){let u=new Set,g=tt(e,m=>{u.forEach(y=>{let{d:b,c:E,n:T,i:f}=y;e===b&&m.every(h=>h[1].length===1&&f.includes(h[1][0]))||y.p||(Mt(e,E),T?J(e):y.p=Promise.resolve().then(()=>{delete y.p,J(e)}))})},!0);a=[u,g,0,new Set],I.set(e,a)}a[0].add(t)},Pt=t=>{let{s:e,d:n}=t,r=F.get(n);r?.[0].delete(t),r?.[0].size===0&&F.delete(n);let a=I.get(e);if(a){let[u,g]=a;u.delete(t),u.size||(g(),I.delete(e))}},he=t=>{let e=F.get(t);return e?Array.from(e[0]):[]};function fe(t,e){let n=e?.proxy||Q({}),r=!!e?.sync,a=Object.keys(t);return a.forEach(u=>{if(Object.getOwnPropertyDescriptor(n,u))throw new Error("object property already defined");let g=t[u],m=null,y=()=>{if(m&&(Array.from(m).map(([f])=>ce(f,y)).some(f=>f)||Array.from(m).every(([f,h])=>St(f)===h.v)))return;let b=new Map,E=g(f=>(b.set(f,{v:St(f)}),f)),T=()=>{b.forEach((f,h)=>{var i;let o=(i=m?.get(h))==null?void 0:i.s;if(o)f.s=o;else{let s={s:h,d:n,k:u,c:y,n:r,i:a};de(s),f.s=s}}),m?.forEach((f,h)=>{!b.has(h)&&f.s&&Pt(f.s)}),m=b};E instanceof Promise?E.finally(T):T(),n[u]=E};y()}),n}function pe(t,e){let n=e?.delete?new Set:null;he(t).forEach(r=>{let{k:a}=r;(!e?.keys||e.keys.includes(a))&&(Pt(r),n&&n.add(a))}),n&&n.forEach(r=>{delete t[r]})}function ve(t){var e;let n=Q({value:"",previousValue:"",event:C({}),context:(e=t.context)!=null?e:C({}),done:!1,tags:[],hasTag(r){return this.tags.includes(r)},matches(...r){return r.includes(this.value)},can(r){return C(this).nextEvents.includes(r)},get nextEvents(){var r,a,u,g;let m=(u=(a=(r=t.states)==null?void 0:r[this.value])==null?void 0:a.on)!=null?u:{},y=(g=t?.on)!=null?g:{};return Object.keys({...m,...y})},get changed(){return this.event.value==="machine.init"||!this.previousValue?!1:this.value!==this.previousValue}});return C(n)}function j(t,e){return(n,r)=>{if(ie(t))return t;if(P(t))return t(n,r);if(S(t)){let a=Number.parseFloat(t);if(!Number.isNaN(a))return a;if(e){let u=e?.[t];if(u==null){let g=`[machine] Cannot determine delay for ${t}. It doesn't exist in options.delays`;throw new Error(g)}return P(u)?u(n,r):u}}}}function x(t){return S(t)?{type:t}:t}function k(t){return t?M(t)?t:[t]:[]}function Ot(t){return S(t)?{target:t}:t}function ge(t,e){return(n,r)=>k(t).map(Ot).find(a=>{var u;let g=It(a.guard,e)(n,r);return(u=g??a.target)!=null?u:a.actions})}function me(t,e){let n=S(t)?Ot(t):t,r=a=>(a.actions&&!a.target&&e&&(a.target=e),a);if(M(n))return n.map(r);if(W(n))return r(C(n))}var B=class{constructor(t,e){this.config=t,this.status="Not Started",this.type="machine",this.activityEvents=new Map,this.delayedEvents=new Map,this.stateListeners=new Set,this.eventListeners=new Set,this.doneListeners=new Set,this.contextWatchers=new Set,this.removeStateListener=At,this.removeEventListener=At,this.children=new Map,this.start=i=>{if(this.status==="Running")return this;this.status="Running";let o=x("machine.init");if(i){let d=W(i)?i:{context:this.config.context,value:i};this.setState(d.value),this.setContext(d.context)}let s={target:i?void 0:this.config.initial},l=this.getNextStateInfo(s,o);return l.target=C(l.target||s.target),this.initialState=l,this.performStateChangeEffects(l.target,l,o),this.removeStateListener=tt(this.state,()=>{this.stateListeners.forEach(d=>{d(this.stateSnapshot)})},this.sync),this.removeEventListener=Ct(this.state,"event",d=>{this.config.onEvent&&this.executeActions(this.config.onEvent,d);for(let c of this.eventListeners)c(d)}),this.setupContextWatchers(),this.executeActivities(x("machine.start"),k(this.config.activities),"machine.start"),this.executeActions(this.config.entry,x("machine.start")),this},this.setupContextWatchers=()=>{var i;for(let[o,s]of Object.entries((i=this.config.watch)!=null?i:{}))this.contextWatchers.add(Ct(this.state.context,o,()=>{this.executeActions(s,this.state.event)}))},this.setupComputed=()=>{var i;let o=C((i=this.config.computed)!=null?i:{}),s=Object.fromEntries(Object.entries(o).map(([l,d])=>[l,c=>d(c(this.state.context))]));fe(s,{proxy:this.state.context})},this.detachComputed=()=>{pe(this.state.context,{delete:!0})},this.stop=()=>{if(this.status!=="Stopped")return this.setState(null),this.setEvent("machine.stop"),this.config.context&&this.setContext(this.config.context),this.stopStateListeners(),this.stopChildren(),this.stopActivities(),this.stopDelayedEvents(),this.stopContextWatchers(),this.stopEventListeners(),this.detachComputed(),this.status="Stopped",this.executeActions(this.config.exit,x("machine.stop")),this},this.stopEventListeners=()=>{this.eventListeners.clear(),this.removeEventListener()},this.stopStateListeners=()=>{this.removeStateListener(),this.stateListeners.clear()},this.stopContextWatchers=()=>{this.contextWatchers.forEach(i=>i()),this.contextWatchers.clear()},this.stopDelayedEvents=()=>{this.delayedEvents.forEach(i=>{i.forEach(o=>o())}),this.delayedEvents.clear()},this.stopActivities=i=>{var o,s;i?((o=this.activityEvents.get(i))==null||o.forEach(l=>l()),(s=this.activityEvents.get(i))==null||s.clear(),this.activityEvents.delete(i)):(this.activityEvents.forEach(l=>{l.forEach(d=>d()),l.clear()}),this.activityEvents.clear())},this.sendChild=(i,o)=>{let s=x(i),l=Tt(o,this.contextSnapshot),d=this.children.get(l);d||G(`[machine/send-child] Cannot send '${s.type}' event to unknown child`),d.send(s)},this.stopChild=i=>{this.children.has(i)||G("[machine/stop-child] Cannot stop unknown child"),this.children.get(i).stop(),this.children.delete(i)},this.removeChild=i=>{this.children.delete(i)},this.stopChildren=()=>{this.children.forEach(i=>i.stop()),this.children.clear()},this.setParent=i=>{this.parent=i},this.spawn=(i,o)=>{let s=Tt(i);return o&&(s.id=o),s.type="machine.actor",s.setParent(this),this.children.set(s.id,C(s)),s.onDone(()=>{this.removeChild(s.id)}).start(),C(_(s))},this.addActivityCleanup=(i,o)=>{var s;!i||(this.activityEvents.has(i)?(s=this.activityEvents.get(i))==null||s.add(o):this.activityEvents.set(i,new Set([o])))},this.setState=i=>{this.state.previousValue=this.state.value,this.state.value=i;let o=this.getStateNode(i);i==null?ee(this.state.tags):this.state.tags=k(o?.tags)},this.setContext=i=>{for(let o in i)this.state.context[o]=i[o]},this.withContext=i=>{this.detachComputed();let o={...this.config.context,...i};return new B({...this.config,context:o},this.options)},this.withOptions=i=>(this.detachComputed(),new B(this.config,{...this.options,...i})),this.setActions=i=>{this.actionMap={...this.actionMap,...i}},this.clone=()=>(this.detachComputed(),new B(this.config,this.options)),this.getStateNode=i=>{var o;if(i)return(o=this.config.states)==null?void 0:o[i]},this.getNextStateInfo=(i,o)=>{var s;let l=this.determineTransition(i,o),d=(s=l?.target)!=null?s:this.state.value,c=this.getStateNode(d);return{transition:l,stateNode:c,target:d}},this.getActionFromDelayedTransition=i=>{let o=x("machine.after"),s=j(i.delay,this.delayMap)(this.contextSnapshot,o),l;return{entry:()=>{l=globalThis.setTimeout(()=>{let d=this.state.value,c=this.getNextStateInfo(i,o);this.performStateChangeEffects(d,c,o)},s)},exit:()=>{globalThis.clearTimeout(l)}}},this.getDelayedEventActions=i=>{let o=this.getStateNode(i),s=x("machine.after");if(!o||!o.after)return;let l=[],d=[];if(M(o.after)){let c=this.determineTransition(o.after,s);if(!c)return;let v=this.getActionFromDelayedTransition(c);l.push(v.entry),d.push(v.exit)}else if(W(o.after))for(let c in o.after){let v=o.after[c],w={};if(M(v)){let R=this.determineTransition(v,s);R&&(w=R)}else S(v)?w={target:v,delay:c}:w={...v,delay:c};let O=this.getActionFromDelayedTransition(w);l.push(O.entry),d.push(O.exit)}return{entries:l,exits:d}},this.executeActions=(i,o)=>{var s;let l=Y(i,this.guardMap)(this.contextSnapshot,o);for(let d of k(l)){let c=S(d)?(s=this.actionMap)==null?void 0:s[d]:d;U(S(d)&&!c,`[machine/exec-action] No implementation found for action: \`${d}\``),c?.(this.state.context,o,this.meta)}},this.executeActivities=(i,o,s)=>{var l;for(let d of o){let c=S(d)?(l=this.activityMap)==null?void 0:l[d]:d;if(!c){U(`[machine/exec-activity] No implementation found for activity: \`${d}\``);continue}let v=c(this.state.context,i,this.meta);v&&this.addActivityCleanup(s??this.state.value,v)}},this.createEveryActivities=(i,o)=>{if(!i)return;let s=x("machine.every");if(M(i)){let l=k(i).find(c=>{let v=j(c.delay,this.delayMap);c.delay=v(this.contextSnapshot,s);let w=It(c.guard,this.guardMap)(this.contextSnapshot,s);return w??c.delay});if(!l)return;let d=j(l.delay,this.delayMap)(this.contextSnapshot,s);o(()=>{let c=globalThis.setInterval(()=>{this.executeActions(l.actions,s)},d);return()=>{globalThis.clearInterval(c)}})}else for(let l in i){let d=i?.[l],c=j(l,this.delayMap)(this.contextSnapshot,s);o(()=>{let v=globalThis.setInterval(()=>{this.executeActions(d,s)},c);return()=>{globalThis.clearInterval(v)}})}},this.setEvent=i=>{this.state.event=_(x(i))},this.performExitEffects=(i,o)=>{let s=this.state.value,l=i?this.getStateNode(i):void 0;this.stopActivities(s);let d=Y(l?.exit,this.guardMap)(this.contextSnapshot,o),c=k(d),v=this.delayedEvents.get(s);v&&c.push(...v),this.executeActions(c,o),this.eventListeners.clear()},this.performEntryEffects=(i,o)=>{let s=this.getStateNode(i),l=k(s?.activities);this.createEveryActivities(s?.every,w=>{l.unshift(w)}),l.length>0&&this.executeActivities(o,l);let d=Y(s?.entry,this.guardMap)(this.contextSnapshot,o),c=k(d),v=this.getDelayedEventActions(i);s?.after&&v&&(this.delayedEvents.set(i,v?.exits),c.push(...v.entries)),this.executeActions(c,o),s?.type==="final"&&(this.state.done=!0,this.doneListeners.forEach(w=>{w(this.stateSnapshot)}),this.stop())},this.performTransitionEffects=(i,o)=>{let s=this.determineTransition(i,o);this.executeActions(s?.actions,o)},this.performStateChangeEffects=(i,o,s)=>{var l,d;this.setEvent(s),o.target=(d=(l=o.target)!=null?l:this.state.value)!=null?d:void 0;let c=o.target&&o.target!==this.state.value;c&&this.performExitEffects(i,s),this.performTransitionEffects(o?.transition,s),this.setState(o.target),c&&this.performEntryEffects(o.target,s)},this.determineTransition=(i,o)=>{let s=ge(i,this.guardMap);return s?.(this.contextSnapshot,o)},this.sendParent=i=>{var o;this.parent||G("[machine/send-parent] Cannot send event to an unknown parent");let s=x(i);(o=this.parent)==null||o.send(s)},this.send=i=>{let o=x(i);this.transition(this.state.value,o)},this.transition=(i,o)=>{var s,l,d;let c=S(i)?this.getStateNode(i):i?.stateNode,v=x(o);if(!c&&!this.config.on){let Dt=this.status==="Stopped"?"[machine/transition] Cannot transition a stopped machine":"[machine/transition] State does not have a definition";U(Dt);return}let w=(d=(s=c?.on)==null?void 0:s[v.type])!=null?d:(l=this.config.on)==null?void 0:l[v.type],O=me(w,this.state.value);if(!O)return;let R=this.getNextStateInfo(O,v);return this.performStateChangeEffects(this.state.value,R,v),R.stateNode},this.subscribe=i=>(this.stateListeners.add(i),this.status==="Running"&&i(this.stateSnapshot),()=>{this.stateListeners.delete(i)}),this.onDone=i=>(this.doneListeners.add(i),this),this.onTransition=i=>(this.stateListeners.add(i),this.status==="Running"&&i(this.stateSnapshot),this),this.onEvent=i=>(i(this.state.event),this.eventListeners.add(i),this);var n,r,a,u,g,m,y,b,E,T,f;this.options=N(e),this.id=(n=t.id)!=null?n:`machine-${ne()}`,this.guardMap=(a=(r=this.options)==null?void 0:r.guards)!=null?a:{},this.actionMap=(g=(u=this.options)==null?void 0:u.actions)!=null?g:{},this.delayMap=(y=(m=this.options)==null?void 0:m.delays)!=null?y:{},this.activityMap=(E=(b=this.options)==null?void 0:b.activities)!=null?E:{},this.sync=(f=(T=this.options)==null?void 0:T.sync)!=null?f:!1,this.state=ve(N(t)),this.setupComputed();let h=x("machine.created");this.executeActions(t?.created,h)}get stateSnapshot(){return C(te(this.state))}get contextSnapshot(){return this.stateSnapshot.context}get self(){let t=this;return{id:this.id,send:this.send.bind(this),sendParent:this.sendParent.bind(this),sendChild:this.sendChild.bind(this),stop:this.stop.bind(this),stopChild:this.stopChild.bind(this),spawn:this.spawn.bind(this),get state(){return t.stateSnapshot}}}get meta(){return{state:this.stateSnapshot,guards:this.guardMap,send:this.send.bind(this),listen:this.onEvent.bind(this),self:this.self,getState:()=>this.stateSnapshot}}},Rt=(t,e)=>new B(t,e);var{not:ye}=kt,Vt=Rt({initial:"unknown",context:{dir:"ltr",orientation:"horizontal",activationMode:"automatic",value:null,focusedValue:null,uid:"",previousValues:[],indicatorRect:{left:"0px",top:"0px",width:"0px",height:"0px"},hasMeasuredRect:!1,isIndicatorRendered:!1,loop:!0,messages:{}},computed:{isHorizontal:t=>t.orientation==="horizontal",isVertical:t=>t.orientation==="vertical"},created:["setPrevSelectedTabs"],watch:{focusedValue:"invokeOnFocus",value:["invokeOnChange","setPrevSelectedTabs","setIndicatorRect","setContentTabIndex"],dir:["clearMeasured","setIndicatorRect"]},on:{SET_VALUE:{actions:"setValue"},DELETE:{actions:"deleteValue"}},states:{unknown:{on:{SETUP:{target:"idle",actions:["setupDocument","checkRenderedElements","setIndicatorRect","setContentTabIndex"]}}},idle:{on:{TAB_FOCUS:{guard:"selectOnFocus",target:"focused",actions:["setFocusedValue","setValue"]},TAB_CLICK:{target:"focused",actions:["setFocusedValue","setValue"]}}},focused:{on:{TAB_CLICK:{target:"focused",actions:["setFocusedValue","setValue"]},ARROW_LEFT:{guard:"isHorizontal",actions:"focusPrevTab"},ARROW_RIGHT:{guard:"isHorizontal",actions:"focusNextTab"},ARROW_UP:{guard:"isVertical",actions:"focusPrevTab"},ARROW_DOWN:{guard:"isVertical",actions:"focusNextTab"},HOME:{actions:"focusFirstTab"},END:{actions:"focusLastTab"},ENTER:{guard:ye("selectOnFocus"),actions:"setValue"},TAB_FOCUS:[{guard:"selectOnFocus",actions:["setFocusedValue","setValue"]},{actions:"setFocusedValue"}],TAB_BLUR:{target:"idle",actions:"clearFocusedValue"}}}}},{guards:{isVertical:t=>t.isVertical,isHorizontal:t=>t.isHorizontal,selectOnFocus:t=>t.activationMode==="automatic"},actions:{setupDocument(t,e){t.uid=e.id,e.doc&&(t.doc=_(e.doc))},setFocusedValue(t,e){t.focusedValue=e.value},clearFocusedValue(t){t.focusedValue=null},setValue(t,e){t.value=e.value},invokeOnDelete(t,e){var n;(n=t.onDelete)==null||n.call(t,{value:e.value})},focusFirstTab(t){L(()=>{var e;return(e=p.getFirstEl(t))==null?void 0:e.focus()})},focusLastTab(t){L(()=>{var e;return(e=p.getLastEl(t))==null?void 0:e.focus()})},focusNextTab(t){if(!t.focusedValue)return;let e=p.getNextEl(t,t.focusedValue);L(()=>e==null?void 0:e.focus())},focusPrevTab(t){if(!t.focusedValue)return;let e=p.getPrevEl(t,t.focusedValue);L(()=>e==null?void 0:e.focus())},setIndicatorRect(t){L(()=>{!t.isIndicatorRendered||!t.value||(t.indicatorRect=p.getRectById(t,t.value),!t.hasMeasuredRect&&L(()=>{t.hasMeasuredRect=!0}))})},checkRenderedElements(t){L(()=>{t.isIndicatorRendered=!!p.getIndicatorEl(t)})},clearMeasured(t){t.hasMeasuredRect=!1},invokeOnChange(t){var e;(e=t.onChange)==null||e.call(t,{value:t.value})},invokeOnFocus(t){var e;(e=t.onFocus)==null||e.call(t,{value:t.focusedValue})},setPrevSelectedTabs(t){if(t.value!=null){let e=Array.from(t.previousValues).concat(t.value);t.previousValues=Array.from(new Set(e))}},setContentTabIndex(t){L(()=>{let e=p.getActiveContentEl(t);if(!e)return;st(e).length>0?e.removeAttribute("tabindex"):e.setAttribute("tabindex","0")})}}});
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __export = (target, all) => {
20
+ for (var name in all)
21
+ __defProp(target, name, { get: all[name], enumerable: true });
22
+ };
23
+ var __copyProps = (to, from, except, desc) => {
24
+ if (from && typeof from === "object" || typeof from === "function") {
25
+ for (let key of __getOwnPropNames(from))
26
+ if (!__hasOwnProp.call(to, key) && key !== except)
27
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
28
+ }
29
+ return to;
30
+ };
31
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
+
33
+ // src/index.ts
34
+ var src_exports = {};
35
+ __export(src_exports, {
36
+ connect: () => connect,
37
+ machine: () => machine
38
+ });
39
+ module.exports = __toCommonJS(src_exports);
40
+
41
+ // ../../utilities/dom/dist/index.mjs
42
+ var dataAttr = (guard) => {
43
+ return guard ? "" : void 0;
44
+ };
45
+ function getStyleCache() {
46
+ ;
47
+ globalThis.__styleCache__ = globalThis.__styleCache__ || /* @__PURE__ */ new WeakMap();
48
+ return globalThis.__styleCache__;
49
+ }
50
+ function getComputedStyle2(el) {
51
+ var _a;
52
+ if (!el)
53
+ return {};
54
+ const cache = getStyleCache();
55
+ let style = cache.get(el);
56
+ if (!style) {
57
+ const win = (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
58
+ style = win.getComputedStyle(el);
59
+ cache.set(el, style);
60
+ }
61
+ return style;
62
+ }
63
+ function nextTick(fn) {
64
+ const set = /* @__PURE__ */ new Set();
65
+ function raf2(fn2) {
66
+ const id = globalThis.requestAnimationFrame(fn2);
67
+ set.add(() => globalThis.cancelAnimationFrame(id));
68
+ }
69
+ raf2(() => raf2(fn));
70
+ return function cleanup() {
71
+ set.forEach(function(fn2) {
72
+ fn2();
73
+ });
74
+ };
75
+ }
76
+ function isHTMLElement(v) {
77
+ return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string";
78
+ }
79
+ var isDisabled = (el) => {
80
+ return (el == null ? void 0 : el.getAttribute("disabled")) != null || !!(el == null ? void 0 : el.getAttribute("aria-disabled")) === true;
81
+ };
82
+ var focusableSelector = /* @__PURE__ */ [
83
+ "input:not([disabled]):not([type=hidden])",
84
+ "select:not([disabled])",
85
+ "textarea:not([disabled])",
86
+ "button:not([disabled])",
87
+ "embed",
88
+ "iframe",
89
+ "object",
90
+ "a[href]",
91
+ "area[href]",
92
+ "[tabindex]",
93
+ "audio[controls]",
94
+ "video[controls]",
95
+ "*[tabindex]:not([aria-disabled])",
96
+ "[contenteditable]:not([contenteditable=false])",
97
+ "details > summary:first-of-type"
98
+ ].join(",");
99
+ function isHidden(el, until) {
100
+ const style = getComputedStyle2(el);
101
+ if (!el || style.getPropertyValue("visibility") === "hidden")
102
+ return true;
103
+ while (el) {
104
+ if (until != null && el === until)
105
+ return false;
106
+ if (style.getPropertyValue("display") === "none")
107
+ return true;
108
+ el = el.parentElement;
109
+ }
110
+ return false;
111
+ }
112
+ var getFocusables = (el, includeContainer = false) => {
113
+ if (!el)
114
+ return [];
115
+ let els = Array.from(el.querySelectorAll(focusableSelector));
116
+ if (includeContainer && isHTMLElement(el)) {
117
+ els.unshift(el);
118
+ }
119
+ return els.filter((el2) => isFocusable(el2) && !isHidden(el2));
120
+ };
121
+ var isFocusable = (el) => {
122
+ if (!isHTMLElement(el) || isHidden(el) || isDisabled(el))
123
+ return false;
124
+ return el == null ? void 0 : el.matches(focusableSelector);
125
+ };
126
+ var rtlKeyMap = {
127
+ ArrowLeft: "ArrowRight",
128
+ ArrowRight: "ArrowLeft",
129
+ Home: "End",
130
+ End: "Home"
131
+ };
132
+ var sameKeyMap = {
133
+ Up: "ArrowUp",
134
+ Down: "ArrowDown",
135
+ Esc: "Escape",
136
+ " ": "Space",
137
+ ",": "Comma",
138
+ Left: "ArrowLeft",
139
+ Right: "ArrowRight"
140
+ };
141
+ function getEventKey(event, options = {}) {
142
+ var _a;
143
+ const { dir = "ltr", orientation = "horizontal" } = options;
144
+ let { key } = event;
145
+ key = (_a = sameKeyMap[key]) != null ? _a : key;
146
+ const isRtl = dir === "rtl" && orientation === "horizontal";
147
+ if (isRtl && key in rtlKeyMap) {
148
+ key = rtlKeyMap[key];
149
+ }
150
+ return key;
151
+ }
152
+ function queryAll(root, selector) {
153
+ var _a;
154
+ return Array.from((_a = root == null ? void 0 : root.querySelectorAll(selector)) != null ? _a : []);
155
+ }
156
+ function itemById(v, id) {
157
+ return v.find((node) => node.id === id);
158
+ }
159
+ function indexOfId(v, id) {
160
+ const item = itemById(v, id);
161
+ return item ? v.indexOf(item) : -1;
162
+ }
163
+ function nextById(v, id, loop = true) {
164
+ let idx = indexOfId(v, id);
165
+ idx = loop ? (idx + 1) % v.length : Math.min(idx + 1, v.length - 1);
166
+ return v[idx];
167
+ }
168
+ function prevById(v, id, loop = true) {
169
+ let idx = indexOfId(v, id);
170
+ if (idx === -1)
171
+ return loop ? v[v.length - 1] : null;
172
+ idx = loop ? (idx - 1 + v.length) % v.length : Math.max(0, idx - 1);
173
+ return v[idx];
174
+ }
175
+
176
+ // ../../types/dist/index.mjs
177
+ function createNormalizer(fn) {
178
+ return { button: fn, label: fn, input: fn, output: fn, element: fn };
179
+ }
180
+ var normalizeProp = createNormalizer((v) => v);
181
+
182
+ // ../../utilities/core/dist/index.mjs
183
+ var first = (v) => v[0];
184
+ var last = (v) => v[v.length - 1];
185
+ var ua = (v) => isDom() && v.test(navigator.userAgent);
186
+ var isDom = () => !!(typeof window !== "undefined");
187
+ var isSafari = () => ua(/^((?!chrome|android).)*safari/i);
188
+
189
+ // src/tabs.dom.ts
190
+ var dom = {
191
+ getDoc: (ctx) => {
192
+ var _a;
193
+ return (_a = ctx.doc) != null ? _a : document;
194
+ },
195
+ getRootId: (ctx) => {
196
+ var _a, _b;
197
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `tabs-${ctx.uid}`;
198
+ },
199
+ getTriggerGroupId: (ctx) => {
200
+ var _a, _b;
201
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.triggerGroup) != null ? _b : `tabs-${ctx.uid}-trigger-group`;
202
+ },
203
+ getContentId: (ctx, id) => {
204
+ var _a, _b;
205
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.content) != null ? _b : `tabs-${ctx.uid}-content-${id}`;
206
+ },
207
+ getContentGroupId: (ctx) => {
208
+ var _a, _b;
209
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.contentGroup) != null ? _b : `tabs-${ctx.uid}-content-group`;
210
+ },
211
+ getTriggerId: (ctx, id) => {
212
+ var _a, _b;
213
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.trigger) != null ? _b : `tabs-${ctx.uid}-trigger-${id}`;
214
+ },
215
+ getIndicatorId: (ctx) => `tabs-${ctx.uid}-indicator`,
216
+ getTriggerGroupEl: (ctx) => dom.getDoc(ctx).getElementById(dom.getTriggerGroupId(ctx)),
217
+ getContentEl: (ctx, id) => dom.getDoc(ctx).getElementById(dom.getContentId(ctx, id)),
218
+ getTriggerEl: (ctx, id) => dom.getDoc(ctx).getElementById(dom.getTriggerId(ctx, id)),
219
+ getIndicatorEl: (ctx) => dom.getDoc(ctx).getElementById(dom.getIndicatorId(ctx)),
220
+ getElements: (ctx) => {
221
+ const ownerId = CSS.escape(dom.getTriggerGroupId(ctx));
222
+ const selector = `[role=tab][data-ownedby='${ownerId}']:not([disabled])`;
223
+ return queryAll(dom.getTriggerGroupEl(ctx), selector);
224
+ },
225
+ getFirstEl: (ctx) => first(dom.getElements(ctx)),
226
+ getLastEl: (ctx) => last(dom.getElements(ctx)),
227
+ getNextEl: (ctx, id) => nextById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
228
+ getPrevEl: (ctx, id) => prevById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
229
+ getRectById: (ctx, id) => {
230
+ var _a;
231
+ const empty = { offsetLeft: 0, offsetTop: 0, offsetWidth: 0, offsetHeight: 0 };
232
+ const tab = (_a = itemById(dom.getElements(ctx), dom.getTriggerId(ctx, id))) != null ? _a : empty;
233
+ if (ctx.isVertical) {
234
+ return { top: `${tab.offsetTop}px`, height: `${tab.offsetHeight}px` };
235
+ }
236
+ return { left: `${tab.offsetLeft}px`, width: `${tab.offsetWidth}px` };
237
+ },
238
+ getActiveContentEl: (ctx) => {
239
+ if (!ctx.value)
240
+ return;
241
+ const id = dom.getContentId(ctx, ctx.value);
242
+ return dom.getDoc(ctx).getElementById(id);
243
+ }
244
+ };
245
+
246
+ // src/tabs.connect.ts
247
+ function connect(state, send, normalize = normalizeProp) {
248
+ const messages = state.context.messages;
249
+ const isFocused = state.matches("focused");
250
+ return {
251
+ value: state.context.value,
252
+ focusedValue: state.context.focusedValue,
253
+ previousValues: Array.from(state.context.previousValues),
254
+ setValue(value) {
255
+ send({ type: "SET_VALUE", value });
256
+ },
257
+ rootProps: normalize.element({
258
+ "data-part": "root",
259
+ id: dom.getRootId(state.context),
260
+ "data-orientation": state.context.orientation,
261
+ "data-focus": dataAttr(isFocused),
262
+ dir: state.context.dir
263
+ }),
264
+ triggerGroupProps: normalize.element({
265
+ "data-part": "trigger-group",
266
+ id: dom.getTriggerGroupId(state.context),
267
+ role: "tablist",
268
+ "data-focus": dataAttr(isFocused),
269
+ "aria-orientation": state.context.orientation,
270
+ "data-orientation": state.context.orientation,
271
+ "aria-label": messages.tablistLabel,
272
+ onKeyDown(event) {
273
+ const keyMap = {
274
+ ArrowDown() {
275
+ send("ARROW_DOWN");
276
+ },
277
+ ArrowUp() {
278
+ send("ARROW_UP");
279
+ },
280
+ ArrowLeft() {
281
+ send("ARROW_LEFT");
282
+ },
283
+ ArrowRight() {
284
+ send("ARROW_RIGHT");
285
+ },
286
+ Home() {
287
+ send("HOME");
288
+ },
289
+ End() {
290
+ send("END");
291
+ },
292
+ Enter() {
293
+ send({ type: "ENTER", value: state.context.focusedValue });
294
+ }
295
+ };
296
+ let key = getEventKey(event, state.context);
297
+ const exec = keyMap[key];
298
+ if (exec) {
299
+ event.preventDefault();
300
+ exec(event);
301
+ }
302
+ }
303
+ }),
304
+ getTriggerProps(props) {
305
+ const { value, disabled } = props;
306
+ const selected = state.context.value === value;
307
+ return normalize.button({
308
+ "data-part": "trigger",
309
+ role: "tab",
310
+ type: "button",
311
+ disabled,
312
+ "data-orientation": state.context.orientation,
313
+ "data-disabled": dataAttr(disabled),
314
+ "aria-disabled": disabled,
315
+ "data-value": value,
316
+ "aria-selected": selected,
317
+ "data-selected": dataAttr(selected),
318
+ "aria-controls": dom.getContentId(state.context, value),
319
+ "data-ownedby": dom.getTriggerGroupId(state.context),
320
+ id: dom.getTriggerId(state.context, value),
321
+ tabIndex: selected ? 0 : -1,
322
+ onFocus() {
323
+ send({ type: "TAB_FOCUS", value });
324
+ },
325
+ onBlur(event) {
326
+ const target = event.relatedTarget;
327
+ if ((target == null ? void 0 : target.getAttribute("role")) !== "tab") {
328
+ send({ type: "TAB_BLUR" });
329
+ }
330
+ },
331
+ onClick(event) {
332
+ if (disabled)
333
+ return;
334
+ if (isSafari()) {
335
+ event.currentTarget.focus();
336
+ }
337
+ send({ type: "TAB_CLICK", value });
338
+ }
339
+ });
340
+ },
341
+ contentGroupProps: normalize.element({
342
+ "data-part": "content-group",
343
+ id: dom.getContentGroupId(state.context),
344
+ "data-orientation": state.context.orientation
345
+ }),
346
+ getContentProps({ value }) {
347
+ const selected = state.context.value === value;
348
+ return normalize.element({
349
+ "data-part": "content",
350
+ id: dom.getContentId(state.context, value),
351
+ tabIndex: 0,
352
+ "aria-labelledby": dom.getTriggerId(state.context, value),
353
+ role: "tabpanel",
354
+ "data-ownedby": dom.getTriggerGroupId(state.context),
355
+ hidden: !selected
356
+ });
357
+ },
358
+ getDeleteButtonProps({ value, disabled }) {
359
+ var _a;
360
+ return normalize.button({
361
+ "data-part": "delete-button",
362
+ type: "button",
363
+ tabIndex: -1,
364
+ "aria-label": (_a = messages.deleteLabel) == null ? void 0 : _a.call(messages, value),
365
+ disabled,
366
+ onClick() {
367
+ send({ type: "DELETE", value });
368
+ }
369
+ });
370
+ },
371
+ indicatorProps: normalize.element({
372
+ id: dom.getIndicatorId(state.context),
373
+ "data-part": "indicator",
374
+ "data-orientation": state.context.orientation,
375
+ style: __spreadValues({
376
+ "--transition-duration": "200ms",
377
+ "--transition-property": "left, right, top, bottom, width, height",
378
+ position: "absolute",
379
+ willChange: "var(--transition-property)",
380
+ transitionProperty: "var(--transition-property)",
381
+ transitionDuration: state.context.hasMeasuredRect ? "var(--transition-duration)" : "0ms",
382
+ transitionTimingFunction: "var(--transition-timing-function)"
383
+ }, state.context.indicatorRect)
384
+ })
385
+ };
386
+ }
387
+
388
+ // src/tabs.machine.ts
389
+ var import_core = require("@zag-js/core");
390
+ var { not } = import_core.guards;
391
+ var machine = (0, import_core.createMachine)({
392
+ initial: "unknown",
393
+ context: {
394
+ dir: "ltr",
395
+ orientation: "horizontal",
396
+ activationMode: "automatic",
397
+ value: null,
398
+ focusedValue: null,
399
+ uid: "",
400
+ previousValues: [],
401
+ indicatorRect: { left: "0px", top: "0px", width: "0px", height: "0px" },
402
+ hasMeasuredRect: false,
403
+ isIndicatorRendered: false,
404
+ loop: true,
405
+ messages: {}
406
+ },
407
+ computed: {
408
+ isHorizontal: (ctx) => ctx.orientation === "horizontal",
409
+ isVertical: (ctx) => ctx.orientation === "vertical"
410
+ },
411
+ created: ["setPrevSelectedTabs"],
412
+ watch: {
413
+ focusedValue: "invokeOnFocus",
414
+ value: ["invokeOnChange", "setPrevSelectedTabs", "setIndicatorRect", "setContentTabIndex"],
415
+ dir: ["clearMeasured", "setIndicatorRect"]
416
+ },
417
+ on: {
418
+ SET_VALUE: {
419
+ actions: "setValue"
420
+ },
421
+ DELETE: {
422
+ actions: "deleteValue"
423
+ }
424
+ },
425
+ states: {
426
+ unknown: {
427
+ on: {
428
+ SETUP: {
429
+ target: "idle",
430
+ actions: ["setupDocument", "checkRenderedElements", "setIndicatorRect", "setContentTabIndex"]
431
+ }
432
+ }
433
+ },
434
+ idle: {
435
+ on: {
436
+ TAB_FOCUS: {
437
+ guard: "selectOnFocus",
438
+ target: "focused",
439
+ actions: ["setFocusedValue", "setValue"]
440
+ },
441
+ TAB_CLICK: {
442
+ target: "focused",
443
+ actions: ["setFocusedValue", "setValue"]
444
+ }
445
+ }
446
+ },
447
+ focused: {
448
+ on: {
449
+ TAB_CLICK: {
450
+ target: "focused",
451
+ actions: ["setFocusedValue", "setValue"]
452
+ },
453
+ ARROW_LEFT: {
454
+ guard: "isHorizontal",
455
+ actions: "focusPrevTab"
456
+ },
457
+ ARROW_RIGHT: {
458
+ guard: "isHorizontal",
459
+ actions: "focusNextTab"
460
+ },
461
+ ARROW_UP: {
462
+ guard: "isVertical",
463
+ actions: "focusPrevTab"
464
+ },
465
+ ARROW_DOWN: {
466
+ guard: "isVertical",
467
+ actions: "focusNextTab"
468
+ },
469
+ HOME: {
470
+ actions: "focusFirstTab"
471
+ },
472
+ END: {
473
+ actions: "focusLastTab"
474
+ },
475
+ ENTER: {
476
+ guard: not("selectOnFocus"),
477
+ actions: "setValue"
478
+ },
479
+ TAB_FOCUS: [
480
+ {
481
+ guard: "selectOnFocus",
482
+ actions: ["setFocusedValue", "setValue"]
483
+ },
484
+ { actions: "setFocusedValue" }
485
+ ],
486
+ TAB_BLUR: {
487
+ target: "idle",
488
+ actions: "clearFocusedValue"
489
+ }
490
+ }
491
+ }
492
+ }
493
+ }, {
494
+ guards: {
495
+ isVertical: (ctx) => ctx.isVertical,
496
+ isHorizontal: (ctx) => ctx.isHorizontal,
497
+ selectOnFocus: (ctx) => ctx.activationMode === "automatic"
498
+ },
499
+ actions: {
500
+ setupDocument(ctx, evt) {
501
+ ctx.uid = evt.id;
502
+ if (evt.doc)
503
+ ctx.doc = (0, import_core.ref)(evt.doc);
504
+ },
505
+ setFocusedValue(ctx, evt) {
506
+ ctx.focusedValue = evt.value;
507
+ },
508
+ clearFocusedValue(ctx) {
509
+ ctx.focusedValue = null;
510
+ },
511
+ setValue(ctx, evt) {
512
+ ctx.value = evt.value;
513
+ },
514
+ invokeOnDelete(ctx, evt) {
515
+ var _a;
516
+ (_a = ctx.onDelete) == null ? void 0 : _a.call(ctx, { value: evt.value });
517
+ },
518
+ focusFirstTab(ctx) {
519
+ nextTick(() => {
520
+ var _a;
521
+ return (_a = dom.getFirstEl(ctx)) == null ? void 0 : _a.focus();
522
+ });
523
+ },
524
+ focusLastTab(ctx) {
525
+ nextTick(() => {
526
+ var _a;
527
+ return (_a = dom.getLastEl(ctx)) == null ? void 0 : _a.focus();
528
+ });
529
+ },
530
+ focusNextTab(ctx) {
531
+ if (!ctx.focusedValue)
532
+ return;
533
+ const next = dom.getNextEl(ctx, ctx.focusedValue);
534
+ nextTick(() => next == null ? void 0 : next.focus());
535
+ },
536
+ focusPrevTab(ctx) {
537
+ if (!ctx.focusedValue)
538
+ return;
539
+ const prev = dom.getPrevEl(ctx, ctx.focusedValue);
540
+ nextTick(() => prev == null ? void 0 : prev.focus());
541
+ },
542
+ setIndicatorRect(ctx) {
543
+ nextTick(() => {
544
+ if (!ctx.isIndicatorRendered || !ctx.value)
545
+ return;
546
+ ctx.indicatorRect = dom.getRectById(ctx, ctx.value);
547
+ if (ctx.hasMeasuredRect)
548
+ return;
549
+ nextTick(() => {
550
+ ctx.hasMeasuredRect = true;
551
+ });
552
+ });
553
+ },
554
+ checkRenderedElements(ctx) {
555
+ nextTick(() => {
556
+ ctx.isIndicatorRendered = !!dom.getIndicatorEl(ctx);
557
+ });
558
+ },
559
+ clearMeasured(ctx) {
560
+ ctx.hasMeasuredRect = false;
561
+ },
562
+ invokeOnChange(ctx) {
563
+ var _a;
564
+ (_a = ctx.onChange) == null ? void 0 : _a.call(ctx, { value: ctx.value });
565
+ },
566
+ invokeOnFocus(ctx) {
567
+ var _a;
568
+ (_a = ctx.onFocus) == null ? void 0 : _a.call(ctx, { value: ctx.focusedValue });
569
+ },
570
+ setPrevSelectedTabs(ctx) {
571
+ if (ctx.value != null) {
572
+ const newSelected = Array.from(ctx.previousValues).concat(ctx.value);
573
+ ctx.previousValues = Array.from(new Set(newSelected));
574
+ }
575
+ },
576
+ setContentTabIndex(ctx) {
577
+ nextTick(() => {
578
+ const panel = dom.getActiveContentEl(ctx);
579
+ if (!panel)
580
+ return;
581
+ const focusables = getFocusables(panel);
582
+ if (focusables.length > 0) {
583
+ panel.removeAttribute("tabindex");
584
+ } else {
585
+ panel.setAttribute("tabindex", "0");
586
+ }
587
+ });
588
+ }
589
+ }
590
+ });
2
591
  //# sourceMappingURL=index.js.map