tokmon 0.28.4 → 0.28.6

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.
Files changed (33) hide show
  1. package/dist/{bootstrap-ink-WG4WG3R2.js → bootstrap-ink-PYYVQAYP.js} +25 -9
  2. package/dist/{chunk-FLANGRI6.js → chunk-23NB5Z6V.js} +64 -9
  3. package/dist/{chunk-P57DVFNH.js → chunk-6E2OJCIQ.js} +4 -4
  4. package/dist/{chunk-TN6V7XSL.js → chunk-BZFDTIFV.js} +32 -10
  5. package/dist/{chunk-CFKUZCMB.js → chunk-DESEB73E.js} +7 -6
  6. package/dist/{chunk-5B3XCEMC.js → chunk-MMAKKTCU.js} +2 -1
  7. package/dist/{chunk-HNWEJ6MS.js → chunk-O7ORALKA.js} +2 -0
  8. package/dist/{chunk-7CH6S7BR.js → chunk-RY24UHMK.js} +2 -2
  9. package/dist/{chunk-JZSZEHVD.js → chunk-UON47FYF.js} +12 -4
  10. package/dist/{cli-command-I4GRR3MF.js → cli-command-MW6EBLNA.js} +17 -8
  11. package/dist/cli.js +6 -6
  12. package/dist/{config-3DGZ47F7.js → config-JEDXAKPZ.js} +1 -1
  13. package/dist/{daemon-ZXV3V5CS.js → daemon-XB6ZORTE.js} +6 -6
  14. package/dist/daemon-handle-4WDYZBVL.js +11 -0
  15. package/dist/server-LNFK5MRX.js +12 -0
  16. package/dist/web/assets/{Area-stRnp8Km.js → Area-BqyvRn2x.js} +1 -1
  17. package/dist/web/assets/{analytics-moZZt9L_.js → analytics-B6QwqU9g.js} +2 -2
  18. package/dist/web/assets/{breakdown-km9w7myU.js → breakdown-DYnVKScr.js} +1 -1
  19. package/dist/web/assets/{button-DrX04Cc2.js → button-CnT5g-Jl.js} +1 -1
  20. package/dist/web/assets/{chart-D0CtuL2k.js → chart-Duz9D-nH.js} +1 -1
  21. package/dist/web/assets/{explore-B11uNJV1.js → explore-P2EolJrt.js} +1 -1
  22. package/dist/web/assets/{index-RDhXsCNG.js → index-9hkGpa7j.js} +24 -24
  23. package/dist/web/assets/{models-DYbZnY34.js → models-8B4FBxr7.js} +2 -2
  24. package/dist/web/assets/{overview-CruICbfJ.js → overview-DXA_HAsw.js} +2 -2
  25. package/dist/web/assets/{panel-xckM3_GC.js → panel-gxLFBb8y.js} +1 -1
  26. package/dist/web/assets/settings-sheet-CJJl-3Gw.js +1 -0
  27. package/dist/web/assets/{share-sheet-weIdd4DW.js → share-sheet-CXdyA1ga.js} +1 -1
  28. package/dist/web/assets/{timeline-BHgniliZ.js → timeline-CzC85trW.js} +1 -1
  29. package/dist/web/index.html +1 -1
  30. package/package.json +1 -1
  31. package/dist/daemon-handle-G4OGPFR3.js +0 -11
  32. package/dist/server-EPSH52DR.js +0 -12
  33. package/dist/web/assets/settings-sheet-G-BTSIF6.js +0 -1
