tokmon 0.28.2 → 0.28.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +156 -234
- package/THIRD_PARTY_NOTICES.md +62 -0
- package/dist/{bootstrap-ink-IMT3S5HU.js → bootstrap-ink-WG4WG3R2.js} +1579 -1136
- package/dist/chunk-5B3XCEMC.js +294 -0
- package/dist/chunk-7CH6S7BR.js +447 -0
- package/dist/{chunk-LCAHTRGP.js → chunk-CFKUZCMB.js} +56 -29
- package/dist/{chunk-LKYOWBD4.js → chunk-FLANGRI6.js} +21 -42
- package/dist/chunk-HNWEJ6MS.js +1094 -0
- package/dist/{chunk-WUK3MQUB.js → chunk-JZSZEHVD.js} +167 -10
- package/dist/{chunk-6ZEW2M6P.js → chunk-P57DVFNH.js} +125 -25
- package/dist/chunk-TN6V7XSL.js +512 -0
- package/dist/chunk-UYPDMVW5.js +21 -0
- package/dist/{cli-command-DCENRCO3.js → cli-command-I4GRR3MF.js} +249 -15
- package/dist/cli.js +6 -6
- package/dist/{config-HXFJTNLM.js → config-3DGZ47F7.js} +23 -3
- package/dist/daemon-ZXV3V5CS.js +384 -0
- package/dist/daemon-handle-G4OGPFR3.js +11 -0
- package/dist/server-EPSH52DR.js +12 -0
- package/dist/web/assets/{Area-CMXvOw33.js → Area-stRnp8Km.js} +1 -1
- package/dist/web/assets/analytics-moZZt9L_.js +2 -0
- package/dist/web/assets/breakdown-km9w7myU.js +4 -0
- package/dist/web/assets/button-DrX04Cc2.js +1 -0
- package/dist/web/assets/{chart-cZoLgpmG.js → chart-D0CtuL2k.js} +1 -1
- package/dist/web/assets/explore-B11uNJV1.js +22 -0
- package/dist/web/assets/index-RDhXsCNG.js +83 -0
- package/dist/web/assets/index-ZmOS8p9O.css +1 -0
- package/dist/web/assets/models-DYbZnY34.js +2 -0
- package/dist/web/assets/overview-CruICbfJ.js +2 -0
- package/dist/web/assets/panel-xckM3_GC.js +1 -0
- package/dist/web/assets/settings-sheet-G-BTSIF6.js +1 -0
- package/dist/web/assets/share-sheet-weIdd4DW.js +2 -0
- package/dist/web/assets/timeline-BHgniliZ.js +1 -0
- package/dist/web/index.html +30 -4
- package/package.json +13 -4
- package/site/THIRD_PARTY_NOTICES.md +83 -0
- package/site/public/fonts/OFL.txt +93 -0
- package/dist/chunk-44ZSQEOS.js +0 -299
- package/dist/chunk-HP5UZCXP.js +0 -436
- package/dist/chunk-J3JW3RFP.js +0 -196
- package/dist/chunk-M7XMV36F.js +0 -275
- package/dist/daemon-6Y4O7NXS.js +0 -241
- package/dist/daemon-handle-GVCYVDPO.js +0 -10
- package/dist/server-GXXOWUVZ.js +0 -11
- package/dist/web/assets/analytics-DqdZXOJL.js +0 -2
- package/dist/web/assets/breakdown-kOSSJ3mI.js +0 -4
- package/dist/web/assets/explore-vcsM8K9I.js +0 -22
- package/dist/web/assets/index-BErCXT7f.css +0 -1
- package/dist/web/assets/index-DH3dOnbg.js +0 -83
- package/dist/web/assets/models-B5ikm83_.js +0 -2
- package/dist/web/assets/overview-DD1kP8CP.js +0 -2
- package/dist/web/assets/panel-DTQBwExW.js +0 -1
- package/dist/web/assets/primitives-C36qJlA2.js +0 -1
- package/dist/web/assets/settings-sheet-_i2zTQjf.js +0 -1
- package/dist/web/assets/share-sheet-BLHmrFbm.js +0 -2
- package/dist/web/assets/timeline-B4uG-Emo.js +0 -1
- package/dist/web/assets/use-dialog-trap-bfaXEMz9.js +0 -1
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./breakdown-kOSSJ3mI.js","./index-DH3dOnbg.js","./index-BErCXT7f.css","./chart-cZoLgpmG.js","./panel-DTQBwExW.js","./primitives-C36qJlA2.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{r as o,j as e,s as f,n as b,f as u,a as N,b as k,S as v,_ as d}from"./index-DH3dOnbg.js";import{P as y}from"./panel-DTQBwExW.js";import{E as _,S as C}from"./primitives-C36qJlA2.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(y,{title:"model leaderboard",titleTag:i,captureName:"models",right:e.jsx(v,{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(_,{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:f(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:b(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(C,{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?N(s.tokens):e.jsx("span",{className:"text-fg-faint",children:"—"})}),e.jsx("span",{className:`tnum text-right text-xs text-fg-faint ${p}`,children:k(s.calls)})]},s.model))]})})}const E=o.lazy(()=>d(()=>import("./breakdown-kOSSJ3mI.js"),__vite__mapDeps([0,1,2,3,4,5]),import.meta.url).then(t=>({default:t.CostByModel}))),T=o.lazy(()=>d(()=>import("./breakdown-kOSSJ3mI.js"),__vite__mapDeps([0,1,2,3,4,5]),import.meta.url).then(t=>({default:t.ProviderDonut}))),M=o.lazy(()=>d(()=>import("./breakdown-kOSSJ3mI.js"),__vite__mapDeps([0,1,2,3,4,5]),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 $({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{$ as ModelsTab};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./timeline-B4uG-Emo.js","./index-DH3dOnbg.js","./index-BErCXT7f.css","./chart-cZoLgpmG.js","./panel-DTQBwExW.js","./primitives-C36qJlA2.js","./Area-CMXvOw33.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{j as e,f as o,a as u,b as h,p as M,P,s as _,c as T,d as A,r as $,_ as L}from"./index-DH3dOnbg.js";import{P as R}from"./panel-DTQBwExW.js";import{S as j}from"./primitives-C36qJlA2.js";function E({derived:s,periodLabel:n}){const l=s.totals,a=s.timeline.map(t=>t.total).slice(-30),r=s.timeline.map(t=>t.tokens).slice(-30),c=s.cacheSavingsSeries.map(t=>t.value).slice(-30);return e.jsxs("div",{className:"grid grid-cols-[repeat(auto-fit,minmax(150px,1fr))] gap-3",children:[e.jsx(p,{label:`spend · ${n}`,value:o(l.cost),accent:"text-cost",spark:a,sparkColor:"var(--color-cost)"}),e.jsx(p,{label:"tokens",value:u(l.tokens),spark:r,sparkColor:"var(--color-fg-dim)"}),e.jsx(p,{label:"cache saved",value:o(l.cacheSavings),accent:"text-positive",spark:c,sparkColor:"var(--color-positive)"}),e.jsx(p,{label:"calls",value:h(l.calls)}),e.jsx(p,{label:"burn · today",value:`${o(s.burnRate)}/hr`,accent:"text-warning"})]})}function p({label:s,value:n,accent:l="text-fg-bright",spark:a,sparkColor:r}){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 ${l}`,children:n}),a&&a.length>1&&e.jsx("div",{className:"mt-auto overflow-hidden pt-2 text-right",children:e.jsx(j,{data:a,color:r??"currentColor",className:"text-sm opacity-70"})})]})}function D({accounts:s,nameOf:n,privacyMode:l,resetDisplay:a,tz:r}){return s.length===0?e.jsx(R,{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((c,t)=>e.jsx(I,{account:c,index:t,providerName:n(c.providerId),privacyMode:l,resetDisplay:a,tz:r},c.id))})}function I({account:s,index:n,providerName:l,privacyMode:a,resetDisplay:r,tz:c}){var v,b,N,k,w,y;const t=s.dashboard,x=((v=s.billing)==null?void 0:v.metrics)??[],m=((b=s.billing)==null?void 0:b.modelSpend)??[],i=(N=s.billing)==null?void 0:N.activity,f=M(s.providerId),C=s.name&&s.name!==l;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:l}),C&&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:"·"}),e.jsx(P,{value:s.name,privacyMode:a,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})]}),t&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mt-4 grid grid-cols-3 gap-2",children:[e.jsx(g,{label:"today",cost:t.today.cost,tokens:t.today.tokens}),e.jsx(g,{label:"week",cost:t.week.cost,tokens:t.week.tokens}),e.jsx(g,{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-warning",children:[o(t.burnRate),"/hr"]})]}),e.jsxs("span",{className:"text-fg-dim",children:["saved ",e.jsx("span",{className:"tnum text-positive",children:o(t.month.cacheSavings)})]})]})]}),x.length>0&&e.jsx("div",{className:`flex flex-col gap-2 ${t?"mt-3 border-t border-line-faint pt-3":"mt-4"}`,children:x.slice(0,8).map((d,S)=>e.jsx(q,{metric:d,resetDisplay:r,tz:c},`${d.label}${S}`))}),m.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"}),m.slice(0,4).map(d=>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:_(d.name)}),e.jsxs("span",{className:"tnum shrink-0 text-cost",children:[o(d.usd),e.jsxs("span",{className:"ml-1.5 text-fg-faint",children:[h(d.requests)," req"]})]})]},d.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(j,{data:t.series,color:f,className:"text-sm"}),e.jsxs("span",{className:"ml-auto text-[10px] text-fg-faint",children:[t.series.length,"d"]})]}),!t&&i&&i.series.length>0&&e.jsxs("div",{className:"mt-3 flex items-center gap-2 border-t border-line-faint pt-3",children:[e.jsx(j,{data:i.series,color:f,className:"text-sm"}),e.jsx("span",{className:"ml-auto text-[10px] text-fg-faint",children:i.summary})]}),x.length===0&&((w=s.billing)==null?void 0:w.error)&&e.jsxs("div",{className:`flex items-start gap-1.5 text-xs text-warning ${t?"mt-3 border-t border-line-faint pt-3":"mt-4"}`,children:[e.jsx("span",{"aria-hidden":!0,children:"⚠"}),e.jsx("span",{children:T(s.billing.error,a)})]}),!t&&x.length===0&&!((y=s.billing)!=null&&y.error)&&m.length===0&&!(i&&i.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 g({label:s,cost:n,tokens:l}){const a=n>0||l===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?o(n):u(l)}),e.jsx("div",{className:"tnum text-[10px] text-fg-faint",children:a?u(l):o(n)})]})}function O(s){return s.format.kind==="dollars"?o(s.used):s.format.kind==="count"?`${h(s.used)}${s.format.suffix?" "+s.format.suffix:""}`:`${Math.round(s.used)}%`}function q({metric:s,resetDisplay:n,tz:l}){const a=s.format.kind==="percent"?Math.min(1,Math.max(0,s.used/100)):s.limit!=null&&s.limit>0?Math.min(1,Math.max(0,s.used/s.limit)):null,r=a==null?"var(--color-accent)":a>=.9?"var(--color-warning)":a>=.7?"var(--color-cost)":"var(--color-positive)";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:[O(s),s.format.kind!=="percent"&&s.limit!=null&&e.jsxs("span",{className:"text-fg-faint",children:[" / ",s.format.kind==="dollars"?o(s.limit):h(s.limit)]}),s.resetsAt&&e.jsxs("span",{className:"ml-1.5 text-fg-faint",children:["· ",A(s.resetsAt,n,Date.now(),l)]})]})]}),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,"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:r}})})]})}const K=$.lazy(()=>L(()=>import("./timeline-B4uG-Emo.js"),__vite__mapDeps([0,1,2,3,4,5,6]),import.meta.url).then(s=>({default:s.CostTimeline})));function F({derived:s,periodLabel:n,scopeLabel:l,providers:a,privacyMode:r,resetDisplay:c,tz:t}){const x=new Map(a.map(i=>[i.id,i.name])),m=i=>x.get(i)??i;return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx(E,{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(K,{derived:s,periodLabel:l,heightClass:"h-[clamp(320px,42vh,560px)]"})}),e.jsx(D,{accounts:s.cardAccounts,nameOf:m,privacyMode:r,resetDisplay:c,tz:t})]})}export{F as OverviewTab};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as l,j as e,y as p,C as d}from"./index-DH3dOnbg.js";function b({title:a,titleTag:r,right:s,captureName:t,children:o,className:i="",bodyClassName:c=""}){const n=l.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:[a&&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:a}),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}),t&&e.jsx("div",{"data-chrome":!0,className:"absolute -top-[11px] right-3 z-20",children:e.jsx(u,{getNode:()=>n.current,name:t})}),e.jsx("div",{className:`p-4 ${c}`,children:o})]})}function u({getNode:a,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 t=a();t&&s({kind:"panel",node:t,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 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent",children:e.jsx(d,{className:"size-3.5"})})}export{b as P};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{j as e}from"./index-DH3dOnbg.js";const r=["▁","▂","▃","▄","▅","▆","▇","█"];function m({data:t,color:a="var(--color-accent)",className:s=""}){const n=r.length-1,i=Math.max(...t,0),l=Math.min(...t,0),c=i>0&&l===i;return e.jsx("span",{className:`font-mono leading-none ${s}`,style:{color:a},"aria-hidden":!0,children:t.length===0?"·":c?r[Math.floor(n/2)].repeat(t.length):t.map(x=>r[i<=0?0:Math.max(0,Math.min(n,Math.floor(x/i*(n+.999))))]).join("")})}function f({label:t,value:a,sub:s,valueClass:n="text-fg-bright"}){return e.jsxs("div",{children:[e.jsx("div",{className:"font-display text-[10px] uppercase tracking-wide text-fg-faint",children:t}),e.jsx("div",{className:`tnum mt-1 text-xl ${n}`,children:a}),s!=null&&e.jsx("div",{className:"mt-0.5 text-xs text-fg-dim",children:s})]})}function h({children:t}){return e.jsx("div",{className:"flex h-full min-h-24 items-center justify-center text-center text-xs text-fg-faint",children:t})}export{h as E,m as S,f as a};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{B as V,E as re,F as O,G as X,j as e,r as i,S as A,H as q,I as se,J as ae,K as H,L as D,N as le,P as oe,O as Y,Q as Z,U as W,V as ie,W as ce,Y as de,Z as ue,$ as U,X as ee,a0 as xe,a1 as fe,a2 as me}from"./index-DH3dOnbg.js";import{F as b,u as te}from"./use-dialog-trap-bfaXEMz9.js";function be(t,r,s,n){return s?{draft:t,revision:r,conflict:r!==null&&n.config.revision>r}:r!==null&&n.config.revision<r?{draft:t,revision:r,conflict:!1}:{draft:n.config,revision:n.config.revision,conflict:!1}}function ge(t){var r;if(t&&typeof t=="object"){const s=t;if(s.kind==="conflict"){const n=s.state,l=(r=n==null?void 0:n.config)==null?void 0:r.revision;return{message:typeof l=="number"?`configuration changed elsewhere (daemon revision ${l})`:"settings changed elsewhere; reload before saving",conflictState:n!=null&&n.config&&typeof l=="number"?n:null}}if(s.kind==="persistence"&&typeof s.message=="string")return{message:s.message,conflictState:null}}return{message:t instanceof Error?t.message:"config update failed",conflictState:null}}function J(t,r={}){return{mode:"add",editingId:null,providerId:r.providerId??V[0],name:r.name??"",homeDir:r.homeDir??"~",color:r.color??re(t.accounts)}}function pe(t){return{mode:"edit",editingId:t.id,providerId:t.providerId,name:t.name,homeDir:t.homeDir,color:t.color||O[t.providerId].color}}function he(t,r){const s=t.mode==="edit"?r.filter(n=>n.id!==t.editingId):r;return t.mode==="edit"?t.editingId??"":X(t.name.trim()||"account",s)}function ve(t,r){const s=t.name.trim(),n=t.homeDir.trim()||"~";return s?t.mode==="add"?{ok:!0,account:{id:X(s,r),providerId:t.providerId,name:s,homeDir:n,color:t.color},mode:"add",editingId:null}:{ok:!0,account:{id:t.editingId,providerId:t.providerId,name:s,homeDir:n,color:t.color},mode:"edit",editingId:t.editingId}:{ok:!1,error:"Name required"}}function G({title:t,right:r,children:s}){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}),r&&e.jsx("div",{className:"ml-auto",children:r})]}),s]})}function C({label:t,hint:r,children:s}){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}),r&&e.jsx("div",{className:"text-[11px] text-fg-faint",children:r})]}),e.jsx("div",{className:"shrink-0",children:s})]})}function M({label:t,hint:r,children:s}){return e.jsxs("div",{children:[e.jsx("div",{className:"mb-1.5 text-xs font-medium text-fg",children:t}),s,r&&e.jsx("div",{className:"mt-1 text-[11px] text-fg-faint",children:r})]})}function Q({label:t,value:r,min:s,unit:n,onChange:l}){const o=u=>l(Math.max(s,Math.round(u))),[f,g]=i.useState(null),h=()=>{if(f===null)return;const u=Number(f);o(Number.isFinite(u)&&f.trim()!==""?u:s),g(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:()=>o(r-1),className:`px-2 py-1 text-xs text-fg-dim transition hover:bg-bg-3 hover:text-fg ${b}`,children:"−"}),e.jsx("input",{type:"number",name:t.toLowerCase().replace(/\s+/g,"-"),autoComplete:"off",inputMode:"numeric",min:s,value:f??r,onChange:u=>{const p=u.target.value;g(p);const v=Number(p);p.trim()!==""&&Number.isFinite(v)&&v>=s&&o(v)},onBlur:h,"aria-label":`${t} (${n})`,className:`tnum w-12 border-x border-line bg-bg-2 px-1 py-1 text-center text-xs text-fg ${b} [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:n}),e.jsx("button",{type:"button","aria-label":"increase",onClick:()=>o(r+1),className:`px-2 py-1 text-xs text-fg-dim transition hover:bg-bg-3 hover:text-fg ${b}`,children:"+"})]})}function F({label:t,onClick:r,disabled:s,danger:n,children:l}){return e.jsx("button",{type:"button","aria-label":t,title:t,disabled:s,onClick:r,className:`rounded p-1 text-fg-faint transition disabled:opacity-30 ${b} ${n?"hover:bg-warning/15 hover:text-warning":"hover:bg-bg-3 hover:text-fg"} disabled:hover:bg-transparent disabled:hover:text-fg-faint`,children:l})}function je({draft:t,patch:r}){return e.jsxs(G,{title:"General",children:[e.jsx(C,{label:"Refresh interval",hint:"dashboard poll, seconds",children:e.jsx(Q,{label:"Refresh interval",value:t.interval,min:1,unit:"s",onChange:s=>r(n=>({...n,interval:s}))})}),e.jsx(C,{label:"Billing poll",hint:"billing refresh, minutes",children:e.jsx(Q,{label:"Billing poll",value:t.billingInterval,min:1,unit:"m",onChange:s=>r(n=>({...n,billingInterval:s}))})}),e.jsx(C,{label:"Clear screen",hint:"redraw on each refresh",children:e.jsx(A,{size:"xs",ariaLabel:"clear screen",options:[{value:"on",label:"on"},{value:"off",label:"off"}],value:t.clearScreen?"on":"off",onChange:s=>r(n=>({...n,clearScreen:s==="on"}))})}),e.jsx(C,{label:"Privacy mode",hint:"hide email addresses by default",children:e.jsx(A,{size:"xs",ariaLabel:"privacy mode",options:[{value:"on",label:"on"},{value:"off",label:"off"}],value:t.privacyMode?"on":"off",onChange:s=>r(n=>({...n,privacyMode:s==="on"}))})}),e.jsx(C,{label:"Timezone",hint:"IANA name · empty = System",children:e.jsx(Ne,{value:t.timezone,onChange:s=>r(n=>({...n,timezone:s}))})}),e.jsx(C,{label:"Dashboard",hint:"grid shows all · single cycles",children:e.jsx(A,{size:"xs",ariaLabel:"dashboard layout",options:[{value:"grid",label:"grid"},{value:"single",label:"single"}],value:t.dashboardLayout,onChange:s=>r(n=>({...n,dashboardLayout:s}))})}),e.jsx(C,{label:"Default focus",hint:"on open",children:e.jsx(A,{size:"xs",ariaLabel:"default focus",options:[{value:"all",label:"all"},{value:"last",label:"last"}],value:t.defaultFocus,onChange:s=>r(n=>({...n,defaultFocus:s}))})}),e.jsx(C,{label:"ASCII mode",hint:"glyph fallback",children:e.jsx(A,{size:"xs",ariaLabel:"ascii mode",options:[{value:"auto",label:"auto"},{value:"on",label:"on"},{value:"off",label:"off"}],value:t.ascii,onChange:s=>r(n=>({...n,ascii:s}))})}),e.jsx(C,{label:"Network access",hint:"applies on daemon restart",children:e.jsx(A,{size:"xs",ariaLabel:"network access",options:[{value:"local",label:"local only"},{value:"network",label:"LAN"}],value:t.allowNetworkAccess?"network":"local",onChange:s=>r(n=>({...n,allowNetworkAccess:s==="network"}))})}),t.allowNetworkAccess&&e.jsxs(e.Fragment,{children:[e.jsx(C,{label:"Allowed hosts",hint:"exact DNS names · comma separated",children:e.jsx(ye,{value:t.allowedHosts,onChange:s=>r(n=>({...n,allowedHosts:s}))})}),e.jsx("p",{className:"rounded border border-warning/50 bg-warning/10 px-3 py-2 text-xs text-warning",role:"alert",children:"Unsafe: after the daemon restarts, usage data and settings will be reachable from your local network."})]}),e.jsx(C,{label:"Reset times",hint:"quota and peak changes",children:e.jsx(A,{size:"xs",ariaLabel:"reset time display",options:[{value:"relative",label:"remaining"},{value:"absolute",label:"date/time"}],value:t.resetDisplay,onChange:s=>r(n=>({...n,resetDisplay:s}))})})]})}function ye({value:t,onChange:r}){const[s,n]=i.useState(t.join(", ")),[l,o]=i.useState(!1),f=i.useId(),g=i.useRef(null),h=t.join(", ");i.useEffect(()=>{if(g.current===h){g.current=null;return}n(h),o(!1)},[h]);const u=p=>{const v=q(p);n(v);const d=v.split(",").map(j=>j.trim()).filter(Boolean).map(ae),x=d.some(j=>j===null);if(o(x),!x){const j=[...new Set(d)];g.current=j.join(", "),r(j)}};return e.jsxs("div",{className:"flex flex-col items-end gap-0.5",children:[e.jsx("input",{type:"text",name:"allowed-hosts",value:s,placeholder:"tokmon.example.com","aria-label":"Allowed hosts","aria-describedby":l?f:void 0,autoComplete:"off",spellCheck:!1,"aria-invalid":l,onChange:p=>u(p.target.value),className:`w-64 rounded border bg-bg-2 px-2 py-1 text-xs text-fg ${b} ${l?"border-warning":"border-line"}`}),l&&e.jsx("span",{id:f,className:"text-[10px] text-warning",role:"alert",children:"Use exact hostnames without a scheme, port, path, or wildcard."})]})}function Ne({value:t,onChange:r}){const[s,n]=i.useState(t??""),[l,o]=i.useState(!1),f=i.useId();i.useEffect(()=>{n(t??""),o(!1)},[t]);const g=h=>{const u=q(h);n(u);const p=u.trim();if(!p){o(!1),r(null);return}se(p)?(o(!1),r(p)):o(!0)};return e.jsxs("div",{className:"flex flex-col items-end gap-0.5",children:[e.jsx("input",{type:"text",name:"timezone",value:s,placeholder:"e.g. Europe/Bucharest…","aria-label":"Timezone","aria-describedby":l?f:void 0,autoComplete:"off",spellCheck:!1,"aria-invalid":l,onChange:h=>g(h.target.value),className:`w-44 rounded border bg-bg-2 px-2 py-1 text-xs text-fg ${b} ${l?"border-warning":"border-line"}`}),l&&e.jsx("span",{id:f,className:"text-[10px] text-warning",role:"alert",children:"Use an IANA zone such as Europe/Bucharest."})]})}function we({draft:t,patch:r}){const s=(n,l)=>r(o=>({...o,knownProviders:o.knownProviders.includes(n)?o.knownProviders:[...o.knownProviders,n],disabledProviders:l?o.disabledProviders.filter(f=>f!==n):Array.from(new Set([...o.disabledProviders,n]))}));return e.jsx(G,{title:"Providers",children:e.jsx("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-2",children:V.map(n=>{const l=!t.disabledProviders.includes(n),o=O[n];return e.jsxs("button",{type:"button",role:"switch","aria-checked":l,onClick:()=>s(n,!l),className:`flex items-center gap-2.5 rounded border px-3 py-2 text-left text-xs transition ${b} ${l?"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:"inline-flex size-4 shrink-0 items-center justify-center rounded-sm border",style:{borderColor:l?D(o.color):"var(--color-line-2)",background:l?D(o.color):"transparent"},children:l&&e.jsx(H,{className:"size-3 text-bg-0"})}),e.jsx("span",{className:"size-2 shrink-0 rounded-full",style:{background:D(o.color)},"aria-hidden":!0}),e.jsx("span",{className:`font-medium ${l?"text-fg":"text-fg-faint"}`,children:o.name}),e.jsx("span",{className:"ml-auto text-[10px] uppercase tracking-wide text-fg-faint",children:l?"tracking":"off"})]},n)})})})}function ke(t,r){return r?r.accounts.find(s=>s.id===t.id)??null:null}function Ce({draft:t,patch:r,snapshot:s,onEdit:n,onConfigure:l,onAdd:o}){const f=le(t,void 0,(s==null?void 0:s.accounts)??void 0),[g,h]=i.useState(null),u=a=>r(d=>({...d,activeAccountId:a})),p=a=>{if(g!==a){h(a);return}r(d=>({...d,accounts:d.accounts.filter(x=>x.id!==a),activeAccountId:d.activeAccountId===a?null:d.activeAccountId})),h(null)},v=(a,d)=>r(x=>{const j=[...x.accounts],N=a+d;return N<0||N>=j.length?x:([j[a],j[N]]=[j[N],j[a]],{...x,accounts:j})});return e.jsx(G,{title:"Accounts",right:e.jsxs("button",{type:"button",onClick:o,className:`flex items-center gap-1 rounded border border-accent/60 bg-bg-1 px-2 py-1 text-[11px] text-accent transition hover:bg-bg-2 ${b}`,children:[e.jsx(ce,{className:"size-3"})," Add account"]}),children:f.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:f.map(a=>{var $;const d=O[a.providerId],x=ke(a,s),j=(x==null?void 0:x.email)||(x==null?void 0:x.displayName)||a.name||d.name,N=(x==null?void 0:x.plan)??(($=x==null?void 0:x.billing)==null?void 0:$.plan)??null,k=D(a.color||d.color),w=a.id===t.activeAccountId,I=a.source==="configured";return e.jsxs("li",{className:"flex items-center gap-2.5 rounded border border-line bg-bg-2/60 px-2.5 py-2",children:[e.jsx("button",{type:"button",role:"radio","aria-checked":w,"aria-label":`Set ${a.name} active`,title:w?"Active account (click to clear)":"Set active",onClick:()=>u(w?null:a.id),className:`relative inline-flex size-4 shrink-0 items-center justify-center rounded-full border transition ${b}`,style:{borderColor:k},children:w&&e.jsx("span",{className:"size-2 rounded-full",style:{background:k}})}),e.jsx("span",{className:"size-2.5 shrink-0 rounded-full",style:{background:k},"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(oe,{value:j,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:d.name}),N&&e.jsx("span",{className:"shrink-0 rounded border border-line px-1.5 py-0.5 text-[10px] text-fg-dim",children:N}),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:a.source==="auto"?"auto":"configured"})]}),e.jsx("div",{className:"truncate font-mono text-[11px] text-fg-faint",children:a.homeDir})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-0.5",children:[g===a.id?e.jsx("span",{className:"mr-1 text-[10px] text-warning",role:"alert",children:"Delete?"}):null,I&&a.explicitIndex!==void 0?e.jsxs(e.Fragment,{children:[e.jsx(F,{label:"Move up",disabled:a.explicitIndex===0,onClick:()=>v(a.explicitIndex,-1),children:e.jsx(Y,{className:"size-3.5"})}),e.jsx(F,{label:"Move down",disabled:a.explicitIndex===t.accounts.length-1,onClick:()=>v(a.explicitIndex,1),children:e.jsx(Z,{className:"size-3.5"})}),e.jsx(F,{label:"Edit account",onClick:()=>n(a),children:e.jsx(W,{className:"size-3.5"})}),e.jsx(F,{label:g===a.id?"Confirm delete account":"Delete account",danger:!0,onClick:()=>p(a.id),children:e.jsx(ie,{className:"size-3.5"})})]}):e.jsx(F,{label:"Configure account",onClick:()=>l(a),children:e.jsx(W,{className:"size-3.5"})})]})]},`${a.source}:${a.id}`)})})})}function Ie(t){const r=(t??"").trim();return r.length>0?r:"~"}function _(t){const r=(t??"").trim();return r.length>0?r:"~"}function Se(t){const r=[];t.parent!==null&&r.push({kind:"parent",key:"..",label:"..",path:t.parent});for(const s of[...t.entries].filter(n=>n.dir).sort((n,l)=>n.name.localeCompare(l.name)))r.push({kind:"entry",key:s.path,label:s.name,path:s.path});return r}function ze({editor:t,accounts:r,onChange:s,onCancel:n,onSubmit:l}){const o=i.useRef(null),f=i.useRef(null),[g,h]=i.useState(null),u=D(t.color);te(o,{active:!0,onEscape:n,initialFocusRef:f});const p=he(t,r),v=()=>{const a=ve(t,r);if(!a.ok){h(a.error);return}l(a.account,a.mode,a.editingId)};return e.jsx("div",{className:"dialog-fade fixed inset-0 z-[70] flex items-start justify-center overflow-y-auto overscroll-contain bg-bg-0/60 p-4 backdrop-blur-sm",onMouseDown:a=>{a.target===a.currentTarget&&n()},role:"dialog","aria-modal":"true","aria-labelledby":"account-editor-title",children:e.jsxs("div",{ref:o,tabIndex:-1,className:"dialog-pop my-8 w-full max-w-[460px] overflow-hidden rounded-md border-l-2 border border-line-2 bg-bg-1 focus:outline-none",style:{borderLeftColor:u},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:u},"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(M,{label:"Provider",hint:"which tool this account tracks",children:e.jsx("div",{className:"flex flex-wrap gap-1.5",children:V.map(a=>{const d=a===t.providerId,x=O[a];return e.jsxs("button",{type:"button",onClick:()=>s({...t,providerId:a}),"aria-pressed":d,className:`flex items-center gap-1.5 rounded border px-2 py-1 text-xs transition ${b} ${d?"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:D(x.color)},"aria-hidden":!0}),x.name]},a)})})}),e.jsx(M,{label:"Name",hint:"display name for this account",children:e.jsx("input",{ref:f,type:"text",name:"account-name",value:t.name,placeholder:"e.g. Work…","aria-label":"Account name",autoComplete:"off",spellCheck:!1,onChange:a=>{h(null),s({...t,name:q(a.target.value)})},onKeyDown:a=>{a.key==="Enter"&&v()},className:`w-full rounded border border-line bg-bg-2 px-2.5 py-1.5 text-sm text-fg ${b}`})}),e.jsx(M,{label:"Home directory",hint:"path containing the tool's data dir · ~ for default",children:e.jsx(Ee,{value:t.homeDir,onChange:a=>s({...t,homeDir:a}),onEnter:v})}),e.jsx(M,{label:"Accent color",hint:"shows on dashboard, account strip, borders",children:e.jsx("div",{className:"flex flex-wrap gap-1.5",children:de.map(a=>{const d=a===t.color;return e.jsx("button",{type:"button","aria-label":a,"aria-pressed":d,title:a,onClick:()=>s({...t,color:a}),className:`size-6 rounded-full border-2 transition ${b} ${d?"scale-110":"border-transparent hover:scale-105"}`,style:{background:D(a),borderColor:d?"var(--color-fg-bright)":"transparent"}},a)})})}),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:u},children:p||"account"}),e.jsx("span",{className:"ml-auto text-[10px] text-fg-faint",children:t.mode==="add"?"auto-generated from name":"fixed"})]}),g&&e.jsxs("p",{className:"text-xs text-warning",role:"alert",children:[g,". 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("button",{type:"button",onClick:n,className:`rounded border border-line bg-bg-1 px-3 py-1.5 text-xs text-fg-dim transition hover:border-line-2 hover:text-fg ${b}`,children:"cancel"}),e.jsxs("button",{type:"button",onClick:v,className:`flex items-center gap-1.5 rounded border border-accent/60 bg-bg-1 px-3 py-1.5 text-xs text-accent transition hover:bg-bg-2 active:scale-[0.97] ${b}`,children:[e.jsx(H,{className:"size-3.5"})," ",t.mode==="add"?"Add account":"Save account"]})]})]})})}function Ee({value:t,onChange:r,onEnter:s}){const[n,l]=i.useState(!1),[o,f]=i.useState(null),[g,h]=i.useState("~"),[u,p]=i.useState(!1),[v,a]=i.useState(null),d=i.useRef(0),x=i.useCallback(async y=>{const z=++d.current,R=Ie(y);h(R),p(!0),a(null);try{const E=await ue(R);if(z!==d.current)return;f(E)}catch(E){if(z!==d.current)return;f(null),a(E instanceof Error?E.message:"cannot read folder")}finally{z===d.current&&p(!1)}},[]);i.useEffect(()=>()=>{d.current++},[]);const j=()=>{l(!0),x(t)},N=()=>{d.current++,l(!1),p(!1),a(null)},k=y=>{u||x(y)},w=()=>{!o||u||(r(_(o.path)),N())},I=o?Se(o):[],$=I.filter(y=>y.kind==="entry"),S=_((o==null?void 0:o.path)??g);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(U,{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:y=>{N(),r(q(y.target.value))},onKeyDown:y=>{y.key==="Enter"&&s()},className:`min-w-0 flex-1 bg-transparent py-1.5 font-mono text-sm text-fg ${b}`})]}),e.jsxs("button",{type:"button",onClick:j,disabled:u,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 ${b}`,children:[e.jsx(Z,{className:"size-3.5"})," Browse"]})]}),n&&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(U,{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:S,children:S}),u&&e.jsx("span",{className:"shrink-0 text-[10px] uppercase tracking-wide text-fg-faint",children:"loading"}),e.jsx("button",{type:"button",onClick:N,"aria-label":"Close folder picker",className:`rounded p-1 text-fg-faint transition hover:text-fg ${b}`,children:e.jsx(ee,{className:"size-3.5"})})]}),v?e.jsxs("div",{className:"px-2.5 py-3",children:[e.jsxs("div",{className:"text-xs text-warning",children:["can't read ",_(g)]}),e.jsx("button",{type:"button",onClick:()=>{u||x(g)},disabled:u,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 ${b}`,children:"retry"})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"max-h-56 overflow-y-auto py-1",children:[I.map(y=>e.jsxs("button",{type:"button",onClick:()=>k(y.path),disabled:u,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 ${b} ${y.kind==="parent"?"text-fg-dim":"text-fg"}`,children:[y.kind==="parent"?e.jsx(Y,{className:"size-3.5 shrink-0"}):e.jsx(U,{className:"size-3.5 shrink-0 text-fg-faint"}),e.jsx("span",{className:"min-w-0 truncate font-mono",children:y.label})]},y.key)),!u&&$.length===0&&e.jsx("div",{className:"px-2.5 py-3 text-xs text-fg-faint",children:"no subdirectories"}),u&&!o&&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("button",{type:"button",onClick:w,disabled:!o||u,className:`flex items-center gap-1.5 rounded border border-accent/60 bg-bg-1 px-2.5 py-1.5 text-xs text-accent transition hover:bg-bg-2 active:scale-[0.97] disabled:opacity-50 ${b}`,children:[e.jsx(H,{className:"size-3.5"})," Select this folder"]})})]})]})]})}const Ae=[{value:"general",label:"General"},{value:"providers",label:"Providers"},{value:"accounts",label:"Accounts"}];function Re({onClose:t,snapshot:r}){const s=i.useRef(null),[n,l]=i.useState(null),[o,f]=i.useState(null),[g,h]=i.useState(null),[u,p]=i.useState(!1),[v,a]=i.useState(null),[d,x]=i.useState(!1),[j,N]=i.useState(!1),[k,w]=i.useState(null),[I,$]=i.useState("general"),S=i.useRef(!1),y=i.useRef(!1),z=i.useRef(null),R=i.useRef(null),E=i.useCallback(c=>{h(null);const m=be(z.current,R.current,S.current,c);S.current||(z.current=m.draft,R.current=m.revision,l(m.draft),f(m.revision)),m.conflict&&a("settings changed elsewhere; close and reopen settings before saving")},[]);i.useEffect(()=>{let c=!0;return xe().then(m=>{c&&E(m)}).catch(m=>{c&&h(m instanceof Error?m.message:"load failed")}),()=>{c=!1}},[E]),i.useEffect(()=>{const c=m=>{S.current&&m.preventDefault()};return window.addEventListener("beforeunload",c),()=>window.removeEventListener("beforeunload",c)},[]),i.useEffect(()=>{let c=!0;const m=fe(P=>{c&&E(P)});return()=>{c=!1,m()}},[E]);const L=()=>{if(!S.current||y.current){t();return}y.current=!0,N(!0),a("unsaved changes; choose discard to close settings")};te(s,{active:!k,onEscape:L}),i.useEffect(()=>{const c=s.current;c&&(k?c.setAttribute("inert",""):c.removeAttribute("inert"))},[k]);const T=c=>{const m=z.current;if(!m)return;const P={...c(m),revision:m.revision};S.current=!0,z.current=P,x(!0),y.current=!1,N(!1),a(null),l(P)},ne=async()=>{if(n){p(!0),a(null);try{if(o===null)throw new Error("config revision is unavailable");const c=await me(n,o);z.current=c.config,R.current=c.config.revision,S.current=!1,l(c.config),f(c.config.revision),x(!1),t()}catch(c){const m=ge(c);a(m.conflictState?`${m.message}; close and reopen settings before saving`:m.message)}finally{p(!1)}}};return e.jsxs("div",{className:"dialog-fade fixed inset-0 z-[60] flex items-start justify-center overflow-y-auto overscroll-contain bg-bg-0/70 p-4 backdrop-blur-sm",onMouseDown:c=>{c.target===c.currentTarget&&!k&&L()},role:"dialog","aria-modal":"true","aria-labelledby":"settings-title",children:[e.jsxs("div",{ref:s,tabIndex:-1,className:"dialog-pop relative my-6 flex w-full max-w-[720px] flex-col overflow-hidden rounded-md border border-line-2 bg-bg-1 focus:outline-none",children:[e.jsx("h2",{id:"settings-title",className:"pointer-events-none absolute left-3 top-2 font-display text-[11px] uppercase tracking-wider text-fg-dim",children:"settings"}),e.jsx("button",{type:"button",onClick:L,"aria-label":"Close",className:`absolute right-2 top-2 z-10 rounded p-1 text-fg-faint transition hover:text-fg ${b}`,children:e.jsx(ee,{className:"size-4"})}),e.jsx("div",{className:"max-h-[78vh] overflow-y-auto px-5 pb-4 pt-9",children:g&&!n?e.jsxs("div",{className:"rounded border border-warning/50 bg-bg-2 p-4 text-sm text-warning",role:"alert",children:["Could not load settings: ",g,". Close settings and try again."]}):n?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mb-4 flex items-center justify-between gap-3 border-b border-line pb-3",children:e.jsx(A,{size:"xs",ariaLabel:"settings section",options:Ae,value:I,onChange:$,containerClassName:"flex items-center overflow-hidden rounded border border-line bg-bg-1",btnClassName:"px-3 py-1.5 text-[11px] transition"})}),I==="general"&&e.jsx(je,{draft:n,patch:T}),I==="providers"&&e.jsx(we,{draft:n,patch:T}),I==="accounts"&&e.jsx(Ce,{draft:n,patch:T,snapshot:r,onEdit:c=>w(pe(c)),onConfigure:c=>w(J(n,{providerId:c.providerId,name:c.name,homeDir:c.homeDir,color:c.color})),onAdd:()=>w(J(n))})]}):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:[v&&e.jsx("span",{className:"mr-auto text-xs text-warning",role:"alert",children:v}),d&&!v&&e.jsx("span",{className:"mr-auto text-xs text-fg-faint",role:"status","aria-live":"polite",children:"unsaved changes"}),e.jsx("button",{type:"button",onClick:L,className:`rounded border border-line bg-bg-1 px-3 py-1.5 text-xs text-fg-dim transition hover:border-line-2 hover:text-fg ${b}`,children:j?"discard":"cancel"}),e.jsxs("button",{type:"button",onClick:ne,disabled:!n||u||!d,className:`flex items-center gap-1.5 rounded border border-accent/60 bg-bg-1 px-3 py-1.5 text-xs text-accent transition hover:bg-bg-2 active:scale-[0.97] disabled:opacity-50 ${b}`,children:[e.jsx(H,{className:"size-3.5"})," ",u?"saving…":"save"]})]})]}),k&&n&&e.jsx(ze,{editor:k,accounts:n.accounts,onChange:w,onCancel:()=>w(null),onSubmit:(c,m,P)=>{T(B=>m==="add"?{...B,accounts:[...B.accounts,c]}:{...B,accounts:B.accounts.map(K=>K.id===P?c:K)}),w(null)}})]})}export{Re as SettingsSheet};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{j as i,r as x,f as O,a as M,b as ft,s as ze,n as dt,R as P,m as mt,o as pt,x as we,T as Y,e as ht,g as xt,X as je,S as V,K as Se,a3 as gt,a4 as yt}from"./index-DH3dOnbg.js";import{S as bt}from"./primitives-C36qJlA2.js";import{S as Pe,V as vt,d as de,L as G,n as wt,w as jt,y as Q,z as St,J as De,W as Pt,v as re,Z as kt,j as At,q as Et,c as Ct,t as D,E as Nt,H as Ot,K as Rt,_ as ke,F as Tt,g as $t,X as Me,Y as Be,P as Ke,f as _t,R as Lt,a as It,G as Ft}from"./chart-cZoLgpmG.js";import{L as zt,A as He}from"./Area-CMXvOw33.js";import{u as Dt}from"./use-dialog-trap-bfaXEMz9.js";function Mt(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(),r=n.createElement("base"),a=n.createElement("a");return n.head.appendChild(r),n.body.appendChild(a),t&&(r.href=t),a.href=e,a.href}const Bt=(()=>{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,r=e.length;n<r;n++)t.push(e[n]);return t}let F=null;function We(e={}){return F||(e.includeStyleProperties?(F=e.includeStyleProperties,F):(F=T(window.getComputedStyle(document.documentElement)),F))}function ae(e,t){const r=(e.ownerDocument.defaultView||window).getComputedStyle(e).getPropertyValue(t);return r?parseFloat(r.replace("px","")):0}function Kt(e){const t=ae(e,"border-left-width"),n=ae(e,"border-right-width");return e.clientWidth+t+n}function Ht(e){const t=ae(e,"border-top-width"),n=ae(e,"border-bottom-width");return e.clientHeight+t+n}function Ue(e,t={}){const n=t.width||Kt(e),r=t.height||Ht(e);return{width:n,height:r}}function Wt(){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 E=16384;function Ut(e){(e.width>E||e.height>E)&&(e.width>E&&e.height>E?e.width>e.height?(e.height*=E/e.width,e.width=E):(e.width*=E/e.height,e.height=E):e.width>E?(e.height*=E/e.width,e.width=E):(e.width*=E/e.height,e.height=E))}function Vt(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 r=window.atob(e.toDataURL(t.type?t.type:void 0,t.quality?t.quality:void 0).split(",")[1]),a=r.length,s=new Uint8Array(a);for(let o=0;o<a;o+=1)s[o]=r.charCodeAt(o);n(new Blob([s],{type:t.type?t.type:"image/png"}))})}function ie(e){return new Promise((t,n)=>{const r=new Image;r.onload=()=>{r.decode().then(()=>{requestAnimationFrame(()=>t(r))})},r.onerror=n,r.crossOrigin="anonymous",r.decoding="async",r.src=e})}async function Gt(e){return Promise.resolve().then(()=>new XMLSerializer().serializeToString(e)).then(encodeURIComponent).then(t=>`data:image/svg+xml;charset=utf-8,${t}`)}async function qt(e,t,n){const r="http://www.w3.org/2000/svg",a=document.createElementNS(r,"svg"),s=document.createElementNS(r,"foreignObject");return a.setAttribute("width",`${t}`),a.setAttribute("height",`${n}`),a.setAttribute("viewBox",`0 0 ${t} ${n}`),s.setAttribute("width","100%"),s.setAttribute("height","100%"),s.setAttribute("x","0"),s.setAttribute("y","0"),s.setAttribute("externalResourcesRequired","true"),a.appendChild(s),s.appendChild(e),Gt(a)}const k=(e,t)=>{if(e instanceof t)return!0;const n=Object.getPrototypeOf(e);return n===null?!1:n.constructor.name===t.name||k(n,t)};function Xt(e){const t=e.getPropertyValue("content");return`${e.cssText} content: '${t.replace(/'|"/g,"")}';`}function Zt(e,t){return We(t).map(n=>{const r=e.getPropertyValue(n),a=e.getPropertyPriority(n);return`${n}: ${r}${a?" !important":""};`}).join(" ")}function Jt(e,t,n,r){const a=`.${e}:${t}`,s=n.cssText?Xt(n):Zt(n,r);return document.createTextNode(`${a}{${s}}`)}function Ae(e,t,n,r){const a=window.getComputedStyle(e,n),s=a.getPropertyValue("content");if(s===""||s==="none")return;const o=Bt();try{t.className=`${t.className} ${o}`}catch{return}const l=document.createElement("style");l.appendChild(Jt(o,n,a,r)),t.appendChild(l)}function Yt(e,t,n){Ae(e,t,":before",n),Ae(e,t,":after",n)}const Ee="application/font-woff",Ce="image/jpeg",Qt={woff:Ee,woff2:Ee,ttf:"application/font-truetype",eot:"application/vnd.ms-fontobject",png:"image/png",jpg:Ce,jpeg:Ce,gif:"image/gif",tiff:"image/tiff",svg:"image/svg+xml",webp:"image/webp"};function en(e){const t=/\.([^./]*?)$/g.exec(e);return t?t[1]:""}function ge(e){const t=en(e).toLowerCase();return Qt[t]||""}function tn(e){return e.split(/,/)[1]}function pe(e){return e.search(/^(data:)/)!==-1}function nn(e,t){return`data:${t};base64,${e}`}async function Ve(e,t,n){const r=await fetch(e,t);if(r.status===404)throw new Error(`Resource "${r.url}" not found`);const a=await r.blob();return new Promise((s,o)=>{const l=new FileReader;l.onerror=o,l.onloadend=()=>{try{s(n({res:r,result:l.result}))}catch(c){o(c)}},l.readAsDataURL(a)})}const me={};function rn(e,t,n){let r=e.replace(/\?.*/,"");return n&&(r=e),/ttf|otf|eot|woff2?/i.test(r)&&(r=r.replace(/.*\//,"")),t?`[${t}]${r}`:r}async function ye(e,t,n){const r=rn(e,t,n.includeQueryParams);if(me[r]!=null)return me[r];n.cacheBust&&(e+=(/\?/.test(e)?"&":"?")+new Date().getTime());let a;try{const s=await Ve(e,n.fetchRequestInit,({res:o,result:l})=>(t||(t=o.headers.get("Content-Type")||""),tn(l)));a=nn(s,t)}catch(s){a=n.imagePlaceholder||"";let o=`Failed to fetch resource: ${e}`;s&&(o=typeof s=="string"?s:s.message),o&&console.warn(o)}return me[r]=a,a}async function an(e){const t=e.toDataURL();return t==="data:,"?e.cloneNode(!1):ie(t)}async function sn(e,t){if(e.currentSrc){const s=document.createElement("canvas"),o=s.getContext("2d");s.width=e.clientWidth,s.height=e.clientHeight,o==null||o.drawImage(e,0,0,s.width,s.height);const l=s.toDataURL();return ie(l)}const n=e.poster,r=ge(n),a=await ye(n,r,t);return ie(a)}async function on(e,t){var n;try{if(!((n=e==null?void 0:e.contentDocument)===null||n===void 0)&&n.body)return await le(e.contentDocument.body,t,!0)}catch{}return e.cloneNode(!1)}async function ln(e,t){return k(e,HTMLCanvasElement)?an(e):k(e,HTMLVideoElement)?sn(e,t):k(e,HTMLIFrameElement)?on(e,t):e.cloneNode(Ge(e))}const cn=e=>e.tagName!=null&&e.tagName.toUpperCase()==="SLOT",Ge=e=>e.tagName!=null&&e.tagName.toUpperCase()==="SVG";async function un(e,t,n){var r,a;if(Ge(t))return t;let s=[];return cn(e)&&e.assignedNodes?s=T(e.assignedNodes()):k(e,HTMLIFrameElement)&&(!((r=e.contentDocument)===null||r===void 0)&&r.body)?s=T(e.contentDocument.body.childNodes):s=T(((a=e.shadowRoot)!==null&&a!==void 0?a:e).childNodes),s.length===0||k(e,HTMLVideoElement)||await s.reduce((o,l)=>o.then(()=>le(l,n)).then(c=>{c&&t.appendChild(c)}),Promise.resolve()),t}function fn(e,t,n){const r=t.style;if(!r)return;const a=window.getComputedStyle(e);a.cssText?(r.cssText=a.cssText,r.transformOrigin=a.transformOrigin):We(n).forEach(s=>{let o=a.getPropertyValue(s);s==="font-size"&&o.endsWith("px")&&(o=`${Math.floor(parseFloat(o.substring(0,o.length-2)))-.1}px`),k(e,HTMLIFrameElement)&&s==="display"&&o==="inline"&&(o="block"),s==="d"&&t.getAttribute("d")&&(o=`path(${t.getAttribute("d")})`),r.setProperty(s,o,a.getPropertyPriority(s))})}function dn(e,t){k(e,HTMLTextAreaElement)&&(t.innerHTML=e.value),k(e,HTMLInputElement)&&t.setAttribute("value",e.value)}function mn(e,t){if(k(e,HTMLSelectElement)){const r=Array.from(t.children).find(a=>e.value===a.getAttribute("value"));r&&r.setAttribute("selected","")}}function pn(e,t,n){return k(t,Element)&&(fn(e,t,n),Yt(e,t,n),dn(e,t),mn(e,t)),t}async function hn(e,t){const n=e.querySelectorAll?e.querySelectorAll("use"):[];if(n.length===0)return e;const r={};for(let s=0;s<n.length;s++){const l=n[s].getAttribute("xlink:href");if(l){const c=e.querySelector(l),f=document.querySelector(l);!c&&f&&!r[l]&&(r[l]=await le(f,t,!0))}}const a=Object.values(r);if(a.length){const s="http://www.w3.org/1999/xhtml",o=document.createElementNS(s,"svg");o.setAttribute("xmlns",s),o.style.position="absolute",o.style.width="0",o.style.height="0",o.style.overflow="hidden",o.style.display="none";const l=document.createElementNS(s,"defs");o.appendChild(l);for(let c=0;c<a.length;c++)l.appendChild(a[c]);e.appendChild(o)}return e}async function le(e,t,n){return!n&&t.filter&&!t.filter(e)?null:Promise.resolve(e).then(r=>ln(r,t)).then(r=>un(e,r,t)).then(r=>pn(e,r,t)).then(r=>hn(r,t))}const qe=/url\((['"]?)([^'"]+?)\1\)/g,xn=/url\([^)]+\)\s*format\((["']?)([^"']+)\1\)/g,gn=/src:\s*(?:url\([^)]+\)\s*format\([^)]+\)[,;]\s*)+/g;function yn(e){const t=e.replace(/([.*+?^${}()|\[\]\/\\])/g,"\\$1");return new RegExp(`(url\\(['"]?)(${t})(['"]?\\))`,"g")}function bn(e){const t=[];return e.replace(qe,(n,r,a)=>(t.push(a),n)),t.filter(n=>!pe(n))}async function vn(e,t,n,r,a){try{const s=n?Mt(t,n):t,o=ge(t);let l;return a||(l=await ye(s,o,r)),e.replace(yn(t),`$1${l}$3`)}catch{}return e}function wn(e,{preferredFontFormat:t}){return t?e.replace(gn,n=>{for(;;){const[r,,a]=xn.exec(n)||[];if(!a)return"";if(a===t)return`src: ${r};`}}):e}function Xe(e){return e.search(qe)!==-1}async function Ze(e,t,n){if(!Xe(e))return e;const r=wn(e,n);return bn(r).reduce((s,o)=>s.then(l=>vn(l,o,t,n)),Promise.resolve(r))}async function z(e,t,n){var r;const a=(r=t.style)===null||r===void 0?void 0:r.getPropertyValue(e);if(a){const s=await Ze(a,null,n);return t.style.setProperty(e,s,t.style.getPropertyPriority(e)),!0}return!1}async function jn(e,t){await z("background",e,t)||await z("background-image",e,t),await z("mask",e,t)||await z("-webkit-mask",e,t)||await z("mask-image",e,t)||await z("-webkit-mask-image",e,t)}async function Sn(e,t){const n=k(e,HTMLImageElement);if(!(n&&!pe(e.src))&&!(k(e,SVGImageElement)&&!pe(e.href.baseVal)))return;const r=n?e.src:e.href.baseVal,a=await ye(r,ge(r),t);await new Promise((s,o)=>{e.onload=s,e.onerror=t.onImageErrorHandler?(...c)=>{try{s(t.onImageErrorHandler(...c))}catch(f){o(f)}}:o;const l=e;l.decode&&(l.decode=s),l.loading==="lazy"&&(l.loading="eager"),n?(e.srcset="",e.src=a):e.href.baseVal=a})}async function Pn(e,t){const r=T(e.childNodes).map(a=>Je(a,t));await Promise.all(r).then(()=>e)}async function Je(e,t){k(e,Element)&&(await jn(e,t),await Sn(e,t),await Pn(e,t))}function kn(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 r=t.style;return r!=null&&Object.keys(r).forEach(a=>{n[a]=r[a]}),e}const Ne={};async function Oe(e){let t=Ne[e];if(t!=null)return t;const r=await(await fetch(e)).text();return t={url:e,cssText:r},Ne[e]=t,t}async function Re(e,t){let n=e.cssText;const r=/url\(["']?([^"')]+)["']?\)/g,s=(n.match(/url\([^)]+\)/g)||[]).map(async o=>{let l=o.replace(r,"$1");return l.startsWith("https://")||(l=new URL(l,e.url).href),Ve(l,t.fetchRequestInit,({result:c})=>(n=n.replace(o,`url(${c})`),[o,c]))});return Promise.all(s).then(()=>n)}function Te(e){if(e==null)return[];const t=[],n=/(\/\*[\s\S]*?\*\/)/gi;let r=e.replace(n,"");const a=new RegExp("((@.*?keyframes [\\s\\S]*?){([\\s\\S]*?}\\s*?)})","gi");for(;;){const c=a.exec(r);if(c===null)break;t.push(c[0])}r=r.replace(a,"");const s=/@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 c=s.exec(r);if(c===null){if(c=l.exec(r),c===null)break;s.lastIndex=l.lastIndex}else l.lastIndex=s.lastIndex;t.push(c[0])}return t}async function An(e,t){const n=[],r=[];return e.forEach(a=>{if("cssRules"in a)try{T(a.cssRules||[]).forEach((s,o)=>{if(s.type===CSSRule.IMPORT_RULE){let l=o+1;const c=s.href,f=Oe(c).then(u=>Re(u,t)).then(u=>Te(u).forEach(d=>{try{a.insertRule(d,d.startsWith("@import")?l+=1:a.cssRules.length)}catch(h){console.error("Error inserting rule from remote css",{rule:d,error:h})}})).catch(u=>{console.error("Error loading remote css",u.toString())});r.push(f)}})}catch(s){const o=e.find(l=>l.href==null)||document.styleSheets[0];a.href!=null&&r.push(Oe(a.href).then(l=>Re(l,t)).then(l=>Te(l).forEach(c=>{o.insertRule(c,o.cssRules.length)})).catch(l=>{console.error("Error loading remote stylesheet",l)})),console.error("Error inlining remote css file",s)}}),Promise.all(r).then(()=>(e.forEach(a=>{if("cssRules"in a)try{T(a.cssRules||[]).forEach(s=>{n.push(s)})}catch(s){console.error(`Error while reading CSS rules from ${a.href}`,s)}}),n))}function En(e){return e.filter(t=>t.type===CSSRule.FONT_FACE_RULE).filter(t=>Xe(t.style.getPropertyValue("src")))}async function Cn(e,t){if(e.ownerDocument==null)throw new Error("Provided element is not within a Document");const n=T(e.ownerDocument.styleSheets),r=await An(n,t);return En(r)}function Ye(e){return e.trim().replace(/["']/g,"")}function Nn(e){const t=new Set;function n(r){(r.style.fontFamily||getComputedStyle(r).fontFamily).split(",").forEach(s=>{t.add(Ye(s))}),Array.from(r.children).forEach(s=>{s instanceof HTMLElement&&n(s)})}return n(e),t}async function On(e,t){const n=await Cn(e,t),r=Nn(e);return(await Promise.all(n.filter(s=>r.has(Ye(s.style.fontFamily))).map(s=>{const o=s.parentStyleSheet?s.parentStyleSheet.href:null;return Ze(s.cssText,o,t)}))).join(`
|
|
2
|
-
`)}async function Rn(e,t){const n=t.fontEmbedCSS!=null?t.fontEmbedCSS:t.skipFonts?null:await On(e,t);if(n){const r=document.createElement("style"),a=document.createTextNode(n);r.appendChild(a),e.firstChild?e.insertBefore(r,e.firstChild):e.appendChild(r)}}async function Tn(e,t={}){const{width:n,height:r}=Ue(e,t),a=await le(e,t,!0);return await Rn(a,t),await Je(a,t),kn(a,t),await qt(a,n,r)}async function Qe(e,t={}){const{width:n,height:r}=Ue(e,t),a=await Tn(e,t),s=await ie(a),o=document.createElement("canvas"),l=o.getContext("2d"),c=t.pixelRatio||Wt(),f=t.canvasWidth||n,u=t.canvasHeight||r;return o.width=f*c,o.height=u*c,t.skipAutoScale||Ut(o),o.style.width=`${f}`,o.style.height=`${u}`,t.backgroundColor&&(l.fillStyle=t.backgroundColor,l.fillRect(0,0,o.width,o.height)),l.drawImage(s,0,0,o.width,o.height),o}async function $n(e,t={}){return(await Qe(e,t)).toDataURL()}async function _n(e,t={}){const n=await Qe(e,t);return await Vt(n)}const Ln=e=>e.toLowerCase().replace(/[^a-z0-9._-]+/g,"-").replace(/^-+|-+$/g,"")||"export";function In(e,t=new Date){const n=r=>String(r).padStart(2,"0");return`tokmon-${Ln(e)}-${t.getFullYear()}${n(t.getMonth()+1)}${n(t.getDate())}-${n(t.getHours())}${n(t.getMinutes())}.png`}const et="#0a0a0a";async function tt(){try{await document.fonts.ready}catch{}await new Promise(e=>requestAnimationFrame(()=>e(null)))}async function Fn(e,t={}){return await tt(),$n(e,{pixelRatio:t.pixelRatio??2,backgroundColor:t.backgroundColor??et,cacheBust:!0,skipFonts:!1})}function zn(e,t){const n=document.createElement("a");n.href=e,n.download=t,document.body.appendChild(n),n.click(),n.remove()}async function Dn(e,t,n){zn(await Fn(e,n),t)}async function Mn(e,t){try{await tt();const n=await _n(e,{pixelRatio:(t==null?void 0:t.pixelRatio)??2,backgroundColor:(t==null?void 0:t.backgroundColor)??et,cacheBust:!0});return!n||!navigator.clipboard||typeof ClipboardItem>"u"?!1:(await navigator.clipboard.write([new ClipboardItem({"image/png":n})]),!0)}catch{return!1}}function B({variant:e="footer",version:t}){return e==="corner"?i.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:[i.jsx("span",{className:"text-accent",children:"●"})," tokmon"]}):i.jsxs("div",{className:"flex items-center gap-2 font-display text-sm tracking-wide",children:[i.jsx("span",{className:"text-accent",children:"●"}),i.jsx("span",{className:"text-fg-bright",children:"tokmon"}),i.jsxs("span",{className:"text-xs tracking-normal text-fg-faint",children:["github.com/DavidIlie/tokmon",t?` · v${t}`:""]})]})}const $e=e=>`last ${e}`,Bn=x.forwardRef(function({derived:t,periodLabel:n,tz:r,version:a,opts:s},o){const l=t.byModel.slice(0,5),c=t.totals.cost>0,f=u=>c?u.share:u.tokenShare;return i.jsxs("div",{ref:o,className:"relative flex flex-col",style:{width:1040,height:540,background:"var(--color-bg-0)",backgroundImage:s.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:s.glow?"100% 100%, 24px 24px":"24px 24px",fontFamily:"var(--font-mono)",color:"var(--color-fg)"},children:[i.jsxs("div",{className:"flex items-baseline gap-2 border-b border-line px-6 py-3.5",children:[i.jsx("span",{className:"font-display text-sm tracking-wide text-accent",children:"tokmon"}),i.jsxs("span",{className:"text-sm text-fg-dim",children:["usage · ",$e(n)]}),i.jsx("span",{className:"ml-auto text-xs text-fg-faint",children:r})]}),i.jsxs("div",{className:"flex flex-1 gap-9 px-9 py-7",children:[i.jsxs("div",{className:"flex w-[300px] shrink-0 flex-col",children:[i.jsx("div",{className:"font-display text-xs uppercase tracking-widest text-fg-faint",children:c?"total spend":"total tokens"}),i.jsx("div",{className:"tnum mt-1 text-cost",style:{fontSize:64,lineHeight:1},children:c?O(t.totals.cost):M(t.totals.tokens)}),i.jsxs("div",{className:"mt-auto flex flex-col gap-3",children:[c?i.jsx(ee,{label:"tokens",value:M(t.totals.tokens)}):i.jsx(ee,{label:"spend",value:O(t.totals.cost)}),i.jsx(ee,{label:"cache saved",value:O(t.totals.cacheSavings),className:"text-positive"}),i.jsx(ee,{label:"calls",value:ft(t.totals.calls)})]})]}),i.jsxs("div",{className:"flex flex-1 flex-col gap-2 border-l border-line pl-9",children:[i.jsxs("div",{className:"font-display text-xs uppercase tracking-widest text-fg-faint",children:["top models · ",$e(n)]}),l.length===0?i.jsx("div",{className:"flex flex-1 items-center text-sm text-fg-faint",children:"no model usage in range"}):l.map(u=>i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("span",{className:"size-2 shrink-0 rounded-[2px]",style:{background:u.color}}),i.jsx("span",{className:"w-28 shrink-0 truncate text-sm text-fg",children:ze(u.model)}),i.jsx("span",{className:"h-1.5 flex-1 overflow-hidden rounded-full bg-bg-3",children:i.jsx("span",{className:"block h-full rounded-full",style:{width:`${Math.min(100,f(u)*100)}%`,minWidth:2,background:u.color}})}),i.jsx("span",{className:"tnum w-10 shrink-0 text-right text-xs text-fg-faint",children:dt(f(u))}),i.jsx("span",{className:"tnum w-20 shrink-0 text-right text-sm text-cost",children:c?O(u.cost):M(u.tokens)})]},u.model))]})]}),i.jsx("div",{className:"border-t border-line px-9 pt-3",children:i.jsx(bt,{data:t.timeline.map(u=>u.total),color:"var(--color-accent)",className:"text-2xl tracking-tight"})}),i.jsxs("div",{className:"flex items-center justify-between border-t border-line px-9 py-3.5",children:[s.wmPos==="footer"?i.jsx(B,{variant:"footer",version:a}):i.jsx("span",{className:"text-xs text-fg-faint",children:"tokmon"}),i.jsx("span",{className:"text-xs text-fg-faint",children:n})]}),s.wmPos==="corner"&&i.jsx(B,{variant:"corner"})]})});function ee({label:e,value:t,className:n="text-fg-bright"}){return i.jsxs("div",{children:[i.jsx("div",{className:"text-[11px] uppercase tracking-wide text-fg-faint",children:e}),i.jsx("div",{className:`tnum mt-1 truncate text-xl ${n}`,children:t})]})}function K(e){"@babel/helpers - typeof";return K=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},K(e)}function Kn(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function Hn(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,at(r.key),r)}}function Wn(e,t,n){return t&&Hn(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e}function Un(e,t,n){return t=se(t),Vn(e,nt()?Reflect.construct(t,n||[],se(e).constructor):t.apply(e,n))}function Vn(e,t){if(t&&(K(t)==="object"||typeof t=="function"))return t;if(t!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return Gn(e)}function Gn(e){if(e===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function nt(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return(nt=function(){return!!e})()}function se(e){return se=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(n){return n.__proto__||Object.getPrototypeOf(n)},se(e)}function qn(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&&he(e,t)}function he(e,t){return he=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(r,a){return r.__proto__=a,r},he(e,t)}function rt(e,t,n){return t=at(t),t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function at(e){var t=Xn(e,"string");return K(t)=="symbol"?t:t+""}function Xn(e,t){if(K(e)!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t);if(K(r)!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}var ce=(function(e){function t(){return Kn(this,t),Un(this,t,arguments)}return qn(t,e),Wn(t,[{key:"render",value:function(){return null}}])})(x.Component);rt(ce,"displayName","ZAxis");rt(ce,"defaultProps",{zAxisId:0,range:[64,64],scale:"auto",type:"number"});var Zn=["option","isActive"];function Z(){return Z=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},Z.apply(this,arguments)}function Jn(e,t){if(e==null)return{};var n=Yn(e,t),r,a;if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);for(a=0;a<s.length;a++)r=s[a],!(t.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(e,r)&&(n[r]=e[r])}return n}function Yn(e,t){if(e==null)return{};var n={};for(var r in e)if(Object.prototype.hasOwnProperty.call(e,r)){if(t.indexOf(r)>=0)continue;n[r]=e[r]}return n}function Qn(e){var t=e.option,n=e.isActive,r=Jn(e,Zn);return typeof t=="string"?x.createElement(Pe,Z({option:x.createElement(vt,Z({type:t},r)),isActive:n,shapeType:"symbols"},r)):x.createElement(Pe,Z({option:t,isActive:n,shapeType:"symbols"},r))}function H(e){"@babel/helpers - typeof";return H=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},H(e)}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 r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},J.apply(this,arguments)}function _e(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(a){return Object.getOwnPropertyDescriptor(e,a).enumerable})),n.push.apply(n,r)}return n}function N(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?_e(Object(n),!0).forEach(function(r){R(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):_e(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function er(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function Le(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,st(r.key),r)}}function tr(e,t,n){return t&&Le(e.prototype,t),n&&Le(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function nr(e,t,n){return t=oe(t),rr(e,it()?Reflect.construct(t,n||[],oe(e).constructor):t.apply(e,n))}function rr(e,t){if(t&&(H(t)==="object"||typeof t=="function"))return t;if(t!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return ar(e)}function ar(e){if(e===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function it(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return(it=function(){return!!e})()}function oe(e){return oe=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(n){return n.__proto__||Object.getPrototypeOf(n)},oe(e)}function ir(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(r,a){return r.__proto__=a,r},xe(e,t)}function R(e,t,n){return t=st(t),t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function st(e){var t=sr(e,"string");return H(t)=="symbol"?t:t+""}function sr(e,t){if(H(e)!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t);if(H(r)!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}var ue=(function(e){function t(){var n;er(this,t);for(var r=arguments.length,a=new Array(r),s=0;s<r;s++)a[s]=arguments[s];return n=nr(this,t,[].concat(a)),R(n,"state",{isAnimationFinished:!1}),R(n,"handleAnimationEnd",function(){n.setState({isAnimationFinished:!0})}),R(n,"handleAnimationStart",function(){n.setState({isAnimationFinished:!1})}),R(n,"id",Tt("recharts-scatter-")),n}return ir(t,e),tr(t,[{key:"renderSymbolsStatically",value:function(r){var a=this,s=this.props,o=s.shape,l=s.activeShape,c=s.activeIndex,f=de(this.props,!1);return r.map(function(u,d){var h=c===d,p=h?l:o,b=N(N({},f),u);return P.createElement(G,J({className:"recharts-scatter-symbol",key:"symbol-".concat(u==null?void 0:u.cx,"-").concat(u==null?void 0:u.cy,"-").concat(u==null?void 0:u.size,"-").concat(d)},wt(a.props,u,d),{role:"img"}),P.createElement(Qn,J({option:p,isActive:h,key:"symbol-".concat(d)},b)))})}},{key:"renderSymbolsWithAnimation",value:function(){var r=this,a=this.props,s=a.points,o=a.isAnimationActive,l=a.animationBegin,c=a.animationDuration,f=a.animationEasing,u=a.animationId,d=this.state.prevPoints;return P.createElement(jt,{begin:l,duration:c,isActive:o,easing:f,from:{t:0},to:{t:1},key:"pie-".concat(u),onAnimationEnd:this.handleAnimationEnd,onAnimationStart:this.handleAnimationStart},function(h){var p=h.t,b=s.map(function(g,w){var y=d&&d[w];if(y){var j=Q(y.cx,g.cx),m=Q(y.cy,g.cy),C=Q(y.size,g.size);return N(N({},g),{},{cx:j(p),cy:m(p),size:C(p)})}var v=Q(0,g.size);return N(N({},g),{},{size:v(p)})});return P.createElement(G,null,r.renderSymbolsStatically(b))})}},{key:"renderSymbols",value:function(){var r=this.props,a=r.points,s=r.isAnimationActive,o=this.state.prevPoints;return s&&a&&a.length&&(!o||!St(o,a))?this.renderSymbolsWithAnimation():this.renderSymbolsStatically(a)}},{key:"renderErrorBar",value:function(){var r=this.props.isAnimationActive;if(r&&!this.state.isAnimationFinished)return null;var a=this.props,s=a.points,o=a.xAxis,l=a.yAxis,c=a.children,f=De(c,Pt);return f?f.map(function(u,d){var h=u.props,p=h.direction,b=h.dataKey;return P.cloneElement(u,{key:"".concat(p,"-").concat(b,"-").concat(s[d]),data:s,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 r=this.props,a=r.points,s=r.line,o=r.lineType,l=r.lineJointType,c=de(this.props,!1),f=de(s,!1),u,d;if(o==="joint")u=a.map(function(m){return{x:m.cx,y:m.cy}});else if(o==="fitting"){var h=kt(a),p=h.xmin,b=h.xmax,g=h.a,w=h.b,y=function(C){return g*C+w};u=[{x:p,y:y(p)},{x:b,y:y(b)}]}var j=N(N(N({},c),{},{fill:"none",stroke:c&&c.fill},f),{},{points:u});return P.isValidElement(s)?d=P.cloneElement(s,j):At(s)?d=s(j):d=P.createElement(Et,J({},j,{type:l})),P.createElement(G,{className:"recharts-scatter-line",key:"recharts-scatter-line"},d)}},{key:"render",value:function(){var r=this.props,a=r.hide,s=r.points,o=r.line,l=r.className,c=r.xAxis,f=r.yAxis,u=r.left,d=r.top,h=r.width,p=r.height,b=r.id,g=r.isAnimationActive;if(a||!s||!s.length)return null;var w=this.state.isAnimationFinished,y=Ct("recharts-scatter",l),j=c&&c.allowDataOverflow,m=f&&f.allowDataOverflow,C=j||m,v=D(b)?this.id:b;return P.createElement(G,{className:y,clipPath:C?"url(#clipPath-".concat(v,")"):null},j||m?P.createElement("defs",null,P.createElement("clipPath",{id:"clipPath-".concat(v)},P.createElement("rect",{x:j?u:u-h/2,y:m?d:d-p/2,width:j?h:h*2,height:m?p:p*2}))):null,o&&this.renderLine(),this.renderErrorBar(),P.createElement(G,{key:"recharts-scatter-symbols"},this.renderSymbols()),(!g||w)&&Nt.renderCallByParent(this.props,s))}}],[{key:"getDerivedStateFromProps",value:function(r,a){return r.animationId!==a.prevAnimationId?{prevAnimationId:r.animationId,curPoints:r.points,prevPoints:a.curPoints}:r.points!==a.curPoints?{curPoints:r.points}:null}}])})(x.PureComponent);R(ue,"displayName","Scatter");R(ue,"defaultProps",{xAxisId:0,yAxisId:0,zAxisId:0,legendType:"circle",lineType:"joint",lineJointType:"linear",data:[],shape:"circle",hide:!1,isAnimationActive:!Ot.isSsr,animationBegin:0,animationDuration:400,animationEasing:"linear"});R(ue,"getComposedData",function(e){var t=e.xAxis,n=e.yAxis,r=e.zAxis,a=e.item,s=e.displayedData,o=e.xAxisTicks,l=e.yAxisTicks,c=e.offset,f=a.props.tooltipType,u=De(a.props.children,Rt),d=D(t.dataKey)?a.props.dataKey:t.dataKey,h=D(n.dataKey)?a.props.dataKey:n.dataKey,p=r&&r.dataKey,b=r?r.range:ce.defaultProps.range,g=b&&b[0],w=t.scale.bandwidth?t.scale.bandwidth():0,y=n.scale.bandwidth?n.scale.bandwidth():0,j=s.map(function(m,C){var v=re(m,d),W=re(m,h),S=!D(p)&&re(m,p)||"-",$=[{name:D(t.dataKey)?a.props.name:t.name||t.dataKey,unit:t.unit||"",value:v,payload:m,dataKey:d,type:f},{name:D(n.dataKey)?a.props.name:n.name||n.dataKey,unit:n.unit||"",value:W,payload:m,dataKey:h,type:f}];S!=="-"&&$.push({name:r.name||r.dataKey,unit:r.unit||"",value:S,payload:m,dataKey:p,type:f});var _=ke({axis:t,ticks:o,bandSize:w,entry:m,index:C,dataKey:d}),L=ke({axis:n,ticks:l,bandSize:y,entry:m,index:C,dataKey:h}),U=S!=="-"?r.scale(S):g,I=Math.sqrt(Math.max(U,0)/Math.PI);return N(N({},m),{},{cx:_,cy:L,x:_-I,y:L-I,xAxis:t,yAxis:n,zAxis:r,width:2*I,height:2*I,size:U,node:{x:v,y:W,z:S},tooltipPayload:$,tooltipPosition:{x:_,y:L},payload:m},u&&u[C]&&u[C].props)});return N({points:j},c)});var or=$t({chartName:"ComposedChart",GraphicalChild:[zt,He,Ke,ue],axisComponents:[{axisType:"xAxis",AxisComp:Me},{axisType:"yAxis",AxisComp:Be},{axisType:"zAxis",AxisComp:ce}],formatAxisMap:_t});const Ie=e=>e.name&&e.name!==e.provider?`${e.provider} · ${e.name}`:e.provider,lr=x.forwardRef(function({source:t,opts:n},r){const a=mt(t.model),s=pt(t.totals),o=cr(t.accounts),l=Math.max(...t.daily.map(c=>c.cost),0);return i.jsxs("div",{ref:r,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, ${a} 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:[i.jsxs("div",{className:"flex items-baseline gap-2 border-b border-line px-6 py-3.5",children:[i.jsx("span",{className:"font-display text-sm tracking-wide text-accent",children:"tokmon"}),i.jsxs("span",{className:"text-sm text-fg-dim",children:["model spotlight · ",t.periodLabel]}),i.jsx("span",{className:"ml-auto text-xs text-fg-faint",children:t.tz})]}),i.jsxs("div",{className:"grid flex-1 grid-cols-[340px_1fr] gap-7 px-8 py-6",children:[i.jsxs("section",{className:"flex min-w-0 flex-col",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"size-2.5 shrink-0 rounded-[3px]",style:{background:a}}),i.jsx("span",{className:"font-display text-xs uppercase tracking-widest text-fg-faint",children:"model"})]}),i.jsxs("div",{className:"mt-3 min-h-[132px]",children:[i.jsx("div",{className:"break-words font-display text-[46px] leading-[0.98]",style:{color:a},children:ze(t.model)}),i.jsx("div",{className:"mt-2 truncate text-xs text-fg-faint",title:t.model,children:t.model})]}),i.jsxs("div",{className:"mt-auto grid grid-cols-2 gap-x-5 gap-y-4",children:[i.jsx(te,{label:"spend",value:O(t.totals.cost),className:"text-cost"}),i.jsx(te,{label:"tokens",value:M(s)}),i.jsx(te,{label:"calls",value:we(t.totals.count)}),i.jsx(te,{label:"accounts",value:we(t.accounts.length)})]})]}),i.jsxs("section",{className:"flex min-w-0 flex-col gap-4 border-l border-line pl-7",children:[i.jsxs("div",{className:"grid grid-cols-4 gap-2",children:[i.jsx(ne,{label:"input",value:t.totals.input,color:Y.input}),i.jsx(ne,{label:"output",value:t.totals.output,color:Y.output}),i.jsx(ne,{label:"cache create",value:t.totals.cacheCreate,color:Y.cacheCreate}),i.jsx(ne,{label:"cache read",value:t.totals.cacheRead,color:Y.cacheRead})]}),i.jsxs("div",{children:[i.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[i.jsx("span",{className:"font-display text-xs uppercase tracking-widest text-fg-faint",children:"account split"}),i.jsx("span",{className:"tnum text-xs text-fg-faint",children:O(t.totals.cost)})]}),i.jsx("div",{className:"flex flex-col gap-1.5",children:o.length===0?i.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"}):o.map(c=>{const f=t.totals.cost>0?c.cost/t.totals.cost*100:0;return i.jsxs("div",{className:"grid grid-cols-[minmax(0,1fr)_76px_78px] items-center gap-3 text-xs",children:[i.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[i.jsx("span",{className:"size-2 shrink-0 rounded-[2px]",style:{background:c.color}}),i.jsx("span",{className:"truncate text-fg-dim",title:c.providerId==="other"?c.name:Ie(c),children:c.providerId==="other"?c.name:Ie(c)})]}),i.jsx("span",{className:"tnum text-right text-cost",children:O(c.cost)}),i.jsx("span",{className:"tnum text-right text-fg-faint",children:M(c.tokens)}),i.jsx("span",{className:"col-span-3 h-1 overflow-hidden rounded-full bg-bg-3",children:i.jsx("span",{className:"block h-full rounded-full",style:{width:`${Math.min(100,f)}%`,minWidth:c.cost>0?2:0,background:c.color}})})]},`${c.providerId}:${c.name}`)})})]}),i.jsxs("div",{className:"mt-auto",children:[i.jsxs("div",{className:"mb-1.5 flex items-center justify-between",children:[i.jsx("span",{className:"font-display text-xs uppercase tracking-widest text-fg-faint",children:"daily cost"}),i.jsxs("span",{className:"tnum text-xs text-fg-faint",children:["peak ",O(l)]})]}),i.jsx("div",{className:"h-[118px] rounded border border-line bg-bg-1/50 px-2 py-2",children:t.daily.length===0?i.jsx("div",{className:"flex h-full items-center justify-center text-xs text-fg-faint",children:"no daily usage"}):i.jsx(Lt,{children:i.jsxs(or,{data:t.daily,margin:{top:8,right:10,left:2,bottom:0},children:[i.jsx(It,{...Ft}),i.jsx(Me,{dataKey:"day",tick:{fill:"var(--color-fg-faint)",fontSize:9,fontFamily:"var(--font-mono)"},tickLine:!1,axisLine:!1,minTickGap:22,tickFormatter:ht}),i.jsx(Be,{hide:!0,tickFormatter:xt,domain:[0,"dataMax"]}),i.jsx(He,{type:"monotone",dataKey:"cost",stroke:a,fill:a,fillOpacity:.14,strokeWidth:1.5,dot:!1,isAnimationActive:!1}),i.jsx(Ke,{dataKey:"cost",fill:a,opacity:.38,radius:[2,2,0,0],isAnimationActive:!1})]})})})]})]})]}),i.jsxs("div",{className:"flex items-center justify-between border-t border-line px-8 py-3.5",children:[n.wmPos==="footer"?i.jsx(B,{variant:"footer",version:t.version}):i.jsx("span",{className:"text-xs text-fg-faint",children:"tokmon"}),i.jsx("span",{className:"text-xs text-fg-faint",children:t.periodLabel})]}),n.wmPos==="corner"&&i.jsx(B,{variant:"corner"})]})});function te({label:e,value:t,className:n="text-fg-bright"}){return i.jsxs("div",{children:[i.jsx("div",{className:"font-display text-[10px] uppercase tracking-wide text-fg-faint",children:e}),i.jsx("div",{className:`tnum mt-1 truncate text-2xl ${n}`,children:t})]})}function ne({label:e,value:t,color:n}){return i.jsxs("div",{className:"min-w-0 rounded border border-line bg-bg-1 px-2 py-2",children:[i.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] uppercase tracking-wide text-fg-faint",children:[i.jsx("span",{className:"size-1.5 shrink-0 rounded-[2px]",style:{background:n}}),i.jsx("span",{className:"truncate",children:e})]}),i.jsx("div",{className:"tnum mt-1 truncate text-sm text-fg-bright",children:M(t)})]})}function cr(e){if(e.length<=6)return e;const t=e.slice(0,5),n=e.slice(5),r=n.reduce((a,s)=>({...a,tokens:a.tokens+s.tokens,cost:a.cost+s.cost}),{name:`${n.length} more accounts`,color:"var(--color-fg-faint)",provider:"Other",providerId:"other",tokens:0,cost:0});return[...t,r]}const ur=x.forwardRef(function({node:t,title:n,framed:r,wmPos:a},s){const o=x.useRef(null);return x.useEffect(()=>{const l=o.current;if(!l)return;l.innerHTML="";const c=t.cloneNode(!0);return c.querySelectorAll("[data-chrome]").forEach(f=>f.remove()),c.style.width=`${Math.round(t.getBoundingClientRect().width)}px`,c.classList.remove("hover:border-line-2"),l.appendChild(c),()=>{l.innerHTML=""}},[t]),i.jsxs("div",{ref:s,className:"relative",style:{background:"var(--color-bg-0)",backgroundImage:"radial-gradient(var(--color-line-faint) 1px, transparent 1px)",backgroundSize:"24px 24px",padding:r?28:16,fontFamily:"var(--font-mono)"},children:[r&&i.jsxs("div",{className:"mb-3 flex items-baseline gap-2",children:[i.jsx("span",{className:"font-display text-xs tracking-wide text-accent",children:"tokmon"}),i.jsxs("span",{className:"font-display text-xs uppercase tracking-wider text-fg-dim",children:["/ ",n]})]}),i.jsx("div",{ref:o}),a==="footer"?i.jsx("div",{className:"mt-3 flex justify-end",children:i.jsx(B,{variant:"footer"})}):i.jsx(B,{variant:"corner"})]})}),fr=600,Fe=360,dr=e=>e==="light"?"#f4f5f5":"#0a0a0a",mr=e=>e.toLowerCase().replace(/[^a-z0-9._-]+/g,"-").replace(/^-+|-+$/g,"")||"model";function br({source:e,onClose:t}){const n=e.kind==="summary",r=e.kind==="model",a=n||r,s=x.useRef(null),o=x.useRef(null),l=x.useRef(null),c=x.useRef(),[f,u]=x.useState(()=>document.documentElement.classList.contains("light")?"light":"dark"),[d,h]=x.useState(a?"footer":"corner"),[p,b]=x.useState("2"),[g,w]=x.useState(!0),[y,j]=x.useState(!0),[m,C]=x.useState({w:n?1040:r?900:700,h:a?540:360}),[v,W]=x.useState(null),[S,$]=x.useState(null);Dt(l,{active:!0,onEscape:t,initialFocusRef:o}),x.useEffect(()=>()=>{c.current&&clearTimeout(c.current)},[]);const _=A=>{W(A),c.current&&clearTimeout(c.current),c.current=setTimeout(()=>W(null),1600)};x.useEffect(()=>{const A=s.current;if(!A)return;const fe=()=>C(ve=>({w:A.offsetWidth||ve.w,h:A.offsetHeight||ve.h}));fe();const be=new ResizeObserver(fe);be.observe(A);const ut=setTimeout(fe,80);return()=>{be.disconnect(),clearTimeout(ut)}},[e,y,d,f,g]);const L=Math.min(fr/m.w,Fe/m.h,1),U={pixelRatio:Number(p),backgroundColor:dr(f)},I=In(n?"summary":r?`model-${mr(e.model)}`:e.captureName),ot=async()=>{if(!(!s.current||S)){$("download");try{await Dn(s.current,I,U),_("dl")}catch{_("fail")}finally{$(null)}}},lt=async()=>{if(!(!s.current||S)){$("copy");try{_(await Mn(s.current,U)?"copy":"fail")}finally{$(null)}}},ct=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 i.jsx("div",{className:"dialog-fade fixed inset-0 z-[60] flex items-center justify-center overflow-y-auto overscroll-contain bg-bg-0/70 p-4 backdrop-blur-sm",onMouseDown:A=>{A.target===A.currentTarget&&t()},role:"dialog","aria-modal":"true","aria-labelledby":"share-title",children:i.jsxs("div",{ref:l,tabIndex:-1,className:"dialog-pop relative flex max-h-[88vh] w-full max-w-[720px] flex-col overflow-hidden rounded-md border border-line-2 bg-bg-1 focus:outline-none",children:[i.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"}),i.jsx("button",{type:"button",onClick:t,"aria-label":"Close",className:"absolute right-2 top-2 z-10 rounded p-1 text-fg-faint transition hover:text-fg focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent",children:i.jsx(je,{className:"size-4"})}),i.jsx("div",{className:"flex items-center justify-center bg-bg-0 px-6 pb-5 pt-9",style:{minHeight:Fe+24},children:i.jsx("div",{className:"overflow-hidden rounded",style:{width:m.w*L,height:m.h*L},children:i.jsx("div",{style:{width:m.w,height:m.h,transform:`scale(${L})`,transformOrigin:"top left"},children:i.jsx("div",{className:f==="light"?"light":"dark",children:n?i.jsx(Bn,{ref:s,derived:e.derived,periodLabel:e.periodLabel,tz:e.tz,version:e.version,opts:{glow:g,wmPos:d}}):r?i.jsx(lr,{ref:s,source:e,opts:{glow:g,wmPos:d}}):i.jsx(ur,{ref:s,node:e.node,title:e.captureName,framed:y,wmPos:d})})})})}),i.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:[i.jsx(X,{label:"theme",children:i.jsx(V,{size:"xs",containerClassName:q,ariaLabel:"export theme",options:[{value:"dark",label:"dark"},{value:"light",label:"light"}],value:f,onChange:u})}),i.jsx(X,{label:"mark",children:i.jsx(V,{size:"xs",containerClassName:q,ariaLabel:"watermark position",options:[{value:"footer",label:"footer"},{value:"corner",label:"corner"}],value:d,onChange:h})}),a?i.jsx(X,{label:"glow",children:i.jsx(V,{size:"xs",containerClassName:q,ariaLabel:"accent glow",options:[{value:"on",label:"on"},{value:"off",label:"off"}],value:g?"on":"off",onChange:A=>w(A==="on")})}):i.jsx(X,{label:"frame",children:i.jsx(V,{size:"xs",containerClassName:q,ariaLabel:"frame",options:[{value:"framed",label:"framed"},{value:"bare",label:"bare"}],value:y?"framed":"bare",onChange:A=>j(A==="framed")})}),i.jsx(X,{label:"scale",children:i.jsx(V,{size:"xs",containerClassName:q,ariaLabel:"export scale",options:[{value:"1",label:"1x"},{value:"2",label:"2x"},{value:"3",label:"3x"}],value:p,onChange:b})}),i.jsxs("span",{className:"ml-auto tnum text-fg-faint",children:[m.w," × ",m.h," · ",p,"x"]})]}),i.jsxs("div",{className:"flex items-center justify-end gap-2 border-t border-line px-4 py-3",children:[i.jsx("span",{className:"mr-auto text-xs text-fg-faint",role:"status","aria-live":"polite",children:ct}),i.jsxs("button",{type:"button",onClick:lt,disabled:S!==null,className:"flex items-center gap-1.5 rounded border border-line bg-bg-1 px-3 py-1.5 text-xs text-fg-dim transition hover:border-line-2 hover:text-fg active:scale-[0.97] disabled:opacity-50 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent",children:[v==="copy"?i.jsx(Se,{className:"size-3.5 text-positive"}):v==="fail"?i.jsx(je,{className:"size-3.5 text-warning"}):i.jsx(gt,{className:"size-3.5"})," ",S==="copy"?"copying…":v==="copy"?"copied":v==="fail"?"copy failed":"copy"]}),i.jsxs("button",{type:"button",ref:o,onClick:ot,disabled:S!==null,className:"flex items-center gap-1.5 rounded border border-accent/60 bg-bg-1 px-3 py-1.5 text-xs text-accent transition hover:bg-bg-2 active:scale-[0.97] disabled:opacity-50 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent",children:[v==="dl"?i.jsx(Se,{className:"size-3.5 text-positive"}):i.jsx(yt,{className:"size-3.5"})," ",S==="download"?"downloading…":"download PNG"]})]})]})})}const q="flex items-center overflow-hidden rounded border border-line text-[10px]";function X({label:e,children:t}){return i.jsxs("span",{className:"flex items-center gap-1.5",children:[i.jsx("span",{className:"text-fg-faint",children:e}),t]})}export{br as ShareSheet};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{j as t,e as h,g as C,f as l,r as L,S as E}from"./index-DH3dOnbg.js";import{g as R,X as c,Y as d,f as M,u as A,C as b,R as k,a as u,G as v,A as n,T as j,b as g,s as T,m as Y}from"./chart-cZoLgpmG.js";import{P as S}from"./panel-DTQBwExW.js";import{E as N}from"./primitives-C36qJlA2.js";import{L as O,A as G}from"./Area-CMXvOw33.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=T("total",l,"var(--color-cost)");function et({derived:a,title:s="cost over time",height:r=260,periodLabel:e,heightClass:o}){const x=A(),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:C,scale:m,allowDataOverflow:m==="log",domain:m==="log"?[.1,"auto"]:[0,"auto"]});return t.jsx(S,{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(N,{children:"no spend in period"}):t.jsx(b,{height:r,heightClass:o,children:t.jsx(k,{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=T("cumulative",l,"var(--color-cost)");function at({derived:a,height:s=220,periodLabel:r}){const e=A(),o=a.cumulative;return t.jsx(S,{title:"cumulative spend",titleTag:r,captureName:"cumulative",children:o.length===0?t.jsx(N,{children:"no spend in period"}):t.jsx(b,{height:s,children:t.jsx(k,{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:C}),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=T("cache saved",l,"var(--color-positive)");function ot({derived:a,height:s=220,periodLabel:r}){const e=A(),o=a.cacheSavingsSeries,x=a.totals.cacheSavings;return t.jsx(S,{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(N,{children:"no cache reads in period"}):t.jsx(b,{height:s,children:t.jsx(k,{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:C}),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{ot as CacheSavings,et as CostTimeline,at as CumulativeSpend};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as f}from"./index-DH3dOnbg.js";const x="focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent",E='button,[href],input,select,textarea,[tabindex]:not([tabindex="-1"])';function k(n,{active:i,onEscape:u,initialFocusRef:r}){const a=f.useRef(u);f.useEffect(()=>{a.current=u},[u]),f.useEffect(()=>{var c,m;if(!i)return;const e=document.activeElement,o=n.current,b=o==null?void 0:o.querySelector(E);(m=(c=(r==null?void 0:r.current)??b??o)==null?void 0:c.focus)==null||m.call(c);const l=t=>{if(t.key==="Escape"){t.stopPropagation(),a.current();return}if(t.key!=="Tab"||!n.current)return;const g=n.current.querySelectorAll(E),s=Array.from(g).filter(v=>v.offsetParent!==null||v===document.activeElement);if(s.length===0)return;const d=s[0],y=s[s.length-1];t.shiftKey&&document.activeElement===d?(t.preventDefault(),y.focus()):!t.shiftKey&&document.activeElement===y&&(t.preventDefault(),d.focus())};return document.addEventListener("keydown",l),()=>{var t;document.removeEventListener("keydown",l),(t=e==null?void 0:e.focus)==null||t.call(e)}},[i,r,n])}export{x as F,k as u};
|