tokentracker-cli 0.49.1 → 0.49.3
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-CdSIa7qF.js → ActivityHeatmap-DByCSENs.js} +1 -1
- package/dashboard/dist/assets/{Card-Ds-oKKa8.js → Card-B71GwGxO.js} +1 -1
- package/dashboard/dist/assets/{DashboardPage-DlSGoNwE.js → DashboardPage-BjOx4W82.js} +1 -1
- package/dashboard/dist/assets/{DevicePage-BmuuVq8P.js → DevicePage-Cfj34qew.js} +1 -1
- package/dashboard/dist/assets/{DialogTitle-DvcD6xbM.js → DialogTitle-BdNBXNZX.js} +1 -1
- package/dashboard/dist/assets/{FadeIn-DVysFsQD.js → FadeIn-BuCfpXMc.js} +1 -1
- package/dashboard/dist/assets/{HeaderGithubStar-DfFuzPIQ.js → HeaderGithubStar-DpZhDW9t.js} +1 -1
- package/dashboard/dist/assets/{IpCheckPage-Cx201GiV.js → IpCheckPage-DJtvaczo.js} +1 -1
- package/dashboard/dist/assets/{LandingPage-CwVgEDkV.js → LandingPage-DVR_EDlv.js} +1 -1
- package/dashboard/dist/assets/{LeaderboardAvatar-ziBbRVvs.js → LeaderboardAvatar-C6KucnuS.js} +1 -1
- package/dashboard/dist/assets/{LeaderboardPage-Biqvdo4g.js → LeaderboardPage-DKHvUmGb.js} +3 -3
- package/dashboard/dist/assets/{LeaderboardProfileModal-DqPL0kqy.js → LeaderboardProfileModal-sb4nmMCj.js} +1 -1
- package/dashboard/dist/assets/{LeaderboardProfilePage-DmRnMtr0.js → LeaderboardProfilePage-BK-1QWfg.js} +1 -1
- package/dashboard/dist/assets/{LimitsPage-Cp5h_6V-.js → LimitsPage-D7m20XVf.js} +1 -1
- package/dashboard/dist/assets/{LocalOnlyNotice-C0NrEMPx.js → LocalOnlyNotice-DZslFoj5.js} +1 -1
- package/dashboard/dist/assets/{LoginPage-MPkEezJe.js → LoginPage-HQ8ks6KL.js} +1 -1
- package/dashboard/dist/assets/{PopoverPopup-tas7bWDM.js → PopoverPopup-BjP_x_N0.js} +1 -1
- package/dashboard/dist/assets/{Select-C1XPo279.js → Select-B5C3SgjS.js} +1 -1
- package/dashboard/dist/assets/{SelectItemText-BXdfdMoI.js → SelectItemText-XBZTRfTk.js} +1 -1
- package/dashboard/dist/assets/{SettingsPage-uCq1kQJB.js → SettingsPage-C3pgKsph.js} +1 -1
- package/dashboard/dist/assets/{SkillsPage-BBK1FZHz.js → SkillsPage-C884cEOL.js} +1 -1
- package/dashboard/dist/assets/{WidgetsPage-B4vqrcSC.js → WidgetsPage-Wsg4rX9h.js} +1 -1
- package/dashboard/dist/assets/{WrappedPage-BKjocXbt.js → WrappedPage-BSWIQwdE.js} +1 -1
- package/dashboard/dist/assets/{agent-logos-aCP1gjjY.js → agent-logos-umK0ojkk.js} +1 -1
- package/dashboard/dist/assets/{arrow-up-right-CKicCc9n.js → arrow-up-right-BGMGSKrn.js} +1 -1
- package/dashboard/dist/assets/{download-CyWoylMR.js → download-DBdm8vu1.js} +1 -1
- package/dashboard/dist/assets/{info-Eoucvx_Y.js → info-Dc1md1UE.js} +1 -1
- package/dashboard/dist/assets/{main-D3YoNdym.js → main-BTU7nBLK.js} +2 -2
- package/dashboard/dist/assets/{use-limits-display-prefs-CXcRsYJQ.js → use-limits-display-prefs-yZId6XkL.js} +1 -1
- package/dashboard/dist/assets/{use-native-settings-zPoh9XtP.js → use-native-settings-CquG9vh_.js} +1 -1
- package/dashboard/dist/assets/{use-usage-limits-C3UnLp-v.js → use-usage-limits-BvhFrG8a.js} +1 -1
- package/dashboard/dist/assets/{useCurrency-Bh791muK.js → useCurrency-DCzLyxzN.js} +1 -1
- package/dashboard/dist/assets/{useScrollLock-CQdlrFZs.js → useScrollLock-C5gi8Y07.js} +1 -1
- package/dashboard/dist/index.html +1 -1
- package/dashboard/dist/share.html +1 -1
- package/package.json +1 -1
- package/src/commands/sync.js +9 -0
- package/src/commands/uninstall.js +12 -0
- package/src/lib/local-api.js +2 -54
- package/src/lib/machine-id.js +238 -0
- package/src/lib/pricing/seed-snapshot.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{G as u,r as a,a_ as M,a$ as j,b0 as G,b1 as J}from"./main-
|
|
1
|
+
import{G as u,r as a,a_ as M,a$ as j,b0 as G,b1 as J}from"./main-BTU7nBLK.js";const B=["claude","codex","cursor","gemini","kimi","kiro","grok","copilot","antigravity"],q={claude:"CLAUDE",codex:"CODEX",cursor:"CURSOR",gemini:"GEMINI",kimi:"KIMI",kiro:"KIRO",grok:"GROK",copilot:"COPILOT",antigravity:"ANTIGRAVITY"};function se(e){return q[e]||null}function ae(e){switch(e){case"claude":return u("limits.provider.claude");case"codex":return u("limits.provider.codex");case"cursor":return u("limits.provider.cursor");case"gemini":return u("limits.provider.gemini");case"kimi":return u("limits.provider.kimi");case"kiro":return u("limits.provider.kiro");case"grok":return u("limits.provider.grok");case"copilot":return u("limits.provider.copilot");case"antigravity":return u("limits.provider.antigravity");default:return String(e||"")}}const y=B,A="tt.limits.providerOrder",E="tt.limits.providerVisibility",h="tt.limits.displayMode",O="tt.limits.updatedAt",V="limitsPreferences",F="limitsDisplayMode",v=Object.freeze({USED:"used",REMAINING:"remaining"}),g=new Set(Object.values(v)),L=new Set([A,E,h,O]);function I(){return[...y]}function b(){return Object.fromEntries(y.map(e=>[e,!0]))}function _(e){const r=[];if(Array.isArray(e))for(const n of e)y.includes(n)&&!r.includes(n)&&r.push(n);for(const n of y)r.includes(n)||r.push(n);return r}function N(e){const r=b();if(!e||typeof e!="object"||Array.isArray(e))return r;for(const n of y)typeof e[n]=="boolean"&&(r[n]=e[n]);return r}function X(e){return g.has(e)?e:v.USED}function m(e){if(e!=null){if(typeof e=="number")return Number.isSafeInteger(e)?e:void 0;if(typeof e=="string"){const r=e.trim();if(r==="")return;const n=Number(r);return Number.isSafeInteger(n)?n:void 0}}}function w(e={}){const r=e&&typeof e=="object"?e:{};return{displayMode:X(r.displayMode),providerOrder:_(r.providerOrder),providerVisibility:N(r.providerVisibility),updatedAt:m(r.updatedAt)}}function $(){if(typeof window>"u")return I();try{const e=window.localStorage.getItem(A);return _(e?JSON.parse(e):void 0)}catch{return I()}}function H(){if(typeof window>"u")return b();try{const e=window.localStorage.getItem(E);return N(e?JSON.parse(e):void 0)}catch{return b()}}function Q(){if(typeof window>"u")return v.USED;try{const e=window.localStorage.getItem(h);return g.has(e)?e:v.USED}catch{return v.USED}}function W(){if(!(typeof window>"u"))try{return m(window.localStorage.getItem(O))}catch{return}}function Z(){if(typeof window>"u")return!1;try{for(const e of L)if(window.localStorage.getItem(e)!==null)return!0}catch{return!1}return!1}function S(){return w({displayMode:Q(),providerOrder:$(),providerVisibility:H(),updatedAt:W()})}function ee(e){if(typeof window>"u")return;const r=w(e);try{window.localStorage.setItem(A,JSON.stringify(r.providerOrder)),window.localStorage.setItem(E,JSON.stringify(r.providerVisibility)),window.localStorage.setItem(h,r.displayMode),r.updatedAt===void 0?window.localStorage.removeItem(O):window.localStorage.setItem(O,String(r.updatedAt))}catch(n){console.warn("[tokentracker] limits preferences localStorage write failed:",n)}}function re(e){const r=w(e);return{displayMode:r.displayMode,providerOrder:[...r.providerOrder],providerVisibility:{...r.providerVisibility},updatedAt:r.updatedAt??null}}function te(...e){let r;for(const s of e){const l=m(s);l!==void 0&&(r=r===void 0?l:Math.max(r,l))}const n=Date.now();return r!==void 0&&n<=r?r+1:n}function ie(e,r){return e.length===r.length&&e.every((n,s)=>n===r[s])}function ne(e,r){return y.every(n=>e[n]===r[n])}function R(e,r){return e.displayMode===r.displayMode&&ie(e.providerOrder,r.providerOrder)&&ne(e.providerVisibility,r.providerVisibility)}function oe(e,r){return R(e,r)&&m(e.updatedAt)===m(r.updatedAt)}function k(e,r){const n=m(e.updatedAt),s=m(r.updatedAt);return n!==void 0&&(s===void 0||n>s)}function ce(){const[e,r]=a.useState(S),n=a.useRef(e),s=a.useCallback((o,t={})=>{const i=w(o);return n.current=i,r(i),t.writeLocal&&ee(i),i},[]),l=a.useCallback(o=>{M()&&j(V,re(o))},[]),c=a.useCallback(o=>{const t=S(),i=k(t,n.current)?s(t):n.current,d=w(o(i));if(R(i,d))return;const f=te(t.updatedAt,i.updatedAt),p=s({...d,updatedAt:f},{writeLocal:!0});l(p)},[s,l]),P=a.useCallback(o=>{g.has(o)&&c(t=>({...t,displayMode:o}))},[c]),D=a.useCallback(o=>{if(!g.has(o))return;const t=S();if(t.updatedAt!==void 0){s(t);return}s({...t,displayMode:o,updatedAt:void 0},{writeLocal:!0})},[s]);a.useEffect(()=>{if(!M())return;const o=G(t=>{const i=t?.[V];if(i&&typeof i=="object"){const d=w(i);if(!Z()){s(d,{writeLocal:!0});return}const f=S();if(k(d,f))s(d,{writeLocal:!0});else{const p=s(f);oe(d,f)||l(p)}return}D(t?.[F])});return J(),o},[D,s,l]),a.useEffect(()=>{if(typeof window>"u")return;const o=t=>{(t.key===null||L.has(t.key))&&s(S())};return window.addEventListener("storage",o),()=>window.removeEventListener("storage",o)},[s]);const x=a.useCallback(o=>{y.includes(o)&&c(t=>({...t,providerVisibility:{...t.providerVisibility,[o]:!t.providerVisibility[o]}}))},[c]),C=a.useCallback(o=>{c(t=>{const i=t.providerOrder.indexOf(o);if(i<=0)return t;const d=[...t.providerOrder];return[d[i-1],d[i]]=[d[i],d[i-1]],{...t,providerOrder:d}})},[c]),U=a.useCallback(o=>{c(t=>{const i=t.providerOrder.indexOf(o);if(i<0||i>=t.providerOrder.length-1)return t;const d=[...t.providerOrder];return[d[i],d[i+1]]=[d[i+1],d[i]],{...t,providerOrder:d}})},[c]),T=a.useCallback((o,t)=>{o!==t&&c(i=>{const d=i.providerOrder.indexOf(o),f=i.providerOrder.indexOf(t);if(d<0||f<0)return i;const p=[...i.providerOrder],[z]=p.splice(d,1);return p.splice(f,0,z),{...i,providerOrder:p}})},[c]),Y=a.useCallback(()=>{c(()=>({displayMode:v.USED,providerOrder:I(),providerVisibility:b()}))},[c]),K=a.useMemo(()=>e.providerOrder.filter(o=>e.providerVisibility[o]!==!1),[e.providerOrder,e.providerVisibility]);return{order:e.providerOrder,visibility:e.providerVisibility,displayMode:e.displayMode,setDisplayMode:P,visibleOrdered:K,toggle:x,moveUp:C,moveDown:U,moveToward:T,reset:Y}}export{v as L,B as a,se as b,ae as l,ce as u};
|
package/dashboard/dist/assets/{use-native-settings-zPoh9XtP.js → use-native-settings-CquG9vh_.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-BTU7nBLK.js";import{C as y}from"./Card-B71GwGxO.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 w,aI as c}from"./main-
|
|
1
|
+
import{r as a,ab as w,aI as c}from"./main-BTU7nBLK.js";function v(i){const o=!!i?.initialState,[b,l]=a.useState(()=>o?i?.initialState?.data??null:null),[m,s]=a.useState(()=>o?i?.initialState?.error??null:null),[y,g]=a.useState(!o),u=!!i?.initialRefresh,f=!!i?.publishToPreloadCache,r=a.useCallback((e,t)=>{!f||!e||typeof e!="object"||w(e,{source:t})},[f]),S=a.useCallback(async()=>{try{const e=await c({refresh:!0}),t=e&&typeof e=="object"?e:null;l(t),s(null),r(t,"manual-refresh")}catch(e){s(e?.message||String(e))}},[r]),d=a.useCallback(async()=>{try{const e=await c(),t=e&&typeof e=="object"?e:null;l(t),s(null),r(t,"page-load")}catch(e){s(e?.message||String(e))}},[r]);return a.useEffect(()=>{if(typeof window>"u"||typeof document>"u")return;const e=15e3;let t=Date.now();const n=()=>{if(document.visibilityState!=="visible")return;const h=Date.now();h-t<e||(t=h,d())};return window.addEventListener("focus",n),document.addEventListener("visibilitychange",n),()=>{window.removeEventListener("focus",n),document.removeEventListener("visibilitychange",n)}},[d]),a.useEffect(()=>{if(o&&!u)return;let e=!1;return(async()=>{try{const t=await c();if(e)return;const n=t&&typeof t=="object"?t:null;l(n),s(null),r(n,"page-load")}catch(t){if(e)return;s(t?.message||String(t))}finally{e||g(!1)}})(),()=>{e=!0}},[o,u,r]),{data:b,error:m,isLoading:y,refresh:S}}export{v 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-BTU7nBLK.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-D3YoNdym.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-BTU7nBLK.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-BTU7nBLK.js"></script>
|
|
239
239
|
<link rel="stylesheet" crossorigin href="/assets/main-Br5SsufY.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-BTU7nBLK.js"></script>
|
|
79
79
|
<link rel="stylesheet" crossorigin href="/assets/main-Br5SsufY.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.49.
|
|
3
|
+
"version": "0.49.3",
|
|
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": {
|
package/src/commands/sync.js
CHANGED
|
@@ -1050,6 +1050,15 @@ async function cmdSync(argv) {
|
|
|
1050
1050
|
|
|
1051
1051
|
if (runtime.deviceToken && runtime.baseUrl) {
|
|
1052
1052
|
uploadAttempted = true;
|
|
1053
|
+
// Mirror the machine identity into the purge-surviving seed file so a
|
|
1054
|
+
// future `uninstall --purge` + reinstall recovers the same cloud device
|
|
1055
|
+
// instead of double-counting history under a new one (issue #176). This
|
|
1056
|
+
// is the migration path for installs that predate the seed file.
|
|
1057
|
+
try {
|
|
1058
|
+
require("../lib/machine-id").getOrCreateMachineId(queuePath);
|
|
1059
|
+
} catch {
|
|
1060
|
+
// best effort — upload below must not be blocked by identity mirroring
|
|
1061
|
+
}
|
|
1053
1062
|
try {
|
|
1054
1063
|
uploadResult = await drainQueueToCloud({
|
|
1055
1064
|
baseUrl: runtime.baseUrl,
|
|
@@ -88,8 +88,17 @@ async function cmdUninstall(argv) {
|
|
|
88
88
|
// Remove local app runtime (installed by init for notify-driven sync).
|
|
89
89
|
await fs.rm(path.join(trackerDir, "app"), { recursive: true, force: true }).catch(() => {});
|
|
90
90
|
|
|
91
|
+
// Deliberately NOT removed by --purge: the machine-identity seed lets a
|
|
92
|
+
// reinstall reuse the same cloud device row instead of double-counting the
|
|
93
|
+
// replayed history under a new device (issue #176).
|
|
94
|
+
const machineIdSeedPath = path.join(home, ".config", "tokentracker", "machine-id");
|
|
95
|
+
let machineIdSeedKept = false;
|
|
91
96
|
if (opts.purge) {
|
|
92
97
|
await fs.rm(path.join(home, ".tokentracker"), { recursive: true, force: true }).catch(() => {});
|
|
98
|
+
machineIdSeedKept = await fs.access(machineIdSeedPath).then(
|
|
99
|
+
() => true,
|
|
100
|
+
() => false,
|
|
101
|
+
);
|
|
93
102
|
}
|
|
94
103
|
|
|
95
104
|
process.stdout.write(
|
|
@@ -153,6 +162,9 @@ async function cmdUninstall(argv) {
|
|
|
153
162
|
? `- Grok Build hook removed: ${grokHookRemove.hookPath}`
|
|
154
163
|
: "- Grok Build hook: no change",
|
|
155
164
|
opts.purge ? `- Purged: ${path.join(home, ".tokentracker")}` : "- Purge: skipped (use --purge)",
|
|
165
|
+
...(machineIdSeedKept
|
|
166
|
+
? [`- Kept: ${machineIdSeedPath} (cloud device identity — a reinstall reuses the same device; delete it to fully reset)`]
|
|
167
|
+
: []),
|
|
156
168
|
"",
|
|
157
169
|
].join("\n"),
|
|
158
170
|
);
|
package/src/lib/local-api.js
CHANGED
|
@@ -11,6 +11,7 @@ const {
|
|
|
11
11
|
normalizeUsageScope,
|
|
12
12
|
} = require("./source-metadata");
|
|
13
13
|
const { accountSlugFor, fetchAccountUsage } = require("./cloud-account");
|
|
14
|
+
const { getOrCreateMachineId, computeStableMachineId } = require("./machine-id");
|
|
14
15
|
|
|
15
16
|
const SYNC_TIMEOUT_MS = 120_000;
|
|
16
17
|
const TRACKER_BIN = path.resolve(__dirname, "../../bin/tracker.js");
|
|
@@ -52,60 +53,6 @@ function resolveQueuePath() {
|
|
|
52
53
|
return path.join(home, ".tokentracker", "tracker", "queue.jsonl");
|
|
53
54
|
}
|
|
54
55
|
|
|
55
|
-
/**
|
|
56
|
-
* Stable per-MACHINE identifier, persisted in config.json next to the queue.
|
|
57
|
-
*
|
|
58
|
-
* The dashboard uses this (not a per-browser localStorage id) as the cloud
|
|
59
|
-
* device_name suffix, so every browser / WKWebView / cleared-cache session on
|
|
60
|
-
* the SAME machine resolves to ONE cloud device_id. That keeps cross-device
|
|
61
|
-
* SUM aggregation correct: one physical machine = one device (its cumulative
|
|
62
|
-
* queue upserts onto a single row), while genuinely distinct machines stay
|
|
63
|
-
* distinct devices that legitimately sum. Browser-keyed ids conflated one
|
|
64
|
-
* machine into several device_ids and inflated the account-view total.
|
|
65
|
-
*
|
|
66
|
-
* Returns null only when the id cannot be persisted (read-only home), in which
|
|
67
|
-
* case the caller falls back to its own client id (prior behavior).
|
|
68
|
-
*/
|
|
69
|
-
function getOrCreateMachineId(queuePath) {
|
|
70
|
-
const configPath = path.join(path.dirname(queuePath || resolveQueuePath()), "config.json");
|
|
71
|
-
let config = {};
|
|
72
|
-
let raw = null;
|
|
73
|
-
try {
|
|
74
|
-
raw = fs.readFileSync(configPath, "utf8");
|
|
75
|
-
} catch (e) {
|
|
76
|
-
// Missing file is fine (fresh install → create config below). Any other
|
|
77
|
-
// read error means an existing config we must NOT clobber.
|
|
78
|
-
if (e && e.code !== "ENOENT") return null;
|
|
79
|
-
}
|
|
80
|
-
if (raw != null) {
|
|
81
|
-
try {
|
|
82
|
-
config = JSON.parse(raw) || {};
|
|
83
|
-
} catch {
|
|
84
|
-
// Corrupt / partially-written config.json — refuse to overwrite it (that
|
|
85
|
-
// would destroy deviceToken and other keys). Caller falls back to the
|
|
86
|
-
// per-browser client id.
|
|
87
|
-
return null;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
const existing = config.machineId;
|
|
91
|
-
if (typeof existing === "string" && existing.length >= 8) return existing;
|
|
92
|
-
let generated;
|
|
93
|
-
try {
|
|
94
|
-
generated = crypto.randomUUID();
|
|
95
|
-
} catch {
|
|
96
|
-
generated = `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
|
|
97
|
-
}
|
|
98
|
-
try {
|
|
99
|
-
config.machineId = generated;
|
|
100
|
-
fs.mkdirSync(path.dirname(configPath), { recursive: true });
|
|
101
|
-
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
|
102
|
-
try { fs.chmodSync(configPath, 0o600); } catch { /* best effort */ }
|
|
103
|
-
} catch {
|
|
104
|
-
return null;
|
|
105
|
-
}
|
|
106
|
-
return generated;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
56
|
function readProjectQueueData(projectQueuePath) {
|
|
110
57
|
let raw;
|
|
111
58
|
try {
|
|
@@ -2142,4 +2089,5 @@ module.exports = {
|
|
|
2142
2089
|
// `tracker device-login` so the CLI device-flow anchors its cloud device
|
|
2143
2090
|
// to the machine, not the hostname.
|
|
2144
2091
|
getOrCreateMachineId,
|
|
2092
|
+
computeStableMachineId,
|
|
2145
2093
|
};
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const fs = require("node:fs");
|
|
4
|
+
const os = require("node:os");
|
|
5
|
+
const path = require("node:path");
|
|
6
|
+
const crypto = require("node:crypto");
|
|
7
|
+
const { execFileSync } = require("node:child_process");
|
|
8
|
+
|
|
9
|
+
function resolveQueuePath() {
|
|
10
|
+
return path.join(os.homedir(), ".tokentracker", "tracker", "queue.jsonl");
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Path of the purge-surviving identity seed file.
|
|
15
|
+
*
|
|
16
|
+
* `uninstall --purge` removes all of `~/.tokentracker` including config.json,
|
|
17
|
+
* which used to destroy the machineId: the reinstall minted a fresh id, the
|
|
18
|
+
* cloud created a brand-new device row, and the full history replay was
|
|
19
|
+
* double-counted next to the still-active old device (issue #176). The seed
|
|
20
|
+
* lives OUTSIDE the purged tree so a reinstall recovers the exact id the
|
|
21
|
+
* existing cloud device row is anchored to — including legacy random UUIDs
|
|
22
|
+
* that cannot be re-derived from hardware.
|
|
23
|
+
*
|
|
24
|
+
* Derived from the queue path's home when it follows the standard
|
|
25
|
+
* `<home>/.tokentracker/tracker/queue.jsonl` layout (keeps tests sandboxed in
|
|
26
|
+
* their temp homes), falling back to the real home directory otherwise.
|
|
27
|
+
*/
|
|
28
|
+
function defaultSeedPath(queuePath) {
|
|
29
|
+
const rootDir = path.dirname(path.dirname(queuePath));
|
|
30
|
+
const home = path.basename(rootDir) === ".tokentracker" ? path.dirname(rootDir) : os.homedir();
|
|
31
|
+
return path.join(home, ".config", "tokentracker", "machine-id");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function isValidMachineIdString(value) {
|
|
35
|
+
return typeof value === "string" && /^[A-Za-z0-9_-]{8,128}$/.test(value);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function readSeedFile(seedPath) {
|
|
39
|
+
try {
|
|
40
|
+
const v = fs.readFileSync(seedPath, "utf8").trim();
|
|
41
|
+
return isValidMachineIdString(v) ? v : null;
|
|
42
|
+
} catch {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Best-effort: keep the seed file mirroring the active machineId. */
|
|
48
|
+
function mirrorSeedFile(seedPath, machineId) {
|
|
49
|
+
if (!isValidMachineIdString(machineId)) return;
|
|
50
|
+
if (readSeedFile(seedPath) === machineId) return;
|
|
51
|
+
try {
|
|
52
|
+
fs.mkdirSync(path.dirname(seedPath), { recursive: true });
|
|
53
|
+
fs.writeFileSync(seedPath, `${machineId}\n`);
|
|
54
|
+
try { fs.chmodSync(seedPath, 0o600); } catch { /* best effort */ }
|
|
55
|
+
} catch {
|
|
56
|
+
// Read-only home etc. — identity still works, it just won't survive purge.
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* dbus machine-id format: 32 lowercase hex chars. Rejects placeholder values
|
|
62
|
+
* (all-zeros / a single repeated character) that cloned images sometimes ship.
|
|
63
|
+
*/
|
|
64
|
+
function isValidLinuxMachineId(value) {
|
|
65
|
+
const v = String(value || "").trim().toLowerCase();
|
|
66
|
+
if (!/^[0-9a-f]{32}$/.test(v)) return false;
|
|
67
|
+
if (/^(.)\1+$/.test(v)) return false;
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Containers routinely share the image's (or host's) /etc/machine-id, so it is
|
|
73
|
+
* NOT a per-machine identity there — two containers on one cloud account would
|
|
74
|
+
* collapse onto one device row and their hourly upserts would overwrite each
|
|
75
|
+
* other. Treat any container signal as "no stable id available".
|
|
76
|
+
*/
|
|
77
|
+
function isLinuxContainer({ env = process.env, pathExists = fs.existsSync, readFile = fs.readFileSync } = {}) {
|
|
78
|
+
try {
|
|
79
|
+
if (env.container) return true;
|
|
80
|
+
if (pathExists("/.dockerenv") || pathExists("/run/.containerenv")) return true;
|
|
81
|
+
const cgroup = String(readFile("/proc/1/cgroup", "utf8"));
|
|
82
|
+
if (/docker|containerd|kubepods|lxc/i.test(cgroup)) return true;
|
|
83
|
+
} catch {
|
|
84
|
+
// Detection failure → assume not a container; the dbus-format validity
|
|
85
|
+
// check still filters placeholder ids.
|
|
86
|
+
}
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Hardware-derived machine fingerprint, or null when no stable OS identifier
|
|
92
|
+
* is available (containers, cloned-image placeholder ids, stripped-down hosts).
|
|
93
|
+
*
|
|
94
|
+
* Used as the machineId for FRESH generations (no seed to recover) so the id
|
|
95
|
+
* survives `uninstall --purge` even when the seed file was deleted too: the
|
|
96
|
+
* post-reinstall login lands on the SAME cloud device row and the history
|
|
97
|
+
* replay upserts onto existing rows instead of duplicating them (issue #176).
|
|
98
|
+
*
|
|
99
|
+
* Privacy: the raw OS identifier never leaves the machine — it is hashed with
|
|
100
|
+
* a fixed namespace plus the OS username (so two OS users sharing one machine
|
|
101
|
+
* and one cloud account keep separate device rows and don't clobber each
|
|
102
|
+
* other's hourly upserts).
|
|
103
|
+
*/
|
|
104
|
+
function computeStableMachineId({
|
|
105
|
+
platform = process.platform,
|
|
106
|
+
execFile = execFileSync,
|
|
107
|
+
username,
|
|
108
|
+
env = process.env,
|
|
109
|
+
pathExists = fs.existsSync,
|
|
110
|
+
readFile = fs.readFileSync,
|
|
111
|
+
} = {}) {
|
|
112
|
+
let raw = null;
|
|
113
|
+
try {
|
|
114
|
+
if (platform === "darwin") {
|
|
115
|
+
const out = execFile("/usr/sbin/ioreg", ["-rd1", "-c", "IOPlatformExpertDevice"], {
|
|
116
|
+
encoding: "utf8",
|
|
117
|
+
timeout: 5000,
|
|
118
|
+
});
|
|
119
|
+
const m = String(out).match(/"IOPlatformUUID"\s*=\s*"([0-9A-Fa-f-]+)"/);
|
|
120
|
+
raw = m ? m[1] : null;
|
|
121
|
+
} else if (platform === "linux") {
|
|
122
|
+
if (isLinuxContainer({ env, pathExists, readFile })) return null;
|
|
123
|
+
for (const p of ["/etc/machine-id", "/var/lib/dbus/machine-id"]) {
|
|
124
|
+
try {
|
|
125
|
+
const v = String(readFile(p, "utf8")).trim();
|
|
126
|
+
if (isValidLinuxMachineId(v)) {
|
|
127
|
+
raw = v.toLowerCase();
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
} catch {
|
|
131
|
+
// try next candidate
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
} else if (platform === "win32") {
|
|
135
|
+
const out = execFile("reg", ["query", "HKLM\\SOFTWARE\\Microsoft\\Cryptography", "/v", "MachineGuid"], {
|
|
136
|
+
encoding: "utf8",
|
|
137
|
+
timeout: 5000,
|
|
138
|
+
});
|
|
139
|
+
const m = String(out).match(/MachineGuid\s+REG_SZ\s+(\S+)/);
|
|
140
|
+
raw = m ? m[1] : null;
|
|
141
|
+
}
|
|
142
|
+
} catch {
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
if (!raw) return null;
|
|
146
|
+
let user = username;
|
|
147
|
+
if (user == null) {
|
|
148
|
+
try {
|
|
149
|
+
user = os.userInfo().username;
|
|
150
|
+
} catch {
|
|
151
|
+
user = "";
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return crypto.createHash("sha256").update(`tokentracker-machine-v1:${raw}:${user}`).digest("hex");
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Stable per-MACHINE identifier, persisted in config.json next to the queue
|
|
159
|
+
* and mirrored to a purge-surviving seed file (see defaultSeedPath).
|
|
160
|
+
*
|
|
161
|
+
* The dashboard uses this (not a per-browser localStorage id) as the cloud
|
|
162
|
+
* device_name suffix, so every browser / WKWebView / cleared-cache session on
|
|
163
|
+
* the SAME machine resolves to ONE cloud device_id. That keeps cross-device
|
|
164
|
+
* SUM aggregation correct: one physical machine = one device (its cumulative
|
|
165
|
+
* queue upserts onto a single row), while genuinely distinct machines stay
|
|
166
|
+
* distinct devices that legitimately sum. Browser-keyed ids conflated one
|
|
167
|
+
* machine into several device_ids and inflated the account-view total.
|
|
168
|
+
*
|
|
169
|
+
* Fresh-generation priority: seed file (recovers the exact id the existing
|
|
170
|
+
* cloud device row is anchored to, including legacy random UUIDs) → hardware
|
|
171
|
+
* fingerprint → random UUID. Existing config.json ids are never migrated —
|
|
172
|
+
* their cloud device row is anchored to the old value.
|
|
173
|
+
*
|
|
174
|
+
* Returns null only when the id cannot be persisted (read-only home), in which
|
|
175
|
+
* case the caller falls back to its own client id (prior behavior).
|
|
176
|
+
*/
|
|
177
|
+
function getOrCreateMachineId(queuePath, { seedPath, stableMachineId } = {}) {
|
|
178
|
+
const resolvedQueuePath = queuePath || resolveQueuePath();
|
|
179
|
+
const configPath = path.join(path.dirname(resolvedQueuePath), "config.json");
|
|
180
|
+
const resolvedSeedPath = seedPath || defaultSeedPath(resolvedQueuePath);
|
|
181
|
+
let config = {};
|
|
182
|
+
let raw = null;
|
|
183
|
+
try {
|
|
184
|
+
raw = fs.readFileSync(configPath, "utf8");
|
|
185
|
+
} catch (e) {
|
|
186
|
+
// Missing file is fine (fresh install → create config below). Any other
|
|
187
|
+
// read error means an existing config we must NOT clobber.
|
|
188
|
+
if (e && e.code !== "ENOENT") return null;
|
|
189
|
+
}
|
|
190
|
+
if (raw != null) {
|
|
191
|
+
try {
|
|
192
|
+
config = JSON.parse(raw) || {};
|
|
193
|
+
} catch {
|
|
194
|
+
// Corrupt / partially-written config.json — refuse to overwrite it (that
|
|
195
|
+
// would destroy deviceToken and other keys). Caller falls back to the
|
|
196
|
+
// per-browser client id.
|
|
197
|
+
return null;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
const existing = config.machineId;
|
|
201
|
+
if (typeof existing === "string" && existing.length >= 8) {
|
|
202
|
+
// Migration for installs that predate the seed file: mirror the active id
|
|
203
|
+
// so it survives a future `uninstall --purge` (issue #176).
|
|
204
|
+
mirrorSeedFile(resolvedSeedPath, existing);
|
|
205
|
+
return existing;
|
|
206
|
+
}
|
|
207
|
+
// Fresh generation: recover the previous identity from the seed first, then
|
|
208
|
+
// fall back to the hardware fingerprint, then to a random UUID.
|
|
209
|
+
let generated = readSeedFile(resolvedSeedPath);
|
|
210
|
+
if (!generated) {
|
|
211
|
+
generated = stableMachineId === undefined ? computeStableMachineId() : stableMachineId;
|
|
212
|
+
}
|
|
213
|
+
if (!generated) {
|
|
214
|
+
try {
|
|
215
|
+
generated = crypto.randomUUID();
|
|
216
|
+
} catch {
|
|
217
|
+
generated = `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
try {
|
|
221
|
+
config.machineId = generated;
|
|
222
|
+
fs.mkdirSync(path.dirname(configPath), { recursive: true });
|
|
223
|
+
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
|
224
|
+
try { fs.chmodSync(configPath, 0o600); } catch { /* best effort */ }
|
|
225
|
+
} catch {
|
|
226
|
+
return null;
|
|
227
|
+
}
|
|
228
|
+
mirrorSeedFile(resolvedSeedPath, generated);
|
|
229
|
+
return generated;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
module.exports = {
|
|
233
|
+
getOrCreateMachineId,
|
|
234
|
+
computeStableMachineId,
|
|
235
|
+
isLinuxContainer,
|
|
236
|
+
isValidLinuxMachineId,
|
|
237
|
+
defaultSeedPath,
|
|
238
|
+
};
|