@@ -1,2 +1,2 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./breakdown-km9w7myU.js","./index-RDhXsCNG.js","./index-ZmOS8p9O.css","./chart-D0CtuL2k.js","./panel-xckM3_GC.js"])))=>i.map(i=>d[i]);
2
- import{r as o,j as e,E as f,h as b,y as N,f as u,S as k,b as v,c as y,n as _,_ as d}from"./index-RDhXsCNG.js";import{P as C}from"./panel-xckM3_GC.js";const P=[{value:"cost",label:"cost"},{value:"tokens",label:"tokens"},{value:"calls",label:"calls"}],g="1.75rem minmax(6rem,12rem) minmax(3.5rem,1fr) 3rem 5.5rem 5rem auto auto auto";function S({derived:t,limit:a,periodLabel:i}){const[l,j]=o.useState(t.totals.cost>0?"cost":"tokens"),x=[...t.byModel].sort((s,n)=>n[l]-s[l]),m=a?x.slice(0,a):x,r=l==="tokens"?"tokenShare":l==="calls"?"callShare":"share",h=l==="tokens"?"block":"hidden md:block",p=l==="calls"?"block":"hidden lg:block";return e.jsx(C,{title:"model leaderboard",titleTag:i,captureName:"models",right:e.jsx(_,{options:P,value:l,onChange:j,size:"xs",ariaLabel:"sort models by",containerClassName:"flex items-center gap-0.5",btnClassName:"rounded px-1.5 py-0.5 text-[11px] transition"}),children:m.length===0?e.jsx(f,{children:"no models in period"}):e.jsxs("div",{className:"mt-6 flex flex-col overflow-x-auto",children:[e.jsxs("div",{className:"grid items-center gap-x-3 border-b border-line px-2 pb-1.5 font-display text-[10px] uppercase tracking-wide text-fg-faint",style:{gridTemplateColumns:g},children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{children:"share"}),e.jsx("span",{className:"text-right",children:"%"}),e.jsx("span",{className:"text-right text-cost/70",children:"cost"}),e.jsx("span",{className:"text-right",children:"trend"}),e.jsx("span",{className:"hidden text-right lg:block",children:"$/call"}),e.jsx("span",{className:`text-right ${h}`,children:"tokens"}),e.jsx("span",{className:`text-right ${p}`,children:"calls"})]}),m.map((s,n)=>e.jsxs("div",{className:"grid items-center gap-x-3 rounded border-b border-line-faint px-2 py-2 transition-colors last:border-0 hover:bg-bg-2/40",style:{gridTemplateColumns:g},children:[e.jsxs("span",{className:`tnum text-xs ${n===0?"font-medium text-accent":n<3?"text-fg-dim":"text-fg-faint"}`,children:["#",n+1]}),e.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"size-2 shrink-0 rounded-[2px]",style:{background:s.color}}),e.jsx("span",{className:"truncate text-fg",title:s.model,children:b(s.model)})]}),e.jsx("div",{className:"h-1.5 overflow-hidden rounded-full bg-bg-3",children:e.jsx("div",{className:"h-full rounded-full",style:{width:`${Math.min(100,s[r]*100)}%`,minWidth:s[r]>0?"2px":0,background:s.color}})}),e.jsx("span",{className:"tnum text-right text-[11px] text-fg-dim",children:N(s[r],s[r]>0&&s[r]<.01?1:0)}),e.jsx("span",{className:"tnum text-right text-xs text-cost",children:u(s.cost)}),e.jsx("span",{className:"overflow-hidden text-right",children:e.jsx(k,{data:s.trend.slice(-30),color:s.color,className:"text-sm"})}),e.jsx("span",{className:"tnum hidden text-right text-xs text-fg-dim lg:block",children:u(s.calls?s.cost/s.calls:0)}),e.jsx("span",{className:`tnum text-right text-xs text-fg-dim ${h}`,children:s.tokens>0?v(s.tokens):e.jsx("span",{className:"text-fg-faint",children:"—"})}),e.jsx("span",{className:`tnum text-right text-xs text-fg-faint ${p}`,children:y(s.calls)})]},s.model))]})})}const E=o.lazy(()=>d(()=>import("./breakdown-km9w7myU.js"),__vite__mapDeps([0,1,2,3,4]),import.meta.url).then(t=>({default:t.CostByModel}))),T=o.lazy(()=>d(()=>import("./breakdown-km9w7myU.js"),__vite__mapDeps([0,1,2,3,4]),import.meta.url).then(t=>({default:t.ProviderDonut}))),M=o.lazy(()=>d(()=>import("./breakdown-km9w7myU.js"),__vite__mapDeps([0,1,2,3,4]),import.meta.url).then(t=>({default:t.CacheByModel})));function c({children:t}){return e.jsx(o.Suspense,{fallback:e.jsx("div",{className:"min-h-64",role:"status","aria-label":"Loading chart"}),children:t})}function O({derived:t,scopeLabel:a}){const i=t.byProvider.length>1;return e.jsxs("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-2",children:[e.jsx("div",{className:"md:col-span-2",children:e.jsx(S,{derived:t,periodLabel:a})}),e.jsx("div",{className:i?void 0:"md:col-span-2",children:e.jsx(c,{children:e.jsx(E,{derived:t,metric:"tokens",limit:12,periodLabel:a})})}),i?e.jsx(c,{children:e.jsx(T,{derived:t,periodLabel:a})}):null,e.jsx("div",{className:"md:col-span-2",children:e.jsx(c,{children:e.jsx(M,{derived:t,periodLabel:a})})})]})}export{O as ModelsTab};
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./breakdown-DYnVKScr.js","./index-9hkGpa7j.js","./index-ZmOS8p9O.css","./chart-Duz9D-nH.js","./panel-gxLFBb8y.js"])))=>i.map(i=>d[i]);
2
+ import{r as o,j as e,E as f,h as b,y as N,f as u,S as k,b as v,c as y,n as _,_ as d}from"./index-9hkGpa7j.js";import{P as C}from"./panel-gxLFBb8y.js";const P=[{value:"cost",label:"cost"},{value:"tokens",label:"tokens"},{value:"calls",label:"calls"}],g="1.75rem minmax(6rem,12rem) minmax(3.5rem,1fr) 3rem 5.5rem 5rem auto auto auto";function S({derived:t,limit:a,periodLabel:i}){const[l,j]=o.useState(t.totals.cost>0?"cost":"tokens"),x=[...t.byModel].sort((s,n)=>n[l]-s[l]),m=a?x.slice(0,a):x,r=l==="tokens"?"tokenShare":l==="calls"?"callShare":"share",h=l==="tokens"?"block":"hidden md:block",p=l==="calls"?"block":"hidden lg:block";return e.jsx(C,{title:"model leaderboard",titleTag:i,captureName:"models",right:e.jsx(_,{options:P,value:l,onChange:j,size:"xs",ariaLabel:"sort models by",containerClassName:"flex items-center gap-0.5",btnClassName:"rounded px-1.5 py-0.5 text-[11px] transition"}),children:m.length===0?e.jsx(f,{children:"no models in period"}):e.jsxs("div",{className:"mt-6 flex flex-col overflow-x-auto",children:[e.jsxs("div",{className:"grid items-center gap-x-3 border-b border-line px-2 pb-1.5 font-display text-[10px] uppercase tracking-wide text-fg-faint",style:{gridTemplateColumns:g},children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{children:"share"}),e.jsx("span",{className:"text-right",children:"%"}),e.jsx("span",{className:"text-right text-cost/70",children:"cost"}),e.jsx("span",{className:"text-right",children:"trend"}),e.jsx("span",{className:"hidden text-right lg:block",children:"$/call"}),e.jsx("span",{className:`text-right ${h}`,children:"tokens"}),e.jsx("span",{className:`text-right ${p}`,children:"calls"})]}),m.map((s,n)=>e.jsxs("div",{className:"grid items-center gap-x-3 rounded border-b border-line-faint px-2 py-2 transition-colors last:border-0 hover:bg-bg-2/40",style:{gridTemplateColumns:g},children:[e.jsxs("span",{className:`tnum text-xs ${n===0?"font-medium text-accent":n<3?"text-fg-dim":"text-fg-faint"}`,children:["#",n+1]}),e.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"size-2 shrink-0 rounded-[2px]",style:{background:s.color}}),e.jsx("span",{className:"truncate text-fg",title:s.model,children:b(s.model)})]}),e.jsx("div",{className:"h-1.5 overflow-hidden rounded-full bg-bg-3",children:e.jsx("div",{className:"h-full rounded-full",style:{width:`${Math.min(100,s[r]*100)}%`,minWidth:s[r]>0?"2px":0,background:s.color}})}),e.jsx("span",{className:"tnum text-right text-[11px] text-fg-dim",children:N(s[r],s[r]>0&&s[r]<.01?1:0)}),e.jsx("span",{className:"tnum text-right text-xs text-cost",children:u(s.cost)}),e.jsx("span",{className:"overflow-hidden text-right",children:e.jsx(k,{data:s.trend.slice(-30),color:s.color,className:"text-sm"})}),e.jsx("span",{className:"tnum hidden text-right text-xs text-fg-dim lg:block",children:u(s.calls?s.cost/s.calls:0)}),e.jsx("span",{className:`tnum text-right text-xs text-fg-dim ${h}`,children:s.tokens>0?v(s.tokens):e.jsx("span",{className:"text-fg-faint",children:"—"})}),e.jsx("span",{className:`tnum text-right text-xs text-fg-faint ${p}`,children:y(s.calls)})]},s.model))]})})}const E=o.lazy(()=>d(()=>import("./breakdown-DYnVKScr.js"),__vite__mapDeps([0,1,2,3,4]),import.meta.url).then(t=>({default:t.CostByModel}))),T=o.lazy(()=>d(()=>import("./breakdown-DYnVKScr.js"),__vite__mapDeps([0,1,2,3,4]),import.meta.url).then(t=>({default:t.ProviderDonut}))),M=o.lazy(()=>d(()=>import("./breakdown-DYnVKScr.js"),__vite__mapDeps([0,1,2,3,4]),import.meta.url).then(t=>({default:t.CacheByModel})));function c({children:t}){return e.jsx(o.Suspense,{fallback:e.jsx("div",{className:"min-h-64",role:"status","aria-label":"Loading chart"}),children:t})}function O({derived:t,scopeLabel:a}){const i=t.byProvider.length>1;return e.jsxs("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-2",children:[e.jsx("div",{className:"md:col-span-2",children:e.jsx(S,{derived:t,periodLabel:a})}),e.jsx("div",{className:i?void 0:"md:col-span-2",children:e.jsx(c,{children:e.jsx(E,{derived:t,metric:"tokens",limit:12,periodLabel:a})})}),i?e.jsx(c,{children:e.jsx(T,{derived:t,periodLabel:a})}):null,e.jsx("div",{className:"md:col-span-2",children:e.jsx(c,{children:e.jsx(M,{derived:t,periodLabel:a})})})]})}export{O as ModelsTab};
@@ -1,2 +1,2 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./timeline-BHgniliZ.js","./index-RDhXsCNG.js","./index-ZmOS8p9O.css","./chart-D0CtuL2k.js","./panel-xckM3_GC.js","./Area-stRnp8Km.js"])))=>i.map(i=>d[i]);
2
- import{u as C,a as E,j as e,f as d,b as j,c as P,S as v,d as I,p as M,e as L,P as R,g as D,s as T,h as O,i as V,k as B,r as $,_ as F}from"./index-RDhXsCNG.js";import{P as H}from"./panel-xckM3_GC.js";const K={unknown:"text-fg",ok:"text-ok",warn:"text-warning",crit:"text-critical"},z={unknown:"var(--color-accent)",ok:"var(--color-ok)",warn:"var(--color-warning)",crit:"var(--color-critical)"};function Q({derived:s,periodLabel:n}){const r=C(),a=E(r.appearance.preset)?"var(--color-accent)":void 0,i=s.totals,m=s.timeline.map(l=>l.total).slice(-30),x=s.timeline.map(l=>l.tokens).slice(-30),t=s.cacheSavingsSeries.map(l=>l.value).slice(-30);return e.jsxs("div",{className:"grid grid-cols-[repeat(auto-fit,minmax(150px,1fr))] gap-3",children:[e.jsx(h,{label:`spend · ${n}`,value:d(i.cost),accent:"text-cost",spark:m,sparkColor:a??"var(--color-cost)"}),e.jsx(h,{label:"tokens",value:j(i.tokens),spark:x,sparkColor:a??"var(--color-fg-dim)"}),e.jsx(h,{label:"cache saved",value:d(i.cacheSavings),accent:"text-positive",spark:t,sparkColor:a??"var(--color-positive)"}),e.jsx(h,{label:"calls",value:P(i.calls)}),e.jsx(h,{label:"burn · today",value:`${d(s.burnRate)}/hr`,accent:"text-critical"})]})}function h({label:s,value:n,accent:r="text-fg-bright",spark:a,sparkColor:i}){return e.jsxs("div",{className:"rise flex min-w-0 flex-col rounded-md border border-line bg-bg-1/80 p-3.5 transition-colors hover:border-line-2",children:[e.jsx("div",{className:"font-display text-[10px] uppercase tracking-wide text-fg-faint",children:s}),e.jsx("div",{className:`tnum mt-1.5 text-xl sm:text-2xl ${r}`,children:n}),a&&a.length>1&&e.jsx("div",{className:"mt-auto overflow-hidden pt-2 text-right",children:e.jsx(v,{data:a,color:i??"currentColor",className:"text-sm opacity-70"})})]})}function U({accounts:s,nameOf:n,privacyMode:r,resetDisplay:a,tz:i}){const x=C().appearance.preset;return s.length===0?e.jsx(H,{title:"accounts",children:e.jsx("div",{className:"py-6 text-center text-xs text-fg-faint",children:"no accounts match the current filter"})}):e.jsx("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-[repeat(auto-fit,minmax(min(340px,100%),1fr))]",children:s.map((t,l)=>e.jsx(X,{account:t,index:l,preset:x,providerName:n(t.providerId),privacyMode:r,resetDisplay:a,tz:i},t.id))})}function X({account:s,index:n,preset:r,providerName:a,privacyMode:i,resetDisplay:m,tz:x}){var b,N,k,w,y,S;const t=s.dashboard,l=s.quotas??[],c=((b=s.billing)==null?void 0:b.modelSpend)??[],p=(N=s.billing)==null?void 0:N.activity,f=I(r,n,M(s.providerId)),g=L(s,a),_=g!==a;return e.jsxs("div",{className:"rise group relative overflow-hidden rounded-md border bg-bg-1/50 p-4 transition-colors",style:{animationDelay:`${n*40}ms`,borderColor:`color-mix(in oklab, ${f} 50%, var(--color-line))`},children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{style:{color:f},children:"●"}),e.jsx("span",{className:"font-display text-sm tracking-wide text-fg-bright",children:a}),_&&e.jsxs("span",{className:"flex min-w-0 items-center gap-1 text-xs text-fg-faint",children:[e.jsx("span",{"aria-hidden":!0,children:"·"}),s.identity?e.jsx("span",{className:"truncate text-fg-faint",title:s.identity.accessibleLabel,children:g}):e.jsx(R,{value:g,privacyMode:i,className:"truncate text-fg-faint"})]})]}),((k=s.billing)==null?void 0:k.plan)&&e.jsx("span",{className:"shrink-0 rounded border border-line px-1.5 py-0.5 text-[10px] text-fg-dim",children:s.billing.plan})]}),((w=s.headroom)==null?void 0:w.value)!=null&&(()=>{const o=D(s.headroom.value),A=K[T(s.headroom.value)];return e.jsxs("div",{className:"mt-3 flex items-baseline justify-between rounded border border-line-faint bg-bg-0/35 px-2.5 py-2",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-wide text-fg-faint",children:"usage"}),e.jsxs("span",{className:`tnum text-sm font-semibold ${A}`,children:[Math.round(o),"% used"]})]})})(),t&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mt-4 grid grid-cols-3 gap-2",children:[e.jsx(u,{label:"today",cost:t.today.cost,tokens:t.today.tokens}),e.jsx(u,{label:"week",cost:t.week.cost,tokens:t.week.tokens}),e.jsx(u,{label:"month",cost:t.month.cost,tokens:t.month.tokens})]}),e.jsxs("div",{className:"mt-3 flex items-center justify-between border-t border-line-faint pt-3 text-xs",children:[e.jsxs("span",{className:"text-fg-dim",children:["burn ",e.jsxs("span",{className:"tnum text-critical",children:[d(t.burnRate),"/hr"]})]}),e.jsxs("span",{className:"text-fg-dim",children:["saved ",e.jsx("span",{className:"tnum text-positive",children:d(t.month.cacheSavings)})]})]})]}),l.length>0&&e.jsx("div",{className:`flex flex-col gap-2 ${t?"mt-3 border-t border-line-faint pt-3":"mt-4"}`,children:l.slice(0,8).map(o=>e.jsx(G,{quota:o,resetDisplay:m,tz:x},o.key))}),c.length>0&&e.jsxs("div",{className:"mt-3 flex flex-col gap-1 border-t border-line-faint pt-3",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wide text-fg-faint",children:"spend by model"}),c.slice(0,4).map(o=>e.jsxs("div",{className:"flex items-center justify-between gap-2 text-[11px]",children:[e.jsx("span",{className:"min-w-0 truncate text-fg-dim",children:O(o.name)}),e.jsxs("span",{className:"tnum shrink-0 text-cost",children:[d(o.usd),e.jsxs("span",{className:"ml-1.5 text-fg-faint",children:[P(o.requests)," req"]})]})]},o.name))]}),t&&t.series.length>0&&e.jsxs("div",{className:"mt-3 flex items-center gap-2 border-t border-line-faint pt-3",children:[e.jsx(v,{data:t.series.slice(-14),color:f,className:"text-sm"}),e.jsxs("span",{className:"ml-auto text-[10px] text-fg-faint",children:[Math.min(14,t.series.length),"d"]})]}),!t&&p&&p.series.length>0&&e.jsxs("div",{className:"mt-3 flex items-center gap-2 border-t border-line-faint pt-3",children:[e.jsx(v,{data:p.series.slice(-14),color:f,className:"text-sm"}),e.jsx("span",{className:"ml-auto text-[10px] text-fg-faint",children:p.summary})]}),l.length===0&&((y=s.billing)==null?void 0:y.error)&&e.jsxs("div",{className:`flex items-start gap-1.5 text-xs text-critical ${t?"mt-3 border-t border-line-faint pt-3":"mt-4"}`,children:[e.jsx("span",{"aria-hidden":!0,children:"⚠"}),e.jsx("span",{children:V(s.billing.error,i)})]}),!t&&l.length===0&&!((S=s.billing)!=null&&S.error)&&c.length===0&&!(p&&p.series.length)&&e.jsx("div",{className:"py-6 text-center text-xs text-fg-faint",children:s.hasUsage?"no usage data":"billing-only · no live metrics"})]})}function u({label:s,cost:n,tokens:r}){const a=n>0||r===0;return e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] uppercase text-fg-faint",children:s}),e.jsx("div",{className:`tnum text-sm ${a?"text-cost":"text-fg-bright"}`,children:a?d(n):j(r)}),e.jsx("div",{className:"tnum text-[10px] text-fg-faint",children:a?j(r):d(n)})]})}function G({quota:s,resetDisplay:n,tz:r}){const a=s.usedPct==null?null:Math.min(1,Math.max(0,s.usedPct/100)),i=z[T(s.remainingPct)];return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between text-[11px]",children:[e.jsx("span",{className:"truncate text-fg-dim",children:s.label}),e.jsxs("span",{className:"tnum text-fg",children:[s.valueText,s.resetsAt&&e.jsxs("span",{className:"ml-1.5 text-fg-faint",children:["· ",B(new Date(s.resetsAt).toISOString(),n,Date.now(),r)]})]})]}),a!=null&&e.jsx("div",{className:"mt-1 h-1.5 w-full overflow-hidden rounded-full bg-bg-3",role:"progressbar","aria-label":`${s.label} used`,"aria-valuenow":Math.round(a*100),"aria-valuemin":0,"aria-valuemax":100,children:e.jsx("div",{className:"h-full rounded-full transition-[width] motion-reduce:transition-none",style:{width:`${a*100}%`,background:i}})})]})}const J=$.lazy(()=>F(()=>import("./timeline-BHgniliZ.js"),__vite__mapDeps([0,1,2,3,4,5]),import.meta.url).then(s=>({default:s.CostTimeline})));function Z({derived:s,periodLabel:n,scopeLabel:r,providers:a,privacyMode:i,resetDisplay:m,tz:x}){const t=new Map(a.map(c=>[c.id,c.name])),l=c=>t.get(c)??c;return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx(Q,{derived:s,periodLabel:n}),e.jsx($.Suspense,{fallback:e.jsx("div",{className:"h-[clamp(320px,42vh,560px)]",role:"status","aria-label":"Loading cost timeline"}),children:e.jsx(J,{derived:s,periodLabel:r,heightClass:"h-[clamp(320px,42vh,560px)]"})}),e.jsx(U,{accounts:s.cardAccounts,nameOf:l,privacyMode:i,resetDisplay:m,tz:x})]})}export{Z as OverviewTab};
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./timeline-CzC85trW.js","./index-9hkGpa7j.js","./index-ZmOS8p9O.css","./chart-Duz9D-nH.js","./panel-gxLFBb8y.js","./Area-BqyvRn2x.js"])))=>i.map(i=>d[i]);
2
+ import{u as C,a as E,j as e,f as d,b as j,c as P,S as v,d as I,p as M,e as L,P as R,g as D,s as T,h as O,i as V,k as B,r as $,_ as F}from"./index-9hkGpa7j.js";import{P as H}from"./panel-gxLFBb8y.js";const K={unknown:"text-fg",ok:"text-ok",warn:"text-warning",crit:"text-critical"},z={unknown:"var(--color-accent)",ok:"var(--color-ok)",warn:"var(--color-warning)",crit:"var(--color-critical)"};function Q({derived:s,periodLabel:n}){const r=C(),a=E(r.appearance.preset)?"var(--color-accent)":void 0,i=s.totals,m=s.timeline.map(l=>l.total).slice(-30),x=s.timeline.map(l=>l.tokens).slice(-30),t=s.cacheSavingsSeries.map(l=>l.value).slice(-30);return e.jsxs("div",{className:"grid grid-cols-[repeat(auto-fit,minmax(150px,1fr))] gap-3",children:[e.jsx(h,{label:`spend · ${n}`,value:d(i.cost),accent:"text-cost",spark:m,sparkColor:a??"var(--color-cost)"}),e.jsx(h,{label:"tokens",value:j(i.tokens),spark:x,sparkColor:a??"var(--color-fg-dim)"}),e.jsx(h,{label:"cache saved",value:d(i.cacheSavings),accent:"text-positive",spark:t,sparkColor:a??"var(--color-positive)"}),e.jsx(h,{label:"calls",value:P(i.calls)}),e.jsx(h,{label:"burn · today",value:`${d(s.burnRate)}/hr`,accent:"text-critical"})]})}function h({label:s,value:n,accent:r="text-fg-bright",spark:a,sparkColor:i}){return e.jsxs("div",{className:"rise flex min-w-0 flex-col rounded-md border border-line bg-bg-1/80 p-3.5 transition-colors hover:border-line-2",children:[e.jsx("div",{className:"font-display text-[10px] uppercase tracking-wide text-fg-faint",children:s}),e.jsx("div",{className:`tnum mt-1.5 text-xl sm:text-2xl ${r}`,children:n}),a&&a.length>1&&e.jsx("div",{className:"mt-auto overflow-hidden pt-2 text-right",children:e.jsx(v,{data:a,color:i??"currentColor",className:"text-sm opacity-70"})})]})}function U({accounts:s,nameOf:n,privacyMode:r,resetDisplay:a,tz:i}){const x=C().appearance.preset;return s.length===0?e.jsx(H,{title:"accounts",children:e.jsx("div",{className:"py-6 text-center text-xs text-fg-faint",children:"no accounts match the current filter"})}):e.jsx("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-[repeat(auto-fit,minmax(min(340px,100%),1fr))]",children:s.map((t,l)=>e.jsx(X,{account:t,index:l,preset:x,providerName:n(t.providerId),privacyMode:r,resetDisplay:a,tz:i},t.id))})}function X({account:s,index:n,preset:r,providerName:a,privacyMode:i,resetDisplay:m,tz:x}){var b,N,k,w,y,S;const t=s.dashboard,l=s.quotas??[],c=((b=s.billing)==null?void 0:b.modelSpend)??[],p=(N=s.billing)==null?void 0:N.activity,f=I(r,n,M(s.providerId)),g=L(s,a),_=g!==a;return e.jsxs("div",{className:"rise group relative overflow-hidden rounded-md border bg-bg-1/50 p-4 transition-colors",style:{animationDelay:`${n*40}ms`,borderColor:`color-mix(in oklab, ${f} 50%, var(--color-line))`},children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{style:{color:f},children:"●"}),e.jsx("span",{className:"font-display text-sm tracking-wide text-fg-bright",children:a}),_&&e.jsxs("span",{className:"flex min-w-0 items-center gap-1 text-xs text-fg-faint",children:[e.jsx("span",{"aria-hidden":!0,children:"·"}),s.identity?e.jsx("span",{className:"truncate text-fg-faint",title:s.identity.accessibleLabel,children:g}):e.jsx(R,{value:g,privacyMode:i,className:"truncate text-fg-faint"})]})]}),((k=s.billing)==null?void 0:k.plan)&&e.jsx("span",{className:"shrink-0 rounded border border-line px-1.5 py-0.5 text-[10px] text-fg-dim",children:s.billing.plan})]}),((w=s.headroom)==null?void 0:w.value)!=null&&(()=>{const o=D(s.headroom.value),A=K[T(s.headroom.value)];return e.jsxs("div",{className:"mt-3 flex items-baseline justify-between rounded border border-line-faint bg-bg-0/35 px-2.5 py-2",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-wide text-fg-faint",children:"usage"}),e.jsxs("span",{className:`tnum text-sm font-semibold ${A}`,children:[Math.round(o),"% used"]})]})})(),t&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mt-4 grid grid-cols-3 gap-2",children:[e.jsx(u,{label:"today",cost:t.today.cost,tokens:t.today.tokens}),e.jsx(u,{label:"week",cost:t.week.cost,tokens:t.week.tokens}),e.jsx(u,{label:"month",cost:t.month.cost,tokens:t.month.tokens})]}),e.jsxs("div",{className:"mt-3 flex items-center justify-between border-t border-line-faint pt-3 text-xs",children:[e.jsxs("span",{className:"text-fg-dim",children:["burn ",e.jsxs("span",{className:"tnum text-critical",children:[d(t.burnRate),"/hr"]})]}),e.jsxs("span",{className:"text-fg-dim",children:["saved ",e.jsx("span",{className:"tnum text-positive",children:d(t.month.cacheSavings)})]})]})]}),l.length>0&&e.jsx("div",{className:`flex flex-col gap-2 ${t?"mt-3 border-t border-line-faint pt-3":"mt-4"}`,children:l.slice(0,8).map(o=>e.jsx(G,{quota:o,resetDisplay:m,tz:x},o.key))}),c.length>0&&e.jsxs("div",{className:"mt-3 flex flex-col gap-1 border-t border-line-faint pt-3",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wide text-fg-faint",children:"spend by model"}),c.slice(0,4).map(o=>e.jsxs("div",{className:"flex items-center justify-between gap-2 text-[11px]",children:[e.jsx("span",{className:"min-w-0 truncate text-fg-dim",children:O(o.name)}),e.jsxs("span",{className:"tnum shrink-0 text-cost",children:[d(o.usd),e.jsxs("span",{className:"ml-1.5 text-fg-faint",children:[P(o.requests)," req"]})]})]},o.name))]}),t&&t.series.length>0&&e.jsxs("div",{className:"mt-3 flex items-center gap-2 border-t border-line-faint pt-3",children:[e.jsx(v,{data:t.series.slice(-14),color:f,className:"text-sm"}),e.jsxs("span",{className:"ml-auto text-[10px] text-fg-faint",children:[Math.min(14,t.series.length),"d"]})]}),!t&&p&&p.series.length>0&&e.jsxs("div",{className:"mt-3 flex items-center gap-2 border-t border-line-faint pt-3",children:[e.jsx(v,{data:p.series.slice(-14),color:f,className:"text-sm"}),e.jsx("span",{className:"ml-auto text-[10px] text-fg-faint",children:p.summary})]}),l.length===0&&((y=s.billing)==null?void 0:y.error)&&e.jsxs("div",{className:`flex items-start gap-1.5 text-xs text-critical ${t?"mt-3 border-t border-line-faint pt-3":"mt-4"}`,children:[e.jsx("span",{"aria-hidden":!0,children:"⚠"}),e.jsx("span",{children:V(s.billing.error,i)})]}),!t&&l.length===0&&!((S=s.billing)!=null&&S.error)&&c.length===0&&!(p&&p.series.length)&&e.jsx("div",{className:"py-6 text-center text-xs text-fg-faint",children:s.hasUsage?"no usage data":"billing-only · no live metrics"})]})}function u({label:s,cost:n,tokens:r}){const a=n>0||r===0;return e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] uppercase text-fg-faint",children:s}),e.jsx("div",{className:`tnum text-sm ${a?"text-cost":"text-fg-bright"}`,children:a?d(n):j(r)}),e.jsx("div",{className:"tnum text-[10px] text-fg-faint",children:a?j(r):d(n)})]})}function G({quota:s,resetDisplay:n,tz:r}){const a=s.usedPct==null?null:Math.min(1,Math.max(0,s.usedPct/100)),i=z[T(s.remainingPct)];return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between text-[11px]",children:[e.jsx("span",{className:"truncate text-fg-dim",children:s.label}),e.jsxs("span",{className:"tnum text-fg",children:[s.valueText,s.resetsAt&&e.jsxs("span",{className:"ml-1.5 text-fg-faint",children:["· ",B(new Date(s.resetsAt).toISOString(),n,Date.now(),r)]})]})]}),a!=null&&e.jsx("div",{className:"mt-1 h-1.5 w-full overflow-hidden rounded-full bg-bg-3",role:"progressbar","aria-label":`${s.label} used`,"aria-valuenow":Math.round(a*100),"aria-valuemin":0,"aria-valuemax":100,children:e.jsx("div",{className:"h-full rounded-full transition-[width] motion-reduce:transition-none",style:{width:`${a*100}%`,background:i}})})]})}const J=$.lazy(()=>F(()=>import("./timeline-CzC85trW.js"),__vite__mapDeps([0,1,2,3,4,5]),import.meta.url).then(s=>({default:s.CostTimeline})));function Z({derived:s,periodLabel:n,scopeLabel:r,providers:a,privacyMode:i,resetDisplay:m,tz:x}){const t=new Map(a.map(c=>[c.id,c.name])),l=c=>t.get(c)??c;return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx(Q,{derived:s,periodLabel:n}),e.jsx($.Suspense,{fallback:e.jsx("div",{className:"h-[clamp(320px,42vh,560px)]",role:"status","aria-label":"Loading cost timeline"}),children:e.jsx(J,{derived:s,periodLabel:r,heightClass:"h-[clamp(320px,42vh,560px)]"})}),e.jsx(U,{accounts:s.cardAccounts,nameOf:l,privacyMode:i,resetDisplay:m,tz:x})]})}export{Z as OverviewTab};
@@ -1 +1 @@
1
- import{r as c,j as e,J as p,F as d,N as x}from"./index-RDhXsCNG.js";function b({title:t,titleTag:r,right:s,captureName:a,children:o,className:i="",bodyClassName:l=""}){const n=c.useRef(null);return e.jsxs("section",{ref:n,className:`group relative rounded-md border border-line bg-bg-1/80 transition-colors hover:border-line-2 ${i}`,children:[t&&e.jsxs("div",{className:"pointer-events-none absolute -top-[7px] left-3 flex items-center gap-2 bg-bg-1 px-1.5",children:[e.jsx("span",{className:"font-display text-[11px] uppercase tracking-wider text-fg-dim",children:t}),r!=null&&e.jsx("span",{className:"text-[10px] normal-case tracking-normal text-fg-faint",children:r})]}),s&&e.jsx("div",{"data-chrome":!0,className:"absolute right-2 top-2 z-20 flex items-center gap-1.5 rounded bg-bg-1 px-0.5",children:s}),a&&e.jsx("div",{"data-chrome":!0,className:"absolute -top-[11px] right-3 z-20",children:e.jsx(u,{getNode:()=>n.current,name:a})}),e.jsx("div",{className:`p-4 ${l}`,children:o})]})}function u({getNode:t,name:r}){const s=p();return e.jsx("button",{type:"button",title:"Share this panel","aria-label":"Share this panel as an image",onClick:()=>{const a=t();a&&s({kind:"panel",node:a,captureName:r})},className:`rounded border border-transparent bg-bg-1 p-1 text-fg-faint opacity-0 transition hover:border-line hover:text-accent group-hover:opacity-100 focus-visible:opacity-100 ${d}`,children:e.jsx(x,{className:"size-3.5"})})}export{b as P};
1
+ import{r as c,j as e,J as p,F as d,N as x}from"./index-9hkGpa7j.js";function b({title:t,titleTag:r,right:s,captureName:a,children:o,className:i="",bodyClassName:l=""}){const n=c.useRef(null);return e.jsxs("section",{ref:n,className:`group relative rounded-md border border-line bg-bg-1/80 transition-colors hover:border-line-2 ${i}`,children:[t&&e.jsxs("div",{className:"pointer-events-none absolute -top-[7px] left-3 flex items-center gap-2 bg-bg-1 px-1.5",children:[e.jsx("span",{className:"font-display text-[11px] uppercase tracking-wider text-fg-dim",children:t}),r!=null&&e.jsx("span",{className:"text-[10px] normal-case tracking-normal text-fg-faint",children:r})]}),s&&e.jsx("div",{"data-chrome":!0,className:"absolute right-2 top-2 z-20 flex items-center gap-1.5 rounded bg-bg-1 px-0.5",children:s}),a&&e.jsx("div",{"data-chrome":!0,className:"absolute -top-[11px] right-3 z-20",children:e.jsx(u,{getNode:()=>n.current,name:a})}),e.jsx("div",{className:`p-4 ${l}`,children:o})]})}function u({getNode:t,name:r}){const s=p();return e.jsx("button",{type:"button",title:"Share this panel","aria-label":"Share this panel as an image",onClick:()=>{const a=t();a&&s({kind:"panel",node:a,captureName:r})},className:`rounded border border-transparent bg-bg-1 p-1 text-fg-faint opacity-0 transition hover:border-line hover:text-accent group-hover:opacity-100 focus-visible:opacity-100 ${d}`,children:e.jsx(x,{className:"size-3.5"})})}export{b as P};
@@ -0,0 +1 @@
1
+ import{O as te,Q as ge,U as W,V as xe,j as e,r as x,F as g,n as C,W as X,Y as ve,Z as je,$ as ye,a0 as O,a1 as B,a2 as ke,a3 as Ne,e as we,P as Ce,a4 as ae,a5 as ne,a6 as le,a7 as Se,a8 as Ie,a9 as ie,X as me,aa as De,ab as Ae,ac as $e,ad as Q,ae as oe,af as ze,ag as G,ah as ce,ai as de,aj as pe,ak as be,al as H,am as Pe,an as V,ao as Z,ap as Ee,aq as Re,u as Te,ar as Le,as as Me,at as Fe,au as Oe,av as Be}from"./index-9hkGpa7j.js";import{B as M,D as he}from"./button-CnT5g-Jl.js";function ue(t,n={}){return{mode:"add",editingId:null,providerId:n.providerId??te[0],name:n.name??"",homeDir:n.homeDir??"~",color:n.color??ge(t.accounts)}}function _e(t){return{mode:"edit",editingId:t.id,providerId:t.providerId,name:t.name,homeDir:t.homeDir,color:t.color||W[t.providerId].color}}function Ue(t,n){const a=t.mode==="edit"?n.filter(s=>s.id!==t.editingId):n;return t.mode==="edit"?t.editingId??"":xe(t.name.trim()||"account",a)}function Ge(t,n){const a=t.name.trim(),s=t.homeDir.trim()||"~";return a?t.mode==="add"?{ok:!0,account:{id:xe(a,n),providerId:t.providerId,name:a,homeDir:s,color:t.color},mode:"add",editingId:null}:{ok:!0,account:{id:t.editingId,providerId:t.providerId,name:a,homeDir:s,color:t.color},mode:"edit",editingId:t.editingId}:{ok:!1,error:"Name required"}}function E({title:t,right:n,children:a}){return e.jsxs("section",{className:"mb-6 last:mb-0",children:[e.jsxs("div",{className:"mb-2.5 flex items-center gap-2 border-b border-line pb-1.5",children:[e.jsx("h3",{className:"font-display text-[11px] uppercase tracking-wider text-fg-dim",children:t}),n&&e.jsx("div",{className:"ml-auto",children:n})]}),a]})}function k({label:t,hint:n,children:a}){return e.jsxs("div",{className:"flex items-center gap-3 py-1.5",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-sm text-fg",children:t}),n&&e.jsx("div",{className:"text-[11px] text-fg-faint",children:n})]}),e.jsx("div",{className:"shrink-0",children:a})]})}function q({label:t,hint:n,children:a}){return e.jsxs("div",{children:[e.jsx("div",{className:"mb-1.5 text-xs font-medium text-fg",children:t}),a,n&&e.jsx("div",{className:"mt-1 text-[11px] text-fg-faint",children:n})]})}function ee({label:t,value:n,min:a,unit:s,onChange:u}){const r=l=>u(Math.max(a,Math.round(l))),[b,h]=x.useState(null),v=()=>{if(b===null)return;const l=Number(b);r(Number.isFinite(l)&&b.trim()!==""?l:a),h(null)};return e.jsxs("div",{className:"flex items-center overflow-hidden rounded border border-line",children:[e.jsx("button",{type:"button","aria-label":"decrease",onClick:()=>r(n-1),className:`px-2 py-1 text-xs text-fg-dim transition hover:bg-bg-3 hover:text-fg ${g}`,children:"−"}),e.jsx("input",{type:"number",name:t.toLowerCase().replace(/\s+/g,"-"),autoComplete:"off",inputMode:"numeric",min:a,value:b??n,onChange:l=>{const o=l.target.value;h(o);const d=Number(o);o.trim()!==""&&Number.isFinite(d)&&d>=a&&r(d)},onBlur:v,"aria-label":`${t} (${s})`,className:`tnum w-12 border-x border-line bg-bg-2 px-1 py-1 text-center text-xs text-fg ${g} [appearance:textfield] [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none`}),e.jsx("span",{className:"px-1.5 text-[10px] text-fg-faint",children:s}),e.jsx("button",{type:"button","aria-label":"increase",onClick:()=>r(n+1),className:`px-2 py-1 text-xs text-fg-dim transition hover:bg-bg-3 hover:text-fg ${g}`,children:"+"})]})}function P({label:t,onClick:n,disabled:a,danger:s,children:u}){return e.jsx("button",{type:"button","aria-label":t,title:t,disabled:a,onClick:n,className:`rounded p-1 text-fg-faint transition disabled:opacity-30 ${g} ${s?"hover:bg-critical/15 hover:text-critical":"hover:bg-bg-3 hover:text-fg"} disabled:hover:bg-transparent disabled:hover:text-fg-faint`,children:u})}function He({draft:t,patch:n}){return e.jsxs(E,{title:"General",children:[e.jsx(k,{label:"Refresh interval",hint:"dashboard poll, seconds",children:e.jsx(ee,{label:"Refresh interval",value:t.interval,min:1,unit:"s",onChange:a=>n(s=>({...s,interval:a}))})}),e.jsx(k,{label:"Billing poll",hint:"billing refresh, minutes",children:e.jsx(ee,{label:"Billing poll",value:t.billingInterval,min:1,unit:"m",onChange:a=>n(s=>({...s,billingInterval:a}))})}),e.jsx(k,{label:"Clear screen",hint:"redraw on each refresh",children:e.jsx(C,{size:"xs",ariaLabel:"clear screen",options:[{value:"on",label:"on"},{value:"off",label:"off"}],value:t.clearScreen?"on":"off",onChange:a=>n(s=>({...s,clearScreen:a==="on"}))})}),e.jsx(k,{label:"Timezone",hint:"IANA name · empty = System",children:e.jsx(Ve,{value:t.timezone,onChange:a=>n(s=>({...s,timezone:a}))})}),e.jsx(k,{label:"Dashboard",hint:"grid shows all · single cycles",children:e.jsx(C,{size:"xs",ariaLabel:"dashboard layout",options:[{value:"grid",label:"grid"},{value:"single",label:"single"}],value:t.dashboardLayout,onChange:a=>n(s=>({...s,dashboardLayout:a}))})}),e.jsx(k,{label:"Default focus",hint:"on open",children:e.jsx(C,{size:"xs",ariaLabel:"default focus",options:[{value:"all",label:"all"},{value:"last",label:"last"}],value:t.defaultFocus,onChange:a=>n(s=>({...s,defaultFocus:a}))})}),e.jsx(k,{label:"ASCII mode",hint:"glyph fallback",children:e.jsx(C,{size:"xs",ariaLabel:"ascii mode",options:[{value:"auto",label:"auto"},{value:"on",label:"on"},{value:"off",label:"off"}],value:t.ascii,onChange:a=>n(s=>({...s,ascii:a}))})}),e.jsx(k,{label:"Network access",hint:"applies on daemon restart",children:e.jsx(C,{size:"xs",ariaLabel:"network access",options:[{value:"local",label:"local only"},{value:"network",label:"LAN"}],value:t.allowNetworkAccess?"network":"local",onChange:a=>n(s=>({...s,allowNetworkAccess:a==="network"}))})}),t.allowNetworkAccess&&e.jsxs(e.Fragment,{children:[e.jsx(k,{label:"Allowed hosts",hint:"exact DNS names · comma separated",children:e.jsx(qe,{value:t.allowedHosts,onChange:a=>n(s=>({...s,allowedHosts:a}))})}),e.jsx("p",{className:"rounded border border-critical/50 bg-critical/10 px-3 py-2 text-xs text-critical",role:"alert",children:"Unsafe: after the daemon restarts, usage data and settings will be reachable from your local network."})]}),e.jsx(k,{label:"Reset times",hint:"quota and peak changes",children:e.jsx(C,{size:"xs",ariaLabel:"reset time display",options:[{value:"relative",label:"remaining"},{value:"absolute",label:"date/time"}],value:t.resetDisplay,onChange:a=>n(s=>({...s,resetDisplay:a}))})})]})}function qe({value:t,onChange:n}){const[a,s]=x.useState(t.join(", ")),[u,r]=x.useState(!1),b=x.useId(),h=x.useRef(null),v=t.join(", ");x.useEffect(()=>{if(h.current===v){h.current=null;return}s(v),r(!1)},[v]);const l=o=>{const d=X(o);s(d);const f=d.split(",").map(p=>p.trim()).filter(Boolean).map(je),i=f.some(p=>p===null);if(r(i),!i){const p=[...new Set(f)];h.current=p.join(", "),n(p)}};return e.jsxs("div",{className:"flex flex-col items-end gap-0.5",children:[e.jsx("input",{type:"text",name:"allowed-hosts",value:a,placeholder:"tokmon.example.com","aria-label":"Allowed hosts","aria-describedby":u?b:void 0,autoComplete:"off",spellCheck:!1,"aria-invalid":u,onChange:o=>l(o.target.value),className:`w-64 rounded border bg-bg-2 px-2 py-1 text-xs text-fg ${g} ${u?"border-critical":"border-line"}`}),u&&e.jsx("span",{id:b,className:"text-[10px] text-critical",role:"alert",children:"Use exact hostnames without a scheme, port, path, or wildcard."})]})}function Ve({value:t,onChange:n}){const[a,s]=x.useState(t??""),[u,r]=x.useState(!1),b=x.useId();x.useEffect(()=>{s(t??""),r(!1)},[t]);const h=v=>{const l=X(v);s(l);const o=l.trim();if(!o){r(!1),n(null);return}ve(o)?(r(!1),n(o)):r(!0)};return e.jsxs("div",{className:"flex flex-col items-end gap-0.5",children:[e.jsx("input",{type:"text",name:"timezone",value:a,placeholder:"e.g. Europe/Bucharest…","aria-label":"Timezone","aria-describedby":u?b:void 0,autoComplete:"off",spellCheck:!1,"aria-invalid":u,onChange:v=>h(v.target.value),className:`w-44 rounded border bg-bg-2 px-2 py-1 text-xs text-fg ${g} ${u?"border-critical":"border-line"}`}),u&&e.jsx("span",{id:b,className:"text-[10px] text-critical",role:"alert",children:"Use an IANA zone such as Europe/Bucharest."})]})}function Ke({draft:t,patch:n}){const a=(s,u)=>n(r=>({...r,knownProviders:r.knownProviders.includes(s)?r.knownProviders:[...r.knownProviders,s],disabledProviders:u?r.disabledProviders.filter(b=>b!==s):Array.from(new Set([...r.disabledProviders,s]))}));return e.jsxs(E,{title:"Providers",right:e.jsxs("button",{type:"button",role:"switch","aria-checked":t.accountDetection.enabled,onClick:()=>n(s=>({...s,accountDetection:{...s.accountDetection,enabled:!s.accountDetection.enabled}})),className:`rounded border px-2 py-1 text-[10px] uppercase tracking-wide transition ${g} ${t.accountDetection.enabled?"border-accent/50 bg-accent/10 text-accent":"border-line text-fg-faint"}`,children:["Auto-detect ",t.accountDetection.enabled?"on":"off"]}),children:[e.jsx("p",{className:"mb-2.5 text-[11px] text-fg-faint",children:"Tracking controls all provider data. Auto-detect only finds accounts; manual accounts keep working when it is off."}),e.jsx("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-2",children:te.map(s=>{const u=!t.disabledProviders.includes(s),r=ye(t.accountDetection,s),b=W[s];return e.jsxs("div",{className:`flex items-center gap-2 rounded border px-2.5 py-2 text-left text-xs transition ${u?"border-line-2 bg-bg-2 text-fg":"border-line bg-bg-1 text-fg-faint hover:border-line-2"}`,children:[e.jsx("span",{className:"size-2 shrink-0 rounded-full",style:{background:O(b.color)},"aria-hidden":!0}),e.jsx("span",{className:`font-medium ${u?"text-fg":"text-fg-faint"}`,children:b.name}),e.jsxs("span",{className:"ml-auto flex items-center gap-1",children:[e.jsxs("button",{type:"button",role:"switch","aria-checked":u,"aria-label":`${u?"Stop":"Start"} tracking ${b.name}`,onClick:()=>a(s,!u),className:`inline-flex items-center gap-1 rounded border px-1.5 py-1 text-[10px] ${g} ${u?"border-line-2 text-fg":"border-line text-fg-faint"}`,children:[u&&e.jsx(B,{className:"size-3"})," Track"]}),e.jsx("button",{type:"button",role:"switch","aria-checked":r,disabled:!t.accountDetection.enabled,"aria-label":`${r?"Disable":"Enable"} ${b.name} account discovery`,onClick:()=>n(h=>({...h,accountDetection:ke(h.accountDetection,s,!r)})),className:`rounded border px-1.5 py-1 text-[10px] disabled:opacity-40 ${g} ${r?"border-accent/50 text-accent":"border-line text-fg-faint"}`,children:"Auto"})]})]},s)})})]})}function We(t,n){return n?n.accounts.find(a=>a.id===t.id)??null:null}function Xe({draft:t,patch:n,snapshot:a,onEdit:s,onConfigure:u,onAdd:r}){const b=Ne(t,void 0,(a==null?void 0:a.accounts)??void 0),[h,v]=x.useState(null),l=c=>n(f=>({...f,activeAccountId:c})),o=c=>{if(h!==c){v(c);return}n(f=>({...f,accounts:f.accounts.filter(i=>i.id!==c),activeAccountId:f.activeAccountId===c?null:f.activeAccountId})),v(null)},d=(c,f)=>n(i=>{const p=[...i.accounts],w=c+f;return w<0||w>=p.length?i:([p[c],p[w]]=[p[w],p[c]],{...i,accounts:p})});return e.jsx(E,{title:"Accounts",right:e.jsxs(M,{variant:"primary",size:"xs",onClick:r,children:[e.jsx(De,{className:"size-3"})," Add account"]}),children:b.length===0?e.jsx("p",{className:"rounded border border-line bg-bg-2/50 px-3 py-3 text-xs text-fg-faint",children:"None configured — enabled providers track automatically."}):e.jsx("ul",{className:"flex flex-col gap-1.5",role:"radiogroup","aria-label":"Active account",children:b.map(c=>{var D;const f=W[c.providerId],i=We(c,a),p=i?we(i,f.name):c.name||f.name,w=(i==null?void 0:i.plan)??((D=i==null?void 0:i.billing)==null?void 0:D.plan)??null,A=O(c.color||f.color),S=c.id===t.activeAccountId,I=c.source==="configured",N=c.source==="ignored";return e.jsxs("li",{className:`flex items-center gap-2.5 rounded border border-line px-2.5 py-2 ${N?"bg-bg-1 opacity-75":"bg-bg-2/60"}`,children:[e.jsx("button",{type:"button",role:"radio","aria-checked":S,disabled:N,"aria-label":`Set ${c.name} active`,title:S?"Active account (click to clear)":"Set active",onClick:()=>l(S?null:c.id),className:`relative inline-flex size-4 shrink-0 items-center justify-center rounded-full border transition ${g}`,style:{borderColor:A},children:S&&e.jsx("span",{className:"size-2 rounded-full",style:{background:A}})}),e.jsx("span",{className:"size-2.5 shrink-0 rounded-full",style:{background:A},"aria-hidden":!0}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ce,{value:p,privacyMode:t.privacyMode,className:"truncate text-sm text-fg-bright"}),e.jsx("span",{className:"shrink-0 rounded bg-bg-3 px-1.5 py-0.5 text-[10px] uppercase tracking-wide text-fg-dim",children:f.name}),w&&e.jsx("span",{className:"shrink-0 rounded border border-line px-1.5 py-0.5 text-[10px] text-fg-dim",children:w}),e.jsx("span",{className:"shrink-0 rounded border border-line px-1.5 py-0.5 text-[10px] uppercase tracking-wide text-fg-faint",children:c.source==="auto"?"detected":N?"ignored":"manual"})]}),e.jsx("div",{className:"truncate font-mono text-[11px] text-fg-faint",children:t.privacyMode?"path hidden":c.homeDir})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-0.5",children:[h===c.id?e.jsx("span",{className:"mr-1 text-[10px] text-critical",role:"alert",children:"Delete?"}):null,I&&c.explicitIndex!==void 0?e.jsxs(e.Fragment,{children:[e.jsx(P,{label:"Move up",disabled:c.explicitIndex===0,onClick:()=>d(c.explicitIndex,-1),children:e.jsx(ae,{className:"size-3.5"})}),e.jsx(P,{label:"Move down",disabled:c.explicitIndex===t.accounts.length-1,onClick:()=>d(c.explicitIndex,1),children:e.jsx(ne,{className:"size-3.5"})}),e.jsx(P,{label:"Edit account",onClick:()=>s(c),children:e.jsx(le,{className:"size-3.5"})}),e.jsx(P,{label:h===c.id?"Confirm delete account":"Delete account",danger:!0,onClick:()=>o(c.id),children:e.jsx(Se,{className:"size-3.5"})})]}):N?e.jsx(P,{label:"Turn detected account on",onClick:()=>c.excludedRef&&n(j=>({...j,accountDetection:ie(j.accountDetection,c.excludedRef,!1)})),children:e.jsx(Ie,{className:"size-3.5"})}):e.jsxs(e.Fragment,{children:[e.jsx(P,{label:"Configure as manual account",onClick:()=>u(c),children:e.jsx(le,{className:"size-3.5"})}),e.jsx(P,{label:"Turn detected account off",onClick:()=>n(j=>({...j,activeAccountId:j.activeAccountId===c.id?null:j.activeAccountId,accountDetection:ie(j.accountDetection,{providerId:c.providerId,homeDir:c.homeDir},!0)})),children:e.jsx(me,{className:"size-3.5"})})]})]})]},`${c.source}:${c.id}`)})})})}function Ye(t){const n=(t??"").trim();return n.length>0?n:"~"}function J(t){const n=(t??"").trim();return n.length>0?n:"~"}function Qe(t){const n=[];t.parent!==null&&n.push({kind:"parent",key:"..",label:"..",path:t.parent});for(const a of[...t.entries].filter(s=>s.dir).sort((s,u)=>s.name.localeCompare(u.name)))n.push({kind:"entry",key:a.path,label:a.name,path:a.path});return n}function Ze({editor:t,accounts:n,onChange:a,onCancel:s,onSubmit:u}){const r=x.useRef(null),[b,h]=x.useState(null),v=O(t.color),l=Ue(t,n),o=()=>{const d=Ge(t,n);if(!d.ok){h(d.error);return}u(d.account,d.mode,d.editingId)};return e.jsxs(he,{onClose:s,labelledBy:"account-editor-title",initialFocusRef:r,showClose:!1,className:"my-8 w-full max-w-[460px] border-l-2",panelStyle:{borderLeftColor:v},children:[e.jsxs("div",{className:"flex items-center gap-2 border-b border-line px-4 py-3",children:[e.jsx("span",{className:"size-2.5 rounded-full",style:{background:v},"aria-hidden":!0}),e.jsx("h2",{id:"account-editor-title",className:"font-display text-xs uppercase tracking-wider text-fg-bright",children:t.mode==="add"?"New account":"Edit account"})]}),e.jsxs("div",{className:"flex flex-col gap-4 px-4 py-4",children:[e.jsx(q,{label:"Provider",hint:"which tool this account tracks",children:e.jsx("div",{className:"flex flex-wrap gap-1.5",children:te.map(d=>{const c=d===t.providerId,f=W[d];return e.jsxs("button",{type:"button",onClick:()=>a({...t,providerId:d}),"aria-pressed":c,className:`flex items-center gap-1.5 rounded border px-2 py-1 text-xs transition ${g} ${c?"border-line-2 bg-bg-3 text-fg-bright":"border-line text-fg-dim hover:text-fg"}`,children:[e.jsx("span",{className:"size-2 rounded-full",style:{background:O(f.color)},"aria-hidden":!0}),f.name]},d)})})}),e.jsx(q,{label:"Name",hint:"display name for this account",children:e.jsx("input",{ref:r,type:"text",name:"account-name",value:t.name,placeholder:"e.g. Work…","aria-label":"Account name",autoComplete:"off",spellCheck:!1,onChange:d=>{h(null),a({...t,name:X(d.target.value)})},onKeyDown:d=>{d.key==="Enter"&&o()},className:`w-full rounded border border-line bg-bg-2 px-2.5 py-1.5 text-sm text-fg ${g}`})}),e.jsx(q,{label:"Home directory",hint:"path containing the tool's data dir · ~ for default",children:e.jsx(Je,{value:t.homeDir,onChange:d=>a({...t,homeDir:d}),onEnter:o})}),e.jsx(q,{label:"Accent color",hint:"shows on dashboard, account strip, borders",children:e.jsx("div",{className:"flex flex-wrap gap-1.5",children:Ae.map(d=>{const c=d===t.color;return e.jsx("button",{type:"button","aria-label":d,"aria-pressed":c,title:d,onClick:()=>a({...t,color:d}),className:`size-6 rounded-full border-2 transition ${g} ${c?"scale-110":"border-transparent hover:scale-105"}`,style:{background:O(d),borderColor:c?"var(--color-fg-bright)":"transparent"}},d)})})}),e.jsxs("div",{className:"flex items-center gap-2 rounded border border-line bg-bg-2/50 px-2.5 py-1.5 text-xs",children:[e.jsx("span",{className:"text-fg-faint",children:"id"}),e.jsx("span",{className:"font-mono text-fg",style:{color:v},children:l||"account"}),e.jsx("span",{className:"ml-auto text-[10px] text-fg-faint",children:t.mode==="add"?"auto-generated from name":"fixed"})]}),b&&e.jsxs("p",{className:"text-xs text-critical",role:"alert",children:[b,". Check the highlighted account fields and try again."]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 border-t border-line px-4 py-3",children:[e.jsx(M,{variant:"secondary",onClick:s,children:"cancel"}),e.jsxs(M,{variant:"primary",onClick:o,children:[e.jsx(B,{className:"size-3.5"})," ",t.mode==="add"?"Add account":"Save account"]})]})]})}function Je({value:t,onChange:n,onEnter:a}){const[s,u]=x.useState(!1),[r,b]=x.useState(null),[h,v]=x.useState("~"),[l,o]=x.useState(!1),[d,c]=x.useState(null),f=x.useRef(0),i=x.useCallback(async j=>{const $=++f.current,T=Ye(j);v(T),o(!0),c(null);try{const z=await $e(T);if($!==f.current)return;b(z)}catch(z){if($!==f.current)return;b(null),c(z instanceof Error?z.message:"cannot read folder")}finally{$===f.current&&o(!1)}},[]);x.useEffect(()=>()=>{f.current++},[]);const p=()=>{u(!0),i(t)},w=()=>{f.current++,u(!1),o(!1),c(null)},A=j=>{l||i(j)},S=()=>{!r||l||(n(J(r.path)),w())},I=r?Qe(r):[],N=I.filter(j=>j.kind==="entry"),D=J((r==null?void 0:r.path)??h);return e.jsxs("div",{className:"relative",children:[e.jsxs("div",{className:"flex overflow-hidden rounded border border-line bg-bg-2",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 px-2.5",children:[e.jsx(Q,{className:"size-4 shrink-0 text-fg-faint"}),e.jsx("input",{type:"text",name:"account-home-directory",value:t,placeholder:"e.g. ~/work…","aria-label":"Account home directory",autoComplete:"off",spellCheck:!1,onChange:j=>{w(),n(X(j.target.value))},onKeyDown:j=>{j.key==="Enter"&&a()},className:`min-w-0 flex-1 bg-transparent py-1.5 font-mono text-sm text-fg ${g}`})]}),e.jsxs("button",{type:"button",onClick:p,disabled:l,className:`flex shrink-0 items-center gap-1 border-l border-line bg-bg-1 px-2.5 py-1.5 text-xs text-fg-dim transition hover:bg-bg-3 hover:text-fg disabled:opacity-50 ${g}`,children:[e.jsx(ne,{className:"size-3.5"})," Browse"]})]}),s&&e.jsxs("div",{className:"mt-2 overflow-hidden rounded border border-line-2 bg-bg-1 shadow-[0_18px_60px_rgba(0,0,0,0.35)]",children:[e.jsxs("div",{className:"flex items-center gap-2 border-b border-line bg-bg-2 px-2.5 py-2",children:[e.jsx(Q,{className:"size-4 shrink-0 text-accent"}),e.jsx("div",{className:"min-w-0 flex-1 truncate font-mono text-xs text-fg-bright",title:D,children:D}),l&&e.jsx("span",{className:"shrink-0 text-[10px] uppercase tracking-wide text-fg-faint",children:"loading"}),e.jsx("button",{type:"button",onClick:w,"aria-label":"Close folder picker",className:`rounded p-1 text-fg-faint transition hover:text-fg ${g}`,children:e.jsx(me,{className:"size-3.5"})})]}),d?e.jsxs("div",{className:"px-2.5 py-3",children:[e.jsxs("div",{className:"text-xs text-critical",children:["can't read ",J(h)]}),e.jsx("button",{type:"button",onClick:()=>{l||i(h)},disabled:l,className:`mt-2 rounded border border-line bg-bg-2 px-2 py-1 text-[11px] text-fg-dim transition hover:border-line-2 hover:text-fg disabled:opacity-50 ${g}`,children:"retry"})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"max-h-56 overflow-y-auto py-1",children:[I.map(j=>e.jsxs("button",{type:"button",onClick:()=>A(j.path),disabled:l,className:`flex w-full items-center gap-2 px-2.5 py-1.5 text-left text-xs transition hover:bg-bg-3 hover:text-fg disabled:opacity-50 ${g} ${j.kind==="parent"?"text-fg-dim":"text-fg"}`,children:[j.kind==="parent"?e.jsx(ae,{className:"size-3.5 shrink-0"}):e.jsx(Q,{className:"size-3.5 shrink-0 text-fg-faint"}),e.jsx("span",{className:"min-w-0 truncate font-mono",children:j.label})]},j.key)),!l&&N.length===0&&e.jsx("div",{className:"px-2.5 py-3 text-xs text-fg-faint",children:"no subdirectories"}),l&&!r&&e.jsx("div",{className:"px-2.5 py-3 text-xs text-fg-faint",role:"status","aria-live":"polite",children:"loading folders…"})]}),e.jsx("div",{className:"flex items-center justify-end gap-2 border-t border-line px-2.5 py-2",children:e.jsxs(M,{variant:"primary",onClick:S,disabled:!r||l,children:[e.jsx(B,{className:"size-3.5"})," Select this folder"]})})]})]})]})}function et({draft:t,patch:n,snapshot:a}){const s=(a==null?void 0:a.providers)??[],u=new Set(s.map(l=>l.id)),r=oe(t.tray.pinnedProviders,u,G),b=oe(t.desktop.expandedProviders,u),h=l=>n(o=>({...o,tray:{...o.tray,pinnedProviders:l,pins:[],pinnedAccount:null}})),v=l=>n(o=>({...o,desktop:{...o.desktop,expandedProviders:ce(o.desktop.expandedProviders,l,u)}}));return e.jsxs(e.Fragment,{children:[e.jsxs(E,{title:"App",children:[e.jsx(k,{label:"Privacy mode",hint:`global identity masking · ${t.privacyToggleKey.toUpperCase()} shortcut`,children:e.jsx(C,{size:"xs",ariaLabel:"privacy mode",options:[{value:"on",label:"on"},{value:"off",label:"off"}],value:t.privacyMode?"on":"off",onChange:l=>n(o=>({...o,privacyMode:l==="on"}))})}),e.jsx(k,{label:"Provider summary",hint:"smart pools account capacity · tightest shows the highest single usage",children:e.jsx(C,{size:"xs",ariaLabel:"menu bar value",options:[{value:"smartHeadroom",label:"smart"},{value:"tightestRemaining",label:"tightest"}],value:t.tray.displayMetric,onChange:l=>n(o=>({...o,tray:{...o.tray,displayMetric:l}}))})}),e.jsx(k,{label:"Menu bar value",hint:"show usage percentage or today's local token total",children:e.jsx(C,{size:"xs",ariaLabel:"menu bar value",options:[{value:"usage",label:"usage"},{value:"todayTokens",label:"tokens today"}],value:t.tray.menuBarValue,onChange:l=>n(o=>({...o,tray:{...o.tray,menuBarValue:l}}))})}),e.jsx(k,{label:"Show value in menu bar",hint:"hide the number and keep the provider mark",children:e.jsx(C,{size:"xs",ariaLabel:"show menu bar value",options:[{value:"on",label:"on"},{value:"off",label:"off"}],value:t.tray.showMenuBarText?"on":"off",onChange:l=>n(o=>({...o,tray:{...o.tray,showMenuBarText:l==="on"}}))})}),e.jsx(k,{label:"Active window",hint:"recent activity used by smart headroom",children:e.jsx(ee,{label:"Active window",value:t.tray.activeTimeoutMin,min:1,unit:"min",onChange:l=>n(o=>({...o,tray:{...o.tray,activeTimeoutMin:Math.min(1440,l)}}))})}),e.jsx(k,{label:"Graph range",hint:"trailing spend activity in the desktop popover",children:e.jsx(C,{size:"xs",ariaLabel:"desktop graph range",options:ze.map(l=>({value:String(l),label:`${l}d`})),value:String(t.desktop.graphRangeDays),onChange:l=>n(o=>({...o,desktop:{...o.desktop,graphRangeDays:Number(l)}}))})}),e.jsx(k,{label:"Launch at login",hint:"start the desktop menu bar app automatically",children:e.jsx(C,{size:"xs",ariaLabel:"launch desktop app at login",options:[{value:"on",label:"on"},{value:"off",label:"off"}],value:t.tray.launchAtLogin?"on":"off",onChange:l=>n(o=>({...o,tray:{...o.tray,launchAtLogin:l==="on"}}))})})]}),e.jsxs(E,{title:"Menu bar providers",right:e.jsxs("span",{className:"text-[10px] text-fg-faint",children:[r.length,"/",G," pinned"]}),children:[s.length===0?e.jsx("p",{className:"rounded border border-line bg-bg-2/50 px-3 py-3 text-xs text-fg-faint",children:"Waiting for provider data…"}):e.jsx("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-2",children:s.map(l=>{const o=r.indexOf(l.id),d=o>=0,c=!d&&r.length>=G;return e.jsxs("div",{className:`flex items-center gap-2 rounded border px-2.5 py-2 ${d?"border-line-2 bg-bg-2":"border-line bg-bg-1"}`,children:[e.jsx("button",{type:"button",role:"checkbox","aria-checked":d,disabled:c,"aria-label":`${d?"Unpin":"Pin"} ${l.name}`,onClick:()=>h(ce(r,l.id,u,G)),className:`inline-flex size-5 shrink-0 items-center justify-center rounded border text-[10px] transition disabled:cursor-not-allowed disabled:opacity-35 ${g}`,style:{borderColor:d?l.color:"var(--color-line-2)",color:l.color},children:d?o+1:e.jsx(B,{className:"size-3 opacity-0"})}),e.jsx("span",{className:"size-2 shrink-0 rounded-full",style:{background:l.color},"aria-hidden":!0}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-xs text-fg",children:l.name}),d&&e.jsxs("span",{className:"flex shrink-0 items-center",children:[e.jsx(P,{label:`Move ${l.name} left`,disabled:o===0,onClick:()=>h(de(r,l.id,-1)),children:e.jsx(ae,{className:"size-3.5 -rotate-90"})}),e.jsx(P,{label:`Move ${l.name} right`,disabled:o===r.length-1,onClick:()=>h(de(r,l.id,1)),children:e.jsx(ne,{className:"size-3.5 -rotate-90"})})]})]},l.id)})}),e.jsx("p",{className:"mt-2 text-[11px] text-fg-faint",children:"The numbered order matches the menu bar from left to right."})]}),e.jsxs(E,{title:"Popover defaults",children:[e.jsx("p",{className:"mb-2 text-[11px] text-fg-faint",children:"Choose which provider cards start expanded. You can still open or close any card in the app."}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:s.map(l=>{const o=b.includes(l.id);return e.jsxs("button",{type:"button","aria-pressed":o,onClick:()=>v(l.id),className:`flex items-center gap-1.5 rounded border px-2 py-1 text-xs transition ${g} ${o?"border-line-2 bg-bg-2 text-fg":"border-line bg-bg-1 text-fg-faint hover:text-fg"}`,children:[e.jsx("span",{style:{color:l.color},"aria-hidden":!0,children:o?"●":"○"}),l.name]},l.id)})})]})]})}const tt=[{label:"surfaces",keys:[{key:"canvas",label:"Canvas"},{key:"panel",label:"Panel"},{key:"inset",label:"Inset"},{key:"insetStrong",label:"Raised inset"},{key:"chrome",label:"Desktop chrome"},{key:"line",label:"Line"},{key:"lineStrong",label:"Strong line"},{key:"lineFaint",label:"Faint line"}]},{label:"type",keys:[{key:"text",label:"Text"},{key:"textDim",label:"Dim text"},{key:"textFaint",label:"Faint text"},{key:"textStrong",label:"Strong text"}]},{label:"signals",keys:[{key:"accent",label:"Accent"},{key:"cost",label:"Cost"},{key:"positive",label:"Savings"}]}],at=[{value:"auto",label:"Auto"},{value:"light",label:"Light"},{value:"dark",label:"Dark"}],nt=[{value:"ansi",label:"Terminal"},{value:"dark",label:"Dark"},{value:"light",label:"Light"},{value:"off",label:"Off"}];function K(t){return t.custom??{base:"tokmon",light:{},dark:{}}}function F(t,n){return{...t,appearance:{...t.appearance,...n}}}function st({preset:t,selected:n,appearance:a,onSelect:s}){const u=t==="custom"?{...a,preset:t,custom:K(a),mode:"dark"}:{...a,preset:t,mode:"dark"},r=pe(u,"dark").tokens;return e.jsxs("button",{type:"button","aria-pressed":n,onClick:s,className:`min-w-0 rounded border p-2 text-left transition ${g} ${n?"border-accent":"border-line hover:border-line-2"}`,style:{background:r.panel,color:r.text},children:[e.jsxs("span",{className:"mb-2 flex items-center gap-1.5 text-[11px] font-medium",children:[e.jsx("span",{className:"size-2 rounded-full",style:{background:r.accent},"aria-hidden":!0}),e.jsx("span",{className:"truncate",children:V(t).name})]}),e.jsx("span",{className:"flex h-5 items-end gap-1","aria-hidden":!0,children:[r.textFaint,r.textDim,r.cost,r.accent].map((b,h)=>e.jsx("span",{className:"flex-1 rounded-sm",style:{height:`${7+h*3}px`,background:b}},b))})]})}function rt({draft:t,patch:n}){const a=t.appearance,[s,u]=x.useState("dark"),r=K(a),b=x.useMemo(()=>pe({...a,preset:"custom",custom:r,mode:s},s),[a,r,s]),h=x.useMemo(()=>be(a),[a]),v=h.filter(i=>i.mode===s),l=new Set(v.flatMap(i=>i.keys)),o=h.length===0,d=i=>n(p=>F(p,{preset:i,...i==="custom"?{custom:K(p.appearance)}:{},...H(i)?{mode:"dark"}:{}})),c=(i=a.preset)=>{Z(i)&&n(p=>F(p,{preset:"custom",custom:{base:i,light:{},dark:{}}}))},f=i=>n(p=>F(p,{preset:"custom",custom:i(K(p.appearance))}));return e.jsxs("div",{className:"space-y-6",children:[e.jsxs(E,{title:"appearance",children:[e.jsx(k,{label:"Mode",hint:"Auto follows the operating system live.",children:e.jsx(C,{options:H(a.preset)?[{value:"dark",label:"Dark"}]:[...at],value:H(a.preset)?"dark":a.mode,onChange:i=>n(p=>F(p,{mode:i})),ariaLabel:"graphical color mode"})}),e.jsx(k,{label:"Terminal colors",hint:"Keep ANSI to preserve the classic Tokmon CLI.",children:e.jsx(C,{options:[...nt],value:a.terminal,onChange:i=>n(p=>F(p,{terminal:i})),ariaLabel:"terminal theme policy",size:"xs"})})]}),e.jsxs(E,{title:"preset",children:[e.jsx("div",{className:"grid grid-cols-2 gap-2 sm:grid-cols-3",children:Pe.map(i=>e.jsx(st,{preset:i.id,selected:a.preset===i.id,appearance:a,onSelect:()=>d(i.id)},i.id))}),e.jsxs("div",{className:"mt-3 flex min-h-7 items-center justify-between gap-3",children:[e.jsx("p",{className:"text-[11px] text-fg-faint",children:H(a.preset)?"Phosphor is intentionally dark-only.":V(a.preset).hint}),Z(a.preset)&&e.jsxs("button",{type:"button",onClick:()=>c(),className:`shrink-0 rounded border border-line px-2.5 py-1 text-[11px] text-fg-dim transition hover:border-line-2 hover:text-fg ${g}`,children:["customize ",V(a.preset).name]})]})]}),a.preset==="custom"&&e.jsxs(E,{title:"custom palette",right:e.jsx(C,{options:[{value:"light",label:"Light"},{value:"dark",label:"Dark"}],value:s,onChange:u,size:"xs",ariaLabel:"custom palette variant"}),children:[e.jsx(k,{label:"Starting point",hint:"Changing the base resets both variants.",children:e.jsx("select",{value:r.base,onChange:i=>{const p=i.target.value;Z(p)&&f(()=>({base:p,light:{},dark:{}}))},"aria-label":"custom theme base",className:`min-h-8 rounded border border-line bg-bg-2 px-2 text-xs text-fg ${g}`,children:Ee.map(i=>e.jsx("option",{value:i,children:V(i).name},i))})}),e.jsx("div",{className:"mt-4 grid gap-x-5 gap-y-4 sm:grid-cols-2",children:tt.flatMap(i=>i.keys.map(p=>({...p,group:i.label}))).map(({key:i,label:p,group:w})=>{const A=r[s][i]??b.tokens[i],S=l.has(i);return e.jsxs("label",{className:"min-w-0",children:[e.jsxs("span",{className:"mb-1 flex items-baseline justify-between gap-2 text-xs text-fg",children:[p,e.jsx("span",{className:"text-[9px] uppercase tracking-wider text-fg-faint",children:w})]}),e.jsxs("span",{className:`flex items-center gap-2 rounded border bg-bg-2 p-1 ${S?"border-critical":"border-line"}`,children:[e.jsx("input",{type:"color","aria-label":`${s} ${p} color`,value:Re(A)??b.tokens[i],onChange:I=>f(N=>({...N,[s]:{...N[s],[i]:I.target.value}})),className:"size-7 cursor-pointer border-0 bg-transparent p-0"}),e.jsx("input",{type:"text",spellCheck:!1,maxLength:7,pattern:"#[0-9A-Fa-f]{6}",value:A,"aria-invalid":S,onChange:I=>f(N=>({...N,[s]:{...N[s],[i]:I.target.value}})),className:`tnum min-w-0 flex-1 bg-transparent px-1 text-xs text-fg outline-none ${g}`})]}),S&&e.jsx("span",{className:"mt-1 block text-[10px] text-critical",children:"Use #RRGGBB with readable contrast."})]},i)})}),e.jsxs("div",{className:"mt-4 flex items-center justify-between gap-3 border-t border-line pt-3",children:[e.jsx("span",{className:`text-[11px] ${o?"text-positive":"text-critical"}`,role:"status",children:o?"Light and dark palettes pass contrast checks":`${h.length} palette issue${h.length===1?"":"s"}`}),e.jsxs("button",{type:"button",onClick:()=>f(i=>({...i,[s]:{}})),className:`rounded border border-line px-2.5 py-1 text-[11px] text-fg-dim transition hover:border-line-2 hover:text-fg ${g}`,children:["reset ",s]})]})]})]})}const lt=[{value:"general",label:"General"},{value:"theme",label:"Theme"},{value:"app",label:"Desktop App"},{value:"providers",label:"Providers"},{value:"accounts",label:"Accounts"}];function ct({onClose:t,snapshot:n}){const a=Te(),s=x.useRef(null),u=x.useRef(null),[r,b]=x.useState(null),[h,v]=x.useState(null),[l,o]=x.useState(null),[d,c]=x.useState(!1),[f,i]=x.useState(null),[p,w]=x.useState(!1),[A,S]=x.useState(!1),[I,N]=x.useState(null),[D,j]=x.useState("general"),$=x.useRef(!1),T=x.useRef(!1),z=x.useRef(null),Y=x.useRef(null),_=x.useCallback(m=>{o(null);const y=Le(z.current,Y.current,$.current,m);$.current||(z.current=y.draft,Y.current=y.revision,b(y.draft),v(y.revision)),y.conflict&&i("settings changed elsewhere; close and reopen settings before saving")},[]);x.useEffect(()=>{let m=!0;return Me().then(y=>{m&&_(y)}).catch(y=>{m&&o(y instanceof Error?y.message:"load failed")}),()=>{m=!1}},[_]),x.useEffect(()=>{const m=y=>{$.current&&y.preventDefault()};return window.addEventListener("beforeunload",m),()=>window.removeEventListener("beforeunload",m)},[]),x.useEffect(()=>{let m=!0;const y=Fe(R=>{m&&_(R)});return()=>{m=!1,y()}},[_]);const se=()=>{if(!$.current||T.current){a.setPreview(null),t();return}T.current=!0,S(!0),i("unsaved changes; choose discard to close settings")};x.useEffect(()=>{const m=s.current;m&&(I?m.setAttribute("inert",""):m.removeAttribute("inert"))},[I]);const L=m=>{const y=z.current;if(!y)return;const R={...m(y),revision:y.revision};a.setPreview(R.appearance),$.current=!0,z.current=R,w(!0),T.current=!1,S(!1),i(null),b(R)},fe=async()=>{if(r){c(!0),i(null);try{if(h===null)throw new Error("config revision is unavailable");const m=await Oe(r,h);z.current=m.config,Y.current=m.config.revision,$.current=!1,b(m.config),v(m.config.revision),w(!1),a.commit(m),t()}catch(m){a.setPreview(null);const y=Be(m);i(y.conflictState?`${y.message}; close and reopen settings before saving`:y.message)}finally{c(!1)}}};return e.jsxs(e.Fragment,{children:[e.jsxs(he,{onClose:se,labelledBy:"settings-title",initialFocusRef:u,panelRef:s,className:"my-6 flex w-full max-w-[900px] flex-col",children:[e.jsx("h2",{ref:u,tabIndex:-1,id:"settings-title",className:"pointer-events-none absolute left-3 top-2 font-display text-[11px] uppercase tracking-wider text-fg-dim focus:outline-none",children:"settings"}),e.jsx("div",{className:"max-h-[78vh] overflow-y-auto px-4 pb-4 pt-9 sm:px-5",children:l&&!r?e.jsxs("div",{className:"rounded border border-critical/50 bg-bg-2 p-4 text-sm text-critical",role:"alert",children:["Could not load settings: ",l,". Close settings and try again."]}):r?e.jsx(e.Fragment,{children:e.jsxs("div",{className:"flex min-w-0 flex-col gap-5 sm:flex-row sm:items-start",children:[e.jsx("nav",{className:"-mx-1 flex shrink-0 gap-1 overflow-x-auto px-1 pb-2 sm:mx-0 sm:w-32 sm:flex-col sm:overflow-visible sm:px-0 sm:pb-0","aria-label":"Settings sections",children:lt.map(m=>e.jsx("button",{type:"button","aria-current":D===m.value?"page":void 0,onClick:()=>j(m.value),className:`shrink-0 rounded px-2.5 py-2 text-left text-[11px] transition ${g} ${D===m.value?"bg-bg-3 text-accent":"text-fg-dim hover:bg-bg-2 hover:text-fg"}`,children:m.label},m.value))}),e.jsxs("div",{className:"min-w-0 flex-1 border-t border-line pt-4 sm:border-l sm:border-t-0 sm:pl-5 sm:pt-0",children:[D==="general"&&e.jsx(He,{draft:r,patch:L}),D==="theme"&&e.jsx(rt,{draft:r,patch:L}),D==="app"&&e.jsx(et,{draft:r,patch:L,snapshot:n}),D==="providers"&&e.jsx(Ke,{draft:r,patch:L}),D==="accounts"&&e.jsx(Xe,{draft:r,patch:L,snapshot:n,onEdit:m=>N(_e(m)),onConfigure:m=>N(ue(r,{providerId:m.providerId,name:m.name,homeDir:m.homeDir,color:m.color})),onAdd:()=>N(ue(r))})]})]})}):e.jsx("div",{className:"py-10 text-center text-sm text-fg-dim",children:"loading config…"})}),e.jsxs("div",{className:"flex items-center justify-end gap-3 border-t border-line px-5 py-3",children:[f&&e.jsx("span",{className:"mr-auto text-xs text-critical",role:"alert",children:f}),p&&!f&&e.jsx("span",{className:"mr-auto text-xs text-fg-faint",role:"status","aria-live":"polite",children:"unsaved changes"}),e.jsx(M,{variant:"secondary",onClick:se,children:A?"discard":"cancel"}),e.jsxs(M,{variant:"primary",onClick:fe,disabled:!r||d||!p||be(r.appearance).length>0,children:[e.jsx(B,{className:"size-3.5"})," ",d?"saving…":"save"]})]})]}),I&&r&&e.jsx(Ze,{editor:I,accounts:r.accounts,onChange:N,onCancel:()=>N(null),onSubmit:(m,y,R)=>{L(U=>y==="add"?{...U,accounts:[...U.accounts,m]}:{...U,accounts:U.accounts.map(re=>re.id===R?m:re)}),N(null)}})]})}export{ct as SettingsSheet};
@@ -1,2 +1,2 @@
1
- import{j as s,r as x,f as O,b as K,c as xt,h as Be,y as gt,S as yt,R as k,u as Ke,d as z,w as bt,z as vt,I as Se,l as wt,m as jt,T as Q,aw as St,ax as kt,n as G,al as ke,a1 as Pe,X as Pt,ay as At,az as Et}from"./index-RDhXsCNG.js";import{D as Ct,B as Ae}from"./button-DrX04Cc2.js";import{S as Ee,V as Nt,d as me,L as q,n as Ot,w as Rt,y as ee,z as Tt,J as He,W as $t,v as re,Z as _t,j as It,q as Lt,c as Ft,t as B,E as zt,H as Dt,K as Mt,_ as Ce,F as Bt,g as Kt,X as We,Y as Ve,P as Ue,f as Ht,R as Wt,a as Vt,G as Ut}from"./chart-D0CtuL2k.js";import{L as Gt,A as Ge}from"./Area-stRnp8Km.js";function qt(e,t){if(e.match(/^[a-z]+:\/\//i))return e;if(e.match(/^\/\//))return window.location.protocol+e;if(e.match(/^[a-z]+:/i))return e;const n=document.implementation.createHTMLDocument(),a=n.createElement("base"),r=n.createElement("a");return n.head.appendChild(a),n.body.appendChild(r),t&&(a.href=t),r.href=e,r.href}const Xt=(()=>{let e=0;const t=()=>`0000${(Math.random()*36**4<<0).toString(36)}`.slice(-4);return()=>(e+=1,`u${t()}${e}`)})();function T(e){const t=[];for(let n=0,a=e.length;n<a;n++)t.push(e[n]);return t}let D=null;function qe(e={}){return D||(e.includeStyleProperties?(D=e.includeStyleProperties,D):(D=T(window.getComputedStyle(document.documentElement)),D))}function ie(e,t){const a=(e.ownerDocument.defaultView||window).getComputedStyle(e).getPropertyValue(t);return a?parseFloat(a.replace("px","")):0}function Zt(e){const t=ie(e,"border-left-width"),n=ie(e,"border-right-width");return e.clientWidth+t+n}function Jt(e){const t=ie(e,"border-top-width"),n=ie(e,"border-bottom-width");return e.clientHeight+t+n}function Xe(e,t={}){const n=t.width||Zt(e),a=t.height||Jt(e);return{width:n,height:a}}function Yt(){let e,t;try{t=process}catch{}const n=t&&t.env?t.env.devicePixelRatio:null;return n&&(e=parseInt(n,10),Number.isNaN(e)&&(e=1)),e||window.devicePixelRatio||1}const A=16384;function Qt(e){(e.width>A||e.height>A)&&(e.width>A&&e.height>A?e.width>e.height?(e.height*=A/e.width,e.width=A):(e.width*=A/e.height,e.height=A):e.width>A?(e.height*=A/e.width,e.width=A):(e.width*=A/e.height,e.height=A))}function en(e,t={}){return e.toBlob?new Promise(n=>{e.toBlob(n,t.type?t.type:"image/png",t.quality?t.quality:1)}):new Promise(n=>{const a=window.atob(e.toDataURL(t.type?t.type:void 0,t.quality?t.quality:void 0).split(",")[1]),r=a.length,i=new Uint8Array(r);for(let o=0;o<r;o+=1)i[o]=a.charCodeAt(o);n(new Blob([i],{type:t.type?t.type:"image/png"}))})}function se(e){return new Promise((t,n)=>{const a=new Image;a.onload=()=>{a.decode().then(()=>{requestAnimationFrame(()=>t(a))})},a.onerror=n,a.crossOrigin="anonymous",a.decoding="async",a.src=e})}async function tn(e){return Promise.resolve().then(()=>new XMLSerializer().serializeToString(e)).then(encodeURIComponent).then(t=>`data:image/svg+xml;charset=utf-8,${t}`)}async function nn(e,t,n){const a="http://www.w3.org/2000/svg",r=document.createElementNS(a,"svg"),i=document.createElementNS(a,"foreignObject");return r.setAttribute("width",`${t}`),r.setAttribute("height",`${n}`),r.setAttribute("viewBox",`0 0 ${t} ${n}`),i.setAttribute("width","100%"),i.setAttribute("height","100%"),i.setAttribute("x","0"),i.setAttribute("y","0"),i.setAttribute("externalResourcesRequired","true"),r.appendChild(i),i.appendChild(e),tn(r)}const P=(e,t)=>{if(e instanceof t)return!0;const n=Object.getPrototypeOf(e);return n===null?!1:n.constructor.name===t.name||P(n,t)};function an(e){const t=e.getPropertyValue("content");return`${e.cssText} content: '${t.replace(/'|"/g,"")}';`}function rn(e,t){return qe(t).map(n=>{const a=e.getPropertyValue(n),r=e.getPropertyPriority(n);return`${n}: ${a}${r?" !important":""};`}).join(" ")}function sn(e,t,n,a){const r=`.${e}:${t}`,i=n.cssText?an(n):rn(n,a);return document.createTextNode(`${r}{${i}}`)}function Ne(e,t,n,a){const r=window.getComputedStyle(e,n),i=r.getPropertyValue("content");if(i===""||i==="none")return;const o=Xt();try{t.className=`${t.className} ${o}`}catch{return}const l=document.createElement("style");l.appendChild(sn(o,n,r,a)),t.appendChild(l)}function on(e,t,n){Ne(e,t,":before",n),Ne(e,t,":after",n)}const Oe="application/font-woff",Re="image/jpeg",ln={woff:Oe,woff2:Oe,ttf:"application/font-truetype",eot:"application/vnd.ms-fontobject",png:"image/png",jpg:Re,jpeg:Re,gif:"image/gif",tiff:"image/tiff",svg:"image/svg+xml",webp:"image/webp"};function cn(e){const t=/\.([^./]*?)$/g.exec(e);return t?t[1]:""}function ye(e){const t=cn(e).toLowerCase();return ln[t]||""}function un(e){return e.split(/,/)[1]}function he(e){return e.search(/^(data:)/)!==-1}function fn(e,t){return`data:${t};base64,${e}`}async function Ze(e,t,n){const a=await fetch(e,t);if(a.status===404)throw new Error(`Resource "${a.url}" not found`);const r=await a.blob();return new Promise((i,o)=>{const l=new FileReader;l.onerror=o,l.onloadend=()=>{try{i(n({res:a,result:l.result}))}catch(u){o(u)}},l.readAsDataURL(r)})}const pe={};function dn(e,t,n){let a=e.replace(/\?.*/,"");return n&&(a=e),/ttf|otf|eot|woff2?/i.test(a)&&(a=a.replace(/.*\//,"")),t?`[${t}]${a}`:a}async function be(e,t,n){const a=dn(e,t,n.includeQueryParams);if(pe[a]!=null)return pe[a];n.cacheBust&&(e+=(/\?/.test(e)?"&":"?")+new Date().getTime());let r;try{const i=await Ze(e,n.fetchRequestInit,({res:o,result:l})=>(t||(t=o.headers.get("Content-Type")||""),un(l)));r=fn(i,t)}catch(i){r=n.imagePlaceholder||"";let o=`Failed to fetch resource: ${e}`;i&&(o=typeof i=="string"?i:i.message),o&&console.warn(o)}return pe[a]=r,r}async function mn(e){const t=e.toDataURL();return t==="data:,"?e.cloneNode(!1):se(t)}async function pn(e,t){if(e.currentSrc){const i=document.createElement("canvas"),o=i.getContext("2d");i.width=e.clientWidth,i.height=e.clientHeight,o==null||o.drawImage(e,0,0,i.width,i.height);const l=i.toDataURL();return se(l)}const n=e.poster,a=ye(n),r=await be(n,a,t);return se(r)}async function hn(e,t){var n;try{if(!((n=e==null?void 0:e.contentDocument)===null||n===void 0)&&n.body)return await ce(e.contentDocument.body,t,!0)}catch{}return e.cloneNode(!1)}async function xn(e,t){return P(e,HTMLCanvasElement)?mn(e):P(e,HTMLVideoElement)?pn(e,t):P(e,HTMLIFrameElement)?hn(e,t):e.cloneNode(Je(e))}const gn=e=>e.tagName!=null&&e.tagName.toUpperCase()==="SLOT",Je=e=>e.tagName!=null&&e.tagName.toUpperCase()==="SVG";async function yn(e,t,n){var a,r;if(Je(t))return t;let i=[];return gn(e)&&e.assignedNodes?i=T(e.assignedNodes()):P(e,HTMLIFrameElement)&&(!((a=e.contentDocument)===null||a===void 0)&&a.body)?i=T(e.contentDocument.body.childNodes):i=T(((r=e.shadowRoot)!==null&&r!==void 0?r:e).childNodes),i.length===0||P(e,HTMLVideoElement)||await i.reduce((o,l)=>o.then(()=>ce(l,n)).then(u=>{u&&t.appendChild(u)}),Promise.resolve()),t}function bn(e,t,n){const a=t.style;if(!a)return;const r=window.getComputedStyle(e);r.cssText?(a.cssText=r.cssText,a.transformOrigin=r.transformOrigin):qe(n).forEach(i=>{let o=r.getPropertyValue(i);i==="font-size"&&o.endsWith("px")&&(o=`${Math.floor(parseFloat(o.substring(0,o.length-2)))-.1}px`),P(e,HTMLIFrameElement)&&i==="display"&&o==="inline"&&(o="block"),i==="d"&&t.getAttribute("d")&&(o=`path(${t.getAttribute("d")})`),a.setProperty(i,o,r.getPropertyPriority(i))})}function vn(e,t){P(e,HTMLTextAreaElement)&&(t.innerHTML=e.value),P(e,HTMLInputElement)&&t.setAttribute("value",e.value)}function wn(e,t){if(P(e,HTMLSelectElement)){const a=Array.from(t.children).find(r=>e.value===r.getAttribute("value"));a&&a.setAttribute("selected","")}}function jn(e,t,n){return P(t,Element)&&(bn(e,t,n),on(e,t,n),vn(e,t),wn(e,t)),t}async function Sn(e,t){const n=e.querySelectorAll?e.querySelectorAll("use"):[];if(n.length===0)return e;const a={};for(let i=0;i<n.length;i++){const l=n[i].getAttribute("xlink:href");if(l){const u=e.querySelector(l),f=document.querySelector(l);!u&&f&&!a[l]&&(a[l]=await ce(f,t,!0))}}const r=Object.values(a);if(r.length){const i="http://www.w3.org/1999/xhtml",o=document.createElementNS(i,"svg");o.setAttribute("xmlns",i),o.style.position="absolute",o.style.width="0",o.style.height="0",o.style.overflow="hidden",o.style.display="none";const l=document.createElementNS(i,"defs");o.appendChild(l);for(let u=0;u<r.length;u++)l.appendChild(r[u]);e.appendChild(o)}return e}async function ce(e,t,n){return!n&&t.filter&&!t.filter(e)?null:Promise.resolve(e).then(a=>xn(a,t)).then(a=>yn(e,a,t)).then(a=>jn(e,a,t)).then(a=>Sn(a,t))}const Ye=/url\((['"]?)([^'"]+?)\1\)/g,kn=/url\([^)]+\)\s*format\((["']?)([^"']+)\1\)/g,Pn=/src:\s*(?:url\([^)]+\)\s*format\([^)]+\)[,;]\s*)+/g;function An(e){const t=e.replace(/([.*+?^${}()|\[\]\/\\])/g,"\\$1");return new RegExp(`(url\\(['"]?)(${t})(['"]?\\))`,"g")}function En(e){const t=[];return e.replace(Ye,(n,a,r)=>(t.push(r),n)),t.filter(n=>!he(n))}async function Cn(e,t,n,a,r){try{const i=n?qt(t,n):t,o=ye(t);let l;return r||(l=await be(i,o,a)),e.replace(An(t),`$1${l}$3`)}catch{}return e}function Nn(e,{preferredFontFormat:t}){return t?e.replace(Pn,n=>{for(;;){const[a,,r]=kn.exec(n)||[];if(!r)return"";if(r===t)return`src: ${a};`}}):e}function Qe(e){return e.search(Ye)!==-1}async function et(e,t,n){if(!Qe(e))return e;const a=Nn(e,n);return En(a).reduce((i,o)=>i.then(l=>Cn(l,o,t,n)),Promise.resolve(a))}async function M(e,t,n){var a;const r=(a=t.style)===null||a===void 0?void 0:a.getPropertyValue(e);if(r){const i=await et(r,null,n);return t.style.setProperty(e,i,t.style.getPropertyPriority(e)),!0}return!1}async function On(e,t){await M("background",e,t)||await M("background-image",e,t),await M("mask",e,t)||await M("-webkit-mask",e,t)||await M("mask-image",e,t)||await M("-webkit-mask-image",e,t)}async function Rn(e,t){const n=P(e,HTMLImageElement);if(!(n&&!he(e.src))&&!(P(e,SVGImageElement)&&!he(e.href.baseVal)))return;const a=n?e.src:e.href.baseVal,r=await be(a,ye(a),t);await new Promise((i,o)=>{e.onload=i,e.onerror=t.onImageErrorHandler?(...u)=>{try{i(t.onImageErrorHandler(...u))}catch(f){o(f)}}:o;const l=e;l.decode&&(l.decode=i),l.loading==="lazy"&&(l.loading="eager"),n?(e.srcset="",e.src=r):e.href.baseVal=r})}async function Tn(e,t){const a=T(e.childNodes).map(r=>tt(r,t));await Promise.all(a).then(()=>e)}async function tt(e,t){P(e,Element)&&(await On(e,t),await Rn(e,t),await Tn(e,t))}function $n(e,t){const{style:n}=e;t.backgroundColor&&(n.backgroundColor=t.backgroundColor),t.width&&(n.width=`${t.width}px`),t.height&&(n.height=`${t.height}px`);const a=t.style;return a!=null&&Object.keys(a).forEach(r=>{n[r]=a[r]}),e}const Te={};async function $e(e){let t=Te[e];if(t!=null)return t;const a=await(await fetch(e)).text();return t={url:e,cssText:a},Te[e]=t,t}async function _e(e,t){let n=e.cssText;const a=/url\(["']?([^"')]+)["']?\)/g,i=(n.match(/url\([^)]+\)/g)||[]).map(async o=>{let l=o.replace(a,"$1");return l.startsWith("https://")||(l=new URL(l,e.url).href),Ze(l,t.fetchRequestInit,({result:u})=>(n=n.replace(o,`url(${u})`),[o,u]))});return Promise.all(i).then(()=>n)}function Ie(e){if(e==null)return[];const t=[],n=/(\/\*[\s\S]*?\*\/)/gi;let a=e.replace(n,"");const r=new RegExp("((@.*?keyframes [\\s\\S]*?){([\\s\\S]*?}\\s*?)})","gi");for(;;){const u=r.exec(a);if(u===null)break;t.push(u[0])}a=a.replace(r,"");const i=/@import[\s\S]*?url\([^)]*\)[\s\S]*?;/gi,o="((\\s*?(?:\\/\\*[\\s\\S]*?\\*\\/)?\\s*?@media[\\s\\S]*?){([\\s\\S]*?)}\\s*?})|(([\\s\\S]*?){([\\s\\S]*?)})",l=new RegExp(o,"gi");for(;;){let u=i.exec(a);if(u===null){if(u=l.exec(a),u===null)break;i.lastIndex=l.lastIndex}else l.lastIndex=i.lastIndex;t.push(u[0])}return t}async function _n(e,t){const n=[],a=[];return e.forEach(r=>{if("cssRules"in r)try{T(r.cssRules||[]).forEach((i,o)=>{if(i.type===CSSRule.IMPORT_RULE){let l=o+1;const u=i.href,f=$e(u).then(c=>_e(c,t)).then(c=>Ie(c).forEach(d=>{try{r.insertRule(d,d.startsWith("@import")?l+=1:r.cssRules.length)}catch(h){console.error("Error inserting rule from remote css",{rule:d,error:h})}})).catch(c=>{console.error("Error loading remote css",c.toString())});a.push(f)}})}catch(i){const o=e.find(l=>l.href==null)||document.styleSheets[0];r.href!=null&&a.push($e(r.href).then(l=>_e(l,t)).then(l=>Ie(l).forEach(u=>{o.insertRule(u,o.cssRules.length)})).catch(l=>{console.error("Error loading remote stylesheet",l)})),console.error("Error inlining remote css file",i)}}),Promise.all(a).then(()=>(e.forEach(r=>{if("cssRules"in r)try{T(r.cssRules||[]).forEach(i=>{n.push(i)})}catch(i){console.error(`Error while reading CSS rules from ${r.href}`,i)}}),n))}function In(e){return e.filter(t=>t.type===CSSRule.FONT_FACE_RULE).filter(t=>Qe(t.style.getPropertyValue("src")))}async function Ln(e,t){if(e.ownerDocument==null)throw new Error("Provided element is not within a Document");const n=T(e.ownerDocument.styleSheets),a=await _n(n,t);return In(a)}function nt(e){return e.trim().replace(/["']/g,"")}function Fn(e){const t=new Set;function n(a){(a.style.fontFamily||getComputedStyle(a).fontFamily).split(",").forEach(i=>{t.add(nt(i))}),Array.from(a.children).forEach(i=>{i instanceof HTMLElement&&n(i)})}return n(e),t}async function zn(e,t){const n=await Ln(e,t),a=Fn(e);return(await Promise.all(n.filter(i=>a.has(nt(i.style.fontFamily))).map(i=>{const o=i.parentStyleSheet?i.parentStyleSheet.href:null;return et(i.cssText,o,t)}))).join(`
1
+ import{j as s,r as x,f as O,b as K,c as xt,h as Be,y as gt,S as yt,R as k,u as Ke,d as z,w as bt,z as vt,I as Se,l as wt,m as jt,T as Q,aw as St,ax as kt,n as G,al as ke,a1 as Pe,X as Pt,ay as At,az as Et}from"./index-9hkGpa7j.js";import{D as Ct,B as Ae}from"./button-CnT5g-Jl.js";import{S as Ee,V as Nt,d as me,L as q,n as Ot,w as Rt,y as ee,z as Tt,J as He,W as $t,v as re,Z as _t,j as It,q as Lt,c as Ft,t as B,E as zt,H as Dt,K as Mt,_ as Ce,F as Bt,g as Kt,X as We,Y as Ve,P as Ue,f as Ht,R as Wt,a as Vt,G as Ut}from"./chart-Duz9D-nH.js";import{L as Gt,A as Ge}from"./Area-BqyvRn2x.js";function qt(e,t){if(e.match(/^[a-z]+:\/\//i))return e;if(e.match(/^\/\//))return window.location.protocol+e;if(e.match(/^[a-z]+:/i))return e;const n=document.implementation.createHTMLDocument(),a=n.createElement("base"),r=n.createElement("a");return n.head.appendChild(a),n.body.appendChild(r),t&&(a.href=t),r.href=e,r.href}const Xt=(()=>{let e=0;const t=()=>`0000${(Math.random()*36**4<<0).toString(36)}`.slice(-4);return()=>(e+=1,`u${t()}${e}`)})();function T(e){const t=[];for(let n=0,a=e.length;n<a;n++)t.push(e[n]);return t}let D=null;function qe(e={}){return D||(e.includeStyleProperties?(D=e.includeStyleProperties,D):(D=T(window.getComputedStyle(document.documentElement)),D))}function ie(e,t){const a=(e.ownerDocument.defaultView||window).getComputedStyle(e).getPropertyValue(t);return a?parseFloat(a.replace("px","")):0}function Zt(e){const t=ie(e,"border-left-width"),n=ie(e,"border-right-width");return e.clientWidth+t+n}function Jt(e){const t=ie(e,"border-top-width"),n=ie(e,"border-bottom-width");return e.clientHeight+t+n}function Xe(e,t={}){const n=t.width||Zt(e),a=t.height||Jt(e);return{width:n,height:a}}function Yt(){let e,t;try{t=process}catch{}const n=t&&t.env?t.env.devicePixelRatio:null;return n&&(e=parseInt(n,10),Number.isNaN(e)&&(e=1)),e||window.devicePixelRatio||1}const A=16384;function Qt(e){(e.width>A||e.height>A)&&(e.width>A&&e.height>A?e.width>e.height?(e.height*=A/e.width,e.width=A):(e.width*=A/e.height,e.height=A):e.width>A?(e.height*=A/e.width,e.width=A):(e.width*=A/e.height,e.height=A))}function en(e,t={}){return e.toBlob?new Promise(n=>{e.toBlob(n,t.type?t.type:"image/png",t.quality?t.quality:1)}):new Promise(n=>{const a=window.atob(e.toDataURL(t.type?t.type:void 0,t.quality?t.quality:void 0).split(",")[1]),r=a.length,i=new Uint8Array(r);for(let o=0;o<r;o+=1)i[o]=a.charCodeAt(o);n(new Blob([i],{type:t.type?t.type:"image/png"}))})}function se(e){return new Promise((t,n)=>{const a=new Image;a.onload=()=>{a.decode().then(()=>{requestAnimationFrame(()=>t(a))})},a.onerror=n,a.crossOrigin="anonymous",a.decoding="async",a.src=e})}async function tn(e){return Promise.resolve().then(()=>new XMLSerializer().serializeToString(e)).then(encodeURIComponent).then(t=>`data:image/svg+xml;charset=utf-8,${t}`)}async function nn(e,t,n){const a="http://www.w3.org/2000/svg",r=document.createElementNS(a,"svg"),i=document.createElementNS(a,"foreignObject");return r.setAttribute("width",`${t}`),r.setAttribute("height",`${n}`),r.setAttribute("viewBox",`0 0 ${t} ${n}`),i.setAttribute("width","100%"),i.setAttribute("height","100%"),i.setAttribute("x","0"),i.setAttribute("y","0"),i.setAttribute("externalResourcesRequired","true"),r.appendChild(i),i.appendChild(e),tn(r)}const P=(e,t)=>{if(e instanceof t)return!0;const n=Object.getPrototypeOf(e);return n===null?!1:n.constructor.name===t.name||P(n,t)};function an(e){const t=e.getPropertyValue("content");return`${e.cssText} content: '${t.replace(/'|"/g,"")}';`}function rn(e,t){return qe(t).map(n=>{const a=e.getPropertyValue(n),r=e.getPropertyPriority(n);return`${n}: ${a}${r?" !important":""};`}).join(" ")}function sn(e,t,n,a){const r=`.${e}:${t}`,i=n.cssText?an(n):rn(n,a);return document.createTextNode(`${r}{${i}}`)}function Ne(e,t,n,a){const r=window.getComputedStyle(e,n),i=r.getPropertyValue("content");if(i===""||i==="none")return;const o=Xt();try{t.className=`${t.className} ${o}`}catch{return}const l=document.createElement("style");l.appendChild(sn(o,n,r,a)),t.appendChild(l)}function on(e,t,n){Ne(e,t,":before",n),Ne(e,t,":after",n)}const Oe="application/font-woff",Re="image/jpeg",ln={woff:Oe,woff2:Oe,ttf:"application/font-truetype",eot:"application/vnd.ms-fontobject",png:"image/png",jpg:Re,jpeg:Re,gif:"image/gif",tiff:"image/tiff",svg:"image/svg+xml",webp:"image/webp"};function cn(e){const t=/\.([^./]*?)$/g.exec(e);return t?t[1]:""}function ye(e){const t=cn(e).toLowerCase();return ln[t]||""}function un(e){return e.split(/,/)[1]}function he(e){return e.search(/^(data:)/)!==-1}function fn(e,t){return`data:${t};base64,${e}`}async function Ze(e,t,n){const a=await fetch(e,t);if(a.status===404)throw new Error(`Resource "${a.url}" not found`);const r=await a.blob();return new Promise((i,o)=>{const l=new FileReader;l.onerror=o,l.onloadend=()=>{try{i(n({res:a,result:l.result}))}catch(u){o(u)}},l.readAsDataURL(r)})}const pe={};function dn(e,t,n){let a=e.replace(/\?.*/,"");return n&&(a=e),/ttf|otf|eot|woff2?/i.test(a)&&(a=a.replace(/.*\//,"")),t?`[${t}]${a}`:a}async function be(e,t,n){const a=dn(e,t,n.includeQueryParams);if(pe[a]!=null)return pe[a];n.cacheBust&&(e+=(/\?/.test(e)?"&":"?")+new Date().getTime());let r;try{const i=await Ze(e,n.fetchRequestInit,({res:o,result:l})=>(t||(t=o.headers.get("Content-Type")||""),un(l)));r=fn(i,t)}catch(i){r=n.imagePlaceholder||"";let o=`Failed to fetch resource: ${e}`;i&&(o=typeof i=="string"?i:i.message),o&&console.warn(o)}return pe[a]=r,r}async function mn(e){const t=e.toDataURL();return t==="data:,"?e.cloneNode(!1):se(t)}async function pn(e,t){if(e.currentSrc){const i=document.createElement("canvas"),o=i.getContext("2d");i.width=e.clientWidth,i.height=e.clientHeight,o==null||o.drawImage(e,0,0,i.width,i.height);const l=i.toDataURL();return se(l)}const n=e.poster,a=ye(n),r=await be(n,a,t);return se(r)}async function hn(e,t){var n;try{if(!((n=e==null?void 0:e.contentDocument)===null||n===void 0)&&n.body)return await ce(e.contentDocument.body,t,!0)}catch{}return e.cloneNode(!1)}async function xn(e,t){return P(e,HTMLCanvasElement)?mn(e):P(e,HTMLVideoElement)?pn(e,t):P(e,HTMLIFrameElement)?hn(e,t):e.cloneNode(Je(e))}const gn=e=>e.tagName!=null&&e.tagName.toUpperCase()==="SLOT",Je=e=>e.tagName!=null&&e.tagName.toUpperCase()==="SVG";async function yn(e,t,n){var a,r;if(Je(t))return t;let i=[];return gn(e)&&e.assignedNodes?i=T(e.assignedNodes()):P(e,HTMLIFrameElement)&&(!((a=e.contentDocument)===null||a===void 0)&&a.body)?i=T(e.contentDocument.body.childNodes):i=T(((r=e.shadowRoot)!==null&&r!==void 0?r:e).childNodes),i.length===0||P(e,HTMLVideoElement)||await i.reduce((o,l)=>o.then(()=>ce(l,n)).then(u=>{u&&t.appendChild(u)}),Promise.resolve()),t}function bn(e,t,n){const a=t.style;if(!a)return;const r=window.getComputedStyle(e);r.cssText?(a.cssText=r.cssText,a.transformOrigin=r.transformOrigin):qe(n).forEach(i=>{let o=r.getPropertyValue(i);i==="font-size"&&o.endsWith("px")&&(o=`${Math.floor(parseFloat(o.substring(0,o.length-2)))-.1}px`),P(e,HTMLIFrameElement)&&i==="display"&&o==="inline"&&(o="block"),i==="d"&&t.getAttribute("d")&&(o=`path(${t.getAttribute("d")})`),a.setProperty(i,o,r.getPropertyPriority(i))})}function vn(e,t){P(e,HTMLTextAreaElement)&&(t.innerHTML=e.value),P(e,HTMLInputElement)&&t.setAttribute("value",e.value)}function wn(e,t){if(P(e,HTMLSelectElement)){const a=Array.from(t.children).find(r=>e.value===r.getAttribute("value"));a&&a.setAttribute("selected","")}}function jn(e,t,n){return P(t,Element)&&(bn(e,t,n),on(e,t,n),vn(e,t),wn(e,t)),t}async function Sn(e,t){const n=e.querySelectorAll?e.querySelectorAll("use"):[];if(n.length===0)return e;const a={};for(let i=0;i<n.length;i++){const l=n[i].getAttribute("xlink:href");if(l){const u=e.querySelector(l),f=document.querySelector(l);!u&&f&&!a[l]&&(a[l]=await ce(f,t,!0))}}const r=Object.values(a);if(r.length){const i="http://www.w3.org/1999/xhtml",o=document.createElementNS(i,"svg");o.setAttribute("xmlns",i),o.style.position="absolute",o.style.width="0",o.style.height="0",o.style.overflow="hidden",o.style.display="none";const l=document.createElementNS(i,"defs");o.appendChild(l);for(let u=0;u<r.length;u++)l.appendChild(r[u]);e.appendChild(o)}return e}async function ce(e,t,n){return!n&&t.filter&&!t.filter(e)?null:Promise.resolve(e).then(a=>xn(a,t)).then(a=>yn(e,a,t)).then(a=>jn(e,a,t)).then(a=>Sn(a,t))}const Ye=/url\((['"]?)([^'"]+?)\1\)/g,kn=/url\([^)]+\)\s*format\((["']?)([^"']+)\1\)/g,Pn=/src:\s*(?:url\([^)]+\)\s*format\([^)]+\)[,;]\s*)+/g;function An(e){const t=e.replace(/([.*+?^${}()|\[\]\/\\])/g,"\\$1");return new RegExp(`(url\\(['"]?)(${t})(['"]?\\))`,"g")}function En(e){const t=[];return e.replace(Ye,(n,a,r)=>(t.push(r),n)),t.filter(n=>!he(n))}async function Cn(e,t,n,a,r){try{const i=n?qt(t,n):t,o=ye(t);let l;return r||(l=await be(i,o,a)),e.replace(An(t),`$1${l}$3`)}catch{}return e}function Nn(e,{preferredFontFormat:t}){return t?e.replace(Pn,n=>{for(;;){const[a,,r]=kn.exec(n)||[];if(!r)return"";if(r===t)return`src: ${a};`}}):e}function Qe(e){return e.search(Ye)!==-1}async function et(e,t,n){if(!Qe(e))return e;const a=Nn(e,n);return En(a).reduce((i,o)=>i.then(l=>Cn(l,o,t,n)),Promise.resolve(a))}async function M(e,t,n){var a;const r=(a=t.style)===null||a===void 0?void 0:a.getPropertyValue(e);if(r){const i=await et(r,null,n);return t.style.setProperty(e,i,t.style.getPropertyPriority(e)),!0}return!1}async function On(e,t){await M("background",e,t)||await M("background-image",e,t),await M("mask",e,t)||await M("-webkit-mask",e,t)||await M("mask-image",e,t)||await M("-webkit-mask-image",e,t)}async function Rn(e,t){const n=P(e,HTMLImageElement);if(!(n&&!he(e.src))&&!(P(e,SVGImageElement)&&!he(e.href.baseVal)))return;const a=n?e.src:e.href.baseVal,r=await be(a,ye(a),t);await new Promise((i,o)=>{e.onload=i,e.onerror=t.onImageErrorHandler?(...u)=>{try{i(t.onImageErrorHandler(...u))}catch(f){o(f)}}:o;const l=e;l.decode&&(l.decode=i),l.loading==="lazy"&&(l.loading="eager"),n?(e.srcset="",e.src=r):e.href.baseVal=r})}async function Tn(e,t){const a=T(e.childNodes).map(r=>tt(r,t));await Promise.all(a).then(()=>e)}async function tt(e,t){P(e,Element)&&(await On(e,t),await Rn(e,t),await Tn(e,t))}function $n(e,t){const{style:n}=e;t.backgroundColor&&(n.backgroundColor=t.backgroundColor),t.width&&(n.width=`${t.width}px`),t.height&&(n.height=`${t.height}px`);const a=t.style;return a!=null&&Object.keys(a).forEach(r=>{n[r]=a[r]}),e}const Te={};async function $e(e){let t=Te[e];if(t!=null)return t;const a=await(await fetch(e)).text();return t={url:e,cssText:a},Te[e]=t,t}async function _e(e,t){let n=e.cssText;const a=/url\(["']?([^"')]+)["']?\)/g,i=(n.match(/url\([^)]+\)/g)||[]).map(async o=>{let l=o.replace(a,"$1");return l.startsWith("https://")||(l=new URL(l,e.url).href),Ze(l,t.fetchRequestInit,({result:u})=>(n=n.replace(o,`url(${u})`),[o,u]))});return Promise.all(i).then(()=>n)}function Ie(e){if(e==null)return[];const t=[],n=/(\/\*[\s\S]*?\*\/)/gi;let a=e.replace(n,"");const r=new RegExp("((@.*?keyframes [\\s\\S]*?){([\\s\\S]*?}\\s*?)})","gi");for(;;){const u=r.exec(a);if(u===null)break;t.push(u[0])}a=a.replace(r,"");const i=/@import[\s\S]*?url\([^)]*\)[\s\S]*?;/gi,o="((\\s*?(?:\\/\\*[\\s\\S]*?\\*\\/)?\\s*?@media[\\s\\S]*?){([\\s\\S]*?)}\\s*?})|(([\\s\\S]*?){([\\s\\S]*?)})",l=new RegExp(o,"gi");for(;;){let u=i.exec(a);if(u===null){if(u=l.exec(a),u===null)break;i.lastIndex=l.lastIndex}else l.lastIndex=i.lastIndex;t.push(u[0])}return t}async function _n(e,t){const n=[],a=[];return e.forEach(r=>{if("cssRules"in r)try{T(r.cssRules||[]).forEach((i,o)=>{if(i.type===CSSRule.IMPORT_RULE){let l=o+1;const u=i.href,f=$e(u).then(c=>_e(c,t)).then(c=>Ie(c).forEach(d=>{try{r.insertRule(d,d.startsWith("@import")?l+=1:r.cssRules.length)}catch(h){console.error("Error inserting rule from remote css",{rule:d,error:h})}})).catch(c=>{console.error("Error loading remote css",c.toString())});a.push(f)}})}catch(i){const o=e.find(l=>l.href==null)||document.styleSheets[0];r.href!=null&&a.push($e(r.href).then(l=>_e(l,t)).then(l=>Ie(l).forEach(u=>{o.insertRule(u,o.cssRules.length)})).catch(l=>{console.error("Error loading remote stylesheet",l)})),console.error("Error inlining remote css file",i)}}),Promise.all(a).then(()=>(e.forEach(r=>{if("cssRules"in r)try{T(r.cssRules||[]).forEach(i=>{n.push(i)})}catch(i){console.error(`Error while reading CSS rules from ${r.href}`,i)}}),n))}function In(e){return e.filter(t=>t.type===CSSRule.FONT_FACE_RULE).filter(t=>Qe(t.style.getPropertyValue("src")))}async function Ln(e,t){if(e.ownerDocument==null)throw new Error("Provided element is not within a Document");const n=T(e.ownerDocument.styleSheets),a=await _n(n,t);return In(a)}function nt(e){return e.trim().replace(/["']/g,"")}function Fn(e){const t=new Set;function n(a){(a.style.fontFamily||getComputedStyle(a).fontFamily).split(",").forEach(i=>{t.add(nt(i))}),Array.from(a.children).forEach(i=>{i instanceof HTMLElement&&n(i)})}return n(e),t}async function zn(e,t){const n=await Ln(e,t),a=Fn(e);return(await Promise.all(n.filter(i=>a.has(nt(i.style.fontFamily))).map(i=>{const o=i.parentStyleSheet?i.parentStyleSheet.href:null;return et(i.cssText,o,t)}))).join(`
2
2
  `)}async function Dn(e,t){const n=t.fontEmbedCSS!=null?t.fontEmbedCSS:t.skipFonts?null:await zn(e,t);if(n){const a=document.createElement("style"),r=document.createTextNode(n);a.appendChild(r),e.firstChild?e.insertBefore(a,e.firstChild):e.appendChild(a)}}async function Mn(e,t={}){const{width:n,height:a}=Xe(e,t),r=await ce(e,t,!0);return await Dn(r,t),await tt(r,t),$n(r,t),await nn(r,n,a)}async function at(e,t={}){const{width:n,height:a}=Xe(e,t),r=await Mn(e,t),i=await se(r),o=document.createElement("canvas"),l=o.getContext("2d"),u=t.pixelRatio||Yt(),f=t.canvasWidth||n,c=t.canvasHeight||a;return o.width=f*u,o.height=c*u,t.skipAutoScale||Qt(o),o.style.width=`${f}`,o.style.height=`${c}`,t.backgroundColor&&(l.fillStyle=t.backgroundColor,l.fillRect(0,0,o.width,o.height)),l.drawImage(i,0,0,o.width,o.height),o}async function Bn(e,t={}){return(await at(e,t)).toDataURL()}async function Kn(e,t={}){const n=await at(e,t);return await en(n)}const Hn=e=>e.toLowerCase().replace(/[^a-z0-9._-]+/g,"-").replace(/^-+|-+$/g,"")||"export";function Wn(e,t=new Date){const n=a=>String(a).padStart(2,"0");return`tokmon-${Hn(e)}-${t.getFullYear()}${n(t.getMonth()+1)}${n(t.getDate())}-${n(t.getHours())}${n(t.getMinutes())}.png`}const rt="#0a0a0a";async function it(){try{await document.fonts.ready}catch{}await new Promise(e=>requestAnimationFrame(()=>e(null)))}async function Vn(e,t={}){return await it(),Bn(e,{pixelRatio:t.pixelRatio??2,backgroundColor:t.backgroundColor??rt,cacheBust:!0,skipFonts:!1})}function Un(e,t){const n=document.createElement("a");n.href=e,n.download=t,document.body.appendChild(n),n.click(),n.remove()}async function Gn(e,t,n){Un(await Vn(e,n),t)}async function qn(e,t){try{await it();const n=await Kn(e,{pixelRatio:(t==null?void 0:t.pixelRatio)??2,backgroundColor:(t==null?void 0:t.backgroundColor)??rt,cacheBust:!0});return!n||!navigator.clipboard||typeof ClipboardItem>"u"?!1:(await navigator.clipboard.write([new ClipboardItem({"image/png":n})]),!0)}catch{return!1}}function H({variant:e="footer",version:t}){return e==="corner"?s.jsxs("div",{className:"pointer-events-none absolute bottom-3 right-3 z-10 flex items-center gap-1.5 rounded bg-bg-0/60 px-2 py-1 font-display text-[11px] tracking-wide text-fg-faint backdrop-blur-sm",children:[s.jsx("span",{className:"text-accent",children:"●"})," tokmon"]}):s.jsxs("div",{className:"flex items-center gap-2 font-display text-sm tracking-wide",children:[s.jsx("span",{className:"text-accent",children:"●"}),s.jsx("span",{className:"text-fg-bright",children:"tokmon"}),s.jsxs("span",{className:"text-xs tracking-normal text-fg-faint",children:["github.com/DavidIlie/tokmon",t?` · v${t}`:""]})]})}const Le=e=>`last ${e}`,Xn=x.forwardRef(function({derived:t,periodLabel:n,tz:a,version:r,opts:i},o){const l=t.byModel.slice(0,5),u=t.totals.cost>0,f=c=>u?c.share:c.tokenShare;return s.jsxs("div",{ref:o,className:"relative flex flex-col",style:{width:1040,height:540,background:"var(--color-bg-0)",backgroundImage:i.glow?"radial-gradient(circle at 50% -10%, color-mix(in oklab, var(--color-accent) 16%, transparent), transparent 55%), radial-gradient(var(--color-line-faint) 1px, transparent 1px)":"radial-gradient(var(--color-line-faint) 1px, transparent 1px)",backgroundSize:i.glow?"100% 100%, 24px 24px":"24px 24px",fontFamily:"var(--font-mono)",color:"var(--color-fg)"},children:[s.jsxs("div",{className:"flex items-baseline gap-2 border-b border-line px-6 py-3.5",children:[s.jsx("span",{className:"font-display text-sm tracking-wide text-accent",children:"tokmon"}),s.jsxs("span",{className:"text-sm text-fg-dim",children:["usage · ",Le(n)]}),s.jsx("span",{className:"ml-auto text-xs text-fg-faint",children:a})]}),s.jsxs("div",{className:"flex flex-1 gap-9 px-9 py-7",children:[s.jsxs("div",{className:"flex w-[300px] shrink-0 flex-col",children:[s.jsx("div",{className:"font-display text-xs uppercase tracking-widest text-fg-faint",children:u?"total spend":"total tokens"}),s.jsx("div",{className:"tnum mt-1 text-cost",style:{fontSize:64,lineHeight:1},children:u?O(t.totals.cost):K(t.totals.tokens)}),s.jsxs("div",{className:"mt-auto flex flex-col gap-3",children:[u?s.jsx(te,{label:"tokens",value:K(t.totals.tokens)}):s.jsx(te,{label:"spend",value:O(t.totals.cost)}),s.jsx(te,{label:"cache saved",value:O(t.totals.cacheSavings),className:"text-positive"}),s.jsx(te,{label:"calls",value:xt(t.totals.calls)})]})]}),s.jsxs("div",{className:"flex flex-1 flex-col gap-2 border-l border-line pl-9",children:[s.jsxs("div",{className:"font-display text-xs uppercase tracking-widest text-fg-faint",children:["top models · ",Le(n)]}),l.length===0?s.jsx("div",{className:"flex flex-1 items-center text-sm text-fg-faint",children:"no model usage in range"}):l.map(c=>s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("span",{className:"size-2 shrink-0 rounded-[2px]",style:{background:c.color}}),s.jsx("span",{className:"w-28 shrink-0 truncate text-sm text-fg",children:Be(c.model)}),s.jsx("span",{className:"h-1.5 flex-1 overflow-hidden rounded-full bg-bg-3",children:s.jsx("span",{className:"block h-full rounded-full",style:{width:`${Math.min(100,f(c)*100)}%`,minWidth:2,background:c.color}})}),s.jsx("span",{className:"tnum w-10 shrink-0 text-right text-xs text-fg-faint",children:gt(f(c))}),s.jsx("span",{className:"tnum w-20 shrink-0 text-right text-sm text-cost",children:u?O(c.cost):K(c.tokens)})]},c.model))]})]}),s.jsx("div",{className:"border-t border-line px-9 pt-3",children:s.jsx(yt,{data:t.timeline.map(c=>c.total),color:"var(--color-accent)",className:"text-2xl tracking-tight"})}),s.jsxs("div",{className:"flex items-center justify-between border-t border-line px-9 py-3.5",children:[i.wmPos==="footer"?s.jsx(H,{variant:"footer",version:r}):s.jsx("span",{className:"text-xs text-fg-faint",children:"tokmon"}),s.jsx("span",{className:"text-xs text-fg-faint",children:n})]}),i.wmPos==="corner"&&s.jsx(H,{variant:"corner"})]})});function te({label:e,value:t,className:n="text-fg-bright"}){return s.jsxs("div",{children:[s.jsx("div",{className:"text-[11px] uppercase tracking-wide text-fg-faint",children:e}),s.jsx("div",{className:`tnum mt-1 truncate text-xl ${n}`,children:t})]})}function W(e){"@babel/helpers - typeof";return W=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},W(e)}function Zn(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function Jn(e,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,lt(a.key),a)}}function Yn(e,t,n){return t&&Jn(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e}function Qn(e,t,n){return t=oe(t),ea(e,st()?Reflect.construct(t,n||[],oe(e).constructor):t.apply(e,n))}function ea(e,t){if(t&&(W(t)==="object"||typeof t=="function"))return t;if(t!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return ta(e)}function ta(e){if(e===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function st(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return(st=function(){return!!e})()}function oe(e){return oe=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(n){return n.__proto__||Object.getPrototypeOf(n)},oe(e)}function na(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&xe(e,t)}function xe(e,t){return xe=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(a,r){return a.__proto__=r,a},xe(e,t)}function ot(e,t,n){return t=lt(t),t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function lt(e){var t=aa(e,"string");return W(t)=="symbol"?t:t+""}function aa(e,t){if(W(e)!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var a=n.call(e,t);if(W(a)!="object")return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}var ue=(function(e){function t(){return Zn(this,t),Qn(this,t,arguments)}return na(t,e),Yn(t,[{key:"render",value:function(){return null}}])})(x.Component);ot(ue,"displayName","ZAxis");ot(ue,"defaultProps",{zAxisId:0,range:[64,64],scale:"auto",type:"number"});var ra=["option","isActive"];function J(){return J=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var a in n)Object.prototype.hasOwnProperty.call(n,a)&&(e[a]=n[a])}return e},J.apply(this,arguments)}function ia(e,t){if(e==null)return{};var n=sa(e,t),a,r;if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r<i.length;r++)a=i[r],!(t.indexOf(a)>=0)&&Object.prototype.propertyIsEnumerable.call(e,a)&&(n[a]=e[a])}return n}function sa(e,t){if(e==null)return{};var n={};for(var a in e)if(Object.prototype.hasOwnProperty.call(e,a)){if(t.indexOf(a)>=0)continue;n[a]=e[a]}return n}function oa(e){var t=e.option,n=e.isActive,a=ia(e,ra);return typeof t=="string"?x.createElement(Ee,J({option:x.createElement(Nt,J({type:t},a)),isActive:n,shapeType:"symbols"},a)):x.createElement(Ee,J({option:t,isActive:n,shapeType:"symbols"},a))}function V(e){"@babel/helpers - typeof";return V=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},V(e)}function Y(){return Y=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var a in n)Object.prototype.hasOwnProperty.call(n,a)&&(e[a]=n[a])}return e},Y.apply(this,arguments)}function Fe(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable})),n.push.apply(n,a)}return n}function C(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?Fe(Object(n),!0).forEach(function(a){R(e,a,n[a])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Fe(Object(n)).forEach(function(a){Object.defineProperty(e,a,Object.getOwnPropertyDescriptor(n,a))})}return e}function la(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function ze(e,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,ut(a.key),a)}}function ca(e,t,n){return t&&ze(e.prototype,t),n&&ze(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function ua(e,t,n){return t=le(t),fa(e,ct()?Reflect.construct(t,n||[],le(e).constructor):t.apply(e,n))}function fa(e,t){if(t&&(V(t)==="object"||typeof t=="function"))return t;if(t!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return da(e)}function da(e){if(e===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function ct(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return(ct=function(){return!!e})()}function le(e){return le=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(n){return n.__proto__||Object.getPrototypeOf(n)},le(e)}function ma(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&ge(e,t)}function ge(e,t){return ge=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(a,r){return a.__proto__=r,a},ge(e,t)}function R(e,t,n){return t=ut(t),t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function ut(e){var t=pa(e,"string");return V(t)=="symbol"?t:t+""}function pa(e,t){if(V(e)!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var a=n.call(e,t);if(V(a)!="object")return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}var fe=(function(e){function t(){var n;la(this,t);for(var a=arguments.length,r=new Array(a),i=0;i<a;i++)r[i]=arguments[i];return n=ua(this,t,[].concat(r)),R(n,"state",{isAnimationFinished:!1}),R(n,"handleAnimationEnd",function(){n.setState({isAnimationFinished:!0})}),R(n,"handleAnimationStart",function(){n.setState({isAnimationFinished:!1})}),R(n,"id",Bt("recharts-scatter-")),n}return ma(t,e),ca(t,[{key:"renderSymbolsStatically",value:function(a){var r=this,i=this.props,o=i.shape,l=i.activeShape,u=i.activeIndex,f=me(this.props,!1);return a.map(function(c,d){var h=u===d,p=h?l:o,b=C(C({},f),c);return k.createElement(q,Y({className:"recharts-scatter-symbol",key:"symbol-".concat(c==null?void 0:c.cx,"-").concat(c==null?void 0:c.cy,"-").concat(c==null?void 0:c.size,"-").concat(d)},Ot(r.props,c,d),{role:"img"}),k.createElement(oa,Y({option:p,isActive:h,key:"symbol-".concat(d)},b)))})}},{key:"renderSymbolsWithAnimation",value:function(){var a=this,r=this.props,i=r.points,o=r.isAnimationActive,l=r.animationBegin,u=r.animationDuration,f=r.animationEasing,c=r.animationId,d=this.state.prevPoints;return k.createElement(Rt,{begin:l,duration:u,isActive:o,easing:f,from:{t:0},to:{t:1},key:"pie-".concat(c),onAnimationEnd:this.handleAnimationEnd,onAnimationStart:this.handleAnimationStart},function(h){var p=h.t,b=i.map(function(g,w){var y=d&&d[w];if(y){var j=ee(y.cx,g.cx),m=ee(y.cy,g.cy),E=ee(y.size,g.size);return C(C({},g),{},{cx:j(p),cy:m(p),size:E(p)})}var v=ee(0,g.size);return C(C({},g),{},{size:v(p)})});return k.createElement(q,null,a.renderSymbolsStatically(b))})}},{key:"renderSymbols",value:function(){var a=this.props,r=a.points,i=a.isAnimationActive,o=this.state.prevPoints;return i&&r&&r.length&&(!o||!Tt(o,r))?this.renderSymbolsWithAnimation():this.renderSymbolsStatically(r)}},{key:"renderErrorBar",value:function(){var a=this.props.isAnimationActive;if(a&&!this.state.isAnimationFinished)return null;var r=this.props,i=r.points,o=r.xAxis,l=r.yAxis,u=r.children,f=He(u,$t);return f?f.map(function(c,d){var h=c.props,p=h.direction,b=h.dataKey;return k.cloneElement(c,{key:"".concat(p,"-").concat(b,"-").concat(i[d]),data:i,xAxis:o,yAxis:l,layout:p==="x"?"vertical":"horizontal",dataPointFormatter:function(w,y){return{x:w.cx,y:w.cy,value:p==="x"?+w.node.x:+w.node.y,errorVal:re(w,y)}}})}):null}},{key:"renderLine",value:function(){var a=this.props,r=a.points,i=a.line,o=a.lineType,l=a.lineJointType,u=me(this.props,!1),f=me(i,!1),c,d;if(o==="joint")c=r.map(function(m){return{x:m.cx,y:m.cy}});else if(o==="fitting"){var h=_t(r),p=h.xmin,b=h.xmax,g=h.a,w=h.b,y=function(E){return g*E+w};c=[{x:p,y:y(p)},{x:b,y:y(b)}]}var j=C(C(C({},u),{},{fill:"none",stroke:u&&u.fill},f),{},{points:c});return k.isValidElement(i)?d=k.cloneElement(i,j):It(i)?d=i(j):d=k.createElement(Lt,Y({},j,{type:l})),k.createElement(q,{className:"recharts-scatter-line",key:"recharts-scatter-line"},d)}},{key:"render",value:function(){var a=this.props,r=a.hide,i=a.points,o=a.line,l=a.className,u=a.xAxis,f=a.yAxis,c=a.left,d=a.top,h=a.width,p=a.height,b=a.id,g=a.isAnimationActive;if(r||!i||!i.length)return null;var w=this.state.isAnimationFinished,y=Ft("recharts-scatter",l),j=u&&u.allowDataOverflow,m=f&&f.allowDataOverflow,E=j||m,v=B(b)?this.id:b;return k.createElement(q,{className:y,clipPath:E?"url(#clipPath-".concat(v,")"):null},j||m?k.createElement("defs",null,k.createElement("clipPath",{id:"clipPath-".concat(v)},k.createElement("rect",{x:j?c:c-h/2,y:m?d:d-p/2,width:j?h:h*2,height:m?p:p*2}))):null,o&&this.renderLine(),this.renderErrorBar(),k.createElement(q,{key:"recharts-scatter-symbols"},this.renderSymbols()),(!g||w)&&zt.renderCallByParent(this.props,i))}}],[{key:"getDerivedStateFromProps",value:function(a,r){return a.animationId!==r.prevAnimationId?{prevAnimationId:a.animationId,curPoints:a.points,prevPoints:r.curPoints}:a.points!==r.curPoints?{curPoints:a.points}:null}}])})(x.PureComponent);R(fe,"displayName","Scatter");R(fe,"defaultProps",{xAxisId:0,yAxisId:0,zAxisId:0,legendType:"circle",lineType:"joint",lineJointType:"linear",data:[],shape:"circle",hide:!1,isAnimationActive:!Dt.isSsr,animationBegin:0,animationDuration:400,animationEasing:"linear"});R(fe,"getComposedData",function(e){var t=e.xAxis,n=e.yAxis,a=e.zAxis,r=e.item,i=e.displayedData,o=e.xAxisTicks,l=e.yAxisTicks,u=e.offset,f=r.props.tooltipType,c=He(r.props.children,Mt),d=B(t.dataKey)?r.props.dataKey:t.dataKey,h=B(n.dataKey)?r.props.dataKey:n.dataKey,p=a&&a.dataKey,b=a?a.range:ue.defaultProps.range,g=b&&b[0],w=t.scale.bandwidth?t.scale.bandwidth():0,y=n.scale.bandwidth?n.scale.bandwidth():0,j=i.map(function(m,E){var v=re(m,d),U=re(m,h),S=!B(p)&&re(m,p)||"-",$=[{name:B(t.dataKey)?r.props.name:t.name||t.dataKey,unit:t.unit||"",value:v,payload:m,dataKey:d,type:f},{name:B(n.dataKey)?r.props.name:n.name||n.dataKey,unit:n.unit||"",value:U,payload:m,dataKey:h,type:f}];S!=="-"&&$.push({name:a.name||a.dataKey,unit:a.unit||"",value:S,payload:m,dataKey:p,type:f});var _=Ce({axis:t,ticks:o,bandSize:w,entry:m,index:E,dataKey:d}),I=Ce({axis:n,ticks:l,bandSize:y,entry:m,index:E,dataKey:h}),L=S!=="-"?a.scale(S):g,F=Math.sqrt(Math.max(L,0)/Math.PI);return C(C({},m),{},{cx:_,cy:I,x:_-F,y:I-F,xAxis:t,yAxis:n,zAxis:a,width:2*F,height:2*F,size:L,node:{x:v,y:U,z:S},tooltipPayload:$,tooltipPosition:{x:_,y:I},payload:m},c&&c[E]&&c[E].props)});return C({points:j},u)});var ha=Kt({chartName:"ComposedChart",GraphicalChild:[Gt,Ge,Ue,fe],axisComponents:[{axisType:"xAxis",AxisComp:We},{axisType:"yAxis",AxisComp:Ve},{axisType:"zAxis",AxisComp:ue}],formatAxisMap:Ht});const De=e=>e.name&&e.name!==e.provider?`${e.provider} · ${e.name}`:e.provider,xa=x.forwardRef(function({source:t,opts:n},a){const i=Ke().appearance.preset,o=z(i,0,bt(t.model)),l=vt(t.totals),u=ga(t.accounts),f=Math.max(...t.daily.map(c=>c.cost),0);return s.jsxs("div",{ref:a,className:"relative flex flex-col overflow-hidden",style:{width:900,height:540,background:"var(--color-bg-0)",backgroundImage:n.glow?`radial-gradient(circle at 42% -12%, color-mix(in oklab, ${o} 18%, transparent), transparent 58%), radial-gradient(var(--color-line-faint) 1px, transparent 1px)`:"radial-gradient(var(--color-line-faint) 1px, transparent 1px)",backgroundSize:n.glow?"100% 100%, 24px 24px":"24px 24px",fontFamily:"var(--font-mono)",color:"var(--color-fg)"},children:[s.jsxs("div",{className:"flex items-baseline gap-2 border-b border-line px-6 py-3.5",children:[s.jsx("span",{className:"font-display text-sm tracking-wide text-accent",children:"tokmon"}),s.jsxs("span",{className:"text-sm text-fg-dim",children:["model spotlight · ",t.periodLabel]}),s.jsx("span",{className:"ml-auto text-xs text-fg-faint",children:t.tz})]}),s.jsxs("div",{className:"grid flex-1 grid-cols-[340px_1fr] gap-7 px-8 py-6",children:[s.jsxs("section",{className:"flex min-w-0 flex-col",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"size-2.5 shrink-0 rounded-[3px]",style:{background:o}}),s.jsx("span",{className:"font-display text-xs uppercase tracking-widest text-fg-faint",children:"model"})]}),s.jsxs("div",{className:"mt-3 min-h-[132px]",children:[s.jsx("div",{className:"break-words font-display text-[46px] leading-[0.98]",style:{color:o},children:Be(t.model)}),s.jsx("div",{className:"mt-2 truncate text-xs text-fg-faint",title:t.model,children:t.model})]}),s.jsxs("div",{className:"mt-auto grid grid-cols-2 gap-x-5 gap-y-4",children:[s.jsx(ne,{label:"spend",value:O(t.totals.cost),className:"text-cost"}),s.jsx(ne,{label:"tokens",value:K(l)}),s.jsx(ne,{label:"calls",value:Se(t.totals.count)}),s.jsx(ne,{label:"accounts",value:Se(t.accounts.length)})]})]}),s.jsxs("section",{className:"flex min-w-0 flex-col gap-4 border-l border-line pl-7",children:[s.jsxs("div",{className:"grid grid-cols-4 gap-2",children:[s.jsx(ae,{label:"input",value:t.totals.input,color:z(i,1,Q.input)}),s.jsx(ae,{label:"output",value:t.totals.output,color:z(i,2,Q.output)}),s.jsx(ae,{label:"cache create",value:t.totals.cacheCreate,color:z(i,3,Q.cacheCreate)}),s.jsx(ae,{label:"cache read",value:t.totals.cacheRead,color:z(i,4,Q.cacheRead)})]}),s.jsxs("div",{children:[s.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[s.jsx("span",{className:"font-display text-xs uppercase tracking-widest text-fg-faint",children:"account split"}),s.jsx("span",{className:"tnum text-xs text-fg-faint",children:O(t.totals.cost)})]}),s.jsx("div",{className:"flex flex-col gap-1.5",children:u.length===0?s.jsx("div",{className:"rounded border border-line bg-bg-1 px-3 py-5 text-center text-xs text-fg-faint",children:"no usage in range"}):u.map((c,d)=>{const h=t.totals.cost>0?c.cost/t.totals.cost*100:0,p=z(i,d+1,c.color);return s.jsxs("div",{className:"grid grid-cols-[minmax(0,1fr)_76px_78px] items-center gap-3 text-xs",children:[s.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:"size-2 shrink-0 rounded-[2px]",style:{background:p}}),s.jsx("span",{className:"truncate text-fg-dim",title:c.providerId==="other"?c.name:De(c),children:c.providerId==="other"?c.name:De(c)})]}),s.jsx("span",{className:"tnum text-right text-cost",children:O(c.cost)}),s.jsx("span",{className:"tnum text-right text-fg-faint",children:K(c.tokens)}),s.jsx("span",{className:"col-span-3 h-1 overflow-hidden rounded-full bg-bg-3",children:s.jsx("span",{className:"block h-full rounded-full",style:{width:`${Math.min(100,h)}%`,minWidth:c.cost>0?2:0,background:p}})})]},`${c.providerId}:${c.name}`)})})]}),s.jsxs("div",{className:"mt-auto",children:[s.jsxs("div",{className:"mb-1.5 flex items-center justify-between",children:[s.jsx("span",{className:"font-display text-xs uppercase tracking-widest text-fg-faint",children:"daily cost"}),s.jsxs("span",{className:"tnum text-xs text-fg-faint",children:["peak ",O(f)]})]}),s.jsx("div",{className:"h-[118px] rounded border border-line bg-bg-1/50 px-2 py-2",children:t.daily.length===0?s.jsx("div",{className:"flex h-full items-center justify-center text-xs text-fg-faint",children:"no daily usage"}):s.jsx(Wt,{children:s.jsxs(ha,{data:t.daily,margin:{top:8,right:10,left:2,bottom:0},children:[s.jsx(Vt,{...Ut}),s.jsx(We,{dataKey:"day",tick:{fill:"var(--color-fg-faint)",fontSize:9,fontFamily:"var(--font-mono)"},tickLine:!1,axisLine:!1,minTickGap:22,tickFormatter:wt}),s.jsx(Ve,{hide:!0,tickFormatter:jt,domain:[0,"dataMax"]}),s.jsx(Ge,{type:"monotone",dataKey:"cost",stroke:o,fill:o,fillOpacity:.14,strokeWidth:1.5,dot:!1,isAnimationActive:!1}),s.jsx(Ue,{dataKey:"cost",fill:o,opacity:.38,radius:[2,2,0,0],isAnimationActive:!1})]})})})]})]})]}),s.jsxs("div",{className:"flex items-center justify-between border-t border-line px-8 py-3.5",children:[n.wmPos==="footer"?s.jsx(H,{variant:"footer",version:t.version}):s.jsx("span",{className:"text-xs text-fg-faint",children:"tokmon"}),s.jsx("span",{className:"text-xs text-fg-faint",children:t.periodLabel})]}),n.wmPos==="corner"&&s.jsx(H,{variant:"corner"})]})});function ne({label:e,value:t,className:n="text-fg-bright"}){return s.jsxs("div",{children:[s.jsx("div",{className:"font-display text-[10px] uppercase tracking-wide text-fg-faint",children:e}),s.jsx("div",{className:`tnum mt-1 truncate text-2xl ${n}`,children:t})]})}function ae({label:e,value:t,color:n}){return s.jsxs("div",{className:"min-w-0 rounded border border-line bg-bg-1 px-2 py-2",children:[s.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] uppercase tracking-wide text-fg-faint",children:[s.jsx("span",{className:"size-1.5 shrink-0 rounded-[2px]",style:{background:n}}),s.jsx("span",{className:"truncate",children:e})]}),s.jsx("div",{className:"tnum mt-1 truncate text-sm text-fg-bright",children:K(t)})]})}function ga(e){if(e.length<=6)return e;const t=e.slice(0,5),n=e.slice(5),a=n.reduce((r,i)=>({...r,tokens:r.tokens+i.tokens,cost:r.cost+i.cost}),{name:`${n.length} more accounts`,color:"var(--color-fg-faint)",provider:"Other",providerId:"other",tokens:0,cost:0});return[...t,a]}const ya=x.forwardRef(function({node:t,title:n,framed:a,wmPos:r},i){const o=x.useRef(null);return x.useEffect(()=>{const l=o.current;if(!l)return;l.innerHTML="";const u=t.cloneNode(!0);return u.querySelectorAll("[data-chrome]").forEach(f=>f.remove()),u.style.width=`${Math.round(t.getBoundingClientRect().width)}px`,u.classList.remove("hover:border-line-2"),l.appendChild(u),()=>{l.innerHTML=""}},[t]),s.jsxs("div",{ref:i,className:"relative",style:{background:"var(--color-bg-0)",backgroundImage:"radial-gradient(var(--color-line-faint) 1px, transparent 1px)",backgroundSize:"24px 24px",padding:a?28:16,fontFamily:"var(--font-mono)"},children:[a&&s.jsxs("div",{className:"mb-3 flex items-baseline gap-2",children:[s.jsx("span",{className:"font-display text-xs tracking-wide text-accent",children:"tokmon"}),s.jsxs("span",{className:"font-display text-xs uppercase tracking-wider text-fg-dim",children:["/ ",n]})]}),s.jsx("div",{ref:o}),r==="footer"?s.jsx("div",{className:"mt-3 flex justify-end",children:s.jsx(H,{variant:"footer"})}):s.jsx(H,{variant:"corner"})]})}),ba=600,Me=360,va=e=>e.toLowerCase().replace(/[^a-z0-9._-]+/g,"-").replace(/^-+|-+$/g,"")||"model";function Pa({source:e,onClose:t}){const n=Ke(),a=e.kind==="summary",r=e.kind==="model",i=a||r,o=x.useRef(null),l=x.useRef(null),u=x.useRef(),[f,c]=x.useState(()=>n.resolved.mode),[d,h]=x.useState(i?"footer":"corner"),[p,b]=x.useState("2"),[g,w]=x.useState(!0),[y,j]=x.useState(!0),[m,E]=x.useState({w:a?1040:r?900:700,h:i?540:360}),[v,U]=x.useState(null),[S,$]=x.useState(null);x.useEffect(()=>()=>{u.current&&clearTimeout(u.current)},[]);const _=N=>{U(N),u.current&&clearTimeout(u.current),u.current=setTimeout(()=>U(null),1600)};x.useEffect(()=>{const N=o.current;if(!N)return;const de=()=>E(je=>({w:N.offsetWidth||je.w,h:N.offsetHeight||je.h}));de();const we=new ResizeObserver(de);we.observe(N);const ht=setTimeout(de,80);return()=>{we.disconnect(),clearTimeout(ht)}},[e,y,d,f,g]);const I=Math.min(ba/m.w,Me/m.h,1),L=x.useMemo(()=>St({...n.appearance,mode:f},f==="dark"),[n.appearance,f]),F=x.useMemo(()=>kt(L.tokens),[L.tokens]),ve={pixelRatio:Number(p),backgroundColor:L.tokens.canvas},ft=Wn(a?"summary":r?`model-${va(e.model)}`:e.captureName),dt=async()=>{if(!(!o.current||S)){$("download");try{await Gn(o.current,ft,ve),_("dl")}catch{_("fail")}finally{$(null)}}},mt=async()=>{if(!(!o.current||S)){$("copy");try{_(await qn(o.current,ve)?"copy":"fail")}finally{$(null)}}},pt=S==="download"?"Creating PNG…":S==="copy"?"Copying image…":v==="dl"?"PNG downloaded.":v==="copy"?"Image copied.":v==="fail"?"Image export failed. Try downloading instead.":"";return s.jsxs(Ct,{onClose:t,labelledBy:"share-title",initialFocusRef:l,className:"flex max-h-[88vh] w-full max-w-[720px] flex-col",children:[s.jsx("h2",{id:"share-title",className:"pointer-events-none absolute left-3 top-2 font-display text-[11px] uppercase tracking-wider text-fg-dim",children:"share"}),s.jsx("div",{className:"flex items-center justify-center bg-bg-0 px-6 pb-5 pt-9",style:{minHeight:Me+24},children:s.jsx("div",{className:"overflow-hidden rounded",style:{width:m.w*I,height:m.h*I},children:s.jsx("div",{style:{width:m.w,height:m.h,transform:`scale(${I})`,transformOrigin:"top left"},children:s.jsx("div",{className:L.mode,"data-theme-preset":n.appearance.preset,style:F,children:a?s.jsx(Xn,{ref:o,derived:e.derived,periodLabel:e.periodLabel,tz:e.tz,version:e.version,opts:{glow:g,wmPos:d}}):r?s.jsx(xa,{ref:o,source:e,opts:{glow:g,wmPos:d}}):s.jsx(ya,{ref:o,node:e.node,title:e.captureName,framed:y,wmPos:d})})})})}),s.jsxs("div",{className:"flex flex-wrap items-center gap-x-4 gap-y-2 border-t border-line px-4 py-3 text-[11px]",children:[s.jsx(Z,{label:"theme",children:s.jsx(G,{size:"xs",containerClassName:X,ariaLabel:"export theme",options:ke(n.appearance.preset)?[{value:"dark",label:"dark"}]:[{value:"dark",label:"dark"},{value:"light",label:"light"}],value:ke(n.appearance.preset)?"dark":f,onChange:c})}),s.jsx(Z,{label:"mark",children:s.jsx(G,{size:"xs",containerClassName:X,ariaLabel:"watermark position",options:[{value:"footer",label:"footer"},{value:"corner",label:"corner"}],value:d,onChange:h})}),i?s.jsx(Z,{label:"glow",children:s.jsx(G,{size:"xs",containerClassName:X,ariaLabel:"accent glow",options:[{value:"on",label:"on"},{value:"off",label:"off"}],value:g?"on":"off",onChange:N=>w(N==="on")})}):s.jsx(Z,{label:"frame",children:s.jsx(G,{size:"xs",containerClassName:X,ariaLabel:"frame",options:[{value:"framed",label:"framed"},{value:"bare",label:"bare"}],value:y?"framed":"bare",onChange:N=>j(N==="framed")})}),s.jsx(Z,{label:"scale",children:s.jsx(G,{size:"xs",containerClassName:X,ariaLabel:"export scale",options:[{value:"1",label:"1x"},{value:"2",label:"2x"},{value:"3",label:"3x"}],value:p,onChange:b})}),s.jsxs("span",{className:"ml-auto tnum text-fg-faint",children:[m.w," × ",m.h," · ",p,"x"]})]}),s.jsxs("div",{className:"flex items-center justify-end gap-2 border-t border-line px-4 py-3",children:[s.jsx("span",{className:"mr-auto text-xs text-fg-faint",role:"status","aria-live":"polite",children:pt}),s.jsxs(Ae,{variant:"secondary",onClick:mt,disabled:S!==null,children:[v==="copy"?s.jsx(Pe,{className:"size-3.5 text-positive"}):v==="fail"?s.jsx(Pt,{className:"size-3.5 text-critical"}):s.jsx(At,{className:"size-3.5"})," ",S==="copy"?"copying…":v==="copy"?"copied":v==="fail"?"copy failed":"copy"]}),s.jsxs(Ae,{variant:"primary",ref:l,onClick:dt,disabled:S!==null,children:[v==="dl"?s.jsx(Pe,{className:"size-3.5 text-positive"}):s.jsx(Et,{className:"size-3.5"})," ",S==="download"?"downloading…":"download PNG"]})]})]})}const X="flex items-center overflow-hidden rounded border border-line text-[10px]";function Z({label:e,children:t}){return s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"text-fg-faint",children:e}),t]})}export{Pa as ShareSheet};
@@ -1 +1 @@
1
- import{j as t,E as C,l as h,m as A,f as l,r as L,n as E}from"./index-RDhXsCNG.js";import{g as R,X as c,Y as d,f as M,u as b,C as k,R as T,a as u,G as v,A as n,T as j,b as g,s as S,m as Y}from"./chart-D0CtuL2k.js";import{P as N}from"./panel-xckM3_GC.js";import{L as O,A as G}from"./Area-stRnp8Km.js";var I=R({chartName:"LineChart",GraphicalChild:O,axisComponents:[{axisType:"xAxis",AxisComp:c},{axisType:"yAxis",AxisComp:d}],formatAxisMap:M}),W=R({chartName:"AreaChart",GraphicalChild:G,axisComponents:[{axisType:"xAxis",AxisComp:c},{axisType:"yAxis",AxisComp:d}],formatAxisMap:M});const _=[{value:"linear",label:"lin"},{value:"log",label:"log"}],B=[{value:"combined",label:"merged"},{value:"byProvider",label:"split"}],F="flex items-center overflow-hidden rounded border border-line text-[10px]",H=Y(a=>{const s=a.filter(e=>e.dataKey!=="total"&&(e.value??0)>0).map(e=>({label:String(e.name??e.dataKey),value:l(e.value??0),color:e.color})),r=a.reduce((e,o)=>e+(o.dataKey==="total"?0:o.value??0),0);return s.length>1&&s.push({label:"total",value:l(r),color:"var(--color-fg-bright)"}),s}),U=S("total",l,"var(--color-cost)");function tt({derived:a,title:s="cost over time",height:r=260,periodLabel:e,heightClass:o}){const x=b(),K=a.byProvider,P=K.length>1,[m,X]=L.useState("linear"),[w,z]=L.useState(P?"byProvider":"combined"),f=a.timeline.map(i=>{const p={date:i.date,total:i.total,...i.byProvider};if(m==="log")for(const y of Object.keys(p))y!=="date"&&p[y]===0&&(p[y]=null);return p}),D=t.jsx(d,{...n,width:52,tickFormatter:A,scale:m,allowDataOverflow:m==="log",domain:m==="log"?[.1,"auto"]:[0,"auto"]});return t.jsx(N,{title:s,titleTag:e,captureName:"cost-over-time",right:t.jsxs("div",{className:"flex items-center gap-1.5",children:[P&&t.jsx(E,{options:B,value:w,onChange:z,size:"xs",containerClassName:F,ariaLabel:"combine providers"}),t.jsx(E,{options:_,value:m,onChange:X,size:"xs",containerClassName:F,ariaLabel:"value scale"})]}),children:f.length===0?t.jsx(C,{children:"no spend in period"}):t.jsx(k,{height:r,heightClass:o,children:t.jsx(T,{children:w==="combined"?t.jsxs(W,{data:f,margin:{top:8,right:8,left:0,bottom:0},children:[t.jsx("defs",{children:t.jsxs("linearGradient",{id:"g-cost",x1:"0",y1:"0",x2:"0",y2:"1",children:[t.jsx("stop",{offset:"0%",stopColor:"var(--color-cost)",stopOpacity:.16}),t.jsx("stop",{offset:"100%",stopColor:"var(--color-cost)",stopOpacity:.02})]})}),t.jsx(u,{...v}),t.jsx(c,{dataKey:"date",...n,tickFormatter:h,minTickGap:28}),D,t.jsx(j,{content:U,cursor:g}),t.jsx(G,{type:"monotone",dataKey:"total",stroke:"var(--color-cost)",strokeWidth:1.8,fill:"url(#g-cost)",connectNulls:!0,isAnimationActive:x,animationDuration:350})]}):t.jsxs(I,{data:f,margin:{top:8,right:8,left:0,bottom:0},children:[t.jsx(u,{...v}),t.jsx(c,{dataKey:"date",...n,tickFormatter:h,minTickGap:28}),D,t.jsx(j,{content:H,cursor:g}),K.map(i=>t.jsx(O,{type:"monotone",dataKey:i.id,name:i.name,stroke:i.color,strokeWidth:1.6,dot:!1,connectNulls:!0,isAnimationActive:x,animationDuration:350},i.id))]})})})})}const q=S("cumulative",l,"var(--color-cost)");function et({derived:a,height:s=220,periodLabel:r}){const e=b(),o=a.cumulative;return t.jsx(N,{title:"cumulative spend",titleTag:r,captureName:"cumulative",children:o.length===0?t.jsx(C,{children:"no spend in period"}):t.jsx(k,{height:s,children:t.jsx(T,{children:t.jsxs(I,{data:o,margin:{top:8,right:8,left:0,bottom:0},children:[t.jsx(u,{...v}),t.jsx(c,{dataKey:"date",...n,tickFormatter:h,minTickGap:28}),t.jsx(d,{...n,width:52,tickFormatter:A}),t.jsx(j,{content:q,cursor:g}),t.jsx(O,{type:"monotone",dataKey:"total",stroke:"var(--color-cost)",strokeWidth:1.8,dot:!1,isAnimationActive:e,animationDuration:350})]})})})})}const J=S("cache saved",l,"var(--color-positive)");function at({derived:a,height:s=220,periodLabel:r}){const e=b(),o=a.cacheSavingsSeries,x=a.totals.cacheSavings;return t.jsx(N,{title:"cache savings",titleTag:r,captureName:"cache-savings",right:t.jsx("span",{className:"tnum text-xs text-positive",children:l(x)}),children:o.length===0?t.jsx(C,{children:"no cache reads in period"}):t.jsx(k,{height:s,children:t.jsx(T,{children:t.jsxs(W,{data:o,margin:{top:8,right:8,left:0,bottom:0},children:[t.jsx("defs",{children:t.jsxs("linearGradient",{id:"g-save",x1:"0",y1:"0",x2:"0",y2:"1",children:[t.jsx("stop",{offset:"0%",stopColor:"var(--color-positive)",stopOpacity:.18}),t.jsx("stop",{offset:"100%",stopColor:"var(--color-positive)",stopOpacity:.02})]})}),t.jsx(u,{...v}),t.jsx(c,{dataKey:"date",...n,tickFormatter:h,minTickGap:28}),t.jsx(d,{...n,width:52,tickFormatter:A}),t.jsx(j,{content:J,cursor:g}),t.jsx(G,{type:"monotone",dataKey:"value",stroke:"var(--color-positive)",strokeWidth:1.6,fill:"url(#g-save)",isAnimationActive:e,animationDuration:350})]})})})})}export{at as CacheSavings,tt as CostTimeline,et as CumulativeSpend};
1
+ import{j as t,E as C,l as h,m as A,f as l,r as L,n as E}from"./index-9hkGpa7j.js";import{g as R,X as c,Y as d,f as M,u as b,C as k,R as T,a as u,G as v,A as n,T as j,b as g,s as S,m as Y}from"./chart-Duz9D-nH.js";import{P as N}from"./panel-gxLFBb8y.js";import{L as O,A as G}from"./Area-BqyvRn2x.js";var I=R({chartName:"LineChart",GraphicalChild:O,axisComponents:[{axisType:"xAxis",AxisComp:c},{axisType:"yAxis",AxisComp:d}],formatAxisMap:M}),W=R({chartName:"AreaChart",GraphicalChild:G,axisComponents:[{axisType:"xAxis",AxisComp:c},{axisType:"yAxis",AxisComp:d}],formatAxisMap:M});const _=[{value:"linear",label:"lin"},{value:"log",label:"log"}],B=[{value:"combined",label:"merged"},{value:"byProvider",label:"split"}],F="flex items-center overflow-hidden rounded border border-line text-[10px]",H=Y(a=>{const s=a.filter(e=>e.dataKey!=="total"&&(e.value??0)>0).map(e=>({label:String(e.name??e.dataKey),value:l(e.value??0),color:e.color})),r=a.reduce((e,o)=>e+(o.dataKey==="total"?0:o.value??0),0);return s.length>1&&s.push({label:"total",value:l(r),color:"var(--color-fg-bright)"}),s}),U=S("total",l,"var(--color-cost)");function tt({derived:a,title:s="cost over time",height:r=260,periodLabel:e,heightClass:o}){const x=b(),K=a.byProvider,P=K.length>1,[m,X]=L.useState("linear"),[w,z]=L.useState(P?"byProvider":"combined"),f=a.timeline.map(i=>{const p={date:i.date,total:i.total,...i.byProvider};if(m==="log")for(const y of Object.keys(p))y!=="date"&&p[y]===0&&(p[y]=null);return p}),D=t.jsx(d,{...n,width:52,tickFormatter:A,scale:m,allowDataOverflow:m==="log",domain:m==="log"?[.1,"auto"]:[0,"auto"]});return t.jsx(N,{title:s,titleTag:e,captureName:"cost-over-time",right:t.jsxs("div",{className:"flex items-center gap-1.5",children:[P&&t.jsx(E,{options:B,value:w,onChange:z,size:"xs",containerClassName:F,ariaLabel:"combine providers"}),t.jsx(E,{options:_,value:m,onChange:X,size:"xs",containerClassName:F,ariaLabel:"value scale"})]}),children:f.length===0?t.jsx(C,{children:"no spend in period"}):t.jsx(k,{height:r,heightClass:o,children:t.jsx(T,{children:w==="combined"?t.jsxs(W,{data:f,margin:{top:8,right:8,left:0,bottom:0},children:[t.jsx("defs",{children:t.jsxs("linearGradient",{id:"g-cost",x1:"0",y1:"0",x2:"0",y2:"1",children:[t.jsx("stop",{offset:"0%",stopColor:"var(--color-cost)",stopOpacity:.16}),t.jsx("stop",{offset:"100%",stopColor:"var(--color-cost)",stopOpacity:.02})]})}),t.jsx(u,{...v}),t.jsx(c,{dataKey:"date",...n,tickFormatter:h,minTickGap:28}),D,t.jsx(j,{content:U,cursor:g}),t.jsx(G,{type:"monotone",dataKey:"total",stroke:"var(--color-cost)",strokeWidth:1.8,fill:"url(#g-cost)",connectNulls:!0,isAnimationActive:x,animationDuration:350})]}):t.jsxs(I,{data:f,margin:{top:8,right:8,left:0,bottom:0},children:[t.jsx(u,{...v}),t.jsx(c,{dataKey:"date",...n,tickFormatter:h,minTickGap:28}),D,t.jsx(j,{content:H,cursor:g}),K.map(i=>t.jsx(O,{type:"monotone",dataKey:i.id,name:i.name,stroke:i.color,strokeWidth:1.6,dot:!1,connectNulls:!0,isAnimationActive:x,animationDuration:350},i.id))]})})})})}const q=S("cumulative",l,"var(--color-cost)");function et({derived:a,height:s=220,periodLabel:r}){const e=b(),o=a.cumulative;return t.jsx(N,{title:"cumulative spend",titleTag:r,captureName:"cumulative",children:o.length===0?t.jsx(C,{children:"no spend in period"}):t.jsx(k,{height:s,children:t.jsx(T,{children:t.jsxs(I,{data:o,margin:{top:8,right:8,left:0,bottom:0},children:[t.jsx(u,{...v}),t.jsx(c,{dataKey:"date",...n,tickFormatter:h,minTickGap:28}),t.jsx(d,{...n,width:52,tickFormatter:A}),t.jsx(j,{content:q,cursor:g}),t.jsx(O,{type:"monotone",dataKey:"total",stroke:"var(--color-cost)",strokeWidth:1.8,dot:!1,isAnimationActive:e,animationDuration:350})]})})})})}const J=S("cache saved",l,"var(--color-positive)");function at({derived:a,height:s=220,periodLabel:r}){const e=b(),o=a.cacheSavingsSeries,x=a.totals.cacheSavings;return t.jsx(N,{title:"cache savings",titleTag:r,captureName:"cache-savings",right:t.jsx("span",{className:"tnum text-xs text-positive",children:l(x)}),children:o.length===0?t.jsx(C,{children:"no cache reads in period"}):t.jsx(k,{height:s,children:t.jsx(T,{children:t.jsxs(W,{data:o,margin:{top:8,right:8,left:0,bottom:0},children:[t.jsx("defs",{children:t.jsxs("linearGradient",{id:"g-save",x1:"0",y1:"0",x2:"0",y2:"1",children:[t.jsx("stop",{offset:"0%",stopColor:"var(--color-positive)",stopOpacity:.18}),t.jsx("stop",{offset:"100%",stopColor:"var(--color-positive)",stopOpacity:.02})]})}),t.jsx(u,{...v}),t.jsx(c,{dataKey:"date",...n,tickFormatter:h,minTickGap:28}),t.jsx(d,{...n,width:52,tickFormatter:A}),t.jsx(j,{content:J,cursor:g}),t.jsx(G,{type:"monotone",dataKey:"value",stroke:"var(--color-positive)",strokeWidth:1.6,fill:"url(#g-save)",isAnimationActive:e,animationDuration:350})]})})})})}export{at as CacheSavings,tt as CostTimeline,et as CumulativeSpend};
@@ -38,7 +38,7 @@
38
38
  document.querySelector('meta[name="theme-color"]').setAttribute('content', cache ? cache.vars['--color-bg-0'] : (mode === 'light' ? '#f4f5f5' : '#0a0a0a'))
39
39
  })()
40
40
  </script>
41
- <script type="module" crossorigin src="./assets/index-RDhXsCNG.js"></script>
41
+ <script type="module" crossorigin src="./assets/index-9hkGpa7j.js"></script>
42
42
  <link rel="stylesheet" crossorigin href="./assets/index-ZmOS8p9O.css">
43
43
  </head>
44
44
  <body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tokmon",
3
- "version": "0.28.4",
3
+ "version": "0.28.6",
4
4
  "description": "Terminal + web dashboard for Claude Code, Codex, Cursor, Grok, opencode, pi, Copilot, Gemini & more — usage, limits, and costs",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,11 +0,0 @@
1
- #!/usr/bin/env node
2
- import {
3
- attachOrSpawn
4
- } from "./chunk-FLANGRI6.js";
5
- import "./chunk-5B3XCEMC.js";
6
- import "./chunk-UYPDMVW5.js";
7
- import "./chunk-JZSZEHVD.js";
8
- import "./chunk-HNWEJ6MS.js";
9
- export {
10
- attachOrSpawn
11
- };
@@ -1,12 +0,0 @@
1
- #!/usr/bin/env node
2
- import {
3
- startWebServer
4
- } from "./chunk-P57DVFNH.js";
5
- import "./chunk-UYPDMVW5.js";
6
- import "./chunk-TN6V7XSL.js";
7
- import "./chunk-CFKUZCMB.js";
8
- import "./chunk-JZSZEHVD.js";
9
- import "./chunk-HNWEJ6MS.js";
10
- export {
11
- startWebServer
12
- };
@@ -1 +0,0 @@
1
- import{O as te,Q as ge,U as W,V as xe,j as e,r as x,F as g,n as C,W as X,Y as ve,Z as je,$ as ye,a0 as O,a1 as B,a2 as ke,a3 as Ne,e as we,P as Ce,a4 as ne,a5 as ae,a6 as le,a7 as Se,a8 as Ie,a9 as ie,X as me,aa as De,ab as Ae,ac as $e,ad as Q,ae as oe,af as ze,ag as G,ah as ce,ai as de,aj as pe,ak as be,al as H,am as Pe,an as V,ao as Z,ap as Ee,aq as Re,u as Te,ar as Le,as as Me,at as Fe,au as Oe,av as Be}from"./index-RDhXsCNG.js";import{B as M,D as he}from"./button-DrX04Cc2.js";function ue(t,a={}){return{mode:"add",editingId:null,providerId:a.providerId??te[0],name:a.name??"",homeDir:a.homeDir??"~",color:a.color??ge(t.accounts)}}function _e(t){return{mode:"edit",editingId:t.id,providerId:t.providerId,name:t.name,homeDir:t.homeDir,color:t.color||W[t.providerId].color}}function Ue(t,a){const n=t.mode==="edit"?a.filter(s=>s.id!==t.editingId):a;return t.mode==="edit"?t.editingId??"":xe(t.name.trim()||"account",n)}function Ge(t,a){const n=t.name.trim(),s=t.homeDir.trim()||"~";return n?t.mode==="add"?{ok:!0,account:{id:xe(n,a),providerId:t.providerId,name:n,homeDir:s,color:t.color},mode:"add",editingId:null}:{ok:!0,account:{id:t.editingId,providerId:t.providerId,name:n,homeDir:s,color:t.color},mode:"edit",editingId:t.editingId}:{ok:!1,error:"Name required"}}function E({title:t,right:a,children:n}){return e.jsxs("section",{className:"mb-6 last:mb-0",children:[e.jsxs("div",{className:"mb-2.5 flex items-center gap-2 border-b border-line pb-1.5",children:[e.jsx("h3",{className:"font-display text-[11px] uppercase tracking-wider text-fg-dim",children:t}),a&&e.jsx("div",{className:"ml-auto",children:a})]}),n]})}function N({label:t,hint:a,children:n}){return e.jsxs("div",{className:"flex items-center gap-3 py-1.5",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-sm text-fg",children:t}),a&&e.jsx("div",{className:"text-[11px] text-fg-faint",children:a})]}),e.jsx("div",{className:"shrink-0",children:n})]})}function q({label:t,hint:a,children:n}){return e.jsxs("div",{children:[e.jsx("div",{className:"mb-1.5 text-xs font-medium text-fg",children:t}),n,a&&e.jsx("div",{className:"mt-1 text-[11px] text-fg-faint",children:a})]})}function ee({label:t,value:a,min:n,unit:s,onChange:u}){const r=l=>u(Math.max(n,Math.round(l))),[b,h]=x.useState(null),v=()=>{if(b===null)return;const l=Number(b);r(Number.isFinite(l)&&b.trim()!==""?l:n),h(null)};return e.jsxs("div",{className:"flex items-center overflow-hidden rounded border border-line",children:[e.jsx("button",{type:"button","aria-label":"decrease",onClick:()=>r(a-1),className:`px-2 py-1 text-xs text-fg-dim transition hover:bg-bg-3 hover:text-fg ${g}`,children:"−"}),e.jsx("input",{type:"number",name:t.toLowerCase().replace(/\s+/g,"-"),autoComplete:"off",inputMode:"numeric",min:n,value:b??a,onChange:l=>{const o=l.target.value;h(o);const d=Number(o);o.trim()!==""&&Number.isFinite(d)&&d>=n&&r(d)},onBlur:v,"aria-label":`${t} (${s})`,className:`tnum w-12 border-x border-line bg-bg-2 px-1 py-1 text-center text-xs text-fg ${g} [appearance:textfield] [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none`}),e.jsx("span",{className:"px-1.5 text-[10px] text-fg-faint",children:s}),e.jsx("button",{type:"button","aria-label":"increase",onClick:()=>r(a+1),className:`px-2 py-1 text-xs text-fg-dim transition hover:bg-bg-3 hover:text-fg ${g}`,children:"+"})]})}function P({label:t,onClick:a,disabled:n,danger:s,children:u}){return e.jsx("button",{type:"button","aria-label":t,title:t,disabled:n,onClick:a,className:`rounded p-1 text-fg-faint transition disabled:opacity-30 ${g} ${s?"hover:bg-critical/15 hover:text-critical":"hover:bg-bg-3 hover:text-fg"} disabled:hover:bg-transparent disabled:hover:text-fg-faint`,children:u})}function He({draft:t,patch:a}){return e.jsxs(E,{title:"General",children:[e.jsx(N,{label:"Refresh interval",hint:"dashboard poll, seconds",children:e.jsx(ee,{label:"Refresh interval",value:t.interval,min:1,unit:"s",onChange:n=>a(s=>({...s,interval:n}))})}),e.jsx(N,{label:"Billing poll",hint:"billing refresh, minutes",children:e.jsx(ee,{label:"Billing poll",value:t.billingInterval,min:1,unit:"m",onChange:n=>a(s=>({...s,billingInterval:n}))})}),e.jsx(N,{label:"Clear screen",hint:"redraw on each refresh",children:e.jsx(C,{size:"xs",ariaLabel:"clear screen",options:[{value:"on",label:"on"},{value:"off",label:"off"}],value:t.clearScreen?"on":"off",onChange:n=>a(s=>({...s,clearScreen:n==="on"}))})}),e.jsx(N,{label:"Timezone",hint:"IANA name · empty = System",children:e.jsx(Ve,{value:t.timezone,onChange:n=>a(s=>({...s,timezone:n}))})}),e.jsx(N,{label:"Dashboard",hint:"grid shows all · single cycles",children:e.jsx(C,{size:"xs",ariaLabel:"dashboard layout",options:[{value:"grid",label:"grid"},{value:"single",label:"single"}],value:t.dashboardLayout,onChange:n=>a(s=>({...s,dashboardLayout:n}))})}),e.jsx(N,{label:"Default focus",hint:"on open",children:e.jsx(C,{size:"xs",ariaLabel:"default focus",options:[{value:"all",label:"all"},{value:"last",label:"last"}],value:t.defaultFocus,onChange:n=>a(s=>({...s,defaultFocus:n}))})}),e.jsx(N,{label:"ASCII mode",hint:"glyph fallback",children:e.jsx(C,{size:"xs",ariaLabel:"ascii mode",options:[{value:"auto",label:"auto"},{value:"on",label:"on"},{value:"off",label:"off"}],value:t.ascii,onChange:n=>a(s=>({...s,ascii:n}))})}),e.jsx(N,{label:"Network access",hint:"applies on daemon restart",children:e.jsx(C,{size:"xs",ariaLabel:"network access",options:[{value:"local",label:"local only"},{value:"network",label:"LAN"}],value:t.allowNetworkAccess?"network":"local",onChange:n=>a(s=>({...s,allowNetworkAccess:n==="network"}))})}),t.allowNetworkAccess&&e.jsxs(e.Fragment,{children:[e.jsx(N,{label:"Allowed hosts",hint:"exact DNS names · comma separated",children:e.jsx(qe,{value:t.allowedHosts,onChange:n=>a(s=>({...s,allowedHosts:n}))})}),e.jsx("p",{className:"rounded border border-critical/50 bg-critical/10 px-3 py-2 text-xs text-critical",role:"alert",children:"Unsafe: after the daemon restarts, usage data and settings will be reachable from your local network."})]}),e.jsx(N,{label:"Reset times",hint:"quota and peak changes",children:e.jsx(C,{size:"xs",ariaLabel:"reset time display",options:[{value:"relative",label:"remaining"},{value:"absolute",label:"date/time"}],value:t.resetDisplay,onChange:n=>a(s=>({...s,resetDisplay:n}))})})]})}function qe({value:t,onChange:a}){const[n,s]=x.useState(t.join(", ")),[u,r]=x.useState(!1),b=x.useId(),h=x.useRef(null),v=t.join(", ");x.useEffect(()=>{if(h.current===v){h.current=null;return}s(v),r(!1)},[v]);const l=o=>{const d=X(o);s(d);const f=d.split(",").map(p=>p.trim()).filter(Boolean).map(je),i=f.some(p=>p===null);if(r(i),!i){const p=[...new Set(f)];h.current=p.join(", "),a(p)}};return e.jsxs("div",{className:"flex flex-col items-end gap-0.5",children:[e.jsx("input",{type:"text",name:"allowed-hosts",value:n,placeholder:"tokmon.example.com","aria-label":"Allowed hosts","aria-describedby":u?b:void 0,autoComplete:"off",spellCheck:!1,"aria-invalid":u,onChange:o=>l(o.target.value),className:`w-64 rounded border bg-bg-2 px-2 py-1 text-xs text-fg ${g} ${u?"border-critical":"border-line"}`}),u&&e.jsx("span",{id:b,className:"text-[10px] text-critical",role:"alert",children:"Use exact hostnames without a scheme, port, path, or wildcard."})]})}function Ve({value:t,onChange:a}){const[n,s]=x.useState(t??""),[u,r]=x.useState(!1),b=x.useId();x.useEffect(()=>{s(t??""),r(!1)},[t]);const h=v=>{const l=X(v);s(l);const o=l.trim();if(!o){r(!1),a(null);return}ve(o)?(r(!1),a(o)):r(!0)};return e.jsxs("div",{className:"flex flex-col items-end gap-0.5",children:[e.jsx("input",{type:"text",name:"timezone",value:n,placeholder:"e.g. Europe/Bucharest…","aria-label":"Timezone","aria-describedby":u?b:void 0,autoComplete:"off",spellCheck:!1,"aria-invalid":u,onChange:v=>h(v.target.value),className:`w-44 rounded border bg-bg-2 px-2 py-1 text-xs text-fg ${g} ${u?"border-critical":"border-line"}`}),u&&e.jsx("span",{id:b,className:"text-[10px] text-critical",role:"alert",children:"Use an IANA zone such as Europe/Bucharest."})]})}function Ke({draft:t,patch:a}){const n=(s,u)=>a(r=>({...r,knownProviders:r.knownProviders.includes(s)?r.knownProviders:[...r.knownProviders,s],disabledProviders:u?r.disabledProviders.filter(b=>b!==s):Array.from(new Set([...r.disabledProviders,s]))}));return e.jsxs(E,{title:"Providers",right:e.jsxs("button",{type:"button",role:"switch","aria-checked":t.accountDetection.enabled,onClick:()=>a(s=>({...s,accountDetection:{...s.accountDetection,enabled:!s.accountDetection.enabled}})),className:`rounded border px-2 py-1 text-[10px] uppercase tracking-wide transition ${g} ${t.accountDetection.enabled?"border-accent/50 bg-accent/10 text-accent":"border-line text-fg-faint"}`,children:["Auto-detect ",t.accountDetection.enabled?"on":"off"]}),children:[e.jsx("p",{className:"mb-2.5 text-[11px] text-fg-faint",children:"Tracking controls all provider data. Auto-detect only finds accounts; manual accounts keep working when it is off."}),e.jsx("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-2",children:te.map(s=>{const u=!t.disabledProviders.includes(s),r=ye(t.accountDetection,s),b=W[s];return e.jsxs("div",{className:`flex items-center gap-2 rounded border px-2.5 py-2 text-left text-xs transition ${u?"border-line-2 bg-bg-2 text-fg":"border-line bg-bg-1 text-fg-faint hover:border-line-2"}`,children:[e.jsx("span",{className:"size-2 shrink-0 rounded-full",style:{background:O(b.color)},"aria-hidden":!0}),e.jsx("span",{className:`font-medium ${u?"text-fg":"text-fg-faint"}`,children:b.name}),e.jsxs("span",{className:"ml-auto flex items-center gap-1",children:[e.jsxs("button",{type:"button",role:"switch","aria-checked":u,"aria-label":`${u?"Stop":"Start"} tracking ${b.name}`,onClick:()=>n(s,!u),className:`inline-flex items-center gap-1 rounded border px-1.5 py-1 text-[10px] ${g} ${u?"border-line-2 text-fg":"border-line text-fg-faint"}`,children:[u&&e.jsx(B,{className:"size-3"})," Track"]}),e.jsx("button",{type:"button",role:"switch","aria-checked":r,disabled:!t.accountDetection.enabled,"aria-label":`${r?"Disable":"Enable"} ${b.name} account discovery`,onClick:()=>a(h=>({...h,accountDetection:ke(h.accountDetection,s,!r)})),className:`rounded border px-1.5 py-1 text-[10px] disabled:opacity-40 ${g} ${r?"border-accent/50 text-accent":"border-line text-fg-faint"}`,children:"Auto"})]})]},s)})})]})}function We(t,a){return a?a.accounts.find(n=>n.id===t.id)??null:null}function Xe({draft:t,patch:a,snapshot:n,onEdit:s,onConfigure:u,onAdd:r}){const b=Ne(t,void 0,(n==null?void 0:n.accounts)??void 0),[h,v]=x.useState(null),l=c=>a(f=>({...f,activeAccountId:c})),o=c=>{if(h!==c){v(c);return}a(f=>({...f,accounts:f.accounts.filter(i=>i.id!==c),activeAccountId:f.activeAccountId===c?null:f.activeAccountId})),v(null)},d=(c,f)=>a(i=>{const p=[...i.accounts],w=c+f;return w<0||w>=p.length?i:([p[c],p[w]]=[p[w],p[c]],{...i,accounts:p})});return e.jsx(E,{title:"Accounts",right:e.jsxs(M,{variant:"primary",size:"xs",onClick:r,children:[e.jsx(De,{className:"size-3"})," Add account"]}),children:b.length===0?e.jsx("p",{className:"rounded border border-line bg-bg-2/50 px-3 py-3 text-xs text-fg-faint",children:"None configured — enabled providers track automatically."}):e.jsx("ul",{className:"flex flex-col gap-1.5",role:"radiogroup","aria-label":"Active account",children:b.map(c=>{var D;const f=W[c.providerId],i=We(c,n),p=i?we(i,f.name):c.name||f.name,w=(i==null?void 0:i.plan)??((D=i==null?void 0:i.billing)==null?void 0:D.plan)??null,A=O(c.color||f.color),S=c.id===t.activeAccountId,I=c.source==="configured",k=c.source==="ignored";return e.jsxs("li",{className:`flex items-center gap-2.5 rounded border border-line px-2.5 py-2 ${k?"bg-bg-1 opacity-75":"bg-bg-2/60"}`,children:[e.jsx("button",{type:"button",role:"radio","aria-checked":S,disabled:k,"aria-label":`Set ${c.name} active`,title:S?"Active account (click to clear)":"Set active",onClick:()=>l(S?null:c.id),className:`relative inline-flex size-4 shrink-0 items-center justify-center rounded-full border transition ${g}`,style:{borderColor:A},children:S&&e.jsx("span",{className:"size-2 rounded-full",style:{background:A}})}),e.jsx("span",{className:"size-2.5 shrink-0 rounded-full",style:{background:A},"aria-hidden":!0}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ce,{value:p,privacyMode:t.privacyMode,className:"truncate text-sm text-fg-bright"}),e.jsx("span",{className:"shrink-0 rounded bg-bg-3 px-1.5 py-0.5 text-[10px] uppercase tracking-wide text-fg-dim",children:f.name}),w&&e.jsx("span",{className:"shrink-0 rounded border border-line px-1.5 py-0.5 text-[10px] text-fg-dim",children:w}),e.jsx("span",{className:"shrink-0 rounded border border-line px-1.5 py-0.5 text-[10px] uppercase tracking-wide text-fg-faint",children:c.source==="auto"?"detected":k?"ignored":"manual"})]}),e.jsx("div",{className:"truncate font-mono text-[11px] text-fg-faint",children:t.privacyMode?"path hidden":c.homeDir})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-0.5",children:[h===c.id?e.jsx("span",{className:"mr-1 text-[10px] text-critical",role:"alert",children:"Delete?"}):null,I&&c.explicitIndex!==void 0?e.jsxs(e.Fragment,{children:[e.jsx(P,{label:"Move up",disabled:c.explicitIndex===0,onClick:()=>d(c.explicitIndex,-1),children:e.jsx(ne,{className:"size-3.5"})}),e.jsx(P,{label:"Move down",disabled:c.explicitIndex===t.accounts.length-1,onClick:()=>d(c.explicitIndex,1),children:e.jsx(ae,{className:"size-3.5"})}),e.jsx(P,{label:"Edit account",onClick:()=>s(c),children:e.jsx(le,{className:"size-3.5"})}),e.jsx(P,{label:h===c.id?"Confirm delete account":"Delete account",danger:!0,onClick:()=>o(c.id),children:e.jsx(Se,{className:"size-3.5"})})]}):k?e.jsx(P,{label:"Turn detected account on",onClick:()=>c.excludedRef&&a(j=>({...j,accountDetection:ie(j.accountDetection,c.excludedRef,!1)})),children:e.jsx(Ie,{className:"size-3.5"})}):e.jsxs(e.Fragment,{children:[e.jsx(P,{label:"Configure as manual account",onClick:()=>u(c),children:e.jsx(le,{className:"size-3.5"})}),e.jsx(P,{label:"Turn detected account off",onClick:()=>a(j=>({...j,activeAccountId:j.activeAccountId===c.id?null:j.activeAccountId,accountDetection:ie(j.accountDetection,{providerId:c.providerId,homeDir:c.homeDir},!0)})),children:e.jsx(me,{className:"size-3.5"})})]})]})]},`${c.source}:${c.id}`)})})})}function Ye(t){const a=(t??"").trim();return a.length>0?a:"~"}function J(t){const a=(t??"").trim();return a.length>0?a:"~"}function Qe(t){const a=[];t.parent!==null&&a.push({kind:"parent",key:"..",label:"..",path:t.parent});for(const n of[...t.entries].filter(s=>s.dir).sort((s,u)=>s.name.localeCompare(u.name)))a.push({kind:"entry",key:n.path,label:n.name,path:n.path});return a}function Ze({editor:t,accounts:a,onChange:n,onCancel:s,onSubmit:u}){const r=x.useRef(null),[b,h]=x.useState(null),v=O(t.color),l=Ue(t,a),o=()=>{const d=Ge(t,a);if(!d.ok){h(d.error);return}u(d.account,d.mode,d.editingId)};return e.jsxs(he,{onClose:s,labelledBy:"account-editor-title",initialFocusRef:r,showClose:!1,className:"my-8 w-full max-w-[460px] border-l-2",panelStyle:{borderLeftColor:v},children:[e.jsxs("div",{className:"flex items-center gap-2 border-b border-line px-4 py-3",children:[e.jsx("span",{className:"size-2.5 rounded-full",style:{background:v},"aria-hidden":!0}),e.jsx("h2",{id:"account-editor-title",className:"font-display text-xs uppercase tracking-wider text-fg-bright",children:t.mode==="add"?"New account":"Edit account"})]}),e.jsxs("div",{className:"flex flex-col gap-4 px-4 py-4",children:[e.jsx(q,{label:"Provider",hint:"which tool this account tracks",children:e.jsx("div",{className:"flex flex-wrap gap-1.5",children:te.map(d=>{const c=d===t.providerId,f=W[d];return e.jsxs("button",{type:"button",onClick:()=>n({...t,providerId:d}),"aria-pressed":c,className:`flex items-center gap-1.5 rounded border px-2 py-1 text-xs transition ${g} ${c?"border-line-2 bg-bg-3 text-fg-bright":"border-line text-fg-dim hover:text-fg"}`,children:[e.jsx("span",{className:"size-2 rounded-full",style:{background:O(f.color)},"aria-hidden":!0}),f.name]},d)})})}),e.jsx(q,{label:"Name",hint:"display name for this account",children:e.jsx("input",{ref:r,type:"text",name:"account-name",value:t.name,placeholder:"e.g. Work…","aria-label":"Account name",autoComplete:"off",spellCheck:!1,onChange:d=>{h(null),n({...t,name:X(d.target.value)})},onKeyDown:d=>{d.key==="Enter"&&o()},className:`w-full rounded border border-line bg-bg-2 px-2.5 py-1.5 text-sm text-fg ${g}`})}),e.jsx(q,{label:"Home directory",hint:"path containing the tool's data dir · ~ for default",children:e.jsx(Je,{value:t.homeDir,onChange:d=>n({...t,homeDir:d}),onEnter:o})}),e.jsx(q,{label:"Accent color",hint:"shows on dashboard, account strip, borders",children:e.jsx("div",{className:"flex flex-wrap gap-1.5",children:Ae.map(d=>{const c=d===t.color;return e.jsx("button",{type:"button","aria-label":d,"aria-pressed":c,title:d,onClick:()=>n({...t,color:d}),className:`size-6 rounded-full border-2 transition ${g} ${c?"scale-110":"border-transparent hover:scale-105"}`,style:{background:O(d),borderColor:c?"var(--color-fg-bright)":"transparent"}},d)})})}),e.jsxs("div",{className:"flex items-center gap-2 rounded border border-line bg-bg-2/50 px-2.5 py-1.5 text-xs",children:[e.jsx("span",{className:"text-fg-faint",children:"id"}),e.jsx("span",{className:"font-mono text-fg",style:{color:v},children:l||"account"}),e.jsx("span",{className:"ml-auto text-[10px] text-fg-faint",children:t.mode==="add"?"auto-generated from name":"fixed"})]}),b&&e.jsxs("p",{className:"text-xs text-critical",role:"alert",children:[b,". Check the highlighted account fields and try again."]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 border-t border-line px-4 py-3",children:[e.jsx(M,{variant:"secondary",onClick:s,children:"cancel"}),e.jsxs(M,{variant:"primary",onClick:o,children:[e.jsx(B,{className:"size-3.5"})," ",t.mode==="add"?"Add account":"Save account"]})]})]})}function Je({value:t,onChange:a,onEnter:n}){const[s,u]=x.useState(!1),[r,b]=x.useState(null),[h,v]=x.useState("~"),[l,o]=x.useState(!1),[d,c]=x.useState(null),f=x.useRef(0),i=x.useCallback(async j=>{const $=++f.current,T=Ye(j);v(T),o(!0),c(null);try{const z=await $e(T);if($!==f.current)return;b(z)}catch(z){if($!==f.current)return;b(null),c(z instanceof Error?z.message:"cannot read folder")}finally{$===f.current&&o(!1)}},[]);x.useEffect(()=>()=>{f.current++},[]);const p=()=>{u(!0),i(t)},w=()=>{f.current++,u(!1),o(!1),c(null)},A=j=>{l||i(j)},S=()=>{!r||l||(a(J(r.path)),w())},I=r?Qe(r):[],k=I.filter(j=>j.kind==="entry"),D=J((r==null?void 0:r.path)??h);return e.jsxs("div",{className:"relative",children:[e.jsxs("div",{className:"flex overflow-hidden rounded border border-line bg-bg-2",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 px-2.5",children:[e.jsx(Q,{className:"size-4 shrink-0 text-fg-faint"}),e.jsx("input",{type:"text",name:"account-home-directory",value:t,placeholder:"e.g. ~/work…","aria-label":"Account home directory",autoComplete:"off",spellCheck:!1,onChange:j=>{w(),a(X(j.target.value))},onKeyDown:j=>{j.key==="Enter"&&n()},className:`min-w-0 flex-1 bg-transparent py-1.5 font-mono text-sm text-fg ${g}`})]}),e.jsxs("button",{type:"button",onClick:p,disabled:l,className:`flex shrink-0 items-center gap-1 border-l border-line bg-bg-1 px-2.5 py-1.5 text-xs text-fg-dim transition hover:bg-bg-3 hover:text-fg disabled:opacity-50 ${g}`,children:[e.jsx(ae,{className:"size-3.5"})," Browse"]})]}),s&&e.jsxs("div",{className:"mt-2 overflow-hidden rounded border border-line-2 bg-bg-1 shadow-[0_18px_60px_rgba(0,0,0,0.35)]",children:[e.jsxs("div",{className:"flex items-center gap-2 border-b border-line bg-bg-2 px-2.5 py-2",children:[e.jsx(Q,{className:"size-4 shrink-0 text-accent"}),e.jsx("div",{className:"min-w-0 flex-1 truncate font-mono text-xs text-fg-bright",title:D,children:D}),l&&e.jsx("span",{className:"shrink-0 text-[10px] uppercase tracking-wide text-fg-faint",children:"loading"}),e.jsx("button",{type:"button",onClick:w,"aria-label":"Close folder picker",className:`rounded p-1 text-fg-faint transition hover:text-fg ${g}`,children:e.jsx(me,{className:"size-3.5"})})]}),d?e.jsxs("div",{className:"px-2.5 py-3",children:[e.jsxs("div",{className:"text-xs text-critical",children:["can't read ",J(h)]}),e.jsx("button",{type:"button",onClick:()=>{l||i(h)},disabled:l,className:`mt-2 rounded border border-line bg-bg-2 px-2 py-1 text-[11px] text-fg-dim transition hover:border-line-2 hover:text-fg disabled:opacity-50 ${g}`,children:"retry"})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"max-h-56 overflow-y-auto py-1",children:[I.map(j=>e.jsxs("button",{type:"button",onClick:()=>A(j.path),disabled:l,className:`flex w-full items-center gap-2 px-2.5 py-1.5 text-left text-xs transition hover:bg-bg-3 hover:text-fg disabled:opacity-50 ${g} ${j.kind==="parent"?"text-fg-dim":"text-fg"}`,children:[j.kind==="parent"?e.jsx(ne,{className:"size-3.5 shrink-0"}):e.jsx(Q,{className:"size-3.5 shrink-0 text-fg-faint"}),e.jsx("span",{className:"min-w-0 truncate font-mono",children:j.label})]},j.key)),!l&&k.length===0&&e.jsx("div",{className:"px-2.5 py-3 text-xs text-fg-faint",children:"no subdirectories"}),l&&!r&&e.jsx("div",{className:"px-2.5 py-3 text-xs text-fg-faint",role:"status","aria-live":"polite",children:"loading folders…"})]}),e.jsx("div",{className:"flex items-center justify-end gap-2 border-t border-line px-2.5 py-2",children:e.jsxs(M,{variant:"primary",onClick:S,disabled:!r||l,children:[e.jsx(B,{className:"size-3.5"})," Select this folder"]})})]})]})]})}function et({draft:t,patch:a,snapshot:n}){const s=(n==null?void 0:n.providers)??[],u=new Set(s.map(l=>l.id)),r=oe(t.tray.pinnedProviders,u,G),b=oe(t.desktop.expandedProviders,u),h=l=>a(o=>({...o,tray:{...o.tray,pinnedProviders:l,pins:[],pinnedAccount:null}})),v=l=>a(o=>({...o,desktop:{...o.desktop,expandedProviders:ce(o.desktop.expandedProviders,l,u)}}));return e.jsxs(e.Fragment,{children:[e.jsxs(E,{title:"App",children:[e.jsx(N,{label:"Privacy mode",hint:`global identity masking · ${t.privacyToggleKey.toUpperCase()} shortcut`,children:e.jsx(C,{size:"xs",ariaLabel:"privacy mode",options:[{value:"on",label:"on"},{value:"off",label:"off"}],value:t.privacyMode?"on":"off",onChange:l=>a(o=>({...o,privacyMode:l==="on"}))})}),e.jsx(N,{label:"Menu bar value",hint:"smart pools account capacity · tightest shows the highest single usage",children:e.jsx(C,{size:"xs",ariaLabel:"menu bar value",options:[{value:"smartHeadroom",label:"smart"},{value:"tightestRemaining",label:"tightest"}],value:t.tray.displayMetric,onChange:l=>a(o=>({...o,tray:{...o.tray,displayMetric:l}}))})}),e.jsx(N,{label:"Show value in menu bar",hint:"hide the number and keep the provider mark",children:e.jsx(C,{size:"xs",ariaLabel:"show menu bar value",options:[{value:"on",label:"on"},{value:"off",label:"off"}],value:t.tray.showMenuBarText?"on":"off",onChange:l=>a(o=>({...o,tray:{...o.tray,showMenuBarText:l==="on"}}))})}),e.jsx(N,{label:"Active window",hint:"recent activity used by smart headroom",children:e.jsx(ee,{label:"Active window",value:t.tray.activeTimeoutMin,min:1,unit:"min",onChange:l=>a(o=>({...o,tray:{...o.tray,activeTimeoutMin:Math.min(1440,l)}}))})}),e.jsx(N,{label:"Graph range",hint:"trailing spend activity in the desktop popover",children:e.jsx(C,{size:"xs",ariaLabel:"desktop graph range",options:ze.map(l=>({value:String(l),label:`${l}d`})),value:String(t.desktop.graphRangeDays),onChange:l=>a(o=>({...o,desktop:{...o.desktop,graphRangeDays:Number(l)}}))})}),e.jsx(N,{label:"Launch at login",hint:"start the desktop menu bar app automatically",children:e.jsx(C,{size:"xs",ariaLabel:"launch desktop app at login",options:[{value:"on",label:"on"},{value:"off",label:"off"}],value:t.tray.launchAtLogin?"on":"off",onChange:l=>a(o=>({...o,tray:{...o.tray,launchAtLogin:l==="on"}}))})})]}),e.jsxs(E,{title:"Menu bar providers",right:e.jsxs("span",{className:"text-[10px] text-fg-faint",children:[r.length,"/",G," pinned"]}),children:[s.length===0?e.jsx("p",{className:"rounded border border-line bg-bg-2/50 px-3 py-3 text-xs text-fg-faint",children:"Waiting for provider data…"}):e.jsx("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-2",children:s.map(l=>{const o=r.indexOf(l.id),d=o>=0,c=!d&&r.length>=G;return e.jsxs("div",{className:`flex items-center gap-2 rounded border px-2.5 py-2 ${d?"border-line-2 bg-bg-2":"border-line bg-bg-1"}`,children:[e.jsx("button",{type:"button",role:"checkbox","aria-checked":d,disabled:c,"aria-label":`${d?"Unpin":"Pin"} ${l.name}`,onClick:()=>h(ce(r,l.id,u,G)),className:`inline-flex size-5 shrink-0 items-center justify-center rounded border text-[10px] transition disabled:cursor-not-allowed disabled:opacity-35 ${g}`,style:{borderColor:d?l.color:"var(--color-line-2)",color:l.color},children:d?o+1:e.jsx(B,{className:"size-3 opacity-0"})}),e.jsx("span",{className:"size-2 shrink-0 rounded-full",style:{background:l.color},"aria-hidden":!0}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-xs text-fg",children:l.name}),d&&e.jsxs("span",{className:"flex shrink-0 items-center",children:[e.jsx(P,{label:`Move ${l.name} left`,disabled:o===0,onClick:()=>h(de(r,l.id,-1)),children:e.jsx(ne,{className:"size-3.5 -rotate-90"})}),e.jsx(P,{label:`Move ${l.name} right`,disabled:o===r.length-1,onClick:()=>h(de(r,l.id,1)),children:e.jsx(ae,{className:"size-3.5 -rotate-90"})})]})]},l.id)})}),e.jsx("p",{className:"mt-2 text-[11px] text-fg-faint",children:"The numbered order matches the menu bar from left to right."})]}),e.jsxs(E,{title:"Popover defaults",children:[e.jsx("p",{className:"mb-2 text-[11px] text-fg-faint",children:"Choose which provider cards start expanded. You can still open or close any card in the app."}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:s.map(l=>{const o=b.includes(l.id);return e.jsxs("button",{type:"button","aria-pressed":o,onClick:()=>v(l.id),className:`flex items-center gap-1.5 rounded border px-2 py-1 text-xs transition ${g} ${o?"border-line-2 bg-bg-2 text-fg":"border-line bg-bg-1 text-fg-faint hover:text-fg"}`,children:[e.jsx("span",{style:{color:l.color},"aria-hidden":!0,children:o?"●":"○"}),l.name]},l.id)})})]})]})}const tt=[{label:"surfaces",keys:[{key:"canvas",label:"Canvas"},{key:"panel",label:"Panel"},{key:"inset",label:"Inset"},{key:"insetStrong",label:"Raised inset"},{key:"chrome",label:"Desktop chrome"},{key:"line",label:"Line"},{key:"lineStrong",label:"Strong line"},{key:"lineFaint",label:"Faint line"}]},{label:"type",keys:[{key:"text",label:"Text"},{key:"textDim",label:"Dim text"},{key:"textFaint",label:"Faint text"},{key:"textStrong",label:"Strong text"}]},{label:"signals",keys:[{key:"accent",label:"Accent"},{key:"cost",label:"Cost"},{key:"positive",label:"Savings"}]}],nt=[{value:"auto",label:"Auto"},{value:"light",label:"Light"},{value:"dark",label:"Dark"}],at=[{value:"ansi",label:"Terminal"},{value:"dark",label:"Dark"},{value:"light",label:"Light"},{value:"off",label:"Off"}];function K(t){return t.custom??{base:"tokmon",light:{},dark:{}}}function F(t,a){return{...t,appearance:{...t.appearance,...a}}}function st({preset:t,selected:a,appearance:n,onSelect:s}){const u=t==="custom"?{...n,preset:t,custom:K(n),mode:"dark"}:{...n,preset:t,mode:"dark"},r=pe(u,"dark").tokens;return e.jsxs("button",{type:"button","aria-pressed":a,onClick:s,className:`min-w-0 rounded border p-2 text-left transition ${g} ${a?"border-accent":"border-line hover:border-line-2"}`,style:{background:r.panel,color:r.text},children:[e.jsxs("span",{className:"mb-2 flex items-center gap-1.5 text-[11px] font-medium",children:[e.jsx("span",{className:"size-2 rounded-full",style:{background:r.accent},"aria-hidden":!0}),e.jsx("span",{className:"truncate",children:V(t).name})]}),e.jsx("span",{className:"flex h-5 items-end gap-1","aria-hidden":!0,children:[r.textFaint,r.textDim,r.cost,r.accent].map((b,h)=>e.jsx("span",{className:"flex-1 rounded-sm",style:{height:`${7+h*3}px`,background:b}},b))})]})}function rt({draft:t,patch:a}){const n=t.appearance,[s,u]=x.useState("dark"),r=K(n),b=x.useMemo(()=>pe({...n,preset:"custom",custom:r,mode:s},s),[n,r,s]),h=x.useMemo(()=>be(n),[n]),v=h.filter(i=>i.mode===s),l=new Set(v.flatMap(i=>i.keys)),o=h.length===0,d=i=>a(p=>F(p,{preset:i,...i==="custom"?{custom:K(p.appearance)}:{},...H(i)?{mode:"dark"}:{}})),c=(i=n.preset)=>{Z(i)&&a(p=>F(p,{preset:"custom",custom:{base:i,light:{},dark:{}}}))},f=i=>a(p=>F(p,{preset:"custom",custom:i(K(p.appearance))}));return e.jsxs("div",{className:"space-y-6",children:[e.jsxs(E,{title:"appearance",children:[e.jsx(N,{label:"Mode",hint:"Auto follows the operating system live.",children:e.jsx(C,{options:H(n.preset)?[{value:"dark",label:"Dark"}]:[...nt],value:H(n.preset)?"dark":n.mode,onChange:i=>a(p=>F(p,{mode:i})),ariaLabel:"graphical color mode"})}),e.jsx(N,{label:"Terminal colors",hint:"Keep ANSI to preserve the classic Tokmon CLI.",children:e.jsx(C,{options:[...at],value:n.terminal,onChange:i=>a(p=>F(p,{terminal:i})),ariaLabel:"terminal theme policy",size:"xs"})})]}),e.jsxs(E,{title:"preset",children:[e.jsx("div",{className:"grid grid-cols-2 gap-2 sm:grid-cols-3",children:Pe.map(i=>e.jsx(st,{preset:i.id,selected:n.preset===i.id,appearance:n,onSelect:()=>d(i.id)},i.id))}),e.jsxs("div",{className:"mt-3 flex min-h-7 items-center justify-between gap-3",children:[e.jsx("p",{className:"text-[11px] text-fg-faint",children:H(n.preset)?"Phosphor is intentionally dark-only.":V(n.preset).hint}),Z(n.preset)&&e.jsxs("button",{type:"button",onClick:()=>c(),className:`shrink-0 rounded border border-line px-2.5 py-1 text-[11px] text-fg-dim transition hover:border-line-2 hover:text-fg ${g}`,children:["customize ",V(n.preset).name]})]})]}),n.preset==="custom"&&e.jsxs(E,{title:"custom palette",right:e.jsx(C,{options:[{value:"light",label:"Light"},{value:"dark",label:"Dark"}],value:s,onChange:u,size:"xs",ariaLabel:"custom palette variant"}),children:[e.jsx(N,{label:"Starting point",hint:"Changing the base resets both variants.",children:e.jsx("select",{value:r.base,onChange:i=>{const p=i.target.value;Z(p)&&f(()=>({base:p,light:{},dark:{}}))},"aria-label":"custom theme base",className:`min-h-8 rounded border border-line bg-bg-2 px-2 text-xs text-fg ${g}`,children:Ee.map(i=>e.jsx("option",{value:i,children:V(i).name},i))})}),e.jsx("div",{className:"mt-4 grid gap-x-5 gap-y-4 sm:grid-cols-2",children:tt.flatMap(i=>i.keys.map(p=>({...p,group:i.label}))).map(({key:i,label:p,group:w})=>{const A=r[s][i]??b.tokens[i],S=l.has(i);return e.jsxs("label",{className:"min-w-0",children:[e.jsxs("span",{className:"mb-1 flex items-baseline justify-between gap-2 text-xs text-fg",children:[p,e.jsx("span",{className:"text-[9px] uppercase tracking-wider text-fg-faint",children:w})]}),e.jsxs("span",{className:`flex items-center gap-2 rounded border bg-bg-2 p-1 ${S?"border-critical":"border-line"}`,children:[e.jsx("input",{type:"color","aria-label":`${s} ${p} color`,value:Re(A)??b.tokens[i],onChange:I=>f(k=>({...k,[s]:{...k[s],[i]:I.target.value}})),className:"size-7 cursor-pointer border-0 bg-transparent p-0"}),e.jsx("input",{type:"text",spellCheck:!1,maxLength:7,pattern:"#[0-9A-Fa-f]{6}",value:A,"aria-invalid":S,onChange:I=>f(k=>({...k,[s]:{...k[s],[i]:I.target.value}})),className:`tnum min-w-0 flex-1 bg-transparent px-1 text-xs text-fg outline-none ${g}`})]}),S&&e.jsx("span",{className:"mt-1 block text-[10px] text-critical",children:"Use #RRGGBB with readable contrast."})]},i)})}),e.jsxs("div",{className:"mt-4 flex items-center justify-between gap-3 border-t border-line pt-3",children:[e.jsx("span",{className:`text-[11px] ${o?"text-positive":"text-critical"}`,role:"status",children:o?"Light and dark palettes pass contrast checks":`${h.length} palette issue${h.length===1?"":"s"}`}),e.jsxs("button",{type:"button",onClick:()=>f(i=>({...i,[s]:{}})),className:`rounded border border-line px-2.5 py-1 text-[11px] text-fg-dim transition hover:border-line-2 hover:text-fg ${g}`,children:["reset ",s]})]})]})]})}const lt=[{value:"general",label:"General"},{value:"theme",label:"Theme"},{value:"app",label:"Desktop App"},{value:"providers",label:"Providers"},{value:"accounts",label:"Accounts"}];function ct({onClose:t,snapshot:a}){const n=Te(),s=x.useRef(null),u=x.useRef(null),[r,b]=x.useState(null),[h,v]=x.useState(null),[l,o]=x.useState(null),[d,c]=x.useState(!1),[f,i]=x.useState(null),[p,w]=x.useState(!1),[A,S]=x.useState(!1),[I,k]=x.useState(null),[D,j]=x.useState("general"),$=x.useRef(!1),T=x.useRef(!1),z=x.useRef(null),Y=x.useRef(null),_=x.useCallback(m=>{o(null);const y=Le(z.current,Y.current,$.current,m);$.current||(z.current=y.draft,Y.current=y.revision,b(y.draft),v(y.revision)),y.conflict&&i("settings changed elsewhere; close and reopen settings before saving")},[]);x.useEffect(()=>{let m=!0;return Me().then(y=>{m&&_(y)}).catch(y=>{m&&o(y instanceof Error?y.message:"load failed")}),()=>{m=!1}},[_]),x.useEffect(()=>{const m=y=>{$.current&&y.preventDefault()};return window.addEventListener("beforeunload",m),()=>window.removeEventListener("beforeunload",m)},[]),x.useEffect(()=>{let m=!0;const y=Fe(R=>{m&&_(R)});return()=>{m=!1,y()}},[_]);const se=()=>{if(!$.current||T.current){n.setPreview(null),t();return}T.current=!0,S(!0),i("unsaved changes; choose discard to close settings")};x.useEffect(()=>{const m=s.current;m&&(I?m.setAttribute("inert",""):m.removeAttribute("inert"))},[I]);const L=m=>{const y=z.current;if(!y)return;const R={...m(y),revision:y.revision};n.setPreview(R.appearance),$.current=!0,z.current=R,w(!0),T.current=!1,S(!1),i(null),b(R)},fe=async()=>{if(r){c(!0),i(null);try{if(h===null)throw new Error("config revision is unavailable");const m=await Oe(r,h);z.current=m.config,Y.current=m.config.revision,$.current=!1,b(m.config),v(m.config.revision),w(!1),n.commit(m),t()}catch(m){n.setPreview(null);const y=Be(m);i(y.conflictState?`${y.message}; close and reopen settings before saving`:y.message)}finally{c(!1)}}};return e.jsxs(e.Fragment,{children:[e.jsxs(he,{onClose:se,labelledBy:"settings-title",initialFocusRef:u,panelRef:s,className:"my-6 flex w-full max-w-[900px] flex-col",children:[e.jsx("h2",{ref:u,tabIndex:-1,id:"settings-title",className:"pointer-events-none absolute left-3 top-2 font-display text-[11px] uppercase tracking-wider text-fg-dim focus:outline-none",children:"settings"}),e.jsx("div",{className:"max-h-[78vh] overflow-y-auto px-4 pb-4 pt-9 sm:px-5",children:l&&!r?e.jsxs("div",{className:"rounded border border-critical/50 bg-bg-2 p-4 text-sm text-critical",role:"alert",children:["Could not load settings: ",l,". Close settings and try again."]}):r?e.jsx(e.Fragment,{children:e.jsxs("div",{className:"flex min-w-0 flex-col gap-5 sm:flex-row sm:items-start",children:[e.jsx("nav",{className:"-mx-1 flex shrink-0 gap-1 overflow-x-auto px-1 pb-2 sm:mx-0 sm:w-32 sm:flex-col sm:overflow-visible sm:px-0 sm:pb-0","aria-label":"Settings sections",children:lt.map(m=>e.jsx("button",{type:"button","aria-current":D===m.value?"page":void 0,onClick:()=>j(m.value),className:`shrink-0 rounded px-2.5 py-2 text-left text-[11px] transition ${g} ${D===m.value?"bg-bg-3 text-accent":"text-fg-dim hover:bg-bg-2 hover:text-fg"}`,children:m.label},m.value))}),e.jsxs("div",{className:"min-w-0 flex-1 border-t border-line pt-4 sm:border-l sm:border-t-0 sm:pl-5 sm:pt-0",children:[D==="general"&&e.jsx(He,{draft:r,patch:L}),D==="theme"&&e.jsx(rt,{draft:r,patch:L}),D==="app"&&e.jsx(et,{draft:r,patch:L,snapshot:a}),D==="providers"&&e.jsx(Ke,{draft:r,patch:L}),D==="accounts"&&e.jsx(Xe,{draft:r,patch:L,snapshot:a,onEdit:m=>k(_e(m)),onConfigure:m=>k(ue(r,{providerId:m.providerId,name:m.name,homeDir:m.homeDir,color:m.color})),onAdd:()=>k(ue(r))})]})]})}):e.jsx("div",{className:"py-10 text-center text-sm text-fg-dim",children:"loading config…"})}),e.jsxs("div",{className:"flex items-center justify-end gap-3 border-t border-line px-5 py-3",children:[f&&e.jsx("span",{className:"mr-auto text-xs text-critical",role:"alert",children:f}),p&&!f&&e.jsx("span",{className:"mr-auto text-xs text-fg-faint",role:"status","aria-live":"polite",children:"unsaved changes"}),e.jsx(M,{variant:"secondary",onClick:se,children:A?"discard":"cancel"}),e.jsxs(M,{variant:"primary",onClick:fe,disabled:!r||d||!p||be(r.appearance).length>0,children:[e.jsx(B,{className:"size-3.5"})," ",d?"saving…":"save"]})]})]}),I&&r&&e.jsx(Ze,{editor:I,accounts:r.accounts,onChange:k,onCancel:()=>k(null),onSubmit:(m,y,R)=>{L(U=>y==="add"?{...U,accounts:[...U.accounts,m]}:{...U,accounts:U.accounts.map(re=>re.id===R?m:re)}),k(null)}})]})}export{ct as SettingsSheet};