tokentracker-cli 0.45.1 → 0.46.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/dashboard/dist/assets/{ActivityHeatmap-CAVVn6yN.js → ActivityHeatmap-Dkjse731.js} +1 -1
- package/dashboard/dist/assets/{Card-0pTyqnXz.js → Card-BaxD5iI0.js} +1 -1
- package/dashboard/dist/assets/{DashboardPage-BpvCmr02.js → DashboardPage-DCms1ksC.js} +1 -1
- package/dashboard/dist/assets/{DevicePage-CCfVm1rz.js → DevicePage-D3OZwzTh.js} +1 -1
- package/dashboard/dist/assets/{DialogTitle-Bd6tEYt9.js → DialogTitle-qBtQz6fD.js} +1 -1
- package/dashboard/dist/assets/{FadeIn-9MSLxqP3.js → FadeIn-Bld6aAMN.js} +1 -1
- package/dashboard/dist/assets/{HeaderGithubStar-CpcLtCU_.js → HeaderGithubStar-DnVGuydb.js} +1 -1
- package/dashboard/dist/assets/{IpCheckPage-C8welQpr.js → IpCheckPage-N8XST_ce.js} +1 -1
- package/dashboard/dist/assets/{LandingPage-BB_TICAq.js → LandingPage-CgdE_gwI.js} +1 -1
- package/dashboard/dist/assets/{LeaderboardAvatar-CwU6utEx.js → LeaderboardAvatar-Bg8Q3zl3.js} +1 -1
- package/dashboard/dist/assets/{LeaderboardPage-DpCbGCfA.js → LeaderboardPage-DBvUMX7l.js} +3 -3
- package/dashboard/dist/assets/{LeaderboardProfileModal-CzbqY1_b.js → LeaderboardProfileModal-CP32cbih.js} +1 -1
- package/dashboard/dist/assets/{LeaderboardProfilePage-B3dgV4z6.js → LeaderboardProfilePage-UQB5Stlc.js} +1 -1
- package/dashboard/dist/assets/{LimitsPage-z88WgAxp.js → LimitsPage-Bekyurgm.js} +1 -1
- package/dashboard/dist/assets/{LocalOnlyNotice-DWjfO0qP.js → LocalOnlyNotice-CV9qPf-2.js} +1 -1
- package/dashboard/dist/assets/{LoginPage-WnbsCuYk.js → LoginPage-NgjgJz58.js} +1 -1
- package/dashboard/dist/assets/{PopoverPopup-SAqMTHwn.js → PopoverPopup-CSsvTzQM.js} +1 -1
- package/dashboard/dist/assets/{Select-Cgy54tgQ.js → Select-CSPGw-1V.js} +1 -1
- package/dashboard/dist/assets/{SelectItemText-C3guTERK.js → SelectItemText-lLLlrhEU.js} +1 -1
- package/dashboard/dist/assets/{SettingsPage-B2_pEDZx.js → SettingsPage-CIOO2-e0.js} +1 -1
- package/dashboard/dist/assets/{SkillsPage-DkdIES1C.js → SkillsPage-C3dBzq9G.js} +1 -1
- package/dashboard/dist/assets/{WidgetsPage-DPRqK5q_.js → WidgetsPage-BLdb8IoI.js} +1 -1
- package/dashboard/dist/assets/{WrappedPage-YfQVJXWl.js → WrappedPage-CiCxobvN.js} +1 -1
- package/dashboard/dist/assets/{agent-logos-Cv1hLATH.js → agent-logos-DJZi4dyE.js} +1 -1
- package/dashboard/dist/assets/{arrow-up-right-IDqTisJH.js → arrow-up-right-Ck0uvqjh.js} +1 -1
- package/dashboard/dist/assets/{download-DdHpJyF2.js → download-BNwS95W5.js} +1 -1
- package/dashboard/dist/assets/{info-vNx6AmGz.js → info-DugSjFYV.js} +1 -1
- package/dashboard/dist/assets/{main-B-R1Na0i.js → main-waZd4gi1.js} +14 -14
- package/dashboard/dist/assets/{use-limits-display-prefs-BSEIyorw.js → use-limits-display-prefs-CMqTK8No.js} +1 -1
- package/dashboard/dist/assets/{use-native-settings-DJmFgjnk.js → use-native-settings-RZBEnuIS.js} +1 -1
- package/dashboard/dist/assets/{use-usage-limits-XLaNz6qG.js → use-usage-limits-DnK1XIjd.js} +1 -1
- package/dashboard/dist/assets/{useCurrency-EH9Pi_5S.js → useCurrency-BZVkM9vB.js} +1 -1
- package/dashboard/dist/assets/{useScrollLock-DmLk8-JD.js → useScrollLock-DZQ9v5FD.js} +1 -1
- package/dashboard/dist/index.html +1 -1
- package/dashboard/dist/share.html +1 -1
- package/package.json +1 -1
- package/src/lib/cloud-account.js +214 -0
- package/src/lib/local-api.js +142 -0
- package/src/lib/pricing/seed-snapshot.json +1 -1
- package/src/lib/runtime-config.js +15 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
import{G as d,r as n,a_ as O,a$ as h,b0 as C,b1 as P}from"./main-
|
|
1
|
+
import{G as d,r as n,a_ as O,a$ as h,b0 as C,b1 as P}from"./main-waZd4gi1.js";const Y=["claude","codex","cursor","gemini","kimi","kiro","grok","copilot","antigravity"],T={claude:"CLAUDE",codex:"CODEX",cursor:"CURSOR",gemini:"GEMINI",kimi:"KIMI",kiro:"KIRO",grok:"GROK",copilot:"COPILOT",antigravity:"ANTIGRAVITY"};function K(e){return T[e]||null}function U(e){switch(e){case"claude":return d("limits.provider.claude");case"codex":return d("limits.provider.codex");case"cursor":return d("limits.provider.cursor");case"gemini":return d("limits.provider.gemini");case"kimi":return d("limits.provider.kimi");case"kiro":return d("limits.provider.kiro");case"grok":return d("limits.provider.grok");case"copilot":return d("limits.provider.copilot");case"antigravity":return d("limits.provider.antigravity");default:return String(e||"")}}const u=Y,I="tt.limits.providerOrder",p="tt.limits.providerVisibility",S="tt.limits.displayMode",D="limitsDisplayMode",l=Object.freeze({USED:"used",REMAINING:"remaining"}),g=new Set(Object.values(l));function b(){if(typeof window>"u")return[...u];try{const e=window.localStorage.getItem(I);if(!e)return[...u];const c=JSON.parse(e);if(!Array.isArray(c))return[...u];const o=c.filter(a=>u.includes(a));for(const a of u)o.includes(a)||o.push(a);return o}catch{return[...u]}}function k(){const e=Object.fromEntries(u.map(c=>[c,!0]));if(typeof window>"u")return e;try{const c=window.localStorage.getItem(p);if(!c)return e;const o=JSON.parse(c);if(!o||typeof o!="object")return e;const a={...e};for(const f of u)typeof o[f]=="boolean"&&(a[f]=o[f]);return a}catch{return e}}function v(){if(typeof window>"u")return l.USED;try{const e=window.localStorage.getItem(S);return g.has(e)?e:l.USED}catch{return l.USED}}function j(){const[e,c]=n.useState(b),[o,a]=n.useState(k),[f,m]=n.useState(v),y=n.useCallback(t=>{g.has(t)&&(m(t),O()&&h(D,t))},[]);n.useEffect(()=>{if(!(typeof window>"u"))try{window.localStorage.setItem(I,JSON.stringify(e))}catch{}},[e]),n.useEffect(()=>{if(!(typeof window>"u"))try{window.localStorage.setItem(p,JSON.stringify(o))}catch{}},[o]),n.useEffect(()=>{if(!(typeof window>"u"))try{window.localStorage.setItem(S,f)}catch{}},[f]),n.useEffect(()=>{if(!O())return;const t=C(i=>{const r=i?.[D];g.has(r)&&m(r)});return P(),t},[]),n.useEffect(()=>{if(typeof window>"u")return;const t=i=>{i.key===I&&c(b()),i.key===p&&a(k()),i.key===S&&m(v())};return window.addEventListener("storage",t),()=>window.removeEventListener("storage",t)},[]);const _=n.useCallback(t=>{a(i=>({...i,[t]:!i[t]}))},[]),L=n.useCallback(t=>{c(i=>{const r=i.indexOf(t);if(r<=0)return i;const s=[...i];return[s[r-1],s[r]]=[s[r],s[r-1]],s})},[]),M=n.useCallback(t=>{c(i=>{const r=i.indexOf(t);if(r<0||r>=i.length-1)return i;const s=[...i];return[s[r],s[r+1]]=[s[r+1],s[r]],s})},[]),x=n.useCallback((t,i)=>{t!==i&&c(r=>{const s=r.indexOf(t),E=r.indexOf(i);if(s<0||E<0)return r;const w=[...r],[A]=w.splice(s,1);return w.splice(E,0,A),w})},[]),N=n.useCallback(()=>{c([...u]),a(Object.fromEntries(u.map(t=>[t,!0]))),y(l.USED)},[y]),R=n.useMemo(()=>e.filter(t=>o[t]!==!1),[e,o]);return{order:e,visibility:o,displayMode:f,setDisplayMode:y,visibleOrdered:R,toggle:_,moveUp:L,moveDown:M,moveToward:x,reset:N}}export{l as L,Y as a,K as b,U as l,j as u};
|
package/dashboard/dist/assets/{use-native-settings-DJmFgjnk.js → use-native-settings-RZBEnuIS.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as a,V as x,r as n,aD as g,c4 as m,b0 as b,b1 as u,a$ as f,c3 as h}from"./main-
|
|
1
|
+
import{j as a,V as x,r as n,aD as g,c4 as m,b0 as b,b1 as u,a$ as f,c3 as h}from"./main-waZd4gi1.js";import{C as y}from"./Card-BaxD5iI0.js";function k({checked:s,onChange:t,disabled:e,ariaLabel:i}){return a.jsx("button",{type:"button",role:"switch","aria-checked":s,"aria-label":i,onClick:t,disabled:e,className:x("relative inline-flex h-5 w-9 shrink-0 items-center rounded-full transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500 disabled:opacity-50 disabled:cursor-not-allowed",s?"bg-oai-brand-500":"bg-oai-gray-300 dark:bg-oai-gray-700"),children:a.jsx("span",{className:x("inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform",s?"translate-x-[18px]":"translate-x-[3px]")})})}function p({label:s,hint:t,control:e}){return a.jsxs("div",{className:"flex items-center justify-between gap-4 py-3",children:[a.jsxs("div",{className:"min-w-0 flex-1",children:[a.jsx("div",{className:"text-sm text-oai-gray-900 dark:text-oai-gray-200",children:s}),t?a.jsx("div",{className:"mt-0.5 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:t}):null]}),a.jsx("div",{className:"shrink-0",children:e})]})}function N({title:s,subtitle:t,action:e,children:i}){return a.jsxs(y,{children:[a.jsxs("div",{className:"mb-3 flex items-start justify-between gap-4",children:[a.jsxs("div",{className:"min-w-0 flex-1",children:[a.jsx("h2",{className:"text-sm font-medium text-oai-gray-500 dark:text-oai-gray-300 uppercase tracking-wide",children:s}),t?a.jsx("p",{className:"mt-1 truncate text-xs text-oai-gray-500 dark:text-oai-gray-400",children:t}):null]}),e?a.jsx("div",{className:"shrink-0",children:e}):null]}),a.jsx("div",{className:"-mb-3 divide-y divide-oai-gray-200/60 dark:divide-oai-gray-800/60",children:i})]})}function w({options:s,value:t,onChange:e}){return a.jsx("div",{className:"inline-flex items-center rounded-lg border border-oai-gray-200 bg-oai-gray-50 p-0.5 dark:border-oai-gray-800 dark:bg-oai-gray-900",children:s.map(({value:i,label:d,Icon:l})=>{const r=t===i;return a.jsxs("button",{type:"button",onClick:()=>e(i),"aria-pressed":r,className:x("inline-flex items-center gap-1.5 rounded-md px-3 py-1.5 text-xs font-medium transition-colors",r?"bg-white text-oai-black shadow-sm dark:bg-oai-gray-800 dark:text-white":"text-oai-gray-500 hover:text-oai-black dark:text-oai-gray-400 dark:hover:text-white"),children:[l?a.jsx(l,{className:"h-3.5 w-3.5","aria-hidden":!0}):null,a.jsx("span",{children:d})]},i)})})}function S(){const[s,t]=n.useState(null),e=g()&&m();n.useEffect(()=>{if(!e)return;const r=b(o=>t(o));return u(),r},[e]);const i=n.useCallback((r,o)=>{e&&(t(c=>c&&{...c,[r]:o}),f(r,o))},[e]),d=n.useCallback(r=>{e&&h(r)},[e]),l=n.useCallback(()=>{e&&u()},[e]);return{available:e,settings:s,setSetting:i,runAction:d,refresh:l}}export{N as S,k as T,p as a,w as b,S as u};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as a,ab as m,aI as f}from"./main-
|
|
1
|
+
import{r as a,ab as m,aI as f}from"./main-waZd4gi1.js";function p(s){const r=!!s?.initialState,[h,i]=a.useState(()=>r?s?.initialState?.data??null:null),[S,l]=a.useState(()=>r?s?.initialState?.error??null:null),[g,b]=a.useState(!r),c=!!s?.initialRefresh,o=!!s?.publishToPreloadCache,n=a.useCallback((e,t)=>{!o||!e||typeof e!="object"||m(e,{source:t})},[o]),d=a.useCallback(async()=>{try{const e=await f({refresh:!0}),t=e&&typeof e=="object"?e:null;i(t),l(null),n(t,"manual-refresh")}catch(e){l(e?.message||String(e))}},[n]);return a.useEffect(()=>{if(r&&!c)return;let e=!1;return(async()=>{try{const t=await f();if(e)return;const u=t&&typeof t=="object"?t:null;i(u),l(null),n(u,"page-load")}catch(t){if(e)return;l(t?.message||String(t))}finally{e||b(!1)}})(),()=>{e=!0}},[r,c,n]),{data:h,error:S,isLoading:g,refresh:d}}export{p as u};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e,c1 as t,c2 as r,K as c}from"./main-
|
|
1
|
+
import{r as e,c1 as t,c2 as r,K as c}from"./main-waZd4gi1.js";const s=Object.freeze({currency:c,rate:1,symbol:"$",rates:{...r},rateSource:"default",rateFetchedAt:null,setCurrency:()=>{}});function a(){return e.useContext(t)??s}export{a as u};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as _t,b5 as St,b3 as G,b6 as Tt,bD as D,d9 as vt,cz as Ot,j as Te,cF as ze,r as f,bB as U,cH as ot,da as Bt,b7 as ct,bA as Ae,c5 as Gt,cG as it,db as wt,bF as x,bE as xe,c0 as Ee,dc as $e,dd as le,cL as ae,bJ as C,bK as Kt,d3 as Ct,cX as Dt,cY as Xt,d6 as xt,c6 as Vt,bX as ut,bS as lt,bU as Ut,de as $t,cM as qt,bG as Re,bW as jt,c_ as zt,b as Me,bP as Jt,df as Je,ba as We,dg as Qt,dh as He,bM as Zt,di as en,bz as Ne,bN as tn,cE as nn,bC as Ce,cv as _e,cu as rn,dj as sn,cs as on,bL as cn,dk as un,bQ as Se,dl as ye,be as ln,b9 as Be,dm as an,dn as at,d0 as fn,cA as Qe}from"./main-B-R1Na0i.js";const dn=[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]],jn=_t("check",dn);function Ie(e,t,n=!0){return e.filter(s=>s.parentId===t).flatMap(s=>[...!n||s.context?.open?[s]:[],...Ie(e,s.id,n)])}function ft(e,t){let n=[],r=e.find(s=>s.id===t)?.parentId;for(;r;){const s=e.find(c=>c.id===r);r=s?.parentId,s&&(n=n.concat(s))}return n}function Ge(e){const t=St(pn,e).current;return t.next=e,G(t.effect),t}function pn(e){const t={current:e,next:e,effect:()=>{t.current=t.next}};return t}let Fe=0;function Ke(e,t={}){const{preventScroll:n=!1,sync:r=!1,shouldFocus:s}=t;cancelAnimationFrame(Fe);function c(){s&&!s()||e?.focus({preventScroll:n})}if(r)return c(),Tt;const o=requestAnimationFrame(c);return Fe=o,()=>{Fe===o&&(cancelAnimationFrame(o),Fe=0)}}const De={inert:new WeakMap,"aria-hidden":new WeakMap},dt="data-base-ui-inert",qe={inert:new WeakSet,"aria-hidden":new WeakSet};let we=new WeakMap,Xe=0;function gn(e){return qe[e]}function It(e){return e?vt(e)?e.host:It(e.parentNode):null}const Ve=(e,t)=>t.map(n=>{if(e.contains(n))return n;const r=It(n);return e.contains(r)?r:null}).filter(n=>n!=null),pt=e=>{const t=new Set;return e.forEach(n=>{let r=n;for(;r&&!t.has(r);)t.add(r),r=r.parentNode}),t},gt=(e,t,n)=>{const r=[],s=c=>{!c||n.has(c)||Array.from(c.children).forEach(o=>{Ot(o)!=="script"&&(t.has(o)?s(o):r.push(o))})};return s(e),r};function hn(e,t,n,r,{mark:s=!0,markerIgnoreElements:c=[]}){const o=r?"inert":n?"aria-hidden":null;let u=null,v=null;const M=Ve(t,e),O=s?Ve(t,c):[],A=new Set(O),z=s?gt(t,pt(M),new Set(M)).filter(m=>!A.has(m)):[],w=[],k=[];if(o){const m=De[o],y=gn(o);v=y,u=m;const b=Ve(t,Array.from(t.querySelectorAll("[aria-live]"))),E=M.concat(b);gt(t,pt(E),new Set(E)).forEach(N=>{const Y=N.getAttribute(o),J=Y!==null&&Y!=="false",I=(m.get(N)||0)+1;m.set(N,I),w.push(N),I===1&&J&&y.add(N),J||N.setAttribute(o,o==="inert"?"":"true")})}return s&&z.forEach(m=>{const y=(we.get(m)||0)+1;we.set(m,y),k.push(m),y===1&&m.setAttribute(dt,"")}),Xe+=1,()=>{u&&w.forEach(m=>{const b=(u.get(m)||0)-1;u.set(m,b),b||(!v?.has(m)&&o&&m.removeAttribute(o),v?.delete(m))}),s&&k.forEach(m=>{const y=(we.get(m)||0)-1;we.set(m,y),y||m.removeAttribute(dt)}),Xe-=1,Xe||(De.inert=new WeakMap,De["aria-hidden"]=new WeakMap,qe.inert=new WeakSet,qe["aria-hidden"]=new WeakSet,we=new WeakMap)}}function ht(e,t={}){const{ariaHidden:n=!1,inert:r=!1,mark:s=!0,markerIgnoreElements:c=[]}=t,o=D(e[0]).body;return hn(e,o,n,r,{mark:s,markerIgnoreElements:c})}function kt(){const e=new Map;return{emit(t,n){e.get(t)?.forEach(r=>r(n))},on(t,n){e.has(t)||e.set(t,new Set),e.get(t).add(n)},off(t,n){e.get(t)?.delete(n)}}}class mn{nodesRef={current:[]};events=kt();addNode(t){this.nodesRef.current.push(t)}removeNode(t){const n=this.nodesRef.current.findIndex(r=>r===t);n!==-1&&this.nodesRef.current.splice(n,1)}}const Pt=f.createContext(null),Ft=f.createContext(null),Ze=()=>f.useContext(Pt)?.id||null,et=e=>{const t=f.useContext(Ft);return e??t};function zn(e){const t=ze(),n=et(e),r=Ze();return G(()=>{if(!t)return;const s={id:t,parentId:r};return n?.addNode(s),()=>{n?.removeNode(s)}},[n,t,r]),t}function Jn(e){const{children:t,id:n}=e,r=Ze();return Te.jsx(Pt.Provider,{value:f.useMemo(()=>({id:n,parentId:r}),[n,r]),children:t})}function Qn(e){const{children:t,externalTree:n}=e,r=St(()=>n??new mn).current;return Te.jsx(Ft.Provider,{value:r,children:t})}function bn(e,t){const n=We(Re(e));return e instanceof n.KeyboardEvent?"keyboard":e instanceof n.FocusEvent?t||"keyboard":"pointerType"in e?e.pointerType||"keyboard":"touches"in e?"touch":e instanceof n.MouseEvent?t||(e.detail===0?"keyboard":"mouse"):""}const mt=20;let fe=[];function tt(){fe=fe.filter(e=>e.deref()?.isConnected)}function En(e){tt(),e&&Ot(e)!=="body"&&(fe.push(new WeakRef(e)),fe.length>mt&&(fe=fe.slice(-mt)))}function Ue(){return tt(),fe[fe.length-1]?.deref()}function yn(e){return e?Je(e)?e:wt(e)[0]||e:null}function bt(e,t){if(e.hasAttribute("tabindex")&&!e.hasAttribute("data-tabindex")||!t.current.includes("floating")&&!e.getAttribute("role")?.includes("dialog"))return;const r=Qt(e).filter(c=>{const o=c.getAttribute("data-tabindex")||"";return Je(c)||c.hasAttribute("data-tabindex")&&!o.startsWith("-")}),s=e.getAttribute("tabindex");t.current.includes("floating")||r.length===0?s!=="0"&&e.setAttribute("tabindex","0"):(s!=="-1"||e.hasAttribute("data-tabindex")&&e.getAttribute("data-tabindex")!=="-1")&&(e.setAttribute("tabindex","-1"),e.setAttribute("data-tabindex","-1"))}function Zn(e){const{context:t,children:n,disabled:r=!1,initialFocus:s=!0,returnFocus:c=!0,restoreFocus:o=!1,modal:u=!0,closeOnFocusOut:v=!0,openInteractionType:M="",nextFocusableElement:O,previousFocusableElement:A,beforeContentFocusGuardRef:z,externalTree:w,getInsideElements:k}=e,m="rootStore"in t?t.rootStore:t,y=m.useState("open"),b=m.useState("domReferenceElement"),E=m.useState("floatingElement"),{events:Z,dataRef:N}=m.context,Y=U(()=>N.current.floatingContext?.nodeId),J=s===!1,I=ot(b)&&J,ee=f.useRef(["content"]),se=Ge(s),P=Ge(c),ie=Ge(M),j=et(w),p=Bt(),$=f.useRef(!1),Q=f.useRef(!1),de=f.useRef(!1),oe=f.useRef(null),te=f.useRef(""),pe=f.useRef(""),ge=f.useRef(null),he=f.useRef(null),ke=ct(ge,z,p?.beforeInsideRef),R=ct(he,p?.afterInsideRef),q=Ae(),ce=Ae(),me=Gt(),Pe=p!=null,g=it(E),K=U((a=g)=>a?wt(a):[]),ne=U(()=>k?.().filter(a=>a!=null)??[]);f.useEffect(()=>{if(r||!u)return;function a(H){H.key==="Tab"&&C(g,ae(D(g)))&&K().length===0&&!I&&qt(H)}const W=D(g);return x(W,"keydown",a)},[r,g,u,I,K]),f.useEffect(()=>{if(r||!y)return;const a=D(g);function W(){de.current=!1}function H(S){const h=Re(S),F=ne(),d=C(E,h)||C(b,h)||C(p?.portalNode,h)||F.some(_=>_===h||C(_,h));de.current=!d,pe.current=S.pointerType||"keyboard",h?.closest(`[${jt}]`)&&(Q.current=!0)}function L(){pe.current="keyboard"}return xe(x(a,"pointerdown",H,!0),x(a,"pointerup",W,!0),x(a,"pointercancel",W,!0),x(a,"keydown",L,!0))},[r,E,b,g,y,p,ne]),f.useEffect(()=>{if(r||!v)return;const a=D(g);function W(){Q.current=!0,ce.start(0,()=>{Q.current=!1})}function H(F){const d=Re(F);Je(d)&&(oe.current=d)}function L(F){const d=F.relatedTarget,_=F.currentTarget,X=Re(F);queueMicrotask(()=>{const be=Y(),V=m.context.triggerElements,Le=ne(),i=d?.hasAttribute($e("focus-guard"))&&[ge.current,he.current,p?.beforeInsideRef.current,p?.afterInsideRef.current,p?.beforeOutsideRef.current,p?.afterOutsideRef.current,le(A),le(O)].includes(d),l=!(C(b,d)||C(E,d)||C(d,E)||C(p?.portalNode,d)||Le.some(T=>T===d||C(T,d))||d!=null&&V.hasElement(d)||V.hasMatchingElement(T=>C(T,d))||i||j&&(Ie(j.nodesRef.current,be).find(T=>C(T.context?.elements.floating,d)||C(T.context?.elements.domReference,d))||ft(j.nodesRef.current,be).find(T=>[T.context?.elements.floating,it(T.context?.elements.floating)].includes(d)||T.context?.elements.domReference===d)));if(_===b&&g&&bt(g,ee),o&&_!==b&&!zt(X)&&ae(a)===a.body){if(Ee(g)&&(g.focus(),o==="popup")){me.request(()=>{g.focus()});return}const T=K(),B=oe.current,ue=(B&&T.includes(B)?B:null)||T[T.length-1]||g;Ee(ue)&&ue.focus()}if(N.current.insideReactTree){N.current.insideReactTree=!1;return}(I||!u)&&d&&l&&!Q.current&&(I||d!==Ue())&&($.current=!0,m.setOpen(!1,Me(Jt,F)))})}function S(){de.current||(N.current.insideReactTree=!0,q.start(0,()=>{N.current.insideReactTree=!1}))}const h=Ee(b)?b:null;if(!(!E&&!h))return xe(h&&x(h,"focusout",L),h&&x(h,"pointerdown",W),E&&x(E,"focusin",H),E&&x(E,"focusout",L),E&&p&&x(E,"focusout",S,!0))},[r,b,E,g,u,j,p,m,v,o,K,I,Y,ee,N,q,ce,me,O,A,ne]),f.useEffect(()=>{if(r||!E||!y)return;const a=Array.from(p?.portalNode?.querySelectorAll(`[${$e("portal")}]`)||[]),H=(j?ft(j.nodesRef.current,Y()):[]).find(_=>ot(_.context?.elements.domReference||null))?.context?.elements.domReference,S=[...[E,...a,ge.current,he.current,p?.beforeOutsideRef.current,p?.afterOutsideRef.current,...ne()],H,le(A),le(O),I?b:null].filter(_=>_!=null),h=ht(S,{ariaHidden:u||I,mark:!1}),F=[E,...a].filter(_=>_!=null),d=ht(F);return()=>{d(),h()}},[y,r,b,E,u,p,I,j,Y,O,A,ne]),G(()=>{if(!y||r||!Ee(g))return;const a=D(g),W=ae(a);queueMicrotask(()=>{const H=se.current,L=typeof H=="function"?H(ie.current||""):H;if(L===void 0||L===!1||C(g,W))return;let h=null;const F=()=>(h==null&&(h=K(g)),h[0]||g);let d;L===!0||L===null?d=F():d=le(L),d=d||F();const _=C(g,ae(a));Ke(d,{preventScroll:d===g,shouldFocus(){if(_)return!0;const X=ae(a);return!(X!==d&&C(g,X))}})})},[r,y,g,K,se,ie]),G(()=>{if(r||!g)return;const a=D(g),W=ae(a);En(W);function H(S){if(S.open||(te.current=bn(S.nativeEvent,pe.current)),S.reason===Kt&&S.nativeEvent.type==="mouseleave"&&($.current=!0),S.reason===Ct)if(S.nested)$.current=!1;else if(Dt(S.nativeEvent)||Xt(S.nativeEvent))$.current=!1;else{let h=!1;D(g).createElement("div").focus({get preventScroll(){return h=!0,!1}}),h?$.current=!1:$.current=!0}}Z.on("openchange",H);function L(){const S=P.current;let h=typeof S=="function"?S(te.current):S;if(h===void 0||h===!1)return null;if(h===null&&(h=!0),typeof h=="boolean")return b?.isConnected?b:Ue()||null;const F=b?.isConnected?b:Ue();return le(h)||F||null}return()=>{Z.off("openchange",H);const S=ae(a),h=ne(),F=C(E,S)||h.some(X=>X===S||C(X,S))||j&&Ie(j.nodesRef.current,Y(),!1).some(X=>C(X.context?.elements.floating,S)),d=P.current,_=L();queueMicrotask(()=>{const X=yn(_),be=typeof d!="boolean";d&&!$.current&&Ee(X)&&(!(!be&&X!==S&&S!==a.body)||F)&&X.focus({preventScroll:!0}),$.current=!1})}},[r,E,g,P,Z,j,b,Y,ne]),G(()=>{if(!xt||y||!E)return;const a=ae(D(E));!Ee(a)||!Vt(a)||C(E,a)&&a.blur()},[y,E]),G(()=>{if(!(r||!p))return p.setFocusManagerState({modal:u,closeOnFocusOut:v,open:y,onOpenChange:m.setOpen,domReference:b}),()=>{p.setFocusManagerState(null)}},[r,p,u,y,m,v,b]),G(()=>{if(!(r||!g))return bt(g,ee),()=>{queueMicrotask(tt)}},[r,g,ee]);const ve=!r&&(u?!I:!0)&&(Pe||u);return Te.jsxs(f.Fragment,{children:[ve&&Te.jsx(ut,{"data-type":"inside",ref:ke,onFocus:a=>{if(u){const W=K();Ke(W[W.length-1])}else p?.portalNode&&($.current=!1,lt(a,p.portalNode)?Ut(b)?.focus():le(A??p.beforeOutsideRef)?.focus())}}),n,ve&&Te.jsx(ut,{"data-type":"inside",ref:R,onFocus:a=>{u?Ke(K()[0]):p?.portalNode&&(v&&($.current=!0),lt(a,p.portalNode)?$t(b)?.focus():le(O??p.afterOutsideRef)?.focus())}})]})}const Rn={intentional:"onClick",sloppy:"onPointerDown"};function Sn(){return!1}function Tn(e){return{escapeKey:typeof e=="boolean"?e:e?.escapeKey??!1,outsidePress:typeof e=="boolean"?e:e?.outsidePress??!0}}function er(e,t={}){const{enabled:n=!0,escapeKey:r=!0,outsidePress:s=!0,outsidePressEvent:c="sloppy",referencePress:o=Sn,referencePressEvent:u="sloppy",bubbles:v,externalTree:M}=t,O="rootStore"in e?e.rootStore:e,A=O.useState("open"),z=O.useState("floatingElement"),{dataRef:w}=O.context,k=et(M),m=U(typeof s=="function"?s:()=>!1),y=typeof s=="function"?m:s,b=y!==!1,E=U(()=>c),{escapeKey:Z,outsidePress:N}=Tn(v),Y=f.useRef(!1),J=f.useRef(!1),I=f.useRef(!1),ee=f.useRef(!1),se=f.useRef(""),P=f.useRef(null),ie=Ae(),j=Ae(),p=U(()=>{j.clear(),w.current.insideReactTree=!1}),$=U(R=>{const q=w.current.floatingContext?.nodeId;return(k?Ie(k.nodesRef.current,q):[]).some(me=>me.context?.open&&!me.context.dataRef.current[R])}),Q=U(R=>He(R,O.select("floatingElement"))||He(R,O.select("domReferenceElement"))),de=U(R=>{o()&&O.setOpen(!1,Me(Zt,R.nativeEvent))}),oe=U(R=>{if(!A||!n||!r||R.key!=="Escape"||ee.current||!Z&&$("__escapeKeyBubbles"))return;const q=en(R)?R.nativeEvent:R,ce=Me(tn,q);O.setOpen(!1,ce),ce.isCanceled||R.preventDefault(),!Z&&!ce.isPropagationAllowed&&R.stopPropagation()}),te=U(()=>{w.current.insideReactTree=!0,j.start(0,p)}),pe=U(R=>{if(!A||!n||R.button!==0)return;const q=Re(R.nativeEvent);C(O.select("floatingElement"),q)&&(Y.current||(Y.current=!0,J.current=!1))}),ge=U(R=>{!A||!n||(R.defaultPrevented||R.nativeEvent.defaultPrevented)&&Y.current&&(J.current=!0)});f.useEffect(()=>{if(!A||!n)return;w.current.__escapeKeyBubbles=Z,w.current.__outsidePressBubbles=N;const R=new Ne,q=new Ne;function ce(){R.clear(),ee.current=!0}function me(){R.start(nn()?5:0,()=>{ee.current=!1})}function Pe(){I.current=!0,q.start(0,()=>{I.current=!1})}function g(){Y.current=!1,J.current=!1}function K(){const i=se.current,l=i==="pen"||!i?"mouse":i,T=E(),B=typeof T=="function"?T():T;return typeof B=="string"?B:B[l]}function ne(i){const l=K();return l==="intentional"&&i.type!=="click"||l==="sloppy"&&i.type==="click"}function ve(i){const l=w.current.floatingContext?.nodeId,T=k&&Ie(k.nodesRef.current,l).some(B=>He(i,B.context?.elements.floating));return Q(i)||T}function a(i){if(ne(i)){i.type!=="click"&&!Q(i)&&(q.clear(),I.current=!1),p();return}if(w.current.insideReactTree){p();return}const l=Re(i),T=`[${$e("inert")}]`,B=Ce(l)?l.getRootNode():null,ue=Array.from((vt(B)?B:D(O.select("floatingElement"))).querySelectorAll(T)),rt=O.context.triggerElements;if(l&&(rt.hasElement(l)||rt.hasMatchingElement(re=>C(re,l))))return;let Oe=Ce(l)?l:null;for(;Oe&&!_e(Oe);){const re=rn(Oe);if(_e(re)||!Ce(re))break;Oe=re}if(!(ue.length&&Ce(l)&&!sn(l)&&!C(l,O.select("floatingElement"))&&ue.every(re=>!C(Oe,re)))){if(Ee(l)&&!("touches"in i)){const re=_e(l),Ye=on(l),st=/auto|scroll/,Mt=re||st.test(Ye.overflowX),At=re||st.test(Ye.overflowY),Nt=Mt&&l.clientWidth>0&&l.scrollWidth>l.clientWidth,Wt=At&&l.clientHeight>0&&l.scrollHeight>l.clientHeight,Lt=Ye.direction==="rtl",Yt=Wt&&(Lt?i.offsetX<=l.offsetWidth-l.clientWidth:i.offsetX>l.clientWidth),Ht=Nt&&i.offsetY>l.clientHeight;if(Yt||Ht)return}if(!ve(i)){if(K()==="intentional"&&I.current){q.clear(),I.current=!1;return}typeof y=="function"&&!y(i)||$("__outsidePressBubbles")||(O.setOpen(!1,Me(Ct,i)),p())}}}function W(i){K()!=="sloppy"||i.pointerType==="touch"||!O.select("open")||!n||Q(i)||a(i)}function H(i){if(K()!=="sloppy"||!O.select("open")||!n||Q(i))return;const l=i.touches[0];l&&(P.current={startTime:Date.now(),startX:l.clientX,startY:l.clientY,dismissOnTouchEnd:!1,dismissOnMouseDown:!0},ie.start(1e3,()=>{P.current&&(P.current.dismissOnTouchEnd=!1,P.current.dismissOnMouseDown=!1)}))}function L(i,l){const T=Re(i);if(!T)return;const B=x(T,i.type,()=>{l(i),B()})}function S(i){se.current="touch",L(i,H)}function h(i){ie.clear(),i.type==="pointerdown"&&(se.current=i.pointerType),!(i.type==="mousedown"&&P.current&&!P.current.dismissOnMouseDown)&&L(i,l=>{l.type==="pointerdown"?W(l):a(l)})}function F(i){if(!Y.current)return;const l=J.current;if(g(),K()==="intentional"){if(i.type==="pointercancel"){l&&Pe();return}if(!ve(i)){if(l){Pe();return}typeof y=="function"&&!y(i)||(q.clear(),I.current=!0,p())}}}function d(i){if(K()!=="sloppy"||!P.current||Q(i))return;const l=i.touches[0];if(!l)return;const T=Math.abs(l.clientX-P.current.startX),B=Math.abs(l.clientY-P.current.startY),ue=Math.sqrt(T*T+B*B);ue>5&&(P.current.dismissOnTouchEnd=!0),ue>10&&(a(i),ie.clear(),P.current=null)}function _(i){L(i,d)}function X(i){K()!=="sloppy"||!P.current||Q(i)||(P.current.dismissOnTouchEnd&&a(i),ie.clear(),P.current=null)}function be(i){L(i,X)}const V=D(z),Le=xe(r&&xe(x(V,"keydown",oe),x(V,"compositionstart",ce),x(V,"compositionend",me)),b&&xe(x(V,"click",h,!0),x(V,"pointerdown",h,!0),x(V,"pointerup",F,!0),x(V,"pointercancel",F,!0),x(V,"mousedown",h,!0),x(V,"mouseup",F,!0),x(V,"touchstart",S,!0),x(V,"touchmove",_,!0),x(V,"touchend",be,!0)));return()=>{Le(),R.clear(),q.clear(),g(),I.current=!1}},[w,z,r,b,y,A,n,Z,N,oe,p,E,$,Q,k,O,ie]),f.useEffect(p,[y,p]);const he=f.useMemo(()=>({onKeyDown:oe,[Rn[u]]:de,...u!=="intentional"&&{onClick:de}}),[oe,de,u]),ke=f.useMemo(()=>({onKeyDown:oe,onPointerDown:ge,onMouseDown:ge,onClickCapture:te,onMouseDownCapture(R){te(),pe(R)},onPointerDownCapture(R){te(),pe(R)},onMouseUpCapture:te,onTouchEndCapture:te,onTouchMoveCapture:te}),[oe,te,pe,ge]);return f.useMemo(()=>n?{reference:he,floating:ke,trigger:he}:{},[n,he,ke])}const vn={open:Se(e=>e.open),transitionStatus:Se(e=>e.transitionStatus),domReferenceElement:Se(e=>e.domReferenceElement),referenceElement:Se(e=>e.positionReference??e.referenceElement),floatingElement:Se(e=>e.floatingElement),floatingId:Se(e=>e.floatingId)};class On extends cn{constructor(t){const{syncOnly:n,nested:r,onOpenChange:s,triggerElements:c,...o}=t;super({...o,positionReference:o.referenceElement,domReferenceElement:o.referenceElement},{onOpenChange:s,dataRef:{current:{}},events:kt(),nested:r,triggerElements:c},vn),this.syncOnly=n}syncOpenEvent=(t,n)=>{(!t||!this.state.open||n!=null&&un(n))&&(this.context.dataRef.current.openEvent=t?n:void 0)};dispatchOpenChange=(t,n)=>{this.syncOpenEvent(t,n.event);const r={open:t,reason:n.reason,nativeEvent:n.event,nested:this.context.nested,triggerElement:n.trigger};this.context.events.emit("openchange",r)};setOpen=(t,n)=>{if(this.syncOnly){this.context.onOpenChange?.(t,n);return}this.dispatchOpenChange(t,n),this.context.onOpenChange?.(t,n)}}function wn(e){const{popupStore:t,treatPopupAsFloatingElement:n=!1,floatingRootContext:r,floatingId:s,nested:c,onOpenChange:o}=e,u=t.useState("open"),v=t.useState("activeTriggerElement"),M=t.useState(n?"popupElement":"positionerElement"),O=t.context.triggerElements,A=o,z=f.useRef(null);r===void 0&&z.current===null&&(z.current=new On({open:u,transitionStatus:void 0,referenceElement:v,floatingElement:M,triggerElements:O,onOpenChange:A,floatingId:s,syncOnly:!0,nested:c}));const w=r??z.current;return t.useSyncedValue("floatingId",s),G(()=>{const k={open:u,floatingId:s,referenceElement:v,floatingElement:M};Ce(v)&&(k.domReferenceElement=v),w.state.positionReference===w.state.referenceElement&&(k.positionReference=v),w.update(k)},[u,s,v,M,w]),w.context.onOpenChange=A,w.context.nested=c,w}function Cn(e,t=!1,n=!1){const[r,s]=f.useState(e&&t?"idle":void 0),[c,o]=f.useState(e);return e&&!c&&(o(!0),s("starting")),!e&&c&&r!=="ending"&&!n&&s("ending"),!e&&!c&&r==="ending"&&s(void 0),G(()=>{if(!e&&c&&r!=="ending"&&n){const u=ye.request(()=>{s("ending")});return()=>{ye.cancel(u)}}},[e,c,r,n]),G(()=>{if(!e||t)return;const u=ye.request(()=>{s(void 0)});return()=>{ye.cancel(u)}},[t,e]),G(()=>{if(!e||!t)return;e&&c&&r!=="idle"&&s("starting");const u=ye.request(()=>{s("idle")});return()=>{ye.cancel(u)}},[t,e,c,r]),{mounted:c,setMounted:o,transitionStatus:r}}const tr={tabIndex:-1,[an]:""};function nr(e,t,n=!1){const r=ze(),s=Ze()!=null,c=f.useRef(null);e===void 0&&c.current===null&&(c.current=t(r,s));const o=e??c.current;return wn({popupStore:o,treatPopupAsFloatingElement:n,floatingRootContext:o.state.floatingRootContext,floatingId:r,nested:s,onOpenChange:o.setOpen}),{store:o,internalStore:c.current}}function xn(e,t){const n=f.useRef(null),r=f.useRef(null);return f.useCallback(s=>{if(e===void 0)return;let c=!1;if(n.current!==null){const o=n.current,u=r.current,v=t.context.triggerElements.getById(o);u&&v===u&&(t.context.triggerElements.delete(o),c=!0),n.current=null,r.current=null}if(s!==null&&(n.current=e,r.current=s,t.context.triggerElements.add(e,s),c=!0),c){const o=t.context.triggerElements.size;t.select("open")&&t.state.triggerCount!==o&&t.set("triggerCount",o)}},[t,e])}function rr(e,t,n){const r=n?.id??null;(r||t)&&(e.activeTriggerId=r,e.activeTriggerElement=n??null)}function sr(e,t,n,r){const s=n.useState("isMountedByTrigger",e),c=xn(e,n),o=U(u=>{if(c(u),!u)return;const v=n.select("open"),M=n.select("activeTriggerId");if(M===e){n.update({activeTriggerElement:u,...v?r:null});return}M==null&&v&&n.update({activeTriggerId:e,activeTriggerElement:u,...r})});return G(()=>{s&&n.update({activeTriggerElement:t.current,...r})},[s,n,t,...Object.values(r)]),{registerTrigger:o,isMountedByThisTrigger:s}}function or(e){const t=e.useState("open"),n=e.useState("triggerCount");G(()=>{if(!t){e.state.triggerCount!==0&&e.set("triggerCount",0);return}const r=e.context.triggerElements.size,s={};if(e.state.triggerCount!==r&&(s.triggerCount=r),!e.select("activeTriggerId")&&r===1){const c=e.context.triggerElements.entries().next();if(!c.done){const[o,u]=c.value;s.activeTriggerId=o,s.activeTriggerElement=u}}(s.triggerCount!==void 0||s.activeTriggerId!==void 0)&&e.update(s)},[t,e,n])}function cr(e,t,n){const{mounted:r,setMounted:s,transitionStatus:c}=Cn(e);t.useSyncedValues({mounted:r,transitionStatus:c});const o=U(()=>{s(!1),t.update({activeTriggerId:null,activeTriggerElement:null,mounted:!1,preventUnmountingOnClose:!1}),n?.(),t.context.onOpenChangeComplete?.(!1)}),u=t.useState("preventUnmountingOnClose");return ln({enabled:r&&!e&&!u,open:e,ref:t.context.popupRef,onComplete(){e||o()}}),{forceUnmount:o,transitionStatus:c}}function ir(e,t){e.useSyncedValues(t),G(()=>()=>{e.update({activeTriggerProps:Be,inactiveTriggerProps:Be,popupProps:Be})},[e])}function ur(e,t){G(()=>{!t&&e.state.openMethod!==null&&e.set("openMethod",null)},[t,e]),G(()=>()=>{e.state.openMethod!==null&&e.set("openMethod",null)},[e])}class lr{constructor(){this.elementsSet=new Set,this.idMap=new Map}add(t,n){const r=this.idMap.get(t);r!==n&&(r!==void 0&&this.elementsSet.delete(r),this.elementsSet.add(n),this.idMap.set(t,n))}delete(t){const n=this.idMap.get(t);n&&(this.elementsSet.delete(n),this.idMap.delete(t))}hasElement(t){return this.elementsSet.has(t)}hasMatchingElement(t){for(const n of this.elementsSet)if(t(n))return!0;return!1}getById(t){return this.idMap.get(t)}entries(){return this.idMap.entries()}elements(){return this.elementsSet.values()}get size(){return this.idMap.size}}let nt=(function(e){return e.open="data-open",e.closed="data-closed",e[e.startingStyle=at.startingStyle]="startingStyle",e[e.endingStyle=at.endingStyle]="endingStyle",e.anchorHidden="data-anchor-hidden",e.side="data-side",e.align="data-align",e})({}),je=(function(e){return e.popupOpen="data-popup-open",e.pressed="data-pressed",e})({});const In={[je.popupOpen]:""},kn={[je.popupOpen]:"",[je.pressed]:""},Pn={[nt.open]:""},Fn={[nt.closed]:""},Mn={[nt.anchorHidden]:""},ar={open(e){return e?In:null}},fr={open(e){return e?kn:null}},dr={open(e){return e?Pn:Fn},anchorHidden(e){return e?Mn:null}};function pr(e){return ze(e,"base-ui")}const An="ArrowUp",Nn="ArrowDown",Wn="ArrowLeft",Ln="ArrowRight",Yn="Home",Hn="End",_n=new Set([Wn,Ln]),Bn=new Set([An,Nn]),Gn=new Set([..._n,...Bn]),gr=new Set([...Gn,Yn,Hn]),hr=f.forwardRef(function(t,n){const{cutout:r,...s}=t;let c;if(r){const o=r.getBoundingClientRect();c=`polygon(0% 0%,100% 0%,100% 100%,0% 100%,0% 0%,${o.left}px ${o.top}px,${o.left}px ${o.bottom}px,${o.right}px ${o.bottom}px,${o.right}px ${o.top}px,${o.left}px ${o.top}px)`}return Te.jsx("div",{ref:n,role:"presentation","data-base-ui-inert":"",...s,style:{position:"fixed",inset:0,userSelect:"none",WebkitUserSelect:"none",clipPath:c}})});function mr(e){const t=f.useRef(!0);t.current&&(t.current=!1,e())}let Et={},yt={},Rt="";function Kn(e){if(typeof document>"u")return!1;const t=D(e);return We(t).innerWidth-t.documentElement.clientWidth>0}function Dn(e){if(!(typeof CSS<"u"&&CSS.supports&&CSS.supports("scrollbar-gutter","stable"))||typeof document>"u")return!1;const n=D(e),r=n.documentElement,s=n.body,c=Qe(r)?r:s,o=c.style.overflowY,u=r.style.scrollbarGutter;r.style.scrollbarGutter="stable",c.style.overflowY="scroll";const v=c.offsetWidth;c.style.overflowY="hidden";const M=c.offsetWidth;return c.style.overflowY=o,r.style.scrollbarGutter=u,v===M}function Xn(e){const t=D(e),n=t.documentElement,r=t.body,s=Qe(n)?n:r,c={overflowY:s.style.overflowY,overflowX:s.style.overflowX};return Object.assign(s.style,{overflowY:"hidden",overflowX:"hidden"}),()=>{Object.assign(s.style,c)}}function Vn(e){const t=D(e),n=t.documentElement,r=t.body,s=We(n);let c=0,o=0,u=!1;const v=ye.create();if(xt&&(s.visualViewport?.scale??1)!==1)return()=>{};function M(){const w=s.getComputedStyle(n),k=s.getComputedStyle(r),b=(w.scrollbarGutter||"").includes("both-edges")?"stable both-edges":"stable";c=n.scrollTop,o=n.scrollLeft,Et={scrollbarGutter:n.style.scrollbarGutter,overflowY:n.style.overflowY,overflowX:n.style.overflowX},Rt=n.style.scrollBehavior,yt={position:r.style.position,height:r.style.height,width:r.style.width,boxSizing:r.style.boxSizing,overflowY:r.style.overflowY,overflowX:r.style.overflowX,scrollBehavior:r.style.scrollBehavior};const E=n.scrollHeight>n.clientHeight,Z=n.scrollWidth>n.clientWidth,N=w.overflowY==="scroll"||k.overflowY==="scroll",Y=w.overflowX==="scroll"||k.overflowX==="scroll",J=Math.max(0,s.innerWidth-r.clientWidth),I=Math.max(0,s.innerHeight-r.clientHeight),ee=parseFloat(k.marginTop)+parseFloat(k.marginBottom),se=parseFloat(k.marginLeft)+parseFloat(k.marginRight),P=Qe(n)?n:r;if(u=Dn(e),u){n.style.scrollbarGutter=b,P.style.overflowY="hidden",P.style.overflowX="hidden";return}Object.assign(n.style,{scrollbarGutter:b,overflowY:"hidden",overflowX:"hidden"}),(E||N)&&(n.style.overflowY="scroll"),(Z||Y)&&(n.style.overflowX="scroll"),Object.assign(r.style,{position:"relative",height:ee||I?`calc(100dvh - ${ee+I}px)`:"100dvh",width:se||J?`calc(100vw - ${se+J}px)`:"100vw",boxSizing:"border-box",overflow:"hidden",scrollBehavior:"unset"}),r.scrollTop=c,r.scrollLeft=o,n.setAttribute("data-base-ui-scroll-locked",""),n.style.scrollBehavior="unset"}function O(){Object.assign(n.style,Et),Object.assign(r.style,yt),u||(n.scrollTop=c,n.scrollLeft=o,n.removeAttribute("data-base-ui-scroll-locked"),n.style.scrollBehavior=Rt)}function A(){O(),v.request(M)}M();const z=x(s,"resize",A);return()=>{v.cancel(),O(),typeof s.removeEventListener=="function"&&z()}}class Un{lockCount=0;restore=null;timeoutLock=Ne.create();timeoutUnlock=Ne.create();acquire(t){return this.lockCount+=1,this.lockCount===1&&this.restore===null&&this.timeoutLock.start(0,()=>this.lock(t)),this.release}release=()=>{this.lockCount-=1,this.lockCount===0&&this.restore&&this.timeoutUnlock.start(0,this.unlock)};unlock=()=>{this.lockCount===0&&this.restore&&(this.restore?.(),this.restore=null)};lock(t){if(this.lockCount===0||this.restore!==null)return;const r=D(t).documentElement,s=We(r).getComputedStyle(r).overflowY;if(s==="hidden"||s==="clip"){this.restore=Tt;return}const c=fn||!Kn(t);this.restore=c?Xn(t):Vn(t)}}const $n=new Un;function br(e=!0,t=null){G(()=>{if(e)return $n.acquire(t)},[e,t])}export{nt as A,jn as C,Qn as F,hr as I,lr as P,Cn as a,et as b,Ze as c,Ge as d,nr as e,mr as f,Ie as g,ur as h,or as i,cr as j,er as k,tr as l,ir as m,sr as n,zn as o,fr as p,Jn as q,Zn as r,rr as s,ar as t,pr as u,gr as v,dr as w,On as x,Ke as y,br as z};
|
|
1
|
+
import{c as _t,b5 as St,b3 as G,b6 as Tt,bD as D,d9 as vt,cz as Ot,j as Te,cF as ze,r as f,bB as U,cH as ot,da as Bt,b7 as ct,bA as Ae,c5 as Gt,cG as it,db as wt,bF as x,bE as xe,c0 as Ee,dc as $e,dd as le,cL as ae,bJ as C,bK as Kt,d3 as Ct,cX as Dt,cY as Xt,d6 as xt,c6 as Vt,bX as ut,bS as lt,bU as Ut,de as $t,cM as qt,bG as Re,bW as jt,c_ as zt,b as Me,bP as Jt,df as Je,ba as We,dg as Qt,dh as He,bM as Zt,di as en,bz as Ne,bN as tn,cE as nn,bC as Ce,cv as _e,cu as rn,dj as sn,cs as on,bL as cn,dk as un,bQ as Se,dl as ye,be as ln,b9 as Be,dm as an,dn as at,d0 as fn,cA as Qe}from"./main-waZd4gi1.js";const dn=[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]],jn=_t("check",dn);function Ie(e,t,n=!0){return e.filter(s=>s.parentId===t).flatMap(s=>[...!n||s.context?.open?[s]:[],...Ie(e,s.id,n)])}function ft(e,t){let n=[],r=e.find(s=>s.id===t)?.parentId;for(;r;){const s=e.find(c=>c.id===r);r=s?.parentId,s&&(n=n.concat(s))}return n}function Ge(e){const t=St(pn,e).current;return t.next=e,G(t.effect),t}function pn(e){const t={current:e,next:e,effect:()=>{t.current=t.next}};return t}let Fe=0;function Ke(e,t={}){const{preventScroll:n=!1,sync:r=!1,shouldFocus:s}=t;cancelAnimationFrame(Fe);function c(){s&&!s()||e?.focus({preventScroll:n})}if(r)return c(),Tt;const o=requestAnimationFrame(c);return Fe=o,()=>{Fe===o&&(cancelAnimationFrame(o),Fe=0)}}const De={inert:new WeakMap,"aria-hidden":new WeakMap},dt="data-base-ui-inert",qe={inert:new WeakSet,"aria-hidden":new WeakSet};let we=new WeakMap,Xe=0;function gn(e){return qe[e]}function It(e){return e?vt(e)?e.host:It(e.parentNode):null}const Ve=(e,t)=>t.map(n=>{if(e.contains(n))return n;const r=It(n);return e.contains(r)?r:null}).filter(n=>n!=null),pt=e=>{const t=new Set;return e.forEach(n=>{let r=n;for(;r&&!t.has(r);)t.add(r),r=r.parentNode}),t},gt=(e,t,n)=>{const r=[],s=c=>{!c||n.has(c)||Array.from(c.children).forEach(o=>{Ot(o)!=="script"&&(t.has(o)?s(o):r.push(o))})};return s(e),r};function hn(e,t,n,r,{mark:s=!0,markerIgnoreElements:c=[]}){const o=r?"inert":n?"aria-hidden":null;let u=null,v=null;const M=Ve(t,e),O=s?Ve(t,c):[],A=new Set(O),z=s?gt(t,pt(M),new Set(M)).filter(m=>!A.has(m)):[],w=[],k=[];if(o){const m=De[o],y=gn(o);v=y,u=m;const b=Ve(t,Array.from(t.querySelectorAll("[aria-live]"))),E=M.concat(b);gt(t,pt(E),new Set(E)).forEach(N=>{const Y=N.getAttribute(o),J=Y!==null&&Y!=="false",I=(m.get(N)||0)+1;m.set(N,I),w.push(N),I===1&&J&&y.add(N),J||N.setAttribute(o,o==="inert"?"":"true")})}return s&&z.forEach(m=>{const y=(we.get(m)||0)+1;we.set(m,y),k.push(m),y===1&&m.setAttribute(dt,"")}),Xe+=1,()=>{u&&w.forEach(m=>{const b=(u.get(m)||0)-1;u.set(m,b),b||(!v?.has(m)&&o&&m.removeAttribute(o),v?.delete(m))}),s&&k.forEach(m=>{const y=(we.get(m)||0)-1;we.set(m,y),y||m.removeAttribute(dt)}),Xe-=1,Xe||(De.inert=new WeakMap,De["aria-hidden"]=new WeakMap,qe.inert=new WeakSet,qe["aria-hidden"]=new WeakSet,we=new WeakMap)}}function ht(e,t={}){const{ariaHidden:n=!1,inert:r=!1,mark:s=!0,markerIgnoreElements:c=[]}=t,o=D(e[0]).body;return hn(e,o,n,r,{mark:s,markerIgnoreElements:c})}function kt(){const e=new Map;return{emit(t,n){e.get(t)?.forEach(r=>r(n))},on(t,n){e.has(t)||e.set(t,new Set),e.get(t).add(n)},off(t,n){e.get(t)?.delete(n)}}}class mn{nodesRef={current:[]};events=kt();addNode(t){this.nodesRef.current.push(t)}removeNode(t){const n=this.nodesRef.current.findIndex(r=>r===t);n!==-1&&this.nodesRef.current.splice(n,1)}}const Pt=f.createContext(null),Ft=f.createContext(null),Ze=()=>f.useContext(Pt)?.id||null,et=e=>{const t=f.useContext(Ft);return e??t};function zn(e){const t=ze(),n=et(e),r=Ze();return G(()=>{if(!t)return;const s={id:t,parentId:r};return n?.addNode(s),()=>{n?.removeNode(s)}},[n,t,r]),t}function Jn(e){const{children:t,id:n}=e,r=Ze();return Te.jsx(Pt.Provider,{value:f.useMemo(()=>({id:n,parentId:r}),[n,r]),children:t})}function Qn(e){const{children:t,externalTree:n}=e,r=St(()=>n??new mn).current;return Te.jsx(Ft.Provider,{value:r,children:t})}function bn(e,t){const n=We(Re(e));return e instanceof n.KeyboardEvent?"keyboard":e instanceof n.FocusEvent?t||"keyboard":"pointerType"in e?e.pointerType||"keyboard":"touches"in e?"touch":e instanceof n.MouseEvent?t||(e.detail===0?"keyboard":"mouse"):""}const mt=20;let fe=[];function tt(){fe=fe.filter(e=>e.deref()?.isConnected)}function En(e){tt(),e&&Ot(e)!=="body"&&(fe.push(new WeakRef(e)),fe.length>mt&&(fe=fe.slice(-mt)))}function Ue(){return tt(),fe[fe.length-1]?.deref()}function yn(e){return e?Je(e)?e:wt(e)[0]||e:null}function bt(e,t){if(e.hasAttribute("tabindex")&&!e.hasAttribute("data-tabindex")||!t.current.includes("floating")&&!e.getAttribute("role")?.includes("dialog"))return;const r=Qt(e).filter(c=>{const o=c.getAttribute("data-tabindex")||"";return Je(c)||c.hasAttribute("data-tabindex")&&!o.startsWith("-")}),s=e.getAttribute("tabindex");t.current.includes("floating")||r.length===0?s!=="0"&&e.setAttribute("tabindex","0"):(s!=="-1"||e.hasAttribute("data-tabindex")&&e.getAttribute("data-tabindex")!=="-1")&&(e.setAttribute("tabindex","-1"),e.setAttribute("data-tabindex","-1"))}function Zn(e){const{context:t,children:n,disabled:r=!1,initialFocus:s=!0,returnFocus:c=!0,restoreFocus:o=!1,modal:u=!0,closeOnFocusOut:v=!0,openInteractionType:M="",nextFocusableElement:O,previousFocusableElement:A,beforeContentFocusGuardRef:z,externalTree:w,getInsideElements:k}=e,m="rootStore"in t?t.rootStore:t,y=m.useState("open"),b=m.useState("domReferenceElement"),E=m.useState("floatingElement"),{events:Z,dataRef:N}=m.context,Y=U(()=>N.current.floatingContext?.nodeId),J=s===!1,I=ot(b)&&J,ee=f.useRef(["content"]),se=Ge(s),P=Ge(c),ie=Ge(M),j=et(w),p=Bt(),$=f.useRef(!1),Q=f.useRef(!1),de=f.useRef(!1),oe=f.useRef(null),te=f.useRef(""),pe=f.useRef(""),ge=f.useRef(null),he=f.useRef(null),ke=ct(ge,z,p?.beforeInsideRef),R=ct(he,p?.afterInsideRef),q=Ae(),ce=Ae(),me=Gt(),Pe=p!=null,g=it(E),K=U((a=g)=>a?wt(a):[]),ne=U(()=>k?.().filter(a=>a!=null)??[]);f.useEffect(()=>{if(r||!u)return;function a(H){H.key==="Tab"&&C(g,ae(D(g)))&&K().length===0&&!I&&qt(H)}const W=D(g);return x(W,"keydown",a)},[r,g,u,I,K]),f.useEffect(()=>{if(r||!y)return;const a=D(g);function W(){de.current=!1}function H(S){const h=Re(S),F=ne(),d=C(E,h)||C(b,h)||C(p?.portalNode,h)||F.some(_=>_===h||C(_,h));de.current=!d,pe.current=S.pointerType||"keyboard",h?.closest(`[${jt}]`)&&(Q.current=!0)}function L(){pe.current="keyboard"}return xe(x(a,"pointerdown",H,!0),x(a,"pointerup",W,!0),x(a,"pointercancel",W,!0),x(a,"keydown",L,!0))},[r,E,b,g,y,p,ne]),f.useEffect(()=>{if(r||!v)return;const a=D(g);function W(){Q.current=!0,ce.start(0,()=>{Q.current=!1})}function H(F){const d=Re(F);Je(d)&&(oe.current=d)}function L(F){const d=F.relatedTarget,_=F.currentTarget,X=Re(F);queueMicrotask(()=>{const be=Y(),V=m.context.triggerElements,Le=ne(),i=d?.hasAttribute($e("focus-guard"))&&[ge.current,he.current,p?.beforeInsideRef.current,p?.afterInsideRef.current,p?.beforeOutsideRef.current,p?.afterOutsideRef.current,le(A),le(O)].includes(d),l=!(C(b,d)||C(E,d)||C(d,E)||C(p?.portalNode,d)||Le.some(T=>T===d||C(T,d))||d!=null&&V.hasElement(d)||V.hasMatchingElement(T=>C(T,d))||i||j&&(Ie(j.nodesRef.current,be).find(T=>C(T.context?.elements.floating,d)||C(T.context?.elements.domReference,d))||ft(j.nodesRef.current,be).find(T=>[T.context?.elements.floating,it(T.context?.elements.floating)].includes(d)||T.context?.elements.domReference===d)));if(_===b&&g&&bt(g,ee),o&&_!==b&&!zt(X)&&ae(a)===a.body){if(Ee(g)&&(g.focus(),o==="popup")){me.request(()=>{g.focus()});return}const T=K(),B=oe.current,ue=(B&&T.includes(B)?B:null)||T[T.length-1]||g;Ee(ue)&&ue.focus()}if(N.current.insideReactTree){N.current.insideReactTree=!1;return}(I||!u)&&d&&l&&!Q.current&&(I||d!==Ue())&&($.current=!0,m.setOpen(!1,Me(Jt,F)))})}function S(){de.current||(N.current.insideReactTree=!0,q.start(0,()=>{N.current.insideReactTree=!1}))}const h=Ee(b)?b:null;if(!(!E&&!h))return xe(h&&x(h,"focusout",L),h&&x(h,"pointerdown",W),E&&x(E,"focusin",H),E&&x(E,"focusout",L),E&&p&&x(E,"focusout",S,!0))},[r,b,E,g,u,j,p,m,v,o,K,I,Y,ee,N,q,ce,me,O,A,ne]),f.useEffect(()=>{if(r||!E||!y)return;const a=Array.from(p?.portalNode?.querySelectorAll(`[${$e("portal")}]`)||[]),H=(j?ft(j.nodesRef.current,Y()):[]).find(_=>ot(_.context?.elements.domReference||null))?.context?.elements.domReference,S=[...[E,...a,ge.current,he.current,p?.beforeOutsideRef.current,p?.afterOutsideRef.current,...ne()],H,le(A),le(O),I?b:null].filter(_=>_!=null),h=ht(S,{ariaHidden:u||I,mark:!1}),F=[E,...a].filter(_=>_!=null),d=ht(F);return()=>{d(),h()}},[y,r,b,E,u,p,I,j,Y,O,A,ne]),G(()=>{if(!y||r||!Ee(g))return;const a=D(g),W=ae(a);queueMicrotask(()=>{const H=se.current,L=typeof H=="function"?H(ie.current||""):H;if(L===void 0||L===!1||C(g,W))return;let h=null;const F=()=>(h==null&&(h=K(g)),h[0]||g);let d;L===!0||L===null?d=F():d=le(L),d=d||F();const _=C(g,ae(a));Ke(d,{preventScroll:d===g,shouldFocus(){if(_)return!0;const X=ae(a);return!(X!==d&&C(g,X))}})})},[r,y,g,K,se,ie]),G(()=>{if(r||!g)return;const a=D(g),W=ae(a);En(W);function H(S){if(S.open||(te.current=bn(S.nativeEvent,pe.current)),S.reason===Kt&&S.nativeEvent.type==="mouseleave"&&($.current=!0),S.reason===Ct)if(S.nested)$.current=!1;else if(Dt(S.nativeEvent)||Xt(S.nativeEvent))$.current=!1;else{let h=!1;D(g).createElement("div").focus({get preventScroll(){return h=!0,!1}}),h?$.current=!1:$.current=!0}}Z.on("openchange",H);function L(){const S=P.current;let h=typeof S=="function"?S(te.current):S;if(h===void 0||h===!1)return null;if(h===null&&(h=!0),typeof h=="boolean")return b?.isConnected?b:Ue()||null;const F=b?.isConnected?b:Ue();return le(h)||F||null}return()=>{Z.off("openchange",H);const S=ae(a),h=ne(),F=C(E,S)||h.some(X=>X===S||C(X,S))||j&&Ie(j.nodesRef.current,Y(),!1).some(X=>C(X.context?.elements.floating,S)),d=P.current,_=L();queueMicrotask(()=>{const X=yn(_),be=typeof d!="boolean";d&&!$.current&&Ee(X)&&(!(!be&&X!==S&&S!==a.body)||F)&&X.focus({preventScroll:!0}),$.current=!1})}},[r,E,g,P,Z,j,b,Y,ne]),G(()=>{if(!xt||y||!E)return;const a=ae(D(E));!Ee(a)||!Vt(a)||C(E,a)&&a.blur()},[y,E]),G(()=>{if(!(r||!p))return p.setFocusManagerState({modal:u,closeOnFocusOut:v,open:y,onOpenChange:m.setOpen,domReference:b}),()=>{p.setFocusManagerState(null)}},[r,p,u,y,m,v,b]),G(()=>{if(!(r||!g))return bt(g,ee),()=>{queueMicrotask(tt)}},[r,g,ee]);const ve=!r&&(u?!I:!0)&&(Pe||u);return Te.jsxs(f.Fragment,{children:[ve&&Te.jsx(ut,{"data-type":"inside",ref:ke,onFocus:a=>{if(u){const W=K();Ke(W[W.length-1])}else p?.portalNode&&($.current=!1,lt(a,p.portalNode)?Ut(b)?.focus():le(A??p.beforeOutsideRef)?.focus())}}),n,ve&&Te.jsx(ut,{"data-type":"inside",ref:R,onFocus:a=>{u?Ke(K()[0]):p?.portalNode&&(v&&($.current=!0),lt(a,p.portalNode)?$t(b)?.focus():le(O??p.afterOutsideRef)?.focus())}})]})}const Rn={intentional:"onClick",sloppy:"onPointerDown"};function Sn(){return!1}function Tn(e){return{escapeKey:typeof e=="boolean"?e:e?.escapeKey??!1,outsidePress:typeof e=="boolean"?e:e?.outsidePress??!0}}function er(e,t={}){const{enabled:n=!0,escapeKey:r=!0,outsidePress:s=!0,outsidePressEvent:c="sloppy",referencePress:o=Sn,referencePressEvent:u="sloppy",bubbles:v,externalTree:M}=t,O="rootStore"in e?e.rootStore:e,A=O.useState("open"),z=O.useState("floatingElement"),{dataRef:w}=O.context,k=et(M),m=U(typeof s=="function"?s:()=>!1),y=typeof s=="function"?m:s,b=y!==!1,E=U(()=>c),{escapeKey:Z,outsidePress:N}=Tn(v),Y=f.useRef(!1),J=f.useRef(!1),I=f.useRef(!1),ee=f.useRef(!1),se=f.useRef(""),P=f.useRef(null),ie=Ae(),j=Ae(),p=U(()=>{j.clear(),w.current.insideReactTree=!1}),$=U(R=>{const q=w.current.floatingContext?.nodeId;return(k?Ie(k.nodesRef.current,q):[]).some(me=>me.context?.open&&!me.context.dataRef.current[R])}),Q=U(R=>He(R,O.select("floatingElement"))||He(R,O.select("domReferenceElement"))),de=U(R=>{o()&&O.setOpen(!1,Me(Zt,R.nativeEvent))}),oe=U(R=>{if(!A||!n||!r||R.key!=="Escape"||ee.current||!Z&&$("__escapeKeyBubbles"))return;const q=en(R)?R.nativeEvent:R,ce=Me(tn,q);O.setOpen(!1,ce),ce.isCanceled||R.preventDefault(),!Z&&!ce.isPropagationAllowed&&R.stopPropagation()}),te=U(()=>{w.current.insideReactTree=!0,j.start(0,p)}),pe=U(R=>{if(!A||!n||R.button!==0)return;const q=Re(R.nativeEvent);C(O.select("floatingElement"),q)&&(Y.current||(Y.current=!0,J.current=!1))}),ge=U(R=>{!A||!n||(R.defaultPrevented||R.nativeEvent.defaultPrevented)&&Y.current&&(J.current=!0)});f.useEffect(()=>{if(!A||!n)return;w.current.__escapeKeyBubbles=Z,w.current.__outsidePressBubbles=N;const R=new Ne,q=new Ne;function ce(){R.clear(),ee.current=!0}function me(){R.start(nn()?5:0,()=>{ee.current=!1})}function Pe(){I.current=!0,q.start(0,()=>{I.current=!1})}function g(){Y.current=!1,J.current=!1}function K(){const i=se.current,l=i==="pen"||!i?"mouse":i,T=E(),B=typeof T=="function"?T():T;return typeof B=="string"?B:B[l]}function ne(i){const l=K();return l==="intentional"&&i.type!=="click"||l==="sloppy"&&i.type==="click"}function ve(i){const l=w.current.floatingContext?.nodeId,T=k&&Ie(k.nodesRef.current,l).some(B=>He(i,B.context?.elements.floating));return Q(i)||T}function a(i){if(ne(i)){i.type!=="click"&&!Q(i)&&(q.clear(),I.current=!1),p();return}if(w.current.insideReactTree){p();return}const l=Re(i),T=`[${$e("inert")}]`,B=Ce(l)?l.getRootNode():null,ue=Array.from((vt(B)?B:D(O.select("floatingElement"))).querySelectorAll(T)),rt=O.context.triggerElements;if(l&&(rt.hasElement(l)||rt.hasMatchingElement(re=>C(re,l))))return;let Oe=Ce(l)?l:null;for(;Oe&&!_e(Oe);){const re=rn(Oe);if(_e(re)||!Ce(re))break;Oe=re}if(!(ue.length&&Ce(l)&&!sn(l)&&!C(l,O.select("floatingElement"))&&ue.every(re=>!C(Oe,re)))){if(Ee(l)&&!("touches"in i)){const re=_e(l),Ye=on(l),st=/auto|scroll/,Mt=re||st.test(Ye.overflowX),At=re||st.test(Ye.overflowY),Nt=Mt&&l.clientWidth>0&&l.scrollWidth>l.clientWidth,Wt=At&&l.clientHeight>0&&l.scrollHeight>l.clientHeight,Lt=Ye.direction==="rtl",Yt=Wt&&(Lt?i.offsetX<=l.offsetWidth-l.clientWidth:i.offsetX>l.clientWidth),Ht=Nt&&i.offsetY>l.clientHeight;if(Yt||Ht)return}if(!ve(i)){if(K()==="intentional"&&I.current){q.clear(),I.current=!1;return}typeof y=="function"&&!y(i)||$("__outsidePressBubbles")||(O.setOpen(!1,Me(Ct,i)),p())}}}function W(i){K()!=="sloppy"||i.pointerType==="touch"||!O.select("open")||!n||Q(i)||a(i)}function H(i){if(K()!=="sloppy"||!O.select("open")||!n||Q(i))return;const l=i.touches[0];l&&(P.current={startTime:Date.now(),startX:l.clientX,startY:l.clientY,dismissOnTouchEnd:!1,dismissOnMouseDown:!0},ie.start(1e3,()=>{P.current&&(P.current.dismissOnTouchEnd=!1,P.current.dismissOnMouseDown=!1)}))}function L(i,l){const T=Re(i);if(!T)return;const B=x(T,i.type,()=>{l(i),B()})}function S(i){se.current="touch",L(i,H)}function h(i){ie.clear(),i.type==="pointerdown"&&(se.current=i.pointerType),!(i.type==="mousedown"&&P.current&&!P.current.dismissOnMouseDown)&&L(i,l=>{l.type==="pointerdown"?W(l):a(l)})}function F(i){if(!Y.current)return;const l=J.current;if(g(),K()==="intentional"){if(i.type==="pointercancel"){l&&Pe();return}if(!ve(i)){if(l){Pe();return}typeof y=="function"&&!y(i)||(q.clear(),I.current=!0,p())}}}function d(i){if(K()!=="sloppy"||!P.current||Q(i))return;const l=i.touches[0];if(!l)return;const T=Math.abs(l.clientX-P.current.startX),B=Math.abs(l.clientY-P.current.startY),ue=Math.sqrt(T*T+B*B);ue>5&&(P.current.dismissOnTouchEnd=!0),ue>10&&(a(i),ie.clear(),P.current=null)}function _(i){L(i,d)}function X(i){K()!=="sloppy"||!P.current||Q(i)||(P.current.dismissOnTouchEnd&&a(i),ie.clear(),P.current=null)}function be(i){L(i,X)}const V=D(z),Le=xe(r&&xe(x(V,"keydown",oe),x(V,"compositionstart",ce),x(V,"compositionend",me)),b&&xe(x(V,"click",h,!0),x(V,"pointerdown",h,!0),x(V,"pointerup",F,!0),x(V,"pointercancel",F,!0),x(V,"mousedown",h,!0),x(V,"mouseup",F,!0),x(V,"touchstart",S,!0),x(V,"touchmove",_,!0),x(V,"touchend",be,!0)));return()=>{Le(),R.clear(),q.clear(),g(),I.current=!1}},[w,z,r,b,y,A,n,Z,N,oe,p,E,$,Q,k,O,ie]),f.useEffect(p,[y,p]);const he=f.useMemo(()=>({onKeyDown:oe,[Rn[u]]:de,...u!=="intentional"&&{onClick:de}}),[oe,de,u]),ke=f.useMemo(()=>({onKeyDown:oe,onPointerDown:ge,onMouseDown:ge,onClickCapture:te,onMouseDownCapture(R){te(),pe(R)},onPointerDownCapture(R){te(),pe(R)},onMouseUpCapture:te,onTouchEndCapture:te,onTouchMoveCapture:te}),[oe,te,pe,ge]);return f.useMemo(()=>n?{reference:he,floating:ke,trigger:he}:{},[n,he,ke])}const vn={open:Se(e=>e.open),transitionStatus:Se(e=>e.transitionStatus),domReferenceElement:Se(e=>e.domReferenceElement),referenceElement:Se(e=>e.positionReference??e.referenceElement),floatingElement:Se(e=>e.floatingElement),floatingId:Se(e=>e.floatingId)};class On extends cn{constructor(t){const{syncOnly:n,nested:r,onOpenChange:s,triggerElements:c,...o}=t;super({...o,positionReference:o.referenceElement,domReferenceElement:o.referenceElement},{onOpenChange:s,dataRef:{current:{}},events:kt(),nested:r,triggerElements:c},vn),this.syncOnly=n}syncOpenEvent=(t,n)=>{(!t||!this.state.open||n!=null&&un(n))&&(this.context.dataRef.current.openEvent=t?n:void 0)};dispatchOpenChange=(t,n)=>{this.syncOpenEvent(t,n.event);const r={open:t,reason:n.reason,nativeEvent:n.event,nested:this.context.nested,triggerElement:n.trigger};this.context.events.emit("openchange",r)};setOpen=(t,n)=>{if(this.syncOnly){this.context.onOpenChange?.(t,n);return}this.dispatchOpenChange(t,n),this.context.onOpenChange?.(t,n)}}function wn(e){const{popupStore:t,treatPopupAsFloatingElement:n=!1,floatingRootContext:r,floatingId:s,nested:c,onOpenChange:o}=e,u=t.useState("open"),v=t.useState("activeTriggerElement"),M=t.useState(n?"popupElement":"positionerElement"),O=t.context.triggerElements,A=o,z=f.useRef(null);r===void 0&&z.current===null&&(z.current=new On({open:u,transitionStatus:void 0,referenceElement:v,floatingElement:M,triggerElements:O,onOpenChange:A,floatingId:s,syncOnly:!0,nested:c}));const w=r??z.current;return t.useSyncedValue("floatingId",s),G(()=>{const k={open:u,floatingId:s,referenceElement:v,floatingElement:M};Ce(v)&&(k.domReferenceElement=v),w.state.positionReference===w.state.referenceElement&&(k.positionReference=v),w.update(k)},[u,s,v,M,w]),w.context.onOpenChange=A,w.context.nested=c,w}function Cn(e,t=!1,n=!1){const[r,s]=f.useState(e&&t?"idle":void 0),[c,o]=f.useState(e);return e&&!c&&(o(!0),s("starting")),!e&&c&&r!=="ending"&&!n&&s("ending"),!e&&!c&&r==="ending"&&s(void 0),G(()=>{if(!e&&c&&r!=="ending"&&n){const u=ye.request(()=>{s("ending")});return()=>{ye.cancel(u)}}},[e,c,r,n]),G(()=>{if(!e||t)return;const u=ye.request(()=>{s(void 0)});return()=>{ye.cancel(u)}},[t,e]),G(()=>{if(!e||!t)return;e&&c&&r!=="idle"&&s("starting");const u=ye.request(()=>{s("idle")});return()=>{ye.cancel(u)}},[t,e,c,r]),{mounted:c,setMounted:o,transitionStatus:r}}const tr={tabIndex:-1,[an]:""};function nr(e,t,n=!1){const r=ze(),s=Ze()!=null,c=f.useRef(null);e===void 0&&c.current===null&&(c.current=t(r,s));const o=e??c.current;return wn({popupStore:o,treatPopupAsFloatingElement:n,floatingRootContext:o.state.floatingRootContext,floatingId:r,nested:s,onOpenChange:o.setOpen}),{store:o,internalStore:c.current}}function xn(e,t){const n=f.useRef(null),r=f.useRef(null);return f.useCallback(s=>{if(e===void 0)return;let c=!1;if(n.current!==null){const o=n.current,u=r.current,v=t.context.triggerElements.getById(o);u&&v===u&&(t.context.triggerElements.delete(o),c=!0),n.current=null,r.current=null}if(s!==null&&(n.current=e,r.current=s,t.context.triggerElements.add(e,s),c=!0),c){const o=t.context.triggerElements.size;t.select("open")&&t.state.triggerCount!==o&&t.set("triggerCount",o)}},[t,e])}function rr(e,t,n){const r=n?.id??null;(r||t)&&(e.activeTriggerId=r,e.activeTriggerElement=n??null)}function sr(e,t,n,r){const s=n.useState("isMountedByTrigger",e),c=xn(e,n),o=U(u=>{if(c(u),!u)return;const v=n.select("open"),M=n.select("activeTriggerId");if(M===e){n.update({activeTriggerElement:u,...v?r:null});return}M==null&&v&&n.update({activeTriggerId:e,activeTriggerElement:u,...r})});return G(()=>{s&&n.update({activeTriggerElement:t.current,...r})},[s,n,t,...Object.values(r)]),{registerTrigger:o,isMountedByThisTrigger:s}}function or(e){const t=e.useState("open"),n=e.useState("triggerCount");G(()=>{if(!t){e.state.triggerCount!==0&&e.set("triggerCount",0);return}const r=e.context.triggerElements.size,s={};if(e.state.triggerCount!==r&&(s.triggerCount=r),!e.select("activeTriggerId")&&r===1){const c=e.context.triggerElements.entries().next();if(!c.done){const[o,u]=c.value;s.activeTriggerId=o,s.activeTriggerElement=u}}(s.triggerCount!==void 0||s.activeTriggerId!==void 0)&&e.update(s)},[t,e,n])}function cr(e,t,n){const{mounted:r,setMounted:s,transitionStatus:c}=Cn(e);t.useSyncedValues({mounted:r,transitionStatus:c});const o=U(()=>{s(!1),t.update({activeTriggerId:null,activeTriggerElement:null,mounted:!1,preventUnmountingOnClose:!1}),n?.(),t.context.onOpenChangeComplete?.(!1)}),u=t.useState("preventUnmountingOnClose");return ln({enabled:r&&!e&&!u,open:e,ref:t.context.popupRef,onComplete(){e||o()}}),{forceUnmount:o,transitionStatus:c}}function ir(e,t){e.useSyncedValues(t),G(()=>()=>{e.update({activeTriggerProps:Be,inactiveTriggerProps:Be,popupProps:Be})},[e])}function ur(e,t){G(()=>{!t&&e.state.openMethod!==null&&e.set("openMethod",null)},[t,e]),G(()=>()=>{e.state.openMethod!==null&&e.set("openMethod",null)},[e])}class lr{constructor(){this.elementsSet=new Set,this.idMap=new Map}add(t,n){const r=this.idMap.get(t);r!==n&&(r!==void 0&&this.elementsSet.delete(r),this.elementsSet.add(n),this.idMap.set(t,n))}delete(t){const n=this.idMap.get(t);n&&(this.elementsSet.delete(n),this.idMap.delete(t))}hasElement(t){return this.elementsSet.has(t)}hasMatchingElement(t){for(const n of this.elementsSet)if(t(n))return!0;return!1}getById(t){return this.idMap.get(t)}entries(){return this.idMap.entries()}elements(){return this.elementsSet.values()}get size(){return this.idMap.size}}let nt=(function(e){return e.open="data-open",e.closed="data-closed",e[e.startingStyle=at.startingStyle]="startingStyle",e[e.endingStyle=at.endingStyle]="endingStyle",e.anchorHidden="data-anchor-hidden",e.side="data-side",e.align="data-align",e})({}),je=(function(e){return e.popupOpen="data-popup-open",e.pressed="data-pressed",e})({});const In={[je.popupOpen]:""},kn={[je.popupOpen]:"",[je.pressed]:""},Pn={[nt.open]:""},Fn={[nt.closed]:""},Mn={[nt.anchorHidden]:""},ar={open(e){return e?In:null}},fr={open(e){return e?kn:null}},dr={open(e){return e?Pn:Fn},anchorHidden(e){return e?Mn:null}};function pr(e){return ze(e,"base-ui")}const An="ArrowUp",Nn="ArrowDown",Wn="ArrowLeft",Ln="ArrowRight",Yn="Home",Hn="End",_n=new Set([Wn,Ln]),Bn=new Set([An,Nn]),Gn=new Set([..._n,...Bn]),gr=new Set([...Gn,Yn,Hn]),hr=f.forwardRef(function(t,n){const{cutout:r,...s}=t;let c;if(r){const o=r.getBoundingClientRect();c=`polygon(0% 0%,100% 0%,100% 100%,0% 100%,0% 0%,${o.left}px ${o.top}px,${o.left}px ${o.bottom}px,${o.right}px ${o.bottom}px,${o.right}px ${o.top}px,${o.left}px ${o.top}px)`}return Te.jsx("div",{ref:n,role:"presentation","data-base-ui-inert":"",...s,style:{position:"fixed",inset:0,userSelect:"none",WebkitUserSelect:"none",clipPath:c}})});function mr(e){const t=f.useRef(!0);t.current&&(t.current=!1,e())}let Et={},yt={},Rt="";function Kn(e){if(typeof document>"u")return!1;const t=D(e);return We(t).innerWidth-t.documentElement.clientWidth>0}function Dn(e){if(!(typeof CSS<"u"&&CSS.supports&&CSS.supports("scrollbar-gutter","stable"))||typeof document>"u")return!1;const n=D(e),r=n.documentElement,s=n.body,c=Qe(r)?r:s,o=c.style.overflowY,u=r.style.scrollbarGutter;r.style.scrollbarGutter="stable",c.style.overflowY="scroll";const v=c.offsetWidth;c.style.overflowY="hidden";const M=c.offsetWidth;return c.style.overflowY=o,r.style.scrollbarGutter=u,v===M}function Xn(e){const t=D(e),n=t.documentElement,r=t.body,s=Qe(n)?n:r,c={overflowY:s.style.overflowY,overflowX:s.style.overflowX};return Object.assign(s.style,{overflowY:"hidden",overflowX:"hidden"}),()=>{Object.assign(s.style,c)}}function Vn(e){const t=D(e),n=t.documentElement,r=t.body,s=We(n);let c=0,o=0,u=!1;const v=ye.create();if(xt&&(s.visualViewport?.scale??1)!==1)return()=>{};function M(){const w=s.getComputedStyle(n),k=s.getComputedStyle(r),b=(w.scrollbarGutter||"").includes("both-edges")?"stable both-edges":"stable";c=n.scrollTop,o=n.scrollLeft,Et={scrollbarGutter:n.style.scrollbarGutter,overflowY:n.style.overflowY,overflowX:n.style.overflowX},Rt=n.style.scrollBehavior,yt={position:r.style.position,height:r.style.height,width:r.style.width,boxSizing:r.style.boxSizing,overflowY:r.style.overflowY,overflowX:r.style.overflowX,scrollBehavior:r.style.scrollBehavior};const E=n.scrollHeight>n.clientHeight,Z=n.scrollWidth>n.clientWidth,N=w.overflowY==="scroll"||k.overflowY==="scroll",Y=w.overflowX==="scroll"||k.overflowX==="scroll",J=Math.max(0,s.innerWidth-r.clientWidth),I=Math.max(0,s.innerHeight-r.clientHeight),ee=parseFloat(k.marginTop)+parseFloat(k.marginBottom),se=parseFloat(k.marginLeft)+parseFloat(k.marginRight),P=Qe(n)?n:r;if(u=Dn(e),u){n.style.scrollbarGutter=b,P.style.overflowY="hidden",P.style.overflowX="hidden";return}Object.assign(n.style,{scrollbarGutter:b,overflowY:"hidden",overflowX:"hidden"}),(E||N)&&(n.style.overflowY="scroll"),(Z||Y)&&(n.style.overflowX="scroll"),Object.assign(r.style,{position:"relative",height:ee||I?`calc(100dvh - ${ee+I}px)`:"100dvh",width:se||J?`calc(100vw - ${se+J}px)`:"100vw",boxSizing:"border-box",overflow:"hidden",scrollBehavior:"unset"}),r.scrollTop=c,r.scrollLeft=o,n.setAttribute("data-base-ui-scroll-locked",""),n.style.scrollBehavior="unset"}function O(){Object.assign(n.style,Et),Object.assign(r.style,yt),u||(n.scrollTop=c,n.scrollLeft=o,n.removeAttribute("data-base-ui-scroll-locked"),n.style.scrollBehavior=Rt)}function A(){O(),v.request(M)}M();const z=x(s,"resize",A);return()=>{v.cancel(),O(),typeof s.removeEventListener=="function"&&z()}}class Un{lockCount=0;restore=null;timeoutLock=Ne.create();timeoutUnlock=Ne.create();acquire(t){return this.lockCount+=1,this.lockCount===1&&this.restore===null&&this.timeoutLock.start(0,()=>this.lock(t)),this.release}release=()=>{this.lockCount-=1,this.lockCount===0&&this.restore&&this.timeoutUnlock.start(0,this.unlock)};unlock=()=>{this.lockCount===0&&this.restore&&(this.restore?.(),this.restore=null)};lock(t){if(this.lockCount===0||this.restore!==null)return;const r=D(t).documentElement,s=We(r).getComputedStyle(r).overflowY;if(s==="hidden"||s==="clip"){this.restore=Tt;return}const c=fn||!Kn(t);this.restore=c?Xn(t):Vn(t)}}const $n=new Un;function br(e=!0,t=null){G(()=>{if(e)return $n.acquire(t)},[e,t])}export{nt as A,jn as C,Qn as F,hr as I,lr as P,Cn as a,et as b,Ze as c,Ge as d,nr as e,mr as f,Ie as g,ur as h,or as i,cr as j,er as k,tr as l,ir as m,sr as n,zn as o,fr as p,Jn as q,Zn as r,rr as s,ar as t,pr as u,gr as v,dr as w,On as x,Ke as y,br as z};
|
|
@@ -235,7 +235,7 @@
|
|
|
235
235
|
]
|
|
236
236
|
}
|
|
237
237
|
</script>
|
|
238
|
-
<script type="module" crossorigin src="/assets/main-
|
|
238
|
+
<script type="module" crossorigin src="/assets/main-waZd4gi1.js"></script>
|
|
239
239
|
<link rel="stylesheet" crossorigin href="/assets/main-BfK9LoKV.css">
|
|
240
240
|
</head>
|
|
241
241
|
<body>
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
"description": "Shareable Token Tracker dashboard snapshot."
|
|
76
76
|
}
|
|
77
77
|
</script>
|
|
78
|
-
<script type="module" crossorigin src="/assets/main-
|
|
78
|
+
<script type="module" crossorigin src="/assets/main-waZd4gi1.js"></script>
|
|
79
79
|
<link rel="stylesheet" crossorigin href="/assets/main-BfK9LoKV.css">
|
|
80
80
|
</head>
|
|
81
81
|
<body>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tokentracker-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.46.0",
|
|
4
4
|
"description": "Token usage tracker for AI agent CLIs (Claude Code, Codex, Cursor, Gemini, Kiro, OpenCode, OpenClaw, Every Code, Hermes, GitHub Copilot, Kimi Code, CodeBuddy, Grok Build, oh-my-pi, pi, Craft Agents, Kilo CLI, Kilo Code, Roo Code, Zed Agent, Goose)",
|
|
5
5
|
"main": "src/cli.js",
|
|
6
6
|
"bin": {
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// Account-aggregated (cross-device) cloud reads for the local server.
|
|
4
|
+
//
|
|
5
|
+
// The native menu-bar / tray popover talks only to the local CLI server and
|
|
6
|
+
// knows nothing about OAuth/JWT. To make the popover show the SAME cross-device
|
|
7
|
+
// totals the dashboard shows in "account view", the local server mints a
|
|
8
|
+
// short-lived access token from the InsForge refresh token it already relays
|
|
9
|
+
// (see local-api.js cookie relay) and proxies the `tokentracker-account-*` edge
|
|
10
|
+
// functions. Those functions mirror the local `tokentracker-usage-*` response
|
|
11
|
+
// schema exactly, so the popover renders the cloud payload unchanged.
|
|
12
|
+
|
|
13
|
+
const { DEFAULT_BASE_URL, DEFAULT_ANON_KEY } = require("./runtime-config");
|
|
14
|
+
|
|
15
|
+
// usage-* (local CLI) → account-* (cloud) slug map. Only these have a
|
|
16
|
+
// cross-device cloud equivalent; project-usage / usage-limits / category
|
|
17
|
+
// breakdown remain local-only and are intentionally absent here.
|
|
18
|
+
const USAGE_TO_ACCOUNT_SLUG = {
|
|
19
|
+
"tokentracker-usage-summary": "tokentracker-account-summary",
|
|
20
|
+
"tokentracker-usage-daily": "tokentracker-account-daily",
|
|
21
|
+
"tokentracker-usage-hourly": "tokentracker-account-hourly",
|
|
22
|
+
"tokentracker-usage-monthly": "tokentracker-account-monthly",
|
|
23
|
+
"tokentracker-usage-heatmap": "tokentracker-account-heatmap",
|
|
24
|
+
"tokentracker-usage-model-breakdown": "tokentracker-account-model-breakdown",
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
function accountSlugFor(usageSlug) {
|
|
28
|
+
return USAGE_TO_ACCOUNT_SLUG[usageSlug] || null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Mirror of dashboard/src/contexts/InsforgeAuthContext.jsx
|
|
32
|
+
// `accessTokenFromRefreshPayload`: the refresh response may put the token at the
|
|
33
|
+
// top level or nested under `session`, in camelCase or snake_case.
|
|
34
|
+
function accessTokenFromRefreshPayload(data) {
|
|
35
|
+
if (!data || typeof data !== "object") return null;
|
|
36
|
+
const session = data.session && typeof data.session === "object" ? data.session : null;
|
|
37
|
+
const raw =
|
|
38
|
+
(typeof data.accessToken === "string" && data.accessToken) ||
|
|
39
|
+
(typeof data.access_token === "string" && data.access_token) ||
|
|
40
|
+
(session && typeof session.accessToken === "string" && session.accessToken) ||
|
|
41
|
+
(session && typeof session.access_token === "string" && session.access_token) ||
|
|
42
|
+
null;
|
|
43
|
+
return raw && raw.length > 0 ? raw : null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function refreshTokenFromRefreshPayload(data) {
|
|
47
|
+
if (!data || typeof data !== "object") return null;
|
|
48
|
+
const session = data.session && typeof data.session === "object" ? data.session : null;
|
|
49
|
+
const raw =
|
|
50
|
+
(typeof data.refreshToken === "string" && data.refreshToken) ||
|
|
51
|
+
(typeof data.refresh_token === "string" && data.refresh_token) ||
|
|
52
|
+
(session && typeof session.refreshToken === "string" && session.refreshToken) ||
|
|
53
|
+
(session && typeof session.refresh_token === "string" && session.refresh_token) ||
|
|
54
|
+
null;
|
|
55
|
+
return raw && raw.length > 0 ? raw : null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function decodeJwtExpMs(token) {
|
|
59
|
+
try {
|
|
60
|
+
const part = String(token || "").split(".")[1];
|
|
61
|
+
if (!part) return 0;
|
|
62
|
+
const json = Buffer.from(part.replace(/-/g, "+").replace(/_/g, "/"), "base64").toString("utf8");
|
|
63
|
+
const payload = JSON.parse(json);
|
|
64
|
+
if (payload && Number.isFinite(payload.exp)) return payload.exp * 1000;
|
|
65
|
+
} catch {
|
|
66
|
+
/* ignore */
|
|
67
|
+
}
|
|
68
|
+
return 0;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Module-level access-token cache, keyed by the refresh token that produced it.
|
|
72
|
+
// The popover polls frequently, so caching avoids hammering /api/auth/refresh.
|
|
73
|
+
let tokenCache = { refreshToken: null, accessToken: null, expMs: 0 };
|
|
74
|
+
|
|
75
|
+
function __resetCloudAccountCacheForTests() {
|
|
76
|
+
tokenCache = { refreshToken: null, accessToken: null, expMs: 0 };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Mint (or reuse a cached) InsForge access token from a refresh token.
|
|
81
|
+
* @returns {Promise<{accessToken: string, refreshToken: string|null}|null>}
|
|
82
|
+
* null when no refresh token is available or the refresh failed.
|
|
83
|
+
*/
|
|
84
|
+
async function mintAccessToken({
|
|
85
|
+
baseUrl,
|
|
86
|
+
anonKey,
|
|
87
|
+
refreshToken,
|
|
88
|
+
fetchImpl = fetch,
|
|
89
|
+
now = Date.now,
|
|
90
|
+
skewMs = 60_000,
|
|
91
|
+
} = {}) {
|
|
92
|
+
if (!refreshToken) return null;
|
|
93
|
+
if (
|
|
94
|
+
tokenCache.refreshToken === refreshToken &&
|
|
95
|
+
tokenCache.accessToken &&
|
|
96
|
+
tokenCache.expMs - skewMs > now()
|
|
97
|
+
) {
|
|
98
|
+
return { accessToken: tokenCache.accessToken, refreshToken: null };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const root = String(baseUrl || DEFAULT_BASE_URL).replace(/\/$/, "");
|
|
102
|
+
const headers = { "Content-Type": "application/json", Accept: "application/json" };
|
|
103
|
+
if (anonKey) headers.apikey = anonKey;
|
|
104
|
+
|
|
105
|
+
let res;
|
|
106
|
+
try {
|
|
107
|
+
res = await fetchImpl(`${root}/api/auth/refresh?client_type=mobile`, {
|
|
108
|
+
method: "POST",
|
|
109
|
+
headers,
|
|
110
|
+
body: JSON.stringify({ refresh_token: refreshToken }),
|
|
111
|
+
});
|
|
112
|
+
} catch {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
if (!res || !res.ok) return null;
|
|
116
|
+
|
|
117
|
+
let data = null;
|
|
118
|
+
try {
|
|
119
|
+
data = await res.json();
|
|
120
|
+
} catch {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const accessToken = accessTokenFromRefreshPayload(data);
|
|
125
|
+
if (!accessToken) return null;
|
|
126
|
+
|
|
127
|
+
const expMs = decodeJwtExpMs(accessToken) || now() + 10 * 60_000;
|
|
128
|
+
tokenCache = { refreshToken, accessToken, expMs };
|
|
129
|
+
|
|
130
|
+
const rotated = refreshTokenFromRefreshPayload(data);
|
|
131
|
+
return {
|
|
132
|
+
accessToken,
|
|
133
|
+
refreshToken: rotated && rotated !== refreshToken ? rotated : null,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* GET a `tokentracker-account-*` edge function, forwarding the popover's query
|
|
139
|
+
* params (minus `account`/`scope`, which are local-only routing knobs).
|
|
140
|
+
*/
|
|
141
|
+
async function fetchAccountFunction({
|
|
142
|
+
baseUrl,
|
|
143
|
+
anonKey,
|
|
144
|
+
accessToken,
|
|
145
|
+
slug,
|
|
146
|
+
searchParams,
|
|
147
|
+
fetchImpl = fetch,
|
|
148
|
+
} = {}) {
|
|
149
|
+
const root = String(baseUrl || DEFAULT_BASE_URL).replace(/\/$/, "");
|
|
150
|
+
const url = new URL(`${root}/functions/${slug}`);
|
|
151
|
+
if (searchParams && typeof searchParams.entries === "function") {
|
|
152
|
+
for (const [key, value] of searchParams.entries()) {
|
|
153
|
+
if (key === "account" || key === "scope") continue;
|
|
154
|
+
if (value != null && value !== "") url.searchParams.set(key, String(value));
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
const headers = { Accept: "application/json", Authorization: `Bearer ${accessToken}` };
|
|
158
|
+
if (anonKey) headers.apikey = anonKey;
|
|
159
|
+
|
|
160
|
+
const res = await fetchImpl(url.toString(), { method: "GET", headers });
|
|
161
|
+
if (!res || !res.ok) {
|
|
162
|
+
const err = new Error(`Account fetch failed with HTTP ${res ? res.status : "?"}`);
|
|
163
|
+
err.status = res ? res.status : 0;
|
|
164
|
+
throw err;
|
|
165
|
+
}
|
|
166
|
+
return res.json();
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* High-level helper used by local-api: mint a token from `refreshToken`, then
|
|
171
|
+
* fetch the cross-device aggregate matching `usageSlug`.
|
|
172
|
+
*
|
|
173
|
+
* @returns {Promise<{data: any, rotatedRefreshToken: string|null}|null>}
|
|
174
|
+
* null when there is no cloud equivalent, no refresh token, or the refresh
|
|
175
|
+
* failed. Throws only when the account endpoint itself errors (so callers can
|
|
176
|
+
* distinguish "not signed in" from "cloud request failed").
|
|
177
|
+
*/
|
|
178
|
+
async function fetchAccountUsage({
|
|
179
|
+
usageSlug,
|
|
180
|
+
searchParams,
|
|
181
|
+
baseUrl = DEFAULT_BASE_URL,
|
|
182
|
+
anonKey = DEFAULT_ANON_KEY,
|
|
183
|
+
refreshToken,
|
|
184
|
+
fetchImpl = fetch,
|
|
185
|
+
now = Date.now,
|
|
186
|
+
} = {}) {
|
|
187
|
+
const slug = accountSlugFor(usageSlug);
|
|
188
|
+
if (!slug) return null;
|
|
189
|
+
|
|
190
|
+
const minted = await mintAccessToken({ baseUrl, anonKey, refreshToken, fetchImpl, now });
|
|
191
|
+
if (!minted) return null;
|
|
192
|
+
|
|
193
|
+
const data = await fetchAccountFunction({
|
|
194
|
+
baseUrl,
|
|
195
|
+
anonKey,
|
|
196
|
+
accessToken: minted.accessToken,
|
|
197
|
+
slug,
|
|
198
|
+
searchParams,
|
|
199
|
+
fetchImpl,
|
|
200
|
+
});
|
|
201
|
+
return { data, rotatedRefreshToken: minted.refreshToken };
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
module.exports = {
|
|
205
|
+
USAGE_TO_ACCOUNT_SLUG,
|
|
206
|
+
accountSlugFor,
|
|
207
|
+
accessTokenFromRefreshPayload,
|
|
208
|
+
refreshTokenFromRefreshPayload,
|
|
209
|
+
decodeJwtExpMs,
|
|
210
|
+
mintAccessToken,
|
|
211
|
+
fetchAccountFunction,
|
|
212
|
+
fetchAccountUsage,
|
|
213
|
+
__resetCloudAccountCacheForTests,
|
|
214
|
+
};
|
package/src/lib/local-api.js
CHANGED
|
@@ -10,6 +10,7 @@ const {
|
|
|
10
10
|
listExcludedSources,
|
|
11
11
|
normalizeUsageScope,
|
|
12
12
|
} = require("./source-metadata");
|
|
13
|
+
const { accountSlugFor, fetchAccountUsage } = require("./cloud-account");
|
|
13
14
|
|
|
14
15
|
const SYNC_TIMEOUT_MS = 120_000;
|
|
15
16
|
const TRACKER_BIN = path.resolve(__dirname, "../../bin/tracker.js");
|
|
@@ -936,6 +937,87 @@ function createLocalApiHandler({ queuePath }) {
|
|
|
936
937
|
if (changed) persistRelayCookies();
|
|
937
938
|
}
|
|
938
939
|
|
|
940
|
+
// --- Account (cross-device) view for the native popover ---------------
|
|
941
|
+
// The popover follows the dashboard: it shows aggregated cross-device data
|
|
942
|
+
// only when the user is signed in (a relayed refresh token exists) AND cloud
|
|
943
|
+
// sync is on. Cloud sync is a dashboard (WebView) preference persisted in
|
|
944
|
+
// localStorage; the dashboard mirrors it here via POST
|
|
945
|
+
// /functions/tokentracker-cloud-sync-pref so the auth-unaware popover can key
|
|
946
|
+
// off the same flag. Defaults OFF, exactly like the dashboard toggle.
|
|
947
|
+
const cloudSyncPrefPath = path.join(trackerDataDir, "cloud-sync-pref.json");
|
|
948
|
+
let cloudSyncPrefCache;
|
|
949
|
+
function getCloudSyncPref() {
|
|
950
|
+
if (cloudSyncPrefCache === undefined) {
|
|
951
|
+
try {
|
|
952
|
+
cloudSyncPrefCache = JSON.parse(fs.readFileSync(cloudSyncPrefPath, "utf8"))?.enabled === true;
|
|
953
|
+
} catch {
|
|
954
|
+
cloudSyncPrefCache = false;
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
return cloudSyncPrefCache;
|
|
958
|
+
}
|
|
959
|
+
function setCloudSyncPref(enabled) {
|
|
960
|
+
cloudSyncPrefCache = Boolean(enabled);
|
|
961
|
+
try {
|
|
962
|
+
if (!fs.existsSync(trackerDataDir)) fs.mkdirSync(trackerDataDir, { recursive: true });
|
|
963
|
+
fs.writeFileSync(
|
|
964
|
+
cloudSyncPrefPath,
|
|
965
|
+
JSON.stringify({ enabled: cloudSyncPrefCache, updatedAt: new Date().toISOString() }),
|
|
966
|
+
{ encoding: "utf8", mode: 0o600 },
|
|
967
|
+
);
|
|
968
|
+
} catch (e) {
|
|
969
|
+
console.error("[LocalAPI] Failed to persist cloud sync pref:", e.message);
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
function getRefreshTokenForCloud() {
|
|
974
|
+
return getRelayCookieValue("insforge_refresh_token", { decode: true });
|
|
975
|
+
}
|
|
976
|
+
function setRelayRefreshToken(token) {
|
|
977
|
+
if (!token || typeof token !== "string") return;
|
|
978
|
+
const cookie = `insforge_refresh_token=${encodeURIComponent(token)}; Path=/; HttpOnly; SameSite=Lax`;
|
|
979
|
+
if (relayCookies.get("insforge_refresh_token") !== cookie) {
|
|
980
|
+
relayCookies.set("insforge_refresh_token", cookie);
|
|
981
|
+
persistRelayCookies();
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
// Returns "served" when the cross-device aggregate was written to `res`, or
|
|
986
|
+
// "fallthrough" when the caller should serve the local single-machine data.
|
|
987
|
+
// Any failure (not signed in, cloud sync off, network/auth error) falls
|
|
988
|
+
// through so the popover always renders something.
|
|
989
|
+
async function tryServeAccountView(usageSlug, url, res) {
|
|
990
|
+
if (!getCloudSyncPref()) return "fallthrough";
|
|
991
|
+
const refreshToken = getRefreshTokenForCloud();
|
|
992
|
+
if (!refreshToken) return "fallthrough";
|
|
993
|
+
const runtime = resolveRuntimeConfig();
|
|
994
|
+
try {
|
|
995
|
+
const out = await fetchAccountUsage({
|
|
996
|
+
usageSlug,
|
|
997
|
+
searchParams: url.searchParams,
|
|
998
|
+
baseUrl: runtime.baseUrl || DEFAULT_BASE_URL,
|
|
999
|
+
anonKey: runtime.anonKey,
|
|
1000
|
+
refreshToken,
|
|
1001
|
+
});
|
|
1002
|
+
if (!out || out.data == null) return "fallthrough";
|
|
1003
|
+
if (out.rotatedRefreshToken) setRelayRefreshToken(out.rotatedRefreshToken);
|
|
1004
|
+
res.writeHead(200, {
|
|
1005
|
+
"Content-Type": "application/json",
|
|
1006
|
+
"Cache-Control": "no-store",
|
|
1007
|
+
"X-TokenTracker-Account-View": "1",
|
|
1008
|
+
});
|
|
1009
|
+
res.end(JSON.stringify(out.data));
|
|
1010
|
+
return "served";
|
|
1011
|
+
} catch (e) {
|
|
1012
|
+
// Signed in + cloud sync on, but the cloud read failed (offline, token
|
|
1013
|
+
// rejected, edge error). Fall back to local data rather than erroring.
|
|
1014
|
+
if (resolveRuntimeConfig().debug) {
|
|
1015
|
+
console.warn(`[LocalAPI] account view fallback for ${usageSlug}:`, e?.message || e);
|
|
1016
|
+
}
|
|
1017
|
+
return "fallthrough";
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
|
|
939
1021
|
function normalizeCookieHeader(value) {
|
|
940
1022
|
if (Array.isArray(value)) return value.filter(Boolean).join("; ");
|
|
941
1023
|
return typeof value === "string" ? value : "";
|
|
@@ -1346,6 +1428,20 @@ function createLocalApiHandler({ queuePath }) {
|
|
|
1346
1428
|
return true;
|
|
1347
1429
|
}
|
|
1348
1430
|
|
|
1431
|
+
// --- account (cross-device) view proxy for the native popover ---
|
|
1432
|
+
// When ?account=1 and the user is signed in with cloud sync on, serve the
|
|
1433
|
+
// same cross-device aggregate the dashboard shows; otherwise tag the
|
|
1434
|
+
// response (X-TokenTracker-Account-View: 0) so the popover knows it got
|
|
1435
|
+
// local single-machine data, and fall through to the local handler below.
|
|
1436
|
+
if (url.searchParams.get("account") === "1") {
|
|
1437
|
+
const usageSlug = p.startsWith("/functions/") ? p.slice("/functions/".length) : "";
|
|
1438
|
+
if (accountSlugFor(usageSlug)) {
|
|
1439
|
+
const result = await tryServeAccountView(usageSlug, url, res);
|
|
1440
|
+
if (result === "served") return true;
|
|
1441
|
+
res.setHeader("X-TokenTracker-Account-View", "0");
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
|
|
1349
1445
|
// --- usage-summary ---
|
|
1350
1446
|
if (p === "/functions/tokentracker-usage-summary") {
|
|
1351
1447
|
const from = url.searchParams.get("from") || "";
|
|
@@ -1681,10 +1777,56 @@ function createLocalApiHandler({ queuePath }) {
|
|
|
1681
1777
|
user_id: "local-user", email: "local@localhost", name: "Local User", is_public: false,
|
|
1682
1778
|
created_at: new Date().toISOString(),
|
|
1683
1779
|
pro: { active: true, sources: ["local"], expires_at: null, partial: false, as_of: new Date().toISOString() },
|
|
1780
|
+
// Cross-device popover state: whether account aggregation can be served
|
|
1781
|
+
// (signed in) and whether the dashboard's cloud-sync toggle is on.
|
|
1782
|
+
account: {
|
|
1783
|
+
available: Boolean(getRefreshTokenForCloud()),
|
|
1784
|
+
cloud_sync_enabled: getCloudSyncPref(),
|
|
1785
|
+
account_view: Boolean(getRefreshTokenForCloud()) && getCloudSyncPref(),
|
|
1786
|
+
},
|
|
1684
1787
|
});
|
|
1685
1788
|
return true;
|
|
1686
1789
|
}
|
|
1687
1790
|
|
|
1791
|
+
// --- cloud-sync preference mirror ---
|
|
1792
|
+
// The dashboard's Settings → Account → Cloud sync toggle (a WebView
|
|
1793
|
+
// localStorage flag) is mirrored here so the auth-unaware native popover can
|
|
1794
|
+
// gate its account (cross-device) view on the same preference.
|
|
1795
|
+
if (p === "/functions/tokentracker-cloud-sync-pref") {
|
|
1796
|
+
const method = String(req.method || "GET").toUpperCase();
|
|
1797
|
+
if (method === "GET") {
|
|
1798
|
+
json(res, {
|
|
1799
|
+
enabled: getCloudSyncPref(),
|
|
1800
|
+
account_available: Boolean(getRefreshTokenForCloud()),
|
|
1801
|
+
});
|
|
1802
|
+
return true;
|
|
1803
|
+
}
|
|
1804
|
+
if (method === "POST" || method === "PUT") {
|
|
1805
|
+
if (!isAuthorizedLocalMutation(req)) {
|
|
1806
|
+
json(res, { ok: false, error: "Unauthorized" }, 401);
|
|
1807
|
+
return true;
|
|
1808
|
+
}
|
|
1809
|
+
let body = {};
|
|
1810
|
+
try {
|
|
1811
|
+
body = await readJsonBody(req);
|
|
1812
|
+
} catch {
|
|
1813
|
+
body = {};
|
|
1814
|
+
}
|
|
1815
|
+
// Reject malformed payloads rather than silently coercing them to a
|
|
1816
|
+
// persisted `false` — this file is the shared cloud-sync preference, so
|
|
1817
|
+
// a bad write would desync the popover from the dashboard.
|
|
1818
|
+
if (typeof body?.enabled !== "boolean") {
|
|
1819
|
+
json(res, { ok: false, error: "enabled must be a boolean" }, 400);
|
|
1820
|
+
return true;
|
|
1821
|
+
}
|
|
1822
|
+
setCloudSyncPref(body.enabled);
|
|
1823
|
+
json(res, { ok: true, enabled: getCloudSyncPref() });
|
|
1824
|
+
return true;
|
|
1825
|
+
}
|
|
1826
|
+
json(res, { error: "Method Not Allowed" }, 405);
|
|
1827
|
+
return true;
|
|
1828
|
+
}
|
|
1829
|
+
|
|
1688
1830
|
// --- machine-id (stable per-machine device identity for cloud sync) ---
|
|
1689
1831
|
// The dashboard reads this before issuing a cloud device token so the
|
|
1690
1832
|
// device_name keys on the MACHINE, not the browser — see
|