tarsk 0.5.57 → 0.5.59
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 +1 -1
- package/dist/bundled-skills/skill-creator/scripts/generate_report.js +0 -1
- package/dist/index.js +40050 -31896
- package/dist/public/assets/account-view-Cc6oDwk4.js +1 -0
- package/dist/public/assets/api-CtfZCd77.js +1 -0
- package/dist/public/assets/async-error-boundary-CaRNnJZe.js +1 -0
- package/dist/public/assets/browser-tab-BfAt-Sho.js +8 -0
- package/dist/public/assets/card-DFACZp3F.js +1 -0
- package/dist/public/assets/commit-dialog-Ck0r2v9S.js +1 -0
- package/dist/public/assets/context-menu-CBvTcHUI.js +1 -0
- package/dist/public/assets/create-repo-dialog-CBvRaov7.js +1 -0
- package/dist/public/assets/dialogs-config-C2KFQf9x.js +51 -0
- package/dist/public/assets/diff-view-DDECIdhE.js +4 -0
- package/dist/public/assets/explorer-file-drop-DaQtKkIj.js +1 -0
- package/dist/public/assets/explorer-tab-context-DCq1BBX_.js +1 -0
- package/dist/public/assets/explorer-tab-view-72Krb0Ir.js +2 -0
- package/dist/public/assets/explorer-tree-CcFgAYMn.js +1 -0
- package/dist/public/assets/explorer-view-DsNxf6nu.js +75 -0
- package/dist/public/assets/git-history-dialog--akFTQOd.js +1 -0
- package/dist/public/assets/git-ops-button-CKGLh3Zk.js +2 -0
- package/dist/public/assets/history-view-IcXfB6BD.js +15 -0
- package/dist/public/assets/index-BmpLvHah.js +75 -0
- package/dist/public/assets/index-r8I03VVW.css +1 -0
- package/dist/public/assets/mcp-server-card-DDmDAlY8.js +1 -0
- package/dist/public/assets/merged-pr-dialog-CiwhRqFv.js +1 -0
- package/dist/public/assets/model-list-controls-D5IaOffK.js +1 -0
- package/dist/public/assets/{monaco-y4UqQVp0.js → monaco-CMkNoWsM.js} +185 -185
- package/dist/public/assets/onboarding-CFIVEI92.js +1 -0
- package/dist/public/assets/project-settings-view-Klpu7p3U.js +1 -0
- package/dist/public/assets/providers-list-view-Df-ONKwe.js +1 -0
- package/dist/public/assets/pull-request-dialog-DVYZgMuN.js +1 -0
- package/dist/public/assets/pull-with-changes-dialog-CHHJ0gpA.js +1 -0
- package/dist/public/assets/push-before-pr-dialog-DoNMB3C8.js +1 -0
- package/dist/public/assets/react-vendor-tSKmVA4e.js +14 -0
- package/dist/public/assets/settings-general-view-yDDYKQmO.js +1 -0
- package/dist/public/assets/settings-instructions-view-y9bUZtKn.js +1 -0
- package/dist/public/assets/settings-list-j_NDw-aW.js +1 -0
- package/dist/public/assets/settings-logs-view-BzrjJRk6.js +5 -0
- package/dist/public/assets/settings-mcp-servers-view-NuKeyQ92.js +5 -0
- package/dist/public/assets/settings-models-view-64UG4njI.js +1 -0
- package/dist/public/assets/settings-rules-view-DdxIfxki.js +8 -0
- package/dist/public/assets/settings-skills-view-DoVxhA-A.js +3 -0
- package/dist/public/assets/settings-slash-commands-view-vm0HNVw1.js +1 -0
- package/dist/public/assets/settings-statistics-view-CKc3bD1x.js +1 -0
- package/dist/public/assets/settings-subagents-view-DuHK-7uc.js +2 -0
- package/dist/public/assets/settings-system-prompt-view-1clIREZ5.js +1 -0
- package/dist/public/assets/settings-telegram-view-DCPC5GxD.js +1 -0
- package/dist/public/assets/settings-view-BweC2YuW.js +2 -0
- package/dist/public/assets/skeleton-DBWV1Usf.js +1 -0
- package/dist/public/assets/slug-utils-D8SJJo7H.js +1 -0
- package/dist/public/assets/tasks-view-Cg9N8GZb.js +2 -0
- package/dist/public/assets/{terminal-panel-C8OewkuK.js → terminal-panel-Dlon-VDl.js} +2 -2
- package/dist/public/assets/ui-components-Dd2afm0c.js +1 -0
- package/dist/public/assets/{use-deferred-search-BDiZsnWG.js → use-deferred-search-Cu-o4nau.js} +1 -1
- package/dist/public/assets/use-installed-ai-files-X8NXRdGD.js +1 -0
- package/dist/public/assets/use-settings-page-loading-D1JlmLmD.js +1 -0
- package/dist/public/assets/{utils-CFYgrqBu.js → utils-Dt07QR3w.js} +1 -1
- package/dist/public/assets/{vosk-speech-BZoPqFPM.js → vosk-speech-Fi-g2v8n.js} +2 -2
- package/dist/public/assets/{web-CU5taXAB.js → web-CdkfJJZ3.js} +1 -1
- package/dist/public/assets/{web-BElJIgS6.js → web-CiaJzwav.js} +1 -1
- package/dist/public/assets/web-DeCAC9ap.js +1 -0
- package/dist/public/assets/{web-B15zzKQ-.js → web-DsLUxLTR.js} +1 -1
- package/dist/public/backgrounds/arctic-tundra.avif +0 -0
- package/dist/public/backgrounds/autumn-leaves.avif +0 -0
- package/dist/public/backgrounds/coastal-cliff.avif +0 -0
- package/dist/public/backgrounds/floating-waterfall.avif +0 -0
- package/dist/public/backgrounds/forest-path.avif +0 -0
- package/dist/public/backgrounds/garden-path.avif +0 -0
- package/dist/public/backgrounds/glow-marsh.avif +0 -0
- package/dist/public/backgrounds/golden-wheat.avif +0 -0
- package/dist/public/backgrounds/moon-desert.avif +0 -0
- package/dist/public/backgrounds/night-pond.avif +0 -0
- package/dist/public/backgrounds/prairie-grassland.avif +0 -0
- package/dist/public/backgrounds/river-winding.avif +0 -0
- package/dist/public/backgrounds/salt-flat.avif +0 -0
- package/dist/public/backgrounds/salt-marsh.avif +0 -0
- package/dist/public/backgrounds/sandy-beach.avif +0 -0
- package/dist/public/backgrounds/snow-river.avif +0 -0
- package/dist/public/backgrounds/sunset-pond.avif +0 -0
- package/dist/public/index.html +9 -9
- package/package.json +5 -4
- package/dist/public/assets/account-view-CCbGosVi.js +0 -1
- package/dist/public/assets/api-DG0vQ1QZ.js +0 -1
- package/dist/public/assets/browser-tab-BpUYCZGi.js +0 -8
- package/dist/public/assets/commit-dialog-DpwAQ4Z6.js +0 -1
- package/dist/public/assets/context-menu-B5kRTqdn.js +0 -1
- package/dist/public/assets/create-repo-dialog-BoCupv2m.js +0 -1
- package/dist/public/assets/dialogs-config-BIrrNhlc.js +0 -51
- package/dist/public/assets/diff-view-D10roF70.js +0 -3
- package/dist/public/assets/explorer-tab-view-CA_AMgZd.js +0 -2
- package/dist/public/assets/explorer-tree-xlOwCJvH.js +0 -1
- package/dist/public/assets/explorer-view-C6eud9zx.js +0 -75
- package/dist/public/assets/git-history-dialog-BN7wBt9F.js +0 -1
- package/dist/public/assets/git-ops-button-CrICekvM.js +0 -2
- package/dist/public/assets/history-view-DfTUOfnG.js +0 -9
- package/dist/public/assets/index-BUA2xxQg.js +0 -79
- package/dist/public/assets/index-BgPn08Yc.css +0 -1
- package/dist/public/assets/mcp-server-card-CzNUrI8l.js +0 -1
- package/dist/public/assets/merged-pr-dialog-CzXN0cEw.js +0 -1
- package/dist/public/assets/model-star-rating-t0v8L-DE.js +0 -1
- package/dist/public/assets/onboarding-B0Jzwrxy.js +0 -1
- package/dist/public/assets/project-settings-view-CsrfJOxB.js +0 -1
- package/dist/public/assets/providers-list-view-CMc48hq3.js +0 -1
- package/dist/public/assets/pull-request-dialog-X0kSTYFA.js +0 -1
- package/dist/public/assets/pull-with-changes-dialog-CSHYq7Pw.js +0 -1
- package/dist/public/assets/push-before-pr-dialog-CQEDHNrv.js +0 -1
- package/dist/public/assets/radio-group-r6OYvBm-.js +0 -1
- package/dist/public/assets/react-vendor-B19oy2bp.js +0 -16
- package/dist/public/assets/settings-general-view-D_9c5_qk.js +0 -1
- package/dist/public/assets/settings-instructions-view-DA4cK-tR.js +0 -1
- package/dist/public/assets/settings-list-DIkoBKWq.js +0 -1
- package/dist/public/assets/settings-mcp-servers-view-DdEOTT5a.js +0 -5
- package/dist/public/assets/settings-models-skeleton-H4k7on9v.js +0 -1
- package/dist/public/assets/settings-models-view-Dr2-jQBx.js +0 -1
- package/dist/public/assets/settings-rules-view-BkwWI1jx.js +0 -8
- package/dist/public/assets/settings-skills-view-C9CI7z7Q.js +0 -3
- package/dist/public/assets/settings-slash-commands-view-TF-A8FFP.js +0 -1
- package/dist/public/assets/settings-subagents-view-B73VymuX.js +0 -2
- package/dist/public/assets/settings-system-prompt-view-CiX_so-K.js +0 -1
- package/dist/public/assets/settings-view-DsEVR17r.js +0 -2
- package/dist/public/assets/skeleton-Cnmylb3F.js +0 -1
- package/dist/public/assets/slug-utils-DLI9k6Hb.js +0 -1
- package/dist/public/assets/tabs-CsOdC2OA.js +0 -1
- package/dist/public/assets/tasks-view-CGMAai1T.js +0 -2
- package/dist/public/assets/ui-components-CTS7wHdF.js +0 -1
- package/dist/public/assets/use-installed-ai-files-BfMG7O3g.js +0 -1
- package/dist/public/assets/web-gruOPZvU.js +0 -1
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/dist-oojFghRi.js","assets/rolldown-runtime-aKtaBQYM.js","assets/vosk-speech-Fi-g2v8n.js","assets/merged-pr-dialog-CiwhRqFv.js","assets/dialogs-config-C2KFQf9x.js","assets/onboarding-CFIVEI92.js","assets/history-view-IcXfB6BD.js","assets/git-ops-button-CKGLh3Zk.js","assets/terminal-panel-Dlon-VDl.js","assets/terminal-panel-kHJ-D0s7.css","assets/diff-view-DDECIdhE.js","assets/async-error-boundary-CaRNnJZe.js","assets/card-DFACZp3F.js","assets/context-menu-CBvTcHUI.js","assets/react-vendor-tSKmVA4e.js","assets/monaco-CMkNoWsM.js","assets/monaco-Br_kD0ds.css","assets/utils-Dt07QR3w.js","assets/explorer-tab-view-72Krb0Ir.js","assets/api-CtfZCd77.js","assets/explorer-file-drop-DaQtKkIj.js","assets/explorer-tab-context-DCq1BBX_.js","assets/browser-tab-BfAt-Sho.js","assets/tasks-view-Cg9N8GZb.js","assets/settings-view-BweC2YuW.js","assets/skeleton-DBWV1Usf.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{i as e,t}from"./rolldown-runtime-aKtaBQYM.js";import{$ as n,$n as r,$o as i,$s as a,$t as o,Aa as s,Ac as c,Ai as l,An as u,Ao as d,Bc as f,Bi as p,Bn as m,Bo as h,Br as g,Bt as _,Cc as v,Ci as y,Cn as b,Co as x,Cs as S,Dn as C,Do as w,Ea as T,Ec as E,Ei as D,En as O,Et as k,Fn as A,Fo as j,Ft as M,Gi as N,Go as P,Ha as F,Hi as I,Hn as L,Ho as R,Hr as z,Ht as B,Ia as ee,Ii as te,Io as ne,Is as re,It as ie,Ja as ae,Jo as oe,Ka as se,Ki as ce,Ks as le,Kt as ue,La as de,Lc as fe,Lo as pe,Ls as V,Ma as me,Mc as he,Mi as ge,Mn as _e,Mo as ve,Mr as ye,Ms as be,Na as xe,Nc as Se,Ni as Ce,No as we,Ns as Te,Nt as H,Oa as Ee,On as De,Oo as Oe,Os as ke,Pc as Ae,Pn as je,Po as Me,Ps as Ne,Qa as Pe,Qi as Fe,Qn as Ie,Qr as Le,Qt as Re,Ra as ze,Rc as Be,Ri as Ve,Ro as He,Rt as Ue,Sa as We,Sc as Ge,Si as Ke,Sn as qe,So as Je,Ta as Ye,Ti as Xe,Tn as Ze,To as Qe,Ts as $e,Ua as et,Uo as tt,Us as nt,Ut as rt,Va as it,Vi as at,Vn as ot,Vo as st,Vt as ct,Wa as lt,Wi as U,Wo as ut,Ws as dt,Wt as ft,Xi as pt,Xn as mt,Xo as ht,Xr as gt,Ya as _t,Yo as vt,Yr as yt,Z as bt,Za as xt,Zr as St,Zt as Ct,_ as wt,_a as Tt,_n as Et,_r as Dt,a as Ot,aa as W,ac as G,ai as kt,an as At,ao as jt,ar as Mt,as as Nt,b as Pt,bo as Ft,bs as It,c as Lt,cc as Rt,ci as zt,cn as Bt,co as Vt,cr as Ht,cs as Ut,d as Wt,da as Gt,dc as Kt,di as qt,dn as Jt,dr as Yt,ds as Xt,dt as Zt,ea as K,ec as Qt,er as $t,es as en,f as tn,fa as nn,fc as rn,fi as an,fn as on,fo as sn,fr as cn,ft as ln,g as un,ga as dn,gc as fn,gi as pn,gn as mn,go as hn,gs as gn,h as _n,hc as vn,hi as q,ho as yn,hs as bn,ia as xn,ic as Sn,ir as Cn,is as wn,ja as Tn,jc as En,ji as Dn,jn as On,jo as kn,js as An,ka as jn,ki as Mn,ko as Nn,ks as Pn,la as Fn,lc as In,li as Ln,lo as Rn,lt as zn,m as Bn,ma as Vn,mc as Hn,mi as Un,mo as Wn,mr as Gn,na as Kn,ni as qn,ns as Jn,oc as Yn,oo as Xn,or as Zn,p as Qn,pc as $n,pi as er,pn as tr,po as nr,ps as rr,qa as ir,qi as ar,qs as or,ra as sr,rc as J,ro as cr,rr as lr,rt as ur,s as dr,sc as fr,so as pr,sr as mr,ss as hr,st as gr,ta as _r,tc as vr,tn as yr,tr as br,ts as xr,tt as Sr,u as Cr,uc as wr,ui as Tr,uo as Er,us as Dr,ut as Or,v as kr,va as Ar,vi as jr,vo as Mr,vt as Nr,wc as Pr,wi as Fr,wn as Ir,ws as Lr,x as Rr,xc as zr,xo as Br,xs as Vr,ya as Hr,yc as Ur,yi as Wr,yn as Gr,yo as Kr,ys as qr,yt as Jr,zc as Yr,zi as Xr,zn as Zr,zo as Qr,zt as $r}from"./dialogs-config-C2KFQf9x.js";import{A as ei,B as ti,F as ni,G as ri,H as ii,I as ai,J as oi,K as si,L as ci,M as li,N as ui,O as di,P as fi,R as pi,U as mi,V as hi,W as gi,Y as _i,j as vi,k as yi,q as bi,z as xi}from"./react-vendor-tSKmVA4e.js";import{$t as Si,A as Ci,An as wi,At as Ti,B as Ei,Bn as Di,Bt as Oi,C as ki,Cn as Ai,Ct as ji,D as Mi,Dn as Ni,Dt as Pi,E as Fi,En as Ii,Et as Li,F as Ri,Fn as zi,G as Bi,Gn as Vi,Gt as Hi,H as Ui,Hn as Wi,Ht as Gi,I as Ki,In as qi,J as Ji,Jn as Yi,Jt as Xi,K as Zi,Kn as Qi,Kt as $i,L as ea,Ln as ta,M as na,Mn as ra,N as ia,Nn as aa,O as oa,Ot as sa,P as ca,Pn as la,Qn as ua,Qt as da,R as fa,Rn as pa,S as ma,Sn as Y,T as ha,Tt as ga,U as _a,Un as va,Ut as X,V as ya,Vn as ba,Vt as xa,Wn as Sa,Wt as Ca,Xn as wa,Xt as Ta,Yn as Ea,Yt as Da,Zn as Oa,Zt as ka,_ as Aa,_n as ja,an as Ma,b as Na,bn as Pa,c as Fa,cn as Ia,d as La,dn as Ra,en as za,fn as Ba,g as Va,gn as Ha,gt as Ua,hn as Wa,ht as Ga,in as Ka,j as qa,jn as Ja,jt as Ya,k as Xa,kn as Za,kt as Qa,l as $a,ln as eo,mn as to,mt as no,nn as ro,on as io,pn as ao,q as oo,qn as so,qt as co,rn as lo,sn as uo,tn as fo,tr as po,u as mo,un as ho,v as go,vn as _o,w as vo,wn as yo,x as bo,xn as xo,y as So,yn as Co,zn as wo}from"./history-view-IcXfB6BD.js";import{o as To,u as Eo,v as Do,y as Oo}from"./onboarding-CFIVEI92.js";import{n as ko,t as Ao}from"./explorer-tab-context-DCq1BBX_.js";import{n as jo,t as Mo}from"./utils-Dt07QR3w.js";(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),e.crossOrigin===`use-credentials`?t.credentials=`include`:e.crossOrigin===`anonymous`?t.credentials=`omit`:t.credentials=`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var No=class extends wi{#e;#t;#n;#r;constructor(e){super(),this.#e=e.client,this.mutationId=e.mutationId,this.#n=e.mutationCache,this.#t=[],this.state=e.state||Po(),this.setOptions(e.options),this.scheduleGc()}setOptions(e){this.options=e,this.updateGcTime(this.options.gcTime)}get meta(){return this.options.meta}addObserver(e){this.#t.includes(e)||(this.#t.push(e),this.clearGcTimeout(),this.#n.notify({type:`observerAdded`,mutation:this,observer:e}))}removeObserver(e){this.#t=this.#t.filter(t=>t!==e),this.scheduleGc(),this.#n.notify({type:`observerRemoved`,mutation:this,observer:e})}optionalRemove(){this.#t.length||(this.state.status===`pending`?this.scheduleGc():this.#n.remove(this))}continue(){return this.#r?.continue()??this.execute(this.state.variables)}async execute(e){let t=()=>{this.#i({type:`continue`})},n={client:this.#e,meta:this.options.meta,mutationKey:this.options.mutationKey};this.#r=Ja({fn:()=>this.options.mutationFn?this.options.mutationFn(e,n):Promise.reject(Error(`No mutationFn found`)),onFail:(e,t)=>{this.#i({type:`failed`,failureCount:e,error:t})},onPause:()=>{this.#i({type:`pause`})},onContinue:t,retry:this.options.retry??0,retryDelay:this.options.retryDelay,networkMode:this.options.networkMode,canRun:()=>this.#n.canRun(this)});let r=this.state.status===`pending`,i=!this.#r.canStart();try{if(r)t();else{this.#i({type:`pending`,variables:e,isPaused:i}),this.#n.config.onMutate&&await this.#n.config.onMutate(e,this,n);let t=await this.options.onMutate?.(e,n);t!==this.state.context&&this.#i({type:`pending`,context:t,variables:e,isPaused:i})}let a=await this.#r.start();return await this.#n.config.onSuccess?.(a,e,this.state.context,this,n),await this.options.onSuccess?.(a,e,this.state.context,n),await this.#n.config.onSettled?.(a,null,this.state.variables,this.state.context,this,n),await this.options.onSettled?.(a,null,e,this.state.context,n),this.#i({type:`success`,data:a}),a}catch(t){try{await this.#n.config.onError?.(t,e,this.state.context,this,n)}catch(e){Promise.reject(e)}try{await this.options.onError?.(t,e,this.state.context,n)}catch(e){Promise.reject(e)}try{await this.#n.config.onSettled?.(void 0,t,this.state.variables,this.state.context,this,n)}catch(e){Promise.reject(e)}try{await this.options.onSettled?.(void 0,t,e,this.state.context,n)}catch(e){Promise.reject(e)}throw this.#i({type:`error`,error:t}),t}finally{this.#n.runNext(this)}}#i(e){let t=t=>{switch(e.type){case`failed`:return{...t,failureCount:e.failureCount,failureReason:e.error};case`pause`:return{...t,isPaused:!0};case`continue`:return{...t,isPaused:!1};case`pending`:return{...t,context:e.context,data:void 0,failureCount:0,failureReason:null,error:null,isPaused:e.isPaused,status:`pending`,variables:e.variables,submittedAt:Date.now()};case`success`:return{...t,data:e.data,failureCount:0,failureReason:null,error:null,status:`success`,isPaused:!1};case`error`:return{...t,data:void 0,error:e.error,failureCount:t.failureCount+1,failureReason:e.error,isPaused:!1,status:`error`}}};this.state=t(this.state),aa.batch(()=>{this.#t.forEach(t=>{t.onMutationUpdate(e)}),this.#n.notify({mutation:this,type:`updated`,action:e})})}};function Po(){return{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:`idle`,variables:void 0,submittedAt:0}}var Fo=class extends Vi{constructor(e={}){super(),this.config=e,this.#e=new Set,this.#t=new Map,this.#n=0}#e;#t;#n;build(e,t,n){let r=new No({client:e,mutationCache:this,mutationId:++this.#n,options:e.defaultMutationOptions(t),state:n});return this.add(r),r}add(e){this.#e.add(e);let t=Io(e);if(typeof t==`string`){let n=this.#t.get(t);n?n.push(e):this.#t.set(t,[e])}this.notify({type:`added`,mutation:e})}remove(e){if(this.#e.delete(e)){let t=Io(e);if(typeof t==`string`){let n=this.#t.get(t);if(n)if(n.length>1){let t=n.indexOf(e);t!==-1&&n.splice(t,1)}else n[0]===e&&this.#t.delete(t)}}this.notify({type:`removed`,mutation:e})}canRun(e){let t=Io(e);if(typeof t==`string`){let n=this.#t.get(t)?.find(e=>e.state.status===`pending`);return!n||n===e}else return!0}runNext(e){let t=Io(e);return typeof t==`string`?(this.#t.get(t)?.find(t=>t!==e&&t.state.isPaused))?.continue()??Promise.resolve():Promise.resolve()}clear(){aa.batch(()=>{this.#e.forEach(e=>{this.notify({type:`removed`,mutation:e})}),this.#e.clear(),this.#t.clear()})}getAll(){return Array.from(this.#e)}find(e){let t={exact:!0,...e};return this.getAll().find(e=>pa(t,e))}findAll(e={}){return this.getAll().filter(t=>pa(e,t))}notify(e){aa.batch(()=>{this.listeners.forEach(t=>{t(e)})})}resumePausedMutations(){let e=this.getAll().filter(e=>e.state.isPaused);return aa.batch(()=>Promise.all(e.map(e=>e.continue().catch(Di))))}};function Io(e){return e.options.scope?.id}var Lo=class extends Vi{constructor(e={}){super(),this.config=e,this.#e=new Map}#e;build(e,t,n){let r=t.queryKey,i=t.queryHash??qi(r,t),a=this.get(i);return a||(a=new Za({client:e,queryKey:r,queryHash:i,options:e.defaultQueryOptions(t),state:n,defaultOptions:e.getQueryDefaults(r)}),this.add(a)),a}add(e){this.#e.has(e.queryHash)||(this.#e.set(e.queryHash,e),this.notify({type:`added`,query:e}))}remove(e){let t=this.#e.get(e.queryHash);t&&(e.destroy(),t===e&&this.#e.delete(e.queryHash),this.notify({type:`removed`,query:e}))}clear(){aa.batch(()=>{this.getAll().forEach(e=>{this.remove(e)})})}get(e){return this.#e.get(e)}getAll(){return[...this.#e.values()]}find(e){let t={exact:!0,...e};return this.getAll().find(e=>wo(t,e))}findAll(e={}){let t=this.getAll();return Object.keys(e).length>0?t.filter(t=>wo(e,t)):t}notify(e){aa.batch(()=>{this.listeners.forEach(t=>{t(e)})})}onFocus(){aa.batch(()=>{this.getAll().forEach(e=>{e.onFocus()})})}onOnline(){aa.batch(()=>{this.getAll().forEach(e=>{e.onOnline()})})}},Ro=class{#e;#t;#n;#r;#i;#a;#o;#s;constructor(e={}){this.#e=e.queryCache||new Lo,this.#t=e.mutationCache||new Fo,this.#n=e.defaultOptions||{},this.#r=new Map,this.#i=new Map,this.#a=0}mount(){this.#a++,this.#a===1&&(this.#o=Sa.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#e.onFocus())}),this.#s=ra.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#e.onOnline())}))}unmount(){this.#a--,this.#a===0&&(this.#o?.(),this.#o=void 0,this.#s?.(),this.#s=void 0)}isFetching(e){return this.#e.findAll({...e,fetchStatus:`fetching`}).length}isMutating(e){return this.#t.findAll({...e,status:`pending`}).length}getQueryData(e){let t=this.defaultQueryOptions({queryKey:e});return this.#e.get(t.queryHash)?.state.data}ensureQueryData(e){let t=this.defaultQueryOptions(e),n=this.#e.build(this,t),r=n.state.data;return r===void 0?this.fetchQuery(e):(e.revalidateIfStale&&n.isStaleByTime(Wi(t.staleTime,n))&&this.prefetchQuery(t),Promise.resolve(r))}getQueriesData(e){return this.#e.findAll(e).map(({queryKey:e,state:t})=>[e,t.data])}setQueryData(e,t,n){let r=this.defaultQueryOptions({queryKey:e}),i=this.#e.get(r.queryHash)?.state.data,a=la(t,i);if(a!==void 0)return this.#e.build(this,r).setData(a,{...n,manual:!0})}setQueriesData(e,t,n){return aa.batch(()=>this.#e.findAll(e).map(({queryKey:e})=>[e,this.setQueryData(e,t,n)]))}getQueryState(e){let t=this.defaultQueryOptions({queryKey:e});return this.#e.get(t.queryHash)?.state}removeQueries(e){let t=this.#e;aa.batch(()=>{t.findAll(e).forEach(e=>{t.remove(e)})})}resetQueries(e,t){let n=this.#e;return aa.batch(()=>(n.findAll(e).forEach(e=>{e.reset()}),this.refetchQueries({type:`active`,...e},t)))}cancelQueries(e,t={}){let n={revert:!0,...t},r=aa.batch(()=>this.#e.findAll(e).map(e=>e.cancel(n)));return Promise.all(r).then(Di).catch(Di)}invalidateQueries(e,t={}){return aa.batch(()=>(this.#e.findAll(e).forEach(e=>{e.invalidate()}),e?.refetchType===`none`?Promise.resolve():this.refetchQueries({...e,type:e?.refetchType??e?.type??`active`},t)))}refetchQueries(e,t={}){let n={...t,cancelRefetch:t.cancelRefetch??!0},r=aa.batch(()=>this.#e.findAll(e).filter(e=>!e.isDisabled()&&!e.isStatic()).map(e=>{let t=e.fetch(void 0,n);return n.throwOnError||(t=t.catch(Di)),e.state.fetchStatus===`paused`?Promise.resolve():t}));return Promise.all(r).then(Di)}fetchQuery(e){let t=this.defaultQueryOptions(e);t.retry===void 0&&(t.retry=!1);let n=this.#e.build(this,t);return n.isStaleByTime(Wi(t.staleTime,n))?n.fetch(t):Promise.resolve(n.state.data)}prefetchQuery(e){return this.fetchQuery(e).then(Di).catch(Di)}fetchInfiniteQuery(e){return e._type=`infinite`,this.fetchQuery(e)}prefetchInfiniteQuery(e){return this.fetchInfiniteQuery(e).then(Di).catch(Di)}ensureInfiniteQueryData(e){return e._type=`infinite`,this.ensureQueryData(e)}resumePausedMutations(){return ra.isOnline()?this.#t.resumePausedMutations():Promise.resolve()}getQueryCache(){return this.#e}getMutationCache(){return this.#t}getDefaultOptions(){return this.#n}setDefaultOptions(e){this.#n=e}setQueryDefaults(e,t){this.#r.set(zi(e),{queryKey:e,defaultOptions:t})}getQueryDefaults(e){let t=[...this.#r.values()],n={};return t.forEach(t=>{ba(e,t.queryKey)&&Object.assign(n,t.defaultOptions)}),n}setMutationDefaults(e,t){this.#i.set(zi(e),{mutationKey:e,defaultOptions:t})}getMutationDefaults(e){let t=[...this.#i.values()],n={};return t.forEach(t=>{ba(e,t.mutationKey)&&Object.assign(n,t.defaultOptions)}),n}defaultQueryOptions(e){if(e._defaulted)return e;let t={...this.#n.queries,...this.getQueryDefaults(e.queryKey),...e,_defaulted:!0};return t.queryHash||=qi(t.queryKey,t),t.refetchOnReconnect===void 0&&(t.refetchOnReconnect=t.networkMode!==`always`),t.throwOnError===void 0&&(t.throwOnError=!!t.suspense),!t.networkMode&&t.persister&&(t.networkMode=`offlineFirst`),t.queryFn===va&&(t.enabled=!1),t}defaultMutationOptions(e){return e?._defaulted?e:{...this.#n.mutations,...e?.mutationKey&&this.getMutationDefaults(e.mutationKey),...e,_defaulted:!0}}clear(){this.#e.clear(),this.#t.clear()}},Z=e(f(),1),zo=_i(),Q=Be(),$=fe(),Bo=Oi(e=>(0,$.jsx)(`svg`,{width:`0`,height:`0`,style:e.v0,"aria-hidden":`true`,children:(0,$.jsxs)(`filter`,{id:e.v1,x:`0`,y:`0`,width:`100%`,height:`100%`,colorInterpolationFilters:`sRGB`,children:[(0,$.jsx)(`feImage`,{x:`0`,y:`0`,width:`80`,height:`80`,href:`data:image/svg+xml;utf8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2280%22%20height%3D%2280%22%20viewBox%3D%220%200%2080%2080%22%3E%3Cdefs%3E%3ClinearGradient%20id%3D%22Y%22%20x1%3D%220%22%20x2%3D%220%22%20y1%3D%222%25%22%20y2%3D%2298%25%22%3E%3Cstop%20offset%3D%220%25%22%20stop-color%3D%22%230F0%22%2F%3E%3Cstop%20offset%3D%22100%25%22%20stop-color%3D%22%23000%22%2F%3E%3C%2FlinearGradient%3E%3ClinearGradient%20id%3D%22X%22%20x1%3D%221%25%22%20x2%3D%2299%25%22%20y1%3D%220%22%20y2%3D%220%22%3E%3Cstop%20offset%3D%220%25%22%20stop-color%3D%22%23F00%22%2F%3E%3Cstop%20offset%3D%22100%25%22%20stop-color%3D%22%23000%22%2F%3E%3C%2FlinearGradient%3E%3C%2Fdefs%3E%3Crect%20width%3D%2280%22%20height%3D%2280%22%20fill%3D%22%23808080%22%2F%3E%3Cg%20filter%3D%22blur(2px)%22%3E%3Crect%20width%3D%2280%22%20height%3D%2280%22%20fill%3D%22%23000080%22%2F%3E%3Crect%20width%3D%2280%22%20height%3D%2280%22%20fill%3D%22url(%23Y)%22%20style%3D%22mix-blend-mode%3Ascreen%22%2F%3E%3Crect%20width%3D%2280%22%20height%3D%2280%22%20fill%3D%22url(%23X)%22%20style%3D%22mix-blend-mode%3Ascreen%22%2F%3E%3Crect%20x%3D%228%22%20y%3D%228%22%20width%3D%2264%22%20height%3D%2264%22%20rx%3D%225%22%20ry%3D%225%22%20fill%3D%22%23808080%22%20filter%3D%22blur(16px)%22%2F%3E%3C%2Fg%3E%3C%2Fsvg%3E`,result:`displacementMap`}),(0,$.jsx)(`feDisplacementMap`,{in:`SourceGraphic`,in2:`displacementMap`,scale:`158`,xChannelSelector:`R`,yChannelSelector:`G`}),(0,$.jsx)(`feColorMatrix`,{type:`matrix`,result:`displacedR`,values:`1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0`}),(0,$.jsx)(`feDisplacementMap`,{in:`SourceGraphic`,in2:`displacementMap`,scale:`156`,xChannelSelector:`R`,yChannelSelector:`G`}),(0,$.jsx)(`feColorMatrix`,{type:`matrix`,result:`displacedG`,values:`0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0`}),(0,$.jsx)(`feDisplacementMap`,{in:`SourceGraphic`,in2:`displacementMap`,scale:`154`,xChannelSelector:`R`,yChannelSelector:`G`}),(0,$.jsx)(`feColorMatrix`,{type:`matrix`,result:`displacedB`,values:`0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0`}),(0,$.jsx)(`feBlend`,{in:`displacedR`,in2:`displacedG`,mode:`screen`,result:`rg`}),(0,$.jsx)(`feBlend`,{in:`rg`,in2:`displacedB`,mode:`screen`})]})}),{name:`LiquidGlassFilterDefs_1`,svg:!0}),Vo=function(){let e=(0,Q.c)(1),t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(Bo,{v0:{position:`absolute`},v1:Ho}),e[0]=t):t=e[0],t},Ho=`lg-filter-project-icon`,Uo=`blur(2px) url(#${Ho}) blur(4px) saturate(1.5) brightness(1.1)`,Wo=`blur(16px) saturate(1.8) brightness(1.15) contrast(1.05)`,Go=`inset 0 0 0 1px rgba(255, 255, 255, 0.15), inset 1.5px 1.5px 0 rgba(255, 255, 255, 0.5), inset 0 0 12px rgba(255, 255, 255, 0.2)`;function Ko(e){let t=(0,Q.c)(17),{project:n,isSelected:r,isDeleting:i,elevated:a,className:o,iconClassName:s}=e,c=r===void 0?!1:r,l=i===void 0?!1:i,u=a===void 0?!0:a,f;t[0]===n?f=t[1]:(f=nt(xn(n)),t[0]=n,t[1]=f);let p=f,m=n.gitUrl?d:Oe,h=c&&`ring-2 ring-brand/40`,g;t[2]!==o||t[3]!==h?(g=K(`relative flex aspect-square items-center justify-center overflow-hidden rounded-[1.15rem] text-foreground/70 dark:text-white`,h,o),t[2]=o,t[3]=h,t[4]=g):g=t[4];let _=`linear-gradient(150deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.02)), ${p}`,v=u?`${Go}, 0 8px 32px rgba(0, 0, 0, 0.2)`:`${Go}, 0 1px 2px rgba(0, 0, 0, 0.15)`,y;t[5]!==_||t[6]!==v?(y={backgroundColor:`rgba(255, 255, 255, 0.17)`,backgroundImage:_,backdropFilter:Uo,WebkitBackdropFilter:Wo,boxShadow:v},t[5]=_,t[6]=v,t[7]=y):y=t[7];let b;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(b=(0,$.jsx)(`div`,{className:`pointer-events-none absolute inset-0 dark:bg-black/55`}),t[8]=b):b=t[8];let x;t[9]!==m||t[10]!==s||t[11]!==l?(x=l?(0,$.jsx)(sn,{className:K(`relative h-8 w-8 animate-spin text-muted-foreground`,s)}):(0,$.jsx)(m,{className:K(`relative h-8 w-8`,s),strokeWidth:1.5}),t[9]=m,t[10]=s,t[11]=l,t[12]=x):x=t[12];let S;return t[13]!==x||t[14]!==g||t[15]!==y?(S=(0,$.jsxs)(`div`,{className:g,style:y,children:[b,x]}),t[13]=x,t[14]=g,t[15]=y,t[16]=S):S=t[16],S}var qo=Oi(e=>(0,$.jsxs)(`div`,{className:`group relative flex w-full max-w-[6.5rem] flex-col items-center gap-2`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:e.v0,className:`flex w-full flex-col items-center gap-2 outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-sidebar rounded-2xl`,children:[e.v1,(0,$.jsx)(`span`,{className:e.v2,children:e.v3})]}),e.v4]}),{name:`IconCard_1`,portals:[`v1`,`v3`,`v4`]}),Jo=function(e){let t=(0,Q.c)(8),{label:n,tile:r,onClick:i,isSelected:a,actions:o}=e,s=a!==void 0&&a?`text-foreground`:`text-foreground/90`,c;t[0]===s?c=t[1]:(c=K(J.compact,`w-full text-center font-medium leading-tight line-clamp-2 break-words`,s),t[0]=s,t[1]=c);let l;return t[2]!==o||t[3]!==n||t[4]!==i||t[5]!==c||t[6]!==r?(l=(0,$.jsx)(qo,{v0:i,v1:r,v2:c,v3:n,v4:o}),t[2]=o,t[3]=n,t[4]=i,t[5]=c,t[6]=r,t[7]=l):l=t[7],l};function Yo(e){let t=(0,Q.c)(18),{projects:n,selectedThreadId:r,selectedProjectId:i,deletingProjectIds:a,onSelectProject:o,onDeleteProject:s}=e,c;t[0]===n.length?c=t[1]:(c=n.length===0&&(0,$.jsx)(`p`,{className:K(J.compact,`col-span-full px-3 pb-2 text-center text-muted-foreground`),children:`No projects yet. Clone a repository to get started.`}),t[0]=n.length,t[1]=c);let l;if(t[2]!==a||t[3]!==s||t[4]!==o||t[5]!==n||t[6]!==i||t[7]!==r){let e;t[9]!==a||t[10]!==s||t[11]!==o||t[12]!==i||t[13]!==r?(e=e=>(0,$.jsx)(Xo,{project:e,isDeleting:a.includes(e.projectId),isSelected:i!=null&&e.projectId===i||e.threads.some(e=>e.threadId===r),onSelectProject:o,onDeleteProject:s},e.projectId||e.gitUrl),t[9]=a,t[10]=s,t[11]=o,t[12]=i,t[13]=r,t[14]=e):e=t[14],l=n.map(e),t[2]=a,t[3]=s,t[4]=o,t[5]=n,t[6]=i,t[7]=r,t[8]=l}else l=t[8];let u;return t[15]!==c||t[16]!==l?(u=(0,$.jsxs)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(5.5rem,1fr))] gap-x-4 gap-y-6 justify-items-center sm:grid-cols-[repeat(auto-fill,minmax(6.5rem,1fr))] sm:gap-x-6 sm:gap-y-8`,children:[c,l]}),t[15]=c,t[16]=l,t[17]=u):u=t[17],u}function Xo(e){let t=(0,Q.c)(19),{project:n,isDeleting:r,isSelected:i,onSelectProject:a,onDeleteProject:o}=e,s=!r&&n.threads.length===0,c;t[0]===n?c=t[1]:(c=xn(n),t[0]=n,t[1]=c);let l;t[2]!==a||t[3]!==n.projectId?(l=()=>a(n.projectId),t[2]=a,t[3]=n.projectId,t[4]=l):l=t[4];let u;t[5]!==r||t[6]!==i||t[7]!==n?(u=(0,$.jsx)(Ko,{project:n,isSelected:i,isDeleting:r,className:`w-full max-w-[4.5rem] transition-transform can-hover:group-hover:scale-[1.03] sm:max-w-[5rem]`,iconClassName:`sm:h-9 sm:w-9`}),t[5]=r,t[6]=i,t[7]=n,t[8]=u):u=t[8];let d;t[9]!==o||t[10]!==n.projectId||t[11]!==s?(d=s?(0,$.jsx)(Ti,{children:(0,$.jsx)(`div`,{className:`pointer-events-none invisible absolute -right-1 -top-1 flex flex-col gap-1 opacity-0 transition-opacity can-hover:group-hover:visible can-hover:group-hover:pointer-events-auto can-hover:group-hover:opacity-100`,children:(0,$.jsxs)(sa,{children:[(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsxs)(Fe,{variant:`ghost`,size:`icon`,className:`h-7 w-7 rounded-full bg-background border border-border shadow-sm text-muted-foreground can-hover:hover:bg-destructive can-hover:hover:text-destructive-foreground`,onClick:()=>o(n.projectId),children:[(0,$.jsx)(Tt,{className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Delete project`})]})}),(0,$.jsx)(Qa,{side:`right`,children:`Delete project`})]})})}):void 0,t[9]=o,t[10]=n.projectId,t[11]=s,t[12]=d):d=t[12];let f;return t[13]!==i||t[14]!==c||t[15]!==l||t[16]!==u||t[17]!==d?(f=(0,$.jsx)(Jo,{label:c,isSelected:i,onClick:l,tile:u,actions:d}),t[13]=i,t[14]=c,t[15]=l,t[16]=u,t[17]=d,t[18]=f):f=t[18],f}function Zo(e){let t=(0,Q.c)(5),{children:n,className:r}=e,i;t[0]===r?i=t[1]:(i=K(`flex min-h-[71px] shrink-0 items-center gap-2 px-4 py-2 electrobun-webkit-app-region-drag`,r),t[0]=r,t[1]=i);let a;return t[2]!==n||t[3]!==i?(a=(0,$.jsx)(`header`,{className:i,children:n}),t[2]=n,t[3]=i,t[4]=a):a=t[4],a}function Qo(e){let t=(0,Q.c)(4),{className:n}=e;if(!Ln())return null;let r;t[0]===n?r=t[1]:(r=K(`h-8 w-full shrink-0 electrobun-webkit-app-region-drag`,n),t[0]=n,t[1]=r);let i;return t[2]===r?i=t[3]:(i=(0,$.jsx)(`div`,{"aria-hidden":!0,className:r}),t[2]=r,t[3]=i),i}function $o(e){let t=(0,Q.c)(30),{onSelectMode:n,onOpenFolder:r}=e,i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,$.jsx)(Ji,{asChild:!0,children:(0,$.jsxs)(Fe,{className:`gap-1`,children:[`New Project`,(0,$.jsx)(Dr,{className:`h-4 w-4 opacity-70`})]})}),t[0]=i):i=t[0];let a;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(a=K(J.body,`gap-2`),t[1]=a):a=t[1];let o;t[2]===n?o=t[3]:(o=()=>n(`folder`),t[2]=n,t[3]=o);let s;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(s=(0,$.jsx)(ir,{className:`h-4 w-4 shrink-0`}),t[4]=s):s=t[4];let c;t[5]===o?c=t[6]:(c=(0,$.jsxs)(ya,{className:a,onSelect:o,children:[s,`Blank Starter`]}),t[5]=o,t[6]=c);let l;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(l=K(J.body,`gap-2`),t[7]=l):l=t[7];let u;t[8]===n?u=t[9]:(u=()=>n(`clone`),t[8]=n,t[9]=u);let d;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,$.jsx)(w,{className:`h-4 w-4 shrink-0`}),t[10]=d):d=t[10];let f;t[11]===u?f=t[12]:(f=(0,$.jsxs)(ya,{className:l,onSelect:u,children:[d,`Git Repo`]}),t[11]=u,t[12]=f);let p;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(p=K(J.body,`gap-2`),t[13]=p):p=t[13];let m;t[14]===r?m=t[15]:(m=()=>{r()},t[14]=r,t[15]=m);let h;t[16]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,$.jsx)(Nn,{className:`h-4 w-4 shrink-0`}),t[16]=h):h=t[16];let g;t[17]===m?g=t[18]:(g=(0,$.jsxs)(ya,{className:p,onSelect:m,children:[h,`Open Folder`]}),t[17]=m,t[18]=g);let _;t[19]===Symbol.for(`react.memo_cache_sentinel`)?(_=K(J.body,`gap-2`),t[19]=_):_=t[19];let v;t[20]===n?v=t[21]:(v=()=>n(`webapp`),t[20]=n,t[21]=v);let y;t[22]===Symbol.for(`react.memo_cache_sentinel`)?(y=(0,$.jsx)(xt,{className:`h-4 w-4 shrink-0`}),t[22]=y):y=t[22];let b;t[23]===v?b=t[24]:(b=(0,$.jsxs)(ya,{className:_,onSelect:v,children:[y,`New App`]}),t[23]=v,t[24]=b);let x;return t[25]!==g||t[26]!==b||t[27]!==c||t[28]!==f?(x=(0,$.jsxs)(fa,{children:[i,(0,$.jsxs)(Ei,{align:`end`,className:`w-44`,children:[c,f,g,b]})]}),t[25]=g,t[26]=b,t[27]=c,t[28]=f,t[29]=x):x=t[29],x}function es(e){let t=(0,Q.c)(40),{projects:n,selectedThreadId:r,selectedProjectId:i,deletingProjectIds:a,onSelectProject:o,onCreateProject:s,onOpenFolder:c,onDeleteProject:l,updateAvailable:u,updatingApp:d,onUpdateApp:f,isDevMode:p}=e,m=ua(),h=X(ns),[g,_]=(0,Z.useState)(!h),v;t[0]===n?v=t[1]:(v=[...n].sort(ts),t[0]=n,t[1]=v);let y=v;!h&&!g&&_(!0);let b;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(b=function(){C(`https://tarsk.io/`)},t[2]=b):b=t[2];let x=b;if(!g){let e;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(Qo,{}),t[3]=e):e=t[3];let n;return t[4]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,$.jsxs)(`div`,{className:`flex h-full flex-col overflow-hidden`,children:[e,(0,$.jsx)(`div`,{className:`flex flex-1 items-center justify-center`,children:(0,$.jsx)(sn,{className:`h-8 w-8 animate-spin text-muted-foreground`})})]}),t[4]=n):n=t[4],n}let S;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(S=(0,$.jsx)(Qo,{}),t[5]=S):S=t[5];let w;t[6]===m?w=t[7]:(w=()=>void m(`/settings/general`),t[6]=m,t[7]=w);let T;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(T=(0,$.jsx)(me,{className:`h-5 w-5`}),t[8]=T):T=t[8];let E;t[9]===w?E=t[10]:(E=(0,$.jsx)(`div`,{className:`absolute right-4 top-4 z-20 electrobun-webkit-app-region-no-drag`,children:(0,$.jsx)(Fe,{variant:`ghost`,size:`icon`,className:`[color:contrast-color(hsl(var(--background)))] hover:[color:contrast-color(hsl(var(--foreground)))]`,onClick:w,"aria-label":`Settings`,children:T})}),t[9]=w,t[10]=E);let D;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(D=(0,$.jsx)(`button`,{type:`button`,onClick:x,className:`flex h-20 w-20 cursor-pointer items-center justify-center overflow-hidden rounded-full border border-border shadow-sm`,children:(0,$.jsx)(`img`,{src:`/tarsk.svg`,alt:`Tarsk`,className:`h-full w-full`})}),t[11]=D):D=t[11];let O;t[12]===p?O=t[13]:(O=p?(0,$.jsx)(`p`,{className:K(J.label,`mt-2 text-destructive dark:text-red-400`),children:`Dev Mode`}):null,t[12]=p,t[13]=O);let k;t[14]===O?k=t[15]:(k=(0,$.jsxs)(`div`,{className:`absolute left-1/2 top-10 z-10 flex -translate-x-1/2 -translate-y-1/2 flex-col items-center`,children:[D,O]}),t[14]=O,t[15]=k);let A;t[16]!==s||t[17]!==c?(A=(0,$.jsx)(Ga,{title:`Projects`,action:(0,$.jsx)($o,{onSelectMode:s,onOpenFolder:c}),sticky:!0,border:!1}),t[16]=s,t[17]=c,t[18]=A):A=t[18];let j;t[19]!==a||t[20]!==l||t[21]!==o||t[22]!==i||t[23]!==r||t[24]!==y?(j=(0,$.jsx)(Yo,{projects:y,selectedThreadId:r,selectedProjectId:i,deletingProjectIds:a,onSelectProject:o,onDeleteProject:l}),t[19]=a,t[20]=l,t[21]=o,t[22]=i,t[23]=r,t[24]=y,t[25]=j):j=t[25];let M;t[26]!==A||t[27]!==j?(M=(0,$.jsxs)(Li,{className:`px-6 pb-6 pt-16`,children:[A,j]}),t[26]=A,t[27]=j,t[28]=M):M=t[28];let N;t[29]!==M||t[30]!==k?(N=(0,$.jsx)(ga,{className:`relative z-10 animate-in fade-in duration-500`,children:(0,$.jsx)(`div`,{className:`flex min-h-full flex-col justify-center`,children:(0,$.jsx)(ji,{className:`w-full py-10`,children:(0,$.jsxs)(`div`,{className:`relative pt-10`,children:[k,M]})})})}),t[29]=M,t[30]=k,t[31]=N):N=t[31];let P;t[32]!==f||t[33]!==u||t[34]!==d?(P=u?(0,$.jsx)(`div`,{className:`relative z-10 flex flex-shrink-0 justify-end px-4 pb-4 pt-2`,children:(0,$.jsxs)(Fe,{variant:`outline`,className:`text-emerald-600 dark:text-emerald-400`,onClick:f,disabled:d,children:[d?(0,$.jsx)(sn,{className:`h-4 w-4 animate-spin`}):(0,$.jsx)(ht,{className:`h-4 w-4`}),d?`Updating...`:`Upgrade to Latest`]})}):null,t[32]=f,t[33]=u,t[34]=d,t[35]=P):P=t[35];let F;return t[36]!==N||t[37]!==P||t[38]!==E?(F=(0,$.jsxs)(`div`,{className:`relative flex h-full flex-col overflow-hidden`,children:[S,E,N,P]}),t[36]=N,t[37]=P,t[38]=E,t[39]=F):F=t[39],F}function ts(e,t){return xn(e).localeCompare(xn(t))}function ns(e){return e.projectsLoading}var rs=e(Yr(),1),is=.1,as=10,os=1.25,ss=.001;function cs(){let e=(0,Q.c)(15),[t,n]=(0,Z.useState)(1),r;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(r={x:0,y:0},e[0]=r):r=e[0];let[i,a]=(0,Z.useState)(r),[o,s]=(0,Z.useState)(!1),c=(0,Z.useRef)(null),l=ls,u;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(u=()=>n(e=>l(e*os)),e[1]=u):u=e[1];let d=u,f;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(f=()=>n(e=>l(e/os)),e[2]=f):f=e[2];let p=f,m;e[3]===Symbol.for(`react.memo_cache_sentinel`)?(m=()=>{n(1),a({x:0,y:0})},e[3]=m):m=e[3];let h=m,g;e[4]===i?g=e[5]:(g=e=>{e.preventDefault(),s(!0),c.current={x:e.clientX,y:e.clientY,ox:i.x,oy:i.y}},e[4]=i,e[5]=g);let _=g,v;e[6]===Symbol.for(`react.memo_cache_sentinel`)?(v=e=>{c.current&&a({x:c.current.ox+(e.clientX-c.current.x),y:c.current.oy+(e.clientY-c.current.y)})},e[6]=v):v=e[6];let y=v,b;e[7]===Symbol.for(`react.memo_cache_sentinel`)?(b=()=>{s(!1),c.current=null},e[7]=b):b=e[7];let x=b,S=(0,Z.useRef)(null),C,w;e[8]===Symbol.for(`react.memo_cache_sentinel`)?(C=()=>{let e=S.current;if(!e)return;let t=function(e){e.preventDefault();let t=-e.deltaY*ss;n(e=>l(e*(1+t)))};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},w=[],e[8]=C,e[9]=w):(C=e[8],w=e[9]),(0,Z.useEffect)(C,w);let T;return e[10]!==o||e[11]!==i||e[12]!==_||e[13]!==t?(T={scale:t,offset:i,isDragging:o,containerRef:S,zoomIn:d,zoomOut:p,reset:h,onMouseDown:_,onMouseMove:y,onMouseUp:x},e[10]=o,e[11]=i,e[12]=_,e[13]=t,e[14]=T):T=e[14],T}function ls(e){return Math.min(Math.max(e,is),as)}var us=Oi(e=>(0,$.jsxs)(`div`,{className:`flex items-center justify-between border-b border-border bg-muted/80 px-4 py-2`,children:[(0,$.jsx)(`span`,{className:e.v0,children:e.v1}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[e.v2,e.v3]})]}),{name:`JSX_header_1`,portals:[`v1`,`v2`,`v3`]}),ds=Oi(e=>(0,$.jsxs)(`div`,{className:e.v0,children:[e.v1,(0,$.jsx)(`pre`,{className:`overflow-x-auto p-4 max-w-full`,children:(0,$.jsx)(`code`,{className:e.v2,children:e.v3})})]}),{name:`MermaidRenderer_1`,portals:[`v1`,`v3`]}),fs=Oi(e=>(0,$.jsxs)(`div`,{className:e.v0,children:[e.v1,(0,$.jsx)(`div`,{className:e.v2,children:`Rendering diagram…`})]}),{name:`MermaidRenderer_2`,portals:[`v1`]}),ps=Oi(e=>e.v0,{name:`MermaidRenderer_3`,portals:[`v0`]}),ms=function(e){let t=(0,Q.c)(47),{content:n,className:r}=e,[i,a]=(0,Z.useState)(!1),[o,s]=(0,Z.useState)(!1),{svgOutput:c,renderError:l}=_s(n,gs()),u;t[0]===n?u=t[1]:(u=async function(){await navigator.clipboard.writeText(n),a(!0),setTimeout(()=>a(!1),2e3)},t[0]=n,t[1]=u);let d=u,f;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(f=K(J.compact,`font-mono text-muted-foreground`),t[2]=f):f=t[2];let p=l?`mermaid (render error)`:`mermaid diagram`,m;t[3]!==l||t[4]!==c?(m=c&&!l&&(0,$.jsxs)(sa,{children:[(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsxs)(Fe,{variant:`action`,size:`icon-xs`,onClick:()=>s(!0),children:[(0,$.jsx)(Er,{}),(0,$.jsx)(`span`,{className:`sr-only`,children:`View fullscreen`})]})}),(0,$.jsx)(Qa,{children:`View fullscreen`})]}),t[3]=l,t[4]=c,t[5]=m):m=t[5];let h;t[6]===i?h=t[7]:(h=i?(0,$.jsx)(Xt,{}):(0,$.jsx)(en,{}),t[6]=i,t[7]=h);let g;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(g=(0,$.jsx)(`span`,{className:`sr-only`,children:`Copy mermaid code`}),t[8]=g):g=t[8];let _;t[9]!==d||t[10]!==h?(_=(0,$.jsxs)(Fe,{variant:`action`,size:`icon-xs`,onClick:d,children:[h,g]}),t[9]=d,t[10]=h,t[11]=_):_=t[11];let v;t[12]!==p||t[13]!==m||t[14]!==_?(v=(0,$.jsx)(us,{v0:f,v1:p,v2:m,v3:_}),t[12]=p,t[13]=m,t[14]=_,t[15]=v):v=t[15];let y=v;if(l){let e;t[16]===r?e=t[17]:(e=K(`group relative overflow-hidden rounded-lg border border-border bg-muted`,r),t[16]=r,t[17]=e);let i;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(i=K(J.compact,`font-mono text-foreground leading-relaxed`),t[18]=i):i=t[18];let a;return t[19]!==n||t[20]!==y||t[21]!==e?(a=(0,$.jsx)(ds,{v0:e,v1:y,v2:i,v3:n}),t[19]=n,t[20]=y,t[21]=e,t[22]=a):a=t[22],a}if(!c){let e;t[23]===r?e=t[24]:(e=K(`group relative overflow-hidden rounded-lg border border-border bg-muted`,r),t[23]=r,t[24]=e);let n;t[25]===Symbol.for(`react.memo_cache_sentinel`)?(n=K(J.compact,`p-4 text-muted-foreground`),t[25]=n):n=t[25];let i;return t[26]!==y||t[27]!==e?(i=(0,$.jsx)(fs,{v0:e,v1:y,v2:n}),t[26]=y,t[27]=e,t[28]=i):i=t[28],i}let b;t[29]===r?b=t[30]:(b=K(`group relative overflow-hidden rounded-lg border border-border bg-muted`,r),t[29]=r,t[30]=b);let x;t[31]===Symbol.for(`react.memo_cache_sentinel`)?(x=()=>s(!0),t[31]=x):x=t[31];let S;t[32]===c?S=t[33]:(S=(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:`block w-full text-left cursor-zoom-in p-4 max-w-full overflow-hidden [&_svg]:max-w-full [&_svg]:h-auto hover:bg-muted/70 transition-colors`,onClick:x,dangerouslySetInnerHTML:{__html:c}})}),t[32]=c,t[33]=S);let C;t[34]===Symbol.for(`react.memo_cache_sentinel`)?(C=(0,$.jsx)(Qa,{children:`Click to view fullscreen`}),t[34]=C):C=t[34];let w;t[35]===S?w=t[36]:(w=(0,$.jsxs)(sa,{children:[S,C]}),t[35]=S,t[36]=w);let T;t[37]!==y||t[38]!==w||t[39]!==b?(T=(0,$.jsxs)(`div`,{className:b,children:[y,w]}),t[37]=y,t[38]=w,t[39]=b,t[40]=T):T=t[40];let E;t[41]!==o||t[42]!==c?(E=o&&(0,$.jsx)(vs,{svgOutput:c,onClose:()=>s(!1)}),t[41]=o,t[42]=c,t[43]=E):E=t[43];let D;return t[44]!==T||t[45]!==E?(D=(0,$.jsx)(ps,{v0:(0,$.jsxs)(Ti,{children:[T,E]})}),t[44]=T,t[45]=E,t[46]=D):D=t[46],D},hs=Pn(`app.mermaid-renderer.ui`);function gs(){let e=(0,Q.c)(2),[t,n]=(0,Z.useState)(!1),r,i;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=()=>{let e=function(){n(document.documentElement.classList.contains(`dark`))};e();let t=new MutationObserver(e);return t.observe(document.documentElement,{attributes:!0,attributeFilter:[`class`]}),()=>t.disconnect()},i=[],e[0]=r,e[1]=i):(r=e[0],i=e[1]),(0,Z.useEffect)(r,i),t}function _s(e,t){let[n,r]=(0,Z.useState)(null),[i,a]=(0,Z.useState)(!1);return(0,Z.useEffect)(()=>{let n=!1;async function i(){try{let{renderMermaidSVG:i}=await po(async()=>{let{renderMermaidSVG:e}=await import(`./dist-oojFghRi.js`);return{renderMermaidSVG:e}},__vite__mapDeps([0,1])),o=i(e,{bg:t?`#18181B`:`#FFFFFF`,fg:t?`#FAFAFA`:`#27272A`,transparent:!1,padding:32});n||(r(o),a(!1))}catch(e){hs.error(`Mermaid render error:`,e),n||a(!0)}}return i(),()=>{n=!0}},[e,t]),{svgOutput:n,renderError:i}}function vs(e){let t=(0,Q.c)(70),{svgOutput:n,onClose:r}=e,{scale:i,offset:a,isDragging:o,containerRef:s,zoomIn:c,zoomOut:l,reset:u,onMouseDown:d,onMouseMove:f,onMouseUp:p}=cs(),m,h;t[0]===r?(m=t[1],h=t[2]):(m=()=>{let e=function(e){e.key===`Escape`&&r()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},h=[r],t[0]=r,t[1]=m,t[2]=h),(0,Z.useEffect)(m,h);let g;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(g=[],t[3]=g):g=t[3],(0,Z.useEffect)(ys,g);let _;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(_=(0,$.jsx)(`span`,{className:K(J.compact,`font-mono text-muted-foreground`),children:`mermaid diagram`}),t[4]=_):_=t[4];let v,y;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,$.jsx)(jt,{className:`h-3.5 w-3.5`}),y=(0,$.jsx)(`span`,{className:`sr-only`,children:`Zoom out`}),t[5]=v,t[6]=y):(v=t[5],y=t[6]);let b;t[7]===l?b=t[8]:(b=(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsxs)(Fe,{variant:`ghost`,size:`icon-xs`,onClick:l,children:[v,y]})}),t[7]=l,t[8]=b);let x;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(x=(0,$.jsx)(Qa,{children:`Zoom out`}),t[9]=x):x=t[9];let S;t[10]===b?S=t[11]:(S=(0,$.jsxs)(sa,{children:[b,x]}),t[10]=b,t[11]=S);let C;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(C=K(J.compact,`min-w-[3rem] px-2 py-1 font-mono text-muted-foreground hover:text-foreground hover:bg-muted rounded transition-colors`),t[12]=C):C=t[12];let w;t[13]===i?w=t[14]:(w=Math.round(i*100),t[13]=i,t[14]=w);let T;t[15]!==u||t[16]!==w?(T=(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,onClick:u,className:C,children:[w,`%`]})}),t[15]=u,t[16]=w,t[17]=T):T=t[17];let E;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(E=(0,$.jsx)(Qa,{children:`Reset zoom`}),t[18]=E):E=t[18];let D;t[19]===T?D=t[20]:(D=(0,$.jsxs)(sa,{children:[T,E]}),t[19]=T,t[20]=D);let O,k;t[21]===Symbol.for(`react.memo_cache_sentinel`)?(O=(0,$.jsx)(ir,{className:`h-3.5 w-3.5`}),k=(0,$.jsx)(`span`,{className:`sr-only`,children:`Zoom in`}),t[21]=O,t[22]=k):(O=t[21],k=t[22]);let A;t[23]===c?A=t[24]:(A=(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsxs)(Fe,{variant:`ghost`,size:`icon-xs`,onClick:c,children:[O,k]})}),t[23]=c,t[24]=A);let j;t[25]===Symbol.for(`react.memo_cache_sentinel`)?(j=(0,$.jsx)(Qa,{children:`Zoom in`}),t[25]=j):j=t[25];let M;t[26]===A?M=t[27]:(M=(0,$.jsxs)(sa,{children:[A,j]}),t[26]=A,t[27]=M);let N,P;t[28]===Symbol.for(`react.memo_cache_sentinel`)?(N=(0,$.jsx)(it,{className:`h-3.5 w-3.5`}),P=(0,$.jsx)(`span`,{className:`sr-only`,children:`Reset view`}),t[28]=N,t[29]=P):(N=t[28],P=t[29]);let F;t[30]===u?F=t[31]:(F=(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsxs)(Fe,{variant:`ghost`,size:`icon-xs`,onClick:u,children:[N,P]})}),t[30]=u,t[31]=F);let I;t[32]===Symbol.for(`react.memo_cache_sentinel`)?(I=(0,$.jsx)(Qa,{children:`Reset view`}),t[32]=I):I=t[32];let L;t[33]===F?L=t[34]:(L=(0,$.jsxs)(sa,{children:[F,I]}),t[33]=F,t[34]=L);let R;t[35]===Symbol.for(`react.memo_cache_sentinel`)?(R=(0,$.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),t[35]=R):R=t[35];let z,B;t[36]===Symbol.for(`react.memo_cache_sentinel`)?(z=(0,$.jsx)(Gt,{className:`h-3.5 w-3.5`}),B=(0,$.jsx)(`span`,{className:`sr-only`,children:`Close`}),t[36]=z,t[37]=B):(z=t[36],B=t[37]);let ee;t[38]===r?ee=t[39]:(ee=(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsxs)(Fe,{variant:`ghost`,size:`icon-xs`,onClick:r,children:[z,B]})}),t[38]=r,t[39]=ee);let te;t[40]===Symbol.for(`react.memo_cache_sentinel`)?(te=(0,$.jsx)(Qa,{children:`Close (Esc)`}),t[40]=te):te=t[40];let ne;t[41]===ee?ne=t[42]:(ne=(0,$.jsxs)(sa,{children:[ee,te]}),t[41]=ee,t[42]=ne);let re;t[43]!==D||t[44]!==M||t[45]!==L||t[46]!==ne||t[47]!==S?(re=(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 bg-background/90 border-b border-border shrink-0`,children:[_,(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[S,D,M,L,R,ne]})]}),t[43]=D,t[44]=M,t[45]=L,t[46]=ne,t[47]=S,t[48]=re):re=t[48];let ie=o?`cursor-grabbing`:`cursor-grab`,ae;t[49]===ie?ae=t[50]:(ae=K(`flex-1 overflow-hidden select-none`,ie),t[49]=ie,t[50]=ae);let oe=`translate(${a.x}px, ${a.y}px) scale(${i})`,se=o?`none`:`transform 0.1s ease-out`,ce;t[51]!==oe||t[52]!==se?(ce={transform:oe,transformOrigin:`center center`,transition:se},t[51]=oe,t[52]=se,t[53]=ce):ce=t[53];let le;t[54]===n?le=t[55]:(le={__html:n},t[54]=n,t[55]=le);let ue;t[56]!==ce||t[57]!==le?(ue=(0,$.jsx)(`div`,{className:`w-full h-full flex items-center justify-center`,style:ce,dangerouslySetInnerHTML:le}),t[56]=ce,t[57]=le,t[58]=ue):ue=t[58];let de;t[59]!==s||t[60]!==d||t[61]!==f||t[62]!==p||t[63]!==ae||t[64]!==ue?(de=(0,$.jsx)(`div`,{ref:s,className:ae,onMouseDown:d,onMouseMove:f,onMouseUp:p,onMouseLeave:p,children:ue}),t[59]=s,t[60]=d,t[61]=f,t[62]=p,t[63]=ae,t[64]=ue,t[65]=de):de=t[65];let fe;t[66]===Symbol.for(`react.memo_cache_sentinel`)?(fe=(0,$.jsx)(`div`,{className:K(J.compact,`shrink-0 px-4 py-2 text-center text-muted-foreground/60 bg-background/60 border-t border-border`),children:`Scroll to zoom · Drag to pan · Esc to close`}),t[66]=fe):fe=t[66];let pe;return t[67]!==re||t[68]!==de?(pe=(0,rs.createPortal)((0,$.jsx)(Ti,{children:(0,$.jsxs)(`div`,{className:`fixed inset-0 z-50 flex flex-col bg-black/85 backdrop-blur-sm`,role:`dialog`,"aria-modal":`true`,"aria-label":`Diagram fullscreen view`,children:[re,de,fe]})}),document.body),t[67]=re,t[68]=de,t[69]=pe):pe=t[69],pe}function ys(){return document.body.style.overflow=`hidden`,bs}function bs(){document.body.style.overflow=``}function xs(e){let t=e.trim();if(t.startsWith(`/`)){let e=qn().replace(/\/$/,``);return Yn(`${e}${t}`,e)}return Yn(t,qn())}function Ss(e){let t=e.trim();if(t.startsWith(`/api/`))return!0;if(!/^https?:\/\//i.test(t))return!1;try{let e=new URL(t);if(G(e.hostname))return!0;let n=new URL(qn());return e.origin===n.origin&&e.pathname.startsWith(`/api/`)}catch{return!1}}function Cs(e){let t=e.trim();return!t||t.startsWith(`mailto:`)||t.startsWith(`tel:`)?!1:Ln()?/^https?:\/\//i.test(t)||t.startsWith(`/api/`):Ss(t)}function ws(e){let t=xs(e);return q()&&!Ln()?(window.open(t,`_blank`,`noopener,noreferrer`),Promise.resolve()):C(t)}function Ts(e){return!!(G(e.hostname)||typeof window<`u`&&e.origin===window.location.origin)}function Es(e){return decodeURIComponent(e.replace(/^\/+/,``))}function Ds(e){let t=e.trim();if(!t||t.includes(`
|
|
3
|
+
`))return null;let n=or(t);if(!n)return null;let r=t.toLowerCase();return r.startsWith(`http://`)||r.startsWith(`https://`)||r.startsWith(`/`)||r.includes(`/explorer/media`)||t.includes(`/`)||t.includes(`\\`)?{kind:n,src:t}:null}function Os(e,t){let n=e.trim();if(!n||n.startsWith(`data:`)||n.includes(`/explorer/media`))return null;let r;if(/^https?:\/\//i.test(n)){let e;try{e=new URL(n)}catch{return null}if(!Ts(e))return null;r=Es(e.pathname)}else r=Es(n);let i=or(r);return!i||t&&i!==t?null:{path:r,kind:i}}function ks(e,t){return xs(`/api/threads/${encodeURIComponent(e)}/explorer/media?path=${encodeURIComponent(t)}`)}function As(e){if(!e.startsWith(`/`))return!1;let t=e.split(`/`)[1]??``;return[`Users`,`tmp`,`var`,`private`,`Volumes`,`home`].includes(t)}function js(e,t){if(!e||e.startsWith(`data:`))return e;if(t){if(As(e)&&or(e))return ks(t,e);let n=Os(e);if(n)return ks(t,n.path)}return e.startsWith(`/`)?xs(e):Yn(e,qn())}function Ms(e,t){return js(e,t)}var Ns=Oi(e=>(0,$.jsxs)(`div`,{className:`mb-3 relative group/img inline-block max-w-full`,children:[(0,$.jsx)(`img`,{src:e.v0,alt:e.v1,className:`max-w-full rounded-lg block`,style:e.v2}),(0,$.jsx)(`div`,{className:`absolute top-2 right-2 flex gap-1 opacity-0 group-hover/img:opacity-100 transition-opacity`,children:e.v3})]}),{name:`GeneratedImageResult_1`,portals:[`v3`]}),Ps=function(e){let t=(0,Q.c)(32),{imageUrl:n,imageData:r,alt:i,threadId:a}=e,o=i===void 0?`Generated image`:i,[s,c]=(0,Z.useState)(!1),l;t[0]!==r||t[1]!==n||t[2]!==a?(l=r?`data:image/png;base64,${r}`:Ms(n??``,a),t[0]=r,t[1]=n,t[2]=a,t[3]=l):l=t[3];let u=l,d;t[4]===u?d=t[5]:(d=async()=>{let e=Sn(u)??`generated-image-${Date.now()}.png`,{path:t}=await L(u.startsWith(`data:`)?{imageData:u.replace(/^data:[^;]+;base64,/,``),filename:e}:{imageUrl:u,filename:e});Ri({title:`Saved to downloads: ${t.split(`/`).pop()}`})},t[4]=u,t[5]=d);let f=d,p;t[6]===u?p=t[7]:(p=async()=>{await zn(u.startsWith(`data:`)?{imageData:u.replace(/^data:[^;]+;base64,/,``)}:{imageUrl:u}),c(!0),setTimeout(()=>c(!1),2e3)},t[6]=u,t[7]=p);let m=p;if(!u)return null;let h;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(h={maxHeight:`512px`},t[8]=h):h=t[8];let g;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(g=(0,$.jsx)(ht,{className:`h-3.5 w-3.5`}),t[9]=g):g=t[9];let _;t[10]===f?_=t[11]:(_=(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsx)(`button`,{onClick:f,className:`flex items-center justify-center h-7 w-7 rounded-md bg-background/80 backdrop-blur-sm border border-border text-foreground hover:bg-background transition-colors`,children:g})}),t[10]=f,t[11]=_);let v;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,$.jsx)(Qa,{children:`Save image`}),t[12]=v):v=t[12];let y;t[13]===_?y=t[14]:(y=(0,$.jsxs)(sa,{children:[_,v]}),t[13]=_,t[14]=y);let b;t[15]===s?b=t[16]:(b=s?(0,$.jsx)(Xt,{className:`h-3.5 w-3.5 text-green-500`}):(0,$.jsx)(en,{className:`h-3.5 w-3.5`}),t[15]=s,t[16]=b);let x;t[17]!==m||t[18]!==b?(x=(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsx)(`button`,{onClick:m,className:`flex items-center justify-center h-7 w-7 rounded-md bg-background/80 backdrop-blur-sm border border-border text-foreground hover:bg-background transition-colors`,children:b})}),t[17]=m,t[18]=b,t[19]=x):x=t[19];let S=s?`Copied!`:`Copy to clipboard`,C;t[20]===S?C=t[21]:(C=(0,$.jsx)(Qa,{children:S}),t[20]=S,t[21]=C);let w;t[22]!==x||t[23]!==C?(w=(0,$.jsxs)(sa,{children:[x,C]}),t[22]=x,t[23]=C,t[24]=w):w=t[24];let T;t[25]!==w||t[26]!==y?(T=(0,$.jsxs)(Ti,{children:[y,w]}),t[25]=w,t[26]=y,t[27]=T):T=t[27];let E;return t[28]!==o||t[29]!==u||t[30]!==T?(E=(0,$.jsx)(Ns,{v0:u,v1:o,v2:h,v3:T}),t[28]=o,t[29]=u,t[30]=T,t[31]=E):E=t[31],E};function Fs(e){let t=fr(e);if(!t?.imageUrl&&!t?.imageData)return null;let n;if(typeof e==`object`&&e){let t=e;if(typeof t.model==`string`)n=t.model;else if(typeof t.content==`string`)try{let e=JSON.parse(t.content);typeof e.model==`string`&&(n=e.model)}catch{}}else if(typeof e==`string`)try{let t=JSON.parse(e.trim());typeof t.model==`string`&&(n=t.model)}catch{}return{imageUrl:t.imageUrl,imageData:t.imageData,model:n}}function Is(e,t){let n=Fs(e)??Fs(t);if(!n?.imageUrl&&!n?.imageData)return null;let r,i=[e,t.content,t];for(let e of i)if(typeof e==`string`&&e.trim().startsWith(`{`))try{let t=JSON.parse(e);if(typeof t.savedPath==`string`){r=t.savedPath;break}}catch{}else if(e&&typeof e==`object`){let t=e;if(typeof t.savedPath==`string`){r=t.savedPath;break}if(typeof t.content==`string`)try{let e=JSON.parse(t.content);if(typeof e.savedPath==`string`){r=e.savedPath;break}}catch{}}return{...n,savedPath:r}}var Ls=Pn(`chat.media`);function Rs(e){if(!e)return`Unknown media error`;switch(e.code){case MediaError.MEDIA_ERR_ABORTED:return`Playback aborted`;case MediaError.MEDIA_ERR_NETWORK:return`Network error while fetching media`;case MediaError.MEDIA_ERR_DECODE:return`Media decode error`;case MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED:return`Unsupported media format or inaccessible source`;default:return`Media error (code ${e.code})`}}async function zs(e){try{let t=await fetch(e,{method:`GET`,headers:{Range:`bytes=0-0`}}),n=t.headers.get(`content-type`)??`unknown`,r=t.headers.get(`accept-ranges`)??`none`,i=t.headers.get(`content-range`),a=i?`, content-range=${i}`:``;return`HTTP ${t.status} ${t.statusText}, content-type=${n}, accept-ranges=${r}${a}`}catch(e){return e instanceof Error?e.message:`Fetch failed`}}function Bs(e){Ls.error(`Failed to load media`,{kind:e.kind,src:e.src,label:e.label,mediaError:e.mediaError?{code:e.mediaError.code,message:e.mediaError.message,label:Rs(e.mediaError)}:void 0,probeResult:e.probeResult})}function Vs(e,t,n,r){let[i,a]=(0,Z.useState)({objectUrl:null,loadError:null,loading:!1});return(0,Z.useEffect)(()=>{if(!t){a(e=>(e.objectUrl&&URL.revokeObjectURL(e.objectUrl),{objectUrl:null,loadError:null,loading:!1}));return}let i=!1;a(e=>(e.objectUrl&&URL.revokeObjectURL(e.objectUrl),{objectUrl:null,loadError:null,loading:!0}));async function o(){try{let t=await fetch(e);if(!t.ok){let t=await zs(e);throw Error(t)}let n=await t.blob();if(i)return;let r=URL.createObjectURL(n);if(i){URL.revokeObjectURL(r);return}a({objectUrl:r,loadError:null,loading:!1})}catch(t){if(i)return;let o=t instanceof Error?t.message:await zs(e);Bs({kind:n,src:e,label:r,probeResult:o}),a({objectUrl:null,loadError:o,loading:!1})}}return o(),()=>{i=!0,a(e=>(e.objectUrl&&URL.revokeObjectURL(e.objectUrl),{objectUrl:null,loadError:null,loading:!1}))}},[e,t,n,r]),i}function Hs(e){let t=(0,Q.c)(44),{src:n,label:r}=e,[i,a]=(0,Z.useState)(!1),[o,s]=(0,Z.useState)(!1),c=(0,Z.useRef)(null),{objectUrl:l,loadError:u,loading:d}=Vs(n,i,`video`,r),f;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(f=function(e){a(e),e||(s(!1),c.current&&c.current.pause())},t[0]=f):f=t[0];let p=f,m;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(m=function(){s(Us)},t[1]=m):m=t[1];let h=m,g;t[2]!==r||t[3]!==n?(g=async function(e){let t=e.currentTarget.error;Bs({kind:`video`,src:n,label:r,mediaError:t,probeResult:await zs(n)})},t[2]=r,t[3]=n,t[4]=g):g=t[4];let _=g,v=r??`Video`,y;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(y=()=>a(!0),t[5]=y):y=t[5];let b=r?`Play ${r}`:`Play video`,x;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(x=(0,$.jsx)(`span`,{className:`flex h-14 w-14 items-center justify-center rounded-full bg-background/90 text-foreground shadow-sm`,children:(0,$.jsx)(ae,{className:`h-7 w-7 fill-current`})}),t[6]=x):x=t[6];let S;t[7]===b?S=t[8]:(S=(0,$.jsx)(`button`,{type:`button`,onClick:y,"aria-label":b,className:`flex min-h-32 w-full items-center justify-center rounded-md bg-muted/30 transition-colors hover:bg-muted/50`,children:x}),t[7]=b,t[8]=S);let C=o?`h-dvh w-dvw max-w-none rounded-none`:`max-w-[min(92vw,960px)]`,w;t[9]===C?w=t[10]:(w=K(`gap-0 overflow-hidden border-none bg-black p-0 sm:rounded-lg`,C),t[9]=C,t[10]=w);let T;t[11]===v?T=t[12]:(T=(0,$.jsx)(un,{className:`sr-only`,children:v}),t[11]=v,t[12]=T);let E;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(E=(0,$.jsx)(Qn,{className:`sr-only`,children:`Video player`}),t[13]=E):E=t[13];let D=o?`Shrink video`:`Expand video`,O;t[14]===o?O=t[15]:(O=o?(0,$.jsx)(Xn,{className:`h-4 w-4`}):(0,$.jsx)(Er,{className:`h-4 w-4`}),t[14]=o,t[15]=O);let k;t[16]!==D||t[17]!==O?(k=(0,$.jsx)(`button`,{type:`button`,onClick:h,"aria-label":D,className:`flex h-7 w-7 items-center justify-center rounded-full text-white/90 transition-colors hover:bg-white/15 hover:text-white`,children:O}),t[16]=D,t[17]=O,t[18]=k):k=t[18];let A;t[19]===Symbol.for(`react.memo_cache_sentinel`)?(A=(0,$.jsxs)(Wt,{className:`flex h-7 w-7 items-center justify-center rounded-full text-white/90 transition-colors hover:bg-white/15 hover:text-white`,children:[(0,$.jsx)(Gt,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Close`})]}),t[19]=A):A=t[19];let j;t[20]===k?j=t[21]:(j=(0,$.jsxs)(`div`,{className:`absolute right-4 top-4 z-10 flex items-center gap-1`,children:[k,A]}),t[20]=k,t[21]=j);let M=o?`h-full`:`min-h-[240px]`,N;t[22]===M?N=t[23]:(N=K(`flex items-center justify-center p-3 pt-12 sm:p-4`,M),t[22]=M,t[23]=N);let P;t[24]!==o||t[25]!==_||t[26]!==u||t[27]!==d||t[28]!==l?(P=d?(0,$.jsx)(`p`,{className:K(J.compact,`text-white/80`),children:`Loading video...`}):u?(0,$.jsxs)(`p`,{className:K(J.compact,`px-4 text-center text-destructive`),children:[`Could not load video: `,u]}):l?(0,$.jsx)(`video`,{ref:c,src:l,controls:!0,autoPlay:!0,playsInline:!0,className:K(`max-w-full rounded`,o?`max-h-full`:`max-h-[80vh]`),onError:_}):null,t[24]=o,t[25]=_,t[26]=u,t[27]=d,t[28]=l,t[29]=P):P=t[29];let F;t[30]!==N||t[31]!==P?(F=(0,$.jsx)(`div`,{className:N,children:P}),t[30]=N,t[31]=P,t[32]=F):F=t[32];let I;t[33]!==T||t[34]!==j||t[35]!==F||t[36]!==w?(I=(0,$.jsxs)(tn,{hideClose:!0,className:w,children:[T,E,j,F]}),t[33]=T,t[34]=j,t[35]=F,t[36]=w,t[37]=I):I=t[37];let L;t[38]!==i||t[39]!==I?(L=(0,$.jsx)(Cr,{open:i,onOpenChange:p,children:I}),t[38]=i,t[39]=I,t[40]=L):L=t[40];let R;return t[41]!==L||t[42]!==S?(R=(0,$.jsxs)($.Fragment,{children:[S,L]}),t[41]=L,t[42]=S,t[43]=R):R=t[43],R}function Us(e){return!e}function Ws(e){let t=(0,Q.c)(12),{src:n,label:r}=e,{objectUrl:i,loadError:a,loading:o}=Vs(n,!0,`audio`,r),s;t[0]!==r||t[1]!==n?(s=async function(e){let t=e.currentTarget.error;Bs({kind:`audio`,src:n,label:r,mediaError:t,probeResult:await zs(n)})},t[0]=r,t[1]=n,t[2]=s):s=t[2];let c=s,l;t[3]!==c||t[4]!==o||t[5]!==i?(l=o?(0,$.jsx)(`p`,{className:K(J.compact,`text-muted-foreground`),children:`Loading audio...`}):i?(0,$.jsx)(`audio`,{src:i,controls:!0,preload:`metadata`,className:`w-full`,onError:c}):null,t[3]=c,t[4]=o,t[5]=i,t[6]=l):l=t[6];let u;t[7]===a?u=t[8]:(u=a?(0,$.jsxs)(`p`,{className:K(J.compact,`mt-2 text-destructive`),children:[`Could not load audio: `,a]}):null,t[7]=a,t[8]=u);let d;return t[9]!==l||t[10]!==u?(d=(0,$.jsxs)($.Fragment,{children:[l,u]}),t[9]=l,t[10]=u,t[11]=d):d=t[11],d}function Gs(e){let t=(0,Q.c)(13),{src:n,kind:r,label:i}=e;if(!n)return null;let a=r===`video`?ne:h,o=r===`video`?`p-2`:`p-3`,s;t[0]===o?s=t[1]:(s=K(`mt-2 max-w-full overflow-hidden rounded-lg border border-border bg-background`,o),t[0]=o,t[1]=s);let c;t[2]!==a||t[3]!==i?(c=i?(0,$.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 text-muted-foreground`,children:[(0,$.jsx)(a,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:K(J.compact,`truncate`),children:i})]}):null,t[2]=a,t[3]=i,t[4]=c):c=t[4];let l;t[5]!==r||t[6]!==i||t[7]!==n?(l=r===`video`?(0,$.jsx)(Hs,{src:n,label:i}):(0,$.jsx)(Ws,{src:n,label:i}),t[5]=r,t[6]=i,t[7]=n,t[8]=l):l=t[8];let u;return t[9]!==s||t[10]!==c||t[11]!==l?(u=(0,$.jsxs)(`div`,{className:s,children:[c,l]}),t[9]=s,t[10]=c,t[11]=l,t[12]=u):u=t[12],u}var Ks=`graph.flowchart.sequenceDiagram.classDiagram.stateDiagram.erDiagram.journey.gantt.pie.quadrantChart.requirementDiagram.gitgraph.mindmap.timeline.zenuml.sankey.block.architecture.c4.packet.circuit.flowchart LR.flowchart TD.flowchart BT.flowchart RL.graph LR.graph TD.graph BT.graph RL`.split(`.`),qs=[/-->/,/--\./,/-\./,/==>/,/--\|/,/\w+\[\w+\]/,/\w+\(\w+\)/,/\w+\{\w+\}/,/\w+>\w+\]/,/\w+\(\w+\)/,/\w+\[\(\w+\)\]/,/participant\s+\w+/,/actor\s+\w+/,/Note over \w+/,/loop\s+/,/alt\s+/,/opt\s+/,/class\s+\w+/,/interface\s+\w+/,/enum\s+\w+/,/\[\*\]/,/\[\*\]/,/title\s+/,/direction\s+/,/subgraph\s+/];function Js(e){if(!e||typeof e!=`string`)return!1;let t=e.split(`
|
|
4
|
+
`).map(e=>e.trim()).filter(e=>e.length>0);if(t.length===0)return!1;if(/```mermaid\s*\n([\s\S]*?)\n```/.test(e))return!0;let n=t[0].toLowerCase();if(Ks.some(e=>n===e.toLowerCase()||n.startsWith(e.toLowerCase()+` `)))return!0;let r=0;for(let t of qs)t.test(e)&&r++;return r>=2}function Ys(e){if(!Js(e))return null;let t=/```mermaid\s*\n([\s\S]*?)\n```/.exec(e);if(t)return t[1].trim();let n=e.split(`
|
|
5
|
+
`).map(e=>e.trim()).filter(e=>e.length>0)[0].toLowerCase();return Ks.some(e=>n===e.toLowerCase()||n.startsWith(e.toLowerCase()+` `))?e.trim():null}function Xs(e){let t=(0,Q.c)(14),{href:n,children:r}=e,i;t[0]===n?i=t[1]:(i=xs(n),t[0]=n,t[1]=i);let a=i,o;t[2]===n?o=t[3]:(o=Cs(n),t[2]=n,t[3]=o);let s=o,c;t[4]!==n||t[5]!==s?(c=function(e){s&&(e.preventDefault(),ws(n))},t[4]=n,t[5]=s,t[6]=c):c=t[6];let l=c,u;t[7]===s?u=t[8]:(u=s?{}:{target:`_blank`,rel:`noopener noreferrer`},t[7]=s,t[8]=u);let d;return t[9]!==r||t[10]!==l||t[11]!==a||t[12]!==u?(d=(0,$.jsx)(`a`,{href:a,onClick:l,className:`text-primary underline underline-offset-2 hover:text-primary/80`,...u,children:r}),t[9]=r,t[10]=l,t[11]=a,t[12]=u,t[13]=d):d=t[13],d}var Zs=Oi(e=>(0,$.jsxs)(`div`,{className:`group relative overflow-hidden rounded-lg border border-border bg-muted`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between border-b border-border bg-muted/80 px-4 py-2`,children:[(0,$.jsx)(`span`,{className:e.v0,children:e.v1}),e.v2]}),(0,$.jsx)(`pre`,{className:e.v3,children:(0,$.jsx)(`code`,{className:e.v4,children:e.v5})})]}),{name:`CodeBlock_1`,portals:[`v1`,`v2`,`v5`]}),Qs=function(e){let t=(0,Q.c)(19),{language:n,code:r,compact:i}=e,a=i===void 0?!1:i,[o,s]=(0,Z.useState)(!1),c;t[0]===r?c=t[1]:(c=async function(){await navigator.clipboard.writeText(r),s(!0),setTimeout(()=>s(!1),2e3)},t[0]=r,t[1]=c);let l=c,u;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(u=K(J.compact,`text-muted-foreground font-mono`),t[2]=u):u=t[2];let d=n||`text`,f;t[3]===o?f=t[4]:(f=o?(0,$.jsx)(Xt,{}):(0,$.jsx)(en,{}),t[3]=o,t[4]=f);let p;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,$.jsx)(`span`,{className:`sr-only`,children:`Copy code`}),t[5]=p):p=t[5];let m;t[6]!==l||t[7]!==f?(m=(0,$.jsxs)(Fe,{variant:`action`,size:`icon-xs`,onClick:l,children:[f,p]}),t[6]=l,t[7]=f,t[8]=m):m=t[8];let h=a?`p-2`:`p-4`,g;t[9]===h?g=t[10]:(g=K(`overflow-x-auto max-w-full`,h),t[9]=h,t[10]=g);let _;t[11]===a?_=t[12]:(_=K(a?K(J.compact,`font-mono`):J.mono,`text-foreground leading-relaxed`),t[11]=a,t[12]=_);let v;return t[13]!==r||t[14]!==_||t[15]!==d||t[16]!==m||t[17]!==g?(v=(0,$.jsx)(Zs,{v0:u,v1:d,v2:m,v3:g,v4:_,v5:r}),t[13]=r,t[14]=_,t[15]=d,t[16]=m,t[17]=g,t[18]=v):v=t[18],v},$s=/^(\s*)([-*+]|\d+\.)\s+(.*)$/,ec=/^!\[([^\]]*)\]\(([^)]+)\)\s*$/,tc=(0,Z.memo)(function(e){let t=(0,Q.c)(13),{content:n,className:r,enableMermaid:i,threadId:a,compact:o}=e,s=i===void 0?!1:i,c=o===void 0?!1:o,l;bb0:{if(!n||typeof n!=`string`){let e;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(e=[],t[0]=e):e=t[0],l=e;break bb0}let e;t[1]!==n||t[2]!==s?(e=lc(n,s),t[1]=n,t[2]=s,t[3]=e):e=t[3],l=e}let u=l;if(u.length===0)return null;let d;t[4]===r?d=t[5]:(d=K(`prose-custom min-w-0 break-words`,r),t[4]=r,t[5]=d);let f;t[6]!==u||t[7]!==c||t[8]!==a?(f=u.map((e,t)=>(0,$.jsx)(`div`,{className:cc(t,u,c),children:(0,$.jsx)(fc,{block:e,threadId:a,compact:c})},t)),t[6]=u,t[7]=c,t[8]=a,t[9]=f):f=t[9];let p;return t[10]!==d||t[11]!==f?(p=(0,$.jsx)(`div`,{className:d,children:f}),t[10]=d,t[11]=f,t[12]=p):p=t[12],p});function nc(e){let t=e.match(ec);return t?{alt:t[1],src:t[2]}:null}function rc(e,t,n){let r=e?`mt-0 space-y-0.5`:`mt-0 space-y-1`,i=n?`mt-1`:``;return t?K(r,i,`pl-6`):K(r,i,`pl-6 list-outside overflow-visible list-disc`)}function ic(e){return e.replace(/\t/g,` `).length}function ac(e){return/^\d+\.$/.test(e)?Number.parseInt(e,10):1}function oc(e,t){return ic(e)>t}function sc(e,t){let n=e[t]?.match($s);if(!n)return{block:{type:`paragraph`,text:``},nextIndex:t+1};let[,r,i,a]=n,o={ordered:/^\d+\.$/.test(i),start:ac(i),items:[{text:a,children:[]}]},s=[{indent:ic(r),item:o.items[0]}],c=t+1;for(;c<e.length;){let t=e[c],n=t.match($s);if(n){let[,e,t,r]=n,i=ic(e),a=/^\d+\.$/.test(t),l={text:r,children:[]};for(;s.length>0&&i<s[s.length-1].indent;)s.pop();if(s.length===0)break;let u=s[s.length-1],d=i===u.indent,f=oc(e,u.indent);if(d){let e=s[s.length-2]?.childList??o;if(e.ordered!==a)break;e.items.push(l),s[s.length-1]={indent:i,item:l},c++;continue}if(!f)break;let p=u.childList;(!p||p.ordered!==a)&&(p={ordered:a,start:ac(t),items:[]},u.item.children.push(p),u.childList=p),p.items.push(l),s.push({indent:i,item:l}),c++;continue}if(t.trim()===``){let t=e[c+1];if(!t||!$s.test(t))break;c++;continue}let r=ic(t.match(/^(\s*)/)?.[1]??``),i=s[s.length-1];if(r>i.indent){i.item.text=`${i.item.text}\n${t.trim()}`,c++;continue}break}return{block:{type:`list`,list:o},nextIndex:c}}function cc(e,t,n=!1){if(e===0)return``;let r=t[e-1],i=t[e];return r.type===`list`||i.type===`list`?``:n?`mt-2`:`mt-3`}function lc(e,t=!1){let n=e.split(`
|
|
6
|
+
`),r=[],i=0;for(;i<n.length;){let e=n[i];if(e.trimStart().startsWith("```")){let a=e.trimStart().slice(3).trim(),o=[];for(i++;i<n.length&&!n[i].trimStart().startsWith("```");)o.push(n[i]),i++;t&&(a===`mermaid`||Js(o.join(`
|
|
7
|
+
`)))?r.push({type:`mermaid`,code:o.join(`
|
|
8
|
+
`)}):r.push({type:`code`,language:a,code:o.join(`
|
|
9
|
+
`)}),i++;continue}let a=e.match(/^(#{1,6})(\s.*)?$/);if(a){r.push({type:`heading`,level:a[1].length,text:a[2]?a[2].trim():``}),i++;continue}if(/^(---|\*\*\*|___)/.test(e.trim())){r.push({type:`hr`}),i++;continue}if(e.includes(`|`)&&i+1<n.length&&n[i+1].match(/^\|?\s*[-:]+/)){let t=e.split(`|`).map(e=>e.trim()).filter(Boolean);i+=2;let a=[];for(;i<n.length&&n[i].includes(`|`);)a.push(n[i].split(`|`).map(e=>e.trim()).filter(Boolean)),i++;r.push({type:`table`,headers:t,rows:a});continue}if(e.startsWith(`> `)){let e=[];for(;i<n.length&&n[i].startsWith(`> `);)e.push(n[i].slice(2)),i++;r.push({type:`blockquote`,text:e.join(`
|
|
10
|
+
`)});continue}if($s.test(e)){let{block:e,nextIndex:t}=sc(n,i);r.push(e),i=t;continue}if(e.trim()===``){i++;continue}let o=nc(e);if(o){r.push({type:`image`,...o}),i++;continue}let s=Ds(e);if(s){r.push({type:`media`,kind:s.kind,src:s.src}),i++;continue}let c=[];for(;i<n.length&&n[i].trim()!==``&&!n[i].startsWith(`#`)&&!n[i].startsWith("```")&&!n[i].startsWith(`> `)&&!$s.test(n[i]);)c.push(n[i]),i++;if(c.length>0){let e=c.join(`
|
|
11
|
+
`);if(t&&Js(e)){let t=Ys(e);t?r.push({type:`mermaid`,code:t}):r.push({type:`paragraph`,text:e})}else r.push({type:`paragraph`,text:e})}}return r}function uc(e,t){return`${t}-${e.text}`}function dc(e){let t=(0,Q.c)(19),{list:n,compact:r,threadId:i,inlineCodeClass:a,nested:o}=e,s=o===void 0?!1:o,c=r?J.caption:J.body,l=n.ordered?`ol`:`ul`,u;t[0]!==c||t[1]!==r||t[2]!==n.ordered||t[3]!==s?(u=K(c,rc(r,n.ordered,s)),t[0]=c,t[1]=r,t[2]=n.ordered,t[3]=s,t[4]=u):u=t[4];let d=n.ordered?n.start:void 0,f;if(t[5]!==r||t[6]!==a||t[7]!==n.items||t[8]!==i){let e;t[10]!==r||t[11]!==a||t[12]!==i?(e=(e,t)=>(0,$.jsx)(`li`,{children:(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(pc,{text:e.text,threadId:i,inlineCodeClass:a}),e.children.map((n,o)=>(0,$.jsx)(dc,{list:n,compact:r,threadId:i,inlineCodeClass:a,nested:!0},`${uc(e,t)}-child-${o}`))]})},uc(e,t)),t[10]=r,t[11]=a,t[12]=i,t[13]=e):e=t[13],f=n.items.map(e),t[5]=r,t[6]=a,t[7]=n.items,t[8]=i,t[9]=f}else f=t[9];let p;return t[14]!==l||t[15]!==u||t[16]!==d||t[17]!==f?(p=(0,$.jsx)(l,{className:u,start:d,children:f}),t[14]=l,t[15]=u,t[16]=d,t[17]=f,t[18]=p):p=t[18],p}var fc=(0,Z.memo)(function(e){let t=(0,Q.c)(86),{block:n,threadId:r,compact:i}=e,a=i===void 0?!1:i,o=a?J.caption:J.body,s;t[0]===a?s=t[1]:(s=a?K(J.compact,`font-mono`):J.mono,t[0]=a,t[1]=s);let c=s;switch(n.type){case`heading`:{let e=`h${n.level}`,i,o;if(t[2]!==e||t[3]!==n.level||t[4]!==a){let r=a?{1:K(J.caption,`font-semibold`),2:K(J.caption,`font-semibold`),3:K(J.body,`font-semibold`),4:K(J.body,`font-semibold`),5:K(J.compact,`font-semibold`),6:K(J.compact,`font-semibold`)}:{1:J.sectionTitle,2:J.subSectionTitle,3:J.subSectionTitle,4:J.subSectionTitle,5:J.sectionSubtitle,6:J.sectionSubtitle};i=e,o=K(r[n.level]),t[2]=e,t[3]=n.level,t[4]=a,t[5]=i,t[6]=o}else i=t[5],o=t[6];let s;t[7]!==n.text||t[8]!==c||t[9]!==r?(s=(0,$.jsx)(pc,{text:n.text,threadId:r,inlineCodeClass:c}),t[7]=n.text,t[8]=c,t[9]=r,t[10]=s):s=t[10];let l;return t[11]!==i||t[12]!==o||t[13]!==s?(l=(0,$.jsx)(i,{className:o,children:s}),t[11]=i,t[12]=o,t[13]=s,t[14]=l):l=t[14],l}case`code`:{let e;return t[15]!==n.code||t[16]!==n.language||t[17]!==a?(e=(0,$.jsx)(Qs,{language:n.language,code:n.code,compact:a}),t[15]=n.code,t[16]=n.language,t[17]=a,t[18]=e):e=t[18],e}case`blockquote`:{let e;t[19]===o?e=t[20]:(e=K(o,`border-l-2 border-border pl-4 text-muted-foreground italic`),t[19]=o,t[20]=e);let i;t[21]!==n.text||t[22]!==c||t[23]!==r?(i=(0,$.jsx)(pc,{text:n.text,threadId:r,inlineCodeClass:c}),t[21]=n.text,t[22]=c,t[23]=r,t[24]=i):i=t[24];let a;return t[25]!==e||t[26]!==i?(a=(0,$.jsx)(`blockquote`,{className:e,children:i}),t[25]=e,t[26]=i,t[27]=a):a=t[27],a}case`list`:{let e;return t[28]!==n.list||t[29]!==a||t[30]!==c||t[31]!==r?(e=(0,$.jsx)(dc,{list:n.list,compact:a,threadId:r,inlineCodeClass:c}),t[28]=n.list,t[29]=a,t[30]=c,t[31]=r,t[32]=e):e=t[32],e}case`paragraph`:{let e;t[33]===o?e=t[34]:(e=K(o,`mt-0 leading-relaxed whitespace-pre-wrap break-words`),t[33]=o,t[34]=e);let i;t[35]!==n.text||t[36]!==c||t[37]!==r?(i=(0,$.jsx)(pc,{text:n.text,threadId:r,inlineCodeClass:c}),t[35]=n.text,t[36]=c,t[37]=r,t[38]=i):i=t[38];let a;return t[39]!==e||t[40]!==i?(a=(0,$.jsx)(`p`,{className:e,children:i}),t[39]=e,t[40]=i,t[41]=a):a=t[41],a}case`hr`:{let e;return t[42]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(`hr`,{className:`border-border`}),t[42]=e):e=t[42],e}case`table`:{let e;t[43]===o?e=t[44]:(e=K(o,`w-full`),t[43]=o,t[44]=e);let i;if(t[45]!==n.headers||t[46]!==c||t[47]!==r){let e;t[49]!==c||t[50]!==r?(e=(e,t)=>(0,$.jsx)(`th`,{className:`px-3 py-2 text-left font-medium`,children:(0,$.jsx)(pc,{text:e,threadId:r,inlineCodeClass:c})},t),t[49]=c,t[50]=r,t[51]=e):e=t[51],i=n.headers.map(e),t[45]=n.headers,t[46]=c,t[47]=r,t[48]=i}else i=t[48];let a;t[52]===i?a=t[53]:(a=(0,$.jsx)(`thead`,{children:(0,$.jsx)(`tr`,{className:`border-b border-table-border`,children:i})}),t[52]=i,t[53]=a);let s;if(t[54]!==n.rows||t[55]!==c||t[56]!==r){let e;t[58]!==c||t[59]!==r?(e=(e,t)=>(0,$.jsx)(`tr`,{children:e.map((e,t)=>(0,$.jsx)(`td`,{className:`px-3 py-2`,children:(0,$.jsx)(pc,{text:e,threadId:r,inlineCodeClass:c})},t))},t),t[58]=c,t[59]=r,t[60]=e):e=t[60],s=n.rows.map(e),t[54]=n.rows,t[55]=c,t[56]=r,t[57]=s}else s=t[57];let l;t[61]===s?l=t[62]:(l=(0,$.jsx)(`tbody`,{children:s}),t[61]=s,t[62]=l);let u;return t[63]!==e||t[64]!==a||t[65]!==l?(u=(0,$.jsx)(`div`,{className:`overflow-x-auto rounded-md border border-table-border max-w-full`,children:(0,$.jsxs)(`table`,{className:e,children:[a,l]})}),t[63]=e,t[64]=a,t[65]=l,t[66]=u):u=t[66],u}case`mermaid`:{let e;return t[67]===n.code?e=t[68]:(e=(0,$.jsx)(ms,{content:n.code}),t[67]=n.code,t[68]=e),e}case`image`:{let e;t[69]!==n.src||t[70]!==r?(e=Ms(n.src,r),t[69]=n.src,t[70]=r,t[71]=e):e=t[71];let i=n.alt||`Image`,a;return t[72]!==e||t[73]!==i?(a=(0,$.jsx)(Ps,{imageUrl:e,alt:i}),t[72]=e,t[73]=i,t[74]=a):a=t[74],a}case`media`:{let e;t[75]!==n.src||t[76]!==r?(e=js(n.src,r),t[75]=n.src,t[76]=r,t[77]=e):e=t[77];let i=e;if(n.kind===`image`){let e;return t[78]===i?e=t[79]:(e=(0,$.jsx)(Ps,{imageUrl:i,alt:`Image`}),t[78]=i,t[79]=e),e}let a;t[80]===n.src?a=t[81]:(a=n.src.split(/[/\\]/).pop(),t[80]=n.src,t[81]=a);let o=a,s;return t[82]!==n.kind||t[83]!==o||t[84]!==i?(s=(0,$.jsx)(Gs,{src:i,kind:n.kind,label:o}),t[82]=n.kind,t[83]=o,t[84]=i,t[85]=s):s=t[85],s}default:return null}}),pc=(0,Z.memo)(function(e){let t=(0,Q.c)(11),{text:n,threadId:r,inlineCodeClass:i}=e,a=i===void 0?J.mono:i,o;t[0]===n?o=t[1]:(o=mc(n),t[0]=n,t[1]=o);let s=o,c;if(t[2]!==a||t[3]!==s||t[4]!==r){let e;t[6]!==a||t[7]!==r?(e=(e,t)=>{switch(e.type){case`bold`:return(0,$.jsx)(`strong`,{className:`font-semibold`,children:e.text},t);case`italic`:return(0,$.jsx)(`em`,{children:e.text},t);case`strikethrough`:return(0,$.jsx)(`del`,{className:`text-muted-foreground`,children:e.text},t);case`code`:return(0,$.jsx)(`code`,{className:K(a,`rounded bg-muted/20 py-0.5`),children:e.text},t);case`link`:return(0,$.jsx)(Xs,{href:e.href,children:e.text},t);case`image`:return(0,$.jsx)(Ps,{imageUrl:Ms(e.src,r),alt:e.alt||`Image`},t);default:return(0,$.jsx)(`span`,{children:e.text},t)}},t[6]=a,t[7]=r,t[8]=e):e=t[8],c=s.map(e),t[2]=a,t[3]=s,t[4]=r,t[5]=c}else c=t[5];let l;return t[9]===c?l=t[10]:(l=(0,$.jsx)($.Fragment,{children:c}),t[9]=c,t[10]=l),l});function mc(e){let t=[],n=/(`[^`]+`)|(!\[[^\]]*\]\([^)]+\))|(\*\*[^*]+\*\*)|(\*[^*]+\*)|(__[^_]+__)|(_[^_]+_)|(~~[^~]+~~)|(\[[^\]]+\]\([^)]+\))/g,r=0,i;for(;(i=n.exec(e))!==null;){i.index>r&&t.push({type:`text`,text:e.slice(r,i.index)});let n=i[0];if(n.startsWith("`"))t.push({type:`code`,text:n.slice(1,-1)});else if(n.startsWith(`![`)){let e=n.match(/!\[([^\]]*)\]\(([^)]+)\)/);e&&t.push({type:`image`,alt:e[1],src:e[2]})}else if(n.startsWith(`**`)||n.startsWith(`__`))t.push({type:`bold`,text:n.slice(2,-2)});else if(n.startsWith(`~~`))t.push({type:`strikethrough`,text:n.slice(2,-2)});else if(n.startsWith(`*`)||n.startsWith(`_`))t.push({type:`italic`,text:n.slice(1,-1)});else if(n.startsWith(`[`)){let e=n.match(/\[([^\]]+)\]\(([^)]+)\)/);e&&t.push({type:`link`,text:e[1],href:e[2]})}r=i.index+n.length}return r<e.length&&t.push({type:`text`,text:e.slice(r)}),t.length>0?t:[{type:`text`,text:e}]}function hc(e){return e.split(/[/\\]/).pop()||void 0}var gc=(0,Z.memo)(function(e){let t=(0,Q.c)(20),{content:n,threadId:r,className:i,enableMermaid:a}=e,o=a===void 0?!0:a,s;t[0]===n?s=t[1]:(s=Ds(n),t[0]=n,t[1]=s);let c=s;if(c){let e;t[2]!==c.src||t[3]!==r?(e=js(c.src,r),t[2]=c.src,t[3]=r,t[4]=e):e=t[4];let n=e;if(c.kind===`image`){let e;return t[5]===n?e=t[6]:(e=(0,$.jsx)(Ps,{imageUrl:n,alt:`Image`}),t[5]=n,t[6]=e),e}let i=c.kind,a;t[7]===c.src?a=t[8]:(a=hc(c.src),t[7]=c.src,t[8]=a);let o;return t[9]!==c.kind||t[10]!==n||t[11]!==a?(o=(0,$.jsx)(Gs,{src:n,kind:i,label:a}),t[9]=c.kind,t[10]=n,t[11]=a,t[12]=o):o=t[12],o}let l;t[13]===n?l=t[14]:(l=Ia(n),t[13]=n,t[14]=l);let u=i??J.body,d;return t[15]!==o||t[16]!==l||t[17]!==u||t[18]!==r?(d=(0,$.jsx)(tc,{content:l,enableMermaid:o,className:u,threadId:r}),t[15]=o,t[16]=l,t[17]=u,t[18]=r,t[19]=d):d=t[19],d});function _c(e){return`data:${e.mimeType};base64,${e.content}`}function vc(e){return e.mimeType.startsWith(`image/`)?`image`:e.mimeType.startsWith(`video/`)?`video`:e.mimeType.startsWith(`audio/`)?`audio`:or(e.fileName)||`file`}function yc(e){let t=(0,Q.c)(6),{icon:n,label:r}=e,i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=K(J.compact,`flex items-center gap-1 rounded-md bg-muted px-2 py-1 text-muted-foreground`),t[0]=i):i=t[0];let a;t[1]===r?a=t[2]:(a=(0,$.jsx)(`span`,{className:`truncate`,children:r}),t[1]=r,t[2]=a);let o;return t[3]!==n||t[4]!==a?(o=(0,$.jsxs)(`div`,{className:i,children:[n,a]}),t[3]=n,t[4]=a,t[5]=o):o=t[5],o}function bc(e){let t=(0,Q.c)(14),{attachment:n}=e,r=vc(n),i;t[0]===n?i=t[1]:(i=_c(n),t[0]=n,t[1]=i);let a=i;if(r===`image`){let e;return t[2]!==n.fileName||t[3]!==a?(e=(0,$.jsx)(`div`,{className:`mt-1 max-w-full overflow-hidden rounded-lg border border-border bg-background`,children:(0,$.jsx)(`img`,{src:a,alt:n.fileName,className:`block max-h-80 max-w-full object-contain`})}),t[2]=n.fileName,t[3]=a,t[4]=e):e=t[4],e}if(r===`video`){let e;return t[5]!==n.fileName||t[6]!==a?(e=(0,$.jsx)(Gs,{src:a,kind:`video`,label:n.fileName}),t[5]=n.fileName,t[6]=a,t[7]=e):e=t[7],e}if(r===`audio`){let e;return t[8]!==n.fileName||t[9]!==a?(e=(0,$.jsx)(Gs,{src:a,kind:`audio`,label:n.fileName}),t[8]=n.fileName,t[9]=a,t[10]=e):e=t[10],e}let o;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,$.jsx)(Pe,{className:`h-2.5 w-2.5`}),t[11]=o):o=t[11];let s;return t[12]===n.fileName?s=t[13]:(s=(0,$.jsx)(yc,{icon:o,label:n.fileName}),t[12]=n.fileName,t[13]=s),s}function xc(e){let t=(0,Q.c)(4),{attachments:n}=e,r;t[0]===n?r=t[1]:(r=n.map(Sc),t[0]=n,t[1]=r);let i;return t[2]===r?i=t[3]:(i=(0,$.jsx)(`div`,{className:`mt-1 space-y-2`,children:r}),t[2]=r,t[3]=i),i}function Sc(e){let t=vc(e),n=`${e.fileName}:${e.mimeType}`;return t===`file`?(0,$.jsx)(bc,{attachment:e},n):(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsx)(yc,{icon:t===`audio`?(0,$.jsx)(h,{className:`h-2.5 w-2.5`}):t===`video`?(0,$.jsx)(ne,{className:`h-2.5 w-2.5`}):(0,$.jsx)(Pe,{className:`h-2.5 w-2.5`}),label:e.fileName}),(0,$.jsx)(bc,{attachment:e})]},n)}var Cc=Pn(`gitops.timing`);function wc(e){let t=[],n=performance.now();async function r(n,r){let i=performance.now();try{return await r()}finally{let r=Math.round(performance.now()-i);t.push({step:n,duration:r}),Cc.debug(`${e} step`,{step:n,duration:r})}}function i(n,r,i){t.push({step:n,duration:r}),Cc.debug(`${e} step`,{step:n,duration:r,...i?{detail:i}:{}})}function a(r){let i=Math.round(performance.now()-n),a=t.reduce((e,t)=>t.duration>=e.duration?t:e,{step:`none`,duration:0}),o=t.map(e=>`${e.step}:${e.duration}`).join(` `);Cc.debug(`${e} summary`,{duration:i,slowestStep:a.step,slowestDuration:a.duration,breakdown:o,...r?{detail:r}:{}})}return{step:r,record:i,summary:a}}var Tc=Pn(`gitops.unified-status`),Ec=3e4,Dc={hasChanges:!1,changedFilesCount:0,hasUnpushedCommits:!1,currentBranch:``,hasRemoteBranch:!1,isOnGitHub:!1,remoteUrl:``,canCreateRepo:!1,repoUrl:void 0,status:`Up to date`,defaultBranch:null,prExists:!1,prUrl:void 0,prState:void 0,commitsAheadOfDefault:!1,defaultBranchAhead:0,defaultBranchBehind:0},Oc=new Map,kc=new Map;function Ac(e,t){let n=Oc.get(e);if(n)for(let e of n)e(t)}function jc(e,t){let n=Oc.get(e);return n||(n=new Set,Oc.set(e,n)),n.add(t),()=>{n.delete(t),n.size===0&&Oc.delete(e)}}function Mc(e){return`unified-git-status-${e}`}function Nc(e){return Le.getSync(Mc(e))}function Pc(e){let[t,n]=(0,Z.useState)(Dc),[r,i]=(0,Z.useState)(!1),a=(0,Z.useRef)(void 0),o=(0,Z.useRef)(0),s=(0,Z.useCallback)(e=>{(0,Z.startTransition)(()=>{n(e)})},[]),c=(0,Z.useRef)(s);c.current=s;let l=(0,Z.useCallback)(async(t=!1)=>{if(!e)return;let n=++o.current,r=wc(`hook fetch thread=${e} force=${t}`),a=setTimeout(()=>{o.current===n&&i(!0)},100);try{let i=Mc(e),a=performance.now(),c=Nc(e);r.record(`local-cache-check`,Math.round(performance.now()-a),`result=${c?`hit`:`miss`}`),t&&(Le.invalidate(i),r.record(`invalidate-local-cache`,0));let l=await r.step(`ttl-cache-get`,()=>Le.get(i,()=>g(e,t,!1),Ec));if(o.current!==n){r.summary(`stale-request`);return}await r.step(`update-state`,async()=>{s(l),Ac(e,l)}),r.summary(`branch=${l.currentBranch} changes=${l.changedFilesCount} prExists=${l.prExists}`)}catch(e){if(o.current!==n)return;Tc.error(`Failed to fetch unified git status`,e),r.summary(`error`)}finally{clearTimeout(a),o.current===n&&i(!1)}},[e,s]),u=(0,Z.useRef)(l);return u.current=l,(0,Z.useEffect)(()=>{if(e)return jc(e,e=>{c.current(e)})},[e]),(0,Z.useEffect)(()=>{if(!e)return;let t=0;function n(){if(document.visibilityState!==`visible`)return;let e=Date.now();e-t<500||(t=e,u.current(!1))}return document.addEventListener(`visibilitychange`,n),window.addEventListener(`focus`,n),()=>{document.removeEventListener(`visibilitychange`,n),window.removeEventListener(`focus`,n)}},[e]),(0,Z.useEffect)(()=>{if(o.current+=1,i(!1),!e){a.current=void 0,(0,Z.startTransition)(()=>{n(Dc)});return}let t=a.current!==e,r=Nc(e);t&&(Tc.debug(`Active thread changed`,{previousThreadId:a.current??`none`,threadId:e}),a.current=e),(0,Z.startTransition)(()=>{n(r??Dc)}),Tc.debug(`Loaded unified git status from local cache`,{threadId:e,cache:r?`hit`:`miss`});let s=e,l=!1;function d(){if(l)return;let e=kc.get(s);if(e){Tc.debug(`Initial unified git status fetch already in flight`,{threadId:s}),e.then(()=>{if(l)return;let e=Nc(s);e&&c.current(e)});return}Tc.debug(`Starting initial unified git status fetch`,{threadId:s});let t=u.current(!1).finally(()=>{Tc.debug(`Initial unified git status fetch settled`,{threadId:s}),kc.delete(s)});kc.set(s,t)}return d(),()=>{l=!0}},[e]),{hasChanges:t.hasChanges,changedFilesCount:t.changedFilesCount,hasUnpushedCommits:t.hasUnpushedCommits,hasRemoteBranch:t.hasRemoteBranch,currentBranch:t.currentBranch,isOnGitHub:t.isOnGitHub,remoteUrl:t.remoteUrl,canCreateRepo:t.canCreateRepo,repoUrl:t.repoUrl,status:t.status,defaultBranch:t.defaultBranch,prExists:t.prExists,prUrl:t.prUrl,prState:t.prState,commitsAheadOfDefault:t.commitsAheadOfDefault,defaultBranchAhead:t.defaultBranchAhead,defaultBranchBehind:t.defaultBranchBehind,isRefreshing:r,fetchUnifiedStatus:l}}var Fc=(0,Z.createContext)(void 0);function Ic(e){let t=(0,Q.c)(8),{threadId:n,fetchUnifiedStatus:r}=e,i=X(zc),a=X(Rc),o=X(Lc),{triggerReviewRefresh:s}=Fi(),c,l;return t[0]!==a||t[1]!==r||t[2]!==i||t[3]!==o||t[4]!==n||t[5]!==s?(c=()=>{if(!(!n||n!==o)&&!i&&a.includes(n)){let e=setTimeout(()=>{r(!0),s(n)},1e3);return()=>clearTimeout(e)}},l=[n,o,i,a,r,s],t[0]=a,t[1]=r,t[2]=i,t[3]=o,t[4]=n,t[5]=s,t[6]=c,t[7]=l):(c=t[6],l=t[7]),(0,Z.useEffect)(c,l),null}function Lc(e){return e.selectedThreadId}function Rc(e){return e.completedThreadIds}function zc(e){return e.isStreaming}function Bc(e){let t=(0,Q.c)(7),{threadId:n,children:r}=e,i=Pc(n),a;t[0]!==n||t[1]!==i.fetchUnifiedStatus?(a=(0,$.jsx)(Ic,{threadId:n,fetchUnifiedStatus:i.fetchUnifiedStatus}),t[0]=n,t[1]=i.fetchUnifiedStatus,t[2]=a):a=t[2];let o;return t[3]!==r||t[4]!==a||t[5]!==i?(o=(0,$.jsxs)(Fc.Provider,{value:i,children:[a,r]}),t[3]=r,t[4]=a,t[5]=i,t[6]=o):o=t[6],o}function Vc(){let e=(0,Z.useContext)(Fc);if(e===void 0)throw Error(`useGitStatus must be used within a GitStatusProvider`);return e}function Hc(e,t){let n=e.findIndex(e=>e.sender===`user`&&e.checkpointRef===t);return n===-1?e:e.slice(0,n)}function Uc(e){let[t,n]=(0,Z.useState)(!1),{fetchUnifiedStatus:r}=Vc(),i=Gi(),a=Ca();async function o(o){if(!(!e||t)){n(!0);try{let t=await yt(e,o);if(t.success){i({type:Y.SetMessages,messages:Hc(a.getState().messages,o)}),i({type:Y.ResetStream,threadId:e,paneId:`primary`});let t=await B(e);i({type:Y.SetMessages,messages:t.messages}),Ri({title:`Checkpoint restored`,description:`Working tree and conversation restored to before this prompt.`}),r(!0)}else Ri({title:`Restore failed`,description:t.error??`Could not restore checkpoint.`,variant:`destructive`})}catch(e){Ri({title:`Restore failed`,description:e instanceof Error?e.message:`Unknown error`,variant:`destructive`})}finally{n(!1)}}}return{isRestoring:t,restore:o}}function Wc(e){let t=(0,Q.c)(7),n=e===void 0?2e3:e,[r,i]=(0,Z.useState)(!1),a,o;t[0]!==r||t[1]!==n?(a=()=>{if(!r)return;let e=setTimeout(()=>i(!1),n);return()=>clearTimeout(e)},o=[r,n],t[0]=r,t[1]=n,t[2]=a,t[3]=o):(a=t[2],o=t[3]),(0,Z.useEffect)(a,o);let s;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(s=function(){i(!0)},t[4]=s):s=t[4];let c=s,l;return t[5]===r?l=t[6]:(l={copied:r,markCopied:c},t[5]=r,t[6]=l),l}function Gc(e){return e.length<=32?e:`${e.slice(0,32)}...`}function Kc(e){let t=(0,Q.c)(64),{message:n,threadId:r,showCheckpointRestore:a,checkpointRestoreTooltip:o}=e,s=a===void 0?!1:a,[c,l]=(0,Z.useState)(!1),u=n.sender===`user`,{isRestoring:d,restore:f}=Uc(r),{copied:p,markCopied:m}=Wc(),h=u&&(s||!!o),g;t[0]===n.timestamp?g=t[1]:(g=n.timestamp?new Date(n.timestamp).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`}):``,t[0]=n.timestamp,t[1]=g);let _=g,v;t[2]===n.content?v=t[3]:(v=Gc(n.content),t[2]=n.content,t[3]=v);let y=v,b;t[4]!==d||t[5]!==n.checkpointRef||t[6]!==s?(b=function(){!n.checkpointRef||!s||d||l(!0)},t[4]=d,t[5]=n.checkpointRef,t[6]=s,t[7]=b):b=t[7];let x=b,S;t[8]!==n.checkpointRef||t[9]!==f||t[10]!==s?(S=async function(){!n.checkpointRef||!s||(await f(n.checkpointRef),l(!1))},t[8]=n.checkpointRef,t[9]=f,t[10]=s,t[11]=S):S=t[11];let C=S,w;t[12]!==m||t[13]!==n.content?(w=async function(){try{await navigator.clipboard.writeText(n.content),m()}catch(e){let t=e;Ri({title:`Copy failed`,description:t instanceof Error?t.message:`Could not copy prompt.`,variant:`destructive`})}},t[12]=m,t[13]=n.content,t[14]=w):w=t[14];let T=w,E=u&&`flex-row-reverse`,D;t[15]===E?D=t[16]:(D=K(`flex items-center gap-2`,E),t[15]=E,t[16]=D);let O;t[17]===Symbol.for(`react.memo_cache_sentinel`)?(O=K(J.compact,`font-medium text-foreground`),t[17]=O):O=t[17];let k;t[18]!==u||t[19]!==n.attributionLabel||t[20]!==n.mode?(k=u?n.attributionLabel??`You`:zr(n.mode),t[18]=u,t[19]=n.attributionLabel,t[20]=n.mode,t[21]=k):k=t[21];let A;t[22]===k?A=t[23]:(A=(0,$.jsx)(`span`,{className:O,children:k}),t[22]=k,t[23]=A);let j;t[24]!==o||t[25]!==T||t[26]!==x||t[27]!==p||t[28]!==d||t[29]!==u||t[30]!==h||t[31]!==s?(j=u&&(0,$.jsx)(Ti,{children:(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity`,children:[(0,$.jsxs)(sa,{children:[(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsx)(`span`,{tabIndex:0,className:`inline-flex`,children:(0,$.jsx)(`button`,{onClick:T,"aria-label":p?`Prompt copied`:`Copy prompt`,className:`flex items-center justify-center h-5 w-5 rounded-md text-muted-foreground transition-colors hover:text-foreground hover:bg-muted`,children:p?(0,$.jsx)(Xt,{className:`h-3 w-3 text-green-500`}):(0,$.jsx)(en,{className:`h-3 w-3`})})})}),(0,$.jsx)(Qa,{side:`left`,children:p?`Copied prompt`:`Copy prompt`})]}),h&&(0,$.jsxs)(sa,{children:[(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsx)(`span`,{tabIndex:0,className:`inline-flex`,children:(0,$.jsx)(`button`,{onClick:s?x:void 0,disabled:!s||d,"aria-label":o??`Restore checkpoint`,className:`flex items-center justify-center h-5 w-5 rounded-md text-muted-foreground transition-colors hover:text-foreground hover:bg-muted disabled:opacity-50 disabled:hover:text-muted-foreground disabled:hover:bg-transparent`,children:(0,$.jsx)(it,{className:K(`h-3 w-3`,d&&`animate-spin`)})})})}),(0,$.jsx)(Qa,{side:`left`,children:o??`Restore checkpoint`})]})]})}),t[24]=o,t[25]=T,t[26]=x,t[27]=p,t[28]=d,t[29]=u,t[30]=h,t[31]=s,t[32]=j):j=t[32];let M;t[33]===_?M=t[34]:(M=_&&(0,$.jsxs)(`span`,{className:K(J.compact,`flex items-center gap-1 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity`),children:[(0,$.jsx)(xr,{className:`h-2.5 w-2.5`}),_]}),t[33]=_,t[34]=M);let N;t[35]===n.model?N=t[36]:(N=n.model&&(0,$.jsxs)(`span`,{className:K(J.compact,`flex items-center gap-1 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity`),children:[(0,$.jsx)(i,{className:`h-2.5 w-2.5`}),Oo(n.model)]}),t[35]=n.model,t[36]=N);let P;t[37]===n.metadata?P=t[38]:(P=n.metadata?.processingTimeMs&&(0,$.jsxs)(`span`,{className:K(J.compact,`flex items-center gap-1 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity`),children:[(0,$.jsx)(Ar,{className:`h-2.5 w-2.5`}),n.metadata.processingTimeMs>=6e4?`${Math.floor(n.metadata.processingTimeMs/6e4)}m ${Math.round(n.metadata.processingTimeMs%6e4/1e3)}s`:`${Math.round(n.metadata.processingTimeMs/1e3)}s`]}),t[37]=n.metadata,t[38]=P);let F;t[39]===n.metadata?F=t[40]:(F=(n.metadata?.tokenCount||n.metadata?.estimatedCost)&&(0,$.jsxs)(`span`,{className:K(J.compact,`text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity`),children:[n.metadata.tokenCount?`${n.metadata.tokenCount.toLocaleString()} tokens`:null,n.metadata.tokenCount&&n.metadata.estimatedCost?` · `:null,n.metadata.estimatedCost?fn(n.metadata.estimatedCost):null]}),t[39]=n.metadata,t[40]=F);let I;t[41]!==A||t[42]!==j||t[43]!==M||t[44]!==N||t[45]!==P||t[46]!==F||t[47]!==D?(I=(0,$.jsxs)(`div`,{className:D,children:[A,j,M,N,P,F]}),t[41]=A,t[42]=j,t[43]=M,t[44]=N,t[45]=P,t[46]=F,t[47]=D,t[48]=I):I=t[48];let L;t[49]===Symbol.for(`react.memo_cache_sentinel`)?(L=(0,$.jsx)(ca,{children:`Restore Checkpoint`}),t[49]=L):L=t[49];let R;t[50]===y?R=t[51]:(R=(0,$.jsxs)(ia,{children:[L,(0,$.jsxs)(qa,{children:[`Restore to the checkpoint before “`,y,`” was started?`]})]}),t[50]=y,t[51]=R);let z;t[52]===Symbol.for(`react.memo_cache_sentinel`)?(z=(0,$.jsx)(Xa,{children:`Cancel`}),t[52]=z):z=t[52];let B;t[53]===C?B=t[54]:(B=(0,$.jsxs)(na,{children:[z,(0,$.jsx)(oa,{onClick:C,children:`Restore checkpoint`})]}),t[53]=C,t[54]=B);let ee;t[55]!==R||t[56]!==B?(ee=(0,$.jsxs)(Ci,{children:[R,B]}),t[55]=R,t[56]=B,t[57]=ee):ee=t[57];let te;t[58]!==c||t[59]!==ee?(te=(0,$.jsx)(Mi,{open:c,onOpenChange:l,children:ee}),t[58]=c,t[59]=ee,t[60]=te):te=t[60];let ne;return t[61]!==I||t[62]!==te?(ne=(0,$.jsxs)($.Fragment,{children:[I,te]}),t[61]=I,t[62]=te,t[63]=ne):ne=t[63],ne}function qc(e){let t=(0,Q.c)(32),{src:n,threadId:r}=e,{copied:i,markCopied:a}=Wc(),o;t[0]!==n||t[1]!==r?(o=n.startsWith(`data:`)?n:Ms(n,r),t[0]=n,t[1]=r,t[2]=o):o=t[2];let s=o,c;t[3]===s?c=t[4]:(c=async function(){let e=`generated-image-${Date.now()}.png`,{path:t}=await L(s.startsWith(`data:`)?{imageData:s.replace(/^data:[^;]+;base64,/,``),filename:e}:{imageUrl:s,filename:e});Ri({title:`Saved to downloads: ${t.split(`/`).pop()}`})},t[3]=s,t[4]=c);let l=c,u;t[5]!==s||t[6]!==a?(u=async function(){await zn(s.startsWith(`data:`)?{imageData:s.replace(/^data:[^;]+;base64,/,``)}:{imageUrl:s}),a()},t[5]=s,t[6]=a,t[7]=u):u=t[7];let d=u,f;t[8]===s?f=t[9]:(f=(0,$.jsx)(`img`,{src:s,alt:`Generated image`,className:`max-w-full rounded-lg border border-border block max-h-[512px]`}),t[8]=s,t[9]=f);let p;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,$.jsx)(ht,{className:`h-3.5 w-3.5`}),t[10]=p):p=t[10];let m;t[11]===l?m=t[12]:(m=(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsx)(`button`,{onClick:l,className:`flex items-center justify-center h-7 w-7 rounded-md bg-background/80 backdrop-blur-sm border border-border text-foreground hover:bg-background transition-colors`,children:p})}),t[11]=l,t[12]=m);let h;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,$.jsx)(Qa,{children:`Save image`}),t[13]=h):h=t[13];let g;t[14]===m?g=t[15]:(g=(0,$.jsxs)(sa,{children:[m,h]}),t[14]=m,t[15]=g);let _;t[16]===i?_=t[17]:(_=i?(0,$.jsx)(Xt,{className:`h-3.5 w-3.5 text-green-500`}):(0,$.jsx)(en,{className:`h-3.5 w-3.5`}),t[16]=i,t[17]=_);let v;t[18]!==d||t[19]!==_?(v=(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsx)(`button`,{onClick:d,className:`flex items-center justify-center h-7 w-7 rounded-md bg-background/80 backdrop-blur-sm border border-border text-foreground hover:bg-background transition-colors`,children:_})}),t[18]=d,t[19]=_,t[20]=v):v=t[20];let y=i?`Copied!`:`Copy to clipboard`,b;t[21]===y?b=t[22]:(b=(0,$.jsx)(Qa,{children:y}),t[21]=y,t[22]=b);let x;t[23]!==v||t[24]!==b?(x=(0,$.jsxs)(sa,{children:[v,b]}),t[23]=v,t[24]=b,t[25]=x):x=t[25];let S;t[26]!==x||t[27]!==g?(S=(0,$.jsx)(`div`,{className:`absolute top-2 right-2 flex gap-1 opacity-0 group-hover/img:opacity-100 transition-opacity`,children:(0,$.jsxs)(Ti,{children:[g,x]})}),t[26]=x,t[27]=g,t[28]=S):S=t[28];let C;return t[29]!==S||t[30]!==f?(C=(0,$.jsxs)(`div`,{className:`mt-2 relative group/img inline-block max-w-full`,children:[f,S]}),t[29]=S,t[30]=f,t[31]=C):C=t[31],C}function Jc(e){return e.startsWith(`/settings`)||e===`/review`}function Yc(){let e=(0,Q.c)(13),{windows:t,addWindow:n,revealWindow:r}=vo(),{setActiveMainTab:i,triggerReviewRefresh:a,triggerTasksRefresh:o}=Fi(),{triggerExplorerRefresh:s}=ko(),c=X(Xc),l=ua(),u=Oa(),d;e[0]!==n||e[1]!==u.pathname||e[2]!==l||e[3]!==r||e[4]!==c||e[5]!==i||e[6]!==s||e[7]!==a||e[8]!==o||e[9]!==t?(d=(e,d)=>{let f=d===void 0?{}:d,p=f.reuseExisting??!0,m=f.navigateToChat??!0;if(i(`chat`),m&&Jc(u.pathname)&&l(`/`),e===`explorer`&&s(),e===`review`&&a(c),e===`tasks`&&o(),p&&e!==`chat`){let n=t.find(t=>t.panelId===e);if(n)return r(n.id),n.id}return n(e)},e[0]=n,e[1]=u.pathname,e[2]=l,e[3]=r,e[4]=c,e[5]=i,e[6]=s,e[7]=a,e[8]=o,e[9]=t,e[10]=d):d=e[10];let f=d,p;return e[11]===f?p=e[12]:(p={openChatDockPanel:f},e[11]=f,e[12]=p),p}function Xc(e){return e.selectedThreadId}var Zc=new RegExp(String.raw`\x1B\[[0-?]*[ -/]*[@-~]`,`g`),Qc=new RegExp(String.raw`\x1B\].*?(?:\x07|\x1B\\)`,`g`),$c=new RegExp(String.raw`\x1B[@-_]`,`g`),el=/\r(?!\n)/g,tl=/\\n/g;function nl(e){return e.replace(Qc,``).replace(Zc,``).replace($c,``)}function rl(e){return nl(e).replace(tl,`
|
|
12
|
+
`).replace(el,`
|
|
13
|
+
`)}function il(e){return Qt(e)}function al(e,t){let n=e.replace(/\s+/g,` `).trim();return n.length<=t?n:`${n.slice(0,t)}...`}function ol(e){let t=e.replace(/\s+/g,` `).trim();return{fullText:t,label:al(t,50)}}function sl(e,t){if(!t||!e||typeof e!=`string`)return e;try{let n=t.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);return e.replace(new RegExp(n,`g`),`.`)}catch{return e}}function cl(e){return typeof e==`string`?e:typeof e==`object`&&e?JSON.stringify(e,null,2):String(e)}var ll=32;function ul(e,t){if(e===void 0)return null;let n;return n=typeof e==`string`?e:typeof e==`number`||typeof e==`boolean`?String(e):e===null?`null`:JSON.stringify(e),n.length>t?`${n.slice(0,t)}...`:n}function dl(e,t=ll,n=[]){if(!e)return null;let r=new Set(n),i=[];for(let[n,a]of Object.entries(e)){if(r.has(n))continue;let e=ul(a,t);e&&i.push(`${n}: ${e}`)}return i.length>0?i.join(`, `):null}function fl(e){if(!e)return`browser`;let t=typeof e.action==`string`?e.action:`browser`;if(typeof e.url==`string`&&e.url.trim())return`${t} · ${e.url.trim()}`;if(typeof e.ref==`string`&&e.ref.trim())return`${t} · ${e.ref.trim()}`;if(typeof e.text==`string`&&e.text.trim())return`${t} · ${e.text.trim()}`;if(typeof e.selector==`string`&&e.selector.trim())return`${t} · ${e.selector.trim()}`;if(typeof e.preset==`string`&&e.preset.trim())return`${t} · ${e.preset.trim()}`;if(typeof e.script==`string`&&e.script.trim()){let n=e.script.trim();return n.length>40?`${t} · ${n.slice(0,40)}…`:`${t} · ${n}`}return t}function pl(e){return typeof e!=`object`||!e||Array.isArray(e)?e:Rt(e)}function ml(e){try{return vl(pl(JSON.parse(e)))}catch{return vl(e)}}function hl(e){let t=e.trim();if(t.startsWith(`{`)&&t.endsWith(`}`)||t.startsWith(`[`)&&t.endsWith(`]`))try{return JSON.parse(t)}catch{return e}return e}function gl(e){if(typeof e!=`object`||!e)return e;if(Array.isArray(e))return e.map(gl);let t={};for(let[n,r]of Object.entries(e))if(typeof r==`string`){let e=hl(r);t[n]=typeof e==`object`?gl(e):r}else t[n]=gl(r);return t}function _l(e){if(e==null||typeof e!=`string`)return``;let t=e;return t=t.replace(/\\\\n/g,`
|
|
14
|
+
`),t=t.replace(/\\\\"/g,`"`),t=t.replace(/\\n/g,`
|
|
15
|
+
`),t=t.replace(/\\"/g,`"`),t}function vl(e){if(e==null)return``;let t=typeof e==`object`&&e?gl(e):e;return rl(_l(typeof t==`string`?t:t==null?``:JSON.stringify(t,null,2)))}function yl(e,t){let n=e.name??`Unknown Tool`,r=e.id??`unknown`,i=e.input,o=i&&typeof i==`object`?i:null,s=i&&typeof i==`object`&&`description`in i,c=s?i.subagent_type:void 0,l=c==null?null:JSON.stringify(c),u=n===`agent`&&o&&typeof o.agentName==`string`?o.agentName:null,d=s?null:sl(cl(i),t),f=s?i.prompt:null,p=sl(typeof f==`string`?f:null,t),m=sl(o&&typeof o.command==`string`?o.command:null,t),h=n===`fetch`&&o&&typeof o.url==`string`?o.url:null,g=o&&typeof o.pattern==`string`?o.pattern:null,_=n===`web_search`&&o&&typeof o.query==`string`?o.query:null,v=o&&typeof o.lang==`string`?o.lang:null,y=sl(o&&typeof o.path==`string`?o.path:null,t),b=n.toLowerCase(),x=b===`get_observation`,S=o&&typeof o.offset==`number`?o.offset:null,C=o&&typeof o.limit==`number`?o.limit:null,w=x?S??1:S,T=x?C??200:C,E=x||b.includes(`read`)||b.includes(`write`)||b.includes(`edit`),D=b.includes(`edit`),O=E&&o&&typeof o.path==`string`?o.path:null,k=O?O.split(`/`).pop()??O:null,A=D&&o&&typeof o.oldText==`string`?o.oldText:null,j=D&&o&&typeof o.newText==`string`?o.newText:null,M=A===null?null:A.split(`
|
|
16
|
+
`).length,N=j===null?null:j.split(`
|
|
17
|
+
`).length,P=A!==null&&j!==null,F=n===`generate_image`&&o&&typeof o.prompt==`string`?o.prompt:null,I=n===`find_images`&&o&&typeof o.query==`string`?o.query:null,L=n===`todo`&&o?o.status:void 0,R=e.displayName??Qt(n),z=e.activeDisplayName??a(n),B=`default`;return b===`bash`||b.includes(`terminal`)||b.includes(`shell`)?B=`bash`:b===`fetch`?B=`fetch`:E?B=`file`:b===`find`||b===`web_search`||b.includes(`search`)||b.includes(`grep`)?B=`search`:b===`agent`||b.includes(`subagent`)||s?B=`agent`:b===`todo`?B=`todo`:b===`generate_image`?B=`imageGen`:b===`find_images`?B=`findImages`:b===`browser`&&(B=`browser`),{toolType:B,toolName:n,toolId:r,displayName:R,activeDisplayName:z,inputObj:o,toolInput:d,command:m,fetchUrl:h,pattern:g,webSearchQuery:_,isFileTool:E,isObservationTool:x,isEditTool:D,filePath:O,fileDisplayName:k,editOldText:A,editNewText:j,editDeletedLineCount:M,editAddedLineCount:N,hasEditDiff:P,path:y,offset:w,limit:T,prompt:p,agentName:u,subagentType:l,lang:v,imageGenPrompt:F,findImagesQuery:I,todoStatus:L}}var bl=new Map;function xl(e){return e.trim()}function Sl(){let e=te(jr.BASH_COMMAND_DURATIONS);if(!e)return{};try{let t=JSON.parse(e);if(typeof t!=`object`||!t||Array.isArray(t))return{};let n={};for(let[e,r]of Object.entries(t))typeof r==`number`&&Number.isFinite(r)&&r>0&&(n[xl(e)]=r);return n}catch{return{}}}function Cl(e){pt(jr.BASH_COMMAND_DURATIONS,JSON.stringify(e))}function wl(e){return Sl()[xl(e)]??null}function Tl(e,t){let n=xl(e);if(!n||!Number.isFinite(t)||t<=0)return;let r=Sl();r[n]=Math.round(t),Cl(r)}function El(e,t){!t?.trim()||bl.has(e)||bl.set(e,{command:xl(t),startedAt:Date.now()})}function Dl(e){let t=bl.get(e);if(!t)return;let n=Date.now()-t.startedAt;Tl(t.command,n),bl.delete(e)}function Ol(e){let t=Math.max(0,Math.floor(e/1e3)),n=Math.floor(t/60),r=t%60;return`${n}:${String(r).padStart(2,`0`)}`}function kl(e,t){return t!==null&&t>0?`${Math.min(99,Math.round(e/t*100))}% complete`:Ol(e)}var Al=1e3;function jl(e,t,n){let[r,i]=(0,Z.useState)(0),[a,o]=(0,Z.useState)(null),s=(0,Z.useRef)(null),c=(0,Z.useRef)(!1),l=(0,Z.useRef)(n);return l.current=n,(0,Z.useEffect)(()=>{if(n&&!c.current){let n=e?.trim()??``;o(n?wl(n):null),El(t,e),s.current=Date.now(),i(0)}else !n&&c.current&&(Dl(t),s.current=null,i(0),o(null));c.current=n},[n,e,t]),(0,Z.useEffect)(()=>()=>{l.current&&Dl(t)},[t]),(0,Z.useEffect)(()=>{if(!n)return;let e=()=>{s.current===null&&(s.current=Date.now()),i(Date.now()-s.current)};e();let t=setInterval(e,Al);return()=>clearInterval(t)},[n]),n?kl(r,a):null}function Ml(e){let{maxHeight:t=`48`,padding:n=`2`,leading:r=!1,className:i}=e??{};return K(J.mono,n===`3`?`p-3`:`p-2`,`bg-muted rounded whitespace-pre-wrap overflow-auto text-foreground`,t===`64`?`max-h-64`:`max-h-48`,r&&`leading-relaxed`,i)}function Nl(e){let t=(0,Q.c)(14),{open:n,onOpenChange:r,title:i,content:a,markdown:o,threadId:s,body:c}=e,l=o===void 0?!1:o,u;t[0]===i?u=t[1]:(u=(0,$.jsx)(_n,{children:(0,$.jsx)(un,{children:(0,$.jsx)(`code`,{className:J.mono,children:i})})}),t[0]=i,t[1]=u);let d;t[2]!==c||t[3]!==a||t[4]!==l||t[5]!==s?(d=c?(0,$.jsx)(`div`,{className:K(`flex-1 overflow-auto min-h-0`,J.body),children:c}):l?(0,$.jsx)(`div`,{className:K(`flex-1 overflow-auto min-h-0`,J.body),children:(0,$.jsx)(tc,{content:Ia(a),threadId:s})}):(0,$.jsx)(`pre`,{className:Ml({padding:`3`,className:`flex-1 max-h-none`}),children:a}),t[2]=c,t[3]=a,t[4]=l,t[5]=s,t[6]=d):d=t[6];let f;t[7]!==u||t[8]!==d?(f=(0,$.jsxs)(tn,{className:`max-w-3xl h-[80vh] flex flex-col`,children:[u,d]}),t[7]=u,t[8]=d,t[9]=f):f=t[9];let p;return t[10]!==r||t[11]!==n||t[12]!==f?(p=(0,$.jsx)(Cr,{open:n,onOpenChange:r,children:f}),t[10]=r,t[11]=n,t[12]=f,t[13]=p):p=t[13],p}var Pl=K(`flex-1 min-h-0 overflow-auto rounded-md border border-border bg-muted/30 p-3`);function Fl(e){let t=(0,Q.c)(17),{open:n,onOpenChange:r,prompt:i,content:a,markdown:o,threadId:s,body:c}=e,l=o===void 0?!1:o,u;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(u=(0,$.jsx)(un,{children:`Subagent`}),t[0]=u):u=t[0];let d;t[1]===i?d=t[2]:(d=i?(0,$.jsx)(Qn,{className:`whitespace-pre-wrap leading-relaxed line-clamp-3`,children:i}):null,t[1]=i,t[2]=d);let f;t[3]===d?f=t[4]:(f=(0,$.jsxs)(_n,{children:[u,d]}),t[3]=d,t[4]=f);let p;t[5]!==c||t[6]!==a||t[7]!==l||t[8]!==s?(p=c?(0,$.jsx)(`div`,{className:K(Pl,J.body),children:c}):l?(0,$.jsx)(`div`,{className:K(Pl,J.body),children:(0,$.jsx)(tc,{content:Ia(a),threadId:s})}):(0,$.jsx)(`pre`,{className:K(Pl,J.mono,`whitespace-pre-wrap`),children:a}),t[5]=c,t[6]=a,t[7]=l,t[8]=s,t[9]=p):p=t[9];let m;t[10]!==f||t[11]!==p?(m=(0,$.jsxs)(tn,{className:`max-w-3xl h-[80vh] flex flex-col gap-4`,children:[f,p]}),t[10]=f,t[11]=p,t[12]=m):m=t[12];let h;return t[13]!==r||t[14]!==n||t[15]!==m?(h=(0,$.jsx)(Cr,{open:n,onOpenChange:r,children:m}),t[13]=r,t[14]=n,t[15]=m,t[16]=h):h=t[16],h}function Il(e){let t=(0,Q.c)(20),{open:n,onOpenChange:r,title:i,requestContent:a,responseContent:o}=e,s;t[0]===i?s=t[1]:(s=(0,$.jsx)(_n,{children:(0,$.jsx)(un,{children:(0,$.jsx)(`code`,{className:J.mono,children:i})})}),t[0]=i,t[1]=s);let c,l;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,$.jsx)(`div`,{className:K(J.compact,`mb-1 text-muted-foreground`),children:`Request`}),l=Ml({padding:`3`,className:`max-h-48`}),t[2]=c,t[3]=l):(c=t[2],l=t[3]);let u;t[4]===a?u=t[5]:(u=(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-col`,children:[c,(0,$.jsx)(`pre`,{className:l,children:a})]}),t[4]=a,t[5]=u);let d,f;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,$.jsx)(`div`,{className:K(J.compact,`mb-1 text-muted-foreground`),children:`Response`}),f=Ml({padding:`3`,className:`flex-1 max-h-none`}),t[6]=d,t[7]=f):(d=t[6],f=t[7]);let p;t[8]===o?p=t[9]:(p=(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[d,(0,$.jsx)(`pre`,{className:f,children:o})]}),t[8]=o,t[9]=p);let m;t[10]!==u||t[11]!==p?(m=(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-4 overflow-hidden`,children:[u,p]}),t[10]=u,t[11]=p,t[12]=m):m=t[12];let h;t[13]!==s||t[14]!==m?(h=(0,$.jsxs)(tn,{className:`max-w-3xl h-[80vh] flex flex-col gap-4`,children:[s,m]}),t[13]=s,t[14]=m,t[15]=h):h=t[15];let g;return t[16]!==r||t[17]!==n||t[18]!==h?(g=(0,$.jsx)(Cr,{open:n,onOpenChange:r,children:h}),t[16]=r,t[17]=n,t[18]=h,t[19]=g):g=t[19],g}function Ll(e){let t=(0,Q.c)(10),{oldText:n,newText:r}=e,i,a,o;if(t[0]!==r||t[1]!==n){let e=n.split(`
|
|
18
|
+
`),s=r.split(`
|
|
19
|
+
`);t[5]===Symbol.for(`react.memo_cache_sentinel`)?(i=K(J.caption,`font-mono whitespace-pre-wrap overflow-auto`),t[5]=i):i=t[5],a=e.map(zl),o=s.map(Rl),t[0]=r,t[1]=n,t[2]=i,t[3]=a,t[4]=o}else i=t[2],a=t[3],o=t[4];let s;return t[6]!==i||t[7]!==a||t[8]!==o?(s=(0,$.jsxs)(`pre`,{className:i,children:[a,o]}),t[6]=i,t[7]=a,t[8]=o,t[9]=s):s=t[9],s}function Rl(e,t){return(0,$.jsxs)(`div`,{className:`bg-green-500/10 text-green-600 dark:text-green-400`,children:[(0,$.jsx)(`span`,{className:`select-none opacity-50 mr-2`,children:`+`}),e]},`new-${t}`)}function zl(e,t){return(0,$.jsxs)(`div`,{className:`bg-red-500/10 text-red-600 dark:text-red-400`,children:[(0,$.jsx)(`span`,{className:`select-none opacity-50 mr-2`,children:`-`}),e]},`old-${t}`)}function Bl(e){let t=(0,Q.c)(3),{name:n}=e,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=K(J.caption,`px-1.5 py-0.5 rounded bg-muted font-mono`),t[0]=r):r=t[0];let i;return t[1]===n?i=t[2]:(i=(0,$.jsx)(`span`,{className:r,children:n}),t[1]=n,t[2]=i),i}function Vl(e){let t=(0,Q.c)(3),{type:n}=e,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=K(J.caption,`px-2 py-0.5 rounded bg-muted`),t[0]=r):r=t[0];let i;return t[1]===n?i=t[2]:(i=(0,$.jsx)(`span`,{className:r,children:n}),t[1]=n,t[2]=i),i}function Hl(e){let t=(0,Q.c)(3),{children:n}=e,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=K(J.caption,`font-mono truncate whitespace-nowrap min-w-0 max-w-full rounded bg-muted/60 px-1 py-0.5`),t[0]=r):r=t[0];let i;return t[1]===n?i=t[2]:(i=(0,$.jsx)(`code`,{className:r,children:n}),t[1]=n,t[2]=i),i}function Ul(e){let t=(0,Q.c)(6),{className:n,size:r}=e,i=(r===void 0?`sm`:r)===`sm`?`h-3.5 w-3.5`:`h-4 w-4`,a;t[0]!==n||t[1]!==i?(a=K(i,`shrink-0 origin-center animate-thread-dot-pulse text-brand`,n),t[0]=n,t[1]=i,t[2]=a):a=t[2];let o;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,$.jsx)(`circle`,{cx:`6`,cy:`6`,r:`5`}),t[3]=o):o=t[3];let s;return t[4]===a?s=t[5]:(s=(0,$.jsx)(`svg`,{"aria-hidden":`true`,className:a,viewBox:`0 0 12 12`,fill:`currentColor`,xmlns:`http://www.w3.org/2000/svg`,children:o}),t[4]=a,t[5]=s),s}function Wl(e){let t=(0,Q.c)(19),{toolName:n,displayName:r,isActive:i,muted:a,size:o,className:s}=e,c=i===void 0?!1:i,l=a===void 0?!0:a,u=o===void 0?`sm`:o,d;t[0]===s?d=t[1]:(d=K(`inline-flex items-center gap-1`,s),t[0]=s,t[1]=d);let f=!l&&`text-foreground`,p;t[2]===f?p=t[3]:(p=K(J.caption,f),t[2]=f,t[3]=p);let m;t[4]!==r||t[5]!==p?(m=(0,$.jsx)(`span`,{className:p,children:r}),t[4]=r,t[5]=p,t[6]=m):m=t[6];let h;t[7]!==c||t[8]!==u?(h=c?(0,$.jsx)(Ul,{size:u}):null,t[7]=c,t[8]=u,t[9]=h):h=t[9];let g;t[10]!==d||t[11]!==m||t[12]!==h?(g=(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsxs)(`span`,{className:d,children:[m,h]})}),t[10]=d,t[11]=m,t[12]=h,t[13]=g):g=t[13];let _;t[14]===n?_=t[15]:(_=(0,$.jsx)(Qa,{children:n}),t[14]=n,t[15]=_);let v;return t[16]!==_||t[17]!==g?(v=(0,$.jsxs)(sa,{children:[g,_]}),t[16]=_,t[17]=g,t[18]=v):v=t[18],v}function Gl(e){let t=(0,Q.c)(34),{className:n,enabled:r,fallback:i,observation:a,rootPath:o,threadId:s}=e,c=a?.id,l;t[0]!==c||t[1]!==s?(l=[`tool-observation`,s,c],t[0]=c,t[1]=s,t[2]=l):l=t[2];let u;t[3]!==a||t[4]!==s?(u=async e=>{let{pageParam:t}=e;if(!s||!a)throw Error(`Observation context is unavailable`);return Ct(s,a.id,t)},t[3]=a,t[4]=s,t[5]=u):u=t[5];let d;t[6]!==r||t[7]!==a||t[8]!==l||t[9]!==u||t[10]!==s?(d={queryKey:l,queryFn:u,initialPageParam:1,getNextPageParam(e){return e.nextOffset},enabled:!!(r&&a&&s),staleTime:1/0},t[6]=r,t[7]=a,t[8]=l,t[9]=u,t[10]=s,t[11]=d):d=t[11];let f=yo(d),p;t[12]===f.data?.pages?p=t[13]:(p=f.data?.pages.map(function(e){return e.content}).join(`
|
|
20
|
+
`),t[12]=f.data?.pages,t[13]=p);let m=p,h;t[14]!==r||t[15]!==i||t[16]!==m||t[17]!==a||t[18]!==f.isError||t[19]!==f.isPending||t[20]!==o?(h=f.isError?`Full output is unavailable.`:f.isPending&&r&&a?`Loading full output…`:sl(m??i,o),t[14]=r,t[15]=i,t[16]=m,t[17]=a,t[18]=f.isError,t[19]=f.isPending,t[20]=o,t[21]=h):h=t[21];let g=h,_;t[22]===f?_=t[23]:(_=function(){f.fetchNextPage()},t[22]=f,t[23]=_);let v=_,y;t[24]!==n||t[25]!==g?(y=(0,$.jsx)(`pre`,{className:n,children:g}),t[24]=n,t[25]=g,t[26]=y):y=t[26];let b;t[27]!==v||t[28]!==f.hasNextPage||t[29]!==f.isFetchingNextPage?(b=f.hasNextPage?(0,$.jsx)(`button`,{type:`button`,onClick:v,disabled:f.isFetchingNextPage,className:K(J.caption,`mt-2 text-brand hover:underline disabled:opacity-50`),children:f.isFetchingNextPage?`Loading more…`:`Load more output`}):null,t[27]=v,t[28]=f.hasNextPage,t[29]=f.isFetchingNextPage,t[30]=b):b=t[30];let x;return t[31]!==y||t[32]!==b?(x=(0,$.jsxs)($.Fragment,{children:[y,b]}),t[31]=y,t[32]=b,t[33]=x):x=t[33],x}function Kl(e){let t=(0,Q.c)(18),{fallback:n,observation:r}=e,[i,a]=(0,Z.useState)(!1),o=X(Jl),s=X(ql),c=r.lineCount>0?`Show full output (${r.lineCount} lines)`:`Show full output…`,l;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(l=()=>a(!0),t[0]=l):l=t[0];let u;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(u=(0,$.jsx)(oe,{className:`h-3.5 w-3.5`}),t[1]=u):u=t[1];let d;t[2]===c?d=t[3]:(d=(0,$.jsxs)(sa,{children:[(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:l,"aria-label":c,className:`inline-flex shrink-0 rounded p-0.5 text-muted-foreground hover:bg-muted hover:text-brand`,children:u})}),(0,$.jsx)(Qa,{children:c})]}),t[2]=c,t[3]=d);let f;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,$.jsx)(_n,{children:(0,$.jsx)(un,{children:`Full Output`})}),t[4]=f):f=t[4];let p;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(p=K(J.caption,`bg-muted p-3 rounded font-mono whitespace-pre-wrap overflow-auto flex-1 text-foreground`),t[5]=p):p=t[5];let m;t[6]!==i||t[7]!==n||t[8]!==r||t[9]!==o||t[10]!==s?(m=(0,$.jsxs)(tn,{className:`max-w-3xl max-h-[80vh] flex flex-col`,children:[f,(0,$.jsx)(Gl,{enabled:i,fallback:n,observation:r,rootPath:o,threadId:s,className:p})]}),t[6]=i,t[7]=n,t[8]=r,t[9]=o,t[10]=s,t[11]=m):m=t[11];let h;t[12]!==i||t[13]!==m?(h=(0,$.jsx)(Cr,{open:i,onOpenChange:a,children:m}),t[12]=i,t[13]=m,t[14]=h):h=t[14];let g;return t[15]!==d||t[16]!==h?(g=(0,$.jsxs)($.Fragment,{children:[d,h]}),t[15]=d,t[16]=h,t[17]=g):g=t[17],g}function ql(e){return e.selectedThreadId}function Jl(e){return e.projects.find(t=>t.projectId===e.selectedProjectId)?.threads.find(t=>t.threadId===e.selectedThreadId)?.path}function Yl(e){let t=(0,Q.c)(25),{expanded:n,onToggle:r,title:i,tooltip:a,isActive:o,trailing:s,buttonClassName:c,children:l}=e,u;t[0]===c?u=t[1]:(u=c??K(J.body,`font-medium text-foreground`),t[0]=c,t[1]=u);let d;t[2]===u?d=t[3]:(d=K(`w-full py-2 flex items-center gap-2 hover:bg-muted/50 transition-colors text-left`,u),t[2]=u,t[3]=d);let f;t[4]===i?f=t[5]:(f=(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:i}),t[4]=i,t[5]=f);let p;t[6]===o?p=t[7]:(p=o&&(0,$.jsx)(Ul,{size:`md`}),t[6]=o,t[7]=p);let m;t[8]===n?m=t[9]:(m=n?(0,$.jsx)(Dr,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(Ut,{className:`h-4 w-4 shrink-0`}),t[8]=n,t[9]=m);let h;t[10]!==r||t[11]!==d||t[12]!==f||t[13]!==p||t[14]!==m||t[15]!==s?(h=(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsxs)(`button`,{onClick:r,className:d,children:[f,p,s,m]})}),t[10]=r,t[11]=d,t[12]=f,t[13]=p,t[14]=m,t[15]=s,t[16]=h):h=t[16];let g;t[17]===a?g=t[18]:(g=(0,$.jsx)(Qa,{children:a}),t[17]=a,t[18]=g);let _;t[19]!==h||t[20]!==g?(_=(0,$.jsxs)(sa,{children:[h,g]}),t[19]=h,t[20]=g,t[21]=_):_=t[21];let v=n&&l,y;return t[22]!==_||t[23]!==v?(y=(0,$.jsxs)(`div`,{className:`overflow-hidden`,children:[_,v]}),t[22]=_,t[23]=v,t[24]=y):y=t[24],y}function Xl(e){let t=(0,Q.c)(6),{toolId:n,children:r}=e,i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=K(J.compact,`text-muted-foreground mb-2 font-mono`),t[0]=i):i=t[0];let a;t[1]===n?a=t[2]:(a=(0,$.jsxs)(`div`,{className:i,children:[`ID: `,n]}),t[1]=n,t[2]=a);let o;return t[3]!==r||t[4]!==a?(o=(0,$.jsxs)(`div`,{className:`py-2 border-t border-border`,children:[a,r]}),t[3]=r,t[4]=a,t[5]=o):o=t[5],o}var Zl=`text-muted-foreground/60 whitespace-pre-wrap overflow-y-auto font-mono`,Ql=`rounded-md border border-border bg-muted/30 p-2`;function $l(e){let t=(0,Q.c)(4),{className:n}=e,r;t[0]===n?r=t[1]:(r=K(`h-3.5 w-3.5 shrink-0 text-destructive`,n),t[0]=n,t[1]=r);let i;return t[2]===r?i=t[3]:(i=(0,$.jsx)(Gt,{"aria-label":`Command failed`,className:r}),t[2]=r,t[3]=i),i}function eu(e){let t=(0,Q.c)(100),{data:n,inline:r,resultContent:i,isError:a,isActive:o}=e,s=(0,Z.useRef)(null),[c,l]=(0,Z.useState)(!!o),[u,d]=(0,Z.useState)(!1),f=(0,Z.useRef)(!!o),p;t[0]===n.toolId?p=t[1]:(p=e=>e.toolCallProgress[n.toolId]?.executionOutput,t[0]=n.toolId,t[1]=p);let m=X(p),h=o?m??i??``:i??``,g=h?rl(h):``,_=o?g:``,v=jl(n.command,n.toolId,!!o),y;t[2]===n.command?y=t[3]:(y=n.command===null?null:ol(n.command),t[2]=n.command,t[3]=y);let b=y,x,S;t[4]===o?(x=t[5],S=t[6]):(x=()=>{o&&!f.current?l(!0):!o&&f.current&&l(!1),f.current=!!o},S=[o],t[4]=o,t[5]=x,t[6]=S),(0,Z.useEffect)(x,S);let C;if(t[7]!==o||t[8]!==c?(C=()=>{c&&o&&s.current&&(s.current.scrollTop=s.current.scrollHeight)},t[7]=o,t[8]=c,t[9]=C):C=t[9],(0,Z.useEffect)(C,[c,o,_]),r){if(o){let e;t[10]===c?e=t[11]:(e=()=>l(!c),t[10]=c,t[11]=e);let r;t[12]!==n.activeDisplayName||t[13]!==n.toolName?(r=(0,$.jsx)(Wl,{toolName:n.toolName,displayName:n.activeDisplayName,isActive:!1,className:`shrink-0`}),t[12]=n.activeDisplayName,t[13]=n.toolName,t[14]=r):r=t[14];let i;t[15]===b?i=t[16]:(i=b!==null&&(0,$.jsx)(`span`,{className:K(J.caption,`min-w-0 flex-1 truncate whitespace-nowrap`),children:b.label}),t[15]=b,t[16]=i);let a;t[17]===v?a=t[18]:(a=v&&(0,$.jsx)(`span`,{className:K(J.caption,`tabular-nums shrink-0`),children:v}),t[17]=v,t[18]=a);let o;t[19]===c?o=t[20]:(o=c?(0,$.jsx)(Dr,{className:`h-3 w-3 text-muted-foreground shrink-0`}):(0,$.jsx)(Ut,{className:`h-3 w-3 text-muted-foreground shrink-0`}),t[19]=c,t[20]=o);let u;t[21]!==c||t[22]!==o||t[23]!==e||t[24]!==r||t[25]!==i||t[26]!==a?(u=(0,$.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1.5 cursor-pointer select-none text-left w-full min-w-0`,onClick:e,"aria-expanded":c,children:[r,i,a,o]}),t[21]=c,t[22]=o,t[23]=e,t[24]=r,t[25]=i,t[26]=a,t[27]=u):u=t[27];let d=c?`grid-rows-[1fr]`:`grid-rows-[0fr]`,f;t[28]===d?f=t[29]:(f=K(`grid transition-[grid-template-rows] duration-200 ease-in-out`,d),t[28]=d,t[29]=f);let p;return t[30]===Symbol.for(`react.memo_cache_sentinel`)?(p={maxHeight:`7.5em`},t[30]=p):p=t[30],(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[u,(0,$.jsx)(`div`,{className:f,children:(0,$.jsx)(`div`,{className:`overflow-hidden`,children:(0,$.jsx)(`div`,{ref:s,className:K(J.caption,Zl,`ml-5`,_&&K(Ql,`mt-1 mb-0.5`)),style:p,children:_})})})]})}if(b!==null&&g){let e=b.label!==b.fullText,r;t[31]!==n.displayName||t[32]!==n.toolName?(r=(0,$.jsx)(Wl,{toolName:n.toolName,displayName:n.displayName,isActive:!1}),t[31]=n.displayName,t[32]=n.toolName,t[33]=r):r=t[33];let i,o;t[34]===Symbol.for(`react.memo_cache_sentinel`)?(i=()=>d(!0),o=K(J.caption,`font-mono hover:underline truncate whitespace-nowrap min-w-0 flex-1 cursor-pointer text-left`),t[34]=i,t[35]=o):(i=t[34],o=t[35]);let s;t[36]===b.label?s=t[37]:(s=(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:i,className:o,children:b.label})}),t[36]=b.label,t[37]=s);let c=e?b.fullText:`View output`,l;t[38]===c?l=t[39]:(l=(0,$.jsx)(Qa,{className:`max-w-md break-all font-mono`,children:c}),t[38]=c,t[39]=l);let f;t[40]!==l||t[41]!==s?(f=(0,$.jsxs)(sa,{children:[s,l]}),t[40]=l,t[41]=s,t[42]=f):f=t[42];let p;t[43]===a?p=t[44]:(p=a&&(0,$.jsx)($l,{className:`ml-auto`}),t[43]=a,t[44]=p);let m;return t[45]!==f||t[46]!==p||t[47]!==r?(m=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 min-w-0 w-full`,children:[r,f,p]}),t[45]=f,t[46]=p,t[47]=r,t[48]=m):m=t[48],(0,$.jsxs)($.Fragment,{children:[m,(0,$.jsx)(Nl,{open:u,onOpenChange:d,title:b.fullText,content:g})]})}if(b===null&&g){let e,r;t[49]===Symbol.for(`react.memo_cache_sentinel`)?(e=()=>d(!0),r=K(J.caption,`hover:underline truncate whitespace-nowrap min-w-0 flex-1 cursor-pointer text-left`),t[49]=e,t[50]=r):(e=t[49],r=t[50]);let i;t[51]===n.displayName?i=t[52]:(i=(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:e,className:r,children:n.displayName})}),t[51]=n.displayName,t[52]=i);let o;t[53]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,$.jsx)(Qa,{children:`View output`}),t[53]=o):o=t[53];let s;t[54]===i?s=t[55]:(s=(0,$.jsxs)(sa,{children:[i,o]}),t[54]=i,t[55]=s);let c;t[56]===a?c=t[57]:(c=a&&(0,$.jsx)($l,{className:`ml-auto`}),t[56]=a,t[57]=c);let l;return t[58]!==s||t[59]!==c?(l=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 min-w-0 w-full`,children:[s,c]}),t[58]=s,t[59]=c,t[60]=l):l=t[60],(0,$.jsxs)($.Fragment,{children:[l,(0,$.jsx)(Nl,{open:u,onOpenChange:d,title:n.displayName,content:g})]})}let e;t[61]!==n.displayName||t[62]!==n.toolName?(e=(0,$.jsx)(Wl,{toolName:n.toolName,displayName:n.displayName,isActive:!1}),t[61]=n.displayName,t[62]=n.toolName,t[63]=e):e=t[63];let r;t[64]===b?r=t[65]:(r=b!==null&&(0,$.jsx)(`code`,{className:K(J.caption,`font-mono truncate whitespace-nowrap rounded bg-muted/60 px-1 py-0.5 min-w-0 flex-1`),children:b.label}),t[64]=b,t[65]=r);let i;t[66]===a?i=t[67]:(i=a&&(0,$.jsx)($l,{className:`ml-auto`}),t[66]=a,t[67]=i);let f;return t[68]!==e||t[69]!==r||t[70]!==i?(f=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 min-w-0 w-full`,children:[e,r,i]}),t[68]=e,t[69]=r,t[70]=i,t[71]=f):f=t[71],f}let w;t[72]===c?w=t[73]:(w=()=>l(!c),t[72]=c,t[73]=w);let T;t[74]===Symbol.for(`react.memo_cache_sentinel`)?(T=K(J.body,`w-full py-2 flex items-center gap-2 font-medium text-foreground hover:bg-muted/50 transition-colors text-left`),t[74]=T):T=t[74];let E;t[75]!==n.activeDisplayName||t[76]!==n.displayName||t[77]!==o||t[78]!==v?(E=o?(0,$.jsxs)($.Fragment,{children:[n.activeDisplayName,v&&(0,$.jsx)(`span`,{className:`ml-2 text-muted-foreground tabular-nums`,children:v})]}):n.displayName,t[75]=n.activeDisplayName,t[76]=n.displayName,t[77]=o,t[78]=v,t[79]=E):E=t[79];let D;t[80]===E?D=t[81]:(D=(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:E}),t[80]=E,t[81]=D);let O;t[82]!==o||t[83]!==a?(O=a&&!o&&(0,$.jsx)($l,{}),t[82]=o,t[83]=a,t[84]=O):O=t[84];let k;t[85]===c?k=t[86]:(k=c?(0,$.jsx)(Dr,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(Ut,{className:`h-4 w-4 shrink-0`}),t[85]=c,t[86]=k);let A;t[87]!==D||t[88]!==O||t[89]!==k||t[90]!==w?(A=(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsxs)(`button`,{onClick:w,className:T,children:[D,O,k]})}),t[87]=D,t[88]=O,t[89]=k,t[90]=w,t[91]=A):A=t[91];let j;t[92]===n.toolName?j=t[93]:(j=(0,$.jsx)(Qa,{children:n.toolName}),t[92]=n.toolName,t[93]=j);let M;t[94]!==A||t[95]!==j?(M=(0,$.jsxs)(sa,{children:[A,j]}),t[94]=A,t[95]=j,t[96]=M):M=t[96];let N=c&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border`,children:[(0,$.jsxs)(`div`,{className:K(J.compact,`text-muted-foreground mb-2 font-mono`),children:[`ID: `,n.toolId]}),o?(0,$.jsx)(`div`,{ref:s,className:K(J.caption,Zl,_&&Ql),style:{maxHeight:`7.5em`},children:_}):n.toolInput?(0,$.jsx)(`pre`,{className:Ml(),children:n.toolInput}):null]}),P;return t[97]!==M||t[98]!==N?(P=(0,$.jsxs)(`div`,{className:`overflow-hidden`,children:[M,N]}),t[97]=M,t[98]=N,t[99]=P):P=t[99],P}function tu(e){let t=(0,Q.c)(50),{data:n,inline:r,resultContent:i,isActive:a}=e,[o,s]=(0,Z.useState)(!!a),[c,l]=(0,Z.useState)(!1),u=n.fetchUrl,d;t[0]===i?d=t[1]:(d=i?nu(i):null,t[0]=i,t[1]=d);let f=d;if(r){let e;t[2]===o?e=t[3]:(e=()=>s(!o),t[2]=o,t[3]=e);let r=n.toolName,c=n.activeDisplayName,l=!!a,d;t[4]!==n.activeDisplayName||t[5]!==n.toolName||t[6]!==l?(d=(0,$.jsx)(Wl,{toolName:r,displayName:c,isActive:l}),t[4]=n.activeDisplayName,t[5]=n.toolName,t[6]=l,t[7]=d):d=t[7];let p;t[8]===u?p=t[9]:(p=u!==null&&(0,$.jsx)(`span`,{className:K(J.caption,`break-all`),children:u}),t[8]=u,t[9]=p);let m;t[10]===f?m=t[11]:(m=f&&(0,$.jsxs)(`span`,{className:K(J.caption,`text-muted-foreground shrink-0`),children:[f.bytes,` bytes · HTTP `,f.code]}),t[10]=f,t[11]=m);let h;t[12]===o?h=t[13]:(h=o?(0,$.jsx)(Dr,{className:`h-3 w-3 text-muted-foreground shrink-0`}):(0,$.jsx)(Ut,{className:`h-3 w-3 text-muted-foreground shrink-0`}),t[12]=o,t[13]=h);let g;t[14]!==o||t[15]!==e||t[16]!==d||t[17]!==p||t[18]!==m||t[19]!==h?(g=(0,$.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1.5 cursor-pointer select-none text-left w-full`,onClick:e,"aria-expanded":o,children:[d,p,m,h]}),t[14]=o,t[15]=e,t[16]=d,t[17]=p,t[18]=m,t[19]=h,t[20]=g):g=t[20];let _;t[21]!==o||t[22]!==i?(_=o&&i&&(0,$.jsx)(`pre`,{className:K(J.mono,J.caption,`whitespace-pre-wrap break-all rounded bg-muted/40 p-2 max-h-48 overflow-auto`),children:ru(i)}),t[21]=o,t[22]=i,t[23]=_):_=t[23];let v;return t[24]!==g||t[25]!==_?(v=(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[g,_]}),t[24]=g,t[25]=_,t[26]=v):v=t[26],v}let p=n.toolName,m=n.displayName,h=!!a,g;t[27]!==n.displayName||t[28]!==n.toolName||t[29]!==h?(g=(0,$.jsx)(Wl,{toolName:p,displayName:m,isActive:h}),t[27]=n.displayName,t[28]=n.toolName,t[29]=h,t[30]=g):g=t[30];let _;t[31]===u?_=t[32]:(_=u!==null&&(0,$.jsxs)(sa,{children:[(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsx)(`code`,{className:K(J.mono,J.caption,`break-all`),children:u})}),(0,$.jsx)(Qa,{children:u})]}),t[31]=u,t[32]=_);let v;t[33]===f?v=t[34]:(v=f&&(0,$.jsxs)(`span`,{className:K(J.caption,`text-muted-foreground`),children:[f.bytes,` bytes · HTTP `,f.code,` · `,f.durationMs,`ms`]}),t[33]=f,t[34]=v);let y;t[35]===i?y=t[36]:(y=i&&(0,$.jsx)(`button`,{type:`button`,className:K(J.caption,`text-brand hover:underline ml-auto`),onClick:()=>l(!0),children:`View result`}),t[35]=i,t[36]=y);let b;t[37]!==g||t[38]!==_||t[39]!==v||t[40]!==y?(b=(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[g,_,v,y]}),t[37]=g,t[38]=_,t[39]=v,t[40]=y,t[41]=b):b=t[41];let x;t[42]===i?x=t[43]:(x=i?ru(i):``,t[42]=i,t[43]=x);let S;t[44]!==c||t[45]!==x?(S=(0,$.jsx)(Nl,{open:c,onOpenChange:l,title:`Fetch result`,content:x}),t[44]=c,t[45]=x,t[46]=S):S=t[46];let C;return t[47]!==S||t[48]!==b?(C=(0,$.jsxs)(`div`,{className:`rounded-lg border border-border p-3 my-1`,children:[b,S]}),t[47]=S,t[48]=b,t[49]=C):C=t[49],C}function nu(e){try{let t=JSON.parse(e);if(typeof t.bytes==`number`&&typeof t.code==`number`)return{bytes:t.bytes,code:t.code,durationMs:typeof t.durationMs==`number`?t.durationMs:0}}catch{}return null}function ru(e){try{let t=JSON.parse(e);if(typeof t.result==`string`)return t.result}catch{}return e}var iu=si,au=bi,ou=Z.forwardRef((e,t)=>{let n=(0,Q.c)(13),r,i,a,o;n[0]===e?(r=n[1],i=n[2],a=n[3],o=n[4]):({className:r,align:a,sideOffset:o,...i}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a,n[4]=o);let s=a===void 0?`center`:a,c=o===void 0?4:o,l;n[5]===r?l=n[6]:(l=K(`z-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2`,r),n[5]=r,n[6]=l);let u;return n[7]!==s||n[8]!==i||n[9]!==t||n[10]!==c||n[11]!==l?(u=(0,$.jsx)(ri,{children:(0,$.jsx)(gi,{ref:t,align:s,sideOffset:c,className:l,...i})}),n[7]=s,n[8]=i,n[9]=t,n[10]=c,n[11]=l,n[12]=u):u=n[12],u});ou.displayName=gi.displayName;function su(e,t){return e===null&&t===null?null:e!==null&&t!==null?`${e}-${e+t}`:e===null?`${t}`:`${e}-`}function cu(e){let t=(0,Q.c)(6),{offset:n,limit:r}=e,i;t[0]!==r||t[1]!==n?(i=su(n,r),t[0]=r,t[1]=n,t[2]=i):i=t[2];let a=i;if(a===null)return null;let o;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(o=K(J.compact,`font-mono tabular-nums text-muted-foreground`),t[3]=o):o=t[3];let s;return t[4]===a?s=t[5]:(s=(0,$.jsx)(`span`,{className:o,children:a}),t[4]=a,t[5]=s),s}function lu(e){let t=(0,Q.c)(8),{added:n,removed:r}=e;if(n===null||r===null)return null;let i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=K(J.compact,`inline-flex items-center gap-2 font-mono tabular-nums`),t[0]=i):i=t[0];let a;t[1]===n?a=t[2]:(a=(0,$.jsxs)(`span`,{className:`text-green-600 dark:text-green-400`,children:[`+`,n]}),t[1]=n,t[2]=a);let o;t[3]===r?o=t[4]:(o=(0,$.jsxs)(`span`,{className:`text-red-600 dark:text-red-400`,children:[`-`,r]}),t[3]=r,t[4]=o);let s;return t[5]!==a||t[6]!==o?(s=(0,$.jsxs)(`span`,{className:i,children:[a,o]}),t[5]=a,t[6]=o,t[7]=s):s=t[7],s}function uu(e){let t=(0,Q.c)(50),{data:n,inline:r,rootPath:i,onOpenFile:a,resultContent:o}=e,[s,c]=(0,Z.useState)(!1),[l,u]=(0,Z.useState)(!1),[d,f]=(0,Z.useState)(!1),p;t[0]!==n.filePath||t[1]!==a||t[2]!==i?(p=function(){!n.filePath||!a||a(i&&n.filePath.startsWith(i)?n.filePath.slice(i.length+1):n.filePath)},t[0]=n.filePath,t[1]=a,t[2]=i,t[3]=p):p=t[3];let m=p;if(r){let e=!!(!n.isObservationTool&&n.toolInput&&!n.command&&!n.path&&!n.pattern&&!n.fileDisplayName),r;t[4]!==n.displayName||t[5]!==n.toolId||t[6]!==n.toolInput||t[7]!==n.toolName||t[8]!==e?(r=e?(0,$.jsxs)(iu,{children:[(0,$.jsx)(au,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex`,children:(0,$.jsx)(`button`,{type:`button`,className:`inline-flex shrink-0 items-center gap-1 rounded p-0.5 text-muted-foreground hover:text-foreground focus:outline-none focus-visible:ring-2 focus-visible:ring-ring`,"aria-label":`Show tool details`,children:(0,$.jsx)(Wl,{toolName:n.toolName,displayName:n.displayName,isActive:!1,muted:!1})})})}),(0,$.jsx)(ou,{className:`w-80 max-h-80 overflow-auto`,align:`start`,children:(0,$.jsxs)(`div`,{className:K(J.caption,`space-y-2`),children:[(0,$.jsxs)(`div`,{className:`font-mono`,children:[`ID: `,n.toolId]}),(0,$.jsx)(`pre`,{className:`font-mono whitespace-pre-wrap overflow-auto max-h-48`,children:n.toolInput})]})})]}):(0,$.jsx)(Wl,{toolName:n.toolName,displayName:n.displayName,isActive:!1}),t[4]=n.displayName,t[5]=n.toolId,t[6]=n.toolInput,t[7]=n.toolName,t[8]=e,t[9]=r):r=t[9];let a;t[10]!==n.displayName||t[11]!==n.isObservationTool||t[12]!==n.limit||t[13]!==n.offset||t[14]!==o||t[15]!==d?(a=n.isObservationTool&&o?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(sa,{children:[(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:()=>f(!0),className:`hover:underline cursor-pointer`,children:(0,$.jsx)(cu,{offset:n.offset,limit:n.limit})})}),(0,$.jsx)(Qa,{children:`View results`})]}),(0,$.jsx)(Nl,{open:d,onOpenChange:f,title:`${n.displayName} ${su(n.offset,n.limit)??``}`.trim(),content:o})]}):n.isObservationTool?(0,$.jsx)(cu,{offset:n.offset,limit:n.limit}):null,t[10]=n.displayName,t[11]=n.isObservationTool,t[12]=n.limit,t[13]=n.offset,t[14]=o,t[15]=d,t[16]=a):a=t[16];let s;t[17]!==n.editAddedLineCount||t[18]!==n.editDeletedLineCount||t[19]!==n.editNewText||t[20]!==n.editOldText||t[21]!==n.fileDisplayName||t[22]!==n.filePath||t[23]!==n.hasEditDiff||t[24]!==n.isEditTool||t[25]!==n.limit||t[26]!==n.offset||t[27]!==n.path||t[28]!==n.toolName||t[29]!==l||t[30]!==m||t[31]!==i?(s=n.fileDisplayName?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(sa,{children:[(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,onClick:n.hasEditDiff?()=>u(!0):m,className:K(`inline-flex max-w-full items-center gap-2 cursor-pointer`,J.caption,`font-mono hover:underline`),children:[(0,$.jsx)(`span`,{className:`truncate max-w-[200px] sm:max-w-[320px]`,children:n.fileDisplayName}),n.toolName===`read`?(0,$.jsx)(cu,{offset:n.offset,limit:n.limit}):null,n.isEditTool?(0,$.jsx)(lu,{added:n.editAddedLineCount,removed:n.editDeletedLineCount}):null]})}),(0,$.jsx)(Qa,{children:n.hasEditDiff?`View diff`:n.filePath?sl(n.filePath,i)??n.filePath:n.fileDisplayName})]}),n.hasEditDiff&&(0,$.jsx)(Cr,{open:l,onOpenChange:u,children:(0,$.jsxs)(tn,{className:`max-w-2xl h-[80vh] flex flex-col`,children:[(0,$.jsx)(_n,{children:(0,$.jsx)(un,{children:(0,$.jsx)(`code`,{className:K(J.caption,`font-mono`),children:sl(n.filePath,i)??n.filePath})})}),(0,$.jsx)(`div`,{className:`overflow-auto flex-1 rounded border border-border bg-muted/30 p-3`,children:(0,$.jsx)(Ll,{oldText:n.editOldText,newText:n.editNewText})})]})})]}):n.path===null?null:(0,$.jsxs)(sa,{children:[(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsx)(`span`,{className:K(J.caption,`font-mono truncate max-w-[200px] sm:max-w-[320px]`),children:n.path})}),(0,$.jsx)(Qa,{children:n.path})]}),t[17]=n.editAddedLineCount,t[18]=n.editDeletedLineCount,t[19]=n.editNewText,t[20]=n.editOldText,t[21]=n.fileDisplayName,t[22]=n.filePath,t[23]=n.hasEditDiff,t[24]=n.isEditTool,t[25]=n.limit,t[26]=n.offset,t[27]=n.path,t[28]=n.toolName,t[29]=l,t[30]=m,t[31]=i,t[32]=s):s=t[32];let c;return t[33]!==r||t[34]!==a||t[35]!==s?(c=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 flex-wrap`,children:[r,a,s]}),t[33]=r,t[34]=a,t[35]=s,t[36]=c):c=t[36],c}let h;t[37]===s?h=t[38]:(h=()=>c(!s),t[37]=s,t[38]=h);let g;t[39]===n.toolInput?g=t[40]:(g=n.toolInput?(0,$.jsx)(`pre`,{className:Ml(),children:n.toolInput}):null,t[39]=n.toolInput,t[40]=g);let _;t[41]!==n.toolId||t[42]!==g?(_=(0,$.jsx)(Xl,{toolId:n.toolId,children:g}),t[41]=n.toolId,t[42]=g,t[43]=_):_=t[43];let v;return t[44]!==n.displayName||t[45]!==n.toolName||t[46]!==s||t[47]!==h||t[48]!==_?(v=(0,$.jsx)(Yl,{expanded:s,onToggle:h,title:n.displayName,tooltip:n.toolName,children:_}),t[44]=n.displayName,t[45]=n.toolName,t[46]=s,t[47]=h,t[48]=_,t[49]=v):v=t[49],v}function du(e){let t=e.replace(/\s+/g,` `).trim();return{fullText:t,label:al(t,50)}}function fu(e){let t=(0,Q.c)(11),{text:n}=e,r;t[0]===n?r=t[1]:(r=du(n),t[0]=n,t[1]=r);let{label:i,fullText:a}=r,o;t[2]===i?o=t[3]:(o=(0,$.jsx)(Hl,{children:i}),t[2]=i,t[3]=o);let s=o;if(i===a)return s;let c;t[4]===s?c=t[5]:(c=(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsx)(`span`,{className:`min-w-0`,children:s})}),t[4]=s,t[5]=c);let l;t[6]===a?l=t[7]:(l=(0,$.jsx)(Qa,{className:`max-w-md break-all font-mono`,children:a}),t[6]=a,t[7]=l);let u;return t[8]!==c||t[9]!==l?(u=(0,$.jsxs)(sa,{children:[c,l]}),t[8]=c,t[9]=l,t[10]=u):u=t[10],u}function pu(e){let t=(0,Q.c)(7),{data:n}=e,r;t[0]===n.webSearchQuery?r=t[1]:(r=n.webSearchQuery!==null&&(0,$.jsx)(fu,{text:n.webSearchQuery}),t[0]=n.webSearchQuery,t[1]=r);let i;t[2]===n.pattern?i=t[3]:(i=n.pattern!==null&&(0,$.jsx)(fu,{text:n.pattern}),t[2]=n.pattern,t[3]=i);let a;return t[4]!==r||t[5]!==i?(a=(0,$.jsxs)($.Fragment,{children:[r,i]}),t[4]=r,t[5]=i,t[6]=a):a=t[6],a}function mu(e){let t=(0,Q.c)(51),{data:n,inline:r,resultContent:i,isActive:a}=e,[o,s]=(0,Z.useState)(!1),[c,l]=(0,Z.useState)(!1),u=n.webSearchQuery??n.pattern??`search`,d;t[0]===u?d=t[1]:(d=du(u),t[0]=u,t[1]=d);let{label:f,fullText:p}=d,m=f!==p;if(r){if(i&&(n.toolName===`find`||n.webSearchQuery!==null||n.pattern!==null)){let e;t[2]!==n.displayName||t[3]!==n.toolName||t[4]!==a?(e=(0,$.jsx)(Wl,{toolName:n.toolName,displayName:n.displayName,isActive:a,className:`shrink-0`}),t[2]=n.displayName,t[3]=n.toolName,t[4]=a,t[5]=e):e=t[5];let r,o;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(r=()=>l(!0),o=K(J.caption,`font-mono hover:underline truncate whitespace-nowrap min-w-0 cursor-pointer text-left`),t[6]=r,t[7]=o):(r=t[6],o=t[7]);let s;t[8]===f?s=t[9]:(s=(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:r,className:o,children:f})}),t[8]=f,t[9]=s);let u=m?p:`View results`,d;t[10]===u?d=t[11]:(d=(0,$.jsx)(Qa,{className:`max-w-md break-all font-mono`,children:u}),t[10]=u,t[11]=d);let h;t[12]!==s||t[13]!==d?(h=(0,$.jsxs)(sa,{children:[s,d]}),t[12]=s,t[13]=d,t[14]=h):h=t[14];let g;t[15]!==e||t[16]!==h?(g=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 min-w-0`,children:[e,h]}),t[15]=e,t[16]=h,t[17]=g):g=t[17];let _;t[18]!==c||t[19]!==i||t[20]!==p?(_=(0,$.jsx)(Nl,{open:c,onOpenChange:l,title:p,content:i}),t[18]=c,t[19]=i,t[20]=p,t[21]=_):_=t[21];let v;return t[22]!==_||t[23]!==g?(v=(0,$.jsxs)($.Fragment,{children:[g,_]}),t[22]=_,t[23]=g,t[24]=v):v=t[24],v}let e;t[25]!==n.displayName||t[26]!==n.toolName||t[27]!==a?(e=(0,$.jsx)(Wl,{toolName:n.toolName,displayName:n.displayName,isActive:a,className:`shrink-0`}),t[25]=n.displayName,t[26]=n.toolName,t[27]=a,t[28]=e):e=t[28];let r;t[29]===n?r=t[30]:(r=(0,$.jsx)(pu,{data:n}),t[29]=n,t[30]=r);let o;t[31]===n.lang?o=t[32]:(o=n.lang!==null&&(0,$.jsx)(`span`,{className:K(J.caption,`px-1.5 py-0.5 rounded bg-muted`),children:n.lang}),t[31]=n.lang,t[32]=o);let s;return t[33]!==e||t[34]!==r||t[35]!==o?(s=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 min-w-0`,children:[e,r,o]}),t[33]=e,t[34]=r,t[35]=o,t[36]=s):s=t[36],s}let h;t[37]===o?h=t[38]:(h=()=>s(!o),t[37]=o,t[38]=h);let g;t[39]===n.toolInput?g=t[40]:(g=n.toolInput?(0,$.jsx)(`pre`,{className:Ml(),children:n.toolInput}):null,t[39]=n.toolInput,t[40]=g);let _;t[41]!==n.toolId||t[42]!==g?(_=(0,$.jsx)(Xl,{toolId:n.toolId,children:g}),t[41]=n.toolId,t[42]=g,t[43]=_):_=t[43];let v;return t[44]!==n.displayName||t[45]!==n.toolName||t[46]!==o||t[47]!==a||t[48]!==h||t[49]!==_?(v=(0,$.jsx)(Yl,{expanded:o,onToggle:h,title:n.displayName,tooltip:n.toolName,isActive:a,children:_}),t[44]=n.displayName,t[45]=n.toolName,t[46]=o,t[47]=a,t[48]=h,t[49]=_,t[50]=v):v=t[50],v}function hu(e,t){let n=e.toLowerCase();return n===`agent`||n.includes(`subagent`)?!0:!!(t&&typeof t==`object`&&`description`in t&&(`prompt`in t||`agentName`in t))}function gu(e){return e.type!==`subagent_event`||!e.subagentEvent?null:_u(e.subagentEvent)}function _u(e){switch(e.type){case`message`:return e.content&&e.isThinking||e.content&&!e.isThinking&&e.role!==`tool`?e.content:e.role===`tool`&&e.content?bu(e.content):null;case`shell_permission`:{let t=e.shellPermission?.command?.trim();return t?`\n⏳ Waiting for shell approval: ${t}\n`:`
|
|
21
|
+
⏳ Waiting for shell approval…
|
|
22
|
+
`}case`web_fetch_permission`:{let t=e.webFetchPermission?.hostname?.trim();return t?`\n⏳ Waiting for approval to fetch ${t}\n`:`
|
|
23
|
+
⏳ Waiting for web fetch approval…
|
|
24
|
+
`}case`error`:return e.content?`\n${e.content}`:null;default:return null}}function vu(e){let t=e.content??``;return typeof t==`string`?t:JSON.stringify(t)}function yu(e,t){switch(t.type){case`message`:{let n=vu(t);return n?t.isThinking?ka(e,`thinking`,n):Xi(n)?Si(e,n):n.trim().startsWith(`[`)?e:ka(e,`content`,n):e}case`result`:{let n=vu(t);return n?Xi(n)?Si(e,n):ka(e,`content`,n):e}case`shell_permission`:return t.shellPermission?fo(e,t.shellPermission):e;case`web_fetch_permission`:return t.webFetchPermission?ro(e,t.webFetchPermission):e;case`error`:{let n=t.content?.trim()||t.error?.message?.trim();return n?ka(e,`content`,`\n\n${n}`):e}default:return e}}function bu(e){try{let t=JSON.parse(e);if(!Array.isArray(t))return null;let n=[];for(let e of t)if(e.type===`tool_use`&&e.name)n.push(`\n→ ${e.name}\n`);else if(e.type===`tool-result`&&e.content){let t=typeof e.content==`string`?e.content.trim():JSON.stringify(e.content),r=t.slice(0,120);if(r){let e=t.length>120?`…`:``;n.push(`✓ ${r}${e}\n`)}}return n.length>0?n.join(``):null}catch{return null}}function xu(e){let t=(0,Z.useRef)([]),n=(0,Z.useRef)(0),r=(0,Z.useRef)(e);r.current!==e&&(r.current=e,t.current=[],n.current=0);let i=X(t=>e?t.subagentTranscripts[e]:void 0),a=i?.length??0;if(i&&a>n.current){let e=t.current;for(let t=n.current;t<a;t++)e=yu(e,i[t]);t.current=e,n.current=a}return a===0&&n.current>0&&(t.current=[],n.current=0),[(0,Z.useMemo)(()=>a===0?null:Ta(t.current),[a]),a>0]}var Su=Oi(e=>(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,$.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1.5 cursor-pointer select-none text-left w-full`,onClick:e.v0,"aria-expanded":e.v1,children:[(0,$.jsx)(`span`,{className:e.v2,children:e.v3}),e.v4,e.v5,e.v6]}),(0,$.jsx)(`div`,{className:e.v7,children:(0,$.jsx)(`div`,{className:`overflow-hidden`,children:e.v8})})]}),{name:`AgentToolBlock_1`,portals:[`v3`,`v4`,`v5`,`v6`,`v8`]}),Cu=Oi(e=>(0,$.jsxs)(`slot`,{children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5 py-0.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:e.v0,className:`inline-flex items-center gap-1 rounded p-0.5 text-muted-foreground hover:text-foreground focus:outline-none focus-visible:ring-2 focus-visible:ring-ring`,"aria-expanded":e.v1,children:[(0,$.jsx)(`span`,{className:e.v2,children:e.v3}),e.v4]}),e.v5,e.v6]}),(0,$.jsx)(`div`,{className:e.v7,children:(0,$.jsx)(`div`,{className:`overflow-hidden`,children:e.v8})})]}),e.v9]}),{name:`AgentToolBlock_2`,portals:[`v3`,`v4`,`v5`,`v6`,`v8`,`v9`]}),wu=Oi(e=>(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5 py-0.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:e.v0,className:`inline-flex items-center gap-1 rounded p-0.5 text-muted-foreground hover:text-foreground focus:outline-none focus-visible:ring-2 focus-visible:ring-ring`,"aria-expanded":e.v1,children:[(0,$.jsx)(`span`,{className:e.v2,children:e.v3}),e.v4]}),e.v5,e.v6]}),(0,$.jsx)(`div`,{className:e.v7,children:(0,$.jsx)(`div`,{className:`overflow-hidden`,children:e.v8})})]}),{name:`AgentToolBlock_3`,portals:[`v3`,`v4`,`v5`,`v6`,`v8`]}),Tu=Oi(e=>(0,$.jsxs)(`slot`,{children:[(0,$.jsxs)(`div`,{className:`overflow-hidden`,children:[e.v0,e.v1]}),e.v2]}),{name:`AgentToolBlock_4`,portals:[`v0`,`v1`,`v2`]}),Eu=function(e){let t=(0,Q.c)(137),{data:n,inline:r,resultContent:i,isActive:a}=e,o=(0,Z.useRef)(null),[s,c]=(0,Z.useState)(!0),[l,u]=(0,Z.useState)(!1),d=(0,Z.useRef)(!!a),f;t[0]===n.toolId?f=t[1]:(f=e=>e.toolCallProgress[n.toolId]?.executionOutput,t[0]=n.toolId,t[1]=f);let p=X(f),m=X(ju),[h,g]=xu(n.toolId),_=!!(h&&h.length>0),v=a?p??i??``:i??p??``,y;t[2]===v?y=t[3]:(y=v?rl(v):``,t[2]=v,t[3]=y);let b=y,x=a?b:``,S;t[4]===n?S=t[5]:(S=Au(n),t[4]=n,t[5]=S);let C=S,w=!!b,T,E;t[6]===a?(T=t[7],E=t[8]):(T=()=>{a&&!d.current&&c(!0),d.current=!!a},E=[a],t[6]=a,t[7]=T,t[8]=E),(0,Z.useEffect)(T,E);let D;t[9]!==s||t[10]!==a?(D=()=>{s&&a&&o.current&&(o.current.scrollTop=o.current.scrollHeight)},t[9]=s,t[10]=a,t[11]=D):D=t[11];let O;if(t[12]!==s||t[13]!==a||t[14]!==x?(O=[s,a,x],t[12]=s,t[13]=a,t[14]=x,t[15]=O):O=t[15],(0,Z.useEffect)(D,O),r){if(a){let e;t[16]===s?e=t[17]:(e=()=>c(!s),t[16]=s,t[17]=e);let r;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(r=(0,$.jsx)(Ul,{size:`sm`}),t[18]=r):r=t[18];let i;t[19]===n.subagentType?i=t[20]:(i=n.subagentType&&(0,$.jsx)(Vl,{type:n.subagentType}),t[19]=n.subagentType,t[20]=i);let l;t[21]===s?l=t[22]:(l=s?(0,$.jsx)(Dr,{className:`h-3 w-3 text-muted-foreground shrink-0`}):(0,$.jsx)(Ut,{className:`h-3 w-3 text-muted-foreground shrink-0`}),t[21]=s,t[22]=l);let u=s?`grid-rows-[1fr]`:`grid-rows-[0fr]`,d;t[23]===u?d=t[24]:(d=K(`grid transition-[grid-template-rows] duration-200 ease-in-out`,u),t[23]=u,t[24]=d);let f;t[25]!==_||t[26]!==a||t[27]!==g||t[28]!==x||t[29]!==m||t[30]!==h?(f=_&&h?(0,$.jsx)(Ou,{scrollRef:o,blocks:h,isStreaming:g&&!!a,threadId:m,className:`ml-5`,style:{maxHeight:`7.5em`}}):(0,$.jsx)(Du,{scrollRef:o,output:x,placeholder:`Running subagent...`,threadId:m,className:`ml-5`,style:{maxHeight:`7.5em`}}),t[25]=_,t[26]=a,t[27]=g,t[28]=x,t[29]=m,t[30]=h,t[31]=f):f=t[31];let p;return t[32]!==s||t[33]!==i||t[34]!==l||t[35]!==d||t[36]!==f||t[37]!==e?(p=(0,$.jsx)(Su,{v0:e,v1:s,v2:J.caption,v3:ku,v4:r,v5:i,v6:l,v7:d,v8:f}),t[32]=s,t[33]=i,t[34]=l,t[35]=d,t[36]=f,t[37]=e,t[38]=p):p=t[38],p}if(b){let e;t[39]===s?e=t[40]:(e=()=>c(!s),t[39]=s,t[40]=e);let r;t[41]===s?r=t[42]:(r=s?(0,$.jsx)(Dr,{className:`h-3.5 w-3.5 shrink-0`}):(0,$.jsx)(Ut,{className:`h-3.5 w-3.5 shrink-0`}),t[41]=s,t[42]=r);let i;t[43]===n.agentName?i=t[44]:(i=n.agentName&&(0,$.jsx)(Bl,{name:n.agentName}),t[43]=n.agentName,t[44]=i);let a;t[45]===n.subagentType?a=t[46]:(a=n.subagentType&&(0,$.jsx)(Vl,{type:n.subagentType}),t[45]=n.subagentType,t[46]=a);let o=s?`grid-rows-[1fr]`:`grid-rows-[0fr]`,d;t[47]===o?d=t[48]:(d=K(`grid transition-[grid-template-rows] duration-200 ease-in-out`,o),t[47]=o,t[48]=d);let f;t[49]===C?f=t[50]:(f=C?(0,$.jsx)(`button`,{type:`button`,onClick:()=>u(!0),className:K(J.caption,`ml-5 block max-w-full text-left whitespace-pre-wrap leading-relaxed text-muted-foreground hover:text-foreground hover:underline focus:outline-none focus-visible:ring-2 focus-visible:ring-ring rounded`),children:C}):(0,$.jsx)(`button`,{type:`button`,onClick:()=>u(!0),className:K(J.caption,`ml-5 text-muted-foreground hover:text-foreground hover:underline focus:outline-none focus-visible:ring-2 focus-visible:ring-ring rounded`),children:`View output`}),t[49]=C,t[50]=f);let p;t[51]!==_||t[52]!==m||t[53]!==h?(p=_&&h?(0,$.jsx)(sf,{blocks:h,isStreaming:!1,threadId:m}):void 0,t[51]=_,t[52]=m,t[53]=h,t[54]=p):p=t[54];let g;t[55]!==l||t[56]!==b||t[57]!==C||t[58]!==p||t[59]!==m?(g=(0,$.jsx)(Fl,{open:l,onOpenChange:u,prompt:C,content:b,markdown:!0,threadId:m,body:p}),t[55]=l,t[56]=b,t[57]=C,t[58]=p,t[59]=m,t[60]=g):g=t[60];let v;return t[61]!==s||t[62]!==i||t[63]!==a||t[64]!==d||t[65]!==f||t[66]!==g||t[67]!==e||t[68]!==r?(v=(0,$.jsx)(Cu,{v0:e,v1:s,v2:J.caption,v3:ku,v4:r,v5:i,v6:a,v7:d,v8:f,v9:g}),t[61]=s,t[62]=i,t[63]=a,t[64]=d,t[65]=f,t[66]=g,t[67]=e,t[68]=r,t[69]=v):v=t[69],v}let e;t[70]===s?e=t[71]:(e=()=>c(!s),t[70]=s,t[71]=e);let r;t[72]===s?r=t[73]:(r=s?(0,$.jsx)(Dr,{className:`h-3.5 w-3.5 shrink-0`}):(0,$.jsx)(Ut,{className:`h-3.5 w-3.5 shrink-0`}),t[72]=s,t[73]=r);let i;t[74]===n.agentName?i=t[75]:(i=n.agentName&&(0,$.jsx)(Bl,{name:n.agentName}),t[74]=n.agentName,t[75]=i);let d;t[76]===n.subagentType?d=t[77]:(d=n.subagentType&&(0,$.jsx)(Vl,{type:n.subagentType}),t[76]=n.subagentType,t[77]=d);let f=s?`grid-rows-[1fr]`:`grid-rows-[0fr]`,p;t[78]===f?p=t[79]:(p=K(`grid transition-[grid-template-rows] duration-200 ease-in-out`,f),t[78]=f,t[79]=p);let v;t[80]===C?v=t[81]:(v=C?(0,$.jsx)(`div`,{className:K(J.caption,`ml-5 whitespace-pre-wrap leading-relaxed text-muted-foreground`),children:C}):null,t[80]=C,t[81]=v);let y;return t[82]!==s||t[83]!==i||t[84]!==d||t[85]!==p||t[86]!==v||t[87]!==e||t[88]!==r?(y=(0,$.jsx)(wu,{v0:e,v1:s,v2:J.caption,v3:ku,v4:r,v5:i,v6:d,v7:p,v8:v}),t[82]=s,t[83]=i,t[84]=d,t[85]=p,t[86]=v,t[87]=e,t[88]=r,t[89]=y):y=t[89],y}let k;t[90]===s?k=t[91]:(k=()=>c(!s),t[90]=s,t[91]=k);let A,j;t[92]===Symbol.for(`react.memo_cache_sentinel`)?(j=K(J.body,`w-full py-2 flex items-center gap-2 font-medium text-foreground hover:bg-muted/50 transition-colors text-left`),A=(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:ku}),t[92]=A,t[93]=j):(A=t[92],j=t[93]);let M;t[94]===n.agentName?M=t[95]:(M=n.agentName&&(0,$.jsx)(Bl,{name:n.agentName}),t[94]=n.agentName,t[95]=M);let N;t[96]===n.subagentType?N=t[97]:(N=n.subagentType&&(0,$.jsx)(Vl,{type:n.subagentType}),t[96]=n.subagentType,t[97]=N);let P;t[98]===a?P=t[99]:(P=a&&(0,$.jsx)(Ul,{size:`md`}),t[98]=a,t[99]=P);let F;t[100]===s?F=t[101]:(F=s?(0,$.jsx)(Dr,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(Ut,{className:`h-4 w-4 shrink-0`}),t[100]=s,t[101]=F);let I;t[102]!==M||t[103]!==N||t[104]!==P||t[105]!==F||t[106]!==k?(I=(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsxs)(`button`,{onClick:k,className:j,children:[A,M,N,P,F]})}),t[102]=M,t[103]=N,t[104]=P,t[105]=F,t[106]=k,t[107]=I):I=t[107];let L;t[108]===n.toolName?L=t[109]:(L=(0,$.jsx)(Qa,{children:n.toolName}),t[108]=n.toolName,t[109]=L);let R;t[110]!==I||t[111]!==L?(R=(0,$.jsxs)(sa,{children:[I,L]}),t[110]=I,t[111]=L,t[112]=R):R=t[112];let z;t[113]!==w||t[114]!==n.toolId||t[115]!==b||t[116]!==s||t[117]!==_||t[118]!==a||t[119]!==g||t[120]!==x||t[121]!==C||t[122]!==m||t[123]!==h?(z=s&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border`,children:[(0,$.jsxs)(`div`,{className:K(J.compact,`text-muted-foreground mb-2 font-mono`),children:[`ID: `,n.toolId]}),_&&h?(0,$.jsx)(Ou,{scrollRef:a?o:void 0,blocks:h,isStreaming:g&&!!a,threadId:m,className:`max-h-96`}):a?(0,$.jsx)(Du,{scrollRef:o,output:x,placeholder:`Running subagent...`,threadId:m,style:{maxHeight:`7.5em`}}):C?w?(0,$.jsx)(`button`,{type:`button`,onClick:()=>u(!0),className:K(Ml({maxHeight:`64`,padding:`3`,leading:!0}),`w-full text-left hover:bg-muted/80 transition-colors`),children:C}):(0,$.jsx)(`div`,{className:Ml({maxHeight:`64`,padding:`3`,leading:!0}),children:C}):b?(0,$.jsx)(Du,{output:b,threadId:m,className:`max-h-64`}):null]}),t[113]=w,t[114]=n.toolId,t[115]=b,t[116]=s,t[117]=_,t[118]=a,t[119]=g,t[120]=x,t[121]=C,t[122]=m,t[123]=h,t[124]=z):z=t[124];let B;t[125]!==w||t[126]!==l||t[127]!==b||t[128]!==_||t[129]!==C||t[130]!==m||t[131]!==h?(B=w?(0,$.jsx)(Fl,{open:l,onOpenChange:u,prompt:C,content:b,markdown:!0,threadId:m,body:_&&h?(0,$.jsx)(sf,{blocks:h,isStreaming:!1,threadId:m}):void 0}):null,t[125]=w,t[126]=l,t[127]=b,t[128]=_,t[129]=C,t[130]=m,t[131]=h,t[132]=B):B=t[132];let ee;return t[133]!==R||t[134]!==z||t[135]!==B?(ee=(0,$.jsx)(Tu,{v0:R,v1:z,v2:B}),t[133]=R,t[134]=z,t[135]=B,t[136]=ee):ee=t[136],ee};function Du(e){let t=(0,Q.c)(13),{output:n,scrollRef:r,placeholder:i,threadId:a,className:o,style:s}=e,c;t[0]===n?c=t[1]:(c=n?Ia(rl(n)):``,t[0]=n,t[1]=c);let l=c,u;t[2]===o?u=t[3]:(u=K(J.caption,`text-muted-foreground/60 overflow-y-auto scrollbar-hide`,o),t[2]=o,t[3]=u);let d;t[4]!==l||t[5]!==i||t[6]!==a?(d=l?(0,$.jsx)(tc,{content:l,compact:!0,threadId:a}):i,t[4]=l,t[5]=i,t[6]=a,t[7]=d):d=t[7];let f;return t[8]!==r||t[9]!==s||t[10]!==u||t[11]!==d?(f=(0,$.jsx)(`div`,{ref:r,className:u,style:s,children:d}),t[8]=r,t[9]=s,t[10]=u,t[11]=d,t[12]=f):f=t[12],f}function Ou(e){let t=(0,Q.c)(11),{blocks:n,isStreaming:r,threadId:i,scrollRef:a,className:o,style:s}=e,c;t[0]===o?c=t[1]:(c=K(`overflow-y-auto scrollbar-hide`,o),t[0]=o,t[1]=c);let l;t[2]!==n||t[3]!==r||t[4]!==i?(l=(0,$.jsx)(sf,{blocks:n,isStreaming:r,threadId:i}),t[2]=n,t[3]=r,t[4]=i,t[5]=l):l=t[5];let u;return t[6]!==a||t[7]!==s||t[8]!==c||t[9]!==l?(u=(0,$.jsx)(`div`,{ref:a,className:c,style:s,children:l}),t[6]=a,t[7]=s,t[8]=c,t[9]=l,t[10]=u):u=t[10],u}var ku=`Subagent`;function Au(e){return e.prompt?.trim()||e.toolInput?.trim()||null}function ju(e){return e.selectedThreadId}function Mu(e){let t=(0,Q.c)(14),{data:n,inline:r,isActive:i}=e,[a,o]=(0,Z.useState)(!1);if(r)return null;let s;t[0]===a?s=t[1]:(s=()=>o(!a),t[0]=a,t[1]=s);let c;t[2]===n.toolInput?c=t[3]:(c=n.toolInput?(0,$.jsx)(`pre`,{className:Ml(),children:n.toolInput}):null,t[2]=n.toolInput,t[3]=c);let l;t[4]!==n.toolId||t[5]!==c?(l=(0,$.jsx)(Xl,{toolId:n.toolId,children:c}),t[4]=n.toolId,t[5]=c,t[6]=l):l=t[6];let u;return t[7]!==n.displayName||t[8]!==n.toolName||t[9]!==a||t[10]!==i||t[11]!==s||t[12]!==l?(u=(0,$.jsx)(Yl,{expanded:a,onToggle:s,title:n.displayName,tooltip:n.toolName,isActive:i,buttonClassName:J.label,children:l}),t[7]=n.displayName,t[8]=n.toolName,t[9]=a,t[10]=i,t[11]=s,t[12]=l,t[13]=u):u=t[13],u}function Nu(e){let t=(0,Q.c)(23),{data:n,inline:r,isActive:i}=e,[a,o]=(0,Z.useState)(!1);if(r){let e;t[0]!==n.displayName||t[1]!==n.toolName||t[2]!==i?(e=(0,$.jsx)(Wl,{toolName:n.toolName,displayName:n.displayName,isActive:i}),t[0]=n.displayName,t[1]=n.toolName,t[2]=i,t[3]=e):e=t[3];let r;t[4]===n.imageGenPrompt?r=t[5]:(r=n.imageGenPrompt!==null&&(0,$.jsxs)(sa,{children:[(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsx)(`span`,{className:K(J.caption,`truncate max-w-[200px] sm:max-w-[320px]`),children:n.imageGenPrompt})}),(0,$.jsx)(Qa,{children:n.imageGenPrompt})]}),t[4]=n.imageGenPrompt,t[5]=r);let a;return t[6]!==e||t[7]!==r?(a=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 flex-wrap`,children:[e,r]}),t[6]=e,t[7]=r,t[8]=a):a=t[8],a}let s;t[9]===a?s=t[10]:(s=()=>o(!a),t[9]=a,t[10]=s);let c;t[11]===n.toolInput?c=t[12]:(c=n.toolInput?(0,$.jsx)(`pre`,{className:Ml(),children:n.toolInput}):null,t[11]=n.toolInput,t[12]=c);let l;t[13]!==n.toolId||t[14]!==c?(l=(0,$.jsx)(Xl,{toolId:n.toolId,children:c}),t[13]=n.toolId,t[14]=c,t[15]=l):l=t[15];let u;return t[16]!==n.displayName||t[17]!==n.toolName||t[18]!==a||t[19]!==i||t[20]!==s||t[21]!==l?(u=(0,$.jsx)(Yl,{expanded:a,onToggle:s,title:n.displayName,tooltip:n.toolName,isActive:i,buttonClassName:J.label,children:l}),t[16]=n.displayName,t[17]=n.toolName,t[18]=a,t[19]=i,t[20]=s,t[21]=l,t[22]=u):u=t[22],u}function Pu(e){if(!e)return null;try{let t=JSON.parse(e);return Is(t,{content:e,...t})}catch{return Is(e,{content:e})}}function Fu(e){return e.savedPath?e.savedPath.split(`/`).pop()??e.savedPath:`image`}function Iu(e){let t=(0,Q.c)(44),{data:n,inline:r,resultContent:i,isActive:a}=e,[o,s]=(0,Z.useState)(!1),[c,l]=(0,Z.useState)(!1),u=X(Lu),d,f;t[0]===i?(d=t[1],f=t[2]):(d=Pu(i),f=d?Fu(d):null,t[0]=i,t[1]=d,t[2]=f);let p=f;if(r){let e;t[3]!==n.displayName||t[4]!==n.toolName||t[5]!==a?(e=(0,$.jsx)(Wl,{toolName:n.toolName,displayName:n.displayName,isActive:a}),t[3]=n.displayName,t[4]=n.toolName,t[5]=a,t[6]=e):e=t[6];let r;t[7]!==n.findImagesQuery||t[8]!==d?(r=n.findImagesQuery!==null&&!d&&(0,$.jsxs)(sa,{children:[(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsx)(`span`,{className:K(J.caption,`truncate max-w-[200px] sm:max-w-[320px]`),children:n.findImagesQuery})}),(0,$.jsx)(Qa,{children:n.findImagesQuery})]}),t[7]=n.findImagesQuery,t[8]=d,t[9]=r):r=t[9];let i;t[10]!==d||t[11]!==p?(i=d&&p&&(0,$.jsxs)(sa,{children:[(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>l(!0),className:K(J.caption,`hover:underline`),children:[`Found `,p]})}),(0,$.jsx)(Qa,{children:`View image`})]}),t[10]=d,t[11]=p,t[12]=i):i=t[12];let o;t[13]!==e||t[14]!==r||t[15]!==i?(o=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 flex-wrap`,children:[e,r,i]}),t[13]=e,t[14]=r,t[15]=i,t[16]=o):o=t[16];let s;t[17]!==c||t[18]!==d||t[19]!==p||t[20]!==u?(s=d&&(0,$.jsx)(Cr,{open:c,onOpenChange:l,children:(0,$.jsxs)(tn,{className:`max-w-3xl max-h-[85vh] flex flex-col overflow-auto`,children:[(0,$.jsx)(_n,{children:(0,$.jsxs)(un,{children:[`Found `,p]})}),(0,$.jsx)(Ps,{imageUrl:d.imageUrl,imageData:d.imageData,threadId:u,alt:p??`Found image`})]})}),t[17]=c,t[18]=d,t[19]=p,t[20]=u,t[21]=s):s=t[21];let f;return t[22]!==o||t[23]!==s?(f=(0,$.jsxs)($.Fragment,{children:[o,s]}),t[22]=o,t[23]=s,t[24]=f):f=t[24],f}let m;t[25]===o?m=t[26]:(m=()=>s(!o),t[25]=o,t[26]=m);let h=d?`Found ${p}`:n.displayName,g;t[27]===n.toolInput?g=t[28]:(g=n.toolInput?(0,$.jsx)(`pre`,{className:Ml(),children:n.toolInput}):null,t[27]=n.toolInput,t[28]=g);let _;t[29]!==d||t[30]!==p||t[31]!==u?(_=d&&(0,$.jsx)(Ps,{imageUrl:d.imageUrl,imageData:d.imageData,threadId:u,alt:p??`Found image`}),t[29]=d,t[30]=p,t[31]=u,t[32]=_):_=t[32];let v;t[33]!==n.toolId||t[34]!==g||t[35]!==_?(v=(0,$.jsxs)(Xl,{toolId:n.toolId,children:[g,_]}),t[33]=n.toolId,t[34]=g,t[35]=_,t[36]=v):v=t[36];let y;return t[37]!==n.toolName||t[38]!==o||t[39]!==a||t[40]!==m||t[41]!==h||t[42]!==v?(y=(0,$.jsx)(Yl,{expanded:o,onToggle:m,title:h,tooltip:n.toolName,isActive:a,children:v}),t[37]=n.toolName,t[38]=o,t[39]=a,t[40]=m,t[41]=h,t[42]=v,t[43]=y):y=t[43],y}function Lu(e){return e.selectedThreadId}function Ru(e){if(!e)return null;try{let t=JSON.parse(e);return t.action===`screenshot`?Is(t,{content:e,...t}):null}catch{return null}}function zu(e){return e.savedPath?e.savedPath.split(`/`).pop()??e.savedPath:`screenshot`}function Bu(e){let t=(0,Q.c)(85),{data:n,inline:r,resultContent:i,isActive:a}=e,[o,s]=(0,Z.useState)(!1),[c,l]=(0,Z.useState)(!1),u=X(Vu),d;t[0]===n.inputObj?d=t[1]:(d=fl(n.inputObj),t[0]=n.inputObj,t[1]=d);let f=d,p;t[2]===n.inputObj?p=t[3]:(p=cl(n.inputObj),t[2]=n.inputObj,t[3]=p);let m=p,h;t[4]===i?h=t[5]:(h=i?ml(i):``,t[4]=i,t[5]=h);let g=h,_,v;t[6]===i?(_=t[7],v=t[8]):(_=Ru(i),v=_?zu(_):null,t[6]=i,t[7]=_,t[8]=v);let y=v;if(r){let e;t[9]!==n.displayName||t[10]!==n.toolName||t[11]!==a?(e=(0,$.jsx)(Wl,{toolName:n.toolName,displayName:n.displayName,isActive:a}),t[9]=n.displayName,t[10]=n.toolName,t[11]=a,t[12]=e):e=t[12];let r;t[13]!==f||t[14]!==i||t[15]!==y||t[16]!==_?(r=_&&y?(0,$.jsxs)(sa,{children:[(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>l(!0),className:K(J.caption,`hover:underline`),children:[`Screenshot `,y]})}),(0,$.jsx)(Qa,{children:`View screenshot`})]}):i?(0,$.jsxs)(sa,{children:[(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:()=>l(!0),className:K(J.caption,`font-mono hover:underline break-all cursor-pointer`),children:f})}),(0,$.jsx)(Qa,{children:`View results`})]}):(0,$.jsx)(`span`,{className:K(J.caption,`font-mono break-all text-muted-foreground`),children:f}),t[13]=f,t[14]=i,t[15]=y,t[16]=_,t[17]=r):r=t[17];let o;t[18]!==e||t[19]!==r?(o=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 flex-wrap`,children:[e,r]}),t[18]=e,t[19]=r,t[20]=o):o=t[20];let s;t[21]!==c||t[22]!==m||t[23]!==f||t[24]!==g||t[25]!==i||t[26]!==y||t[27]!==_||t[28]!==u?(s=_?(0,$.jsx)(Cr,{open:c,onOpenChange:l,children:(0,$.jsxs)(tn,{className:`max-w-3xl max-h-[85vh] flex flex-col overflow-auto`,children:[(0,$.jsx)(_n,{children:(0,$.jsxs)(un,{children:[`Screenshot `,y]})}),(0,$.jsx)(Ps,{imageUrl:_.imageUrl,imageData:_.imageData,threadId:u,alt:y??`Browser screenshot`})]})}):i&&(0,$.jsx)(Il,{open:c,onOpenChange:l,title:f,requestContent:m,responseContent:g}),t[21]=c,t[22]=m,t[23]=f,t[24]=g,t[25]=i,t[26]=y,t[27]=_,t[28]=u,t[29]=s):s=t[29];let d;return t[30]!==o||t[31]!==s?(d=(0,$.jsxs)($.Fragment,{children:[o,s]}),t[30]=o,t[31]=s,t[32]=d):d=t[32],d}let b;t[33]===o?b=t[34]:(b=()=>s(!o),t[33]=o,t[34]=b);let x;t[35]===Symbol.for(`react.memo_cache_sentinel`)?(x=K(J.body,`w-full py-2 flex items-center gap-2 font-medium text-foreground hover:bg-muted/50 transition-colors text-left`),t[35]=x):x=t[35];let S;t[36]===a?S=t[37]:(S=a&&(0,$.jsx)(Ul,{size:`md`}),t[36]=a,t[37]=S);let C=_&&y?`Screenshot ${y}`:n.displayName,w;t[38]===C?w=t[39]:(w=(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:C}),t[38]=C,t[39]=w);let T;t[40]===Symbol.for(`react.memo_cache_sentinel`)?(T=K(J.caption,`font-mono text-muted-foreground truncate max-w-[200px] sm:max-w-[320px]`),t[40]=T):T=t[40];let E;t[41]===f?E=t[42]:(E=(0,$.jsx)(`span`,{className:T,children:f}),t[41]=f,t[42]=E);let D;t[43]!==i||t[44]!==_?(D=i&&!_&&(0,$.jsx)(`button`,{type:`button`,className:K(J.caption,`text-brand hover:underline shrink-0`),onClick:e=>{e.stopPropagation(),l(!0)},children:`View results`}),t[43]=i,t[44]=_,t[45]=D):D=t[45];let O;t[46]===_?O=t[47]:(O=_&&(0,$.jsx)(`button`,{type:`button`,className:K(J.caption,`text-brand hover:underline shrink-0`),onClick:e=>{e.stopPropagation(),l(!0)},children:`View screenshot`}),t[46]=_,t[47]=O);let k;t[48]===o?k=t[49]:(k=o?(0,$.jsx)(Dr,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(Ut,{className:`h-4 w-4 shrink-0`}),t[48]=o,t[49]=k);let A;t[50]!==E||t[51]!==D||t[52]!==O||t[53]!==k||t[54]!==b||t[55]!==S||t[56]!==w?(A=(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsxs)(`button`,{onClick:b,className:x,children:[S,w,E,D,O,k]})}),t[50]=E,t[51]=D,t[52]=O,t[53]=k,t[54]=b,t[55]=S,t[56]=w,t[57]=A):A=t[57];let j;t[58]===n.toolName?j=t[59]:(j=(0,$.jsx)(Qa,{children:n.toolName}),t[58]=n.toolName,t[59]=j);let M;t[60]!==A||t[61]!==j?(M=(0,$.jsxs)(sa,{children:[A,j]}),t[60]=A,t[61]=j,t[62]=M):M=t[62];let N;t[63]!==n.toolId||t[64]!==o||t[65]!==m||t[66]!==g||t[67]!==i||t[68]!==y||t[69]!==_||t[70]!==u?(N=o&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border space-y-2`,children:[(0,$.jsxs)(`div`,{className:K(J.compact,`text-muted-foreground font-mono`),children:[`ID: `,n.toolId]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:K(J.compact,`text-muted-foreground mb-1`),children:`Request`}),(0,$.jsx)(`pre`,{className:Ml(),children:m})]}),_?(0,$.jsx)(Ps,{imageUrl:_.imageUrl,imageData:_.imageData,threadId:u,alt:y??`Browser screenshot`}):i&&(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:K(J.compact,`text-muted-foreground mb-1`),children:`Response`}),(0,$.jsx)(`pre`,{className:Ml({maxHeight:`64`}),children:g})]})]}),t[63]=n.toolId,t[64]=o,t[65]=m,t[66]=g,t[67]=i,t[68]=y,t[69]=_,t[70]=u,t[71]=N):N=t[71];let P;t[72]!==c||t[73]!==m||t[74]!==f||t[75]!==g||t[76]!==i||t[77]!==y||t[78]!==_||t[79]!==u?(P=_?(0,$.jsx)(Cr,{open:c,onOpenChange:l,children:(0,$.jsxs)(tn,{className:`max-w-3xl max-h-[85vh] flex flex-col overflow-auto`,children:[(0,$.jsx)(_n,{children:(0,$.jsxs)(un,{children:[`Screenshot `,y]})}),(0,$.jsx)(Ps,{imageUrl:_.imageUrl,imageData:_.imageData,threadId:u,alt:y??`Browser screenshot`})]})}):i&&(0,$.jsx)(Il,{open:c,onOpenChange:l,title:f,requestContent:m,responseContent:g}),t[72]=c,t[73]=m,t[74]=f,t[75]=g,t[76]=i,t[77]=y,t[78]=_,t[79]=u,t[80]=P):P=t[80];let F;return t[81]!==M||t[82]!==N||t[83]!==P?(F=(0,$.jsxs)(`div`,{className:`overflow-hidden`,children:[M,N,P]}),t[81]=M,t[82]=N,t[83]=P,t[84]=F):F=t[84],F}function Vu(e){return e.selectedThreadId}function Hu(e){let t=(0,Q.c)(10),{summary:n,fullSummary:r}=e,i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=K(J.caption,`font-mono text-muted-foreground truncate max-w-[200px] sm:max-w-[320px]`),t[0]=i):i=t[0];let a;t[1]===n?a=t[2]:(a=(0,$.jsx)(`span`,{className:i,children:n}),t[1]=n,t[2]=a);let o=a;if(n===r)return o;let s;t[3]===o?s=t[4]:(s=(0,$.jsx)(Ya,{asChild:!0,children:o}),t[3]=o,t[4]=s);let c;t[5]===r?c=t[6]:(c=(0,$.jsx)(Qa,{className:`max-w-md break-all font-mono`,children:r}),t[5]=r,t[6]=c);let l;return t[7]!==s||t[8]!==c?(l=(0,$.jsxs)(sa,{children:[s,c]}),t[7]=s,t[8]=c,t[9]=l):l=t[9],l}function Uu(e){let t=(0,Q.c)(40),{data:n,inline:r,isActive:i}=e,[a,o]=(0,Z.useState)(!1),s,c;if(t[0]!==n.inputObj||t[1]!==n.path||t[2]!==n.prompt){let e=n.path===null?[]:[`path`];s=n.prompt===null?dl(n.inputObj,32,e):null,c=n.prompt===null?dl(n.inputObj,1/0,e):null,t[0]=n.inputObj,t[1]=n.path,t[2]=n.prompt,t[3]=s,t[4]=c}else s=t[3],c=t[4];let l=c;if(r){let e=!!(n.prompt??(n.toolInput&&!n.command&&!n.path&&!n.pattern&&!n.fileDisplayName)),r;t[5]!==n.displayName||t[6]!==n.prompt||t[7]!==n.toolId||t[8]!==n.toolInput||t[9]!==n.toolName||t[10]!==e||t[11]!==i?(r=e?(0,$.jsxs)(iu,{children:[(0,$.jsx)(au,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex`,children:(0,$.jsx)(`button`,{type:`button`,className:`inline-flex shrink-0 items-center gap-1 rounded p-0.5 text-muted-foreground hover:text-foreground focus:outline-none focus-visible:ring-2 focus-visible:ring-ring`,"aria-label":`Show tool details`,children:(0,$.jsx)(Wl,{toolName:n.toolName,displayName:n.displayName,isActive:i,muted:!1})})})}),(0,$.jsx)(ou,{className:`w-80 max-h-80 overflow-auto`,align:`start`,children:(0,$.jsxs)(`div`,{className:K(J.bodyMuted,`space-y-2`),children:[(0,$.jsxs)(`div`,{className:`font-mono`,children:[`ID: `,n.toolId]}),n.prompt?(0,$.jsx)(`div`,{className:`whitespace-pre-wrap leading-relaxed`,children:n.prompt}):n.toolInput?(0,$.jsx)(`pre`,{className:`font-mono whitespace-pre-wrap overflow-auto max-h-48`,children:n.toolInput}):null]})})]}):(0,$.jsx)(Wl,{toolName:n.toolName,displayName:n.displayName,isActive:i}),t[5]=n.displayName,t[6]=n.prompt,t[7]=n.toolId,t[8]=n.toolInput,t[9]=n.toolName,t[10]=e,t[11]=i,t[12]=r):r=t[12];let a;t[13]!==l||t[14]!==s?(a=s&&l&&(0,$.jsx)(Hu,{summary:s,fullSummary:l}),t[13]=l,t[14]=s,t[15]=a):a=t[15];let o;t[16]===n.path?o=t[17]:(o=n.path!==null&&(0,$.jsxs)(sa,{children:[(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsx)(`span`,{className:K(J.caption,`font-mono truncate max-w-[200px] sm:max-w-[320px]`),children:n.path})}),(0,$.jsx)(Qa,{children:n.path})]}),t[16]=n.path,t[17]=o);let c;return t[18]!==r||t[19]!==a||t[20]!==o?(c=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 flex-wrap`,children:[r,a,o]}),t[18]=r,t[19]=a,t[20]=o,t[21]=c):c=t[21],c}let u;t[22]===a?u=t[23]:(u=()=>o(!a),t[22]=a,t[23]=u);let d;t[24]===s?d=t[25]:(d=s?(0,$.jsx)(`span`,{className:K(J.caption,`font-mono text-muted-foreground truncate max-w-[200px] sm:max-w-[320px]`),children:s}):void 0,t[24]=s,t[25]=d);let f;t[26]!==n.prompt||t[27]!==n.toolInput?(f=n.prompt?(0,$.jsx)(`div`,{className:Ml({maxHeight:`64`,padding:`3`,leading:!0}),children:n.prompt}):n.toolInput?(0,$.jsx)(`pre`,{className:Ml(),children:n.toolInput}):null,t[26]=n.prompt,t[27]=n.toolInput,t[28]=f):f=t[28];let p;t[29]!==n.toolId||t[30]!==f?(p=(0,$.jsx)(Xl,{toolId:n.toolId,children:f}),t[29]=n.toolId,t[30]=f,t[31]=p):p=t[31];let m;return t[32]!==n.displayName||t[33]!==n.toolName||t[34]!==a||t[35]!==i||t[36]!==u||t[37]!==d||t[38]!==p?(m=(0,$.jsx)(Yl,{expanded:a,onToggle:u,title:n.displayName,tooltip:n.toolName,isActive:i,trailing:d,children:p}),t[32]=n.displayName,t[33]=n.toolName,t[34]=a,t[35]=i,t[36]=u,t[37]=d,t[38]=p,t[39]=m):m=t[39],m}function Wu(e){let t=(0,Q.c)(66),{block:n,inline:r,resultContent:i,resultIsError:a,isActive:o,observation:s}=e,{openChatDockPanel:c}=Yc(),{setPendingExplorerPath:l}=ko(),u=X(Gu),d=yl(n,u),f=!!o,p;t[0]!==c||t[1]!==l?(p=function(e){l(e),c(`explorer`)},t[0]=c,t[1]=l,t[2]=p):p=t[2];let m=p,h;bb0:switch(d.toolType){case`bash`:{let e;t[3]!==d||t[4]!==r||t[5]!==f||t[6]!==i||t[7]!==a?(e=(0,$.jsx)(eu,{data:d,inline:r,resultContent:i,isError:a,isActive:f}),t[3]=d,t[4]=r,t[5]=f,t[6]=i,t[7]=a,t[8]=e):e=t[8],h=e;break bb0}case`fetch`:{let e;t[9]!==d||t[10]!==r||t[11]!==f||t[12]!==i?(e=(0,$.jsx)(tu,{data:d,inline:r,resultContent:i,isActive:f}),t[9]=d,t[10]=r,t[11]=f,t[12]=i,t[13]=e):e=t[13],h=e;break bb0}case`file`:{let e;t[14]!==d||t[15]!==m||t[16]!==r||t[17]!==f||t[18]!==i||t[19]!==u?(e=(0,$.jsx)(uu,{data:d,inline:r,rootPath:u,onOpenFile:m,resultContent:i,isActive:f}),t[14]=d,t[15]=m,t[16]=r,t[17]=f,t[18]=i,t[19]=u,t[20]=e):e=t[20],h=e;break bb0}case`search`:{let e;t[21]!==d||t[22]!==r||t[23]!==f||t[24]!==i?(e=(0,$.jsx)(mu,{data:d,inline:r,resultContent:i,isActive:f}),t[21]=d,t[22]=r,t[23]=f,t[24]=i,t[25]=e):e=t[25],h=e;break bb0}case`agent`:{let e;t[26]!==d||t[27]!==r||t[28]!==f||t[29]!==i?(e=(0,$.jsx)(Eu,{data:d,inline:r,resultContent:i,isActive:f}),t[26]=d,t[27]=r,t[28]=f,t[29]=i,t[30]=e):e=t[30],h=e;break bb0}case`todo`:{let e;t[31]!==d||t[32]!==r||t[33]!==f?(e=(0,$.jsx)(Mu,{data:d,inline:r,isActive:f}),t[31]=d,t[32]=r,t[33]=f,t[34]=e):e=t[34],h=e;break bb0}case`imageGen`:{let e;t[35]!==d||t[36]!==r||t[37]!==f?(e=(0,$.jsx)(Nu,{data:d,inline:r,isActive:f}),t[35]=d,t[36]=r,t[37]=f,t[38]=e):e=t[38],h=e;break bb0}case`findImages`:{let e;t[39]!==d||t[40]!==r||t[41]!==f||t[42]!==i?(e=(0,$.jsx)(Iu,{data:d,inline:r,resultContent:i,isActive:f}),t[39]=d,t[40]=r,t[41]=f,t[42]=i,t[43]=e):e=t[43],h=e;break bb0}case`browser`:{let e;t[44]!==d||t[45]!==r||t[46]!==f||t[47]!==i?(e=(0,$.jsx)(Bu,{data:d,inline:r,resultContent:i,isActive:f}),t[44]=d,t[45]=r,t[46]=f,t[47]=i,t[48]=e):e=t[48],h=e;break bb0}default:{let e;t[49]!==d||t[50]!==r||t[51]!==f?(e=(0,$.jsx)(Uu,{data:d,inline:r,isActive:f}),t[49]=d,t[50]=r,t[51]=f,t[52]=e):e=t[52],h=e}}if(!s)return h;let g=i??``,_;t[53]!==s||t[54]!==g?(_=(0,$.jsx)(Kl,{fallback:g,observation:s}),t[53]=s,t[54]=g,t[55]=_):_=t[55];let v=_;if(r){let e;t[56]===h?e=t[57]:(e=(0,$.jsx)(`div`,{className:`min-w-0`,children:h}),t[56]=h,t[57]=e);let n;return t[58]!==v||t[59]!==e?(n=(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[e,v]}),t[58]=v,t[59]=e,t[60]=n):n=t[60],n}let y;t[61]===v?y=t[62]:(y=(0,$.jsx)(`div`,{className:`mb-3`,children:v}),t[61]=v,t[62]=y);let b;return t[63]!==y||t[64]!==h?(b=(0,$.jsxs)($.Fragment,{children:[h,y]}),t[63]=y,t[64]=h,t[65]=b):b=t[65],b}function Gu(e){return e.projects.find(t=>t.projectId===e.selectedProjectId)?.threads.find(t=>t.threadId===e.selectedThreadId)?.path}var Ku=Pn(`app.todo-list.ui`),qu=(0,Z.createContext)({todos:[],setTodos:()=>{}});function Ju(e){let t=(0,Q.c)(10),{children:n,threadId:r}=e,i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=[],t[0]=i):i=t[0];let[a,o]=(0,Z.useState)(i),s=(0,Z.useRef)(-1),c;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(c=(e,t)=>{t>=s.current&&(s.current=t,o(e))},t[1]=c):c=t[1];let l=c,u;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(u=()=>{s.current=-1,o([])},t[2]=u):u=t[2];let d;t[3]===r?d=t[4]:(d=[r],t[3]=r,t[4]=d),(0,Z.useEffect)(u,d);let f;t[5]===a?f=t[6]:(f={todos:a,setTodos:l},t[5]=a,t[6]=f);let p;return t[7]!==n||t[8]!==f?(p=(0,$.jsx)(qu.Provider,{value:f,children:n}),t[7]=n,t[8]=f,t[9]=p):p=t[9],p}function Yu(e){let t=[e.result,e.content],n=[];for(let e of t)if(typeof e==`string`)n.push(e);else if(Array.isArray(e))for(let t of e)typeof t==`object`&&t&&`text`in t&&typeof t.text==`string`&&n.push(t.text);for(let e of n){let t=e.trim();if(t.startsWith(`{`))try{let e=JSON.parse(t);if(e&&Array.isArray(e.todos))return e.todos}catch(e){Ku.error(`Failed to parse todo JSON:`,e)}}return null}function Xu(e){let t=(0,Q.c)(5),{todos:n,sequence:r}=e,{setTodos:i}=(0,Z.useContext)(qu),a,o;return t[0]!==r||t[1]!==i||t[2]!==n?(a=()=>{i(n,r)},o=[n,i,r],t[0]=r,t[1]=i,t[2]=n,t[3]=a,t[4]=o):(a=t[3],o=t[4]),(0,Z.useEffect)(a,o),null}function Zu(e){let t=(0,Q.c)(90),{block:n,inline:r,sequence:i}=e,a=i===void 0?0:i,[o,s]=(0,Z.useState)(!1),[c,l]=(0,Z.useState)(!1),u=X($u),d=X(Qu),f=n.toolName??`Unknown Tool`,p=n.toolCallId??`unknown`,m=n,h=n.result??m.content,g=Kt(m.observation)?m.observation:void 0,_;t[0]!==m||t[1]!==f?(_=f===`todo`?Yu(m):null,t[0]=m,t[1]=f,t[2]=_):_=t[2];let v=_,y,b,x,S,C,w,T;if(t[3]!==m||t[4]!==r||t[5]!==g||t[6]!==h||t[7]!==u||t[8]!==a||t[9]!==d||t[10]!==v||t[11]!==f){T=Symbol.for(`react.early_return_sentinel`);bb0:{if(b=f===`find_images`?Is(h,m):null,S=sl(vl(h),u),!(S.length>0)&&v===null&&!b){T=null;break bb0}if(y=il(f),typeof h==`object`&&h){let e=h,n=e.returnDisplay??e.return_display;if(typeof n==`string`&&n.trim()){let e;t[19]===n?e=t[20]:(e=n.trim(),t[19]=n,t[20]=e),y=e}else if(f===`read`||f===`file_read`){let n=e.filePath??e.file_path??e.path??``;if(n){let e;t[21]===n?e=t[22]:(e=n.split(`/`).pop()??n,t[21]=n,t[22]=e),y=`Completed ${e}`}}}else if(h==null){let e;t[23]===f?e=t[24]:(e=il(f),t[23]=f,t[24]=e),y=`${e} (no result)`}if(b){let e=b.savedPath?sl(b.savedPath.split(`/`).pop()??b.savedPath,u):null;y=e?`Found ${e}`:`Found image`}if(y=sl(y,u),v!==null){let e;t[25]!==a||t[26]!==v?(e=(0,$.jsx)(Xu,{todos:v,sequence:a}),t[25]=a,t[26]=v,t[27]=e):e=t[27],T=e;break bb0}if(r&&(b||f===`browser`||g)){T=null;break bb0}if(f===`generate_image`){let e;t[28]!==m||t[29]!==h?(e=Fs(h)??Fs(m),t[28]=m,t[29]=h,t[30]=e):e=t[30];let n=e;if(n&&(n.imageUrl||n.imageData)){let e;t[31]!==n.imageData||t[32]!==n.imageUrl||t[33]!==d?(e=(0,$.jsx)(Ps,{imageUrl:n.imageUrl,imageData:n.imageData,threadId:d}),t[31]=n.imageData,t[32]=n.imageUrl,t[33]=d,t[34]=e):e=t[34],T=e;break bb0}}if(r){T=null;break bb0}let e;t[35]===f?e=t[36]:(e=f.toLowerCase().includes(`bash`),t[35]=f,t[36]=e),x=e,C=S?S.split(`
|
|
25
|
+
`):[],w=x?C.slice(0,3).join(`
|
|
26
|
+
`):S}t[3]=m,t[4]=r,t[5]=g,t[6]=h,t[7]=u,t[8]=a,t[9]=d,t[10]=v,t[11]=f,t[12]=y,t[13]=b,t[14]=x,t[15]=S,t[16]=C,t[17]=w,t[18]=T}else y=t[12],b=t[13],x=t[14],S=t[15],C=t[16],w=t[17],T=t[18];if(T!==Symbol.for(`react.early_return_sentinel`))return T;let E=w,D=x&&(g!==void 0||C.length>3),O=g&&g.lineCount>0?`Show full output (${g.lineCount} lines)`:`Show full output…`;if(x){let e;t[37]===Symbol.for(`react.memo_cache_sentinel`)?(e=K(J.body,`px-3 py-2 flex items-center gap-2 font-medium text-foreground`),t[37]=e):e=t[37];let n;t[38]===y?n=t[39]:(n=(0,$.jsx)(`span`,{className:`min-w-0 truncate`,children:y}),t[38]=y,t[39]=n);let r;t[40]!==O||t[41]!==D?(r=D?(0,$.jsxs)(sa,{children:[(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:()=>l(!0),"aria-label":O,className:`inline-flex shrink-0 rounded p-0.5 text-muted-foreground hover:bg-muted hover:text-brand`,children:(0,$.jsx)(oe,{className:`h-3.5 w-3.5`})})}),(0,$.jsx)(Qa,{children:O})]}):null,t[40]=O,t[41]=D,t[42]=r):r=t[42];let i;t[43]!==n||t[44]!==r?(i=(0,$.jsxs)(`div`,{className:e,children:[n,r]}),t[43]=n,t[44]=r,t[45]=i):i=t[45];let a;t[46]!==D||t[47]!==E||t[48]!==S?(a=S&&(0,$.jsx)(`div`,{className:`px-3 pb-2 bg-background border-t border-border`,children:D?(0,$.jsxs)(sa,{children:[(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsxs)(`pre`,{className:K(J.caption,`bg-muted p-2 rounded font-mono whitespace-pre-wrap overflow-auto text-foreground text-left mt-2 cursor-pointer hover:bg-muted/80`),onClick:()=>l(!0),children:[E,(0,$.jsxs)(`span`,{className:`text-muted-foreground`,children:[`
|
|
27
|
+
`,`...`]})]})}),(0,$.jsx)(Qa,{children:`Show full output…`})]}):(0,$.jsx)(`pre`,{className:K(J.caption,`bg-muted p-2 rounded font-mono whitespace-pre-wrap overflow-auto text-foreground text-left mt-2`),children:E})}),t[46]=D,t[47]=E,t[48]=S,t[49]=a):a=t[49];let o;t[50]!==i||t[51]!==a?(o=(0,$.jsxs)(`div`,{className:`mb-3 rounded-lg border border-border bg-muted/50 overflow-hidden`,children:[i,a]}),t[50]=i,t[51]=a,t[52]=o):o=t[52];let s;t[53]!==c||t[54]!==D||t[55]!==g||t[56]!==S||t[57]!==u||t[58]!==d?(s=D&&(0,$.jsx)(Cr,{open:c,onOpenChange:l,children:(0,$.jsxs)(tn,{className:`max-w-3xl max-h-[80vh] flex flex-col`,children:[(0,$.jsx)(_n,{children:(0,$.jsx)(un,{children:`Full Output`})}),(0,$.jsx)(Gl,{enabled:c,fallback:S,observation:g,rootPath:u,threadId:d,className:K(J.caption,`bg-muted p-3 rounded font-mono whitespace-pre-wrap overflow-auto flex-1 text-foreground`)})]})}),t[53]=c,t[54]=D,t[55]=g,t[56]=S,t[57]=u,t[58]=d,t[59]=s):s=t[59];let f;return t[60]!==o||t[61]!==s?(f=(0,$.jsxs)($.Fragment,{children:[o,s]}),t[60]=o,t[61]=s,t[62]=f):f=t[62],f}let k;t[63]===o?k=t[64]:(k=()=>s(!o),t[63]=o,t[64]=k);let A;t[65]===Symbol.for(`react.memo_cache_sentinel`)?(A=K(J.body,`w-full px-3 py-2 flex items-center gap-2 font-medium text-foreground hover:bg-muted transition-colors text-left`),t[65]=A):A=t[65];let j;t[66]===y?j=t[67]:(j=(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:y}),t[66]=y,t[67]=j);let M;t[68]===o?M=t[69]:(M=o?(0,$.jsx)(Dr,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(Ut,{className:`h-4 w-4 shrink-0`}),t[68]=o,t[69]=M);let N;t[70]!==k||t[71]!==j||t[72]!==M?(N=(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsxs)(`button`,{onClick:k,className:A,children:[j,M]})}),t[70]=k,t[71]=j,t[72]=M,t[73]=N):N=t[73];let P=`${f} result`,F;t[74]===P?F=t[75]:(F=(0,$.jsx)(Qa,{children:P}),t[74]=P,t[75]=F);let I;t[76]!==F||t[77]!==N?(I=(0,$.jsxs)(sa,{children:[N,F]}),t[76]=F,t[77]=N,t[78]=I):I=t[78];let L;t[79]!==o||t[80]!==b||t[81]!==g||t[82]!==S||t[83]!==u||t[84]!==d||t[85]!==p?(L=o&&(0,$.jsxs)(`div`,{className:`px-3 py-2 bg-background border-t border-border`,children:[(0,$.jsxs)(`div`,{className:K(J.compact,`text-muted-foreground mb-2 font-mono`),children:[`Call ID: `,p]}),b&&(0,$.jsx)(Ps,{imageUrl:b.imageUrl,imageData:b.imageData,threadId:d}),S&&!b&&(0,$.jsx)(Gl,{enabled:o,fallback:S,observation:g,rootPath:u,threadId:d,className:K(J.caption,`bg-muted p-2 rounded font-mono whitespace-pre-wrap overflow-auto max-h-48 text-foreground text-left`)})]}),t[79]=o,t[80]=b,t[81]=g,t[82]=S,t[83]=u,t[84]=d,t[85]=p,t[86]=L):L=t[86];let R;return t[87]!==I||t[88]!==L?(R=(0,$.jsxs)(`div`,{className:`mb-3 rounded-lg border border-border bg-muted/50 overflow-hidden`,children:[I,L]}),t[87]=I,t[88]=L,t[89]=R):R=t[89],R}function Qu(e){return e.selectedThreadId}function $u(e){return e.projects.find(t=>t.projectId===e.selectedProjectId)?.threads.find(t=>t.threadId===e.selectedThreadId)?.path}var ed=Oi(e=>(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,$.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1.5 cursor-pointer select-none text-left w-full`,onClick:e.v0,"aria-expanded":e.v1,children:[e.v2,(0,$.jsx)(`span`,{className:e.v3,children:e.v4}),e.v5]}),(0,$.jsx)(`div`,{className:e.v6,children:(0,$.jsx)(`div`,{className:`overflow-hidden`,children:e.v7})})]}),{name:`ThinkingBlock_1`,portals:[`v2`,`v4`,`v5`,`v7`]}),td=function(e){let t=(0,Q.c)(42),{text:n,isStreaming:r,label:i,threadId:a}=e,o=n===void 0?``:n,s=r===void 0?!1:r,c=(0,Z.useRef)(null),l;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(l=Date.now(),t[0]=l):l=t[0];let u=(0,Z.useRef)(l),[d,f]=(0,Z.useState)(0),[p,m]=(0,Z.useState)(!1),h=(0,Z.useRef)(s),g,_;t[1]===s?(g=t[2],_=t[3]):(g=()=>{s&&!h.current?(u.current=Date.now(),f(0)):h.current&&!s&&(f(Date.now()-u.current),m(!1)),h.current=s},_=[s],t[1]=s,t[2]=g,t[3]=_),(0,Z.useEffect)(g,_);let v;t[4]!==p||t[5]!==s?(v=()=>{p&&s&&c.current&&(c.current.scrollTop=c.current.scrollHeight)},t[4]=p,t[5]=s,t[6]=v):v=t[6];let y;if(t[7]!==p||t[8]!==s||t[9]!==o?(y=[o,p,s],t[7]=p,t[8]=s,t[9]=o,t[10]=y):y=t[10],(0,Z.useEffect)(v,y),!o&&!s||!s&&d<=0&&i!==`MCP`&&i!==`Validated`)return null;let b=!s&&i===`Validated`,x;t[11]!==d||t[12]!==s||t[13]!==i||t[14]!==o?(x=id(s,i,d,rn(o)),t[11]=d,t[12]=s,t[13]=i,t[14]=o,t[15]=x):x=t[15];let S=x,C;t[16]!==p||t[17]!==o?(C=p&&o?Ia(rl(o)):``,t[16]=p,t[17]=o,t[18]=C):C=t[18];let w=C,T;t[19]===p?T=t[20]:(T=()=>m(!p),t[19]=p,t[20]=T);let E;t[21]===b?E=t[22]:(E=b?(0,$.jsx)(Nt,{className:`h-3.5 w-3.5 shrink-0 text-green-600`}):null,t[21]=b,t[22]=E);let D;t[23]===p?D=t[24]:(D=p?(0,$.jsx)(Dr,{className:`h-3 w-3 text-muted-foreground shrink-0`}):(0,$.jsx)(Ut,{className:`h-3 w-3 text-muted-foreground shrink-0`}),t[23]=p,t[24]=D);let O=p?`grid-rows-[1fr]`:`grid-rows-[0fr]`,k;t[25]===O?k=t[26]:(k=[`grid transition-[grid-template-rows] duration-200 ease-in-out`,O],t[25]=O,t[26]=k);let A=k.join(` `),j,M;t[27]===Symbol.for(`react.memo_cache_sentinel`)?(j=K(J.caption,`ml-5 text-muted-foreground/60 overflow-y-auto scrollbar-hide`),M={maxHeight:`7.5em`},t[27]=j,t[28]=M):(j=t[27],M=t[28]);let N;t[29]!==w||t[30]!==a?(N=w?(0,$.jsx)(tc,{content:w,compact:!0,threadId:a}):null,t[29]=w,t[30]=a,t[31]=N):N=t[31];let P;t[32]===N?P=t[33]:(P=(0,$.jsx)(`div`,{ref:c,className:j,style:M,children:N}),t[32]=N,t[33]=P);let F;return t[34]!==p||t[35]!==S||t[36]!==T||t[37]!==E||t[38]!==D||t[39]!==A||t[40]!==P?(F=(0,$.jsx)(ed,{v0:T,v1:p,v2:E,v3:J.caption,v4:S,v5:D,v6:A,v7:P}),t[34]=p,t[35]=S,t[36]=T,t[37]=E,t[38]=D,t[39]=A,t[40]=P,t[41]=F):F=t[41],F};function nd(e){if(e<1e3){let t=Math.max(1,Math.round(e));return`${t} millisecond${t===1?``:`s`}`}let t=Math.max(1,Math.round(e/1e3));if(t<60)return`${t} second${t===1?``:`s`}`;let n=Math.floor(t/60),r=t%60;return r===0?`${n} minute${n===1?``:`s`}`:`${n} minute${n===1?``:`s`} ${r} second${r===1?``:`s`}`}function rd(e){return` ${e.toLocaleString()} token${e===1?``:`s`}`}function id(e,t,n,r){let i=e&&r>0?rd(r):``;return e?t===`MCP`?`Connecting MCP servers...${i}`:t===`Validating`?`Validating...${i}`:`Thinking...${i}`:t===`MCP`?`MCP setup complete.`:t===`Validated`?`Validated`:n<=0?`Thought complete.`:`Thought for ${nd(n)}.`}function ad(e){let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n)|0;return`${t}-${e.length}`}function od(e){if(typeof e.executionOutput==`string`)return e.executionOutput;let t=e.partial?.content?.[0]?.arguments;if(!(!t||typeof t!=`object`)&&`content`in t&&typeof t.content==`string`)return t.content}function sd(e,t){let n=e.find(e=>io(e)&&e.toolCallId===t);if(!n)return;let r=n,i=r.result??r.content;if(i!=null){if(typeof i==`string`){if(r.imageUrl&&i.trim().startsWith(`{`))try{let e=JSON.parse(i);if(!e.imageUrl)return JSON.stringify({...e,imageUrl:r.imageUrl})}catch{}return i}return JSON.stringify(i,null,2)}}function cd(e,t){let n=e.find(e=>io(e)&&e.toolCallId===t);if(!(!n||!Kt(n.observation)))return n.observation}function ld(e,t){return e.find(e=>io(e)&&e.toolCallId===t)?.isError===!0}function ud(e,t){return e.some(e=>io(e)&&e.toolCallId===t)}function dd(e,t,n,r,i){return ud(e,n)?!1:r===n?!0:!!(t?.isThinking||t===void 0&&i)}function fd(e,t){if(t)return sd(e,t)}var pd=Oi(e=>(0,$.jsxs)(`div`,{className:`rounded-lg border-t border-border p-4 my-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-2 mb-2`,children:[e.v0,(0,$.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,$.jsx)(`div`,{className:e.v1,children:e.v2}),e.v3]})]}),(0,$.jsxs)(`div`,{className:e.v4,children:[(0,$.jsxs)(`span`,{className:`font-medium`,children:[e.v5,`:`]}),` `,(0,$.jsx)(`span`,{children:e.v6})]})]}),{name:`AskUserBlock_1`,portals:[`v0`,`v2`,`v3`,`v5`,`v6`]}),md=Oi(e=>(0,$.jsx)(`div`,{className:`rounded-lg border-t border-border p-4 my-2`,children:(0,$.jsxs)(`div`,{className:`flex items-start gap-2`,children:[e.v0,(0,$.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,$.jsx)(`div`,{className:e.v1,children:e.v2}),e.v3,(0,$.jsx)(`p`,{className:e.v4,children:e.v5})]})]})}),{name:`AskUserBlock_2`,portals:[`v0`,`v2`,`v3`,`v5`]}),hd=Oi(e=>(0,$.jsxs)(`div`,{className:`rounded-lg border-t border-border p-4 my-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-2 mb-3`,children:[e.v0,(0,$.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,$.jsx)(`div`,{className:e.v1,children:e.v2}),e.v3]})]}),e.v4,(0,$.jsxs)(`form`,{onSubmit:e.v5,className:`flex flex-col rounded-2xl border border-border focus-within:ring-2 focus-within:ring-brand`,children:[(0,$.jsx)(`input`,{type:`text`,value:e.v6,onChange:e.v7,placeholder:e.v8,disabled:e.v9,className:`w-full bg-transparent px-4 pt-3 pb-1 text-base text-foreground placeholder:text-muted-foreground focus:outline-none disabled:opacity-50`}),(0,$.jsx)(`div`,{className:`flex items-center justify-end px-3 pb-2`,children:(0,$.jsx)(`button`,{type:`submit`,disabled:e.v10,className:`h-7 w-7 rounded-full bg-primary text-primary-foreground hover:bg-primary/90 transition-colors disabled:opacity-50 flex items-center justify-center shrink-0`,children:e.v11})})]})]}),{name:`AskUserBlock_3`,portals:[`v0`,`v2`,`v3`,`v4`,`v11`]}),gd=function(e){let t=(0,Q.c)(62),{toolCallId:n,question:r,options:i,context:a,answeredText:o,answeredLabel:s,interactive:c,respondViaTelegram:l}=e,u=c===void 0?!0:c,d=l===void 0?!1:l,[f,p]=(0,Z.useState)(``),[m,h]=(0,Z.useState)(!!o),[g,_]=(0,Z.useState)(o??``),[v,y]=(0,Z.useState)(!1),[b,x]=(0,Z.useState)(null),S,C;t[0]===o?(S=t[1],C=t[2]):(S=()=>{let e=o?.trim();if(e){h(!0),_(e),y(!1),x(null);return}h(!1),_(``)},C=[o],t[0]=o,t[1]=S,t[2]=C),(0,Z.useEffect)(S,C);let w;t[3]!==v||t[4]!==n?(w=async e=>{if(!(!e.trim()||v)){y(!0);try{await lr(n,e.trim()),_(e.trim()),h(!0)}catch(e){let t=e;_d.error(`Failed to submit answer`,{err:t}),y(!1),x(null)}}},t[3]=v,t[4]=n,t[5]=w):w=t[5];let T=w,E;t[6]!==T||t[7]!==v||t[8]!==m?(E=e=>{m||v||(x(e),T(e))},t[6]=T,t[7]=v,t[8]=m,t[9]=E):E=t[9];let D=E,O;if(t[10]!==f||t[11]!==T||t[12]!==v||t[13]!==m){let e=function(){if(m||v)return;let e=f.trim();e&&T(e)};O=function(t){t.preventDefault(),e()},t[10]=f,t[11]=T,t[12]=v,t[13]=m,t[14]=O}else O=t[14];let k=O;if(m){let e,n;t[15]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(Xt,{className:`h-5 w-5 text-brand shrink-0 mt-0.5`}),n=K(J.label,`text-foreground`),t[15]=e,t[16]=n):(e=t[15],n=t[16]);let i;t[17]===r?i=t[18]:(i=(0,$.jsx)(tc,{content:r}),t[17]=r,t[18]=i);let o;t[19]===a?o=t[20]:(o=a&&(0,$.jsx)(`p`,{className:K(J.bodyMuted,`mt-1`),children:a}),t[19]=a,t[20]=o);let c=s??`You answered`,l;return t[21]!==g||t[22]!==i||t[23]!==o||t[24]!==c?(l=(0,$.jsx)(pd,{v0:e,v1:n,v2:i,v3:o,v4:J.bodyMuted,v5:c,v6:g}),t[21]=g,t[22]=i,t[23]=o,t[24]=c,t[25]=l):l=t[25],l}if(!u){let e,n;t[26]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(wn,{className:`h-5 w-5 text-brand shrink-0 mt-0.5`}),n=K(J.label,`text-foreground`),t[26]=e,t[27]=n):(e=t[26],n=t[27]);let i;t[28]===r?i=t[29]:(i=(0,$.jsx)(tc,{content:r}),t[28]=r,t[29]=i);let o;t[30]===a?o=t[31]:(o=a&&(0,$.jsx)(`p`,{className:K(J.bodyMuted,`mt-1`),children:a}),t[30]=a,t[31]=o);let s;t[32]===Symbol.for(`react.memo_cache_sentinel`)?(s=K(J.bodyMuted,`mt-2`),t[32]=s):s=t[32];let c=d?`Answer in Telegram to continue.`:`Respond below to continue.`,l;return t[33]!==i||t[34]!==o||t[35]!==c?(l=(0,$.jsx)(md,{v0:e,v1:n,v2:i,v3:o,v4:s,v5:c}),t[33]=i,t[34]=o,t[35]=c,t[36]=l):l=t[36],l}let A,j;t[37]===Symbol.for(`react.memo_cache_sentinel`)?(A=(0,$.jsx)(wn,{className:`h-5 w-5 text-brand shrink-0 mt-0.5`}),j=K(J.label,`text-foreground`),t[37]=A,t[38]=j):(A=t[37],j=t[38]);let M;t[39]===r?M=t[40]:(M=(0,$.jsx)(tc,{content:r}),t[39]=r,t[40]=M);let N;t[41]===a?N=t[42]:(N=a&&(0,$.jsx)(`p`,{className:K(J.bodyMuted,`mt-1`),children:a}),t[41]=a,t[42]=N);let P;t[43]!==D||t[44]!==v||t[45]!==i||t[46]!==b?(P=i&&i.length>0&&(0,$.jsx)(`div`,{className:`flex flex-wrap gap-2 mb-3`,children:i.map(e=>{let t=b===e;return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>D(e),disabled:v,className:K(`rounded-md border px-3 py-1.5 transition-colors disabled:opacity-50 flex items-center gap-1.5`,J.label,t?`border-foreground/20 bg-accent text-accent-foreground`:`border-foreground/20 bg-background text-foreground hover:bg-accent hover:text-accent-foreground`),children:[t&&(0,$.jsx)(Xt,{className:`h-3.5 w-3.5 text-foreground`}),e]},e)})}),t[43]=D,t[44]=v,t[45]=i,t[46]=b,t[47]=P):P=t[47];let F;t[48]===Symbol.for(`react.memo_cache_sentinel`)?(F=e=>p(e.target.value),t[48]=F):F=t[48];let I=i?.length?`Or type a custom answer...`:`Type your answer...`,L;t[49]!==f||t[50]!==v?(L=v||!f.trim(),t[49]=f,t[50]=v,t[51]=L):L=t[51];let R;t[52]===Symbol.for(`react.memo_cache_sentinel`)?(R=(0,$.jsx)(gn,{className:`h-3 w-3`}),t[52]=R):R=t[52];let z;return t[53]!==f||t[54]!==k||t[55]!==v||t[56]!==M||t[57]!==N||t[58]!==P||t[59]!==I||t[60]!==L?(z=(0,$.jsx)(hd,{v0:A,v1:j,v2:M,v3:N,v4:P,v5:k,v6:f,v7:F,v8:I,v9:v,v10:L,v11:R}),t[53]=f,t[54]=k,t[55]=v,t[56]=M,t[57]=N,t[58]=P,t[59]=I,t[60]=L,t[61]=z):z=t[61],z},_d=Pn(`chat.ask-user`),vd=Oi(e=>(0,$.jsxs)(`div`,{className:`rounded-lg border border-border p-4 my-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-2 mb-2`,children:[e.v0,(0,$.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,$.jsx)(`div`,{className:e.v1,children:e.v2}),e.v3]})]}),(0,$.jsx)(`div`,{className:e.v4,children:e.v5})]}),{name:`PermissionPromptBlock_1`,portals:[`v0`,`v2`,`v3`,`v5`]}),yd=Oi(e=>(0,$.jsxs)(`div`,{className:`rounded-lg border border-border p-4 my-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-2 mb-3`,children:[e.v0,(0,$.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,$.jsx)(`div`,{className:e.v1,children:e.v2}),e.v3]})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsxs)(`div`,{className:`inline-flex rounded-md shadow-sm`,children:[e.v4,e.v5]}),e.v6]})]}),{name:`PermissionPromptBlock_2`,portals:[`v0`,`v2`,`v3`,`v4`,`v5`,`v6`]}),bd=function(e){let t=(0,Q.c)(42),{icon:n,promptTitle:r,skippedTitle:i,detail:a,wildcardOptions:o,secondaryButtonLabel:s,resolvedDecision:c,successLabel:l,onAllowOnce:u,onAllowWildcard:d,onSecondary:f}=e,p=l===void 0?`Allowed`:l,[m,h]=(0,Z.useState)(!!c),[g,_]=(0,Z.useState)(c??null),[v,y]=(0,Z.useState)(!1),b,x;t[0]===c?(b=t[1],x=t[2]):(b=()=>{c&&(h(!0),_(c),y(!1))},x=[c],t[0]=c,t[1]=b,t[2]=x),(0,Z.useEffect)(b,x);let S;t[3]!==v||t[4]!==u||t[5]!==m?(S=async function(){if(!(v||m)){y(!0);try{await u(),h(!0),_(`allowed`)}catch(e){let t=e;xd.error(`Failed to submit permission response:`,t),y(!1)}}},t[3]=v,t[4]=u,t[5]=m,t[6]=S):S=t[6];let C=S,w;t[7]!==v||t[8]!==d||t[9]!==m?(w=async function(e){if(!(v||m)){y(!0);try{await d(e),h(!0),_(`allowed`)}catch(e){let t=e;xd.error(`Failed to submit permission response:`,t),y(!1)}}},t[7]=v,t[8]=d,t[9]=m,t[10]=w):w=t[10];let T=w,E;t[11]!==v||t[12]!==f||t[13]!==m?(E=async function(){if(!(v||m)){y(!0);try{await f(),h(!0),_(`skipped`)}catch(e){let t=e;xd.error(`Failed to submit permission response:`,t),y(!1)}}},t[11]=v,t[12]=f,t[13]=m,t[14]=E):E=t[14];let D=E;if(m){let e;t[15]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(Xt,{className:`h-5 w-5 text-brand shrink-0 mt-0.5`}),t[15]=e):e=t[15];let n=g===`skipped`?i:r,o=g===`skipped`?`Skipped`:p,s;return t[16]!==a||t[17]!==n||t[18]!==o?(s=(0,$.jsx)(vd,{v0:e,v1:J.label,v2:n,v3:a,v4:J.bodyMuted,v5:o}),t[16]=a,t[17]=n,t[18]=o,t[19]=s):s=t[19],s}let O;t[20]===C?O=t[21]:(O=()=>void C(),t[20]=C,t[21]=O);let k;t[22]!==v||t[23]!==O?(k=(0,$.jsx)(Fe,{type:`button`,size:`sm`,disabled:v,onClick:O,className:`rounded-r-none`,children:`Allow`}),t[22]=v,t[23]=O,t[24]=k):k=t[24];let A;t[25]!==T||t[26]!==v||t[27]!==o?(A=o.length>0&&(0,$.jsxs)(fa,{children:[(0,$.jsx)(Ji,{asChild:!0,children:(0,$.jsx)(Fe,{type:`button`,size:`sm`,disabled:v,className:K(`rounded-l-none border-l border-primary-foreground/20 px-2`),"aria-label":`More allow options`,children:(0,$.jsx)(Dr,{className:`h-4 w-4`})})}),(0,$.jsx)(Ei,{align:`end`,className:`max-w-md`,children:o.map(e=>(0,$.jsx)(ya,{onClick:()=>void T(e),children:e.label},`${e.scope}-${e.pattern}`))})]}),t[25]=T,t[26]=v,t[27]=o,t[28]=A):A=t[28];let j;t[29]===D?j=t[30]:(j=()=>void D(),t[29]=D,t[30]=j);let M;t[31]!==v||t[32]!==s||t[33]!==j?(M=(0,$.jsx)(Fe,{type:`button`,size:`sm`,variant:`outline`,disabled:v,onClick:j,children:s}),t[31]=v,t[32]=s,t[33]=j,t[34]=M):M=t[34];let N;return t[35]!==a||t[36]!==n||t[37]!==r||t[38]!==M||t[39]!==k||t[40]!==A?(N=(0,$.jsx)(yd,{v0:n,v1:J.label,v2:r,v3:a,v4:k,v5:A,v6:M}),t[35]=a,t[36]=n,t[37]=r,t[38]=M,t[39]=k,t[40]=A,t[41]=N):N=t[41],N},xd=Pn(`app.permission-prompt-block.ui`);function Sd(e){let t=(0,Q.c)(3),{command:n}=e,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=K(J.mono,J.bodyMuted,`mt-2 block break-all rounded bg-muted/60 px-2 py-1`),t[0]=r):r=t[0];let i;return t[1]===n?i=t[2]:(i=(0,$.jsx)(`code`,{className:r,children:n}),t[1]=n,t[2]=i),i}function Cd(e){let t=(0,Q.c)(16),{toolCallId:n,command:r,projectId:i,wildcardOptions:a,resolvedDecision:o}=e,s;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(s=(0,$.jsx)(Tn,{className:`h-5 w-5 text-brand shrink-0 mt-0.5`}),t[0]=s):s=t[0];let c;t[1]===r?c=t[2]:(c=(0,$.jsx)(Sd,{command:r}),t[1]=r,t[2]=c);let l,u;t[3]!==i||t[4]!==n?(l=()=>Mt(n,`allow_once`,{projectId:i??void 0}),u=e=>Mt(n,e.scope===`project`?`allow_pattern_project`:`allow_pattern_session`,{pattern:e.pattern,projectId:i??void 0}),t[3]=i,t[4]=n,t[5]=l,t[6]=u):(l=t[5],u=t[6]);let d;t[7]===n?d=t[8]:(d=()=>Mt(n,`skip`),t[7]=n,t[8]=d);let f;return t[9]!==o||t[10]!==c||t[11]!==l||t[12]!==u||t[13]!==d||t[14]!==a?(f=(0,$.jsx)(bd,{icon:s,promptTitle:`Allow the agent to run this command?`,skippedTitle:`Shell command permission`,detail:c,wildcardOptions:a,secondaryButtonLabel:`Skip`,resolvedDecision:o,successLabel:`Allowed`,onAllowOnce:l,onAllowWildcard:u,onSecondary:d}),t[9]=o,t[10]=c,t[11]=l,t[12]=u,t[13]=d,t[14]=a,t[15]=f):f=t[15],f}function wd(e){let t=(0,Q.c)(9),{hostname:n,url:r}=e,i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=K(J.mono,J.bodyMuted,`mt-2 block break-all rounded bg-muted/60 px-2 py-1`),t[0]=i):i=t[0];let a;t[1]===n?a=t[2]:(a=(0,$.jsx)(`code`,{className:i,children:n}),t[1]=n,t[2]=a);let o;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(o=K(J.caption,J.bodyMuted,`mt-1 break-all`),t[3]=o):o=t[3];let s;t[4]===r?s=t[5]:(s=(0,$.jsx)(`div`,{className:o,children:r}),t[4]=r,t[5]=s);let c;return t[6]!==a||t[7]!==s?(c=(0,$.jsxs)($.Fragment,{children:[a,s]}),t[6]=a,t[7]=s,t[8]=c):c=t[8],c}function Td(e){let t=(0,Q.c)(15),{toolCallId:n,hostname:r,url:i,wildcardOptions:a,resolvedDecision:o}=e,s;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(s=(0,$.jsx)(x,{className:`h-5 w-5 text-brand shrink-0 mt-0.5`}),t[0]=s):s=t[0];let c;t[1]!==r||t[2]!==i?(c=(0,$.jsx)(wd,{hostname:r,url:i}),t[1]=r,t[2]=i,t[3]=c):c=t[3];let l,u,d;t[4]===n?(l=t[5],u=t[6],d=t[7]):(l=()=>Zn(n,`allow_once`),u=e=>Zn(n,e.scope===`project`?`allow_domain_project`:`allow_domain_session`),d=()=>Zn(n,`skip`),t[4]=n,t[5]=l,t[6]=u,t[7]=d);let f;return t[8]!==o||t[9]!==c||t[10]!==l||t[11]!==u||t[12]!==d||t[13]!==a?(f=(0,$.jsx)(bd,{icon:s,promptTitle:`Allow the agent to fetch from this domain?`,skippedTitle:`Web fetch permission`,detail:c,wildcardOptions:a,secondaryButtonLabel:`Deny`,resolvedDecision:o,successLabel:`Allowed`,onAllowOnce:l,onAllowWildcard:u,onSecondary:d}),t[8]=o,t[9]=c,t[10]=l,t[11]=u,t[12]=d,t[13]=a,t[14]=f):f=t[14],f}var Ed=new Map,Dd=Pn(`browser.js-executor`),Od=new Map;function kd(e){return Ed.get(e)}function Ad(e,t){let n=Od.get(e);return n||(n=new Set,Od.set(e,n)),n.add(t),()=>{n.delete(t),n.size===0&&Od.delete(e)}}function jd(e){let t=Od.get(e);if(t)for(let e of t)e()}function Md(e,t){return async function(n,r){let i=await fetch(e+`/api/browser-js/execute-tool`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({threadId:t,toolName:n,params:r})});if(!i.ok){let e=await i.text();try{let t=JSON.parse(e).error||{};e=t.details||t.message||e}catch{}return{text:null,error:`Tool `+n+` failed: `+e}}let a=await i.json();return{text:a.content&&a.content[0]?a.content[0].text:null,error:null}}}function Nd(e,t,n){if(Ed.has(e))return;Ed.set(e,{status:`running`}),jd(e);let r=qn();(async()=>{try{let i=Md(r,n),a=Object.getPrototypeOf(async function(){}).constructor,o=await new a(`callTool`,t)(i),s=o===void 0?null:o;Ed.set(e,{status:`success`,result:s}),jd(e),await Cn(e,s)}catch(t){let n=t instanceof Error?t.stack||t.message:String(t);Ed.set(e,{status:`error`,error:n}),jd(e);try{await Cn(e,{error:n})}catch(e){Dd.error(`Failed to submit browser JS error result`,e)}}})()}var Pd=Oi(e=>(0,$.jsx)(`div`,{className:`overflow-hidden`,children:(0,$.jsxs)(`div`,{className:e.v0,children:[e.v1,(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:e.v2})]})}),{name:`RunWebWorkerBlock_1`,portals:[`v1`,`v2`]}),Fd=Oi(e=>(0,$.jsxs)(`div`,{className:`overflow-hidden`,children:[(0,$.jsxs)(`button`,{onClick:e.v0,className:e.v1,children:[e.v2,(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:e.v3}),e.v4]}),e.v5]}),{name:`RunWebWorkerBlock_2`,portals:[`v2`,`v3`,`v4`,`v5`]}),Id=Oi(e=>(0,$.jsxs)(`div`,{className:`overflow-hidden`,children:[(0,$.jsxs)(`button`,{onClick:e.v0,className:e.v1,children:[e.v2,(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:e.v3}),e.v4]}),e.v5]}),{name:`RunWebWorkerBlock_3`,portals:[`v2`,`v3`,`v4`,`v5`]}),Ld=function(e){let t=(0,Q.c)(41),{toolCallId:n,intention:r,code:a}=e,o=X(Rd),s;t[0]===n?s=t[1]:(s=kd(n),t[0]=n,t[1]=s);let c=s,[l,u]=(0,Z.useState)(c?.status??`running`),d;t[2]===c?d=t[3]:(d=()=>{if(!c||c.status!==`success`)return null;let e=c.result;return e==null?null:typeof e==`string`?e:JSON.stringify(e,null,2)},t[2]=c,t[3]=d);let[f,p]=(0,Z.useState)(d),[m,h]=(0,Z.useState)(c?.error??null),g,_;t[4]===n?(g=t[5],_=t[6]):(g=()=>Ad(n,()=>{let e=kd(n);if(e)if(u(e.status),e.status===`success`){let t=e.result;p(t==null?null:typeof t==`string`?t:JSON.stringify(t,null,2))}else e.status===`error`&&h(e.error??null)}),_=[n],t[4]=n,t[5]=g,t[6]=_),(0,Z.useEffect)(g,_);let v,y;t[7]!==a||t[8]!==o||t[9]!==n?(v=()=>{o&&Nd(n,a,o)},y=[n,a,o],t[7]=a,t[8]=o,t[9]=n,t[10]=v,t[11]=y):(v=t[10],y=t[11]),(0,Z.useEffect)(v,y);let[b,x]=(0,Z.useState)(!1),S;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(S=()=>x(zd),t[12]=S):S=t[12];let C=S;if(l===`running`){let e,n;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(e=K(J.label,`w-full py-2 flex items-center gap-2`),n=(0,$.jsx)(i,{className:`h-4 w-4 shrink-0 text-brand animate-pulse`}),t[13]=e,t[14]=n):(e=t[13],n=t[14]);let a=r||`Executing Browser JS...`,o;return t[15]===a?o=t[16]:(o=(0,$.jsx)(Pd,{v0:e,v1:n,v2:a}),t[15]=a,t[16]=o),o}if(l===`success`){let e,n;t[17]===Symbol.for(`react.memo_cache_sentinel`)?(e=K(J.label,`w-full py-2 flex items-center gap-2 hover:bg-muted/50 transition-colors text-left`),n=(0,$.jsx)(i,{className:`h-4 w-4 shrink-0 text-brand`}),t[17]=e,t[18]=n):(e=t[17],n=t[18]);let o=r||`Browser JS Executed Successfully`,s;t[19]===b?s=t[20]:(s=b?(0,$.jsx)(Dr,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(Ut,{className:`h-4 w-4 shrink-0`}),t[19]=b,t[20]=s);let c;t[21]!==a||t[22]!==b||t[23]!==f?(c=b&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border flex flex-col gap-2`,children:[(0,$.jsx)(`pre`,{className:K(J.bodyMuted,`leading-relaxed whitespace-pre-wrap`),children:a}),f!=null&&(0,$.jsx)(`pre`,{className:K(J.body,`leading-relaxed whitespace-pre-wrap border-t border-border pt-2`),children:f})]}),t[21]=a,t[22]=b,t[23]=f,t[24]=c):c=t[24];let l;return t[25]!==o||t[26]!==s||t[27]!==c?(l=(0,$.jsx)(Fd,{v0:C,v1:e,v2:n,v3:o,v4:s,v5:c}),t[25]=o,t[26]=s,t[27]=c,t[28]=l):l=t[28],l}let w,T;t[29]===Symbol.for(`react.memo_cache_sentinel`)?(w=K(J.label,`w-full py-2 flex items-center gap-2 hover:bg-muted/50 transition-colors text-left`),T=(0,$.jsx)(i,{className:`h-4 w-4 shrink-0 text-destructive`}),t[29]=w,t[30]=T):(w=t[29],T=t[30]);let E=r||`Browser JS Execution Failed`,D;t[31]===b?D=t[32]:(D=b?(0,$.jsx)(Dr,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(Ut,{className:`h-4 w-4 shrink-0`}),t[31]=b,t[32]=D);let O;t[33]!==a||t[34]!==m||t[35]!==b?(O=b&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border flex flex-col gap-2`,children:[(0,$.jsx)(`pre`,{className:K(J.bodyMuted,`leading-relaxed whitespace-pre-wrap`),children:m}),(0,$.jsx)(`pre`,{className:K(J.bodyMuted,`leading-relaxed whitespace-pre-wrap`),children:a})]}),t[33]=a,t[34]=m,t[35]=b,t[36]=O):O=t[36];let k;return t[37]!==E||t[38]!==D||t[39]!==O?(k=(0,$.jsx)(Id,{v0:C,v1:w,v2:T,v3:E,v4:D,v5:O}),t[37]=E,t[38]=D,t[39]=O,t[40]=k):k=t[40],k};function Rd(e){return e.selectedThreadId}function zd(e){return!e}function Bd(e){let t=(0,Q.c)(12),{url:n,title:r}=e,i;t[0]!==r||t[1]!==n?(i=Ba(r,n),t[0]=r,t[1]=n,t[2]=i):i=t[2];let a=i,o,s;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(o=K(J.label,`flex cursor-default items-center gap-2 py-2`),s=(0,$.jsx)(hn,{className:`h-4 w-4 shrink-0 text-brand`}),t[3]=o,t[4]=s):(o=t[3],s=t[4]);let c;t[5]===a?c=t[6]:(c=(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsxs)(`div`,{className:o,children:[s,(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-left`,children:a})]})}),t[5]=a,t[6]=c);let l;t[7]===n?l=t[8]:(l=(0,$.jsx)(Qa,{className:`max-w-md break-all`,children:n}),t[7]=n,t[8]=l);let u;return t[9]!==c||t[10]!==l?(u=(0,$.jsx)(`div`,{className:`my-1 overflow-hidden`,children:(0,$.jsxs)(sa,{children:[c,l]})}),t[9]=c,t[10]=l,t[11]=u):u=t[11],u}function Vd(e){let t=(0,Q.c)(65),{toolCall:n,className:r}=e,i=Gi(),[o,s]=(0,Z.useState)(!1),c;t[0]===n.id?c=t[1]:(c=e=>e.toolCallProgress[n.id],t[0]=n.id,t[1]=c);let l=X(c),u=X(Gd),d=X(Wd),f;t[2]!==n.activeDisplayName||t[3]!==n.name?(f=n.activeDisplayName??a(n.name),t[2]=n.activeDisplayName,t[3]=n.name,t[4]=f):f=t[4];let p=f;if(!u)return null;let m;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(m=()=>{s(Ud)},t[5]=m):m=t[5];let h=m,g;t[6]!==i||t[7]!==d||t[8]!==n.id||t[9]!==n.name?(g=()=>{i({type:Y.StopStream});let e={type:`tool-result`,toolCallId:n.id,toolName:n.name,result:`Tool execution was cancelled by the user. The command was taking too long or required user approval.`,isError:!0,content:`Tool execution was cancelled by the user. The command was taking too long or required user approval.`};i({type:Y.AppendStreamChunk,chunkType:`content`,content:JSON.stringify([e]),segments:d})},t[6]=i,t[7]=d,t[8]=n.id,t[9]=n.name,t[10]=g):g=t[10];let _=g,v=Hd,y=n.name===`bash`&&typeof n.input?.command==`string`?n.input.command:null,b;t[11]===y?b=t[12]:(b=y===null?null:ol(y),t[11]=y,t[12]=b);let x=b,S=n.name===`fetch`&&typeof n.input?.url==`string`?n.input.url:null,C=n.name===`web_search`&&typeof n.input?.query==`string`?n.input.query:null,w=!y&&typeof n.input?.description==`string`?n.input.description:null,T;t[13]===r?T=t[14]:(T=K(`overflow-hidden mb-2`,r),t[13]=r,t[14]=T);let E;t[15]===p?E=t[16]:(E=(0,$.jsx)(`span`,{className:J.bodyMuted,children:p}),t[15]=p,t[16]=E);let D;t[17]===Symbol.for(`react.memo_cache_sentinel`)?(D=(0,$.jsx)(Ul,{}),t[17]=D):D=t[17];let O;t[18]===E?O=t[19]:(O=(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[E,D]})}),t[18]=E,t[19]=O);let k;t[20]===n.name?k=t[21]:(k=(0,$.jsx)(Qa,{children:n.name}),t[20]=n.name,t[21]=k);let A;t[22]!==k||t[23]!==O?(A=(0,$.jsxs)(sa,{children:[O,k]}),t[22]=k,t[23]=O,t[24]=A):A=t[24];let j;t[25]===x?j=t[26]:(j=x!==null&&(0,$.jsx)(`code`,{className:K(J.mono,J.bodyMuted,`truncate whitespace-nowrap rounded bg-muted/60 px-1 py-0.5 max-w-full`),children:x.label}),t[25]=x,t[26]=j);let M;t[27]===S?M=t[28]:(M=S!==null&&(0,$.jsx)(`code`,{className:K(J.mono,J.bodyMuted,`break-all rounded bg-muted/60 px-1 py-0.5`),children:S.length>60?`${S.slice(0,59)}…`:S}),t[27]=S,t[28]=M);let N;t[29]===C?N=t[30]:(N=C!==null&&(0,$.jsx)(`code`,{className:K(J.mono,J.bodyMuted,`break-all rounded bg-muted/60 px-1 py-0.5`),children:C.length>60?`${C.slice(0,59)}…`:C}),t[29]=C,t[30]=N);let P;t[31]===w?P=t[32]:(P=w!==null&&(0,$.jsx)(`span`,{className:J.bodyMuted,children:w}),t[31]=w,t[32]=P);let F;t[33]===o?F=t[34]:(F=(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsx)(`button`,{onClick:h,className:`p-1 hover:bg-muted/50 rounded transition-colors`,children:o?(0,$.jsx)(hr,{className:`h-3 w-3`}):(0,$.jsx)(Dr,{className:`h-3 w-3`})})}),t[33]=o,t[34]=F);let I=o?`Collapse`:`Expand`,L;t[35]===I?L=t[36]:(L=(0,$.jsx)(Qa,{children:I}),t[35]=I,t[36]=L);let R;t[37]!==F||t[38]!==L?(R=(0,$.jsxs)(sa,{children:[F,L]}),t[37]=F,t[38]=L,t[39]=R):R=t[39];let z;t[40]===Symbol.for(`react.memo_cache_sentinel`)?(z=(0,$.jsx)(Gt,{className:`h-3 w-3`}),t[40]=z):z=t[40];let B;t[41]===_?B=t[42]:(B=(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsx)(`button`,{onClick:_,className:`p-1 hover:bg-red-200 dark:hover:bg-red-800 rounded transition-colors text-red-600 dark:text-red-400`,children:z})}),t[41]=_,t[42]=B);let ee;t[43]===Symbol.for(`react.memo_cache_sentinel`)?(ee=(0,$.jsx)(Qa,{className:`bg-red-600 text-white border-red-600`,children:`Stop this process`}),t[43]=ee):ee=t[43];let te;t[44]===B?te=t[45]:(te=(0,$.jsxs)(sa,{children:[B,ee]}),t[44]=B,t[45]=te);let ne;t[46]!==R||t[47]!==te?(ne=(0,$.jsxs)(`div`,{className:`flex items-center gap-1 ml-auto shrink-0`,children:[R,te]}),t[46]=R,t[47]=te,t[48]=ne):ne=t[48];let re;t[49]!==A||t[50]!==j||t[51]!==M||t[52]!==N||t[53]!==P||t[54]!==ne?(re=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 flex-wrap`,children:[A,j,M,N,P,ne]}),t[49]=A,t[50]=j,t[51]=M,t[52]=N,t[53]=P,t[54]=ne,t[55]=re):re=t[55];let ie;t[56]!==o||t[57]!==n.id||t[58]!==n.input||t[59]!==l?(ie=o&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border min-h-[8rem] overflow-auto`,children:[(0,$.jsxs)(`div`,{className:K(J.compact,J.bodyMuted,`mb-2 font-mono`),children:[`ID: `,n.id]}),(0,$.jsxs)(`div`,{className:`mb-2`,children:[(0,$.jsx)(`div`,{className:K(J.compact,J.label,`text-muted-foreground mb-1`),children:`Input:`}),(0,$.jsx)(`pre`,{className:Ml({className:`border border-border`}),children:v(n.input)})]}),l&&(0,$.jsxs)(`div`,{className:`mb-2`,children:[(0,$.jsx)(`div`,{className:K(J.compact,J.label,`text-muted-foreground mb-1`),children:`Progress:`}),(0,$.jsxs)(`div`,{className:K(J.body,`bg-green-50 dark:bg-green-900/20 p-2 rounded border border-green-200 dark:border-green-800`),children:[(0,$.jsx)(`div`,{className:K(J.mono,`text-green-700 dark:text-green-300`),children:l.delta}),l.partial?.content?.[0]?.arguments&&typeof l.partial.content[0].arguments==`object`&&`content`in l.partial.content[0].arguments&&typeof l.partial.content[0].arguments.content==`string`&&(0,$.jsxs)(`div`,{className:K(J.mono,`mt-1 text-green-600 dark:text-green-400`),children:[`Building: `,l.partial.content[0].arguments.content.slice(-50),l.partial.content[0].arguments.content.length>50&&`...`]})]})]}),(0,$.jsxs)(`div`,{className:K(J.compact,`flex items-center gap-1.5 text-muted-foreground`),children:[(0,$.jsx)(Ul,{}),`Executing`,l&&` with progress`,`...`]})]}),t[56]=o,t[57]=n.id,t[58]=n.input,t[59]=l,t[60]=ie):ie=t[60];let ae;return t[61]!==re||t[62]!==ie||t[63]!==T?(ae=(0,$.jsxs)(`div`,{className:T,children:[re,ie]}),t[61]=re,t[62]=ie,t[63]=T,t[64]=ae):ae=t[64],ae}function Hd(e){return JSON.stringify(e,null,2)}function Ud(e){return!e}function Wd(e){return e.streamingSegments}function Gd(e){return e.isStreaming}function Kd(e){return{question:typeof e.question==`string`?e.question:``,options:Array.isArray(e.options)?e.options.filter(e=>typeof e==`string`):void 0,context:typeof e.context==`string`?e.context:void 0}}function qd(e){return{intention:typeof e.intention==`string`?e.intention:``,code:typeof e.code==`string`?e.code:``}}function Jd(e){return{url:typeof e.url==`string`?e.url:``,title:typeof e.title==`string`?e.title:void 0}}function Yd(e){let t=(0,Q.c)(6),{prompt:n,answeredText:r}=e,i=n.toolCallId??`long-running-confirmation`,a;return t[0]!==r||t[1]!==n.context||t[2]!==n.options||t[3]!==n.question||t[4]!==i?(a=(0,$.jsx)(gd,{toolCallId:i,question:n.question,options:n.options,context:n.context,answeredText:r,answeredLabel:`You answered`}),t[0]=r,t[1]=n.context,t[2]=n.options,t[3]=n.question,t[4]=i,t[5]=a):a=t[5],a}function Xd(e){let t=(0,Q.c)(6),{prompt:n,projectId:r,resolvedDecision:i}=e,a;return t[0]!==r||t[1]!==n.command||t[2]!==n.toolCallId||t[3]!==n.wildcardOptions||t[4]!==i?(a=(0,$.jsx)(Cd,{toolCallId:n.toolCallId,command:n.command,projectId:r,wildcardOptions:n.wildcardOptions,resolvedDecision:i}),t[0]=r,t[1]=n.command,t[2]=n.toolCallId,t[3]=n.wildcardOptions,t[4]=i,t[5]=a):a=t[5],a}function Zd(e){let t=(0,Q.c)(7),{prompt:n,projectId:r,resolvedDecision:i}=e,a;return t[0]!==r||t[1]!==n.hostname||t[2]!==n.toolCallId||t[3]!==n.url||t[4]!==n.wildcardOptions||t[5]!==i?(a=(0,$.jsx)(Td,{toolCallId:n.toolCallId,hostname:n.hostname,url:n.url,projectId:r,wildcardOptions:n.wildcardOptions,resolvedDecision:i}),t[0]=r,t[1]=n.hostname,t[2]=n.toolCallId,t[3]=n.url,t[4]=n.wildcardOptions,t[5]=i,t[6]=a):a=t[6],a}function Qd(e,t,n=!1){if(e.name!==`ask_user`)return null;let r=Kd(e.input);return(0,$.jsx)(gd,{toolCallId:e.id,question:r.question,options:r.options,context:r.context,answeredText:t,interactive:!1,respondViaTelegram:n})}function $d(e){if(e.name!==`run_js`&&e.name!==`run_web_worker`)return null;let t=qd(e.input);return(0,$.jsx)(Ld,{toolCallId:e.id,intention:t.intention,code:t.code})}function ef(e){if(e.name!==`open_widget`)return null;let t=Jd(e.input);return t.url?(0,$.jsx)(Bd,{url:t.url,title:t.title}):null}function tf(e){let t=(0,Q.c)(14),{block:n,resultContent:r,resultIsError:i,observation:a}=e,o;t[0]===n.id?o=t[1]:(o=e=>e.toolCallProgress[n.id],t[0]=n.id,t[1]=o);let s=X(o),c;t[2]===s?c=t[3]:(c=s??{},t[2]=s,t[3]=c);let l;t[4]===c?l=t[5]:(l=od(c),t[4]=c,t[5]=l);let u=l,d=r===void 0,f=n.name===`bash`||n.name===`read`||n.name===`file_read`||hu(n.name,n.input);if(d&&!f){let e;return t[6]===n?e=t[7]:(e=(0,$.jsx)(Vd,{toolCall:n}),t[6]=n,t[7]=e),e}let p=d?u:r,m;return t[8]!==n||t[9]!==d||t[10]!==a||t[11]!==i||t[12]!==p?(m=(0,$.jsx)(Wu,{inline:!0,block:n,resultContent:p,resultIsError:i,isActive:d,observation:a}),t[8]=n,t[9]=d,t[10]=a,t[11]=i,t[12]=p,t[13]=m):m=t[13],m}function nf(e){let t=(0,Q.c)(18),{block:n,showActive:r,resultContent:i,resultIsError:a,observation:o,respondViaTelegram:s}=e,c=s===void 0?!1:s,l;t[0]!==n||t[1]!==c||t[2]!==i?(l=Qd(n,i,c),t[0]=n,t[1]=c,t[2]=i,t[3]=l):l=t[3];let u=l;if(u)return u;let d;t[4]===n?d=t[5]:(d=$d(n),t[4]=n,t[5]=d);let f=d;if(f)return f;let p;t[6]===n?p=t[7]:(p=ef(n),t[6]=n,t[7]=p);let m=p;if(m)return m;if(n.name===`call_widget_tool`)return null;if(r){let e;return t[8]!==n||t[9]!==o||t[10]!==i||t[11]!==a?(e=(0,$.jsx)(tf,{block:n,resultContent:i,resultIsError:a,observation:o}),t[8]=n,t[9]=o,t[10]=i,t[11]=a,t[12]=e):e=t[12],e}let h;return t[13]!==n||t[14]!==o||t[15]!==i||t[16]!==a?(h=(0,$.jsx)(Wu,{inline:!0,block:n,resultContent:i,resultIsError:a,isActive:!1,observation:o}),t[13]=n,t[14]=o,t[15]=i,t[16]=a,t[17]=h):h=t[17],h}function rf(e){let t=(0,Q.c)(3),{block:n,sequence:r}=e,i;return t[0]!==n||t[1]!==r?(i=(0,$.jsx)(Zu,{inline:!0,sequence:r,block:n}),t[0]=n,t[1]=r,t[2]=i):i=t[2],i}function af(e){if(Ma(e)){let t=e.text.slice(0,128);return`thinking-${e.label??`none`}-${ad(t)}`}switch(e.type){case`tool_use`:return`tool-${e.id}`;case`tool-result`:return`result-${e.toolCallId}`;case`long_running_confirmation`:return`lrc-${e.prompt.toolCallId??ad(e.prompt.question)}`;case`shell_permission`:return`shell-${e.prompt.toolCallId}`;case`web_fetch_permission`:return`fetch-${e.prompt.toolCallId}`;case`text`:return`text-${ad(e.text.slice(0,128))}`}}function of(e,t,n){let{lookupBlocks:r,isStreaming:i,threadId:a,projectId:o,messageIndex:s,message:c,activeLocalToolCallId:l,respondViaTelegram:u}=n;if(uo(e)&&e.name===`todo`)return null;if(io(e)){if(e.toolName===`todo`)return(0,$.jsx)(rf,{sequence:s,block:e},t);if(e.toolName===`ask_user`||e.toolName===`open_widget`||e.toolName===`call_widget_tool`)return null}switch(e.type){case`long_running_confirmation`:return(0,$.jsx)(Yd,{prompt:e.prompt,answeredText:fd(r,e.prompt.toolCallId)},t);case`shell_permission`:{let n=ud(r,e.prompt.toolCallId)?`allowed`:void 0;return(0,$.jsx)(Xd,{prompt:e.prompt,projectId:o,resolvedDecision:n},t)}case`web_fetch_permission`:{let n=ud(r,e.prompt.toolCallId)?`allowed`:void 0;return(0,$.jsx)(Zd,{prompt:e.prompt,projectId:o,resolvedDecision:n},t)}case`text`:return(0,$.jsx)(gc,{content:e.text,threadId:a},t);case`tool_use`:{let n=sd(r,e.id),a=ld(r,e.id),o=cd(r,e.id);return(0,$.jsx)(nf,{block:e,showActive:dd(r,c,e.id,l,i),resultContent:n,resultIsError:a,observation:o,respondViaTelegram:u},t)}case`tool-result`:return(0,$.jsx)(rf,{block:e},t)}}function sf(e){let t=(0,Q.c)(24),{blocks:n,isStreaming:r,threadId:i,projectId:a,messageIndex:o,message:s,respondViaTelegram:c}=e,l=r===void 0?!1:r,u=o===void 0?0:o,d=c===void 0?!1:c,f=X(cf),p;t[0]!==n||t[1]!==l?(p=lo(n,l),t[0]=n,t[1]=l,t[2]=p):p=t[2];let m=p,h;if(t[3]!==f||t[4]!==n||t[5]!==l||t[6]!==s||t[7]!==u||t[8]!==a||t[9]!==m||t[10]!==d||t[11]!==i){let e;t[13]!==f||t[14]!==n||t[15]!==l||t[16]!==s||t[17]!==u||t[18]!==a||t[19]!==d||t[20]!==i?(e=e=>{let t=af(e);return Ma(e)?(0,$.jsx)(td,{text:e.text,label:e.label,isStreaming:e.isCurrentlyStreaming,threadId:i},t):of(e,t,{lookupBlocks:n,isStreaming:l,threadId:i,projectId:a,messageIndex:u,message:s,activeLocalToolCallId:f,respondViaTelegram:d})},t[13]=f,t[14]=n,t[15]=l,t[16]=s,t[17]=u,t[18]=a,t[19]=d,t[20]=i,t[21]=e):e=t[21],h=m.map(e),t[3]=f,t[4]=n,t[5]=l,t[6]=s,t[7]=u,t[8]=a,t[9]=m,t[10]=d,t[11]=i,t[12]=h}else h=t[12];let g;return t[22]===h?g=t[23]:(g=(0,$.jsx)($.Fragment,{children:h}),t[22]=h,t[23]=g),g}function cf(e){if(!e.selectedThreadId)return null;let t=e.threadToolSessions[e.selectedThreadId];if(t)return t.toolCallId;let n=e.devServerToolSession;return!n||n.threadId!==e.selectedThreadId?null:n.toolCallId}var lf=Oi(e=>(0,$.jsx)(`div`,{className:e.v0,children:(0,$.jsxs)(`div`,{className:e.v1,children:[e.v2,(0,$.jsx)(`div`,{className:e.v3,children:e.v4}),e.v5,e.v6]})}),{name:`ChatMessage_1`,portals:[`v2`,`v4`,`v5`,`v6`]}),uf=function(e){let t=(0,Q.c)(37),{message:n,threadId:r,messageIndex:i,showCheckpointRestore:a,checkpointRestoreTooltip:o}=e,s=i===void 0?0:i,c=a===void 0?!1:a,l=n.sender===`user`,u;t[0]!==l||t[1]!==n.content?(u=l?null:eo(n.content),t[0]=l,t[1]=n.content,t[2]=u):u=t[2];let d=u,f;t[3]!==n.content||t[4]!==n.isThinking?(f=n.isThinking?ho(n.content):null,t[3]=n.content,t[4]=n.isThinking,t[5]=f):f=t[5];let p=f,m=l&&`flex justify-end`,h;t[6]===m?h=t[7]:(h=K(`group px-4 py-4`,m),t[6]=m,t[7]=h);let g=l&&`items-end`,_;t[8]===g?_=t[9]:(_=K(`flex flex-col gap-1 min-w-0 max-w-full`,g),t[8]=g,t[9]=_);let v;t[10]!==o||t[11]!==n||t[12]!==c||t[13]!==r?(v=(0,$.jsx)(Kc,{message:n,threadId:r,showCheckpointRestore:c,checkpointRestoreTooltip:o}),t[10]=o,t[11]=n,t[12]=c,t[13]=r,t[14]=v):v=t[14];let y=l&&`rounded-xl px-4 py-3 bg-foreground text-background`,b;t[15]===y?b=t[16]:(b=K(`flex flex-col gap-0.5 min-w-0 text-base`,y),t[15]=y,t[16]=b);let x;t[17]!==n||t[18]!==s||t[19]!==d||t[20]!==p||t[21]!==r?(x=(0,$.jsx)(df,{message:n,threadId:r,messageIndex:s,structuredContent:d,thinkingBlocks:p}),t[17]=n,t[18]=s,t[19]=d,t[20]=p,t[21]=r,t[22]=x):x=t[22];let S;t[23]!==n.generatedImageData||t[24]!==n.generatedImageUrl||t[25]!==r?(S=(n.generatedImageUrl||n.generatedImageData)&&(0,$.jsx)(qc,{src:n.generatedImageData?`data:image/png;base64,${n.generatedImageData}`:n.generatedImageUrl,threadId:r}),t[23]=n.generatedImageData,t[24]=n.generatedImageUrl,t[25]=r,t[26]=S):S=t[26];let C;t[27]===n.attachments?C=t[28]:(C=n.attachments&&n.attachments.length>0&&(0,$.jsx)(xc,{attachments:n.attachments}),t[27]=n.attachments,t[28]=C);let w;return t[29]!==b||t[30]!==x||t[31]!==S||t[32]!==C||t[33]!==h||t[34]!==_||t[35]!==v?(w=(0,$.jsx)(lf,{v0:h,v1:_,v2:v,v3:b,v4:x,v5:S,v6:C}),t[29]=b,t[30]=x,t[31]=S,t[32]=C,t[33]=h,t[34]=_,t[35]=v,t[36]=w):w=t[36],w};function df(e){let t=(0,Q.c)(15),{message:n,threadId:r,messageIndex:i,structuredContent:a,thinkingBlocks:o}=e;if(n.isThinking){if(o?.length){let e;return t[0]!==o||t[1]!==r?(e=(0,$.jsx)(sf,{blocks:o,threadId:r}),t[0]=o,t[1]=r,t[2]=e):e=t[2],e}let e;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(e=K(J.bodyMuted,`leading-relaxed whitespace-pre-wrap`),t[3]=e):e=t[3];let i;return t[4]!==n.content||t[5]!==r?(i=(0,$.jsx)(`div`,{className:e,children:(0,$.jsx)(gc,{content:n.content,threadId:r})}),t[4]=n.content,t[5]=r,t[6]=i):i=t[6],i}if(a){let e;return t[7]!==n||t[8]!==i||t[9]!==a||t[10]!==r?(e=(0,$.jsx)(sf,{blocks:a,threadId:r,messageIndex:i,message:n}),t[7]=n,t[8]=i,t[9]=a,t[10]=r,t[11]=e):e=t[11],e}let s;return t[12]!==n.content||t[13]!==r?(s=(0,$.jsx)(gc,{content:n.content,threadId:r,className:J.body}),t[12]=n.content,t[13]=r,t[14]=s):s=t[14],s}function ff(e){let t=(0,Z.useRef)(new Map);return(0,Z.useMemo)(()=>{let n=t.current,r=[],i=new Set;for(let t of e){if(i.add(t),t.type===`long_running_confirmation`){r.push({type:`long_running_confirmation`,prompt:t.prompt});continue}if(t.type===`shell_permission`){r.push({type:`shell_permission`,prompt:t.prompt});continue}if(t.type===`web_fetch_permission`){r.push({type:`web_fetch_permission`,prompt:t.prompt});continue}let e=n.get(t);if(e&&e.chunks===t.chunks){r.push(...e.blocks);continue}let a=t.chunks.join(``),o;o=t.type===`thinking`?ho(a)??[]:eo(a)??(a.trim()?[{type:`text`,text:a}]:[]),n.set(t,{chunks:t.chunks,blocks:o}),r.push(...o)}for(let e of n.keys())i.has(e)||n.delete(e);return r},[e])}var pf=Oi(e=>(0,$.jsx)(`div`,{className:e.v0,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-1 min-w-0`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:e.v1,children:e.v2}),e.v3]}),e.v4]})}),{name:`StreamingMessage_1`,portals:[`v2`,`v3`,`v4`]}),mf=function(e){let t=(0,Q.c)(20),{segments:n,model:r,mode:a,threadId:o,projectId:s,isCreatingProject:c,isProcessingThread:l,totalMessages:u,showProcessingLine:d,respondViaTelegram:f}=e,p=u===void 0?0:u,m=d===void 0?!1:d,h=f===void 0?!1:f,g=ff(n),_=m?`pb-0`:`pb-4`,v;t[0]===_?v=t[1]:(v=K(`group px-4 pt-4`,_),t[0]=_,t[1]=v);let y;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(y=K(J.compact,`font-medium text-foreground`),t[2]=y):y=t[2];let b;t[3]===a?b=t[4]:(b=zr(a),t[3]=a,t[4]=b);let x;t[5]===r?x=t[6]:(x=r&&(0,$.jsxs)(`span`,{className:K(J.compact,`flex items-center gap-1 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity`),children:[(0,$.jsx)(i,{className:`h-2.5 w-2.5`}),Oo(r)]}),t[5]=r,t[6]=x);let S;t[7]!==c||t[8]!==l||t[9]!==g||t[10]!==s||t[11]!==h||t[12]!==o||t[13]!==p?(S=g.length>0?(0,$.jsx)(`div`,{className:`flex flex-col gap-0.5 min-w-0 text-base`,children:(0,$.jsx)(sf,{blocks:g,isStreaming:!0,threadId:o,projectId:s,messageIndex:p,respondViaTelegram:h})}):c||l?(0,$.jsx)(`div`,{className:`min-w-0`,children:(0,$.jsx)(td,{isStreaming:!0})}):null,t[7]=c,t[8]=l,t[9]=g,t[10]=s,t[11]=h,t[12]=o,t[13]=p,t[14]=S):S=t[14];let C;return t[15]!==v||t[16]!==b||t[17]!==x||t[18]!==S?(C=(0,$.jsx)(pf,{v0:v,v1:y,v2:b,v3:x,v4:S}),t[15]=v,t[16]=b,t[17]=x,t[18]=S,t[19]=C):C=t[19],C},hf=3e3;function gf(e){let t=e?wr.filter(t=>t!==e):wr;return t[Math.floor(Math.random()*t.length)]}function _f(e){let t=(0,Q.c)(3),[n,r]=(0,Z.useState)(In),i=(0,Z.useRef)(In),a,o;return t[0]===e?(a=t[1],o=t[2]):(a=()=>{if(!e){r(In),i.current=In;return}let t=setInterval(()=>{let e=i.current===`Processing...`?gf():gf(i.current);i.current=e,r(e)},hf);return()=>clearInterval(t)},o=[e],t[0]=e,t[1]=a,t[2]=o),(0,Z.useEffect)(a,o),n}var vf=Oi(e=>(0,$.jsx)(`div`,{className:e.v0,"aria-live":`polite`,"aria-busy":e.v1,children:(0,$.jsx)(`span`,{className:e.v2,children:e.v3})}),{name:`ProcessingIndicator_1`,portals:[`v3`]}),yf=function(e){let t=(0,Q.c)(7),{active:n,label:r,className:i}=e,a=n===void 0?!0:n,o=_f(a&&!r),s=a?`animate-shimmer`:void 0,c;t[0]===s?c=t[1]:(c=K(J.caption,s),t[0]=s,t[1]=c);let l=r??o,u;return t[2]!==a||t[3]!==i||t[4]!==c||t[5]!==l?(u=(0,$.jsx)(vf,{v0:i,v1:a,v2:c,v3:l}),t[2]=a,t[3]=i,t[4]=c,t[5]=l,t[6]=u):u=t[6],u},bf=Oi(e=>(0,$.jsxs)(`div`,{className:`mx-auto flex max-w-3xl flex-1 flex-col items-center gap-8 overflow-y-auto px-4 py-8`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,children:[(0,$.jsx)(`img`,{src:`/tarsk-color.svg`,alt:`Tarsk`,className:`h-16 w-16 rounded-lg`}),(0,$.jsxs)(`div`,{className:`text-center`,children:[(0,$.jsx)(`h1`,{className:e.v0,children:`Let's build it!`}),(0,$.jsx)(`p`,{className:e.v1,children:e.v2})]})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap justify-center gap-3`,children:[e.v3,(0,$.jsxs)(`button`,{type:`button`,className:`flex w-56 flex-col gap-2 rounded-xl border border-border bg-background p-4 text-left shadow-sm transition-colors hover:bg-muted`,onClick:e.v4,children:[e.v5,(0,$.jsx)(`span`,{className:e.v6,children:`Connect a repo`}),(0,$.jsx)(`span`,{className:e.v7,children:`Clone an existing repository`})]}),(0,$.jsxs)(`button`,{type:`button`,className:`flex w-56 flex-col gap-2 rounded-xl border border-border bg-background p-4 text-left shadow-sm transition-colors hover:bg-muted`,onClick:e.v8,children:[e.v9,(0,$.jsx)(`span`,{className:e.v10,children:`New App`}),(0,$.jsx)(`span`,{className:e.v11,children:`Create a new project from template`})]}),(0,$.jsxs)(`button`,{type:`button`,className:`flex w-56 flex-col gap-2 rounded-xl border border-border bg-background p-4 text-left shadow-sm transition-colors hover:bg-muted`,onClick:e.v12,children:[e.v13,(0,$.jsx)(`span`,{className:e.v14,children:`Open Folder`}),(0,$.jsx)(`span`,{className:e.v15,children:`Use an existing local folder`})]})]})]}),{name:`WelcomeScreen_1`,portals:[`v2`,`v3`,`v5`,`v9`,`v13`]}),xf=function(e){let t=(0,Q.c)(17),{projects:n,onSelectProject:r,onCreateThread:i,onConnectRepo:a,onNewApp:o,onOpenFolder:s}=e,c;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(c=K(J.pageTitle,`tracking-tight text-balance`),t[0]=c):c=t[0];let l=n.length===0?`Start or connect your first project`:`Select a project to start coding`,u;if(t[1]!==i||t[2]!==r||t[3]!==n){let e;t[5]!==i||t[6]!==r?(e=e=>(0,$.jsxs)(`button`,{type:`button`,className:`flex w-56 flex-col gap-2 rounded-xl border border-border bg-background p-4 text-left shadow-sm transition-colors hover:bg-muted`,onClick:()=>{e.threads.length===0?i(e.projectId):r(e.projectId,e.threads[0].threadId)},children:[(0,$.jsx)(d,{className:`h-5 w-5 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`${J.body} text-foreground leading-snug font-medium`,children:e.name}),(0,$.jsxs)(`span`,{className:J.caption,children:[e.threads.length,` thread`,e.threads.length===1?``:`s`]})]},e.projectId),t[5]=i,t[6]=r,t[7]=e):e=t[7],u=n.map(e),t[1]=i,t[2]=r,t[3]=n,t[4]=u}else u=t[4];let f;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,$.jsx)(w,{className:`h-5 w-5 text-muted-foreground`}),t[8]=f):f=t[8];let p;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,$.jsx)(xt,{className:`h-5 w-5 text-muted-foreground`}),t[9]=p):p=t[9];let m;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,$.jsx)(Nn,{className:`h-5 w-5 text-muted-foreground`}),t[10]=m):m=t[10];let h;return t[11]!==a||t[12]!==o||t[13]!==s||t[14]!==l||t[15]!==u?(h=(0,$.jsx)(bf,{v0:c,v1:`mt-1 ${J.pageSubtitle}`,v2:l,v3:u,v4:a,v5:f,v6:`${J.body} text-foreground leading-snug font-medium`,v7:J.caption,v8:o,v9:p,v10:`${J.body} text-foreground leading-snug font-medium`,v11:J.caption,v12:s,v13:m,v14:`${J.body} text-foreground leading-snug font-medium`,v15:J.caption}),t[11]=a,t[12]=o,t[13]=s,t[14]=l,t[15]=u,t[16]=h):h=t[16],h},Sf=`md:mr-4`,Cf=`cubic-bezier(0.22, 0.61, 0.36, 1)`,wf=`animate-in fade-in duration-200 ease-out`,Tf=`[data-composer-surface]`;function Ef(e){e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,160)}px`}function Df(e){return e?`w-full min-w-0 px-4`:`mx-auto max-w-3xl w-full min-w-0`}function Of(e){return K(e?`relative w-full min-w-0 pl-4`:`relative mx-auto w-full max-w-3xl min-w-0`,Sf)}function kf(e){return`relative w-full min-w-0`}function Af(e,t,n=!1,r=!1){return t?`absolute inset-x-0 bottom-0 mx-auto w-full max-w-3xl max-md:px-2 px-4 pb-4 pointer-events-none`:r?`relative w-full min-w-0`:n?`relative mx-auto w-full max-w-3xl px-0`:e?`relative w-full min-w-0 pb-2 md:pb-4`:`relative w-full max-w-3xl max-md:px-0 pb-2 md:pl-4 md:pb-4 md:-ml-[6px]`}function jf(e,t=!1){return e?`relative flex min-w-0 flex-1 flex-col bg-background pointer-events-auto`:K(`relative flex min-w-0 flex-1 flex-col rounded-[24px] border focus-within:ring-2 focus-within:ring-brand pointer-events-auto`,t?`border-border/50 bg-background/80 shadow-lg backdrop-blur-sm`:`border-border bg-background shadow-2xl`)}function Mf(e){let t=(0,Q.c)(10),n;t[0]===e?n=t[1]:(n=ma.models.enabled(e),t[0]=e,t[1]=n);let r;t[2]===n?r=t[3]:(r={queryKey:n,queryFn:_,placeholderData:ta},t[2]=n,t[3]=r);let i=oi(r),a;bb0:{if(!i.data){let e;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(e=[],t[4]=e):e=t[4],a=e;break bb0}let e;t[5]===i.data?e=t[6]:(e=Object.values(i.data).flat(),t[5]=i.data,t[6]=e),a=e}let o=a,s;return t[7]!==o||t[8]!==i?(s={...i,models:o},t[7]=o,t[8]=i,t[9]=s):s=t[9],s}var Nf=(0,Z.createContext)(void 0);function Pf(e){let t=(0,Q.c)(12),{paneId:n,conversationId:r,fillPane:i,children:a}=e,o=i===void 0?!1:i,s=Gi(),c=X(Ff),l;t[0]!==s||t[1]!==n?(l=()=>{s({type:Y.SetFocusedPane,paneId:n})},t[0]=s,t[1]=n,t[2]=l):l=t[2];let u=l,d=c===n,f;t[3]!==r||t[4]!==o||t[5]!==n||t[6]!==u||t[7]!==d?(f={paneId:n,conversationId:r,isFocused:d,fillPane:o,setFocused:u},t[3]=r,t[4]=o,t[5]=n,t[6]=u,t[7]=d,t[8]=f):f=t[8];let p=f,m;return t[9]!==a||t[10]!==p?(m=(0,$.jsx)(Nf.Provider,{value:p,children:a}),t[9]=a,t[10]=p,t[11]=m):m=t[11],m}function Ff(e){return e.focusedPane}function If(){let e=(0,Q.c)(1),t=(0,Z.useContext)(Nf);if(t===void 0){let t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t={paneId:`primary`,conversationId:void 0,isFocused:!0,fillPane:!1,setFocused:Lf},e[0]=t):t=e[0],t}return t}function Lf(){}var Rf=Pn(`chat.input-state`);function zf(e,t){return t===`primary`?e:`${e}:${t}`}function Bf({initialValue:e}={}){let t=Gi(),{paneId:n}=If(),r=X(e=>e.selectedThreadId),i=X(e=>e.selectedProjectId),a=X(e=>e.projects),o=X(e=>e.projectModelSelections),s=X(e=>e.chatInputDrafts),c=X(e=>e.configUpdatedAt),l=X(e=>e.focusChatInput),u=X(e=>e.isStreaming),{models:d,isFetched:f}=Mf(c),[p,m]=(0,Z.useState)(()=>{if(r){let e=zf(r,n);if(s[e])return s[e]}return e??``}),[h,g]=(0,Z.useState)(-1),[_,v]=(0,Z.useState)(``),[y,b]=(0,Z.useState)(0),x=(0,Z.useRef)(p);(0,Z.useEffect)(()=>{x.current=p},[p]);let S=(0,Z.useRef)(s);(0,Z.useEffect)(()=>{S.current=s},[s]);let C=(0,Z.useRef)(!0);(0,Z.useEffect)(()=>(C.current=!0,()=>{C.current=!1}),[]);let[w,T]=(0,Z.useState)([]),[E,D]=(0,Z.useState)(()=>(r?o[r]:void 0)??null),O=(0,Z.useRef)(E?.id??``),k=(0,Z.useRef)(E?.provider??``),A=(0,Z.useRef)(null),[j,M]=(0,Z.useState)(!1),[N,P]=(0,Z.useState)(!1),[F,I]=(0,Z.useState)([]),L=a.find(e=>e.projectId===i),R=L?.defaultChatMode??`auto`,z=(0,Z.useRef)(Pr(R)).current,[B,ee]=(0,Z.useState)(z.planMode),[te,ne]=(0,Z.useState)(z.ralphMode),[re,ie]=(0,Z.useState)(z.orchestrateMode),[ae,oe]=(0,Z.useState)(z.autoMode),[se,ce]=(0,Z.useState)(z.imageMode),le=(0,Z.useCallback)(function(e){let t=Pr(e);ee(t.planMode),ce(t.imageMode),ne(t.ralphMode),ie(t.orchestrateMode),oe(t.autoMode)},[]),[ue,de]=(0,Z.useState)([]),[fe,pe]=(0,Z.useState)(null),[V,me]=(0,Z.useState)([]),[he,ge]=(0,Z.useState)(!1),[_e,ve]=(0,Z.useState)(``),[ye,be]=(0,Z.useState)(0),[xe,Se]=(0,Z.useState)([]),[Ce,we]=(0,Z.useState)([]),[Te,H]=(0,Z.useState)([]),[Ee,De]=(0,Z.useState)(!1),[Oe,ke]=(0,Z.useState)(!1),[Ae,je]=(0,Z.useState)(``),Me=(0,Z.useRef)(null),Ne=(0,Z.useRef)(null),Pe=(0,Z.useRef)(null),Fe=(0,Z.useRef)(null),Ie=(0,Z.useRef)(null),Le=(0,Z.useRef)(null);(0,Z.useEffect)(()=>{O.current=E?.id??``,k.current=E?.provider??``},[E?.id,E?.provider]);let Re=(0,Z.useCallback)((e,n)=>{D(e);let a=r;if(!a||(t({type:Y.SetProjectModel,threadId:a,model:e}),n?.persist===!1))return;let o=`${a}:${e.provider??``}:${e.id}`;A.current!==o&&(A.current=o,Rf.info(`Persisting model to thread`,{threadId:a,model:{id:e.id,provider:e.provider}}),Dt(a,{model:e.id,modelProvider:e.provider}).then(()=>{let t=i;t&&cn(t,{lastSelectedModel:e.id,lastSelectedModelProvider:e.provider}).catch(e=>{Rf.error(`Failed to save model to project`,{err:e})}),A.current===o&&(A.current=null),Rf.info(`Model persisted successfully`)}).catch(e=>{A.current===o&&(A.current=null),Rf.error(`Failed to save model to thread`,{err:e})}))},[i,r,t]);(0,Z.useEffect)(()=>{let e=i?a.find(e=>e.projectId===i):void 0,t=e?.threads.find(e=>e.threadId===r),n=r?o[r]:void 0,s=t?.model??n?.id??e?.lastSelectedModel??null,c=t?.modelProvider??n?.provider??e?.lastSelectedModelProvider??null;if(d.length===0){f&&(T([]),D(null));return}T(d);let l=s&&c?d.find(e=>e.id===s&&e.provider===c)??null:null,u=d[0],p=l??u,m=!l&&!!(s||c),h=O.current===p.id&&k.current===p.provider;if(!d.some(e=>e.id===O.current&&e.provider===k.current)&&O.current){Re(u,{persist:!0});return}h||Re(p,{persist:m})},[r,i,a,o,d,f,Re]),(0,Z.useEffect)(()=>{!se||ue.length>0||(async()=>{try{let e=await $r(),t=Object.values(e).flat();t.length>0&&(de(t),pe(e=>e??t[0]))}catch(e){Rf.error(`Failed to load image models`,{err:e})}})()},[se,ue.length]);let[ze,Be]=(0,Z.useState)(r);(0,Z.useEffect)(()=>{if(r!==ze){ze&&x.current.trim()&&S.current[zf(ze,n)]!==x.current&&t({type:Y.SetChatInputDraft,threadId:zf(ze,n),draft:x.current});let e=!1;return queueMicrotask(()=>{e||!C.current||(Be(r),m(r?S.current[zf(r,n)]??``:``),me([]),ge(!1),Se([]),we([]),H([]),De(!1),ke(!1),le(R))}),()=>{e=!0}}},[r,ze,n,t,le,R]);let Ve=(0,Z.useRef)(L?i:null);(0,Z.useEffect)(()=>{!i||!L||Ve.current!==i&&(Ve.current=i,le(R))},[i,L,R,le]),(0,Z.useEffect)(()=>{r&&mn(r).then(({commands:e,skills:t,bundledSkills:n})=>{Rf.debug(`Loaded slash commands and skills`,{commands:e,skills:t,bundledSkills:n}),Se(e),we(t),H(n)}).catch(e=>Rf.error(`Failed to load slash commands and skills`,{err:e}))},[r]);let He=(0,Z.useRef)(!1);(0,Z.useEffect)(()=>{Oe&&!He.current&&r&&mn(r).then(({commands:e,skills:t,bundledSkills:n})=>{Se(e),we(t),H(n)}).catch(e=>Rf.error(`Failed to refresh slash commands and skills:`,e)),He.current=Oe},[Oe,r]);let Ue=r?s[zf(r,n)]??``:``;return(0,Z.useEffect)(()=>{r&&m(Ue)},[r,Ue,n]),(0,Z.useLayoutEffect)(()=>{let e=Ne.current;e&&Ef(e)},[p]),(0,Z.useEffect)(()=>{l&&r&&!u&&(Ne.current?.focus(),t({type:Y.ClearFocusChatInput}))},[l,r,u,t]),(0,Z.useEffect)(()=>{let e=r,i=e?zf(e,n):null;return()=>{i&&x.current.trim()&&S.current[i]!==x.current&&t({type:Y.SetChatInputDraft,threadId:i,draft:x.current})}},[r,n,t]),(0,Z.useEffect)(()=>{let e=e=>{Pe.current&&!Pe.current.contains(e.target)&&M(!1),Fe.current&&!Fe.current.contains(e.target)&&P(!1)};if(j||N)return document.addEventListener(`mousedown`,e),()=>{document.removeEventListener(`mousedown`,e)}},[j,N]),{message:p,setMessage:m,historyIndex:h,setHistoryIndex:g,draftMessage:_,setDraftMessage:v,cursorPosition:y,setCursorPosition:b,availableModels:w,setAvailableModels:T,selectedModel:E,setSelectedModel:Re,selectedModelIdRef:O,showModelMenu:j,setShowModelMenu:M,showPlusMenu:N,setShowPlusMenu:P,attachments:F,setAttachments:I,planMode:B,setPlanMode:ee,ralphMode:te,setRalphMode:ne,orchestrateMode:re,setOrchestrateMode:ie,autoMode:ae,setAutoMode:oe,imageMode:se,setImageMode:ce,availableImageModels:ue,setAvailableImageModels:de,selectedImageModel:fe,setSelectedImageModel:pe,allFiles:V,setAllFiles:me,showSuggestions:he,setShowSuggestions:ge,suggestionQuery:_e,setSuggestionQuery:ve,selectedIndex:ye,setSelectedIndex:be,slashCommands:xe,setSlashCommands:Se,skills:Ce,setSkills:we,bundledSkills:Te,setBundledSkills:H,bundledSkillMode:Ee,setBundledSkillMode:De,showCommandSuggestions:Oe,setShowCommandSuggestions:ke,commandQuery:Ae,setCommandQuery:je,messageRef:x,fileInputRef:Me,textareaRef:Ne,modelMenuRef:Pe,plusMenuRef:Fe,suggestionsRef:Ie,commandSuggestionsRef:Le,selectedThreadId:r,dispatch:t}}var Vf=e=>{Wr(e)},Hf=`pending-auto-route`;function Uf(e){return{messageId:Hf,sender:`user`,content:e.prompt,contentType:`text`,timestamp:e.startedAt,attachments:e.attachments}}function Wf(e){return{id:e.model,provider:e.provider}}function Gf(e,t,n){switch(e){case`cheap`:{let r=Se(`cheap`,t);return{decision:e,model:r?Wf(r):n}}case`smart`:{let r=Ae(t);return{decision:e,model:r?Wf(r):n}}default:return{decision:`default`,model:n}}}var Kf=`/orchestrate`,qf=/^\s*\/orchestrate(?:\s|$)/i;function Jf(e){return qf.test(e)}function Yf(e){if(Jf(e))return e;let t=e.trimStart();return t?`${Kf} ${t}`:`${Kf} `}var Xf=Pn(`app.use-chat-input-handlers.hook`);function Zf(e,t){return t===`primary`?e:`${e}:${t}`}function Qf({message:e,setMessage:t,userTasks:n,onMatchedUserTaskSend:r,attachments:i,selectedModel:a,onSend:o,isStreaming:s,selectedThreadId:c,isListening:l,stopListening:u,resetTranscript:d,dispatch:f,historyIndex:p,setHistoryIndex:m,draftMessage:h,setDraftMessage:g,cursorPosition:_,setCursorPosition:v,showSuggestions:y,setShowSuggestions:b,suggestionQuery:x,setSuggestionQuery:S,allFiles:C,setAllFiles:w,selectedIndex:T,setSelectedIndex:E,showCommandSuggestions:D,setShowCommandSuggestions:O,commandQuery:k,setCommandQuery:A,slashCommands:j,skills:M,bundledSkills:N,bundledSkillMode:P,setBundledSkillMode:F,messageRef:I,textareaRef:L,setAttachments:R,planMode:z,setPlanMode:B,ralphMode:ee,setRalphMode:te,orchestrateMode:ne,setOrchestrateMode:re,autoMode:ie,setAutoMode:ae,modelAliases:oe,onAutoRouteResolved:se,ensureCanOrchestrate:ce,requestOrchestrateMode:le,imageMode:ue,setImageMode:de,selectedImageModel:fe,hasConversationMessages:pe,isFirstUserPrompt:V}){let{paneId:me}=If(),{toast:he}=Ki(),[ge,_e]=(0,Z.useState)(!1),ve=(0,Z.useCallback)(()=>{t(``),I.current=``,R([]),m(-1),g(``),c&&f({type:Y.ClearChatInputDraft,threadId:Zf(c,me)}),L.current&&(L.current.style.height=`auto`)},[f,I,me,c,R,g,m,t,L]),ye=(0,Z.useCallback)((e,n)=>{I.current.trim()||(t(e),I.current=e,R(n),L.current?.focus())},[I,R,t,L]),be=(0,Z.useCallback)(async()=>{if(ge||!e.trim()&&i.length===0||!c)return;let t=ue?fe:a;if(!t)return;let p=e,m=i,h=ie&&!ue&&V,g=h&&!s;function _(){!g||!c||f({type:Y.EndAutoRoute,threadId:c,paneId:me})}function v(){_(),g&&ye(p,m)}let y=null;if(h){_e(!0),g&&(ve(),f({type:Y.StartAutoRoute,route:{threadId:c,paneId:me,prompt:p,attachments:m,startedAt:new Date().toISOString()}}));try{y=Gf(await Zr(c,p),oe,t),se?.(y)}catch(e){Xf.warn(`Auto routing failed; returning the prompt to the composer`,{err:e}),v(),he({title:`Couldn't pick a model`,description:`Send again, or choose a model yourself.`,variant:`destructive`});return}finally{_e(!1)}}let b=y?.model??t;if(ne&&!ce()){v();return}let x=ne?Yf(p):p;l&&(u(),d()),s?f({type:Y.EnqueueChatMessage,message:{id:`queued-${Date.now()}`,threadId:c,paneId:me,message:x,model:b.id,attachments:m,provider:b.provider,planMode:z,imageMode:ue,ralphMode:ee,orchestrateMode:ne}}):o(x,b.id,m,b.provider,z,ue,ee,ne),_(),Vf(p),g||ve();let S=n.find(e=>e.content===x);S&&r?.(S)},[e,i,a,o,l,u,d,s,f,c,me,ve,ye,he,z,ee,ne,ie,oe,se,ce,ue,fe,n,r,ge,V]),xe=(0,Z.useCallback)(n=>{let r=e.substring(0,_-x.length-1);t(`${r}${n} ${e.substring(_)}`),b(!1),setTimeout(()=>{if(L.current){L.current.focus();let e=r.length+n.length+1;L.current.setSelectionRange(e,e)}},0)},[e,_,x,t,b,L]),Se=(0,Z.useCallback)(n=>{let r=n.metadata.mode===`orchestrate`;if(r&&!le()){O(!1);return}let i=n.metadata.action===`compact`?`/compact`:r?``:n.content,a=e.substring(0,_-k.length-1);t(`${a}${i}${e.substring(_)}`),O(!1),setTimeout(()=>{if(L.current){L.current.focus();let e=a.length+i.length;L.current.setSelectionRange(e,e)}},0),n.metadata.mode===`plan`?(B(!0),te(!1),re(!1),de(!1),ae(!1)):n.metadata.mode===`ralph`?(te(!0),B(!1),re(!1),de(!1),ae(!1)):n.metadata.mode===`orchestrate`&&(B(!1),te(!1),de(!1),ae(!1))},[e,_,k,t,O,B,te,re,de,ae,le,L]),Ce=(0,Z.useCallback)(e=>e.scope===`bundled`?`//${e.name}`:e.name.includes(` `)?`/"${e.name}"`:`/${e.name}`,[]),we=(0,Z.useCallback)(n=>{let r=P?k.length+2:k.length+1,i=e.substring(0,_-r),a=e.substring(_),o=Ce(n);t(`${i}${o}${a}`),O(!1),F(!1),setTimeout(()=>{if(L.current){L.current.focus();let e=i.length+o.length;L.current.setSelectionRange(e,e)}},0)},[e,_,k,P,Ce,t,O,F,L]),Te=(0,Z.useCallback)(n=>{let r=`/${n.name}`,i=e.substring(0,_);t(`${i}${r}${e.substring(_)}`),O(!1),setTimeout(()=>{if(L.current){L.current.focus();let e=i.length+r.length;L.current.setSelectionRange(e,e)}},0)},[e,_,t,O,L]),H=(0,Z.useCallback)(n=>{let r=Ce(n),i=e.substring(0,_);t(`${i}${r}${e.substring(_)}`),O(!1),F(!1),setTimeout(()=>{if(L.current){L.current.focus();let e=i.length+r.length;L.current.setSelectionRange(e,e)}},0)},[e,_,Ce,t,O,F,L]),Ee=n=>{if(D){if(n.key===`ArrowDown`){n.preventDefault(),E((T+1)%je.length);return}if(n.key===`ArrowUp`){n.preventDefault(),E((T-1+je.length)%je.length);return}if(n.key===`Enter`||n.key===`Tab`){n.preventDefault();let e=je[T];e&&(e.type===`command`?Se(e.data):we(e.data));return}if(n.key===`Escape`){O(!1);return}}if(y){let e=Me.length>0;if(n.key===`ArrowDown`&&e){n.preventDefault(),E((T+1)%Me.length);return}if(n.key===`ArrowUp`&&e){n.preventDefault(),E((T-1+Me.length)%Me.length);return}if(n.key===`Enter`||n.key===`Tab`){n.preventDefault(),Me[T]&&xe(Me[T]);return}if(n.key===`Escape`){b(!1);return}}if(n.key===`Enter`&&!n.shiftKey){n.preventDefault(),be();return}let r=Mn();r.length!==0&&(n.key===`ArrowUp`?(n.preventDefault(),p===-1?(g(e),m(r.length-1),t(r[r.length-1])):p>0&&(m(p-1),t(r[p-1]))):n.key===`ArrowDown`&&(n.preventDefault(),p>0?(m(p-1),t(r[p-1])):p===0&&(m(-1),t(h))))},De=e=>{let n=e.target.value,r=e.target.selectionStart;t(n),v(r);let i=n.substring(0,r),a=i.lastIndexOf(`//`);if(a!==-1){let t=a>0?i[a-1]:``;if(a===0||/\s/.test(t)){let t=i.substring(a+2);if(!t.includes(` `)){A(t),F(!0),O(!0),b(!1),E(0),Ef(e.target);return}}}F(!1);let o=i.lastIndexOf(`/`),s=!1;if(o!==-1){let e=o>0?i[o-1]:``;if(o===0||/\s/.test(e)){let e=i.substring(o+1);e.includes(` `)?O(!1):(s=!0,A(e),O(!0),b(!1),E(0))}else O(!1)}else O(!1);if(!s){let e=i.lastIndexOf(`@`);if(e!==-1){let t=e>0?i[e-1]:``;if(e===0||/\s/.test(t)){let t=i.substring(e+1);t.includes(` `)?b(!1):(S(t),b(!0),E(0),C.length===0&&c&&qe(c).then(e=>{w(e)}).catch(e=>Xf.error(`Failed to fetch files:`,e)))}else b(!1)}else b(!1)}Ef(e.target)},Oe=k.toLowerCase(),ke=j.filter(e=>e.metadata.action===`compact`&&!pe?!1:e.name.toLowerCase().includes(Oe)).sort((e,t)=>Number(!!t.isBuiltIn)-Number(!!e.isBuiltIn)),Ae=(P?N:M).filter(e=>e.name.toLowerCase().includes(Oe)),je=[...P?[]:ke.map(e=>({type:`command`,data:e})),...Ae.map(e=>({type:`skill`,data:e}))],Me=y?C.filter(e=>e.toLowerCase().includes(x.toLowerCase())).slice(0,10):[];return{handleSend:be,handleKeyDown:Ee,handleTextareaInput:De,insertFileReference:xe,insertCommand:Se,insertSkill:we,insertSkillAtCursor:H,insertSlashCommandAtCursor:Te,allSuggestions:je,fileSuggestions:Me,isRouting:ge}}var $f=1;function ep(e){let t=window.getComputedStyle(e);return(parseFloat(t.lineHeight)||parseFloat(t.fontSize)*1.5)+parseFloat(t.paddingTop)+parseFloat(t.paddingBottom)}function tp(e,t){let n=e.style.width,r=e.style.height,i=e.style.minHeight;t!==null&&(e.style.width=`${t}px`),e.style.minHeight=`0px`,e.style.height=`auto`;let a=e.scrollHeight>ep(e)+$f;return e.style.width=n,e.style.minHeight=i,e.style.height=r,a}function np(e){let t=(0,Q.c)(15),{message:n,forceMultiline:r,textareaRef:i,rowRef:a}=e,[o,s]=(0,Z.useState)(!0),[c,l]=(0,Z.useState)(0),u=(0,Z.useRef)(null),d,f;t[0]===a?(d=t[1],f=t[2]):(d=function(){let e=a.current;if(!e)return;let t=new ResizeObserver(function(e){l(e[0]?.contentRect.width??0)});return t.observe(e),function(){t.disconnect()}},f=[a],t[0]=a,t[1]=d,t[2]=f),(0,Z.useLayoutEffect)(d,f);let p;t[3]!==r||t[4]!==o||t[5]!==a||t[6]!==i?(p=function(){let e=i.current,t=a.current;if(!(!e||!t)){if(o&&(u.current=t.clientWidth-e.offsetWidth),r)s(!1);else{let n=u.current;s(!tp(e,o||n===null?null:t.clientWidth-n))}Ef(e)}},t[3]=r,t[4]=o,t[5]=a,t[6]=i,t[7]=p):p=t[7];let m;return t[8]!==r||t[9]!==o||t[10]!==n||t[11]!==a||t[12]!==c||t[13]!==i?(m=[n,r,o,c,a,i],t[8]=r,t[9]=o,t[10]=n,t[11]=a,t[12]=c,t[13]=i,t[14]=m):m=t[14],(0,Z.useLayoutEffect)(p,m),o&&!r}function rp(e){let t=(0,Q.c)(17),{visible:n,suggestions:r,skillReferencePrefix:i,query:a,selectedIndex:o,onSelectCommand:s,onSelectSkill:c,onMouseEnterSuggestion:l,containerRef:u}=e,d=i===void 0?`/`:i;if(!n)return null;let f=d===`//`,p,m;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(p=K(J.dropdownGroupHeading,`px-2 py-1.5 border-b border-border/50 mb-1 flex items-center gap-2`),m=(0,$.jsx)(Hr,{className:`h-3 w-3`}),t[0]=p,t[1]=m):(p=t[0],m=t[1]);let h=f?`Bundled Skills`:`Skills & Commands`,g=a&&` matching "${a}"`,_;t[2]!==h||t[3]!==g?(_=(0,$.jsxs)(`div`,{className:p,children:[m,h,g]}),t[2]=h,t[3]=g,t[4]=_):_=t[4];let v;t[5]!==f||t[6]!==l||t[7]!==s||t[8]!==c||t[9]!==o||t[10]!==d||t[11]!==r?(v=r.length>0?(()=>{let e=[],t=!1,n=!1;return r.forEach((r,i)=>{let a=i===o;if(r.type===`command`&&!n&&(n=!0,e.push((0,$.jsx)(`div`,{className:K(J.dropdownGroupHeading,`px-2 py-1.5 pt-2`),children:`Commands`},`group-commands`))),r.type===`skill`&&!t&&(t=!0,e.push((0,$.jsx)(`div`,{className:K(J.dropdownGroupHeading,`px-2 py-1.5 pt-2`),children:`Skills`},`group-skills`))),r.type===`command`){let t=r.data;e.push((0,$.jsxs)(`button`,{type:`button`,className:K(`flex w-full flex-col gap-1 rounded-lg px-3 py-2 text-left transition-colors`,a?`bg-accent text-accent-foreground`:`text-popover-foreground hover:bg-accent/50`),onClick:()=>s(t),onMouseEnter:()=>l(i),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsxs)(`span`,{className:`font-medium`,children:[`/`,t.name]}),t.metadata.argumentHint&&(0,$.jsx)(`span`,{className:J.compact,children:t.metadata.argumentHint})]}),t.metadata.description&&(0,$.jsx)(`span`,{className:J.compact,children:t.metadata.description})]},`cmd-${t.name}`))}else{let t=r.data;e.push((0,$.jsxs)(`button`,{type:`button`,className:K(`flex w-full flex-col gap-1 rounded-lg px-3 py-2 text-left transition-colors`,a?`bg-accent text-accent-foreground`:`text-popover-foreground hover:bg-accent/50`),onClick:()=>c(t),onMouseEnter:()=>l(i),children:[(0,$.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,$.jsxs)(`span`,{className:`font-medium`,children:[d,t.name]})}),(0,$.jsx)(`span`,{className:J.compact,children:t.description})]},`skill-${t.name}`))}}),e})():(0,$.jsxs)(`div`,{className:K(J.compact,`px-3 py-4 text-center text-muted-foreground`),children:[f?`No bundled skills found.`:`No commands or skills found.`,(0,$.jsx)(`br`,{}),(0,$.jsxs)(`span`,{className:J.compact,children:[f?(0,$.jsx)($.Fragment,{children:`Use bundled skills with syntax like `}):(0,$.jsx)($.Fragment,{children:`Create commands in `}),f?(0,$.jsx)(`code`,{className:`bg-muted px-1 rounded`,children:`//skill-name`}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`code`,{className:`bg-muted px-1 rounded`,children:`.agents/commands/`}),` or skills in`,` `,(0,$.jsx)(`code`,{className:`bg-muted px-1 rounded`,children:`.agents/skills/`})]})]})]}),t[5]=f,t[6]=l,t[7]=s,t[8]=c,t[9]=o,t[10]=d,t[11]=r,t[12]=v):v=t[12];let y;return t[13]!==u||t[14]!==_||t[15]!==v?(y=(0,$.jsxs)(`div`,{ref:u,className:`absolute bottom-full left-0 mb-2 w-full max-h-64 overflow-y-auto rounded-xl border border-border bg-popover p-1 shadow-lg z-50 animate-in fade-in slide-in-from-bottom-2`,children:[_,v]}),t[13]=u,t[14]=_,t[15]=v,t[16]=y):y=t[16],y}function ip(e){return e.startsWith(`image/`)}function ap(e){return e.startsWith(`video/`)}function op(e){return e.startsWith(`audio/`)}function sp(e){let t=(0,Q.c)(7),{attachments:n,onRemove:r}=e;if(n.length===0)return null;let i;if(t[0]!==n||t[1]!==r){let e;t[3]===r?e=t[4]:(e=(e,t)=>(0,$.jsx)(`div`,{className:K(J.compact,`group relative flex items-center gap-1 rounded-md bg-muted text-muted-foreground`),children:ip(e.mimeType)?(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(`img`,{src:`data:${e.mimeType};base64,${e.content}`,alt:e.fileName,className:`h-16 w-16 rounded-md object-cover`}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>r(t),className:`absolute -right-1.5 -top-1.5 flex h-4 w-4 items-center justify-center rounded-full bg-foreground text-background opacity-0 transition-opacity group-hover:opacity-100`,children:[(0,$.jsx)(Gt,{className:`h-2.5 w-2.5`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Remove attachment`})]})]}):ap(e.mimeType)?(0,$.jsxs)(`span`,{className:`flex items-center gap-1 px-2 py-1`,children:[(0,$.jsx)(ne,{className:`h-3 w-3`}),e.fileName,(0,$.jsxs)(`button`,{type:`button`,onClick:()=>r(t),className:`ml-1 hover:text-foreground`,children:[(0,$.jsx)(Gt,{className:`h-3 w-3`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Remove attachment`})]})]}):op(e.mimeType)?(0,$.jsxs)(`span`,{className:`flex items-center gap-1 px-2 py-1`,children:[(0,$.jsx)(h,{className:`h-3 w-3`}),e.fileName,(0,$.jsxs)(`button`,{type:`button`,onClick:()=>r(t),className:`ml-1 hover:text-foreground`,children:[(0,$.jsx)(Gt,{className:`h-3 w-3`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Remove attachment`})]})]}):(0,$.jsxs)(`span`,{className:`flex items-center gap-1 px-2 py-1`,children:[(0,$.jsx)(Pe,{className:`h-3 w-3`}),e.fileName,(0,$.jsxs)(`button`,{type:`button`,onClick:()=>r(t),className:`ml-1 hover:text-foreground`,children:[(0,$.jsx)(Gt,{className:`h-3 w-3`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Remove attachment`})]})]})},t),t[3]=r,t[4]=e),i=n.map(e),t[0]=n,t[1]=r,t[2]=i}else i=t[2];let a;return t[5]===i?a=t[6]:(a=(0,$.jsx)(`div`,{className:`mb-2 flex flex-wrap gap-1.5`,children:i}),t[5]=i,t[6]=a),a}var cp=Oi(e=>(0,$.jsxs)(`div`,{className:`w-72 space-y-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`h3`,{className:e.v0,children:`Context`}),e.v1]}),(0,$.jsxs)(`div`,{className:e.v2,children:[(0,$.jsxs)(`span`,{children:[e.v3,`% Full`]}),(0,$.jsxs)(`span`,{children:[e.v4,e.v5,` / `,e.v6,` Tokens`]})]}),(0,$.jsx)(`div`,{className:`h-2 w-full overflow-hidden rounded-full bg-muted/60`,children:(0,$.jsx)(`div`,{className:`flex h-full w-full`,children:e.v7})}),(0,$.jsx)(`div`,{className:`space-y-1.5`,children:e.v8})]}),{name:`ContextUsagePanel_1`,portals:[`v1`,`v3`,`v4`,`v5`,`v6`,`v7`,`v8`]}),lp=function({breakdown:e,actualUsage:t=e.actualUsage,onClose:n}){let{categories:r}=e,i=fp(e,t),a=i.tokens,o=i.percent,s=i.contextWindow,c=up.filter(e=>r[e.key]>0);return(0,$.jsx)(cp,{v0:J.label,v1:n&&(0,$.jsxs)(Fe,{variant:`ghost`,size:`icon-sm`,className:`text-muted-foreground hover:text-background`,onClick:n,children:[(0,$.jsx)(Gt,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Close`})]}),v2:K(J.compact,`flex items-center justify-between text-muted-foreground`),v3:o,v4:i.isActual?``:`~`,v5:pp(a),v6:mp(s),v7:c.map(e=>{let t=r[e.key],n=s>0?t/s*100:0;return(0,$.jsx)(`div`,{style:{width:`${Math.max(n,t>0?.5:0)}%`,backgroundColor:e.color}},e.key)}),v8:up.map(e=>(0,$.jsxs)(`div`,{className:K(J.compact,`flex items-center justify-between text-muted-foreground`),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`h-2.5 w-2.5 shrink-0 rounded-sm`,style:{backgroundColor:e.color}}),(0,$.jsx)(`span`,{children:e.label})]}),(0,$.jsx)(`span`,{className:`tabular-nums`,children:pp(r[e.key])})]},e.key))})},up=[{key:`systemPrompt`,label:`System prompt`,color:`#9CA3AF`},{key:`toolDefinitions`,label:`Tool definitions`,color:`#B088F0`},{key:`rules`,label:`Rules`,color:`#88D088`},{key:`skills`,label:`Skills`,color:`#D0A000`},{key:`subagentDefinitions`,label:`Subagent definitions`,color:`#2080D0`},{key:`conversation`,label:`Conversation`,color:`#E09030`}];function dp(e){return typeof e.effectiveWindow==`number`&&e.effectiveWindow>0?e.effectiveWindow:e.contextWindow}function fp(e,t=e.actualUsage){return t?{tokens:t.tokens,contextWindow:t.contextWindow,percent:Math.round(t.percent),isActual:!0}:{tokens:e.totalTokens,contextWindow:dp(e),percent:e.percentageFull,isActual:!1}}function pp(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toString()}function mp(e){return e>=1e6?`${Math.round(e/1e6)}M`:e>=1e3?`${Math.round(e/1e3)}K`:e.toString()}var hp=Pn(`app.token-usage-tooltip.ui`);function gp({threadId:e,currentConversationId:t,initialBreakdown:n,actualUsage:r,refreshKey:i,children:a}){let[o,s]=(0,Z.useState)(n??null),[c,l]=(0,Z.useState)(!1),[u,d]=(0,Z.useState)(null),[f,p]=(0,Z.useState)(!1),[m,h]=(0,Z.useState)(n?t:void 0),[g,_]=(0,Z.useState)(n?i:void 0);return(0,Z.useEffect)(()=>{n&&(s(n),h(t),_(i),d(null))},[n,t]),(0,Z.useEffect)(()=>{n||(t!==m||i!==g)&&(s(null),h(void 0),_(void 0),d(null))},[n,t,m,g,i]),(0,Z.useEffect)(()=>{if(!f||!e||!t||!(m!==t||g!==i))return;let n=!1;async function r(){let r=t;if(r){l(!0),d(null);try{let t=await ft(e,r,{forceRefresh:!0});if(n)return;s(t),h(r),_(i)}catch(e){if(hp.error(`[TokenUsageTooltip] Failed to load context data:`,e),n)return;s(e=>(e||d(`Failed to load context data`),e))}finally{n||l(!1)}}}return r(),()=>{n=!0}},[f,e,t,m,g,i]),!e||e===``?(0,$.jsx)($.Fragment,{children:a}):(0,$.jsxs)(iu,{open:f,onOpenChange:p,children:[(0,$.jsxs)(sa,{children:[(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsx)(au,{asChild:!0,children:a})}),(0,$.jsx)(Qa,{side:`top`,className:`bg-popover text-popover-foreground`,children:`Show context usage`})]}),(0,$.jsxs)(ou,{side:`top`,align:`end`,className:`w-auto p-4`,children:[c&&(0,$.jsxs)(`div`,{className:K(J.compact,`flex w-72 items-center gap-2 text-muted-foreground`),children:[(0,$.jsx)(rr,{className:`h-3 w-3 animate-pulse`}),(0,$.jsx)(`span`,{children:`Loading context...`})]}),u&&!c&&(0,$.jsxs)(`div`,{className:K(J.compact,`flex w-72 items-center gap-2 text-muted-foreground`),children:[(0,$.jsx)(rr,{className:`h-3 w-3`}),(0,$.jsx)(`span`,{children:u})]}),!c&&!u&&o&&(0,$.jsx)(lp,{breakdown:o,actualUsage:r,onClose:()=>p(!1)})]})]})}var _p=Oi(e=>(0,$.jsxs)(`svg`,{className:e.v0,viewBox:`0 0 20 20`,"aria-hidden":`true`,children:[(0,$.jsx)(`circle`,{className:`text-muted-foreground/25`,cx:`10`,cy:`10`,r:e.v1,fill:`none`,stroke:`currentColor`,strokeWidth:`3`}),(0,$.jsx)(`circle`,{cx:`10`,cy:`10`,r:e.v2,fill:`none`,stroke:`currentColor`,strokeWidth:`3`,strokeLinecap:`round`,strokeDasharray:e.v3,strokeDashoffset:e.v4,transform:`rotate(-90 10 10)`})]}),{name:`ContextUsageRing_1`,svg:!0}),vp=function(e){let t=(0,Q.c)(5),{percentage:n}=e,r=2*Math.PI*7,i=r*(1-Math.min(n,100)/100),a;t[0]===n?a=t[1]:(a=xp(n),t[0]=n,t[1]=a);let o=`h-4 w-4 ${a}`,s;return t[2]!==i||t[3]!==o?(s=(0,$.jsx)(_p,{v0:o,v1:7,v2:7,v3:r,v4:i}),t[2]=i,t[3]=o,t[4]=s):s=t[4],s},yp=Pn(`app.token-usage-icon.ui`);function bp(e){let t=e.filter(e=>e.sender===`agent`),n=t.length>0?t[t.length-1]:void 0,r=t.reduce((e,t)=>e+(t.metadata?.tokenCount??0),0);return[t.length,n?.messageId??``,n?.content.length??0,r].join(`:`)}function xp(e){return e>75?`text-red-500`:e>50?`text-orange-500`:`text-muted-foreground`}var Sp=500;function Cp(e){let t=(0,Q.c)(43),{threadId:n,conversationId:r,messages:i,isStreaming:a,liveContextUsage:o}=e,s;t[0]===i?s=t[1]:(s=i===void 0?[]:i,t[0]=i,t[1]=s);let c=s,l=a===void 0?!1:a,[u,d]=(0,Z.useState)(r),[f,p]=(0,Z.useState)(),m;t[2]===c?m=t[3]:(m=bp(c),t[2]=c,t[3]=m);let h=m,[g,_]=(0,Z.useState)(h),v=(0,Z.useRef)(null),y=(0,Z.useRef)(n),b,x;t[4]===h?(b=t[5],x=t[6]):(b=()=>(v.current&&clearTimeout(v.current),v.current=setTimeout(()=>{_(h)},Sp),()=>{v.current&&clearTimeout(v.current)}),x=[h],t[4]=h,t[5]=b,t[6]=x),(0,Z.useEffect)(b,x);let S,C;t[7]===n?(S=t[8],C=t[9]):(S=()=>{y.current!==n&&(y.current&&(Le.invalidate(`thread-${y.current}`),Le.invalidatePattern(RegExp(`^context-breakdown-${y.current}-`))),y.current=n,d(void 0),p(void 0))},C=[n],t[7]=n,t[8]=S,t[9]=C),(0,Z.useEffect)(S,C);let w,T;t[10]===r?(w=t[11],T=t[12]):(T=()=>{if(r){d(r);return}},w=[r],t[10]=r,t[11]=w,t[12]=T),(0,Z.useEffect)(T,w);let E;t[13]!==r||t[14]!==n?(E=()=>{let e=!1;return(async function(){if(!n){d(void 0),p(void 0);return}if(r){d(r);return}try{let t=await Gr(n);if(e)return;d(t.currentConversationId)}catch(e){let t=e;yp.error(`Failed to fetch thread data:`,t)}})(),()=>{e=!0}},t[13]=r,t[14]=n,t[15]=E):E=t[15];let D;t[16]!==r||t[17]!==g||t[18]!==n?(D=[r,n,g],t[16]=r,t[17]=g,t[18]=n,t[19]=D):D=t[19],(0,Z.useEffect)(E,D);let O;t[20]!==l||t[21]!==c.length||t[22]!==u||t[23]!==n?(O=()=>{let e=!1;return(async function(){if(!l){if(!n||!u||c.length===0){p(void 0);return}try{let t=await ft(n,u,{forceRefresh:!0});if(e)return;p(t)}catch(e){let t=e;if(t instanceof Error&&t.message===`Conversation not found`){p(void 0);return}yp.error(`Failed to fetch context breakdown:`,t)}}})(),()=>{e=!0}},t[20]=l,t[21]=c.length,t[22]=u,t[23]=n,t[24]=O):O=t[24];let k;if(t[25]!==g||t[26]!==l||t[27]!==c.length||t[28]!==u||t[29]!==n?(k=[n,u,g,c.length,l],t[25]=g,t[26]=l,t[27]=c.length,t[28]=u,t[29]=n,t[30]=k):k=t[30],(0,Z.useEffect)(O,k),!n||n===``)return null;let A=o??f?.actualUsage,j=A?.percent??f?.percentageFull;if(!(typeof j==`number`&&j>0))return null;let M=String(g),N;t[31]===j?N=t[32]:(N=(0,$.jsx)(vp,{percentage:j}),t[31]=j,t[32]=N);let P;t[33]===Symbol.for(`react.memo_cache_sentinel`)?(P=(0,$.jsx)(`span`,{className:`sr-only`,children:`Show context usage`}),t[33]=P):P=t[33];let F;t[34]===N?F=t[35]:(F=(0,$.jsxs)(Fe,{variant:`ghost`,size:`icon-sm`,className:`text-muted-foreground hover:text-background`,children:[N,P]}),t[34]=N,t[35]=F);let I;return t[36]!==A||t[37]!==f||t[38]!==u||t[39]!==M||t[40]!==F||t[41]!==n?(I=(0,$.jsx)(gp,{threadId:n,currentConversationId:u,initialBreakdown:f,actualUsage:A,refreshKey:M,children:F}),t[36]=A,t[37]=f,t[38]=u,t[39]=M,t[40]=F,t[41]=n,t[42]=I):I=t[42],I}function wp(e,t){let n=e.target.files;if(!n||n.length===0)return;let r=Array.from(n),i=r.length,a=Array.from({length:i}),o=0;e.target.value=``,r.forEach((e,n)=>{let r=new FileReader;r.onload=()=>{let s=r.result.split(`,`)[1];a[n]={fileName:e.name,content:s,mimeType:e.type||`application/octet-stream`},o+=1,o===i&&t(a)},r.readAsDataURL(e)})}function Tp(e,t){switch(e){case`archive`:return(0,$.jsx)(P,{className:t});case`audio`:return(0,$.jsx)(pe,{className:t});case`code`:return(0,$.jsx)(R,{className:t});case`config`:return(0,$.jsx)(st,{className:t});case`data`:return(0,$.jsx)(tt,{className:t});case`document`:return(0,$.jsx)(we,{className:t});case`image`:return(0,$.jsx)(Qr,{className:t});case`json`:return(0,$.jsx)(ut,{className:t});case`presentation`:return(0,$.jsx)(se,{className:t});case`security`:return(0,$.jsx)(He,{className:t});case`spreadsheet`:return(0,$.jsx)(j,{className:t});case`text`:return(0,$.jsx)(Me,{className:t});case`video`:return(0,$.jsx)(ve,{className:t});case`web`:return(0,$.jsx)(R,{className:t});case`file`:return(0,$.jsx)(kn,{className:t})}}function Ep({filename:e,className:t}){let n=`file`,r=`text-muted-foreground`;try{if(typeof le==`function`&&e){let t=le(e);n=t.name,r=t.className??r}}catch{}let i=K(`h-4 w-4 flex-shrink-0`,r,t);return Tp(n,i)}function Dp(e){let t=(0,Q.c)(17),{showSuggestions:n,fileSuggestions:r,suggestionQuery:i,selectedIndex:a,onSelectFile:o,onMouseEnterSuggestion:s,containerRef:c}=e;if(!n||r.length===0)return null;let l,u;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(l=K(J.dropdownGroupHeading,`px-2 py-1.5 border-b border-border/50 mb-1 flex items-center gap-2`),u=(0,$.jsx)(de,{className:`h-3 w-3`}),t[0]=l,t[1]=u):(l=t[0],u=t[1]);let d;t[2]===i?d=t[3]:(d=(0,$.jsxs)(`div`,{className:l,children:[u,`Files matching "`,i,`"`]}),t[2]=i,t[3]=d);let f;if(t[4]!==r||t[5]!==s||t[6]!==o||t[7]!==a){let e;t[9]!==s||t[10]!==o||t[11]!==a?(e=(e,t)=>{let n=e.split(`/`).pop()??e,r=t===a;return(0,$.jsxs)(`button`,{type:`button`,className:K(J.body,`flex w-full items-center gap-2 rounded-lg px-3 py-2 text-left transition-colors`,r?`bg-accent text-accent-foreground`:`text-popover-foreground hover:bg-accent/50`),onClick:()=>o(e),onMouseEnter:()=>s(t),children:[(0,$.jsx)(Ep,{filename:n}),(0,$.jsxs)(`div`,{className:`flex flex-col overflow-hidden`,children:[(0,$.jsx)(`span`,{className:`truncate font-medium`,children:n}),(0,$.jsx)(`span`,{className:K(J.compact,`truncate text-muted-foreground opacity-70`),children:e})]})]},e)},t[9]=s,t[10]=o,t[11]=a,t[12]=e):e=t[12],f=r.map(e),t[4]=r,t[5]=s,t[6]=o,t[7]=a,t[8]=f}else f=t[8];let p;return t[13]!==c||t[14]!==d||t[15]!==f?(p=(0,$.jsxs)(`div`,{ref:c,className:`absolute bottom-full left-0 mb-2 w-full max-h-64 overflow-y-auto rounded-xl border border-border bg-popover p-1 shadow-lg z-50 animate-in fade-in slide-in-from-bottom-2`,children:[d,f]}),t[13]=c,t[14]=d,t[15]=f,t[16]=p):p=t[16],p}function Op(e){let t=(0,Q.c)(5),{providerSlug:n}=e;if(!n)return null;let r;t[0]===n?r=t[1]:(r=Jt(n),t[0]=n,t[1]=r);let i=`${n} logo`,a;return t[2]!==r||t[3]!==i?(a=(0,$.jsx)(`img`,{src:r,alt:i,className:`h-3.5 w-3.5 flex-shrink-0 dark:invert`,onError:kp}),t[2]=r,t[3]=i,t[4]=a):a=t[4],a}function kp(e){e.currentTarget.style.visibility=`hidden`}function Ap(e){let t=(0,Q.c)(17),{providerSlug:n,providerData:r}=e,i=r?.name??n,a;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=K(J.dropdownGroupHeading,`flex items-center gap-1.5 px-3 py-1.5 uppercase tracking-wide`),t[0]=a):a=t[0];let o=`/settings/providers/${encodeURIComponent(n)}`,s;t[1]===n?s=t[2]:(s=(0,$.jsx)(Op,{providerSlug:n}),t[1]=n,t[2]=s);let c;t[3]!==o||t[4]!==s?(c=(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsx)(so,{to:o,className:`flex items-center hover:opacity-70 transition-opacity`,children:s})}),t[3]=o,t[4]=s,t[5]=c):c=t[5];let l=`Configure ${i} provider`,u;t[6]===l?u=t[7]:(u=(0,$.jsx)(Qa,{side:`left`,children:(0,$.jsx)(`p`,{children:l})}),t[6]=l,t[7]=u);let d;t[8]!==c||t[9]!==u?(d=(0,$.jsx)(Ti,{children:(0,$.jsxs)(sa,{children:[c,u]})}),t[8]=c,t[9]=u,t[10]=d):d=t[10];let f;t[11]!==i||t[12]!==r?(f=r?.url?(0,$.jsx)(To,{url:r.url,showIcon:!1,variant:`inline`,children:i}):i,t[11]=i,t[12]=r,t[13]=f):f=t[13];let p;return t[14]!==d||t[15]!==f?(p=(0,$.jsxs)(`div`,{className:a,children:[d,f]}),t[14]=d,t[15]=f,t[16]=p):p=t[16],p}function jp(e){let t=e.pricing?.prompt;return t==null?null:Math.ceil(t*3)}function Mp(e){return`$${_r(e)}`}function Np(e,t){return e.pricing?(0,$.jsxs)(`div`,{className:`max-w-64 whitespace-normal break-words text-left leading-relaxed`,children:[(0,$.jsx)(`div`,{children:`${Mp(e.pricing.prompt??0)} input per million tokens`}),(0,$.jsx)(`div`,{children:`${Mp(e.pricing.completion??0)} output per million tokens`}),(0,$.jsx)(`div`,{children:`Displayed value of ${t} is a relative price.`})]}):null}function Pp(e,t){return[...e].sort((e,n)=>{let r=(e.provider??`Other`).localeCompare(n.provider??`Other`);if(r!==0)return r;if(t===`relative-price`){let t=(jp(e)??2**53-1)-(jp(n)??2**53-1);if(t!==0)return t}return Oo(e.id).localeCompare(Oo(n.id))})}function Fp(e){let t=(0,Q.c)(40),{availableModels:n,selectedModel:r,onModelSelect:i}=e,[a,o]=Z.useState(!1),[s,c]=Z.useState(`relative-price`),l;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(l=new Map,t[0]=l):l=t[0];let[u,d]=Z.useState(l),f=Z.useRef(null),p,m;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(p=()=>{on().then(function(e){d(new Map(e.map(Rp)))})},m=[],t[1]=p,t[2]=m):(p=t[1],m=t[2]),Z.useEffect(p,m);let h,g;t[3]===a?(h=t[4],g=t[5]):(h=()=>{let e=e=>{f.current&&!f.current.contains(e.target)&&o(!1)};if(a)return document.addEventListener(`mousedown`,e),()=>{document.removeEventListener(`mousedown`,e)}},g=[a],t[3]=a,t[4]=h,t[5]=g),Z.useEffect(h,g);let _;t[6]===i?_=t[7]:(_=e=>{i(e),o(!1)},t[6]=i,t[7]=_);let v=_,y;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(y=()=>{c(function(e){return e===`relative-price`?`alphabetical`:`relative-price`})},t[8]=y):y=t[8];let b=y,x;t[9]!==n||t[10]!==s?(x=Pp(n,s),t[9]=n,t[10]=s,t[11]=x):x=t[11];let S=x,C=s===`relative-price`?bn:qr,w=s===`relative-price`?`Sort by relative price`:`Sort alphabetically`,T,E;t[12]===n.length?(T=t[13],E=t[14]):(E=()=>{let e=function(e){let t=e.key.toLowerCase();!((e.metaKey||e.ctrlKey)&&e.shiftKey&&!e.altKey)||t!==`m`||n.length===0||(e.preventDefault(),o(Lp))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},T=[n.length],t[12]=n.length,t[13]=T,t[14]=E),Z.useEffect(E,T);let D;t[15]===a?D=t[16]:(D=()=>o(!a),t[15]=a,t[16]=D);let O;t[17]===Symbol.for(`react.memo_cache_sentinel`)?(O=K(J.body,`font-normal`),t[17]=O):O=t[17];let k;t[18]===r?k=t[19]:(k=r?Oo(r.id):`No model`,t[18]=r,t[19]=k);let A;t[20]===k?A=t[21]:(A=(0,$.jsx)(`span`,{className:O,children:k}),t[20]=k,t[21]=A);let j;t[22]===Symbol.for(`react.memo_cache_sentinel`)?(j=(0,$.jsx)(hr,{className:`h-3 w-3`}),t[22]=j):j=t[22];let M;t[23]!==D||t[24]!==A?(M=(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsxs)(Fe,{variant:`action`,size:`icon-sm`,className:`gap-1 w-auto px-2`,onClick:D,children:[A,j]})}),t[23]=D,t[24]=A,t[25]=M):M=t[25];let N;t[26]===Symbol.for(`react.memo_cache_sentinel`)?(N=(0,$.jsx)(Qa,{children:`Select Model`}),t[26]=N):N=t[26];let P;t[27]===M?P=t[28]:(P=(0,$.jsxs)(sa,{children:[M,N]}),t[27]=M,t[28]=P);let F;t[29]!==C||t[30]!==v||t[31]!==u||t[32]!==r?.id||t[33]!==a||t[34]!==w||t[35]!==S?(F=a&&(0,$.jsx)(`div`,{className:`absolute bottom-full right-0 mb-1 w-80 max-h-80 overflow-y-auto rounded-lg border border-border bg-popover p-1 shadow-md z-50`,children:(0,$.jsxs)(Ti,{children:[(0,$.jsx)(`div`,{className:`-mb-3 flex justify-end px-1 pb-1`,children:(0,$.jsxs)(sa,{children:[(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,"aria-label":w,className:`rounded-md p-1 text-muted-foreground transition-colors hover:bg-accent hover:text-accent-foreground`,onClick:b,children:(0,$.jsx)(C,{className:`h-3.5 w-3.5`})})}),(0,$.jsx)(Qa,{side:`left`,align:`start`,sideOffset:8,children:w})]})}),Object.entries(S.reduce(Ip,{})).map((e,t)=>{let[n,i]=e;return(0,$.jsxs)(`div`,{children:[t>0&&(0,$.jsx)(Do,{className:`my-1`}),(0,$.jsx)(Ap,{providerSlug:n,providerData:u.get(n)}),i.map(e=>{let t=jp(e),n=t==null?null:Np(e,t);return(0,$.jsx)(`div`,{children:(0,$.jsx)(`div`,{children:(0,$.jsxs)(`button`,{type:`button`,className:K(J.body,`flex w-full items-center justify-between gap-3 whitespace-nowrap rounded-md px-3 py-1.5 pl-8 text-popover-foreground hover:bg-accent`,e.id===r?.id&&`bg-accent font-medium`),onClick:()=>v(e),children:[(0,$.jsx)(`span`,{className:`min-w-0 truncate`,children:Oo(e.id)}),t!=null&&n&&(0,$.jsxs)(sa,{children:[(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsx)(`span`,{className:`shrink-0 text-xs text-muted-foreground`,children:t})}),(0,$.jsx)(Qa,{side:`left`,align:`end`,sideOffset:8,className:`max-w-64`,children:n})]})]})})},e.id)})]},n)})]})}),t[29]=C,t[30]=v,t[31]=u,t[32]=r?.id,t[33]=a,t[34]=w,t[35]=S,t[36]=F):F=t[36];let I;return t[37]!==P||t[38]!==F?(I=(0,$.jsxs)(`div`,{className:`relative`,ref:f,children:[P,F]}),t[37]=P,t[38]=F,t[39]=I):I=t[39],I}function Ip(e,t){let n=t.provider??`Other`;return e[n]||(e[n]=[]),e[n].push(t),e}function Lp(e){return!e}function Rp(e){return[e.slug,e]}function zp(e){let t=(0,Q.c)(16),{value:n,onChange:r,disabled:i,disableOn:a,ariaLabel:o,className:s}=e,c=i===void 0?!1:i,l=a===void 0?!1:a,u;t[0]!==r||t[1]!==n?(u=function(){r(!n)},t[0]=r,t[1]=n,t[2]=u):u=t[2];let d=u,f=c||l&&!n,p;t[3]===s?p=t[4]:(p=K(`h-7 w-7 shrink-0 rounded-full border-0 bg-background hover:bg-background hover:text-foreground`,s),t[3]=s,t[4]=p);let m=!n&&`invisible`,h;t[5]===m?h=t[6]:(h=K(m),t[5]=m,t[6]=h);let g;t[7]===h?g=t[8]:(g=(0,$.jsx)(Xt,{"aria-hidden":`true`,className:h}),t[7]=h,t[8]=g);let _;return t[9]!==o||t[10]!==d||t[11]!==f||t[12]!==p||t[13]!==g||t[14]!==n?(_=(0,$.jsx)(Fe,{type:`button`,variant:`ghost`,size:`icon-sm`,role:`checkbox`,"aria-checked":n,"aria-label":o,disabled:f,onClick:d,className:p,children:g}),t[9]=o,t[10]=d,t[11]=f,t[12]=p,t[13]=g,t[14]=n,t[15]=_):_=t[15],_}var Bp=Pn(`app.use-seatbelt-sandbox.hook`);function Vp(){let[e,t]=(0,Z.useState)(!1),[n,r]=(0,Z.useState)(!1),[i,a]=(0,Z.useState)(!1),[o,s]=(0,Z.useState)(``),[c,l]=(0,Z.useState)(!0),[u,d]=(0,Z.useState)(!1);(0,Z.useEffect)(()=>{let e=!1;async function n(){try{let n=await Ue();e||(t(n.seatbeltSandboxEnabled),r(n.seatbeltSandboxSupported),a(n.seatbeltSandboxHealthy),s(n.seatbeltSandboxMessage))}catch(e){Bp.error(`Failed to load seatbelt sandbox setting:`,e)}finally{e||l(!1)}}return n(),()=>{e=!0}},[]);async function f(e){d(!0);try{let n=await Yt({seatbeltSandboxEnabled:e});t(n.seatbeltSandboxEnabled),r(n.seatbeltSandboxSupported),a(n.seatbeltSandboxHealthy),s(n.seatbeltSandboxMessage)}catch(e){throw Bp.error(`Failed to update seatbelt sandbox setting:`,e),e}finally{d(!1)}}return{isEnabled:e,isSupported:n,isHealthy:i,statusMessage:o,isLoading:c,isSaving:u,updateIsEnabled:f}}var Hp=[{value:`auto`,label:`Auto`,icon:jn,description:`Picks the model for a thread's first prompt`},{value:`build`,label:`Build`,icon:Br,description:`Executes code changes and implements features`},{value:`plan`,label:`Plan`,icon:yn,description:`Creates implementation plans without making changes`},{value:`image`,label:`Image`,icon:Mr,description:`Generates and edits images`},{value:`ralph`,label:`Ralph`,icon:F,description:`Runs rapid iterative test-fix cycles`},{value:`orchestrate`,label:`Orchestrate`,icon:nn,description:`Plans on a smart model and delegates implementation to a cheap model`}],Up={auto:{title:`Fast or Cheap model required`,description:`Auto needs a Fast or Cheap model alias to classify each prompt. Set one under Project Settings → Advanced → Model Aliases.`},orchestrate:{title:`Cheap model required`,description:`Orchestrate needs a Cheap model alias so implementation work can run on a lower-cost model. Set it under Project Settings → Advanced → Model Aliases.`}};function Wp(e){let t=(0,Q.c)(17),{requirement:n,onOpenChange:r,onOpenSettings:i}=e,a=Up[n??`orchestrate`],o=n!==null,s;t[0]===a.title?s=t[1]:(s=(0,$.jsx)(ca,{children:a.title}),t[0]=a.title,t[1]=s);let c;t[2]===a.description?c=t[3]:(c=(0,$.jsx)(qa,{children:a.description}),t[2]=a.description,t[3]=c);let l;t[4]!==s||t[5]!==c?(l=(0,$.jsxs)(ia,{children:[s,c]}),t[4]=s,t[5]=c,t[6]=l):l=t[6];let u;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(u=(0,$.jsx)(Xa,{children:`Cancel`}),t[7]=u):u=t[7];let d;t[8]===i?d=t[9]:(d=(0,$.jsxs)(na,{children:[u,(0,$.jsx)(oa,{onClick:i,children:`Open Project Settings`})]}),t[8]=i,t[9]=d);let f;t[10]!==l||t[11]!==d?(f=(0,$.jsxs)(Ci,{children:[l,d]}),t[10]=l,t[11]=d,t[12]=f):f=t[12];let p;return t[13]!==r||t[14]!==o||t[15]!==f?(p=(0,$.jsx)(Mi,{open:o,onOpenChange:r,children:f}),t[13]=r,t[14]=o,t[15]=f,t[16]=p):p=t[16],p}var Gp=Pn(`app.use-mode-menu.ui`);function Kp(e,t,n){return t?`${e}: ${t.provider}/${t.model}`:`${e}: ${n}`}function qp({planMode:e,imageMode:t,ralphMode:n,orchestrateMode:r,autoMode:i,setPlanMode:a,setImageMode:o,setRalphMode:s,setOrchestrateMode:l,setAutoMode:u,lastAutoRouteDecision:d=null,projectId:f,onOpenProjectSettings:p}){let m=Gi(),h=X(function(e){if(f)return e.projects.find(e=>e.projectId===f)}),[g,_]=Z.useState(!0),[y,b]=Z.useState(!1),[x,S]=Z.useState(null),C=v({planMode:e,imageMode:t,ralphMode:n,orchestrateMode:r,autoMode:i}),w=Hp.find(e=>e.value===C),T=c(h?.modelAliases),D=T||i?Hp:Hp.filter(e=>e.value!==`auto`),O=C===`auto`&&d?`last picked ${Ur[d]}`:w.description,k=he(h?.modelAliases),A=C===`auto`?[k?`Decides with: ${k.provider}/${k.model}`:`Decides with: Fast or Cheap, neither is set`,Kp(E.cheap,Se(`cheap`,h?.modelAliases),`not set`),Kp(E.smart,Ae(h?.modelAliases),`not set, uses your selected model`)]:[],j=(0,$.jsxs)(`div`,{className:`max-w-64 whitespace-normal text-left leading-relaxed`,children:[(0,$.jsx)(`p`,{children:`${w.label} - ${O}`}),A.map(e=>(0,$.jsx)(`p`,{children:e},e))]});Z.useEffect(()=>{h&&_(h.allowAllCommands===!1)},[h]),Z.useEffect(()=>{h&&i&&!T&&u(!1)},[i,T,h,u]);async function M(){if(!f||y)return;let e=!g;_(e),b(!0);try{await cn(f,{allowAllCommands:!e}),Ir(f);let t=await Bt();m({type:Y.SetProjects,projects:t.projects})}catch(t){_(!e),Gp.error(`Failed to update command confirmation setting:`,t)}finally{b(!1)}}function N(e){let t=Pr(e);a(t.planMode),o(t.imageMode),s(t.ralphMode),l(t.orchestrateMode),u(t.autoMode)}async function P(e){if(f)try{await cn(f,{defaultChatMode:e}),Ir(f);let t=await Bt();m({type:Y.SetProjects,projects:t.projects})}catch(e){Gp.error(`Failed to save the project's default mode:`,e)}}function F(){N(`orchestrate`)}function I(){return En(h?.modelAliases)?!0:(S(`orchestrate`),!1)}function L(){return I()?(F(),!0):!1}function R(){return I()?(F(),!0):!1}function z(e){if(e===`orchestrate`){L()&&P(e);return}if(e===`auto`&&!T){S(`auto`);return}N(e),P(e)}function B(){S(null),f&&p&&p(f)}return{chatModes:D,confirmCommands:g,currentConfig:w,currentMode:C,modeTooltipContent:j,isUpdatingConfirmCommands:y,selectMode:z,trySelectOrchestrate:L,ensureCanOrchestrate:I,requestOrchestrateMode:R,toggleConfirmCommands:M,cheapAliasDialog:(0,$.jsx)(Wp,{requirement:x,onOpenChange:e=>{e||S(null)},onOpenSettings:B})}}function Jp(e){return e.replace(/[-_]+/g,` `).trim().split(/\s+/g).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `)}function Yp(e,t){return t&&e.skillPath.startsWith(`${t}/`)?`${e.skillPath.slice(t.length+1)}/SKILL.md`:`.agents/skills/${e.name}/SKILL.md`}function Xp(e){let t=(0,Q.c)(11),{skill:n,onOpen:r}=e,i;t[0]===n.name?i=t[1]:(i=Jp(n.name),t[0]=n.name,t[1]=i);let a=`Open ${i} in Files`,o;t[2]===r?o=t[3]:(o=e=>{e.stopPropagation(),r()},t[2]=r,t[3]=o);let s;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(s=(0,$.jsx)(oe,{}),t[4]=s):s=t[4];let c;t[5]!==a||t[6]!==o?(c=(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsx)(Fe,{type:`button`,variant:`action`,size:`icon-xs`,className:`ml-auto shrink-0`,"aria-label":a,onClick:o,onPointerDown:Zp,children:s})}),t[5]=a,t[6]=o,t[7]=c):c=t[7];let l;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,$.jsx)(Qa,{children:`Open in Files`}),t[8]=l):l=t[8];let u;return t[9]===c?u=t[10]:(u=(0,$.jsxs)(sa,{children:[c,l]}),t[9]=c,t[10]=u),u}function Zp(e){e.stopPropagation()}function Qp(e){let t=(0,Q.c)(16),{icon:n,iconClassName:r,label:i,value:a,onChange:o,disabled:s,disableOn:c,ariaLabel:l}=e,u=s===void 0?!1:s,d=c===void 0?!1:c,f;t[0]!==n||t[1]!==r?(f=(0,$.jsx)(n,{className:r}),t[0]=n,t[1]=r,t[2]=f):f=t[2];let p;t[3]!==i||t[4]!==f?(p=(0,$.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[f,i]}),t[3]=i,t[4]=f,t[5]=p):p=t[5];let m;t[6]!==l||t[7]!==d||t[8]!==u||t[9]!==o||t[10]!==a?(m=(0,$.jsx)(`span`,{onPointerDown:em,onClick:$p,children:(0,$.jsx)(zp,{value:a,onChange:o,disabled:u,disableOn:d,ariaLabel:l})}),t[6]=l,t[7]=d,t[8]=u,t[9]=o,t[10]=a,t[11]=m):m=t[11];let h;return t[12]!==u||t[13]!==p||t[14]!==m?(h=(0,$.jsxs)(ya,{className:`flex items-center justify-between gap-2 [&_svg]:size-3.5`,onSelect:tm,disabled:u,children:[p,m]}),t[12]=u,t[13]=p,t[14]=m,t[15]=h):h=t[15],h}function $p(e){e.stopPropagation()}function em(e){e.stopPropagation()}function tm(e){e.preventDefault()}function nm(e){let t=(0,Q.c)(135),{planMode:n,imageMode:r,ralphMode:i,orchestrateMode:a,autoMode:o,setPlanMode:c,setImageMode:l,setRalphMode:u,setOrchestrateMode:d,setAutoMode:f,lastAutoRouteDecision:p,projectId:m,disabled:h,canAddTask:g,skills:_,onSelectSkill:v,slashCommands:y,onSelectSlashCommand:b,onFileAttach:x,onAddTask:S}=e,C=p===void 0?null:p,w=h===void 0?!1:h,E=ua(),[D,O]=(0,Z.useState)(!1),{isEnabled:k,isSupported:A,isHealthy:j,isLoading:M,isSaving:N,updateIsEnabled:P}=Vp(),{setPendingExplorerPath:F}=ko(),{openChatDockPanel:I}=Yc(),L=X(om),R;t[0]!==o||t[1]!==r||t[2]!==C||t[3]!==E||t[4]!==a||t[5]!==n||t[6]!==m||t[7]!==i||t[8]!==f||t[9]!==l||t[10]!==d||t[11]!==c||t[12]!==u?(R={planMode:n,imageMode:r,ralphMode:i,orchestrateMode:a,autoMode:o,setPlanMode:c,setImageMode:l,setRalphMode:u,setOrchestrateMode:d,setAutoMode:f,lastAutoRouteDecision:C,projectId:m,onOpenProjectSettings(e){E(`/settings/project/${e}?section=model-aliases`)}},t[0]=o,t[1]=r,t[2]=C,t[3]=E,t[4]=a,t[5]=n,t[6]=m,t[7]=i,t[8]=f,t[9]=l,t[10]=d,t[11]=c,t[12]=u,t[13]=R):R=t[13];let{chatModes:z,confirmCommands:B,currentConfig:ee,currentMode:te,modeTooltipContent:ne,isUpdatingConfirmCommands:re,selectMode:ie,toggleConfirmCommands:ae,cheapAliasDialog:oe}=qp(R),se,ce,le,ue,de,fe,pe,V,me,he,ge,_e,ve,ye,be,xe;if(t[14]!==z||t[15]!==B||t[16]!==ee.icon||t[17]!==ee.label||t[18]!==te||t[19]!==w||t[20]!==M||t[21]!==N||t[22]!==re||t[23]!==D||t[24]!==ne||t[25]!==v||t[26]!==I||t[27]!==m||t[28]!==L||t[29]!==k||t[30]!==j||t[31]!==A||t[32]!==ie||t[33]!==F||t[34]!==_||t[35]!==ae||t[36]!==P){let e=[..._].sort(am),n;t[53]!==I||t[54]!==L||t[55]!==F?(n=function(e){F(Yp(e,L)),I(`explorer`),O(!1)},t[53]=I,t[54]=L,t[55]=F,t[56]=n):n=t[56];let r=n;ue=fa,V=D,me=O;let i;t[57]===ee.icon?i=t[58]:(i=(0,$.jsx)(ee.icon,{className:`h-4 w-4`}),t[57]=ee.icon,t[58]=i);let a;t[59]===ee.label?a=t[60]:(a=(0,$.jsxs)(`span`,{className:`sr-only`,children:[ee.label,` mode`]}),t[59]=ee.label,t[60]=a);let o;t[61]!==w||t[62]!==i||t[63]!==a?(o=(0,$.jsx)(Ji,{asChild:!0,children:(0,$.jsxs)(Fe,{variant:`action`,size:`icon-sm`,disabled:w,children:[i,a]})}),t[61]=w,t[62]=i,t[63]=a,t[64]=o):o=t[64];let c;t[65]!==M||t[66]!==k||t[67]!==A?(c=A&&!M&&!k&&(0,$.jsx)(`span`,{className:`absolute -right-0.5 -top-0.5 h-2.5 w-2.5 rounded-full bg-destructive ring-2 ring-background`}),t[65]=M,t[66]=k,t[67]=A,t[68]=c):c=t[68];let l;t[69]!==o||t[70]!==c?(l=(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsxs)(`div`,{className:`relative`,children:[o,c]})}),t[69]=o,t[70]=c,t[71]=l):l=t[71];let u;if(t[72]===ne?u=t[73]:(u=(0,$.jsx)(Qa,{children:ne}),t[72]=ne,t[73]=u),t[74]!==l||t[75]!==u?(he=(0,$.jsx)(Ti,{children:(0,$.jsxs)(sa,{children:[l,u]})}),t[74]=l,t[75]=u,t[76]=he):he=t[76],le=Ei,ye=`start`,be=`top`,xe=`w-56`,t[77]!==B||t[78]!==M||t[79]!==N||t[80]!==re||t[81]!==m||t[82]!==k||t[83]!==j||t[84]!==A||t[85]!==ae||t[86]!==P?(de=(m||A&&!M)&&(0,$.jsxs)($.Fragment,{children:[m&&(0,$.jsx)(Qp,{icon:Hr,label:`Confirm Commands`,value:B,onChange:()=>{ae()},disabled:re,ariaLabel:`Confirm Commands`}),A&&!M&&(0,$.jsx)(Qp,{icon:s,iconClassName:K(k&&j?`text-brand`:`text-destructive`),label:`Sandbox`,value:k&&j,onChange:e=>{e&&!j||P(e).catch(im)},disabled:N||!j&&!k,disableOn:!j,ariaLabel:`Sandbox`}),(0,$.jsx)(_a,{})]}),t[77]=B,t[78]=M,t[79]=N,t[80]=re,t[81]=m,t[82]=k,t[83]=j,t[84]=A,t[85]=ae,t[86]=P,t[87]=de):de=t[87],t[88]!==z||t[89]!==te||t[90]!==ie){let e;t[92]!==te||t[93]!==ie?(e=e=>{let t=e.icon,n=e.value===te;return(0,$.jsxs)(ya,{onClick:()=>ie(e.value),className:K(n&&`bg-accent`),children:[(0,$.jsx)(t,{className:`h-3.5 w-3.5`}),e.label,n&&(0,$.jsx)(Xt,{className:`ml-auto h-3.5 w-3.5`})]},e.value)},t[92]=te,t[93]=ie,t[94]=e):e=t[94],fe=z.map(e),t[88]=z,t[89]=te,t[90]=ie,t[91]=fe}else fe=t[91];t[95]===Symbol.for(`react.memo_cache_sentinel`)?(pe=(0,$.jsx)(_a,{}),t[95]=pe):pe=t[95],ce=Bi,t[96]===Symbol.for(`react.memo_cache_sentinel`)?(ve=(0,$.jsxs)(oo,{children:[(0,$.jsx)(T,{className:`h-3.5 w-3.5`}),`Skills`]}),t[96]=ve):ve=t[96],se=Zi,ge=`max-h-[min(400px,80vh)] w-64 overflow-y-auto`,_e=e.length===0?(0,$.jsx)(ya,{disabled:!0,children:`No skills available`}):e.map(e=>(0,$.jsxs)(ya,{onClick:()=>v(e),className:`gap-2 [&_svg]:size-3`,children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:Jp(e.name)}),(0,$.jsx)(Xp,{skill:e,onOpen:()=>r(e)})]},e.skillPath)),t[14]=z,t[15]=B,t[16]=ee.icon,t[17]=ee.label,t[18]=te,t[19]=w,t[20]=M,t[21]=N,t[22]=re,t[23]=D,t[24]=ne,t[25]=v,t[26]=I,t[27]=m,t[28]=L,t[29]=k,t[30]=j,t[31]=A,t[32]=ie,t[33]=F,t[34]=_,t[35]=ae,t[36]=P,t[37]=se,t[38]=ce,t[39]=le,t[40]=ue,t[41]=de,t[42]=fe,t[43]=pe,t[44]=V,t[45]=me,t[46]=he,t[47]=ge,t[48]=_e,t[49]=ve,t[50]=ye,t[51]=be,t[52]=xe}else se=t[37],ce=t[38],le=t[39],ue=t[40],de=t[41],fe=t[42],pe=t[43],V=t[44],me=t[45],he=t[46],ge=t[47],_e=t[48],ve=t[49],ye=t[50],be=t[51],xe=t[52];let Se;t[97]!==se||t[98]!==ge||t[99]!==_e?(Se=(0,$.jsx)(se,{className:ge,children:_e}),t[97]=se,t[98]=ge,t[99]=_e,t[100]=Se):Se=t[100];let Ce;t[101]!==ce||t[102]!==Se||t[103]!==ve?(Ce=(0,$.jsxs)(ce,{children:[ve,Se]}),t[101]=ce,t[102]=Se,t[103]=ve,t[104]=Ce):Ce=t[104];let we;t[105]!==b||t[106]!==y?(we=y.length>0&&(0,$.jsxs)(Bi,{children:[(0,$.jsxs)(oo,{children:[(0,$.jsx)(Ee,{className:`h-3.5 w-3.5`}),`Slash Commands`]}),(0,$.jsx)(Zi,{className:`max-h-[min(400px,80vh)] w-64 overflow-y-auto`,children:[...y].sort(rm).map(e=>(0,$.jsxs)(ya,{onClick:()=>b(e),className:`gap-2 [&_svg]:size-3`,children:[(0,$.jsxs)(`span`,{className:`min-w-0 flex-1 truncate`,children:[`/`,e.name]}),e.metadata.description&&(0,$.jsx)(`span`,{className:`text-muted-foreground truncate text-xs`,children:e.metadata.description})]},e.filePath))})]}),t[105]=b,t[106]=y,t[107]=we):we=t[107];let Te;t[108]===Symbol.for(`react.memo_cache_sentinel`)?(Te=(0,$.jsx)(Pe,{className:`h-3.5 w-3.5`}),t[108]=Te):Te=t[108];let H;t[109]===x?H=t[110]:(H=(0,$.jsxs)(ya,{onClick:x,children:[Te,`Attach File`]}),t[109]=x,t[110]=H);let De;t[111]!==g||t[112]!==S?(De=g&&(0,$.jsxs)(ya,{onClick:S,children:[(0,$.jsx)(Wn,{className:`h-3.5 w-3.5`}),`Add Prompt`]}),t[111]=g,t[112]=S,t[113]=De):De=t[113];let Oe;t[114]!==le||t[115]!==de||t[116]!==fe||t[117]!==pe||t[118]!==Ce||t[119]!==we||t[120]!==H||t[121]!==De||t[122]!==ye||t[123]!==be||t[124]!==xe?(Oe=(0,$.jsxs)(le,{align:ye,side:be,className:xe,children:[de,fe,pe,Ce,we,H,De]}),t[114]=le,t[115]=de,t[116]=fe,t[117]=pe,t[118]=Ce,t[119]=we,t[120]=H,t[121]=De,t[122]=ye,t[123]=be,t[124]=xe,t[125]=Oe):Oe=t[125];let ke;t[126]!==ue||t[127]!==V||t[128]!==me||t[129]!==he||t[130]!==Oe?(ke=(0,$.jsxs)(ue,{open:V,onOpenChange:me,children:[he,Oe]}),t[126]=ue,t[127]=V,t[128]=me,t[129]=he,t[130]=Oe,t[131]=ke):ke=t[131];let Ae;return t[132]!==oe||t[133]!==ke?(Ae=(0,$.jsxs)($.Fragment,{children:[ke,oe]}),t[132]=oe,t[133]=ke,t[134]=Ae):Ae=t[134],Ae}function rm(e,t){return e.name.localeCompare(t.name)}function im(){}function am(e,t){return Jp(e.name).localeCompare(Jp(t.name))}function om(e){return e.projects.find(t=>t.projectId===e.selectedProjectId)?.threads.find(t=>t.threadId===e.selectedThreadId)?.path}function sm(){if(typeof window>`u`)return null;let e=window;return e.SpeechRecognition??e.webkitSpeechRecognition??null}function cm(){return sm()!==null}function lm(){let e=sm();return e?new e:null}var um=!1;function dm(){um||typeof globalThis.fetch!=`function`||(ke(e=>{if(e.event.startsWith(`voice.`))try{fetch(`/api/logs`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({level:[`DEBUG`,`INFO`,`WARN`,`ERROR`][e.level]??`INFO`,context:e.event,message:e.message,data:e.data})}).catch(()=>{})}catch{}}),um=!0)}function fm(e){dm();let t=Pn(e);return{debug:(e,n)=>t.debug(e,n),info:(e,n)=>t.info(e,n),warn:(e,n)=>t.warn(e,n),error:(e,n)=>t.error(e,n),separator:e=>t.info(`${`─`.repeat(20)} ${e} ${`─`.repeat(20)}`)}}var pm=fm(`voice.stt.web`);function mm(e){switch(e){case`not-allowed`:return`Microphone access was denied. Please allow microphone access to use voice input.`;case`service-not-allowed`:return`Speech recognition is not allowed in this environment.`;case`audio-capture`:return`No microphone was found. Please connect a microphone to use voice input.`;case`network`:return`Speech recognition requires a network connection.`;case`no-speech`:case`aborted`:return null;default:return`Speech recognition error: ${e}`}}function hm(e){let t=``;for(let n=0;n<e.results.length;n+=1)t+=e.results[n][0]?.transcript??``;return t}function gm(){let[e,t]=(0,Z.useState)(`idle`),[n,r]=(0,Z.useState)(null),[i,a]=(0,Z.useState)(``),[o,s]=(0,Z.useState)(null),c=(0,Z.useRef)(null),l=(0,Z.useRef)(!1);(0,Z.useEffect)(()=>()=>{l.current=!1,c.current?.abort(),c.current=null},[]);let u=(0,Z.useCallback)(()=>{let e=lm();if(!e){l.current=!1,t(`error`),r(!1),s(`Speech recognition is not supported in this environment.`);return}e.continuous=!0,e.interimResults=!0,e.lang=`en-US`,e.onresult=e=>{let t=hm(e).trim();t&&a(t)},e.onerror=e=>{let t=mm(e.error);pm.error(`Web Speech recognition error`,{error:e.error,message:e.message}),t&&s(t)},e.onend=()=>{if(c.current=null,!l.current){t(`ready`);return}pm.info(`Web Speech recognition ended — restarting`),u()},c.current=e;try{e.start(),t(`recording`),pm.info(`Web Speech recognition started`)}catch(e){c.current=null,l.current=!1;let n=e instanceof Error?e.message:`Unknown error`;pm.error(`Failed to start Web Speech recognition`,{error:n}),t(`ready`),s(`Failed to start speech recognition: ${n}`)}},[]),d=(0,Z.useCallback)(async()=>{if(e===`ready`||e===`error`)return e;t(`checking-support`),s(null),pm.info(`Checking Web Speech API support`,{userAgent:navigator.userAgent,platform:navigator.platform});let n=cm();return r(n),n?(pm.info(`Web Speech API available — ready`),t(`ready`),`ready`):(pm.error(`Web Speech API not available`),t(`error`),s(`Speech recognition is not supported in this environment.`),`error`)},[e]);return{state:e,isSupported:n,transcript:i,error:o,downloadProgress:0,startListening:(0,Z.useCallback)(async()=>{l.current=!0,s(null),a(``),pm.info(`Starting Web Speech recognition`),u()},[u]),stopListening:(0,Z.useCallback)(async()=>{l.current=!1,c.current?.stop(),c.current=null,t(`ready`),pm.info(`Web Speech recognition stopped`)},[]),requestModelDownload:(0,Z.useCallback)(async()=>{},[]),ensureReady:d,resetTranscript:(0,Z.useCallback)(()=>{a(``),s(null)},[])}}var _m=class{cacheEnabled=!0;log=Pn(`voice.vosk-cache`);async getCachedModelByUrl(e){return this.cacheEnabled?this.readCachedModelByUrl(e):null}async loadModelByUrl(e,t){let n=await this.getCachedModelByUrl(e);if(n)return this.log.info(`Voice model loaded from cache`,{url:e}),t?.(100),n;this.log.info(`Downloading voice model`,{url:e});let r=await fetch(e);if(!r.ok)throw Error(`Failed to download voice model: ${r.statusText}`);let i=await this.fetchBinaryWithProgress(r,t);return this.cacheEnabled&&await this.saveModelToCacheByUrl(e,i),t?.(100),i}async fetchBinaryWithProgress(e,t){let n=e.headers.get(`content-length`),r=n?parseInt(n,10):0,i=0,a=e.body?.getReader();if(!a)throw Error(`Response body is not readable`);let o=[];try{let e=!1;for(;!e;){let n=await a.read();e=n.done,!e&&n.value&&(o.push(n.value),i+=n.value.length,t&&r>0&&t(Math.round(i/r*100)))}}finally{a.releaseLock()}let s=o.reduce((e,t)=>e+t.length,0),c=new Uint8Array(s),l=0;for(let e of o)c.set(e,l),l+=e.length;return c}async readCachedModelByUrl(e){try{let t=(await this.openIndexedDB()).transaction([`modelsByUrl`],`readonly`).objectStore(`modelsByUrl`);return new Promise((n,r)=>{let i=t.get(e);i.onsuccess=()=>{let e=i.result;e?.data?n(e.data):n(null)},i.onerror=()=>r(i.error)})}catch(e){return this.log.error(`Error reading voice model from cache`,e),null}}async saveModelToCacheByUrl(e,t){try{let n=(await this.openIndexedDB()).transaction([`modelsByUrl`],`readwrite`).objectStore(`modelsByUrl`);await new Promise((r,i)=>{let a=n.put({url:e,data:t,timestamp:Date.now(),size:t.length});a.onsuccess=()=>r(),a.onerror=()=>i(a.error)}),this.log.info(`Voice model saved to cache`,{url:e})}catch(e){this.log.error(`Error saving voice model to cache`,e)}}async openIndexedDB(){return new Promise((e,t)=>{let n=indexedDB.open(`VoskModels`,1);n.onerror=()=>t(n.error),n.onsuccess=()=>e(n.result),n.onupgradeneeded=e=>{let t=e.target.result;if(!t.objectStoreNames.contains(`modelsByUrl`)){let e=t.createObjectStore(`modelsByUrl`,{keyPath:`url`});e.createIndex(`timestamp`,`timestamp`,{unique:!1}),e.createIndex(`size`,`size`,{unique:!1})}}})}},vm=fm(`voice.stt.vosk`),ym=new URL(`data:text/javascript;base64,Y2xhc3MgUmVjb2duaXplckF1ZGlvUHJvY2Vzc29yIGV4dGVuZHMgQXVkaW9Xb3JrbGV0UHJvY2Vzc29yIHsKICBjb25zdHJ1Y3RvcihvcHRpb25zKSB7CiAgICBzdXBlcihvcHRpb25zKTsKICAgIHRoaXMucG9ydC5vbm1lc3NhZ2UgPSB0aGlzLl9wcm9jZXNzTWVzc2FnZS5iaW5kKHRoaXMpOwogIH0KCiAgX3Byb2Nlc3NNZXNzYWdlKGV2ZW50KSB7CiAgICBpZiAoZXZlbnQuZGF0YS5hY3Rpb24gPT09ICJpbml0IikgewogICAgICB0aGlzLl9yZWNvZ25pemVySWQgPSBldmVudC5kYXRhLnJlY29nbml6ZXJJZDsKICAgICAgdGhpcy5fcmVjb2duaXplclBvcnQgPSBldmVudC5wb3J0c1swXTsKICAgIH0KICB9CgogIHByb2Nlc3MoaW5wdXRzKSB7CiAgICBjb25zdCBkYXRhID0gaW5wdXRzWzBdWzBdOwogICAgaWYgKHRoaXMuX3JlY29nbml6ZXJQb3J0ICYmIGRhdGEpIHsKICAgICAgY29uc3QgYXVkaW9BcnJheSA9IGRhdGEubWFwKCh2YWx1ZSkgPT4gdmFsdWUgKiAweDgwMDApOwoKICAgICAgdGhpcy5fcmVjb2duaXplclBvcnQucG9zdE1lc3NhZ2UoCiAgICAgICAgewogICAgICAgICAgYWN0aW9uOiAiYXVkaW9DaHVuayIsCiAgICAgICAgICBkYXRhOiBhdWRpb0FycmF5LAogICAgICAgICAgcmVjb2duaXplcklkOiB0aGlzLl9yZWNvZ25pemVySWQsCiAgICAgICAgICBzYW1wbGVSYXRlLAogICAgICAgIH0sCiAgICAgICAgewogICAgICAgICAgdHJhbnNmZXI6IFthdWRpb0FycmF5LmJ1ZmZlcl0sCiAgICAgICAgfSwKICAgICAgKTsKICAgIH0KICAgIHJldHVybiB0cnVlOwogIH0KfQoKcmVnaXN0ZXJQcm9jZXNzb3IoInJlY29nbml6ZXItcHJvY2Vzc29yIiwgUmVjb2duaXplckF1ZGlvUHJvY2Vzc29yKTsK`,``+import.meta.url);async function bm(t){let{createModel:n}=await po(async()=>{let{createModel:t}=await import(`./vosk-speech-Fi-g2v8n.js`).then(t=>e(t.t(),1));return{createModel:t}},__vite__mapDeps([2,1]));return n(t)}var xm=class{model=null;modelBlobUrl=null;checkSupport(){return typeof WebAssembly<`u`&&typeof Worker<`u`&&typeof indexedDB<`u`}async initModel(e){vm.info(`Initializing Vosk model`,{modelUrl:e});try{this.model=await bm(e),vm.info(`Vosk model ready`)}catch(e){let t=e instanceof Error?e.message:String(e);throw vm.error(`Failed to initialize Vosk model`,{error:t}),Error(`Failed to initialize voice model: ${t}`)}}async initModelFromBytes(e){this.revokeModelBlobUrl();let t=new Uint8Array(e),n=new Blob([t],{type:`application/gzip`});this.modelBlobUrl=URL.createObjectURL(n);try{await this.initModel(this.modelBlobUrl)}catch(e){throw this.revokeModelBlobUrl(),e}}isModelLoaded(){return this.model?.ready===!0}async startMicPipeline(e){if(!this.model?.ready)throw Error(`Voice model is not loaded.`);let t=this.model,n=t.KaldiRecognizer,r=await navigator.mediaDevices.getUserMedia({video:!1,audio:{echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0,channelCount:1}}),i=new AudioContext,a=new n(i.sampleRate),o=i.createMediaStreamSource(r);a.on(`partialresult`,t=>{let n=t.result.partial.trim();n&&e.onPartial(n)}),a.on(`result`,t=>{let n=t.result.text.trim();n&&e.onResult(n)});let s=await Sm(i,t,a,o);return s.audioNode.connect(i.destination),vm.info(`Vosk mic pipeline started`,{sampleRate:i.sampleRate,processor:s.processorType}),{stop:async()=>{s.audioNode.disconnect(),o.disconnect(),s.messageChannel?.port1.close(),s.messageChannel?.port2.close(),r.getTracks().forEach(e=>e.stop()),a.retrieveFinalResult(),await i.close(),a.remove(),vm.info(`Vosk mic pipeline stopped`)}}}terminate(){this.model?.terminate(),this.model=null,this.revokeModelBlobUrl()}revokeModelBlobUrl(){this.modelBlobUrl&&=(URL.revokeObjectURL(this.modelBlobUrl),null)}};async function Sm(e,t,n,r){return await Cm(e,t,n,r)||(vm.warn(`AudioWorklet unavailable — falling back to ScriptProcessorNode`),wm(e,n,r))}async function Cm(e,t,n,r){if(!e.audioWorklet)return null;try{await e.audioWorklet.addModule(ym);let i=new MessageChannel;t.registerPort(i.port1);let a=new AudioWorkletNode(e,`recognizer-processor`,{channelCount:1,numberOfInputs:1,numberOfOutputs:1});return a.port.postMessage({action:`init`,recognizerId:n.id},[i.port2]),r.connect(a),{audioNode:a,messageChannel:i,processorType:`audioworklet`}}catch(e){return vm.warn(`Failed to initialize AudioWorklet pipeline`,{error:e instanceof Error?e.message:String(e)}),null}}function wm(e,t,n){let r=e.createScriptProcessor(4096,1,1);return r.onaudioprocess=e=>{try{t.acceptWaveform(e.inputBuffer)}catch(e){vm.error(`acceptWaveform failed`,{error:e instanceof Error?e.message:String(e)})}},n.connect(r),{audioNode:r,processorType:`scriptprocessor`}}var Tm=`/api/voice-model/download`;function Em(){return Tm}var Dm=fm(`voice.stt.vosk-hook`);function Om(e,t){let n=e.trim(),r=t.trim();return n&&r?`${n} ${r}`:n||r}function km(){let[e,t]=(0,Z.useState)(`idle`),[n,r]=(0,Z.useState)(null),[i,a]=(0,Z.useState)(``),[o,s]=(0,Z.useState)(null),[c,l]=(0,Z.useState)(0),u=(0,Z.useRef)(null),d=(0,Z.useRef)(null),f=(0,Z.useRef)(null),p=(0,Z.useRef)(null),m=(0,Z.useRef)(!1),h=(0,Z.useRef)(``),g=(0,Z.useRef)(``),_=(0,Z.useCallback)(e=>{m.current=e},[]);(0,Z.useEffect)(()=>()=>{f.current?.stop(),f.current=null,u.current?.terminate(),u.current=null},[]);let v=(0,Z.useCallback)(()=>{a(Om(h.current,g.current))},[]),y=(0,Z.useCallback)(async()=>{if(e===`ready`||e===`needs-model`||e===`error`)return e;if(p.current)return p.current;let n=Em();async function i(){t(`checking-support`),_(!1),l(0),s(null),Dm.separator(`VOICE SESSION START`),Dm.info(`Checking Vosk support`,{userAgent:navigator.userAgent,platform:navigator.platform,url:n});try{let e=new xm;u.current=e;let i=e.checkSupport();if(r(i),!i)return Dm.error(`Vosk not supported in this environment`),t(`error`),s(`Local speech recognition is not supported in this environment.`),`error`;let a=new _m;d.current=a,Dm.info(`Checking IndexedDB model cache`,{url:n});let o=await a.getCachedModelByUrl(n);return o?(Dm.info(`Cached model found — initializing Vosk`,{sizeBytes:o.byteLength,sizeMB:(o.byteLength/1024/1024).toFixed(2)}),_(!0),t(`initializing`),await e.initModelFromBytes(o),Dm.info(`Vosk model initialized from cache — ready`),t(`ready`),`ready`):(Dm.info(`Model not in cache — download required`),t(`needs-model`),`needs-model`)}catch(e){let n=e instanceof Error?e.message:`Unknown error`;return Dm.error(`Failed to check speech recognition support`,{error:n}),t(`error`),s(`Failed to check speech recognition support: ${n}`),`error`}}let a=i();p.current=a;try{return await a}finally{p.current=null}},[e,_]),b=(0,Z.useCallback)(async()=>{if(!u.current||!d.current)return;let e=Em();t(`downloading-model`),l(0),s(null),Dm.info(`Model download requested`,{url:e});try{let n=await d.current.loadModelByUrl(e,e=>{l(e),e%10==0&&Dm.debug(`Model download progress`,{progress:e})});Dm.info(`Model download complete — initializing Vosk`,{sizeBytes:n.byteLength,sizeMB:(n.byteLength/1024/1024).toFixed(2)}),t(`initializing`),await u.current.initModelFromBytes(n),Dm.info(`Vosk model initialized after download — ready`),_(!0),t(`ready`)}catch(e){let n=e instanceof Error?e.message:`An unknown error occurred.`;Dm.error(`Model download or initialization failed`,{error:n}),t(`needs-model`),s(n)}},[_]);return{state:e,isSupported:n,transcript:i,error:o,downloadProgress:c,startListening:(0,Z.useCallback)(async()=>{if(!(!u.current||!m.current)){if(t(`requesting-mic`),s(null),h.current=``,g.current=``,a(``),Dm.separator(`RECORDING START`),!navigator.mediaDevices?.getUserMedia){Dm.error(`navigator.mediaDevices.getUserMedia not available`),t(`ready`),s(`Microphone is not available in this environment.`);return}try{f.current=await u.current.startMicPipeline({onPartial:e=>{g.current=e,v()},onResult:e=>{let t=h.current.trim();h.current=t?`${t} ${e}`:e,g.current=``,v()}}),t(`recording`),Dm.info(`Recording started`)}catch(e){t(`ready`),e instanceof DOMException&&e.name===`NotAllowedError`?s(`Microphone access was denied. Please allow microphone access to use voice input.`):e instanceof DOMException&&e.name===`NotFoundError`?s(`No microphone was found. Please connect a microphone to use voice input.`):s(`Microphone error: ${e instanceof Error?e.message:`Unknown error`}`)}}},[v]),stopListening:(0,Z.useCallback)(async()=>{if(!f.current){Dm.info(`stopListening called but no active recording`),m.current&&t(`ready`);return}t(`transcribing`),Dm.info(`Stopping recording`);try{await f.current.stop(),g.current=``,v(),t(`ready`),Dm.info(`Recording stopped`)}catch(e){let n=e instanceof Error?e.message:`Unknown error`;Dm.error(`Failed to stop recording`,{error:n}),t(`ready`),s(`Failed to stop recording: ${n}`)}finally{f.current=null}},[v]),requestModelDownload:b,ensureReady:y,resetTranscript:(0,Z.useCallback)(()=>{h.current=``,g.current=``,a(``),s(null)},[])}}function Am(){let e=(0,Q.c)(22),t=km(),n=gm();if(Ln()){let n;return e[0]!==t.downloadProgress||e[1]!==t.ensureReady||e[2]!==t.error||e[3]!==t.isSupported||e[4]!==t.requestModelDownload||e[5]!==t.resetTranscript||e[6]!==t.startListening||e[7]!==t.state||e[8]!==t.stopListening||e[9]!==t.transcript?(n={state:t.state,isSupported:t.isSupported,usesLocalModel:!0,transcript:t.transcript,error:t.error,downloadProgress:t.downloadProgress,startListening:t.startListening,stopListening:t.stopListening,requestModelDownload:t.requestModelDownload,ensureReady:t.ensureReady,resetTranscript:t.resetTranscript},e[0]=t.downloadProgress,e[1]=t.ensureReady,e[2]=t.error,e[3]=t.isSupported,e[4]=t.requestModelDownload,e[5]=t.resetTranscript,e[6]=t.startListening,e[7]=t.state,e[8]=t.stopListening,e[9]=t.transcript,e[10]=n):n=e[10],n}let r;return e[11]!==n.downloadProgress||e[12]!==n.ensureReady||e[13]!==n.error||e[14]!==n.isSupported||e[15]!==n.requestModelDownload||e[16]!==n.resetTranscript||e[17]!==n.startListening||e[18]!==n.state||e[19]!==n.stopListening||e[20]!==n.transcript?(r={state:n.state,isSupported:n.isSupported,usesLocalModel:!1,transcript:n.transcript,error:n.error,downloadProgress:n.downloadProgress,startListening:n.startListening,stopListening:n.stopListening,requestModelDownload:n.requestModelDownload,ensureReady:n.ensureReady,resetTranscript:n.resetTranscript},e[11]=n.downloadProgress,e[12]=n.ensureReady,e[13]=n.error,e[14]=n.isSupported,e[15]=n.requestModelDownload,e[16]=n.resetTranscript,e[17]=n.startListening,e[18]=n.state,e[19]=n.stopListening,e[20]=n.transcript,e[21]=r):r=e[21],r}var jm=new Map;function Mm(e){let t=jm.get(e);if(t)return t;let n=Pn(e);return jm.set(e,n),n}function Nm({key:e,defaultValue:t,logScope:n,settingLabel:r}){let[i,a]=(0,Z.useState)(t),[o,s]=(0,Z.useState)(!0),[c,l]=(0,Z.useState)(!1);(0,Z.useEffect)(()=>{let t=!1,i=Mm(n);async function o(){try{let n=await Ue();t||a(n[e])}catch(e){i.error(`Failed to load ${r} setting:`,e)}finally{t||s(!1)}}return o(),()=>{t=!0}},[e,n,r]);async function u(t){let i=Mm(n);l(!0);try{a((await Yt({[e]:t}))[e])}catch(e){throw i.error(`Failed to update ${r} setting:`,e),e}finally{l(!1)}}return{isEnabled:i,isLoading:o,isSaving:c,updateIsEnabled:u}}function Pm(){let e=(0,Q.c)(1),t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t={key:`voiceAiProcessing`,defaultValue:!0,logScope:`app.use-voice-ai-processing.hook`,settingLabel:`voice AI processing`},e[0]=t):t=e[0],Nm(t)}var Fm=Z.forwardRef((e,t)=>{let n=(0,Q.c)(13),r,i,a;n[0]===e?(r=n[1],i=n[2],a=n[3]):({className:r,value:a,...i}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a);let o;n[4]===r?o=n[5]:(o=K(`relative h-4 w-full overflow-hidden rounded-full bg-secondary`,r),n[4]=r,n[5]=o);let s=`translateX(-${100-(a||0)}%)`,c;n[6]===s?c=n[7]:(c=(0,$.jsx)(ii,{className:`h-full w-full flex-1 bg-primary transition-all`,style:{transform:s}}),n[6]=s,n[7]=c);let l;return n[8]!==i||n[9]!==t||n[10]!==o||n[11]!==c?(l=(0,$.jsx)(mi,{ref:t,className:o,...i,children:c}),n[8]=i,n[9]=t,n[10]=o,n[11]=c,n[12]=l):l=n[12],l});Fm.displayName=mi.displayName;function Im(e,t,n){return t?`Preparing voice input…`:n<100?`Downloading voice model… ${n}%`:e?`Finishing download…`:`Downloading voice model…`}function Lm(e){let t=(0,Q.c)(24),{open:n,onOpenChange:r,onRetry:i,isDownloading:a,isInitializing:o,progress:s,error:c}=e,l=a||o,u;t[0]!==l||t[1]!==r?(u=function(e){l&&!e||r(e)},t[0]=l,t[1]=r,t[2]=u):u=t[2];let d=u,f=c?`Voice model download failed`:`Setting up voice input`,p;t[3]===f?p=t[4]:(p=(0,$.jsx)(un,{children:f}),t[3]=f,t[4]=p);let m=c?`The English voice model could not be downloaded or prepared.`:`First-time setup downloads a ~40 MB English speech model to your device.`,h;t[5]===m?h=t[6]:(h=(0,$.jsx)(Qn,{children:m}),t[5]=m,t[6]=h);let g;t[7]!==p||t[8]!==h?(g=(0,$.jsxs)(_n,{children:[p,h]}),t[7]=p,t[8]=h,t[9]=g):g=t[9];let _;t[10]!==c||t[11]!==a||t[12]!==o||t[13]!==r||t[14]!==i||t[15]!==s?(_=c?(0,$.jsxs)(`div`,{className:`space-y-4 py-2`,children:[(0,$.jsx)(no,{variant:`error`,className:`mb-0`,children:c}),(0,$.jsxs)(Bn,{children:[(0,$.jsx)(Fe,{variant:`outline`,onClick:()=>r(!1),children:`Cancel`}),(0,$.jsx)(Fe,{onClick:i,children:`Try again`})]})]}):(0,$.jsxs)(`div`,{className:`space-y-4 py-2`,children:[(0,$.jsx)(no,{variant:`info`,className:`mb-0`,children:`One-time download. After this finishes, voice input works offline and you will not need to download the model again.`}),(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsx)(Ua,{title:Im(a,o,s)}),(0,$.jsx)(Fm,{value:o?100:s,className:`w-full`}),(0,$.jsx)(`p`,{className:K(J.bodyMuted,`text-center`),children:o?`Loading the model into memory. This usually takes a few seconds.`:s<100?`About 40 MB — kept on this device for future use.`:`Saving the model locally…`})]})]}),t[10]=c,t[11]=a,t[12]=o,t[13]=r,t[14]=i,t[15]=s,t[16]=_):_=t[16];let v;t[17]!==g||t[18]!==_?(v=(0,$.jsxs)(tn,{children:[g,_]}),t[17]=g,t[18]=_,t[19]=v):v=t[19];let y;return t[20]!==d||t[21]!==n||t[22]!==v?(y=(0,$.jsx)(Cr,{open:n,onOpenChange:d,children:v}),t[20]=d,t[21]=n,t[22]=v,t[23]=y):y=t[23],y}var Rm=Oi(e=>(0,$.jsxs)(`slot`,{children:[(0,$.jsx)(`style`,{children:`
|
|
28
|
+
.recording-waveform {
|
|
29
|
+
display: flex;
|
|
30
|
+
align-items: center;
|
|
31
|
+
gap: 2px;
|
|
32
|
+
height: 16px;
|
|
33
|
+
}
|
|
34
|
+
.recording-waveform-bar {
|
|
35
|
+
display: block;
|
|
36
|
+
width: 3px;
|
|
37
|
+
height: 4px;
|
|
38
|
+
border-radius: 2px;
|
|
39
|
+
background: currentColor;
|
|
40
|
+
animation: waveform-bounce 0.7s ease-in-out infinite alternate;
|
|
41
|
+
}
|
|
42
|
+
@keyframes waveform-bounce {
|
|
43
|
+
from { height: 3px; }
|
|
44
|
+
to { height: 14px; }
|
|
45
|
+
}
|
|
46
|
+
`}),e.v0,e.v1]}),{name:`SpeechInput_1`,portals:[`v0`,`v1`]}),zm=function({onTranscript:e,onVoiceSessionStart:t,threadId:n,provider:r,model:i,children:a}){let{state:o,isSupported:s,usesLocalModel:c,transcript:l,error:u,downloadProgress:d,startListening:f,stopListening:p,requestModelDownload:m,ensureReady:h,resetTranscript:g}=Am(),{isEnabled:_}=Pm(),{toast:v}=Ki(),[y,b]=(0,Z.useState)(!1),[x,S]=(0,Z.useState)(!1),C=(0,Z.useRef)(``),w=(0,Z.useRef)(null),T=(0,Z.useRef)(`idle`),E=o===`recording`,D=o===`transcribing`,O=E||D,k=o===`needs-model`,A=o===`downloading-model`,j=o===`initializing`,M=A||j,N=o===`checking-support`;(0,Z.useEffect)(()=>{u&&u!==w.current&&!y&&v({title:`Voice Input Error`,description:u,variant:`destructive`}),w.current=u},[u,y,v]),(0,Z.useEffect)(()=>{if(l&&l!==C.current){let t=l.substring(C.current.length);C.current=l,e(t)}},[l,e]),(0,Z.useEffect)(()=>{l||(C.current=``)},[l]),(0,Z.useEffect)(()=>{let t=T.current;if(T.current=o,(t===`recording`||t===`transcribing`)&&o===`ready`&&_&&C.current){let t=C.current;S(!0),_e(t,{threadId:n,provider:r,model:i}).then(t=>{e(t,{replace:!0})}).catch(()=>{e(t,{replace:!0})}).finally(()=>{S(!1)})}},[o,_,e,n,r,i]);function P(){b(!0),m()}let F=(0,Z.useCallback)(async()=>{if(O){p();return}if(k){P();return}if(o===`ready`){g(),t?.(),f();return}if(o===`idle`){let e=await h();e===`needs-model`?P():e===`ready`&&(g(),t?.(),f())}},[k,O,o,h,p,f,g,m,t]),I=(0,Z.useCallback)(()=>{m()},[m]);(0,Z.useEffect)(()=>{o===`ready`&&y&&b(!1)},[o,y]);let L=(0,Z.useCallback)(()=>N?`Checking voice input support...`:s===!1?`Voice input not supported in this browser`:u||(M?`Downloading speech model...`:x?`Processing transcription`:D?`Transcribing...`:E?`Stop listening`:k?`Click to download speech model`:`Start listening`),[u,x,N,M,E,D,s,k]),R=(0,Z.useCallback)(()=>M||D||x?(0,$.jsx)(sn,{className:`h-3 w-3 animate-spin`}):E?(0,$.jsxs)(`span`,{className:`recording-waveform`,"aria-hidden":!0,children:[(0,$.jsx)(`span`,{className:`recording-waveform-bar`,style:{animationDelay:`0ms`}}),(0,$.jsx)(`span`,{className:`recording-waveform-bar`,style:{animationDelay:`150ms`}}),(0,$.jsx)(`span`,{className:`recording-waveform-bar`,style:{animationDelay:`75ms`}}),(0,$.jsx)(`span`,{className:`recording-waveform-bar`,style:{animationDelay:`225ms`}})]}):(0,$.jsx)(pr,{className:`h-3 w-3`}),[x,M,E,D]),z=L(),B=O||x?z:`Voice input`;return(0,$.jsx)(Rm,{v0:(0,$.jsxs)(sa,{children:[(0,$.jsx)(Ya,{asChild:!0,children:a({onClick:F,disabled:N||M||D||x||s===!1,icon:R(),label:z,isRecording:E,isTranscribing:D||x,isDownloading:M,needsModel:k,isSupported:s!==!1})}),(0,$.jsx)(Qa,{side:`top`,className:`bg-popover text-popover-foreground max-w-64`,children:B})]}),v1:c?(0,$.jsx)(Lm,{open:y,onOpenChange:b,onRetry:I,isDownloading:A,isInitializing:j,progress:d,error:y?u:null}):null})};function Bm(e){let t=(0,Q.c)(8),{queuedMessages:n,onRemoveQueuedMessage:r}=e;if(n.length===0)return null;let i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,$.jsx)(`div`,{className:K(J.compact,J.label,`text-muted-foreground`),children:`Queued messages`}),t[0]=i):i=t[0];let a;if(t[1]!==r||t[2]!==n){let e;t[4]===r?e=t[5]:(e=e=>(0,$.jsxs)(`div`,{className:K(J.body,`flex items-start justify-between gap-3 rounded-md border border-border/60 bg-background px-3 py-2`),children:[(0,$.jsx)(`p`,{className:`flex-1 whitespace-pre-wrap text-foreground`,children:e.message}),(0,$.jsx)(`button`,{type:`button`,className:`rounded-full p-1 text-muted-foreground transition-colors hover:bg-foreground hover:text-background`,onClick:()=>r(e.id),"aria-label":`Remove queued message`,children:(0,$.jsx)(Gt,{className:`h-3.5 w-3.5`})})]},e.id),t[4]=r,t[5]=e),a=n.map(e),t[1]=r,t[2]=n,t[3]=a}else a=t[3];let o;return t[6]===a?o=t[7]:(o=(0,$.jsxs)(no,{className:`mb-3 border border-border/60 bg-muted/30 px-4 py-3`,children:[i,(0,$.jsx)(`div`,{className:`mt-2 flex flex-col gap-2`,children:a})]}),t[6]=a,t[7]=o),o}var Vm=Pn(`app.chat-input.ui`);function Hm(e){let t=(0,Q.c)(27),{onSpeechClick:n,speechDisabled:r,icon:i,label:a,isRecording:o,isTranscribing:s,isDownloading:c,isSupported:l,hasMessageText:u,setIsVoiceActive:d,isStreaming:f,disabled:p,canSubmitMessage:m,attachmentsLength:h,effectiveModel:g,onStop:_,onSend:v,isRouting:y}=e,b=y===void 0?!1:y,x=o||s||c,S,C;t[0]!==x||t[1]!==d?(S=()=>{d(x)},C=[x,d],t[0]=x,t[1]=d,t[2]=S,t[3]=C):(S=t[2],C=t[3]),(0,Z.useEffect)(S,C);let w=!f&&!x&&((p??!1)||b||!m&&r||!u&&h>0&&!g||u&&!g),T;t[4]!==m||t[5]!==f||t[6]!==x||t[7]!==v||t[8]!==n||t[9]!==_?(T=function(){if(f){_?.();return}if(x){n();return}if(m){v();return}n()},t[4]=m,t[5]=f,t[6]=x,t[7]=v,t[8]=n,t[9]=_,t[10]=T):T=t[10];let E=T,D=f?`Stop generation`:x?a:m?`Send message`:a,O=`relative h-7 w-7 rounded-full ${o?`bg-primary text-primary-foreground hover:bg-primary/90`:``} ${f?`before:absolute before:inset-[-1px] before:rounded-full before:border before:border-primary/60 before:animate-ping-subtle before:content-['']`:``}`,k;t[11]!==m||t[12]!==i||t[13]!==f||t[14]!==x?(k=f?(0,$.jsx)(`span`,{className:`block h-3 w-3 shrink-0 rounded-[2px] bg-current`,"aria-hidden":`true`}):x||!m?i:(0,$.jsx)(gn,{className:`h-3 w-3`}),t[11]=m,t[12]=i,t[13]=f,t[14]=x,t[15]=k):k=t[15];let A;t[16]===D?A=t[17]:(A=(0,$.jsx)(`span`,{className:`sr-only`,children:D}),t[16]=D,t[17]=A);let j;t[18]===l?j=t[19]:(j=!l&&(0,$.jsx)(`span`,{className:`sr-only`,children:`Voice input not supported`}),t[18]=l,t[19]=j);let M;return t[20]!==E||t[21]!==w||t[22]!==O||t[23]!==k||t[24]!==A||t[25]!==j?(M=(0,$.jsxs)(Fe,{size:`icon`,className:O,onClick:E,disabled:w,children:[k,A,j]}),t[20]=E,t[21]=w,t[22]=O,t[23]=k,t[24]=A,t[25]=j,t[26]=M):M=t[26],M}function Um(e){let t=(0,Q.c)(248),{planMode:n,setPlanMode:r,onSend:i,onStop:a,isStreaming:o,disabled:s,initialValue:c,queuedMessages:l,onRemoveQueuedMessage:u,isOverlay:d,placeholder:f,userTasks:p,onMatchedUserTaskSend:m,onUserTaskCreated:h,autoFocus:g,centered:_,embedded:v}=e,y=o===void 0?!1:o,b=d===void 0?!1:d,x;t[0]===p?x=t[1]:(x=p===void 0?[]:p,t[0]=p,t[1]=x);let S=x,C=g===void 0?!1:g,w=_===void 0?!1:_,T=v===void 0?!1:v,E;t[2]===c?E=t[3]:(E={initialValue:c},t[2]=c,t[3]=E);let{message:D,setMessage:O,historyIndex:k,setHistoryIndex:A,draftMessage:j,setDraftMessage:M,cursorPosition:N,setCursorPosition:P,availableModels:F,selectedModel:I,setSelectedModel:L,attachments:R,setAttachments:z,planMode:B,setPlanMode:ee,ralphMode:te,setRalphMode:ne,orchestrateMode:re,setOrchestrateMode:ie,autoMode:ae,setAutoMode:oe,imageMode:se,setImageMode:ce,availableImageModels:le,selectedImageModel:ue,setSelectedImageModel:de,allFiles:fe,setAllFiles:pe,showSuggestions:V,setShowSuggestions:me,suggestionQuery:he,setSuggestionQuery:ge,selectedIndex:_e,setSelectedIndex:ve,slashCommands:ye,skills:be,bundledSkills:xe,bundledSkillMode:Se,setBundledSkillMode:Ce,showCommandSuggestions:we,setShowCommandSuggestions:Te,commandQuery:H,setCommandQuery:Ee,fileInputRef:De,messageRef:Oe,textareaRef:ke,suggestionsRef:Ae,commandSuggestionsRef:je,selectedThreadId:Me,dispatch:Ne}=Bf(E),Pe=ua(),{paneId:Fe,conversationId:Ie,setFocused:Le,fillPane:Re}=If(),ze;t[4]!==Fe||t[5]!==Me?(ze=e=>_o(e.threadStreamingStates,Me,Fe).contextUsage,t[4]=Fe,t[5]=Me,t[6]=ze):ze=t[6];let Be=X(ze),Ve;t[7]===Fe?Ve=t[8]:(Ve=e=>Wa(e,Fe),t[7]=Fe,t[8]=Ve);let He=X(Ve),Ue=X(Zm),We;t[9]===Ue?We=t[10]:(We=e=>{if(Ue)return e.projects.find(e=>e.projectId===Ue)?.modelAliases},t[9]=Ue,t[10]=We);let Ge=X(We),Ke;t[11]===He?Ke=t[12]:(Ke=He.some(Xm),t[11]=He,t[12]=Ke);let qe=Ke,Je;t[13]===He?Je=t[14]:(Je=He.some(Ym),t[13]=He,t[14]=Je);let Ye=!Je,Xe=se?ue:I,Ze=se?le:F,Qe=ae&&!se&&Ye,$e;t[15]===D?$e=t[16]:($e=D.trim(),t[15]=D,t[16]=$e);let et=$e.length>0,tt=et||R.length>0,[nt,rt]=Z.useState(!1),[it,at]=(0,Z.useState)(null),ot=it&&it.threadId===Me?it.resolution:null,st;t[17]!==F||t[18]!==I?.id||t[19]!==I?.provider||t[20]!==L||t[21]!==Me?(st=e=>{at({threadId:Me,resolution:e});let t=F.find(t=>t.id===e.model.id&&t.provider===e.model.provider);t&&(t.id!==I?.id||t.provider!==I?.provider)&&L(t)},t[17]=F,t[18]=I?.id,t[19]=I?.provider,t[20]=L,t[21]=Me,t[22]=st):st=t[22];let ct=st,lt=Z.useRef(null),U=R.length>0,ut;t[23]!==D||t[24]!==U||t[25]!==ke?(ut={message:D,forceMultiline:U,textareaRef:ke,rowRef:lt},t[23]=D,t[24]=U,t[25]=ke,t[26]=ut):ut=t[26];let dt=np(ut),ft=n??B,pt=r??ee,mt=ot?.decision??null,ht;t[27]!==ae||t[28]!==ft||t[29]!==pt||t[30]!==se||t[31]!==Pe||t[32]!==re||t[33]!==te||t[34]!==Ue||t[35]!==oe||t[36]!==ce||t[37]!==ie||t[38]!==ne||t[39]!==mt?(ht={planMode:ft,imageMode:se,ralphMode:te,orchestrateMode:re,autoMode:ae,setPlanMode:pt,setImageMode:ce,setRalphMode:ne,setOrchestrateMode:ie,setAutoMode:oe,lastAutoRouteDecision:mt,projectId:Ue,onOpenProjectSettings(e){Pe(`/settings/project/${e}?section=model-aliases`)}},t[27]=ae,t[28]=ft,t[29]=pt,t[30]=se,t[31]=Pe,t[32]=re,t[33]=te,t[34]=Ue,t[35]=oe,t[36]=ce,t[37]=ie,t[38]=ne,t[39]=mt,t[40]=ht):ht=t[40];let{ensureCanOrchestrate:gt,requestOrchestrateMode:_t,cheapAliasDialog:vt}=qp(ht),yt=Me??void 0,bt;t[41]!==fe||t[42]!==R||t[43]!==ae||t[44]!==Se||t[45]!==xe||t[46]!==H||t[47]!==N||t[48]!==Ne||t[49]!==j||t[50]!==ft||t[51]!==pt||t[52]!==gt||t[53]!==ct||t[54]!==qe||t[55]!==k||t[56]!==se||t[57]!==Ye||t[58]!==y||t[59]!==D||t[60]!==Oe||t[61]!==Ge||t[62]!==m||t[63]!==i||t[64]!==re||t[65]!==te||t[66]!==_t||t[67]!==ue||t[68]!==_e||t[69]!==I||t[70]!==pe||t[71]!==z||t[72]!==oe||t[73]!==Ce||t[74]!==Ee||t[75]!==P||t[76]!==M||t[77]!==A||t[78]!==ce||t[79]!==O||t[80]!==ie||t[81]!==ne||t[82]!==ve||t[83]!==Te||t[84]!==me||t[85]!==ge||t[86]!==we||t[87]!==V||t[88]!==be||t[89]!==ye||t[90]!==he||t[91]!==yt||t[92]!==ke||t[93]!==S?(bt={message:D,setMessage:O,userTasks:S,onMatchedUserTaskSend:m,attachments:R,selectedModel:I,onSend:i,isStreaming:y,selectedThreadId:yt,isListening:!1,stopListening:Jm,resetTranscript:qm,dispatch:Ne,historyIndex:k,setHistoryIndex:A,draftMessage:j,setDraftMessage:M,cursorPosition:N,setCursorPosition:P,showSuggestions:V,setShowSuggestions:me,suggestionQuery:he,setSuggestionQuery:ge,allFiles:fe,setAllFiles:pe,selectedIndex:_e,setSelectedIndex:ve,showCommandSuggestions:we,setShowCommandSuggestions:Te,commandQuery:H,setCommandQuery:Ee,slashCommands:ye,skills:be,bundledSkills:xe,bundledSkillMode:Se,setBundledSkillMode:Ce,messageRef:Oe,textareaRef:ke,setAttachments:z,planMode:ft,setPlanMode:pt,ralphMode:te,setRalphMode:ne,orchestrateMode:re,setOrchestrateMode:ie,autoMode:ae,setAutoMode:oe,modelAliases:Ge,onAutoRouteResolved:ct,ensureCanOrchestrate:gt,requestOrchestrateMode:_t,imageMode:se,setImageMode:ce,selectedImageModel:ue,hasConversationMessages:qe,isFirstUserPrompt:Ye},t[41]=fe,t[42]=R,t[43]=ae,t[44]=Se,t[45]=xe,t[46]=H,t[47]=N,t[48]=Ne,t[49]=j,t[50]=ft,t[51]=pt,t[52]=gt,t[53]=ct,t[54]=qe,t[55]=k,t[56]=se,t[57]=Ye,t[58]=y,t[59]=D,t[60]=Oe,t[61]=Ge,t[62]=m,t[63]=i,t[64]=re,t[65]=te,t[66]=_t,t[67]=ue,t[68]=_e,t[69]=I,t[70]=pe,t[71]=z,t[72]=oe,t[73]=Ce,t[74]=Ee,t[75]=P,t[76]=M,t[77]=A,t[78]=ce,t[79]=O,t[80]=ie,t[81]=ne,t[82]=ve,t[83]=Te,t[84]=me,t[85]=ge,t[86]=we,t[87]=V,t[88]=be,t[89]=ye,t[90]=he,t[91]=yt,t[92]=ke,t[93]=S,t[94]=bt):bt=t[94];let{handleSend:xt,handleKeyDown:St,handleTextareaInput:Ct,insertFileReference:wt,insertCommand:Tt,insertSkill:Et,insertSkillAtCursor:Dt,insertSlashCommandAtCursor:Ot,allSuggestions:W,fileSuggestions:G,isRouting:kt}=Qf(bt),At=Z.useRef(``),jt;t[95]===O?jt=t[96]:(jt=()=>{O(e=>(At.current=e,e))},t[95]=O,t[96]=jt);let Mt=jt,Nt;t[97]===O?Nt=t[98]:(Nt=(e,t)=>{if(t?.replace){O(At.current+e);return}O(t=>(t.endsWith(` `),t+e))},t[97]=O,t[98]=Nt);let Pt=Nt,Ft;t[99]===z?Ft=t[100]:(Ft=e=>{let t=e.clipboardData?.items;if(!t)return;let n=Array.from(t).filter(Km);if(n.length!==0){e.preventDefault();for(let e of n){let t=e.getAsFile();if(!t)continue;let n=new FileReader;n.onload=()=>{let e=n.result.split(`,`)[1];z(n=>[...n,{fileName:t.name||`pasted-image.${t.type.split(`/`)[1]||`png`}`,content:e,mimeType:t.type}])},n.readAsDataURL(t)}}},t[99]=z,t[100]=Ft);let It=Ft,Lt;t[101]!==w||t[102]!==T||t[103]!==Re||t[104]!==b?(Lt=Af(Re,b,w,T),t[101]=w,t[102]=T,t[103]=Re,t[104]=b,t[105]=Lt):Lt=t[105];let Rt;t[106]!==T||t[107]!==b?(Rt=jf(T,b),t[106]=T,t[107]=b,t[108]=Rt):Rt=t[108];let zt;t[109]!==u||t[110]!==l?(zt=(0,$.jsx)(Bm,{queuedMessages:l,onRemoveQueuedMessage:u}),t[109]=u,t[110]=l,t[111]=zt):zt=t[111];let Bt=dt?`py-2`:`gap-y-1 pb-2`,Vt;t[112]===Bt?Vt=t[113]:(Vt=K(`flex min-w-0 flex-wrap items-center justify-between gap-x-1 px-3`,Bt),t[112]=Bt,t[113]=Vt);let Ht=f??(te?`Describe stories for Ralph to implement autonomously...`:ft?`Describe what you want Tarsk to plan...`:se?`Describe the image you want to generate...`:nt?`Dictate your message...`:`Ask Tarsk anything, @ for files, / for commands & skills`),Ut=dt?`order-2 flex-1 overflow-hidden py-1.5`:`order-1 min-h-[4.5rem] w-full pt-4 pb-2`,Wt;t[114]===Ut?Wt=t[115]:(Wt=K(J.body,`min-w-0 resize-none bg-transparent px-3 text-foreground placeholder:text-muted-foreground focus:outline-none`,Ut),t[114]=Ut,t[115]=Wt);let Gt;t[116]!==C||t[117]!==s||t[118]!==St||t[119]!==It||t[120]!==Ct||t[121]!==D||t[122]!==Le||t[123]!==Ht||t[124]!==Wt||t[125]!==ke?(Gt=(0,$.jsx)(`textarea`,{ref:ke,autoFocus:C,value:D,onChange:Ct,onKeyDown:St,onPaste:It,onFocus:Le,placeholder:Ht,rows:1,className:Wt,disabled:s}),t[116]=C,t[117]=s,t[118]=St,t[119]=It,t[120]=Ct,t[121]=D,t[122]=Le,t[123]=Ht,t[124]=Wt,t[125]=ke,t[126]=Gt):Gt=t[126];let Kt;t[127]!==R||t[128]!==I?.id||t[129]!==I?.name||t[130]!==I?.supportsImages||t[131]!==z?(Kt=R.length>0&&(0,$.jsxs)(`div`,{className:`order-2 w-full px-1`,children:[(0,$.jsx)(sp,{attachments:R,onRemove:e=>z(t=>t.filter((t,n)=>n!==e))}),R.some(Gm)&&I?.supportsImages===!1&&(0,$.jsxs)(`div`,{className:K(J.compact,`mb-2 flex items-center gap-1.5 text-amber-500`),children:[(0,$.jsx)(dn,{className:`h-3 w-3 shrink-0`}),(0,$.jsxs)(`span`,{children:[`Images are not supported by `,I?.name||I?.id]})]})]}),t[127]=R,t[128]=I?.id,t[129]=I?.name,t[130]=I?.supportsImages,t[131]=z,t[132]=Kt):Kt=t[132];let qt=dt?`order-1`:`order-3`,Jt;t[133]===qt?Jt=t[134]:(Jt=K(`flex items-center`,qt),t[133]=qt,t[134]=Jt);let Yt=s||kt,Xt=ot?.decision??null,Zt;t[135]===De?Zt=t[136]:(Zt=()=>De.current?.click(),t[135]=De,t[136]=Zt);let Qt;t[137]!==Ne||t[138]!==D||t[139]!==h||t[140]!==Fe||t[141]!==Ue||t[142]!==z||t[143]!==O||t[144]!==Me||t[145]!==ke?(Qt=()=>{if(!Ue||!Me)return;let e=D.trim();e&&Nr(Ue,e).then(e=>{h?.(e),O(``),z([]),Ne({type:Y.ClearChatInputDraft,threadId:Fe===`primary`?Me:`${Me}:${Fe}`}),ke.current&&(ke.current.style.height=`auto`)}).catch(Wm)},t[137]=Ne,t[138]=D,t[139]=h,t[140]=Fe,t[141]=Ue,t[142]=z,t[143]=O,t[144]=Me,t[145]=ke,t[146]=Qt):Qt=t[146];let $t;t[147]!==ae||t[148]!==ft||t[149]!==pt||t[150]!==et||t[151]!==se||t[152]!==Dt||t[153]!==Ot||t[154]!==re||t[155]!==te||t[156]!==Ue||t[157]!==oe||t[158]!==ce||t[159]!==ie||t[160]!==ne||t[161]!==be||t[162]!==ye||t[163]!==Yt||t[164]!==Xt||t[165]!==Zt||t[166]!==Qt?($t=(0,$.jsx)(nm,{disabled:Yt,canAddTask:et,planMode:ft,imageMode:se,ralphMode:te,orchestrateMode:re,autoMode:ae,setPlanMode:pt,setImageMode:ce,setRalphMode:ne,setOrchestrateMode:ie,setAutoMode:oe,lastAutoRouteDecision:Xt,projectId:Ue,skills:be,onSelectSkill:Dt,slashCommands:ye,onSelectSlashCommand:Ot,onFileAttach:Zt,onAddTask:Qt}),t[147]=ae,t[148]=ft,t[149]=pt,t[150]=et,t[151]=se,t[152]=Dt,t[153]=Ot,t[154]=re,t[155]=te,t[156]=Ue,t[157]=oe,t[158]=ce,t[159]=ie,t[160]=ne,t[161]=be,t[162]=ye,t[163]=Yt,t[164]=Xt,t[165]=Zt,t[166]=Qt,t[167]=$t):$t=t[167];let en;t[168]!==Jt||t[169]!==$t?(en=(0,$.jsx)(`div`,{className:Jt,children:$t}),t[168]=Jt,t[169]=$t,t[170]=en):en=t[170];let tn=dt?`order-3`:`order-4`,nn;t[171]===tn?nn=t[172]:(nn=K(`flex items-center gap-1`,tn),t[171]=tn,t[172]=nn);let rn;t[173]!==Ze||t[174]!==Xe||t[175]!==Qe||t[176]!==se||t[177]!==de||t[178]!==L?(rn=!Qe&&(0,$.jsx)(Fp,{availableModels:Ze,selectedModel:Xe,onModelSelect:se?de:L}),t[173]=Ze,t[174]=Xe,t[175]=Qe,t[176]=se,t[177]=de,t[178]=L,t[179]=rn):rn=t[179];let an=Me??void 0,on=y?Be:void 0,sn;t[180]!==Ie||t[181]!==y||t[182]!==He||t[183]!==an||t[184]!==on?(sn=(0,$.jsx)(Cp,{threadId:an,conversationId:Ie,messages:He,isStreaming:y,liveContextUsage:on}),t[180]=Ie,t[181]=y,t[182]=He,t[183]=an,t[184]=on,t[185]=sn):sn=t[185];let cn=Me??void 0,ln=I?.provider,un=I?.id,fn;t[186]!==R.length||t[187]!==tt||t[188]!==s||t[189]!==Xe||t[190]!==xt||t[191]!==et||t[192]!==kt||t[193]!==y||t[194]!==a?(fn=e=>{let{onClick:t,disabled:n,icon:r,label:i,isRecording:o,isTranscribing:c,isDownloading:l,isSupported:u}=e;return(0,$.jsx)(Hm,{onSpeechClick:t,speechDisabled:n,icon:r,label:i,isRecording:o,isTranscribing:c,isDownloading:l,isSupported:u,hasMessageText:et,setIsVoiceActive:rt,isStreaming:y,disabled:s,canSubmitMessage:tt,attachmentsLength:R.length,effectiveModel:Xe,onStop:a,onSend:xt,isRouting:kt})},t[186]=R.length,t[187]=tt,t[188]=s,t[189]=Xe,t[190]=xt,t[191]=et,t[192]=kt,t[193]=y,t[194]=a,t[195]=fn):fn=t[195];let pn;t[196]!==Pt||t[197]!==Mt||t[198]!==cn||t[199]!==ln||t[200]!==un||t[201]!==fn?(pn=(0,$.jsx)(zm,{onTranscript:Pt,onVoiceSessionStart:Mt,threadId:cn,provider:ln,model:un,children:fn}),t[196]=Pt,t[197]=Mt,t[198]=cn,t[199]=ln,t[200]=un,t[201]=fn,t[202]=pn):pn=t[202];let mn;t[203]!==nn||t[204]!==rn||t[205]!==sn||t[206]!==pn?(mn=(0,$.jsxs)(`div`,{className:nn,children:[rn,sn,pn]}),t[203]=nn,t[204]=rn,t[205]=sn,t[206]=pn,t[207]=mn):mn=t[207];let hn;t[208]!==Vt||t[209]!==Gt||t[210]!==Kt||t[211]!==en||t[212]!==mn?(hn=(0,$.jsxs)(`div`,{ref:lt,className:Vt,children:[Gt,Kt,en,mn]}),t[208]=Vt,t[209]=Gt,t[210]=Kt,t[211]=en,t[212]=mn,t[213]=hn):hn=t[213];let gn=Se?`//`:`/`,_n;t[214]!==W||t[215]!==H||t[216]!==je||t[217]!==Tt||t[218]!==Et||t[219]!==_e||t[220]!==ve||t[221]!==we||t[222]!==gn?(_n=(0,$.jsx)(rp,{visible:we,suggestions:W,skillReferencePrefix:gn,query:H,selectedIndex:_e,onSelectCommand:Tt,onSelectSkill:Et,onMouseEnterSuggestion:ve,containerRef:je}),t[214]=W,t[215]=H,t[216]=je,t[217]=Tt,t[218]=Et,t[219]=_e,t[220]=ve,t[221]=we,t[222]=gn,t[223]=_n):_n=t[223];let vn;t[224]!==G||t[225]!==wt||t[226]!==_e||t[227]!==ve||t[228]!==V||t[229]!==he||t[230]!==Ae?(vn=(0,$.jsx)(Dp,{showSuggestions:V,fileSuggestions:G,suggestionQuery:he,selectedIndex:_e,onSelectFile:wt,onMouseEnterSuggestion:ve,containerRef:Ae}),t[224]=G,t[225]=wt,t[226]=_e,t[227]=ve,t[228]=V,t[229]=he,t[230]=Ae,t[231]=vn):vn=t[231];let q;t[232]!==Rt||t[233]!==zt||t[234]!==hn||t[235]!==_n||t[236]!==vn?(q=(0,$.jsx)(`div`,{className:`relative flex min-w-0 items-center gap-1`,children:(0,$.jsxs)(`div`,{"data-composer-surface":!0,className:Rt,children:[zt,hn,_n,vn]})}),t[232]=Rt,t[233]=zt,t[234]=hn,t[235]=_n,t[236]=vn,t[237]=q):q=t[237];let yn;t[238]===z?yn=t[239]:(yn=e=>wp(e,e=>z(t=>[...t,...e])),t[238]=z,t[239]=yn);let bn;t[240]!==De||t[241]!==yn?(bn=(0,$.jsx)(`input`,{ref:De,type:`file`,multiple:!0,className:`hidden`,onChange:yn}),t[240]=De,t[241]=yn,t[242]=bn):bn=t[242];let xn;return t[243]!==vt||t[244]!==Lt||t[245]!==q||t[246]!==bn?(xn=(0,$.jsxs)(`div`,{className:Lt,children:[q,bn,vt]}),t[243]=vt,t[244]=Lt,t[245]=q,t[246]=bn,t[247]=xn):xn=t[247],xn}function Wm(e){Vm.error(`Failed to create user task:`,e)}function Gm(e){return e.mimeType.startsWith(`image/`)}function Km(e){return e.type.startsWith(`image/`)}function qm(){}function Jm(){}function Ym(e){return e.sender===`user`}function Xm(e){return e.sender===`agent`}function Zm(e){return e.selectedProjectId}var Qm=(0,Z.createContext)(null);function $m(e){let t=(0,Q.c)(8),{children:n,placement:r,embedded:i,composerPhase:a,composerReveal:o}=e,s=r===void 0?`overlay`:r,c=i===void 0?!1:i,l=a===void 0?`footer`:a,u=o===void 0?!1:o,d=(0,Z.useRef)(null),f=(0,Z.useRef)(null),p;t[0]!==l||t[1]!==u||t[2]!==c||t[3]!==s?(p={overlayRef:d,placement:s,embedded:c,composerPhase:l,composerReveal:u,centeredComposerTopRef:f},t[0]=l,t[1]=u,t[2]=c,t[3]=s,t[4]=p):p=t[4];let m=p,h;return t[5]!==n||t[6]!==m?(h=(0,$.jsx)(Qm.Provider,{value:m,children:n}),t[5]=n,t[6]=m,t[7]=h):h=t[7],h}function eh(){return(0,Z.useContext)(Qm)}function th(){let e=(0,Z.useContext)(Qm);return!e||e.embedded?`footer`:e.composerPhase}function nh(){let e=(0,Z.useContext)(Qm);return!e||e.embedded?!1:e.composerReveal}function rh(e){return e!==`loading`&&e!==`centered`}function ih(e,t){let n=e.threadId===t.threadId;return t.loading?{phase:`loading`,reveal:!1}:e.loading&&n?{phase:t.centered?`centered`:`footer`,reveal:!0}:t.centered?{phase:`centered`,reveal:!1}:e.centered&&n?{phase:`moving-to-footer`,reveal:!1}:{phase:`footer`,reveal:!1}}function ah(e){let t=(0,Q.c)(9),{centered:n,loading:r,threadId:i}=e,a;t[0]!==n||t[1]!==r||t[2]!==i?(a={centered:n,loading:r,threadId:i},t[0]=n,t[1]=r,t[2]=i,t[3]=a):a=t[3];let o=a,s;t[4]===o?s=t[5]:(s=()=>ih(o,o),t[4]=o,t[5]=s);let[c,l]=(0,Z.useState)(s),[u,d]=(0,Z.useState)(o);(u.centered!==n||u.loading!==r||u.threadId!==i)&&(d(o),l(ih(u,o)));let f,p;return t[6]===c.phase?(f=t[7],p=t[8]):(f=()=>{if(c.phase!==`moving-to-footer`)return;let e=setTimeout(()=>{l(oh)},300);return()=>clearTimeout(e)},p=[c.phase],t[6]=c.phase,t[7]=f,t[8]=p),(0,Z.useEffect)(f,p),c}function oh(e){return e.phase===`moving-to-footer`?{phase:`footer`,reveal:!1}:e}var sh=Oi(e=>(0,$.jsx)(`div`,{className:e.v0,children:(0,$.jsxs)(`div`,{className:e.v1,children:[e.v2,(0,$.jsxs)(`div`,{className:`flex items-start gap-2 px-6 pt-4 pr-12`,children:[e.v3,(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`div`,{className:e.v4,children:e.v5}),e.v6]})]}),e.v7,e.v8,(0,$.jsx)(`div`,{className:`flex items-center justify-end px-3 pb-2`,children:(0,$.jsxs)(`button`,{type:`button`,onClick:e.v9,disabled:e.v10,className:`flex h-7 w-7 shrink-0 items-center justify-center rounded-full bg-primary text-primary-foreground transition-colors hover:bg-primary/90 disabled:opacity-50`,children:[e.v11,(0,$.jsx)(`span`,{className:`sr-only`,children:`Submit answer`})]})})]})}),{name:`AskUserChatInput_1`,portals:[`v2`,`v3`,`v5`,`v6`,`v7`,`v8`,`v11`]}),ch=function(e){let t=(0,Q.c)(59),{toolCallId:n,question:r,options:i,context:a,onAnswered:o,onStop:s}=e,{fillPane:c}=If(),l=eh()?.embedded??!1,[u,d]=(0,Z.useState)(``),[f,p]=(0,Z.useState)(!1),[m,h]=(0,Z.useState)(null),g=(0,Z.useRef)(null),_;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(_=()=>{d(``),p(!1),h(null),g.current?.focus()},t[0]=_):_=t[0];let v;t[1]===n?v=t[2]:(v=[n],t[1]=n,t[2]=v),(0,Z.useEffect)(_,v);let y;t[3]!==f||t[4]!==o||t[5]!==n?(y=async function(e){let t=e.trim();if(!(!t||f)){p(!0);try{await lr(n,t),o(n)}catch(e){let t=e;lh.error(`Failed to submit answer`,{err:t}),p(!1),h(null)}}},t[3]=f,t[4]=o,t[5]=n,t[6]=y):y=t[6];let b=y,x;t[7]!==f||t[8]!==b?(x=function(e){f||(h(e),b(e))},t[7]=f,t[8]=b,t[9]=x):x=t[9];let S=x,C;t[10]!==u||t[11]!==b?(C=function(e){e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),b(u))},t[10]=u,t[11]=b,t[12]=C):C=t[12];let w=C,T;t[13]===s?T=t[14]:(T=function(){s?.()},t[13]=s,t[14]=T);let E=T,D;t[15]!==u||t[16]!==f?(D=u.trim().length>0&&!f,t[15]=u,t[16]=f,t[17]=D):D=t[17];let O=D,k;t[18]!==l||t[19]!==c?(k=Af(c,!1,!1,l),t[18]=l,t[19]=c,t[20]=k):k=t[20];let A;t[21]===l?A=t[22]:(A=jf(l),t[21]=l,t[22]=A);let j;t[23]!==E||t[24]!==f||t[25]!==s?(j=s&&(0,$.jsx)(`div`,{className:`absolute top-2 right-2 z-10`,children:(0,$.jsxs)(sa,{children:[(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsxs)(Fe,{type:`button`,size:`icon`,variant:`action`,className:`h-7 w-7`,onClick:E,disabled:f,children:[(0,$.jsx)(Gt,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Stop generation`})]})}),(0,$.jsx)(Qa,{children:`Stop generation`})]})}),t[23]=E,t[24]=f,t[25]=s,t[26]=j):j=t[26];let M,N;t[27]===Symbol.for(`react.memo_cache_sentinel`)?(M=(0,$.jsx)(wn,{className:`h-5 w-5 shrink-0 text-brand`}),N=K(J.label,`text-foreground`),t[27]=M,t[28]=N):(M=t[27],N=t[28]);let P;t[29]===r?P=t[30]:(P=(0,$.jsx)(tc,{content:r}),t[29]=r,t[30]=P);let F;t[31]===a?F=t[32]:(F=a&&(0,$.jsx)(`p`,{className:K(J.bodyMuted,`mt-1`),children:a}),t[31]=a,t[32]=F);let I;t[33]!==S||t[34]!==f||t[35]!==i||t[36]!==m?(I=i&&i.length>0&&(0,$.jsx)(`div`,{className:`flex flex-wrap gap-2 px-6 pt-3`,children:i.map(e=>{let t=m===e;return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>S(e),disabled:f,className:K(`flex items-center gap-1.5 rounded-md border px-3 py-1.5 transition-colors disabled:opacity-50`,J.label,t?`border-foreground/20 bg-accent text-accent-foreground`:`border-foreground/20 bg-background text-foreground hover:bg-accent hover:text-accent-foreground`),children:[t&&(0,$.jsx)(Xt,{className:`h-3.5 w-3.5 text-foreground`}),e]},e)})}),t[33]=S,t[34]=f,t[35]=i,t[36]=m,t[37]=I):I=t[37];let L;t[38]===Symbol.for(`react.memo_cache_sentinel`)?(L=e=>d(e.target.value),t[38]=L):L=t[38];let R=i?.length?`Or type a custom answer...`:`Type your answer...`,z;t[39]===Symbol.for(`react.memo_cache_sentinel`)?(z=K(J.body,`min-h-[3rem] w-full resize-none bg-transparent px-6 pt-3 pb-2 text-foreground placeholder:text-muted-foreground focus:outline-none disabled:opacity-50`),t[39]=z):z=t[39];let B;t[40]!==u||t[41]!==w||t[42]!==f||t[43]!==R?(B=(0,$.jsx)(`textarea`,{ref:g,autoFocus:!0,value:u,onChange:L,onKeyDown:w,placeholder:R,disabled:f,rows:1,className:z}),t[40]=u,t[41]=w,t[42]=f,t[43]=R,t[44]=B):B=t[44];let ee;t[45]!==u||t[46]!==b?(ee=()=>void b(u),t[45]=u,t[46]=b,t[47]=ee):ee=t[47];let te=!O,ne;t[48]===Symbol.for(`react.memo_cache_sentinel`)?(ne=(0,$.jsx)(gn,{className:`h-3 w-3`}),t[48]=ne):ne=t[48];let re;return t[49]!==j||t[50]!==P||t[51]!==F||t[52]!==I||t[53]!==B||t[54]!==ee||t[55]!==te||t[56]!==k||t[57]!==A?(re=(0,$.jsx)(sh,{v0:k,v1:A,v2:j,v3:M,v4:N,v5:P,v6:F,v7:I,v8:B,v9:ee,v10:te,v11:ne}),t[49]=j,t[50]=P,t[51]=F,t[52]=I,t[53]=B,t[54]=ee,t[55]=te,t[56]=k,t[57]=A,t[58]=re):re=t[58],re},lh=Pn(`chat.ask-user-input`);function uh(){let e=(0,Q.c)(4),t=X(ph),n=X(fh),r=X(dh),i;return e[0]!==n||e[1]!==t||e[2]!==r?(i=t===`actions`&&n!=null&&r.some(e=>e.projectId===n),e[0]=n,e[1]=t,e[2]=r,e[3]=i):i=e[3],i}function dh(e){return e.projects}function fh(e){return e.projectPanelProjectId}function ph(e){return e.projectPanelView}var mh=Oi(e=>(0,$.jsxs)(`svg`,{"aria-hidden":`true`,viewBox:e.v0,className:`size-4 shrink-0`,children:[(0,$.jsx)(`circle`,{cx:e.v1,cy:e.v2,r:e.v3,fill:`none`,stroke:`currentColor`,strokeOpacity:`0.2`,strokeWidth:e.v4}),(0,$.jsx)(`circle`,{cx:e.v5,cy:e.v6,r:e.v7,fill:`none`,stroke:`currentColor`,strokeWidth:e.v8,strokeDasharray:e.v9,strokeDashoffset:e.v10,strokeLinecap:`round`,transform:e.v11,style:e.v12})]}),{name:`TodoProgressRing_1`,svg:!0}),hh=function(e){let t=(0,Q.c)(5),{completedCount:n,totalCount:r}=e,i=Math.min(n+1,r),[a,o]=(0,Z.useState)(0),s=yh*(1-(r>0?Math.min(a,r)/r:0)),c=gh/2,l,u;t[0]===i?(l=t[1],u=t[2]):(l=()=>{let e=requestAnimationFrame(()=>{o(i)});return()=>cancelAnimationFrame(e)},u=[i],t[0]=i,t[1]=l,t[2]=u),(0,Z.useEffect)(l,u);let d;return t[3]===s?d=t[4]:(d=(0,$.jsx)(mh,{v0:`0 0 ${gh} ${gh}`,v1:c,v2:c,v3:vh,v4:_h,v5:c,v6:c,v7:vh,v8:_h,v9:yh,v10:s,v11:`rotate(-90 ${c} ${c})`,v12:bh}),t[3]=s,t[4]=d),d},gh=40,_h=4,vh=10,yh=2*Math.PI*vh,bh={transitionDuration:`5000ms`,transitionProperty:`stroke-dashoffset`,transitionTimingFunction:`ease-out`};function xh(e,t){return`${Math.min(e+1,t)} of ${t}`}function Sh(e){let t=(0,Q.c)(12),{todos:n}=e,r,i,a,o;if(t[0]!==n){let e=n.filter(wh).length;r=`space-y-1`,t[5]===n.length?i=t[6]:(i=n.length===0&&(0,$.jsx)(`p`,{className:J.compact,children:`No todo items.`}),t[5]=n.length,t[6]=i),a=n.map(Ch),o=n.length>0&&(0,$.jsx)(`p`,{className:K(J.compact,`pt-1`),children:xh(e,n.length)}),t[0]=n,t[1]=r,t[2]=i,t[3]=a,t[4]=o}else r=t[1],i=t[2],a=t[3],o=t[4];let s;return t[7]!==r||t[8]!==i||t[9]!==a||t[10]!==o?(s=(0,$.jsxs)(`div`,{className:r,children:[i,a,o]}),t[7]=r,t[8]=i,t[9]=a,t[10]=o,t[11]=s):s=t[11],s}function Ch(e){return(0,$.jsxs)(`div`,{className:K(J.caption,`flex items-start gap-2`),children:[e.status===`done`?(0,$.jsx)(Nt,{className:`h-4 w-4 shrink-0 mt-0.5 text-brand`}):e.status===`working`?(0,$.jsx)(xr,{className:`h-4 w-4 shrink-0 mt-0.5 text-yellow-500`}):(0,$.jsx)(Jn,{className:`h-4 w-4 shrink-0 mt-0.5 text-muted-foreground`}),(0,$.jsx)(`span`,{className:e.status===`done`?`line-through text-muted-foreground`:`text-foreground`,children:e.description})]},e.id)}function wh(e){return e.status===`done`}function Th(e){let t=(0,Q.c)(46),{layout:n}=e,r=n===void 0?`bar`:n,{todos:i}=(0,Z.useContext)(qu),[a,o]=(0,Z.useState)(!1),s;t[0]===i?s=t[1]:(s=i.filter(Eh),t[0]=i,t[1]=s);let c=s.length,l=i.length-c,u;t[2]!==c||t[3]!==i.length?(u=xh(c,i.length),t[2]=c,t[3]=i.length,t[4]=u):u=t[4];let d=u;if(l<=0)return null;if(r===`menu`){let e;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(e=()=>o(!0),t[5]=e):e=t[5];let n;t[6]!==c||t[7]!==i.length?(n=(0,$.jsx)(hh,{completedCount:c,totalCount:i.length}),t[6]=c,t[7]=i.length,t[8]=n):n=t[8];let r;t[9]===d?r=t[10]:(r=(0,$.jsx)(`span`,{children:d}),t[9]=d,t[10]=r);let s;t[11]!==n||t[12]!==r?(s=(0,$.jsxs)(Fe,{variant:`ghost`,size:`sm`,className:`w-full justify-start gap-2`,onClick:e,children:[n,r]}),t[11]=n,t[12]=r,t[13]=s):s=t[13];let l;t[14]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,$.jsx)(_n,{children:(0,$.jsx)(un,{children:`Agent Todos`})}),t[14]=l):l=t[14];let u;t[15]===i?u=t[16]:(u=(0,$.jsxs)(tn,{className:`max-w-md`,children:[l,(0,$.jsx)(Sh,{todos:i})]}),t[15]=i,t[16]=u);let f;t[17]!==a||t[18]!==u?(f=(0,$.jsx)(Cr,{open:a,onOpenChange:o,children:u}),t[17]=a,t[18]=u,t[19]=f):f=t[19];let p;return t[20]!==f||t[21]!==s?(p=(0,$.jsxs)($.Fragment,{children:[s,f]}),t[20]=f,t[21]=s,t[22]=p):p=t[22],p}let f;t[23]===Symbol.for(`react.memo_cache_sentinel`)?(f=()=>o(!0),t[23]=f):f=t[23];let p;t[24]!==c||t[25]!==i.length?(p=(0,$.jsx)(hh,{completedCount:c,totalCount:i.length}),t[24]=c,t[25]=i.length,t[26]=p):p=t[26];let m;t[27]===d?m=t[28]:(m=(0,$.jsx)(`span`,{children:d}),t[27]=d,t[28]=m);let h;t[29]!==p||t[30]!==m?(h=(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsxs)(Fe,{variant:`outline`,size:`sm`,onClick:f,children:[p,m]})}),t[29]=p,t[30]=m,t[31]=h):h=t[31];let g;t[32]===d?g=t[33]:(g=(0,$.jsx)(Qa,{children:d}),t[32]=d,t[33]=g);let _;t[34]!==h||t[35]!==g?(_=(0,$.jsx)(Ti,{children:(0,$.jsxs)(sa,{children:[h,g]})}),t[34]=h,t[35]=g,t[36]=_):_=t[36];let v;t[37]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,$.jsx)(_n,{children:(0,$.jsx)(un,{children:`Agent Todos`})}),t[37]=v):v=t[37];let y;t[38]===i?y=t[39]:(y=(0,$.jsxs)(tn,{className:`max-w-md`,children:[v,(0,$.jsx)(Sh,{todos:i})]}),t[38]=i,t[39]=y);let b;t[40]!==a||t[41]!==y?(b=(0,$.jsx)(Cr,{open:a,onOpenChange:o,children:y}),t[40]=a,t[41]=y,t[42]=b):b=t[42];let x;return t[43]!==b||t[44]!==_?(x=(0,$.jsxs)($.Fragment,{children:[_,b]}),t[43]=b,t[44]=_,t[45]=x):x=t[45],x}function Eh(e){return e.status===`done`}function Dh(e){let t=(0,Q.c)(34),{tasks:n,disabled:r,onSelectTask:i,onTogglePinned:a,onRemoveTask:o,layout:s}=e,c=r===void 0?!1:r,l=s===void 0?`bar`:s,[u,d]=(0,Z.useState)(!1),f=n.length,p=`${f} ${f===1?`Prompt`:`Prompts`}`;if(f===0)return null;let m;t[0]===i?m=t[1]:(m=function(e){i(e),d(!1)},t[0]=i,t[1]=m);let h=m,g;t[2]!==o||t[3]!==f?(g=function(e){o(e),f===1&&d(!1)},t[2]=o,t[3]=f,t[4]=g):g=t[4];let _=g,v;t[5]===a?v=t[6]:(v=function(e){a(e)},t[5]=a,t[6]=v);let y=v,b=l===`menu`?`ghost`:`outline`,x=l===`bar`&&`bg-background`,S=l===`menu`&&`w-full justify-start`,C;t[7]!==x||t[8]!==S?(C=K(`gap-2`,x,S),t[7]=x,t[8]=S,t[9]=C):C=t[9];let w;t[10]===p?w=t[11]:(w=(0,$.jsx)(`span`,{children:p}),t[10]=p,t[11]=w);let T;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(T=(0,$.jsx)(hr,{className:`h-4 w-4 shrink-0`}),t[12]=T):T=t[12];let E;t[13]!==c||t[14]!==w||t[15]!==b||t[16]!==C?(E=(0,$.jsx)(au,{asChild:!0,children:(0,$.jsxs)(Fe,{variant:b,size:`sm`,className:C,disabled:c,children:[w,T]})}),t[13]=c,t[14]=w,t[15]=b,t[16]=C,t[17]=E):E=t[17];let D;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(D=(0,$.jsx)(`div`,{className:K(J.compact,J.label,`px-2 pb-1 pt-1 text-muted-foreground`),children:`Prompts`}),t[18]=D):D=t[18];let O;if(t[19]!==_||t[20]!==h||t[21]!==y||t[22]!==n){let e;t[24]!==_||t[25]!==h||t[26]!==y?(e=e=>(0,$.jsxs)(`div`,{className:`flex items-start gap-2 rounded-md border border-transparent px-2 py-2 hover:bg-accent`,children:[(0,$.jsxs)(`button`,{type:`button`,className:`flex min-w-0 flex-1 items-start gap-2 text-left`,onClick:()=>h(e),children:[(0,$.jsx)(ee,{className:`mt-0.5 h-4 w-4 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{className:K(J.body,`line-clamp-3 text-foreground`),children:e.content})]}),(0,$.jsxs)(sa,{children:[(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsxs)(Fe,{type:`button`,variant:`ghost`,size:`icon`,className:K(`h-7 w-7 shrink-0`,e.pinned&&`text-primary hover:text-primary`),onClick:()=>y(e.id),children:[(0,$.jsx)(_t,{className:K(`h-4 w-4`,e.pinned&&`fill-current`)}),(0,$.jsx)(`span`,{className:`sr-only`,children:e.pinned?`Unpin prompt`:`Pin prompt`})]})}),(0,$.jsx)(Qa,{children:e.pinned?`Unpin prompt`:`Pin prompt`})]}),(0,$.jsxs)(Fe,{type:`button`,variant:`ghost`,size:`icon`,className:`h-7 w-7 shrink-0`,onClick:()=>_(e.id),children:[(0,$.jsx)(Gt,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Remove prompt`})]})]},e.id),t[24]=_,t[25]=h,t[26]=y,t[27]=e):e=t[27],O=n.map(e),t[19]=_,t[20]=h,t[21]=y,t[22]=n,t[23]=O}else O=t[23];let k;t[28]===O?k=t[29]:(k=(0,$.jsx)(ou,{align:`start`,className:`w-96 p-2`,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[D,O]})}),t[28]=O,t[29]=k);let A;return t[30]!==u||t[31]!==E||t[32]!==k?(A=(0,$.jsx)(Ti,{children:(0,$.jsxs)(iu,{open:u,onOpenChange:d,children:[E,k]})}),t[30]=u,t[31]=E,t[32]=k,t[33]=A):A=t[33],A}function Oh(e){let t=(0,Q.c)(23),n=Ni(),r;t[0]===e?r=t[1]:(r=ma.userTasks(e),t[0]=e,t[1]=r);let i;t[2]===e?i=t[3]:(i=()=>b(e),t[2]=e,t[3]=i);let a=!!e,o;t[4]!==r||t[5]!==i||t[6]!==a?(o={queryKey:r,queryFn:i,enabled:a},t[4]=r,t[5]=i,t[6]=a,t[7]=o):o=t[7];let s=oi(o),c;t[8]!==e||t[9]!==n?(c=t=>{e&&n.setQueryData(ma.userTasks(e),e=>typeof t==`function`?t(e??[]):t)},t[8]=e,t[9]=n,t[10]=c):c=t[10];let l=c,u;t[11]===s.data?u=t[12]:(u=s.data??[],t[11]=s.data,t[12]=u);let d;t[13]!==e||t[14]!==n?(d=()=>n.invalidateQueries({queryKey:ma.userTasks(e)}),t[13]=e,t[14]=n,t[15]=d):d=t[15];let f;return t[16]!==s.error||t[17]!==s.isError||t[18]!==s.isLoading||t[19]!==l||t[20]!==u||t[21]!==d?(f={userTasks:u,isLoading:s.isLoading,isError:s.isError,error:s.error,setUserTasks:l,invalidate:d},t[16]=s.error,t[17]=s.isError,t[18]=s.isLoading,t[19]=l,t[20]=u,t[21]=d,t[22]=f):f=t[22],f}function kh(e,t,n){let r=e.flatMap(e=>e.threads).find(e=>e.threadId===t),i=new Set(Object.values(r?.chatTitles??{}).filter(e=>typeof e==`string`&&e.trim().length>0).map(e=>e.trim())),a=1,o=`New Chat`;for(;i.has(o);)a+=1,o=`New Chat ${a}`;return o}var Ah=Pn(`chat.input-toolbar`),jh=(0,Z.createContext)(void 0);function Mh(e){let t=(0,Q.c)(33),{children:n}=e,r=Gi(),{paneId:i}=If(),a=X(Lh),o=X(Ih),s=X(Fh),c=X(Ph),{toast:l}=Ki(),u=Ni(),{userTasks:d,setUserTasks:f,isError:p}=Oh(i===`primary`?s:null),m;t[0]===i?m=t[1]:(m=e=>{let t=i===`primary`&&e.pendingChatMessage?.threadId===e.selectedThreadId;return e.selectedThreadId?_o(e.threadStreamingStates,e.selectedThreadId,i).isStreaming||t:!1},t[0]=i,t[1]=m);let h=X(m),g,_;t[2]!==p||t[3]!==l?(g=()=>{p&&l({title:`Could not load prompts`,description:`Failed to load prompts for this project.`,variant:`destructive`})},_=[p,l],t[2]=p,t[3]=l,t[4]=g,t[5]=_):(g=t[4],_=t[5]),(0,Z.useEffect)(g,_);let v;t[6]!==r||t[7]!==i||t[8]!==o||t[9]!==s||t[10]!==a?(v=async()=>{if(!a)return;let e=kh(o,a,i),t={...o.flatMap(Nh).find(e=>e.threadId===a)?.chatTitles,[i]:e};if(s&&(Dt(a,{chatTitles:t}).catch(e=>{Ah.error(`Failed to update chat title for new chat`,{error:e,threadId:a})}),r({type:Y.UpdateChatTitle,projectId:s,threadId:a,paneId:i,title:e})),i!==`primary`){r({type:Y.SetPaneMessages,paneId:i,messages:[]});return}try{let e=await ur(a);r({type:Y.ClearMessages}),Ah.info(`New conversation started`,{conversationId:e,threadId:a}),setTimeout(()=>{(async()=>{try{let e=await B(a);r({type:Y.SetMessages,messages:e.messages})}catch(e){let t=e;Ah.error(`Failed to refresh chat history after starting new chat`,{error:t,threadId:a})}})()},0)}catch(e){let t=e;Ah.error(`Failed to start new chat`,{error:t,threadId:a})}},t[6]=r,t[7]=i,t[8]=o,t[9]=s,t[10]=a,t[11]=v):v=t[11];let y=v,b;t[12]!==u||t[13]!==s||t[14]!==l?(b=async e=>{if(s)try{await k(s,e),u.setQueryData(ma.userTasks(s),t=>(t??[]).filter(t=>t.id!==e))}catch(t){let n=t;Ah.error(`Failed to delete user task`,{error:n,projectId:s,taskId:e}),l({title:`Could not remove prompt`,description:`Failed to delete the selected prompt.`,variant:`destructive`})}},t[12]=u,t[13]=s,t[14]=l,t[15]=b):b=t[15];let x=b,S;t[16]===f?S=t[17]:(S=e=>{f(t=>t.map(t=>t.id===e?{...t,pinned:!t.pinned}:t))},t[16]=f,t[17]=S);let C=S,w;t[18]!==r||t[19]!==a?(w=e=>{a&&r({type:Y.SetChatInputDraft,threadId:a,draft:e.content})},t[18]=r,t[19]=a,t[20]=w):w=t[20];let T=w,E;t[21]!==h||t[22]!==y||t[23]!==x||t[24]!==T||t[25]!==c||t[26]!==f||t[27]!==C||t[28]!==d?(E={userTasks:d,setUserTasks:f,handleNewChat:y,handleSelectUserTask:T,handleRemoveUserTask:x,toggleUserTaskPinned:C,effectiveIsStreaming:h,isCreatingProject:c},t[21]=h,t[22]=y,t[23]=x,t[24]=T,t[25]=c,t[26]=f,t[27]=C,t[28]=d,t[29]=E):E=t[29];let D=E,O;return t[30]!==n||t[31]!==D?(O=(0,$.jsx)(jh.Provider,{value:D,children:n}),t[30]=n,t[31]=D,t[32]=O):O=t[32],O}function Nh(e){return e.threads}function Ph(e){return e.isCreatingProject}function Fh(e){return e.selectedProjectId}function Ih(e){return e.projects}function Lh(e){return e.selectedThreadId}function Rh(){let e=(0,Z.useContext)(jh);if(e===void 0)throw Error(`useChatInputToolbar must be used within a ChatInputToolbarProvider`);return e}var zh=(0,Z.createContext)(null);function Bh(e){let t=(0,Q.c)(8),{children:n}=e,[r,i]=(0,Z.useState)(null),[a,o]=(0,Z.useState)(!1),[s,c]=(0,Z.useState)(null),[l,u]=(0,Z.useState)(!1),d=(0,Z.useRef)(!1),f;t[0]!==l||t[1]!==s||t[2]!==a||t[3]!==r?(f={devServerUrl:r,setDevServerUrl:i,devServerRunning:a,setDevServerRunning:o,devServerProjectId:s,setDevServerProjectId:c,devServerLoading:l,setDevServerLoading:u,devServerStopRequestedRef:d},t[0]=l,t[1]=s,t[2]=a,t[3]=r,t[4]=f):f=t[4];let p=f,m;return t[5]!==n||t[6]!==p?(m=(0,$.jsx)(zh.Provider,{value:p,children:n}),t[5]=n,t[6]=p,t[7]=m):m=t[7],m}function Vh(){let e=(0,Z.useContext)(zh);if(!e)throw Error(`useDevServer must be used within a DevServerProvider`);return e}async function Hh(e){if(e.useBuiltInBrowser){e.onTerminalMessage?.(`✓ Server running at: ${e.url}`),e.setDevServerUrl(e.url),e.openBrowserPanel();return}e.onTerminalMessage?.(`✓ Server running at: ${e.url} (opened in your browser)`),await e.openExternalUrl(e.url)}function Uh(e){return typeof e==`object`&&!!e&&e.type===`url`&&typeof e.url==`string`}var Wh=Z.forwardRef((e,t)=>{let n=(0,Q.c)(9),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=K(`flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,$.jsx)(`textarea`,{className:a,ref:t,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});Wh.displayName=`Textarea`;var Gh=Pn(`app.commands-dialog.ui`),Kh=`Play.Square.RotateCcw.Terminal.Bug.TestTube.FlaskConical.Wrench.Hammer.Zap.Search.FileCode.Code2.History.Settings.Activity.Cpu.Server.Database.Package.Box.GitBranch.Layers.ExternalLink.Eye.Shield.Flag.Star.Monitor.Smartphone`.split(`.`);function qh({open:e,onOpenChange:t,projectId:n,commands:r,onRefresh:i,initialCommand:a}){let[s,c]=(0,Z.useState)(null),[l,u]=(0,Z.useState)(!1),[d,f]=(0,Z.useState)(!1),[p,m]=(0,Z.useState)([]),[h,g]=(0,Z.useState)(0),[_,v]=(0,Z.useState)(!1),y=(0,Z.useRef)(null),b=(0,Z.useRef)(null);(0,Z.useEffect)(()=>{!e||!a||(c({id:crypto.randomUUID(),icon:`Play`,...a}),f(!1),m([]))},[a,e]);let x=()=>{c({id:crypto.randomUUID(),name:``,icon:`Play`,commandLine:``}),f(!1),m([])},S=e=>{c({...e}),f(!1),m([])},C=async()=>{try{v(!0);let e=await o(n);m(e.scripts),g(0),f(e.scripts.length>0)}catch(e){Gh.error(`Failed to load package scripts:`,e),Ri({title:`Error`,description:`Failed to load package scripts`,variant:`destructive`})}finally{v(!1)}},w=e=>{c(t=>t?{...t,name:e.name,commandLine:e.commandLine,relativeFolder:e.relativePath||``}:null),f(!1),m([]),y.current?.focus()},T=e=>{d&&(e.key===`ArrowDown`?(e.preventDefault(),g(e=>e<p.length-1?e+1:e)):e.key===`ArrowUp`?(e.preventDefault(),g(e=>e>0?e-1:0)):e.key===`Enter`?(e.preventDefault(),h<p.length&&w(p[h])):e.key===`Escape`&&(e.preventDefault(),f(!1),m([])))};(0,Z.useEffect)(()=>{let e=e=>{b.current&&!b.current.contains(e.target)&&(f(!1),m([]))};return d&&document.addEventListener(`mousedown`,e),()=>{document.removeEventListener(`mousedown`,e)}},[d]);let E=async e=>{try{await Jr(n,e),Ri({title:`Success`,description:`Command deleted`}),i()}catch{Ri({title:`Error`,description:`Failed to delete command`,variant:`destructive`})}};return(0,$.jsx)(Cr,{open:e,onOpenChange:t,children:(0,$.jsxs)(tn,{className:`sm:max-w-[500px]`,children:[(0,$.jsxs)(_n,{children:[(0,$.jsx)(un,{children:`Project Commands`}),(0,$.jsx)(Qn,{children:`Manage custom commands for this project.`})]}),(0,$.jsx)(`div`,{className:`py-4 flex flex-col gap-4`,children:s?(0,$.jsxs)(`div`,{className:`p-4 border rounded-lg bg-muted/30 flex flex-col gap-4 animate-in slide-in-from-top-2`,children:[(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[(0,$.jsx)(dr,{htmlFor:`name`,children:`Command Name`}),(0,$.jsx)(Lt,{id:`name`,value:s.name,onChange:e=>c({...s,name:e.target.value}),placeholder:`e.g. Run Tests`,autoComplete:`off`})]}),(0,$.jsxs)(`div`,{className:`grid gap-2 relative`,children:[(0,$.jsx)(dr,{htmlFor:`commandLine`,children:`Command Line`}),(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(Wh,{ref:y,id:`commandLine`,value:s.commandLine,onChange:e=>c({...s,commandLine:e.target.value}),onKeyDown:T,placeholder:`e.g. npm test`,className:`font-mono text-base min-h-[100px] resize-none pr-10`}),(0,$.jsx)(Ti,{children:(0,$.jsxs)(sa,{children:[(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsx)(Fe,{type:`button`,variant:`ghost`,size:`icon`,className:`absolute right-2 top-2 h-6 w-6 text-muted-foreground transition-colors`,onClick:()=>void C(),disabled:_,children:(0,$.jsx)(Dr,{className:`h-4 w-4`})})}),(0,$.jsx)(Qa,{children:(0,$.jsx)(`p`,{children:`Discover package scripts`})})]})})]}),d&&(0,$.jsx)(`div`,{ref:b,className:`absolute bottom-full left-0 right-0 mb-2 max-h-60 overflow-y-auto rounded-lg border border-border bg-popover shadow-lg z-50`,children:(0,$.jsxs)(`div`,{className:`p-2`,children:[(0,$.jsxs)(`div`,{className:K(J.dropdownGroupHeading,`px-2 py-1.5 border-b border-border/50 mb-1 flex items-center gap-2`),children:[(0,$.jsx)(Dr,{className:`h-3 w-3`}),`Available Scripts `,_&&`(loading...)`]}),p.length>0?(()=>{let e={};p.forEach(t=>{e[t.relativePath]||(e[t.relativePath]=[]),e[t.relativePath].push(t)});let t=Object.keys(e).sort(),n=0;return t.map(t=>{let r=e[t].sort((e,t)=>e.name.localeCompare(t.name));return(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:K(J.dropdownGroupHeading,`px-3 py-1.5 text-muted-foreground/70 bg-muted/30`),children:t}),r.map(e=>{let t=n===h;return n++,(0,$.jsxs)(`button`,{type:`button`,className:K(`flex w-full flex-col gap-1 rounded-lg mx-1 px-3 py-2 text-left transition-colors`,t?`bg-accent text-accent-foreground`:`text-popover-foreground hover:bg-accent/50`),onClick:()=>w(e),onMouseEnter:()=>g(n-1),children:[(0,$.jsx)(`span`,{className:`font-medium`,children:e.name}),(0,$.jsx)(`span`,{className:K(J.caption,`font-mono`),children:e.commandLine})]},e.commandLine)})]},t)})})():(0,$.jsx)(`div`,{className:K(J.caption,`px-3 py-4 text-center`),children:_?`Loading scripts...`:`No package scripts found`})]})})]}),(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[(0,$.jsx)(dr,{htmlFor:`relativeFolder`,children:`Relative Folder`}),(0,$.jsx)(Lt,{id:`relativeFolder`,value:s.relativeFolder??``,onChange:e=>c({...s,relativeFolder:e.target.value}),placeholder:`e.g. frontend, packages/api (optional)`,autoComplete:`off`}),(0,$.jsx)(`p`,{className:J.bodyMuted,children:`Folder path relative to project root where the command will be executed. Leave empty to run from project root.`})]}),(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[(0,$.jsx)(dr,{children:`Icon`}),(0,$.jsx)(Ti,{children:(0,$.jsx)(`div`,{className:`grid grid-cols-10 gap-1 p-2 bg-background rounded-md border border-border`,children:Kh.map(e=>{let t=Fn[e]||wn;return(0,$.jsxs)(sa,{children:[(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsx)(Fe,{variant:s.icon===e?`default`:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:()=>c({...s,icon:e}),children:(0,$.jsx)(t,{className:`h-4 w-4`})})}),(0,$.jsx)(Qa,{children:e})]},e)})})})]}),(0,$.jsxs)(`div`,{className:`flex justify-end gap-2 mt-2`,children:[(0,$.jsxs)(Fe,{variant:`ghost`,size:`sm`,onClick:()=>c(null),children:[(0,$.jsx)(Gt,{className:`h-4 w-4 mr-2`}),` Cancel`]}),(0,$.jsx)(Fe,{size:`sm`,onClick:async()=>{if(!s?.name||!s?.commandLine){Ri({title:`Error`,description:`Name and Command Line are required`,variant:`destructive`});return}try{u(!0),await ot(n,s),Ri({title:`Success`,description:`Command saved`}),c(null),i()}catch{Ri({title:`Error`,description:`Failed to save command`,variant:`destructive`})}finally{u(!1)}},disabled:l,children:l?`Saving...`:`Save`})]})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 max-h-[400px] overflow-y-auto pr-2`,children:[r.length===0&&(0,$.jsx)(`div`,{className:`text-center py-8 text-muted-foreground border-2 border-dashed rounded-lg`,children:`No commands defined yet.`}),r.map(e=>(0,$.jsxs)(`div`,{className:`flex items-center justify-between p-3 rounded-md border border-border bg-card hover:bg-muted/50 cursor-pointer group transition-colors`,onClick:()=>S(e),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(`div`,{className:`p-2 bg-muted rounded`,children:(0,$.jsx)(Fn[e.icon]||ae,{className:`h-4 w-4`})}),(0,$.jsxs)(`div`,{className:`flex flex-col`,children:[(0,$.jsx)(`span`,{className:J.label,children:e.name}),(0,$.jsx)(`span`,{className:K(J.caption,`line-clamp-1 font-mono`),children:e.commandLine})]})]}),(0,$.jsx)(`div`,{className:`flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity`,children:(0,$.jsx)(Fe,{variant:`ghost`,size:`icon`,className:`h-8 w-8 text-muted-foreground hover:bg-destructive hover:text-destructive-foreground transition-colors`,onClick:t=>{t.stopPropagation(),E(e.id)},children:(0,$.jsx)(Tt,{className:`h-4 w-4`})})})]},e.id))]}),(0,$.jsxs)(Fe,{variant:`outline`,className:`w-full border-dashed`,onClick:x,children:[(0,$.jsx)(ir,{className:`h-4 w-4 mr-2`}),` Add New Command`]})]})})]})})}var Jh=function({workspaceEntries:e,hasMultipleWorkspaces:t,runningScripts:n,onScriptClick:r,onPinClick:i}){return t?e.map(([e,t])=>(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`div`,{className:`px-2 py-1 text-xs font-medium text-muted-foreground`,children:e}),t.map(e=>(0,$.jsxs)(`div`,{className:`group flex items-center rounded-sm hover:bg-accent`,children:[(0,$.jsxs)(`button`,{type:`button`,className:`flex min-w-0 flex-1 items-center gap-2 px-2 py-1.5 text-sm`,onClick:()=>{r(e)},children:[n.has(e.name)?(0,$.jsx)(sn,{className:`h-3 w-3 animate-spin shrink-0`}):(0,$.jsx)(`div`,{className:`h-3 w-3 shrink-0`}),(0,$.jsx)(`span`,{className:`truncate`,children:e.friendlyName})]}),(0,$.jsx)(Xh,{script:e,onPinClick:i})]},e.name))]},e)):e[0]?.[1].map(e=>(0,$.jsxs)(`div`,{className:`group flex items-center rounded-sm hover:bg-accent`,children:[(0,$.jsxs)(`button`,{type:`button`,className:`flex min-w-0 flex-1 items-center gap-2 px-2 py-1.5 text-sm`,onClick:()=>{r(e)},children:[n.has(e.name)?(0,$.jsx)(sn,{className:`h-3 w-3 animate-spin shrink-0`}):(0,$.jsx)(`div`,{className:`h-3 w-3 shrink-0`}),(0,$.jsx)(`span`,{className:`truncate`,children:e.friendlyName})]}),(0,$.jsx)(Xh,{script:e,onPinClick:i})]},e.name))};function Yh(e){let t=e.match(/^cd\s+(.+?)\s+&&\s+(.+)$/);return t?{relativeFolder:t[1],commandLine:t[2]}:{commandLine:e}}function Xh(e){let t=(0,Q.c)(10),{script:n,onPinClick:r}=e,i=`Add ${n.friendlyName} as a project command`,a;t[0]!==r||t[1]!==n?(a=e=>{e.stopPropagation(),r(n)},t[0]=r,t[1]=n,t[2]=a):a=t[2];let o;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,$.jsx)(_t,{className:`h-3.5 w-3.5`}),t[3]=o):o=t[3];let s;t[4]!==i||t[5]!==a?(s=(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsx)(Fe,{type:`button`,variant:`ghost`,size:`icon`,className:`ml-auto h-6 w-6 shrink-0 opacity-0 pointer-events-none transition-opacity can-hover:group-hover:opacity-100 can-hover:group-hover:pointer-events-auto focus-visible:opacity-100`,"aria-label":i,"data-script-pin":!0,onClick:a,children:o})}),t[4]=i,t[5]=a,t[6]=s):s=t[6];let c;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,$.jsx)(Qa,{children:`Add as project command`}),t[7]=c):c=t[7];let l;return t[8]===s?l=t[9]:(l=(0,$.jsxs)(sa,{children:[s,c]}),t[8]=s,t[9]=l),l}function Zh({workspaceEntries:e,hasMultipleWorkspaces:t,runningScripts:n,onScriptClick:r,onPinClick:i}){return t?e.map(([e,t])=>(0,$.jsxs)(Bi,{children:[(0,$.jsx)(oo,{children:e}),(0,$.jsx)(Zi,{className:`max-h-[min(400px,80vh)] overflow-y-auto`,children:t.map(e=>(0,$.jsxs)(ya,{onClick:()=>{r(e)},className:`group gap-2`,children:[n.has(e.name)?(0,$.jsx)(sn,{className:`h-3 w-3 animate-spin shrink-0`}):(0,$.jsx)(`div`,{className:`h-3 w-3 shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.friendlyName}),(0,$.jsx)(Xh,{script:e,onPinClick:i})]},e.name))})]},e)):e[0]?.[1].map(e=>(0,$.jsxs)(ya,{onClick:()=>{r(e)},className:`group gap-2`,children:[n.has(e.name)?(0,$.jsx)(sn,{className:`h-3 w-3 animate-spin shrink-0`}):(0,$.jsx)(`div`,{className:`h-3 w-3 shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.friendlyName}),(0,$.jsx)(Xh,{script:e,onPinClick:i})]},e.name))}function Qh({threadId:e,layout:t=`bar`}){let n=Gi(),r=X(e=>e.projects).find(t=>t.threads.some(t=>t.threadId===e)),{setTerminalNotification:i}=Fi(),{openChatDockPanel:a}=Yc(),{setDevServerUrl:o}=Vh(),s=uh(),[c,l]=(0,Z.useState)(null),[u,d]=(0,Z.useState)(new Set),[f,p]=(0,Z.useState)(null),h=(0,Z.useRef)(new Map);(0,Z.useEffect)(()=>((async()=>{try{let t=await At(e);if(t.length===0){l(null);return}l(t),d(new Set(t.filter(e=>e.isRunning).map(e=>e.name)))}catch{l(null)}})(),()=>{for(let e of h.current.values())e.abort();h.current.clear()}),[e]);function g(t){if(typeof t==`string`){n({type:Y.AppendTerminalLine,threadId:e,line:{type:`output`,content:t}});return}if(!(!t||typeof t!=`object`)){if(Uh(t)){Hh({url:t.url,useBuiltInBrowser:r?.useBuiltInBrowser!==!1,setDevServerUrl:o,openBrowserPanel:()=>{a(`browser`)},openExternalUrl:C,onTerminalMessage:t=>{n({type:Y.AppendTerminalLine,threadId:e,line:{type:`system`,content:t}})}});return}`type`in t&&t.type===`error`&&`message`in t&&n({type:Y.AppendTerminalLine,threadId:e,line:{type:`error`,content:String(t.message)}})}}let _=async t=>{if(u.has(t.name)){let r=h.current.get(t.name);r&&(r.abort(),h.current.delete(t.name));try{await br(e,t.name)}catch{}n({type:Y.AppendTerminalLine,threadId:e,line:{type:`system`,content:`■ ${t.friendlyName} stopped`}}),d(e=>{let n=new Set(e);return n.delete(t.name),n})}else{let r=new AbortController;h.current.set(t.name,r),d(e=>new Set([...e,t.name])),i(!0),n({type:Y.AppendTerminalLine,threadId:e,line:{type:`system`,content:`▶ ${t.friendlyName}`}});try{let i=await m(e,t.name,t.command,{signal:r.signal});i&&await bo(i,e=>{g(e)}),n({type:Y.AppendTerminalLine,threadId:e,line:{type:`system`,content:`✓ ${t.friendlyName} done`}})}catch{}finally{h.current.delete(t.name),d(e=>{let n=new Set(e);return n.delete(t.name),n})}}};if(!c)return null;let v=c.reduce((e,t)=>(e[t.workspace]||(e[t.workspace]=[]),e[t.workspace].push(t),e),{}),y=Object.entries(v).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>[e,[...t].sort((e,t)=>e.friendlyName.localeCompare(t.friendlyName))]),b=y.length>1;function x(e){_(e)}function S(e){p(e)}function w(e){e||p(null)}function T(){p(null),n({type:Y.ConfigUpdated})}return t===`menu`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Ti,{children:(0,$.jsxs)(iu,{children:[(0,$.jsx)(au,{asChild:!0,children:(0,$.jsxs)(Fe,{variant:`ghost`,size:`sm`,className:`w-full justify-start gap-2`,children:[(0,$.jsx)(ze,{className:`h-4 w-4 shrink-0`}),`Project Scripts`]})}),(0,$.jsx)(ou,{align:`start`,className:`w-56 p-1`,children:(0,$.jsx)(Jh,{workspaceEntries:y,hasMultipleWorkspaces:b,runningScripts:u,onScriptClick:x,onPinClick:S})})]})}),r&&(0,$.jsx)(qh,{open:f!==null,onOpenChange:w,projectId:r.projectId,commands:r.commands??[],onRefresh:T,initialCommand:f?{name:f.friendlyName,...Yh(f.command)}:void 0})]}):(0,$.jsxs)(fa,{children:[(0,$.jsx)(Ti,{children:(0,$.jsxs)(sa,{children:[(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsx)(Ji,{asChild:!0,children:(0,$.jsx)(Fe,{variant:`action`,size:`icon-md`,className:s?`text-foreground`:void 0,children:(0,$.jsx)(ze,{})})})}),(0,$.jsx)(Qa,{children:`Project Scripts`})]})}),(0,$.jsx)(Ei,{align:`end`,className:`min-w-[180px]`,children:(0,$.jsx)(Zh,{workspaceEntries:y,hasMultipleWorkspaces:b,runningScripts:u,onScriptClick:x,onPinClick:S})}),r&&(0,$.jsx)(qh,{open:f!==null,onOpenChange:w,projectId:r.projectId,commands:r.commands??[],onRefresh:T,initialCommand:f?{name:f.friendlyName,...Yh(f.command)}:void 0})]})}function $h({layout:e=`bar`,threadId:t}){let n=X(e=>e.selectedProjectId),r=X(e=>e.selectedThreadId),i=X(e=>e.projects),a=Gi(),{setTerminalNotification:o}=Fi(),{openChatDockPanel:s}=Yc(),{setDevServerUrl:c}=Vh(),l=uh(),[u,d]=(0,Z.useState)(new Set),f=(0,Z.useRef)(new Map),p=t??r,h=i.find(e=>e.projectId===n),g=h?.commands??[];(0,Z.useEffect)(()=>()=>{let e=f.current;for(let t of e.values())t.abort();e.clear()},[p]);function _(e){if(p){if(typeof e==`string`){a({type:Y.AppendTerminalLine,threadId:p,line:{type:`output`,content:e}});return}if(!(!e||typeof e!=`object`)){if(Uh(e)){Hh({url:e.url,useBuiltInBrowser:h?.useBuiltInBrowser!==!1,setDevServerUrl:c,openBrowserPanel:()=>{s(`browser`)},openExternalUrl:C,onTerminalMessage:e=>{a({type:Y.AppendTerminalLine,threadId:p,line:{type:`system`,content:e}})}});return}`type`in e&&e.type===`error`&&`message`in e&&a({type:Y.AppendTerminalLine,threadId:p,line:{type:`error`,content:String(e.message)}})}}}async function v(e){if(!p)return;if(u.has(e.id)){let t=f.current.get(e.id);t&&(t.abort(),f.current.delete(e.id));try{await br(p,e.id)}catch{}a({type:Y.AppendTerminalLine,threadId:p,line:{type:`system`,content:`■ ${e.name} stopped`}}),d(t=>{let n=new Set(t);return n.delete(e.id),n});return}let t=new AbortController;f.current.set(e.id,t),d(t=>new Set([...t,e.id])),o(!0),a({type:Y.AppendTerminalLine,threadId:p,line:{type:`system`,content:`▶ ${e.name}`}});try{let n=await m(p,e.id,e.commandLine,{signal:t.signal,relativeFolder:e.relativeFolder});n&&await bo(n,e=>{_(e)}),t.signal.aborted||a({type:Y.AppendTerminalLine,threadId:p,line:{type:`system`,content:`✓ ${e.name} done`}})}catch{}finally{f.current.delete(e.id),d(t=>{let n=new Set(t);return n.delete(e.id),n})}}return!n||g.length===0?null:e===`menu`?(0,$.jsx)($.Fragment,{children:g.map(e=>{let t=u.has(e.id),n=Fn[e.icon]||ae;return(0,$.jsx)(Ti,{children:(0,$.jsxs)(sa,{children:[(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsxs)(Fe,{variant:`ghost`,size:`sm`,className:K(`w-full justify-start gap-2`,t&&`text-muted-foreground opacity-80`),onClick:()=>v(e),children:[(0,$.jsxs)(`span`,{className:`relative inline-flex items-center justify-center`,children:[t&&(0,$.jsx)(`span`,{"aria-hidden":!0,className:`pointer-events-none absolute inset-[-8px] rounded-full border-2 border-brand/30 border-t-brand animate-spin`}),(0,$.jsx)(n,{className:K(`h-4 w-4 shrink-0`,t&&`opacity-60`)})]}),e.name]})}),(0,$.jsx)(Qa,{side:`right`,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,$.jsx)(`span`,{className:`font-medium`,children:e.name}),(0,$.jsx)(`span`,{className:`text-[10px] opacity-70 font-mono whitespace-pre-wrap max-w-[300px] max-h-[100px] overflow-y-auto`,children:e.commandLine}),t&&(0,$.jsx)(`span`,{className:`text-[10px] text-primary font-medium`,children:`Click to stop`})]})})]})},e.id)})}):(0,$.jsx)(`div`,{className:`flex items-center gap-1`,children:(0,$.jsx)(Ti,{children:g.map(e=>{let t=u.has(e.id),n=Fn[e.icon]||ae;return(0,$.jsxs)(sa,{children:[(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsx)(Fe,{variant:`action`,size:`icon-md`,className:K(l&&!t&&`text-foreground`,t&&`text-muted-foreground opacity-80`),onClick:()=>v(e),children:(0,$.jsxs)(`span`,{className:`relative inline-flex items-center justify-center`,children:[t&&(0,$.jsx)(`span`,{"aria-hidden":!0,className:`pointer-events-none absolute inset-[-8px] rounded-full border-2 border-brand/30 border-t-brand animate-spin`}),(0,$.jsx)(n,{className:K(t&&`opacity-60`)})]})})}),(0,$.jsx)(Qa,{children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,$.jsx)(`span`,{className:`font-medium`,children:e.name}),(0,$.jsx)(`span`,{className:`text-[10px] opacity-70 font-mono whitespace-pre-wrap max-w-[300px] max-h-[100px] overflow-y-auto`,children:e.commandLine}),t&&(0,$.jsx)(`span`,{className:`text-[10px] text-primary font-medium`,children:`Click to stop`})]})})]},e.id)})})})}var eg=Pn(`app.open-with-button.ui`),tg=`VS Code`;function ng(e){return e||Dn(tg)}var rg={"VS Code":`vscode`,Antigravity:`antigravity`,Cursor:`cursor`,"Devin Desktop":`devin`,Windsurf:`windsurf`,Xcode:`xcode`,"Android Studio":`android-studio`,Kiro:`kiro`,Terminal:`terminal`};function ig({projectId:e,threadId:t,openWith:n,layout:r=`bar`}){let i=uh(),[a,o]=(0,Z.useState)(!1),[s,c]=(0,Z.useState)([]),[l,d]=(0,Z.useState)(()=>ng(n)),[f,p]=(0,Z.useState)(!0);(0,Z.useEffect)(()=>{(async()=>{try{let e=await ct();c(e);let t=ng(n);e.includes(t)?d(t):e.length>0&&d(e[0])}catch(e){eg.error(`Failed to fetch available programs:`,e),c([tg])}finally{p(!1)}})()},[]),(0,Z.useEffect)(()=>{if(n&&s.includes(n)){d(n);return}let e=Dn(tg);!n&&s.includes(e)&&d(e)},[n,s]);async function m(t){d(t),N(t),await Gn(e,t)}let h=async n=>{try{o(!0),await m(n),t?await On(t,n):await u(e,n),Ri({title:`Success`,description:`Opened project in ${n}`})}catch(e){eg.error(`Failed to open project in ${n}:`,e);let t=`Failed to open project in ${n}`;if(e instanceof Error){let n=e;t=n.details?n.details:e.message}Ri({title:`Error`,description:t,variant:`destructive`})}finally{o(!1)}};async function g(e){try{await m(e)}catch(t){eg.error(`Failed to save preferred IDE (${e}):`,t),Ri({title:`Error`,description:`Failed to save IDE preference`,variant:`destructive`})}}let _=async()=>{await h(l)},v=i?`ghost`:`outline`,y=i?`text-foreground`:`border-transparent`;return f?(0,$.jsx)(Fe,{variant:v,size:`sm`,className:K(`h-8`,y),disabled:!0,children:(0,$.jsx)(`div`,{className:`h-4 w-4 animate-pulse bg-muted rounded`})}):r===`menu`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(Fe,{variant:`ghost`,size:`sm`,className:`w-full justify-start gap-2`,disabled:a,onClick:()=>{_()},children:[(0,$.jsx)(`img`,{src:`/ide/${rg[l]||rg[tg]}.svg`,alt:l,className:`h-4 w-4 shrink-0`}),`Open in `,l]}),(0,$.jsxs)(iu,{children:[(0,$.jsx)(au,{asChild:!0,children:(0,$.jsxs)(Fe,{variant:`ghost`,size:`sm`,className:`w-full justify-start gap-2`,children:[(0,$.jsx)(Dr,{className:`h-4 w-4 shrink-0`}),`Change IDE`]})}),(0,$.jsx)(ou,{align:`start`,className:`w-56 p-1`,children:s.map(e=>(0,$.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-2 rounded-sm px-2 py-1.5 text-sm hover:bg-accent disabled:opacity-50`,onClick:()=>{g(e)},disabled:a,children:[(0,$.jsx)(`img`,{src:`/ide/${rg[e]||rg[tg]}.svg`,alt:e,className:`h-4 w-4 shrink-0`}),e]},e))})]})]}):(0,$.jsxs)(`div`,{className:`flex items-center gap-0`,children:[(0,$.jsxs)(sa,{children:[(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsx)(Fe,{variant:v,size:`sm`,className:K(`h-8 rounded-r-none`,i?`text-foreground`:`border-r-0 border-transparent`),disabled:a,onClick:_,children:(0,$.jsx)(`img`,{src:`/ide/${rg[l]||rg[tg]}.svg`,alt:l,className:`h-4 w-4`})})}),(0,$.jsx)(Qa,{children:`Open in ${l}`})]}),(0,$.jsxs)(fa,{children:[(0,$.jsx)(Ji,{asChild:!0,children:(0,$.jsx)(Fe,{variant:v,size:`sm`,className:K(`h-8 w-8 rounded-l-none px-1`,y),disabled:a,children:(0,$.jsx)(Dr,{className:`h-3.5 w-3.5`})})}),(0,$.jsx)(Ei,{align:`end`,children:s.map(e=>(0,$.jsxs)(ya,{onClick:()=>void g(e),disabled:a,className:`flex items-center gap-2`,children:[(0,$.jsx)(`img`,{src:`/ide/${rg[e]||rg[tg]}.svg`,alt:e,className:`h-4 w-4`}),e]},e))})]})]})}function ag(){return`dev-server-${Date.now()}-${Math.random().toString(36).slice(2,9)}`}function og(e,t){return Na({messageId:`msg-dev-server-${t}`,command:e,toolCallId:t})}function sg(e,t){e({type:Y.AddMessage,message:og(t.command,t.toolCallId),threadId:t.threadId}),e({type:Y.SetDevServerToolSession,session:t})}function cg(e,t,n){n&&e({type:Y.AppendToolExecutionOutput,toolCallId:t,toolName:`bash`,delta:n})}function lg(e,t,n,r){e({type:Y.UpdateMessage,messageId:t.messageId,threadId:t.threadId,content:go(So(t.command,t.toolCallId),t.toolCallId,n,r)}),e({type:Y.ClearToolCallProgress,toolCallId:t.toolCallId}),e({type:Y.SetDevServerToolSession,session:null})}function ug(e){return function(t){if(typeof t==`string`){cg(e.dispatch,e.toolCallId,t);return}if(!(!t||typeof t!=`object`)&&`type`in t){if(t.type===`stdout`||t.type===`stderr`){`content`in t&&typeof t.content==`string`&&cg(e.dispatch,e.toolCallId,t.content);return}if(Uh(t)){Promise.resolve(e.onUrl?.(t.url));return}if(t.type===`complete`){`exitCode`in t&&typeof t.exitCode==`number`&&e.onExitCode?.(t.exitCode);return}if(t.type===`error`){let n=`message`in t&&t.message!=null?String(t.message):`error`in t&&t.error!=null?String(t.error):`Dev server error`;cg(e.dispatch,e.toolCallId,`${n}\n`)}}}}function dg(e){return e instanceof DOMException&&e.name===`AbortError`}async function fg(e,t,n){let r=e.getReader(),i=new TextDecoder,a=``;try{for(;;){if(n?.aborted){await r.cancel();return}let{done:e,value:o}=await r.read();if(e)break;a+=i.decode(o,{stream:!0});let s=a.split(`
|
|
47
|
+
`);a=s.pop()??``;for(let e of s)if(e.trim())try{t(JSON.parse(e))}catch{t(e)}}if(a.trim())try{t(JSON.parse(a))}catch{t(a)}}catch(e){if(n?.aborted||dg(e))return;throw e}finally{r.releaseLock()}}var pg=Pn(`app.use-start-dev-server.hook`);function mg(){let e=(0,Q.c)(28),t=X(hg),n=Gi(),r=Ca(),{openChatDockPanel:i}=Yc(),{setDevServerUrl:a,setDevServerRunning:o,setDevServerProjectId:s,setDevServerLoading:c,devServerStopRequestedRef:l}=Vh(),u=(0,Z.useRef)(null),d=(0,Z.useRef)(!1),f;e[0]===r?f=e[1]:(f=function(e){return r.getState().toolCallProgress[e.toolCallId]?.executionOutput??``},e[0]=r,e[1]=f);let p=f,m;e[2]!==l||e[3]!==p?(m=function(e){let t=p(e);return l.current?(l.current=!1,`${t}${t.endsWith(`
|
|
48
|
+
`)?`Server stopped.
|
|
49
|
+
`:`
|
|
50
|
+
Server stopped.
|
|
51
|
+
`}`):t.trim()?t:`Dev server exited.
|
|
52
|
+
`},e[2]=l,e[3]=p,e[4]=m):m=e[4];let h=m,g;e[5]!==n||e[6]!==p?(g=function(e){if(d.current)return;d.current=!0;let t=p(e);lg(n,e,t.trim()?t:`Dev server started.
|
|
53
|
+
`),u.current?.abort(),u.current=null},e[5]=n,e[6]=p,e[7]=g):g=e[7];let _=g,v;e[8]!==n||e[9]!==h||e[10]!==s||e[11]!==o?(v=function(e,t){if(d.current)return;d.current=!0;let r=t!==void 0&&t!==0;lg(n,e,h(e),r),o(!1),s(null)},e[8]=n,e[9]=h,e[10]=s,e[11]=o,e[12]=v):v=e[12];let y=v,b;e[13]!==l||e[14]!==n||e[15]!==y||e[16]!==_||e[17]!==p||e[18]!==i||e[19]!==t||e[20]!==s||e[21]!==a||e[22]!==c||e[23]!==o?(b=async e=>{if(!e?.runCommand||!e?.projectId||!t)return;l.current=!1,d.current=!1,u.current?.abort(),u.current=new AbortController;let r=u.current.signal;s(e.projectId),o(!0),c(!0);let f=ag(),m={threadId:t,toolCallId:f,messageId:`msg-dev-server-${f}`,command:e.runCommand};sg(n,m);try{let l=await Ie(e.projectId,t,r);if(!l){lg(n,m,`Failed to start dev server.
|
|
54
|
+
`),o(!1),s(null),c(!1),d.current=!0;return}c(!1);let u;await fg(l,ug({dispatch:n,toolCallId:f,onUrl:async t=>{await Hh({url:t,useBuiltInBrowser:e.useBuiltInBrowser!==!1,setDevServerUrl:a,openBrowserPanel:()=>{i(`browser`,{navigateToChat:!1})},openExternalUrl:C,onTerminalMessage:e=>{n({type:Y.AppendToolExecutionOutput,toolCallId:f,toolName:`bash`,delta:`${e}\n`})}}),_(m)},onExitCode:e=>{u=e}}),r),d.current||y(m,u)}catch(e){let t=e;if(r.aborted&&d.current)return;pg.error(`Failed to start dev server:`,t),c(!1),d.current||=(lg(n,m,`${p(m)}Failed to start dev server.\n`.trimStart()),!0),o(!1),s(null)}},e[13]=l,e[14]=n,e[15]=y,e[16]=_,e[17]=p,e[18]=i,e[19]=t,e[20]=s,e[21]=a,e[22]=c,e[23]=o,e[24]=b):b=e[24];let x=b,S;return e[25]!==a||e[26]!==x?(S={startServer:x,setServerUrl:a},e[25]=a,e[26]=x,e[27]=S):S=e[27],S}function hg(e){return e.selectedThreadId}var gg=3e4,_g=2e3,vg=5e3;function yg(e,t,n){return!!(e&&t&&n===e)}function bg(e){let{devServerRunning:t,setDevServerRunning:n,devServerProjectId:r,setDevServerProjectId:i,devServerLoading:a}=Vh(),o=yg(e,t,r),s=(0,Z.useRef)(!1),c=(0,Z.useRef)(t),l=(0,Z.useRef)(r);c.current=t,l.current=r;let u=(0,Z.useCallback)(t=>{if(e){if(t){i(e),n(!0);return}r===e&&(n(!1),i(null))}},[e,r,i,n]);return(0,Z.useEffect)(()=>{e&&(s.current=!1,(async()=>{try{let t=await Ze(e),n=yg(e,c.current,l.current);if(!t.isRunning&&n)return;u(t.isRunning)}catch{yg(e,c.current,l.current)||u(!1)}finally{s.current=!0}})())},[e,u]),(0,Z.useEffect)(()=>{if(!e||!a)return;let t=Date.now(),n=setInterval(()=>{if(Date.now()-t>gg){clearInterval(n);return}Ze(e).then(e=>{e.isRunning&&(u(!0),clearInterval(n))}).catch(()=>{})},_g);return()=>clearInterval(n)},[e,a,u]),(0,Z.useEffect)(()=>{if(!e||!o)return;let t=setInterval(()=>{Ze(e).then(e=>{e.isRunning||u(!1)}).catch(()=>{})},vg);return()=>clearInterval(t)},[e,o,u]),{isRunning:o,isLoading:a,recheck:(0,Z.useCallback)(async()=>{if(e)try{u((await Ze(e)).isRunning)}catch{u(!1)}},[e,u])}}var xg=Oi(e=>(0,$.jsxs)(`button`,{onClick:e.v0,disabled:e.v1,className:e.v2,children:[e.v3,(0,$.jsx)(`span`,{className:e.v4,children:e.v5})]}),{name:`RunStopButton_1`,portals:[`v3`,`v5`]}),Sg=Oi(e=>e.v0,{name:`RunStopButton_2`,portals:[`v0`]}),Cg=Oi(e=>(0,$.jsx)(`slot`,{children:e.v0}),{name:`RunStopButton_3`,portals:[`v0`]}),wg=function({projectId:e,runCommand:t,large:n,layout:r=`bar`}){let i=X(e=>e.projects).find(t=>t.projectId===e),{setDevServerUrl:a,setDevServerRunning:o,setDevServerProjectId:s,setDevServerLoading:c,devServerStopRequestedRef:l}=Vh(),{startServer:u}=mg(),{isRunning:d,isLoading:f}=bg(e),p=uh();function m(){u({projectId:e,runCommand:t||``,useBuiltInBrowser:i?.useBuiltInBrowser!==!1})}async function h(){l.current=!0,c(!0);try{await $t(e),o(!1),s(null),a(null)}catch(e){Ri({title:`Error`,description:e instanceof Error?e.message:`Failed to stop dev server`,variant:`destructive`})}finally{c(!1)}}let g=!!t,_=f?`Starting...`:d?`Stop dev server`:`Start dev server`;return n?(0,$.jsx)(xg,{v0:d?h:m,v1:f||!d&&!g,v2:`flex flex-col items-center gap-3 group disabled:opacity-40 disabled:cursor-not-allowed ${d?`text-orange-500`:`text-muted-foreground`}`,v3:f?(0,$.jsx)(sn,{className:`h-10 w-10 animate-spin`}):d?(0,$.jsx)(Ye,{className:`h-10 w-10 fill-current`}):(0,$.jsx)(ae,{className:`h-10 w-10 fill-current group-hover:text-foreground transition-colors`}),v4:K(J.body,`group-hover:text-foreground transition-colors`),v5:_}):r===`menu`?(0,$.jsx)(Sg,{v0:(0,$.jsxs)(Fe,{variant:`ghost`,size:`sm`,className:K(`w-full justify-start gap-2`,d&&`text-orange-500`),onClick:d?h:m,disabled:f||!d&&!g,children:[f?(0,$.jsx)(sn,{className:`h-4 w-4 shrink-0 animate-spin`}):d?(0,$.jsx)(Ye,{className:`h-4 w-4 shrink-0 fill-current`}):(0,$.jsx)(ae,{className:`h-4 w-4 shrink-0`}),_]})}):(0,$.jsx)(Cg,{v0:(0,$.jsx)(Ti,{children:(0,$.jsxs)(sa,{children:[(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsxs)(Fe,{variant:`ghost`,size:`icon`,className:K(`relative h-8 w-8`,d&&`text-orange-500 bg-orange-500/10`,!d&&(p?`text-foreground`:`text-muted-foreground`),d&&`before:absolute before:inset-[-1px] before:rounded-full before:border before:border-orange-500/60 before:animate-ping-subtle before:content-['']`),onClick:d?h:m,disabled:f||!d&&!g,children:[f?(0,$.jsx)(sn,{className:`h-4 w-4 animate-spin`}):d?(0,$.jsx)(Ye,{className:`h-4 w-4 fill-current`}):(0,$.jsx)(ae,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:d?`Stop dev server`:`Start dev server`})]})}),(0,$.jsx)(Qa,{children:d?`Stop dev server`:g?`Start dev server: ${t}`:`Set run command in project settings`})]})})})};function Tg(){return{autoGenerateCommitMessage:Ke(),autoGeneratePRInfo:y(),privateRepositoryDefault:ge(),newChatOnNewBranch:l()}}function Eg(e){e.autoGenerateCommitMessage!==void 0&&Ve(e.autoGenerateCommitMessage),e.autoGeneratePRInfo!==void 0&&Xr(e.autoGeneratePRInfo),e.privateRepositoryDefault!==void 0&&ce(e.privateRepositoryDefault),e.newChatOnNewBranch!==void 0&&U(e.newChatOnNewBranch)}var Dg=Pn(`app.merged-pr-dialog-host.ui`),Og=(0,Z.lazy)(()=>po(()=>import(`./merged-pr-dialog-CiwhRqFv.js`).then(e=>({default:e.MergedPRDialog})),__vite__mapDeps([3,4,1,5,6])));function kg({threadId:e,projectId:t}){let n=Gi(),r=X(e=>e.projects.find(e=>e.projectId===t)),i=Vc(),[a,o]=(0,Z.useState)(!1),[s,c]=(0,Z.useState)(!1),l=(0,Z.useRef)(null),[u,d]=(0,Z.useState)(()=>Tg());(0,Z.useEffect)(()=>{Eg(u)},[u]),(0,Z.useEffect)(()=>{i.prExists&&i.prState===`MERGED`&&l.current!==e&&(l.current=e,o(!0))},[i.prExists,i.prState,e]);async function f(){try{c(!0);let r=await z(e);if(u.newChatOnNewBranch){let r=`New Chat`;await Dt(e,{title:r}),n({type:Y.UpdateThreadTitle,projectId:t,threadId:e,title:r}),await ur(e),n({type:Y.ClearMessages}),setTimeout(()=>{(async()=>{try{let t=await B(e);n({type:Y.SetMessages,messages:t.messages})}catch(e){Dg.error(`Failed to refresh chat history after starting new chat:`,e)}})()},0)}Ir();let a=await Bt();n({type:Y.SetProjects,projects:a.projects}),Ri({title:`New branch created`,description:`Created new branch "${r.branchName}" from the latest default branch`}),o(!1),await i.fetchUnifiedStatus(!0),setTimeout(()=>void i.fetchUnifiedStatus(!0),1500)}catch(e){Dg.error(`Failed to create new branch:`,e),Ri({title:`Failed to create new branch`,description:e instanceof Error?e.message:`Unknown error occurred`,variant:`destructive`})}finally{c(!1)}}function p(){o(!1),i.fetchUnifiedStatus(!0)}return a?(0,$.jsx)(Z.Suspense,{fallback:null,children:(0,$.jsx)(Og,{open:a,onOpenChange:o,onNewBranch:f,onJustOpen:p,newChatOnNewBranch:u.newChatOnNewBranch,onNewChatOnNewBranchChange:e=>d(t=>({...t,newChatOnNewBranch:e})),isLoading:s,projectName:r?.name})}):null}function Ag(){return typeof window>`u`?null:Lr(window.location.search)}function jg(){return typeof window>`u`?null:$e(window.location.search)}function Mg(){return Ag()===S}var Ng=(0,Z.lazy)(()=>po(()=>import(`./git-ops-button-CKGLh3Zk.js`).then(e=>({default:e.GitOpsButton})),__vite__mapDeps([7,1,6,4,5])));function Pg(e){return e===`menu`?`w-full justify-start gap-2`:`gap-2`}function Fg(e){let t=(0,Q.c)(4),{threadId:n,projectId:r,messages:i,userTasks:a}=e,{hasChanges:o}=Vc(),s=i.length>0,c=!!n&&(s||o||a.length>0||!!(n&&r)),l;return t[0]!==o||t[1]!==s||t[2]!==c?(l={isVisible:c,hasMessages:s,hasChanges:o},t[0]=o,t[1]=s,t[2]=c,t[3]=l):l=t[3],l}function Ig(e){let t=(0,Q.c)(2),{hasMessages:n,onNewChat:r}=e;if(!n)return null;let i;return t[0]===r?i=t[1]:(i=(0,$.jsx)(`div`,{className:`absolute -top-12 left-0 z-10 ml-8 flex flex-wrap items-center gap-2`,"data-chat-toolbar":!0,children:(0,$.jsx)(Fe,{variant:`outline`,size:`sm`,onClick:r,children:`New Chat`})}),t[0]=r,t[1]=i),i}function Lg(e){let t=(0,Q.c)(64),{threadId:n,projectId:r,messages:i,userTasks:a,effectiveIsStreaming:o,isCreatingProject:s,onNewChat:c,onSelectUserTask:l,onToggleUserTaskPinned:u,onRemoveUserTask:d,layout:f}=e,p=f===void 0?`bar`:f,{openChatDockPanel:m}=Yc(),h;t[0]!==i||t[1]!==r||t[2]!==n||t[3]!==a?(h={threadId:n,projectId:r,messages:i,userTasks:a},t[0]=i,t[1]=r,t[2]=n,t[3]=a,t[4]=h):h=t[4];let{hasMessages:g,hasChanges:_,isVisible:v}=Fg(h),{changedFilesCount:y}=Vc(),b;t[5]===p?b=t[6]:(b=Pg(p),t[5]=p,t[6]=b);let x=b,S=X(Rg),C;if(t[7]!==r||t[8]!==S){let e;t[10]===r?e=t[11]:(e=e=>e.projectId===r,t[10]=r,t[11]=e),C=S.find(e),t[7]=r,t[8]=S,t[9]=C}else C=t[9];let w=C,T=p===`menu`&&!!n&&!!r,E=g||_||a.length>0||!!(n&&r),D;t[12]===p?D=t[13]:(D=p===`menu`||Mg(),t[12]=p,t[13]=D);let O=D;if(!v)return null;let k=p===`bar`&&`absolute -top-12 left-0 z-10 ml-8 flex flex-wrap items-center gap-2`,A=p===`menu`&&`flex flex-col items-stretch gap-1 p-1 min-w-[220px]`,j;t[14]!==k||t[15]!==A?(j=K(k,A),t[14]=k,t[15]=A,t[16]=j):j=t[16];let M=p===`bar`?!0:void 0,N;t[17]!==g||t[18]!==p||t[19]!==c||t[20]!==x?(N=g&&(0,$.jsx)(Fe,{variant:p===`menu`?`ghost`:`outline`,size:`sm`,className:x,onClick:c,children:`New Chat`}),t[17]=g,t[18]=p,t[19]=c,t[20]=x,t[21]=N):N=t[21];let P;t[22]!==y||t[23]!==_||t[24]!==p||t[25]!==m||t[26]!==x?(P=_&&p===`menu`&&(0,$.jsxs)(Fe,{variant:`ghost`,size:`sm`,className:x,onClick:()=>{m(`review`)},children:[y,` `,y===1?`Change`:`Changes`]}),t[22]=y,t[23]=_,t[24]=p,t[25]=m,t[26]=x,t[27]=P):P=t[27];let F;t[28]!==o||t[29]!==s||t[30]!==p||t[31]!==d||t[32]!==l||t[33]!==u||t[34]!==n||t[35]!==a?(F=a.length>0&&(0,$.jsx)(Dh,{tasks:a,disabled:o||!n&&!s,onSelectTask:l,onTogglePinned:u,onRemoveTask:d,layout:p}),t[28]=o,t[29]=s,t[30]=p,t[31]=d,t[32]=l,t[33]=u,t[34]=n,t[35]=a,t[36]=F):F=t[36];let I;t[37]!==p||t[38]!==r||t[39]!==O||t[40]!==n?(I=n&&r&&O&&(0,$.jsx)(Z.Suspense,{fallback:null,children:(0,$.jsx)(Ng,{projectId:r,threadId:n,layout:p},n)}),t[37]=p,t[38]=r,t[39]=O,t[40]=n,t[41]=I):I=t[41];let L;t[42]!==g||t[43]!==p?(L=g&&(0,$.jsx)(Th,{layout:p}),t[42]=g,t[43]=p,t[44]=L):L=t[44];let R;t[45]!==E||t[46]!==T?(R=T&&E&&(0,$.jsx)(_a,{className:`my-1`}),t[45]=E,t[46]=T,t[47]=R):R=t[47];let z;t[48]!==r||t[49]!==w?.openWith||t[50]!==w?.runCommand||t[51]!==T||t[52]!==n?(z=T&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(wg,{projectId:r,runCommand:w?.runCommand,layout:`menu`}),(0,$.jsx)(Qh,{threadId:n,layout:`menu`}),(0,$.jsx)($h,{layout:`menu`}),(0,$.jsx)(ig,{projectId:r,threadId:n,openWith:w?.openWith,layout:`menu`})]}),t[48]=r,t[49]=w?.openWith,t[50]=w?.runCommand,t[51]=T,t[52]=n,t[53]=z):z=t[53];let B;return t[54]!==N||t[55]!==P||t[56]!==F||t[57]!==I||t[58]!==L||t[59]!==R||t[60]!==z||t[61]!==j||t[62]!==M?(B=(0,$.jsx)($.Fragment,{children:(0,$.jsxs)(`div`,{className:j,"data-chat-toolbar":M,children:[N,P,F,I,L,R,z]})}),t[54]=N,t[55]=P,t[56]=F,t[57]=I,t[58]=L,t[59]=R,t[60]=z,t[61]=j,t[62]=M,t[63]=B):B=t[63],B}function Rg(e){return e.projects}function zg(e){let t=(0,Q.c)(10),{mode:n,messages:r,onNewChat:i}=e,a=n===void 0?`full`:n,o;t[0]!==r||t[1]!==e.projectId||t[2]!==e.threadId||t[3]!==e.userTasks?(o={threadId:e.threadId,projectId:e.projectId,messages:r,userTasks:e.userTasks},t[0]=r,t[1]=e.projectId,t[2]=e.threadId,t[3]=e.userTasks,t[4]=o):o=t[4];let{hasMessages:s}=Fg(o);if(a===`newChatOnly`){let e;return t[5]!==s||t[6]!==i?(e=(0,$.jsx)(Ig,{hasMessages:s,onNewChat:i}),t[5]=s,t[6]=i,t[7]=e):e=t[7],e}let c;return t[8]===e?c=t[9]:(c=(0,$.jsx)(Lg,{...e}),t[8]=e,t[9]=c),c}function Bg(e){let t=(0,Q.c)(2),n;return t[0]===e?n=t[1]:(n=(0,$.jsx)(zg,{...e}),t[0]=e,t[1]=n),n}function Vg(e){let t=(0,Q.c)(29),{inPill:n}=e,r=n===void 0?!1:n,i=uh(),a=X(Wg),o=X(Ug),s=X(Hg),{userTasks:c,handleNewChat:l,handleSelectUserTask:u,handleRemoveUserTask:d,toggleUserTaskPinned:f,effectiveIsStreaming:p,isCreatingProject:m}=Rh(),h;t[0]!==s||t[1]!==o||t[2]!==a||t[3]!==c?(h={threadId:a,projectId:o,messages:s,userTasks:c},t[0]=s,t[1]=o,t[2]=a,t[3]=c,t[4]=h):h=t[4];let{isVisible:g}=Fg(h);if(!a||!g)return null;let _=r||!i?`text-muted-foreground`:`scenic-foreground-muted hover:scenic-foreground`,v;t[5]===_?v=t[6]:(v=K(`h-8 w-8 shrink-0 md:hidden electrobun-webkit-app-region-no-drag`,_),t[5]=_,t[6]=v);let y,b;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(y=(0,$.jsx)(Rn,{className:`h-4 w-4`}),b=(0,$.jsx)(`span`,{className:`sr-only`,children:`Chat actions`}),t[7]=y,t[8]=b):(y=t[7],b=t[8]);let x;t[9]===v?x=t[10]:(x=(0,$.jsx)(Ji,{asChild:!0,children:(0,$.jsxs)(Fe,{variant:`ghost`,size:`icon`,className:v,children:[y,b]})}),t[9]=v,t[10]=x);let S=o??``,C;t[11]===l?C=t[12]:(C=()=>{l()},t[11]=l,t[12]=C);let w;t[13]===d?w=t[14]:(w=e=>{d(e)},t[13]=d,t[14]=w);let T;t[15]!==p||t[16]!==u||t[17]!==m||t[18]!==s||t[19]!==a||t[20]!==w||t[21]!==S||t[22]!==C||t[23]!==f||t[24]!==c?(T=(0,$.jsx)(Ei,{align:`end`,className:`electrobun-webkit-app-region-no-drag`,children:(0,$.jsx)(Lg,{threadId:a,projectId:S,messages:s,userTasks:c,effectiveIsStreaming:p,isCreatingProject:m,onNewChat:C,onSelectUserTask:u,onToggleUserTaskPinned:f,onRemoveUserTask:w,layout:`menu`})}),t[15]=p,t[16]=u,t[17]=m,t[18]=s,t[19]=a,t[20]=w,t[21]=S,t[22]=C,t[23]=f,t[24]=c,t[25]=T):T=t[25];let E;return t[26]!==T||t[27]!==x?(E=(0,$.jsxs)(fa,{children:[x,T]}),t[26]=T,t[27]=x,t[28]=E):E=t[28],E}function Hg(e){return e.messages}function Ug(e){return e.selectedProjectId}function Wg(e){return e.selectedThreadId}function Gg(e){let t=(0,Q.c)(6),{threadId:n,children:r}=e,i=X(Kg),a;t[0]!==i||t[1]!==n?(a=n&&i?(0,$.jsx)(kg,{threadId:n,projectId:i}):null,t[0]=i,t[1]=n,t[2]=a):a=t[2];let o;return t[3]!==r||t[4]!==a?(o=(0,$.jsxs)($.Fragment,{children:[a,r]}),t[3]=r,t[4]=a,t[5]=o):o=t[5],o}function Kg(e){return e.selectedProjectId}function qg(e){let t=(0,Q.c)(6),{threadId:n,children:r}=e,i;t[0]!==r||t[1]!==n?(i=(0,$.jsx)(Gg,{threadId:n,children:r}),t[0]=r,t[1]=n,t[2]=i):i=t[2];let a;return t[3]!==i||t[4]!==n?(a=(0,$.jsx)(Bc,{threadId:n,children:i}),t[3]=i,t[4]=n,t[5]=a):a=t[5],a}function Jg(e){for(let t=e.length-1;t>=0;--t){let n=e[t];if(n.sender===`user`)return!!n.attributionLabel}return!1}var Yg=3e3;function Xg(e){let t=[];for(let n of e){let e=eo(n.content);e&&t.push(...e)}return t}function Zg(e){let t=new Set;for(let n of e)io(n)&&t.add(n.toolCallId);let n=null;for(let r of e){if(!uo(r)||r.name!==`ask_user`||t.has(r.id))continue;let e=Kd(r.input);e.question&&(n={toolCallId:r.id,question:e.question,options:e.options,context:e.context})}return n}function Qg(e){let t=(0,Q.c)(17),{paneId:n}=If(),r=X($g),i;t[0]!==n||t[1]!==r?(i=e=>_o(e.threadStreamingStates,r,n).streamingSegments,t[0]=n,t[1]=r,t[2]=i):i=t[2];let a=X(i),o;t[3]!==n||t[4]!==r?(o=e=>r?_o(e.threadStreamingStates,r,n).isStreaming||e.processingThreadIds.includes(r):!1,t[3]=n,t[4]=r,t[5]=o):o=t[5];let s=X(o),c=Jg(e),l;t[6]===e?l=t[7]:(l=Xg(e),t[6]=e,t[7]=l);let u=l,d;bb0:{if(!s||c){d=null;break bb0}let e;t[8]!==u||t[9]!==a?(e=Zg([...u,...Ta(a)]),t[8]=u,t[9]=a,t[10]=e):e=t[10],d=e}let f=d,p=f?.toolCallId??null,[m,h]=(0,Z.useState)(null),g=(0,Z.useRef)(!1),_;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(_=()=>{g.current=!1,h(null)},t[11]=_):_=t[11];let v;t[12]===p?v=t[13]:(v=[p],t[12]=p,t[13]=v),(0,Z.useEffect)(_,v);let y,b;return t[14]===p?(y=t[15],b=t[16]):(y=()=>{if(!p)return;let e=!1,t=async function(){try{let t=await H();if(e)return;if(t.some(e=>e.toolCallId===p)){g.current=!0;return}g.current&&h(p)}catch{}};t();let n=setInterval(()=>{t()},Yg);return()=>{e=!0,clearInterval(n)}},b=[p],t[14]=p,t[15]=y,t[16]=b),(0,Z.useEffect)(y,b),!f||m===f.toolCallId?null:f}function $g(e){return e.selectedThreadId}function e_(e){let t=(0,Q.c)(10),{open:n,onClose:r}=e,i=ua(),a;t[0]===r?a=t[1]:(a=e=>{e||r()},t[0]=r,t[1]=a);let o;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,$.jsxs)(ia,{children:[(0,$.jsx)(ca,{children:`Balance empty`}),(0,$.jsx)(qa,{children:`You have no prompts remaining. Purchase additional prompts to continue.`})]}),t[2]=o):o=t[2];let s;t[3]!==i||t[4]!==r?(s=(0,$.jsxs)(Ci,{children:[o,(0,$.jsx)(na,{children:(0,$.jsx)(Fe,{onClick:()=>{r(),i(`/settings/account`)},children:`Go to Account`})})]}),t[3]=i,t[4]=r,t[5]=s):s=t[5];let c;return t[6]!==n||t[7]!==a||t[8]!==s?(c=(0,$.jsx)(Mi,{open:n,onOpenChange:a,children:s}),t[6]=n,t[7]=a,t[8]=s,t[9]=c):c=t[9],c}var t_=new Set,n_=new Map,r_=5e3;function i_(e){t_.add(e);let t=n_.get(e);t&&clearTimeout(t),n_.set(e,setTimeout(()=>{t_.delete(e),n_.delete(e)},r_))}function a_(e){return t_.has(e)}function o_(e){return e.filter(e=>!t_.has(e))}var s_;(function(e){e.Unimplemented=`UNIMPLEMENTED`,e.Unavailable=`UNAVAILABLE`})(s_||={});var c_=class extends Error{constructor(e,t,n){super(e),this.message=e,this.code=t,this.data=n}},l_=e=>e?.androidBridge?`android`:e?.webkit?.messageHandlers?.bridge?`ios`:`web`,u_=e=>{let t=e.CapacitorCustomPlatform||null,n=e.Capacitor||{},r=n.Plugins=n.Plugins||{},i=()=>t===null?l_(e):t.name,a=()=>i()!==`web`,o=e=>!!(l.get(e)?.platforms.has(i())||s(e)),s=e=>n.PluginHeaders?.find(t=>t.name===e),c=t=>e.console.error(t),l=new Map;return n.convertFileSrc||=e=>e,n.getPlatform=i,n.handleError=c,n.isNativePlatform=a,n.isPluginAvailable=o,n.registerPlugin=(e,a={})=>{let o=l.get(e);if(o)return console.warn(`Capacitor plugin "${e}" already registered. Cannot register plugins twice.`),o.proxy;let c=i(),u=s(e),d,f=async()=>(!d&&c in a?d=d=typeof a[c]==`function`?await a[c]():a[c]:t!==null&&!d&&`web`in a&&(d=d=typeof a.web==`function`?await a.web():a.web),d),p=(t,r)=>{if(u){let i=u?.methods.find(e=>r===e.name);if(i)return i.rtype===`promise`?t=>n.nativePromise(e,r.toString(),t):(t,i)=>n.nativeCallback(e,r.toString(),t,i);if(t)return t[r]?.bind(t)}else if(t)return t[r]?.bind(t);else throw new c_(`"${e}" plugin is not implemented on ${c}`,s_.Unimplemented)},m=t=>{let n,r=(...r)=>{let i=f().then(i=>{let a=p(i,t);if(a){let e=a(...r);return n=e?.remove,e}else throw new c_(`"${e}.${t}()" is not implemented on ${c}`,s_.Unimplemented)});return t===`addListener`&&(i.remove=async()=>n()),i};return r.toString=()=>`${t.toString()}() { [capacitor code] }`,Object.defineProperty(r,"name",{value:t,writable:!1,configurable:!1}),r},h=m(`addListener`),g=m(`removeListener`),_=(e,t)=>{let n=h({eventName:e},t),r=async()=>{g({eventName:e,callbackId:await n},t)},i=new Promise(e=>n.then(()=>e({remove:r})));return i.remove=async()=>{console.warn(`Using addListener() without 'await' is deprecated.`),await r()},i},v=new Proxy({},{get(e,t){switch(t){case`$$typeof`:return;case`toJSON`:return()=>({});case`addListener`:return u?_:h;case`removeListener`:return g;default:return m(t)}}});return r[e]=v,l.set(e,{name:e,proxy:v,platforms:new Set([...Object.keys(a),...u?[c]:[]])}),v},n.Exception=c_,n.DEBUG=!!n.DEBUG,n.isLoggingEnabled=!!n.isLoggingEnabled,n},d_=(e=>e.Capacitor=u_(e))(typeof globalThis<`u`?globalThis:typeof self<`u`?self:typeof window<`u`?window:typeof global<`u`?global:{}),f_=d_.registerPlugin,p_=class{constructor(){this.listeners={},this.retainedEventArguments={},this.windowListeners={}}addListener(e,t){let n=!1;this.listeners[e]||(this.listeners[e]=[],n=!0),this.listeners[e].push(t);let r=this.windowListeners[e];return r&&!r.registered&&this.addWindowListener(r),n&&this.sendRetainedArgumentsForEvent(e),Promise.resolve({remove:async()=>this.removeListener(e,t)})}async removeAllListeners(){this.listeners={};for(let e in this.windowListeners)this.removeWindowListener(this.windowListeners[e]);this.windowListeners={}}notifyListeners(e,t,n){let r=this.listeners[e];if(!r){if(n){let n=this.retainedEventArguments[e];n||=[],n.push(t),this.retainedEventArguments[e]=n}return}r.forEach(e=>e(t))}hasListeners(e){return!!this.listeners[e]?.length}registerWindowListener(e,t){this.windowListeners[t]={registered:!1,windowEventName:e,pluginEventName:t,handler:e=>{this.notifyListeners(t,e)}}}unimplemented(e=`not implemented`){return new d_.Exception(e,s_.Unimplemented)}unavailable(e=`not available`){return new d_.Exception(e,s_.Unavailable)}async removeListener(e,t){let n=this.listeners[e];if(!n)return;let r=n.indexOf(t);this.listeners[e].splice(r,1),this.listeners[e].length||this.removeWindowListener(this.windowListeners[e])}addWindowListener(e){window.addEventListener(e.windowEventName,e.handler),e.registered=!0}removeWindowListener(e){e&&(window.removeEventListener(e.windowEventName,e.handler),e.registered=!1)}sendRetainedArgumentsForEvent(e){let t=this.retainedEventArguments[e];t&&(delete this.retainedEventArguments[e],t.forEach(t=>{this.notifyListeners(e,t)}))}},m_=e=>encodeURIComponent(e).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape),h_=e=>e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent),g_=class extends p_{async getCookies(){let e=document.cookie,t={};return e.split(`;`).forEach(e=>{if(e.length<=0)return;let[n,r]=e.replace(/=/,`CAP_COOKIE`).split(`CAP_COOKIE`);n=h_(n).trim(),r=h_(r).trim(),t[n]=r}),t}async setCookie(e){try{let t=m_(e.key),n=m_(e.value),r=e.expires?`; expires=${e.expires.replace(`expires=`,``)}`:``,i=(e.path||`/`).replace(`path=`,``),a=e.url!=null&&e.url.length>0?`domain=${e.url}`:``;document.cookie=`${t}=${n||``}${r}; path=${i}; ${a};`}catch(e){return Promise.reject(e)}}async deleteCookie(e){try{document.cookie=`${e.key}=; Max-Age=0`}catch(e){return Promise.reject(e)}}async clearCookies(){try{let e=document.cookie.split(`;`)||[];for(let t of e)document.cookie=t.replace(/^ +/,``).replace(/=.*/,`=;expires=${new Date().toUTCString()};path=/`)}catch(e){return Promise.reject(e)}}async clearAllCookies(){try{await this.clearCookies()}catch(e){return Promise.reject(e)}}};f_(`CapacitorCookies`,{web:()=>new g_});var __=async e=>new Promise((t,n)=>{let r=new FileReader;r.onload=()=>{let e=r.result;t(e.indexOf(`,`)>=0?e.split(`,`)[1]:e)},r.onerror=e=>n(e),r.readAsDataURL(e)}),v_=(e={})=>{let t=Object.keys(e);return Object.keys(e).map(e=>e.toLocaleLowerCase()).reduce((n,r,i)=>(n[r]=e[t[i]],n),{})},y_=(e,t=!0)=>e?Object.entries(e).reduce((e,n)=>{let[r,i]=n,a,o;return Array.isArray(i)?(o=``,i.forEach(e=>{a=t?encodeURIComponent(e):e,o+=`${r}=${a}&`}),o.slice(0,-1)):(a=t?encodeURIComponent(i):i,o=`${r}=${a}`),`${e}&${o}`},``).substr(1):null,b_=(e,t={})=>{let n=Object.assign({method:e.method||`GET`,headers:e.headers},t),r=v_(e.headers)[`content-type`]||``;if(typeof e.data==`string`)n.body=e.data;else if(r.includes(`application/x-www-form-urlencoded`)){let t=new URLSearchParams;for(let[n,r]of Object.entries(e.data||{}))t.set(n,r);n.body=t.toString()}else if(r.includes(`multipart/form-data`)||e.data instanceof FormData){let t=new FormData;if(e.data instanceof FormData)e.data.forEach((e,n)=>{t.append(n,e)});else for(let n of Object.keys(e.data))t.append(n,e.data[n]);n.body=t;let r=new Headers(n.headers);r.delete(`content-type`),n.headers=r}else (r.includes(`application/json`)||typeof e.data==`object`)&&(n.body=JSON.stringify(e.data));return n},x_=class extends p_{async request(e){let t=b_(e,e.webFetchExtra),n=y_(e.params,e.shouldEncodeUrlParams),r=n?`${e.url}?${n}`:e.url,i=await fetch(r,t),a=i.headers.get(`content-type`)||``,{responseType:o=`text`}=i.ok?e:{};a.includes(`application/json`)&&(o=`json`);let s,c;switch(o){case`arraybuffer`:case`blob`:c=await i.blob(),s=await __(c);break;case`json`:s=await i.json();break;default:s=await i.text()}let l={};return i.headers.forEach((e,t)=>{l[t]=e}),{data:s,headers:l,status:i.status,url:i.url}}async get(e){return this.request(Object.assign(Object.assign({},e),{method:`GET`}))}async post(e){return this.request(Object.assign(Object.assign({},e),{method:`POST`}))}async put(e){return this.request(Object.assign(Object.assign({},e),{method:`PUT`}))}async patch(e){return this.request(Object.assign(Object.assign({},e),{method:`PATCH`}))}async delete(e){return this.request(Object.assign(Object.assign({},e),{method:`DELETE`}))}};f_(`CapacitorHttp`,{web:()=>new x_});var S_;(function(e){e.Dark=`DARK`,e.Light=`LIGHT`,e.Default=`DEFAULT`})(S_||={});var C_;(function(e){e.StatusBar=`StatusBar`,e.NavigationBar=`NavigationBar`})(C_||={});var w_=class extends p_{async setStyle(){this.unavailable(`not available for web`)}async setAnimation(){this.unavailable(`not available for web`)}async show(){this.unavailable(`not available for web`)}async hide(){this.unavailable(`not available for web`)}};f_(`SystemBars`,{web:()=>new w_});var T_=f_(`KeepAwake`,{web:()=>po(()=>import(`./web-CdkfJJZ3.js`).then(e=>new e.KeepAwakeWeb),[])}),E_=0;function D_(){return typeof window<`u`&&q()}async function O_(){if(D_()&&(E_+=1,!(E_>1)))try{await T_.keepAwake()}catch{E_=0}}async function k_(){if(D_()&&E_!==0&&(--E_,!(E_>0)))try{await T_.allowSleep()}catch{E_=0}}async function A_(){if(E_=0,D_())try{await T_.allowSleep()}catch{}}var j_=Pn(`app.use-chat-handlers.hook`),M_=Pn(`git.checkpoint`);async function N_(e,t,n,r,i,a){let o=await B(t,r);if(t===i.current&&!a?.isStale?.()){if(n!==Ai){e({type:Y.SetPaneMessages,paneId:n,messages:o.messages});return}e({type:Y.SetMessages,messages:o.messages})}}function P_(e,t,n){return{...e,threadId:t,paneId:n}}var F_=/^\/compact(?:\s+(.*))?$/i,I_=`[Compact] Compaction in progress...`;function L_(e,t,n){let r={type:`thinking`,content:I_,model:n};e(P_({type:Y.SetStreaming,isStreaming:!0},t,`primary`)),e(P_({type:Y.SetStreamModel,model:n},t,`primary`)),e(P_({type:Y.AppendStreamChunk,chunkType:`thinking`,content:r.content??``,segments:ka([],`thinking`,r.content??``)},t,`primary`))}var R_=8e3;async function z_(e,t){try{let n=await Promise.race([ye(e,t),new Promise(e=>{setTimeout(()=>e(null),R_)})]);if(n===null){M_.warn(`Checkpoint creation timed out`,{threadId:e,messageId:t});return}if(n.success&&n.checkpointRef)return n.stashed||M_.debug(`Checkpoint recorded with clean working tree`,{threadId:e,messageId:t}),n.checkpointRef;`error`in n&&n.error?M_.warn(`Checkpoint creation failed`,{threadId:e,messageId:t,error:n.error}):n.success||M_.debug(`Checkpoint skipped`,{threadId:e,messageId:t,reason:n.reason})}catch(n){M_.warn(`Checkpoint creation errored`,{threadId:e,messageId:t,error:n instanceof Error?n.message:String(n)})}}var B_=25e3,V_=12e3,H_=`0 0 0.5rem 0.5rem`,U_=3e3,W_=`tarsk-widget-layer`,G_=Pn(`widget.bridge`);function K_(e,t){G_.info(e,t)}function q_(e,t){G_.warn(e,t)}function J_(e,t){G_.error(e,t)}var Y_=new Map,X_=new Map,Z_=new Set,Q_=new Map,$_=null,ev=!1,tv=!1;function nv(e){return e.trim().replace(/\/+$/,``)}function rv(e){try{return new URL(e).origin}catch{return``}}function iv(e){return btoa(e).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)}function av(e){let t=qn().replace(/\/$/,``);try{let n=new URL(e);return`${t}/api/widget/proxy/${iv(n.origin)}${`${n.pathname}${n.search}`}`}catch{return e}}function ov(){return typeof window>`u`?``:window.location.origin}function sv(){return`wreq-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function cv(e){return Y_.get(nv(e))}function lv(e,t){let n=nv(e),r=Q_.get(n);return r||(r=new Set,Q_.set(n,r)),r.add(t),t(),()=>{r.delete(t),r.size===0&&Q_.delete(n)}}function uv(e){let t=Q_.get(e);if(t)for(let e of t)e()}function dv(e,t,n){e.status=t,e.error=n,t===`error`?J_(`Status changed to error for ${e.url}`,n):K_(`Status changed to ${t} for ${e.url}`),uv(nv(e.url))}function fv(){return $_&&document.body.contains($_)?$_:($_=document.createElement(`div`),$_.id=W_,$_.style.position=`fixed`,$_.style.top=`0`,$_.style.left=`0`,$_.style.width=`0`,$_.style.height=`0`,$_.style.zIndex=`20`,$_.style.pointerEvents=`none`,document.body.appendChild($_),$_)}function pv(e,t,n){e.lastVisible!==t&&(e.lastVisible=t,t&&n?K_(`iframe visible for ${e.url} at`,`${Math.round(n.left)},${Math.round(n.top)} ${Math.round(n.width)}x${Math.round(n.height)}`):K_(`Iframe hidden for ${e.url}`,{reason:`no-anchor-or-off-screen`}))}function mv(){for(let e of Y_.values()){let{iframe:t,anchor:n}=e;if(!n||!n.isConnected){t.style.display=`none`,pv(e,!1);continue}let r=n.getBoundingClientRect();if(!(r.bottom>0&&r.top<window.innerHeight&&r.right>0&&r.left<window.innerWidth&&r.width>0&&r.height>0)){t.style.display=`none`,pv(e,!1);continue}t.style.display=`block`,t.style.position=`fixed`,t.style.top=`${r.top}px`,t.style.left=`${r.left}px`,t.style.width=`${r.width}px`,t.style.height=`${r.height}px`,t.style.borderRadius=H_,t.style.overflow=`hidden`,t.style.pointerEvents=`auto`,pv(e,!0,r)}}function hv(){tv&&(mv(),requestAnimationFrame(hv))}function gv(){tv||(tv=!0,requestAnimationFrame(hv))}function _v(){ev||typeof window>`u`||(ev=!0,window.addEventListener(`message`,e=>{let t=e.data,n=yv(e.origin);n&&(n.messagesReceived+=1);{let n=t&&typeof t==`object`?{source:t.source,action:t.action}:typeof t;K_(`raw message from ${e.origin}`,n)}if(Ne(t)){let t=yv(e.origin);if(!t){q_(`Received widgetReady from unknown origin ${e.origin}`);return}K_(`Received widgetReady from ${e.origin}`),bv(t);return}if(!Te(t))return;if(K_(`Received message "${t.action}" from ${e.origin}`,{requestId:t.requestId}),t.action!==An.getToolsResponse&&t.action!==An.callToolResponse){K_(`Ignoring message with unexpected action "${t.action}"`);return}let r=X_.get(t.requestId);if(!r){q_(`Ignoring response with no pending request for requestId ${t.requestId}`);return}let i=Y_.get(r.widgetId);if(i&&i.origin&&e.origin!==i.origin){q_(`Ignoring response due to origin mismatch`,{expectedOrigin:i.origin,actualOrigin:e.origin});return}clearTimeout(r.timeout),X_.delete(t.requestId),r.resolve(t)}),K_(`message listener attached`))}function vv(e){let t=nv(e),n=Y_.get(t);if(n)return n;_v();let r=fv(),i=av(e),a=rv(i)||ov();K_(`mounting widget ${e}`,{proxySrc:i,origin:a,appOrigin:ov(),electrobun:Ln()});let o=document.createElement(`iframe`);o.title=`Widget`,o.setAttribute(`sandbox`,`allow-scripts allow-same-origin allow-forms allow-popups`),o.style.border=`none`,o.style.display=`none`,o.style.background=`transparent`;let s,c={url:e,origin:a,iframe:o,loaded:new Promise(e=>{s=e}),markLoaded:s,hasLoaded:!1,readyReceived:!1,readyResolvers:[],messagesReceived:0,tools:[],status:`loading`,anchor:null};return o.addEventListener(`load`,()=>{c.hasLoaded=!0,K_(`Iframe load fired for ${e}`),s()},{once:!0}),o.addEventListener(`error`,t=>{J_(`Iframe error event for ${e}`,t)}),r.appendChild(o),o.src=i,Y_.set(t,c),gv(),c}function yv(e){if(e){for(let t of Y_.values())if(t.origin===e)return t}}function bv(e){if(e.readyReceived)return;e.readyReceived=!0;let t=e.readyResolvers.splice(0);for(let e of t)e()}function xv(e){return e.readyReceived?Promise.resolve():new Promise(t=>{let n=!1,r,i=()=>{n||(n=!0,clearTimeout(a),r&&clearTimeout(r),e.readyResolvers=e.readyResolvers.filter(e=>e!==i),t())};e.readyResolvers.push(i),e.loaded.then(()=>{n||e.readyReceived||(r=setTimeout(()=>{e.readyReceived||q_(`No widgetReady received within ${U_}ms after load for ${e.url}; proceeding without it because the widget may not implement the readiness beacon.`),i()},U_))});let a=setTimeout(()=>{if(n)return;let t=Ln()?`running in the Electrobun desktop build, which may block embedding external sites in an iframe`:`the site may block embedding (X-Frame-Options / CSP frame-ancestors) or be unreachable`;q_(`no widgetReady within ${V_}ms for ${e.url} — ${t}. Attempting the handshake anyway.`),i()},V_)})}function Sv(e,t){let n=vv(e);n.anchor=t,K_(`Anchor ${t?`set`:`cleared`} for ${e}`),mv()}function Cv(e){let t=nv(e),n=Y_.get(t);if(n){n.anchor=null,n.iframe.remove(),Y_.delete(t),Q_.delete(t);for(let[e,n]of X_.entries())n.widgetId===t&&(clearTimeout(n.timeout),X_.delete(e));K_(`Closed widget ${e}`),Y_.size===0?(tv=!1,$_&&=($_.remove(),null)):mv()}}function wv(e,t,n,r,i=B_){return new Promise((a,o)=>{let s=setTimeout(()=>{X_.delete(r);let n=`iframeLoaded=${e.hasLoaded}, widgetReady=${e.readyReceived}, messagesFromIframe=${e.messagesReceived}`;o(Error(`Widget did not respond to "${t}" within ${i}ms (no ${t}Response received) [${n}]`))},i);X_.set(r,{widgetId:nv(e.url),resolve:a,reject:o,timeout:s});let c=e.iframe.contentWindow;if(!c){clearTimeout(s),X_.delete(r),o(Error(`Widget iframe has no content window`));return}K_(`Posting message "${t}"`,{requestId:r,targetOrigin:e.origin||`*`,iframeSrc:e.iframe.getAttribute(`src`),readyReceived:e.readyReceived,hasLoaded:e.hasLoaded}),c.postMessage(n,e.origin||`*`)})}async function Tv(e,t){if(Z_.has(e)){K_(`Skipping duplicate discoverWidgetTools call`,{toolCallId:e});return}Z_.add(e),K_(`Starting widget tool discovery`,{toolCallId:e,url:t});let n=vv(t);try{await xv(n),dv(n,`discovering`);let r,i;for(let e=1;e<=3;e++){let a=sv();try{r=await wv(n,An.getTools,{source:be,requestId:a,action:An.getTools,options:{fromOrigins:[ov()]}},a,7e3);break}catch(n){i=n,q_(`getTools attempt ${e}/3 failed for ${t}`,n)}}if(!r)throw i instanceof Error?i:Error(String(i));let a=Array.isArray(r.tools)?r.tools:[];K_(`discovered ${a.length} tool(s) for ${t}:`,a.map(e=>e.name)),n.tools=a,dv(n,`ready`),await mr(e,{tools:a})}catch(t){let r=t instanceof Error?t.message:String(t);dv(n,`error`,r);try{await mr(e,{error:r})}catch(e){J_(`Failed to submit discovery error`,e)}}}async function Ev(e,t,n,r){if(Z_.has(e)){K_(`Skipping duplicate callWidgetTool call`,{toolCallId:e});return}Z_.add(e),K_(`Starting widget tool call`,{toolCallId:e,url:t,tool:n,input:r});let i=vv(t);try{await xv(i);let t=sv(),a=await wv(i,An.callTool,{source:be,requestId:t,action:An.callTool,name:n,arguments:r},t);if(a.error||a.isError){let t=a.error??Dv(a.result)??`Widget tool failed`;q_(`Widget tool "${n}" returned error`,t),await mr(e,{error:t});return}K_(`Widget tool "${n}" succeeded`),await mr(e,{result:a.result})}catch(t){let r=t instanceof Error?t.message:String(t);J_(`Widget tool "${n}" failed`,r);try{await mr(e,{error:r})}catch(e){J_(`Failed to submit widget call error`,e)}}}function Dv(e){if(e&&typeof e==`object`&&`content`in e){let t=e.content;if(Array.isArray(t)){let e=t.find(e=>e?.type===`text`&&typeof e.text==`string`);if(e?.text)return e.text}}return null}var Ov=`tarsk-browser-tool-request`,kv=`tarsk-ask-user-prompt`,Av=new Set,jv=new Set;function Mv(e){Ln()&&window.dispatchEvent(new CustomEvent(Ov,{detail:e}))}function Nv(e,t,n){!Ln()||Av.has(e)||t.action&&(Av.add(e),Mv({toolCallId:e,input:t,threadId:n}))}function Pv(e,t){jv.has(e)||(jv.add(e),window.dispatchEvent(new CustomEvent(kv,{detail:{toolCallId:e,threadId:t}})))}function Fv(){return Ln()?`views://public/browser-preview-rpc.js`:`${qn()}/browser-preview-rpc.js`}async function Iv(e,t){await A(e,t)}async function Lv(e,t){await je(e,t)}function Rv(e,t){if(!(!t||!e.includes(`"run_js"`)))try{let n=JSON.parse(e.trim());if(!Array.isArray(n))return;for(let e of n)e?.type===`tool_use`&&e?.name===`run_js`&&e?.id&&e?.input?.code&&Nd(e.id,e.input.code,t)}catch{}}function zv(e,t){if(e.includes(`"browser"`))try{let n=JSON.parse(e.trim());if(!Array.isArray(n))return;for(let e of n)e?.type===`tool_use`&&e?.name===`browser`&&e?.id&&e?.input&&Nv(e.id,e.input,t)}catch{}}function Bv(e,t){if(!(!e.includes(`"open_widget"`)&&!e.includes(`"call_widget_tool"`)))try{let n=JSON.parse(e.trim());if(!Array.isArray(n))return;for(let e of n)if(!(e?.type!==`tool_use`||!e?.id)){if(e.name===`open_widget`&&typeof e.input?.url==`string`)t({type:Y.AddOpenWidget,widget:{id:e.id,url:e.input.url,title:typeof e.input.title==`string`?e.input.title:void 0}}),Tv(e.id,e.input.url);else if(e.name===`call_widget_tool`&&typeof e.input?.url==`string`&&typeof e.input?.tool==`string`){let t=e.input.input&&typeof e.input.input==`object`?e.input.input:{};Ev(e.id,e.input.url,e.input.tool,t)}}}catch{}}function Vv(e,t){if(e.includes(`"ask_user"`))try{let n=JSON.parse(e.trim());if(!Array.isArray(n))return;for(let e of n)e?.type===`tool_use`&&e?.name===`ask_user`&&e?.id&&Pv(e.id,t)}catch{}}function Hv(e){if(!(!e.includes(`"tool_use"`)||!e.includes(`"bash"`)))try{let t=JSON.parse(e.trim());if(!Array.isArray(t))return;for(let e of t)e?.type===`tool_use`&&e?.id&&typeof e.name==`string`&&e.name.toLowerCase()===`bash`&&typeof e.input?.command==`string`&&El(e.id,e.input.command)}catch{}}function Uv(e){if(!(!e.includes(`"tool-result"`)||!e.includes(`"bash"`)))try{let t=JSON.parse(e.trim());if(!Array.isArray(t))return;for(let e of t)e?.type===`tool-result`&&e?.toolCallId&&typeof e.toolName==`string`&&e.toolName.toLowerCase()===`bash`&&Dl(e.toolCallId)}catch{}}function Wv(e){let{dispatch:t,streamSessionsRef:n,connectThreadStreamRef:r,selectedThreadIdRef:i}=e;function a(e,o,s){let c=ja(e,s.paneId);if(s.pendingTransientRecovery){s.pendingTransientRecovery=!1,(async()=>{try{if((await yr()).includes(e)){r.current?.(e,t=>Ht(e,t),o,s.paneId,s.conversationId);return}}catch(e){j_.error(`Failed to recover chat stream after disconnect:`,e)}a(e,o,s)})();return}if(n.current.get(c)!==s){n.current.has(c)||(i_(e),t(P_({type:Y.ResetStream},e,s.paneId)),t({type:Y.RemoveProcessingThread,threadId:e}));return}if(n.current.delete(c),t({type:Y.ClearToolCallProgress}),s.keepsDeviceAwake&&(s.keepsDeviceAwake=!1,k_()),s.stopHandled)return;if(i_(e),s.error){let n={messageId:`msg-${Date.now()}-error`,sender:`agent`,content:`Error: ${s.error}`,contentType:`text`,timestamp:new Date().toISOString(),model:o||`default`,isThinking:!1};t({type:Y.AddMessage,message:n,threadId:e,paneId:s.paneId}),t(P_({type:Y.ResetStream},e,s.paneId)),t({type:Y.RemoveProcessingThread,threadId:e});return}let l=co(s.segments)||`...`,u={messageId:`msg-${Date.now()}-agent`,sender:`agent`,content:l,contentType:`markdown`,timestamp:new Date().toISOString(),model:o||`default`,isThinking:!1};async function d(){let r=!1;for(let a=0;a<4;a++){if(a>0&&await new Promise(e=>setTimeout(e,150*a)),n.current.has(c))return;try{if(await N_(t,e,s.paneId,s.conversationId,i,{isStale:()=>n.current.has(c)}),n.current.has(c))return;r=!0;break}catch(e){j_.error(`Failed to reload chat history after stream:`,e);break}}n.current.has(c)||(r||t({type:Y.AddMessage,message:u,threadId:e,paneId:s.paneId}),t(P_({type:Y.ResetStream},e,s.paneId)),t({type:Y.SetActiveStreamPane,paneId:null}),t({type:Y.MarkThreadCompleted,threadId:e}),t({type:Y.RemoveProcessingThread,threadId:e}))}d()}return a}function Gv(e){let{dispatch:t,streamSessionsRef:n,selectedThreadIdRef:r,setError:i,setShowEmptyBalanceDialog:a,finalizeThreadStream:o}=e;function s(e,s,c,l,u){let d=ja(e,l),f=n.current.get(d);f&&(f.controller.abort(),f.cancel?.());let p=new AbortController,m={controller:p,cancel:null,segments:[],assistantMessage:``,assistantThinking:``,hasStructuredContent:!1,error:null,stopHandled:!1,pendingTransientRecovery:!1,activeSubagentToolCallId:null,paneId:l,conversationId:u,keepsDeviceAwake:!1};return n.current.set(d,m),t(P_({type:Y.ResetStream},e,l)),t({type:Y.AddProcessingThread,threadId:e}),t(P_({type:Y.SetStreaming,isStreaming:!0},e,l)),t({type:Y.SetActiveStreamPane,paneId:l}),O_().then(()=>{m.keepsDeviceAwake=!0}),s(p.signal).then(n=>{if(!n||p.signal.aborted){o(e,c,m);return}m.cancel=St(n,n=>{if(t(P_({type:Y.IncrementStreamEventCount},e,l)),n.type===`error`){let t=Vr(n.content?.trim()||n.error?.message?.trim()||n.message?.trim()||`Unknown error occurred`);m.error=t,e===r.current&&i(t);return}if(n.type!==`message`){if(n.type===`auto_compact`){let r=n.messagesBefore,i=n.content?.trim()||(typeof r==`number`?`Auto-compacted conversation (${r} → 1)`:`Auto-compacted conversation`);m.segments=ka(m.segments,`thinking`,`[Auto-compacted] ${i}\n`),t(P_({type:Y.AppendStreamChunk,chunkType:`thinking`,content:i,segments:m.segments},e,l));return}if(n.type===`long_running_confirmation`){let r=n.prompt;if(!r)return;m.segments=da(m.segments,r),t(P_({type:Y.AppendStreamChunk,chunkType:`content`,content:``,segments:m.segments},e,l));return}if(n.type===`shell_permission`){let r=n.shellPermission;if(!r)return;m.activeSubagentToolCallId&&t({type:Y.AppendToolExecutionOutput,toolCallId:m.activeSubagentToolCallId,toolName:`agent`,delta:`\n⏳ Waiting for shell approval: ${r.command}\n`}),m.segments=fo(m.segments,r),t(P_({type:Y.AppendStreamChunk,chunkType:`content`,content:``,segments:m.segments},e,l));return}if(n.type===`web_fetch_permission`){let r=n.webFetchPermission;if(!r)return;m.activeSubagentToolCallId&&t({type:Y.AppendToolExecutionOutput,toolCallId:m.activeSubagentToolCallId,toolName:`agent`,delta:`\n⏳ Waiting for approval to fetch ${r.hostname}\n`}),m.segments=ro(m.segments,r),t(P_({type:Y.AppendStreamChunk,chunkType:`content`,content:``,segments:m.segments},e,l));return}if(n.type===`toolcall_delta`){n.partial?.content?.[0]?.id&&n.delta&&t({type:Y.UpdateToolCallProgress,toolCallId:n.partial.content[0].id,progress:{toolCallId:n.partial.content[0].id,toolName:n.partial.content[0].name,delta:n.delta,partial:n.partial}});return}if(n.type===`tool_execution_update`){n.toolCallId&&n.executionOutput!==void 0&&t({type:Y.UpdateToolExecutionOutput,toolCallId:n.toolCallId,toolName:n.toolName,executionOutput:n.executionOutput});return}if(n.type===`subagent_start`){if(n.toolCallId){m.activeSubagentToolCallId=n.toolCallId;let e=n.subagentName?.trim()||`subagent`;t({type:Y.UpdateToolExecutionOutput,toolCallId:n.toolCallId,toolName:`agent`,executionOutput:`Running ${e}…\n`})}return}if(n.type===`subagent_event`){if(n.toolCallId){n.subagentEvent&&t({type:Y.AppendSubagentEvent,toolCallId:n.toolCallId,event:n.subagentEvent});let e=gu(n);e&&t({type:Y.AppendToolExecutionOutput,toolCallId:n.toolCallId,toolName:`agent`,delta:e})}return}if(n.type===`subagent_complete`){n.toolCallId&&(m.activeSubagentToolCallId=null,n.subagentResult&&t({type:Y.UpdateToolExecutionOutput,toolCallId:n.toolCallId,toolName:`agent`,executionOutput:n.subagentResult}));return}if(n.type===`context_usage`){n.contextUsage&&t(P_({type:Y.SetContextUsage,contextUsage:n.contextUsage},e,l));return}if(n.model&&t(P_({type:Y.SetStreamModel,model:n.model},e,l)),n.type===`thinking`||n.isThinking){let r=n.content??``;Rv(r,e),zv(r,e),Vv(r,e),Bv(r,t),m.assistantThinking+=r,m.segments=ka(m.segments,`thinking`,r),t(P_({type:Y.AppendStreamChunk,chunkType:`thinking`,content:r,segments:m.segments},e,l))}else if(n.type===`result`){m.hasStructuredContent=!0;let r=n.content??``;m.assistantMessage=r,m.segments=za(m.segments,r),t(P_({type:Y.SetStreamContent,content:r},e,l)),typeof r==`string`&&(Rv(r,e),zv(r,e),Vv(r,e),Bv(r,t))}else{if(m.hasStructuredContent)return;let r=n.content??``;m.assistantMessage+=r,m.segments=ka(m.segments,`content`,r),t(P_({type:Y.AppendStreamChunk,chunkType:`content`,content:r,segments:m.segments},e,l))}}},()=>{o(e,c,m)},t=>{if(t.includes(`AbortError`)||t.includes(`canceled`)||t.includes(`BodyStreamBuffer was aborted`)){o(e,c,m);return}if(gt(t)){m.pendingTransientRecovery=!0;return}m.error=t,e===r.current&&i(t)},n=>{if(t(P_({type:Y.IncrementStreamEventCount},e,l)),n.role===`assistant`){let r=n.content??``,i=typeof r==`string`?r:JSON.stringify(r);if(n.isThinking??!1){m.assistantThinking+=i,m.segments=ka(m.segments,`thinking`,i),t(P_({type:Y.AppendStreamChunk,chunkType:`thinking`,content:i,segments:m.segments},e,l));return}let a=!1;if(typeof r==`object`&&Array.isArray(r)&&r.length>0)a=!0;else if(typeof i==`string`&&i.trim().startsWith(`[`))try{let e=JSON.parse(i);a=Array.isArray(e)&&e.length>0}catch{}a?(m.hasStructuredContent=!0,m.assistantMessage=i,m.segments=za(m.segments,i),t(P_({type:Y.SetStreamContent,content:i},e,l)),Rv(i,e),zv(i,e),Vv(i,e),Bv(i,t)):(m.assistantMessage+=i,m.segments=ka(m.segments,`content`,i),t(P_({type:Y.AppendStreamChunk,chunkType:`content`,content:i,segments:m.segments},e,l)))}else if(n.role===`tool`){let r=n.content??``,i=typeof r==`string`?r:JSON.stringify(r);i&&(Hv(i),Uv(i),Xi(i)?(m.hasStructuredContent=!0,m.segments=Si(m.segments,i),m.assistantMessage=Da(m.segments),t(P_({type:Y.SetStreamContent,content:m.assistantMessage},e,l))):i.trim().startsWith(`[`)||(m.assistantMessage+=i,m.segments=ka(m.segments,`content`,i),t(P_({type:Y.AppendStreamChunk,chunkType:`content`,content:i,segments:m.segments},e,l))))}})}).catch(s=>{if(s instanceof Error&&s.name===`AbortError`){n.current.delete(d),t(P_({type:Y.ResetStream},e,l)),t({type:Y.RemoveProcessingThread,threadId:e});return}if(s instanceof bt){n.current.delete(d),t(P_({type:Y.ResetStream},e,l)),t({type:Y.RemoveProcessingThread,threadId:e}),a(!0);return}if(s instanceof Error&&s.message.includes(`not currently processing`)){n.current.delete(d),t(P_({type:Y.ResetStream},e,l)),t({type:Y.RemoveProcessingThread,threadId:e});return}if(s instanceof Error&>(s.message)){m.pendingTransientRecovery=!0,o(e,c,m);return}n.current.delete(d);let u=s instanceof Error?s.message:`Failed to send message. Please ensure the CLI server is running on localhost:641`;e===r.current&&i(u),j_.error(`Failed to subscribe to chat stream:`,s),t(P_({type:Y.ResetStream},e,l)),t({type:Y.RemoveProcessingThread,threadId:e})}),p}return s}function Kv(e){return e.trim().replace(/\n/g,` `).slice(0,100)}function qv(e,t,n,r,i,a){i&&(Dt(n,{chatTitles:{...a,[r]:i}}).catch(e=>{j_.error(`Failed to update chat title:`,e)}),e({type:Y.UpdateChatTitle,projectId:t,threadId:n,paneId:r,title:i}))}function Jv(e){let{selectedThreadId:t,selectedProjectId:n,processingThreadIds:r,dispatch:i,toast:a,connectThreadStream:o,onPlanModeConsumed:s,setError:c,setStopRequestedForThreadId:l,getPaneMessages:u,isPaneStreaming:d,getChatTitles:f}=e;return(0,Z.useCallback)(async(e,p,m,h,g,_,v,y,b,x)=>{if(!t)return;let S=t,C=u(e);c(null),l(null);let w=m.trim().match(F_);if(w){if(e!==`primary`)return;if(C.filter(e=>e.sender===`agent`).length<2){a({title:`Nothing to compact`,description:`Start a conversation with at least two exchanges first.`});return}if(r.includes(S)||d(S,e)){a({title:`Agent is busy`,description:`Wait for the agent to finish before compacting.`});return}let t=w[1]?.trim();L_(i,S,h);try{let n=await gr(S,{model:h,provider:_,instructions:t});i({type:Y.SetMessages,messages:n.messages}),i(P_({type:Y.ResetStream},S,e)),a({title:`Conversation compacted`,description:`${n.messagesBefore} messages → ${n.messagesAfter} summary`})}catch(t){i(P_({type:Y.ResetStream},S,e)),a({title:`Compaction failed`,description:t instanceof Error?t.message:`Failed to compact conversation`,variant:`destructive`})}return}let T=`msg-${Date.now()}`,E={messageId:T,sender:`user`,content:m,contentType:`text`,timestamp:new Date().toISOString(),model:h,attachments:g.map(e=>({fileName:e.fileName,content:e.content,mimeType:e.mimeType}))};i({type:Y.AddMessage,message:E,threadId:S,paneId:e});let D=await z_(S,T);if(D&&i({type:Y.UpdateMessageCheckpointRef,messageId:T,threadId:S,paneId:e,checkpointRef:D}),n){let t=Kv(m);qv(i,n,S,e,t,f(S)),ie(S,m,{provider:_,model:h}).then(r=>{r&&r!==t&&qv(i,n,S,e,r,f(S))}).catch(e=>{j_.error(`Failed to generate chat title:`,e)})}if(y){let t=_??void 0;if(!t&&typeof h==`string`){let e=h.split(/[:/]/)[0]?.trim();e&&(t=e)}if(!t){let t={messageId:`msg-${Date.now()}-error`,sender:`agent`,content:`Image generation is not available because no provider is configured for the selected model.`,contentType:`text`,timestamp:new Date().toISOString(),model:h,isThinking:!1};i({type:Y.AddMessage,message:t,threadId:S,paneId:e}),i(P_({type:Y.ResetStream},S,e)),i({type:Y.SetActiveStreamPane,paneId:null});return}i(P_({type:Y.SetStreaming,isStreaming:!0},S,e)),i({type:Y.SetActiveStreamPane,paneId:e});try{let n=await M(m,h,t,S),r={messageId:`msg-${Date.now()}-agent`,sender:`agent`,content:m,contentType:`text`,timestamp:new Date().toISOString(),model:h,mode:`image`,isThinking:!1,generatedImageUrl:n.imageUrl,generatedImageData:n.imageData};i({type:Y.AddMessage,message:r,threadId:S,paneId:e})}catch(t){let n=t instanceof Error?t.message:`Image generation failed`,r={messageId:`msg-${Date.now()}-error`,sender:`agent`,content:`Error: ${n}`,contentType:`text`,timestamp:new Date().toISOString(),model:h,isThinking:!1};i({type:Y.AddMessage,message:r,threadId:S,paneId:e})}finally{i(P_({type:Y.ResetStream},S,e)),i({type:Y.SetActiveStreamPane,paneId:null})}return}o(S,e=>mt(S,m,h,g,e,_,v,b,D,p,x),h,e,p),i(P_({type:Y.SetStreamAgentMode,mode:Ge({planMode:v,ralphMode:b,orchestrateMode:x})},S,e)),v&&s?.()},[t,n,i,o,r,a,s,u,d,f,c,l])}function Yv(e){let t=Gi(),{toast:n}=Ki(),i=Ca(),[a,o]=(0,Z.useState)(null),[s,c]=(0,Z.useState)(!1),[l,u]=(0,Z.useState)(null),d=(0,Z.useRef)(null),f=(0,Z.useRef)(new Map),p=(0,Z.useRef)(null),m=(0,Z.useRef)({}),h=X(e=>e.selectedThreadId),g=X(e=>e.selectedProjectId),_=X(e=>e.queuedChatMessages),v=X(e=>e.pendingChatMessage),y=X(e=>e.processingThreadIds);d.current=h;function b(e){return Wa(i.getState(),e)}function x(e){return to(i.getState(),e)}function S(e,t){return _o(i.getState().threadStreamingStates,e,t).isStreaming}function C(e,t){return _o(i.getState().threadStreamingStates,e,t).streamingModel||`default`}function w(e){let t=i.getState();for(let n of t.projects){let t=n.threads.find(t=>t.threadId===e);if(t)return t.chatTitles}}let T=(0,Z.useCallback)(e=>h?_.filter(t=>t.threadId===h&&t.paneId===e):[],[_,h]),E=(0,Z.useCallback)(Wv({dispatch:t,streamSessionsRef:f,connectThreadStreamRef:p,selectedThreadIdRef:d}),[t]),D=(0,Z.useCallback)(e=>{if(!h)return;u(h);let n=ja(h,e),i=f.current.get(n);i&&(i.stopHandled=!0,i.controller.abort(),i.cancel?.(),f.current.delete(n),i.keepsDeviceAwake&&(i.keepsDeviceAwake=!1,k_())),r(h);let a={messageId:`msg-${Date.now()}-stopped`,sender:`agent`,content:`I've stopped working on your request.`,contentType:`text`,timestamp:new Date().toISOString(),model:C(h,e),isThinking:!1};t({type:Y.AddMessage,message:a,threadId:h,paneId:e}),t({type:Y.ClearToolCallProgress}),t(P_({type:Y.ResetStream},h,e)),t({type:Y.SetActiveStreamPane,paneId:null}),t({type:Y.MarkThreadCompleted,threadId:h}),t({type:Y.RemoveProcessingThread,threadId:h}),i_(h)},[h,t,i]);(0,Z.useEffect)(()=>()=>{for(let[e,n]of f.current.entries()){n.controller.abort(),n.cancel?.(),n.keepsDeviceAwake&&(n.keepsDeviceAwake=!1,k_());let[r,i]=e.split(`:`);t(P_({type:Y.ResetStream},r,i))}f.current.clear()},[t]);let O=(0,Z.useCallback)(Gv({dispatch:t,streamSessionsRef:f,selectedThreadIdRef:d,setError:o,setShowEmptyBalanceDialog:c,finalizeThreadStream:E}),[t,E]);p.current=O,(0,Z.useEffect)(()=>{for(let e of y)a_(e)||i.getState().threadToolSessions[e]?.kind!==`create`&&(Pa(e,{hasSession:t=>f.current.has(ja(e,t)),streamingStates:i.getState().threadStreamingStates,sessionPaneIds:[...f.current.keys()].filter(t=>t.startsWith(`${e}:`)).map(t=>t.slice(e.length+1))})||O(e,t=>Ht(e,t),`default`,`primary`))},[O,y,i]);let k=Jv({selectedThreadId:h,selectedProjectId:g,processingThreadIds:y,dispatch:t,toast:n,connectThreadStream:O,onPlanModeConsumed:e,setError:o,setStopRequestedForThreadId:u,getPaneMessages:b,isPaneStreaming:S,getChatTitles:w});return(0,Z.useEffect)(()=>{let e=v;if(!e||e.threadId!==h||S(h??``,`primary`))return;let n=setTimeout(()=>{t({type:Y.ClearPendingChatMessage}),k(`primary`,void 0,e.message,e.model,[],e.provider)},100);return()=>clearTimeout(n)},[v,h,t,k,i]),(0,Z.useEffect)(()=>{if(!h)return;let e={},n=new Set([`primary`,...ao(i.getState()),..._.filter(e=>e.threadId===h).map(e=>e.paneId)]);for(let r of n){let n=T(r);if(n.length===0||S(h,r)||m.current[r])continue;let[i]=n;m.current[r]=!0,e[r]=setTimeout(()=>{m.current[r]=!1,t({type:Y.RemoveQueuedChatMessage,queuedMessageId:i.id}),k(r,x(r),i.message,i.model,i.attachments,i.provider,i.planMode,i.imageMode,i.ralphMode,i.orchestrateMode)},0)}return()=>{for(let t of n){let n=e[t];n&&clearTimeout(n)}}},[t,T,k,_,h,i]),{error:a,setError:o,handleSend:k,handleStop:D,getQueuedMessagesForPane:T,handleRemoveQueuedMessage:(0,Z.useCallback)((e,n)=>{let r=T(e).find(e=>e.id===n);t({type:Y.RemoveQueuedChatMessage,queuedMessageId:n}),!(!r||S(h??``,e)||b(e).length>0||!h)&&k(e,x(e),r.message,r.model,r.attachments,r.provider,r.planMode,r.imageMode,r.ralphMode,r.orchestrateMode)},[t,T,k,h,i]),showEmptyBalanceDialog:s,setShowEmptyBalanceDialog:c}}var Xv=(0,Z.createContext)(void 0);function Zv(e){let t=(0,Q.c)(3),{children:n}=e,r=Yv(),i;return t[0]!==n||t[1]!==r?(i=(0,$.jsx)(Xv.Provider,{value:r,children:n}),t[0]=n,t[1]=r,t[2]=i):i=t[2],i}function Qv(){let e=(0,Z.useContext)(Xv);if(e===void 0)throw Error(`useChatHandlersContext must be used within a ChatHandlersProvider`);return e}function $v(e){let t=(0,Q.c)(4),{messages:n}=e,r;t[0]===n?r=t[1]:(r=n===void 0?[]:n,t[0]=n,t[1]=r);let i=r,a;return t[2]===i?a=t[3]:(a=(0,$.jsx)(ey,{messages:i}),t[2]=i,t[3]=a),a}function ey(e){let t=(0,Q.c)(64),{messages:n}=e,{paneId:r,conversationId:i,fillPane:a}=If(),o=eh(),s=o?.placement===`footer`&&!o.embedded,c=o?.embedded??!1,l=X(iy),u=X(ry),d=X(ny),[f,p]=Z.useState(!1),{handleSend:m,handleStop:h,getQueuedMessagesForPane:g,handleRemoveQueuedMessage:_,showEmptyBalanceDialog:v,setShowEmptyBalanceDialog:y}=Qv(),{userTasks:b,setUserTasks:x,handleNewChat:S,handleSelectUserTask:C,handleRemoveUserTask:w,toggleUserTaskPinned:T,effectiveIsStreaming:E}=Rh(),[D,O]=(0,Z.useState)(ty),k=Qg(n),A;t[0]!==D||t[1]!==k?(A=k&&!D.has(k.toolCallId)?k:null,t[0]=D,t[1]=k,t[2]=A):A=t[2];let j=A,M;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(M=e=>{O(t=>{let n=new Set(t);return n.add(e),n})},t[3]=M):M=t[3];let N=M,P;t[4]!==i||t[5]!==m||t[6]!==r?(P=(e,t,n,a,o,s,c,l)=>m(r,i,e,t,n,a,o,s,c,l),t[4]=i,t[5]=m,t[6]=r,t[7]=P):P=t[7];let F=P,I;t[8]!==h||t[9]!==r?(I=()=>{h(r)},t[8]=h,t[9]=r,t[10]=I):I=t[10];let L=I,R;t[11]!==j||t[12]!==L?(R=()=>{L(),j&&N(j.toolCallId)},t[11]=j,t[12]=L,t[13]=R):R=t[13];let z=R,B;t[14]!==_||t[15]!==r?(B=e=>{_(r,e)},t[14]=_,t[15]=r,t[16]=B):B=t[16];let ee=B,te=r===`primary`&&u&&(d||n.length>0||b.length>0),ne=r!==`primary`&&u&&n.length>0,re;t[17]===y?re=t[18]:(re=()=>y(!1),t[17]=y,t[18]=re);let ie;t[19]!==v||t[20]!==re?(ie=(0,$.jsx)(e_,{open:v,onClose:re}),t[19]=v,t[20]=re,t[21]=ie):ie=t[21];let ae;t[22]===a?ae=t[23]:(ae=kf(a),t[22]=a,t[23]=ae);let oe;t[24]!==E||t[25]!==S||t[26]!==w||t[27]!==C||t[28]!==l||t[29]!==n||t[30]!==r||t[31]!==d||t[32]!==u||t[33]!==ne||t[34]!==te||t[35]!==T||t[36]!==b?(oe=(te||ne)&&(0,$.jsx)(`div`,{className:`max-md:hidden`,children:(0,$.jsx)(Bg,{threadId:u,projectId:d??``,messages:n,userTasks:r===`primary`?b:[],effectiveIsStreaming:E,isCreatingProject:l,mode:r===`primary`?`full`:`newChatOnly`,onNewChat:()=>{S()},onSelectUserTask:C,onToggleUserTaskPinned:T,onRemoveUserTask:e=>{w(e)}})}),t[24]=E,t[25]=S,t[26]=w,t[27]=C,t[28]=l,t[29]=n,t[30]=r,t[31]=d,t[32]=u,t[33]=ne,t[34]=te,t[35]=T,t[36]=b,t[37]=oe):oe=t[37];let se;t[38]!==j||t[39]!==s||t[40]!==E||t[41]!==c||t[42]!==g||t[43]!==z||t[44]!==w||t[45]!==l||t[46]!==ee||t[47]!==F||t[48]!==L||t[49]!==r||t[50]!==f||t[51]!==u||t[52]!==x||t[53]!==b?(se=j?(0,$.jsx)(ch,{toolCallId:j.toolCallId,question:j.question,options:j.options,context:j.context,onAnswered:N,onStop:z}):(0,$.jsx)(Um,{planMode:f,setPlanMode:p,onSend:F,onStop:L,isStreaming:E,disabled:!u&&!l,initialValue:``,queuedMessages:g(r),onRemoveQueuedMessage:ee,isOverlay:!1,centered:s,embedded:c,userTasks:b,onMatchedUserTaskSend:e=>{e.pinned||w(e.id)},onUserTaskCreated:e=>{x(t=>[...t,e])}}),t[38]=j,t[39]=s,t[40]=E,t[41]=c,t[42]=g,t[43]=z,t[44]=w,t[45]=l,t[46]=ee,t[47]=F,t[48]=L,t[49]=r,t[50]=f,t[51]=u,t[52]=x,t[53]=b,t[54]=se):se=t[54];let ce;t[55]!==oe||t[56]!==se?(ce=(0,$.jsxs)(`div`,{className:`relative`,children:[oe,se]}),t[55]=oe,t[56]=se,t[57]=ce):ce=t[57];let le;t[58]!==ce||t[59]!==ae?(le=(0,$.jsx)(`div`,{className:ae,children:ce}),t[58]=ce,t[59]=ae,t[60]=le):le=t[60];let ue;return t[61]!==le||t[62]!==ie?(ue=(0,$.jsxs)($.Fragment,{children:[ie,le]}),t[61]=le,t[62]=ie,t[63]=ue):ue=t[63],ue}function ty(){return new Set}function ny(e){return e.selectedProjectId}function ry(e){return e.selectedThreadId}function iy(e){return e.isCreatingProject}function ay(e){let t=e?.querySelector(Tf);return t?t.getBoundingClientRect().top:null}function oy(e,t,n){let r=(0,Q.c)(5),i,a;r[0]!==n||r[1]!==t||r[2]!==e?(i=()=>{let r=e.current;if(!n||!r)return;let i=function(){t.current=ay(r)};i();let a=new ResizeObserver(i);return a.observe(r),window.addEventListener(`resize`,i),()=>{a.disconnect(),window.removeEventListener(`resize`,i)}},a=[n,t,e],r[0]=n,r[1]=t,r[2]=e,r[3]=i,r[4]=a):(i=r[3],a=r[4]),(0,Z.useEffect)(i,a)}function sy(e,t,n){let r=(0,Q.c)(5),i,a;r[0]!==n||r[1]!==t||r[2]!==e?(i=()=>{let r=e.current,i=t.current;if(!n||!r||i===null)return;t.current=null;let a=ay(r);if(a===null||Math.abs(i-a)<1||window.matchMedia(`(prefers-reduced-motion: reduce)`).matches)return;let o=r.animate([{transform:`translateY(${i-a}px)`},{transform:`translateY(0px)`}],{duration:300,easing:Cf});return()=>o.cancel()},a=[n,t,e],r[0]=n,r[1]=t,r[2]=e,r[3]=i,r[4]=a):(i=r[3],a=r[4]),(0,Z.useLayoutEffect)(i,a)}var cy;(function(e){e.Dark=`DARK`,e.Light=`LIGHT`,e.Default=`DEFAULT`})(cy||={});var ly;(function(e){e.Body=`body`,e.Ionic=`ionic`,e.Native=`native`,e.None=`none`})(ly||={});var uy=f_(`Keyboard`);function dy(e){let t=window.visualViewport;if(!e||!t)return 0;let n=t.height+t.offsetTop,r=e.getBoundingClientRect().bottom;return Math.max(0,Math.round(r-n))}function fy(e,t){return Un()?t:e>0?e:t}function py(e,t){let n=(0,Q.c)(6),[r,i]=(0,Z.useState)(0),[a,o]=(0,Z.useState)(0),s=t?.onlyWhenOverlapping??!1,c,l;if(n[0]===e?(c=n[1],l=n[2]):(c=()=>{let t=function(){i(dy(e.current))},n=function(){t(),requestAnimationFrame(t)};n();let r=window.visualViewport;r?.addEventListener(`resize`,n),r?.addEventListener(`scroll`,n),window.addEventListener(`resize`,n);let a=[];return q()&&a.push(uy.addListener(`keyboardWillShow`,e=>{o(e.keyboardHeight)}),uy.addListener(`keyboardDidShow`,e=>{o(e.keyboardHeight)}),uy.addListener(`keyboardWillHide`,()=>{o(0)}),uy.addListener(`keyboardDidHide`,()=>{o(0)})),()=>{r?.removeEventListener(`resize`,n),r?.removeEventListener(`scroll`,n),window.removeEventListener(`resize`,n);for(let e of a)e.then(my)}},l=[e],n[0]=e,n[1]=c,n[2]=l),(0,Z.useEffect)(c,l),s&&r<=0)return 0;let u;return n[3]!==r||n[4]!==a?(u=fy(r,a),n[3]=r,n[4]=a,n[5]=u):u=n[5],u}function my(e){e.remove()}function hy(e){let t=(0,Q.c)(53),{paneId:n,inline:r}=e,i=r===void 0?!1:r,a=X(_y),o=X(gy),s=n??o,c;t[0]===s?c=t[1]:(c=e=>to(e,s),t[0]=s,t[1]=c);let l=X(c),u;t[2]===s?u=t[3]:(u=e=>Wa(e,s),t[2]=s,t[3]=u);let d=X(u),f=eh(),p=th(),m=nh()?wf:void 0,h=f?.overlayRef,g=(0,Z.useRef)(null),_=(0,Z.useRef)(null),v=f?.placement??`overlay`,y=f?.embedded??!1,b=y?g:h,x=b??g,S=f?.centeredComposerTopRef??_,C;t[4]===b?C=t[5]:(C=b??{current:null},t[4]=b,t[5]=C);let w=py(C);if(oy(x,S,i&&p===`centered`),sy(x,S,!i&&p===`moving-to-footer`),!a||!b)return null;let T;t[6]===d?T=t[7]:(T=(0,$.jsx)(Mh,{children:(0,$.jsx)($v,{messages:d})}),t[6]=d,t[7]=T);let E;t[8]!==l||t[9]!==y||t[10]!==s||t[11]!==T?(E=(0,$.jsx)(Pf,{paneId:s,conversationId:l,fillPane:y,children:T},s),t[8]=l,t[9]=y,t[10]=s,t[11]=T,t[12]=E):E=t[12];let D=E;if(v===`footer`){if(y){let e;t[13]===w?e=t[14]:(e={paddingBottom:w},t[13]=w,t[14]=e);let n;t[15]===D?n=t[16]:(n=(0,$.jsx)(`div`,{className:`pointer-events-auto`,children:D}),t[15]=D,t[16]=n);let r;return t[17]!==b||t[18]!==e||t[19]!==n?(r=(0,$.jsx)(`div`,{ref:b,className:`mx-0.5 mb-2 shrink-0 border-t border-border bg-background`,style:e,children:n}),t[17]=b,t[18]=e,t[19]=n,t[20]=r):r=t[20],r}if(i){let e;t[21]===m?e=t[22]:(e=K(`w-full min-w-0 shrink-0`,m),t[21]=m,t[22]=e);let n;t[23]===w?n=t[24]:(n={paddingBottom:w},t[23]=w,t[24]=n);let r;t[25]===D?r=t[26]:(r=(0,$.jsx)(`div`,{className:`pointer-events-auto w-full`,children:D}),t[25]=D,t[26]=r);let i;return t[27]!==b||t[28]!==e||t[29]!==n||t[30]!==r?(i=(0,$.jsx)(`div`,{ref:b,className:e,style:n,children:r}),t[27]=b,t[28]=e,t[29]=n,t[30]=r,t[31]=i):i=t[31],i}let e;t[32]===m?e=t[33]:(e=K(`shrink-0 bg-transparent max-md:px-2`,m),t[32]=m,t[33]=e);let n;t[34]===w?n=t[35]:(n={paddingBottom:w},t[34]=w,t[35]=n);let r;t[36]===D?r=t[37]:(r=(0,$.jsx)(`div`,{className:`relative mx-auto w-full max-w-3xl min-w-0 px-6`,children:(0,$.jsx)(`div`,{className:`pointer-events-auto pt-2 pb-6`,children:D})}),t[36]=D,t[37]=r);let a;return t[38]!==b||t[39]!==e||t[40]!==n||t[41]!==r?(a=(0,$.jsx)(`div`,{ref:b,className:e,style:n,children:r}),t[38]=b,t[39]=e,t[40]=n,t[41]=r,t[42]=a):a=t[42],a}let O;t[43]===w?O=t[44]:(O={bottom:w},t[43]=w,t[44]=O);let k,A;t[45]===Symbol.for(`react.memo_cache_sentinel`)?(k=Of(!1),A=(0,$.jsx)(`div`,{className:`h-0 bg-gradient-to-t from-background to-transparent md:h-16`}),t[45]=k,t[46]=A):(k=t[45],A=t[46]);let j;t[47]===D?j=t[48]:(j=(0,$.jsxs)(`div`,{className:k,children:[A,(0,$.jsx)(`div`,{className:`pointer-events-auto bg-background pb-2 md:pb-4`,children:D})]}),t[47]=D,t[48]=j);let M;return t[49]!==b||t[50]!==j||t[51]!==O?(M=(0,$.jsx)(`div`,{ref:b,className:`pointer-events-none absolute inset-x-0 z-30 max-md:px-2`,style:O,children:j}),t[49]=b,t[50]=j,t[51]=O,t[52]=M):M=t[52],M}function gy(e){return e.focusedPane}function _y(e){return e.selectedThreadId}var vy=Oi(e=>(0,$.jsx)(`div`,{className:`relative flex h-full min-h-0 flex-col overflow-hidden`,children:e.v0}),{name:`ChatMessagesPlaceholder_1`,portals:[`v0`]}),yy=Oi(e=>(0,$.jsx)(`div`,{className:`flex flex-1 flex-col items-center justify-center`,children:(0,$.jsxs)(`div`,{className:`flex w-full max-w-3xl flex-col items-center gap-6 px-4`,children:[(0,$.jsx)(`img`,{src:`/tarsk-color.svg`,alt:`Tarsk`,className:`h-16 w-16 rounded-lg`}),(0,$.jsxs)(`div`,{className:`text-center`,children:[(0,$.jsx)(`h1`,{className:e.v0,children:e.v1}),(0,$.jsx)(`p`,{className:e.v2,children:e.v3})]}),e.v4,e.v5]})}),{name:`ChatMessagesPlaceholder_2`,portals:[`v1`,`v3`,`v4`,`v5`]}),by=function(e){let t=(0,Q.c)(40),{project:n}=e,r=uh(),{isRunning:i}=bg(n?.projectId),{startServer:a}=mg(),o=eh(),s=o!=null&&!o.embedded;n?.name;let c=n?.name??`your project`,l;t[0]===c?l=t[1]:(l=xy(c),t[0]=c,t[1]=l);let u=l,d=!i&&n?.runCommand,f;t[2]!==n||t[3]!==a?(f=function(){n&&a(n)},t[2]=n,t[3]=a,t[4]=f):f=t[4];let p=f;if(r&&n){let e;t[5]===n?e=t[6]:(e=(0,$.jsx)(`div`,{className:`absolute left-1/2 top-10 z-10 flex -translate-x-1/2 -translate-y-1/2 flex-col items-center`,children:(0,$.jsx)(Ko,{project:n,className:`h-20 w-20`,iconClassName:`h-8 w-8`})}),t[5]=n,t[6]=e);let r;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(r=K(J.pageTitle,`tracking-tight text-balance text-foreground`),t[7]=r):r=t[7];let i;t[8]===n.name?i=t[9]:(i=(0,$.jsx)(`h1`,{className:r,children:n.name}),t[8]=n.name,t[9]=i);let a;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(a=K(J.pageSubtitle,`mt-2`),t[10]=a):a=t[10];let o;t[11]===u?o=t[12]:(o=(0,$.jsx)(`p`,{className:a,children:u}),t[11]=u,t[12]=o);let c;t[13]!==i||t[14]!==o?(c=(0,$.jsxs)(`div`,{children:[i,o]}),t[13]=i,t[14]=o,t[15]=c):c=t[15];let l;t[16]!==p||t[17]!==d?(l=d?(0,$.jsx)(`button`,{type:`button`,onClick:p,className:K(J.label,`inline-flex items-center gap-2 rounded-full bg-primary px-4 py-2 text-primary-foreground transition-colors hover:bg-primary/90`),children:`Start App`}):null,t[16]=p,t[17]=d,t[18]=l):l=t[18];let f;t[19]===s?f=t[20]:(f=s?(0,$.jsx)(hy,{inline:!0}):null,t[19]=s,t[20]=f);let m;t[21]!==l||t[22]!==f||t[23]!==c?(m=(0,$.jsx)(Li,{className:`px-6 pb-6 pt-16`,children:(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-6 text-center`,children:[c,l,f]})}),t[21]=l,t[22]=f,t[23]=c,t[24]=m):m=t[24];let h;return t[25]!==m||t[26]!==e?(h=(0,$.jsx)(vy,{v0:(0,$.jsx)(ga,{className:`relative z-10 animate-in fade-in duration-500`,children:(0,$.jsx)(`div`,{className:`flex min-h-full flex-col justify-center`,children:(0,$.jsx)(ji,{className:`w-full py-10`,children:(0,$.jsxs)(`div`,{className:`relative pt-10`,children:[e,m]})})})})}),t[25]=m,t[26]=e,t[27]=h):h=t[27],h}let m;t[28]===Symbol.for(`react.memo_cache_sentinel`)?(m=K(J.pageTitle,`tracking-tight text-balance text-foreground`),t[28]=m):m=t[28];let h=n?.name??`Project`,g;t[29]===Symbol.for(`react.memo_cache_sentinel`)?(g=K(J.pageSubtitle,`mt-2`),t[29]=g):g=t[29];let _;t[30]!==p||t[31]!==d?(_=d&&(0,$.jsx)(`button`,{type:`button`,onClick:p,className:K(J.label,`inline-flex items-center gap-2 rounded-full bg-primary px-4 py-2 text-primary-foreground transition-colors hover:bg-primary/90`),children:`Start App`}),t[30]=p,t[31]=d,t[32]=_):_=t[32];let v;t[33]===s?v=t[34]:(v=s?(0,$.jsx)(hy,{inline:!0}):null,t[33]=s,t[34]=v);let y;return t[35]!==u||t[36]!==h||t[37]!==_||t[38]!==v?(y=(0,$.jsx)(yy,{v0:m,v1:h,v2:g,v3:u,v4:_,v5:v}),t[35]=u,t[36]=h,t[37]=_,t[38]=v,t[39]=y):y=t[39],y};function xy(e){let t=[`What would you like to add to ${e}?`,`What should we build in ${e}?`,`What changes do you want to make to ${e}?`,`What feature should we add to ${e}?`,`What would you like to fix in ${e}?`,`What are we working on in ${e}?`,`What's next for ${e}?`,`What should we improve in ${e}?`,`How can we make ${e} better?`,`What would you like to change in ${e}?`,`What should we ship in ${e} next?`];return t[Math.floor(Math.random()*t.length)]}function Sy({virtuosoRef:e,selectedThreadId:t,messagesLoaded:n,messageCount:r,isStreaming:i,hasPendingMessage:a,streamingSegmentCount:o}){let s=(0,Z.useRef)(0),c=(0,Z.useRef)(!1),l=(0,Z.useRef)(!1),u=(0,Z.useRef)(!1),d=(0,Z.useRef)(0),f=(0,Z.useRef)(null),p=(0,Z.useCallback)(()=>{t&&e.current?.getState(e=>{ar(t,e.scrollTop)})},[t,e]),m=(0,Z.useRef)(p);m.current=p;function h(){u.current&&m.current()}(0,Z.useEffect)(()=>{function e(){h()}return window.addEventListener(`beforeunload`,e),()=>{window.removeEventListener(`beforeunload`,e)}},[t]),(0,Z.useEffect)(()=>{let e=setInterval(()=>{h()},5e3);return()=>clearInterval(e)},[t]),(0,Z.useEffect)(()=>()=>{f.current&&clearTimeout(f.current)},[]),(0,Z.useEffect)(()=>{l.current=!1,u.current=!1,s.current=0},[t]),(0,Z.useEffect)(()=>{if(!t||!n||r===0||l.current)return;l.current=!0,s.current=r;let i=Ce(t);if(i!==null&&i>0){requestAnimationFrame(()=>{requestAnimationFrame(()=>{e.current?.scrollTo({top:i,behavior:`auto`}),u.current=!0})});return}u.current=!0},[t,n,r,e]),(0,Z.useEffect)(()=>{if(!l.current)return;let t=r>s.current,n=c.current&&!i;if(i||a||t||n){d.current&&cancelAnimationFrame(d.current);let t=n?`smooth`:`auto`;d.current=requestAnimationFrame(()=>{e.current?.scrollTo({top:2**53-1,behavior:t}),d.current=0})}return s.current=r,c.current=i,()=>{d.current&&=(cancelAnimationFrame(d.current),0)}},[i,a,r,o,e]);function g(){f.current&&clearTimeout(f.current),f.current=setTimeout(()=>{h(),f.current=null},150)}function _(e){e||h()}return{onRangeChanged:g,onScrollingStateChange:_}}function Cy(e){return e.isCreatingProject||e.streamingSegmentCount>0?!0:e.lastMessageSender===`user`}function wy(e){if(e.isUser)return e.hasCheckpointRef?e.isStreaming||e.hasPendingMessage||e.isCreatingProject||e.isProcessingThread?`Restore unavailable while this thread is still processing.`:`Restore checkpoint`:`Restore unavailable: no checkpoint was created for this prompt.`}function Ty(e){return{bottomInset:e.bottomInset,columnClassName:e.columnClassName,isStreaming:e.isStreaming,isCreatingProject:e.isCreatingProject,isProcessingThread:e.isProcessingThread,hasPendingMessage:e.hasPendingMessage,isAutoRouting:e.isAutoRouting,hasActiveBlockingPrompt:Ka(e.streamingSegments),telegramTurn:e.telegramTurn,selectedProjectId:e.selectedProjectId,selectedThreadId:e.selectedThreadId,streamingSegments:e.streamingSegments,streamingModel:e.streamingModel,streamingAgentMode:e.streamingAgentMode,totalMessages:e.totalMessages,lastMessageSender:e.lastMessageSender,error:e.error,onClearError:e.onClearError,showCheckpointRestore:t=>t.sender===`user`&&!!t.checkpointRef&&!e.isStreaming&&!e.hasPendingMessage&&!e.isCreatingProject&&!e.isProcessingThread,getCheckpointTooltip:t=>wy({isUser:t.sender===`user`,hasCheckpointRef:!!t.checkpointRef,isStreaming:e.isStreaming,hasPendingMessage:e.hasPendingMessage,isCreatingProject:e.isCreatingProject,isProcessingThread:e.isProcessingThread})}}function Ey(e){let t=(0,Z.forwardRef)((t,n)=>{let r=(0,Q.c)(9),i,a,o;r[0]===t?(i=r[1],a=r[2],o=r[3]):({style:o,children:i,...a}=t,r[0]=t,r[1]=i,r[2]=a,r[3]=o);let s;return r[4]!==i||r[5]!==a||r[6]!==n||r[7]!==o?(s=(0,$.jsx)(`div`,{ref:n,style:o,...a,className:e,children:i}),r[4]=i,r[5]=a,r[6]=n,r[7]=o,r[8]=s):s=r[8],s});return t.displayName=`MessageList`,t}var Dy=(0,Z.forwardRef)(function(e,t){let n=(0,Q.c)(9),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=K(`chat-scrollbar`,r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,$.jsx)(`div`,{...i,ref:t,className:a}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});function Oy(e){let t=(0,Q.c)(32),{context:n}=e;if(!n)return null;let{bottomInset:r,isStreaming:i,isCreatingProject:a,isProcessingThread:o,hasPendingMessage:s,isAutoRouting:c,hasActiveBlockingPrompt:l,selectedProjectId:u,selectedThreadId:d,streamingSegments:f,streamingModel:p,streamingAgentMode:m,totalMessages:h,lastMessageSender:g,error:_,onClearError:v,telegramTurn:y}=n,b=f.length>0||a||o&&(i||s),x;t[0]!==a||t[1]!==g||t[2]!==f.length?(x=Cy({isCreatingProject:a,streamingSegmentCount:f.length,lastMessageSender:g}),t[0]=a,t[1]=g,t[2]=f.length,t[3]=x):x=t[3];let S=x,C=c||b&&(i||a||o)&&S,w=c||(i||s)&&!l&&S,T;t[4]===r?T=t[5]:(T={paddingBottom:r},t[4]=r,t[5]=T);let E;t[6]!==c||t[7]!==a||t[8]!==o||t[9]!==u||t[10]!==d||t[11]!==C||t[12]!==w||t[13]!==m||t[14]!==p||t[15]!==f||t[16]!==y||t[17]!==h?(E=C&&(0,$.jsx)(mf,{segments:f,model:p,mode:m,threadId:d,projectId:u,isCreatingProject:a,isProcessingThread:o&&!c,totalMessages:h,showProcessingLine:w,respondViaTelegram:y}),t[6]=c,t[7]=a,t[8]=o,t[9]=u,t[10]=d,t[11]=C,t[12]=w,t[13]=m,t[14]=p,t[15]=f,t[16]=y,t[17]=h,t[18]=E):E=t[18];let D;t[19]!==c||t[20]!==C||t[21]!==w?(D=w&&(0,$.jsx)(`div`,{className:K(`px-4 pb-4`,C?`pt-0`:`pt-2`),children:(0,$.jsx)(yf,{active:w,label:c?`Picking a model...`:void 0})}),t[19]=c,t[20]=C,t[21]=w,t[22]=D):D=t[22];let O;t[23]!==_||t[24]!==v?(O=_&&(0,$.jsxs)(`div`,{className:`mx-4 my-2`,children:[(0,$.jsx)(no,{variant:`error`,className:`mb-0`,children:_}),(0,$.jsx)(`button`,{type:`button`,className:K(J.compact,`mt-1 text-destructive underline underline-offset-2 hover:text-destructive/80`),onClick:v,children:`Dismiss`})]}),t[23]=_,t[24]=v,t[25]=O):O=t[25];let k;return t[26]!==n.columnClassName||t[27]!==T||t[28]!==E||t[29]!==D||t[30]!==O?(k=(0,$.jsxs)(`div`,{className:n.columnClassName,style:T,children:[E,D,O]}),t[26]=n.columnClassName,t[27]=T,t[28]=E,t[29]=D,t[30]=O,t[31]=k):k=t[31],k}function ky(e,t,n){return(0,$.jsx)(uf,{message:t,threadId:n.selectedThreadId,messageIndex:e,showCheckpointRestore:n.showCheckpointRestore(t),checkpointRestoreTooltip:n.getCheckpointTooltip(t)})}var Ay=(0,Z.forwardRef)(function(e,t){let n=(0,Q.c)(63),{bottomInset:r,messages:i,isStreaming:a,streamingSegments:o,streamingModel:s,streamingAgentMode:c,isCreatingProject:l,isProcessingThread:u,hasPendingMessage:d,isAutoRouting:f,selectedThreadId:p,selectedProjectId:m,projects:h,projectsLoading:g,messagesLoaded:_,onSelectThread:v,onCreateThread:y,onConnectRepo:b,onNewApp:x,onOpenFolder:S,error:C,onClearError:w,onAtBottomChange:T,onAtTopChange:E,hideEmptyState:D}=e,O=r===void 0?0:r,k=D===void 0?!1:D,{fillPane:A}=If(),j=th(),M;n[0]===A?M=n[1]:(M=Df(A),n[0]=A,n[1]=M);let N=M,P=(0,Z.useRef)(null),F;n[2]===N?F=n[3]:(F=Ey(N),n[2]=N,n[3]=F);let I;n[4]===F?I=n[5]:(I={Scroller:Dy,List:F,Footer:Oy},n[4]=F,n[5]=I);let L=I,R;n[6]===Symbol.for(`react.memo_cache_sentinel`)?(R=()=>({scrollToBottom:()=>{P.current?.scrollTo({top:2**53-1,behavior:`smooth`})},scrollToTop:()=>{P.current?.scrollTo({top:0,behavior:`smooth`})}}),n[6]=R):R=n[6],(0,Z.useImperativeHandle)(t,R);let z;n[7]!==d||n[8]!==a||n[9]!==i.length||n[10]!==_||n[11]!==p||n[12]!==o.length?(z={virtuosoRef:P,selectedThreadId:p,messagesLoaded:_,messageCount:i.length,isStreaming:a,hasPendingMessage:d,streamingSegmentCount:o.length},n[7]=d,n[8]=a,n[9]=i.length,n[10]=_,n[11]=p,n[12]=o.length,n[13]=z):z=n[13];let{onRangeChanged:B,onScrollingStateChange:ee}=Sy(z),te=!k&&i.length===0&&!a&&!l&&!p,ne=!k&&_&&i.length===0&&!a&&!l&&!u&&!d&&p,re;if(n[14]!==h||n[15]!==m){let e;n[17]===m?e=n[18]:(e=e=>e.projectId===m,n[17]=m,n[18]=e),re=h.find(e),n[14]=h,n[15]=m,n[16]=re}else re=n[16];let ie=re,ae=i.length>0?i[i.length-1].sender:null,oe;if(n[19]!==O||n[20]!==N||n[21]!==C||n[22]!==d||n[23]!==f||n[24]!==l||n[25]!==u||n[26]!==a||n[27]!==ae||n[28]!==i||n[29]!==w||n[30]!==m||n[31]!==p||n[32]!==c||n[33]!==s||n[34]!==o){let e=Jg(i);oe=Ty({bottomInset:O,columnClassName:N,isStreaming:a,isCreatingProject:l,isProcessingThread:u,hasPendingMessage:d,isAutoRouting:f,streamingSegments:o,selectedProjectId:m,selectedThreadId:p,streamingModel:s,streamingAgentMode:c,totalMessages:i.length,lastMessageSender:ae,telegramTurn:e,error:C,onClearError:w}),n[19]=O,n[20]=N,n[21]=C,n[22]=d,n[23]=f,n[24]=l,n[25]=u,n[26]=a,n[27]=ae,n[28]=i,n[29]=w,n[30]=m,n[31]=p,n[32]=c,n[33]=s,n[34]=o,n[35]=oe}else oe=n[35];let se=oe;if(te){let e=`flex min-h-0 flex-1 self-stretch transition-opacity duration-500 ease-in-out ${g?`opacity-0`:`opacity-100`}`,t;n[36]!==b||n[37]!==y||n[38]!==x||n[39]!==S||n[40]!==v||n[41]!==h?(t=(0,$.jsx)(xf,{projects:h,onSelectProject:v,onCreateThread:y,onConnectRepo:b,onNewApp:x,onOpenFolder:S}),n[36]=b,n[37]=y,n[38]=x,n[39]=S,n[40]=v,n[41]=h,n[42]=t):t=n[42];let r;return n[43]!==e||n[44]!==t?(r=(0,$.jsx)(`div`,{className:`flex h-full min-h-0 flex-1 flex-col items-center overflow-hidden`,children:(0,$.jsx)(`div`,{className:e,children:t})}),n[43]=e,n[44]=t,n[45]=r):r=n[45],r}if(ne){let e;return n[46]===ie?e=n[47]:(e=(0,$.jsx)(by,{project:ie}),n[46]=ie,n[47]=e),e}let ce=j===`moving-to-footer`&&`animate-in fade-in duration-300 ease-out`,le;n[48]===ce?le=n[49]:(le=K(`h-full overflow-hidden`,ce),n[48]=ce,n[49]=le);let ue=p??void 0,de;n[50]===Symbol.for(`react.memo_cache_sentinel`)?(de={height:`100%`},n[50]=de):de=n[50];let fe;n[51]!==i||n[52]!==T||n[53]!==E||n[54]!==B||n[55]!==ee||n[56]!==ue||n[57]!==L||n[58]!==se?(fe=(0,$.jsx)(ea,{ref:P,style:de,data:i,computeItemKey:jy,context:se,itemContent:ky,overscan:500,components:L,atBottomStateChange:T,atTopStateChange:E,rangeChanged:B,isScrolling:ee},ue),n[51]=i,n[52]=T,n[53]=E,n[54]=B,n[55]=ee,n[56]=ue,n[57]=L,n[58]=se,n[59]=fe):fe=n[59];let pe;return n[60]!==le||n[61]!==fe?(pe=(0,$.jsx)(`div`,{className:le,children:fe}),n[60]=le,n[61]=fe,n[62]=pe):pe=n[62],pe});function jy(e,t){return t.messageId}var My=Pn(`app.use-pane-chat-history.hook`);function Ny(e){let t=(0,Q.c)(9),{paneId:n,conversationId:r}=e,i=Gi(),a=X(Py),o;t[0]===n?o=t[1]:(o=e=>n===Ai||!!e.extraChatPanes[n],t[0]=n,t[1]=o);let s=X(o),c,l;t[2]!==r||t[3]!==i||t[4]!==s||t[5]!==n||t[6]!==a?(c=()=>{if(n===Ai||!s||!a||!r)return;let e=a,t=r,o=n,c=!1;return(async function(){try{let n=await B(e,t);if(c)return;i({type:Y.SetPaneMessages,paneId:o,messages:n.messages})}catch(e){let t=e;My.error(`Failed to load pane chat history:`,t),c||i({type:Y.SetPaneMessages,paneId:o,messages:[]})}})(),()=>{c=!0}},l=[r,i,s,n,a],t[2]=r,t[3]=i,t[4]=s,t[5]=n,t[6]=a,t[7]=c,t[8]=l):(c=t[7],l=t[8]),(0,Z.useEffect)(c,l)}function Py(e){return e.selectedThreadId}var Fy=4,Iy=8,Ly=64,Ry=`(max-width: 767px)`;function zy(){return window.matchMedia(Ry).matches?Fy:Ly}function By(e,t){let n=e.getBoundingClientRect().bottom,r=t.getBoundingClientRect().top,i=t.querySelector(`[data-chat-toolbar]`);i&&i.getBoundingClientRect().height>0&&(r=Math.min(r,i.getBoundingClientRect().top));let a=Math.max(0,Math.ceil(n-r)),o=window.matchMedia(Ry).matches?Fy:0,s=window.matchMedia(Ry).matches?0:Iy;return Math.max(a+o+s,zy())}function Vy(e,t,n){let r=(0,Q.c)(5),[i,a]=(0,Z.useState)(0),o,s;return r[0]!==t||r[1]!==e||r[2]!==n?(o=()=>{if(!n){a(0);return}let r=e.current,i=t.current;if(!r||!i){a(zy());return}let o=function(){let n=e.current,r=t.current;!n||!r||a(By(n,r))};o();let s=new ResizeObserver(o);s.observe(r),s.observe(i);let c=i.querySelector(`[data-chat-toolbar]`);c&&s.observe(c);let l=new MutationObserver(o);l.observe(i,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[`class`,`style`,`hidden`]}),window.addEventListener(`resize`,o);let u=window.visualViewport;return u?.addEventListener(`resize`,o),u?.addEventListener(`scroll`,o),()=>{s.disconnect(),l.disconnect(),window.removeEventListener(`resize`,o),u?.removeEventListener(`resize`,o),u?.removeEventListener(`scroll`,o)}},s=[e,t,n],r[0]=t,r[1]=e,r[2]=n,r[3]=o,r[4]=s):(o=r[3],s=r[4]),(0,Z.useEffect)(o,s),i}var Hy=Pn(`app.chat-pane.ui`);function Uy({paneId:e,conversationId:t,onCreateThread:n,showEmptyState:r=e===`primary`,fillPane:i=!1,hideInput:a=!0,onConnectRepo:o=()=>{},onNewApp:s=()=>{},onOpenFolder:c=()=>{}}){let l=Gi(),u=X(e=>e.selectedThreadId),d=X(e=>e.selectedProjectId),f=X(e=>e.projects),p=X(e=>e.projectsLoading),m=X(e=>e.isCreatingProject),h=X(e=>e.processingThreadIds),g=X(e=>e.pendingChatMessage),_=X(t=>u?_o(t.threadStreamingStates,u,e):null),v=X(t=>xo(t.pendingAutoRoutes,u,e)),y=X(e=>e.messages),b=X(e=>e.extraChatPanes),x=X(e=>e.messagesLoaded),S=e===`primary`?y:b[e]?.messages??[],C=v?[...S,Uf(v)]:S,w=e===`primary`?x:b[e]?.messagesLoaded??!1,T=!!(u&&h.includes(u)),E=e===`primary`&&g?.threadId===u,D=_?.isStreaming??!1;Ny({paneId:e,conversationId:t});let O=(0,Z.useRef)(null),k=(0,Z.useRef)(null),A=eh(),j=A?.overlayRef??{current:null},[M,N]=(0,Z.useState)(!0),[P,F]=(0,Z.useState)(!0),I=a&&!!u&&!!A,L=I&&A.placement===`overlay`,R=Vy(O,j,I),z=I&&!M;function B(){l({type:Y.CloseSidebar})}function ee(){l({type:Y.SetFocusedPane,paneId:e})}return(0,$.jsx)(Pf,{paneId:e,conversationId:t,fillPane:i,children:(0,$.jsxs)(`div`,{ref:O,className:`relative flex h-full min-w-0 flex-col`,onPointerDown:ee,children:[(0,$.jsx)(Ay,{ref:k,bottomInset:R,messages:C,isStreaming:D,streamingSegments:D?_?.streamingSegments??[]:[],streamingModel:D?_?.streamingModel??``:``,streamingAgentMode:D?_?.streamingAgentMode??null:null,isCreatingProject:r?m:!1,isProcessingThread:T,hasPendingMessage:E,isAutoRouting:!!v,selectedThreadId:u,selectedProjectId:d,projects:f,projectsLoading:p,messagesLoaded:w,onSelectThread:(e,t)=>{B(),l({type:Y.SelectThread,projectId:e,threadId:t}),yr().then(e=>{l({type:Y.SetProcessingThreads,threadIds:e})}).catch(e=>{Hy.error(`Failed to refresh processing threads after thread selection:`,e)})},onCreateThread:n,onConnectRepo:o,onNewApp:s,onOpenFolder:c,error:null,onClearError:()=>{},onAtBottomChange:N,onAtTopChange:F,hideEmptyState:!r}),!P&&C.length>0&&(0,$.jsx)(`div`,{className:`pointer-events-none absolute inset-x-0 top-3 z-20 flex justify-center`,children:(0,$.jsx)(Fe,{variant:`outline`,size:`icon-md`,onClick:()=>k.current?.scrollToTop(),className:`pointer-events-auto bg-background shadow-md`,"aria-label":`Scroll to top`,children:(0,$.jsx)(hr,{className:`h-4 w-4`})})}),z&&(0,$.jsx)(`div`,{className:`pointer-events-none absolute inset-x-0 z-20 flex justify-center ${L?`bottom-24`:`bottom-2`}`,children:(0,$.jsx)(Fe,{variant:`outline`,size:`icon-md`,onClick:()=>k.current?.scrollToBottom(),className:`pointer-events-auto bg-background shadow-md`,"aria-label":`Scroll to bottom`,children:(0,$.jsx)(Dr,{className:`h-4 w-4`})})})]})})}var Wy=(0,Z.lazy)(()=>po(()=>import(`./terminal-panel-Dlon-VDl.js`).then(e=>({default:e.TerminalPanel})),__vite__mapDeps([8,1,6,4,9]))),Gy=(0,Z.lazy)(()=>po(()=>import(`./diff-view-DDECIdhE.js`),__vite__mapDeps([10,1,6,4,5,11,12,13,14,15,16,17]))),Ky=(0,Z.lazy)(()=>po(()=>import(`./explorer-tab-view-72Krb0Ir.js`),__vite__mapDeps([18,1,6,4,19,20,11,12,21]))),qy=(0,Z.lazy)(()=>po(()=>import(`./browser-tab-BfAt-Sho.js`).then(e=>({default:e.BrowserTab})),__vite__mapDeps([22,1,6,4]))),Jy=(0,Z.lazy)(()=>po(()=>import(`./tasks-view-Cg9N8GZb.js`).then(e=>({default:e.TasksView})),__vite__mapDeps([23,1,6,4,11,12])));function Yy(e){let t=(0,Q.c)(22),{panelId:n,instanceId:r,onClose:i}=e,a=X(Qy),o=X(Zy),s;t[0]===r?s=t[1]:(s=e=>to(e,r),t[0]=r,t[1]=s);let c=X(s),{reviewRefreshTickByThread:l,tasksRefreshTick:u}=Fi();if(n===`chat`){let e;return t[2]!==c||t[3]!==r?(e=(0,$.jsx)(Uy,{paneId:r,fillPane:!0,conversationId:c,onCreateThread:Xy,showEmptyState:!1,hideInput:!0}),t[2]=c,t[3]=r,t[4]=e):e=t[4],e}if(n===`terminal`){let e;return t[5]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(Z.Suspense,{fallback:null,children:(0,$.jsx)(Wy,{})}),t[5]=e):e=t[5],e}if(n===`browser`){let e;return t[6]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(Z.Suspense,{fallback:null,children:(0,$.jsx)(qy,{})}),t[6]=e):e=t[6],e}if(n===`explorer`){if(!a){let e;return t[7]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)($y,{message:`Select a conversation to browse files.`}),t[7]=e):e=t[7],e}let e;return t[8]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(Z.Suspense,{fallback:(0,$.jsx)(Aa,{}),children:(0,$.jsx)(Ky,{})}),t[8]=e):e=t[8],e}if(n===`tasks`){if(!o){let e;return t[9]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)($y,{message:`Select a project to view tasks.`}),t[9]=e):e=t[9],e}let e;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(Aa,{}),t[10]=e):e=t[10];let n;return t[11]!==o||t[12]!==u?(n=(0,$.jsx)(Z.Suspense,{fallback:e,children:(0,$.jsx)(Jy,{projectId:o,refreshTrigger:u})}),t[11]=o,t[12]=u,t[13]=n):n=t[13],n}if(!a){let e;return t[14]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)($y,{message:`Select a conversation to review changes.`}),t[14]=e):e=t[14],e}let d=l[a]??0,f;t[15]!==i||t[16]!==a||t[17]!==d?(f=(0,$.jsx)(Z.Suspense,{fallback:null,children:(0,$.jsx)(Gy,{threadId:a,onExit:i,refreshTrigger:d})}),t[15]=i,t[16]=a,t[17]=d,t[18]=f):f=t[18];let p;return t[19]!==a||t[20]!==f?(p=(0,$.jsx)(Bc,{threadId:a,children:f}),t[19]=a,t[20]=f,t[21]=p):p=t[21],p}function Xy(){}function Zy(e){return e.selectedProjectId}function Qy(e){return e.selectedThreadId}function $y(e){let t=(0,Q.c)(2),{message:n}=e,r;return t[0]===n?r=t[1]:(r=(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center p-4 text-center text-muted-foreground`,children:n}),t[0]=n,t[1]=r),r}function eb(e){let t=(0,Q.c)(21),{title:n,titleSuffix:r,titleActions:i,showTitle:a,selected:o,onSelect:s,onTitleDoubleClick:c,onClose:l,disableClose:u,footer:d,children:f,className:p}=e,m=o===void 0?!1:o,h=u===void 0?!1:u,g=m&&`ring-2 ring-inset ring-brand`,_;t[0]!==p||t[1]!==g?(_=K(`flex h-full min-h-0 flex-col bg-background`,g,p),t[0]=p,t[1]=g,t[2]=_):_=t[2];let v;t[3]!==h||t[4]!==l||t[5]!==c||t[6]!==a||t[7]!==n||t[8]!==i||t[9]!==r?(v=a?(0,$.jsxs)(`div`,{className:`flex h-9 shrink-0 items-center justify-between gap-2 border-b border-border px-2`,onDoubleClick:c,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1 truncate px-1`,children:[(0,$.jsx)(`span`,{className:K(J.label,`truncate`),children:n}),r&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:K(J.label,`text-muted-foreground`),children:`–`}),r]})]}),(i||l)&&(0,$.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[i,l?(0,$.jsxs)(Fe,{type:`button`,variant:`ghost`,size:`icon-sm`,className:`text-muted-foreground`,onClick:l,onDoubleClick:tb,disabled:h,children:[(0,$.jsx)(Gt,{className:`h-4 w-4`}),(0,$.jsxs)(`span`,{className:`sr-only`,children:[`Close `,n]})]}):null]})]}):null,t[3]=h,t[4]=l,t[5]=c,t[6]=a,t[7]=n,t[8]=i,t[9]=r,t[10]=v):v=t[10];let y;t[11]===f?y=t[12]:(y=(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-hidden`,children:f}),t[11]=f,t[12]=y);let b;t[13]===d?b=t[14]:(b=d?(0,$.jsx)(`div`,{className:`shrink-0`,children:d}):null,t[13]=d,t[14]=b);let x;return t[15]!==s||t[16]!==_||t[17]!==v||t[18]!==y||t[19]!==b?(x=(0,$.jsxs)(`div`,{className:_,onPointerDown:s,children:[v,y,b]}),t[15]=s,t[16]=_,t[17]=v,t[18]=y,t[19]=b,t[20]=x):x=t[20],x}function tb(e){return e.stopPropagation()}var nb=[{id:`chat`,label:`Chat`,icon:Vt},{id:`explorer`,label:`Files`,icon:Nn},{id:`browser`,label:`Browser`,icon:x},{id:`terminal`,label:`Terminal`,icon:Hr},{id:`tasks`,label:`Tasks`,icon:nr},{id:`review`,label:`Review Changes`,icon:Qe}];function rb(e){return nb.find(t=>t.id===e)?.label??e}function ib(e){return nb.find(t=>t.id===e)?.icon??Vt}var ab=(0,Z.createContext)(void 0);function ob(e){let t=(0,Q.c)(5),{children:n}=e,[r,i]=(0,Z.useState)(null),a;t[0]===r?a=t[1]:(a={stats:r,setStats:i},t[0]=r,t[1]=a);let o;return t[2]!==n||t[3]!==a?(o=(0,$.jsx)(ab.Provider,{value:a,children:n}),t[2]=n,t[3]=a,t[4]=o):o=t[4],o}function sb(){let e=(0,Z.useContext)(ab);if(e===void 0)throw Error(`useReviewStats must be used within a ReviewStatsProvider`);return e}var cb=(0,Z.createContext)(void 0);function lb(e){let t=(0,Q.c)(5),{children:n}=e,[r,i]=(0,Z.useState)(null),a;t[0]===r?a=t[1]:(a={actions:r,setActions:i},t[0]=r,t[1]=a);let o;return t[2]!==n||t[3]!==a?(o=(0,$.jsx)(cb.Provider,{value:a,children:n}),t[2]=n,t[3]=a,t[4]=o):o=t[4],o}function ub(){let e=(0,Z.useContext)(cb);if(e===void 0)throw Error(`useChatDockTitleActions must be used within a ChatDockTitleActionsProvider`);return e}var db=Oi(e=>(0,$.jsxs)(`span`,{className:e.v0,children:[(0,$.jsxs)(`span`,{className:`text-muted-foreground`,children:[e.v1,` file`,e.v2]}),(0,$.jsxs)(`span`,{className:`text-green-500`,children:[`+`,e.v3]}),(0,$.jsxs)(`span`,{className:`text-red-500`,children:[`-`,e.v4]})]}),{name:`ReviewStatsSuffix_1`,portals:[`v1`,`v2`,`v3`,`v4`]}),fb=function(){let e=(0,Q.c)(6),{stats:t}=sb();if(!t||t.fileCount===0)return null;let n;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(n=K(J.label,`flex items-center gap-1 truncate`),e[0]=n):n=e[0];let r=t.fileCount===1?``:`s`,i;return e[1]!==t.additions||e[2]!==t.deletions||e[3]!==t.fileCount||e[4]!==r?(i=(0,$.jsx)(db,{v0:n,v1:t.fileCount,v2:r,v3:t.additions,v4:t.deletions}),e[1]=t.additions,e[2]=t.deletions,e[3]=t.fileCount,e[4]=r,e[5]=i):i=e[5],i};function pb(e){let t=(0,Q.c)(46),{instanceId:n,panelId:r,footer:i}=e,a=Gi(),{closeWindow:o,expandWindow:s,isLayoutExpanded:c,selectedWindowId:l,selectWindow:u,revealWindow:d}=vo(),f=X(gb),p=X(hb),m=X(mb),{triggerReviewRefresh:h}=Fi(),{triggerExplorerRefresh:g}=ko(),_=r===`chat`,v;t[0]!==n||t[1]!==_||t[2]!==r||t[3]!==f||t[4]!==p?(v=_?sr(f,p,n):rb(r),t[0]=n,t[1]=_,t[2]=r,t[3]=f,t[4]=p,t[5]=v):v=t[5];let y=v,b=!c&&l===n,x;t[6]!==n||t[7]!==_||t[8]!==m?(x=_&&Object.entries(m).some(e=>{let[t,r]=e;return t.endsWith(`:${n}`)&&r.isStreaming}),t[6]=n,t[7]=_,t[8]=m,t[9]=x):x=t[9];let S=x,C;t[10]!==o||t[11]!==n?(C=function(){o(n)},t[10]=o,t[11]=n,t[12]=C):C=t[12];let w=C,T;t[13]!==a||t[14]!==n||t[15]!==_||t[16]!==d||t[17]!==u?(T=function(){u(n),d(n),_&&a({type:Y.SetFocusedPane,paneId:n})},t[13]=a,t[14]=n,t[15]=_,t[16]=d,t[17]=u,t[18]=T):T=t[18];let E=T,D;t[19]!==s||t[20]!==E||t[21]!==n||t[22]!==c?(D=function(){c||(E(),s(n))},t[19]=s,t[20]=E,t[21]=n,t[22]=c,t[23]=D):D=t[23];let O=D,{actions:k}=ub(),A;t[24]===r?A=t[25]:(A=r===`review`?(0,$.jsx)(fb,{}):void 0,t[24]=r,t[25]=A);let j=A,M;t[26]!==r||t[27]!==p||t[28]!==g||t[29]!==h?(M=r===`review`&&p?(0,$.jsxs)(sa,{children:[(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsxs)(Fe,{variant:`ghost`,size:`icon-sm`,className:`text-muted-foreground`,onClick:()=>h(p),children:[(0,$.jsx)(it,{className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Refresh`})]})}),(0,$.jsx)(Qa,{children:`Refresh changes`})]}):r===`explorer`?(0,$.jsxs)(sa,{children:[(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsxs)(Fe,{variant:`ghost`,size:`icon-sm`,className:`text-muted-foreground`,onClick:g,children:[(0,$.jsx)(et,{className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Refresh`})]})}),(0,$.jsx)(Qa,{children:`Refresh`})]}):void 0,t[26]=r,t[27]=p,t[28]=g,t[29]=h,t[30]=M):M=t[30];let N=M??k,P;t[31]!==w||t[32]!==n||t[33]!==r?(P=(0,$.jsx)(Yy,{panelId:r,instanceId:n,onClose:w}),t[31]=w,t[32]=n,t[33]=r,t[34]=P):P=t[34];let F;return t[35]!==i||t[36]!==w||t[37]!==E||t[38]!==O||t[39]!==S||t[40]!==y||t[41]!==b||t[42]!==P||t[43]!==N||t[44]!==j?(F=(0,$.jsx)(eb,{title:y,titleSuffix:j,titleActions:N,showTitle:!0,selected:b,onSelect:E,onTitleDoubleClick:O,onClose:w,disableClose:S,footer:i,className:`h-full overflow-hidden rounded-lg border border-border bg-background`,children:P}),t[35]=i,t[36]=w,t[37]=E,t[38]=O,t[39]=S,t[40]=y,t[41]=b,t[42]=P,t[43]=N,t[44]=j,t[45]=F):F=t[45],F}function mb(e){return e.threadStreamingStates}function hb(e){return e.selectedThreadId}function gb(e){return e.projects}function _b(e){let t=(0,Q.c)(2),n;return t[0]===e?n=t[1]:(n=(0,$.jsx)(ob,{children:(0,$.jsx)(lb,{children:(0,$.jsx)(pb,{...e})})}),t[0]=e,t[1]=n),n}var vb=Oi(e=>(0,$.jsx)(`svg`,{"aria-hidden":`true`,className:e.v0,viewBox:`0 0 12 12`,fill:e.v1,stroke:e.v2,strokeWidth:`2`,xmlns:`http://www.w3.org/2000/svg`,children:(0,$.jsx)(`circle`,{cx:`6`,cy:`6`,r:e.v3})}),{name:`BrowserProcessingDot_1`,svg:!0}),yb=function(e){let t=(0,Q.c)(8),{active:n,className:r}=e,i=n===void 0?!1:n,a=i?`animate-thread-dot-pulse text-brand opacity-100`:`text-muted-foreground/40 opacity-100`,o;t[0]!==r||t[1]!==a?(o=K(`h-3 w-3 shrink-0 origin-center transition-opacity`,a,r),t[0]=r,t[1]=a,t[2]=o):o=t[2];let s=i?`currentColor`:`none`,c=i?`none`:`currentColor`,l=i?`5`:`4.5`,u;return t[3]!==o||t[4]!==s||t[5]!==c||t[6]!==l?(u=(0,$.jsx)(vb,{v0:o,v1:s,v2:c,v3:l}),t[3]=o,t[4]=s,t[5]=c,t[6]=l,t[7]=u):u=t[7],u},bb=Oi(e=>e.v0,{name:`ThreadStatusDot_1`,portals:[`v0`]}),xb=Oi(e=>(0,$.jsx)(`svg`,{className:e.v0,viewBox:`0 0 12 12`,fill:`currentColor`,xmlns:`http://www.w3.org/2000/svg`,children:(0,$.jsx)(`circle`,{cx:`6`,cy:`6`,r:`5`})}),{name:`ThreadStatusDot_2`,svg:!0}),Sb=Oi(e=>(0,$.jsx)(`svg`,{className:e.v0,viewBox:`0 0 12 12`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.0`,xmlns:`http://www.w3.org/2000/svg`,children:(0,$.jsx)(`circle`,{cx:`6`,cy:`6`,r:`4.5`})}),{name:`ThreadStatusDot_3`,svg:!0}),Cb=function(e){let t=(0,Q.c)(10),{gitStatusDot:n,isProcessing:r,isDeleting:i}=e,a=!!n||r;if(r){let e;return t[0]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(bb,{v0:(0,$.jsx)(yb,{active:!0})}),t[0]=e):e=t[0],e}let o=i&&`animate-thread-dot-pulse`,s=n===`changes`&&`text-brand`,c;t[1]!==a||t[2]!==n||t[3]!==o||t[4]!==s?(c=K(`h-3 w-3 shrink-0 origin-center`,o,s,re(n)&&`text-orange-500`,!a&&`text-muted-foreground`),t[1]=a,t[2]=n,t[3]=o,t[4]=s,t[5]=c):c=t[5];let l=c;if(a){let e;return t[6]===l?e=t[7]:(e=(0,$.jsx)(xb,{v0:l}),t[6]=l,t[7]=e),e}let u;return t[8]===l?u=t[9]:(u=(0,$.jsx)(Sb,{v0:l}),t[8]=l,t[9]=u),u};function wb(){let e=(0,Q.c)(76),t=Gi(),n=X(Mb),r=X(jb),i=X(Ab),a=X(kb),o=X(Ob),s=X(Db),c=X(Eb),l=X(Tb),{handleSelectThread:u,handleCreateThread:d,handleDeleteThread:f}=mo(),p=Pc(i??void 0),[m,h]=(0,Z.useState)(!1),[g,_]=(0,Z.useState)(null),v,y,b,x,S,C,T,E,D,O,k,A;if(e[0]!==o||e[1]!==s||e[2]!==t||e[3]!==d||e[4]!==f||e[5]!==u||e[6]!==m||e[7]!==l||e[8]!==g||e[9]!==a||e[10]!==n||e[11]!==p||e[12]!==r||e[13]!==i||e[14]!==c){A=Symbol.for(`react.early_return_sentinel`);bb0:{let j;e[27]===r?j=e[28]:(j=e=>e.projectId===r,e[27]=r,e[28]=j);let M=n.find(j);if(!M){A=null;break bb0}let N=M.projectId,P;e[29]===i?P=e[30]:(P=e=>e.threadId===i,e[29]=i,e[30]=P);let F=M.threads.find(P),I=(i?p.currentBranch||F?.currentBranch:void 0)||F?.title||`Branches`,L;e[31]!==t||e[32]!==u?(L=function(e,n){t({type:Y.ClearThreadCompleted,threadId:n}),u(e,n),h(!1)},e[31]=t,e[32]=u,e[33]=L):L=e[33];let R=L,z=function(){d(N,void 0),h(!1)},B=function(e,t){if(e.gitStatusDot){h(!1),_({threadId:e.threadId,displayName:t});return}f(N,e.threadId)},ee=g!==null,te;e[34]===Symbol.for(`react.memo_cache_sentinel`)?(te=e=>{e||_(null)},e[34]=te):te=e[34];let ne;e[35]===Symbol.for(`react.memo_cache_sentinel`)?(ne=(0,$.jsx)(ca,{children:`Delete Branch`}),e[35]=ne):ne=e[35];let re=g?.displayName,ie;e[36]===re?ie=e[37]:(ie=(0,$.jsxs)(qa,{children:[`Are you sure you want to delete "`,re,`" and all its files? This action cannot be undone.`]}),e[36]=re,e[37]=ie);let ae;e[38]===Symbol.for(`react.memo_cache_sentinel`)?(ae=(0,$.jsx)(Xa,{children:`Cancel`}),e[38]=ae):ae=e[38];let oe=(0,$.jsxs)(`div`,{className:`flex gap-3 justify-end`,children:[ae,(0,$.jsx)(oa,{onClick:()=>{g&&f(N,g.threadId),_(null)},className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:`Delete`})]}),se;e[39]!==ie||e[40]!==oe?(se=(0,$.jsxs)(Ci,{children:[ne,ie,oe]}),e[39]=ie,e[40]=oe,e[41]=se):se=e[41],e[42]!==ee||e[43]!==se?(k=(0,$.jsx)(Mi,{open:ee,onOpenChange:te,children:se}),e[42]=ee,e[43]=se,e[44]=k):k=e[44],y=iu,E=m,D=h;let ce,le,ue;e[45]===Symbol.for(`react.memo_cache_sentinel`)?(ce=K(`flex h-10 w-10 items-center justify-center rounded-full bg-background/25 text-foreground shadow-md backdrop-blur-sm transition-colors hover:bg-foreground hover:text-background dark:bg-background/75 md:h-10 md:w-auto md:max-w-[12rem] md:justify-start md:gap-1.5 md:px-3`),le=(0,$.jsx)(w,{className:`h-4 w-4 shrink-0`}),ue=K(J.compact,`hidden truncate md:inline`),e[45]=ce,e[46]=le,e[47]=ue):(ce=e[45],le=e[46],ue=e[47]);let de;e[48]===Symbol.for(`react.memo_cache_sentinel`)?(de=(0,$.jsx)(hr,{className:`hidden h-3.5 w-3.5 shrink-0 opacity-60 md:block`}),e[48]=de):de=e[48];let fe=(0,$.jsxs)(`button`,{type:`button`,"aria-label":`Branches`,className:ce,children:[le,(0,$.jsx)(`span`,{className:ue,children:I}),de]}),pe;e[49]===fe?pe=e[50]:(pe=(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsx)(au,{asChild:!0,children:fe})}),e[49]=fe,e[50]=pe);let V;e[51]===Symbol.for(`react.memo_cache_sentinel`)?(V=(0,$.jsx)(Qa,{side:`top`,children:`Branches`}),e[51]=V):V=e[51],e[52]===pe?O=e[53]:(O=(0,$.jsxs)(sa,{children:[pe,V]}),e[52]=pe,e[53]=O),v=ou,b=`end`,x=`top`,S=`w-72 p-1`;let me;e[54]===Symbol.for(`react.memo_cache_sentinel`)?(me=(0,$.jsx)(`span`,{className:K(J.label,`text-muted-foreground font-medium`),children:`Branches`}),e[54]=me):me=e[54];let he,ge;e[55]===Symbol.for(`react.memo_cache_sentinel`)?(he=(0,$.jsx)(ir,{}),ge=(0,$.jsx)(`span`,{className:`sr-only`,children:`Add branch`}),e[55]=he,e[56]=ge):(he=e[55],ge=e[56]);let _e=(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsxs)(Fe,{variant:`action`,size:`icon-sm`,className:`shrink-0`,onClick:z,children:[he,ge]})}),ve;e[57]===Symbol.for(`react.memo_cache_sentinel`)?(ve=(0,$.jsx)(Qa,{side:`left`,children:`Add branch (⌘⇧T)`}),e[57]=ve):ve=e[57],e[58]===_e?C=e[59]:(C=(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-2 py-1.5`,children:[me,(0,$.jsxs)(sa,{children:[_e,ve]})]}),e[58]=_e,e[59]=C),T=M.threads.length===0?(0,$.jsx)(`p`,{className:K(J.compact,`px-2 py-4 text-center text-muted-foreground`),children:`No branches yet. Create one to get started.`}):(0,$.jsx)(`div`,{className:`max-h-[min(320px,50vh)] overflow-y-auto`,children:M.threads.map(e=>(0,$.jsx)(Nb,{thread:e,projectId:N,selectedThreadId:i,isProcessing:Co(e.threadId,a,c,l),isDeleting:s.includes(e.threadId),isCompleted:o.includes(e.threadId),branchName:e.threadId===i&&p.currentBranch||e.currentBranch,onSelectThread:R,onRequestDelete:B},e.threadId))})}e[0]=o,e[1]=s,e[2]=t,e[3]=d,e[4]=f,e[5]=u,e[6]=m,e[7]=l,e[8]=g,e[9]=a,e[10]=n,e[11]=p,e[12]=r,e[13]=i,e[14]=c,e[15]=v,e[16]=y,e[17]=b,e[18]=x,e[19]=S,e[20]=C,e[21]=T,e[22]=E,e[23]=D,e[24]=O,e[25]=k,e[26]=A}else v=e[15],y=e[16],b=e[17],x=e[18],S=e[19],C=e[20],T=e[21],E=e[22],D=e[23],O=e[24],k=e[25],A=e[26];if(A!==Symbol.for(`react.early_return_sentinel`))return A;let j;e[60]!==v||e[61]!==b||e[62]!==x||e[63]!==S||e[64]!==C||e[65]!==T?(j=(0,$.jsxs)(v,{align:b,side:x,className:S,children:[C,T]}),e[60]=v,e[61]=b,e[62]=x,e[63]=S,e[64]=C,e[65]=T,e[66]=j):j=e[66];let M;e[67]!==y||e[68]!==j||e[69]!==E||e[70]!==D||e[71]!==O?(M=(0,$.jsxs)(y,{open:E,onOpenChange:D,children:[O,j]}),e[67]=y,e[68]=j,e[69]=E,e[70]=D,e[71]=O,e[72]=M):M=e[72];let N;return e[73]!==M||e[74]!==k?(N=(0,$.jsxs)($.Fragment,{children:[k,M]}),e[73]=M,e[74]=k,e[75]=N):N=e[75],N}function Tb(e){return e.pendingChatMessage}function Eb(e){return e.threadStreamingStates}function Db(e){return e.deletingThreadIds}function Ob(e){return e.completedThreadIds}function kb(e){return e.processingThreadIds}function Ab(e){return e.selectedThreadId}function jb(e){return e.selectedProjectId}function Mb(e){return e.projects}function Nb(e){let t=(0,Q.c)(34),{thread:n,projectId:r,selectedThreadId:i,isProcessing:a,isDeleting:o,isCompleted:s,branchName:c,onSelectThread:l,onRequestDelete:u}=e,d=(0,Z.useRef)(null),f=n.threadId===i,p=c||n.title||n.threadId,m,h;t[0]===a?(m=t[1],h=t[2]):(m=()=>{a&&d.current&&d.current.scrollIntoView({behavior:`smooth`,block:`nearest`})},h=[a],t[0]=a,t[1]=m,t[2]=h),(0,Z.useEffect)(m,h);let g;t[3]!==p||t[4]!==u||t[5]!==n?(g=function(e){e.stopPropagation(),u(n,p)},t[3]=p,t[4]=u,t[5]=n,t[6]=g):g=t[6];let _=g,v;t[7]!==l||t[8]!==r||t[9]!==n.threadId?(v=()=>l(r,n.threadId),t[7]=l,t[8]=r,t[9]=n.threadId,t[10]=v):v=t[10];let y;t[11]!==o||t[12]!==a||t[13]!==n.gitStatusDot?(y=(0,$.jsx)(Cb,{gitStatusDot:n.gitStatusDot,isProcessing:a,isDeleting:o}),t[11]=o,t[12]=a,t[13]=n.gitStatusDot,t[14]=y):y=t[14];let b;t[15]===Symbol.for(`react.memo_cache_sentinel`)?(b=K(J.body,`min-w-0 flex-1 truncate text-left`),t[15]=b):b=t[15];let x;t[16]===p?x=t[17]:(x=(0,$.jsx)(`span`,{className:b,children:p}),t[16]=p,t[17]=x);let S;t[18]===s?S=t[19]:(S=s?(0,$.jsx)(Xt,{className:`ml-auto h-3 w-3 shrink-0 text-green-500`}):null,t[18]=s,t[19]=S);let C;t[20]!==f||t[21]!==v||t[22]!==y||t[23]!==x||t[24]!==S?(C=(0,$.jsxs)(Eo,{selected:f,className:`min-w-0 flex-1 items-center rounded-md`,onClick:v,children:[y,x,S]}),t[20]=f,t[21]=v,t[22]=y,t[23]=x,t[24]=S,t[25]=C):C=t[25];let w;t[26]!==_||t[27]!==s||t[28]!==o||t[29]!==a?(w=!a&&!o&&!s&&(0,$.jsxs)(sa,{children:[(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsxs)(Fe,{variant:`ghost`,size:`icon-sm`,className:`hidden can-hover:group-hover:flex shrink-0 items-center justify-center text-muted-foreground can-hover:hover:bg-destructive can-hover:hover:text-destructive-foreground transition-colors`,onClick:_,children:[(0,$.jsx)(Tt,{}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Delete branch`})]})}),(0,$.jsx)(Qa,{side:`left`,children:`Delete branch and files from the repo`})]}),t[26]=_,t[27]=s,t[28]=o,t[29]=a,t[30]=w):w=t[30];let T;return t[31]!==w||t[32]!==C?(T=(0,$.jsxs)(`div`,{ref:d,className:`group flex min-w-0 items-center`,children:[C,w]}),t[31]=w,t[32]=C,t[33]=T):T=t[33],T}function Pb(){let e=(0,Q.c)(102),t=Gi(),{windows:n,hasOpenWindows:r,isLayoutExpanded:i,expandedWindowId:a,expandWindow:o,collapseLayout:s,isPanelOpen:c,selectedWindowId:l,selectWindow:u,revealWindow:d}=vo(),{openChatDockPanel:f}=Yc(),p=X(Hb),m=X(Vb),h=X(Bb),g=X(zb),_=X(Rb),v=X(Lb),y=X(Ib),b=X(Fb),x;if(e[0]!==p||e[1]!==m){let t;e[3]===m?t=e[4]:(t=e=>e.projectId===m,e[3]=m,e[4]=t),x=p.find(t),e[0]=p,e[1]=m,e[2]=x}else x=e[2];let S=x?.useBuiltInBrowser!==!1,{hasChanges:C,changedFilesCount:w}=Pc(h??void 0),T;e[5]!==b||e[6]!==y||e[7]!==v?.threadId||e[8]!==_||e[9]!==h||e[10]!==g?(T=function(e,t){return t===`chat`?e===`primary`?h?v?.threadId===h||(b===null||b===Ai)&&_.includes(h)?!0:_o(g,h).isStreaming:!1:!y[e]||!h?!1:b===e&&_.includes(h)?!0:_o(g,h,e).isStreaming:!1},e[5]=b,e[6]=y,e[7]=v?.threadId,e[8]=_,e[9]=h,e[10]=g,e[11]=T):T=e[11];let E=T,D,O,k,A,j,M,N,P,F,I,L,R,z,B;if(e[12]!==w||e[13]!==s||e[14]!==t||e[15]!==o||e[16]!==a||e[17]!==C||e[18]!==r||e[19]!==i||e[20]!==c||e[21]!==E||e[22]!==f||e[23]!==p||e[24]!==d||e[25]!==u||e[26]!==h||e[27]!==l||e[28]!==S||e[29]!==n){let m;e[44]!==h||e[45]!==S?(m=e=>!(e.id===`browser`&&!S||e.id===`chat`&&!h),e[44]=h,e[45]=S,e[46]=m):m=e[46];let g=nb.filter(m),_=[{id:dt,panelId:`chat`,title:sr(p,h,dt)},...n.map(e=>({id:e.id,panelId:e.panelId,title:e.panelId===`chat`?sr(p,h,e.id):rb(e.panelId)}))],v;e[47]===c?v=e[48]:(v=function(e){return e===`chat`?!0:c(e)},e[47]=c,e[48]=v);let y=v,b;e[49]===y?b=e[50]:(b=e=>!y(e.id),e[49]=y,e[50]=b);let x=g.filter(b),T=function(e){return i?a===e:l===e},ee=function(e){u(e.id),d(e.id),e.panelId===`chat`&&t({type:Y.SetFocusedPane,paneId:e.id})},te;e[51]===f?te=e[52]:(te=function(e){f(e,{reuseExisting:!1})},e[51]=f,e[52]=te);let ne=te,re;e[53]===f?re=e[54]:(re=function(e){f(e,{reuseExisting:!1})},e[53]=f,e[54]=re);let ie=re,ae;e[55]!==s||e[56]!==o||e[57]!==a||e[58]!==r||e[59]!==i||e[60]!==l||e[61]!==n?(ae=function(){if(r){if(i){s();return}if(l===`primary`||n.some(e=>e.id===l)){o(l);return}o(a??`primary`)}},e[55]=s,e[56]=o,e[57]=a,e[58]=r,e[59]=i,e[60]=l,e[61]=n,e[62]=ae):ae=e[62];let oe=ae,se=i?`Grid layout`:`Expanded layout`;R=`toolbar`,z=`Window taskbar`,B=`flex items-center gap-0.5 rounded-full bg-background/25 p-1 text-foreground shadow-md backdrop-blur-sm dark:bg-background/75`;let ce=_.map(e=>{let t=ib(e.panelId),n=T(e.id),r=e.panelId===`review`&&C,i=E(e.id,e.panelId),a=r?`${w} changed file${w===1?``:`s`}`:e.title;return(0,$.jsxs)(sa,{children:[(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsxs)(Fe,{type:`button`,role:`tab`,"aria-selected":n,"aria-label":e.title,variant:`ghost`,size:`icon-sm`,className:K(`relative rounded-full`,n&&`bg-foreground text-background hover:bg-foreground hover:text-background`),onClick:()=>ee(e),children:[(0,$.jsxs)(`span`,{className:`relative inline-flex items-center justify-center`,children:[i&&(0,$.jsx)(`span`,{"aria-hidden":!0,className:`pointer-events-none absolute inset-[-6px] rounded-full border-2 border-brand/30 border-t-brand animate-spin`}),(0,$.jsx)(t,{className:K(`h-4 w-4`,i&&`opacity-60`)})]}),r&&(0,$.jsx)(`span`,{className:`absolute -right-0.5 -top-0.5 h-2 w-2 rounded-full bg-brand`})]})}),(0,$.jsx)(Qa,{side:`top`,children:a})]},e.id)});e[63]===ce?k=e[64]:(k=(0,$.jsx)(`div`,{role:`tablist`,"aria-label":`Open windows`,className:`flex items-center gap-0.5`,children:ce}),e[63]=ce,e[64]=k),A=x.length>0?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`mx-0.5 h-4 w-px shrink-0 bg-border`,"aria-hidden":!0}),(0,$.jsx)(`div`,{"aria-label":`Closed window types`,className:`flex items-center gap-0.5`,children:x.map(e=>{let t=e.icon,n=e.id===`review`&&C,r=n?`${w} changed file${w===1?``:`s`}`:e.label;return(0,$.jsxs)(sa,{children:[(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsxs)(Fe,{type:`button`,"aria-label":e.label,variant:`ghost`,size:`icon-sm`,className:`relative rounded-full opacity-50`,onClick:()=>ne(e.id),children:[(0,$.jsx)(t,{className:`h-4 w-4`}),n&&(0,$.jsx)(`span`,{className:`absolute -right-0.5 -top-0.5 h-2 w-2 rounded-full bg-brand`})]})}),(0,$.jsx)(Qa,{side:`top`,children:r})]},e.id)})})]}):null,e[65]===Symbol.for(`react.memo_cache_sentinel`)?(j=(0,$.jsx)(`div`,{className:`mx-0.5 h-4 w-px shrink-0 bg-border`,"aria-hidden":!0}),e[65]=j):j=e[65];let le=r&&!i,ue=!r,de=r&&!i&&`bg-foreground text-background hover:bg-foreground hover:text-background`,fe;e[66]===de?fe=e[67]:(fe=K(`rounded-full`,de),e[66]=de,e[67]=fe);let pe;e[68]===Symbol.for(`react.memo_cache_sentinel`)?(pe=(0,$.jsx)(hn,{className:`h-4 w-4`}),e[68]=pe):pe=e[68];let V;e[69]!==oe||e[70]!==se||e[71]!==le||e[72]!==ue||e[73]!==fe?(V=(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsx)(Fe,{type:`button`,variant:`ghost`,size:`icon-sm`,"aria-label":se,"aria-pressed":le,disabled:ue,className:fe,onClick:oe,children:pe})}),e[69]=oe,e[70]=se,e[71]=le,e[72]=ue,e[73]=fe,e[74]=V):V=e[74];let me;e[75]===se?me=e[76]:(me=(0,$.jsx)(Qa,{side:`top`,children:se}),e[75]=se,e[76]=me),e[77]!==V||e[78]!==me?(M=(0,$.jsxs)(sa,{children:[V,me]}),e[77]=V,e[78]=me,e[79]=M):M=e[79],O=fa,e[80]===Symbol.for(`react.memo_cache_sentinel`)?(L=(0,$.jsxs)(sa,{children:[(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsx)(Ji,{asChild:!0,children:(0,$.jsx)(Fe,{type:`button`,variant:`ghost`,size:`icon-sm`,"aria-label":`Add window`,className:`rounded-full`,children:(0,$.jsx)(ir,{className:`h-4 w-4`})})})}),(0,$.jsx)(Qa,{side:`top`,children:`Add window`})]}),e[80]=L):L=e[80],D=Ei,N=`top`,P=`center`,F=`w-44 p-1`;let he;e[81]===ie?he=e[82]:(he=e=>{let t=e.icon;return(0,$.jsxs)(ya,{className:K(J.body,`gap-2`),onSelect:()=>ie(e.id),children:[(0,$.jsx)(t,{className:`h-4 w-4 shrink-0`}),e.label]},e.id)},e[81]=ie,e[82]=he),I=g.map(he),e[12]=w,e[13]=s,e[14]=t,e[15]=o,e[16]=a,e[17]=C,e[18]=r,e[19]=i,e[20]=c,e[21]=E,e[22]=f,e[23]=p,e[24]=d,e[25]=u,e[26]=h,e[27]=l,e[28]=S,e[29]=n,e[30]=D,e[31]=O,e[32]=k,e[33]=A,e[34]=j,e[35]=M,e[36]=N,e[37]=P,e[38]=F,e[39]=I,e[40]=L,e[41]=R,e[42]=z,e[43]=B}else D=e[30],O=e[31],k=e[32],A=e[33],j=e[34],M=e[35],N=e[36],P=e[37],F=e[38],I=e[39],L=e[40],R=e[41],z=e[42],B=e[43];let ee;e[83]!==D||e[84]!==N||e[85]!==P||e[86]!==F||e[87]!==I?(ee=(0,$.jsx)(D,{side:N,align:P,className:F,children:I}),e[83]=D,e[84]=N,e[85]=P,e[86]=F,e[87]=I,e[88]=ee):ee=e[88];let te;e[89]!==O||e[90]!==ee||e[91]!==L?(te=(0,$.jsxs)(O,{children:[L,ee]}),e[89]=O,e[90]=ee,e[91]=L,e[92]=te):te=e[92];let ne;return e[93]!==k||e[94]!==A||e[95]!==j||e[96]!==M||e[97]!==te||e[98]!==R||e[99]!==z||e[100]!==B?(ne=(0,$.jsxs)(`div`,{role:R,"aria-label":z,className:B,children:[k,A,j,M,te]}),e[93]=k,e[94]=A,e[95]=j,e[96]=M,e[97]=te,e[98]=R,e[99]=z,e[100]=B,e[101]=ne):ne=e[101],ne}function Fb(e){return e.activeStreamPane}function Ib(e){return e.extraChatPanes}function Lb(e){return e.pendingChatMessage}function Rb(e){return e.processingThreadIds}function zb(e){return e.threadStreamingStates}function Bb(e){return e.selectedThreadId}function Vb(e){return e.selectedProjectId}function Hb(e){return e.projects}var Ub=(0,Z.lazy)(()=>po(()=>import(`./git-ops-button-CKGLh3Zk.js`).then(e=>({default:e.GitOpsButton})),__vite__mapDeps([7,1,6,4,5]))),Wb=`h-full overflow-hidden rounded-lg border border-border bg-background`;function Gb(e,t){let n=e.getBoundingClientRect(),r=t.getBoundingClientRect(),i=getComputedStyle(e),a=Number.parseFloat(i.paddingTop)||0,o=Number.parseFloat(i.paddingBottom)||0,s=Number.parseFloat(i.paddingLeft)||0,c=Number.parseFloat(i.paddingRight)||0,l=n.top+a,u=n.bottom-o,d=n.left+s,f=n.right-c,p=u-l,m=f-d,h=0,g=0;r.height<=p?r.bottom>u?h=r.bottom-u:r.top<l&&(h=r.top-l):r.top>u?h=r.top-l:r.bottom<l&&(h=r.bottom-u),r.width<=m?r.right>f?g=r.right-f:r.left<d&&(g=r.left-d):r.left>f?g=r.left-d:r.right<d&&(g=r.right-f),!(g===0&&h===0)&&e.scrollBy({left:g,top:h,behavior:`smooth`})}function Kb(e){let t=(0,Q.c)(79),{children:n}=e,r=Gi(),{windows:i,hasOpenWindows:a,isLayoutExpanded:o,expandedWindowId:s,expandWindow:c,pendingScrollWindowId:l,clearPendingScrollWindow:u,selectedWindowId:d,selectWindow:f,revealWindow:p}=vo(),m=X(tx),h=X(ex),g=X($b),_=X(Qb),v=X(Zb),y=X(Xb),b=X(Yb),x=X(Jb),S;t[0]===h?S=t[1]:(S=e=>h?_o(e.threadStreamingStates,h,dt).isStreaming:!1,t[0]=h,t[1]=S);let C=X(S),w;t[2]===h?w=t[3]:(w=e=>h?Pa(h,{hasSession:qb,streamingStates:e.threadStreamingStates}):!1,t[2]=h,t[3]=w);let T=X(w),E;t[4]!==m||t[5]!==h?(E=sr(m,h,`primary`),t[4]=m,t[5]=h,t[6]=E):E=t[6];let D=E,O=(0,Z.useRef)(null),k=!!(h&&g),A;t[7]!==a||t[8]!==y||t[9]!==C||t[10]!==_||t[11]!==x?.threadId||t[12]!==b||t[13]!==h?(A=!a&&!!h&&_.length===0&&!C&&!y&&!(h&&b.includes(h))&&x?.threadId!==h,t[7]=a,t[8]=y,t[9]=C,t[10]=_,t[11]=x?.threadId,t[12]=b,t[13]=h,t[14]=A):A=t[14];let j=A,M=j&&v,N=j&&!v&&!T,P;t[15]!==N||t[16]!==h||t[17]!==M?(P={centered:M,loading:N,threadId:h},t[15]=N,t[16]=h,t[17]=M,t[18]=P):P=t[18];let{phase:F,reveal:I}=ah(P),L=uh(),R;t[19]!==s||t[20]!==o?(R=()=>{!o||!s||!O.current||O.current.querySelector(`[data-window-id="${s}"]`)?.scrollIntoView({inline:`start`,block:`nearest`,behavior:`auto`})},t[19]=s,t[20]=o,t[21]=R):R=t[21];let z;t[22]!==s||t[23]!==o||t[24]!==i?(z=[s,o,i],t[22]=s,t[23]=o,t[24]=i,t[25]=z):z=t[25],(0,Z.useEffect)(R,z);let B;t[26]!==u||t[27]!==o||t[28]!==l?(B=()=>{if(!l||!O.current)return;let e=O.current,t=e.querySelector(`[data-window-id="${l}"]`);t&&(o?t.scrollIntoView({behavior:`smooth`,block:`nearest`,inline:`start`}):Gb(e,t),u())},t[26]=u,t[27]=o,t[28]=l,t[29]=B):B=t[29];let ee;t[30]!==u||t[31]!==o||t[32]!==l||t[33]!==i?(ee=[u,o,l,i],t[30]=u,t[31]=o,t[32]=l,t[33]=i,t[34]=ee):ee=t[34],(0,Z.useEffect)(B,ee);let te=!o&&d===`primary`,ne;t[35]!==r||t[36]!==p||t[37]!==f?(ne=()=>{f(dt),p(dt),r({type:Y.SetFocusedPane,paneId:`primary`})},t[35]=r,t[36]=p,t[37]=f,t[38]=ne):ne=t[38];let re;t[39]!==r||t[40]!==c||t[41]!==o||t[42]!==f?(re=()=>{o||(f(dt),r({type:Y.SetFocusedPane,paneId:`primary`}),c(dt))},t[39]=r,t[40]=c,t[41]=o,t[42]=f,t[43]=re):re=t[43];let ie;t[44]===Symbol.for(`react.memo_cache_sentinel`)?(ie=(0,$.jsx)(hy,{paneId:dt}),t[44]=ie):ie=t[44];let ae;t[45]!==n||t[46]!==D||t[47]!==te||t[48]!==ne||t[49]!==re?(ae=(0,$.jsx)(eb,{title:D,showTitle:!0,selected:te,onSelect:ne,onTitleDoubleClick:re,footer:ie,className:Wb,children:n}),t[45]=n,t[46]=D,t[47]=te,t[48]=ne,t[49]=re,t[50]=ae):ae=t[50];let oe=ae,se;t[51]!==n||t[52]!==F||t[53]!==a||t[54]!==o||t[55]!==oe||t[56]!==L||t[57]!==i?(se=a?(0,$.jsxs)(`div`,{ref:O,className:K(`h-full min-h-0`,o?`scrollbar-hide flex overflow-x-auto overflow-y-hidden scroll-smooth snap-x snap-mandatory`:`grid gap-3 overflow-auto p-3`),style:o?void 0:{gridTemplateColumns:`repeat(auto-fit, minmax(min(100%, 24rem), 1fr))`,gridAutoRows:`minmax(min(100%, 20rem), 1fr)`},children:[(0,$.jsx)(`div`,{"data-window-id":dt,className:K(`min-h-0 min-w-0`,o&&`box-border h-full w-full shrink-0 grow-0 basis-full snap-start snap-always p-3`),children:oe}),i.map(e=>{let t=e.panelId===`chat`?(0,$.jsx)(hy,{paneId:e.id}):void 0;return(0,$.jsx)(`div`,{"data-window-id":e.id,className:K(`min-h-0 min-w-0`,o&&`box-border h-full w-full shrink-0 grow-0 basis-full snap-start snap-always p-3`),children:(0,$.jsx)(_b,{instanceId:e.id,panelId:e.panelId,footer:t})},e.id)})]}):(0,$.jsx)(`div`,{className:`relative flex h-full min-h-0 flex-col`,children:(0,$.jsxs)(`div`,{className:K(`flex h-full min-h-0 flex-col`,Df(!1),L&&`rounded-2xl border border-border bg-background/75 shadow-lg backdrop-blur-sm`),children:[(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-hidden`,children:n}),rh(F)?(0,$.jsx)(hy,{}):null]})}),t[51]=n,t[52]=F,t[53]=a,t[54]=o,t[55]=oe,t[56]=L,t[57]=i,t[58]=se):se=t[58];let ce=se,le;t[59]===ce?le=t[60]:(le=(0,$.jsx)(`div`,{className:`relative z-10 min-h-0 flex-1`,children:ce}),t[59]=ce,t[60]=le);let ue;t[61]!==g||t[62]!==h||t[63]!==k?(ue=k&&h&&g?(0,$.jsx)(Bc,{threadId:h,children:(0,$.jsx)(Z.Suspense,{fallback:null,children:(0,$.jsx)(Ub,{projectId:g,threadId:h,layout:`bar`},h)})}):null,t[61]=g,t[62]=h,t[63]=k,t[64]=ue):ue=t[64];let de;t[65]===ue?de=t[66]:(de=(0,$.jsx)(`div`,{className:`hidden justify-self-start md:block`,children:ue}),t[65]=ue,t[66]=de);let fe;t[67]===Symbol.for(`react.memo_cache_sentinel`)?(fe=(0,$.jsx)(`div`,{className:`justify-self-center md:col-start-2`,children:(0,$.jsx)(Pb,{})}),t[67]=fe):fe=t[67];let pe;t[68]===Symbol.for(`react.memo_cache_sentinel`)?(pe=(0,$.jsx)(`div`,{className:`flex items-center justify-end gap-2 justify-self-end`,children:(0,$.jsx)(wb,{})}),t[68]=pe):pe=t[68];let V;t[69]===de?V=t[70]:(V=(0,$.jsxs)(`div`,{className:`relative z-0 grid shrink-0 grid-cols-[1fr_auto] items-center bg-transparent px-4 pb-4 pt-2 md:grid-cols-[1fr_auto_1fr]`,children:[de,fe,pe]}),t[69]=de,t[70]=V);let me;t[71]!==le||t[72]!==V?(me=(0,$.jsxs)(`div`,{className:`relative flex h-full min-h-0 w-full flex-col overflow-hidden`,children:[le,V]}),t[71]=le,t[72]=V,t[73]=me):me=t[73];let he;return t[74]!==F||t[75]!==I||t[76]!==a||t[77]!==me?(he=(0,$.jsx)($m,{placement:`footer`,embedded:a,composerPhase:F,composerReveal:I,children:me}),t[74]=F,t[75]=I,t[76]=a,t[77]=me,t[78]=he):he=t[78],he}function qb(){return!1}function Jb(e){return e.pendingChatMessage}function Yb(e){return e.processingThreadIds}function Xb(e){return e.isCreatingProject}function Zb(e){return Ha(e,dt)}function Qb(e){return Wa(e,dt)}function $b(e){return e.selectedProjectId}function ex(e){return e.selectedThreadId}function tx(e){return e.projects}function nx(e,t){for(let n of e){if(n.type!==`tool_use`||n.name!==`open_widget`)continue;let e=Jd(n.input);e.url&&t.push({id:n.id,url:e.url,title:e.title})}}function rx(e){let t=[],n=new Set;for(let r of e){let e=eo(r.content);if(!e)continue;let i=t.length;nx(e,t);for(let e=i;e<t.length;e++){let r=t[e];if(n.has(r.id)){t.splice(e,1),--e;continue}n.add(r.id)}}return t}function ix(){let e=(0,Q.c)(5),t=Gi(),n=X(ox),r=X(ax),i,a;e[0]!==t||e[1]!==n||e[2]!==r?(i=()=>{if(!r)return;let e=rx(n);e.length!==0&&t({type:Y.SyncOpenWidgetsFromMessages,widgets:e})},a=[t,n,r],e[0]=t,e[1]=n,e[2]=r,e[3]=i,e[4]=a):(i=e[3],a=e[4]),(0,Z.useEffect)(i,a)}function ax(e){return e.messagesLoaded}function ox(e){return e.messages}var sx=768;function cx(){let e=(0,Q.c)(2),[t,n]=Z.useState(lx),r,i;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=()=>{let e=window.matchMedia(`(max-width: ${sx-1}px)`),t=()=>{n(window.innerWidth<sx)};return e.addEventListener(`change`,t),n(window.innerWidth<sx),()=>e.removeEventListener(`change`,t)},i=[],e[0]=r,e[1]=i):(r=e[0],i=e[1]),Z.useEffect(r,i),t}function lx(){return typeof window>`u`?!1:window.innerWidth<sx}function ux(){let e=(0,Q.c)(7),t=Gi(),n=cx(),r=X(fx),i=X(dx),a=i.length>0&&!n&&!!r,o;e[0]!==t||e[1]!==i?(o=e=>{let n=i.find(t=>t.id===e);n&&(i.some(t=>t.id!==e&&Ra(t.url)===Ra(n.url))||Cv(n.url),t({type:Y.CloseWidget,id:e}))},e[0]=t,e[1]=i,e[2]=o):o=e[2];let s=o,c;return e[3]!==s||e[4]!==a||e[5]!==i?(c={openWidgets:i,isWidgetPanelOpen:a,closeWidget:s},e[3]=s,e[4]=a,e[5]=i,e[6]=c):c=e[6],c}function dx(e){return e.openWidgets}function fx(e){return e.selectedThreadId}var px=320;function mx(e){let t=(0,Q.c)(45),{widget:n,onClose:r}=e,{url:i,title:a,id:o}=n,s=(0,Z.useRef)(null),c;t[0]===i?c=t[1]:(c=()=>cv(i)?.status,t[0]=i,t[1]=c);let[l,u]=(0,Z.useState)(c),d;t[2]===i?d=t[3]:(d=()=>cv(i)?.error,t[2]=i,t[3]=d);let[f,p]=(0,Z.useState)(d),m,h;t[4]===i?(m=t[5],h=t[6]):(m=()=>lv(i,()=>{let e=cv(i);u(e?.status),p(e?.error)}),h=[i],t[4]=i,t[5]=m,t[6]=h),(0,Z.useEffect)(m,h);let g,_;t[7]===i?(g=t[8],_=t[9]):(g=()=>{let e=s.current;return Sv(i,e),()=>{Sv(i,null)}},_=[i],t[7]=i,t[8]=g,t[9]=_),(0,Z.useEffect)(g,_);let v;t[10]!==a||t[11]!==i?(v=Ba(a,i),t[10]=a,t[11]=i,t[12]=v):v=t[12];let y=v,b=l===`loading`||l===`discovering`,x=l===void 0||l===`loading`||l===`discovering`,S,C;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(S=K(J.label,`flex items-center gap-2 border-b border-border px-3 py-2`),C=(0,$.jsx)(hn,{className:`h-4 w-4 shrink-0 text-brand`}),t[13]=S,t[14]=C):(S=t[13],C=t[14]);let w;t[15]===y?w=t[16]:(w=(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate cursor-default`,children:y})}),t[15]=y,t[16]=w);let T;t[17]===i?T=t[18]:(T=(0,$.jsx)(Qa,{className:`max-w-md break-all`,children:i}),t[17]=i,t[18]=T);let E;t[19]!==w||t[20]!==T?(E=(0,$.jsxs)(sa,{children:[w,T]}),t[19]=w,t[20]=T,t[21]=E):E=t[21];let D;t[22]===b?D=t[23]:(D=b&&(0,$.jsx)(sn,{className:`h-3.5 w-3.5 shrink-0 animate-spin text-muted-foreground`}),t[22]=b,t[23]=D);let O;t[24]!==o||t[25]!==r?(O=()=>r(o),t[24]=o,t[25]=r,t[26]=O):O=t[26];let k=`Close ${y}`,A;t[27]===Symbol.for(`react.memo_cache_sentinel`)?(A=(0,$.jsx)(Gt,{className:`h-4 w-4`}),t[27]=A):A=t[27];let j;t[28]!==O||t[29]!==k?(j=(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsx)(Fe,{type:`button`,variant:`ghost`,size:`icon`,className:`h-7 w-7 shrink-0`,onClick:O,"aria-label":k,children:A})}),t[28]=O,t[29]=k,t[30]=j):j=t[30];let M;t[31]===Symbol.for(`react.memo_cache_sentinel`)?(M=(0,$.jsx)(Qa,{children:`Close widget`}),t[31]=M):M=t[31];let N;t[32]===j?N=t[33]:(N=(0,$.jsxs)(sa,{children:[j,M]}),t[32]=j,t[33]=N);let P;t[34]!==E||t[35]!==D||t[36]!==N?(P=(0,$.jsxs)(`div`,{className:S,children:[C,E,D,N]}),t[34]=E,t[35]=D,t[36]=N,t[37]=P):P=t[37];let F;t[38]!==f||t[39]!==x||t[40]!==l?(F=l===`error`?(0,$.jsxs)(`div`,{className:K(J.bodyMuted,`border-destructive/40 bg-destructive/5 space-y-1 p-3`),children:[(0,$.jsx)(`div`,{className:`font-medium text-destructive`,children:`Failed to load widget`}),(0,$.jsx)(`div`,{className:`break-words`,children:f??`Unknown error`})]}):(0,$.jsx)(`div`,{ref:s,className:`flex items-center justify-center overflow-hidden rounded-b-lg bg-background`,style:{height:px},children:x&&(0,$.jsx)(sn,{className:`h-5 w-5 animate-spin text-muted-foreground`,"aria-label":`Loading widget`})}),t[38]=f,t[39]=x,t[40]=l,t[41]=F):F=t[41];let I;return t[42]!==P||t[43]!==F?(I=(0,$.jsxs)(`div`,{className:`min-w-0 max-w-full flex-[1_1_380px] overflow-hidden rounded-lg border border-border bg-background`,children:[P,F]}),t[42]=P,t[43]=F,t[44]=I):I=t[44],I}function hx(){let e=(0,Q.c)(7),{openWidgets:t,closeWidget:n}=ux();if(t.length===0)return null;let r;if(e[0]!==n||e[1]!==t){let i;e[3]===n?i=e[4]:(i=e=>(0,$.jsx)(mx,{widget:e,onClose:n},e.id),e[3]=n,e[4]=i),r=t.map(i),e[0]=n,e[1]=t,e[2]=r}else r=e[2];let i;return e[5]===r?i=e[6]:(i=(0,$.jsx)(`div`,{className:`flex flex-wrap gap-4 p-4`,children:r}),e[5]=r,e[6]=i),i}function gx(){let e=(0,Q.c)(1);ix();let t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(`div`,{className:`flex h-full min-h-0 w-full flex-col`,children:(0,$.jsx)(Ot,{className:`min-h-0 flex-1`,children:(0,$.jsx)(hx,{})})}),e[0]=t):t=e[0],t}var _x=768;function vx(){let e=(0,Q.c)(2),[t,n]=Z.useState(void 0),r,i;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=()=>{let e=window.matchMedia(`(max-width: ${_x-1}px)`),t=()=>{n(window.innerWidth<_x)};return e.addEventListener(`change`,t),n(window.innerWidth<_x),()=>e.removeEventListener(`change`,t)},i=[],e[0]=r,e[1]=i):(r=e[0],i=e[1]),Z.useEffect(r,i),!!t}var yx=Pn(`app.use-chat-history.hook`);function bx(){let e=(0,Q.c)(9),t=Gi(),n=Ca(),r=X(Cx),i=X(Sx),a;e[0]!==t||e[1]!==r||e[2]!==n?(a=()=>{if(!r)return;let e=r,i=!1;return(async function(){if(n.getState().threadToolSessions[e]?.kind!==`create`)try{let r=await B(e);if(i)return;let a=Pa(e,{hasSession:xx,streamingStates:n.getState().threadStreamingStates});if(a||t({type:Y.SetMessages,messages:r.messages}),a)return;Le.invalidate(`processing-threads`);let o=await yr();if(i)return;t({type:Y.SetProcessingThreads,threadIds:o})}catch(n){let r=n;yx.error(`Failed to load chat history:`,r),i||(t({type:Y.SetMessages,messages:[]}),t({type:Y.ResetStream,threadId:e,paneId:`primary`}))}})(),()=>{i=!0}},e[0]=t,e[1]=r,e[2]=n,e[3]=a):a=e[3];let o;e[4]!==t||e[5]!==i||e[6]!==r||e[7]!==n?(o=[r,i,t,n],e[4]=t,e[5]=i,e[6]=r,e[7]=n,e[8]=o):o=e[8],(0,Z.useEffect)(a,o)}function xx(){return!1}function Sx(e){return e.selectedProjectId}function Cx(e){return e.selectedThreadId}function wx(){let e=(0,Q.c)(8),t=Gi(),n=Ca(),r=X(Tx),i=r?.messageId,a;e[0]===i?a=e[1]:(a=e=>i?e.messages.some(e=>e.messageId===i):!0,e[0]=i,e[1]=a);let o=X(a),s,c;e[2]!==t||e[3]!==o||e[4]!==r||e[5]!==n?(s=()=>{!r||o||t({type:Y.SetMessages,messages:[...n.getState().messages,La(r)]})},c=[r,o,t,n],e[2]=t,e[3]=o,e[4]=r,e[5]=n,e[6]=s,e[7]=c):(s=e[6],c=e[7]),(0,Z.useEffect)(s,c)}function Tx(e){if(!e.selectedThreadId)return null;let t=e.threadToolSessions[e.selectedThreadId];return t?.kind===`create`?t:null}var Ex=e=>{let t=(0,Q.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=K(`flex h-full w-full data-[panel-group-direction=vertical]:flex-col`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,$.jsx)(ti,{className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a},Dx=xi,Ox=e=>{let t=(0,Q.c)(12),n,r,i;t[0]===e?(n=t[1],r=t[2],i=t[3]):({withHandle:i,className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i);let a;t[4]===n?a=t[5]:(a=K(`relative flex w-px items-center justify-center bg-transparent after:absolute after:inset-y-0 after:left-1/2 after:w-1 after:-translate-x-1/2 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-1 data-[panel-group-direction=vertical]:h-px data-[panel-group-direction=vertical]:w-full data-[panel-group-direction=vertical]:after:left-0 data-[panel-group-direction=vertical]:after:h-1 data-[panel-group-direction=vertical]:after:w-full data-[panel-group-direction=vertical]:after:-translate-y-1/2 data-[panel-group-direction=vertical]:after:translate-x-0 [&[data-panel-group-direction=vertical]>div]:rotate-90`,n),t[4]=n,t[5]=a);let o;t[6]===i?o=t[7]:(o=i&&(0,$.jsx)(`div`,{className:`hidden z-10 flex h-4 w-3 items-center justify-center rounded-sm border bg-border`,children:(0,$.jsx)(Je,{className:`h-2.5 w-2.5`})}),t[6]=i,t[7]=o);let s;return t[8]!==r||t[9]!==a||t[10]!==o?(s=(0,$.jsx)(hi,{className:a,...r,children:o}),t[8]=r,t[9]=a,t[10]=o,t[11]=s):s=t[11],s},kx=(0,Z.lazy)(()=>po(()=>import(`./diff-view-DDECIdhE.js`),__vite__mapDeps([10,1,6,4,5,11,12,13,14,15,16,17]))),Ax=(0,Z.lazy)(()=>po(()=>import(`./dialogs-config-C2KFQf9x.js`).then(e=>e.t),__vite__mapDeps([4,1]))),jx=Pn(`chat.area`);function Mx(e){let t=(0,Q.c)(38),{onCreateThread:n}=e,r=Gi(),i=ua(),a=Oa(),[o,s]=(0,Z.useState)(!1),[c,l]=(0,Z.useState)(null),u=X(Nx),{isWidgetPanelOpen:d}=ux(),f=vx(),p;t[0]===r?p=t[1]:(p=()=>{r({type:Y.CloseSidebar})},t[0]=r,t[1]=p);let m=p,h;t[2]===m?h=t[3]:(h=()=>{m(),l(`clone`),s(!0)},t[2]=m,t[3]=h);let g=h,_;t[4]===m?_=t[5]:(_=()=>{m(),l(`webapp`),s(!0)},t[4]=m,t[5]=_);let v=_,y;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(y=async(e,t)=>{try{await Zt(e,t),s(!1),l(null)}catch(e){let t=e;jx.error(`Failed to clone repository`,{err:t})}},t[6]=y):y=t[6];let b=y,x;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(x=async(e,t,n)=>{try{await ln(e,t,n),s(!1),l(null)}catch(e){let t=e;jx.error(`Failed to create project`,{err:t})}},t[7]=x):x=t[7];let S=x,C;t[8]===m?C=t[9]:(C=async()=>{m();try{await De(),s(!1),l(null)}catch(e){let t=e;jx.error(`Failed to open folder`,{err:t})}},t[8]=m,t[9]=C);let w=C,T;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(T=async e=>{try{await Or(e),s(!1),l(null)}catch(e){let t=e;jx.error(`Failed to create folder`,{err:t})}},t[10]=T):T=t[10];let E=T,D=a.pathname===`/review`,O;t[11]===i?O=t[12]:(O=()=>{i(`/`)},t[11]=i,t[12]=O);let k=O;bx(),wx();let A=!D,j=A&&d&&!f,M;t[13]!==g||t[14]!==v||t[15]!==w||t[16]!==n||t[17]!==j?(M=(0,$.jsx)(Uy,{paneId:`primary`,fillPane:j,onCreateThread:n,showEmptyState:!0,hideInput:!0,onConnectRepo:g,onNewApp:v,onOpenFolder:w}),t[13]=g,t[14]=v,t[15]=w,t[16]=n,t[17]=j,t[18]=M):M=t[18];let N=M,P;t[19]!==N||t[20]!==A||t[21]!==j?(P=j?(0,$.jsxs)(Ex,{direction:`horizontal`,className:`h-full`,children:[(0,$.jsx)(Dx,{defaultSize:55,minSize:30,children:N}),(0,$.jsx)(Ox,{withHandle:!0}),(0,$.jsx)(Dx,{defaultSize:45,minSize:25,className:`border-l border-border`,children:(0,$.jsx)(gx,{})})]}):A?N:null,t[19]=N,t[20]=A,t[21]=j,t[22]=P):P=t[22];let F=P,I;t[23]!==F||t[24]!==k||t[25]!==D||t[26]!==u||t[27]!==A?(I=D&&u?(0,$.jsx)(Bc,{threadId:u,children:(0,$.jsx)(Z.Suspense,{fallback:(0,$.jsx)(Va,{}),children:(0,$.jsx)(kx,{threadId:u,onExit:k})})}):A?(0,$.jsx)(Kb,{children:F}):null,t[23]=F,t[24]=k,t[25]=D,t[26]=u,t[27]=A,t[28]=I):I=t[28];let L=c??void 0,R;t[29]!==o||t[30]!==L?(R=(0,$.jsx)(Z.Suspense,{fallback:null,children:(0,$.jsx)(Ax,{open:o,onOpenChange:s,initialMode:L,onSubmitClone:b,onSubmitWebApp:S,onSubmitFolder:E})}),t[29]=o,t[30]=L,t[31]=R):R=t[31];let z;t[32]!==I||t[33]!==R?(z=(0,$.jsxs)(`div`,{className:`relative flex h-full flex-col`,children:[I,R]}),t[32]=I,t[33]=R,t[34]=z):z=t[34];let B;return t[35]!==u||t[36]!==z?(B=(0,$.jsx)(Ju,{threadId:u,children:z}),t[35]=u,t[36]=z,t[37]=B):B=t[37],B}function Nx(e){return e.selectedThreadId}var Px=ci,Fx=Z.forwardRef((e,t)=>{let n=(0,Q.c)(9),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=K(`inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground`,r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,$.jsx)(ai,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});Fx.displayName=ai.displayName;var Ix=Z.forwardRef((e,t)=>{let n=(0,Q.c)(9),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=K(`inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-base font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-sm dark:data-[state=active]:bg-foreground dark:data-[state=active]:text-background`,r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,$.jsx)(pi,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});Ix.displayName=pi.displayName;var Lx=Z.forwardRef((e,t)=>{let n=(0,Q.c)(9),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=K(`mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2`,r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,$.jsx)(ni,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});Lx.displayName=ni.displayName;var Rx=Pn(`app.use-daily-spend.hook`);function zx(e=``){let[t,n]=(0,Z.useState)(0),[r,i]=(0,Z.useState)(0),[a,o]=(0,Z.useState)(0),[s,c]=(0,Z.useState)(0),[l,u]=(0,Z.useState)(0),[d,f]=(0,Z.useState)(0),[p,m]=(0,Z.useState)(0),[h,g]=(0,Z.useState)(0),[_,v]=(0,Z.useState)(0),[y,b]=(0,Z.useState)(0),[x,S]=(0,Z.useState)(0),[C,w]=(0,Z.useState)(0),[T,E]=(0,Z.useState)(0),[D,O]=(0,Z.useState)(0),[k,A]=(0,Z.useState)(0),[j,M]=(0,Z.useState)(0),[N,P]=(0,Z.useState)(!0),F=(0,Z.useCallback)(async function(){try{let e=await Et();n(e.today),i(e.last30Days),o(e.todayInputTokens),c(e.todayOutputTokens),u(e.last30DaysInputTokens),f(e.last30DaysOutputTokens),m(e.todayCacheReadTokens),g(e.todayCacheWriteTokens),v(e.last30DaysCacheReadTokens),b(e.last30DaysCacheWriteTokens),S(e.todayCacheReadCost),w(e.todayCacheWriteCost),E(e.last30DaysCacheReadCost),O(e.last30DaysCacheWriteCost),A(e.todayCompressionBytesSaved),M(e.last30DaysCompressionBytesSaved)}catch(e){Rx.error(`Failed to load daily spend summary`,e)}finally{P(!1)}},[]);return(0,Z.useEffect)(()=>{F()},[F,e]),{today:t,last30Days:r,todayInputTokens:a,todayOutputTokens:s,last30DaysInputTokens:l,last30DaysOutputTokens:d,todayCacheReadTokens:p,todayCacheWriteTokens:h,last30DaysCacheReadTokens:_,last30DaysCacheWriteTokens:y,todayCacheReadCost:x,todayCacheWriteCost:C,last30DaysCacheReadCost:T,last30DaysCacheWriteCost:D,todayCompressionBytesSaved:k,last30DaysCompressionBytesSaved:j,isLoading:N,refresh:F}}function Bx(){let e=(0,Q.c)(1),t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t={key:`showDailySpend`,defaultValue:!0,logScope:`app.use-show-daily-spend.hook`,settingLabel:`daily spend`},e[0]=t):t=e[0],Nm(t)}var Vx=Oi(e=>(0,$.jsxs)(`div`,{className:`space-y-1 pt-3`,children:[(0,$.jsx)(`div`,{className:e.v0,children:`Prompt cache`}),(0,$.jsxs)(`div`,{className:e.v1,children:[e.v2,` cache read /`,` `,e.v3,` cache write tokens ·`,` `,e.v4,` hit rate`]}),(0,$.jsxs)(`div`,{className:e.v5,children:[e.v6,` cache savings /`,` `,e.v7,` cache writes`]})]}),{name:`PromptCacheLast30DaysDetails_1`,portals:[`v2`,`v3`,`v4`,`v6`,`v7`]}),Hx=function(e){let t=(0,Q.c)(26),{last30DaysInputTokens:n,last30DaysCacheReadTokens:r,last30DaysCacheWriteTokens:i,last30DaysCacheReadCost:a,last30DaysCacheWriteCost:o}=e,s,c,l,u,d,f;if(t[0]!==r||t[1]!==i||t[2]!==n){let e=Jx(r,n);s=Vx,c=J.label,l=J.bodyMuted,t[9]===r?u=t[10]:(u=vn(r),t[9]=r,t[10]=u),t[11]===i?d=t[12]:(d=vn(i),t[11]=i,t[12]=d),f=qx(e),t[0]=r,t[1]=i,t[2]=n,t[3]=s,t[4]=c,t[5]=l,t[6]=u,t[7]=d,t[8]=f}else s=t[3],c=t[4],l=t[5],u=t[6],d=t[7],f=t[8];let p;t[13]===a?p=t[14]:(p=Hn(a),t[13]=a,t[14]=p);let m;t[15]===o?m=t[16]:(m=Hn(o),t[15]=o,t[16]=m);let h;return t[17]!==s||t[18]!==c||t[19]!==l||t[20]!==u||t[21]!==d||t[22]!==f||t[23]!==p||t[24]!==m?(h=(0,$.jsx)(s,{v0:c,v1:l,v2:u,v3:d,v4:f,v5:J.bodyMuted,v6:p,v7:m}),t[17]=s,t[18]=c,t[19]=l,t[20]=u,t[21]=d,t[22]=f,t[23]=p,t[24]=m,t[25]=h):h=t[25],h},Ux=Oi(e=>(0,$.jsxs)(`div`,{className:`space-y-1 pt-3`,children:[(0,$.jsx)(`div`,{className:e.v0,children:`Prompt cache`}),(0,$.jsxs)(`div`,{className:e.v1,children:[e.v2,` cache read /`,` `,e.v3,` cache write tokens ·`,` `,e.v4,` hit rate`]}),(0,$.jsxs)(`div`,{className:e.v5,children:[e.v6,` cache savings /`,` `,e.v7,` cache writes`]})]}),{name:`PromptCacheTodayDetails_1`,portals:[`v2`,`v3`,`v4`,`v6`,`v7`]}),Wx=function(e){let t=(0,Q.c)(26),{todayInputTokens:n,todayCacheReadTokens:r,todayCacheWriteTokens:i,todayCacheReadCost:a,todayCacheWriteCost:o}=e,s,c,l,u,d,f;if(t[0]!==r||t[1]!==i||t[2]!==n){let e=Jx(r,n);s=Ux,c=J.label,l=J.bodyMuted,t[9]===r?u=t[10]:(u=vn(r),t[9]=r,t[10]=u),t[11]===i?d=t[12]:(d=vn(i),t[11]=i,t[12]=d),f=qx(e),t[0]=r,t[1]=i,t[2]=n,t[3]=s,t[4]=c,t[5]=l,t[6]=u,t[7]=d,t[8]=f}else s=t[3],c=t[4],l=t[5],u=t[6],d=t[7],f=t[8];let p;t[13]===a?p=t[14]:(p=Hn(a),t[13]=a,t[14]=p);let m;t[15]===o?m=t[16]:(m=Hn(o),t[15]=o,t[16]=m);let h;return t[17]!==s||t[18]!==c||t[19]!==l||t[20]!==u||t[21]!==d||t[22]!==f||t[23]!==p||t[24]!==m?(h=(0,$.jsx)(s,{v0:c,v1:l,v2:u,v3:d,v4:f,v5:J.bodyMuted,v6:p,v7:m}),t[17]=s,t[18]=c,t[19]=l,t[20]=u,t[21]=d,t[22]=f,t[23]=p,t[24]=m,t[25]=h):h=t[25],h},Gx=`h-auto rounded-full border bg-muted/40`,Kx=`rounded-full px-4 data-[state=active]:bg-foreground data-[state=active]:text-background data-[state=active]:shadow-sm`;function qx(e){return!Number.isFinite(e)||e<=0?`0%`:`${(e*100).toFixed(1)}%`}function Jx(e,t){let n=e+t;return n<=0?0:e/n}function Yx(e){let t=(0,Q.c)(21),{todayLabel:n,todayInputTokens:r,todayOutputTokens:i,todayCacheReadTokens:a,todayCacheWriteTokens:o,todayCacheReadCost:s,todayCacheWriteCost:c,todayCompressionBytesSaved:l}=e,u=r>0||i>0||a>0||o>0,d=a>0||o>0||s>0||c>0,f=l>0,p;t[0]===n?p=t[1]:(p=(0,$.jsx)(`div`,{className:`space-y-1`,children:(0,$.jsxs)(`div`,{children:[n,` spent`]})}),t[0]=n,t[1]=p);let m;t[2]!==u||t[3]!==r||t[4]!==i?(m=u?(0,$.jsxs)(`div`,{className:`space-y-1 pt-3`,children:[(0,$.jsx)(`div`,{className:J.label,children:`Tokens`}),(0,$.jsxs)(`div`,{className:J.bodyMuted,children:[vn(r),` input / `,vn(i),` `,`output tokens`]})]}):null,t[2]=u,t[3]=r,t[4]=i,t[5]=m):m=t[5];let h;t[6]!==d||t[7]!==s||t[8]!==a||t[9]!==c||t[10]!==o||t[11]!==r?(h=d?(0,$.jsx)(Wx,{todayInputTokens:r,todayCacheReadTokens:a,todayCacheWriteTokens:o,todayCacheReadCost:s,todayCacheWriteCost:c}):null,t[6]=d,t[7]=s,t[8]=a,t[9]=c,t[10]=o,t[11]=r,t[12]=h):h=t[12];let g;t[13]!==f||t[14]!==l?(g=f?(0,$.jsxs)(`div`,{className:`space-y-1 pt-3`,children:[(0,$.jsx)(`div`,{className:J.label,children:`Tool output compression`}),(0,$.jsxs)(`div`,{className:J.bodyMuted,children:[$n(l),` saved`]})]}):null,t[13]=f,t[14]=l,t[15]=g):g=t[15];let _;return t[16]!==p||t[17]!==m||t[18]!==h||t[19]!==g?(_=(0,$.jsxs)(`div`,{className:`space-y-4`,children:[p,m,h,g]}),t[16]=p,t[17]=m,t[18]=h,t[19]=g,t[20]=_):_=t[20],_}function Xx(e){let t=(0,Q.c)(22),{last30DaysLabel:n,averagePerDayLabel:r,last30DaysInputTokens:i,last30DaysOutputTokens:a,last30DaysCacheReadTokens:o,last30DaysCacheWriteTokens:s,last30DaysCacheReadCost:c,last30DaysCacheWriteCost:l,last30DaysCompressionBytesSaved:u}=e,d=i>0||a>0||o>0||s>0,f=o>0||s>0||c>0||l>0,p=u>0,m;t[0]!==r||t[1]!==n?(m=(0,$.jsx)(`div`,{className:`space-y-1`,children:(0,$.jsxs)(`div`,{children:[n,` spent · `,r,`/day average`]})}),t[0]=r,t[1]=n,t[2]=m):m=t[2];let h;t[3]!==d||t[4]!==i||t[5]!==a?(h=d?(0,$.jsxs)(`div`,{className:`space-y-1 pt-3`,children:[(0,$.jsx)(`div`,{className:J.label,children:`Tokens`}),(0,$.jsxs)(`div`,{className:J.bodyMuted,children:[vn(i),` input /`,` `,vn(a),` output tokens`]})]}):null,t[3]=d,t[4]=i,t[5]=a,t[6]=h):h=t[6];let g;t[7]!==f||t[8]!==c||t[9]!==o||t[10]!==l||t[11]!==s||t[12]!==i?(g=f?(0,$.jsx)(Hx,{last30DaysInputTokens:i,last30DaysCacheReadTokens:o,last30DaysCacheWriteTokens:s,last30DaysCacheReadCost:c,last30DaysCacheWriteCost:l}):null,t[7]=f,t[8]=c,t[9]=o,t[10]=l,t[11]=s,t[12]=i,t[13]=g):g=t[13];let _;t[14]!==p||t[15]!==u?(_=p?(0,$.jsxs)(`div`,{className:`space-y-1 pt-3`,children:[(0,$.jsx)(`div`,{className:J.label,children:`Tool output compression`}),(0,$.jsxs)(`div`,{className:J.bodyMuted,children:[$n(u),` saved`]})]}):null,t[14]=p,t[15]=u,t[16]=_):_=t[16];let v;return t[17]!==m||t[18]!==h||t[19]!==g||t[20]!==_?(v=(0,$.jsxs)(`div`,{className:`space-y-4`,children:[m,h,g,_]}),t[17]=m,t[18]=h,t[19]=g,t[20]=_,t[21]=v):v=t[21],v}function Zx(){let e=(0,Q.c)(56),t=X(Qx),n;e[0]===t?n=e[1]:(n=t.join(`,`),e[0]=t,e[1]=n);let r=n,{isEnabled:i,isLoading:a}=Bx(),{today:o,last30Days:s,todayInputTokens:c,todayOutputTokens:l,last30DaysInputTokens:u,last30DaysOutputTokens:d,todayCacheReadTokens:f,todayCacheWriteTokens:p,last30DaysCacheReadTokens:m,last30DaysCacheWriteTokens:h,todayCacheReadCost:g,todayCacheWriteCost:_,last30DaysCacheReadCost:v,last30DaysCacheWriteCost:y,todayCompressionBytesSaved:b,last30DaysCompressionBytesSaved:x,isLoading:S}=zx(r),[C,w]=(0,Z.useState)(!1);if(!i||a||S||o===0)return null;let T=s/30,E;e[2]===o?E=e[3]:(E=Hn(o),e[2]=o,e[3]=E);let D=E,O;e[4]===s?O=e[5]:(O=Hn(s),e[4]=s,e[5]=O);let k=O,A;e[6]===T?A=e[7]:(A=Hn(T),e[6]=T,e[7]=A);let j=A,M,N;e[8]===Symbol.for(`react.memo_cache_sentinel`)?(M=K(J.compact,`inline-flex items-center pl-2 pr-2 font-mono tabular-nums electrobun-webkit-app-region-no-drag cursor-pointer rounded-sm text-foreground transition-colors hover:text-foreground/80`),N=()=>w(!0),e[8]=M,e[9]=N):(M=e[8],N=e[9]);let P;e[10]===Symbol.for(`react.memo_cache_sentinel`)?(P=(0,$.jsx)(`span`,{className:`sr-only`,children:`View daily spend details`}),e[10]=P):P=e[10];let F;e[11]===D?F=e[12]:(F=(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,className:M,onClick:N,children:[D,P]})}),e[11]=D,e[12]=F);let I;e[13]===D?I=e[14]:(I=(0,$.jsxs)(`div`,{children:[D,` spent today`]}),e[13]=D,e[14]=I);let L;e[15]===k?L=e[16]:(L=(0,$.jsxs)(`div`,{children:[k,` spend last 30 days`]}),e[15]=k,e[16]=L);let R;e[17]===j?R=e[18]:(R=(0,$.jsxs)(`div`,{children:[j,` average per day`]}),e[17]=j,e[18]=R);let z;e[19]!==R||e[20]!==I||e[21]!==L?(z=(0,$.jsxs)(Qa,{className:`space-y-1`,children:[I,L,R]}),e[19]=R,e[20]=I,e[21]=L,e[22]=z):z=e[22];let B;e[23]!==z||e[24]!==F?(B=(0,$.jsx)(Ti,{children:(0,$.jsxs)(sa,{children:[F,z]})}),e[23]=z,e[24]=F,e[25]=B):B=e[25];let ee;e[26]===Symbol.for(`react.memo_cache_sentinel`)?(ee=(0,$.jsx)(_n,{children:(0,$.jsx)(un,{children:`Daily Spend`})}),e[26]=ee):ee=e[26];let te;e[27]===Symbol.for(`react.memo_cache_sentinel`)?(te=(0,$.jsxs)(Fx,{className:Gx,children:[(0,$.jsx)(Ix,{value:`today`,className:Kx,children:`Today`}),(0,$.jsx)(Ix,{value:`last30Days`,className:Kx,children:`Last 30 Days`})]}),e[27]=te):te=e[27];let ne;e[28]!==g||e[29]!==f||e[30]!==_||e[31]!==p||e[32]!==b||e[33]!==c||e[34]!==D||e[35]!==l?(ne=(0,$.jsx)(Lx,{value:`today`,className:`h-[400px] max-h-[90vh] overflow-y-auto`,children:(0,$.jsx)(Yx,{todayLabel:D,todayInputTokens:c,todayOutputTokens:l,todayCacheReadTokens:f,todayCacheWriteTokens:p,todayCacheReadCost:g,todayCacheWriteCost:_,todayCompressionBytesSaved:b})}),e[28]=g,e[29]=f,e[30]=_,e[31]=p,e[32]=b,e[33]=c,e[34]=D,e[35]=l,e[36]=ne):ne=e[36];let re;e[37]!==j||e[38]!==v||e[39]!==m||e[40]!==y||e[41]!==h||e[42]!==x||e[43]!==u||e[44]!==k||e[45]!==d?(re=(0,$.jsx)(Lx,{value:`last30Days`,className:`h-[400px] max-h-[90vh] overflow-y-auto`,children:(0,$.jsx)(Xx,{last30DaysLabel:k,averagePerDayLabel:j,last30DaysInputTokens:u,last30DaysOutputTokens:d,last30DaysCacheReadTokens:m,last30DaysCacheWriteTokens:h,last30DaysCacheReadCost:v,last30DaysCacheWriteCost:y,last30DaysCompressionBytesSaved:x})}),e[37]=j,e[38]=v,e[39]=m,e[40]=y,e[41]=h,e[42]=x,e[43]=u,e[44]=k,e[45]=d,e[46]=re):re=e[46];let ie;e[47]!==ne||e[48]!==re?(ie=(0,$.jsxs)(tn,{className:`max-w-xl`,children:[ee,(0,$.jsxs)(Px,{defaultValue:`today`,className:`h-[400px] max-h-[90vh]`,children:[te,ne,re]})]}),e[47]=ne,e[48]=re,e[49]=ie):ie=e[49];let ae;e[50]!==C||e[51]!==ie?(ae=(0,$.jsx)(Cr,{open:C,onOpenChange:w,children:ie}),e[50]=C,e[51]=ie,e[52]=ae):ae=e[52];let oe;return e[53]!==B||e[54]!==ae?(oe=(0,$.jsxs)($.Fragment,{children:[B,ae]}),e[53]=B,e[54]=ae,e[55]=oe):oe=e[55],oe}function Qx(e){return e.completedThreadIds}function $x(){let e=(0,Q.c)(15),{resolvedTheme:t,setTheme:n}=jo(),r=t===`dark`,i;e[0]!==r||e[1]!==n?(i=function(){n(r?`light`:`dark`)},e[0]=r,e[1]=n,e[2]=i):i=e[2];let a=i,o;e[3]===Symbol.for(`react.memo_cache_sentinel`)?(o=K(`h-8 w-8 shrink-0 scenic-foreground-muted hover:scenic-foreground electrobun-webkit-app-region-no-drag`),e[3]=o):o=e[3];let s=r?`Switch to light mode`:`Switch to dark mode`,c;e[4]===r?c=e[5]:(c=r?(0,$.jsx)(We,{className:`h-4 w-4`}):(0,$.jsx)(cr,{className:`h-4 w-4`}),e[4]=r,e[5]=c);let l;e[6]!==a||e[7]!==s||e[8]!==c?(l=(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsx)(Fe,{variant:`ghost`,size:`icon`,className:o,onClick:a,"aria-label":s,children:c})}),e[6]=a,e[7]=s,e[8]=c,e[9]=l):l=e[9];let u=r?`Light mode`:`Dark mode`,d;e[10]===u?d=e[11]:(d=(0,$.jsx)(Qa,{children:u}),e[10]=u,e[11]=d);let f;return e[12]!==l||e[13]!==d?(f=(0,$.jsxs)(sa,{children:[l,d]}),e[12]=l,e[13]=d,e[14]=f):f=e[14],f}function eS(e){let t=(0,Q.c)(47),{open:n,onOpenChange:r,feedbackName:i,onFeedbackNameChange:a,feedbackEmail:o,onFeedbackEmailChange:s,feedbackText:c,onFeedbackTextChange:l,loadingFeedbackUser:u,submittingFeedback:d,onSubmit:f}=e,p;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,$.jsxs)(_n,{children:[(0,$.jsx)(un,{children:`Send Feedback`}),(0,$.jsx)(Qn,{children:`Share feedback about Tarsk.`})]}),t[0]=p):p=t[0];let m;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,$.jsx)(dr,{htmlFor:`feedback-name`,children:`Name`}),t[1]=m):m=t[1];let h;t[2]===a?h=t[3]:(h=e=>a(e.target.value),t[2]=a,t[3]=h);let g=d||u,_;t[4]!==i||t[5]!==h||t[6]!==g?(_=(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[m,(0,$.jsx)(Lt,{id:`feedback-name`,value:i,onChange:h,placeholder:`Your name`,disabled:g})]}),t[4]=i,t[5]=h,t[6]=g,t[7]=_):_=t[7];let v;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,$.jsx)(dr,{htmlFor:`feedback-email`,children:`Email`}),t[8]=v):v=t[8];let y;t[9]===s?y=t[10]:(y=e=>s(e.target.value),t[9]=s,t[10]=y);let b=d||u,x;t[11]!==o||t[12]!==y||t[13]!==b?(x=(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[v,(0,$.jsx)(Lt,{id:`feedback-email`,type:`email`,value:o,onChange:y,placeholder:`you@example.com`,disabled:b})]}),t[11]=o,t[12]=y,t[13]=b,t[14]=x):x=t[14];let S;t[15]===Symbol.for(`react.memo_cache_sentinel`)?(S=(0,$.jsx)(dr,{htmlFor:`feedback-text`,children:`Feedback`}),t[15]=S):S=t[15];let C;t[16]===l?C=t[17]:(C=e=>l(e.target.value),t[16]=l,t[17]=C);let w;t[18]!==c||t[19]!==d||t[20]!==C?(w=(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[S,(0,$.jsx)(Wh,{id:`feedback-text`,value:c,onChange:C,placeholder:`Tell us what you think...`,className:`min-h-32`,disabled:d})]}),t[18]=c,t[19]=d,t[20]=C,t[21]=w):w=t[21];let T;t[22]!==w||t[23]!==_||t[24]!==x?(T=(0,$.jsxs)(`div`,{className:`grid gap-4 py-2`,children:[_,x,w]}),t[22]=w,t[23]=_,t[24]=x,t[25]=T):T=t[25];let E;t[26]===r?E=t[27]:(E=()=>r(!1),t[26]=r,t[27]=E);let D;t[28]!==d||t[29]!==E?(D=(0,$.jsx)(Fe,{variant:`outline`,onClick:E,disabled:d,children:`Cancel`}),t[28]=d,t[29]=E,t[30]=D):D=t[30];let O;t[31]===d?O=t[32]:(O=d?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(sn,{className:`mr-2 h-4 w-4 animate-spin`}),`Sending...`]}):`Send`,t[31]=d,t[32]=O);let k;t[33]!==f||t[34]!==d||t[35]!==O?(k=(0,$.jsx)(Fe,{onClick:f,disabled:d,children:O}),t[33]=f,t[34]=d,t[35]=O,t[36]=k):k=t[36];let A;t[37]!==D||t[38]!==k?(A=(0,$.jsxs)(Bn,{children:[D,k]}),t[37]=D,t[38]=k,t[39]=A):A=t[39];let j;t[40]!==T||t[41]!==A?(j=(0,$.jsxs)(tn,{className:`max-w-xl max-md:top-[max(1rem,env(safe-area-inset-top,0px))] max-md:max-h-[calc(100dvh-2rem)] max-md:translate-y-0 max-md:overflow-y-auto max-md:data-[state=closed]:slide-out-to-top max-md:data-[state=open]:slide-in-from-top max-md:data-[state=closed]:slide-out-to-left-0 max-md:data-[state=open]:slide-in-from-left-0 max-md:data-[state=closed]:zoom-out-100 max-md:data-[state=open]:zoom-in-100`,children:[p,T,A]}),t[40]=T,t[41]=A,t[42]=j):j=t[42];let M;return t[43]!==r||t[44]!==n||t[45]!==j?(M=(0,$.jsx)(Cr,{open:n,onOpenChange:r,children:j}),t[43]=r,t[44]=n,t[45]=j,t[46]=M):M=t[46],M}function tS({open:e,onOpenChange:t}){let[n,r]=(0,Z.useState)([]),[i,a]=(0,Z.useState)(null),[o,s]=(0,Z.useState)(!1),[c,l]=(0,Z.useState)(!1);(0,Z.useEffect)(()=>{if(!e){a(null);return}let t=!1;return s(!0),rt().then(e=>{t||r(e)}).catch(()=>{t||(r([]),Ri({title:`Unable to load processes`,description:`The CLI process list could not be loaded.`,variant:`destructive`}))}).finally(()=>{t||s(!1)}),()=>{t=!0}},[e]);async function u(){if(i){l(!0);try{await O(i),r(e=>e.filter(e=>e.id!==i)),a(null)}catch{Ri({title:`Unable to kill process`,description:`The process may have already exited.`,variant:`destructive`}),r(await rt().catch(()=>[])),a(null)}finally{l(!1)}}}return(0,$.jsx)(Cr,{open:e,onOpenChange:t,children:(0,$.jsxs)(tn,{children:[(0,$.jsxs)(_n,{children:[(0,$.jsx)(un,{children:`Processes`}),(0,$.jsx)(Qn,{children:`Select a process started by Tarsk to terminate it.`})]}),(0,$.jsx)(`div`,{className:`max-h-80 overflow-y-auto rounded-md border`,role:`listbox`,children:o?(0,$.jsxs)(`div`,{className:K(J.bodyMuted,`flex items-center justify-center gap-2 py-10`),children:[(0,$.jsx)(sn,{className:`h-4 w-4 animate-spin`}),`Loading processes...`]}):n.length===0?(0,$.jsx)(`div`,{className:K(J.bodyMuted,`py-10 text-center`),children:`No processes started by Tarsk are running.`}):n.map(e=>{let t=e.id===i;return(0,$.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":t,className:K(`flex w-full flex-col gap-1 border-b px-4 py-3 text-left transition-colors last:border-b-0`,t?`bg-accent text-accent-foreground`:`can-hover:hover:bg-muted/50`),onClick:()=>a(e.id),children:[(0,$.jsx)(`span`,{className:K(J.label,`break-all font-mono`),children:e.command}),(0,$.jsxs)(`span`,{className:K(J.caption,`break-all`),children:[`PID `,e.pid,e.cwd?` · ${e.cwd}`:``]})]},e.id)})}),(0,$.jsx)(Bn,{children:(0,$.jsx)(Fe,{variant:`destructive`,disabled:!i||o||c,onClick:()=>void u(),children:c?`Killing...`:`Kill`})})]})})}function nS(){let[e,t]=(0,Z.useState)(!1),[n,r]=(0,Z.useState)(``),[i,a]=(0,Z.useState)(``),[o,s]=(0,Z.useState)(``),[c,l]=(0,Z.useState)(!1),[u,d]=(0,Z.useState)(!1);return(0,Z.useEffect)(()=>{if(!e)return;let t=!0;return l(!0),ue().then(e=>{t&&(r(t=>t||e.name),a(t=>t||e.email))}).catch(()=>{t&&Ri({title:`Could not load git details`,description:`You can still submit feedback by entering your name and email manually.`,variant:`destructive`})}).finally(()=>{t&&l(!1)}),()=>{t=!1}},[e]),{showFeedback:e,feedbackName:n,setFeedbackName:r,feedbackEmail:i,setFeedbackEmail:a,feedbackText:o,setFeedbackText:s,loadingFeedbackUser:c,submittingFeedback:u,handleFeedbackDialogChange:e=>{t(e),e||s(``)},handleSubmitFeedback:async()=>{let e=o.trim();if(!e){Ri({title:`Feedback required`,description:`Please enter your feedback before submitting.`,variant:`destructive`});return}d(!0);try{await kt(`api/feedback`,{name:n.trim(),email:i.trim(),feedback:e}),Ri({title:`Feedback sent`,description:`Thanks for sharing your feedback.`}),s(``),t(!1)}catch(e){Ri({title:`Failed to send feedback`,description:e instanceof Error?e.message:`Please try again.`,variant:`destructive`})}finally{d(!1)}}}}function rS(){let e=(0,Q.c)(90),t=ua(),n=Gi(),r=uh(),{openConversation:a}=Fa(),o=X(aS),s=X(iS),[c,l]=(0,Z.useState)(!1),[u,d]=(0,Z.useState)(!1),f;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(f=[],e[0]=f):f=e[0];let[p,m]=(0,Z.useState)(f),[h,g]=(0,Z.useState)(!1),[_,v]=(0,Z.useState)(!1),{showFeedback:y,feedbackName:b,setFeedbackName:x,feedbackEmail:S,setFeedbackEmail:C,feedbackText:w,setFeedbackText:T,loadingFeedbackUser:E,submittingFeedback:D,handleFeedbackDialogChange:O,handleSubmitFeedback:k}=nS(),A;if(e[1]!==s||e[2]!==o){let t;e[4]===o?t=e[5]:(t=e=>e.projectId===o,e[4]=o,e[5]=t),A=s.find(t),e[1]=s,e[2]=o,e[3]=A}else A=e[3];let j=A,M;e[6]===j?.commands?M=e[7]:(M=j?.commands??[],e[6]=j?.commands,e[7]=M);let N=M,P;if(e[8]!==h){let t=function(){h||tr(20).then(e=>{m(e.conversations??[]),g(!0)}).catch(()=>{g(!1)})};P=function(e){v(e),e&&t()},e[8]=h,e[9]=P}else P=e[9];let F=P,I=r?`ghost`:`outline`,L=r?`text-foreground`:`border-transparent`,R;e[10]===L?R=e[11]:(R=K(`h-8 w-8 px-0`,L),e[10]=L,e[11]=R);let z;e[12]===Symbol.for(`react.memo_cache_sentinel`)?(z=(0,$.jsx)(vt,{className:`h-4 w-4`}),e[12]=z):z=e[12];let B;e[13]!==I||e[14]!==R?(B=(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsx)(Ji,{asChild:!0,children:(0,$.jsx)(Fe,{variant:I,size:`sm`,className:R,"aria-label":`More options`,children:z})})}),e[13]=I,e[14]=R,e[15]=B):B=e[15];let ee;e[16]===Symbol.for(`react.memo_cache_sentinel`)?(ee=(0,$.jsx)(Qa,{children:`More options`}),e[16]=ee):ee=e[16];let te;e[17]===B?te=e[18]:(te=(0,$.jsxs)(sa,{children:[B,ee]}),e[17]=B,e[18]=te);let ne;e[19]!==F||e[20]!==h||e[21]!==_||e[22]!==t||e[23]!==a||e[24]!==p||e[25]!==o?(ne=o?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(_a,{}),(0,$.jsx)(Ui,{className:J.body,children:`Project`}),(0,$.jsxs)(ya,{className:K(J.body,`gap-2`),onSelect:()=>void t(`/settings/project/${o}`),children:[(0,$.jsx)(me,{className:`h-4 w-4 shrink-0`}),`Settings`]}),(0,$.jsxs)(ya,{className:K(J.body,`gap-2`),onSelect:()=>l(!0),children:[(0,$.jsx)(xe,{className:`h-4 w-4 shrink-0`}),`Commands`]}),(0,$.jsxs)(Bi,{open:_,onOpenChange:F,children:[(0,$.jsxs)(oo,{className:K(J.body,`gap-2`),children:[(0,$.jsx)(Ft,{className:`h-4 w-4 shrink-0`}),`History`]}),(0,$.jsx)(Zi,{className:`w-96 max-h-80 overflow-y-auto`,children:h?p.length===0?(0,$.jsx)(ya,{disabled:!0,className:J.bodyMuted,children:`No recent conversations`}):p.map(e=>(0,$.jsxs)(ya,{className:K(J.body,`gap-2 cursor-pointer`),onSelect:()=>a(e),children:[(0,$.jsx)(Vt,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`truncate`,children:e.title}),(0,$.jsx)(`span`,{className:K(J.bodyMuted,`ml-auto shrink-0 tabular-nums`),children:Kn(e.lastMessageAt)})]},e.conversationId)):(0,$.jsx)(ya,{disabled:!0,className:J.bodyMuted,children:`Loading...`})})]})]}):null,e[19]=F,e[20]=h,e[21]=_,e[22]=t,e[23]=a,e[24]=p,e[25]=o,e[26]=ne):ne=e[26];let re,ie;e[27]===Symbol.for(`react.memo_cache_sentinel`)?(re=(0,$.jsx)(_a,{}),ie=(0,$.jsx)(Ui,{className:J.body,children:`General`}),e[27]=re,e[28]=ie):(re=e[27],ie=e[28]);let ae;e[29]===Symbol.for(`react.memo_cache_sentinel`)?(ae=K(J.body,`gap-2`),e[29]=ae):ae=e[29];let oe;e[30]===t?oe=e[31]:(oe=()=>void t(`/settings/providers`),e[30]=t,e[31]=oe);let se;e[32]===Symbol.for(`react.memo_cache_sentinel`)?(se=(0,$.jsx)(i,{className:`h-4 w-4 shrink-0`}),e[32]=se):se=e[32];let ce;e[33]===oe?ce=e[34]:(ce=(0,$.jsxs)(ya,{className:ae,onSelect:oe,children:[se,`Providers`]}),e[33]=oe,e[34]=ce);let le;e[35]===Symbol.for(`react.memo_cache_sentinel`)?(le=K(J.body,`gap-2`),e[35]=le):le=e[35];let ue;e[36]===t?ue=e[37]:(ue=()=>void t(`/settings/general`),e[36]=t,e[37]=ue);let de;e[38]===Symbol.for(`react.memo_cache_sentinel`)?(de=(0,$.jsx)(me,{className:`h-4 w-4 shrink-0`}),e[38]=de):de=e[38];let fe;e[39]===ue?fe=e[40]:(fe=(0,$.jsxs)(ya,{className:le,onSelect:ue,children:[de,`Settings`]}),e[39]=ue,e[40]=fe);let pe;e[41]===Symbol.for(`react.memo_cache_sentinel`)?(pe=K(J.body,`gap-2`),e[41]=pe):pe=e[41];let V;e[42]===t?V=e[43]:(V=()=>void t(`/settings/account`),e[42]=t,e[43]=V);let he;e[44]===Symbol.for(`react.memo_cache_sentinel`)?(he=(0,$.jsx)(Vn,{className:`h-4 w-4 shrink-0`}),e[44]=he):he=e[44];let ge;e[45]===V?ge=e[46]:(ge=(0,$.jsxs)(ya,{className:pe,onSelect:V,children:[he,`Account`]}),e[45]=V,e[46]=ge);let _e;e[47]===Symbol.for(`react.memo_cache_sentinel`)?(_e=K(J.body,`gap-2`),e[47]=_e):_e=e[47];let ve;e[48]===O?ve=e[49]:(ve=()=>O(!0),e[48]=O,e[49]=ve);let ye;e[50]===Symbol.for(`react.memo_cache_sentinel`)?(ye=(0,$.jsx)(Vt,{className:`h-4 w-4 shrink-0`}),e[50]=ye):ye=e[50];let be;e[51]===ve?be=e[52]:(be=(0,$.jsxs)(ya,{className:_e,onSelect:ve,children:[ye,`Feedback`]}),e[51]=ve,e[52]=be);let Se;e[53]===Symbol.for(`react.memo_cache_sentinel`)?(Se=(0,$.jsx)(_a,{}),e[53]=Se):Se=e[53];let Ce;e[54]===Symbol.for(`react.memo_cache_sentinel`)?(Ce=(0,$.jsxs)(ya,{className:K(J.body,`gap-2`),onSelect:()=>d(!0),children:[(0,$.jsx)(It,{className:`h-4 w-4 shrink-0`}),`Processes`]}),e[54]=Ce):Ce=e[54];let we;e[55]!==ne||e[56]!==ce||e[57]!==fe||e[58]!==ge||e[59]!==be?(we=(0,$.jsxs)(Ei,{align:`end`,className:`w-52`,children:[ne,re,ie,ce,fe,ge,be,Se,Ce]}),e[55]=ne,e[56]=ce,e[57]=fe,e[58]=ge,e[59]=be,e[60]=we):we=e[60];let Te;e[61]!==te||e[62]!==we?(Te=(0,$.jsxs)(fa,{children:[te,we]}),e[61]=te,e[62]=we,e[63]=Te):Te=e[63];let H;e[64]!==N||e[65]!==n||e[66]!==o||e[67]!==c?(H=o?(0,$.jsx)(qh,{open:c,onOpenChange:l,projectId:o,commands:N,onRefresh:()=>n({type:Y.ConfigUpdated})}):null,e[64]=N,e[65]=n,e[66]=o,e[67]=c,e[68]=H):H=e[68];let Ee;e[69]===u?Ee=e[70]:(Ee=(0,$.jsx)(tS,{open:u,onOpenChange:d}),e[69]=u,e[70]=Ee);let De;e[71]===k?De=e[72]:(De=()=>void k(),e[71]=k,e[72]=De);let Oe;e[73]!==S||e[74]!==b||e[75]!==w||e[76]!==O||e[77]!==E||e[78]!==C||e[79]!==x||e[80]!==T||e[81]!==y||e[82]!==D||e[83]!==De?(Oe=(0,$.jsx)(eS,{open:y,onOpenChange:O,feedbackName:b,onFeedbackNameChange:x,feedbackEmail:S,onFeedbackEmailChange:C,feedbackText:w,onFeedbackTextChange:T,loadingFeedbackUser:E,submittingFeedback:D,onSubmit:De}),e[73]=S,e[74]=b,e[75]=w,e[76]=O,e[77]=E,e[78]=C,e[79]=x,e[80]=T,e[81]=y,e[82]=D,e[83]=De,e[84]=Oe):Oe=e[84];let ke;return e[85]!==Te||e[86]!==H||e[87]!==Ee||e[88]!==Oe?(ke=(0,$.jsxs)($.Fragment,{children:[Te,H,Ee,Oe]}),e[85]=Te,e[86]=H,e[87]=Ee,e[88]=Oe,e[89]=ke):ke=e[89],ke}function iS(e){return e.projects}function aS(e){return e.selectedProjectId}function oS(e){let t=(0,Q.c)(3),{children:n,className:r}=e,i=`flex items-center gap-2 rounded-full shadow-md ${r===void 0?``:r}`,a;return t[0]!==n||t[1]!==i?(a=(0,$.jsx)(`div`,{className:i,children:n}),t[0]=n,t[1]=i,t[2]=a):a=t[2],a}var sS;(function(e){e.Heavy=`HEAVY`,e.Medium=`MEDIUM`,e.Light=`LIGHT`})(sS||={});var cS;(function(e){e.Success=`SUCCESS`,e.Warning=`WARNING`,e.Error=`ERROR`})(cS||={});var lS=f_(`Haptics`,{web:()=>po(()=>import(`./web-CiaJzwav.js`).then(e=>new e.HapticsWeb),[])});function uS(){return typeof window<`u`&&q()}function dS(e=sS.Medium){uS()&&lS.impact({style:e}).catch(()=>{})}function fS(e){let t=(0,Q.c)(12),{className:n}=e,r=ua(),i;t[0]===n?i=t[1]:(i=K(`h-8 w-8 text-muted-foreground shrink-0`,n),t[0]=n,t[1]=i);let a;t[2]===r?a=t[3]:(a=()=>void r(`/settings/general`),t[2]=r,t[3]=a);let o,s;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,$.jsx)(me,{className:`h-4 w-4`}),s=(0,$.jsx)(`span`,{className:`sr-only`,children:`Settings`}),t[4]=o,t[5]=s):(o=t[4],s=t[5]);let c;t[6]!==i||t[7]!==a?(c=(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsxs)(Fe,{variant:`ghost`,size:`icon`,className:i,onClick:a,children:[o,s]})}),t[6]=i,t[7]=a,t[8]=c):c=t[8];let l;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,$.jsx)(Qa,{children:`Settings`}),t[9]=l):l=t[9];let u;return t[10]===c?u=t[11]:(u=(0,$.jsx)(Ti,{children:(0,$.jsxs)(sa,{children:[c,l]})}),t[10]=c,t[11]=u),u}function pS(e){let t=(0,Q.c)(68),{onBackToProjects:n,onSelectProject:r}=e,i=uh(),a=X(vS),o=X(_S),s=X(gS),c=X(hS),{handleNewChat:l}=Rh(),u;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(u=Mg(),t[0]=u):u=t[0];let f=u,p=c.length>0,m;if(t[1]!==s||t[2]!==o){let e;t[4]===o?e=t[5]:(e=e=>e.projectId===o,t[4]=o,t[5]=e),m=s.find(e),t[1]=s,t[2]=o,t[3]=m}else m=t[3];let h=m,g,_,v,y,b,x;if(t[6]!==l||t[7]!==p||t[8]!==n||t[9]!==r||t[10]!==s||t[11]!==h||t[12]!==o||t[13]!==a||t[14]!==i){let e=Ln(),c;if(t[21]!==n||t[22]!==r||t[23]!==s||t[24]!==h||t[25]!==o||t[26]!==i){let e=[...s].sort(mS),a;t[29]!==n||t[30]!==i?(a=!f&&n?(0,$.jsx)(Ti,{children:(0,$.jsxs)(sa,{children:[(0,$.jsx)(Ya,{asChild:!0,children:(0,$.jsxs)(Fe,{variant:`ghost`,size:`icon`,className:K(`h-8 w-8 shrink-0 electrobun-webkit-app-region-no-drag`,i?`text-foreground`:`text-muted-foreground`),onClick:n,children:[(0,$.jsx)(Kr,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Back to projects`})]})}),(0,$.jsx)(Qa,{children:`Projects`})]})}):null,t[29]=n,t[30]=i,t[31]=a):a=t[31],v=a,c=h&&r?(0,$.jsxs)(fa,{children:[(0,$.jsx)(Ji,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,className:`flex min-w-0 max-w-full items-center gap-1 rounded-md px-1.5 py-0.5 text-left outline-none transition-colors can-hover:hover:bg-muted focus-visible:ring-2 focus-visible:ring-ring electrobun-webkit-app-region-no-drag`,children:[(0,$.jsx)(Ko,{project:h,elevated:!1,className:`h-5 w-5 shrink-0 rounded`,iconClassName:`h-3 w-3`}),(0,$.jsx)(`span`,{className:K(J.sectionTitle,`truncate min-w-0`,!i&&`text-foreground`),children:xn(h)}),(0,$.jsx)(Dr,{className:K(`h-4 w-4 shrink-0`,i?`scenic-foreground-muted`:`text-muted-foreground`)}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Switch project`})]})}),(0,$.jsx)(Ei,{align:i?`center`:`start`,collisionPadding:12,className:`max-h-[var(--radix-dropdown-menu-content-available-height)] w-64 overflow-y-auto`,children:e.map(e=>{let t=e.gitUrl?d:Oe,n=e.projectId===o;return(0,$.jsxs)(ya,{className:K(J.body,`gap-2`),onSelect:()=>r(e.projectId),children:[(0,$.jsx)(t,{className:`h-4 w-4 shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:xn(e)}),n?(0,$.jsx)(Xt,{className:`ml-auto h-4 w-4 shrink-0`}):null]},e.projectId)})})]}):h?(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,$.jsx)(Ko,{project:h,elevated:!1,className:`h-5 w-5 shrink-0 rounded`,iconClassName:`h-3 w-3`}),(0,$.jsx)(`span`,{className:K(J.sectionTitle,`truncate min-w-0`,!i&&`text-foreground`),children:xn(h)})]}):null,t[21]=n,t[22]=r,t[23]=s,t[24]=h,t[25]=o,t[26]=i,t[27]=v,t[28]=c}else v=t[27],c=t[28];b=c;let u;t[32]!==b||t[33]!==i?(u=b?(0,$.jsxs)($.Fragment,{children:[i?null:(0,$.jsx)(Ut,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),b]}):null,t[32]=b,t[33]=i,t[34]=u):u=t[34];let m;t[35]!==v||t[36]!==u?(m=(0,$.jsxs)($.Fragment,{children:[v,u]}),t[35]=v,t[36]=u,t[37]=m):m=t[37],y=m;let S=!!a&&(p||!!o),C;t[38]===i?C=t[39]:(C=i&&zt()?(0,$.jsx)(`div`,{className:`hidden shrink-0 md:flex`,children:(0,$.jsx)($x,{})}):null,t[38]=i,t[39]=C);let w;t[40]!==l||t[41]!==p||t[42]!==S||t[43]!==i?(w=S?(0,$.jsxs)(oS,{className:K(`md:hidden electrobun-webkit-app-region-no-drag`,i&&`bg-background/25 p-1 text-foreground backdrop-blur-sm dark:bg-background/75 electrobun-webkit-app-region-no-drag`),children:[p?(0,$.jsxs)(Fe,{variant:i?`ghost`:`outline`,size:`icon-sm`,className:K(i?`text-foreground`:`rounded-full bg-background text-foreground hover:bg-accent hover:text-accent-foreground`),onClick:()=>{dS(),l()},children:[(0,$.jsx)(ir,{className:`h-3 w-3`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`New Chat`})]}):null,(0,$.jsx)(Vg,{inPill:i})]}):null,t[40]=l,t[41]=p,t[42]=S,t[43]=i,t[44]=w):w=t[44];let T;t[45]!==h?.openWith||t[46]!==h?.runCommand||t[47]!==o||t[48]!==a||t[49]!==i?(T=o&&(0,$.jsxs)(oS,{className:K(`electrobun-webkit-app-region-no-drag`,i&&`bg-background/25 p-1 text-foreground backdrop-blur-sm dark:bg-background/75 electrobun-webkit-app-region-no-drag`),children:[(0,$.jsx)(Zx,{}),(0,$.jsx)(wg,{projectId:o,runCommand:h?.runCommand}),a&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Qh,{threadId:a}),(0,$.jsx)($h,{})]}),!f&&a?(0,$.jsx)(ig,{projectId:o,threadId:a,openWith:h?.openWith}):null,f?null:(0,$.jsx)(rS,{})]}),t[45]=h?.openWith,t[46]=h?.runCommand,t[47]=o,t[48]=a,t[49]=i,t[50]=T):T=t[50];let E;t[51]===T?E=t[52]:(E=(0,$.jsx)(`div`,{className:`hidden md:flex flex-wrap items-center justify-end gap-2`,children:T}),t[51]=T,t[52]=E);let D;t[53]===Symbol.for(`react.memo_cache_sentinel`)?(D=f&&(0,$.jsx)(fS,{}),t[53]=D):D=t[53];let O;t[54]!==E||t[55]!==C||t[56]!==w?(O=(0,$.jsxs)($.Fragment,{children:[C,w,E,D]}),t[54]=E,t[55]=C,t[56]=w,t[57]=O):O=t[57],_=O,g=Zo,x=K(`pt-1`,e&&`pt-4 md:min-h-[103px]`,i&&`scenic-foreground grid grid-cols-[1fr_auto_1fr] items-center gap-2`),t[6]=l,t[7]=p,t[8]=n,t[9]=r,t[10]=s,t[11]=h,t[12]=o,t[13]=a,t[14]=i,t[15]=g,t[16]=_,t[17]=v,t[18]=y,t[19]=b,t[20]=x}else g=t[15],_=t[16],v=t[17],y=t[18],b=t[19],x=t[20];let S;t[58]!==_||t[59]!==v||t[60]!==y||t[61]!==b||t[62]!==i?(S=i?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`flex min-w-0 items-center justify-start`,children:v?(0,$.jsx)(oS,{className:`bg-background/25 p-1 text-foreground backdrop-blur-sm dark:bg-background/75 electrobun-webkit-app-region-no-drag`,children:v}):null}),(0,$.jsx)(`div`,{className:`flex min-w-0 items-center justify-center`,children:b?(0,$.jsx)(`div`,{className:K(`flex min-w-0 max-w-full items-center rounded-full`,`bg-transparent p-1 scenic-foreground electrobun-webkit-app-region-no-drag`),children:b}):null}),(0,$.jsx)(`div`,{className:`flex min-w-0 items-center justify-end gap-2`,children:_})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`flex min-w-0 flex-1 items-center gap-1`,children:y}),(0,$.jsx)(`div`,{className:`ml-auto flex min-w-0 shrink-0 items-center gap-2`,children:_})]}),t[58]=_,t[59]=v,t[60]=y,t[61]=b,t[62]=i,t[63]=S):S=t[63];let C;return t[64]!==g||t[65]!==x||t[66]!==S?(C=(0,$.jsx)(g,{className:x,children:S}),t[64]=g,t[65]=x,t[66]=S,t[67]=C):C=t[67],C}function mS(e,t){return xn(e).localeCompare(xn(t))}function hS(e){return e.messages}function gS(e){return e.projects}function _S(e){return e.selectedProjectId}function vS(e){return e.selectedThreadId}var yS=(0,Z.createContext)(null);function bS(e){let t=(0,Q.c)(11),{children:n}=e,[r,i]=(0,Z.useState)(0),[a,o]=(0,Z.useState)(`desktop`),[s,c]=(0,Z.useState)(!1),[l,u]=(0,Z.useState)(null),[d,f]=(0,Z.useState)(!1),[p,m]=(0,Z.useState)(null),h;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(h=()=>{i(xS)},t[0]=h):h=t[0];let g=h,_;t[1]!==p||t[2]!==a||t[3]!==r||t[4]!==s||t[5]!==d||t[6]!==l?(_={browserResetTrigger:r,triggerBrowserReset:g,browserDeviceMode:a,setBrowserDeviceMode:o,isSelectModeEnabled:s,setIsSelectModeEnabled:c,selectedBrowserElement:l,setSelectedBrowserElement:u,isSelectionPromptOpen:d,setIsSelectionPromptOpen:f,browserAgentProcessingThreadId:p,setBrowserAgentProcessingThreadId:m},t[1]=p,t[2]=a,t[3]=r,t[4]=s,t[5]=d,t[6]=l,t[7]=_):_=t[7];let v=_,y;return t[8]!==n||t[9]!==v?(y=(0,$.jsx)(yS.Provider,{value:v,children:n}),t[8]=n,t[9]=v,t[10]=y):y=t[10],y}function xS(e){return e+1}function SS(){let e=(0,Z.useContext)(yS);if(!e)throw Error(`useBrowserTab must be used within a BrowserTabProvider`);return e}var CS=`tarsk-browser-element-selected`;function wS(e){let t=[`<browser-selection url="${e.url}" selector="${e.selector}" tag="${e.tagName}">`,e.html,`</browser-selection>`];return e.text.trim()&&t.push(`Text: ${e.text.trim()}`),t.join(`
|
|
55
|
+
`)}function TS(e){if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.html==`string`&&typeof t.text==`string`&&typeof t.tagName==`string`&&typeof t.selector==`string`&&typeof t.url==`string`}function ES(e){if(!e||typeof e!=`object`)return null;let t=e;return t.type!==`tarsk-browser-element-selected`||!TS(t.payload)?null:t.payload}function DS(e){window.dispatchEvent(new CustomEvent(CS,{detail:e}))}function OS(e){return ES(e)??(TS(e)?e:null)}function kS(e,t){let n=t.trim();return n?`${e}\n\n${n}`:e}function AS(e){if(Ln()){(e?.querySelector(`electrobun-webview`))?.executeJavascript?.(`(function(){window.__tarskBrowserPreview?.setSelectMode?.(false,false);})();`);return}(e?.querySelector(`iframe`)?.contentWindow?.__tarskBrowserPreview)?.setSelectMode?.(!1,!1)}function jS(e){let t=(0,Q.c)(39),{container:n}=e,r=Gi(),i=X(PS),a=X(NS),{selectedBrowserElement:o,isSelectionPromptOpen:s,setIsSelectionPromptOpen:c,setSelectedBrowserElement:l,setBrowserAgentProcessingThreadId:u}=SS(),{paneId:d,conversationId:f}=If(),{handleSend:p,handleStop:m,getQueuedMessagesForPane:h,handleRemoveQueuedMessage:g}=Qv(),{userTasks:_,setUserTasks:v,effectiveIsStreaming:y,handleRemoveUserTask:b}=Rh(),[x,S]=Z.useState(0),C;t[0]===o?C=t[1]:(C=o?wS(o):``,t[0]=o,t[1]=C);let w=C,T;t[2]===s?T=t[3]:(T=()=>{s&&S(MS)},t[2]=s,t[3]=T);let E;t[4]!==s||t[5]!==o?(E=[s,o],t[4]=s,t[5]=o,t[6]=E):E=t[6],(0,Z.useEffect)(T,E);let D;t[7]!==n||t[8]!==c||t[9]!==l?(D=e=>{c(e),e||(AS(n),l(null))},t[7]=n,t[8]=c,t[9]=l,t[10]=D):D=t[10];let O=D,k;t[11]!==n||t[12]!==f||t[13]!==r||t[14]!==p||t[15]!==d||t[16]!==i||t[17]!==w||t[18]!==u||t[19]!==c||t[20]!==l?(k=(e,t,a,o,s,m,h)=>{!i||!w||(p(d,f,kS(w,e),t,a,o,s,m,h),r({type:Y.SetChatInputDraft,threadId:d===`primary`?i:`${i}:${d}`,draft:``}),u(i),c(!1),l(null),AS(n))},t[11]=n,t[12]=f,t[13]=r,t[14]=p,t[15]=d,t[16]=i,t[17]=w,t[18]=u,t[19]=c,t[20]=l,t[21]=k):k=t[21];let A=k,j=s&&!!(i&&a&&o&&n),M;t[22]!==n||t[23]!==y||t[24]!==h||t[25]!==g||t[26]!==b||t[27]!==m||t[28]!==A||t[29]!==d||t[30]!==x||t[31]!==i||t[32]!==v||t[33]!==_?(M=n?(0,$.jsxs)(Rr,{container:n,children:[(0,$.jsx)(Pt,{className:K(`absolute inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0`)}),(0,$.jsxs)(kr,{className:K(`absolute inset-x-0 top-0 z-50 w-full border-b border-border bg-background p-0 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top`),children:[(0,$.jsx)(un,{className:`sr-only`,children:`Prompt with selected element`}),(0,$.jsxs)(wt,{className:`absolute right-4 top-4 z-10 flex h-7 w-7 items-center justify-center rounded-full transition-colors hover:bg-foreground hover:text-background disabled:pointer-events-none`,children:[(0,$.jsx)(Gt,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Close`})]}),(0,$.jsx)(`div`,{className:`px-4 pt-3 pb-2`,children:(0,$.jsx)(Um,{centered:!0,autoFocus:!0,onSend:A,onStop:()=>m(d),isStreaming:y,disabled:!i,initialValue:``,queuedMessages:h(d),onRemoveQueuedMessage:e=>{g(d,e)},placeholder:`How do you want to change the selected element?`,userTasks:_,onMatchedUserTaskSend:e=>{e.pinned||b(e.id)},onUserTaskCreated:e=>{v(t=>[...t,e])}},x)})]})]}):null,t[22]=n,t[23]=y,t[24]=h,t[25]=g,t[26]=b,t[27]=m,t[28]=A,t[29]=d,t[30]=x,t[31]=i,t[32]=v,t[33]=_,t[34]=M):M=t[34];let N;return t[35]!==O||t[36]!==j||t[37]!==M?(N=(0,$.jsx)(Cr,{open:j,onOpenChange:O,children:M}),t[35]=O,t[36]=j,t[37]=M,t[38]=N):N=t[38],N}function MS(e){return e+1}function NS(e){return e.selectedProjectId}function PS(e){return e.selectedThreadId}function FS(){let e=(0,Q.c)(1),t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center`,children:(0,$.jsx)(`div`,{className:`h-8 w-8 animate-spin rounded-full border-2 border-muted border-t-primary`})}),e[0]=t):t=e[0],t}var IS=(0,Z.lazy)(()=>po(()=>import(`./settings-view-BweC2YuW.js`),__vite__mapDeps([24,1,6,4,5,25,14,15,16])));function LS(e){let t=(0,Q.c)(28),{selectedProjectId:n,isReviewRoute:r,isSettingsRoute:i,onCreateThread:a,onBackToProjects:o,onSelectProject:s}=e,{isPanelOpen:c}=vo(),l=uh(),u=!r&&!i,d=u&&!l,[f,p]=(0,Z.useState)(null),m=X(RS),h;if(t[0]!==m||t[1]!==n){let e;t[3]===n?e=t[4]:(e=e=>e.projectId===n,t[3]=n,t[4]=e),h=m.find(e),t[0]=m,t[1]=n,t[2]=h}else h=t[2];let g=h?.useBuiltInBrowser!==!1,_;t[5]===c?_=t[6]:(_=c(`browser`),t[5]=c,t[6]=_);let v=_,y=d&&`bg-background`,b;t[7]===y?b=t[8]:(b=K(`relative flex h-full flex-col overflow-hidden`,y),t[7]=y,t[8]=b);let x;t[9]!==o||t[10]!==s||t[11]!==u?(x=u&&(0,$.jsx)(pS,{onBackToProjects:o,onSelectProject:s}),t[9]=o,t[10]=s,t[11]=u,t[12]=x):x=t[12];let S;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(S=(0,$.jsx)(Ea,{path:`/settings/providers/:providerSlug`,element:(0,$.jsx)(Z.Suspense,{fallback:(0,$.jsx)(FS,{}),children:(0,$.jsx)(IS,{})})}),t[13]=S):S=t[13];let C;t[14]===Symbol.for(`react.memo_cache_sentinel`)?(C=(0,$.jsx)(Ea,{path:`/settings/project/:projectId`,element:(0,$.jsx)(Z.Suspense,{fallback:(0,$.jsx)(FS,{}),children:(0,$.jsx)(IS,{})})}),t[14]=C):C=t[14];let w;t[15]===Symbol.for(`react.memo_cache_sentinel`)?(w=(0,$.jsx)(Ea,{path:`/settings/:tab?`,element:(0,$.jsx)(Z.Suspense,{fallback:(0,$.jsx)(FS,{}),children:(0,$.jsx)(IS,{})})}),t[15]=w):w=t[15];let T;t[16]===a?T=t[17]:(T=(0,$.jsx)(`main`,{className:`flex-1 overflow-hidden`,children:(0,$.jsxs)(wa,{children:[S,C,w,(0,$.jsx)(Ea,{path:`*`,element:(0,$.jsx)(Mx,{onCreateThread:a})})]})}),t[16]=a,t[17]=T);let E;t[18]!==v||t[19]!==f||t[20]!==g||t[21]!==u?(E=u&&g&&v?(0,$.jsx)(jS,{container:f}):null,t[18]=v,t[19]=f,t[20]=g,t[21]=u,t[22]=E):E=t[22];let D;return t[23]!==E||t[24]!==b||t[25]!==x||t[26]!==T?(D=(0,$.jsxs)(`div`,{ref:p,className:b,children:[x,T,E]}),t[23]=E,t[24]=b,t[25]=x,t[26]=T,t[27]=D):D=t[27],D}function RS(e){return e.projects}function zS(e){let t=(0,Q.c)(14),{open:n,projectName:r,onOpenChange:i,onConfirm:a}=e,o;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,$.jsx)(ca,{children:`Delete Project`}),t[0]=o):o=t[0];let s;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(s=K(J.body,`font-semibold text-foreground`),t[1]=s):s=t[1];let c;t[2]===r?c=t[3]:(c=(0,$.jsxs)(ia,{children:[o,(0,$.jsxs)(qa,{children:[`Are you sure you want to delete`,` `,(0,$.jsxs)(`span`,{className:s,children:[`"`,r,`"`]}),`? This will remove the project and all its data. This action cannot be undone.`]})]}),t[2]=r,t[3]=c);let l;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,$.jsx)(Xa,{children:`Cancel`}),t[4]=l):l=t[4];let u;t[5]===a?u=t[6]:(u=(0,$.jsxs)(na,{children:[l,(0,$.jsx)(oa,{onClick:a,className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:`Delete`})]}),t[5]=a,t[6]=u);let d;t[7]!==c||t[8]!==u?(d=(0,$.jsxs)(Ci,{children:[c,u]}),t[7]=c,t[8]=u,t[9]=d):d=t[9];let f;return t[10]!==i||t[11]!==n||t[12]!==d?(f=(0,$.jsx)(Mi,{open:n,onOpenChange:i,children:d}),t[10]=i,t[11]=n,t[12]=d,t[13]=f):f=t[13],f}function BS(e){let t=(0,Q.c)(28),{open:n,setupScripts:r,onConfirm:i}=e;if(r.length===0)return null;let a;t[0]===i?a=t[1]:(a=e=>{e||i(!1)},t[0]=i,t[1]=a);let o;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,$.jsx)(ca,{children:`Install dependencies?`}),t[2]=o):o=t[2];let s=r.length===1?``:`s`,c;t[3]!==r.length||t[4]!==s?(c=(0,$.jsxs)(ia,{children:[o,(0,$.jsxs)(qa,{children:[`Found `,r.length,` package`,s,` with dependencies to install:`]})]}),t[3]=r.length,t[4]=s,t[5]=c):c=t[5];let l;t[6]===r?l=t[7]:(l=r.map(VS),t[6]=r,t[7]=l);let u;t[8]===l?u=t[9]:(u=(0,$.jsx)(`div`,{className:`my-4 max-h-60 overflow-y-auto`,children:(0,$.jsx)(`div`,{className:`space-y-2`,children:l})}),t[8]=l,t[9]=u);let d;t[10]===i?d=t[11]:(d=(0,$.jsx)(Xa,{onClick:()=>i(!1),children:`No`}),t[10]=i,t[11]=d);let f;t[12]===i?f=t[13]:(f=()=>i(!0),t[12]=i,t[13]=f);let p;t[14]!==r.length||t[15]!==f?(p=(0,$.jsxs)(oa,{onClick:f,children:[`Install All (`,r.length,`)`]}),t[14]=r.length,t[15]=f,t[16]=p):p=t[16];let m;t[17]!==d||t[18]!==p?(m=(0,$.jsxs)(na,{children:[d,p]}),t[17]=d,t[18]=p,t[19]=m):m=t[19];let h;t[20]!==m||t[21]!==c||t[22]!==u?(h=(0,$.jsxs)(Ci,{className:`max-w-2xl`,children:[c,u,m]}),t[20]=m,t[21]=c,t[22]=u,t[23]=h):h=t[23];let g;return t[24]!==n||t[25]!==a||t[26]!==h?(g=(0,$.jsx)(Mi,{open:n,onOpenChange:a,children:h}),t[24]=n,t[25]=a,t[26]=h,t[27]=g):g=t[27],g}function VS(e,t){let n=e.match(/^cd "([^"]+)" && (.+)$/),r=n?n[1]:`root`,i=n?n[2]:e;return(0,$.jsx)(`div`,{className:`flex items-center justify-between p-3 rounded-lg border bg-muted/50`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-blue-500`}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:J.label,children:r||`root`}),(0,$.jsx)(`div`,{className:J.bodyMuted,children:i})]})]})},t)}var HS;(function(e){e[e.QR_CODE=0]=`QR_CODE`,e[e.AZTEC=1]=`AZTEC`,e[e.CODABAR=2]=`CODABAR`,e[e.CODE_39=3]=`CODE_39`,e[e.CODE_93=4]=`CODE_93`,e[e.CODE_128=5]=`CODE_128`,e[e.DATA_MATRIX=6]=`DATA_MATRIX`,e[e.MAXICODE=7]=`MAXICODE`,e[e.ITF=8]=`ITF`,e[e.EAN_13=9]=`EAN_13`,e[e.EAN_8=10]=`EAN_8`,e[e.PDF_417=11]=`PDF_417`,e[e.RSS_14=12]=`RSS_14`,e[e.RSS_EXPANDED=13]=`RSS_EXPANDED`,e[e.UPC_A=14]=`UPC_A`,e[e.UPC_E=15]=`UPC_E`,e[e.UPC_EAN_EXTENSION=16]=`UPC_EAN_EXTENSION`})(HS||={});var US=new Map([[HS.QR_CODE,`QR_CODE`],[HS.AZTEC,`AZTEC`],[HS.CODABAR,`CODABAR`],[HS.CODE_39,`CODE_39`],[HS.CODE_93,`CODE_93`],[HS.CODE_128,`CODE_128`],[HS.DATA_MATRIX,`DATA_MATRIX`],[HS.MAXICODE,`MAXICODE`],[HS.ITF,`ITF`],[HS.EAN_13,`EAN_13`],[HS.EAN_8,`EAN_8`],[HS.PDF_417,`PDF_417`],[HS.RSS_14,`RSS_14`],[HS.RSS_EXPANDED,`RSS_EXPANDED`],[HS.UPC_A,`UPC_A`],[HS.UPC_E,`UPC_E`],[HS.UPC_EAN_EXTENSION,`UPC_EAN_EXTENSION`]]),WS;(function(e){e[e.UNKNOWN=0]=`UNKNOWN`,e[e.URL=1]=`URL`})(WS||={});function GS(e){return Object.values(HS).includes(e)}var KS;(function(e){e[e.SCAN_TYPE_CAMERA=0]=`SCAN_TYPE_CAMERA`,e[e.SCAN_TYPE_FILE=1]=`SCAN_TYPE_FILE`})(KS||={});var qS=function(){function e(){}return e.GITHUB_PROJECT_URL=`https://github.com/mebjas/html5-qrcode`,e.SCAN_DEFAULT_FPS=2,e.DEFAULT_DISABLE_FLIP=!1,e.DEFAULT_REMEMBER_LAST_CAMERA_USED=!0,e.DEFAULT_SUPPORTED_SCAN_TYPE=[KS.SCAN_TYPE_CAMERA,KS.SCAN_TYPE_FILE],e}(),JS=function(){function e(e,t){this.format=e,this.formatName=t}return e.prototype.toString=function(){return this.formatName},e.create=function(t){if(!US.has(t))throw`${t} not in html5QrcodeSupportedFormatsTextMap`;return new e(t,US.get(t))},e}(),YS=function(){function e(){}return e.createFromText=function(e){return{decodedText:e,result:{text:e}}},e.createFromQrcodeResult=function(e){return{decodedText:e.text,result:e}},e}(),XS;(function(e){e[e.UNKWOWN_ERROR=0]=`UNKWOWN_ERROR`,e[e.IMPLEMENTATION_ERROR=1]=`IMPLEMENTATION_ERROR`,e[e.NO_CODE_FOUND_ERROR=2]=`NO_CODE_FOUND_ERROR`})(XS||={});var ZS=function(){function e(){}return e.createFrom=function(e){return{errorMessage:e,type:XS.UNKWOWN_ERROR}},e}(),QS=function(){function e(e){this.verbose=e}return e.prototype.log=function(e){this.verbose&&console.log(e)},e.prototype.warn=function(e){this.verbose&&console.warn(e)},e.prototype.logError=function(e,t){(this.verbose||t===!0)&&console.error(e)},e.prototype.logErrors=function(e){if(e.length===0)throw`Logger#logError called without arguments`;this.verbose&&console.error(e)},e}();function $S(e){return e==null}function eC(e,t,n){return e>n?n:e<t?t:e}var tC=function(){function e(){}return e.codeParseError=function(e){return`QR code parse error, error = ${e}`},e.errorGettingUserMedia=function(e){return`Error getting userMedia, error = ${e}`},e.onlyDeviceSupportedError=function(){return`The device doesn't support navigator.mediaDevices , only supported cameraIdOrConfig in this case is deviceId parameter (string).`},e.cameraStreamingNotSupported=function(){return`Camera streaming not supported by the browser.`},e.unableToQuerySupportedDevices=function(){return`Unable to query supported devices, unknown error.`},e.insecureContextCameraQueryError=function(){return`Camera access is only supported in secure context like https or localhost.`},e.scannerPaused=function(){return`Scanner paused`},e}(),nC=function(){function e(){}return e.scanningStatus=function(){return`Scanning`},e.idleStatus=function(){return`Idle`},e.errorStatus=function(){return`Error`},e.permissionStatus=function(){return`Permission`},e.noCameraFoundErrorStatus=function(){return`No Cameras`},e.lastMatch=function(e){return`Last Match: ${e}`},e.codeScannerTitle=function(){return`Code Scanner`},e.cameraPermissionTitle=function(){return`Request Camera Permissions`},e.cameraPermissionRequesting=function(){return`Requesting camera permissions...`},e.noCameraFound=function(){return`No camera found`},e.scanButtonStopScanningText=function(){return`Stop Scanning`},e.scanButtonStartScanningText=function(){return`Start Scanning`},e.torchOnButton=function(){return`Switch On Torch`},e.torchOffButton=function(){return`Switch Off Torch`},e.torchOnFailedMessage=function(){return`Failed to turn on torch`},e.torchOffFailedMessage=function(){return`Failed to turn off torch`},e.scanButtonScanningStarting=function(){return`Launching Camera...`},e.textIfCameraScanSelected=function(){return`Scan an Image File`},e.textIfFileScanSelected=function(){return`Scan using camera directly`},e.selectCamera=function(){return`Select Camera`},e.fileSelectionChooseImage=function(){return`Choose Image`},e.fileSelectionChooseAnother=function(){return`Choose Another`},e.fileSelectionNoImageSelected=function(){return`No image choosen`},e.anonymousCameraPrefix=function(){return`Anonymous Camera`},e.dragAndDropMessage=function(){return`Or drop an image to scan`},e.dragAndDropMessageOnlyImages=function(){return`Or drop an image to scan (other files not supported)`},e.zoom=function(){return`zoom`},e.loadingImage=function(){return`Loading image...`},e.cameraScanAltText=function(){return`Camera based scan`},e.fileScanAltText=function(){return`Fule based scan`},e}(),rC=function(){function e(){}return e.poweredBy=function(){return`Powered by `},e.reportIssues=function(){return`Report issues`},e}(),iC=function(){function e(){}return e.isMediaStreamConstraintsValid=function(e,t){if(typeof e!=`object`){var n=typeof e;return t.logError(`videoConstraints should be of type object, the object passed is of type ${n}.`,!0),!1}for(var r=new Set([`autoGainControl`,`channelCount`,`echoCancellation`,`latency`,`noiseSuppression`,`sampleRate`,`sampleSize`,`volume`]),i=Object.keys(e),a=0,o=i;a<o.length;a++){var s=o[a];if(r.has(s))return t.logError(`${s} is not supported videoConstaints.`,!0),!1}return!0},e}(),aC=e(t(((e,t)=>{(function(n,r){typeof e==`object`&&t!==void 0?r(e):typeof define==`function`&&define.amd?define([`exports`],r):(n=typeof globalThis<`u`?globalThis:n||self,r(n.ZXing={}))})(e,(function(e){function t(e){return e==null}var n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])};function r(e,t){n(e,t);function r(){this.constructor=e}e.prototype=t===null?Object.create(t):(r.prototype=t.prototype,new r)}function i(e,t){var n=Object.setPrototypeOf;n?n(e,t):e.__proto__=t}function a(e,t){t===void 0&&(t=e.constructor);var n=Error.captureStackTrace;n&&n(e,t)}var o=(function(e){r(t,e);function t(t){var n=this.constructor,r=e.call(this,t)||this;return Object.defineProperty(r,"name",{value:n.name,enumerable:!1}),i(r,n.prototype),a(r),r}return t})(Error);class s extends o{constructor(e=void 0){super(e),this.message=e}getKind(){return this.constructor.kind}}s.kind=`Exception`;class c extends s{}c.kind=`ArgumentException`;class l extends s{}l.kind=`IllegalArgumentException`;class u{constructor(e){if(this.binarizer=e,e===null)throw new l(`Binarizer must be non-null.`)}getWidth(){return this.binarizer.getWidth()}getHeight(){return this.binarizer.getHeight()}getBlackRow(e,t){return this.binarizer.getBlackRow(e,t)}getBlackMatrix(){return(this.matrix===null||this.matrix===void 0)&&(this.matrix=this.binarizer.getBlackMatrix()),this.matrix}isCropSupported(){return this.binarizer.getLuminanceSource().isCropSupported()}crop(e,t,n,r){let i=this.binarizer.getLuminanceSource().crop(e,t,n,r);return new u(this.binarizer.createBinarizer(i))}isRotateSupported(){return this.binarizer.getLuminanceSource().isRotateSupported()}rotateCounterClockwise(){let e=this.binarizer.getLuminanceSource().rotateCounterClockwise();return new u(this.binarizer.createBinarizer(e))}rotateCounterClockwise45(){let e=this.binarizer.getLuminanceSource().rotateCounterClockwise45();return new u(this.binarizer.createBinarizer(e))}toString(){try{return this.getBlackMatrix().toString()}catch{return``}}}class d extends s{static getChecksumInstance(){return new d}}d.kind=`ChecksumException`;class f{constructor(e){this.source=e}getLuminanceSource(){return this.source}getWidth(){return this.source.getWidth()}getHeight(){return this.source.getHeight()}}class p{static arraycopy(e,t,n,r,i){for(;i--;)n[r++]=e[t++]}static currentTimeMillis(){return Date.now()}}class m extends s{}m.kind=`IndexOutOfBoundsException`;class h extends m{constructor(e=void 0,t=void 0){super(t),this.index=e,this.message=t}}h.kind=`ArrayIndexOutOfBoundsException`;class g{static fill(e,t){for(let n=0,r=e.length;n<r;n++)e[n]=t}static fillWithin(e,t,n,r){g.rangeCheck(e.length,t,n);for(let i=t;i<n;i++)e[i]=r}static rangeCheck(e,t,n){if(t>n)throw new l(`fromIndex(`+t+`) > toIndex(`+n+`)`);if(t<0)throw new h(t);if(n>e)throw new h(n)}static asList(...e){return e}static create(e,t,n){return Array.from({length:e}).map(e=>Array.from({length:t}).fill(n))}static createInt32Array(e,t,n){return Array.from({length:e}).map(e=>Int32Array.from({length:t}).fill(n))}static equals(e,t){if(!e||!t||!e.length||!t.length||e.length!==t.length)return!1;for(let n=0,r=e.length;n<r;n++)if(e[n]!==t[n])return!1;return!0}static hashCode(e){if(e===null)return 0;let t=1;for(let n of e)t=31*t+n;return t}static fillUint8Array(e,t){for(let n=0;n!==e.length;n++)e[n]=t}static copyOf(e,t){return e.slice(0,t)}static copyOfUint8Array(e,t){if(e.length<=t){let n=new Uint8Array(t);return n.set(e),n}return e.slice(0,t)}static copyOfRange(e,t,n){let r=n-t,i=new Int32Array(r);return p.arraycopy(e,t,i,0,r),i}static binarySearch(e,t,n){n===void 0&&(n=g.numberComparator);let r=0,i=e.length-1;for(;r<=i;){let a=i+r>>1,o=n(t,e[a]);if(o>0)r=a+1;else if(o<0)i=a-1;else return a}return-r-1}static numberComparator(e,t){return e-t}}class _{static numberOfTrailingZeros(e){let t;if(e===0)return 32;let n=31;return t=e<<16,t!==0&&(n-=16,e=t),t=e<<8,t!==0&&(n-=8,e=t),t=e<<4,t!==0&&(n-=4,e=t),t=e<<2,t!==0&&(n-=2,e=t),n-(e<<1>>>31)}static numberOfLeadingZeros(e){if(e===0)return 32;let t=1;return e>>>16||(t+=16,e<<=16),e>>>24||(t+=8,e<<=8),e>>>28||(t+=4,e<<=4),e>>>30||(t+=2,e<<=2),t-=e>>>31,t}static toHexString(e){return e.toString(16)}static toBinaryString(e){return String(parseInt(String(e),2))}static bitCount(e){return e-=e>>>1&1431655765,e=(e&858993459)+(e>>>2&858993459),e=e+(e>>>4)&252645135,e+=e>>>8,e+=e>>>16,e&63}static truncDivision(e,t){return Math.trunc(e/t)}static parseInt(e,t=void 0){return parseInt(e,t)}}_.MIN_VALUE_32_BITS=-2147483648,_.MAX_VALUE=2**53-1;class v{constructor(e,t){e===void 0?(this.size=0,this.bits=new Int32Array(1)):(this.size=e,t==null?this.bits=v.makeArray(e):this.bits=t)}getSize(){return this.size}getSizeInBytes(){return Math.floor((this.size+7)/8)}ensureCapacity(e){if(e>this.bits.length*32){let t=v.makeArray(e);p.arraycopy(this.bits,0,t,0,this.bits.length),this.bits=t}}get(e){return(this.bits[Math.floor(e/32)]&1<<(e&31))!=0}set(e){this.bits[Math.floor(e/32)]|=1<<(e&31)}flip(e){this.bits[Math.floor(e/32)]^=1<<(e&31)}getNextSet(e){let t=this.size;if(e>=t)return t;let n=this.bits,r=Math.floor(e/32),i=n[r];i&=~((1<<(e&31))-1);let a=n.length;for(;i===0;){if(++r===a)return t;i=n[r]}let o=r*32+_.numberOfTrailingZeros(i);return o>t?t:o}getNextUnset(e){let t=this.size;if(e>=t)return t;let n=this.bits,r=Math.floor(e/32),i=~n[r];i&=~((1<<(e&31))-1);let a=n.length;for(;i===0;){if(++r===a)return t;i=~n[r]}let o=r*32+_.numberOfTrailingZeros(i);return o>t?t:o}setBulk(e,t){this.bits[Math.floor(e/32)]=t}setRange(e,t){if(t<e||e<0||t>this.size)throw new l;if(t===e)return;t--;let n=Math.floor(e/32),r=Math.floor(t/32),i=this.bits;for(let a=n;a<=r;a++){let o=a>n?0:e&31,s=(2<<(a<r?31:t&31))-(1<<o);i[a]|=s}}clear(){let e=this.bits.length,t=this.bits;for(let n=0;n<e;n++)t[n]=0}isRange(e,t,n){if(t<e||e<0||t>this.size)throw new l;if(t===e)return!0;t--;let r=Math.floor(e/32),i=Math.floor(t/32),a=this.bits;for(let o=r;o<=i;o++){let s=o>r?0:e&31,c=(2<<(o<i?31:t&31))-(1<<s)&4294967295;if((a[o]&c)!==(n?c:0))return!1}return!0}appendBit(e){this.ensureCapacity(this.size+1),e&&(this.bits[Math.floor(this.size/32)]|=1<<(this.size&31)),this.size++}appendBits(e,t){if(t<0||t>32)throw new l(`Num bits must be between 0 and 32`);this.ensureCapacity(this.size+t);for(let n=t;n>0;n--)this.appendBit((e>>n-1&1)==1)}appendBitArray(e){let t=e.size;this.ensureCapacity(this.size+t);for(let n=0;n<t;n++)this.appendBit(e.get(n))}xor(e){if(this.size!==e.size)throw new l(`Sizes don't match`);let t=this.bits;for(let n=0,r=t.length;n<r;n++)t[n]^=e.bits[n]}toBytes(e,t,n,r){for(let i=0;i<r;i++){let r=0;for(let t=0;t<8;t++)this.get(e)&&(r|=1<<7-t),e++;t[n+i]=r}}getBitArray(){return this.bits}reverse(){let e=new Int32Array(this.bits.length),t=Math.floor((this.size-1)/32),n=t+1,r=this.bits;for(let i=0;i<n;i++){let n=r[i];n=n>>1&1431655765|(n&1431655765)<<1,n=n>>2&858993459|(n&858993459)<<2,n=n>>4&252645135|(n&252645135)<<4,n=n>>8&16711935|(n&16711935)<<8,n=n>>16&65535|(n&65535)<<16,e[t-i]=n}if(this.size!==n*32){let t=n*32-this.size,r=e[0]>>>t;for(let i=1;i<n;i++){let n=e[i];r|=n<<32-t,e[i-1]=r,r=n>>>t}e[n-1]=r}this.bits=e}static makeArray(e){return new Int32Array(Math.floor((e+31)/32))}equals(e){if(!(e instanceof v))return!1;let t=e;return this.size===t.size&&g.equals(this.bits,t.bits)}hashCode(){return 31*this.size+g.hashCode(this.bits)}toString(){let e=``;for(let t=0,n=this.size;t<n;t++)t&7||(e+=` `),e+=this.get(t)?`X`:`.`;return e}clone(){return new v(this.size,this.bits.slice())}}var y;(function(e){e[e.OTHER=0]=`OTHER`,e[e.PURE_BARCODE=1]=`PURE_BARCODE`,e[e.POSSIBLE_FORMATS=2]=`POSSIBLE_FORMATS`,e[e.TRY_HARDER=3]=`TRY_HARDER`,e[e.CHARACTER_SET=4]=`CHARACTER_SET`,e[e.ALLOWED_LENGTHS=5]=`ALLOWED_LENGTHS`,e[e.ASSUME_CODE_39_CHECK_DIGIT=6]=`ASSUME_CODE_39_CHECK_DIGIT`,e[e.ASSUME_GS1=7]=`ASSUME_GS1`,e[e.RETURN_CODABAR_START_END=8]=`RETURN_CODABAR_START_END`,e[e.NEED_RESULT_POINT_CALLBACK=9]=`NEED_RESULT_POINT_CALLBACK`,e[e.ALLOWED_EAN_EXTENSIONS=10]=`ALLOWED_EAN_EXTENSIONS`})(y||={});var b=y;class x extends s{static getFormatInstance(){return new x}}x.kind=`FormatException`;var S;(function(e){e[e.Cp437=0]=`Cp437`,e[e.ISO8859_1=1]=`ISO8859_1`,e[e.ISO8859_2=2]=`ISO8859_2`,e[e.ISO8859_3=3]=`ISO8859_3`,e[e.ISO8859_4=4]=`ISO8859_4`,e[e.ISO8859_5=5]=`ISO8859_5`,e[e.ISO8859_6=6]=`ISO8859_6`,e[e.ISO8859_7=7]=`ISO8859_7`,e[e.ISO8859_8=8]=`ISO8859_8`,e[e.ISO8859_9=9]=`ISO8859_9`,e[e.ISO8859_10=10]=`ISO8859_10`,e[e.ISO8859_11=11]=`ISO8859_11`,e[e.ISO8859_13=12]=`ISO8859_13`,e[e.ISO8859_14=13]=`ISO8859_14`,e[e.ISO8859_15=14]=`ISO8859_15`,e[e.ISO8859_16=15]=`ISO8859_16`,e[e.SJIS=16]=`SJIS`,e[e.Cp1250=17]=`Cp1250`,e[e.Cp1251=18]=`Cp1251`,e[e.Cp1252=19]=`Cp1252`,e[e.Cp1256=20]=`Cp1256`,e[e.UnicodeBigUnmarked=21]=`UnicodeBigUnmarked`,e[e.UTF8=22]=`UTF8`,e[e.ASCII=23]=`ASCII`,e[e.Big5=24]=`Big5`,e[e.GB18030=25]=`GB18030`,e[e.EUC_KR=26]=`EUC_KR`})(S||={});class C{constructor(e,t,n,...r){this.valueIdentifier=e,this.name=n,typeof t==`number`?this.values=Int32Array.from([t]):this.values=t,this.otherEncodingNames=r,C.VALUE_IDENTIFIER_TO_ECI.set(e,this),C.NAME_TO_ECI.set(n,this);let i=this.values;for(let e=0,t=i.length;e!==t;e++){let t=i[e];C.VALUES_TO_ECI.set(t,this)}for(let e of r)C.NAME_TO_ECI.set(e,this)}getValueIdentifier(){return this.valueIdentifier}getName(){return this.name}getValue(){return this.values[0]}static getCharacterSetECIByValue(e){if(e<0||e>=900)throw new x(`incorect value`);let t=C.VALUES_TO_ECI.get(e);if(t===void 0)throw new x(`incorect value`);return t}static getCharacterSetECIByName(e){let t=C.NAME_TO_ECI.get(e);if(t===void 0)throw new x(`incorect value`);return t}equals(e){if(!(e instanceof C))return!1;let t=e;return this.getName()===t.getName()}}C.VALUE_IDENTIFIER_TO_ECI=new Map,C.VALUES_TO_ECI=new Map,C.NAME_TO_ECI=new Map,C.Cp437=new C(S.Cp437,Int32Array.from([0,2]),`Cp437`),C.ISO8859_1=new C(S.ISO8859_1,Int32Array.from([1,3]),`ISO-8859-1`,`ISO88591`,`ISO8859_1`),C.ISO8859_2=new C(S.ISO8859_2,4,`ISO-8859-2`,`ISO88592`,`ISO8859_2`),C.ISO8859_3=new C(S.ISO8859_3,5,`ISO-8859-3`,`ISO88593`,`ISO8859_3`),C.ISO8859_4=new C(S.ISO8859_4,6,`ISO-8859-4`,`ISO88594`,`ISO8859_4`),C.ISO8859_5=new C(S.ISO8859_5,7,`ISO-8859-5`,`ISO88595`,`ISO8859_5`),C.ISO8859_6=new C(S.ISO8859_6,8,`ISO-8859-6`,`ISO88596`,`ISO8859_6`),C.ISO8859_7=new C(S.ISO8859_7,9,`ISO-8859-7`,`ISO88597`,`ISO8859_7`),C.ISO8859_8=new C(S.ISO8859_8,10,`ISO-8859-8`,`ISO88598`,`ISO8859_8`),C.ISO8859_9=new C(S.ISO8859_9,11,`ISO-8859-9`,`ISO88599`,`ISO8859_9`),C.ISO8859_10=new C(S.ISO8859_10,12,`ISO-8859-10`,`ISO885910`,`ISO8859_10`),C.ISO8859_11=new C(S.ISO8859_11,13,`ISO-8859-11`,`ISO885911`,`ISO8859_11`),C.ISO8859_13=new C(S.ISO8859_13,15,`ISO-8859-13`,`ISO885913`,`ISO8859_13`),C.ISO8859_14=new C(S.ISO8859_14,16,`ISO-8859-14`,`ISO885914`,`ISO8859_14`),C.ISO8859_15=new C(S.ISO8859_15,17,`ISO-8859-15`,`ISO885915`,`ISO8859_15`),C.ISO8859_16=new C(S.ISO8859_16,18,`ISO-8859-16`,`ISO885916`,`ISO8859_16`),C.SJIS=new C(S.SJIS,20,`SJIS`,`Shift_JIS`),C.Cp1250=new C(S.Cp1250,21,`Cp1250`,`windows-1250`),C.Cp1251=new C(S.Cp1251,22,`Cp1251`,`windows-1251`),C.Cp1252=new C(S.Cp1252,23,`Cp1252`,`windows-1252`),C.Cp1256=new C(S.Cp1256,24,`Cp1256`,`windows-1256`),C.UnicodeBigUnmarked=new C(S.UnicodeBigUnmarked,25,`UnicodeBigUnmarked`,`UTF-16BE`,`UnicodeBig`),C.UTF8=new C(S.UTF8,26,`UTF8`,`UTF-8`),C.ASCII=new C(S.ASCII,Int32Array.from([27,170]),`ASCII`,`US-ASCII`),C.Big5=new C(S.Big5,28,`Big5`),C.GB18030=new C(S.GB18030,29,`GB18030`,`GB2312`,`EUC_CN`,`GBK`),C.EUC_KR=new C(S.EUC_KR,30,`EUC_KR`,`EUC-KR`);class w extends s{}w.kind=`UnsupportedOperationException`;class T{static decode(e,t){let n=this.encodingName(t);return this.customDecoder?this.customDecoder(e,n):typeof TextDecoder>`u`||this.shouldDecodeOnFallback(n)?this.decodeFallback(e,n):new TextDecoder(n).decode(e)}static shouldDecodeOnFallback(e){return!T.isBrowser()&&e===`ISO-8859-1`}static encode(e,t){let n=this.encodingName(t);return this.customEncoder?this.customEncoder(e,n):typeof TextEncoder>`u`?this.encodeFallback(e):new TextEncoder().encode(e)}static isBrowser(){return typeof window<`u`&&{}.toString.call(window)===`[object Window]`}static encodingName(e){return typeof e==`string`?e:e.getName()}static encodingCharacterSet(e){return e instanceof C?e:C.getCharacterSetECIByName(e)}static decodeFallback(e,t){let n=this.encodingCharacterSet(t);if(T.isDecodeFallbackSupported(n)){let t=``;for(let n=0,r=e.length;n<r;n++){let r=e[n].toString(16);r.length<2&&(r=`0`+r),t+=`%`+r}return decodeURIComponent(t)}if(n.equals(C.UnicodeBigUnmarked))return String.fromCharCode.apply(null,new Uint16Array(e.buffer));throw new w(`Encoding ${this.encodingName(t)} not supported by fallback.`)}static isDecodeFallbackSupported(e){return e.equals(C.UTF8)||e.equals(C.ISO8859_1)||e.equals(C.ASCII)}static encodeFallback(e){let t=btoa(unescape(encodeURIComponent(e))).split(``),n=[];for(let e=0;e<t.length;e++)n.push(t[e].charCodeAt(0));return new Uint8Array(n)}}class E{static castAsNonUtf8Char(e,t=null){let n=t?t.getName():this.ISO88591;return T.decode(new Uint8Array([e]),n)}static guessEncoding(e,t){if(t!=null&&t.get(b.CHARACTER_SET)!==void 0)return t.get(b.CHARACTER_SET).toString();let n=e.length,r=!0,i=!0,a=!0,o=0,s=0,c=0,l=0,u=0,d=0,f=0,p=0,m=0,h=0,g=0,_=e.length>3&&e[0]===239&&e[1]===187&&e[2]===191;for(let t=0;t<n&&(r||i||a);t++){let n=e[t]&255;a&&(o>0?n&128?o--:a=!1:n&128&&(n&64?(o++,n&32?(o++,n&16?(o++,n&8?a=!1:l++):c++):s++):a=!1)),r&&(n>127&&n<160?r=!1:n>159&&(n<192||n===215||n===247)&&g++),i&&(u>0?n<64||n===127||n>252?i=!1:u--:n===128||n===160||n>239?i=!1:n>160&&n<224?(d++,p=0,f++,f>m&&(m=f)):n>127?(u++,f=0,p++,p>h&&(h=p)):(f=0,p=0))}return a&&o>0&&(a=!1),i&&u>0&&(i=!1),a&&(_||s+c+l>0)?E.UTF8:i&&(E.ASSUME_SHIFT_JIS||m>=3||h>=3)?E.SHIFT_JIS:r&&i?m===2&&d===2||g*10>=n?E.SHIFT_JIS:E.ISO88591:r?E.ISO88591:i?E.SHIFT_JIS:a?E.UTF8:E.PLATFORM_DEFAULT_ENCODING}static format(e,...t){let n=-1;function r(e,r,i,a,o,s){if(e===`%%`)return`%`;if(t[++n]===void 0)return;e=a?parseInt(a.substr(1)):void 0;let c=o?parseInt(o.substr(1)):void 0,l;switch(s){case`s`:l=t[n];break;case`c`:l=t[n][0];break;case`f`:l=parseFloat(t[n]).toFixed(e);break;case`p`:l=parseFloat(t[n]).toPrecision(e);break;case`e`:l=parseFloat(t[n]).toExponential(e);break;case`x`:l=parseInt(t[n]).toString(c||16);break;case`d`:l=parseFloat(parseInt(t[n],c||10).toPrecision(e)).toFixed(0);break}l=typeof l==`object`?JSON.stringify(l):(+l).toString(c);let u=parseInt(i),d=i&&i[0]+``==`0`?`0`:` `;for(;l.length<u;)l=r===void 0?d+l:l+d;return l}return e.replace(/%(-)?(0?[0-9]+)?([.][0-9]+)?([#][0-9]+)?([scfpexd%])/g,r)}static getBytes(e,t){return T.encode(e,t)}static getCharCode(e,t=0){return e.charCodeAt(t)}static getCharAt(e){return String.fromCharCode(e)}}E.SHIFT_JIS=C.SJIS.getName(),E.GB2312=`GB2312`,E.ISO88591=C.ISO8859_1.getName(),E.EUC_JP=`EUC_JP`,E.UTF8=C.UTF8.getName(),E.PLATFORM_DEFAULT_ENCODING=E.UTF8,E.ASSUME_SHIFT_JIS=!1;class D{constructor(e=``){this.value=e}enableDecoding(e){return this.encoding=e,this}append(e){return typeof e==`string`?this.value+=e.toString():this.encoding?this.value+=E.castAsNonUtf8Char(e,this.encoding):this.value+=String.fromCharCode(e),this}appendChars(e,t,n){for(let r=t;t<t+n;r++)this.append(e[r]);return this}length(){return this.value.length}charAt(e){return this.value.charAt(e)}deleteCharAt(e){this.value=this.value.substr(0,e)+this.value.substring(e+1)}setCharAt(e,t){this.value=this.value.substr(0,e)+t+this.value.substr(e+1)}substring(e,t){return this.value.substring(e,t)}setLengthToZero(){this.value=``}toString(){return this.value}insert(e,t){this.value=this.value.substr(0,e)+t+this.value.substr(e+t.length)}}class O{constructor(e,t,n,r){if(this.width=e,this.height=t,this.rowSize=n,this.bits=r,t??=e,this.height=t,e<1||t<1)throw new l(`Both dimensions must be greater than 0`);n??=Math.floor((e+31)/32),this.rowSize=n,r??(this.bits=new Int32Array(this.rowSize*this.height))}static parseFromBooleanArray(e){let t=e.length,n=e[0].length,r=new O(n,t);for(let i=0;i<t;i++){let t=e[i];for(let e=0;e<n;e++)t[e]&&r.set(e,i)}return r}static parseFromString(e,t,n){if(e===null)throw new l(`stringRepresentation cannot be null`);let r=Array(e.length),i=0,a=0,o=-1,s=0,c=0;for(;c<e.length;)if(e.charAt(c)===`
|
|
56
|
+
`||e.charAt(c)===`\r`){if(i>a){if(o===-1)o=i-a;else if(i-a!==o)throw new l(`row lengths do not match`);a=i,s++}c++}else if(e.substring(c,c+t.length)===t)c+=t.length,r[i]=!0,i++;else if(e.substring(c,c+n.length)===n)c+=n.length,r[i]=!1,i++;else throw new l(`illegal character encountered: `+e.substring(c));if(i>a){if(o===-1)o=i-a;else if(i-a!==o)throw new l(`row lengths do not match`);s++}let u=new O(o,s);for(let e=0;e<i;e++)r[e]&&u.set(Math.floor(e%o),Math.floor(e/o));return u}get(e,t){let n=t*this.rowSize+Math.floor(e/32);return(this.bits[n]>>>(e&31)&1)!=0}set(e,t){let n=t*this.rowSize+Math.floor(e/32);this.bits[n]|=1<<(e&31)&4294967295}unset(e,t){let n=t*this.rowSize+Math.floor(e/32);this.bits[n]&=~(1<<(e&31)&4294967295)}flip(e,t){let n=t*this.rowSize+Math.floor(e/32);this.bits[n]^=1<<(e&31)&4294967295}xor(e){if(this.width!==e.getWidth()||this.height!==e.getHeight()||this.rowSize!==e.getRowSize())throw new l(`input matrix dimensions do not match`);let t=new v(Math.floor(this.width/32)+1),n=this.rowSize,r=this.bits;for(let i=0,a=this.height;i<a;i++){let a=i*n,o=e.getRow(i,t).getBitArray();for(let e=0;e<n;e++)r[a+e]^=o[e]}}clear(){let e=this.bits,t=e.length;for(let n=0;n<t;n++)e[n]=0}setRegion(e,t,n,r){if(t<0||e<0)throw new l(`Left and top must be nonnegative`);if(r<1||n<1)throw new l(`Height and width must be at least 1`);let i=e+n,a=t+r;if(a>this.height||i>this.width)throw new l(`The region must fit inside the matrix`);let o=this.rowSize,s=this.bits;for(let n=t;n<a;n++){let t=n*o;for(let n=e;n<i;n++)s[t+Math.floor(n/32)]|=1<<(n&31)&4294967295}}getRow(e,t){t==null||t.getSize()<this.width?t=new v(this.width):t.clear();let n=this.rowSize,r=this.bits,i=e*n;for(let e=0;e<n;e++)t.setBulk(e*32,r[i+e]);return t}setRow(e,t){p.arraycopy(t.getBitArray(),0,this.bits,e*this.rowSize,this.rowSize)}rotate180(){let e=this.getWidth(),t=this.getHeight(),n=new v(e),r=new v(e);for(let e=0,i=Math.floor((t+1)/2);e<i;e++)n=this.getRow(e,n),r=this.getRow(t-1-e,r),n.reverse(),r.reverse(),this.setRow(e,r),this.setRow(t-1-e,n)}getEnclosingRectangle(){let e=this.width,t=this.height,n=this.rowSize,r=this.bits,i=e,a=t,o=-1,s=-1;for(let e=0;e<t;e++)for(let t=0;t<n;t++){let c=r[e*n+t];if(c!==0){if(e<a&&(a=e),e>s&&(s=e),t*32<i){let e=0;for(;!(c<<31-e&4294967295);)e++;t*32+e<i&&(i=t*32+e)}if(t*32+31>o){let e=31;for(;!(c>>>e);)e--;t*32+e>o&&(o=t*32+e)}}}return o<i||s<a?null:Int32Array.from([i,a,o-i+1,s-a+1])}getTopLeftOnBit(){let e=this.rowSize,t=this.bits,n=0;for(;n<t.length&&t[n]===0;)n++;if(n===t.length)return null;let r=n/e,i=n%e*32,a=t[n],o=0;for(;!(a<<31-o&4294967295);)o++;return i+=o,Int32Array.from([i,r])}getBottomRightOnBit(){let e=this.rowSize,t=this.bits,n=t.length-1;for(;n>=0&&t[n]===0;)n--;if(n<0)return null;let r=Math.floor(n/e),i=Math.floor(n%e)*32,a=t[n],o=31;for(;!(a>>>o);)o--;return i+=o,Int32Array.from([i,r])}getWidth(){return this.width}getHeight(){return this.height}getRowSize(){return this.rowSize}equals(e){if(!(e instanceof O))return!1;let t=e;return this.width===t.width&&this.height===t.height&&this.rowSize===t.rowSize&&g.equals(this.bits,t.bits)}hashCode(){let e=this.width;return e=31*e+this.width,e=31*e+this.height,e=31*e+this.rowSize,e=31*e+g.hashCode(this.bits),e}toString(e=`X `,t=` `,n=`
|
|
57
|
+
`){return this.buildToString(e,t,n)}buildToString(e,t,n){let r=new D;for(let i=0,a=this.height;i<a;i++){for(let n=0,a=this.width;n<a;n++)r.append(this.get(n,i)?e:t);r.append(n)}return r.toString()}clone(){return new O(this.width,this.height,this.rowSize,this.bits.slice())}}class k extends s{static getNotFoundInstance(){return new k}}k.kind=`NotFoundException`;class A extends f{constructor(e){super(e),this.luminances=A.EMPTY,this.buckets=new Int32Array(A.LUMINANCE_BUCKETS)}getBlackRow(e,t){let n=this.getLuminanceSource(),r=n.getWidth();t==null||t.getSize()<r?t=new v(r):t.clear(),this.initArrays(r);let i=n.getRow(e,this.luminances),a=this.buckets;for(let e=0;e<r;e++)a[(i[e]&255)>>A.LUMINANCE_SHIFT]++;let o=A.estimateBlackPoint(a);if(r<3)for(let e=0;e<r;e++)(i[e]&255)<o&&t.set(e);else{let e=i[0]&255,n=i[1]&255;for(let a=1;a<r-1;a++){let r=i[a+1]&255;(n*4-e-r)/2<o&&t.set(a),e=n,n=r}}return t}getBlackMatrix(){let e=this.getLuminanceSource(),t=e.getWidth(),n=e.getHeight(),r=new O(t,n);this.initArrays(t);let i=this.buckets;for(let r=1;r<5;r++){let a=Math.floor(n*r/5),o=e.getRow(a,this.luminances),s=Math.floor(t*4/5);for(let e=Math.floor(t/5);e<s;e++){let t=o[e]&255;i[t>>A.LUMINANCE_SHIFT]++}}let a=A.estimateBlackPoint(i),o=e.getMatrix();for(let e=0;e<n;e++){let n=e*t;for(let i=0;i<t;i++)(o[n+i]&255)<a&&r.set(i,e)}return r}createBinarizer(e){return new A(e)}initArrays(e){this.luminances.length<e&&(this.luminances=new Uint8ClampedArray(e));let t=this.buckets;for(let e=0;e<A.LUMINANCE_BUCKETS;e++)t[e]=0}static estimateBlackPoint(e){let t=e.length,n=0,r=0,i=0;for(let a=0;a<t;a++)e[a]>i&&(r=a,i=e[a]),e[a]>n&&(n=e[a]);let a=0,o=0;for(let n=0;n<t;n++){let t=n-r,i=e[n]*t*t;i>o&&(a=n,o=i)}if(r>a){let e=r;r=a,a=e}if(a-r<=t/16)throw new k;let s=a-1,c=-1;for(let t=a-1;t>r;t--){let i=t-r,o=i*i*(a-t)*(n-e[t]);o>c&&(s=t,c=o)}return s<<A.LUMINANCE_SHIFT}}A.LUMINANCE_BITS=5,A.LUMINANCE_SHIFT=8-A.LUMINANCE_BITS,A.LUMINANCE_BUCKETS=1<<A.LUMINANCE_BITS,A.EMPTY=Uint8ClampedArray.from([0]);class j extends A{constructor(e){super(e),this.matrix=null}getBlackMatrix(){if(this.matrix!==null)return this.matrix;let e=this.getLuminanceSource(),t=e.getWidth(),n=e.getHeight();if(t>=j.MINIMUM_DIMENSION&&n>=j.MINIMUM_DIMENSION){let r=e.getMatrix(),i=t>>j.BLOCK_SIZE_POWER;(t&j.BLOCK_SIZE_MASK)!==0&&i++;let a=n>>j.BLOCK_SIZE_POWER;(n&j.BLOCK_SIZE_MASK)!==0&&a++;let o=j.calculateBlackPoints(r,i,a,t,n),s=new O(t,n);j.calculateThresholdForBlock(r,i,a,t,n,o,s),this.matrix=s}else this.matrix=super.getBlackMatrix();return this.matrix}createBinarizer(e){return new j(e)}static calculateThresholdForBlock(e,t,n,r,i,a,o){let s=i-j.BLOCK_SIZE,c=r-j.BLOCK_SIZE;for(let i=0;i<n;i++){let l=i<<j.BLOCK_SIZE_POWER;l>s&&(l=s);let u=j.cap(i,2,n-3);for(let n=0;n<t;n++){let i=n<<j.BLOCK_SIZE_POWER;i>c&&(i=c);let s=j.cap(n,2,t-3),d=0;for(let e=-2;e<=2;e++){let t=a[u+e];d+=t[s-2]+t[s-1]+t[s]+t[s+1]+t[s+2]}let f=d/25;j.thresholdBlock(e,i,l,f,r,o)}}}static cap(e,t,n){return e<t?t:e>n?n:e}static thresholdBlock(e,t,n,r,i,a){for(let o=0,s=n*i+t;o<j.BLOCK_SIZE;o++,s+=i)for(let i=0;i<j.BLOCK_SIZE;i++)(e[s+i]&255)<=r&&a.set(t+i,n+o)}static calculateBlackPoints(e,t,n,r,i){let a=i-j.BLOCK_SIZE,o=r-j.BLOCK_SIZE,s=Array(n);for(let i=0;i<n;i++){s[i]=new Int32Array(t);let n=i<<j.BLOCK_SIZE_POWER;n>a&&(n=a);for(let a=0;a<t;a++){let t=a<<j.BLOCK_SIZE_POWER;t>o&&(t=o);let c=0,l=255,u=0;for(let i=0,a=n*r+t;i<j.BLOCK_SIZE;i++,a+=r){for(let t=0;t<j.BLOCK_SIZE;t++){let n=e[a+t]&255;c+=n,n<l&&(l=n),n>u&&(u=n)}if(u-l>j.MIN_DYNAMIC_RANGE)for(i++,a+=r;i<j.BLOCK_SIZE;i++,a+=r)for(let t=0;t<j.BLOCK_SIZE;t++)c+=e[a+t]&255}let d=c>>j.BLOCK_SIZE_POWER*2;if(u-l<=j.MIN_DYNAMIC_RANGE&&(d=l/2,i>0&&a>0)){let e=(s[i-1][a]+2*s[i][a-1]+s[i-1][a-1])/4;l<e&&(d=e)}s[i][a]=d}}return s}}j.BLOCK_SIZE_POWER=3,j.BLOCK_SIZE=1<<j.BLOCK_SIZE_POWER,j.BLOCK_SIZE_MASK=j.BLOCK_SIZE-1,j.MINIMUM_DIMENSION=j.BLOCK_SIZE*5,j.MIN_DYNAMIC_RANGE=24;class M{constructor(e,t){this.width=e,this.height=t}getWidth(){return this.width}getHeight(){return this.height}isCropSupported(){return!1}crop(e,t,n,r){throw new w(`This luminance source does not support cropping.`)}isRotateSupported(){return!1}rotateCounterClockwise(){throw new w(`This luminance source does not support rotation by 90 degrees.`)}rotateCounterClockwise45(){throw new w(`This luminance source does not support rotation by 45 degrees.`)}toString(){let e=new Uint8ClampedArray(this.width),t=new D;for(let n=0;n<this.height;n++){let r=this.getRow(n,e);for(let e=0;e<this.width;e++){let n=r[e]&255,i;i=n<64?`#`:n<128?`+`:n<192?`.`:` `,t.append(i)}t.append(`
|
|
58
|
+
`)}return t.toString()}}class N extends M{constructor(e){super(e.getWidth(),e.getHeight()),this.delegate=e}getRow(e,t){let n=this.delegate.getRow(e,t),r=this.getWidth();for(let e=0;e<r;e++)n[e]=255-(n[e]&255);return n}getMatrix(){let e=this.delegate.getMatrix(),t=this.getWidth()*this.getHeight(),n=new Uint8ClampedArray(t);for(let r=0;r<t;r++)n[r]=255-(e[r]&255);return n}isCropSupported(){return this.delegate.isCropSupported()}crop(e,t,n,r){return new N(this.delegate.crop(e,t,n,r))}isRotateSupported(){return this.delegate.isRotateSupported()}invert(){return this.delegate}rotateCounterClockwise(){return new N(this.delegate.rotateCounterClockwise())}rotateCounterClockwise45(){return new N(this.delegate.rotateCounterClockwise45())}}class P extends M{constructor(e){super(e.width,e.height),this.canvas=e,this.tempCanvasElement=null,this.buffer=P.makeBufferFromCanvasImageData(e)}static makeBufferFromCanvasImageData(e){let t=e.getContext(`2d`).getImageData(0,0,e.width,e.height);return P.toGrayscaleBuffer(t.data,e.width,e.height)}static toGrayscaleBuffer(e,t,n){let r=new Uint8ClampedArray(t*n);for(let t=0,n=0,i=e.length;t<i;t+=4,n++){let i;if(e[t+3]===0)i=255;else{let n=e[t],r=e[t+1],a=e[t+2];i=306*n+601*r+117*a+512>>10}r[n]=i}return r}getRow(e,t){if(e<0||e>=this.getHeight())throw new l(`Requested row is outside the image: `+e);let n=this.getWidth(),r=e*n;return t===null?t=this.buffer.slice(r,r+n):(t.length<n&&(t=new Uint8ClampedArray(n)),t.set(this.buffer.slice(r,r+n))),t}getMatrix(){return this.buffer}isCropSupported(){return!0}crop(e,t,n,r){return super.crop(e,t,n,r),this}isRotateSupported(){return!0}rotateCounterClockwise(){return this.rotate(-90),this}rotateCounterClockwise45(){return this.rotate(-45),this}getTempCanvasElement(){if(this.tempCanvasElement===null){let e=this.canvas.ownerDocument.createElement(`canvas`);e.width=this.canvas.width,e.height=this.canvas.height,this.tempCanvasElement=e}return this.tempCanvasElement}rotate(e){let t=this.getTempCanvasElement(),n=t.getContext(`2d`),r=e*P.DEGREE_TO_RADIANS,i=this.canvas.width,a=this.canvas.height,o=Math.ceil(Math.abs(Math.cos(r))*i+Math.abs(Math.sin(r))*a),s=Math.ceil(Math.abs(Math.sin(r))*i+Math.abs(Math.cos(r))*a);return t.width=o,t.height=s,n.translate(o/2,s/2),n.rotate(r),n.drawImage(this.canvas,i/-2,a/-2),this.buffer=P.makeBufferFromCanvasImageData(t),this}invert(){return new N(this)}}P.DEGREE_TO_RADIANS=Math.PI/180;class F{constructor(e,t,n){this.deviceId=e,this.label=t,this.kind=`videoinput`,this.groupId=n||void 0}toJSON(){return{kind:this.kind,groupId:this.groupId,deviceId:this.deviceId,label:this.label}}}var I=(globalThis||global||self||window||void 0)&&(globalThis||global||self||window||void 0).__awaiter||function(e,t,n,r){function i(e){return e instanceof n?e:new n(function(t){t(e)})}return new(n||=Promise)(function(n,a){function o(e){try{c(r.next(e))}catch(e){a(e)}}function s(e){try{c(r.throw(e))}catch(e){a(e)}}function c(e){e.done?n(e.value):i(e.value).then(o,s)}c((r=r.apply(e,t||[])).next())})};class L{constructor(e,t=500,n){this.reader=e,this.timeBetweenScansMillis=t,this._hints=n,this._stopContinuousDecode=!1,this._stopAsyncDecode=!1,this._timeBetweenDecodingAttempts=0}get hasNavigator(){return typeof navigator<`u`}get isMediaDevicesSuported(){return this.hasNavigator&&!!navigator.mediaDevices}get canEnumerateDevices(){return!!(this.isMediaDevicesSuported&&navigator.mediaDevices.enumerateDevices)}get timeBetweenDecodingAttempts(){return this._timeBetweenDecodingAttempts}set timeBetweenDecodingAttempts(e){this._timeBetweenDecodingAttempts=e<0?0:e}set hints(e){this._hints=e||null}get hints(){return this._hints}listVideoInputDevices(){return I(this,void 0,void 0,function*(){if(!this.hasNavigator)throw Error(`Can't enumerate devices, navigator is not present.`);if(!this.canEnumerateDevices)throw Error(`Can't enumerate devices, method not supported.`);let e=yield navigator.mediaDevices.enumerateDevices(),t=[];for(let n of e){let e=n.kind===`video`?`videoinput`:n.kind;if(e!==`videoinput`)continue;let r={deviceId:n.deviceId||n.id,label:n.label||`Video device ${t.length+1}`,kind:e,groupId:n.groupId};t.push(r)}return t})}getVideoInputDevices(){return I(this,void 0,void 0,function*(){return(yield this.listVideoInputDevices()).map(e=>new F(e.deviceId,e.label))})}findDeviceById(e){return I(this,void 0,void 0,function*(){let t=yield this.listVideoInputDevices();return t?t.find(t=>t.deviceId===e):null})}decodeFromInputVideoDevice(e,t){return I(this,void 0,void 0,function*(){return yield this.decodeOnceFromVideoDevice(e,t)})}decodeOnceFromVideoDevice(e,t){return I(this,void 0,void 0,function*(){this.reset();let n;n=e?{deviceId:{exact:e}}:{facingMode:`environment`};let r={video:n};return yield this.decodeOnceFromConstraints(r,t)})}decodeOnceFromConstraints(e,t){return I(this,void 0,void 0,function*(){let n=yield navigator.mediaDevices.getUserMedia(e);return yield this.decodeOnceFromStream(n,t)})}decodeOnceFromStream(e,t){return I(this,void 0,void 0,function*(){this.reset();let n=yield this.attachStreamToVideo(e,t);return yield this.decodeOnce(n)})}decodeFromInputVideoDeviceContinuously(e,t,n){return I(this,void 0,void 0,function*(){return yield this.decodeFromVideoDevice(e,t,n)})}decodeFromVideoDevice(e,t,n){return I(this,void 0,void 0,function*(){let r;r=e?{deviceId:{exact:e}}:{facingMode:`environment`};let i={video:r};return yield this.decodeFromConstraints(i,t,n)})}decodeFromConstraints(e,t,n){return I(this,void 0,void 0,function*(){let r=yield navigator.mediaDevices.getUserMedia(e);return yield this.decodeFromStream(r,t,n)})}decodeFromStream(e,t,n){return I(this,void 0,void 0,function*(){this.reset();let r=yield this.attachStreamToVideo(e,t);return yield this.decodeContinuously(r,n)})}stopAsyncDecode(){this._stopAsyncDecode=!0}stopContinuousDecode(){this._stopContinuousDecode=!0}attachStreamToVideo(e,t){return I(this,void 0,void 0,function*(){let n=this.prepareVideoElement(t);return this.addVideoSource(n,e),this.videoElement=n,this.stream=e,yield this.playVideoOnLoadAsync(n),n})}playVideoOnLoadAsync(e){return new Promise((t,n)=>this.playVideoOnLoad(e,()=>t()))}playVideoOnLoad(e,t){this.videoEndedListener=()=>this.stopStreams(),this.videoCanPlayListener=()=>this.tryPlayVideo(e),e.addEventListener(`ended`,this.videoEndedListener),e.addEventListener(`canplay`,this.videoCanPlayListener),e.addEventListener(`playing`,t),this.tryPlayVideo(e)}isVideoPlaying(e){return e.currentTime>0&&!e.paused&&!e.ended&&e.readyState>2}tryPlayVideo(e){return I(this,void 0,void 0,function*(){if(this.isVideoPlaying(e)){console.warn(`Trying to play video that is already playing.`);return}try{yield e.play()}catch{console.warn(`It was not possible to play the video.`)}})}getMediaElement(e,t){let n=document.getElementById(e);if(!n)throw new c(`element with id '${e}' not found`);if(n.nodeName.toLowerCase()!==t.toLowerCase())throw new c(`element with id '${e}' must be an ${t} element`);return n}decodeFromImage(e,t){if(!e&&!t)throw new c(`either imageElement with a src set or an url must be provided`);return t&&!e?this.decodeFromImageUrl(t):this.decodeFromImageElement(e)}decodeFromVideo(e,t){if(!e&&!t)throw new c(`Either an element with a src set or an URL must be provided`);return t&&!e?this.decodeFromVideoUrl(t):this.decodeFromVideoElement(e)}decodeFromVideoContinuously(e,t,n){if(e===void 0&&t===void 0)throw new c(`Either an element with a src set or an URL must be provided`);return t&&!e?this.decodeFromVideoUrlContinuously(t,n):this.decodeFromVideoElementContinuously(e,n)}decodeFromImageElement(e){if(!e)throw new c(`An image element must be provided.`);this.reset();let t=this.prepareImageElement(e);this.imageElement=t;let n;return n=this.isImageLoaded(t)?this.decodeOnce(t,!1,!0):this._decodeOnLoadImage(t),n}decodeFromVideoElement(e){let t=this._decodeFromVideoElementSetup(e);return this._decodeOnLoadVideo(t)}decodeFromVideoElementContinuously(e,t){let n=this._decodeFromVideoElementSetup(e);return this._decodeOnLoadVideoContinuously(n,t)}_decodeFromVideoElementSetup(e){if(!e)throw new c(`A video element must be provided.`);this.reset();let t=this.prepareVideoElement(e);return this.videoElement=t,t}decodeFromImageUrl(e){if(!e)throw new c(`An URL must be provided.`);this.reset();let t=this.prepareImageElement();this.imageElement=t;let n=this._decodeOnLoadImage(t);return t.src=e,n}decodeFromVideoUrl(e){if(!e)throw new c(`An URL must be provided.`);this.reset();let t=this.prepareVideoElement(),n=this.decodeFromVideoElement(t);return t.src=e,n}decodeFromVideoUrlContinuously(e,t){if(!e)throw new c(`An URL must be provided.`);this.reset();let n=this.prepareVideoElement(),r=this.decodeFromVideoElementContinuously(n,t);return n.src=e,r}_decodeOnLoadImage(e){return new Promise((t,n)=>{this.imageLoadedListener=()=>this.decodeOnce(e,!1,!0).then(t,n),e.addEventListener(`load`,this.imageLoadedListener)})}_decodeOnLoadVideo(e){return I(this,void 0,void 0,function*(){return yield this.playVideoOnLoadAsync(e),yield this.decodeOnce(e)})}_decodeOnLoadVideoContinuously(e,t){return I(this,void 0,void 0,function*(){yield this.playVideoOnLoadAsync(e),this.decodeContinuously(e,t)})}isImageLoaded(e){return!(!e.complete||e.naturalWidth===0)}prepareImageElement(e){let t;return e===void 0&&(t=document.createElement(`img`),t.width=200,t.height=200),typeof e==`string`&&(t=this.getMediaElement(e,`img`)),e instanceof HTMLImageElement&&(t=e),t}prepareVideoElement(e){let t;return!e&&typeof document<`u`&&(t=document.createElement(`video`),t.width=200,t.height=200),typeof e==`string`&&(t=this.getMediaElement(e,`video`)),e instanceof HTMLVideoElement&&(t=e),t.setAttribute(`autoplay`,`true`),t.setAttribute(`muted`,`true`),t.setAttribute(`playsinline`,`true`),t}decodeOnce(e,t=!0,n=!0){this._stopAsyncDecode=!1;let r=(i,a)=>{if(this._stopAsyncDecode){a(new k(`Video stream has ended before any code could be detected.`)),this._stopAsyncDecode=void 0;return}try{i(this.decode(e))}catch(e){let o=t&&e instanceof k,s=(e instanceof d||e instanceof x)&&n;if(o||s)return setTimeout(r,this._timeBetweenDecodingAttempts,i,a);a(e)}};return new Promise((e,t)=>r(e,t))}decodeContinuously(e,t){this._stopContinuousDecode=!1;let n=()=>{if(this._stopContinuousDecode){this._stopContinuousDecode=void 0;return}try{t(this.decode(e),null),setTimeout(n,this.timeBetweenScansMillis)}catch(e){t(null,e);let r=e instanceof d||e instanceof x,i=e instanceof k;(r||i)&&setTimeout(n,this._timeBetweenDecodingAttempts)}};n()}decode(e){let t=this.createBinaryBitmap(e);return this.decodeBitmap(t)}_isHTMLVideoElement(e){return e.videoWidth!==0}drawFrameOnCanvas(e,t,n){t||={sx:0,sy:0,sWidth:e.videoWidth,sHeight:e.videoHeight,dx:0,dy:0,dWidth:e.videoWidth,dHeight:e.videoHeight},n||=this.captureCanvasContext,n.drawImage(e,t.sx,t.sy,t.sWidth,t.sHeight,t.dx,t.dy,t.dWidth,t.dHeight)}drawImageOnCanvas(e,t,n=this.captureCanvasContext){t||={sx:0,sy:0,sWidth:e.naturalWidth,sHeight:e.naturalHeight,dx:0,dy:0,dWidth:e.naturalWidth,dHeight:e.naturalHeight},n||=this.captureCanvasContext,n.drawImage(e,t.sx,t.sy,t.sWidth,t.sHeight,t.dx,t.dy,t.dWidth,t.dHeight)}createBinaryBitmap(e){return this.getCaptureCanvasContext(e),this._isHTMLVideoElement(e)?this.drawFrameOnCanvas(e):this.drawImageOnCanvas(e),new u(new j(new P(this.getCaptureCanvas(e))))}getCaptureCanvasContext(e){if(!this.captureCanvasContext){let t=this.getCaptureCanvas(e).getContext(`2d`);this.captureCanvasContext=t}return this.captureCanvasContext}getCaptureCanvas(e){if(!this.captureCanvas){let t=this.createCaptureCanvas(e);this.captureCanvas=t}return this.captureCanvas}decodeBitmap(e){return this.reader.decode(e,this._hints)}createCaptureCanvas(e){if(typeof document>`u`)return this._destroyCaptureCanvas(),null;let t=document.createElement(`canvas`),n,r;return e!==void 0&&(e instanceof HTMLVideoElement?(n=e.videoWidth,r=e.videoHeight):e instanceof HTMLImageElement&&(n=e.naturalWidth||e.width,r=e.naturalHeight||e.height)),t.style.width=n+`px`,t.style.height=r+`px`,t.width=n,t.height=r,t}stopStreams(){this.stream&&=(this.stream.getVideoTracks().forEach(e=>e.stop()),void 0),this._stopAsyncDecode===!1&&this.stopAsyncDecode(),this._stopContinuousDecode===!1&&this.stopContinuousDecode()}reset(){this.stopStreams(),this._destroyVideoElement(),this._destroyImageElement(),this._destroyCaptureCanvas()}_destroyVideoElement(){this.videoElement&&=(this.videoEndedListener!==void 0&&this.videoElement.removeEventListener(`ended`,this.videoEndedListener),this.videoPlayingEventListener!==void 0&&this.videoElement.removeEventListener(`playing`,this.videoPlayingEventListener),this.videoCanPlayListener!==void 0&&this.videoElement.removeEventListener(`loadedmetadata`,this.videoCanPlayListener),this.cleanVideoSource(this.videoElement),void 0)}_destroyImageElement(){this.imageElement&&=(this.imageLoadedListener!==void 0&&this.imageElement.removeEventListener(`load`,this.imageLoadedListener),this.imageElement.src=void 0,this.imageElement.removeAttribute(`src`),void 0)}_destroyCaptureCanvas(){this.captureCanvasContext=void 0,this.captureCanvas=void 0}addVideoSource(e,t){try{e.srcObject=t}catch{e.src=URL.createObjectURL(t)}}cleanVideoSource(e){try{e.srcObject=null}catch{e.src=``}this.videoElement.removeAttribute(`src`)}}class R{constructor(e,t,n=t==null?0:8*t.length,r,i,a=p.currentTimeMillis()){this.text=e,this.rawBytes=t,this.numBits=n,this.resultPoints=r,this.format=i,this.timestamp=a,this.text=e,this.rawBytes=t,n==null?this.numBits=t==null?0:8*t.length:this.numBits=n,this.resultPoints=r,this.format=i,this.resultMetadata=null,a==null?this.timestamp=p.currentTimeMillis():this.timestamp=a}getText(){return this.text}getRawBytes(){return this.rawBytes}getNumBits(){return this.numBits}getResultPoints(){return this.resultPoints}getBarcodeFormat(){return this.format}getResultMetadata(){return this.resultMetadata}putMetadata(e,t){this.resultMetadata===null&&(this.resultMetadata=new Map),this.resultMetadata.set(e,t)}putAllMetadata(e){e!==null&&(this.resultMetadata===null?this.resultMetadata=e:this.resultMetadata=new Map(e))}addResultPoints(e){let t=this.resultPoints;if(t===null)this.resultPoints=e;else if(e!==null&&e.length>0){let n=Array(t.length+e.length);p.arraycopy(t,0,n,0,t.length),p.arraycopy(e,0,n,t.length,e.length),this.resultPoints=n}}getTimestamp(){return this.timestamp}toString(){return this.text}}var z;(function(e){e[e.AZTEC=0]=`AZTEC`,e[e.CODABAR=1]=`CODABAR`,e[e.CODE_39=2]=`CODE_39`,e[e.CODE_93=3]=`CODE_93`,e[e.CODE_128=4]=`CODE_128`,e[e.DATA_MATRIX=5]=`DATA_MATRIX`,e[e.EAN_8=6]=`EAN_8`,e[e.EAN_13=7]=`EAN_13`,e[e.ITF=8]=`ITF`,e[e.MAXICODE=9]=`MAXICODE`,e[e.PDF_417=10]=`PDF_417`,e[e.QR_CODE=11]=`QR_CODE`,e[e.RSS_14=12]=`RSS_14`,e[e.RSS_EXPANDED=13]=`RSS_EXPANDED`,e[e.UPC_A=14]=`UPC_A`,e[e.UPC_E=15]=`UPC_E`,e[e.UPC_EAN_EXTENSION=16]=`UPC_EAN_EXTENSION`})(z||={});var B=z,ee;(function(e){e[e.OTHER=0]=`OTHER`,e[e.ORIENTATION=1]=`ORIENTATION`,e[e.BYTE_SEGMENTS=2]=`BYTE_SEGMENTS`,e[e.ERROR_CORRECTION_LEVEL=3]=`ERROR_CORRECTION_LEVEL`,e[e.ISSUE_NUMBER=4]=`ISSUE_NUMBER`,e[e.SUGGESTED_PRICE=5]=`SUGGESTED_PRICE`,e[e.POSSIBLE_COUNTRY=6]=`POSSIBLE_COUNTRY`,e[e.UPC_EAN_EXTENSION=7]=`UPC_EAN_EXTENSION`,e[e.PDF417_EXTRA_METADATA=8]=`PDF417_EXTRA_METADATA`,e[e.STRUCTURED_APPEND_SEQUENCE=9]=`STRUCTURED_APPEND_SEQUENCE`,e[e.STRUCTURED_APPEND_PARITY=10]=`STRUCTURED_APPEND_PARITY`})(ee||={});var te=ee;class ne{constructor(e,t,n,r,i=-1,a=-1){this.rawBytes=e,this.text=t,this.byteSegments=n,this.ecLevel=r,this.structuredAppendSequenceNumber=i,this.structuredAppendParity=a,this.numBits=e==null?0:8*e.length}getRawBytes(){return this.rawBytes}getNumBits(){return this.numBits}setNumBits(e){this.numBits=e}getText(){return this.text}getByteSegments(){return this.byteSegments}getECLevel(){return this.ecLevel}getErrorsCorrected(){return this.errorsCorrected}setErrorsCorrected(e){this.errorsCorrected=e}getErasures(){return this.erasures}setErasures(e){this.erasures=e}getOther(){return this.other}setOther(e){this.other=e}hasStructuredAppend(){return this.structuredAppendParity>=0&&this.structuredAppendSequenceNumber>=0}getStructuredAppendParity(){return this.structuredAppendParity}getStructuredAppendSequenceNumber(){return this.structuredAppendSequenceNumber}}class re{exp(e){return this.expTable[e]}log(e){if(e===0)throw new l;return this.logTable[e]}static addOrSubtract(e,t){return e^t}}class ie{constructor(e,t){if(t.length===0)throw new l;this.field=e;let n=t.length;if(n>1&&t[0]===0){let e=1;for(;e<n&&t[e]===0;)e++;e===n?this.coefficients=Int32Array.from([0]):(this.coefficients=new Int32Array(n-e),p.arraycopy(t,e,this.coefficients,0,this.coefficients.length))}else this.coefficients=t}getCoefficients(){return this.coefficients}getDegree(){return this.coefficients.length-1}isZero(){return this.coefficients[0]===0}getCoefficient(e){return this.coefficients[this.coefficients.length-1-e]}evaluateAt(e){if(e===0)return this.getCoefficient(0);let t=this.coefficients,n;if(e===1){n=0;for(let e=0,r=t.length;e!==r;e++){let r=t[e];n=re.addOrSubtract(n,r)}return n}n=t[0];let r=t.length,i=this.field;for(let a=1;a<r;a++)n=re.addOrSubtract(i.multiply(e,n),t[a]);return n}addOrSubtract(e){if(!this.field.equals(e.field))throw new l(`GenericGFPolys do not have same GenericGF field`);if(this.isZero())return e;if(e.isZero())return this;let t=this.coefficients,n=e.coefficients;if(t.length>n.length){let e=t;t=n,n=e}let r=new Int32Array(n.length),i=n.length-t.length;p.arraycopy(n,0,r,0,i);for(let e=i;e<n.length;e++)r[e]=re.addOrSubtract(t[e-i],n[e]);return new ie(this.field,r)}multiply(e){if(!this.field.equals(e.field))throw new l(`GenericGFPolys do not have same GenericGF field`);if(this.isZero()||e.isZero())return this.field.getZero();let t=this.coefficients,n=t.length,r=e.coefficients,i=r.length,a=new Int32Array(n+i-1),o=this.field;for(let e=0;e<n;e++){let n=t[e];for(let t=0;t<i;t++)a[e+t]=re.addOrSubtract(a[e+t],o.multiply(n,r[t]))}return new ie(o,a)}multiplyScalar(e){if(e===0)return this.field.getZero();if(e===1)return this;let t=this.coefficients.length,n=this.field,r=new Int32Array(t),i=this.coefficients;for(let a=0;a<t;a++)r[a]=n.multiply(i[a],e);return new ie(n,r)}multiplyByMonomial(e,t){if(e<0)throw new l;if(t===0)return this.field.getZero();let n=this.coefficients,r=n.length,i=new Int32Array(r+e),a=this.field;for(let e=0;e<r;e++)i[e]=a.multiply(n[e],t);return new ie(a,i)}divide(e){if(!this.field.equals(e.field))throw new l(`GenericGFPolys do not have same GenericGF field`);if(e.isZero())throw new l(`Divide by 0`);let t=this.field,n=t.getZero(),r=this,i=e.getCoefficient(e.getDegree()),a=t.inverse(i);for(;r.getDegree()>=e.getDegree()&&!r.isZero();){let i=r.getDegree()-e.getDegree(),o=t.multiply(r.getCoefficient(r.getDegree()),a),s=e.multiplyByMonomial(i,o),c=t.buildMonomial(i,o);n=n.addOrSubtract(c),r=r.addOrSubtract(s)}return[n,r]}toString(){let e=``;for(let t=this.getDegree();t>=0;t--){let n=this.getCoefficient(t);if(n!==0){if(n<0?(e+=` - `,n=-n):e.length>0&&(e+=` + `),t===0||n!==1){let t=this.field.log(n);t===0?e+=`1`:t===1?e+=`a`:(e+=`a^`,e+=t)}t!==0&&(t===1?e+=`x`:(e+=`x^`,e+=t))}}return e}}class ae extends s{}ae.kind=`ArithmeticException`;class oe extends re{constructor(e,t,n){super(),this.primitive=e,this.size=t,this.generatorBase=n;let r=new Int32Array(t),i=1;for(let n=0;n<t;n++)r[n]=i,i*=2,i>=t&&(i^=e,i&=t-1);this.expTable=r;let a=new Int32Array(t);for(let e=0;e<t-1;e++)a[r[e]]=e;this.logTable=a,this.zero=new ie(this,Int32Array.from([0])),this.one=new ie(this,Int32Array.from([1]))}getZero(){return this.zero}getOne(){return this.one}buildMonomial(e,t){if(e<0)throw new l;if(t===0)return this.zero;let n=new Int32Array(e+1);return n[0]=t,new ie(this,n)}inverse(e){if(e===0)throw new ae;return this.expTable[this.size-this.logTable[e]-1]}multiply(e,t){return e===0||t===0?0:this.expTable[(this.logTable[e]+this.logTable[t])%(this.size-1)]}getSize(){return this.size}getGeneratorBase(){return this.generatorBase}toString(){return`GF(0x`+_.toHexString(this.primitive)+`,`+this.size+`)`}equals(e){return e===this}}oe.AZTEC_DATA_12=new oe(4201,4096,1),oe.AZTEC_DATA_10=new oe(1033,1024,1),oe.AZTEC_DATA_6=new oe(67,64,1),oe.AZTEC_PARAM=new oe(19,16,1),oe.QR_CODE_FIELD_256=new oe(285,256,0),oe.DATA_MATRIX_FIELD_256=new oe(301,256,1),oe.AZTEC_DATA_8=oe.DATA_MATRIX_FIELD_256,oe.MAXICODE_FIELD_64=oe.AZTEC_DATA_6;class se extends s{}se.kind=`ReedSolomonException`;class ce extends s{}ce.kind=`IllegalStateException`;class le{constructor(e){this.field=e}decode(e,t){let n=this.field,r=new ie(n,e),i=new Int32Array(t),a=!0;for(let e=0;e<t;e++){let t=r.evaluateAt(n.exp(e+n.getGeneratorBase()));i[i.length-1-e]=t,t!==0&&(a=!1)}if(a)return;let o=new ie(n,i),s=this.runEuclideanAlgorithm(n.buildMonomial(t,1),o,t),c=s[0],l=s[1],u=this.findErrorLocations(c),d=this.findErrorMagnitudes(l,u);for(let t=0;t<u.length;t++){let r=e.length-1-n.log(u[t]);if(r<0)throw new se(`Bad error location`);e[r]=oe.addOrSubtract(e[r],d[t])}}runEuclideanAlgorithm(e,t,n){if(e.getDegree()<t.getDegree()){let n=e;e=t,t=n}let r=this.field,i=e,a=t,o=r.getZero(),s=r.getOne();for(;a.getDegree()>=(n/2|0);){let e=i,t=o;if(i=a,o=s,i.isZero())throw new se(`r_{i-1} was zero`);a=e;let n=r.getZero(),c=i.getCoefficient(i.getDegree()),l=r.inverse(c);for(;a.getDegree()>=i.getDegree()&&!a.isZero();){let e=a.getDegree()-i.getDegree(),t=r.multiply(a.getCoefficient(a.getDegree()),l);n=n.addOrSubtract(r.buildMonomial(e,t)),a=a.addOrSubtract(i.multiplyByMonomial(e,t))}if(s=n.multiply(o).addOrSubtract(t),a.getDegree()>=i.getDegree())throw new ce(`Division algorithm failed to reduce polynomial?`)}let c=s.getCoefficient(0);if(c===0)throw new se(`sigmaTilde(0) was zero`);let l=r.inverse(c);return[s.multiplyScalar(l),a.multiplyScalar(l)]}findErrorLocations(e){let t=e.getDegree();if(t===1)return Int32Array.from([e.getCoefficient(1)]);let n=new Int32Array(t),r=0,i=this.field;for(let a=1;a<i.getSize()&&r<t;a++)e.evaluateAt(a)===0&&(n[r]=i.inverse(a),r++);if(r!==t)throw new se(`Error locator degree does not match number of roots`);return n}findErrorMagnitudes(e,t){let n=t.length,r=new Int32Array(n),i=this.field;for(let a=0;a<n;a++){let o=i.inverse(t[a]),s=1;for(let e=0;e<n;e++)if(a!==e){let n=i.multiply(t[e],o),r=n&1?n&-2:n|1;s=i.multiply(s,r)}r[a]=i.multiply(e.evaluateAt(o),i.inverse(s)),i.getGeneratorBase()!==0&&(r[a]=i.multiply(r[a],o))}return r}}var ue;(function(e){e[e.UPPER=0]=`UPPER`,e[e.LOWER=1]=`LOWER`,e[e.MIXED=2]=`MIXED`,e[e.DIGIT=3]=`DIGIT`,e[e.PUNCT=4]=`PUNCT`,e[e.BINARY=5]=`BINARY`})(ue||={});class de{decode(e){this.ddata=e;let t=e.getBits(),n=this.extractBits(t),r=this.correctBits(n),i=new ne(de.convertBoolArrayToByteArray(r),de.getEncodedData(r),null,null);return i.setNumBits(r.length),i}static highLevelDecode(e){return this.getEncodedData(e)}static getEncodedData(e){let t=e.length,n=ue.UPPER,r=ue.UPPER,i=``,a=0;for(;a<t;)if(r===ue.BINARY){if(t-a<5)break;let o=de.readCode(e,a,5);if(a+=5,o===0){if(t-a<11)break;o=de.readCode(e,a,11)+31,a+=11}for(let n=0;n<o;n++){if(t-a<8){a=t;break}let n=de.readCode(e,a,8);i+=E.castAsNonUtf8Char(n),a+=8}r=n}else{let o=r===ue.DIGIT?4:5;if(t-a<o)break;let s=de.readCode(e,a,o);a+=o;let c=de.getCharacter(r,s);c.startsWith(`CTRL_`)?(n=r,r=de.getTable(c.charAt(5)),c.charAt(6)===`L`&&(n=r)):(i+=c,r=n)}return i}static getTable(e){switch(e){case`L`:return ue.LOWER;case`P`:return ue.PUNCT;case`M`:return ue.MIXED;case`D`:return ue.DIGIT;case`B`:return ue.BINARY;default:return ue.UPPER}}static getCharacter(e,t){switch(e){case ue.UPPER:return de.UPPER_TABLE[t];case ue.LOWER:return de.LOWER_TABLE[t];case ue.MIXED:return de.MIXED_TABLE[t];case ue.PUNCT:return de.PUNCT_TABLE[t];case ue.DIGIT:return de.DIGIT_TABLE[t];default:throw new ce(`Bad table`)}}correctBits(e){let t,n;this.ddata.getNbLayers()<=2?(n=6,t=oe.AZTEC_DATA_6):this.ddata.getNbLayers()<=8?(n=8,t=oe.AZTEC_DATA_8):this.ddata.getNbLayers()<=22?(n=10,t=oe.AZTEC_DATA_10):(n=12,t=oe.AZTEC_DATA_12);let r=this.ddata.getNbDatablocks(),i=e.length/n;if(i<r)throw new x;let a=e.length%n,o=new Int32Array(i);for(let t=0;t<i;t++,a+=n)o[t]=de.readCode(e,a,n);try{new le(t).decode(o,i-r)}catch(e){throw new x(e)}let s=(1<<n)-1,c=0;for(let e=0;e<r;e++){let t=o[e];if(t===0||t===s)throw new x;(t===1||t===s-1)&&c++}let l=Array(r*n-c),u=0;for(let e=0;e<r;e++){let t=o[e];if(t===1||t===s-1)l.fill(t>1,u,u+n-1),u+=n-1;else for(let e=n-1;e>=0;--e)l[u++]=(t&1<<e)!=0}return l}extractBits(e){let t=this.ddata.isCompact(),n=this.ddata.getNbLayers(),r=(t?11:14)+n*4,i=new Int32Array(r),a=Array(this.totalBitsInLayer(n,t));if(t)for(let e=0;e<i.length;e++)i[e]=e;else{let e=r+1+2*_.truncDivision(_.truncDivision(r,2)-1,15),t=r/2,n=_.truncDivision(e,2);for(let e=0;e<t;e++){let r=e+_.truncDivision(e,15);i[t-e-1]=n-r-1,i[t+e]=n+r+1}}for(let o=0,s=0;o<n;o++){let c=(n-o)*4+(t?9:12),l=o*2,u=r-1-l;for(let t=0;t<c;t++){let n=t*2;for(let r=0;r<2;r++)a[s+n+r]=e.get(i[l+r],i[l+t]),a[s+2*c+n+r]=e.get(i[l+t],i[u-r]),a[s+4*c+n+r]=e.get(i[u-r],i[u-t]),a[s+6*c+n+r]=e.get(i[u-t],i[l+r])}s+=c*8}return a}static readCode(e,t,n){let r=0;for(let i=t;i<t+n;i++)r<<=1,e[i]&&(r|=1);return r}static readByte(e,t){let n=e.length-t;return n>=8?de.readCode(e,t,8):de.readCode(e,t,n)<<8-n}static convertBoolArrayToByteArray(e){let t=new Uint8Array((e.length+7)/8);for(let n=0;n<t.length;n++)t[n]=de.readByte(e,8*n);return t}totalBitsInLayer(e,t){return((t?88:112)+16*e)*e}}de.UPPER_TABLE=`CTRL_PS. .A.B.C.D.E.F.G.H.I.J.K.L.M.N.O.P.Q.R.S.T.U.V.W.X.Y.Z.CTRL_LL.CTRL_ML.CTRL_DL.CTRL_BS`.split(`.`),de.LOWER_TABLE=`CTRL_PS. .a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z.CTRL_US.CTRL_ML.CTRL_DL.CTRL_BS`.split(`.`),de.MIXED_TABLE=`CTRL_PS. .\\1.\\2.\\3.\\4.\\5.\\6.\\7.\b. .
|
|
59
|
+
.\\13.\f.\r.\\33.\\34.\\35.\\36.\\37.@.\\.^._.\`.|.~.\\177.CTRL_LL.CTRL_UL.CTRL_PL.CTRL_BS`.split(`.`),de.PUNCT_TABLE=[``,`\r`,`\r
|
|
60
|
+
`,`. `,`, `,`: `,`!`,`"`,`#`,`$`,`%`,`&`,`'`,`(`,`)`,`*`,`+`,`,`,`-`,`.`,`/`,`:`,`;`,`<`,`=`,`>`,`?`,`[`,`]`,`{`,`}`,`CTRL_UL`],de.DIGIT_TABLE=[`CTRL_PS`,` `,`0`,`1`,`2`,`3`,`4`,`5`,`6`,`7`,`8`,`9`,`,`,`.`,`CTRL_UL`,`CTRL_US`];class fe{constructor(){}static round(e){return e===NaN?0:e<=-(2**53-1)?-(2**53-1):e>=2**53-1?2**53-1:e+(e<0?-.5:.5)|0}static distance(e,t,n,r){let i=e-n,a=t-r;return Math.sqrt(i*i+a*a)}static sum(e){let t=0;for(let n=0,r=e.length;n!==r;n++){let r=e[n];t+=r}return t}}class pe{static floatToIntBits(e){return e}}pe.MAX_VALUE=2**53-1;class V{constructor(e,t){this.x=e,this.y=t}getX(){return this.x}getY(){return this.y}equals(e){if(e instanceof V){let t=e;return this.x===t.x&&this.y===t.y}return!1}hashCode(){return 31*pe.floatToIntBits(this.x)+pe.floatToIntBits(this.y)}toString(){return`(`+this.x+`,`+this.y+`)`}static orderBestPatterns(e){let t=this.distance(e[0],e[1]),n=this.distance(e[1],e[2]),r=this.distance(e[0],e[2]),i,a,o;if(n>=t&&n>=r?(a=e[0],i=e[1],o=e[2]):r>=n&&r>=t?(a=e[1],i=e[0],o=e[2]):(a=e[2],i=e[0],o=e[1]),this.crossProductZ(i,a,o)<0){let e=i;i=o,o=e}e[0]=i,e[1]=a,e[2]=o}static distance(e,t){return fe.distance(e.x,e.y,t.x,t.y)}static crossProductZ(e,t,n){let r=t.x,i=t.y;return(n.x-r)*(e.y-i)-(n.y-i)*(e.x-r)}}class me{constructor(e,t){this.bits=e,this.points=t}getBits(){return this.bits}getPoints(){return this.points}}class he extends me{constructor(e,t,n,r,i){super(e,t),this.compact=n,this.nbDatablocks=r,this.nbLayers=i}getNbLayers(){return this.nbLayers}getNbDatablocks(){return this.nbDatablocks}isCompact(){return this.compact}}class ge{constructor(e,t,n,r){this.image=e,this.height=e.getHeight(),this.width=e.getWidth(),t??=ge.INIT_SIZE,n??=e.getWidth()/2|0,r??=e.getHeight()/2|0;let i=t/2|0;if(this.leftInit=n-i,this.rightInit=n+i,this.upInit=r-i,this.downInit=r+i,this.upInit<0||this.leftInit<0||this.downInit>=this.height||this.rightInit>=this.width)throw new k}detect(){let e=this.leftInit,t=this.rightInit,n=this.upInit,r=this.downInit,i=!1,a=!0,o=!1,s=!1,c=!1,l=!1,u=!1,d=this.width,f=this.height;for(;a;){a=!1;let p=!0;for(;(p||!s)&&t<d;)p=this.containsBlackPoint(n,r,t,!1),p?(t++,a=!0,s=!0):s||t++;if(t>=d){i=!0;break}let m=!0;for(;(m||!c)&&r<f;)m=this.containsBlackPoint(e,t,r,!0),m?(r++,a=!0,c=!0):c||r++;if(r>=f){i=!0;break}let h=!0;for(;(h||!l)&&e>=0;)h=this.containsBlackPoint(n,r,e,!1),h?(e--,a=!0,l=!0):l||e--;if(e<0){i=!0;break}let g=!0;for(;(g||!u)&&n>=0;)g=this.containsBlackPoint(e,t,n,!0),g?(n--,a=!0,u=!0):u||n--;if(n<0){i=!0;break}a&&(o=!0)}if(!i&&o){let i=t-e,a=null;for(let t=1;a===null&&t<i;t++)a=this.getBlackPointOnSegment(e,r-t,e+t,r);if(a==null)throw new k;let o=null;for(let t=1;o===null&&t<i;t++)o=this.getBlackPointOnSegment(e,n+t,e+t,n);if(o==null)throw new k;let s=null;for(let e=1;s===null&&e<i;e++)s=this.getBlackPointOnSegment(t,n+e,t-e,n);if(s==null)throw new k;let c=null;for(let e=1;c===null&&e<i;e++)c=this.getBlackPointOnSegment(t,r-e,t-e,r);if(c==null)throw new k;return this.centerEdges(c,a,s,o)}else throw new k}getBlackPointOnSegment(e,t,n,r){let i=fe.round(fe.distance(e,t,n,r)),a=(n-e)/i,o=(r-t)/i,s=this.image;for(let n=0;n<i;n++){let r=fe.round(e+n*a),i=fe.round(t+n*o);if(s.get(r,i))return new V(r,i)}return null}centerEdges(e,t,n,r){let i=e.getX(),a=e.getY(),o=t.getX(),s=t.getY(),c=n.getX(),l=n.getY(),u=r.getX(),d=r.getY(),f=ge.CORR;return i<this.width/2?[new V(u-f,d+f),new V(o+f,s+f),new V(c-f,l-f),new V(i+f,a-f)]:[new V(u+f,d+f),new V(o+f,s-f),new V(c-f,l+f),new V(i-f,a-f)]}containsBlackPoint(e,t,n,r){let i=this.image;if(r){for(let r=e;r<=t;r++)if(i.get(r,n))return!0}else for(let r=e;r<=t;r++)if(i.get(n,r))return!0;return!1}}ge.INIT_SIZE=10,ge.CORR=1;class _e{static checkAndNudgePoints(e,t){let n=e.getWidth(),r=e.getHeight(),i=!0;for(let e=0;e<t.length&&i;e+=2){let a=Math.floor(t[e]),o=Math.floor(t[e+1]);if(a<-1||a>n||o<-1||o>r)throw new k;i=!1,a===-1?(t[e]=0,i=!0):a===n&&(t[e]=n-1,i=!0),o===-1?(t[e+1]=0,i=!0):o===r&&(t[e+1]=r-1,i=!0)}i=!0;for(let e=t.length-2;e>=0&&i;e-=2){let a=Math.floor(t[e]),o=Math.floor(t[e+1]);if(a<-1||a>n||o<-1||o>r)throw new k;i=!1,a===-1?(t[e]=0,i=!0):a===n&&(t[e]=n-1,i=!0),o===-1?(t[e+1]=0,i=!0):o===r&&(t[e+1]=r-1,i=!0)}}}class ve{constructor(e,t,n,r,i,a,o,s,c){this.a11=e,this.a21=t,this.a31=n,this.a12=r,this.a22=i,this.a32=a,this.a13=o,this.a23=s,this.a33=c}static quadrilateralToQuadrilateral(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h){let g=ve.quadrilateralToSquare(e,t,n,r,i,a,o,s);return ve.squareToQuadrilateral(c,l,u,d,f,p,m,h).times(g)}transformPoints(e){let t=e.length,n=this.a11,r=this.a12,i=this.a13,a=this.a21,o=this.a22,s=this.a23,c=this.a31,l=this.a32,u=this.a33;for(let d=0;d<t;d+=2){let t=e[d],f=e[d+1],p=i*t+s*f+u;e[d]=(n*t+a*f+c)/p,e[d+1]=(r*t+o*f+l)/p}}transformPointsWithValues(e,t){let n=this.a11,r=this.a12,i=this.a13,a=this.a21,o=this.a22,s=this.a23,c=this.a31,l=this.a32,u=this.a33,d=e.length;for(let f=0;f<d;f++){let d=e[f],p=t[f],m=i*d+s*p+u;e[f]=(n*d+a*p+c)/m,t[f]=(r*d+o*p+l)/m}}static squareToQuadrilateral(e,t,n,r,i,a,o,s){let c=e-n+i-o,l=t-r+a-s;if(c===0&&l===0)return new ve(n-e,i-n,e,r-t,a-r,t,0,0,1);{let u=n-i,d=o-i,f=r-a,p=s-a,m=u*p-d*f,h=(c*p-d*l)/m,g=(u*l-c*f)/m;return new ve(n-e+h*n,o-e+g*o,e,r-t+h*r,s-t+g*s,t,h,g,1)}}static quadrilateralToSquare(e,t,n,r,i,a,o,s){return ve.squareToQuadrilateral(e,t,n,r,i,a,o,s).buildAdjoint()}buildAdjoint(){return new ve(this.a22*this.a33-this.a23*this.a32,this.a23*this.a31-this.a21*this.a33,this.a21*this.a32-this.a22*this.a31,this.a13*this.a32-this.a12*this.a33,this.a11*this.a33-this.a13*this.a31,this.a12*this.a31-this.a11*this.a32,this.a12*this.a23-this.a13*this.a22,this.a13*this.a21-this.a11*this.a23,this.a11*this.a22-this.a12*this.a21)}times(e){return new ve(this.a11*e.a11+this.a21*e.a12+this.a31*e.a13,this.a11*e.a21+this.a21*e.a22+this.a31*e.a23,this.a11*e.a31+this.a21*e.a32+this.a31*e.a33,this.a12*e.a11+this.a22*e.a12+this.a32*e.a13,this.a12*e.a21+this.a22*e.a22+this.a32*e.a23,this.a12*e.a31+this.a22*e.a32+this.a32*e.a33,this.a13*e.a11+this.a23*e.a12+this.a33*e.a13,this.a13*e.a21+this.a23*e.a22+this.a33*e.a23,this.a13*e.a31+this.a23*e.a32+this.a33*e.a33)}}class ye extends _e{sampleGrid(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h,g,_,v){let y=ve.quadrilateralToQuadrilateral(r,i,a,o,s,c,l,u,d,f,p,m,h,g,_,v);return this.sampleGridWithTransform(e,t,n,y)}sampleGridWithTransform(e,t,n,r){if(t<=0||n<=0)throw new k;let i=new O(t,n),a=new Float32Array(2*t);for(let t=0;t<n;t++){let n=a.length,o=t+.5;for(let e=0;e<n;e+=2)a[e]=e/2+.5,a[e+1]=o;r.transformPoints(a),_e.checkAndNudgePoints(e,a);try{for(let r=0;r<n;r+=2)e.get(Math.floor(a[r]),Math.floor(a[r+1]))&&i.set(r/2,t)}catch{throw new k}}return i}}class be{static setGridSampler(e){be.gridSampler=e}static getInstance(){return be.gridSampler}}be.gridSampler=new ye;class xe{constructor(e,t){this.x=e,this.y=t}toResultPoint(){return new V(this.getX(),this.getY())}getX(){return this.x}getY(){return this.y}}class Se{constructor(e){this.EXPECTED_CORNER_BITS=new Int32Array([3808,476,2107,1799]),this.image=e}detect(){return this.detectMirror(!1)}detectMirror(e){let t=this.getMatrixCenter(),n=this.getBullsEyeCorners(t);if(e){let e=n[0];n[0]=n[2],n[2]=e}return this.extractParameters(n),new he(this.sampleGrid(this.image,n[this.shift%4],n[(this.shift+1)%4],n[(this.shift+2)%4],n[(this.shift+3)%4]),this.getMatrixCornerPoints(n),this.compact,this.nbDataBlocks,this.nbLayers)}extractParameters(e){if(!this.isValidPoint(e[0])||!this.isValidPoint(e[1])||!this.isValidPoint(e[2])||!this.isValidPoint(e[3]))throw new k;let t=2*this.nbCenterLayers,n=new Int32Array([this.sampleLine(e[0],e[1],t),this.sampleLine(e[1],e[2],t),this.sampleLine(e[2],e[3],t),this.sampleLine(e[3],e[0],t)]);this.shift=this.getRotation(n,t);let r=0;for(let e=0;e<4;e++){let t=n[(this.shift+e)%4];this.compact?(r<<=7,r+=t>>1&127):(r<<=10,r+=(t>>2&992)+(t>>1&31))}let i=this.getCorrectedParameterData(r,this.compact);this.compact?(this.nbLayers=(i>>6)+1,this.nbDataBlocks=(i&63)+1):(this.nbLayers=(i>>11)+1,this.nbDataBlocks=(i&2047)+1)}getRotation(e,t){let n=0;e.forEach((e,r,i)=>{let a=(e>>t-2<<1)+(e&1);n=(n<<3)+a}),n=((n&1)<<11)+(n>>1);for(let e=0;e<4;e++)if(_.bitCount(n^this.EXPECTED_CORNER_BITS[e])<=2)return e;throw new k}getCorrectedParameterData(e,t){let n,r;t?(n=7,r=2):(n=10,r=4);let i=n-r,a=new Int32Array(n);for(let t=n-1;t>=0;--t)a[t]=e&15,e>>=4;try{new le(oe.AZTEC_PARAM).decode(a,i)}catch{throw new k}let o=0;for(let e=0;e<r;e++)o=(o<<4)+a[e];return o}getBullsEyeCorners(e){let t=e,n=e,r=e,i=e,a=!0;for(this.nbCenterLayers=1;this.nbCenterLayers<9;this.nbCenterLayers++){let e=this.getFirstDifferent(t,a,1,-1),o=this.getFirstDifferent(n,a,1,1),s=this.getFirstDifferent(r,a,-1,1),c=this.getFirstDifferent(i,a,-1,-1);if(this.nbCenterLayers>2){let n=this.distancePoint(c,e)*this.nbCenterLayers/(this.distancePoint(i,t)*(this.nbCenterLayers+2));if(n<.75||n>1.25||!this.isWhiteOrBlackRectangle(e,o,s,c))break}t=e,n=o,r=s,i=c,a=!a}if(this.nbCenterLayers!==5&&this.nbCenterLayers!==7)throw new k;this.compact=this.nbCenterLayers===5;let o=new V(t.getX()+.5,t.getY()-.5),s=new V(n.getX()+.5,n.getY()+.5),c=new V(r.getX()-.5,r.getY()+.5),l=new V(i.getX()-.5,i.getY()-.5);return this.expandSquare([o,s,c,l],2*this.nbCenterLayers-3,2*this.nbCenterLayers)}getMatrixCenter(){let e,t,n,r;try{let i=new ge(this.image).detect();e=i[0],t=i[1],n=i[2],r=i[3]}catch{let i=this.image.getWidth()/2,a=this.image.getHeight()/2;e=this.getFirstDifferent(new xe(i+7,a-7),!1,1,-1).toResultPoint(),t=this.getFirstDifferent(new xe(i+7,a+7),!1,1,1).toResultPoint(),n=this.getFirstDifferent(new xe(i-7,a+7),!1,-1,1).toResultPoint(),r=this.getFirstDifferent(new xe(i-7,a-7),!1,-1,-1).toResultPoint()}let i=fe.round((e.getX()+r.getX()+t.getX()+n.getX())/4),a=fe.round((e.getY()+r.getY()+t.getY()+n.getY())/4);try{let o=new ge(this.image,15,i,a).detect();e=o[0],t=o[1],n=o[2],r=o[3]}catch{e=this.getFirstDifferent(new xe(i+7,a-7),!1,1,-1).toResultPoint(),t=this.getFirstDifferent(new xe(i+7,a+7),!1,1,1).toResultPoint(),n=this.getFirstDifferent(new xe(i-7,a+7),!1,-1,1).toResultPoint(),r=this.getFirstDifferent(new xe(i-7,a-7),!1,-1,-1).toResultPoint()}return i=fe.round((e.getX()+r.getX()+t.getX()+n.getX())/4),a=fe.round((e.getY()+r.getY()+t.getY()+n.getY())/4),new xe(i,a)}getMatrixCornerPoints(e){return this.expandSquare(e,2*this.nbCenterLayers,this.getDimension())}sampleGrid(e,t,n,r,i){let a=be.getInstance(),o=this.getDimension(),s=o/2-this.nbCenterLayers,c=o/2+this.nbCenterLayers;return a.sampleGrid(e,o,o,s,s,c,s,c,c,s,c,t.getX(),t.getY(),n.getX(),n.getY(),r.getX(),r.getY(),i.getX(),i.getY())}sampleLine(e,t,n){let r=0,i=this.distanceResultPoint(e,t),a=i/n,o=e.getX(),s=e.getY(),c=a*(t.getX()-e.getX())/i,l=a*(t.getY()-e.getY())/i;for(let e=0;e<n;e++)this.image.get(fe.round(o+e*c),fe.round(s+e*l))&&(r|=1<<n-e-1);return r}isWhiteOrBlackRectangle(e,t,n,r){e=new xe(e.getX()-3,e.getY()+3),t=new xe(t.getX()-3,t.getY()-3),n=new xe(n.getX()+3,n.getY()-3),r=new xe(r.getX()+3,r.getY()+3);let i=this.getColor(r,e);if(i===0)return!1;let a=this.getColor(e,t);return a!==i||(a=this.getColor(t,n),a!==i)?!1:(a=this.getColor(n,r),a===i)}getColor(e,t){let n=this.distancePoint(e,t),r=(t.getX()-e.getX())/n,i=(t.getY()-e.getY())/n,a=0,o=e.getX(),s=e.getY(),c=this.image.get(e.getX(),e.getY()),l=Math.ceil(n);for(let e=0;e<l;e++)o+=r,s+=i,this.image.get(fe.round(o),fe.round(s))!==c&&a++;let u=a/n;return u>.1&&u<.9?0:u<=.1===c?1:-1}getFirstDifferent(e,t,n,r){let i=e.getX()+n,a=e.getY()+r;for(;this.isValid(i,a)&&this.image.get(i,a)===t;)i+=n,a+=r;for(i-=n,a-=r;this.isValid(i,a)&&this.image.get(i,a)===t;)i+=n;for(i-=n;this.isValid(i,a)&&this.image.get(i,a)===t;)a+=r;return a-=r,new xe(i,a)}expandSquare(e,t,n){let r=n/(2*t),i=e[0].getX()-e[2].getX(),a=e[0].getY()-e[2].getY(),o=(e[0].getX()+e[2].getX())/2,s=(e[0].getY()+e[2].getY())/2,c=new V(o+r*i,s+r*a),l=new V(o-r*i,s-r*a);return i=e[1].getX()-e[3].getX(),a=e[1].getY()-e[3].getY(),o=(e[1].getX()+e[3].getX())/2,s=(e[1].getY()+e[3].getY())/2,[c,new V(o+r*i,s+r*a),l,new V(o-r*i,s-r*a)]}isValid(e,t){return e>=0&&e<this.image.getWidth()&&t>0&&t<this.image.getHeight()}isValidPoint(e){let t=fe.round(e.getX()),n=fe.round(e.getY());return this.isValid(t,n)}distancePoint(e,t){return fe.distance(e.getX(),e.getY(),t.getX(),t.getY())}distanceResultPoint(e,t){return fe.distance(e.getX(),e.getY(),t.getX(),t.getY())}getDimension(){return this.compact?4*this.nbLayers+11:this.nbLayers<=4?4*this.nbLayers+15:4*this.nbLayers+2*(_.truncDivision(this.nbLayers-4,8)+1)+15}}class Ce{decode(e,t=null){let n=null,r=new Se(e.getBlackMatrix()),i=null,a=null;try{let e=r.detectMirror(!1);i=e.getPoints(),this.reportFoundResultPoints(t,i),a=new de().decode(e)}catch(e){n=e}if(a==null)try{let e=r.detectMirror(!0);i=e.getPoints(),this.reportFoundResultPoints(t,i),a=new de().decode(e)}catch(e){throw n??e}let o=new R(a.getText(),a.getRawBytes(),a.getNumBits(),i,B.AZTEC,p.currentTimeMillis()),s=a.getByteSegments();s!=null&&o.putMetadata(te.BYTE_SEGMENTS,s);let c=a.getECLevel();return c!=null&&o.putMetadata(te.ERROR_CORRECTION_LEVEL,c),o}reportFoundResultPoints(e,t){if(e!=null){let n=e.get(b.NEED_RESULT_POINT_CALLBACK);n!=null&&t.forEach((e,t,r)=>{n.foundPossibleResultPoint(e)})}}reset(){}}class we extends L{constructor(e=500){super(new Ce,e)}}class Te{decode(e,t){try{return this.doDecode(e,t)}catch{if(t&&t.get(b.TRY_HARDER)===!0&&e.isRotateSupported()){let n=e.rotateCounterClockwise(),r=this.doDecode(n,t),i=r.getResultMetadata(),a=270;i!==null&&i.get(te.ORIENTATION)===!0&&(a+=i.get(te.ORIENTATION)%360),r.putMetadata(te.ORIENTATION,a);let o=r.getResultPoints();if(o!==null){let e=n.getHeight();for(let t=0;t<o.length;t++)o[t]=new V(e-o[t].getY()-1,o[t].getX())}return r}else throw new k}}reset(){}doDecode(e,t){let n=e.getWidth(),r=e.getHeight(),i=new v(n),a=t&&t.get(b.TRY_HARDER)===!0,o=Math.max(1,r>>(a?8:5)),s;s=a?r:15;let c=Math.trunc(r/2);for(let a=0;a<s;a++){let s=Math.trunc((a+1)/2),l=c+o*(a&1?-s:s);if(l<0||l>=r)break;try{i=e.getBlackRow(l,i)}catch{continue}for(let e=0;e<2;e++){if(e===1&&(i.reverse(),t&&t.get(b.NEED_RESULT_POINT_CALLBACK)===!0)){let e=new Map;t.forEach((t,n)=>e.set(n,t)),e.delete(b.NEED_RESULT_POINT_CALLBACK),t=e}try{let r=this.decodeRow(l,i,t);if(e===1){r.putMetadata(te.ORIENTATION,180);let e=r.getResultPoints();e!==null&&(e[0]=new V(n-e[0].getX()-1,e[0].getY()),e[1]=new V(n-e[1].getX()-1,e[1].getY()))}return r}catch{}}}throw new k}static recordPattern(e,t,n){let r=n.length;for(let e=0;e<r;e++)n[e]=0;let i=e.getSize();if(t>=i)throw new k;let a=!e.get(t),o=0,s=t;for(;s<i;){if(e.get(s)!==a)n[o]++;else if(++o===r)break;else n[o]=1,a=!a;s++}if(!(o===r||o===r-1&&s===i))throw new k}static recordPatternInReverse(e,t,n){let r=n.length,i=e.get(t);for(;t>0&&r>=0;)e.get(--t)!==i&&(r--,i=!i);if(r>=0)throw new k;Te.recordPattern(e,t+1,n)}static patternMatchVariance(e,t,n){let r=e.length,i=0,a=0;for(let n=0;n<r;n++)i+=e[n],a+=t[n];if(i<a)return 1/0;let o=i/a;n*=o;let s=0;for(let i=0;i<r;i++){let r=e[i],a=t[i]*o,c=r>a?r-a:a-r;if(c>n)return 1/0;s+=c}return s/i}}class H extends Te{static findStartPattern(e){let t=e.getSize(),n=e.getNextSet(0),r=0,i=Int32Array.from([0,0,0,0,0,0]),a=n,o=!1;for(let s=n;s<t;s++)if(e.get(s)!==o)i[r]++;else{if(r===5){let t=H.MAX_AVG_VARIANCE,n=-1;for(let e=H.CODE_START_A;e<=H.CODE_START_C;e++){let r=Te.patternMatchVariance(i,H.CODE_PATTERNS[e],H.MAX_INDIVIDUAL_VARIANCE);r<t&&(t=r,n=e)}if(n>=0&&e.isRange(Math.max(0,a-(s-a)/2),a,!1))return Int32Array.from([a,s,n]);a+=i[0]+i[1],i=i.slice(2,i.length-1),i[r-1]=0,i[r]=0,r--}else r++;i[r]=1,o=!o}throw new k}static decodeCode(e,t,n){Te.recordPattern(e,n,t);let r=H.MAX_AVG_VARIANCE,i=-1;for(let e=0;e<H.CODE_PATTERNS.length;e++){let n=H.CODE_PATTERNS[e],a=this.patternMatchVariance(t,n,H.MAX_INDIVIDUAL_VARIANCE);a<r&&(r=a,i=e)}if(i>=0)return i;throw new k}decodeRow(e,t,n){let r=n&&n.get(b.ASSUME_GS1)===!0,i=H.findStartPattern(t),a=i[2],o=0,s=new Uint8Array(20);s[o++]=a;let c;switch(a){case H.CODE_START_A:c=H.CODE_CODE_A;break;case H.CODE_START_B:c=H.CODE_CODE_B;break;case H.CODE_START_C:c=H.CODE_CODE_C;break;default:throw new x}let l=!1,u=!1,f=``,p=i[0],m=i[1],h=Int32Array.from([0,0,0,0,0,0]),g=0,_=0,v=a,y=0,S=!0,C=!1,w=!1;for(;!l;){let e=u;switch(u=!1,g=_,_=H.decodeCode(t,h,m),s[o++]=_,_!==H.CODE_STOP&&(S=!0),_!==H.CODE_STOP&&(y++,v+=y*_),p=m,m+=h.reduce((e,t)=>e+t,0),_){case H.CODE_START_A:case H.CODE_START_B:case H.CODE_START_C:throw new x}switch(c){case H.CODE_CODE_A:if(_<64)w===C?f+=String.fromCharCode(32+_):f+=String.fromCharCode(32+_+128),w=!1;else if(_<96)w===C?f+=String.fromCharCode(_-64):f+=String.fromCharCode(_+64),w=!1;else switch(_!==H.CODE_STOP&&(S=!1),_){case H.CODE_FNC_1:r&&(f.length===0?f+=`]C1`:f+=``);break;case H.CODE_FNC_2:case H.CODE_FNC_3:break;case H.CODE_FNC_4_A:!C&&w?(C=!0,w=!1):C&&w?(C=!1,w=!1):w=!0;break;case H.CODE_SHIFT:u=!0,c=H.CODE_CODE_B;break;case H.CODE_CODE_B:c=H.CODE_CODE_B;break;case H.CODE_CODE_C:c=H.CODE_CODE_C;break;case H.CODE_STOP:l=!0;break}break;case H.CODE_CODE_B:if(_<96)w===C?f+=String.fromCharCode(32+_):f+=String.fromCharCode(32+_+128),w=!1;else switch(_!==H.CODE_STOP&&(S=!1),_){case H.CODE_FNC_1:r&&(f.length===0?f+=`]C1`:f+=``);break;case H.CODE_FNC_2:case H.CODE_FNC_3:break;case H.CODE_FNC_4_B:!C&&w?(C=!0,w=!1):C&&w?(C=!1,w=!1):w=!0;break;case H.CODE_SHIFT:u=!0,c=H.CODE_CODE_A;break;case H.CODE_CODE_A:c=H.CODE_CODE_A;break;case H.CODE_CODE_C:c=H.CODE_CODE_C;break;case H.CODE_STOP:l=!0;break}break;case H.CODE_CODE_C:if(_<100)_<10&&(f+=`0`),f+=_;else switch(_!==H.CODE_STOP&&(S=!1),_){case H.CODE_FNC_1:r&&(f.length===0?f+=`]C1`:f+=``);break;case H.CODE_CODE_A:c=H.CODE_CODE_A;break;case H.CODE_CODE_B:c=H.CODE_CODE_B;break;case H.CODE_STOP:l=!0;break}break}e&&(c=c===H.CODE_CODE_A?H.CODE_CODE_B:H.CODE_CODE_A)}let T=m-p;if(m=t.getNextUnset(m),!t.isRange(m,Math.min(t.getSize(),m+(m-p)/2),!1))throw new k;if(v-=y*g,v%103!==g)throw new d;let E=f.length;if(E===0)throw new k;E>0&&S&&(f=c===H.CODE_CODE_C?f.substring(0,E-2):f.substring(0,E-1));let D=(i[1]+i[0])/2,O=p+T/2,A=s.length,j=new Uint8Array(A);for(let e=0;e<A;e++)j[e]=s[e];let M=[new V(D,e),new V(O,e)];return new R(f,j,0,M,B.CODE_128,new Date().getTime())}}H.CODE_PATTERNS=[Int32Array.from([2,1,2,2,2,2]),Int32Array.from([2,2,2,1,2,2]),Int32Array.from([2,2,2,2,2,1]),Int32Array.from([1,2,1,2,2,3]),Int32Array.from([1,2,1,3,2,2]),Int32Array.from([1,3,1,2,2,2]),Int32Array.from([1,2,2,2,1,3]),Int32Array.from([1,2,2,3,1,2]),Int32Array.from([1,3,2,2,1,2]),Int32Array.from([2,2,1,2,1,3]),Int32Array.from([2,2,1,3,1,2]),Int32Array.from([2,3,1,2,1,2]),Int32Array.from([1,1,2,2,3,2]),Int32Array.from([1,2,2,1,3,2]),Int32Array.from([1,2,2,2,3,1]),Int32Array.from([1,1,3,2,2,2]),Int32Array.from([1,2,3,1,2,2]),Int32Array.from([1,2,3,2,2,1]),Int32Array.from([2,2,3,2,1,1]),Int32Array.from([2,2,1,1,3,2]),Int32Array.from([2,2,1,2,3,1]),Int32Array.from([2,1,3,2,1,2]),Int32Array.from([2,2,3,1,1,2]),Int32Array.from([3,1,2,1,3,1]),Int32Array.from([3,1,1,2,2,2]),Int32Array.from([3,2,1,1,2,2]),Int32Array.from([3,2,1,2,2,1]),Int32Array.from([3,1,2,2,1,2]),Int32Array.from([3,2,2,1,1,2]),Int32Array.from([3,2,2,2,1,1]),Int32Array.from([2,1,2,1,2,3]),Int32Array.from([2,1,2,3,2,1]),Int32Array.from([2,3,2,1,2,1]),Int32Array.from([1,1,1,3,2,3]),Int32Array.from([1,3,1,1,2,3]),Int32Array.from([1,3,1,3,2,1]),Int32Array.from([1,1,2,3,1,3]),Int32Array.from([1,3,2,1,1,3]),Int32Array.from([1,3,2,3,1,1]),Int32Array.from([2,1,1,3,1,3]),Int32Array.from([2,3,1,1,1,3]),Int32Array.from([2,3,1,3,1,1]),Int32Array.from([1,1,2,1,3,3]),Int32Array.from([1,1,2,3,3,1]),Int32Array.from([1,3,2,1,3,1]),Int32Array.from([1,1,3,1,2,3]),Int32Array.from([1,1,3,3,2,1]),Int32Array.from([1,3,3,1,2,1]),Int32Array.from([3,1,3,1,2,1]),Int32Array.from([2,1,1,3,3,1]),Int32Array.from([2,3,1,1,3,1]),Int32Array.from([2,1,3,1,1,3]),Int32Array.from([2,1,3,3,1,1]),Int32Array.from([2,1,3,1,3,1]),Int32Array.from([3,1,1,1,2,3]),Int32Array.from([3,1,1,3,2,1]),Int32Array.from([3,3,1,1,2,1]),Int32Array.from([3,1,2,1,1,3]),Int32Array.from([3,1,2,3,1,1]),Int32Array.from([3,3,2,1,1,1]),Int32Array.from([3,1,4,1,1,1]),Int32Array.from([2,2,1,4,1,1]),Int32Array.from([4,3,1,1,1,1]),Int32Array.from([1,1,1,2,2,4]),Int32Array.from([1,1,1,4,2,2]),Int32Array.from([1,2,1,1,2,4]),Int32Array.from([1,2,1,4,2,1]),Int32Array.from([1,4,1,1,2,2]),Int32Array.from([1,4,1,2,2,1]),Int32Array.from([1,1,2,2,1,4]),Int32Array.from([1,1,2,4,1,2]),Int32Array.from([1,2,2,1,1,4]),Int32Array.from([1,2,2,4,1,1]),Int32Array.from([1,4,2,1,1,2]),Int32Array.from([1,4,2,2,1,1]),Int32Array.from([2,4,1,2,1,1]),Int32Array.from([2,2,1,1,1,4]),Int32Array.from([4,1,3,1,1,1]),Int32Array.from([2,4,1,1,1,2]),Int32Array.from([1,3,4,1,1,1]),Int32Array.from([1,1,1,2,4,2]),Int32Array.from([1,2,1,1,4,2]),Int32Array.from([1,2,1,2,4,1]),Int32Array.from([1,1,4,2,1,2]),Int32Array.from([1,2,4,1,1,2]),Int32Array.from([1,2,4,2,1,1]),Int32Array.from([4,1,1,2,1,2]),Int32Array.from([4,2,1,1,1,2]),Int32Array.from([4,2,1,2,1,1]),Int32Array.from([2,1,2,1,4,1]),Int32Array.from([2,1,4,1,2,1]),Int32Array.from([4,1,2,1,2,1]),Int32Array.from([1,1,1,1,4,3]),Int32Array.from([1,1,1,3,4,1]),Int32Array.from([1,3,1,1,4,1]),Int32Array.from([1,1,4,1,1,3]),Int32Array.from([1,1,4,3,1,1]),Int32Array.from([4,1,1,1,1,3]),Int32Array.from([4,1,1,3,1,1]),Int32Array.from([1,1,3,1,4,1]),Int32Array.from([1,1,4,1,3,1]),Int32Array.from([3,1,1,1,4,1]),Int32Array.from([4,1,1,1,3,1]),Int32Array.from([2,1,1,4,1,2]),Int32Array.from([2,1,1,2,1,4]),Int32Array.from([2,1,1,2,3,2]),Int32Array.from([2,3,3,1,1,1,2])],H.MAX_AVG_VARIANCE=.25,H.MAX_INDIVIDUAL_VARIANCE=.7,H.CODE_SHIFT=98,H.CODE_CODE_C=99,H.CODE_CODE_B=100,H.CODE_CODE_A=101,H.CODE_FNC_1=102,H.CODE_FNC_2=97,H.CODE_FNC_3=96,H.CODE_FNC_4_A=101,H.CODE_FNC_4_B=100,H.CODE_START_A=103,H.CODE_START_B=104,H.CODE_START_C=105,H.CODE_STOP=106;class Ee extends Te{constructor(e=!1,t=!1){super(),this.usingCheckDigit=e,this.extendedMode=t,this.decodeRowResult=``,this.counters=new Int32Array(9)}decodeRow(e,t,n){let r=this.counters;r.fill(0),this.decodeRowResult=``;let i=Ee.findAsteriskPattern(t,r),a=t.getNextSet(i[1]),o=t.getSize(),s,c;do{Ee.recordPattern(t,a,r);let e=Ee.toNarrowWidePattern(r);if(e<0)throw new k;s=Ee.patternToChar(e),this.decodeRowResult+=s,c=a;for(let e of r)a+=e;a=t.getNextSet(a)}while(s!==`*`);this.decodeRowResult=this.decodeRowResult.substring(0,this.decodeRowResult.length-1);let l=0;for(let e of r)l+=e;let u=a-c-l;if(a!==o&&u*2<l)throw new k;if(this.usingCheckDigit){let e=this.decodeRowResult.length-1,t=0;for(let n=0;n<e;n++)t+=Ee.ALPHABET_STRING.indexOf(this.decodeRowResult.charAt(n));if(this.decodeRowResult.charAt(e)!==Ee.ALPHABET_STRING.charAt(t%43))throw new d;this.decodeRowResult=this.decodeRowResult.substring(0,e)}if(this.decodeRowResult.length===0)throw new k;let f;f=this.extendedMode?Ee.decodeExtended(this.decodeRowResult):this.decodeRowResult;let p=(i[1]+i[0])/2,m=c+l/2;return new R(f,null,0,[new V(p,e),new V(m,e)],B.CODE_39,new Date().getTime())}static findAsteriskPattern(e,t){let n=e.getSize(),r=e.getNextSet(0),i=0,a=r,o=!1,s=t.length;for(let c=r;c<n;c++)if(e.get(c)!==o)t[i]++;else{if(i===s-1){if(this.toNarrowWidePattern(t)===Ee.ASTERISK_ENCODING&&e.isRange(Math.max(0,a-Math.floor((c-a)/2)),a,!1))return[a,c];a+=t[0]+t[1],t.copyWithin(0,2,2+i-1),t[i-1]=0,t[i]=0,i--}else i++;t[i]=1,o=!o}throw new k}static toNarrowWidePattern(e){let t=e.length,n=0,r;do{let i=2147483647;for(let t of e)t<i&&t>n&&(i=t);n=i,r=0;let a=0,o=0;for(let i=0;i<t;i++){let s=e[i];s>n&&(o|=1<<t-1-i,r++,a+=s)}if(r===3){for(let i=0;i<t&&r>0;i++){let t=e[i];if(t>n&&(r--,t*2>=a))return-1}return o}}while(r>3);return-1}static patternToChar(e){for(let t=0;t<Ee.CHARACTER_ENCODINGS.length;t++)if(Ee.CHARACTER_ENCODINGS[t]===e)return Ee.ALPHABET_STRING.charAt(t);if(e===Ee.ASTERISK_ENCODING)return`*`;throw new k}static decodeExtended(e){let t=e.length,n=``;for(let r=0;r<t;r++){let t=e.charAt(r);if(t===`+`||t===`$`||t===`%`||t===`/`){let i=e.charAt(r+1),a=`\0`;switch(t){case`+`:if(i>=`A`&&i<=`Z`)a=String.fromCharCode(i.charCodeAt(0)+32);else throw new x;break;case`$`:if(i>=`A`&&i<=`Z`)a=String.fromCharCode(i.charCodeAt(0)-64);else throw new x;break;case`%`:if(i>=`A`&&i<=`E`)a=String.fromCharCode(i.charCodeAt(0)-38);else if(i>=`F`&&i<=`J`)a=String.fromCharCode(i.charCodeAt(0)-11);else if(i>=`K`&&i<=`O`)a=String.fromCharCode(i.charCodeAt(0)+16);else if(i>=`P`&&i<=`T`)a=String.fromCharCode(i.charCodeAt(0)+43);else if(i===`U`)a=`\0`;else if(i===`V`)a=`@`;else if(i===`W`)a="`";else if(i===`X`||i===`Y`||i===`Z`)a=``;else throw new x;break;case`/`:if(i>=`A`&&i<=`O`)a=String.fromCharCode(i.charCodeAt(0)-32);else if(i===`Z`)a=`:`;else throw new x;break}n+=a,r++}else n+=t}return n}}Ee.ALPHABET_STRING=`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%`,Ee.CHARACTER_ENCODINGS=[52,289,97,352,49,304,112,37,292,100,265,73,328,25,280,88,13,268,76,28,259,67,322,19,274,82,7,262,70,22,385,193,448,145,400,208,133,388,196,168,162,138,42],Ee.ASTERISK_ENCODING=148;class De extends Te{constructor(){super(...arguments),this.narrowLineWidth=-1}decodeRow(e,t,n){let r=this.decodeStart(t),i=this.decodeEnd(t),a=new D;De.decodeMiddle(t,r[1],i[0],a);let o=a.toString(),s=null;n!=null&&(s=n.get(b.ALLOWED_LENGTHS)),s??=De.DEFAULT_ALLOWED_LENGTHS;let c=o.length,l=!1,u=0;for(let e of s){if(c===e){l=!0;break}e>u&&(u=e)}if(!l&&c>u&&(l=!0),!l)throw new x;return new R(o,null,0,[new V(r[1],e),new V(i[0],e)],B.ITF,new Date().getTime())}static decodeMiddle(e,t,n,r){let i=new Int32Array(10),a=new Int32Array(5),o=new Int32Array(5);for(i.fill(0),a.fill(0),o.fill(0);t<n;){Te.recordPattern(e,t,i);for(let e=0;e<5;e++){let t=2*e;a[e]=i[t],o[e]=i[t+1]}let n=De.decodeDigit(a);r.append(n.toString()),n=this.decodeDigit(o),r.append(n.toString()),i.forEach(function(e){t+=e})}}decodeStart(e){let t=De.skipWhiteSpace(e),n=De.findGuardPattern(e,t,De.START_PATTERN);return this.narrowLineWidth=(n[1]-n[0])/4,this.validateQuietZone(e,n[0]),n}validateQuietZone(e,t){let n=this.narrowLineWidth*10;n=n<t?n:t;for(let r=t-1;n>0&&r>=0&&!e.get(r);r--)n--;if(n!==0)throw new k}static skipWhiteSpace(e){let t=e.getSize(),n=e.getNextSet(0);if(n===t)throw new k;return n}decodeEnd(e){e.reverse();try{let t=De.skipWhiteSpace(e),n;try{n=De.findGuardPattern(e,t,De.END_PATTERN_REVERSED[0])}catch(r){r instanceof k&&(n=De.findGuardPattern(e,t,De.END_PATTERN_REVERSED[1]))}this.validateQuietZone(e,n[0]);let r=n[0];return n[0]=e.getSize()-n[1],n[1]=e.getSize()-r,n}finally{e.reverse()}}static findGuardPattern(e,t,n){let r=n.length,i=new Int32Array(r),a=e.getSize(),o=!1,s=0,c=t;i.fill(0);for(let l=t;l<a;l++)if(e.get(l)!==o)i[s]++;else{if(s===r-1){if(Te.patternMatchVariance(i,n,De.MAX_INDIVIDUAL_VARIANCE)<De.MAX_AVG_VARIANCE)return[c,l];c+=i[0]+i[1],p.arraycopy(i,2,i,0,s-1),i[s-1]=0,i[s]=0,s--}else s++;i[s]=1,o=!o}throw new k}static decodeDigit(e){let t=De.MAX_AVG_VARIANCE,n=-1,r=De.PATTERNS.length;for(let i=0;i<r;i++){let r=De.PATTERNS[i],a=Te.patternMatchVariance(e,r,De.MAX_INDIVIDUAL_VARIANCE);a<t?(t=a,n=i):a===t&&(n=-1)}if(n>=0)return n%10;throw new k}}De.PATTERNS=[Int32Array.from([1,1,2,2,1]),Int32Array.from([2,1,1,1,2]),Int32Array.from([1,2,1,1,2]),Int32Array.from([2,2,1,1,1]),Int32Array.from([1,1,2,1,2]),Int32Array.from([2,1,2,1,1]),Int32Array.from([1,2,2,1,1]),Int32Array.from([1,1,1,2,2]),Int32Array.from([2,1,1,2,1]),Int32Array.from([1,2,1,2,1]),Int32Array.from([1,1,3,3,1]),Int32Array.from([3,1,1,1,3]),Int32Array.from([1,3,1,1,3]),Int32Array.from([3,3,1,1,1]),Int32Array.from([1,1,3,1,3]),Int32Array.from([3,1,3,1,1]),Int32Array.from([1,3,3,1,1]),Int32Array.from([1,1,1,3,3]),Int32Array.from([3,1,1,3,1]),Int32Array.from([1,3,1,3,1])],De.MAX_AVG_VARIANCE=.38,De.MAX_INDIVIDUAL_VARIANCE=.5,De.DEFAULT_ALLOWED_LENGTHS=[6,8,10,12,14],De.START_PATTERN=Int32Array.from([1,1,1,1]),De.END_PATTERN_REVERSED=[Int32Array.from([1,1,2]),Int32Array.from([1,1,3])];class Oe extends Te{constructor(){super(...arguments),this.decodeRowStringBuffer=``}static findStartGuardPattern(e){let t=!1,n,r=0,i=Int32Array.from([0,0,0]);for(;!t;){i=Int32Array.from([0,0,0]),n=Oe.findGuardPattern(e,r,!1,this.START_END_PATTERN,i);let a=n[0];r=n[1];let o=a-(r-a);o>=0&&(t=e.isRange(o,a,!1))}return n}static checkChecksum(e){return Oe.checkStandardUPCEANChecksum(e)}static checkStandardUPCEANChecksum(e){let t=e.length;if(t===0)return!1;let n=parseInt(e.charAt(t-1),10);return Oe.getStandardUPCEANChecksum(e.substring(0,t-1))===n}static getStandardUPCEANChecksum(e){let t=e.length,n=0;for(let r=t-1;r>=0;r-=2){let t=e.charAt(r).charCodeAt(0)-48;if(t<0||t>9)throw new x;n+=t}n*=3;for(let r=t-2;r>=0;r-=2){let t=e.charAt(r).charCodeAt(0)-48;if(t<0||t>9)throw new x;n+=t}return(1e3-n)%10}static decodeEnd(e,t){return Oe.findGuardPattern(e,t,!1,Oe.START_END_PATTERN,new Int32Array(Oe.START_END_PATTERN.length).fill(0))}static findGuardPatternWithoutCounters(e,t,n,r){return this.findGuardPattern(e,t,n,r,new Int32Array(r.length))}static findGuardPattern(e,t,n,r,i){let a=e.getSize();t=n?e.getNextUnset(t):e.getNextSet(t);let o=0,s=t,c=r.length,l=n;for(let n=t;n<a;n++)if(e.get(n)!==l)i[o]++;else{if(o===c-1){if(Te.patternMatchVariance(i,r,Oe.MAX_INDIVIDUAL_VARIANCE)<Oe.MAX_AVG_VARIANCE)return Int32Array.from([s,n]);s+=i[0]+i[1];let e=i.slice(2,i.length-1);for(let t=0;t<o-1;t++)i[t]=e[t];i[o-1]=0,i[o]=0,o--}else o++;i[o]=1,l=!l}throw new k}static decodeDigit(e,t,n,r){this.recordPattern(e,n,t);let i=this.MAX_AVG_VARIANCE,a=-1,o=r.length;for(let e=0;e<o;e++){let n=r[e],o=Te.patternMatchVariance(t,n,Oe.MAX_INDIVIDUAL_VARIANCE);o<i&&(i=o,a=e)}if(a>=0)return a;throw new k}}Oe.MAX_AVG_VARIANCE=.48,Oe.MAX_INDIVIDUAL_VARIANCE=.7,Oe.START_END_PATTERN=Int32Array.from([1,1,1]),Oe.MIDDLE_PATTERN=Int32Array.from([1,1,1,1,1]),Oe.END_PATTERN=Int32Array.from([1,1,1,1,1,1]),Oe.L_PATTERNS=[Int32Array.from([3,2,1,1]),Int32Array.from([2,2,2,1]),Int32Array.from([2,1,2,2]),Int32Array.from([1,4,1,1]),Int32Array.from([1,1,3,2]),Int32Array.from([1,2,3,1]),Int32Array.from([1,1,1,4]),Int32Array.from([1,3,1,2]),Int32Array.from([1,2,1,3]),Int32Array.from([3,1,1,2])];class ke{constructor(){this.CHECK_DIGIT_ENCODINGS=[24,20,18,17,12,6,3,10,9,5],this.decodeMiddleCounters=Int32Array.from([0,0,0,0]),this.decodeRowStringBuffer=``}decodeRow(e,t,n){let r=this.decodeRowStringBuffer,i=this.decodeMiddle(t,n,r),a=r.toString(),o=ke.parseExtensionString(a),s=new R(a,null,0,[new V((n[0]+n[1])/2,e),new V(i,e)],B.UPC_EAN_EXTENSION,new Date().getTime());return o!=null&&s.putAllMetadata(o),s}decodeMiddle(e,t,n){let r=this.decodeMiddleCounters;r[0]=0,r[1]=0,r[2]=0,r[3]=0;let i=e.getSize(),a=t[1],o=0;for(let t=0;t<5&&a<i;t++){let i=Oe.decodeDigit(e,r,a,Oe.L_AND_G_PATTERNS);n+=String.fromCharCode(48+i%10);for(let e of r)a+=e;i>=10&&(o|=1<<4-t),t!==4&&(a=e.getNextSet(a),a=e.getNextUnset(a))}if(n.length!==5)throw new k;let s=this.determineCheckDigit(o);if(ke.extensionChecksum(n.toString())!==s)throw new k;return a}static extensionChecksum(e){let t=e.length,n=0;for(let r=t-2;r>=0;r-=2)n+=e.charAt(r).charCodeAt(0)-48;n*=3;for(let r=t-1;r>=0;r-=2)n+=e.charAt(r).charCodeAt(0)-48;return n*=3,n%10}determineCheckDigit(e){for(let t=0;t<10;t++)if(e===this.CHECK_DIGIT_ENCODINGS[t])return t;throw new k}static parseExtensionString(e){if(e.length!==5)return null;let t=ke.parseExtension5String(e);return t==null?null:new Map([[te.SUGGESTED_PRICE,t]])}static parseExtension5String(e){let t;switch(e.charAt(0)){case`0`:t=`£`;break;case`5`:t=`$`;break;case`9`:switch(e){case`90000`:return null;case`99991`:return`0.00`;case`99990`:return`Used`}t=``;break;default:t=``;break}let n=parseInt(e.substring(1)),r=(n/100).toString(),i=n%100,a=i<10?`0`+i:i.toString();return t+r+`.`+a}}class Ae{constructor(){this.decodeMiddleCounters=Int32Array.from([0,0,0,0]),this.decodeRowStringBuffer=``}decodeRow(e,t,n){let r=this.decodeRowStringBuffer,i=this.decodeMiddle(t,n,r),a=r.toString(),o=Ae.parseExtensionString(a),s=new R(a,null,0,[new V((n[0]+n[1])/2,e),new V(i,e)],B.UPC_EAN_EXTENSION,new Date().getTime());return o!=null&&s.putAllMetadata(o),s}decodeMiddle(e,t,n){let r=this.decodeMiddleCounters;r[0]=0,r[1]=0,r[2]=0,r[3]=0;let i=e.getSize(),a=t[1],o=0;for(let t=0;t<2&&a<i;t++){let i=Oe.decodeDigit(e,r,a,Oe.L_AND_G_PATTERNS);n+=String.fromCharCode(48+i%10);for(let e of r)a+=e;i>=10&&(o|=1<<1-t),t!==1&&(a=e.getNextSet(a),a=e.getNextUnset(a))}if(n.length!==2||parseInt(n.toString())%4!==o)throw new k;return a}static parseExtensionString(e){return e.length===2?new Map([[te.ISSUE_NUMBER,parseInt(e)]]):null}}class je{static decodeRow(e,t,n){let r=Oe.findGuardPattern(t,n,!1,this.EXTENSION_START_PATTERN,new Int32Array(this.EXTENSION_START_PATTERN.length).fill(0));try{return new ke().decodeRow(e,t,r)}catch{return new Ae().decodeRow(e,t,r)}}}je.EXTENSION_START_PATTERN=Int32Array.from([1,1,2]);class Me extends Oe{constructor(){super(),this.decodeRowStringBuffer=``,Me.L_AND_G_PATTERNS=Me.L_PATTERNS.map(e=>Int32Array.from(e));for(let e=10;e<20;e++){let t=Me.L_PATTERNS[e-10],n=new Int32Array(t.length);for(let e=0;e<t.length;e++)n[e]=t[t.length-e-1];Me.L_AND_G_PATTERNS[e]=n}}decodeRow(e,t,n){let r=Me.findStartGuardPattern(t),i=n==null?null:n.get(b.NEED_RESULT_POINT_CALLBACK);if(i!=null){let t=new V((r[0]+r[1])/2,e);i.foundPossibleResultPoint(t)}let a=this.decodeMiddle(t,r,this.decodeRowStringBuffer),o=a.rowOffset,s=a.resultString;if(i!=null){let t=new V(o,e);i.foundPossibleResultPoint(t)}let c=this.decodeEnd(t,o);if(i!=null){let t=new V((c[0]+c[1])/2,e);i.foundPossibleResultPoint(t)}let l=c[1],u=l+(l-c[0]);if(u>=t.getSize()||!t.isRange(l,u,!1))throw new k;let f=s.toString();if(f.length<8)throw new x;if(!Me.checkChecksum(f))throw new d;let p=(r[1]+r[0])/2,m=(c[1]+c[0])/2,h=this.getBarcodeFormat(),g=new R(f,null,0,[new V(p,e),new V(m,e)],h,new Date().getTime()),_=0;try{let n=je.decodeRow(e,t,c[1]);g.putMetadata(te.UPC_EAN_EXTENSION,n.getText()),g.putAllMetadata(n.getResultMetadata()),g.addResultPoints(n.getResultPoints()),_=n.getText().length}catch{}let v=n==null?null:n.get(b.ALLOWED_EAN_EXTENSIONS);if(v!=null){let e=!1;for(let t in v)if(_.toString()===t){e=!0;break}if(!e)throw new k}return g}decodeEnd(e,t){return Me.findGuardPattern(e,t,!1,Me.START_END_PATTERN,new Int32Array(Me.START_END_PATTERN.length).fill(0))}static checkChecksum(e){return Me.checkStandardUPCEANChecksum(e)}static checkStandardUPCEANChecksum(e){let t=e.length;if(t===0)return!1;let n=parseInt(e.charAt(t-1),10);return Me.getStandardUPCEANChecksum(e.substring(0,t-1))===n}static getStandardUPCEANChecksum(e){let t=e.length,n=0;for(let r=t-1;r>=0;r-=2){let t=e.charAt(r).charCodeAt(0)-48;if(t<0||t>9)throw new x;n+=t}n*=3;for(let r=t-2;r>=0;r-=2){let t=e.charAt(r).charCodeAt(0)-48;if(t<0||t>9)throw new x;n+=t}return(1e3-n)%10}}class Ne extends Me{constructor(){super(),this.decodeMiddleCounters=Int32Array.from([0,0,0,0])}decodeMiddle(e,t,n){let r=this.decodeMiddleCounters;r[0]=0,r[1]=0,r[2]=0,r[3]=0;let i=e.getSize(),a=t[1],o=0;for(let t=0;t<6&&a<i;t++){let i=Me.decodeDigit(e,r,a,Me.L_AND_G_PATTERNS);n+=String.fromCharCode(48+i%10);for(let e of r)a+=e;i>=10&&(o|=1<<5-t)}n=Ne.determineFirstDigit(n,o),a=Me.findGuardPattern(e,a,!0,Me.MIDDLE_PATTERN,new Int32Array(Me.MIDDLE_PATTERN.length).fill(0))[1];for(let t=0;t<6&&a<i;t++){let t=Me.decodeDigit(e,r,a,Me.L_PATTERNS);n+=String.fromCharCode(48+t);for(let e of r)a+=e}return{rowOffset:a,resultString:n}}getBarcodeFormat(){return B.EAN_13}static determineFirstDigit(e,t){for(let n=0;n<10;n++)if(t===this.FIRST_DIGIT_ENCODINGS[n])return e=String.fromCharCode(48+n)+e,e;throw new k}}Ne.FIRST_DIGIT_ENCODINGS=[0,11,13,14,19,25,28,21,22,26];class Pe extends Me{constructor(){super(),this.decodeMiddleCounters=Int32Array.from([0,0,0,0])}decodeMiddle(e,t,n){let r=this.decodeMiddleCounters;r[0]=0,r[1]=0,r[2]=0,r[3]=0;let i=e.getSize(),a=t[1];for(let t=0;t<4&&a<i;t++){let t=Me.decodeDigit(e,r,a,Me.L_PATTERNS);n+=String.fromCharCode(48+t);for(let e of r)a+=e}a=Me.findGuardPattern(e,a,!0,Me.MIDDLE_PATTERN,new Int32Array(Me.MIDDLE_PATTERN.length).fill(0))[1];for(let t=0;t<4&&a<i;t++){let t=Me.decodeDigit(e,r,a,Me.L_PATTERNS);n+=String.fromCharCode(48+t);for(let e of r)a+=e}return{rowOffset:a,resultString:n}}getBarcodeFormat(){return B.EAN_8}}class Fe extends Me{constructor(){super(...arguments),this.ean13Reader=new Ne}getBarcodeFormat(){return B.UPC_A}decode(e,t){return this.maybeReturnResult(this.ean13Reader.decode(e))}decodeRow(e,t,n){return this.maybeReturnResult(this.ean13Reader.decodeRow(e,t,n))}decodeMiddle(e,t,n){return this.ean13Reader.decodeMiddle(e,t,n)}maybeReturnResult(e){let t=e.getText();if(t.charAt(0)===`0`){let n=new R(t.substring(1),null,null,e.getResultPoints(),B.UPC_A);return e.getResultMetadata()!=null&&n.putAllMetadata(e.getResultMetadata()),n}else throw new k}reset(){this.ean13Reader.reset()}}class Ie extends Me{constructor(){super(),this.decodeMiddleCounters=new Int32Array(4)}decodeMiddle(e,t,n){let r=this.decodeMiddleCounters.map(e=>e);r[0]=0,r[1]=0,r[2]=0,r[3]=0;let i=e.getSize(),a=t[1],o=0;for(let t=0;t<6&&a<i;t++){let i=Ie.decodeDigit(e,r,a,Ie.L_AND_G_PATTERNS);n+=String.fromCharCode(48+i%10);for(let e of r)a+=e;i>=10&&(o|=1<<5-t)}let s=Ie.determineNumSysAndCheckDigit(n,o);return{rowOffset:a,resultString:s}}decodeEnd(e,t){return Ie.findGuardPatternWithoutCounters(e,t,!0,Ie.MIDDLE_END_PATTERN)}checkChecksum(e){return Me.checkChecksum(Ie.convertUPCEtoUPCA(e))}static determineNumSysAndCheckDigit(e,t){for(let n=0;n<=1;n++)for(let r=0;r<10;r++)if(t===this.NUMSYS_AND_CHECK_DIGIT_PATTERNS[n][r]){let t=String.fromCharCode(48+n),i=String.fromCharCode(48+r);return t+e+i}throw k.getNotFoundInstance()}getBarcodeFormat(){return B.UPC_E}static convertUPCEtoUPCA(e){let t=e.slice(1,7).split(``).map(e=>e.charCodeAt(0)),n=new D;n.append(e.charAt(0));let r=t[5];switch(r){case 0:case 1:case 2:n.appendChars(t,0,2),n.append(r),n.append(`0000`),n.appendChars(t,2,3);break;case 3:n.appendChars(t,0,3),n.append(`00000`),n.appendChars(t,3,2);break;case 4:n.appendChars(t,0,4),n.append(`00000`),n.append(t[4]);break;default:n.appendChars(t,0,5),n.append(`0000`),n.append(r);break}return e.length>=8&&n.append(e.charAt(7)),n.toString()}}Ie.MIDDLE_END_PATTERN=Int32Array.from([1,1,1,1,1,1]),Ie.NUMSYS_AND_CHECK_DIGIT_PATTERNS=[Int32Array.from([56,52,50,49,44,38,35,42,41,37]),Int32Array.from([7,11,13,14,19,25,28,21,22,26])];class Le extends Te{constructor(e){super();let n=e==null?null:e.get(b.POSSIBLE_FORMATS),r=[];t(n)?(r.push(new Ne),r.push(new Fe),r.push(new Pe),r.push(new Ie)):(n.indexOf(B.EAN_13)>-1&&r.push(new Ne),n.indexOf(B.UPC_A)>-1&&r.push(new Fe),n.indexOf(B.EAN_8)>-1&&r.push(new Pe),n.indexOf(B.UPC_E)>-1&&r.push(new Ie)),this.readers=r}decodeRow(e,t,n){for(let r of this.readers)try{let i=r.decodeRow(e,t,n),a=i.getBarcodeFormat()===B.EAN_13&&i.getText().charAt(0)===`0`,o=n==null?null:n.get(b.POSSIBLE_FORMATS),s=o==null||o.includes(B.UPC_A);if(a&&s){let e=i.getRawBytes(),t=new R(i.getText().substring(1),e,e?e.length:null,i.getResultPoints(),B.UPC_A);return t.putAllMetadata(i.getResultMetadata()),t}return i}catch{}throw new k}reset(){for(let e of this.readers)e.reset()}}class Re extends Te{constructor(){super(),this.decodeFinderCounters=new Int32Array(4),this.dataCharacterCounters=new Int32Array(8),this.oddRoundingErrors=[,,,,],this.evenRoundingErrors=[,,,,],this.oddCounts=Array(this.dataCharacterCounters.length/2),this.evenCounts=Array(this.dataCharacterCounters.length/2)}getDecodeFinderCounters(){return this.decodeFinderCounters}getDataCharacterCounters(){return this.dataCharacterCounters}getOddRoundingErrors(){return this.oddRoundingErrors}getEvenRoundingErrors(){return this.evenRoundingErrors}getOddCounts(){return this.oddCounts}getEvenCounts(){return this.evenCounts}parseFinderValue(e,t){for(let n=0;n<t.length;n++)if(Te.patternMatchVariance(e,t[n],Re.MAX_INDIVIDUAL_VARIANCE)<Re.MAX_AVG_VARIANCE)return n;throw new k}static count(e){return fe.sum(new Int32Array(e))}static increment(e,t){let n=0,r=t[0];for(let i=1;i<e.length;i++)t[i]>r&&(r=t[i],n=i);e[n]++}static decrement(e,t){let n=0,r=t[0];for(let i=1;i<e.length;i++)t[i]<r&&(r=t[i],n=i);e[n]--}static isFinderPattern(e){let t=e[0]+e[1],n=t/(t+e[2]+e[3]);if(n>=Re.MIN_FINDER_PATTERN_RATIO&&n<=Re.MAX_FINDER_PATTERN_RATIO){let t=2**53-1,n=-(2**53-1);for(let r of e)r>n&&(n=r),r<t&&(t=r);return n<10*t}return!1}}Re.MAX_AVG_VARIANCE=.2,Re.MAX_INDIVIDUAL_VARIANCE=.45,Re.MIN_FINDER_PATTERN_RATIO=9.5/12,Re.MAX_FINDER_PATTERN_RATIO=12.5/14;class ze{constructor(e,t){this.value=e,this.checksumPortion=t}getValue(){return this.value}getChecksumPortion(){return this.checksumPortion}toString(){return this.value+`(`+this.checksumPortion+`)`}equals(e){if(!(e instanceof ze))return!1;let t=e;return this.value===t.value&&this.checksumPortion===t.checksumPortion}hashCode(){return this.value^this.checksumPortion}}class Be{constructor(e,t,n,r,i){this.value=e,this.startEnd=t,this.value=e,this.startEnd=t,this.resultPoints=[],this.resultPoints.push(new V(n,i)),this.resultPoints.push(new V(r,i))}getValue(){return this.value}getStartEnd(){return this.startEnd}getResultPoints(){return this.resultPoints}equals(e){if(!(e instanceof Be))return!1;let t=e;return this.value===t.value}hashCode(){return this.value}}class Ve{constructor(){}static getRSSvalue(e,t,n){let r=0;for(let t of e)r+=t;let i=0,a=0,o=e.length;for(let s=0;s<o-1;s++){let c;for(c=1,a|=1<<s;c<e[s];c++,a&=~(1<<s)){let e=Ve.combins(r-c-1,o-s-2);if(n&&a===0&&r-c-(o-s-1)>=o-s-1&&(e-=Ve.combins(r-c-(o-s),o-s-2)),o-s-1>1){let n=0;for(let e=r-c-(o-s-2);e>t;e--)n+=Ve.combins(r-c-e-1,o-s-3);e-=n*(o-1-s)}else r-c>t&&e--;i+=e}r-=c}return i}static combins(e,t){let n,r;e-t>t?(r=t,n=e-t):(r=e-t,n=t);let i=1,a=1;for(let t=e;t>n;t--)i*=t,a<=r&&(i/=a,a++);for(;a<=r;)i/=a,a++;return i}}class He{static buildBitArray(e){let t=e.length*2-1;e[e.length-1].getRightChar()??--t;let n=new v(12*t),r=0,i=e[0].getRightChar().getValue();for(let e=11;e>=0;--e)i&1<<e&&n.set(r),r++;for(let t=1;t<e.length;++t){let i=e[t],a=i.getLeftChar().getValue();for(let e=11;e>=0;--e)a&1<<e&&n.set(r),r++;if(i.getRightChar()!=null){let e=i.getRightChar().getValue();for(let t=11;t>=0;--t)e&1<<t&&n.set(r),r++}}return n}}class Ue{constructor(e,t){t?this.decodedInformation=null:(this.finished=e,this.decodedInformation=t)}getDecodedInformation(){return this.decodedInformation}isFinished(){return this.finished}}class We{constructor(e){this.newPosition=e}getNewPosition(){return this.newPosition}}class Ge extends We{constructor(e,t){super(e),this.value=t}getValue(){return this.value}isFNC1(){return this.value===Ge.FNC1}}Ge.FNC1=`$`;class Ke extends We{constructor(e,t,n){super(e),n?(this.remaining=!0,this.remainingValue=this.remainingValue):(this.remaining=!1,this.remainingValue=0),this.newString=t}getNewString(){return this.newString}isRemaining(){return this.remaining}getRemainingValue(){return this.remainingValue}}class qe extends We{constructor(e,t,n){if(super(e),t<0||t>10||n<0||n>10)throw new x;this.firstDigit=t,this.secondDigit=n}getFirstDigit(){return this.firstDigit}getSecondDigit(){return this.secondDigit}getValue(){return this.firstDigit*10+this.secondDigit}isFirstDigitFNC1(){return this.firstDigit===qe.FNC1}isSecondDigitFNC1(){return this.secondDigit===qe.FNC1}isAnyFNC1(){return this.firstDigit===qe.FNC1||this.secondDigit===qe.FNC1}}qe.FNC1=10;class Je{constructor(){}static parseFieldsInGeneralPurpose(e){if(!e)return null;if(e.length<2)throw new k;let t=e.substring(0,2);for(let n of Je.TWO_DIGIT_DATA_LENGTH)if(n[0]===t)return n[1]===Je.VARIABLE_LENGTH?Je.processVariableAI(2,n[2],e):Je.processFixedAI(2,n[1],e);if(e.length<3)throw new k;let n=e.substring(0,3);for(let t of Je.THREE_DIGIT_DATA_LENGTH)if(t[0]===n)return t[1]===Je.VARIABLE_LENGTH?Je.processVariableAI(3,t[2],e):Je.processFixedAI(3,t[1],e);for(let t of Je.THREE_DIGIT_PLUS_DIGIT_DATA_LENGTH)if(t[0]===n)return t[1]===Je.VARIABLE_LENGTH?Je.processVariableAI(4,t[2],e):Je.processFixedAI(4,t[1],e);if(e.length<4)throw new k;let r=e.substring(0,4);for(let t of Je.FOUR_DIGIT_DATA_LENGTH)if(t[0]===r)return t[1]===Je.VARIABLE_LENGTH?Je.processVariableAI(4,t[2],e):Je.processFixedAI(4,t[1],e);throw new k}static processFixedAI(e,t,n){if(n.length<e)throw new k;let r=n.substring(0,e);if(n.length<e+t)throw new k;let i=n.substring(e,e+t),a=n.substring(e+t),o=`(`+r+`)`+i,s=Je.parseFieldsInGeneralPurpose(a);return s==null?o:o+s}static processVariableAI(e,t,n){let r=n.substring(0,e),i;i=n.length<e+t?n.length:e+t;let a=n.substring(e,i),o=n.substring(i),s=`(`+r+`)`+a,c=Je.parseFieldsInGeneralPurpose(o);return c==null?s:s+c}}Je.VARIABLE_LENGTH=[],Je.TWO_DIGIT_DATA_LENGTH=[[`00`,18],[`01`,14],[`02`,14],[`10`,Je.VARIABLE_LENGTH,20],[`11`,6],[`12`,6],[`13`,6],[`15`,6],[`17`,6],[`20`,2],[`21`,Je.VARIABLE_LENGTH,20],[`22`,Je.VARIABLE_LENGTH,29],[`30`,Je.VARIABLE_LENGTH,8],[`37`,Je.VARIABLE_LENGTH,8],[`90`,Je.VARIABLE_LENGTH,30],[`91`,Je.VARIABLE_LENGTH,30],[`92`,Je.VARIABLE_LENGTH,30],[`93`,Je.VARIABLE_LENGTH,30],[`94`,Je.VARIABLE_LENGTH,30],[`95`,Je.VARIABLE_LENGTH,30],[`96`,Je.VARIABLE_LENGTH,30],[`97`,Je.VARIABLE_LENGTH,3],[`98`,Je.VARIABLE_LENGTH,30],[`99`,Je.VARIABLE_LENGTH,30]],Je.THREE_DIGIT_DATA_LENGTH=[[`240`,Je.VARIABLE_LENGTH,30],[`241`,Je.VARIABLE_LENGTH,30],[`242`,Je.VARIABLE_LENGTH,6],[`250`,Je.VARIABLE_LENGTH,30],[`251`,Je.VARIABLE_LENGTH,30],[`253`,Je.VARIABLE_LENGTH,17],[`254`,Je.VARIABLE_LENGTH,20],[`400`,Je.VARIABLE_LENGTH,30],[`401`,Je.VARIABLE_LENGTH,30],[`402`,17],[`403`,Je.VARIABLE_LENGTH,30],[`410`,13],[`411`,13],[`412`,13],[`413`,13],[`414`,13],[`420`,Je.VARIABLE_LENGTH,20],[`421`,Je.VARIABLE_LENGTH,15],[`422`,3],[`423`,Je.VARIABLE_LENGTH,15],[`424`,3],[`425`,3],[`426`,3]],Je.THREE_DIGIT_PLUS_DIGIT_DATA_LENGTH=[[`310`,6],[`311`,6],[`312`,6],[`313`,6],[`314`,6],[`315`,6],[`316`,6],[`320`,6],[`321`,6],[`322`,6],[`323`,6],[`324`,6],[`325`,6],[`326`,6],[`327`,6],[`328`,6],[`329`,6],[`330`,6],[`331`,6],[`332`,6],[`333`,6],[`334`,6],[`335`,6],[`336`,6],[`340`,6],[`341`,6],[`342`,6],[`343`,6],[`344`,6],[`345`,6],[`346`,6],[`347`,6],[`348`,6],[`349`,6],[`350`,6],[`351`,6],[`352`,6],[`353`,6],[`354`,6],[`355`,6],[`356`,6],[`357`,6],[`360`,6],[`361`,6],[`362`,6],[`363`,6],[`364`,6],[`365`,6],[`366`,6],[`367`,6],[`368`,6],[`369`,6],[`390`,Je.VARIABLE_LENGTH,15],[`391`,Je.VARIABLE_LENGTH,18],[`392`,Je.VARIABLE_LENGTH,15],[`393`,Je.VARIABLE_LENGTH,18],[`703`,Je.VARIABLE_LENGTH,30]],Je.FOUR_DIGIT_DATA_LENGTH=[[`7001`,13],[`7002`,Je.VARIABLE_LENGTH,30],[`7003`,10],[`8001`,14],[`8002`,Je.VARIABLE_LENGTH,20],[`8003`,Je.VARIABLE_LENGTH,30],[`8004`,Je.VARIABLE_LENGTH,30],[`8005`,6],[`8006`,18],[`8007`,Je.VARIABLE_LENGTH,30],[`8008`,Je.VARIABLE_LENGTH,12],[`8018`,18],[`8020`,Je.VARIABLE_LENGTH,25],[`8100`,6],[`8101`,10],[`8102`,2],[`8110`,Je.VARIABLE_LENGTH,70],[`8200`,Je.VARIABLE_LENGTH,70]];class Ye{constructor(e){this.buffer=new D,this.information=e}decodeAllCodes(e,t){let n=t,r=null;do{let t=this.decodeGeneralPurposeField(n,r),i=Je.parseFieldsInGeneralPurpose(t.getNewString());if(i!=null&&e.append(i),r=t.isRemaining()?``+t.getRemainingValue():null,n===t.getNewPosition())break;n=t.getNewPosition()}while(!0);return e.toString()}isStillNumeric(e){if(e+7>this.information.getSize())return e+4<=this.information.getSize();for(let t=e;t<e+3;++t)if(this.information.get(t))return!0;return this.information.get(e+3)}decodeNumeric(e){if(e+7>this.information.getSize()){let t=this.extractNumericValueFromBitArray(e,4);return t===0?new qe(this.information.getSize(),qe.FNC1,qe.FNC1):new qe(this.information.getSize(),t-1,qe.FNC1)}let t=this.extractNumericValueFromBitArray(e,7),n=(t-8)/11,r=(t-8)%11;return new qe(e+7,n,r)}extractNumericValueFromBitArray(e,t){return Ye.extractNumericValueFromBitArray(this.information,e,t)}static extractNumericValueFromBitArray(e,t,n){let r=0;for(let i=0;i<n;++i)e.get(t+i)&&(r|=1<<n-i-1);return r}decodeGeneralPurposeField(e,t){this.buffer.setLengthToZero(),t!=null&&this.buffer.append(t),this.current.setPosition(e);let n=this.parseBlocks();return n!=null&&n.isRemaining()?new Ke(this.current.getPosition(),this.buffer.toString(),n.getRemainingValue()):new Ke(this.current.getPosition(),this.buffer.toString())}parseBlocks(){let e,t;do{let n=this.current.getPosition();if(this.current.isAlpha()?(t=this.parseAlphaBlock(),e=t.isFinished()):this.current.isIsoIec646()?(t=this.parseIsoIec646Block(),e=t.isFinished()):(t=this.parseNumericBlock(),e=t.isFinished()),n===this.current.getPosition()&&!e)break}while(!e);return t.getDecodedInformation()}parseNumericBlock(){for(;this.isStillNumeric(this.current.getPosition());){let e=this.decodeNumeric(this.current.getPosition());if(this.current.setPosition(e.getNewPosition()),e.isFirstDigitFNC1()){let t;return t=e.isSecondDigitFNC1()?new Ke(this.current.getPosition(),this.buffer.toString()):new Ke(this.current.getPosition(),this.buffer.toString(),e.getSecondDigit()),new Ue(!0,t)}if(this.buffer.append(e.getFirstDigit()),e.isSecondDigitFNC1())return new Ue(!0,new Ke(this.current.getPosition(),this.buffer.toString()));this.buffer.append(e.getSecondDigit())}return this.isNumericToAlphaNumericLatch(this.current.getPosition())&&(this.current.setAlpha(),this.current.incrementPosition(4)),new Ue(!1)}parseIsoIec646Block(){for(;this.isStillIsoIec646(this.current.getPosition());){let e=this.decodeIsoIec646(this.current.getPosition());if(this.current.setPosition(e.getNewPosition()),e.isFNC1())return new Ue(!0,new Ke(this.current.getPosition(),this.buffer.toString()));this.buffer.append(e.getValue())}return this.isAlphaOr646ToNumericLatch(this.current.getPosition())?(this.current.incrementPosition(3),this.current.setNumeric()):this.isAlphaTo646ToAlphaLatch(this.current.getPosition())&&(this.current.getPosition()+5<this.information.getSize()?this.current.incrementPosition(5):this.current.setPosition(this.information.getSize()),this.current.setAlpha()),new Ue(!1)}parseAlphaBlock(){for(;this.isStillAlpha(this.current.getPosition());){let e=this.decodeAlphanumeric(this.current.getPosition());if(this.current.setPosition(e.getNewPosition()),e.isFNC1())return new Ue(!0,new Ke(this.current.getPosition(),this.buffer.toString()));this.buffer.append(e.getValue())}return this.isAlphaOr646ToNumericLatch(this.current.getPosition())?(this.current.incrementPosition(3),this.current.setNumeric()):this.isAlphaTo646ToAlphaLatch(this.current.getPosition())&&(this.current.getPosition()+5<this.information.getSize()?this.current.incrementPosition(5):this.current.setPosition(this.information.getSize()),this.current.setIsoIec646()),new Ue(!1)}isStillIsoIec646(e){if(e+5>this.information.getSize())return!1;let t=this.extractNumericValueFromBitArray(e,5);if(t>=5&&t<16)return!0;if(e+7>this.information.getSize())return!1;let n=this.extractNumericValueFromBitArray(e,7);if(n>=64&&n<116)return!0;if(e+8>this.information.getSize())return!1;let r=this.extractNumericValueFromBitArray(e,8);return r>=232&&r<253}decodeIsoIec646(e){let t=this.extractNumericValueFromBitArray(e,5);if(t===15)return new Ge(e+5,Ge.FNC1);if(t>=5&&t<15)return new Ge(e+5,`0`+(t-5));let n=this.extractNumericValueFromBitArray(e,7);if(n>=64&&n<90)return new Ge(e+7,``+(n+1));if(n>=90&&n<116)return new Ge(e+7,``+(n+7));let r=this.extractNumericValueFromBitArray(e,8),i;switch(r){case 232:i=`!`;break;case 233:i=`"`;break;case 234:i=`%`;break;case 235:i=`&`;break;case 236:i=`'`;break;case 237:i=`(`;break;case 238:i=`)`;break;case 239:i=`*`;break;case 240:i=`+`;break;case 241:i=`,`;break;case 242:i=`-`;break;case 243:i=`.`;break;case 244:i=`/`;break;case 245:i=`:`;break;case 246:i=`;`;break;case 247:i=`<`;break;case 248:i=`=`;break;case 249:i=`>`;break;case 250:i=`?`;break;case 251:i=`_`;break;case 252:i=` `;break;default:throw new x}return new Ge(e+8,i)}isStillAlpha(e){if(e+5>this.information.getSize())return!1;let t=this.extractNumericValueFromBitArray(e,5);if(t>=5&&t<16)return!0;if(e+6>this.information.getSize())return!1;let n=this.extractNumericValueFromBitArray(e,6);return n>=16&&n<63}decodeAlphanumeric(e){let t=this.extractNumericValueFromBitArray(e,5);if(t===15)return new Ge(e+5,Ge.FNC1);if(t>=5&&t<15)return new Ge(e+5,`0`+(t-5));let n=this.extractNumericValueFromBitArray(e,6);if(n>=32&&n<58)return new Ge(e+6,``+(n+33));let r;switch(n){case 58:r=`*`;break;case 59:r=`,`;break;case 60:r=`-`;break;case 61:r=`.`;break;case 62:r=`/`;break;default:throw new ce(`Decoding invalid alphanumeric value: `+n)}return new Ge(e+6,r)}isAlphaTo646ToAlphaLatch(e){if(e+1>this.information.getSize())return!1;for(let t=0;t<5&&t+e<this.information.getSize();++t)if(t===2){if(!this.information.get(e+2))return!1}else if(this.information.get(e+t))return!1;return!0}isAlphaOr646ToNumericLatch(e){if(e+3>this.information.getSize())return!1;for(let t=e;t<e+3;++t)if(this.information.get(t))return!1;return!0}isNumericToAlphaNumericLatch(e){if(e+1>this.information.getSize())return!1;for(let t=0;t<4&&t+e<this.information.getSize();++t)if(this.information.get(e+t))return!1;return!0}}class Xe{constructor(e){this.information=e,this.generalDecoder=new Ye(e)}getInformation(){return this.information}getGeneralDecoder(){return this.generalDecoder}}class Ze extends Xe{constructor(e){super(e)}encodeCompressedGtin(e,t){e.append(`(01)`);let n=e.length();e.append(`9`),this.encodeCompressedGtinWithoutAI(e,t,n)}encodeCompressedGtinWithoutAI(e,t,n){for(let n=0;n<4;++n){let r=this.getGeneralDecoder().extractNumericValueFromBitArray(t+10*n,10);r/100==0&&e.append(`0`),r/10==0&&e.append(`0`),e.append(r)}Ze.appendCheckDigit(e,n)}static appendCheckDigit(e,t){let n=0;for(let r=0;r<13;r++){let i=e.charAt(r+t).charCodeAt(0)-48;n+=r&1?i:3*i}n=10-n%10,n===10&&(n=0),e.append(n)}}Ze.GTIN_SIZE=40;class Qe extends Ze{constructor(e){super(e)}parseInformation(){let e=new D;e.append(`(01)`);let t=e.length(),n=this.getGeneralDecoder().extractNumericValueFromBitArray(Qe.HEADER_SIZE,4);return e.append(n),this.encodeCompressedGtinWithoutAI(e,Qe.HEADER_SIZE+4,t),this.getGeneralDecoder().decodeAllCodes(e,Qe.HEADER_SIZE+44)}}Qe.HEADER_SIZE=4;class $e extends Xe{constructor(e){super(e)}parseInformation(){let e=new D;return this.getGeneralDecoder().decodeAllCodes(e,$e.HEADER_SIZE)}}$e.HEADER_SIZE=5;class et extends Ze{constructor(e){super(e)}encodeCompressedWeight(e,t,n){let r=this.getGeneralDecoder().extractNumericValueFromBitArray(t,n);this.addWeightCode(e,r);let i=this.checkWeight(r),a=1e5;for(let t=0;t<5;++t)i/a===0&&e.append(`0`),a/=10;e.append(i)}}class tt extends et{constructor(e){super(e)}parseInformation(){if(this.getInformation().getSize()!=tt.HEADER_SIZE+et.GTIN_SIZE+tt.WEIGHT_SIZE)throw new k;let e=new D;return this.encodeCompressedGtin(e,tt.HEADER_SIZE),this.encodeCompressedWeight(e,tt.HEADER_SIZE+et.GTIN_SIZE,tt.WEIGHT_SIZE),e.toString()}}tt.HEADER_SIZE=5,tt.WEIGHT_SIZE=15;class nt extends tt{constructor(e){super(e)}addWeightCode(e,t){e.append(`(3103)`)}checkWeight(e){return e}}class rt extends tt{constructor(e){super(e)}addWeightCode(e,t){t<1e4?e.append(`(3202)`):e.append(`(3203)`)}checkWeight(e){return e<1e4?e:e-1e4}}class it extends Ze{constructor(e){super(e)}parseInformation(){if(this.getInformation().getSize()<it.HEADER_SIZE+Ze.GTIN_SIZE)throw new k;let e=new D;this.encodeCompressedGtin(e,it.HEADER_SIZE);let t=this.getGeneralDecoder().extractNumericValueFromBitArray(it.HEADER_SIZE+Ze.GTIN_SIZE,it.LAST_DIGIT_SIZE);e.append(`(392`),e.append(t),e.append(`)`);let n=this.getGeneralDecoder().decodeGeneralPurposeField(it.HEADER_SIZE+Ze.GTIN_SIZE+it.LAST_DIGIT_SIZE,null);return e.append(n.getNewString()),e.toString()}}it.HEADER_SIZE=8,it.LAST_DIGIT_SIZE=2;class at extends Ze{constructor(e){super(e)}parseInformation(){if(this.getInformation().getSize()<at.HEADER_SIZE+Ze.GTIN_SIZE)throw new k;let e=new D;this.encodeCompressedGtin(e,at.HEADER_SIZE);let t=this.getGeneralDecoder().extractNumericValueFromBitArray(at.HEADER_SIZE+Ze.GTIN_SIZE,at.LAST_DIGIT_SIZE);e.append(`(393`),e.append(t),e.append(`)`);let n=this.getGeneralDecoder().extractNumericValueFromBitArray(at.HEADER_SIZE+Ze.GTIN_SIZE+at.LAST_DIGIT_SIZE,at.FIRST_THREE_DIGITS_SIZE);n/100==0&&e.append(`0`),n/10==0&&e.append(`0`),e.append(n);let r=this.getGeneralDecoder().decodeGeneralPurposeField(at.HEADER_SIZE+Ze.GTIN_SIZE+at.LAST_DIGIT_SIZE+at.FIRST_THREE_DIGITS_SIZE,null);return e.append(r.getNewString()),e.toString()}}at.HEADER_SIZE=8,at.LAST_DIGIT_SIZE=2,at.FIRST_THREE_DIGITS_SIZE=10;class ot extends et{constructor(e,t,n){super(e),this.dateCode=n,this.firstAIdigits=t}parseInformation(){if(this.getInformation().getSize()!=ot.HEADER_SIZE+ot.GTIN_SIZE+ot.WEIGHT_SIZE+ot.DATE_SIZE)throw new k;let e=new D;return this.encodeCompressedGtin(e,ot.HEADER_SIZE),this.encodeCompressedWeight(e,ot.HEADER_SIZE+ot.GTIN_SIZE,ot.WEIGHT_SIZE),this.encodeCompressedDate(e,ot.HEADER_SIZE+ot.GTIN_SIZE+ot.WEIGHT_SIZE),e.toString()}encodeCompressedDate(e,t){let n=this.getGeneralDecoder().extractNumericValueFromBitArray(t,ot.DATE_SIZE);if(n==38400)return;e.append(`(`),e.append(this.dateCode),e.append(`)`);let r=n%32;n/=32;let i=n%12+1;n/=12;let a=n;a/10==0&&e.append(`0`),e.append(a),i/10==0&&e.append(`0`),e.append(i),r/10==0&&e.append(`0`),e.append(r)}addWeightCode(e,t){e.append(`(`),e.append(this.firstAIdigits),e.append(t/1e5),e.append(`)`)}checkWeight(e){return e%1e5}}ot.HEADER_SIZE=8,ot.WEIGHT_SIZE=20,ot.DATE_SIZE=16;function st(e){try{if(e.get(1))return new Qe(e);if(!e.get(2))return new $e(e);switch(Ye.extractNumericValueFromBitArray(e,1,4)){case 4:return new nt(e);case 5:return new rt(e)}switch(Ye.extractNumericValueFromBitArray(e,1,5)){case 12:return new it(e);case 13:return new at(e)}switch(Ye.extractNumericValueFromBitArray(e,1,7)){case 56:return new ot(e,`310`,`11`);case 57:return new ot(e,`320`,`11`);case 58:return new ot(e,`310`,`13`);case 59:return new ot(e,`320`,`13`);case 60:return new ot(e,`310`,`15`);case 61:return new ot(e,`320`,`15`);case 62:return new ot(e,`310`,`17`);case 63:return new ot(e,`320`,`17`)}}catch(t){throw console.log(t),new ce(`unknown decoder: `+e)}}class ct{constructor(e,t,n,r){this.leftchar=e,this.rightchar=t,this.finderpattern=n,this.maybeLast=r}mayBeLast(){return this.maybeLast}getLeftChar(){return this.leftchar}getRightChar(){return this.rightchar}getFinderPattern(){return this.finderpattern}mustBeLast(){return this.rightchar==null}toString(){return`[ `+this.leftchar+`, `+this.rightchar+` : `+(this.finderpattern==null?`null`:this.finderpattern.getValue())+` ]`}static equals(e,t){return e instanceof ct?ct.equalsOrNull(e.leftchar,t.leftchar)&&ct.equalsOrNull(e.rightchar,t.rightchar)&&ct.equalsOrNull(e.finderpattern,t.finderpattern):!1}static equalsOrNull(e,t){return e===null?t===null:ct.equals(e,t)}hashCode(){return this.leftchar.getValue()^this.rightchar.getValue()^this.finderpattern.getValue()}}class lt{constructor(e,t,n){this.pairs=e,this.rowNumber=t,this.wasReversed=n}getPairs(){return this.pairs}getRowNumber(){return this.rowNumber}isReversed(){return this.wasReversed}isEquivalent(e){return this.checkEqualitity(this,e)}toString(){return`{ `+this.pairs+` }`}equals(e,t){return e instanceof lt?this.checkEqualitity(e,t)&&e.wasReversed===t.wasReversed:!1}checkEqualitity(e,t){if(!e||!t)return;let n;return e.forEach((e,r)=>{t.forEach(t=>{e.getLeftChar().getValue()===t.getLeftChar().getValue()&&e.getRightChar().getValue()===t.getRightChar().getValue()&&e.getFinderPatter().getValue()===t.getFinderPatter().getValue()&&(n=!0)})}),n}}class U extends Re{constructor(e){super(...arguments),this.pairs=Array(U.MAX_PAIRS),this.rows=[],this.startEnd=[2],this.verbose=e===!0}decodeRow(e,t,n){this.pairs.length=0,this.startFromEven=!1;try{return U.constructResult(this.decodeRow2pairs(e,t))}catch(e){this.verbose&&console.log(e)}return this.pairs.length=0,this.startFromEven=!0,U.constructResult(this.decodeRow2pairs(e,t))}reset(){this.pairs.length=0,this.rows.length=0}decodeRow2pairs(e,t){let n=!1;for(;!n;)try{this.pairs.push(this.retrieveNextPair(t,this.pairs,e))}catch(e){if(e instanceof k){if(!this.pairs.length)throw new k;n=!0}}if(this.checkChecksum())return this.pairs;let r;if(r=!!this.rows.length,this.storeRow(e,!1),r){let e=this.checkRowsBoolean(!1);if(e!=null||(e=this.checkRowsBoolean(!0),e!=null))return e}throw new k}checkRowsBoolean(e){if(this.rows.length>25)return this.rows.length=0,null;this.pairs.length=0,e&&(this.rows=this.rows.reverse());let t=null;try{t=this.checkRows([],0)}catch(e){this.verbose&&console.log(e)}return e&&(this.rows=this.rows.reverse()),t}checkRows(e,t){for(let n=t;n<this.rows.length;n++){let t=this.rows[n];this.pairs.length=0;for(let t of e)this.pairs.push(t.getPairs());if(this.pairs.push(t.getPairs()),!U.isValidSequence(this.pairs))continue;if(this.checkChecksum())return this.pairs;let r=Array(e);r.push(t);try{return this.checkRows(r,n+1)}catch(e){this.verbose&&console.log(e)}}throw new k}static isValidSequence(e){for(let t of U.FINDER_PATTERN_SEQUENCES){if(e.length>t.length)continue;let n=!0;for(let r=0;r<e.length;r++)if(e[r].getFinderPattern().getValue()!=t[r]){n=!1;break}if(n)return!0}return!1}storeRow(e,t){let n=0,r=!1,i=!1;for(;n<this.rows.length;){let t=this.rows[n];if(t.getRowNumber()>e){i=t.isEquivalent(this.pairs);break}r=t.isEquivalent(this.pairs),n++}i||r||U.isPartialRow(this.pairs,this.rows)||(this.rows.push(n,new lt(this.pairs,e,t)),this.removePartialRows(this.pairs,this.rows))}removePartialRows(e,t){for(let n of t)if(n.getPairs().length!==e.length){for(let t of n.getPairs())for(let n of e)if(ct.equals(t,n))break}}static isPartialRow(e,t){for(let n of t){let t=!0;for(let r of e){let e=!1;for(let t of n.getPairs())if(r.equals(t)){e=!0;break}if(!e){t=!1;break}}if(t)return!0}return!1}getRows(){return this.rows}static constructResult(e){let t=st(He.buildBitArray(e)).parseInformation(),n=e[0].getFinderPattern().getResultPoints(),r=e[e.length-1].getFinderPattern().getResultPoints();return new R(t,null,null,[n[0],n[1],r[0],r[1]],B.RSS_EXPANDED,null)}checkChecksum(){let e=this.pairs.get(0),t=e.getLeftChar(),n=e.getRightChar();if(n==null)return!1;let r=n.getChecksumPortion(),i=2;for(let e=1;e<this.pairs.size();++e){let t=this.pairs.get(e);r+=t.getLeftChar().getChecksumPortion(),i++;let n=t.getRightChar();n!=null&&(r+=n.getChecksumPortion(),i++)}return r%=211,211*(i-4)+r==t.getValue()}static getNextSecondBar(e,t){let n;return e.get(t)?(n=e.getNextUnset(t),n=e.getNextSet(n)):(n=e.getNextSet(t),n=e.getNextUnset(n)),n}retrieveNextPair(e,t,n){let r=t.length%2==0;this.startFromEven&&(r=!r);let i,a=!0,o=-1;do this.findNextPair(e,t,o),i=this.parseFoundFinderPattern(e,n,r),i==null?o=U.getNextSecondBar(e,this.startEnd[0]):a=!1;while(a);let s=this.decodeDataCharacter(e,i,r,!0);if(!this.isEmptyPair(t)&&t[t.length-1].mustBeLast())throw new k;let c;try{c=this.decodeDataCharacter(e,i,r,!1)}catch(e){c=null,this.verbose&&console.log(e)}return new ct(s,c,i,!0)}isEmptyPair(e){return e.length===0}findNextPair(e,t,n){let r=this.getDecodeFinderCounters();r[0]=0,r[1]=0,r[2]=0,r[3]=0;let i=e.getSize(),a;a=n>=0?n:this.isEmptyPair(t)?0:t[t.length-1].getFinderPattern().getStartEnd()[1];let o=t.length%2!=0;this.startFromEven&&(o=!o);let s=!1;for(;a<i&&(s=!e.get(a),s);)a++;let c=0,l=a;for(let t=a;t<i;t++)if(e.get(t)!=s)r[c]++;else{if(c==3){if(o&&U.reverseCounters(r),U.isFinderPattern(r)){this.startEnd[0]=l,this.startEnd[1]=t;return}o&&U.reverseCounters(r),l+=r[0]+r[1],r[0]=r[2],r[1]=r[3],r[2]=0,r[3]=0,c--}else c++;r[c]=1,s=!s}throw new k}static reverseCounters(e){let t=e.length;for(let n=0;n<t/2;++n){let r=e[n];e[n]=e[t-n-1],e[t-n-1]=r}}parseFoundFinderPattern(e,t,n){let r,i,a;if(n){let t=this.startEnd[0]-1;for(;t>=0&&!e.get(t);)t--;t++,r=this.startEnd[0]-t,i=t,a=this.startEnd[1]}else i=this.startEnd[0],a=e.getNextUnset(this.startEnd[1]+1),r=a-this.startEnd[1];let o=this.getDecodeFinderCounters();p.arraycopy(o,0,o,1,o.length-1),o[0]=r;let s;try{s=this.parseFinderValue(o,U.FINDER_PATTERNS)}catch{return null}return new Be(s,[i,a],i,a,t)}decodeDataCharacter(e,t,n,r){let i=this.getDataCharacterCounters();for(let e=0;e<i.length;e++)i[e]=0;if(r)U.recordPatternInReverse(e,t.getStartEnd()[0],i);else{U.recordPattern(e,t.getStartEnd()[1],i);for(let e=0,t=i.length-1;e<t;e++,t--){let n=i[e];i[e]=i[t],i[t]=n}}let a=fe.sum(new Int32Array(i))/17,o=(t.getStartEnd()[1]-t.getStartEnd()[0])/15;if(Math.abs(a-o)/o>.3)throw new k;let s=this.getOddCounts(),c=this.getEvenCounts(),l=this.getOddRoundingErrors(),u=this.getEvenRoundingErrors();for(let e=0;e<i.length;e++){let t=1*i[e]/a,n=t+.5;if(n<1){if(t<.3)throw new k;n=1}else if(n>8){if(t>8.7)throw new k;n=8}let r=e/2;e&1?(c[r]=n,u[r]=t-n):(s[r]=n,l[r]=t-n)}this.adjustOddEvenCounts(17);let d=4*t.getValue()+(n?0:2)+ +!r-1,f=0,p=0;for(let e=s.length-1;e>=0;e--){if(U.isNotA1left(t,n,r)){let t=U.WEIGHTS[d][2*e];p+=s[e]*t}f+=s[e]}let m=0;for(let e=c.length-1;e>=0;e--)if(U.isNotA1left(t,n,r)){let t=U.WEIGHTS[d][2*e+1];m+=c[e]*t}let h=p+m;if(f&1||f>13||f<4)throw new k;let g=(13-f)/2,_=U.SYMBOL_WIDEST[g],v=9-_,y=Ve.getRSSvalue(s,_,!0),b=Ve.getRSSvalue(c,v,!1),x=U.EVEN_TOTAL_SUBSET[g],S=U.GSUM[g];return new ze(y*x+b+S,h)}static isNotA1left(e,t,n){return!(e.getValue()==0&&t&&n)}adjustOddEvenCounts(e){let t=fe.sum(new Int32Array(this.getOddCounts())),n=fe.sum(new Int32Array(this.getEvenCounts())),r=!1,i=!1;t>13?i=!0:t<4&&(r=!0);let a=!1,o=!1;n>13?o=!0:n<4&&(a=!0);let s=t+n-e,c=(t&1)==1,l=(n&1)==0;if(s==1)if(c){if(l)throw new k;i=!0}else{if(!l)throw new k;o=!0}else if(s==-1)if(c){if(l)throw new k;r=!0}else{if(!l)throw new k;a=!0}else if(s==0){if(c){if(!l)throw new k;t<n?(r=!0,o=!0):(i=!0,a=!0)}else if(l)throw new k}else throw new k;if(r){if(i)throw new k;U.increment(this.getOddCounts(),this.getOddRoundingErrors())}if(i&&U.decrement(this.getOddCounts(),this.getOddRoundingErrors()),a){if(o)throw new k;U.increment(this.getEvenCounts(),this.getOddRoundingErrors())}o&&U.decrement(this.getEvenCounts(),this.getEvenRoundingErrors())}}U.SYMBOL_WIDEST=[7,5,4,3,1],U.EVEN_TOTAL_SUBSET=[4,20,52,104,204],U.GSUM=[0,348,1388,2948,3988],U.FINDER_PATTERNS=[Int32Array.from([1,8,4,1]),Int32Array.from([3,6,4,1]),Int32Array.from([3,4,6,1]),Int32Array.from([3,2,8,1]),Int32Array.from([2,6,5,1]),Int32Array.from([2,2,9,1])],U.WEIGHTS=[[1,3,9,27,81,32,96,77],[20,60,180,118,143,7,21,63],[189,145,13,39,117,140,209,205],[193,157,49,147,19,57,171,91],[62,186,136,197,169,85,44,132],[185,133,188,142,4,12,36,108],[113,128,173,97,80,29,87,50],[150,28,84,41,123,158,52,156],[46,138,203,187,139,206,196,166],[76,17,51,153,37,111,122,155],[43,129,176,106,107,110,119,146],[16,48,144,10,30,90,59,177],[109,116,137,200,178,112,125,164],[70,210,208,202,184,130,179,115],[134,191,151,31,93,68,204,190],[148,22,66,198,172,94,71,2],[6,18,54,162,64,192,154,40],[120,149,25,75,14,42,126,167],[79,26,78,23,69,207,199,175],[103,98,83,38,114,131,182,124],[161,61,183,127,170,88,53,159],[55,165,73,8,24,72,5,15],[45,135,194,160,58,174,100,89]],U.FINDER_PAT_A=0,U.FINDER_PAT_B=1,U.FINDER_PAT_C=2,U.FINDER_PAT_D=3,U.FINDER_PAT_E=4,U.FINDER_PAT_F=5,U.FINDER_PATTERN_SEQUENCES=[[U.FINDER_PAT_A,U.FINDER_PAT_A],[U.FINDER_PAT_A,U.FINDER_PAT_B,U.FINDER_PAT_B],[U.FINDER_PAT_A,U.FINDER_PAT_C,U.FINDER_PAT_B,U.FINDER_PAT_D],[U.FINDER_PAT_A,U.FINDER_PAT_E,U.FINDER_PAT_B,U.FINDER_PAT_D,U.FINDER_PAT_C],[U.FINDER_PAT_A,U.FINDER_PAT_E,U.FINDER_PAT_B,U.FINDER_PAT_D,U.FINDER_PAT_D,U.FINDER_PAT_F],[U.FINDER_PAT_A,U.FINDER_PAT_E,U.FINDER_PAT_B,U.FINDER_PAT_D,U.FINDER_PAT_E,U.FINDER_PAT_F,U.FINDER_PAT_F],[U.FINDER_PAT_A,U.FINDER_PAT_A,U.FINDER_PAT_B,U.FINDER_PAT_B,U.FINDER_PAT_C,U.FINDER_PAT_C,U.FINDER_PAT_D,U.FINDER_PAT_D],[U.FINDER_PAT_A,U.FINDER_PAT_A,U.FINDER_PAT_B,U.FINDER_PAT_B,U.FINDER_PAT_C,U.FINDER_PAT_C,U.FINDER_PAT_D,U.FINDER_PAT_E,U.FINDER_PAT_E],[U.FINDER_PAT_A,U.FINDER_PAT_A,U.FINDER_PAT_B,U.FINDER_PAT_B,U.FINDER_PAT_C,U.FINDER_PAT_C,U.FINDER_PAT_D,U.FINDER_PAT_E,U.FINDER_PAT_F,U.FINDER_PAT_F],[U.FINDER_PAT_A,U.FINDER_PAT_A,U.FINDER_PAT_B,U.FINDER_PAT_B,U.FINDER_PAT_C,U.FINDER_PAT_D,U.FINDER_PAT_D,U.FINDER_PAT_E,U.FINDER_PAT_E,U.FINDER_PAT_F,U.FINDER_PAT_F]],U.MAX_PAIRS=11;class ut extends ze{constructor(e,t,n){super(e,t),this.count=0,this.finderPattern=n}getFinderPattern(){return this.finderPattern}getCount(){return this.count}incrementCount(){this.count++}}class dt extends Re{constructor(){super(...arguments),this.possibleLeftPairs=[],this.possibleRightPairs=[]}decodeRow(e,t,n){let r=this.decodePair(t,!1,e,n);dt.addOrTally(this.possibleLeftPairs,r),t.reverse();let i=this.decodePair(t,!0,e,n);dt.addOrTally(this.possibleRightPairs,i),t.reverse();for(let e of this.possibleLeftPairs)if(e.getCount()>1){for(let t of this.possibleRightPairs)if(t.getCount()>1&&dt.checkChecksum(e,t))return dt.constructResult(e,t)}throw new k}static addOrTally(e,t){if(t==null)return;let n=!1;for(let r of e)if(r.getValue()===t.getValue()){r.incrementCount(),n=!0;break}n||e.push(t)}reset(){this.possibleLeftPairs.length=0,this.possibleRightPairs.length=0}static constructResult(e,t){let n=4537077*e.getValue()+t.getValue(),r=new String(n).toString(),i=new D;for(let e=13-r.length;e>0;e--)i.append(`0`);i.append(r);let a=0;for(let e=0;e<13;e++){let t=i.charAt(e).charCodeAt(0)-48;a+=e&1?t:3*t}a=10-a%10,a===10&&(a=0),i.append(a.toString());let o=e.getFinderPattern().getResultPoints(),s=t.getFinderPattern().getResultPoints();return new R(i.toString(),null,0,[o[0],o[1],s[0],s[1]],B.RSS_14,new Date().getTime())}static checkChecksum(e,t){let n=(e.getChecksumPortion()+16*t.getChecksumPortion())%79,r=9*e.getFinderPattern().getValue()+t.getFinderPattern().getValue();return r>72&&r--,r>8&&r--,n===r}decodePair(e,t,n,r){try{let i=this.findFinderPattern(e,t),a=this.parseFoundFinderPattern(e,n,t,i),o=r==null?null:r.get(b.NEED_RESULT_POINT_CALLBACK);if(o!=null){let r=(i[0]+i[1])/2;t&&(r=e.getSize()-1-r),o.foundPossibleResultPoint(new V(r,n))}let s=this.decodeDataCharacter(e,a,!0),c=this.decodeDataCharacter(e,a,!1);return new ut(1597*s.getValue()+c.getValue(),s.getChecksumPortion()+4*c.getChecksumPortion(),a)}catch{return null}}decodeDataCharacter(e,t,n){let r=this.getDataCharacterCounters();for(let e=0;e<r.length;e++)r[e]=0;if(n)Te.recordPatternInReverse(e,t.getStartEnd()[0],r);else{Te.recordPattern(e,t.getStartEnd()[1]+1,r);for(let e=0,t=r.length-1;e<t;e++,t--){let n=r[e];r[e]=r[t],r[t]=n}}let i=n?16:15,a=fe.sum(new Int32Array(r))/i,o=this.getOddCounts(),s=this.getEvenCounts(),c=this.getOddRoundingErrors(),l=this.getEvenRoundingErrors();for(let e=0;e<r.length;e++){let t=r[e]/a,n=Math.floor(t+.5);n<1?n=1:n>8&&(n=8);let i=Math.floor(e/2);e&1?(s[i]=n,l[i]=t-n):(o[i]=n,c[i]=t-n)}this.adjustOddEvenCounts(n,i);let u=0,d=0;for(let e=o.length-1;e>=0;e--)d*=9,d+=o[e],u+=o[e];let f=0,p=0;for(let e=s.length-1;e>=0;e--)f*=9,f+=s[e],p+=s[e];let m=d+3*f;if(n){if(u&1||u>12||u<4)throw new k;let e=(12-u)/2,t=dt.OUTSIDE_ODD_WIDEST[e],n=9-t,r=Ve.getRSSvalue(o,t,!1),i=Ve.getRSSvalue(s,n,!0),a=dt.OUTSIDE_EVEN_TOTAL_SUBSET[e],c=dt.OUTSIDE_GSUM[e];return new ze(r*a+i+c,m)}else{if(p&1||p>10||p<4)throw new k;let e=(10-p)/2,t=dt.INSIDE_ODD_WIDEST[e],n=9-t,r=Ve.getRSSvalue(o,t,!0),i=Ve.getRSSvalue(s,n,!1),a=dt.INSIDE_ODD_TOTAL_SUBSET[e],c=dt.INSIDE_GSUM[e];return new ze(i*a+r+c,m)}}findFinderPattern(e,t){let n=this.getDecodeFinderCounters();n[0]=0,n[1]=0,n[2]=0,n[3]=0;let r=e.getSize(),i=!1,a=0;for(;a<r&&(i=!e.get(a),t!==i);)a++;let o=0,s=a;for(let t=a;t<r;t++)if(e.get(t)!==i)n[o]++;else{if(o===3){if(Re.isFinderPattern(n))return[s,t];s+=n[0]+n[1],n[0]=n[2],n[1]=n[3],n[2]=0,n[3]=0,o--}else o++;n[o]=1,i=!i}throw new k}parseFoundFinderPattern(e,t,n,r){let i=e.get(r[0]),a=r[0]-1;for(;a>=0&&i!==e.get(a);)a--;a++;let o=r[0]-a,s=this.getDecodeFinderCounters(),c=new Int32Array(s.length);p.arraycopy(s,0,c,1,s.length-1),c[0]=o;let l=this.parseFinderValue(c,dt.FINDER_PATTERNS),u=a,d=r[1];return n&&(u=e.getSize()-1-u,d=e.getSize()-1-d),new Be(l,[a,r[1]],u,d,t)}adjustOddEvenCounts(e,t){let n=fe.sum(new Int32Array(this.getOddCounts())),r=fe.sum(new Int32Array(this.getEvenCounts())),i=!1,a=!1,o=!1,s=!1;e?(n>12?a=!0:n<4&&(i=!0),r>12?s=!0:r<4&&(o=!0)):(n>11?a=!0:n<5&&(i=!0),r>10?s=!0:r<4&&(o=!0));let c=n+r-t,l=(n&1)==+!!e,u=(r&1)==1;if(c===1)if(l){if(u)throw new k;a=!0}else{if(!u)throw new k;s=!0}else if(c===-1)if(l){if(u)throw new k;i=!0}else{if(!u)throw new k;o=!0}else if(c===0){if(l){if(!u)throw new k;n<r?(i=!0,s=!0):(a=!0,o=!0)}else if(u)throw new k}else throw new k;if(i){if(a)throw new k;Re.increment(this.getOddCounts(),this.getOddRoundingErrors())}if(a&&Re.decrement(this.getOddCounts(),this.getOddRoundingErrors()),o){if(s)throw new k;Re.increment(this.getEvenCounts(),this.getOddRoundingErrors())}s&&Re.decrement(this.getEvenCounts(),this.getEvenRoundingErrors())}}dt.OUTSIDE_EVEN_TOTAL_SUBSET=[1,10,34,70,126],dt.INSIDE_ODD_TOTAL_SUBSET=[4,20,48,81],dt.OUTSIDE_GSUM=[0,161,961,2015,2715],dt.INSIDE_GSUM=[0,336,1036,1516],dt.OUTSIDE_ODD_WIDEST=[8,6,4,3,1],dt.INSIDE_ODD_WIDEST=[2,4,6,8],dt.FINDER_PATTERNS=[Int32Array.from([3,8,2,1]),Int32Array.from([3,5,5,1]),Int32Array.from([3,3,7,1]),Int32Array.from([3,1,9,1]),Int32Array.from([2,7,4,1]),Int32Array.from([2,5,6,1]),Int32Array.from([2,3,8,1]),Int32Array.from([1,5,7,1]),Int32Array.from([1,3,9,1])];class ft extends Te{constructor(e,t){super(),this.readers=[],this.verbose=t===!0;let n=e?e.get(b.POSSIBLE_FORMATS):null,r=e&&e.get(b.ASSUME_CODE_39_CHECK_DIGIT)!==void 0;n?((n.includes(B.EAN_13)||n.includes(B.UPC_A)||n.includes(B.EAN_8)||n.includes(B.UPC_E))&&this.readers.push(new Le(e)),n.includes(B.CODE_39)&&this.readers.push(new Ee(r)),n.includes(B.CODE_128)&&this.readers.push(new H),n.includes(B.ITF)&&this.readers.push(new De),n.includes(B.RSS_14)&&this.readers.push(new dt),n.includes(B.RSS_EXPANDED)&&this.readers.push(new U(this.verbose))):(this.readers.push(new Le(e)),this.readers.push(new Ee),this.readers.push(new Le(e)),this.readers.push(new H),this.readers.push(new De),this.readers.push(new dt),this.readers.push(new U(this.verbose)))}decodeRow(e,t,n){for(let r=0;r<this.readers.length;r++)try{return this.readers[r].decodeRow(e,t,n)}catch{}throw new k}reset(){this.readers.forEach(e=>e.reset())}}class pt extends L{constructor(e=500,t){super(new ft(t),e,t)}}class mt{constructor(e,t,n){this.ecCodewords=e,this.ecBlocks=[t],n&&this.ecBlocks.push(n)}getECCodewords(){return this.ecCodewords}getECBlocks(){return this.ecBlocks}}class ht{constructor(e,t){this.count=e,this.dataCodewords=t}getCount(){return this.count}getDataCodewords(){return this.dataCodewords}}class gt{constructor(e,t,n,r,i,a){this.versionNumber=e,this.symbolSizeRows=t,this.symbolSizeColumns=n,this.dataRegionSizeRows=r,this.dataRegionSizeColumns=i,this.ecBlocks=a;let o=0,s=a.getECCodewords(),c=a.getECBlocks();for(let e of c)o+=e.getCount()*(e.getDataCodewords()+s);this.totalCodewords=o}getVersionNumber(){return this.versionNumber}getSymbolSizeRows(){return this.symbolSizeRows}getSymbolSizeColumns(){return this.symbolSizeColumns}getDataRegionSizeRows(){return this.dataRegionSizeRows}getDataRegionSizeColumns(){return this.dataRegionSizeColumns}getTotalCodewords(){return this.totalCodewords}getECBlocks(){return this.ecBlocks}static getVersionForDimensions(e,t){if(e&1||t&1)throw new x;for(let n of gt.VERSIONS)if(n.symbolSizeRows===e&&n.symbolSizeColumns===t)return n;throw new x}toString(){return``+this.versionNumber}static buildVersions(){return[new gt(1,10,10,8,8,new mt(5,new ht(1,3))),new gt(2,12,12,10,10,new mt(7,new ht(1,5))),new gt(3,14,14,12,12,new mt(10,new ht(1,8))),new gt(4,16,16,14,14,new mt(12,new ht(1,12))),new gt(5,18,18,16,16,new mt(14,new ht(1,18))),new gt(6,20,20,18,18,new mt(18,new ht(1,22))),new gt(7,22,22,20,20,new mt(20,new ht(1,30))),new gt(8,24,24,22,22,new mt(24,new ht(1,36))),new gt(9,26,26,24,24,new mt(28,new ht(1,44))),new gt(10,32,32,14,14,new mt(36,new ht(1,62))),new gt(11,36,36,16,16,new mt(42,new ht(1,86))),new gt(12,40,40,18,18,new mt(48,new ht(1,114))),new gt(13,44,44,20,20,new mt(56,new ht(1,144))),new gt(14,48,48,22,22,new mt(68,new ht(1,174))),new gt(15,52,52,24,24,new mt(42,new ht(2,102))),new gt(16,64,64,14,14,new mt(56,new ht(2,140))),new gt(17,72,72,16,16,new mt(36,new ht(4,92))),new gt(18,80,80,18,18,new mt(48,new ht(4,114))),new gt(19,88,88,20,20,new mt(56,new ht(4,144))),new gt(20,96,96,22,22,new mt(68,new ht(4,174))),new gt(21,104,104,24,24,new mt(56,new ht(6,136))),new gt(22,120,120,18,18,new mt(68,new ht(6,175))),new gt(23,132,132,20,20,new mt(62,new ht(8,163))),new gt(24,144,144,22,22,new mt(62,new ht(8,156),new ht(2,155))),new gt(25,8,18,6,16,new mt(7,new ht(1,5))),new gt(26,8,32,6,14,new mt(11,new ht(1,10))),new gt(27,12,26,10,24,new mt(14,new ht(1,16))),new gt(28,12,36,10,16,new mt(18,new ht(1,22))),new gt(29,16,36,14,16,new mt(24,new ht(1,32))),new gt(30,16,48,14,22,new mt(28,new ht(1,49)))]}}gt.VERSIONS=gt.buildVersions();class _t{constructor(e){let t=e.getHeight();if(t<8||t>144||t&1)throw new x;this.version=_t.readVersion(e),this.mappingBitMatrix=this.extractDataRegion(e),this.readMappingMatrix=new O(this.mappingBitMatrix.getWidth(),this.mappingBitMatrix.getHeight())}getVersion(){return this.version}static readVersion(e){let t=e.getHeight(),n=e.getWidth();return gt.getVersionForDimensions(t,n)}readCodewords(){let e=new Int8Array(this.version.getTotalCodewords()),t=0,n=4,r=0,i=this.mappingBitMatrix.getHeight(),a=this.mappingBitMatrix.getWidth(),o=!1,s=!1,c=!1,l=!1;do if(n===i&&r===0&&!o)e[t++]=this.readCorner1(i,a)&255,n-=2,r+=2,o=!0;else if(n===i-2&&r===0&&a&3&&!s)e[t++]=this.readCorner2(i,a)&255,n-=2,r+=2,s=!0;else if(n===i+4&&r===2&&!(a&7)&&!c)e[t++]=this.readCorner3(i,a)&255,n-=2,r+=2,c=!0;else if(n===i-2&&r===0&&(a&7)==4&&!l)e[t++]=this.readCorner4(i,a)&255,n-=2,r+=2,l=!0;else{do n<i&&r>=0&&!this.readMappingMatrix.get(r,n)&&(e[t++]=this.readUtah(n,r,i,a)&255),n-=2,r+=2;while(n>=0&&r<a);n+=1,r+=3;do n>=0&&r<a&&!this.readMappingMatrix.get(r,n)&&(e[t++]=this.readUtah(n,r,i,a)&255),n+=2,r-=2;while(n<i&&r>=0);n+=3,r+=1}while(n<i||r<a);if(t!==this.version.getTotalCodewords())throw new x;return e}readModule(e,t,n,r){return e<0&&(e+=n,t+=4-(n+4&7)),t<0&&(t+=r,e+=4-(r+4&7)),this.readMappingMatrix.set(t,e),this.mappingBitMatrix.get(t,e)}readUtah(e,t,n,r){let i=0;return this.readModule(e-2,t-2,n,r)&&(i|=1),i<<=1,this.readModule(e-2,t-1,n,r)&&(i|=1),i<<=1,this.readModule(e-1,t-2,n,r)&&(i|=1),i<<=1,this.readModule(e-1,t-1,n,r)&&(i|=1),i<<=1,this.readModule(e-1,t,n,r)&&(i|=1),i<<=1,this.readModule(e,t-2,n,r)&&(i|=1),i<<=1,this.readModule(e,t-1,n,r)&&(i|=1),i<<=1,this.readModule(e,t,n,r)&&(i|=1),i}readCorner1(e,t){let n=0;return this.readModule(e-1,0,e,t)&&(n|=1),n<<=1,this.readModule(e-1,1,e,t)&&(n|=1),n<<=1,this.readModule(e-1,2,e,t)&&(n|=1),n<<=1,this.readModule(0,t-2,e,t)&&(n|=1),n<<=1,this.readModule(0,t-1,e,t)&&(n|=1),n<<=1,this.readModule(1,t-1,e,t)&&(n|=1),n<<=1,this.readModule(2,t-1,e,t)&&(n|=1),n<<=1,this.readModule(3,t-1,e,t)&&(n|=1),n}readCorner2(e,t){let n=0;return this.readModule(e-3,0,e,t)&&(n|=1),n<<=1,this.readModule(e-2,0,e,t)&&(n|=1),n<<=1,this.readModule(e-1,0,e,t)&&(n|=1),n<<=1,this.readModule(0,t-4,e,t)&&(n|=1),n<<=1,this.readModule(0,t-3,e,t)&&(n|=1),n<<=1,this.readModule(0,t-2,e,t)&&(n|=1),n<<=1,this.readModule(0,t-1,e,t)&&(n|=1),n<<=1,this.readModule(1,t-1,e,t)&&(n|=1),n}readCorner3(e,t){let n=0;return this.readModule(e-1,0,e,t)&&(n|=1),n<<=1,this.readModule(e-1,t-1,e,t)&&(n|=1),n<<=1,this.readModule(0,t-3,e,t)&&(n|=1),n<<=1,this.readModule(0,t-2,e,t)&&(n|=1),n<<=1,this.readModule(0,t-1,e,t)&&(n|=1),n<<=1,this.readModule(1,t-3,e,t)&&(n|=1),n<<=1,this.readModule(1,t-2,e,t)&&(n|=1),n<<=1,this.readModule(1,t-1,e,t)&&(n|=1),n}readCorner4(e,t){let n=0;return this.readModule(e-3,0,e,t)&&(n|=1),n<<=1,this.readModule(e-2,0,e,t)&&(n|=1),n<<=1,this.readModule(e-1,0,e,t)&&(n|=1),n<<=1,this.readModule(0,t-2,e,t)&&(n|=1),n<<=1,this.readModule(0,t-1,e,t)&&(n|=1),n<<=1,this.readModule(1,t-1,e,t)&&(n|=1),n<<=1,this.readModule(2,t-1,e,t)&&(n|=1),n<<=1,this.readModule(3,t-1,e,t)&&(n|=1),n}extractDataRegion(e){let t=this.version.getSymbolSizeRows(),n=this.version.getSymbolSizeColumns();if(e.getHeight()!==t)throw new l(`Dimension of bitMatrix must match the version size`);let r=this.version.getDataRegionSizeRows(),i=this.version.getDataRegionSizeColumns(),a=t/r|0,o=n/i|0,s=a*r,c=new O(o*i,s);for(let t=0;t<a;++t){let n=t*r;for(let a=0;a<o;++a){let o=a*i;for(let s=0;s<r;++s){let l=t*(r+2)+1+s,u=n+s;for(let t=0;t<i;++t){let n=a*(i+2)+1+t;if(e.get(n,l)){let e=o+t;c.set(e,u)}}}}}return c}}class vt{constructor(e,t){this.numDataCodewords=e,this.codewords=t}static getDataBlocks(e,t){let n=t.getECBlocks(),r=0,i=n.getECBlocks();for(let e of i)r+=e.getCount();let a=Array(r),o=0;for(let e of i)for(let t=0;t<e.getCount();t++){let t=e.getDataCodewords(),r=n.getECCodewords()+t;a[o++]=new vt(t,new Uint8Array(r))}let s=a[0].codewords.length-n.getECCodewords(),c=s-1,u=0;for(let t=0;t<c;t++)for(let n=0;n<o;n++)a[n].codewords[t]=e[u++];let d=t.getVersionNumber()===24,f=d?8:o;for(let t=0;t<f;t++)a[t].codewords[s-1]=e[u++];let p=a[0].codewords.length;for(let t=s;t<p;t++)for(let n=0;n<o;n++){let r=d?(n+8)%o:n,i=d&&r>7?t-1:t;a[r].codewords[i]=e[u++]}if(u!==e.length)throw new l;return a}getNumDataCodewords(){return this.numDataCodewords}getCodewords(){return this.codewords}}class yt{constructor(e){this.bytes=e,this.byteOffset=0,this.bitOffset=0}getBitOffset(){return this.bitOffset}getByteOffset(){return this.byteOffset}readBits(e){if(e<1||e>32||e>this.available())throw new l(``+e);let t=0,n=this.bitOffset,r=this.byteOffset,i=this.bytes;if(n>0){let a=8-n,o=e<a?e:a,s=a-o,c=255>>8-o<<s;t=(i[r]&c)>>s,e-=o,n+=o,n===8&&(n=0,r++)}if(e>0){for(;e>=8;)t=t<<8|i[r]&255,r++,e-=8;if(e>0){let a=8-e,o=255>>a<<a;t=t<<e|(i[r]&o)>>a,n+=e}}return this.bitOffset=n,this.byteOffset=r,t}available(){return 8*(this.bytes.length-this.byteOffset)-this.bitOffset}}var bt;(function(e){e[e.PAD_ENCODE=0]=`PAD_ENCODE`,e[e.ASCII_ENCODE=1]=`ASCII_ENCODE`,e[e.C40_ENCODE=2]=`C40_ENCODE`,e[e.TEXT_ENCODE=3]=`TEXT_ENCODE`,e[e.ANSIX12_ENCODE=4]=`ANSIX12_ENCODE`,e[e.EDIFACT_ENCODE=5]=`EDIFACT_ENCODE`,e[e.BASE256_ENCODE=6]=`BASE256_ENCODE`})(bt||={});class xt{static decode(e){let t=new yt(e),n=new D,r=new D,i=[],a=bt.ASCII_ENCODE;do if(a===bt.ASCII_ENCODE)a=this.decodeAsciiSegment(t,n,r);else{switch(a){case bt.C40_ENCODE:this.decodeC40Segment(t,n);break;case bt.TEXT_ENCODE:this.decodeTextSegment(t,n);break;case bt.ANSIX12_ENCODE:this.decodeAnsiX12Segment(t,n);break;case bt.EDIFACT_ENCODE:this.decodeEdifactSegment(t,n);break;case bt.BASE256_ENCODE:this.decodeBase256Segment(t,n,i);break;default:throw new x}a=bt.ASCII_ENCODE}while(a!==bt.PAD_ENCODE&&t.available()>0);return r.length()>0&&n.append(r.toString()),new ne(e,n.toString(),i.length===0?null:i,null)}static decodeAsciiSegment(e,t,n){let r=!1;do{let i=e.readBits(8);if(i===0)throw new x;if(i<=128)return r&&(i+=128),t.append(String.fromCharCode(i-1)),bt.ASCII_ENCODE;if(i===129)return bt.PAD_ENCODE;if(i<=229){let e=i-130;e<10&&t.append(`0`),t.append(``+e)}else switch(i){case 230:return bt.C40_ENCODE;case 231:return bt.BASE256_ENCODE;case 232:t.append(``);break;case 233:case 234:break;case 235:r=!0;break;case 236:t.append(`[)>05`),n.insert(0,``);break;case 237:t.append(`[)>06`),n.insert(0,``);break;case 238:return bt.ANSIX12_ENCODE;case 239:return bt.TEXT_ENCODE;case 240:return bt.EDIFACT_ENCODE;case 241:break;default:if(i!==254||e.available()!==0)throw new x;break}}while(e.available()>0);return bt.ASCII_ENCODE}static decodeC40Segment(e,t){let n=!1,r=[],i=0;do{if(e.available()===8)return;let a=e.readBits(8);if(a===254)return;this.parseTwoBytes(a,e.readBits(8),r);for(let e=0;e<3;e++){let a=r[e];switch(i){case 0:if(a<3)i=a+1;else if(a<this.C40_BASIC_SET_CHARS.length){let e=this.C40_BASIC_SET_CHARS[a];n?(t.append(String.fromCharCode(e.charCodeAt(0)+128)),n=!1):t.append(e)}else throw new x;break;case 1:n?(t.append(String.fromCharCode(a+128)),n=!1):t.append(String.fromCharCode(a)),i=0;break;case 2:if(a<this.C40_SHIFT2_SET_CHARS.length){let e=this.C40_SHIFT2_SET_CHARS[a];n?(t.append(String.fromCharCode(e.charCodeAt(0)+128)),n=!1):t.append(e)}else switch(a){case 27:t.append(``);break;case 30:n=!0;break;default:throw new x}i=0;break;case 3:n?(t.append(String.fromCharCode(a+224)),n=!1):t.append(String.fromCharCode(a+96)),i=0;break;default:throw new x}}}while(e.available()>0)}static decodeTextSegment(e,t){let n=!1,r=[],i=0;do{if(e.available()===8)return;let a=e.readBits(8);if(a===254)return;this.parseTwoBytes(a,e.readBits(8),r);for(let e=0;e<3;e++){let a=r[e];switch(i){case 0:if(a<3)i=a+1;else if(a<this.TEXT_BASIC_SET_CHARS.length){let e=this.TEXT_BASIC_SET_CHARS[a];n?(t.append(String.fromCharCode(e.charCodeAt(0)+128)),n=!1):t.append(e)}else throw new x;break;case 1:n?(t.append(String.fromCharCode(a+128)),n=!1):t.append(String.fromCharCode(a)),i=0;break;case 2:if(a<this.TEXT_SHIFT2_SET_CHARS.length){let e=this.TEXT_SHIFT2_SET_CHARS[a];n?(t.append(String.fromCharCode(e.charCodeAt(0)+128)),n=!1):t.append(e)}else switch(a){case 27:t.append(``);break;case 30:n=!0;break;default:throw new x}i=0;break;case 3:if(a<this.TEXT_SHIFT3_SET_CHARS.length){let e=this.TEXT_SHIFT3_SET_CHARS[a];n?(t.append(String.fromCharCode(e.charCodeAt(0)+128)),n=!1):t.append(e),i=0}else throw new x;break;default:throw new x}}}while(e.available()>0)}static decodeAnsiX12Segment(e,t){let n=[];do{if(e.available()===8)return;let r=e.readBits(8);if(r===254)return;this.parseTwoBytes(r,e.readBits(8),n);for(let e=0;e<3;e++){let r=n[e];switch(r){case 0:t.append(`\r`);break;case 1:t.append(`*`);break;case 2:t.append(`>`);break;case 3:t.append(` `);break;default:if(r<14)t.append(String.fromCharCode(r+44));else if(r<40)t.append(String.fromCharCode(r+51));else throw new x;break}}}while(e.available()>0)}static parseTwoBytes(e,t,n){let r=(e<<8)+t-1,i=Math.floor(r/1600);n[0]=i,r-=i*1600,i=Math.floor(r/40),n[1]=i,n[2]=r-i*40}static decodeEdifactSegment(e,t){do{if(e.available()<=16)return;for(let n=0;n<4;n++){let n=e.readBits(6);if(n===31){let t=8-e.getBitOffset();t!==8&&e.readBits(t);return}n&32||(n|=64),t.append(String.fromCharCode(n))}}while(e.available()>0)}static decodeBase256Segment(e,t,n){let r=1+e.getByteOffset(),i=this.unrandomize255State(e.readBits(8),r++),a;if(a=i===0?e.available()/8|0:i<250?i:250*(i-249)+this.unrandomize255State(e.readBits(8),r++),a<0)throw new x;let o=new Uint8Array(a);for(let t=0;t<a;t++){if(e.available()<8)throw new x;o[t]=this.unrandomize255State(e.readBits(8),r++)}n.push(o);try{t.append(T.decode(o,E.ISO88591))}catch(e){throw new ce(`Platform does not support required encoding: `+e.message)}}static unrandomize255State(e,t){let n=e-(149*t%255+1);return n>=0?n:n+256}}xt.C40_BASIC_SET_CHARS=`*** 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ`.split(``),xt.C40_SHIFT2_SET_CHARS=`!"#$%&'()*+,-./:;<=>?@[\\]^_`.split(``),xt.TEXT_BASIC_SET_CHARS=`*** 0123456789abcdefghijklmnopqrstuvwxyz`.split(``),xt.TEXT_SHIFT2_SET_CHARS=xt.C40_SHIFT2_SET_CHARS,xt.TEXT_SHIFT3_SET_CHARS="`ABCDEFGHIJKLMNOPQRSTUVWXYZ{|}~".split(``);class St{constructor(){this.rsDecoder=new le(oe.DATA_MATRIX_FIELD_256)}decode(e){let t=new _t(e),n=t.getVersion(),r=t.readCodewords(),i=vt.getDataBlocks(r,n),a=0;for(let e of i)a+=e.getNumDataCodewords();let o=new Uint8Array(a),s=i.length;for(let e=0;e<s;e++){let t=i[e],n=t.getCodewords(),r=t.getNumDataCodewords();this.correctErrors(n,r);for(let t=0;t<r;t++)o[t*s+e]=n[t]}return xt.decode(o)}correctErrors(e,t){let n=new Int32Array(e);try{this.rsDecoder.decode(n,e.length-t)}catch{throw new d}for(let r=0;r<t;r++)e[r]=n[r]}}class Ct{constructor(e){this.image=e,this.rectangleDetector=new ge(this.image)}detect(){let e=this.rectangleDetector.detect(),t=this.detectSolid1(e);if(t=this.detectSolid2(t),t[3]=this.correctTopRight(t),!t[3])throw new k;t=this.shiftToModuleCenter(t);let n=t[0],r=t[1],i=t[2],a=t[3],o=this.transitionsBetween(n,a)+1,s=this.transitionsBetween(i,a)+1;return(o&1)==1&&(o+=1),(s&1)==1&&(s+=1),4*o<7*s&&4*s<7*o&&(o=s=Math.max(o,s)),new me(Ct.sampleGrid(this.image,n,r,i,a,o,s),[n,r,i,a])}static shiftPoint(e,t,n){let r=(t.getX()-e.getX())/(n+1),i=(t.getY()-e.getY())/(n+1);return new V(e.getX()+r,e.getY()+i)}static moveAway(e,t,n){let r=e.getX(),i=e.getY();return r<t?--r:r+=1,i<n?--i:i+=1,new V(r,i)}detectSolid1(e){let t=e[0],n=e[1],r=e[3],i=e[2],a=this.transitionsBetween(t,n),o=this.transitionsBetween(n,r),s=this.transitionsBetween(r,i),c=this.transitionsBetween(i,t),l=a,u=[i,t,n,r];return l>o&&(l=o,u[0]=t,u[1]=n,u[2]=r,u[3]=i),l>s&&(l=s,u[0]=n,u[1]=r,u[2]=i,u[3]=t),l>c&&(u[0]=r,u[1]=i,u[2]=t,u[3]=n),u}detectSolid2(e){let t=e[0],n=e[1],r=e[2],i=e[3],a=this.transitionsBetween(t,i),o=Ct.shiftPoint(n,r,(a+1)*4),s=Ct.shiftPoint(r,n,(a+1)*4);return this.transitionsBetween(o,t)<this.transitionsBetween(s,i)?(e[0]=t,e[1]=n,e[2]=r,e[3]=i):(e[0]=n,e[1]=r,e[2]=i,e[3]=t),e}correctTopRight(e){let t=e[0],n=e[1],r=e[2],i=e[3],a=this.transitionsBetween(t,i),o=this.transitionsBetween(n,i),s=Ct.shiftPoint(t,n,(o+1)*4),c=Ct.shiftPoint(r,n,(a+1)*4);a=this.transitionsBetween(s,i),o=this.transitionsBetween(c,i);let l=new V(i.getX()+(r.getX()-n.getX())/(a+1),i.getY()+(r.getY()-n.getY())/(a+1)),u=new V(i.getX()+(t.getX()-n.getX())/(o+1),i.getY()+(t.getY()-n.getY())/(o+1));return this.isValid(l)?!this.isValid(u)||this.transitionsBetween(s,l)+this.transitionsBetween(c,l)>this.transitionsBetween(s,u)+this.transitionsBetween(c,u)?l:u:this.isValid(u)?u:null}shiftToModuleCenter(e){let t=e[0],n=e[1],r=e[2],i=e[3],a=this.transitionsBetween(t,i)+1,o=this.transitionsBetween(r,i)+1,s=Ct.shiftPoint(t,n,o*4),c=Ct.shiftPoint(r,n,a*4);a=this.transitionsBetween(s,i)+1,o=this.transitionsBetween(c,i)+1,(a&1)==1&&(a+=1),(o&1)==1&&(o+=1);let l=(t.getX()+n.getX()+r.getX()+i.getX())/4,u=(t.getY()+n.getY()+r.getY()+i.getY())/4;t=Ct.moveAway(t,l,u),n=Ct.moveAway(n,l,u),r=Ct.moveAway(r,l,u),i=Ct.moveAway(i,l,u);let d,f;return s=Ct.shiftPoint(t,n,o*4),s=Ct.shiftPoint(s,i,a*4),d=Ct.shiftPoint(n,t,o*4),d=Ct.shiftPoint(d,r,a*4),c=Ct.shiftPoint(r,i,o*4),c=Ct.shiftPoint(c,n,a*4),f=Ct.shiftPoint(i,r,o*4),f=Ct.shiftPoint(f,t,a*4),[s,d,c,f]}isValid(e){return e.getX()>=0&&e.getX()<this.image.getWidth()&&e.getY()>0&&e.getY()<this.image.getHeight()}static sampleGrid(e,t,n,r,i,a,o){return be.getInstance().sampleGrid(e,a,o,.5,.5,a-.5,.5,a-.5,o-.5,.5,o-.5,t.getX(),t.getY(),i.getX(),i.getY(),r.getX(),r.getY(),n.getX(),n.getY())}transitionsBetween(e,t){let n=Math.trunc(e.getX()),r=Math.trunc(e.getY()),i=Math.trunc(t.getX()),a=Math.trunc(t.getY()),o=Math.abs(a-r)>Math.abs(i-n);if(o){let e=n;n=r,r=e,e=i,i=a,a=e}let s=Math.abs(i-n),c=Math.abs(a-r),l=-s/2,u=r<a?1:-1,d=n<i?1:-1,f=0,p=this.image.get(o?r:n,o?n:r);for(let e=n,t=r;e!==i;e+=d){let n=this.image.get(o?t:e,o?e:t);if(n!==p&&(f++,p=n),l+=c,l>0){if(t===a)break;t+=u,l-=s}}return f}}class wt{constructor(){this.decoder=new St}decode(e,t=null){let n,r;if(t!=null&&t.has(b.PURE_BARCODE)){let t=wt.extractPureBits(e.getBlackMatrix());n=this.decoder.decode(t),r=wt.NO_POINTS}else{let t=new Ct(e.getBlackMatrix()).detect();n=this.decoder.decode(t.getBits()),r=t.getPoints()}let i=n.getRawBytes(),a=new R(n.getText(),i,8*i.length,r,B.DATA_MATRIX,p.currentTimeMillis()),o=n.getByteSegments();o!=null&&a.putMetadata(te.BYTE_SEGMENTS,o);let s=n.getECLevel();return s!=null&&a.putMetadata(te.ERROR_CORRECTION_LEVEL,s),a}reset(){}static extractPureBits(e){let t=e.getTopLeftOnBit(),n=e.getBottomRightOnBit();if(t==null||n==null)throw new k;let r=this.moduleSize(t,e),i=t[1],a=n[1],o=t[0],s=(n[0]-o+1)/r,c=(a-i+1)/r;if(s<=0||c<=0)throw new k;let l=r/2;i+=l,o+=l;let u=new O(s,c);for(let t=0;t<c;t++){let n=i+t*r;for(let i=0;i<s;i++)e.get(o+i*r,n)&&u.set(i,t)}return u}static moduleSize(e,t){let n=t.getWidth(),r=e[0],i=e[1];for(;r<n&&t.get(r,i);)r++;if(r===n)throw new k;let a=r-e[0];if(a===0)throw new k;return a}}wt.NO_POINTS=[];class Tt extends L{constructor(e=500){super(new wt,e)}}var Et;(function(e){e[e.L=0]=`L`,e[e.M=1]=`M`,e[e.Q=2]=`Q`,e[e.H=3]=`H`})(Et||={});class Dt{constructor(e,t,n){this.value=e,this.stringValue=t,this.bits=n,Dt.FOR_BITS.set(n,this),Dt.FOR_VALUE.set(e,this)}getValue(){return this.value}getBits(){return this.bits}static fromString(e){switch(e){case`L`:return Dt.L;case`M`:return Dt.M;case`Q`:return Dt.Q;case`H`:return Dt.H;default:throw new c(e+`not available`)}}toString(){return this.stringValue}equals(e){if(!(e instanceof Dt))return!1;let t=e;return this.value===t.value}static forBits(e){if(e<0||e>=Dt.FOR_BITS.size)throw new l;return Dt.FOR_BITS.get(e)}}Dt.FOR_BITS=new Map,Dt.FOR_VALUE=new Map,Dt.L=new Dt(Et.L,`L`,1),Dt.M=new Dt(Et.M,`M`,0),Dt.Q=new Dt(Et.Q,`Q`,3),Dt.H=new Dt(Et.H,`H`,2);class Ot{constructor(e){this.errorCorrectionLevel=Dt.forBits(e>>3&3),this.dataMask=e&7}static numBitsDiffering(e,t){return _.bitCount(e^t)}static decodeFormatInformation(e,t){let n=Ot.doDecodeFormatInformation(e,t);return n===null?Ot.doDecodeFormatInformation(e^Ot.FORMAT_INFO_MASK_QR,t^Ot.FORMAT_INFO_MASK_QR):n}static doDecodeFormatInformation(e,t){let n=2**53-1,r=0;for(let i of Ot.FORMAT_INFO_DECODE_LOOKUP){let a=i[0];if(a===e||a===t)return new Ot(i[1]);let o=Ot.numBitsDiffering(e,a);o<n&&(r=i[1],n=o),e!==t&&(o=Ot.numBitsDiffering(t,a),o<n&&(r=i[1],n=o))}return n<=3?new Ot(r):null}getErrorCorrectionLevel(){return this.errorCorrectionLevel}getDataMask(){return this.dataMask}hashCode(){return this.errorCorrectionLevel.getBits()<<3|this.dataMask}equals(e){if(!(e instanceof Ot))return!1;let t=e;return this.errorCorrectionLevel===t.errorCorrectionLevel&&this.dataMask===t.dataMask}}Ot.FORMAT_INFO_MASK_QR=21522,Ot.FORMAT_INFO_DECODE_LOOKUP=[Int32Array.from([21522,0]),Int32Array.from([20773,1]),Int32Array.from([24188,2]),Int32Array.from([23371,3]),Int32Array.from([17913,4]),Int32Array.from([16590,5]),Int32Array.from([20375,6]),Int32Array.from([19104,7]),Int32Array.from([30660,8]),Int32Array.from([29427,9]),Int32Array.from([32170,10]),Int32Array.from([30877,11]),Int32Array.from([26159,12]),Int32Array.from([25368,13]),Int32Array.from([27713,14]),Int32Array.from([26998,15]),Int32Array.from([5769,16]),Int32Array.from([5054,17]),Int32Array.from([7399,18]),Int32Array.from([6608,19]),Int32Array.from([1890,20]),Int32Array.from([597,21]),Int32Array.from([3340,22]),Int32Array.from([2107,23]),Int32Array.from([13663,24]),Int32Array.from([12392,25]),Int32Array.from([16177,26]),Int32Array.from([14854,27]),Int32Array.from([9396,28]),Int32Array.from([8579,29]),Int32Array.from([11994,30]),Int32Array.from([11245,31])];class W{constructor(e,...t){this.ecCodewordsPerBlock=e,this.ecBlocks=t}getECCodewordsPerBlock(){return this.ecCodewordsPerBlock}getNumBlocks(){let e=0,t=this.ecBlocks;for(let n of t)e+=n.getCount();return e}getTotalECCodewords(){return this.ecCodewordsPerBlock*this.getNumBlocks()}getECBlocks(){return this.ecBlocks}}class G{constructor(e,t){this.count=e,this.dataCodewords=t}getCount(){return this.count}getDataCodewords(){return this.dataCodewords}}class kt{constructor(e,t,...n){this.versionNumber=e,this.alignmentPatternCenters=t,this.ecBlocks=n;let r=0,i=n[0].getECCodewordsPerBlock(),a=n[0].getECBlocks();for(let e of a)r+=e.getCount()*(e.getDataCodewords()+i);this.totalCodewords=r}getVersionNumber(){return this.versionNumber}getAlignmentPatternCenters(){return this.alignmentPatternCenters}getTotalCodewords(){return this.totalCodewords}getDimensionForVersion(){return 17+4*this.versionNumber}getECBlocksForLevel(e){return this.ecBlocks[e.getValue()]}static getProvisionalVersionForDimension(e){if(e%4!=1)throw new x;try{return this.getVersionForNumber((e-17)/4)}catch{throw new x}}static getVersionForNumber(e){if(e<1||e>40)throw new l;return kt.VERSIONS[e-1]}static decodeVersionInformation(e){let t=2**53-1,n=0;for(let r=0;r<kt.VERSION_DECODE_INFO.length;r++){let i=kt.VERSION_DECODE_INFO[r];if(i===e)return kt.getVersionForNumber(r+7);let a=Ot.numBitsDiffering(e,i);a<t&&(n=r+7,t=a)}return t<=3?kt.getVersionForNumber(n):null}buildFunctionPattern(){let e=this.getDimensionForVersion(),t=new O(e);t.setRegion(0,0,9,9),t.setRegion(e-8,0,8,9),t.setRegion(0,e-8,9,8);let n=this.alignmentPatternCenters.length;for(let e=0;e<n;e++){let r=this.alignmentPatternCenters[e]-2;for(let i=0;i<n;i++)e===0&&(i===0||i===n-1)||e===n-1&&i===0||t.setRegion(this.alignmentPatternCenters[i]-2,r,5,5)}return t.setRegion(6,9,1,e-17),t.setRegion(9,6,e-17,1),this.versionNumber>6&&(t.setRegion(e-11,0,3,6),t.setRegion(0,e-11,6,3)),t}toString(){return``+this.versionNumber}}kt.VERSION_DECODE_INFO=Int32Array.from([31892,34236,39577,42195,48118,51042,55367,58893,63784,68472,70749,76311,79154,84390,87683,92361,96236,102084,102881,110507,110734,117786,119615,126325,127568,133589,136944,141498,145311,150283,152622,158308,161089,167017]),kt.VERSIONS=[new kt(1,new Int32Array,new W(7,new G(1,19)),new W(10,new G(1,16)),new W(13,new G(1,13)),new W(17,new G(1,9))),new kt(2,Int32Array.from([6,18]),new W(10,new G(1,34)),new W(16,new G(1,28)),new W(22,new G(1,22)),new W(28,new G(1,16))),new kt(3,Int32Array.from([6,22]),new W(15,new G(1,55)),new W(26,new G(1,44)),new W(18,new G(2,17)),new W(22,new G(2,13))),new kt(4,Int32Array.from([6,26]),new W(20,new G(1,80)),new W(18,new G(2,32)),new W(26,new G(2,24)),new W(16,new G(4,9))),new kt(5,Int32Array.from([6,30]),new W(26,new G(1,108)),new W(24,new G(2,43)),new W(18,new G(2,15),new G(2,16)),new W(22,new G(2,11),new G(2,12))),new kt(6,Int32Array.from([6,34]),new W(18,new G(2,68)),new W(16,new G(4,27)),new W(24,new G(4,19)),new W(28,new G(4,15))),new kt(7,Int32Array.from([6,22,38]),new W(20,new G(2,78)),new W(18,new G(4,31)),new W(18,new G(2,14),new G(4,15)),new W(26,new G(4,13),new G(1,14))),new kt(8,Int32Array.from([6,24,42]),new W(24,new G(2,97)),new W(22,new G(2,38),new G(2,39)),new W(22,new G(4,18),new G(2,19)),new W(26,new G(4,14),new G(2,15))),new kt(9,Int32Array.from([6,26,46]),new W(30,new G(2,116)),new W(22,new G(3,36),new G(2,37)),new W(20,new G(4,16),new G(4,17)),new W(24,new G(4,12),new G(4,13))),new kt(10,Int32Array.from([6,28,50]),new W(18,new G(2,68),new G(2,69)),new W(26,new G(4,43),new G(1,44)),new W(24,new G(6,19),new G(2,20)),new W(28,new G(6,15),new G(2,16))),new kt(11,Int32Array.from([6,30,54]),new W(20,new G(4,81)),new W(30,new G(1,50),new G(4,51)),new W(28,new G(4,22),new G(4,23)),new W(24,new G(3,12),new G(8,13))),new kt(12,Int32Array.from([6,32,58]),new W(24,new G(2,92),new G(2,93)),new W(22,new G(6,36),new G(2,37)),new W(26,new G(4,20),new G(6,21)),new W(28,new G(7,14),new G(4,15))),new kt(13,Int32Array.from([6,34,62]),new W(26,new G(4,107)),new W(22,new G(8,37),new G(1,38)),new W(24,new G(8,20),new G(4,21)),new W(22,new G(12,11),new G(4,12))),new kt(14,Int32Array.from([6,26,46,66]),new W(30,new G(3,115),new G(1,116)),new W(24,new G(4,40),new G(5,41)),new W(20,new G(11,16),new G(5,17)),new W(24,new G(11,12),new G(5,13))),new kt(15,Int32Array.from([6,26,48,70]),new W(22,new G(5,87),new G(1,88)),new W(24,new G(5,41),new G(5,42)),new W(30,new G(5,24),new G(7,25)),new W(24,new G(11,12),new G(7,13))),new kt(16,Int32Array.from([6,26,50,74]),new W(24,new G(5,98),new G(1,99)),new W(28,new G(7,45),new G(3,46)),new W(24,new G(15,19),new G(2,20)),new W(30,new G(3,15),new G(13,16))),new kt(17,Int32Array.from([6,30,54,78]),new W(28,new G(1,107),new G(5,108)),new W(28,new G(10,46),new G(1,47)),new W(28,new G(1,22),new G(15,23)),new W(28,new G(2,14),new G(17,15))),new kt(18,Int32Array.from([6,30,56,82]),new W(30,new G(5,120),new G(1,121)),new W(26,new G(9,43),new G(4,44)),new W(28,new G(17,22),new G(1,23)),new W(28,new G(2,14),new G(19,15))),new kt(19,Int32Array.from([6,30,58,86]),new W(28,new G(3,113),new G(4,114)),new W(26,new G(3,44),new G(11,45)),new W(26,new G(17,21),new G(4,22)),new W(26,new G(9,13),new G(16,14))),new kt(20,Int32Array.from([6,34,62,90]),new W(28,new G(3,107),new G(5,108)),new W(26,new G(3,41),new G(13,42)),new W(30,new G(15,24),new G(5,25)),new W(28,new G(15,15),new G(10,16))),new kt(21,Int32Array.from([6,28,50,72,94]),new W(28,new G(4,116),new G(4,117)),new W(26,new G(17,42)),new W(28,new G(17,22),new G(6,23)),new W(30,new G(19,16),new G(6,17))),new kt(22,Int32Array.from([6,26,50,74,98]),new W(28,new G(2,111),new G(7,112)),new W(28,new G(17,46)),new W(30,new G(7,24),new G(16,25)),new W(24,new G(34,13))),new kt(23,Int32Array.from([6,30,54,78,102]),new W(30,new G(4,121),new G(5,122)),new W(28,new G(4,47),new G(14,48)),new W(30,new G(11,24),new G(14,25)),new W(30,new G(16,15),new G(14,16))),new kt(24,Int32Array.from([6,28,54,80,106]),new W(30,new G(6,117),new G(4,118)),new W(28,new G(6,45),new G(14,46)),new W(30,new G(11,24),new G(16,25)),new W(30,new G(30,16),new G(2,17))),new kt(25,Int32Array.from([6,32,58,84,110]),new W(26,new G(8,106),new G(4,107)),new W(28,new G(8,47),new G(13,48)),new W(30,new G(7,24),new G(22,25)),new W(30,new G(22,15),new G(13,16))),new kt(26,Int32Array.from([6,30,58,86,114]),new W(28,new G(10,114),new G(2,115)),new W(28,new G(19,46),new G(4,47)),new W(28,new G(28,22),new G(6,23)),new W(30,new G(33,16),new G(4,17))),new kt(27,Int32Array.from([6,34,62,90,118]),new W(30,new G(8,122),new G(4,123)),new W(28,new G(22,45),new G(3,46)),new W(30,new G(8,23),new G(26,24)),new W(30,new G(12,15),new G(28,16))),new kt(28,Int32Array.from([6,26,50,74,98,122]),new W(30,new G(3,117),new G(10,118)),new W(28,new G(3,45),new G(23,46)),new W(30,new G(4,24),new G(31,25)),new W(30,new G(11,15),new G(31,16))),new kt(29,Int32Array.from([6,30,54,78,102,126]),new W(30,new G(7,116),new G(7,117)),new W(28,new G(21,45),new G(7,46)),new W(30,new G(1,23),new G(37,24)),new W(30,new G(19,15),new G(26,16))),new kt(30,Int32Array.from([6,26,52,78,104,130]),new W(30,new G(5,115),new G(10,116)),new W(28,new G(19,47),new G(10,48)),new W(30,new G(15,24),new G(25,25)),new W(30,new G(23,15),new G(25,16))),new kt(31,Int32Array.from([6,30,56,82,108,134]),new W(30,new G(13,115),new G(3,116)),new W(28,new G(2,46),new G(29,47)),new W(30,new G(42,24),new G(1,25)),new W(30,new G(23,15),new G(28,16))),new kt(32,Int32Array.from([6,34,60,86,112,138]),new W(30,new G(17,115)),new W(28,new G(10,46),new G(23,47)),new W(30,new G(10,24),new G(35,25)),new W(30,new G(19,15),new G(35,16))),new kt(33,Int32Array.from([6,30,58,86,114,142]),new W(30,new G(17,115),new G(1,116)),new W(28,new G(14,46),new G(21,47)),new W(30,new G(29,24),new G(19,25)),new W(30,new G(11,15),new G(46,16))),new kt(34,Int32Array.from([6,34,62,90,118,146]),new W(30,new G(13,115),new G(6,116)),new W(28,new G(14,46),new G(23,47)),new W(30,new G(44,24),new G(7,25)),new W(30,new G(59,16),new G(1,17))),new kt(35,Int32Array.from([6,30,54,78,102,126,150]),new W(30,new G(12,121),new G(7,122)),new W(28,new G(12,47),new G(26,48)),new W(30,new G(39,24),new G(14,25)),new W(30,new G(22,15),new G(41,16))),new kt(36,Int32Array.from([6,24,50,76,102,128,154]),new W(30,new G(6,121),new G(14,122)),new W(28,new G(6,47),new G(34,48)),new W(30,new G(46,24),new G(10,25)),new W(30,new G(2,15),new G(64,16))),new kt(37,Int32Array.from([6,28,54,80,106,132,158]),new W(30,new G(17,122),new G(4,123)),new W(28,new G(29,46),new G(14,47)),new W(30,new G(49,24),new G(10,25)),new W(30,new G(24,15),new G(46,16))),new kt(38,Int32Array.from([6,32,58,84,110,136,162]),new W(30,new G(4,122),new G(18,123)),new W(28,new G(13,46),new G(32,47)),new W(30,new G(48,24),new G(14,25)),new W(30,new G(42,15),new G(32,16))),new kt(39,Int32Array.from([6,26,54,82,110,138,166]),new W(30,new G(20,117),new G(4,118)),new W(28,new G(40,47),new G(7,48)),new W(30,new G(43,24),new G(22,25)),new W(30,new G(10,15),new G(67,16))),new kt(40,Int32Array.from([6,30,58,86,114,142,170]),new W(30,new G(19,118),new G(6,119)),new W(28,new G(18,47),new G(31,48)),new W(30,new G(34,24),new G(34,25)),new W(30,new G(20,15),new G(61,16)))];var At;(function(e){e[e.DATA_MASK_000=0]=`DATA_MASK_000`,e[e.DATA_MASK_001=1]=`DATA_MASK_001`,e[e.DATA_MASK_010=2]=`DATA_MASK_010`,e[e.DATA_MASK_011=3]=`DATA_MASK_011`,e[e.DATA_MASK_100=4]=`DATA_MASK_100`,e[e.DATA_MASK_101=5]=`DATA_MASK_101`,e[e.DATA_MASK_110=6]=`DATA_MASK_110`,e[e.DATA_MASK_111=7]=`DATA_MASK_111`})(At||={});class jt{constructor(e,t){this.value=e,this.isMasked=t}unmaskBitMatrix(e,t){for(let n=0;n<t;n++)for(let r=0;r<t;r++)this.isMasked(n,r)&&e.flip(r,n)}}jt.values=new Map([[At.DATA_MASK_000,new jt(At.DATA_MASK_000,(e,t)=>(e+t&1)==0)],[At.DATA_MASK_001,new jt(At.DATA_MASK_001,(e,t)=>(e&1)==0)],[At.DATA_MASK_010,new jt(At.DATA_MASK_010,(e,t)=>t%3==0)],[At.DATA_MASK_011,new jt(At.DATA_MASK_011,(e,t)=>(e+t)%3==0)],[At.DATA_MASK_100,new jt(At.DATA_MASK_100,(e,t)=>(Math.floor(e/2)+Math.floor(t/3)&1)==0)],[At.DATA_MASK_101,new jt(At.DATA_MASK_101,(e,t)=>e*t%6==0)],[At.DATA_MASK_110,new jt(At.DATA_MASK_110,(e,t)=>e*t%6<3)],[At.DATA_MASK_111,new jt(At.DATA_MASK_111,(e,t)=>(e+t+e*t%3&1)==0)]]);class Mt{constructor(e){let t=e.getHeight();if(t<21||(t&3)!=1)throw new x;this.bitMatrix=e}readFormatInformation(){if(this.parsedFormatInfo!==null&&this.parsedFormatInfo!==void 0)return this.parsedFormatInfo;let e=0;for(let t=0;t<6;t++)e=this.copyBit(t,8,e);e=this.copyBit(7,8,e),e=this.copyBit(8,8,e),e=this.copyBit(8,7,e);for(let t=5;t>=0;t--)e=this.copyBit(8,t,e);let t=this.bitMatrix.getHeight(),n=0,r=t-7;for(let e=t-1;e>=r;e--)n=this.copyBit(8,e,n);for(let e=t-8;e<t;e++)n=this.copyBit(e,8,n);if(this.parsedFormatInfo=Ot.decodeFormatInformation(e,n),this.parsedFormatInfo!==null)return this.parsedFormatInfo;throw new x}readVersion(){if(this.parsedVersion!==null&&this.parsedVersion!==void 0)return this.parsedVersion;let e=this.bitMatrix.getHeight(),t=Math.floor((e-17)/4);if(t<=6)return kt.getVersionForNumber(t);let n=0,r=e-11;for(let t=5;t>=0;t--)for(let i=e-9;i>=r;i--)n=this.copyBit(i,t,n);let i=kt.decodeVersionInformation(n);if(i!==null&&i.getDimensionForVersion()===e)return this.parsedVersion=i,i;n=0;for(let t=5;t>=0;t--)for(let i=e-9;i>=r;i--)n=this.copyBit(t,i,n);if(i=kt.decodeVersionInformation(n),i!==null&&i.getDimensionForVersion()===e)return this.parsedVersion=i,i;throw new x}copyBit(e,t,n){return(this.isMirror?this.bitMatrix.get(t,e):this.bitMatrix.get(e,t))?n<<1|1:n<<1}readCodewords(){let e=this.readFormatInformation(),t=this.readVersion(),n=jt.values.get(e.getDataMask()),r=this.bitMatrix.getHeight();n.unmaskBitMatrix(this.bitMatrix,r);let i=t.buildFunctionPattern(),a=!0,o=new Uint8Array(t.getTotalCodewords()),s=0,c=0,l=0;for(let e=r-1;e>0;e-=2){e===6&&e--;for(let t=0;t<r;t++){let n=a?r-1-t:t;for(let t=0;t<2;t++)i.get(e-t,n)||(l++,c<<=1,this.bitMatrix.get(e-t,n)&&(c|=1),l===8&&(o[s++]=c,l=0,c=0))}a=!a}if(s!==t.getTotalCodewords())throw new x;return o}remask(){if(this.parsedFormatInfo===null)return;let e=jt.values[this.parsedFormatInfo.getDataMask()],t=this.bitMatrix.getHeight();e.unmaskBitMatrix(this.bitMatrix,t)}setMirror(e){this.parsedVersion=null,this.parsedFormatInfo=null,this.isMirror=e}mirror(){let e=this.bitMatrix;for(let t=0,n=e.getWidth();t<n;t++)for(let n=t+1,r=e.getHeight();n<r;n++)e.get(t,n)!==e.get(n,t)&&(e.flip(n,t),e.flip(t,n))}}class Nt{constructor(e,t){this.numDataCodewords=e,this.codewords=t}static getDataBlocks(e,t,n){if(e.length!==t.getTotalCodewords())throw new l;let r=t.getECBlocksForLevel(n),i=0,a=r.getECBlocks();for(let e of a)i+=e.getCount();let o=Array(i),s=0;for(let e of a)for(let t=0;t<e.getCount();t++){let t=e.getDataCodewords(),n=r.getECCodewordsPerBlock()+t;o[s++]=new Nt(t,new Uint8Array(n))}let c=o[0].codewords.length,u=o.length-1;for(;u>=0&&o[u].codewords.length!==c;)u--;u++;let d=c-r.getECCodewordsPerBlock(),f=0;for(let t=0;t<d;t++)for(let n=0;n<s;n++)o[n].codewords[t]=e[f++];for(let t=u;t<s;t++)o[t].codewords[d]=e[f++];let p=o[0].codewords.length;for(let t=d;t<p;t++)for(let n=0;n<s;n++){let r=n<u?t:t+1;o[n].codewords[r]=e[f++]}return o}getNumDataCodewords(){return this.numDataCodewords}getCodewords(){return this.codewords}}var Pt;(function(e){e[e.TERMINATOR=0]=`TERMINATOR`,e[e.NUMERIC=1]=`NUMERIC`,e[e.ALPHANUMERIC=2]=`ALPHANUMERIC`,e[e.STRUCTURED_APPEND=3]=`STRUCTURED_APPEND`,e[e.BYTE=4]=`BYTE`,e[e.ECI=5]=`ECI`,e[e.KANJI=6]=`KANJI`,e[e.FNC1_FIRST_POSITION=7]=`FNC1_FIRST_POSITION`,e[e.FNC1_SECOND_POSITION=8]=`FNC1_SECOND_POSITION`,e[e.HANZI=9]=`HANZI`})(Pt||={});class Ft{constructor(e,t,n,r){this.value=e,this.stringValue=t,this.characterCountBitsForVersions=n,this.bits=r,Ft.FOR_BITS.set(r,this),Ft.FOR_VALUE.set(e,this)}static forBits(e){let t=Ft.FOR_BITS.get(e);if(t===void 0)throw new l;return t}getCharacterCountBits(e){let t=e.getVersionNumber(),n;return n=t<=9?0:t<=26?1:2,this.characterCountBitsForVersions[n]}getValue(){return this.value}getBits(){return this.bits}equals(e){if(!(e instanceof Ft))return!1;let t=e;return this.value===t.value}toString(){return this.stringValue}}Ft.FOR_BITS=new Map,Ft.FOR_VALUE=new Map,Ft.TERMINATOR=new Ft(Pt.TERMINATOR,`TERMINATOR`,Int32Array.from([0,0,0]),0),Ft.NUMERIC=new Ft(Pt.NUMERIC,`NUMERIC`,Int32Array.from([10,12,14]),1),Ft.ALPHANUMERIC=new Ft(Pt.ALPHANUMERIC,`ALPHANUMERIC`,Int32Array.from([9,11,13]),2),Ft.STRUCTURED_APPEND=new Ft(Pt.STRUCTURED_APPEND,`STRUCTURED_APPEND`,Int32Array.from([0,0,0]),3),Ft.BYTE=new Ft(Pt.BYTE,`BYTE`,Int32Array.from([8,16,16]),4),Ft.ECI=new Ft(Pt.ECI,`ECI`,Int32Array.from([0,0,0]),7),Ft.KANJI=new Ft(Pt.KANJI,`KANJI`,Int32Array.from([8,10,12]),8),Ft.FNC1_FIRST_POSITION=new Ft(Pt.FNC1_FIRST_POSITION,`FNC1_FIRST_POSITION`,Int32Array.from([0,0,0]),5),Ft.FNC1_SECOND_POSITION=new Ft(Pt.FNC1_SECOND_POSITION,`FNC1_SECOND_POSITION`,Int32Array.from([0,0,0]),9),Ft.HANZI=new Ft(Pt.HANZI,`HANZI`,Int32Array.from([8,10,12]),13);class It{static decode(e,t,n,r){let i=new yt(e),a=new D,o=[],s=-1,c=-1;try{let e=null,n=!1,l;do{if(i.available()<4)l=Ft.TERMINATOR;else{let e=i.readBits(4);l=Ft.forBits(e)}switch(l){case Ft.TERMINATOR:break;case Ft.FNC1_FIRST_POSITION:case Ft.FNC1_SECOND_POSITION:n=!0;break;case Ft.STRUCTURED_APPEND:if(i.available()<16)throw new x;s=i.readBits(8),c=i.readBits(8);break;case Ft.ECI:let u=It.parseECIValue(i);if(e=C.getCharacterSetECIByValue(u),e===null)throw new x;break;case Ft.HANZI:let d=i.readBits(4),f=i.readBits(l.getCharacterCountBits(t));d===It.GB2312_SUBSET&&It.decodeHanziSegment(i,a,f);break;default:let p=i.readBits(l.getCharacterCountBits(t));switch(l){case Ft.NUMERIC:It.decodeNumericSegment(i,a,p);break;case Ft.ALPHANUMERIC:It.decodeAlphanumericSegment(i,a,p,n);break;case Ft.BYTE:It.decodeByteSegment(i,a,p,e,o,r);break;case Ft.KANJI:It.decodeKanjiSegment(i,a,p);break;default:throw new x}break}}while(l!==Ft.TERMINATOR)}catch{throw new x}return new ne(e,a.toString(),o.length===0?null:o,n===null?null:n.toString(),s,c)}static decodeHanziSegment(e,t,n){if(n*13>e.available())throw new x;let r=new Uint8Array(2*n),i=0;for(;n>0;){let t=e.readBits(13),a=t/96<<8&4294967295|t%96;a<959?a+=41377:a+=42657,r[i]=a>>8&255,r[i+1]=a&255,i+=2,n--}try{t.append(T.decode(r,E.GB2312))}catch(e){throw new x(e)}}static decodeKanjiSegment(e,t,n){if(n*13>e.available())throw new x;let r=new Uint8Array(2*n),i=0;for(;n>0;){let t=e.readBits(13),a=t/192<<8&4294967295|t%192;a<7936?a+=33088:a+=49472,r[i]=a>>8,r[i+1]=a,i+=2,n--}try{t.append(T.decode(r,E.SHIFT_JIS))}catch(e){throw new x(e)}}static decodeByteSegment(e,t,n,r,i,a){if(8*n>e.available())throw new x;let o=new Uint8Array(n);for(let t=0;t<n;t++)o[t]=e.readBits(8);let s;s=r===null?E.guessEncoding(o,a):r.getName();try{t.append(T.decode(o,s))}catch(e){throw new x(e)}i.push(o)}static toAlphaNumericChar(e){if(e>=It.ALPHANUMERIC_CHARS.length)throw new x;return It.ALPHANUMERIC_CHARS[e]}static decodeAlphanumericSegment(e,t,n,r){let i=t.length();for(;n>1;){if(e.available()<11)throw new x;let r=e.readBits(11);t.append(It.toAlphaNumericChar(Math.floor(r/45))),t.append(It.toAlphaNumericChar(r%45)),n-=2}if(n===1){if(e.available()<6)throw new x;t.append(It.toAlphaNumericChar(e.readBits(6)))}if(r)for(let e=i;e<t.length();e++)t.charAt(e)===`%`&&(e<t.length()-1&&t.charAt(e+1)===`%`?t.deleteCharAt(e+1):t.setCharAt(e,``))}static decodeNumericSegment(e,t,n){for(;n>=3;){if(e.available()<10)throw new x;let r=e.readBits(10);if(r>=1e3)throw new x;t.append(It.toAlphaNumericChar(Math.floor(r/100))),t.append(It.toAlphaNumericChar(Math.floor(r/10)%10)),t.append(It.toAlphaNumericChar(r%10)),n-=3}if(n===2){if(e.available()<7)throw new x;let n=e.readBits(7);if(n>=100)throw new x;t.append(It.toAlphaNumericChar(Math.floor(n/10))),t.append(It.toAlphaNumericChar(n%10))}else if(n===1){if(e.available()<4)throw new x;let n=e.readBits(4);if(n>=10)throw new x;t.append(It.toAlphaNumericChar(n))}}static parseECIValue(e){let t=e.readBits(8);if(!(t&128))return t&127;if((t&192)==128){let n=e.readBits(8);return(t&63)<<8&4294967295|n}if((t&224)==192){let n=e.readBits(16);return(t&31)<<16&4294967295|n}throw new x}}It.ALPHANUMERIC_CHARS=`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:`,It.GB2312_SUBSET=1;class Lt{constructor(e){this.mirrored=e}isMirrored(){return this.mirrored}applyMirroredCorrection(e){if(!this.mirrored||e===null||e.length<3)return;let t=e[0];e[0]=e[2],e[2]=t}}class Rt{constructor(){this.rsDecoder=new le(oe.QR_CODE_FIELD_256)}decodeBooleanArray(e,t){return this.decodeBitMatrix(O.parseFromBooleanArray(e),t)}decodeBitMatrix(e,t){let n=new Mt(e),r=null;try{return this.decodeBitMatrixParser(n,t)}catch(e){r=e}try{n.remask(),n.setMirror(!0),n.readVersion(),n.readFormatInformation(),n.mirror();let e=this.decodeBitMatrixParser(n,t);return e.setOther(new Lt(!0)),e}catch(e){throw r===null?e:r}}decodeBitMatrixParser(e,t){let n=e.readVersion(),r=e.readFormatInformation().getErrorCorrectionLevel(),i=e.readCodewords(),a=Nt.getDataBlocks(i,n,r),o=0;for(let e of a)o+=e.getNumDataCodewords();let s=new Uint8Array(o),c=0;for(let e of a){let t=e.getCodewords(),n=e.getNumDataCodewords();this.correctErrors(t,n);for(let e=0;e<n;e++)s[c++]=t[e]}return It.decode(s,n,r,t)}correctErrors(e,t){let n=new Int32Array(e);try{this.rsDecoder.decode(n,e.length-t)}catch{throw new d}for(let r=0;r<t;r++)e[r]=n[r]}}class zt extends V{constructor(e,t,n){super(e,t),this.estimatedModuleSize=n}aboutEquals(e,t,n){if(Math.abs(t-this.getY())<=e&&Math.abs(n-this.getX())<=e){let t=Math.abs(e-this.estimatedModuleSize);return t<=1||t<=this.estimatedModuleSize}return!1}combineEstimate(e,t,n){return new zt((this.getX()+t)/2,(this.getY()+e)/2,(this.estimatedModuleSize+n)/2)}}class Bt{constructor(e,t,n,r,i,a,o){this.image=e,this.startX=t,this.startY=n,this.width=r,this.height=i,this.moduleSize=a,this.resultPointCallback=o,this.possibleCenters=[],this.crossCheckStateCount=new Int32Array(3)}find(){let e=this.startX,t=this.height,n=e+this.width,r=this.startY+t/2,i=new Int32Array(3),a=this.image;for(let o=0;o<t;o++){let t=r+(o&1?-Math.floor((o+1)/2):Math.floor((o+1)/2));i[0]=0,i[1]=0,i[2]=0;let s=e;for(;s<n&&!a.get(s,t);)s++;let c=0;for(;s<n;){if(a.get(s,t))if(c===1)i[1]++;else if(c===2){if(this.foundPatternCross(i)){let e=this.handlePossibleCenter(i,t,s);if(e!==null)return e}i[0]=i[2],i[1]=1,i[2]=0,c=1}else i[++c]++;else c===1&&c++,i[c]++;s++}if(this.foundPatternCross(i)){let e=this.handlePossibleCenter(i,t,n);if(e!==null)return e}}if(this.possibleCenters.length!==0)return this.possibleCenters[0];throw new k}static centerFromEnd(e,t){return t-e[2]-e[1]/2}foundPatternCross(e){let t=this.moduleSize,n=t/2;for(let r=0;r<3;r++)if(Math.abs(t-e[r])>=n)return!1;return!0}crossCheckVertical(e,t,n,r){let i=this.image,a=i.getHeight(),o=this.crossCheckStateCount;o[0]=0,o[1]=0,o[2]=0;let s=e;for(;s>=0&&i.get(t,s)&&o[1]<=n;)o[1]++,s--;if(s<0||o[1]>n)return NaN;for(;s>=0&&!i.get(t,s)&&o[0]<=n;)o[0]++,s--;if(o[0]>n)return NaN;for(s=e+1;s<a&&i.get(t,s)&&o[1]<=n;)o[1]++,s++;if(s===a||o[1]>n)return NaN;for(;s<a&&!i.get(t,s)&&o[2]<=n;)o[2]++,s++;if(o[2]>n)return NaN;let c=o[0]+o[1]+o[2];return 5*Math.abs(c-r)>=2*r?NaN:this.foundPatternCross(o)?Bt.centerFromEnd(o,s):NaN}handlePossibleCenter(e,t,n){let r=e[0]+e[1]+e[2],i=Bt.centerFromEnd(e,n),a=this.crossCheckVertical(t,i,2*e[1],r);if(!isNaN(a)){let t=(e[0]+e[1]+e[2])/3;for(let e of this.possibleCenters)if(e.aboutEquals(t,a,i))return e.combineEstimate(a,i,t);let n=new zt(i,a,t);this.possibleCenters.push(n),this.resultPointCallback!==null&&this.resultPointCallback!==void 0&&this.resultPointCallback.foundPossibleResultPoint(n)}return null}}class Vt extends V{constructor(e,t,n,r){super(e,t),this.estimatedModuleSize=n,this.count=r,r===void 0&&(this.count=1)}getEstimatedModuleSize(){return this.estimatedModuleSize}getCount(){return this.count}aboutEquals(e,t,n){if(Math.abs(t-this.getY())<=e&&Math.abs(n-this.getX())<=e){let t=Math.abs(e-this.estimatedModuleSize);return t<=1||t<=this.estimatedModuleSize}return!1}combineEstimate(e,t,n){let r=this.count+1;return new Vt((this.count*this.getX()+t)/r,(this.count*this.getY()+e)/r,(this.count*this.estimatedModuleSize+n)/r,r)}}class Ht{constructor(e){this.bottomLeft=e[0],this.topLeft=e[1],this.topRight=e[2]}getBottomLeft(){return this.bottomLeft}getTopLeft(){return this.topLeft}getTopRight(){return this.topRight}}class Ut{constructor(e,t){this.image=e,this.resultPointCallback=t,this.possibleCenters=[],this.crossCheckStateCount=new Int32Array(5),this.resultPointCallback=t}getImage(){return this.image}getPossibleCenters(){return this.possibleCenters}find(e){let t=e!=null&&e.get(b.TRY_HARDER)!==void 0,n=e!=null&&e.get(b.PURE_BARCODE)!==void 0,r=this.image,i=r.getHeight(),a=r.getWidth(),o=Math.floor(3*i/(4*Ut.MAX_MODULES));(o<Ut.MIN_SKIP||t)&&(o=Ut.MIN_SKIP);let s=!1,c=new Int32Array(5);for(let e=o-1;e<i&&!s;e+=o){c[0]=0,c[1]=0,c[2]=0,c[3]=0,c[4]=0;let t=0;for(let i=0;i<a;i++)if(r.get(i,e))(t&1)==1&&t++,c[t]++;else if(t&1)c[t]++;else if(t===4)if(Ut.foundPatternCross(c)){if(this.handlePossibleCenter(c,e,i,n)===!0)if(o=2,this.hasSkipped===!0)s=this.haveMultiplyConfirmedCenters();else{let t=this.findRowSkip();t>c[2]&&(e+=t-c[2]-o,i=a-1)}else{c[0]=c[2],c[1]=c[3],c[2]=c[4],c[3]=1,c[4]=0,t=3;continue}t=0,c[0]=0,c[1]=0,c[2]=0,c[3]=0,c[4]=0}else c[0]=c[2],c[1]=c[3],c[2]=c[4],c[3]=1,c[4]=0,t=3;else c[++t]++;Ut.foundPatternCross(c)&&this.handlePossibleCenter(c,e,a,n)===!0&&(o=c[0],this.hasSkipped&&(s=this.haveMultiplyConfirmedCenters()))}let l=this.selectBestPatterns();return V.orderBestPatterns(l),new Ht(l)}static centerFromEnd(e,t){return t-e[4]-e[3]-e[2]/2}static foundPatternCross(e){let t=0;for(let n=0;n<5;n++){let r=e[n];if(r===0)return!1;t+=r}if(t<7)return!1;let n=t/7,r=n/2;return Math.abs(n-e[0])<r&&Math.abs(n-e[1])<r&&Math.abs(3*n-e[2])<3*r&&Math.abs(n-e[3])<r&&Math.abs(n-e[4])<r}getCrossCheckStateCount(){let e=this.crossCheckStateCount;return e[0]=0,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e}crossCheckDiagonal(e,t,n,r){let i=this.getCrossCheckStateCount(),a=0,o=this.image;for(;e>=a&&t>=a&&o.get(t-a,e-a);)i[2]++,a++;if(e<a||t<a)return!1;for(;e>=a&&t>=a&&!o.get(t-a,e-a)&&i[1]<=n;)i[1]++,a++;if(e<a||t<a||i[1]>n)return!1;for(;e>=a&&t>=a&&o.get(t-a,e-a)&&i[0]<=n;)i[0]++,a++;if(i[0]>n)return!1;let s=o.getHeight(),c=o.getWidth();for(a=1;e+a<s&&t+a<c&&o.get(t+a,e+a);)i[2]++,a++;if(e+a>=s||t+a>=c)return!1;for(;e+a<s&&t+a<c&&!o.get(t+a,e+a)&&i[3]<n;)i[3]++,a++;if(e+a>=s||t+a>=c||i[3]>=n)return!1;for(;e+a<s&&t+a<c&&o.get(t+a,e+a)&&i[4]<n;)i[4]++,a++;if(i[4]>=n)return!1;let l=i[0]+i[1]+i[2]+i[3]+i[4];return Math.abs(l-r)<2*r&&Ut.foundPatternCross(i)}crossCheckVertical(e,t,n,r){let i=this.image,a=i.getHeight(),o=this.getCrossCheckStateCount(),s=e;for(;s>=0&&i.get(t,s);)o[2]++,s--;if(s<0)return NaN;for(;s>=0&&!i.get(t,s)&&o[1]<=n;)o[1]++,s--;if(s<0||o[1]>n)return NaN;for(;s>=0&&i.get(t,s)&&o[0]<=n;)o[0]++,s--;if(o[0]>n)return NaN;for(s=e+1;s<a&&i.get(t,s);)o[2]++,s++;if(s===a)return NaN;for(;s<a&&!i.get(t,s)&&o[3]<n;)o[3]++,s++;if(s===a||o[3]>=n)return NaN;for(;s<a&&i.get(t,s)&&o[4]<n;)o[4]++,s++;if(o[4]>=n)return NaN;let c=o[0]+o[1]+o[2]+o[3]+o[4];return 5*Math.abs(c-r)>=2*r?NaN:Ut.foundPatternCross(o)?Ut.centerFromEnd(o,s):NaN}crossCheckHorizontal(e,t,n,r){let i=this.image,a=i.getWidth(),o=this.getCrossCheckStateCount(),s=e;for(;s>=0&&i.get(s,t);)o[2]++,s--;if(s<0)return NaN;for(;s>=0&&!i.get(s,t)&&o[1]<=n;)o[1]++,s--;if(s<0||o[1]>n)return NaN;for(;s>=0&&i.get(s,t)&&o[0]<=n;)o[0]++,s--;if(o[0]>n)return NaN;for(s=e+1;s<a&&i.get(s,t);)o[2]++,s++;if(s===a)return NaN;for(;s<a&&!i.get(s,t)&&o[3]<n;)o[3]++,s++;if(s===a||o[3]>=n)return NaN;for(;s<a&&i.get(s,t)&&o[4]<n;)o[4]++,s++;if(o[4]>=n)return NaN;let c=o[0]+o[1]+o[2]+o[3]+o[4];return 5*Math.abs(c-r)>=r?NaN:Ut.foundPatternCross(o)?Ut.centerFromEnd(o,s):NaN}handlePossibleCenter(e,t,n,r){let i=e[0]+e[1]+e[2]+e[3]+e[4],a=Ut.centerFromEnd(e,n),o=this.crossCheckVertical(t,Math.floor(a),e[2],i);if(!isNaN(o)&&(a=this.crossCheckHorizontal(Math.floor(a),Math.floor(o),e[2],i),!isNaN(a)&&(!r||this.crossCheckDiagonal(Math.floor(o),Math.floor(a),e[2],i)))){let e=i/7,t=!1,n=this.possibleCenters;for(let r=0,i=n.length;r<i;r++){let i=n[r];if(i.aboutEquals(e,o,a)){n[r]=i.combineEstimate(o,a,e),t=!0;break}}if(!t){let t=new Vt(a,o,e);n.push(t),this.resultPointCallback!==null&&this.resultPointCallback!==void 0&&this.resultPointCallback.foundPossibleResultPoint(t)}return!0}return!1}findRowSkip(){if(this.possibleCenters.length<=1)return 0;let e=null;for(let t of this.possibleCenters)if(t.getCount()>=Ut.CENTER_QUORUM)if(e==null)e=t;else return this.hasSkipped=!0,Math.floor((Math.abs(e.getX()-t.getX())-Math.abs(e.getY()-t.getY()))/2);return 0}haveMultiplyConfirmedCenters(){let e=0,t=0,n=this.possibleCenters.length;for(let n of this.possibleCenters)n.getCount()>=Ut.CENTER_QUORUM&&(e++,t+=n.getEstimatedModuleSize());if(e<3)return!1;let r=t/n,i=0;for(let e of this.possibleCenters)i+=Math.abs(e.getEstimatedModuleSize()-r);return i<=.05*t}selectBestPatterns(){let e=this.possibleCenters.length;if(e<3)throw new k;let t=this.possibleCenters,n;if(e>3){let r=0,i=0;for(let e of this.possibleCenters){let t=e.getEstimatedModuleSize();r+=t,i+=t*t}n=r/e;let a=Math.sqrt(i/e-n*n);t.sort((e,t)=>{let r=Math.abs(t.getEstimatedModuleSize()-n),i=Math.abs(e.getEstimatedModuleSize()-n);return r<i?-1:+(r>i)});let o=Math.max(.2*n,a);for(let e=0;e<t.length&&t.length>3;e++){let r=t[e];Math.abs(r.getEstimatedModuleSize()-n)>o&&(t.splice(e,1),e--)}}if(t.length>3){let e=0;for(let n of t)e+=n.getEstimatedModuleSize();n=e/t.length,t.sort((e,t)=>{if(t.getCount()===e.getCount()){let r=Math.abs(t.getEstimatedModuleSize()-n),i=Math.abs(e.getEstimatedModuleSize()-n);return r<i?1:r>i?-1:0}else return t.getCount()-e.getCount()}),t.splice(3)}return[t[0],t[1],t[2]]}}Ut.CENTER_QUORUM=2,Ut.MIN_SKIP=3,Ut.MAX_MODULES=57;class Wt{constructor(e){this.image=e}getImage(){return this.image}getResultPointCallback(){return this.resultPointCallback}detect(e){this.resultPointCallback=e==null?null:e.get(b.NEED_RESULT_POINT_CALLBACK);let t=new Ut(this.image,this.resultPointCallback).find(e);return this.processFinderPatternInfo(t)}processFinderPatternInfo(e){let t=e.getTopLeft(),n=e.getTopRight(),r=e.getBottomLeft(),i=this.calculateModuleSize(t,n,r);if(i<1)throw new k(`No pattern found in proccess finder.`);let a=Wt.computeDimension(t,n,r,i),o=kt.getProvisionalVersionForDimension(a),s=o.getDimensionForVersion()-7,c=null;if(o.getAlignmentPatternCenters().length>0){let e=n.getX()-t.getX()+r.getX(),a=n.getY()-t.getY()+r.getY(),o=1-3/s,l=Math.floor(t.getX()+o*(e-t.getX())),u=Math.floor(t.getY()+o*(a-t.getY()));for(let e=4;e<=16;e<<=1)try{c=this.findAlignmentInRegion(i,l,u,e);break}catch(e){if(!(e instanceof k))throw e}}let l=Wt.createTransform(t,n,r,c,a),u=Wt.sampleGrid(this.image,l,a),d;return d=c===null?[r,t,n]:[r,t,n,c],new me(u,d)}static createTransform(e,t,n,r,i){let a=i-3.5,o,s,c,l;return r===null?(o=t.getX()-e.getX()+n.getX(),s=t.getY()-e.getY()+n.getY(),c=a,l=a):(o=r.getX(),s=r.getY(),c=a-3,l=c),ve.quadrilateralToQuadrilateral(3.5,3.5,a,3.5,c,l,3.5,a,e.getX(),e.getY(),t.getX(),t.getY(),o,s,n.getX(),n.getY())}static sampleGrid(e,t,n){return be.getInstance().sampleGridWithTransform(e,n,n,t)}static computeDimension(e,t,n,r){let i=fe.round(V.distance(e,t)/r),a=fe.round(V.distance(e,n)/r),o=Math.floor((i+a)/2)+7;switch(o&3){case 0:o++;break;case 2:o--;break;case 3:throw new k(`Dimensions could be not found.`)}return o}calculateModuleSize(e,t,n){return(this.calculateModuleSizeOneWay(e,t)+this.calculateModuleSizeOneWay(e,n))/2}calculateModuleSizeOneWay(e,t){let n=this.sizeOfBlackWhiteBlackRunBothWays(Math.floor(e.getX()),Math.floor(e.getY()),Math.floor(t.getX()),Math.floor(t.getY())),r=this.sizeOfBlackWhiteBlackRunBothWays(Math.floor(t.getX()),Math.floor(t.getY()),Math.floor(e.getX()),Math.floor(e.getY()));return isNaN(n)?r/7:isNaN(r)?n/7:(n+r)/14}sizeOfBlackWhiteBlackRunBothWays(e,t,n,r){let i=this.sizeOfBlackWhiteBlackRun(e,t,n,r),a=1,o=e-(n-e);o<0?(a=e/(e-o),o=0):o>=this.image.getWidth()&&(a=(this.image.getWidth()-1-e)/(o-e),o=this.image.getWidth()-1);let s=Math.floor(t-(r-t)*a);return a=1,s<0?(a=t/(t-s),s=0):s>=this.image.getHeight()&&(a=(this.image.getHeight()-1-t)/(s-t),s=this.image.getHeight()-1),o=Math.floor(e+(o-e)*a),i+=this.sizeOfBlackWhiteBlackRun(e,t,o,s),i-1}sizeOfBlackWhiteBlackRun(e,t,n,r){let i=Math.abs(r-t)>Math.abs(n-e);if(i){let i=e;e=t,t=i,i=n,n=r,r=i}let a=Math.abs(n-e),o=Math.abs(r-t),s=-a/2,c=e<n?1:-1,l=t<r?1:-1,u=0,d=n+c;for(let n=e,f=t;n!==d;n+=c){let c=i?f:n,d=i?n:f;if(u===1===this.image.get(c,d)){if(u===2)return fe.distance(n,f,e,t);u++}if(s+=o,s>0){if(f===r)break;f+=l,s-=a}}return u===2?fe.distance(n+c,r,e,t):NaN}findAlignmentInRegion(e,t,n,r){let i=Math.floor(r*e),a=Math.max(0,t-i),o=Math.min(this.image.getWidth()-1,t+i);if(o-a<e*3)throw new k(`Alignment top exceeds estimated module size.`);let s=Math.max(0,n-i),c=Math.min(this.image.getHeight()-1,n+i);if(c-s<e*3)throw new k(`Alignment bottom exceeds estimated module size.`);return new Bt(this.image,a,s,o-a,c-s,e,this.resultPointCallback).find()}}class Gt{constructor(){this.decoder=new Rt}getDecoder(){return this.decoder}decode(e,t){let n,r;if(t!=null&&t.get(b.PURE_BARCODE)!==void 0){let i=Gt.extractPureBits(e.getBlackMatrix());n=this.decoder.decodeBitMatrix(i,t),r=Gt.NO_POINTS}else{let i=new Wt(e.getBlackMatrix()).detect(t);n=this.decoder.decodeBitMatrix(i.getBits(),t),r=i.getPoints()}n.getOther()instanceof Lt&&n.getOther().applyMirroredCorrection(r);let i=new R(n.getText(),n.getRawBytes(),void 0,r,B.QR_CODE,void 0),a=n.getByteSegments();a!==null&&i.putMetadata(te.BYTE_SEGMENTS,a);let o=n.getECLevel();return o!==null&&i.putMetadata(te.ERROR_CORRECTION_LEVEL,o),n.hasStructuredAppend()&&(i.putMetadata(te.STRUCTURED_APPEND_SEQUENCE,n.getStructuredAppendSequenceNumber()),i.putMetadata(te.STRUCTURED_APPEND_PARITY,n.getStructuredAppendParity())),i}reset(){}static extractPureBits(e){let t=e.getTopLeftOnBit(),n=e.getBottomRightOnBit();if(t===null||n===null)throw new k;let r=this.moduleSize(t,e),i=t[1],a=n[1],o=t[0],s=n[0];if(o>=s||i>=a||a-i!==s-o&&(s=o+(a-i),s>=e.getWidth()))throw new k;let c=Math.round((s-o+1)/r),l=Math.round((a-i+1)/r);if(c<=0||l<=0||l!==c)throw new k;let u=Math.floor(r/2);i+=u,o+=u;let d=o+Math.floor((c-1)*r)-s;if(d>0){if(d>u)throw new k;o-=d}let f=i+Math.floor((l-1)*r)-a;if(f>0){if(f>u)throw new k;i-=f}let p=new O(c,l);for(let t=0;t<l;t++){let n=i+Math.floor(t*r);for(let i=0;i<c;i++)e.get(o+Math.floor(i*r),n)&&p.set(i,t)}return p}static moduleSize(e,t){let n=t.getHeight(),r=t.getWidth(),i=e[0],a=e[1],o=!0,s=0;for(;i<r&&a<n;){if(o!==t.get(i,a)){if(++s===5)break;o=!o}i++,a++}if(i===r||a===n)throw new k;return(i-e[0])/7}}Gt.NO_POINTS=[];class Kt{PDF417Common(){}static getBitCountSum(e){return fe.sum(e)}static toIntArray(e){if(e==null||!e.length)return Kt.EMPTY_INT_ARRAY;let t=new Int32Array(e.length),n=0;for(let r of e)t[n++]=r;return t}static getCodeword(e){let t=g.binarySearch(Kt.SYMBOL_TABLE,e&262143);return t<0?-1:(Kt.CODEWORD_TABLE[t]-1)%Kt.NUMBER_OF_CODEWORDS}}Kt.NUMBER_OF_CODEWORDS=929,Kt.MAX_CODEWORDS_IN_BARCODE=Kt.NUMBER_OF_CODEWORDS-1,Kt.MIN_ROWS_IN_BARCODE=3,Kt.MAX_ROWS_IN_BARCODE=90,Kt.MODULES_IN_CODEWORD=17,Kt.MODULES_IN_STOP_PATTERN=18,Kt.BARS_IN_MODULE=8,Kt.EMPTY_INT_ARRAY=new Int32Array([]),Kt.SYMBOL_TABLE=Int32Array.from([66142,66170,66206,66236,66290,66292,66350,66382,66396,66454,66470,66476,66594,66600,66614,66626,66628,66632,66640,66654,66662,66668,66682,66690,66718,66720,66748,66758,66776,66798,66802,66804,66820,66824,66832,66846,66848,66876,66880,66936,66950,66956,66968,66992,67006,67022,67036,67042,67044,67048,67062,67118,67150,67164,67214,67228,67256,67294,67322,67350,67366,67372,67398,67404,67416,67438,67474,67476,67490,67492,67496,67510,67618,67624,67650,67656,67664,67678,67686,67692,67706,67714,67716,67728,67742,67744,67772,67782,67788,67800,67822,67826,67828,67842,67848,67870,67872,67900,67904,67960,67974,67992,68016,68030,68046,68060,68066,68068,68072,68086,68104,68112,68126,68128,68156,68160,68216,68336,68358,68364,68376,68400,68414,68448,68476,68494,68508,68536,68546,68548,68552,68560,68574,68582,68588,68654,68686,68700,68706,68708,68712,68726,68750,68764,68792,68802,68804,68808,68816,68830,68838,68844,68858,68878,68892,68920,68976,68990,68994,68996,69e3,69008,69022,69024,69052,69062,69068,69080,69102,69106,69108,69142,69158,69164,69190,69208,69230,69254,69260,69272,69296,69310,69326,69340,69386,69394,69396,69410,69416,69430,69442,69444,69448,69456,69470,69478,69484,69554,69556,69666,69672,69698,69704,69712,69726,69754,69762,69764,69776,69790,69792,69820,69830,69836,69848,69870,69874,69876,69890,69918,69920,69948,69952,70008,70022,70040,70064,70078,70094,70108,70114,70116,70120,70134,70152,70174,70176,70264,70384,70412,70448,70462,70496,70524,70542,70556,70584,70594,70600,70608,70622,70630,70636,70664,70672,70686,70688,70716,70720,70776,70896,71136,71180,71192,71216,71230,71264,71292,71360,71416,71452,71480,71536,71550,71554,71556,71560,71568,71582,71584,71612,71622,71628,71640,71662,71726,71732,71758,71772,71778,71780,71784,71798,71822,71836,71864,71874,71880,71888,71902,71910,71916,71930,71950,71964,71992,72048,72062,72066,72068,72080,72094,72096,72124,72134,72140,72152,72174,72178,72180,72206,72220,72248,72304,72318,72416,72444,72456,72464,72478,72480,72508,72512,72568,72588,72600,72624,72638,72654,72668,72674,72676,72680,72694,72726,72742,72748,72774,72780,72792,72814,72838,72856,72880,72894,72910,72924,72930,72932,72936,72950,72966,72972,72984,73008,73022,73056,73084,73102,73116,73144,73156,73160,73168,73182,73190,73196,73210,73226,73234,73236,73250,73252,73256,73270,73282,73284,73296,73310,73318,73324,73346,73348,73352,73360,73374,73376,73404,73414,73420,73432,73454,73498,73518,73522,73524,73550,73564,73570,73572,73576,73590,73800,73822,73858,73860,73872,73886,73888,73916,73944,73970,73972,73992,74014,74016,74044,74048,74104,74118,74136,74160,74174,74210,74212,74216,74230,74244,74256,74270,74272,74360,74480,74502,74508,74544,74558,74592,74620,74638,74652,74680,74690,74696,74704,74726,74732,74782,74784,74812,74992,75232,75288,75326,75360,75388,75456,75512,75576,75632,75646,75650,75652,75664,75678,75680,75708,75718,75724,75736,75758,75808,75836,75840,75896,76016,76256,76736,76824,76848,76862,76896,76924,76992,77048,77296,77340,77368,77424,77438,77536,77564,77572,77576,77584,77600,77628,77632,77688,77702,77708,77720,77744,77758,77774,77788,77870,77902,77916,77922,77928,77966,77980,78008,78018,78024,78032,78046,78060,78074,78094,78136,78192,78206,78210,78212,78224,78238,78240,78268,78278,78284,78296,78322,78324,78350,78364,78448,78462,78560,78588,78600,78622,78624,78652,78656,78712,78726,78744,78768,78782,78798,78812,78818,78820,78824,78838,78862,78876,78904,78960,78974,79072,79100,79296,79352,79368,79376,79390,79392,79420,79424,79480,79600,79628,79640,79664,79678,79712,79740,79772,79800,79810,79812,79816,79824,79838,79846,79852,79894,79910,79916,79942,79948,79960,79982,79988,80006,80024,80048,80062,80078,80092,80098,80100,80104,80134,80140,80176,80190,80224,80252,80270,80284,80312,80328,80336,80350,80358,80364,80378,80390,80396,80408,80432,80446,80480,80508,80576,80632,80654,80668,80696,80752,80766,80776,80784,80798,80800,80828,80844,80856,80878,80882,80884,80914,80916,80930,80932,80936,80950,80962,80968,80976,80990,80998,81004,81026,81028,81040,81054,81056,81084,81094,81100,81112,81134,81154,81156,81160,81168,81182,81184,81212,81216,81272,81286,81292,81304,81328,81342,81358,81372,81380,81384,81398,81434,81454,81458,81460,81486,81500,81506,81508,81512,81526,81550,81564,81592,81602,81604,81608,81616,81630,81638,81644,81702,81708,81722,81734,81740,81752,81774,81778,81780,82050,82078,82080,82108,82180,82184,82192,82206,82208,82236,82240,82296,82316,82328,82352,82366,82402,82404,82408,82440,82448,82462,82464,82492,82496,82552,82672,82694,82700,82712,82736,82750,82784,82812,82830,82882,82884,82888,82896,82918,82924,82952,82960,82974,82976,83004,83008,83064,83184,83424,83468,83480,83504,83518,83552,83580,83648,83704,83740,83768,83824,83838,83842,83844,83848,83856,83872,83900,83910,83916,83928,83950,83984,84e3,84028,84032,84088,84208,84448,84928,85040,85054,85088,85116,85184,85240,85488,85560,85616,85630,85728,85756,85764,85768,85776,85790,85792,85820,85824,85880,85894,85900,85912,85936,85966,85980,86048,86080,86136,86256,86496,86976,88160,88188,88256,88312,88560,89056,89200,89214,89312,89340,89536,89592,89608,89616,89632,89664,89720,89840,89868,89880,89904,89952,89980,89998,90012,90040,90190,90204,90254,90268,90296,90306,90308,90312,90334,90382,90396,90424,90480,90494,90500,90504,90512,90526,90528,90556,90566,90572,90584,90610,90612,90638,90652,90680,90736,90750,90848,90876,90884,90888,90896,90910,90912,90940,90944,91e3,91014,91020,91032,91056,91070,91086,91100,91106,91108,91112,91126,91150,91164,91192,91248,91262,91360,91388,91584,91640,91664,91678,91680,91708,91712,91768,91888,91928,91952,91966,92e3,92028,92046,92060,92088,92098,92100,92104,92112,92126,92134,92140,92188,92216,92272,92384,92412,92608,92664,93168,93200,93214,93216,93244,93248,93304,93424,93664,93720,93744,93758,93792,93820,93888,93944,93980,94008,94064,94078,94084,94088,94096,94110,94112,94140,94150,94156,94168,94246,94252,94278,94284,94296,94318,94342,94348,94360,94384,94398,94414,94428,94440,94470,94476,94488,94512,94526,94560,94588,94606,94620,94648,94658,94660,94664,94672,94686,94694,94700,94714,94726,94732,94744,94768,94782,94816,94844,94912,94968,94990,95004,95032,95088,95102,95112,95120,95134,95136,95164,95180,95192,95214,95218,95220,95244,95256,95280,95294,95328,95356,95424,95480,95728,95758,95772,95800,95856,95870,95968,95996,96008,96016,96030,96032,96060,96064,96120,96152,96176,96190,96220,96226,96228,96232,96290,96292,96296,96310,96322,96324,96328,96336,96350,96358,96364,96386,96388,96392,96400,96414,96416,96444,96454,96460,96472,96494,96498,96500,96514,96516,96520,96528,96542,96544,96572,96576,96632,96646,96652,96664,96688,96702,96718,96732,96738,96740,96744,96758,96772,96776,96784,96798,96800,96828,96832,96888,97008,97030,97036,97048,97072,97086,97120,97148,97166,97180,97208,97220,97224,97232,97246,97254,97260,97326,97330,97332,97358,97372,97378,97380,97384,97398,97422,97436,97464,97474,97476,97480,97488,97502,97510,97516,97550,97564,97592,97648,97666,97668,97672,97680,97694,97696,97724,97734,97740,97752,97774,97830,97836,97850,97862,97868,97880,97902,97906,97908,97926,97932,97944,97968,97998,98012,98018,98020,98024,98038,98618,98674,98676,98838,98854,98874,98892,98904,98926,98930,98932,98968,99006,99042,99044,99048,99062,99166,99194,99246,99286,99350,99366,99372,99386,99398,99416,99438,99442,99444,99462,99504,99518,99534,99548,99554,99556,99560,99574,99590,99596,99608,99632,99646,99680,99708,99726,99740,99768,99778,99780,99784,99792,99806,99814,99820,99834,99858,99860,99874,99880,99894,99906,99920,99934,99962,99970,99972,99976,99984,99998,1e5,100028,100038,100044,100056,100078,100082,100084,100142,100174,100188,100246,100262,100268,100306,100308,100390,100396,100410,100422,100428,100440,100462,100466,100468,100486,100504,100528,100542,100558,100572,100578,100580,100584,100598,100620,100656,100670,100704,100732,100750,100792,100802,100808,100816,100830,100838,100844,100858,100888,100912,100926,100960,100988,101056,101112,101148,101176,101232,101246,101250,101252,101256,101264,101278,101280,101308,101318,101324,101336,101358,101362,101364,101410,101412,101416,101430,101442,101448,101456,101470,101478,101498,101506,101508,101520,101534,101536,101564,101580,101618,101620,101636,101640,101648,101662,101664,101692,101696,101752,101766,101784,101838,101858,101860,101864,101934,101938,101940,101966,101980,101986,101988,101992,102030,102044,102072,102082,102084,102088,102096,102138,102166,102182,102188,102214,102220,102232,102254,102282,102290,102292,102306,102308,102312,102326,102444,102458,102470,102476,102488,102514,102516,102534,102552,102576,102590,102606,102620,102626,102632,102646,102662,102668,102704,102718,102752,102780,102798,102812,102840,102850,102856,102864,102878,102886,102892,102906,102936,102974,103008,103036,103104,103160,103224,103280,103294,103298,103300,103312,103326,103328,103356,103366,103372,103384,103406,103410,103412,103472,103486,103520,103548,103616,103672,103920,103992,104048,104062,104160,104188,104194,104196,104200,104208,104224,104252,104256,104312,104326,104332,104344,104368,104382,104398,104412,104418,104420,104424,104482,104484,104514,104520,104528,104542,104550,104570,104578,104580,104592,104606,104608,104636,104652,104690,104692,104706,104712,104734,104736,104764,104768,104824,104838,104856,104910,104930,104932,104936,104968,104976,104990,104992,105020,105024,105080,105200,105240,105278,105312,105372,105410,105412,105416,105424,105446,105518,105524,105550,105564,105570,105572,105576,105614,105628,105656,105666,105672,105680,105702,105722,105742,105756,105784,105840,105854,105858,105860,105864,105872,105888,105932,105970,105972,106006,106022,106028,106054,106060,106072,106100,106118,106124,106136,106160,106174,106190,106210,106212,106216,106250,106258,106260,106274,106276,106280,106306,106308,106312,106320,106334,106348,106394,106414,106418,106420,106566,106572,106610,106612,106630,106636,106648,106672,106686,106722,106724,106728,106742,106758,106764,106776,106800,106814,106848,106876,106894,106908,106936,106946,106948,106952,106960,106974,106982,106988,107032,107056,107070,107104,107132,107200,107256,107292,107320,107376,107390,107394,107396,107400,107408,107422,107424,107452,107462,107468,107480,107502,107506,107508,107544,107568,107582,107616,107644,107712,107768,108016,108060,108088,108144,108158,108256,108284,108290,108292,108296,108304,108318,108320,108348,108352,108408,108422,108428,108440,108464,108478,108494,108508,108514,108516,108520,108592,108640,108668,108736,108792,109040,109536,109680,109694,109792,109820,110016,110072,110084,110088,110096,110112,110140,110144,110200,110320,110342,110348,110360,110384,110398,110432,110460,110478,110492,110520,110532,110536,110544,110558,110658,110686,110714,110722,110724,110728,110736,110750,110752,110780,110796,110834,110836,110850,110852,110856,110864,110878,110880,110908,110912,110968,110982,111e3,111054,111074,111076,111080,111108,111112,111120,111134,111136,111164,111168,111224,111344,111372,111422,111456,111516,111554,111556,111560,111568,111590,111632,111646,111648,111676,111680,111736,111856,112096,112152,112224,112252,112320,112440,112514,112516,112520,112528,112542,112544,112588,112686,112718,112732,112782,112796,112824,112834,112836,112840,112848,112870,112890,112910,112924,112952,113008,113022,113026,113028,113032,113040,113054,113056,113100,113138,113140,113166,113180,113208,113264,113278,113376,113404,113416,113424,113440,113468,113472,113560,113614,113634,113636,113640,113686,113702,113708,113734,113740,113752,113778,113780,113798,113804,113816,113840,113854,113870,113890,113892,113896,113926,113932,113944,113968,113982,114016,114044,114076,114114,114116,114120,114128,114150,114170,114194,114196,114210,114212,114216,114242,114244,114248,114256,114270,114278,114306,114308,114312,114320,114334,114336,114364,114380,114420,114458,114478,114482,114484,114510,114524,114530,114532,114536,114842,114866,114868,114970,114994,114996,115042,115044,115048,115062,115130,115226,115250,115252,115278,115292,115298,115300,115304,115318,115342,115394,115396,115400,115408,115422,115430,115436,115450,115478,115494,115514,115526,115532,115570,115572,115738,115758,115762,115764,115790,115804,115810,115812,115816,115830,115854,115868,115896,115906,115912,115920,115934,115942,115948,115962,115996,116024,116080,116094,116098,116100,116104,116112,116126,116128,116156,116166,116172,116184,116206,116210,116212,116246,116262,116268,116282,116294,116300,116312,116334,116338,116340,116358,116364,116376,116400,116414,116430,116444,116450,116452,116456,116498,116500,116514,116520,116534,116546,116548,116552,116560,116574,116582,116588,116602,116654,116694,116714,116762,116782,116786,116788,116814,116828,116834,116836,116840,116854,116878,116892,116920,116930,116936,116944,116958,116966,116972,116986,117006,117048,117104,117118,117122,117124,117136,117150,117152,117180,117190,117196,117208,117230,117234,117236,117304,117360,117374,117472,117500,117506,117508,117512,117520,117536,117564,117568,117624,117638,117644,117656,117680,117694,117710,117724,117730,117732,117736,117750,117782,117798,117804,117818,117830,117848,117874,117876,117894,117936,117950,117966,117986,117988,117992,118022,118028,118040,118064,118078,118112,118140,118172,118210,118212,118216,118224,118238,118246,118266,118306,118312,118338,118352,118366,118374,118394,118402,118404,118408,118416,118430,118432,118460,118476,118514,118516,118574,118578,118580,118606,118620,118626,118628,118632,118678,118694,118700,118730,118738,118740,118830,118834,118836,118862,118876,118882,118884,118888,118902,118926,118940,118968,118978,118980,118984,118992,119006,119014,119020,119034,119068,119096,119152,119166,119170,119172,119176,119184,119198,119200,119228,119238,119244,119256,119278,119282,119284,119324,119352,119408,119422,119520,119548,119554,119556,119560,119568,119582,119584,119612,119616,119672,119686,119692,119704,119728,119742,119758,119772,119778,119780,119784,119798,119920,119934,120032,120060,120256,120312,120324,120328,120336,120352,120384,120440,120560,120582,120588,120600,120624,120638,120672,120700,120718,120732,120760,120770,120772,120776,120784,120798,120806,120812,120870,120876,120890,120902,120908,120920,120946,120948,120966,120972,120984,121008,121022,121038,121058,121060,121064,121078,121100,121112,121136,121150,121184,121212,121244,121282,121284,121288,121296,121318,121338,121356,121368,121392,121406,121440,121468,121536,121592,121656,121730,121732,121736,121744,121758,121760,121804,121842,121844,121890,121922,121924,121928,121936,121950,121958,121978,121986,121988,121992,122e3,122014,122016,122044,122060,122098,122100,122116,122120,122128,122142,122144,122172,122176,122232,122246,122264,122318,122338,122340,122344,122414,122418,122420,122446,122460,122466,122468,122472,122510,122524,122552,122562,122564,122568,122576,122598,122618,122646,122662,122668,122694,122700,122712,122738,122740,122762,122770,122772,122786,122788,122792,123018,123026,123028,123042,123044,123048,123062,123098,123146,123154,123156,123170,123172,123176,123190,123202,123204,123208,123216,123238,123244,123258,123290,123314,123316,123402,123410,123412,123426,123428,123432,123446,123458,123464,123472,123486,123494,123500,123514,123522,123524,123528,123536,123552,123580,123590,123596,123608,123630,123634,123636,123674,123698,123700,123740,123746,123748,123752,123834,123914,123922,123924,123938,123944,123958,123970,123976,123984,123998,124006,124012,124026,124034,124036,124048,124062,124064,124092,124102,124108,124120,124142,124146,124148,124162,124164,124168,124176,124190,124192,124220,124224,124280,124294,124300,124312,124336,124350,124366,124380,124386,124388,124392,124406,124442,124462,124466,124468,124494,124508,124514,124520,124558,124572,124600,124610,124612,124616,124624,124646,124666,124694,124710,124716,124730,124742,124748,124760,124786,124788,124818,124820,124834,124836,124840,124854,124946,124948,124962,124964,124968,124982,124994,124996,125e3,125008,125022,125030,125036,125050,125058,125060,125064,125072,125086,125088,125116,125126,125132,125144,125166,125170,125172,125186,125188,125192,125200,125216,125244,125248,125304,125318,125324,125336,125360,125374,125390,125404,125410,125412,125416,125430,125444,125448,125456,125472,125504,125560,125680,125702,125708,125720,125744,125758,125792,125820,125838,125852,125880,125890,125892,125896,125904,125918,125926,125932,125978,125998,126002,126004,126030,126044,126050,126052,126056,126094,126108,126136,126146,126148,126152,126160,126182,126202,126222,126236,126264,126320,126334,126338,126340,126344,126352,126366,126368,126412,126450,126452,126486,126502,126508,126522,126534,126540,126552,126574,126578,126580,126598,126604,126616,126640,126654,126670,126684,126690,126692,126696,126738,126754,126756,126760,126774,126786,126788,126792,126800,126814,126822,126828,126842,126894,126898,126900,126934,127126,127142,127148,127162,127178,127186,127188,127254,127270,127276,127290,127302,127308,127320,127342,127346,127348,127370,127378,127380,127394,127396,127400,127450,127510,127526,127532,127546,127558,127576,127598,127602,127604,127622,127628,127640,127664,127678,127694,127708,127714,127716,127720,127734,127754,127762,127764,127778,127784,127810,127812,127816,127824,127838,127846,127866,127898,127918,127922,127924,128022,128038,128044,128058,128070,128076,128088,128110,128114,128116,128134,128140,128152,128176,128190,128206,128220,128226,128228,128232,128246,128262,128268,128280,128304,128318,128352,128380,128398,128412,128440,128450,128452,128456,128464,128478,128486,128492,128506,128522,128530,128532,128546,128548,128552,128566,128578,128580,128584,128592,128606,128614,128634,128642,128644,128648,128656,128670,128672,128700,128716,128754,128756,128794,128814,128818,128820,128846,128860,128866,128868,128872,128886,128918,128934,128940,128954,128978,128980,129178,129198,129202,129204,129238,129258,129306,129326,129330,129332,129358,129372,129378,129380,129384,129398,129430,129446,129452,129466,129482,129490,129492,129562,129582,129586,129588,129614,129628,129634,129636,129640,129654,129678,129692,129720,129730,129732,129736,129744,129758,129766,129772,129814,129830,129836,129850,129862,129868,129880,129902,129906,129908,129930,129938,129940,129954,129956,129960,129974,130010]),Kt.CODEWORD_TABLE=Int32Array.from([2627,1819,2622,2621,1813,1812,2729,2724,2723,2779,2774,2773,902,896,908,868,865,861,859,2511,873,871,1780,835,2493,825,2491,842,837,844,1764,1762,811,810,809,2483,807,2482,806,2480,815,814,813,812,2484,817,816,1745,1744,1742,1746,2655,2637,2635,2626,2625,2623,2628,1820,2752,2739,2737,2728,2727,2725,2730,2785,2783,2778,2777,2775,2780,787,781,747,739,736,2413,754,752,1719,692,689,681,2371,678,2369,700,697,694,703,1688,1686,642,638,2343,631,2341,627,2338,651,646,643,2345,654,652,1652,1650,1647,1654,601,599,2322,596,2321,594,2319,2317,611,610,608,606,2324,603,2323,615,614,612,1617,1616,1614,1612,616,1619,1618,2575,2538,2536,905,901,898,909,2509,2507,2504,870,867,864,860,2512,875,872,1781,2490,2489,2487,2485,1748,836,834,832,830,2494,827,2492,843,841,839,845,1765,1763,2701,2676,2674,2653,2648,2656,2634,2633,2631,2629,1821,2638,2636,2770,2763,2761,2750,2745,2753,2736,2735,2733,2731,1848,2740,2738,2786,2784,591,588,576,569,566,2296,1590,537,534,526,2276,522,2274,545,542,539,548,1572,1570,481,2245,466,2242,462,2239,492,485,482,2249,496,494,1534,1531,1528,1538,413,2196,406,2191,2188,425,419,2202,415,2199,432,430,427,1472,1467,1464,433,1476,1474,368,367,2160,365,2159,362,2157,2155,2152,378,377,375,2166,372,2165,369,2162,383,381,379,2168,1419,1418,1416,1414,385,1411,384,1423,1422,1420,1424,2461,802,2441,2439,790,786,783,794,2409,2406,2403,750,742,738,2414,756,753,1720,2367,2365,2362,2359,1663,693,691,684,2373,680,2370,702,699,696,704,1690,1687,2337,2336,2334,2332,1624,2329,1622,640,637,2344,634,2342,630,2340,650,648,645,2346,655,653,1653,1651,1649,1655,2612,2597,2595,2571,2568,2565,2576,2534,2529,2526,1787,2540,2537,907,904,900,910,2503,2502,2500,2498,1768,2495,1767,2510,2508,2506,869,866,863,2513,876,874,1782,2720,2713,2711,2697,2694,2691,2702,2672,2670,2664,1828,2678,2675,2647,2646,2644,2642,1823,2639,1822,2654,2652,2650,2657,2771,1855,2765,2762,1850,1849,2751,2749,2747,2754,353,2148,344,342,336,2142,332,2140,345,1375,1373,306,2130,299,2128,295,2125,319,314,311,2132,1354,1352,1349,1356,262,257,2101,253,2096,2093,274,273,267,2107,263,2104,280,278,275,1316,1311,1308,1320,1318,2052,202,2050,2044,2040,219,2063,212,2060,208,2055,224,221,2066,1260,1258,1252,231,1248,229,1266,1264,1261,1268,155,1998,153,1996,1994,1991,1988,165,164,2007,162,2006,159,2003,2e3,172,171,169,2012,166,2010,1186,1184,1182,1179,175,1176,173,1192,1191,1189,1187,176,1194,1193,2313,2307,2305,592,589,2294,2292,2289,578,572,568,2297,580,1591,2272,2267,2264,1547,538,536,529,2278,525,2275,547,544,541,1574,1571,2237,2235,2229,1493,2225,1489,478,2247,470,2244,465,2241,493,488,484,2250,498,495,1536,1533,1530,1539,2187,2186,2184,2182,1432,2179,1430,2176,1427,414,412,2197,409,2195,405,2193,2190,426,424,421,2203,418,2201,431,429,1473,1471,1469,1466,434,1477,1475,2478,2472,2470,2459,2457,2454,2462,803,2437,2432,2429,1726,2443,2440,792,789,785,2401,2399,2393,1702,2389,1699,2411,2408,2405,745,741,2415,758,755,1721,2358,2357,2355,2353,1661,2350,1660,2347,1657,2368,2366,2364,2361,1666,690,687,2374,683,2372,701,698,705,1691,1689,2619,2617,2610,2608,2605,2613,2593,2588,2585,1803,2599,2596,2563,2561,2555,1797,2551,1795,2573,2570,2567,2577,2525,2524,2522,2520,1786,2517,1785,2514,1783,2535,2533,2531,2528,1788,2541,2539,906,903,911,2721,1844,2715,2712,1838,1836,2699,2696,2693,2703,1827,1826,1824,2673,2671,2669,2666,1829,2679,2677,1858,1857,2772,1854,1853,1851,1856,2766,2764,143,1987,139,1986,135,133,131,1984,128,1983,125,1981,138,137,136,1985,1133,1132,1130,112,110,1974,107,1973,104,1971,1969,122,121,119,117,1977,114,1976,124,1115,1114,1112,1110,1117,1116,84,83,1953,81,1952,78,1950,1948,1945,94,93,91,1959,88,1958,85,1955,99,97,95,1961,1086,1085,1083,1081,1078,100,1090,1089,1087,1091,49,47,1917,44,1915,1913,1910,1907,59,1926,56,1925,53,1922,1919,66,64,1931,61,1929,1042,1040,1038,71,1035,70,1032,68,1048,1047,1045,1043,1050,1049,12,10,1869,1867,1864,1861,21,1880,19,1877,1874,1871,28,1888,25,1886,22,1883,982,980,977,974,32,30,991,989,987,984,34,995,994,992,2151,2150,2147,2146,2144,356,355,354,2149,2139,2138,2136,2134,1359,343,341,338,2143,335,2141,348,347,346,1376,1374,2124,2123,2121,2119,1326,2116,1324,310,308,305,2131,302,2129,298,2127,320,318,316,313,2133,322,321,1355,1353,1351,1357,2092,2091,2089,2087,1276,2084,1274,2081,1271,259,2102,256,2100,252,2098,2095,272,269,2108,266,2106,281,279,277,1317,1315,1313,1310,282,1321,1319,2039,2037,2035,2032,1203,2029,1200,1197,207,2053,205,2051,201,2049,2046,2043,220,218,2064,215,2062,211,2059,228,226,223,2069,1259,1257,1254,232,1251,230,1267,1265,1263,2316,2315,2312,2311,2309,2314,2304,2303,2301,2299,1593,2308,2306,590,2288,2287,2285,2283,1578,2280,1577,2295,2293,2291,579,577,574,571,2298,582,581,1592,2263,2262,2260,2258,1545,2255,1544,2252,1541,2273,2271,2269,2266,1550,535,532,2279,528,2277,546,543,549,1575,1573,2224,2222,2220,1486,2217,1485,2214,1482,1479,2238,2236,2234,2231,1496,2228,1492,480,477,2248,473,2246,469,2243,490,487,2251,497,1537,1535,1532,2477,2476,2474,2479,2469,2468,2466,2464,1730,2473,2471,2453,2452,2450,2448,1729,2445,1728,2460,2458,2456,2463,805,804,2428,2427,2425,2423,1725,2420,1724,2417,1722,2438,2436,2434,2431,1727,2444,2442,793,791,788,795,2388,2386,2384,1697,2381,1696,2378,1694,1692,2402,2400,2398,2395,1703,2392,1701,2412,2410,2407,751,748,744,2416,759,757,1807,2620,2618,1806,1805,2611,2609,2607,2614,1802,1801,1799,2594,2592,2590,2587,1804,2600,2598,1794,1793,1791,1789,2564,2562,2560,2557,1798,2554,1796,2574,2572,2569,2578,1847,1846,2722,1843,1842,1840,1845,2716,2714,1835,1834,1832,1830,1839,1837,2700,2698,2695,2704,1817,1811,1810,897,862,1777,829,826,838,1760,1758,808,2481,1741,1740,1738,1743,2624,1818,2726,2776,782,740,737,1715,686,679,695,1682,1680,639,628,2339,647,644,1645,1643,1640,1648,602,600,597,595,2320,593,2318,609,607,604,1611,1610,1608,1606,613,1615,1613,2328,926,924,892,886,899,857,850,2505,1778,824,823,821,819,2488,818,2486,833,831,828,840,1761,1759,2649,2632,2630,2746,2734,2732,2782,2781,570,567,1587,531,527,523,540,1566,1564,476,467,463,2240,486,483,1524,1521,1518,1529,411,403,2192,399,2189,423,416,1462,1457,1454,428,1468,1465,2210,366,363,2158,360,2156,357,2153,376,373,370,2163,1410,1409,1407,1405,382,1402,380,1417,1415,1412,1421,2175,2174,777,774,771,784,732,725,722,2404,743,1716,676,674,668,2363,665,2360,685,1684,1681,626,624,622,2335,620,2333,617,2330,641,635,649,1646,1644,1642,2566,928,925,2530,2527,894,891,888,2501,2499,2496,858,856,854,851,1779,2692,2668,2665,2645,2643,2640,2651,2768,2759,2757,2744,2743,2741,2748,352,1382,340,337,333,1371,1369,307,300,296,2126,315,312,1347,1342,1350,261,258,250,2097,246,2094,271,268,264,1306,1301,1298,276,1312,1309,2115,203,2048,195,2045,191,2041,213,209,2056,1246,1244,1238,225,1234,222,1256,1253,1249,1262,2080,2079,154,1997,150,1995,147,1992,1989,163,160,2004,156,2001,1175,1174,1172,1170,1167,170,1164,167,1185,1183,1180,1177,174,1190,1188,2025,2024,2022,587,586,564,559,556,2290,573,1588,520,518,512,2268,508,2265,530,1568,1565,461,457,2233,450,2230,446,2226,479,471,489,1526,1523,1520,397,395,2185,392,2183,389,2180,2177,410,2194,402,422,1463,1461,1459,1456,1470,2455,799,2433,2430,779,776,773,2397,2394,2390,734,728,724,746,1717,2356,2354,2351,2348,1658,677,675,673,670,667,688,1685,1683,2606,2589,2586,2559,2556,2552,927,2523,2521,2518,2515,1784,2532,895,893,890,2718,2709,2707,2689,2687,2684,2663,2662,2660,2658,1825,2667,2769,1852,2760,2758,142,141,1139,1138,134,132,129,126,1982,1129,1128,1126,1131,113,111,108,105,1972,101,1970,120,118,115,1109,1108,1106,1104,123,1113,1111,82,79,1951,75,1949,72,1946,92,89,86,1956,1077,1076,1074,1072,98,1069,96,1084,1082,1079,1088,1968,1967,48,45,1916,42,1914,39,1911,1908,60,57,54,1923,50,1920,1031,1030,1028,1026,67,1023,65,1020,62,1041,1039,1036,1033,69,1046,1044,1944,1943,1941,11,9,1868,7,1865,1862,1859,20,1878,16,1875,13,1872,970,968,966,963,29,960,26,23,983,981,978,975,33,971,31,990,988,985,1906,1904,1902,993,351,2145,1383,331,330,328,326,2137,323,2135,339,1372,1370,294,293,291,289,2122,286,2120,283,2117,309,303,317,1348,1346,1344,245,244,242,2090,239,2088,236,2085,2082,260,2099,249,270,1307,1305,1303,1300,1314,189,2038,186,2036,183,2033,2030,2026,206,198,2047,194,216,1247,1245,1243,1240,227,1237,1255,2310,2302,2300,2286,2284,2281,565,563,561,558,575,1589,2261,2259,2256,2253,1542,521,519,517,514,2270,511,533,1569,1567,2223,2221,2218,2215,1483,2211,1480,459,456,453,2232,449,474,491,1527,1525,1522,2475,2467,2465,2451,2449,2446,801,800,2426,2424,2421,2418,1723,2435,780,778,775,2387,2385,2382,2379,1695,2375,1693,2396,735,733,730,727,749,1718,2616,2615,2604,2603,2601,2584,2583,2581,2579,1800,2591,2550,2549,2547,2545,1792,2542,1790,2558,929,2719,1841,2710,2708,1833,1831,2690,2688,2686,1815,1809,1808,1774,1756,1754,1737,1736,1734,1739,1816,1711,1676,1674,633,629,1638,1636,1633,1641,598,1605,1604,1602,1600,605,1609,1607,2327,887,853,1775,822,820,1757,1755,1584,524,1560,1558,468,464,1514,1511,1508,1519,408,404,400,1452,1447,1444,417,1458,1455,2208,364,361,358,2154,1401,1400,1398,1396,374,1393,371,1408,1406,1403,1413,2173,2172,772,726,723,1712,672,669,666,682,1678,1675,625,623,621,618,2331,636,632,1639,1637,1635,920,918,884,880,889,849,848,847,846,2497,855,852,1776,2641,2742,2787,1380,334,1367,1365,301,297,1340,1338,1335,1343,255,251,247,1296,1291,1288,265,1302,1299,2113,204,196,192,2042,1232,1230,1224,214,1220,210,1242,1239,1235,1250,2077,2075,151,148,1993,144,1990,1163,1162,1160,1158,1155,161,1152,157,1173,1171,1168,1165,168,1181,1178,2021,2020,2018,2023,585,560,557,1585,516,509,1562,1559,458,447,2227,472,1516,1513,1510,398,396,393,390,2181,386,2178,407,1453,1451,1449,1446,420,1460,2209,769,764,720,712,2391,729,1713,664,663,661,659,2352,656,2349,671,1679,1677,2553,922,919,2519,2516,885,883,881,2685,2661,2659,2767,2756,2755,140,1137,1136,130,127,1125,1124,1122,1127,109,106,102,1103,1102,1100,1098,116,1107,1105,1980,80,76,73,1947,1068,1067,1065,1063,90,1060,87,1075,1073,1070,1080,1966,1965,46,43,40,1912,36,1909,1019,1018,1016,1014,58,1011,55,1008,51,1029,1027,1024,1021,63,1037,1034,1940,1939,1937,1942,8,1866,4,1863,1,1860,956,954,952,949,946,17,14,969,967,964,961,27,957,24,979,976,972,1901,1900,1898,1896,986,1905,1903,350,349,1381,329,327,324,1368,1366,292,290,287,284,2118,304,1341,1339,1337,1345,243,240,237,2086,233,2083,254,1297,1295,1293,1290,1304,2114,190,187,184,2034,180,2031,177,2027,199,1233,1231,1229,1226,217,1223,1241,2078,2076,584,555,554,552,550,2282,562,1586,507,506,504,502,2257,499,2254,515,1563,1561,445,443,441,2219,438,2216,435,2212,460,454,475,1517,1515,1512,2447,798,797,2422,2419,770,768,766,2383,2380,2376,721,719,717,714,731,1714,2602,2582,2580,2548,2546,2543,923,921,2717,2706,2705,2683,2682,2680,1771,1752,1750,1733,1732,1731,1735,1814,1707,1670,1668,1631,1629,1626,1634,1599,1598,1596,1594,1603,1601,2326,1772,1753,1751,1581,1554,1552,1504,1501,1498,1509,1442,1437,1434,401,1448,1445,2206,1392,1391,1389,1387,1384,359,1399,1397,1394,1404,2171,2170,1708,1672,1669,619,1632,1630,1628,1773,1378,1363,1361,1333,1328,1336,1286,1281,1278,248,1292,1289,2111,1218,1216,1210,197,1206,193,1228,1225,1221,1236,2073,2071,1151,1150,1148,1146,152,1143,149,1140,145,1161,1159,1156,1153,158,1169,1166,2017,2016,2014,2019,1582,510,1556,1553,452,448,1506,1500,394,391,387,1443,1441,1439,1436,1450,2207,765,716,713,1709,662,660,657,1673,1671,916,914,879,878,877,882,1135,1134,1121,1120,1118,1123,1097,1096,1094,1092,103,1101,1099,1979,1059,1058,1056,1054,77,1051,74,1066,1064,1061,1071,1964,1963,1007,1006,1004,1002,999,41,996,37,1017,1015,1012,1009,52,1025,1022,1936,1935,1933,1938,942,940,938,935,932,5,2,955,953,950,947,18,943,15,965,962,958,1895,1894,1892,1890,973,1899,1897,1379,325,1364,1362,288,285,1334,1332,1330,241,238,234,1287,1285,1283,1280,1294,2112,188,185,181,178,2028,1219,1217,1215,1212,200,1209,1227,2074,2072,583,553,551,1583,505,503,500,513,1557,1555,444,442,439,436,2213,455,451,1507,1505,1502,796,763,762,760,767,711,710,708,706,2377,718,715,1710,2544,917,915,2681,1627,1597,1595,2325,1769,1749,1747,1499,1438,1435,2204,1390,1388,1385,1395,2169,2167,1704,1665,1662,1625,1623,1620,1770,1329,1282,1279,2109,1214,1207,1222,2068,2065,1149,1147,1144,1141,146,1157,1154,2013,2011,2008,2015,1579,1549,1546,1495,1487,1433,1431,1428,1425,388,1440,2205,1705,658,1667,1664,1119,1095,1093,1978,1057,1055,1052,1062,1962,1960,1005,1003,1e3,997,38,1013,1010,1932,1930,1927,1934,941,939,936,933,6,930,3,951,948,944,1889,1887,1884,1881,959,1893,1891,35,1377,1360,1358,1327,1325,1322,1331,1277,1275,1272,1269,235,1284,2110,1205,1204,1201,1198,182,1195,179,1213,2070,2067,1580,501,1551,1548,440,437,1497,1494,1490,1503,761,709,707,1706,913,912,2198,1386,2164,2161,1621,1766,2103,1208,2058,2054,1145,1142,2005,2002,1999,2009,1488,1429,1426,2200,1698,1659,1656,1975,1053,1957,1954,1001,998,1924,1921,1918,1928,937,934,931,1879,1876,1873,1870,945,1885,1882,1323,1273,1270,2105,1202,1199,1196,1211,2061,2057,1576,1543,1540,1484,1481,1478,1491,1700]);class qt{constructor(e,t){this.bits=e,this.points=t}getBits(){return this.bits}getPoints(){return this.points}}class Jt{static detectMultiple(e,t,n){let r=e.getBlackMatrix(),i=Jt.detect(n,r);return i.length||(r=r.clone(),r.rotate180(),i=Jt.detect(n,r)),new qt(r,i)}static detect(e,t){let n=[],r=0,i=0,a=!1;for(;r<t.getHeight();){let o=Jt.findVertices(t,r,i);if(o[0]==null&&o[3]==null){if(!a)break;a=!1,i=0;for(let e of n)e[1]!=null&&(r=Math.trunc(Math.max(r,e[1].getY()))),e[3]!=null&&(r=Math.max(r,Math.trunc(e[3].getY())));r+=Jt.ROW_STEP;continue}if(a=!0,n.push(o),!e)break;o[2]==null?(i=Math.trunc(o[4].getX()),r=Math.trunc(o[4].getY())):(i=Math.trunc(o[2].getX()),r=Math.trunc(o[2].getY()))}return n}static findVertices(e,t,n){let r=e.getHeight(),i=e.getWidth(),a=Array(8);return Jt.copyToResult(a,Jt.findRowsWithPattern(e,r,i,t,n,Jt.START_PATTERN),Jt.INDEXES_START_PATTERN),a[4]!=null&&(n=Math.trunc(a[4].getX()),t=Math.trunc(a[4].getY())),Jt.copyToResult(a,Jt.findRowsWithPattern(e,r,i,t,n,Jt.STOP_PATTERN),Jt.INDEXES_STOP_PATTERN),a}static copyToResult(e,t,n){for(let r=0;r<n.length;r++)e[n[r]]=t[r]}static findRowsWithPattern(e,t,n,r,i,a){let o=[,,,,],s=!1,c=new Int32Array(a.length);for(;r<t;r+=Jt.ROW_STEP){let t=Jt.findGuardPattern(e,i,r,n,!1,a,c);if(t!=null){for(;r>0;){let o=Jt.findGuardPattern(e,i,--r,n,!1,a,c);if(o!=null)t=o;else{r++;break}}o[0]=new V(t[0],r),o[1]=new V(t[1],r),s=!0;break}}let l=r+1;if(s){let r=0,i=Int32Array.from([Math.trunc(o[0].getX()),Math.trunc(o[1].getX())]);for(;l<t;l++){let t=Jt.findGuardPattern(e,i[0],l,n,!1,a,c);if(t!=null&&Math.abs(i[0]-t[0])<Jt.MAX_PATTERN_DRIFT&&Math.abs(i[1]-t[1])<Jt.MAX_PATTERN_DRIFT)i=t,r=0;else if(r>Jt.SKIPPED_ROW_COUNT_MAX)break;else r++}l-=r+1,o[2]=new V(i[0],l),o[3]=new V(i[1],l)}return l-r<Jt.BARCODE_MIN_HEIGHT&&g.fill(o,null),o}static findGuardPattern(e,t,n,r,i,a,o){g.fillWithin(o,0,o.length,0);let s=t,c=0;for(;e.get(s,n)&&s>0&&c++<Jt.MAX_PIXEL_DRIFT;)s--;let l=s,u=0,d=a.length;for(let t=i;l<r;l++)if(e.get(l,n)!==t)o[u]++;else{if(u===d-1){if(Jt.patternMatchVariance(o,a,Jt.MAX_INDIVIDUAL_VARIANCE)<Jt.MAX_AVG_VARIANCE)return new Int32Array([s,l]);s+=o[0]+o[1],p.arraycopy(o,2,o,0,u-1),o[u-1]=0,o[u]=0,u--}else u++;o[u]=1,t=!t}return u===d-1&&Jt.patternMatchVariance(o,a,Jt.MAX_INDIVIDUAL_VARIANCE)<Jt.MAX_AVG_VARIANCE?new Int32Array([s,l-1]):null}static patternMatchVariance(e,t,n){let r=e.length,i=0,a=0;for(let n=0;n<r;n++)i+=e[n],a+=t[n];if(i<a)return 1/0;let o=i/a;n*=o;let s=0;for(let i=0;i<r;i++){let r=e[i],a=t[i]*o,c=r>a?r-a:a-r;if(c>n)return 1/0;s+=c}return s/i}}Jt.INDEXES_START_PATTERN=Int32Array.from([0,4,1,5]),Jt.INDEXES_STOP_PATTERN=Int32Array.from([6,2,7,3]),Jt.MAX_AVG_VARIANCE=.42,Jt.MAX_INDIVIDUAL_VARIANCE=.8,Jt.START_PATTERN=Int32Array.from([8,1,1,1,1,1,1,3]),Jt.STOP_PATTERN=Int32Array.from([7,1,1,3,1,1,1,2,1]),Jt.MAX_PIXEL_DRIFT=3,Jt.MAX_PATTERN_DRIFT=5,Jt.SKIPPED_ROW_COUNT_MAX=25,Jt.ROW_STEP=5,Jt.BARCODE_MIN_HEIGHT=10;class Yt{constructor(e,t){if(t.length===0)throw new l;this.field=e;let n=t.length;if(n>1&&t[0]===0){let e=1;for(;e<n&&t[e]===0;)e++;e===n?this.coefficients=new Int32Array([0]):(this.coefficients=new Int32Array(n-e),p.arraycopy(t,e,this.coefficients,0,this.coefficients.length))}else this.coefficients=t}getCoefficients(){return this.coefficients}getDegree(){return this.coefficients.length-1}isZero(){return this.coefficients[0]===0}getCoefficient(e){return this.coefficients[this.coefficients.length-1-e]}evaluateAt(e){if(e===0)return this.getCoefficient(0);if(e===1){let e=0;for(let t of this.coefficients)e=this.field.add(e,t);return e}let t=this.coefficients[0],n=this.coefficients.length;for(let r=1;r<n;r++)t=this.field.add(this.field.multiply(e,t),this.coefficients[r]);return t}add(e){if(!this.field.equals(e.field))throw new l(`ModulusPolys do not have same ModulusGF field`);if(this.isZero())return e;if(e.isZero())return this;let t=this.coefficients,n=e.coefficients;if(t.length>n.length){let e=t;t=n,n=e}let r=new Int32Array(n.length),i=n.length-t.length;p.arraycopy(n,0,r,0,i);for(let e=i;e<n.length;e++)r[e]=this.field.add(t[e-i],n[e]);return new Yt(this.field,r)}subtract(e){if(!this.field.equals(e.field))throw new l(`ModulusPolys do not have same ModulusGF field`);return e.isZero()?this:this.add(e.negative())}multiply(e){return e instanceof Yt?this.multiplyOther(e):this.multiplyScalar(e)}multiplyOther(e){if(!this.field.equals(e.field))throw new l(`ModulusPolys do not have same ModulusGF field`);if(this.isZero()||e.isZero())return new Yt(this.field,new Int32Array([0]));let t=this.coefficients,n=t.length,r=e.coefficients,i=r.length,a=new Int32Array(n+i-1);for(let e=0;e<n;e++){let n=t[e];for(let t=0;t<i;t++)a[e+t]=this.field.add(a[e+t],this.field.multiply(n,r[t]))}return new Yt(this.field,a)}negative(){let e=this.coefficients.length,t=new Int32Array(e);for(let n=0;n<e;n++)t[n]=this.field.subtract(0,this.coefficients[n]);return new Yt(this.field,t)}multiplyScalar(e){if(e===0)return new Yt(this.field,new Int32Array([0]));if(e===1)return this;let t=this.coefficients.length,n=new Int32Array(t);for(let r=0;r<t;r++)n[r]=this.field.multiply(this.coefficients[r],e);return new Yt(this.field,n)}multiplyByMonomial(e,t){if(e<0)throw new l;if(t===0)return new Yt(this.field,new Int32Array([0]));let n=this.coefficients.length,r=new Int32Array(n+e);for(let e=0;e<n;e++)r[e]=this.field.multiply(this.coefficients[e],t);return new Yt(this.field,r)}toString(){let e=new D;for(let t=this.getDegree();t>=0;t--){let n=this.getCoefficient(t);n!==0&&(n<0?(e.append(` - `),n=-n):e.length()>0&&e.append(` + `),(t===0||n!==1)&&e.append(n),t!==0&&(t===1?e.append(`x`):(e.append(`x^`),e.append(t))))}return e.toString()}}class Xt{add(e,t){return(e+t)%this.modulus}subtract(e,t){return(this.modulus+e-t)%this.modulus}exp(e){return this.expTable[e]}log(e){if(e===0)throw new l;return this.logTable[e]}inverse(e){if(e===0)throw new ae;return this.expTable[this.modulus-this.logTable[e]-1]}multiply(e,t){return e===0||t===0?0:this.expTable[(this.logTable[e]+this.logTable[t])%(this.modulus-1)]}getSize(){return this.modulus}equals(e){return e===this}}class Zt extends Xt{constructor(e,t){super(),this.modulus=e,this.expTable=new Int32Array(e),this.logTable=new Int32Array(e);let n=1;for(let r=0;r<e;r++)this.expTable[r]=n,n=n*t%e;for(let t=0;t<e-1;t++)this.logTable[this.expTable[t]]=t;this.zero=new Yt(this,new Int32Array([0])),this.one=new Yt(this,new Int32Array([1]))}getZero(){return this.zero}getOne(){return this.one}buildMonomial(e,t){if(e<0)throw new l;if(t===0)return this.zero;let n=new Int32Array(e+1);return n[0]=t,new Yt(this,n)}}Zt.PDF417_GF=new Zt(Kt.NUMBER_OF_CODEWORDS,3);class K{constructor(){this.field=Zt.PDF417_GF}decode(e,t,n){let r=new Yt(this.field,e),i=new Int32Array(t),a=!1;for(let e=t;e>0;e--){let n=r.evaluateAt(this.field.exp(e));i[t-e]=n,n!==0&&(a=!0)}if(!a)return 0;let o=this.field.getOne();if(n!=null)for(let t of n){let n=this.field.exp(e.length-1-t),r=new Yt(this.field,new Int32Array([this.field.subtract(0,n),1]));o=o.multiply(r)}let s=new Yt(this.field,i),c=this.runEuclideanAlgorithm(this.field.buildMonomial(t,1),s,t),l=c[0],u=c[1],f=this.findErrorLocations(l),p=this.findErrorMagnitudes(u,l,f);for(let t=0;t<f.length;t++){let n=e.length-1-this.field.log(f[t]);if(n<0)throw d.getChecksumInstance();e[n]=this.field.subtract(e[n],p[t])}return f.length}runEuclideanAlgorithm(e,t,n){if(e.getDegree()<t.getDegree()){let n=e;e=t,t=n}let r=e,i=t,a=this.field.getZero(),o=this.field.getOne();for(;i.getDegree()>=Math.round(n/2);){let e=r,t=a;if(r=i,a=o,r.isZero())throw d.getChecksumInstance();i=e;let n=this.field.getZero(),s=r.getCoefficient(r.getDegree()),c=this.field.inverse(s);for(;i.getDegree()>=r.getDegree()&&!i.isZero();){let e=i.getDegree()-r.getDegree(),t=this.field.multiply(i.getCoefficient(i.getDegree()),c);n=n.add(this.field.buildMonomial(e,t)),i=i.subtract(r.multiplyByMonomial(e,t))}o=n.multiply(a).subtract(t).negative()}let s=o.getCoefficient(0);if(s===0)throw d.getChecksumInstance();let c=this.field.inverse(s);return[o.multiply(c),i.multiply(c)]}findErrorLocations(e){let t=e.getDegree(),n=new Int32Array(t),r=0;for(let i=1;i<this.field.getSize()&&r<t;i++)e.evaluateAt(i)===0&&(n[r]=this.field.inverse(i),r++);if(r!==t)throw d.getChecksumInstance();return n}findErrorMagnitudes(e,t,n){let r=t.getDegree(),i=new Int32Array(r);for(let e=1;e<=r;e++)i[r-e]=this.field.multiply(e,t.getCoefficient(e));let a=new Yt(this.field,i),o=n.length,s=new Int32Array(o);for(let t=0;t<o;t++){let r=this.field.inverse(n[t]),i=this.field.subtract(0,e.evaluateAt(r)),o=this.field.inverse(a.evaluateAt(r));s[t]=this.field.multiply(i,o)}return s}}class Qt{constructor(e,t,n,r,i){e instanceof Qt?this.constructor_2(e):this.constructor_1(e,t,n,r,i)}constructor_1(e,t,n,r,i){let a=t==null||n==null,o=r==null||i==null;if(a&&o)throw new k;a?(t=new V(0,r.getY()),n=new V(0,i.getY())):o&&(r=new V(e.getWidth()-1,t.getY()),i=new V(e.getWidth()-1,n.getY())),this.image=e,this.topLeft=t,this.bottomLeft=n,this.topRight=r,this.bottomRight=i,this.minX=Math.trunc(Math.min(t.getX(),n.getX())),this.maxX=Math.trunc(Math.max(r.getX(),i.getX())),this.minY=Math.trunc(Math.min(t.getY(),r.getY())),this.maxY=Math.trunc(Math.max(n.getY(),i.getY()))}constructor_2(e){this.image=e.image,this.topLeft=e.getTopLeft(),this.bottomLeft=e.getBottomLeft(),this.topRight=e.getTopRight(),this.bottomRight=e.getBottomRight(),this.minX=e.getMinX(),this.maxX=e.getMaxX(),this.minY=e.getMinY(),this.maxY=e.getMaxY()}static merge(e,t){return e==null?t:t==null?e:new Qt(e.image,e.topLeft,e.bottomLeft,t.topRight,t.bottomRight)}addMissingRows(e,t,n){let r=this.topLeft,i=this.bottomLeft,a=this.topRight,o=this.bottomRight;if(e>0){let t=n?this.topLeft:this.topRight,i=Math.trunc(t.getY()-e);i<0&&(i=0);let o=new V(t.getX(),i);n?r=o:a=o}if(t>0){let e=n?this.bottomLeft:this.bottomRight,r=Math.trunc(e.getY()+t);r>=this.image.getHeight()&&(r=this.image.getHeight()-1);let a=new V(e.getX(),r);n?i=a:o=a}return new Qt(this.image,r,i,a,o)}getMinX(){return this.minX}getMaxX(){return this.maxX}getMinY(){return this.minY}getMaxY(){return this.maxY}getTopLeft(){return this.topLeft}getTopRight(){return this.topRight}getBottomLeft(){return this.bottomLeft}getBottomRight(){return this.bottomRight}}class $t{constructor(e,t,n,r){this.columnCount=e,this.errorCorrectionLevel=r,this.rowCountUpperPart=t,this.rowCountLowerPart=n,this.rowCount=t+n}getColumnCount(){return this.columnCount}getErrorCorrectionLevel(){return this.errorCorrectionLevel}getRowCount(){return this.rowCount}getRowCountUpperPart(){return this.rowCountUpperPart}getRowCountLowerPart(){return this.rowCountLowerPart}}class en{constructor(){this.buffer=``}static form(e,t){let n=-1;function r(e,r,i,a,o,s){if(e===`%%`)return`%`;if(t[++n]===void 0)return;e=a?parseInt(a.substr(1)):void 0;let c=o?parseInt(o.substr(1)):void 0,l;switch(s){case`s`:l=t[n];break;case`c`:l=t[n][0];break;case`f`:l=parseFloat(t[n]).toFixed(e);break;case`p`:l=parseFloat(t[n]).toPrecision(e);break;case`e`:l=parseFloat(t[n]).toExponential(e);break;case`x`:l=parseInt(t[n]).toString(c||16);break;case`d`:l=parseFloat(parseInt(t[n],c||10).toPrecision(e)).toFixed(0);break}l=typeof l==`object`?JSON.stringify(l):(+l).toString(c);let u=parseInt(i),d=i&&i[0]+``==`0`?`0`:` `;for(;l.length<u;)l=r===void 0?d+l:l+d;return l}return e.replace(/%(-)?(0?[0-9]+)?([.][0-9]+)?([#][0-9]+)?([scfpexd%])/g,r)}format(e,...t){this.buffer+=en.form(e,t)}toString(){return this.buffer}}class tn{constructor(e){this.boundingBox=new Qt(e),this.codewords=Array(e.getMaxY()-e.getMinY()+1)}getCodewordNearby(e){let t=this.getCodeword(e);if(t!=null)return t;for(let n=1;n<tn.MAX_NEARBY_DISTANCE;n++){let r=this.imageRowToCodewordIndex(e)-n;if(r>=0&&(t=this.codewords[r],t!=null)||(r=this.imageRowToCodewordIndex(e)+n,r<this.codewords.length&&(t=this.codewords[r],t!=null)))return t}return null}imageRowToCodewordIndex(e){return e-this.boundingBox.getMinY()}setCodeword(e,t){this.codewords[this.imageRowToCodewordIndex(e)]=t}getCodeword(e){return this.codewords[this.imageRowToCodewordIndex(e)]}getBoundingBox(){return this.boundingBox}getCodewords(){return this.codewords}toString(){let e=new en,t=0;for(let n of this.codewords){if(n==null){e.format(`%3d: | %n`,t++);continue}e.format(`%3d: %3d|%3d%n`,t++,n.getRowNumber(),n.getValue())}return e.toString()}}tn.MAX_NEARBY_DISTANCE=5;class nn{constructor(){this.values=new Map}setValue(e){e=Math.trunc(e);let t=this.values.get(e);t??=0,t++,this.values.set(e,t)}getValue(){let e=-1,t=[];for(let[n,r]of this.values.entries()){let i={getKey:()=>n,getValue:()=>r};i.getValue()>e?(e=i.getValue(),t=[],t.push(i.getKey())):i.getValue()===e&&t.push(i.getKey())}return Kt.toIntArray(t)}getConfidence(e){return this.values.get(e)}}class rn extends tn{constructor(e,t){super(e),this._isLeft=t}setRowNumbers(){for(let e of this.getCodewords())e?.setRowNumberAsRowIndicatorColumn()}adjustCompleteIndicatorColumnRowNumbers(e){let t=this.getCodewords();this.setRowNumbers(),this.removeIncorrectCodewords(t,e);let n=this.getBoundingBox(),r=this._isLeft?n.getTopLeft():n.getTopRight(),i=this._isLeft?n.getBottomLeft():n.getBottomRight(),a=this.imageRowToCodewordIndex(Math.trunc(r.getY())),o=this.imageRowToCodewordIndex(Math.trunc(i.getY())),s=-1,c=1,l=0;for(let n=a;n<o;n++){if(t[n]==null)continue;let r=t[n],i=r.getRowNumber()-s;if(i===0)l++;else if(i===1)c=Math.max(c,l),l=1,s=r.getRowNumber();else if(i<0||r.getRowNumber()>=e.getRowCount()||i>n)t[n]=null;else{let e;e=c>2?(c-2)*i:i;let a=e>=n;for(let r=1;r<=e&&!a;r++)a=t[n-r]!=null;a?t[n]=null:(s=r.getRowNumber(),l=1)}}}getRowHeights(){let e=this.getBarcodeMetadata();if(e==null)return null;this.adjustIncompleteIndicatorColumnRowNumbers(e);let t=new Int32Array(e.getRowCount());for(let e of this.getCodewords())if(e!=null){let n=e.getRowNumber();if(n>=t.length)continue;t[n]++}return t}adjustIncompleteIndicatorColumnRowNumbers(e){let t=this.getBoundingBox(),n=this._isLeft?t.getTopLeft():t.getTopRight(),r=this._isLeft?t.getBottomLeft():t.getBottomRight(),i=this.imageRowToCodewordIndex(Math.trunc(n.getY())),a=this.imageRowToCodewordIndex(Math.trunc(r.getY())),o=this.getCodewords(),s=-1;for(let t=i;t<a;t++){if(o[t]==null)continue;let n=o[t];n.setRowNumberAsRowIndicatorColumn();let r=n.getRowNumber()-s;r===0||(r===1?s=n.getRowNumber():n.getRowNumber()>=e.getRowCount()?o[t]=null:s=n.getRowNumber())}}getBarcodeMetadata(){let e=this.getCodewords(),t=new nn,n=new nn,r=new nn,i=new nn;for(let a of e){if(a==null)continue;a.setRowNumberAsRowIndicatorColumn();let e=a.getValue()%30,o=a.getRowNumber();switch(this._isLeft||(o+=2),o%3){case 0:n.setValue(e*3+1);break;case 1:i.setValue(e/3),r.setValue(e%3);break;case 2:t.setValue(e+1);break}}if(t.getValue().length===0||n.getValue().length===0||r.getValue().length===0||i.getValue().length===0||t.getValue()[0]<1||n.getValue()[0]+r.getValue()[0]<Kt.MIN_ROWS_IN_BARCODE||n.getValue()[0]+r.getValue()[0]>Kt.MAX_ROWS_IN_BARCODE)return null;let a=new $t(t.getValue()[0],n.getValue()[0],r.getValue()[0],i.getValue()[0]);return this.removeIncorrectCodewords(e,a),a}removeIncorrectCodewords(e,t){for(let n=0;n<e.length;n++){let r=e[n];if(e[n]==null)continue;let i=r.getValue()%30,a=r.getRowNumber();if(a>t.getRowCount()){e[n]=null;continue}switch(this._isLeft||(a+=2),a%3){case 0:i*3+1!==t.getRowCountUpperPart()&&(e[n]=null);break;case 1:(Math.trunc(i/3)!==t.getErrorCorrectionLevel()||i%3!==t.getRowCountLowerPart())&&(e[n]=null);break;case 2:i+1!==t.getColumnCount()&&(e[n]=null);break}}}isLeft(){return this._isLeft}toString(){return`IsLeft: `+this._isLeft+`
|
|
61
|
+
`+super.toString()}}class an{constructor(e,t){this.ADJUST_ROW_NUMBER_SKIP=2,this.barcodeMetadata=e,this.barcodeColumnCount=e.getColumnCount(),this.boundingBox=t,this.detectionResultColumns=Array(this.barcodeColumnCount+2)}getDetectionResultColumns(){this.adjustIndicatorColumnRowNumbers(this.detectionResultColumns[0]),this.adjustIndicatorColumnRowNumbers(this.detectionResultColumns[this.barcodeColumnCount+1]);let e=Kt.MAX_CODEWORDS_IN_BARCODE,t;do t=e,e=this.adjustRowNumbersAndGetCount();while(e>0&&e<t);return this.detectionResultColumns}adjustIndicatorColumnRowNumbers(e){e?.adjustCompleteIndicatorColumnRowNumbers(this.barcodeMetadata)}adjustRowNumbersAndGetCount(){let e=this.adjustRowNumbersByRow();if(e===0)return 0;for(let e=1;e<this.barcodeColumnCount+1;e++){let t=this.detectionResultColumns[e].getCodewords();for(let n=0;n<t.length;n++)t[n]!=null&&(t[n].hasValidRowNumber()||this.adjustRowNumbers(e,n,t))}return e}adjustRowNumbersByRow(){return this.adjustRowNumbersFromBothRI(),this.adjustRowNumbersFromLRI()+this.adjustRowNumbersFromRRI()}adjustRowNumbersFromBothRI(){if(this.detectionResultColumns[0]==null||this.detectionResultColumns[this.barcodeColumnCount+1]==null)return;let e=this.detectionResultColumns[0].getCodewords(),t=this.detectionResultColumns[this.barcodeColumnCount+1].getCodewords();for(let n=0;n<e.length;n++)if(e[n]!=null&&t[n]!=null&&e[n].getRowNumber()===t[n].getRowNumber())for(let t=1;t<=this.barcodeColumnCount;t++){let r=this.detectionResultColumns[t].getCodewords()[n];r!=null&&(r.setRowNumber(e[n].getRowNumber()),r.hasValidRowNumber()||(this.detectionResultColumns[t].getCodewords()[n]=null))}}adjustRowNumbersFromRRI(){if(this.detectionResultColumns[this.barcodeColumnCount+1]==null)return 0;let e=0,t=this.detectionResultColumns[this.barcodeColumnCount+1].getCodewords();for(let n=0;n<t.length;n++){if(t[n]==null)continue;let r=t[n].getRowNumber(),i=0;for(let t=this.barcodeColumnCount+1;t>0&&i<this.ADJUST_ROW_NUMBER_SKIP;t--){let a=this.detectionResultColumns[t].getCodewords()[n];a!=null&&(i=an.adjustRowNumberIfValid(r,i,a),a.hasValidRowNumber()||e++)}}return e}adjustRowNumbersFromLRI(){if(this.detectionResultColumns[0]==null)return 0;let e=0,t=this.detectionResultColumns[0].getCodewords();for(let n=0;n<t.length;n++){if(t[n]==null)continue;let r=t[n].getRowNumber(),i=0;for(let t=1;t<this.barcodeColumnCount+1&&i<this.ADJUST_ROW_NUMBER_SKIP;t++){let a=this.detectionResultColumns[t].getCodewords()[n];a!=null&&(i=an.adjustRowNumberIfValid(r,i,a),a.hasValidRowNumber()||e++)}}return e}static adjustRowNumberIfValid(e,t,n){return n==null||n.hasValidRowNumber()||(n.isValidRowNumber(e)?(n.setRowNumber(e),t=0):++t),t}adjustRowNumbers(e,t,n){if(!this.detectionResultColumns[e-1])return;let r=n[t],i=this.detectionResultColumns[e-1].getCodewords(),a=i;this.detectionResultColumns[e+1]!=null&&(a=this.detectionResultColumns[e+1].getCodewords());let o=Array(14);o[2]=i[t],o[3]=a[t],t>0&&(o[0]=n[t-1],o[4]=i[t-1],o[5]=a[t-1]),t>1&&(o[8]=n[t-2],o[10]=i[t-2],o[11]=a[t-2]),t<n.length-1&&(o[1]=n[t+1],o[6]=i[t+1],o[7]=a[t+1]),t<n.length-2&&(o[9]=n[t+2],o[12]=i[t+2],o[13]=a[t+2]);for(let e of o)if(an.adjustRowNumber(r,e))return}static adjustRowNumber(e,t){return t==null?!1:t.hasValidRowNumber()&&t.getBucket()===e.getBucket()?(e.setRowNumber(t.getRowNumber()),!0):!1}getBarcodeColumnCount(){return this.barcodeColumnCount}getBarcodeRowCount(){return this.barcodeMetadata.getRowCount()}getBarcodeECLevel(){return this.barcodeMetadata.getErrorCorrectionLevel()}setBoundingBox(e){this.boundingBox=e}getBoundingBox(){return this.boundingBox}setDetectionResultColumn(e,t){this.detectionResultColumns[e]=t}getDetectionResultColumn(e){return this.detectionResultColumns[e]}toString(){let e=this.detectionResultColumns[0];e??=this.detectionResultColumns[this.barcodeColumnCount+1];let t=new en;for(let n=0;n<e.getCodewords().length;n++){t.format(`CW %3d:`,n);for(let e=0;e<this.barcodeColumnCount+2;e++){if(this.detectionResultColumns[e]==null){t.format(` | `);continue}let r=this.detectionResultColumns[e].getCodewords()[n];if(r==null){t.format(` | `);continue}t.format(` %3d|%3d`,r.getRowNumber(),r.getValue())}t.format(`%n`)}return t.toString()}}class on{constructor(e,t,n,r){this.rowNumber=on.BARCODE_ROW_UNKNOWN,this.startX=Math.trunc(e),this.endX=Math.trunc(t),this.bucket=Math.trunc(n),this.value=Math.trunc(r)}hasValidRowNumber(){return this.isValidRowNumber(this.rowNumber)}isValidRowNumber(e){return e!==on.BARCODE_ROW_UNKNOWN&&this.bucket===e%3*3}setRowNumberAsRowIndicatorColumn(){this.rowNumber=Math.trunc(Math.trunc(this.value/30)*3+Math.trunc(this.bucket/3))}getWidth(){return this.endX-this.startX}getStartX(){return this.startX}getEndX(){return this.endX}getBucket(){return this.bucket}getValue(){return this.value}getRowNumber(){return this.rowNumber}setRowNumber(e){this.rowNumber=e}toString(){return this.rowNumber+`|`+this.value}}on.BARCODE_ROW_UNKNOWN=-1;class sn{static initialize(){for(let e=0;e<Kt.SYMBOL_TABLE.length;e++){let t=Kt.SYMBOL_TABLE[e],n=t&1;for(let r=0;r<Kt.BARS_IN_MODULE;r++){let i=0;for(;(t&1)===n;)i+=1,t>>=1;n=t&1,sn.RATIOS_TABLE[e]||(sn.RATIOS_TABLE[e]=Array(Kt.BARS_IN_MODULE)),sn.RATIOS_TABLE[e][Kt.BARS_IN_MODULE-r-1]=Math.fround(i/Kt.MODULES_IN_CODEWORD)}}this.bSymbolTableReady=!0}static getDecodedValue(e){let t=sn.getDecodedCodewordValue(sn.sampleBitCounts(e));return t===-1?sn.getClosestDecodedValue(e):t}static sampleBitCounts(e){let t=fe.sum(e),n=new Int32Array(Kt.BARS_IN_MODULE),r=0,i=0;for(let a=0;a<Kt.MODULES_IN_CODEWORD;a++){let o=t/(2*Kt.MODULES_IN_CODEWORD)+a*t/Kt.MODULES_IN_CODEWORD;i+e[r]<=o&&(i+=e[r],r++),n[r]++}return n}static getDecodedCodewordValue(e){let t=sn.getBitValue(e);return Kt.getCodeword(t)===-1?-1:t}static getBitValue(e){let t=0;for(let n=0;n<e.length;n++)for(let r=0;r<e[n];r++)t=t<<1|n%2==0;return Math.trunc(t)}static getClosestDecodedValue(e){let t=fe.sum(e),n=Array(Kt.BARS_IN_MODULE);if(t>1)for(let r=0;r<n.length;r++)n[r]=Math.fround(e[r]/t);let r=pe.MAX_VALUE,i=-1;this.bSymbolTableReady||sn.initialize();for(let e=0;e<sn.RATIOS_TABLE.length;e++){let t=0,a=sn.RATIOS_TABLE[e];for(let e=0;e<Kt.BARS_IN_MODULE;e++){let i=Math.fround(a[e]-n[e]);if(t+=Math.fround(i*i),t>=r)break}t<r&&(r=t,i=Kt.SYMBOL_TABLE[e])}return i}}sn.bSymbolTableReady=!1,sn.RATIOS_TABLE=Array(Kt.SYMBOL_TABLE.length).map(e=>e=Array(Kt.BARS_IN_MODULE));class cn{constructor(){this.segmentCount=-1,this.fileSize=-1,this.timestamp=-1,this.checksum=-1}getSegmentIndex(){return this.segmentIndex}setSegmentIndex(e){this.segmentIndex=e}getFileId(){return this.fileId}setFileId(e){this.fileId=e}getOptionalData(){return this.optionalData}setOptionalData(e){this.optionalData=e}isLastSegment(){return this.lastSegment}setLastSegment(e){this.lastSegment=e}getSegmentCount(){return this.segmentCount}setSegmentCount(e){this.segmentCount=e}getSender(){return this.sender||null}setSender(e){this.sender=e}getAddressee(){return this.addressee||null}setAddressee(e){this.addressee=e}getFileName(){return this.fileName}setFileName(e){this.fileName=e}getFileSize(){return this.fileSize}setFileSize(e){this.fileSize=e}getChecksum(){return this.checksum}setChecksum(e){this.checksum=e}getTimestamp(){return this.timestamp}setTimestamp(e){this.timestamp=e}}class ln{static parseLong(e,t=void 0){return parseInt(e,t)}}class un extends s{}un.kind=`NullPointerException`;class dn{writeBytes(e){this.writeBytesOffset(e,0,e.length)}writeBytesOffset(e,t,n){if(e==null)throw new un;if(t<0||t>e.length||n<0||t+n>e.length||t+n<0)throw new m;if(n!==0)for(let r=0;r<n;r++)this.write(e[t+r])}flush(){}close(){}}class fn extends s{}class pn extends dn{constructor(e=32){if(super(),this.count=0,e<0)throw new l(`Negative initial size: `+e);this.buf=new Uint8Array(e)}ensureCapacity(e){e-this.buf.length>0&&this.grow(e)}grow(e){let t=this.buf.length<<1;if(t-e<0&&(t=e),t<0){if(e<0)throw new fn;t=_.MAX_VALUE}this.buf=g.copyOfUint8Array(this.buf,t)}write(e){this.ensureCapacity(this.count+1),this.buf[this.count]=e,this.count+=1}writeBytesOffset(e,t,n){if(t<0||t>e.length||n<0||t+n-e.length>0)throw new m;this.ensureCapacity(this.count+n),p.arraycopy(e,t,this.buf,this.count,n),this.count+=n}writeTo(e){e.writeBytesOffset(this.buf,0,this.count)}reset(){this.count=0}toByteArray(){return g.copyOfUint8Array(this.buf,this.count)}size(){return this.count}toString(e){return e?typeof e==`string`?this.toString_string(e):this.toString_number(e):this.toString_void()}toString_void(){return new String(this.buf).toString()}toString_string(e){return new String(this.buf).toString()}toString_number(e){return new String(this.buf).toString()}close(){}}var mn;(function(e){e[e.ALPHA=0]=`ALPHA`,e[e.LOWER=1]=`LOWER`,e[e.MIXED=2]=`MIXED`,e[e.PUNCT=3]=`PUNCT`,e[e.ALPHA_SHIFT=4]=`ALPHA_SHIFT`,e[e.PUNCT_SHIFT=5]=`PUNCT_SHIFT`})(mn||={});function hn(){if(typeof window<`u`)return window.BigInt||null;if(typeof global<`u`)return global.BigInt||null;if(typeof self<`u`)return self.BigInt||null;throw Error(`Can't search globals for BigInt!`)}let gn;function _n(e){if(gn===void 0&&(gn=hn()),gn===null)throw Error(`BigInt is not supported!`);return gn(e)}function vn(){let e=[];e[0]=_n(1);let t=_n(900);e[1]=t;for(let n=2;n<16;n++)e[n]=e[n-1]*t;return e}class q{static decode(e,t){let n=new D(``),r=C.ISO8859_1;n.enableDecoding(r);let i=1,a=e[i++],o=new cn;for(;i<e[0];){switch(a){case q.TEXT_COMPACTION_MODE_LATCH:i=q.textCompaction(e,i,n);break;case q.BYTE_COMPACTION_MODE_LATCH:case q.BYTE_COMPACTION_MODE_LATCH_6:i=q.byteCompaction(a,e,r,i,n);break;case q.MODE_SHIFT_TO_BYTE_COMPACTION_MODE:n.append(e[i++]);break;case q.NUMERIC_COMPACTION_MODE_LATCH:i=q.numericCompaction(e,i,n);break;case q.ECI_CHARSET:C.getCharacterSetECIByValue(e[i++]);break;case q.ECI_GENERAL_PURPOSE:i+=2;break;case q.ECI_USER_DEFINED:i++;break;case q.BEGIN_MACRO_PDF417_CONTROL_BLOCK:i=q.decodeMacroBlock(e,i,o);break;case q.BEGIN_MACRO_PDF417_OPTIONAL_FIELD:case q.MACRO_PDF417_TERMINATOR:throw new x;default:i--,i=q.textCompaction(e,i,n);break}if(i<e.length)a=e[i++];else throw x.getFormatInstance()}if(n.length()===0)throw x.getFormatInstance();let s=new ne(null,n.toString(),null,t);return s.setOther(o),s}static decodeMacroBlock(e,t,n){if(t+q.NUMBER_OF_SEQUENCE_CODEWORDS>e[0])throw x.getFormatInstance();let r=new Int32Array(q.NUMBER_OF_SEQUENCE_CODEWORDS);for(let n=0;n<q.NUMBER_OF_SEQUENCE_CODEWORDS;n++,t++)r[n]=e[t];n.setSegmentIndex(_.parseInt(q.decodeBase900toBase10(r,q.NUMBER_OF_SEQUENCE_CODEWORDS)));let i=new D;t=q.textCompaction(e,t,i),n.setFileId(i.toString());let a=-1;for(e[t]===q.BEGIN_MACRO_PDF417_OPTIONAL_FIELD&&(a=t+1);t<e[0];)switch(e[t]){case q.BEGIN_MACRO_PDF417_OPTIONAL_FIELD:switch(t++,e[t]){case q.MACRO_PDF417_OPTIONAL_FIELD_FILE_NAME:let r=new D;t=q.textCompaction(e,t+1,r),n.setFileName(r.toString());break;case q.MACRO_PDF417_OPTIONAL_FIELD_SENDER:let i=new D;t=q.textCompaction(e,t+1,i),n.setSender(i.toString());break;case q.MACRO_PDF417_OPTIONAL_FIELD_ADDRESSEE:let a=new D;t=q.textCompaction(e,t+1,a),n.setAddressee(a.toString());break;case q.MACRO_PDF417_OPTIONAL_FIELD_SEGMENT_COUNT:let o=new D;t=q.numericCompaction(e,t+1,o),n.setSegmentCount(_.parseInt(o.toString()));break;case q.MACRO_PDF417_OPTIONAL_FIELD_TIME_STAMP:let s=new D;t=q.numericCompaction(e,t+1,s),n.setTimestamp(ln.parseLong(s.toString()));break;case q.MACRO_PDF417_OPTIONAL_FIELD_CHECKSUM:let c=new D;t=q.numericCompaction(e,t+1,c),n.setChecksum(_.parseInt(c.toString()));break;case q.MACRO_PDF417_OPTIONAL_FIELD_FILE_SIZE:let l=new D;t=q.numericCompaction(e,t+1,l),n.setFileSize(ln.parseLong(l.toString()));break;default:throw x.getFormatInstance()}break;case q.MACRO_PDF417_TERMINATOR:t++,n.setLastSegment(!0);break;default:throw x.getFormatInstance()}if(a!==-1){let r=t-a;n.isLastSegment()&&r--,n.setOptionalData(g.copyOfRange(e,a,a+r))}return t}static textCompaction(e,t,n){let r=new Int32Array((e[0]-t)*2),i=new Int32Array((e[0]-t)*2),a=0,o=!1;for(;t<e[0]&&!o;){let n=e[t++];if(n<q.TEXT_COMPACTION_MODE_LATCH)r[a]=n/30,r[a+1]=n%30,a+=2;else switch(n){case q.TEXT_COMPACTION_MODE_LATCH:r[a++]=q.TEXT_COMPACTION_MODE_LATCH;break;case q.BYTE_COMPACTION_MODE_LATCH:case q.BYTE_COMPACTION_MODE_LATCH_6:case q.NUMERIC_COMPACTION_MODE_LATCH:case q.BEGIN_MACRO_PDF417_CONTROL_BLOCK:case q.BEGIN_MACRO_PDF417_OPTIONAL_FIELD:case q.MACRO_PDF417_TERMINATOR:t--,o=!0;break;case q.MODE_SHIFT_TO_BYTE_COMPACTION_MODE:r[a]=q.MODE_SHIFT_TO_BYTE_COMPACTION_MODE,n=e[t++],i[a]=n,a++;break}}return q.decodeTextCompaction(r,i,a,n),t}static decodeTextCompaction(e,t,n,r){let i=mn.ALPHA,a=mn.ALPHA,o=0;for(;o<n;){let n=e[o],s=``;switch(i){case mn.ALPHA:if(n<26)s=String.fromCharCode(65+n);else switch(n){case 26:s=` `;break;case q.LL:i=mn.LOWER;break;case q.ML:i=mn.MIXED;break;case q.PS:a=i,i=mn.PUNCT_SHIFT;break;case q.MODE_SHIFT_TO_BYTE_COMPACTION_MODE:r.append(t[o]);break;case q.TEXT_COMPACTION_MODE_LATCH:i=mn.ALPHA;break}break;case mn.LOWER:if(n<26)s=String.fromCharCode(97+n);else switch(n){case 26:s=` `;break;case q.AS:a=i,i=mn.ALPHA_SHIFT;break;case q.ML:i=mn.MIXED;break;case q.PS:a=i,i=mn.PUNCT_SHIFT;break;case q.MODE_SHIFT_TO_BYTE_COMPACTION_MODE:r.append(t[o]);break;case q.TEXT_COMPACTION_MODE_LATCH:i=mn.ALPHA;break}break;case mn.MIXED:if(n<q.PL)s=q.MIXED_CHARS[n];else switch(n){case q.PL:i=mn.PUNCT;break;case 26:s=` `;break;case q.LL:i=mn.LOWER;break;case q.AL:i=mn.ALPHA;break;case q.PS:a=i,i=mn.PUNCT_SHIFT;break;case q.MODE_SHIFT_TO_BYTE_COMPACTION_MODE:r.append(t[o]);break;case q.TEXT_COMPACTION_MODE_LATCH:i=mn.ALPHA;break}break;case mn.PUNCT:if(n<q.PAL)s=q.PUNCT_CHARS[n];else switch(n){case q.PAL:i=mn.ALPHA;break;case q.MODE_SHIFT_TO_BYTE_COMPACTION_MODE:r.append(t[o]);break;case q.TEXT_COMPACTION_MODE_LATCH:i=mn.ALPHA;break}break;case mn.ALPHA_SHIFT:if(i=a,n<26)s=String.fromCharCode(65+n);else switch(n){case 26:s=` `;break;case q.TEXT_COMPACTION_MODE_LATCH:i=mn.ALPHA;break}break;case mn.PUNCT_SHIFT:if(i=a,n<q.PAL)s=q.PUNCT_CHARS[n];else switch(n){case q.PAL:i=mn.ALPHA;break;case q.MODE_SHIFT_TO_BYTE_COMPACTION_MODE:r.append(t[o]);break;case q.TEXT_COMPACTION_MODE_LATCH:i=mn.ALPHA;break}break}s!==``&&r.append(s),o++}}static byteCompaction(e,t,n,r,i){let a=new pn,o=0,s=0,c=!1;switch(e){case q.BYTE_COMPACTION_MODE_LATCH:let e=new Int32Array(6),n=t[r++];for(;r<t[0]&&!c;)switch(e[o++]=n,s=900*s+n,n=t[r++],n){case q.TEXT_COMPACTION_MODE_LATCH:case q.BYTE_COMPACTION_MODE_LATCH:case q.NUMERIC_COMPACTION_MODE_LATCH:case q.BYTE_COMPACTION_MODE_LATCH_6:case q.BEGIN_MACRO_PDF417_CONTROL_BLOCK:case q.BEGIN_MACRO_PDF417_OPTIONAL_FIELD:case q.MACRO_PDF417_TERMINATOR:r--,c=!0;break;default:if(o%5==0&&o>0){for(let e=0;e<6;++e)a.write(Number(_n(s)>>_n(8*(5-e))));s=0,o=0}break}r===t[0]&&n<q.TEXT_COMPACTION_MODE_LATCH&&(e[o++]=n);for(let t=0;t<o;t++)a.write(e[t]);break;case q.BYTE_COMPACTION_MODE_LATCH_6:for(;r<t[0]&&!c;){let e=t[r++];if(e<q.TEXT_COMPACTION_MODE_LATCH)o++,s=900*s+e;else switch(e){case q.TEXT_COMPACTION_MODE_LATCH:case q.BYTE_COMPACTION_MODE_LATCH:case q.NUMERIC_COMPACTION_MODE_LATCH:case q.BYTE_COMPACTION_MODE_LATCH_6:case q.BEGIN_MACRO_PDF417_CONTROL_BLOCK:case q.BEGIN_MACRO_PDF417_OPTIONAL_FIELD:case q.MACRO_PDF417_TERMINATOR:r--,c=!0;break}if(o%5==0&&o>0){for(let e=0;e<6;++e)a.write(Number(_n(s)>>_n(8*(5-e))));s=0,o=0}}break}return i.append(T.decode(a.toByteArray(),n)),r}static numericCompaction(e,t,n){let r=0,i=!1,a=new Int32Array(q.MAX_NUMERIC_CODEWORDS);for(;t<e[0]&&!i;){let o=e[t++];if(t===e[0]&&(i=!0),o<q.TEXT_COMPACTION_MODE_LATCH)a[r]=o,r++;else switch(o){case q.TEXT_COMPACTION_MODE_LATCH:case q.BYTE_COMPACTION_MODE_LATCH:case q.BYTE_COMPACTION_MODE_LATCH_6:case q.BEGIN_MACRO_PDF417_CONTROL_BLOCK:case q.BEGIN_MACRO_PDF417_OPTIONAL_FIELD:case q.MACRO_PDF417_TERMINATOR:t--,i=!0;break}(r%q.MAX_NUMERIC_CODEWORDS===0||o===q.NUMERIC_COMPACTION_MODE_LATCH||i)&&r>0&&(n.append(q.decodeBase900toBase10(a,r)),r=0)}return t}static decodeBase900toBase10(e,t){let n=_n(0);for(let r=0;r<t;r++)n+=q.EXP900[t-r-1]*_n(e[r]);let r=n.toString();if(r.charAt(0)!==`1`)throw new x;return r.substring(1)}}q.TEXT_COMPACTION_MODE_LATCH=900,q.BYTE_COMPACTION_MODE_LATCH=901,q.NUMERIC_COMPACTION_MODE_LATCH=902,q.BYTE_COMPACTION_MODE_LATCH_6=924,q.ECI_USER_DEFINED=925,q.ECI_GENERAL_PURPOSE=926,q.ECI_CHARSET=927,q.BEGIN_MACRO_PDF417_CONTROL_BLOCK=928,q.BEGIN_MACRO_PDF417_OPTIONAL_FIELD=923,q.MACRO_PDF417_TERMINATOR=922,q.MODE_SHIFT_TO_BYTE_COMPACTION_MODE=913,q.MAX_NUMERIC_CODEWORDS=15,q.MACRO_PDF417_OPTIONAL_FIELD_FILE_NAME=0,q.MACRO_PDF417_OPTIONAL_FIELD_SEGMENT_COUNT=1,q.MACRO_PDF417_OPTIONAL_FIELD_TIME_STAMP=2,q.MACRO_PDF417_OPTIONAL_FIELD_SENDER=3,q.MACRO_PDF417_OPTIONAL_FIELD_ADDRESSEE=4,q.MACRO_PDF417_OPTIONAL_FIELD_FILE_SIZE=5,q.MACRO_PDF417_OPTIONAL_FIELD_CHECKSUM=6,q.PL=25,q.LL=27,q.AS=27,q.ML=28,q.AL=28,q.PS=29,q.PAL=29,q.PUNCT_CHARS=`;<>@[\\]_\`~!\r ,:
|
|
62
|
+
-.$/"|*()?{}'`,q.MIXED_CHARS=`0123456789&\r ,:#-.$/+%*=^`,q.EXP900=hn()?vn():[],q.NUMBER_OF_SEQUENCE_CODEWORDS=2;class yn{constructor(){}static decode(e,t,n,r,i,a,o){let s=new Qt(e,t,n,r,i),c=null,l=null,u;for(let n=!0;;n=!1){if(t!=null&&(c=yn.getRowIndicatorColumn(e,s,t,!0,a,o)),r!=null&&(l=yn.getRowIndicatorColumn(e,s,r,!1,a,o)),u=yn.merge(c,l),u==null)throw k.getNotFoundInstance();let i=u.getBoundingBox();if(n&&i!=null&&(i.getMinY()<s.getMinY()||i.getMaxY()>s.getMaxY()))s=i;else break}u.setBoundingBox(s);let d=u.getBarcodeColumnCount()+1;u.setDetectionResultColumn(0,c),u.setDetectionResultColumn(d,l);let f=c!=null;for(let t=1;t<=d;t++){let n=f?t:d-t;if(u.getDetectionResultColumn(n)!==void 0)continue;let r;r=n===0||n===d?new rn(s,n===0):new tn(s),u.setDetectionResultColumn(n,r);let i=-1,c=i;for(let t=s.getMinY();t<=s.getMaxY();t++){if(i=yn.getStartColumn(u,n,t,f),i<0||i>s.getMaxX()){if(c===-1)continue;i=c}let l=yn.detectCodeword(e,s.getMinX(),s.getMaxX(),f,i,t,a,o);l!=null&&(r.setCodeword(t,l),c=i,a=Math.min(a,l.getWidth()),o=Math.max(o,l.getWidth()))}}return yn.createDecoderResult(u)}static merge(e,t){if(e==null&&t==null)return null;let n=yn.getBarcodeMetadata(e,t);return n==null?null:new an(n,Qt.merge(yn.adjustBoundingBox(e),yn.adjustBoundingBox(t)))}static adjustBoundingBox(e){if(e==null)return null;let t=e.getRowHeights();if(t==null)return null;let n=yn.getMax(t),r=0;for(let e of t)if(r+=n-e,e>0)break;let i=e.getCodewords();for(let e=0;r>0&&i[e]==null;e++)r--;let a=0;for(let e=t.length-1;e>=0&&(a+=n-t[e],!(t[e]>0));e--);for(let e=i.length-1;a>0&&i[e]==null;e--)a--;return e.getBoundingBox().addMissingRows(r,a,e.isLeft())}static getMax(e){let t=-1;for(let n of e)t=Math.max(t,n);return t}static getBarcodeMetadata(e,t){let n;if(e==null||(n=e.getBarcodeMetadata())==null)return t==null?null:t.getBarcodeMetadata();let r;return t==null||(r=t.getBarcodeMetadata())==null?n:n.getColumnCount()!==r.getColumnCount()&&n.getErrorCorrectionLevel()!==r.getErrorCorrectionLevel()&&n.getRowCount()!==r.getRowCount()?null:n}static getRowIndicatorColumn(e,t,n,r,i,a){let o=new rn(t,r);for(let s=0;s<2;s++){let c=s===0?1:-1,l=Math.trunc(Math.trunc(n.getX()));for(let s=Math.trunc(Math.trunc(n.getY()));s<=t.getMaxY()&&s>=t.getMinY();s+=c){let t=yn.detectCodeword(e,0,e.getWidth(),r,l,s,i,a);t!=null&&(o.setCodeword(s,t),l=r?t.getStartX():t.getEndX())}}return o}static adjustCodewordCount(e,t){let n=t[0][1],r=n.getValue(),i=e.getBarcodeColumnCount()*e.getBarcodeRowCount()-yn.getNumberOfECCodeWords(e.getBarcodeECLevel());if(r.length===0){if(i<1||i>Kt.MAX_CODEWORDS_IN_BARCODE)throw k.getNotFoundInstance();n.setValue(i)}else r[0]!==i&&n.setValue(i)}static createDecoderResult(e){let t=yn.createBarcodeMatrix(e);yn.adjustCodewordCount(e,t);let n=[],r=new Int32Array(e.getBarcodeRowCount()*e.getBarcodeColumnCount()),i=[],a=[];for(let o=0;o<e.getBarcodeRowCount();o++)for(let s=0;s<e.getBarcodeColumnCount();s++){let c=t[o][s+1].getValue(),l=o*e.getBarcodeColumnCount()+s;c.length===0?n.push(l):c.length===1?r[l]=c[0]:(a.push(l),i.push(c))}let o=Array(i.length);for(let e=0;e<o.length;e++)o[e]=i[e];return yn.createDecoderResultFromAmbiguousValues(e.getBarcodeECLevel(),r,Kt.toIntArray(n),Kt.toIntArray(a),o)}static createDecoderResultFromAmbiguousValues(e,t,n,r,i){let a=new Int32Array(r.length),o=100;for(;o-- >0;){for(let e=0;e<a.length;e++)t[r[e]]=i[e][a[e]];try{return yn.decodeCodewords(t,e,n)}catch(e){if(!(e instanceof d))throw e}if(a.length===0)throw d.getChecksumInstance();for(let e=0;e<a.length;e++)if(a[e]<i[e].length-1){a[e]++;break}else if(a[e]=0,e===a.length-1)throw d.getChecksumInstance()}throw d.getChecksumInstance()}static createBarcodeMatrix(e){let t=Array.from({length:e.getBarcodeRowCount()},()=>Array(e.getBarcodeColumnCount()+2));for(let e=0;e<t.length;e++)for(let n=0;n<t[e].length;n++)t[e][n]=new nn;let n=0;for(let r of e.getDetectionResultColumns()){if(r!=null){for(let e of r.getCodewords())if(e!=null){let r=e.getRowNumber();if(r>=0){if(r>=t.length)continue;t[r][n].setValue(e.getValue())}}}n++}return t}static isValidBarcodeColumn(e,t){return t>=0&&t<=e.getBarcodeColumnCount()+1}static getStartColumn(e,t,n,r){let i=r?1:-1,a=null;if(yn.isValidBarcodeColumn(e,t-i)&&(a=e.getDetectionResultColumn(t-i).getCodeword(n)),a!=null)return r?a.getEndX():a.getStartX();if(a=e.getDetectionResultColumn(t).getCodewordNearby(n),a!=null)return r?a.getStartX():a.getEndX();if(yn.isValidBarcodeColumn(e,t-i)&&(a=e.getDetectionResultColumn(t-i).getCodewordNearby(n)),a!=null)return r?a.getEndX():a.getStartX();let o=0;for(;yn.isValidBarcodeColumn(e,t-i);){t-=i;for(let n of e.getDetectionResultColumn(t).getCodewords())if(n!=null)return(r?n.getEndX():n.getStartX())+i*o*(n.getEndX()-n.getStartX());o++}return r?e.getBoundingBox().getMinX():e.getBoundingBox().getMaxX()}static detectCodeword(e,t,n,r,i,a,o,s){i=yn.adjustCodewordStartColumn(e,t,n,r,i,a);let c=yn.getModuleBitCount(e,t,n,r,i,a);if(c==null)return null;let l,u=fe.sum(c);if(r)l=i+u;else{for(let e=0;e<c.length/2;e++){let t=c[e];c[e]=c[c.length-1-e],c[c.length-1-e]=t}l=i,i=l-u}if(!yn.checkCodewordSkew(u,o,s))return null;let d=sn.getDecodedValue(c),f=Kt.getCodeword(d);return f===-1?null:new on(i,l,yn.getCodewordBucketNumber(d),f)}static getModuleBitCount(e,t,n,r,i,a){let o=i,s=new Int32Array(8),c=0,l=r?1:-1,u=r;for(;(r?o<n:o>=t)&&c<s.length;)e.get(o,a)===u?(s[c]++,o+=l):(c++,u=!u);return c===s.length||o===(r?n:t)&&c===s.length-1?s:null}static getNumberOfECCodeWords(e){return 2<<e}static adjustCodewordStartColumn(e,t,n,r,i,a){let o=i,s=r?-1:1;for(let c=0;c<2;c++){for(;(r?o>=t:o<n)&&r===e.get(o,a);){if(Math.abs(i-o)>yn.CODEWORD_SKEW_SIZE)return i;o+=s}s=-s,r=!r}return o}static checkCodewordSkew(e,t,n){return t-yn.CODEWORD_SKEW_SIZE<=e&&e<=n+yn.CODEWORD_SKEW_SIZE}static decodeCodewords(e,t,n){if(e.length===0)throw x.getFormatInstance();let r=1<<t+1,i=yn.correctErrors(e,n,r);yn.verifyCodewordCount(e,r);let a=q.decode(e,``+t);return a.setErrorsCorrected(i),a.setErasures(n.length),a}static correctErrors(e,t,n){if(t!=null&&t.length>n/2+yn.MAX_ERRORS||n<0||n>yn.MAX_EC_CODEWORDS)throw d.getChecksumInstance();return yn.errorCorrection.decode(e,n,t)}static verifyCodewordCount(e,t){if(e.length<4)throw x.getFormatInstance();let n=e[0];if(n>e.length)throw x.getFormatInstance();if(n===0)if(t<e.length)e[0]=e.length-t;else throw x.getFormatInstance()}static getBitCountForCodeword(e){let t=new Int32Array(8),n=0,r=t.length-1;for(;!((e&1)!==n&&(n=e&1,r--,r<0));)t[r]++,e>>=1;return t}static getCodewordBucketNumber(e){return e instanceof Int32Array?this.getCodewordBucketNumber_Int32Array(e):this.getCodewordBucketNumber_number(e)}static getCodewordBucketNumber_number(e){return yn.getCodewordBucketNumber(yn.getBitCountForCodeword(e))}static getCodewordBucketNumber_Int32Array(e){return(e[0]-e[2]+e[4]-e[6]+9)%9}static toString(e){let t=new en;for(let n=0;n<e.length;n++){t.format(`Row %2d: `,n);for(let r=0;r<e[n].length;r++){let i=e[n][r];i.getValue().length===0?t.format(` `,null):t.format(`%4d(%2d)`,i.getValue()[0],i.getConfidence(i.getValue()[0]))}t.format(`%n`)}return t.toString()}}yn.CODEWORD_SKEW_SIZE=2,yn.MAX_ERRORS=3,yn.MAX_EC_CODEWORDS=512,yn.errorCorrection=new K;class bn{decode(e,t=null){let n=bn.decode(e,t,!1);if(n==null||n.length===0||n[0]==null)throw k.getNotFoundInstance();return n[0]}decodeMultiple(e,t=null){try{return bn.decode(e,t,!0)}catch(e){throw e instanceof x||e instanceof d?k.getNotFoundInstance():e}}static decode(e,t,n){let r=[],i=Jt.detectMultiple(e,t,n);for(let e of i.getPoints()){let t=yn.decode(i.getBits(),e[4],e[5],e[6],e[7],bn.getMinCodewordWidth(e),bn.getMaxCodewordWidth(e)),n=new R(t.getText(),t.getRawBytes(),void 0,e,B.PDF_417);n.putMetadata(te.ERROR_CORRECTION_LEVEL,t.getECLevel());let a=t.getOther();a!=null&&n.putMetadata(te.PDF417_EXTRA_METADATA,a),r.push(n)}return r.map(e=>e)}static getMaxWidth(e,t){return e==null||t==null?0:Math.trunc(Math.abs(e.getX()-t.getX()))}static getMinWidth(e,t){return e==null||t==null?_.MAX_VALUE:Math.trunc(Math.abs(e.getX()-t.getX()))}static getMaxCodewordWidth(e){return Math.floor(Math.max(Math.max(bn.getMaxWidth(e[0],e[4]),bn.getMaxWidth(e[6],e[2])*Kt.MODULES_IN_CODEWORD/Kt.MODULES_IN_STOP_PATTERN),Math.max(bn.getMaxWidth(e[1],e[5]),bn.getMaxWidth(e[7],e[3])*Kt.MODULES_IN_CODEWORD/Kt.MODULES_IN_STOP_PATTERN)))}static getMinCodewordWidth(e){return Math.floor(Math.min(Math.min(bn.getMinWidth(e[0],e[4]),bn.getMinWidth(e[6],e[2])*Kt.MODULES_IN_CODEWORD/Kt.MODULES_IN_STOP_PATTERN),Math.min(bn.getMinWidth(e[1],e[5]),bn.getMinWidth(e[7],e[3])*Kt.MODULES_IN_CODEWORD/Kt.MODULES_IN_STOP_PATTERN)))}reset(){}}class xn extends s{}xn.kind=`ReaderException`;class Sn{constructor(e,t){this.verbose=e===!0,t&&this.setHints(t)}decode(e,t){return t&&this.setHints(t),this.decodeInternal(e)}decodeWithState(e){return(this.readers===null||this.readers===void 0)&&this.setHints(null),this.decodeInternal(e)}setHints(e){this.hints=e;let n=!t(e)&&e.get(b.TRY_HARDER)===!0,r=t(e)?null:e.get(b.POSSIBLE_FORMATS),i=[];if(!t(r)){let t=r.some(e=>e===B.UPC_A||e===B.UPC_E||e===B.EAN_13||e===B.EAN_8||e===B.CODABAR||e===B.CODE_39||e===B.CODE_93||e===B.CODE_128||e===B.ITF||e===B.RSS_14||e===B.RSS_EXPANDED);t&&!n&&i.push(new ft(e,this.verbose)),r.includes(B.QR_CODE)&&i.push(new Gt),r.includes(B.DATA_MATRIX)&&i.push(new wt),r.includes(B.AZTEC)&&i.push(new Ce),r.includes(B.PDF_417)&&i.push(new bn),t&&n&&i.push(new ft(e,this.verbose))}i.length===0&&(n||i.push(new ft(e,this.verbose)),i.push(new Gt),i.push(new wt),i.push(new Ce),i.push(new bn),n&&i.push(new ft(e,this.verbose))),this.readers=i}reset(){if(this.readers!==null)for(let e of this.readers)e.reset()}decodeInternal(e){if(this.readers===null)throw new xn(`No readers where selected, nothing can be read.`);for(let t of this.readers)try{return t.decode(e,this.hints)}catch(e){if(e instanceof xn)continue}throw new k(`No MultiFormat Readers were able to detect the code.`)}}class Cn extends L{constructor(e=null,t=500){let n=new Sn;n.setHints(e),super(n,t)}decodeBitmap(e){return this.reader.decodeWithState(e)}}class wn extends L{constructor(e=500){super(new bn,e)}}class Tn extends L{constructor(e=500){super(new Gt,e)}}var En;(function(e){e[e.ERROR_CORRECTION=0]=`ERROR_CORRECTION`,e[e.CHARACTER_SET=1]=`CHARACTER_SET`,e[e.DATA_MATRIX_SHAPE=2]=`DATA_MATRIX_SHAPE`,e[e.MIN_SIZE=3]=`MIN_SIZE`,e[e.MAX_SIZE=4]=`MAX_SIZE`,e[e.MARGIN=5]=`MARGIN`,e[e.PDF417_COMPACT=6]=`PDF417_COMPACT`,e[e.PDF417_COMPACTION=7]=`PDF417_COMPACTION`,e[e.PDF417_DIMENSIONS=8]=`PDF417_DIMENSIONS`,e[e.AZTEC_LAYERS=9]=`AZTEC_LAYERS`,e[e.QR_VERSION=10]=`QR_VERSION`})(En||={});var Dn=En;class On{constructor(e){this.field=e,this.cachedGenerators=[],this.cachedGenerators.push(new ie(e,Int32Array.from([1])))}buildGenerator(e){let t=this.cachedGenerators;if(e>=t.length){let n=t[t.length-1],r=this.field;for(let i=t.length;i<=e;i++){let e=n.multiply(new ie(r,Int32Array.from([1,r.exp(i-1+r.getGeneratorBase())])));t.push(e),n=e}}return t[e]}encode(e,t){if(t===0)throw new l(`No error correction bytes`);let n=e.length-t;if(n<=0)throw new l(`No data bytes provided`);let r=this.buildGenerator(t),i=new Int32Array(n);p.arraycopy(e,0,i,0,n);let a=new ie(this.field,i);a=a.multiplyByMonomial(t,1);let o=a.divide(r)[1].getCoefficients(),s=t-o.length;for(let t=0;t<s;t++)e[n+t]=0;p.arraycopy(o,0,e,n+s,o.length)}}class kn{constructor(){}static applyMaskPenaltyRule1(e){return kn.applyMaskPenaltyRule1Internal(e,!0)+kn.applyMaskPenaltyRule1Internal(e,!1)}static applyMaskPenaltyRule2(e){let t=0,n=e.getArray(),r=e.getWidth(),i=e.getHeight();for(let e=0;e<i-1;e++){let i=n[e];for(let a=0;a<r-1;a++){let r=i[a];r===i[a+1]&&r===n[e+1][a]&&r===n[e+1][a+1]&&t++}}return kn.N2*t}static applyMaskPenaltyRule3(e){let t=0,n=e.getArray(),r=e.getWidth(),i=e.getHeight();for(let e=0;e<i;e++)for(let a=0;a<r;a++){let o=n[e];a+6<r&&o[a]===1&&o[a+1]===0&&o[a+2]===1&&o[a+3]===1&&o[a+4]===1&&o[a+5]===0&&o[a+6]===1&&(kn.isWhiteHorizontal(o,a-4,a)||kn.isWhiteHorizontal(o,a+7,a+11))&&t++,e+6<i&&n[e][a]===1&&n[e+1][a]===0&&n[e+2][a]===1&&n[e+3][a]===1&&n[e+4][a]===1&&n[e+5][a]===0&&n[e+6][a]===1&&(kn.isWhiteVertical(n,a,e-4,e)||kn.isWhiteVertical(n,a,e+7,e+11))&&t++}return t*kn.N3}static isWhiteHorizontal(e,t,n){t=Math.max(t,0),n=Math.min(n,e.length);for(let r=t;r<n;r++)if(e[r]===1)return!1;return!0}static isWhiteVertical(e,t,n,r){n=Math.max(n,0),r=Math.min(r,e.length);for(let i=n;i<r;i++)if(e[i][t]===1)return!1;return!0}static applyMaskPenaltyRule4(e){let t=0,n=e.getArray(),r=e.getWidth(),i=e.getHeight();for(let e=0;e<i;e++){let i=n[e];for(let e=0;e<r;e++)i[e]===1&&t++}let a=e.getHeight()*e.getWidth();return Math.floor(Math.abs(t*2-a)*10/a)*kn.N4}static getDataMaskBit(e,t,n){let r,i;switch(e){case 0:r=n+t&1;break;case 1:r=n&1;break;case 2:r=t%3;break;case 3:r=(n+t)%3;break;case 4:r=Math.floor(n/2)+Math.floor(t/3)&1;break;case 5:i=n*t,r=(i&1)+i%3;break;case 6:i=n*t,r=(i&1)+i%3&1;break;case 7:i=n*t,r=i%3+(n+t&1)&1;break;default:throw new l(`Invalid mask pattern: `+e)}return r===0}static applyMaskPenaltyRule1Internal(e,t){let n=0,r=t?e.getHeight():e.getWidth(),i=t?e.getWidth():e.getHeight(),a=e.getArray();for(let e=0;e<r;e++){let r=0,o=-1;for(let s=0;s<i;s++){let i=t?a[e][s]:a[s][e];i===o?r++:(r>=5&&(n+=kn.N1+(r-5)),r=1,o=i)}r>=5&&(n+=kn.N1+(r-5))}return n}}kn.N1=3,kn.N2=3,kn.N3=40,kn.N4=10;class An{constructor(e,t){this.width=e,this.height=t;let n=Array(t);for(let r=0;r!==t;r++)n[r]=new Uint8Array(e);this.bytes=n}getHeight(){return this.height}getWidth(){return this.width}get(e,t){return this.bytes[t][e]}getArray(){return this.bytes}setNumber(e,t,n){this.bytes[t][e]=n}setBoolean(e,t,n){this.bytes[t][e]=+!!n}clear(e){for(let t of this.bytes)g.fill(t,e)}equals(e){if(!(e instanceof An))return!1;let t=e;if(this.width!==t.width||this.height!==t.height)return!1;for(let e=0,n=this.height;e<n;++e){let n=this.bytes[e],r=t.bytes[e];for(let e=0,t=this.width;e<t;++e)if(n[e]!==r[e])return!1}return!0}toString(){let e=new D;for(let t=0,n=this.height;t<n;++t){let n=this.bytes[t];for(let t=0,r=this.width;t<r;++t)switch(n[t]){case 0:e.append(` 0`);break;case 1:e.append(` 1`);break;default:e.append(` `);break}e.append(`
|
|
63
|
+
`)}return e.toString()}}class jn{constructor(){this.maskPattern=-1}getMode(){return this.mode}getECLevel(){return this.ecLevel}getVersion(){return this.version}getMaskPattern(){return this.maskPattern}getMatrix(){return this.matrix}toString(){let e=new D;return e.append(`<<
|
|
64
|
+
`),e.append(` mode: `),e.append(this.mode?this.mode.toString():`null`),e.append(`
|
|
65
|
+
ecLevel: `),e.append(this.ecLevel?this.ecLevel.toString():`null`),e.append(`
|
|
66
|
+
version: `),e.append(this.version?this.version.toString():`null`),e.append(`
|
|
67
|
+
maskPattern: `),e.append(this.maskPattern.toString()),this.matrix?(e.append(`
|
|
68
|
+
matrix:
|
|
69
|
+
`),e.append(this.matrix.toString())):e.append(`
|
|
70
|
+
matrix: null
|
|
71
|
+
`),e.append(`>>
|
|
72
|
+
`),e.toString()}setMode(e){this.mode=e}setECLevel(e){this.ecLevel=e}setVersion(e){this.version=e}setMaskPattern(e){this.maskPattern=e}setMatrix(e){this.matrix=e}static isValidMaskPattern(e){return e>=0&&e<jn.NUM_MASK_PATTERNS}}jn.NUM_MASK_PATTERNS=8;class Mn extends s{}Mn.kind=`WriterException`;class Nn{constructor(){}static clearMatrix(e){e.clear(255)}static buildMatrix(e,t,n,r,i){Nn.clearMatrix(i),Nn.embedBasicPatterns(n,i),Nn.embedTypeInfo(t,r,i),Nn.maybeEmbedVersionInfo(n,i),Nn.embedDataBits(e,r,i)}static embedBasicPatterns(e,t){Nn.embedPositionDetectionPatternsAndSeparators(t),Nn.embedDarkDotAtLeftBottomCorner(t),Nn.maybeEmbedPositionAdjustmentPatterns(e,t),Nn.embedTimingPatterns(t)}static embedTypeInfo(e,t,n){let r=new v;Nn.makeTypeInfoBits(e,t,r);for(let e=0,t=r.getSize();e<t;++e){let t=r.get(r.getSize()-1-e),i=Nn.TYPE_INFO_COORDINATES[e],a=i[0],o=i[1];if(n.setBoolean(a,o,t),e<8){let r=n.getWidth()-e-1;n.setBoolean(r,8,t)}else{let r=n.getHeight()-7+(e-8);n.setBoolean(8,r,t)}}}static maybeEmbedVersionInfo(e,t){if(e.getVersionNumber()<7)return;let n=new v;Nn.makeVersionInfoBits(e,n);let r=17;for(let e=0;e<6;++e)for(let i=0;i<3;++i){let a=n.get(r);r--,t.setBoolean(e,t.getHeight()-11+i,a),t.setBoolean(t.getHeight()-11+i,e,a)}}static embedDataBits(e,t,n){let r=0,i=-1,a=n.getWidth()-1,o=n.getHeight()-1;for(;a>0;){for(a===6&&--a;o>=0&&o<n.getHeight();){for(let i=0;i<2;++i){let s=a-i;if(!Nn.isEmpty(n.get(s,o)))continue;let c;r<e.getSize()?(c=e.get(r),++r):c=!1,t!==255&&kn.getDataMaskBit(t,s,o)&&(c=!c),n.setBoolean(s,o,c)}o+=i}i=-i,o+=i,a-=2}if(r!==e.getSize())throw new Mn(`Not all bits consumed: `+r+`/`+e.getSize())}static findMSBSet(e){return 32-_.numberOfLeadingZeros(e)}static calculateBCHCode(e,t){if(t===0)throw new l(`0 polynomial`);let n=Nn.findMSBSet(t);for(e<<=n-1;Nn.findMSBSet(e)>=n;)e^=t<<Nn.findMSBSet(e)-n;return e}static makeTypeInfoBits(e,t,n){if(!jn.isValidMaskPattern(t))throw new Mn(`Invalid mask pattern`);let r=e.getBits()<<3|t;n.appendBits(r,5);let i=Nn.calculateBCHCode(r,Nn.TYPE_INFO_POLY);n.appendBits(i,10);let a=new v;if(a.appendBits(Nn.TYPE_INFO_MASK_PATTERN,15),n.xor(a),n.getSize()!==15)throw new Mn(`should not happen but we got: `+n.getSize())}static makeVersionInfoBits(e,t){t.appendBits(e.getVersionNumber(),6);let n=Nn.calculateBCHCode(e.getVersionNumber(),Nn.VERSION_INFO_POLY);if(t.appendBits(n,12),t.getSize()!==18)throw new Mn(`should not happen but we got: `+t.getSize())}static isEmpty(e){return e===255}static embedTimingPatterns(e){for(let t=8;t<e.getWidth()-8;++t){let n=(t+1)%2;Nn.isEmpty(e.get(t,6))&&e.setNumber(t,6,n),Nn.isEmpty(e.get(6,t))&&e.setNumber(6,t,n)}}static embedDarkDotAtLeftBottomCorner(e){if(e.get(8,e.getHeight()-8)===0)throw new Mn;e.setNumber(8,e.getHeight()-8,1)}static embedHorizontalSeparationPattern(e,t,n){for(let r=0;r<8;++r){if(!Nn.isEmpty(n.get(e+r,t)))throw new Mn;n.setNumber(e+r,t,0)}}static embedVerticalSeparationPattern(e,t,n){for(let r=0;r<7;++r){if(!Nn.isEmpty(n.get(e,t+r)))throw new Mn;n.setNumber(e,t+r,0)}}static embedPositionAdjustmentPattern(e,t,n){for(let r=0;r<5;++r){let i=Nn.POSITION_ADJUSTMENT_PATTERN[r];for(let a=0;a<5;++a)n.setNumber(e+a,t+r,i[a])}}static embedPositionDetectionPattern(e,t,n){for(let r=0;r<7;++r){let i=Nn.POSITION_DETECTION_PATTERN[r];for(let a=0;a<7;++a)n.setNumber(e+a,t+r,i[a])}}static embedPositionDetectionPatternsAndSeparators(e){let t=Nn.POSITION_DETECTION_PATTERN[0].length;Nn.embedPositionDetectionPattern(0,0,e),Nn.embedPositionDetectionPattern(e.getWidth()-t,0,e),Nn.embedPositionDetectionPattern(0,e.getWidth()-t,e),Nn.embedHorizontalSeparationPattern(0,7,e),Nn.embedHorizontalSeparationPattern(e.getWidth()-8,7,e),Nn.embedHorizontalSeparationPattern(0,e.getWidth()-8,e),Nn.embedVerticalSeparationPattern(7,0,e),Nn.embedVerticalSeparationPattern(e.getHeight()-7-1,0,e),Nn.embedVerticalSeparationPattern(7,e.getHeight()-7,e)}static maybeEmbedPositionAdjustmentPatterns(e,t){if(e.getVersionNumber()<2)return;let n=e.getVersionNumber()-1,r=Nn.POSITION_ADJUSTMENT_PATTERN_COORDINATE_TABLE[n];for(let e=0,n=r.length;e!==n;e++){let i=r[e];if(i>=0)for(let e=0;e!==n;e++){let n=r[e];n>=0&&Nn.isEmpty(t.get(n,i))&&Nn.embedPositionAdjustmentPattern(n-2,i-2,t)}}}}Nn.POSITION_DETECTION_PATTERN=Array.from([Int32Array.from([1,1,1,1,1,1,1]),Int32Array.from([1,0,0,0,0,0,1]),Int32Array.from([1,0,1,1,1,0,1]),Int32Array.from([1,0,1,1,1,0,1]),Int32Array.from([1,0,1,1,1,0,1]),Int32Array.from([1,0,0,0,0,0,1]),Int32Array.from([1,1,1,1,1,1,1])]),Nn.POSITION_ADJUSTMENT_PATTERN=Array.from([Int32Array.from([1,1,1,1,1]),Int32Array.from([1,0,0,0,1]),Int32Array.from([1,0,1,0,1]),Int32Array.from([1,0,0,0,1]),Int32Array.from([1,1,1,1,1])]),Nn.POSITION_ADJUSTMENT_PATTERN_COORDINATE_TABLE=Array.from([Int32Array.from([-1,-1,-1,-1,-1,-1,-1]),Int32Array.from([6,18,-1,-1,-1,-1,-1]),Int32Array.from([6,22,-1,-1,-1,-1,-1]),Int32Array.from([6,26,-1,-1,-1,-1,-1]),Int32Array.from([6,30,-1,-1,-1,-1,-1]),Int32Array.from([6,34,-1,-1,-1,-1,-1]),Int32Array.from([6,22,38,-1,-1,-1,-1]),Int32Array.from([6,24,42,-1,-1,-1,-1]),Int32Array.from([6,26,46,-1,-1,-1,-1]),Int32Array.from([6,28,50,-1,-1,-1,-1]),Int32Array.from([6,30,54,-1,-1,-1,-1]),Int32Array.from([6,32,58,-1,-1,-1,-1]),Int32Array.from([6,34,62,-1,-1,-1,-1]),Int32Array.from([6,26,46,66,-1,-1,-1]),Int32Array.from([6,26,48,70,-1,-1,-1]),Int32Array.from([6,26,50,74,-1,-1,-1]),Int32Array.from([6,30,54,78,-1,-1,-1]),Int32Array.from([6,30,56,82,-1,-1,-1]),Int32Array.from([6,30,58,86,-1,-1,-1]),Int32Array.from([6,34,62,90,-1,-1,-1]),Int32Array.from([6,28,50,72,94,-1,-1]),Int32Array.from([6,26,50,74,98,-1,-1]),Int32Array.from([6,30,54,78,102,-1,-1]),Int32Array.from([6,28,54,80,106,-1,-1]),Int32Array.from([6,32,58,84,110,-1,-1]),Int32Array.from([6,30,58,86,114,-1,-1]),Int32Array.from([6,34,62,90,118,-1,-1]),Int32Array.from([6,26,50,74,98,122,-1]),Int32Array.from([6,30,54,78,102,126,-1]),Int32Array.from([6,26,52,78,104,130,-1]),Int32Array.from([6,30,56,82,108,134,-1]),Int32Array.from([6,34,60,86,112,138,-1]),Int32Array.from([6,30,58,86,114,142,-1]),Int32Array.from([6,34,62,90,118,146,-1]),Int32Array.from([6,30,54,78,102,126,150]),Int32Array.from([6,24,50,76,102,128,154]),Int32Array.from([6,28,54,80,106,132,158]),Int32Array.from([6,32,58,84,110,136,162]),Int32Array.from([6,26,54,82,110,138,166]),Int32Array.from([6,30,58,86,114,142,170])]),Nn.TYPE_INFO_COORDINATES=Array.from([Int32Array.from([8,0]),Int32Array.from([8,1]),Int32Array.from([8,2]),Int32Array.from([8,3]),Int32Array.from([8,4]),Int32Array.from([8,5]),Int32Array.from([8,7]),Int32Array.from([8,8]),Int32Array.from([7,8]),Int32Array.from([5,8]),Int32Array.from([4,8]),Int32Array.from([3,8]),Int32Array.from([2,8]),Int32Array.from([1,8]),Int32Array.from([0,8])]),Nn.VERSION_INFO_POLY=7973,Nn.TYPE_INFO_POLY=1335,Nn.TYPE_INFO_MASK_PATTERN=21522;class Pn{constructor(e,t){this.dataBytes=e,this.errorCorrectionBytes=t}getDataBytes(){return this.dataBytes}getErrorCorrectionBytes(){return this.errorCorrectionBytes}}class Fn{constructor(){}static calculateMaskPenalty(e){return kn.applyMaskPenaltyRule1(e)+kn.applyMaskPenaltyRule2(e)+kn.applyMaskPenaltyRule3(e)+kn.applyMaskPenaltyRule4(e)}static encode(e,t,n=null){let r=Fn.DEFAULT_BYTE_MODE_ENCODING,i=n!==null&&n.get(Dn.CHARACTER_SET)!==void 0;i&&(r=n.get(Dn.CHARACTER_SET).toString());let a=this.chooseMode(e,r),o=new v;if(a===Ft.BYTE&&(i||Fn.DEFAULT_BYTE_MODE_ENCODING!==r)){let e=C.getCharacterSetECIByName(r);e!==void 0&&this.appendECI(e,o)}this.appendModeInfo(a,o);let s=new v;this.appendBytes(e,a,s,r);let c;if(n!==null&&n.get(Dn.QR_VERSION)!==void 0){let e=Number.parseInt(n.get(Dn.QR_VERSION).toString(),10);c=kt.getVersionForNumber(e);let r=this.calculateBitsNeeded(a,o,s,c);if(!this.willFit(r,c,t))throw new Mn(`Data too big for requested version`)}else c=this.recommendVersion(t,a,o,s);let l=new v;l.appendBitArray(o);let u=a===Ft.BYTE?s.getSizeInBytes():e.length;this.appendLengthInfo(u,c,a,l),l.appendBitArray(s);let d=c.getECBlocksForLevel(t),f=c.getTotalCodewords()-d.getTotalECCodewords();this.terminateBits(f,l);let p=this.interleaveWithECBytes(l,c.getTotalCodewords(),f,d.getNumBlocks()),m=new jn;m.setECLevel(t),m.setMode(a),m.setVersion(c);let h=c.getDimensionForVersion(),g=new An(h,h),_=this.chooseMaskPattern(p,t,c,g);return m.setMaskPattern(_),Nn.buildMatrix(p,t,c,_,g),m.setMatrix(g),m}static recommendVersion(e,t,n,r){let i=this.calculateBitsNeeded(t,n,r,kt.getVersionForNumber(1)),a=this.chooseVersion(i,e),o=this.calculateBitsNeeded(t,n,r,a);return this.chooseVersion(o,e)}static calculateBitsNeeded(e,t,n,r){return t.getSize()+e.getCharacterCountBits(r)+n.getSize()}static getAlphanumericCode(e){return e<Fn.ALPHANUMERIC_TABLE.length?Fn.ALPHANUMERIC_TABLE[e]:-1}static chooseMode(e,t=null){if(C.SJIS.getName()===t&&this.isOnlyDoubleByteKanji(e))return Ft.KANJI;let n=!1,r=!1;for(let t=0,i=e.length;t<i;++t){let i=e.charAt(t);if(Fn.isDigit(i))n=!0;else if(this.getAlphanumericCode(i.charCodeAt(0))!==-1)r=!0;else return Ft.BYTE}return r?Ft.ALPHANUMERIC:n?Ft.NUMERIC:Ft.BYTE}static isOnlyDoubleByteKanji(e){let t;try{t=T.encode(e,C.SJIS)}catch{return!1}let n=t.length;if(n%2!=0)return!1;for(let e=0;e<n;e+=2){let n=t[e]&255;if((n<129||n>159)&&(n<224||n>235))return!1}return!0}static chooseMaskPattern(e,t,n,r){let i=2**53-1,a=-1;for(let o=0;o<jn.NUM_MASK_PATTERNS;o++){Nn.buildMatrix(e,t,n,o,r);let s=this.calculateMaskPenalty(r);s<i&&(i=s,a=o)}return a}static chooseVersion(e,t){for(let n=1;n<=40;n++){let r=kt.getVersionForNumber(n);if(Fn.willFit(e,r,t))return r}throw new Mn(`Data too big`)}static willFit(e,t,n){return t.getTotalCodewords()-t.getECBlocksForLevel(n).getTotalECCodewords()>=(e+7)/8}static terminateBits(e,t){let n=e*8;if(t.getSize()>n)throw new Mn(`data bits cannot fit in the QR Code`+t.getSize()+` > `+n);for(let e=0;e<4&&t.getSize()<n;++e)t.appendBit(!1);let r=t.getSize()&7;if(r>0)for(let e=r;e<8;e++)t.appendBit(!1);let i=e-t.getSizeInBytes();for(let e=0;e<i;++e)t.appendBits(e&1?17:236,8);if(t.getSize()!==n)throw new Mn(`Bits size does not equal capacity`)}static getNumDataBytesAndNumECBytesForBlockID(e,t,n,r,i,a){if(r>=n)throw new Mn(`Block ID too large`);let o=e%n,s=n-o,c=Math.floor(e/n),l=c+1,u=Math.floor(t/n),d=u+1,f=c-u,p=l-d;if(f!==p)throw new Mn(`EC bytes mismatch`);if(n!==s+o)throw new Mn(`RS blocks mismatch`);if(e!==(u+f)*s+(d+p)*o)throw new Mn(`Total bytes mismatch`);r<s?(i[0]=u,a[0]=f):(i[0]=d,a[0]=p)}static interleaveWithECBytes(e,t,n,r){if(e.getSizeInBytes()!==n)throw new Mn(`Number of bits and data bytes does not match`);let i=0,a=0,o=0,s=[];for(let c=0;c<r;++c){let l=new Int32Array(1),u=new Int32Array(1);Fn.getNumDataBytesAndNumECBytesForBlockID(t,n,r,c,l,u);let d=l[0],f=new Uint8Array(d);e.toBytes(8*i,f,0,d);let p=Fn.generateECBytes(f,u[0]);s.push(new Pn(f,p)),a=Math.max(a,d),o=Math.max(o,p.length),i+=l[0]}if(n!==i)throw new Mn(`Data bytes does not match offset`);let c=new v;for(let e=0;e<a;++e)for(let t of s){let n=t.getDataBytes();e<n.length&&c.appendBits(n[e],8)}for(let e=0;e<o;++e)for(let t of s){let n=t.getErrorCorrectionBytes();e<n.length&&c.appendBits(n[e],8)}if(t!==c.getSizeInBytes())throw new Mn(`Interleaving error: `+t+` and `+c.getSizeInBytes()+` differ.`);return c}static generateECBytes(e,t){let n=e.length,r=new Int32Array(n+t);for(let t=0;t<n;t++)r[t]=e[t]&255;new On(oe.QR_CODE_FIELD_256).encode(r,t);let i=new Uint8Array(t);for(let e=0;e<t;e++)i[e]=r[n+e];return i}static appendModeInfo(e,t){t.appendBits(e.getBits(),4)}static appendLengthInfo(e,t,n,r){let i=n.getCharacterCountBits(t);if(e>=1<<i)throw new Mn(e+` is bigger than `+((1<<i)-1));r.appendBits(e,i)}static appendBytes(e,t,n,r){switch(t){case Ft.NUMERIC:Fn.appendNumericBytes(e,n);break;case Ft.ALPHANUMERIC:Fn.appendAlphanumericBytes(e,n);break;case Ft.BYTE:Fn.append8BitBytes(e,n,r);break;case Ft.KANJI:Fn.appendKanjiBytes(e,n);break;default:throw new Mn(`Invalid mode: `+t)}}static getDigit(e){return e.charCodeAt(0)-48}static isDigit(e){let t=Fn.getDigit(e);return t>=0&&t<=9}static appendNumericBytes(e,t){let n=e.length,r=0;for(;r<n;){let i=Fn.getDigit(e.charAt(r));if(r+2<n){let n=Fn.getDigit(e.charAt(r+1)),a=Fn.getDigit(e.charAt(r+2));t.appendBits(i*100+n*10+a,10),r+=3}else if(r+1<n){let n=Fn.getDigit(e.charAt(r+1));t.appendBits(i*10+n,7),r+=2}else t.appendBits(i,4),r++}}static appendAlphanumericBytes(e,t){let n=e.length,r=0;for(;r<n;){let i=Fn.getAlphanumericCode(e.charCodeAt(r));if(i===-1)throw new Mn;if(r+1<n){let n=Fn.getAlphanumericCode(e.charCodeAt(r+1));if(n===-1)throw new Mn;t.appendBits(i*45+n,11),r+=2}else t.appendBits(i,6),r++}}static append8BitBytes(e,t,n){let r;try{r=T.encode(e,n)}catch(e){throw new Mn(e)}for(let e=0,n=r.length;e!==n;e++){let n=r[e];t.appendBits(n,8)}}static appendKanjiBytes(e,t){let n;try{n=T.encode(e,C.SJIS)}catch(e){throw new Mn(e)}let r=n.length;for(let e=0;e<r;e+=2){let r=n[e]&255,i=n[e+1]&255,a=r<<8&4294967295|i,o=-1;if(a>=33088&&a<=40956?o=a-33088:a>=57408&&a<=60351&&(o=a-49472),o===-1)throw new Mn(`Invalid byte sequence`);let s=(o>>8)*192+(o&255);t.appendBits(s,13)}}static appendECI(e,t){t.appendBits(Ft.ECI.getBits(),4),t.appendBits(e.getValue(),8)}}Fn.ALPHANUMERIC_TABLE=Int32Array.from([-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,36,-1,-1,-1,37,38,-1,-1,-1,-1,39,40,-1,41,42,43,0,1,2,3,4,5,6,7,8,9,44,-1,-1,-1,-1,-1,-1,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,-1,-1,-1,-1,-1]),Fn.DEFAULT_BYTE_MODE_ENCODING=C.UTF8.getName();class In{write(e,t,n,r=null){if(e.length===0)throw new l(`Found empty contents`);if(t<0||n<0)throw new l(`Requested dimensions are too small: `+t+`x`+n);let i=Dt.L,a=In.QUIET_ZONE_SIZE;r!==null&&(r.get(Dn.ERROR_CORRECTION)!==void 0&&(i=Dt.fromString(r.get(Dn.ERROR_CORRECTION).toString())),r.get(Dn.MARGIN)!==void 0&&(a=Number.parseInt(r.get(Dn.MARGIN).toString(),10)));let o=Fn.encode(e,i,r);return this.renderResult(o,t,n,a)}writeToDom(e,t,n,r,i=null){typeof e==`string`&&(e=document.querySelector(e));let a=this.write(t,n,r,i);e&&e.appendChild(a)}renderResult(e,t,n,r){let i=e.getMatrix();if(i===null)throw new ce;let a=i.getWidth(),o=i.getHeight(),s=a+r*2,c=o+r*2,l=Math.max(t,s),u=Math.max(n,c),d=Math.min(Math.floor(l/s),Math.floor(u/c)),f=Math.floor((l-a*d)/2),p=Math.floor((u-o*d)/2),m=this.createSVGElement(l,u);for(let e=0,t=p;e<o;e++,t+=d)for(let n=0,r=f;n<a;n++,r+=d)if(i.get(n,e)===1){let e=this.createSvgRectElement(r,t,d,d);m.appendChild(e)}return m}createSVGElement(e,t){let n=document.createElementNS(In.SVG_NS,`svg`);return n.setAttributeNS(null,`height`,e.toString()),n.setAttributeNS(null,`width`,t.toString()),n}createSvgRectElement(e,t,n,r){let i=document.createElementNS(In.SVG_NS,`rect`);return i.setAttributeNS(null,`x`,e.toString()),i.setAttributeNS(null,`y`,t.toString()),i.setAttributeNS(null,`height`,n.toString()),i.setAttributeNS(null,`width`,r.toString()),i.setAttributeNS(null,`fill`,`#000000`),i}}In.QUIET_ZONE_SIZE=4,In.SVG_NS=`http://www.w3.org/2000/svg`;class Ln{encode(e,t,n,r,i){if(e.length===0)throw new l(`Found empty contents`);if(t!==B.QR_CODE)throw new l(`Can only encode QR_CODE, but got `+t);if(n<0||r<0)throw new l(`Requested dimensions are too small: ${n}x${r}`);let a=Dt.L,o=Ln.QUIET_ZONE_SIZE;i!==null&&(i.get(Dn.ERROR_CORRECTION)!==void 0&&(a=Dt.fromString(i.get(Dn.ERROR_CORRECTION).toString())),i.get(Dn.MARGIN)!==void 0&&(o=Number.parseInt(i.get(Dn.MARGIN).toString(),10)));let s=Fn.encode(e,a,i);return Ln.renderResult(s,n,r,o)}static renderResult(e,t,n,r){let i=e.getMatrix();if(i===null)throw new ce;let a=i.getWidth(),o=i.getHeight(),s=a+r*2,c=o+r*2,l=Math.max(t,s),u=Math.max(n,c),d=Math.min(Math.floor(l/s),Math.floor(u/c)),f=Math.floor((l-a*d)/2),p=Math.floor((u-o*d)/2),m=new O(l,u);for(let e=0,t=p;e<o;e++,t+=d)for(let n=0,r=f;n<a;n++,r+=d)i.get(n,e)===1&&m.setRegion(r,t,d,d);return m}}Ln.QUIET_ZONE_SIZE=4;class Rn{encode(e,t,n,r,i){let a;switch(t){case B.QR_CODE:a=new Ln;break;default:throw new l(`No encoder available for format `+t)}return a.encode(e,t,n,r,i)}}class zn extends M{constructor(e,t,n,r,i,a,o,s){if(super(a,o),this.yuvData=e,this.dataWidth=t,this.dataHeight=n,this.left=r,this.top=i,r+a>t||i+o>n)throw new l(`Crop rectangle does not fit within image data.`);s&&this.reverseHorizontal(a,o)}getRow(e,t){if(e<0||e>=this.getHeight())throw new l(`Requested row is outside the image: `+e);let n=this.getWidth();(t==null||t.length<n)&&(t=new Uint8ClampedArray(n));let r=(e+this.top)*this.dataWidth+this.left;return p.arraycopy(this.yuvData,r,t,0,n),t}getMatrix(){let e=this.getWidth(),t=this.getHeight();if(e===this.dataWidth&&t===this.dataHeight)return this.yuvData;let n=e*t,r=new Uint8ClampedArray(n),i=this.top*this.dataWidth+this.left;if(e===this.dataWidth)return p.arraycopy(this.yuvData,i,r,0,n),r;for(let n=0;n<t;n++){let t=n*e;p.arraycopy(this.yuvData,i,r,t,e),i+=this.dataWidth}return r}isCropSupported(){return!0}crop(e,t,n,r){return new zn(this.yuvData,this.dataWidth,this.dataHeight,this.left+e,this.top+t,n,r,!1)}renderThumbnail(){let e=this.getWidth()/zn.THUMBNAIL_SCALE_FACTOR,t=this.getHeight()/zn.THUMBNAIL_SCALE_FACTOR,n=new Int32Array(e*t),r=this.yuvData,i=this.top*this.dataWidth+this.left;for(let a=0;a<t;a++){let t=a*e;for(let a=0;a<e;a++){let e=r[i+a*zn.THUMBNAIL_SCALE_FACTOR]&255;n[t+a]=4278190080|e*65793}i+=this.dataWidth*zn.THUMBNAIL_SCALE_FACTOR}return n}getThumbnailWidth(){return this.getWidth()/zn.THUMBNAIL_SCALE_FACTOR}getThumbnailHeight(){return this.getHeight()/zn.THUMBNAIL_SCALE_FACTOR}reverseHorizontal(e,t){let n=this.yuvData;for(let r=0,i=this.top*this.dataWidth+this.left;r<t;r++,i+=this.dataWidth){let t=i+e/2;for(let r=i,a=i+e-1;r<t;r++,a--){let e=n[r];n[r]=n[a],n[a]=e}}}invert(){return new N(this)}}zn.THUMBNAIL_SCALE_FACTOR=2;class Bn extends M{constructor(e,t,n,r,i,a,o){if(super(t,n),this.dataWidth=r,this.dataHeight=i,this.left=a,this.top=o,e.BYTES_PER_ELEMENT===4){let r=t*n,i=new Uint8ClampedArray(r);for(let t=0;t<r;t++){let n=e[t],r=n>>16&255,a=n>>7&510,o=n&255;i[t]=(r+a+o)/4&255}this.luminances=i}else this.luminances=e;if(r===void 0&&(this.dataWidth=t),i===void 0&&(this.dataHeight=n),a===void 0&&(this.left=0),o===void 0&&(this.top=0),this.left+t>this.dataWidth||this.top+n>this.dataHeight)throw new l(`Crop rectangle does not fit within image data.`)}getRow(e,t){if(e<0||e>=this.getHeight())throw new l(`Requested row is outside the image: `+e);let n=this.getWidth();(t==null||t.length<n)&&(t=new Uint8ClampedArray(n));let r=(e+this.top)*this.dataWidth+this.left;return p.arraycopy(this.luminances,r,t,0,n),t}getMatrix(){let e=this.getWidth(),t=this.getHeight();if(e===this.dataWidth&&t===this.dataHeight)return this.luminances;let n=e*t,r=new Uint8ClampedArray(n),i=this.top*this.dataWidth+this.left;if(e===this.dataWidth)return p.arraycopy(this.luminances,i,r,0,n),r;for(let n=0;n<t;n++){let t=n*e;p.arraycopy(this.luminances,i,r,t,e),i+=this.dataWidth}return r}isCropSupported(){return!0}crop(e,t,n,r){return new Bn(this.luminances,n,r,this.dataWidth,this.dataHeight,this.left+e,this.top+t)}invert(){return new N(this)}}class Vn extends C{static forName(e){return this.getCharacterSetECIByName(e)}}class Hn{}Hn.ISO_8859_1=C.ISO8859_1;class Un{isCompact(){return this.compact}setCompact(e){this.compact=e}getSize(){return this.size}setSize(e){this.size=e}getLayers(){return this.layers}setLayers(e){this.layers=e}getCodeWords(){return this.codeWords}setCodeWords(e){this.codeWords=e}getMatrix(){return this.matrix}setMatrix(e){this.matrix=e}}class Wn{static singletonList(e){return[e]}static min(e,t){return e.sort(t)[0]}}class Gn{constructor(e){this.previous=e}getPrevious(){return this.previous}}class Kn extends Gn{constructor(e,t,n){super(e),this.value=t,this.bitCount=n}appendTo(e,t){e.appendBits(this.value,this.bitCount)}add(e,t){return new Kn(this,e,t)}addBinaryShift(e,t){return console.warn(`addBinaryShift on SimpleToken, this simply returns a copy of this token`),new Kn(this,e,t)}toString(){let e=this.value&(1<<this.bitCount)-1;return e|=1<<this.bitCount,`<`+_.toBinaryString(e|1<<this.bitCount).substring(1)+`>`}}class qn extends Kn{constructor(e,t,n){super(e,0,0),this.binaryShiftStart=t,this.binaryShiftByteCount=n}appendTo(e,t){for(let n=0;n<this.binaryShiftByteCount;n++)(n===0||n===31&&this.binaryShiftByteCount<=62)&&(e.appendBits(31,5),this.binaryShiftByteCount>62?e.appendBits(this.binaryShiftByteCount-31,16):n===0?e.appendBits(Math.min(this.binaryShiftByteCount,31),5):e.appendBits(this.binaryShiftByteCount-31,5)),e.appendBits(t[this.binaryShiftStart+n],8)}addBinaryShift(e,t){return new qn(this,e,t)}toString(){return`<`+this.binaryShiftStart+`::`+(this.binaryShiftStart+this.binaryShiftByteCount-1)+`>`}}function Jn(e,t,n){return new qn(e,t,n)}function Yn(e,t,n){return new Kn(e,t,n)}let Xn=[`UPPER`,`LOWER`,`DIGIT`,`MIXED`,`PUNCT`],Zn=new Kn(null,0,0),Qn=[Int32Array.from([0,327708,327710,327709,656318]),Int32Array.from([590318,0,327710,327709,656318]),Int32Array.from([262158,590300,0,590301,932798]),Int32Array.from([327709,327708,656318,0,327710]),Int32Array.from([327711,656380,656382,656381,0])];function $n(e){for(let t of e)g.fill(t,-1);return e[0][4]=0,e[1][4]=0,e[1][0]=28,e[3][4]=0,e[2][4]=0,e[2][0]=15,e}let er=$n(g.createInt32Array(6,6));class tr{constructor(e,t,n,r){this.token=e,this.mode=t,this.binaryShiftByteCount=n,this.bitCount=r}getMode(){return this.mode}getToken(){return this.token}getBinaryShiftByteCount(){return this.binaryShiftByteCount}getBitCount(){return this.bitCount}latchAndAppend(e,t){let n=this.bitCount,r=this.token;if(e!==this.mode){let t=Qn[this.mode][e];r=Yn(r,t&65535,t>>16),n+=t>>16}let i=e===2?4:5;return r=Yn(r,t,i),new tr(r,e,0,n+i)}shiftAndAppend(e,t){let n=this.token,r=this.mode===2?4:5;return n=Yn(n,er[this.mode][e],r),n=Yn(n,t,5),new tr(n,this.mode,0,this.bitCount+r+5)}addBinaryShiftChar(e){let t=this.token,n=this.mode,r=this.bitCount;if(this.mode===4||this.mode===2){let e=Qn[n][0];t=Yn(t,e&65535,e>>16),r+=e>>16,n=0}let i=this.binaryShiftByteCount===0||this.binaryShiftByteCount===31?18:this.binaryShiftByteCount===62?9:8,a=new tr(t,n,this.binaryShiftByteCount+1,r+i);return a.binaryShiftByteCount===2078&&(a=a.endBinaryShift(e+1)),a}endBinaryShift(e){if(this.binaryShiftByteCount===0)return this;let t=this.token;return t=Jn(t,e-this.binaryShiftByteCount,this.binaryShiftByteCount),new tr(t,this.mode,0,this.bitCount)}isBetterThanOrEqualTo(e){let t=this.bitCount+(Qn[this.mode][e.mode]>>16);return this.binaryShiftByteCount<e.binaryShiftByteCount?t+=tr.calculateBinaryShiftCost(e)-tr.calculateBinaryShiftCost(this):this.binaryShiftByteCount>e.binaryShiftByteCount&&e.binaryShiftByteCount>0&&(t+=10),t<=e.bitCount}toBitArray(e){let t=[];for(let n=this.endBinaryShift(e.length).token;n!==null;n=n.getPrevious())t.unshift(n);let n=new v;for(let r of t)r.appendTo(n,e);return n}toString(){return E.format(`%s bits=%d bytes=%d`,Xn[this.mode],this.bitCount,this.binaryShiftByteCount)}static calculateBinaryShiftCost(e){return e.binaryShiftByteCount>62?21:e.binaryShiftByteCount>31?20:e.binaryShiftByteCount>0?10:0}}tr.INITIAL_STATE=new tr(Zn,0,0,0);function nr(e){let t=E.getCharCode(` `),n=E.getCharCode(`.`),r=E.getCharCode(`,`);e[0][t]=1;let i=E.getCharCode(`Z`),a=E.getCharCode(`A`);for(let t=a;t<=i;t++)e[0][t]=t-a+2;e[1][t]=1;let o=E.getCharCode(`z`),s=E.getCharCode(`a`);for(let t=s;t<=o;t++)e[1][t]=t-s+2;e[2][t]=1;let c=E.getCharCode(`9`),l=E.getCharCode(`0`);for(let t=l;t<=c;t++)e[2][t]=t-l+2;e[2][r]=12,e[2][n]=13;let u=`\0 \x07\b
|
|
73
|
+
\v\f\r\x1B@\\^_\`|~`.split(``);for(let t=0;t<u.length;t++)e[3][E.getCharCode(u[t])]=t;let d=`\0\r\0\0\0\0!'#$%&'()*+,-./:;<=>?[]{}`.split(``);for(let t=0;t<d.length;t++)E.getCharCode(d[t])>0&&(e[4][E.getCharCode(d[t])]=t);return e}let rr=nr(g.createInt32Array(5,256));class ir{constructor(e){this.text=e}encode(){let e=E.getCharCode(` `),t=E.getCharCode(`
|
|
74
|
+
`),n=Wn.singletonList(tr.INITIAL_STATE);for(let r=0;r<this.text.length;r++){let i,a=r+1<this.text.length?this.text[r+1]:0;switch(this.text[r]){case E.getCharCode(`\r`):i=a===t?2:0;break;case E.getCharCode(`.`):i=a===e?3:0;break;case E.getCharCode(`,`):i=a===e?4:0;break;case E.getCharCode(`:`):i=a===e?5:0;break;default:i=0}i>0?(n=ir.updateStateListForPair(n,r,i),r++):n=this.updateStateListForChar(n,r)}return Wn.min(n,(e,t)=>e.getBitCount()-t.getBitCount()).toBitArray(this.text)}updateStateListForChar(e,t){let n=[];for(let r of e)this.updateStateForChar(r,t,n);return ir.simplifyStates(n)}updateStateForChar(e,t,n){let r=this.text[t]&255,i=rr[e.getMode()][r]>0,a=null;for(let o=0;o<=4;o++){let s=rr[o][r];if(s>0){if(a??=e.endBinaryShift(t),!i||o===e.getMode()||o===2){let e=a.latchAndAppend(o,s);n.push(e)}if(!i&&er[e.getMode()][o]>=0){let e=a.shiftAndAppend(o,s);n.push(e)}}}if(e.getBinaryShiftByteCount()>0||rr[e.getMode()][r]===0){let r=e.addBinaryShiftChar(t);n.push(r)}}static updateStateListForPair(e,t,n){let r=[];for(let i of e)this.updateStateForPair(i,t,n,r);return this.simplifyStates(r)}static updateStateForPair(e,t,n,r){let i=e.endBinaryShift(t);if(r.push(i.latchAndAppend(4,n)),e.getMode()!==4&&r.push(i.shiftAndAppend(4,n)),n===3||n===4){let e=i.latchAndAppend(2,16-n).latchAndAppend(2,1);r.push(e)}if(e.getBinaryShiftByteCount()>0){let n=e.addBinaryShiftChar(t).addBinaryShiftChar(t+1);r.push(n)}}static simplifyStates(e){let t=[];for(let n of e){let e=!0;for(let r of t){if(r.isBetterThanOrEqualTo(n)){e=!1;break}n.isBetterThanOrEqualTo(r)&&(t=t.filter(e=>e!==r))}e&&t.push(n)}return t}}class ar{constructor(){}static encodeBytes(e){return ar.encode(e,ar.DEFAULT_EC_PERCENT,ar.DEFAULT_AZTEC_LAYERS)}static encode(e,t,n){let r=new ir(e).encode(),i=_.truncDivision(r.getSize()*t,100)+11,a=r.getSize()+i,o,s,c,u,d;if(n!==ar.DEFAULT_AZTEC_LAYERS){if(o=n<0,s=Math.abs(n),s>(o?ar.MAX_NB_BITS_COMPACT:ar.MAX_NB_BITS))throw new l(E.format(`Illegal value %s for layers`,n));c=ar.totalBitsInLayer(s,o),u=ar.WORD_SIZE[s];let e=c-c%u;if(d=ar.stuffBits(r,u),d.getSize()+i>e||o&&d.getSize()>u*64)throw new l(`Data to large for user specified layer`)}else{u=0,d=null;for(let e=0;;e++){if(e>ar.MAX_NB_BITS)throw new l(`Data too large for an Aztec code`);if(o=e<=3,s=o?e+1:e,c=ar.totalBitsInLayer(s,o),a>c)continue;(d==null||u!==ar.WORD_SIZE[s])&&(u=ar.WORD_SIZE[s],d=ar.stuffBits(r,u));let t=c-c%u;if(!(o&&d.getSize()>u*64)&&d.getSize()+i<=t)break}}let f=ar.generateCheckWords(d,c,u),p=d.getSize()/u,m=ar.generateModeMessage(o,s,p),h=(o?11:14)+s*4,g=new Int32Array(h),v;if(o){v=h;for(let e=0;e<g.length;e++)g[e]=e}else{v=h+1+2*_.truncDivision(_.truncDivision(h,2)-1,15);let e=_.truncDivision(h,2),t=_.truncDivision(v,2);for(let n=0;n<e;n++){let r=n+_.truncDivision(n,15);g[e-n-1]=t-r-1,g[e+n]=t+r+1}}let y=new O(v);for(let e=0,t=0;e<s;e++){let n=(s-e)*4+(o?9:12);for(let r=0;r<n;r++){let i=r*2;for(let a=0;a<2;a++)f.get(t+i+a)&&y.set(g[e*2+a],g[e*2+r]),f.get(t+n*2+i+a)&&y.set(g[e*2+r],g[h-1-e*2-a]),f.get(t+n*4+i+a)&&y.set(g[h-1-e*2-a],g[h-1-e*2-r]),f.get(t+n*6+i+a)&&y.set(g[h-1-e*2-r],g[e*2+a])}t+=n*8}if(ar.drawModeMessage(y,o,v,m),o)ar.drawBullsEye(y,_.truncDivision(v,2),5);else{ar.drawBullsEye(y,_.truncDivision(v,2),7);for(let e=0,t=0;e<_.truncDivision(h,2)-1;e+=15,t+=16)for(let e=_.truncDivision(v,2)&1;e<v;e+=2)y.set(_.truncDivision(v,2)-t,e),y.set(_.truncDivision(v,2)+t,e),y.set(e,_.truncDivision(v,2)-t),y.set(e,_.truncDivision(v,2)+t)}let b=new Un;return b.setCompact(o),b.setSize(v),b.setLayers(s),b.setCodeWords(p),b.setMatrix(y),b}static drawBullsEye(e,t,n){for(let r=0;r<n;r+=2)for(let n=t-r;n<=t+r;n++)e.set(n,t-r),e.set(n,t+r),e.set(t-r,n),e.set(t+r,n);e.set(t-n,t-n),e.set(t-n+1,t-n),e.set(t-n,t-n+1),e.set(t+n,t-n),e.set(t+n,t-n+1),e.set(t+n,t+n-1)}static generateModeMessage(e,t,n){let r=new v;return e?(r.appendBits(t-1,2),r.appendBits(n-1,6),r=ar.generateCheckWords(r,28,4)):(r.appendBits(t-1,5),r.appendBits(n-1,11),r=ar.generateCheckWords(r,40,4)),r}static drawModeMessage(e,t,n,r){let i=_.truncDivision(n,2);if(t)for(let t=0;t<7;t++){let n=i-3+t;r.get(t)&&e.set(n,i-5),r.get(t+7)&&e.set(i+5,n),r.get(20-t)&&e.set(n,i+5),r.get(27-t)&&e.set(i-5,n)}else for(let t=0;t<10;t++){let n=i-5+t+_.truncDivision(t,5);r.get(t)&&e.set(n,i-7),r.get(t+10)&&e.set(i+7,n),r.get(29-t)&&e.set(n,i+7),r.get(39-t)&&e.set(i-7,n)}}static generateCheckWords(e,t,n){let r=e.getSize()/n,i=new On(ar.getGF(n)),a=_.truncDivision(t,n),o=ar.bitsToWords(e,n,a);i.encode(o,a-r);let s=t%n,c=new v;c.appendBits(0,s);for(let e of Array.from(o))c.appendBits(e,n);return c}static bitsToWords(e,t,n){let r=new Int32Array(n),i,a;for(i=0,a=e.getSize()/t;i<a;i++){let n=0;for(let r=0;r<t;r++)n|=e.get(i*t+r)?1<<t-r-1:0;r[i]=n}return r}static getGF(e){switch(e){case 4:return oe.AZTEC_PARAM;case 6:return oe.AZTEC_DATA_6;case 8:return oe.AZTEC_DATA_8;case 10:return oe.AZTEC_DATA_10;case 12:return oe.AZTEC_DATA_12;default:throw new l(`Unsupported word size `+e)}}static stuffBits(e,t){let n=new v,r=e.getSize(),i=(1<<t)-2;for(let a=0;a<r;a+=t){let o=0;for(let n=0;n<t;n++)(a+n>=r||e.get(a+n))&&(o|=1<<t-1-n);(o&i)===i?(n.appendBits(o&i,t),a--):(o&i)===0?(n.appendBits(o|1,t),a--):n.appendBits(o,t)}return n}static totalBitsInLayer(e,t){return((t?88:112)+16*e)*e}}ar.DEFAULT_EC_PERCENT=33,ar.DEFAULT_AZTEC_LAYERS=0,ar.MAX_NB_BITS=32,ar.MAX_NB_BITS_COMPACT=4,ar.WORD_SIZE=Int32Array.from([4,6,6,8,8,8,8,8,8,10,10,10,10,10,10,10,10,10,10,10,10,10,10,12,12,12,12,12,12,12,12,12,12]);class or{encode(e,t,n,r){return this.encodeWithHints(e,t,n,r,null)}encodeWithHints(e,t,n,r,i){let a=Hn.ISO_8859_1,o=ar.DEFAULT_EC_PERCENT,s=ar.DEFAULT_AZTEC_LAYERS;return i!=null&&(i.has(Dn.CHARACTER_SET)&&(a=Vn.forName(i.get(Dn.CHARACTER_SET).toString())),i.has(Dn.ERROR_CORRECTION)&&(o=_.parseInt(i.get(Dn.ERROR_CORRECTION).toString())),i.has(Dn.AZTEC_LAYERS)&&(s=_.parseInt(i.get(Dn.AZTEC_LAYERS).toString()))),or.encodeLayers(e,t,n,r,a,o,s)}static encodeLayers(e,t,n,r,i,a,o){if(t!==B.AZTEC)throw new l(`Can only encode AZTEC, but got `+t);let s=ar.encode(E.getBytes(e,i),a,o);return or.renderResult(s,n,r)}static renderResult(e,t,n){let r=e.getMatrix();if(r==null)throw new ce;let i=r.getWidth(),a=r.getHeight(),o=Math.max(t,i),s=Math.max(n,a),c=Math.min(o/i,s/a),l=(o-i*c)/2,u=(s-a*c)/2,d=new O(o,s);for(let e=0,t=u;e<a;e++,t+=c)for(let n=0,a=l;n<i;n++,a+=c)r.get(n,e)&&d.setRegion(a,t,c,c);return d}}e.AbstractExpandedDecoder=Xe,e.ArgumentException=c,e.ArithmeticException=ae,e.AztecCode=Un,e.AztecCodeReader=Ce,e.AztecCodeWriter=or,e.AztecDecoder=de,e.AztecDetector=Se,e.AztecDetectorResult=he,e.AztecEncoder=ar,e.AztecHighLevelEncoder=ir,e.AztecPoint=xe,e.BarcodeFormat=B,e.Binarizer=f,e.BinaryBitmap=u,e.BitArray=v,e.BitMatrix=O,e.BitSource=yt,e.BrowserAztecCodeReader=we,e.BrowserBarcodeReader=pt,e.BrowserCodeReader=L,e.BrowserDatamatrixCodeReader=Tt,e.BrowserMultiFormatReader=Cn,e.BrowserPDF417Reader=wn,e.BrowserQRCodeReader=Tn,e.BrowserQRCodeSvgWriter=In,e.CharacterSetECI=C,e.ChecksumException=d,e.Code128Reader=H,e.Code39Reader=Ee,e.DataMatrixDecodedBitStreamParser=xt,e.DataMatrixReader=wt,e.DecodeHintType=b,e.DecoderResult=ne,e.DefaultGridSampler=ye,e.DetectorResult=me,e.EAN13Reader=Ne,e.EncodeHintType=Dn,e.Exception=s,e.FormatException=x,e.GenericGF=oe,e.GenericGFPoly=ie,e.GlobalHistogramBinarizer=A,e.GridSampler=_e,e.GridSamplerInstance=be,e.HTMLCanvasElementLuminanceSource=P,e.HybridBinarizer=j,e.ITFReader=De,e.IllegalArgumentException=l,e.IllegalStateException=ce,e.InvertedLuminanceSource=N,e.LuminanceSource=M,e.MathUtils=fe,e.MultiFormatOneDReader=ft,e.MultiFormatReader=Sn,e.MultiFormatWriter=Rn,e.NotFoundException=k,e.OneDReader=Te,e.PDF417DecodedBitStreamParser=q,e.PDF417DecoderErrorCorrection=K,e.PDF417Reader=bn,e.PDF417ResultMetadata=cn,e.PerspectiveTransform=ve,e.PlanarYUVLuminanceSource=zn,e.QRCodeByteMatrix=An,e.QRCodeDataMask=jt,e.QRCodeDecodedBitStreamParser=It,e.QRCodeDecoderErrorCorrectionLevel=Dt,e.QRCodeDecoderFormatInformation=Ot,e.QRCodeEncoder=Fn,e.QRCodeEncoderQRCode=jn,e.QRCodeMaskUtil=kn,e.QRCodeMatrixUtil=Nn,e.QRCodeMode=Ft,e.QRCodeReader=Gt,e.QRCodeVersion=kt,e.QRCodeWriter=Ln,e.RGBLuminanceSource=Bn,e.RSS14Reader=dt,e.RSSExpandedReader=U,e.ReaderException=xn,e.ReedSolomonDecoder=le,e.ReedSolomonEncoder=On,e.ReedSolomonException=se,e.Result=R,e.ResultMetadataType=te,e.ResultPoint=V,e.StringUtils=E,e.UnsupportedOperationException=w,e.VideoInputDevice=F,e.WhiteRectangleDetector=ge,e.WriterException=Mn,e.ZXingArrays=g,e.ZXingCharset=Vn,e.ZXingInteger=_,e.ZXingStandardCharsets=Hn,e.ZXingStringBuilder=D,e.ZXingStringEncoding=T,e.ZXingSystem=p,e.createAbstractExpandedDecoder=st,Object.defineProperty(e,"__esModule",{value:!0})}))}))()),oC=function(){function e(e,t,n){if(this.formatMap=new Map([[HS.QR_CODE,aC.BarcodeFormat.QR_CODE],[HS.AZTEC,aC.BarcodeFormat.AZTEC],[HS.CODABAR,aC.BarcodeFormat.CODABAR],[HS.CODE_39,aC.BarcodeFormat.CODE_39],[HS.CODE_93,aC.BarcodeFormat.CODE_93],[HS.CODE_128,aC.BarcodeFormat.CODE_128],[HS.DATA_MATRIX,aC.BarcodeFormat.DATA_MATRIX],[HS.MAXICODE,aC.BarcodeFormat.MAXICODE],[HS.ITF,aC.BarcodeFormat.ITF],[HS.EAN_13,aC.BarcodeFormat.EAN_13],[HS.EAN_8,aC.BarcodeFormat.EAN_8],[HS.PDF_417,aC.BarcodeFormat.PDF_417],[HS.RSS_14,aC.BarcodeFormat.RSS_14],[HS.RSS_EXPANDED,aC.BarcodeFormat.RSS_EXPANDED],[HS.UPC_A,aC.BarcodeFormat.UPC_A],[HS.UPC_E,aC.BarcodeFormat.UPC_E],[HS.UPC_EAN_EXTENSION,aC.BarcodeFormat.UPC_EAN_EXTENSION]]),this.reverseFormatMap=this.createReverseFormatMap(),!aC)throw`Use html5qrcode.min.js without edit, ZXing not found.`;this.verbose=t,this.logger=n;var r=this.createZXingFormats(e),i=new Map;i.set(aC.DecodeHintType.POSSIBLE_FORMATS,r),i.set(aC.DecodeHintType.TRY_HARDER,!1),this.hints=i}return e.prototype.decodeAsync=function(e){var t=this;return new Promise(function(n,r){try{n(t.decode(e))}catch(e){r(e)}})},e.prototype.decode=function(e){var t=new aC.MultiFormatReader(this.verbose,this.hints),n=new aC.HTMLCanvasElementLuminanceSource(e),r=new aC.BinaryBitmap(new aC.HybridBinarizer(n)),i=t.decode(r);return{text:i.text,format:JS.create(this.toHtml5QrcodeSupportedFormats(i.format)),debugData:this.createDebugData()}},e.prototype.createReverseFormatMap=function(){var e=new Map;return this.formatMap.forEach(function(t,n,r){e.set(t,n)}),e},e.prototype.toHtml5QrcodeSupportedFormats=function(e){if(!this.reverseFormatMap.has(e))throw`reverseFormatMap doesn't have ${e}`;return this.reverseFormatMap.get(e)},e.prototype.createZXingFormats=function(e){for(var t=[],n=0,r=e;n<r.length;n++){var i=r[n];this.formatMap.has(i)?t.push(this.formatMap.get(i)):this.logger.logError(`${i} is not supported byZXingHtml5QrcodeShim`)}return t},e.prototype.createDebugData=function(){return{decoderName:`zxing-js`}},e}(),sC=function(e,t,n,r){function i(e){return e instanceof n?e:new n(function(t){t(e)})}return new(n||=Promise)(function(n,a){function o(e){try{c(r.next(e))}catch(e){a(e)}}function s(e){try{c(r.throw(e))}catch(e){a(e)}}function c(e){e.done?n(e.value):i(e.value).then(o,s)}c((r=r.apply(e,t||[])).next())})},cC=function(e,t){var n={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},r,i,a,o;return o={next:s(0),throw:s(1),return:s(2)},typeof Symbol==`function`&&(o[Symbol.iterator]=function(){return this}),o;function s(e){return function(t){return c([e,t])}}function c(s){if(r)throw TypeError(`Generator is already executing.`);for(;o&&(o=0,s[0]&&(n=0)),n;)try{if(r=1,i&&(a=s[0]&2?i.return:s[0]?i.throw||((a=i.return)&&a.call(i),0):i.next)&&!(a=a.call(i,s[1])).done)return a;switch(i=0,a&&(s=[s[0]&2,a.value]),s[0]){case 0:case 1:a=s;break;case 4:return n.label++,{value:s[1],done:!1};case 5:n.label++,i=s[1],s=[0];continue;case 7:s=n.ops.pop(),n.trys.pop();continue;default:if((a=n.trys,!(a=a.length>0&&a[a.length-1]))&&(s[0]===6||s[0]===2)){n=0;continue}if(s[0]===3&&(!a||s[1]>a[0]&&s[1]<a[3])){n.label=s[1];break}if(s[0]===6&&n.label<a[1]){n.label=a[1],a=s;break}if(a&&n.label<a[2]){n.label=a[2],n.ops.push(s);break}a[2]&&n.ops.pop(),n.trys.pop();continue}s=t.call(e,n)}catch(e){s=[6,e],i=0}finally{r=a=0}if(s[0]&5)throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}},lC=function(){function e(t,n,r){if(this.formatMap=new Map([[HS.QR_CODE,`qr_code`],[HS.AZTEC,`aztec`],[HS.CODABAR,`codabar`],[HS.CODE_39,`code_39`],[HS.CODE_93,`code_93`],[HS.CODE_128,`code_128`],[HS.DATA_MATRIX,`data_matrix`],[HS.ITF,`itf`],[HS.EAN_13,`ean_13`],[HS.EAN_8,`ean_8`],[HS.PDF_417,`pdf417`],[HS.UPC_A,`upc_a`],[HS.UPC_E,`upc_e`]]),this.reverseFormatMap=this.createReverseFormatMap(),!e.isSupported())throw`Use html5qrcode.min.js without edit, Use BarcodeDetectorDelegate only if it isSupported();`;this.verbose=n,this.logger=r;var i=this.createBarcodeDetectorFormats(t);if(this.detector=new BarcodeDetector(i),!this.detector)throw`BarcodeDetector detector not supported`}return e.isSupported=function(){return`BarcodeDetector`in window?new BarcodeDetector({formats:[`qr_code`]})!==void 0:!1},e.prototype.decodeAsync=function(e){return sC(this,void 0,void 0,function(){var t,n;return cC(this,function(r){switch(r.label){case 0:return[4,this.detector.detect(e)];case 1:if(t=r.sent(),!t||t.length===0)throw`No barcode or QR code detected.`;return n=this.selectLargestBarcode(t),[2,{text:n.rawValue,format:JS.create(this.toHtml5QrcodeSupportedFormats(n.format)),debugData:this.createDebugData()}]}})})},e.prototype.selectLargestBarcode=function(e){for(var t=null,n=0,r=0,i=e;r<i.length;r++){var a=i[r],o=a.boundingBox.width*a.boundingBox.height;o>n&&(n=o,t=a)}if(!t)throw`No largest barcode found`;return t},e.prototype.createBarcodeDetectorFormats=function(e){for(var t=[],n=0,r=e;n<r.length;n++){var i=r[n];this.formatMap.has(i)?t.push(this.formatMap.get(i)):this.logger.warn(`${i} is not supported byBarcodeDetectorDelegate`)}return{formats:t}},e.prototype.toHtml5QrcodeSupportedFormats=function(e){if(!this.reverseFormatMap.has(e))throw`reverseFormatMap doesn't have ${e}`;return this.reverseFormatMap.get(e)},e.prototype.createReverseFormatMap=function(){var e=new Map;return this.formatMap.forEach(function(t,n,r){e.set(t,n)}),e},e.prototype.createDebugData=function(){return{decoderName:`BarcodeDetector`}},e}(),uC=function(e,t,n,r){function i(e){return e instanceof n?e:new n(function(t){t(e)})}return new(n||=Promise)(function(n,a){function o(e){try{c(r.next(e))}catch(e){a(e)}}function s(e){try{c(r.throw(e))}catch(e){a(e)}}function c(e){e.done?n(e.value):i(e.value).then(o,s)}c((r=r.apply(e,t||[])).next())})},dC=function(e,t){var n={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},r,i,a,o;return o={next:s(0),throw:s(1),return:s(2)},typeof Symbol==`function`&&(o[Symbol.iterator]=function(){return this}),o;function s(e){return function(t){return c([e,t])}}function c(s){if(r)throw TypeError(`Generator is already executing.`);for(;o&&(o=0,s[0]&&(n=0)),n;)try{if(r=1,i&&(a=s[0]&2?i.return:s[0]?i.throw||((a=i.return)&&a.call(i),0):i.next)&&!(a=a.call(i,s[1])).done)return a;switch(i=0,a&&(s=[s[0]&2,a.value]),s[0]){case 0:case 1:a=s;break;case 4:return n.label++,{value:s[1],done:!1};case 5:n.label++,i=s[1],s=[0];continue;case 7:s=n.ops.pop(),n.trys.pop();continue;default:if((a=n.trys,!(a=a.length>0&&a[a.length-1]))&&(s[0]===6||s[0]===2)){n=0;continue}if(s[0]===3&&(!a||s[1]>a[0]&&s[1]<a[3])){n.label=s[1];break}if(s[0]===6&&n.label<a[1]){n.label=a[1],a=s;break}if(a&&n.label<a[2]){n.label=a[2],n.ops.push(s);break}a[2]&&n.ops.pop(),n.trys.pop();continue}s=t.call(e,n)}catch(e){s=[6,e],i=0}finally{r=a=0}if(s[0]&5)throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}},fC=function(){function e(e,t,n,r){this.EXECUTIONS_TO_REPORT_PERFORMANCE=100,this.executions=0,this.executionResults=[],this.wasPrimaryDecoderUsedInLastDecode=!1,this.verbose=n,t&&lC.isSupported()?(this.primaryDecoder=new lC(e,n,r),this.secondaryDecoder=new oC(e,n,r)):this.primaryDecoder=new oC(e,n,r)}return e.prototype.decodeAsync=function(e){return uC(this,void 0,void 0,function(){var t;return dC(this,function(n){switch(n.label){case 0:t=performance.now(),n.label=1;case 1:return n.trys.push([1,,3,4]),[4,this.getDecoder().decodeAsync(e)];case 2:return[2,n.sent()];case 3:return this.possiblyLogPerformance(t),[7];case 4:return[2]}})})},e.prototype.decodeRobustlyAsync=function(e){return uC(this,void 0,void 0,function(){var t,n;return dC(this,function(r){switch(r.label){case 0:t=performance.now(),r.label=1;case 1:return r.trys.push([1,3,4,5]),[4,this.primaryDecoder.decodeAsync(e)];case 2:return[2,r.sent()];case 3:if(n=r.sent(),this.secondaryDecoder)return[2,this.secondaryDecoder.decodeAsync(e)];throw n;case 4:return this.possiblyLogPerformance(t),[7];case 5:return[2]}})})},e.prototype.getDecoder=function(){return this.secondaryDecoder?this.wasPrimaryDecoderUsedInLastDecode===!1?(this.wasPrimaryDecoderUsedInLastDecode=!0,this.primaryDecoder):(this.wasPrimaryDecoderUsedInLastDecode=!1,this.secondaryDecoder):this.primaryDecoder},e.prototype.possiblyLogPerformance=function(e){if(this.verbose){var t=performance.now()-e;this.executionResults.push(t),this.executions++,this.possiblyFlushPerformanceReport()}},e.prototype.possiblyFlushPerformanceReport=function(){if(!(this.executions<this.EXECUTIONS_TO_REPORT_PERFORMANCE)){for(var e=0,t=0,n=this.executionResults;t<n.length;t++){var r=n[t];e+=r}var i=e/this.executionResults.length;console.log(`${i} ms for ${this.executionResults.length} last runs.`),this.executions=0,this.executionResults=[]}},e}(),pC=(function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};return function(t,n){if(typeof n!=`function`&&n!==null)throw TypeError(`Class extends value `+String(n)+` is not a constructor or null`);e(t,n);function r(){this.constructor=t}t.prototype=n===null?Object.create(n):(r.prototype=n.prototype,new r)}})(),mC=function(e,t,n,r){function i(e){return e instanceof n?e:new n(function(t){t(e)})}return new(n||=Promise)(function(n,a){function o(e){try{c(r.next(e))}catch(e){a(e)}}function s(e){try{c(r.throw(e))}catch(e){a(e)}}function c(e){e.done?n(e.value):i(e.value).then(o,s)}c((r=r.apply(e,t||[])).next())})},hC=function(e,t){var n={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},r,i,a,o;return o={next:s(0),throw:s(1),return:s(2)},typeof Symbol==`function`&&(o[Symbol.iterator]=function(){return this}),o;function s(e){return function(t){return c([e,t])}}function c(s){if(r)throw TypeError(`Generator is already executing.`);for(;o&&(o=0,s[0]&&(n=0)),n;)try{if(r=1,i&&(a=s[0]&2?i.return:s[0]?i.throw||((a=i.return)&&a.call(i),0):i.next)&&!(a=a.call(i,s[1])).done)return a;switch(i=0,a&&(s=[s[0]&2,a.value]),s[0]){case 0:case 1:a=s;break;case 4:return n.label++,{value:s[1],done:!1};case 5:n.label++,i=s[1],s=[0];continue;case 7:s=n.ops.pop(),n.trys.pop();continue;default:if((a=n.trys,!(a=a.length>0&&a[a.length-1]))&&(s[0]===6||s[0]===2)){n=0;continue}if(s[0]===3&&(!a||s[1]>a[0]&&s[1]<a[3])){n.label=s[1];break}if(s[0]===6&&n.label<a[1]){n.label=a[1],a=s;break}if(a&&n.label<a[2]){n.label=a[2],n.ops.push(s);break}a[2]&&n.ops.pop(),n.trys.pop();continue}s=t.call(e,n)}catch(e){s=[6,e],i=0}finally{r=a=0}if(s[0]&5)throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}},gC=function(){function e(e,t){this.name=e,this.track=t}return e.prototype.isSupported=function(){return this.track.getCapabilities?this.name in this.track.getCapabilities():!1},e.prototype.apply=function(e){var t={};t[this.name]=e;var n={advanced:[t]};return this.track.applyConstraints(n)},e.prototype.value=function(){var e=this.track.getSettings();return this.name in e?e[this.name]:null},e}(),_C=function(e){pC(t,e);function t(t){return e.call(this,`zoom`,t)||this}return t}(function(e){pC(t,e);function t(t,n){return e.call(this,t,n)||this}return t.prototype.min=function(){return this.getCapabilities().min},t.prototype.max=function(){return this.getCapabilities().max},t.prototype.step=function(){return this.getCapabilities().step},t.prototype.apply=function(e){var t={};t[this.name]=e;var n={advanced:[t]};return this.track.applyConstraints(n)},t.prototype.getCapabilities=function(){this.failIfNotSupported();var e=this.track.getCapabilities()[this.name];return{min:e.min,max:e.max,step:e.step}},t.prototype.failIfNotSupported=function(){if(!this.isSupported())throw Error(`${this.name} capability not supported`)},t}(gC)),vC=function(e){pC(t,e);function t(t){return e.call(this,`torch`,t)||this}return t}(gC),yC=function(){function e(e){this.track=e}return e.prototype.zoomFeature=function(){return new _C(this.track)},e.prototype.torchFeature=function(){return new vC(this.track)},e}(),bC=function(){function e(e,t,n){this.isClosed=!1,this.parentElement=e,this.mediaStream=t,this.callbacks=n,this.surface=this.createVideoElement(this.parentElement.clientWidth),e.append(this.surface)}return e.prototype.createVideoElement=function(e){var t=document.createElement(`video`);return t.style.width=`${e}px`,t.style.display=`block`,t.muted=!0,t.setAttribute(`muted`,`true`),t.playsInline=!0,t},e.prototype.setupSurface=function(){var e=this;this.surface.onabort=function(){throw`RenderedCameraImpl video surface onabort() called`},this.surface.onerror=function(){throw`RenderedCameraImpl video surface onerror() called`};var t=function(){var n=e.surface.clientWidth,r=e.surface.clientHeight;e.callbacks.onRenderSurfaceReady(n,r),e.surface.removeEventListener(`playing`,t)};this.surface.addEventListener(`playing`,t),this.surface.srcObject=this.mediaStream,this.surface.play()},e.create=function(t,n,r,i){return mC(this,void 0,void 0,function(){var a,o;return hC(this,function(s){switch(s.label){case 0:return a=new e(t,n,i),r.aspectRatio?(o={aspectRatio:r.aspectRatio},[4,a.getFirstTrackOrFail().applyConstraints(o)]):[3,2];case 1:s.sent(),s.label=2;case 2:return a.setupSurface(),[2,a]}})})},e.prototype.failIfClosed=function(){if(this.isClosed)throw`The RenderedCamera has already been closed.`},e.prototype.getFirstTrackOrFail=function(){if(this.failIfClosed(),this.mediaStream.getVideoTracks().length===0)throw`No video tracks found`;return this.mediaStream.getVideoTracks()[0]},e.prototype.pause=function(){this.failIfClosed(),this.surface.pause()},e.prototype.resume=function(e){this.failIfClosed();var t=this,n=function(){setTimeout(e,200),t.surface.removeEventListener(`playing`,n)};this.surface.addEventListener(`playing`,n),this.surface.play()},e.prototype.isPaused=function(){return this.failIfClosed(),this.surface.paused},e.prototype.getSurface=function(){return this.failIfClosed(),this.surface},e.prototype.getRunningTrackCapabilities=function(){return this.getFirstTrackOrFail().getCapabilities()},e.prototype.getRunningTrackSettings=function(){return this.getFirstTrackOrFail().getSettings()},e.prototype.applyVideoConstraints=function(e){return mC(this,void 0,void 0,function(){return hC(this,function(t){if(`aspectRatio`in e)throw`Changing 'aspectRatio' in run-time is not yet supported.`;return[2,this.getFirstTrackOrFail().applyConstraints(e)]})})},e.prototype.close=function(){if(this.isClosed)return Promise.resolve();var e=this;return new Promise(function(t,n){var r=e.mediaStream.getVideoTracks().length,i=0;e.mediaStream.getVideoTracks().forEach(function(n){e.mediaStream.removeTrack(n),n.stop(),++i,i>=r&&(e.isClosed=!0,e.parentElement.removeChild(e.surface),t())})})},e.prototype.getCapabilities=function(){return new yC(this.getFirstTrackOrFail())},e}(),xC=function(){function e(e){this.mediaStream=e}return e.prototype.render=function(e,t,n){return mC(this,void 0,void 0,function(){return hC(this,function(r){return[2,bC.create(e,this.mediaStream,t,n)]})})},e.create=function(t){return mC(this,void 0,void 0,function(){var n,r;return hC(this,function(i){switch(i.label){case 0:if(!navigator.mediaDevices)throw`navigator.mediaDevices not supported`;return n={audio:!1,video:t},[4,navigator.mediaDevices.getUserMedia(n)];case 1:return r=i.sent(),[2,new e(r)]}})})},e}(),SC=function(e,t,n,r){function i(e){return e instanceof n?e:new n(function(t){t(e)})}return new(n||=Promise)(function(n,a){function o(e){try{c(r.next(e))}catch(e){a(e)}}function s(e){try{c(r.throw(e))}catch(e){a(e)}}function c(e){e.done?n(e.value):i(e.value).then(o,s)}c((r=r.apply(e,t||[])).next())})},CC=function(e,t){var n={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},r,i,a,o;return o={next:s(0),throw:s(1),return:s(2)},typeof Symbol==`function`&&(o[Symbol.iterator]=function(){return this}),o;function s(e){return function(t){return c([e,t])}}function c(s){if(r)throw TypeError(`Generator is already executing.`);for(;o&&(o=0,s[0]&&(n=0)),n;)try{if(r=1,i&&(a=s[0]&2?i.return:s[0]?i.throw||((a=i.return)&&a.call(i),0):i.next)&&!(a=a.call(i,s[1])).done)return a;switch(i=0,a&&(s=[s[0]&2,a.value]),s[0]){case 0:case 1:a=s;break;case 4:return n.label++,{value:s[1],done:!1};case 5:n.label++,i=s[1],s=[0];continue;case 7:s=n.ops.pop(),n.trys.pop();continue;default:if((a=n.trys,!(a=a.length>0&&a[a.length-1]))&&(s[0]===6||s[0]===2)){n=0;continue}if(s[0]===3&&(!a||s[1]>a[0]&&s[1]<a[3])){n.label=s[1];break}if(s[0]===6&&n.label<a[1]){n.label=a[1],a=s;break}if(a&&n.label<a[2]){n.label=a[2],n.ops.push(s);break}a[2]&&n.ops.pop(),n.trys.pop();continue}s=t.call(e,n)}catch(e){s=[6,e],i=0}finally{r=a=0}if(s[0]&5)throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}},wC=function(){function e(){}return e.failIfNotSupported=function(){return SC(this,void 0,void 0,function(){return CC(this,function(t){if(!navigator.mediaDevices)throw`navigator.mediaDevices not supported`;return[2,new e]})})},e.prototype.create=function(e){return SC(this,void 0,void 0,function(){return CC(this,function(t){return[2,xC.create(e)]})})},e}(),TC=function(e,t,n,r){function i(e){return e instanceof n?e:new n(function(t){t(e)})}return new(n||=Promise)(function(n,a){function o(e){try{c(r.next(e))}catch(e){a(e)}}function s(e){try{c(r.throw(e))}catch(e){a(e)}}function c(e){e.done?n(e.value):i(e.value).then(o,s)}c((r=r.apply(e,t||[])).next())})},EC=function(e,t){var n={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},r,i,a,o;return o={next:s(0),throw:s(1),return:s(2)},typeof Symbol==`function`&&(o[Symbol.iterator]=function(){return this}),o;function s(e){return function(t){return c([e,t])}}function c(s){if(r)throw TypeError(`Generator is already executing.`);for(;o&&(o=0,s[0]&&(n=0)),n;)try{if(r=1,i&&(a=s[0]&2?i.return:s[0]?i.throw||((a=i.return)&&a.call(i),0):i.next)&&!(a=a.call(i,s[1])).done)return a;switch(i=0,a&&(s=[s[0]&2,a.value]),s[0]){case 0:case 1:a=s;break;case 4:return n.label++,{value:s[1],done:!1};case 5:n.label++,i=s[1],s=[0];continue;case 7:s=n.ops.pop(),n.trys.pop();continue;default:if((a=n.trys,!(a=a.length>0&&a[a.length-1]))&&(s[0]===6||s[0]===2)){n=0;continue}if(s[0]===3&&(!a||s[1]>a[0]&&s[1]<a[3])){n.label=s[1];break}if(s[0]===6&&n.label<a[1]){n.label=a[1],a=s;break}if(a&&n.label<a[2]){n.label=a[2],n.ops.push(s);break}a[2]&&n.ops.pop(),n.trys.pop();continue}s=t.call(e,n)}catch(e){s=[6,e],i=0}finally{r=a=0}if(s[0]&5)throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}},DC=function(){function e(){}return e.retrieve=function(){return navigator.mediaDevices?e.getCamerasFromMediaDevices():MediaStreamTrack&&MediaStreamTrack.getSources?e.getCamerasFromMediaStreamTrack():e.rejectWithError()},e.rejectWithError=function(){var t=tC.unableToQuerySupportedDevices();return e.isHttpsOrLocalhost()||(t=tC.insecureContextCameraQueryError()),Promise.reject(t)},e.isHttpsOrLocalhost=function(){if(location.protocol===`https:`)return!0;var e=location.host.split(`:`)[0];return e===`127.0.0.1`||e===`localhost`},e.getCamerasFromMediaDevices=function(){return TC(this,void 0,void 0,function(){var e,t,n,r,i,a,o;return EC(this,function(s){switch(s.label){case 0:return e=function(e){for(var t=e.getVideoTracks(),n=0,r=t;n<r.length;n++){var i=r[n];i.enabled=!1,i.stop(),e.removeTrack(i)}},[4,navigator.mediaDevices.getUserMedia({audio:!1,video:!0})];case 1:return t=s.sent(),[4,navigator.mediaDevices.enumerateDevices()];case 2:for(n=s.sent(),r=[],i=0,a=n;i<a.length;i++)o=a[i],o.kind===`videoinput`&&r.push({id:o.deviceId,label:o.label});return e(t),[2,r]}})})},e.getCamerasFromMediaStreamTrack=function(){return new Promise(function(e,t){MediaStreamTrack.getSources(function(t){for(var n=[],r=0,i=t;r<i.length;r++){var a=i[r];a.kind===`video`&&n.push({id:a.id,label:a.label})}e(n)})})},e}(),OC;(function(e){e[e.UNKNOWN=0]=`UNKNOWN`,e[e.NOT_STARTED=1]=`NOT_STARTED`,e[e.SCANNING=2]=`SCANNING`,e[e.PAUSED=3]=`PAUSED`})(OC||={});var kC=function(){function e(){this.state=OC.NOT_STARTED,this.onGoingTransactionNewState=OC.UNKNOWN}return e.prototype.directTransition=function(e){this.failIfTransitionOngoing(),this.validateTransition(e),this.state=e},e.prototype.startTransition=function(e){return this.failIfTransitionOngoing(),this.validateTransition(e),this.onGoingTransactionNewState=e,this},e.prototype.execute=function(){if(this.onGoingTransactionNewState===OC.UNKNOWN)throw`Transaction is already cancelled, cannot execute().`;var e=this.onGoingTransactionNewState;this.onGoingTransactionNewState=OC.UNKNOWN,this.directTransition(e)},e.prototype.cancel=function(){if(this.onGoingTransactionNewState===OC.UNKNOWN)throw`Transaction is already cancelled, cannot cancel().`;this.onGoingTransactionNewState=OC.UNKNOWN},e.prototype.getState=function(){return this.state},e.prototype.failIfTransitionOngoing=function(){if(this.onGoingTransactionNewState!==OC.UNKNOWN)throw`Cannot transition to a new state, already under transition`},e.prototype.validateTransition=function(e){switch(this.state){case OC.UNKNOWN:throw`Transition from unknown is not allowed`;case OC.NOT_STARTED:this.failIfNewStateIs(e,[OC.PAUSED]);break;case OC.SCANNING:break;case OC.PAUSED:break}},e.prototype.failIfNewStateIs=function(e,t){for(var n=0,r=t;n<r.length;n++)if(e===r[n])throw`Cannot transition from ${this.state} to ${e}`},e}(),AC=function(){function e(e){this.stateManager=e}return e.prototype.startTransition=function(e){return this.stateManager.startTransition(e)},e.prototype.directTransition=function(e){this.stateManager.directTransition(e)},e.prototype.getState=function(){return this.stateManager.getState()},e.prototype.canScanFile=function(){return this.stateManager.getState()===OC.NOT_STARTED},e.prototype.isScanning=function(){return this.stateManager.getState()!==OC.NOT_STARTED},e.prototype.isStrictlyScanning=function(){return this.stateManager.getState()===OC.SCANNING},e.prototype.isPaused=function(){return this.stateManager.getState()===OC.PAUSED},e}(),jC=function(){function e(){}return e.create=function(){return new AC(new kC)},e}(),MC=(function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};return function(t,n){if(typeof n!=`function`&&n!==null)throw TypeError(`Class extends value `+String(n)+` is not a constructor or null`);e(t,n);function r(){this.constructor=t}t.prototype=n===null?Object.create(n):(r.prototype=n.prototype,new r)}})(),NC=function(e){MC(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.DEFAULT_WIDTH=300,t.DEFAULT_WIDTH_OFFSET=2,t.FILE_SCAN_MIN_HEIGHT=300,t.FILE_SCAN_HIDDEN_CANVAS_PADDING=100,t.MIN_QR_BOX_SIZE=50,t.SHADED_LEFT=1,t.SHADED_RIGHT=2,t.SHADED_TOP=3,t.SHADED_BOTTOM=4,t.SHADED_REGION_ELEMENT_ID=`qr-shaded-region`,t.VERBOSE=!1,t.BORDER_SHADER_DEFAULT_COLOR=`#ffffff`,t.BORDER_SHADER_MATCH_COLOR=`rgb(90, 193, 56)`,t}(qS),PC=function(){function e(e,t){this.logger=t,this.fps=NC.SCAN_DEFAULT_FPS,e?(e.fps&&(this.fps=e.fps),this.disableFlip=e.disableFlip===!0,this.qrbox=e.qrbox,this.aspectRatio=e.aspectRatio,this.videoConstraints=e.videoConstraints):this.disableFlip=NC.DEFAULT_DISABLE_FLIP}return e.prototype.isMediaStreamConstraintsValid=function(){return this.videoConstraints?iC.isMediaStreamConstraintsValid(this.videoConstraints,this.logger):(this.logger.logError(`Empty videoConstraints`,!0),!1)},e.prototype.isShadedBoxEnabled=function(){return!$S(this.qrbox)},e.create=function(t,n){return new e(t,n)},e}(),FC=function(){function e(e,t){if(this.element=null,this.canvasElement=null,this.scannerPausedUiElement=null,this.hasBorderShaders=null,this.borderShaders=null,this.qrMatch=null,this.renderedCamera=null,this.qrRegion=null,this.context=null,this.lastScanImageFile=null,this.isScanning=!1,!document.getElementById(e))throw`HTML Element with id=${e} not found`;this.elementId=e,this.verbose=!1;var n;typeof t==`boolean`?this.verbose=t===!0:t&&(n=t,this.verbose=n.verbose===!0,n.experimentalFeatures),this.logger=new QS(this.verbose),this.qrcode=new fC(this.getSupportedFormats(t),this.getUseBarCodeDetectorIfSupported(n),this.verbose,this.logger),this.foreverScanTimeout,this.shouldScan=!0,this.stateManagerProxy=jC.create()}return e.prototype.start=function(e,t,n,r){var i=this;if(!e)throw`cameraIdOrConfig is required`;if(!n||typeof n!=`function`)throw`qrCodeSuccessCallback is required and should be a function.`;var a=r||(this.verbose?this.logger.log:function(){}),o=PC.create(t,this.logger);this.clearElement();var s=!1;o.videoConstraints&&(o.isMediaStreamConstraintsValid()?s=!0:this.logger.logError(`'videoConstraints' is not valid 'MediaStreamConstraints, it will be ignored.'`,!0));var c=s,l=document.getElementById(this.elementId);l.clientWidth?l.clientWidth:NC.DEFAULT_WIDTH,l.style.position=`relative`,this.shouldScan=!0,this.element=l;var u=this,d=this.stateManagerProxy.startTransition(OC.SCANNING);return new Promise(function(t,r){var s=c?o.videoConstraints:u.createVideoConstraints(e);if(!s){d.cancel(),r(`videoConstraints should be defined`);return}var l={};(!c||o.aspectRatio)&&(l.aspectRatio=o.aspectRatio);var f={onRenderSurfaceReady:function(e,t){u.setupUi(e,t,o),u.isScanning=!0,u.foreverScan(o,n,a)}};wC.failIfNotSupported().then(function(e){e.create(s).then(function(e){return e.render(i.element,l,f).then(function(e){u.renderedCamera=e,d.execute(),t(null)}).catch(function(e){d.cancel(),r(e)})}).catch(function(e){d.cancel(),r(tC.errorGettingUserMedia(e))})}).catch(function(e){d.cancel(),r(tC.cameraStreamingNotSupported())})})},e.prototype.pause=function(e){if(!this.stateManagerProxy.isStrictlyScanning())throw`Cannot pause, scanner is not scanning.`;this.stateManagerProxy.directTransition(OC.PAUSED),this.showPausedState(),($S(e)||e!==!0)&&(e=!1),e&&this.renderedCamera&&this.renderedCamera.pause()},e.prototype.resume=function(){if(!this.stateManagerProxy.isPaused())throw`Cannot result, scanner is not paused.`;if(!this.renderedCamera)throw`renderedCamera doesn't exist while trying resume()`;var e=this,t=function(){e.stateManagerProxy.directTransition(OC.SCANNING),e.hidePausedState()};if(!this.renderedCamera.isPaused()){t();return}this.renderedCamera.resume(function(){t()})},e.prototype.getState=function(){return this.stateManagerProxy.getState()},e.prototype.stop=function(){var e=this;if(!this.stateManagerProxy.isScanning())throw`Cannot stop, scanner is not running or paused.`;var t=this.stateManagerProxy.startTransition(OC.NOT_STARTED);this.shouldScan=!1,this.foreverScanTimeout&&clearTimeout(this.foreverScanTimeout);var n=function(){if(e.element){var t=document.getElementById(NC.SHADED_REGION_ELEMENT_ID);t&&e.element.removeChild(t)}},r=this;return this.renderedCamera.close().then(function(){return r.renderedCamera=null,r.element&&(r.element.removeChild(r.canvasElement),r.canvasElement=null),n(),r.qrRegion&&=null,r.context&&=null,t.execute(),r.hidePausedState(),r.isScanning=!1,Promise.resolve()})},e.prototype.scanFile=function(e,t){return this.scanFileV2(e,t).then(function(e){return e.decodedText})},e.prototype.scanFileV2=function(e,t){var n=this;if(!e||!(e instanceof File))throw`imageFile argument is mandatory and should be instance of File. Use 'event.target.files[0]'.`;if($S(t)&&(t=!0),!this.stateManagerProxy.canScanFile())throw`Cannot start file scan - ongoing camera scan`;return new Promise(function(r,i){n.possiblyCloseLastScanImageFile(),n.clearElement(),n.lastScanImageFile=URL.createObjectURL(e);var a=new Image;a.onload=function(){var e=a.width,o=a.height,s=document.getElementById(n.elementId),c=s.clientWidth?s.clientWidth:NC.DEFAULT_WIDTH,l=Math.max(s.clientHeight?s.clientHeight:o,NC.FILE_SCAN_MIN_HEIGHT),u=n.computeCanvasDrawConfig(e,o,c,l);if(t){var d=n.createCanvasElement(c,l,`qr-canvas-visible`);d.style.display=`inline-block`,s.appendChild(d);var f=d.getContext(`2d`);if(!f)throw`Unable to get 2d context from canvas`;f.canvas.width=c,f.canvas.height=l,f.drawImage(a,0,0,e,o,u.x,u.y,u.width,u.height)}var p=NC.FILE_SCAN_HIDDEN_CANVAS_PADDING,m=Math.max(a.width,u.width),h=Math.max(a.height,u.height),g=m+2*p,_=h+2*p,v=n.createCanvasElement(g,_);s.appendChild(v);var y=v.getContext(`2d`);if(!y)throw`Unable to get 2d context from canvas`;y.canvas.width=g,y.canvas.height=_,y.drawImage(a,0,0,e,o,p,p,m,h);try{n.qrcode.decodeRobustlyAsync(v).then(function(e){r(YS.createFromQrcodeResult(e))}).catch(i)}catch(e){i(`QR code parse error, error = ${e}`)}},a.onerror=i,a.onabort=i,a.onstalled=i,a.onsuspend=i,a.src=URL.createObjectURL(e)})},e.prototype.clear=function(){this.clearElement()},e.getCameras=function(){return DC.retrieve()},e.prototype.getRunningTrackCapabilities=function(){return this.getRenderedCameraOrFail().getRunningTrackCapabilities()},e.prototype.getRunningTrackSettings=function(){return this.getRenderedCameraOrFail().getRunningTrackSettings()},e.prototype.getRunningTrackCameraCapabilities=function(){return this.getRenderedCameraOrFail().getCapabilities()},e.prototype.applyVideoConstraints=function(e){if(!e)throw`videoConstaints is required argument.`;if(!iC.isMediaStreamConstraintsValid(e,this.logger))throw`invalid videoConstaints passed, check logs for more details`;return this.getRenderedCameraOrFail().applyVideoConstraints(e)},e.prototype.getRenderedCameraOrFail=function(){if(this.renderedCamera==null)throw`Scanning is not in running state, call this API only when QR code scanning using camera is in running state.`;return this.renderedCamera},e.prototype.getSupportedFormats=function(e){var t=[HS.QR_CODE,HS.AZTEC,HS.CODABAR,HS.CODE_39,HS.CODE_93,HS.CODE_128,HS.DATA_MATRIX,HS.MAXICODE,HS.ITF,HS.EAN_13,HS.EAN_8,HS.PDF_417,HS.RSS_14,HS.RSS_EXPANDED,HS.UPC_A,HS.UPC_E,HS.UPC_EAN_EXTENSION];if(!e||typeof e==`boolean`||!e.formatsToSupport)return t;if(!Array.isArray(e.formatsToSupport))throw`configOrVerbosityFlag.formatsToSupport should be undefined or an array.`;if(e.formatsToSupport.length===0)throw`Atleast 1 formatsToSupport is needed.`;for(var n=[],r=0,i=e.formatsToSupport;r<i.length;r++){var a=i[r];GS(a)?n.push(a):this.logger.warn(`Invalid format: ${a} passed in config, ignoring.`)}if(n.length===0)throw`None of formatsToSupport match supported values.`;return n},e.prototype.getUseBarCodeDetectorIfSupported=function(e){if($S(e))return!0;if(!$S(e.useBarCodeDetectorIfSupported))return e.useBarCodeDetectorIfSupported!==!1;if($S(e.experimentalFeatures))return!0;var t=e.experimentalFeatures;return $S(t.useBarCodeDetectorIfSupported)?!0:t.useBarCodeDetectorIfSupported!==!1},e.prototype.validateQrboxSize=function(e,t,n){var r=this,i=n.qrbox;this.validateQrboxConfig(i);var a=this.toQrdimensions(e,t,i),o=function(e){if(e<NC.MIN_QR_BOX_SIZE)throw`minimum size of 'config.qrbox' dimension value is ${NC.MIN_QR_BOX_SIZE}px.`};o(a.width),o(a.height),a.width=function(t){return t>e&&(r.logger.warn("`qrbox.width` or `qrbox` is larger than the width of the root element. The width will be truncated to the width of root element."),t=e),t}(a.width)},e.prototype.validateQrboxConfig=function(e){if(typeof e!=`number`&&typeof e!=`function`&&(e.width===void 0||e.height===void 0))throw`Invalid instance of QrDimensions passed for 'config.qrbox'. Both 'width' and 'height' should be set.`},e.prototype.toQrdimensions=function(e,t,n){if(typeof n==`number`)return{width:n,height:n};if(typeof n==`function`)try{return n(e,t)}catch(e){throw Error(`qrbox config was passed as a function but it failed with unknown error`+e)}return n},e.prototype.setupUi=function(e,t,n){n.isShadedBoxEnabled()&&this.validateQrboxSize(e,t,n);var r=$S(n.qrbox)?{width:e,height:t}:n.qrbox;this.validateQrboxConfig(r);var i=this.toQrdimensions(e,t,r);i.height>t&&this.logger.warn(`[Html5Qrcode] config.qrbox has height that isgreater than the height of the video stream. Shading will be ignored`);var a=n.isShadedBoxEnabled()&&i.height<=t,o=a?this.getShadedRegionBounds(e,t,i):{x:0,y:0,width:e,height:t},s=this.createCanvasElement(o.width,o.height),c=s.getContext(`2d`,{willReadFrequently:!0});c.canvas.width=o.width,c.canvas.height=o.height,this.element.append(s),a&&this.possiblyInsertShadingElement(this.element,e,t,i),this.createScannerPausedUiElement(this.element),this.qrRegion=o,this.context=c,this.canvasElement=s},e.prototype.createScannerPausedUiElement=function(e){var t=document.createElement(`div`);t.innerText=tC.scannerPaused(),t.style.display=`none`,t.style.position=`absolute`,t.style.top=`0px`,t.style.zIndex=`1`,t.style.background=`rgba(9, 9, 9, 0.46)`,t.style.color=`#FFECEC`,t.style.textAlign=`center`,t.style.width=`100%`,e.appendChild(t),this.scannerPausedUiElement=t},e.prototype.scanContext=function(e,t){var n=this;return this.stateManagerProxy.isPaused()?Promise.resolve(!1):this.qrcode.decodeAsync(this.canvasElement).then(function(t){return e(t.text,YS.createFromQrcodeResult(t)),n.possiblyUpdateShaders(!0),!0}).catch(function(e){n.possiblyUpdateShaders(!1);var r=tC.codeParseError(e);return t(r,ZS.createFrom(r)),!1})},e.prototype.foreverScan=function(e,t,n){var r=this;if(this.shouldScan&&this.renderedCamera){var i=this.renderedCamera.getSurface(),a=i.videoWidth/i.clientWidth,o=i.videoHeight/i.clientHeight;if(!this.qrRegion)throw`qrRegion undefined when localMediaStream is ready.`;var s=this.qrRegion.width*a,c=this.qrRegion.height*o,l=this.qrRegion.x*a,u=this.qrRegion.y*o;this.context.drawImage(i,l,u,s,c,0,0,this.qrRegion.width,this.qrRegion.height);var d=function(){r.foreverScanTimeout=setTimeout(function(){r.foreverScan(e,t,n)},r.getTimeoutFps(e.fps))};this.scanContext(t,n).then(function(i){!i&&e.disableFlip!==!0?(r.context.translate(r.context.canvas.width,0),r.context.scale(-1,1),r.scanContext(t,n).finally(function(){d()})):d()}).catch(function(e){r.logger.logError(`Error happend while scanning context`,e),d()})}},e.prototype.createVideoConstraints=function(e){if(typeof e==`string`)return{deviceId:{exact:e}};if(typeof e==`object`){var t=`facingMode`,n=`deviceId`,r={user:!0,environment:!0},i=`exact`,a=function(e){if(e in r)return!0;throw`config has invalid 'facingMode' value = '${e}'`},o=Object.keys(e);if(o.length!==1)throw`'cameraIdOrConfig' object should have exactly 1 key, if passed as an object, found ${o.length} keys`;var s=Object.keys(e)[0];if(s!==t&&s!==n)throw`Only '${t}' and '${n}' are supported for 'cameraIdOrConfig'`;if(s===t){var c=e.facingMode;if(typeof c==`string`){if(a(c))return{facingMode:c}}else if(typeof c==`object`)if(i in c){if(a(c[`${i}`]))return{facingMode:{exact:c[`${i}`]}}}else throw`'facingMode' should be string or object with ${i} as key.`;else throw`Invalid type of 'facingMode' = ${typeof c}`}else{var l=e.deviceId;if(typeof l==`string`)return{deviceId:l};if(typeof l==`object`){if(i in l)return{deviceId:{exact:l[`${i}`]}};throw`'deviceId' should be string or object with ${i} as key.`}else throw`Invalid type of 'deviceId' = ${typeof l}`}}throw`Invalid type of 'cameraIdOrConfig' = ${typeof e}`},e.prototype.computeCanvasDrawConfig=function(e,t,n,r){if(e<=n&&t<=r)return{x:(n-e)/2,y:(r-t)/2,width:e,height:t};var i=e,a=t;return e>n&&(t=n/e*t,e=n),t>r&&(e=r/t*e,t=r),this.logger.log(`Image downsampled from ${i}X${a} to ${e}X${t}.`),this.computeCanvasDrawConfig(e,t,n,r)},e.prototype.clearElement=function(){if(this.stateManagerProxy.isScanning())throw`Cannot clear while scan is ongoing, close it first.`;var e=document.getElementById(this.elementId);e&&(e.innerHTML=``)},e.prototype.possiblyUpdateShaders=function(e){this.qrMatch!==e&&(this.hasBorderShaders&&this.borderShaders&&this.borderShaders.length&&this.borderShaders.forEach(function(t){t.style.backgroundColor=e?NC.BORDER_SHADER_MATCH_COLOR:NC.BORDER_SHADER_DEFAULT_COLOR}),this.qrMatch=e)},e.prototype.possiblyCloseLastScanImageFile=function(){this.lastScanImageFile&&=(URL.revokeObjectURL(this.lastScanImageFile),null)},e.prototype.createCanvasElement=function(e,t,n){var r=e,i=t,a=document.createElement(`canvas`);return a.style.width=`${r}px`,a.style.height=`${i}px`,a.style.display=`none`,a.id=$S(n)?`qr-canvas`:n,a},e.prototype.getShadedRegionBounds=function(e,t,n){if(n.width>e||n.height>t)throw`'config.qrbox' dimensions should not be greater than the dimensions of the root HTML element.`;return{x:(e-n.width)/2,y:(t-n.height)/2,width:n.width,height:n.height}},e.prototype.possiblyInsertShadingElement=function(e,t,n,r){if(!(t-r.width<1||n-r.height<1)){var i=document.createElement(`div`);i.style.position=`absolute`;var a=(t-r.width)/2,o=(n-r.height)/2;if(i.style.borderLeft=`${a}px solid rgba(0, 0, 0, 0.48)`,i.style.borderRight=`${a}px solid rgba(0, 0, 0, 0.48)`,i.style.borderTop=`${o}px solid rgba(0, 0, 0, 0.48)`,i.style.borderBottom=`${o}px solid rgba(0, 0, 0, 0.48)`,i.style.boxSizing=`border-box`,i.style.top=`0px`,i.style.bottom=`0px`,i.style.left=`0px`,i.style.right=`0px`,i.id=`${NC.SHADED_REGION_ELEMENT_ID}`,t-r.width<11||n-r.height<11)this.hasBorderShaders=!1;else{var s=5,c=40;this.insertShaderBorders(i,c,s,-s,null,0,!0),this.insertShaderBorders(i,c,s,-s,null,0,!1),this.insertShaderBorders(i,c,s,null,-s,0,!0),this.insertShaderBorders(i,c,s,null,-s,0,!1),this.insertShaderBorders(i,s,c+s,-s,null,-s,!0),this.insertShaderBorders(i,s,c+s,null,-s,-s,!0),this.insertShaderBorders(i,s,c+s,-s,null,-s,!1),this.insertShaderBorders(i,s,c+s,null,-s,-s,!1),this.hasBorderShaders=!0}e.append(i)}},e.prototype.insertShaderBorders=function(e,t,n,r,i,a,o){var s=document.createElement(`div`);s.style.position=`absolute`,s.style.backgroundColor=NC.BORDER_SHADER_DEFAULT_COLOR,s.style.width=`${t}px`,s.style.height=`${n}px`,r!==null&&(s.style.top=`${r}px`),i!==null&&(s.style.bottom=`${i}px`),o?s.style.left=`${a}px`:s.style.right=`${a}px`,this.borderShaders||=[],this.borderShaders.push(s),e.appendChild(s)},e.prototype.showPausedState=function(){if(!this.scannerPausedUiElement)throw`[internal error] scanner paused UI element not found`;this.scannerPausedUiElement.style.display=`block`},e.prototype.hidePausedState=function(){if(!this.scannerPausedUiElement)throw`[internal error] scanner paused UI element not found`;this.scannerPausedUiElement.style.display=`none`},e.prototype.getTimeoutFps=function(e){return 1e3/e},e}(),IC=`data:image/svg+xml;base64,`,LC=IC+`PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAzNzEuNjQzIDM3MS42NDMiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDM3MS42NDMgMzcxLjY0MyIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+PHBhdGggZD0iTTEwNS4wODQgMzguMjcxaDE2My43Njh2MjBIMTA1LjA4NHoiLz48cGF0aCBkPSJNMzExLjU5NiAxOTAuMTg5Yy03LjQ0MS05LjM0Ny0xOC40MDMtMTYuMjA2LTMyLjc0My0yMC41MjJWMzBjMC0xNi41NDItMTMuNDU4LTMwLTMwLTMwSDEyNS4wODRjLTE2LjU0MiAwLTMwIDEzLjQ1OC0zMCAzMHYxMjAuMTQzaC04LjI5NmMtMTYuNTQyIDAtMzAgMTMuNDU4LTMwIDMwdjEuMzMzYTI5LjgwNCAyOS44MDQgMCAwIDAgNC42MDMgMTUuOTM5Yy03LjM0IDUuNDc0LTEyLjEwMyAxNC4yMjEtMTIuMTAzIDI0LjA2MXYxLjMzM2MwIDkuODQgNC43NjMgMTguNTg3IDEyLjEwMyAyNC4wNjJhMjkuODEgMjkuODEgMCAwIDAtNC42MDMgMTUuOTM4djEuMzMzYzAgMTYuNTQyIDEzLjQ1OCAzMCAzMCAzMGg4LjMyNGMuNDI3IDExLjYzMSA3LjUwMyAyMS41ODcgMTcuNTM0IDI2LjE3Ny45MzEgMTAuNTAzIDQuMDg0IDMwLjE4NyAxNC43NjggNDUuNTM3YTkuOTg4IDkuOTg4IDAgMCAwIDguMjE2IDQuMjg4IDkuOTU4IDkuOTU4IDAgMCAwIDUuNzA0LTEuNzkzYzQuNTMzLTMuMTU1IDUuNjUtOS4zODggMi40OTUtMTMuOTIxLTYuNzk4LTkuNzY3LTkuNjAyLTIyLjYwOC0xMC43Ni0zMS40aDgyLjY4NWMuMjcyLjQxNC41NDUuODE4LjgxNSAxLjIxIDMuMTQyIDQuNTQxIDkuMzcyIDUuNjc5IDEzLjkxMyAyLjUzNCA0LjU0Mi0zLjE0MiA1LjY3Ny05LjM3MSAyLjUzNS0xMy45MTMtMTEuOTE5LTE3LjIyOS04Ljc4Ny0zNS44ODQgOS41ODEtNTcuMDEyIDMuMDY3LTIuNjUyIDEyLjMwNy0xMS43MzIgMTEuMjE3LTI0LjAzMy0uODI4LTkuMzQzLTcuMTA5LTE3LjE5NC0xOC42NjktMjMuMzM3YTkuODU3IDkuODU3IDAgMCAwLTEuMDYxLS40ODZjLS40NjYtLjE4Mi0xMS40MDMtNC41NzktOS43NDEtMTUuNzA2IDEuMDA3LTYuNzM3IDE0Ljc2OC04LjI3MyAyMy43NjYtNy42NjYgMjMuMTU2IDEuNTY5IDM5LjY5OCA3LjgwMyA0Ny44MzYgMTguMDI2IDUuNzUyIDcuMjI1IDcuNjA3IDE2LjYyMyA1LjY3MyAyOC43MzMtLjQxMyAyLjU4NS0uODI0IDUuMjQxLTEuMjQ1IDcuOTU5LTUuNzU2IDM3LjE5NC0xMi45MTkgODMuNDgzLTQ5Ljg3IDExNC42NjEtNC4yMjEgMy41NjEtNC43NTYgOS44Ny0xLjE5NCAxNC4wOTJhOS45OCA5Ljk4IDAgMCAwIDcuNjQ4IDMuNTUxIDkuOTU1IDkuOTU1IDAgMCAwIDYuNDQ0LTIuMzU4YzQyLjY3Mi0zNi4wMDUgNTAuODAyLTg4LjUzMyA1Ni43MzctMTI2Ljg4OC40MTUtMi42ODQuODIxLTUuMzA5IDEuMjI5LTcuODYzIDIuODM0LTE3LjcyMS0uNDU1LTMyLjY0MS05Ljc3Mi00NC4zNDV6bS0yMzIuMzA4IDQyLjYyYy01LjUxNCAwLTEwLTQuNDg2LTEwLTEwdi0xLjMzM2MwLTUuNTE0IDQuNDg2LTEwIDEwLTEwaDE1djIxLjMzM2gtMTV6bS0yLjUtNTIuNjY2YzAtNS41MTQgNC40ODYtMTAgMTAtMTBoNy41djIxLjMzM2gtNy41Yy01LjUxNCAwLTEwLTQuNDg2LTEwLTEwdi0xLjMzM3ptMTcuNSA5My45OTloLTcuNWMtNS41MTQgMC0xMC00LjQ4Ni0xMC0xMHYtMS4zMzNjMC01LjUxNCA0LjQ4Ni0xMCAxMC0xMGg3LjV2MjEuMzMzem0zMC43OTYgMjguODg3Yy01LjUxNCAwLTEwLTQuNDg2LTEwLTEwdi04LjI3MWg5MS40NTdjLS44NTEgNi42NjgtLjQzNyAxMi43ODcuNzMxIDE4LjI3MWgtODIuMTg4em03OS40ODItMTEzLjY5OGMtMy4xMjQgMjAuOTA2IDEyLjQyNyAzMy4xODQgMjEuNjI1IDM3LjA0IDUuNDQxIDIuOTY4IDcuNTUxIDUuNjQ3IDcuNzAxIDcuMTg4LjIxIDIuMTUtMi41NTMgNS42ODQtNC40NzcgNy4yNTEtLjQ4Mi4zNzgtLjkyOS44LTEuMzM1IDEuMjYxLTYuOTg3IDcuOTM2LTExLjk4MiAxNS41Mi0xNS40MzIgMjIuNjg4aC05Ny41NjRWMzBjMC01LjUxNCA0LjQ4Ni0xMCAxMC0xMGgxMjMuNzY5YzUuNTE0IDAgMTAgNC40ODYgMTAgMTB2MTM1LjU3OWMtMy4wMzItLjM4MS02LjE1LS42OTQtOS4zODktLjkxNC0yNS4xNTktMS42OTQtNDIuMzcgNy43NDgtNDQuODk4IDI0LjY2NnoiLz48cGF0aCBkPSJNMTc5LjEyOSA4My4xNjdoLTI0LjA2YTUgNSAwIDAgMC01IDV2MjQuMDYxYTUgNSAwIDAgMCA1IDVoMjQuMDZhNSA1IDAgMCAwIDUtNVY4OC4xNjdhNSA1IDAgMCAwLTUtNXpNMTcyLjYyOSAxNDIuODZoLTEyLjU2VjEzMC44YTUgNSAwIDEgMC0xMCAwdjE3LjA2MWE1IDUgMCAwIDAgNSA1aDE3LjU2YTUgNSAwIDEgMCAwLTEwLjAwMXpNMjE2LjU2OCA4My4xNjdoLTI0LjA2YTUgNSAwIDAgMC01IDV2MjQuMDYxYTUgNSAwIDAgMCA1IDVoMjQuMDZhNSA1IDAgMCAwIDUtNVY4OC4xNjdhNSA1IDAgMCAwLTUtNXptLTUgMjQuMDYxaC0xNC4wNlY5My4xNjdoMTQuMDZ2MTQuMDYxek0yMTEuNjY5IDEyNS45MzZIMTk3LjQxYTUgNSAwIDAgMC01IDV2MTQuMjU3YTUgNSAwIDAgMCA1IDVoMTQuMjU5YTUgNSAwIDAgMCA1LTV2LTE0LjI1N2E1IDUgMCAwIDAtNS01eiIvPjwvc3ZnPg==`,RC=IC+`PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA1OS4wMTggNTkuMDE4IiBzdHlsZT0iZW5hYmxlLWJhY2tncm91bmQ6bmV3IDAgMCA1OS4wMTggNTkuMDE4IiB4bWw6c3BhY2U9InByZXNlcnZlIj48cGF0aCBkPSJtNTguNzQxIDU0LjgwOS01Ljk2OS02LjI0NGExMC43NCAxMC43NCAwIDAgMCAyLjgyLTcuMjVjMC01Ljk1My00Ljg0My0xMC43OTYtMTAuNzk2LTEwLjc5NlMzNCAzNS4zNjEgMzQgNDEuMzE0IDM4Ljg0MyA1Mi4xMSA0NC43OTYgNTIuMTFjMi40NDEgMCA0LjY4OC0uODI0IDYuNDk5LTIuMTk2bDYuMDAxIDYuMjc3YS45OTguOTk4IDAgMCAwIDEuNDE0LjAzMiAxIDEgMCAwIDAgLjAzMS0xLjQxNHpNMzYgNDEuMzE0YzAtNC44NSAzLjk0Ni04Ljc5NiA4Ljc5Ni04Ljc5NnM4Ljc5NiAzLjk0NiA4Ljc5NiA4Ljc5Ni0zLjk0NiA4Ljc5Ni04Ljc5NiA4Ljc5NlMzNiA0Ni4xNjQgMzYgNDEuMzE0ek0xMC40MzEgMTYuMDg4YzAgMy4wNyAyLjQ5OCA1LjU2OCA1LjU2OSA1LjU2OHM1LjU2OS0yLjQ5OCA1LjU2OS01LjU2OGMwLTMuMDcxLTIuNDk4LTUuNTY5LTUuNTY5LTUuNTY5cy01LjU2OSAyLjQ5OC01LjU2OSA1LjU2OXptOS4xMzggMGMwIDEuOTY4LTEuNjAyIDMuNTY4LTMuNTY5IDMuNTY4cy0zLjU2OS0xLjYwMS0zLjU2OS0zLjU2OCAxLjYwMi0zLjU2OSAzLjU2OS0zLjU2OSAzLjU2OSAxLjYwMSAzLjU2OSAzLjU2OXoiLz48cGF0aCBkPSJtMzAuODgyIDI4Ljk4NyA5LjE4LTEwLjA1NCAxMS4yNjIgMTAuMzIzYTEgMSAwIDAgMCAxLjM1MS0xLjQ3NWwtMTItMTFhMSAxIDAgMCAwLTEuNDE0LjA2M2wtOS43OTQgMTAuNzI3LTQuNzQzLTQuNzQzYTEuMDAzIDEuMDAzIDAgMCAwLTEuMzY4LS4wNDRMNi4zMzkgMzcuNzY4YTEgMSAwIDEgMCAxLjMyMiAxLjUwMWwxNi4zMTMtMTQuMzYyIDcuMzE5IDcuMzE4YS45OTkuOTk5IDAgMSAwIDEuNDE0LTEuNDE0bC0xLjgyNS0xLjgyNHoiLz48cGF0aCBkPSJNMzAgNDYuNTE4SDJ2LTQyaDU0djI4YTEgMSAwIDEgMCAyIDB2LTI5YTEgMSAwIDAgMC0xLTFIMWExIDEgMCAwIDAtMSAxdjQ0YTEgMSAwIDAgMCAxIDFoMjlhMSAxIDAgMSAwIDAtMnoiLz48L3N2Zz4=`,zC=IC+`PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0NjAgNDYwIiBzdHlsZT0iZW5hYmxlLWJhY2tncm91bmQ6bmV3IDAgMCA0NjAgNDYwIiB4bWw6c3BhY2U9InByZXNlcnZlIj48cGF0aCBkPSJNMjMwIDBDMTAyLjk3NSAwIDAgMTAyLjk3NSAwIDIzMHMxMDIuOTc1IDIzMCAyMzAgMjMwIDIzMC0xMDIuOTc0IDIzMC0yMzBTMzU3LjAyNSAwIDIzMCAwem0zOC4zMzMgMzc3LjM2YzAgOC42NzYtNy4wMzQgMTUuNzEtMTUuNzEgMTUuNzFoLTQzLjEwMWMtOC42NzYgMC0xNS43MS03LjAzNC0xNS43MS0xNS43MVYyMDIuNDc3YzAtOC42NzYgNy4wMzMtMTUuNzEgMTUuNzEtMTUuNzFoNDMuMTAxYzguNjc2IDAgMTUuNzEgNy4wMzMgMTUuNzEgMTUuNzFWMzc3LjM2ek0yMzAgMTU3Yy0yMS41MzkgMC0zOS0xNy40NjEtMzktMzlzMTcuNDYxLTM5IDM5LTM5IDM5IDE3LjQ2MSAzOSAzOS0xNy40NjEgMzktMzkgMzl6Ii8+PC9zdmc+`,BC=`data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAAQgAAAEIBarqQRAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAE1SURBVDiNfdI7S0NBEAXgLya1otFgpbYSbISAgpXYi6CmiH9KCAiChaVga6OiWPgfRDQ+0itaGVNosXtluWwcuMzePfM4M3sq8lbHBubwg1dc4m1E/J/N4ghDPOIsfk/4xiEao5KX0McFljN4C9d4QTPXuY99jP3DsIoDPGM6BY5i5yI5R7O4q+ImFkJY2DCh3cAH2klyB+9J1xUMMAG7eCh1a+Mr+k48b5diXrFVwwLuS+BJ9MfR7+G0FHOHhTHhnXNWS87VDF4pcnfQK4Ep7XScNLmPTZgURNKKYENYWDpzW1BhscS1WHS8CDgURFJQrWcoF3c13KKbgg1BYQfy8xZWEzTTw1QZbAoKu8FqJnktdu5hcVSHmchiILzzuaDQvjBzV2m8yohCE1jHfPx/xhU+y4G/D75ELlRJsSYAAAAASUVORK5CYII=`,VC=function(){function e(){}return e.createDefault=function(){return{hasPermission:!1,lastUsedCameraId:null}},e}(),HC=function(){function e(){this.data=VC.createDefault();var t=localStorage.getItem(e.LOCAL_STORAGE_KEY);t?this.data=JSON.parse(t):this.reset()}return e.prototype.hasCameraPermissions=function(){return this.data.hasPermission},e.prototype.getLastUsedCameraId=function(){return this.data.lastUsedCameraId},e.prototype.setHasPermission=function(e){this.data.hasPermission=e,this.flush()},e.prototype.setLastUsedCameraId=function(e){this.data.lastUsedCameraId=e,this.flush()},e.prototype.resetLastUsedCameraId=function(){this.data.lastUsedCameraId=null,this.flush()},e.prototype.reset=function(){this.data=VC.createDefault(),this.flush()},e.prototype.flush=function(){localStorage.setItem(e.LOCAL_STORAGE_KEY,JSON.stringify(this.data))},e.LOCAL_STORAGE_KEY=`HTML5_QRCODE_DATA`,e}(),UC=function(){function e(){this.infoDiv=document.createElement(`div`)}return e.prototype.renderInto=function(e){this.infoDiv.style.position=`absolute`,this.infoDiv.style.top=`10px`,this.infoDiv.style.right=`10px`,this.infoDiv.style.zIndex=`2`,this.infoDiv.style.display=`none`,this.infoDiv.style.padding=`5pt`,this.infoDiv.style.border=`1px solid #171717`,this.infoDiv.style.fontSize=`10pt`,this.infoDiv.style.background=`rgb(0 0 0 / 69%)`,this.infoDiv.style.borderRadius=`5px`,this.infoDiv.style.textAlign=`center`,this.infoDiv.style.fontWeight=`400`,this.infoDiv.style.color=`white`,this.infoDiv.innerText=rC.poweredBy();var t=document.createElement(`a`);t.innerText=`ScanApp`,t.href=`https://scanapp.org`,t.target=`new`,t.style.color=`white`,this.infoDiv.appendChild(t);var n=document.createElement(`br`),r=document.createElement(`br`);this.infoDiv.appendChild(n),this.infoDiv.appendChild(r);var i=document.createElement(`a`);i.innerText=rC.reportIssues(),i.href=`https://github.com/mebjas/html5-qrcode/issues`,i.target=`new`,i.style.color=`white`,this.infoDiv.appendChild(i),e.appendChild(this.infoDiv)},e.prototype.show=function(){this.infoDiv.style.display=`block`},e.prototype.hide=function(){this.infoDiv.style.display=`none`},e}(),WC=function(){function e(e,t){this.isShowingInfoIcon=!0,this.onTapIn=e,this.onTapOut=t,this.infoIcon=document.createElement(`img`)}return e.prototype.renderInto=function(e){var t=this;this.infoIcon.alt=`Info icon`,this.infoIcon.src=zC,this.infoIcon.style.position=`absolute`,this.infoIcon.style.top=`4px`,this.infoIcon.style.right=`4px`,this.infoIcon.style.opacity=`0.6`,this.infoIcon.style.cursor=`pointer`,this.infoIcon.style.zIndex=`2`,this.infoIcon.style.width=`16px`,this.infoIcon.style.height=`16px`,this.infoIcon.onmouseover=function(e){return t.onHoverIn()},this.infoIcon.onmouseout=function(e){return t.onHoverOut()},this.infoIcon.onclick=function(e){return t.onClick()},e.appendChild(this.infoIcon)},e.prototype.onHoverIn=function(){this.isShowingInfoIcon&&(this.infoIcon.style.opacity=`1`)},e.prototype.onHoverOut=function(){this.isShowingInfoIcon&&(this.infoIcon.style.opacity=`0.6`)},e.prototype.onClick=function(){this.isShowingInfoIcon?(this.isShowingInfoIcon=!1,this.onTapIn(),this.infoIcon.src=BC,this.infoIcon.style.opacity=`1`):(this.isShowingInfoIcon=!0,this.onTapOut(),this.infoIcon.src=zC,this.infoIcon.style.opacity=`0.6`)},e}(),GC=function(){function e(){var e=this;this.infoDiv=new UC,this.infoIcon=new WC(function(){e.infoDiv.show()},function(){e.infoDiv.hide()})}return e.prototype.renderInto=function(e){this.infoDiv.renderInto(e),this.infoIcon.renderInto(e)},e}(),KC=function(e,t,n,r){function i(e){return e instanceof n?e:new n(function(t){t(e)})}return new(n||=Promise)(function(n,a){function o(e){try{c(r.next(e))}catch(e){a(e)}}function s(e){try{c(r.throw(e))}catch(e){a(e)}}function c(e){e.done?n(e.value):i(e.value).then(o,s)}c((r=r.apply(e,t||[])).next())})},qC=function(e,t){var n={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},r,i,a,o;return o={next:s(0),throw:s(1),return:s(2)},typeof Symbol==`function`&&(o[Symbol.iterator]=function(){return this}),o;function s(e){return function(t){return c([e,t])}}function c(s){if(r)throw TypeError(`Generator is already executing.`);for(;o&&(o=0,s[0]&&(n=0)),n;)try{if(r=1,i&&(a=s[0]&2?i.return:s[0]?i.throw||((a=i.return)&&a.call(i),0):i.next)&&!(a=a.call(i,s[1])).done)return a;switch(i=0,a&&(s=[s[0]&2,a.value]),s[0]){case 0:case 1:a=s;break;case 4:return n.label++,{value:s[1],done:!1};case 5:n.label++,i=s[1],s=[0];continue;case 7:s=n.ops.pop(),n.trys.pop();continue;default:if((a=n.trys,!(a=a.length>0&&a[a.length-1]))&&(s[0]===6||s[0]===2)){n=0;continue}if(s[0]===3&&(!a||s[1]>a[0]&&s[1]<a[3])){n.label=s[1];break}if(s[0]===6&&n.label<a[1]){n.label=a[1],a=s;break}if(a&&n.label<a[2]){n.label=a[2],n.ops.push(s);break}a[2]&&n.ops.pop(),n.trys.pop();continue}s=t.call(e,n)}catch(e){s=[6,e],i=0}finally{r=a=0}if(s[0]&5)throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}},JC=function(){function e(){}return e.hasPermissions=function(){return KC(this,void 0,void 0,function(){var e,t,n,r;return qC(this,function(i){switch(i.label){case 0:return[4,navigator.mediaDevices.enumerateDevices()];case 1:for(e=i.sent(),t=0,n=e;t<n.length;t++)if(r=n[t],r.kind===`videoinput`&&r.label)return[2,!0];return[2,!1]}})})},e}(),YC=function(){function e(e){this.supportedScanTypes=this.validateAndReturnScanTypes(e)}return e.prototype.getDefaultScanType=function(){return this.supportedScanTypes[0]},e.prototype.hasMoreThanOneScanType=function(){return this.supportedScanTypes.length>1},e.prototype.isCameraScanRequired=function(){for(var t=0,n=this.supportedScanTypes;t<n.length;t++){var r=n[t];if(e.isCameraScanType(r))return!0}return!1},e.isCameraScanType=function(e){return e===KS.SCAN_TYPE_CAMERA},e.isFileScanType=function(e){return e===KS.SCAN_TYPE_FILE},e.prototype.validateAndReturnScanTypes=function(e){if(!e||e.length===0)return qS.DEFAULT_SUPPORTED_SCAN_TYPE;var t=qS.DEFAULT_SUPPORTED_SCAN_TYPE.length;if(e.length>t)throw`Max ${t} values expected for supportedScanTypes`;for(var n=0,r=e;n<r.length;n++){var i=r[n];if(!qS.DEFAULT_SUPPORTED_SCAN_TYPE.includes(i))throw`Unsupported scan type ${i}`}return e},e}(),XC=function(){function e(){}return e.ALL_ELEMENT_CLASS=`html5-qrcode-element`,e.CAMERA_PERMISSION_BUTTON_ID=`html5-qrcode-button-camera-permission`,e.CAMERA_START_BUTTON_ID=`html5-qrcode-button-camera-start`,e.CAMERA_STOP_BUTTON_ID=`html5-qrcode-button-camera-stop`,e.TORCH_BUTTON_ID=`html5-qrcode-button-torch`,e.CAMERA_SELECTION_SELECT_ID=`html5-qrcode-select-camera`,e.FILE_SELECTION_BUTTON_ID=`html5-qrcode-button-file-selection`,e.ZOOM_SLIDER_ID=`html5-qrcode-input-range-zoom`,e.SCAN_TYPE_CHANGE_ANCHOR_ID=`html5-qrcode-anchor-scan-type-change`,e.TORCH_BUTTON_CLASS_TORCH_ON=`html5-qrcode-button-torch-on`,e.TORCH_BUTTON_CLASS_TORCH_OFF=`html5-qrcode-button-torch-off`,e}(),ZC=function(){function e(){}return e.createElement=function(e,t){var n=document.createElement(e);return n.id=t,n.classList.add(XC.ALL_ELEMENT_CLASS),e===`button`&&n.setAttribute(`type`,`button`),n},e}(),QC=function(e,t,n,r){function i(e){return e instanceof n?e:new n(function(t){t(e)})}return new(n||=Promise)(function(n,a){function o(e){try{c(r.next(e))}catch(e){a(e)}}function s(e){try{c(r.throw(e))}catch(e){a(e)}}function c(e){e.done?n(e.value):i(e.value).then(o,s)}c((r=r.apply(e,t||[])).next())})},$C=function(e,t){var n={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},r,i,a,o;return o={next:s(0),throw:s(1),return:s(2)},typeof Symbol==`function`&&(o[Symbol.iterator]=function(){return this}),o;function s(e){return function(t){return c([e,t])}}function c(s){if(r)throw TypeError(`Generator is already executing.`);for(;o&&(o=0,s[0]&&(n=0)),n;)try{if(r=1,i&&(a=s[0]&2?i.return:s[0]?i.throw||((a=i.return)&&a.call(i),0):i.next)&&!(a=a.call(i,s[1])).done)return a;switch(i=0,a&&(s=[s[0]&2,a.value]),s[0]){case 0:case 1:a=s;break;case 4:return n.label++,{value:s[1],done:!1};case 5:n.label++,i=s[1],s=[0];continue;case 7:s=n.ops.pop(),n.trys.pop();continue;default:if((a=n.trys,!(a=a.length>0&&a[a.length-1]))&&(s[0]===6||s[0]===2)){n=0;continue}if(s[0]===3&&(!a||s[1]>a[0]&&s[1]<a[3])){n.label=s[1];break}if(s[0]===6&&n.label<a[1]){n.label=a[1],a=s;break}if(a&&n.label<a[2]){n.label=a[2],n.ops.push(s);break}a[2]&&n.ops.pop(),n.trys.pop();continue}s=t.call(e,n)}catch(e){s=[6,e],i=0}finally{r=a=0}if(s[0]&5)throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}},ew=function(){function e(e,t,n){this.isTorchOn=!1,this.torchCapability=e,this.buttonController=t,this.onTorchActionFailureCallback=n}return e.prototype.isTorchEnabled=function(){return this.isTorchOn},e.prototype.flipState=function(){return QC(this,void 0,void 0,function(){var e,t;return $C(this,function(n){switch(n.label){case 0:this.buttonController.disable(),e=!this.isTorchOn,n.label=1;case 1:return n.trys.push([1,3,,4]),[4,this.torchCapability.apply(e)];case 2:return n.sent(),this.updateUiBasedOnLatestSettings(this.torchCapability.value(),e),[3,4];case 3:return t=n.sent(),this.propagateFailure(e,t),this.buttonController.enable(),[3,4];case 4:return[2]}})})},e.prototype.updateUiBasedOnLatestSettings=function(e,t){e===t?(this.buttonController.setText(t?nC.torchOffButton():nC.torchOnButton()),this.isTorchOn=t):this.propagateFailure(t),this.buttonController.enable()},e.prototype.propagateFailure=function(e,t){var n=e?nC.torchOnFailedMessage():nC.torchOffFailedMessage();t&&(n+=`; Error = `+t),this.onTorchActionFailureCallback(n)},e.prototype.reset=function(){this.isTorchOn=!1},e}(),tw=function(){function e(e,t){this.onTorchActionFailureCallback=t,this.torchButton=ZC.createElement(`button`,XC.TORCH_BUTTON_ID),this.torchController=new ew(e,this,t)}return e.prototype.render=function(e,t){var n=this;this.torchButton.innerText=nC.torchOnButton(),this.torchButton.style.display=t.display,this.torchButton.style.marginLeft=t.marginLeft;var r=this;this.torchButton.addEventListener(`click`,function(e){return QC(n,void 0,void 0,function(){return $C(this,function(e){switch(e.label){case 0:return[4,r.torchController.flipState()];case 1:return e.sent(),r.torchController.isTorchEnabled()?(r.torchButton.classList.remove(XC.TORCH_BUTTON_CLASS_TORCH_OFF),r.torchButton.classList.add(XC.TORCH_BUTTON_CLASS_TORCH_ON)):(r.torchButton.classList.remove(XC.TORCH_BUTTON_CLASS_TORCH_ON),r.torchButton.classList.add(XC.TORCH_BUTTON_CLASS_TORCH_OFF)),[2]}})})}),e.appendChild(this.torchButton)},e.prototype.updateTorchCapability=function(e){this.torchController=new ew(e,this,this.onTorchActionFailureCallback)},e.prototype.getTorchButton=function(){return this.torchButton},e.prototype.hide=function(){this.torchButton.style.display=`none`},e.prototype.show=function(){this.torchButton.style.display=`inline-block`},e.prototype.disable=function(){this.torchButton.disabled=!0},e.prototype.enable=function(){this.torchButton.disabled=!1},e.prototype.setText=function(e){this.torchButton.innerText=e},e.prototype.reset=function(){this.torchButton.innerText=nC.torchOnButton(),this.torchController.reset()},e.create=function(t,n,r,i){var a=new e(n,i);return a.render(t,r),a},e}(),nw=function(){function e(e,t,n){this.fileBasedScanRegion=this.createFileBasedScanRegion(),this.fileBasedScanRegion.style.display=t?`block`:`none`,e.appendChild(this.fileBasedScanRegion);var r=document.createElement(`label`);r.setAttribute(`for`,this.getFileScanInputId()),r.style.display=`inline-block`,this.fileBasedScanRegion.appendChild(r),this.fileSelectionButton=ZC.createElement(`button`,XC.FILE_SELECTION_BUTTON_ID),this.setInitialValueToButton(),this.fileSelectionButton.addEventListener(`click`,function(e){r.click()}),r.append(this.fileSelectionButton),this.fileScanInput=ZC.createElement(`input`,this.getFileScanInputId()),this.fileScanInput.type=`file`,this.fileScanInput.accept=`image/*`,this.fileScanInput.style.display=`none`,r.appendChild(this.fileScanInput);var i=this;this.fileScanInput.addEventListener(`change`,function(e){if(!(e==null||e.target==null)){var t=e.target;if(!(t.files&&t.files.length===0)){var r=t.files[0],a=r.name;i.setImageNameToButton(a),n(r)}}});var a=this.createDragAndDropMessage();this.fileBasedScanRegion.appendChild(a),this.fileBasedScanRegion.addEventListener(`dragenter`,function(e){i.fileBasedScanRegion.style.border=i.fileBasedScanRegionActiveBorder(),e.stopPropagation(),e.preventDefault()}),this.fileBasedScanRegion.addEventListener(`dragleave`,function(e){i.fileBasedScanRegion.style.border=i.fileBasedScanRegionDefaultBorder(),e.stopPropagation(),e.preventDefault()}),this.fileBasedScanRegion.addEventListener(`dragover`,function(e){i.fileBasedScanRegion.style.border=i.fileBasedScanRegionActiveBorder(),e.stopPropagation(),e.preventDefault()}),this.fileBasedScanRegion.addEventListener(`drop`,function(e){e.stopPropagation(),e.preventDefault(),i.fileBasedScanRegion.style.border=i.fileBasedScanRegionDefaultBorder();var t=e.dataTransfer;if(t){var r=t.files;if(!r||r.length===0)return;for(var o=!1,s=0;s<r.length;++s){var c=r.item(s);if(c&&c.type.match(/image.*/)){o=!0;var l=c.name;i.setImageNameToButton(l),n(c),a.innerText=nC.dragAndDropMessage();break}}o||(a.innerText=nC.dragAndDropMessageOnlyImages())}})}return e.prototype.hide=function(){this.fileBasedScanRegion.style.display=`none`,this.fileScanInput.disabled=!0},e.prototype.show=function(){this.fileBasedScanRegion.style.display=`block`,this.fileScanInput.disabled=!1},e.prototype.isShowing=function(){return this.fileBasedScanRegion.style.display===`block`},e.prototype.resetValue=function(){this.fileScanInput.value=``,this.setInitialValueToButton()},e.prototype.createFileBasedScanRegion=function(){var e=document.createElement(`div`);return e.style.textAlign=`center`,e.style.margin=`auto`,e.style.width=`80%`,e.style.maxWidth=`600px`,e.style.border=this.fileBasedScanRegionDefaultBorder(),e.style.padding=`10px`,e.style.marginBottom=`10px`,e},e.prototype.fileBasedScanRegionDefaultBorder=function(){return`6px dashed #ebebeb`},e.prototype.fileBasedScanRegionActiveBorder=function(){return`6px dashed rgb(153 151 151)`},e.prototype.createDragAndDropMessage=function(){var e=document.createElement(`div`);return e.innerText=nC.dragAndDropMessage(),e.style.fontWeight=`400`,e},e.prototype.setImageNameToButton=function(e){if(e.length>20){var t=e.substring(0,8),n=e.length;e=`${t}....${e.substring(n-8,n)}`}var r=nC.fileSelectionChooseAnother()+` - `+e;this.fileSelectionButton.innerText=r},e.prototype.setInitialValueToButton=function(){var e=nC.fileSelectionChooseImage()+` - `+nC.fileSelectionNoImageSelected();this.fileSelectionButton.innerText=e},e.prototype.getFileScanInputId=function(){return`html5-qrcode-private-filescan-input`},e.create=function(t,n,r){return new e(t,n,r)},e}(),rw=function(){function e(e){this.selectElement=ZC.createElement(`select`,XC.CAMERA_SELECTION_SELECT_ID),this.cameras=e,this.options=[]}return e.prototype.render=function(e){var t=document.createElement(`span`);t.style.marginRight=`10px`;var n=this.cameras.length;if(n===0)throw Error(`No cameras found`);n===1?t.style.display=`none`:t.innerText=`${nC.selectCamera()} (${this.cameras.length}) `;for(var r=1,i=0,a=this.cameras;i<a.length;i++){var o=a[i],s=o.id,c=o.label==null?s:o.label;(!c||c===``)&&(c=[nC.anonymousCameraPrefix(),r++].join(` `));var l=document.createElement(`option`);l.value=s,l.innerText=c,this.options.push(l),this.selectElement.appendChild(l)}t.appendChild(this.selectElement),e.appendChild(t)},e.prototype.disable=function(){this.selectElement.disabled=!0},e.prototype.isDisabled=function(){return this.selectElement.disabled===!0},e.prototype.enable=function(){this.selectElement.disabled=!1},e.prototype.getValue=function(){return this.selectElement.value},e.prototype.hasValue=function(e){for(var t=0,n=this.options;t<n.length;t++)if(n[t].value===e)return!0;return!1},e.prototype.setValue=function(e){if(!this.hasValue(e))throw Error(`${e} is not present in the camera list.`);this.selectElement.value=e},e.prototype.hasSingleItem=function(){return this.cameras.length===1},e.prototype.numCameras=function(){return this.cameras.length},e.create=function(t,n){var r=new e(n);return r.render(t),r},e}(),iw=function(){function e(){this.onChangeCallback=null,this.zoomElementContainer=document.createElement(`div`),this.rangeInput=ZC.createElement(`input`,XC.ZOOM_SLIDER_ID),this.rangeInput.type=`range`,this.rangeText=document.createElement(`span`),this.rangeInput.min=`1`,this.rangeInput.max=`5`,this.rangeInput.value=`1`,this.rangeInput.step=`0.1`}return e.prototype.render=function(e,t){this.zoomElementContainer.style.display=t?`block`:`none`,this.zoomElementContainer.style.padding=`5px 10px`,this.zoomElementContainer.style.textAlign=`center`,e.appendChild(this.zoomElementContainer),this.rangeInput.style.display=`inline-block`,this.rangeInput.style.width=`50%`,this.rangeInput.style.height=`5px`,this.rangeInput.style.background=`#d3d3d3`,this.rangeInput.style.outline=`none`,this.rangeInput.style.opacity=`0.7`;var n=nC.zoom();this.rangeText.innerText=`${this.rangeInput.value}x ${n}`,this.rangeText.style.marginRight=`10px`;var r=this;this.rangeInput.addEventListener(`input`,function(){return r.onValueChange()}),this.rangeInput.addEventListener(`change`,function(){return r.onValueChange()}),this.zoomElementContainer.appendChild(this.rangeInput),this.zoomElementContainer.appendChild(this.rangeText)},e.prototype.onValueChange=function(){var e=nC.zoom();this.rangeText.innerText=`${this.rangeInput.value}x ${e}`,this.onChangeCallback&&this.onChangeCallback(parseFloat(this.rangeInput.value))},e.prototype.setValues=function(e,t,n,r){this.rangeInput.min=e.toString(),this.rangeInput.max=t.toString(),this.rangeInput.step=r.toString(),this.rangeInput.value=n.toString(),this.onValueChange()},e.prototype.show=function(){this.zoomElementContainer.style.display=`block`},e.prototype.hide=function(){this.zoomElementContainer.style.display=`none`},e.prototype.setOnCameraZoomValueChangeCallback=function(e){this.onChangeCallback=e},e.prototype.removeOnCameraZoomValueChangeCallback=function(){this.onChangeCallback=null},e.create=function(t,n){var r=new e;return r.render(t,n),r},e}(),aw;(function(e){e[e.STATUS_DEFAULT=0]=`STATUS_DEFAULT`,e[e.STATUS_SUCCESS=1]=`STATUS_SUCCESS`,e[e.STATUS_WARNING=2]=`STATUS_WARNING`,e[e.STATUS_REQUESTING_PERMISSION=3]=`STATUS_REQUESTING_PERMISSION`})(aw||={});function ow(e){return{fps:e.fps,qrbox:e.qrbox,aspectRatio:e.aspectRatio,disableFlip:e.disableFlip,videoConstraints:e.videoConstraints}}function sw(e,t){return{formatsToSupport:e.formatsToSupport,useBarCodeDetectorIfSupported:e.useBarCodeDetectorIfSupported,experimentalFeatures:e.experimentalFeatures,verbose:t}}(function(){function e(e,t,n){if(this.lastMatchFound=null,this.cameraScanImage=null,this.fileScanImage=null,this.fileSelectionUi=null,this.elementId=e,this.config=this.createConfig(t),this.verbose=n===!0,!document.getElementById(e))throw`HTML Element with id=${e} not found`;this.scanTypeSelector=new YC(this.config.supportedScanTypes),this.currentScanType=this.scanTypeSelector.getDefaultScanType(),this.sectionSwapAllowed=!0,this.logger=new QS(this.verbose),this.persistedDataManager=new HC,t.rememberLastUsedCamera!==!0&&this.persistedDataManager.reset()}return e.prototype.render=function(e,t){var n=this;this.lastMatchFound=null,this.qrCodeSuccessCallback=function(t,r){if(e)e(t,r);else{if(n.lastMatchFound===t)return;n.lastMatchFound=t,n.setHeaderMessage(nC.lastMatch(t),aw.STATUS_SUCCESS)}},this.qrCodeErrorCallback=function(e,n){t&&t(e,n)};var r=document.getElementById(this.elementId);if(!r)throw`HTML Element with id=${this.elementId} not found`;r.innerHTML=``,this.createBasicLayout(r),this.html5Qrcode=new FC(this.getScanRegionId(),sw(this.config,this.verbose))},e.prototype.pause=function(e){($S(e)||e!==!0)&&(e=!1),this.getHtml5QrcodeOrFail().pause(e)},e.prototype.resume=function(){this.getHtml5QrcodeOrFail().resume()},e.prototype.getState=function(){return this.getHtml5QrcodeOrFail().getState()},e.prototype.clear=function(){var e=this,t=function(){var t=document.getElementById(e.elementId);t&&(t.innerHTML=``,e.resetBasicLayout(t))};return this.html5Qrcode?new Promise(function(n,r){if(!e.html5Qrcode){n();return}e.html5Qrcode.isScanning?e.html5Qrcode.stop().then(function(r){if(!e.html5Qrcode){n();return}e.html5Qrcode.clear(),t(),n()}).catch(function(t){e.verbose&&e.logger.logError(`Unable to stop qrcode scanner`,t),r(t)}):(e.html5Qrcode.clear(),t(),n())}):Promise.resolve()},e.prototype.getRunningTrackCapabilities=function(){return this.getHtml5QrcodeOrFail().getRunningTrackCapabilities()},e.prototype.getRunningTrackSettings=function(){return this.getHtml5QrcodeOrFail().getRunningTrackSettings()},e.prototype.applyVideoConstraints=function(e){return this.getHtml5QrcodeOrFail().applyVideoConstraints(e)},e.prototype.getHtml5QrcodeOrFail=function(){if(!this.html5Qrcode)throw`Code scanner not initialized.`;return this.html5Qrcode},e.prototype.createConfig=function(e){return e?(e.fps||=qS.SCAN_DEFAULT_FPS,e.rememberLastUsedCamera!==!qS.DEFAULT_REMEMBER_LAST_CAMERA_USED&&(e.rememberLastUsedCamera=qS.DEFAULT_REMEMBER_LAST_CAMERA_USED),e.supportedScanTypes||=qS.DEFAULT_SUPPORTED_SCAN_TYPE,e):{fps:qS.SCAN_DEFAULT_FPS,rememberLastUsedCamera:qS.DEFAULT_REMEMBER_LAST_CAMERA_USED,supportedScanTypes:qS.DEFAULT_SUPPORTED_SCAN_TYPE}},e.prototype.createBasicLayout=function(e){e.style.position=`relative`,e.style.padding=`0px`,e.style.border=`1px solid silver`,this.createHeader(e);var t=document.createElement(`div`);t.id=this.getScanRegionId(),t.style.width=`100%`,t.style.minHeight=`100px`,t.style.textAlign=`center`,e.appendChild(t),YC.isCameraScanType(this.currentScanType)?this.insertCameraScanImageToScanRegion():this.insertFileScanImageToScanRegion();var n=document.createElement(`div`);n.id=this.getDashboardId(),n.style.width=`100%`,e.appendChild(n),this.setupInitialDashboard(n)},e.prototype.resetBasicLayout=function(e){e.style.border=`none`},e.prototype.setupInitialDashboard=function(e){this.createSection(e),this.createSectionControlPanel(),this.scanTypeSelector.hasMoreThanOneScanType()&&this.createSectionSwap()},e.prototype.createHeader=function(e){var t=document.createElement(`div`);t.style.textAlign=`left`,t.style.margin=`0px`,e.appendChild(t),new GC().renderInto(t);var n=document.createElement(`div`);n.id=this.getHeaderMessageContainerId(),n.style.display=`none`,n.style.textAlign=`center`,n.style.fontSize=`14px`,n.style.padding=`2px 10px`,n.style.margin=`4px`,n.style.borderTop=`1px solid #f6f6f6`,t.appendChild(n)},e.prototype.createSection=function(e){var t=document.createElement(`div`);t.id=this.getDashboardSectionId(),t.style.width=`100%`,t.style.padding=`10px 0px 10px 0px`,t.style.textAlign=`left`,e.appendChild(t)},e.prototype.createCameraListUi=function(e,t,n){var r=this;r.showHideScanTypeSwapLink(!1),r.setHeaderMessage(nC.cameraPermissionRequesting());var i=function(){n||r.createPermissionButton(e,t)};FC.getCameras().then(function(n){r.persistedDataManager.setHasPermission(!0),r.showHideScanTypeSwapLink(!0),r.resetHeaderMessage(),n&&n.length>0?(e.removeChild(t),r.renderCameraSelection(n)):(r.setHeaderMessage(nC.noCameraFound(),aw.STATUS_WARNING),i())}).catch(function(e){r.persistedDataManager.setHasPermission(!1),n?n.disabled=!1:i(),r.setHeaderMessage(e,aw.STATUS_WARNING),r.showHideScanTypeSwapLink(!0)})},e.prototype.createPermissionButton=function(e,t){var n=this,r=ZC.createElement(`button`,this.getCameraPermissionButtonId());r.innerText=nC.cameraPermissionTitle(),r.addEventListener(`click`,function(){r.disabled=!0,n.createCameraListUi(e,t,r)}),t.appendChild(r)},e.prototype.createPermissionsUi=function(e,t){var n=this;if(YC.isCameraScanType(this.currentScanType)&&this.persistedDataManager.hasCameraPermissions()){JC.hasPermissions().then(function(r){r?n.createCameraListUi(e,t):(n.persistedDataManager.setHasPermission(!1),n.createPermissionButton(e,t))}).catch(function(r){n.persistedDataManager.setHasPermission(!1),n.createPermissionButton(e,t)});return}this.createPermissionButton(e,t)},e.prototype.createSectionControlPanel=function(){var e=document.getElementById(this.getDashboardSectionId()),t=document.createElement(`div`);e.appendChild(t);var n=document.createElement(`div`);n.id=this.getDashboardSectionCameraScanRegionId(),n.style.display=YC.isCameraScanType(this.currentScanType)?`block`:`none`,t.appendChild(n);var r=document.createElement(`div`);r.style.textAlign=`center`,n.appendChild(r),this.scanTypeSelector.isCameraScanRequired()&&this.createPermissionsUi(n,r),this.renderFileScanUi(t)},e.prototype.renderFileScanUi=function(e){var t=YC.isFileScanType(this.currentScanType),n=this,r=function(e){if(!n.html5Qrcode)throw`html5Qrcode not defined`;YC.isFileScanType(n.currentScanType)&&(n.setHeaderMessage(nC.loadingImage()),n.html5Qrcode.scanFileV2(e,!0).then(function(e){n.resetHeaderMessage(),n.qrCodeSuccessCallback(e.decodedText,e)}).catch(function(e){n.setHeaderMessage(e,aw.STATUS_WARNING),n.qrCodeErrorCallback(e,ZS.createFrom(e))}))};this.fileSelectionUi=nw.create(e,t,r)},e.prototype.renderCameraSelection=function(e){var t=this,n=this,r=document.getElementById(this.getDashboardSectionCameraScanRegionId());r.style.textAlign=`center`;var i=iw.create(r,!1),a=function(e){var n=e.zoomFeature();if(n.isSupported()){i.setOnCameraZoomValueChangeCallback(function(e){n.apply(e)});var r=1;t.config.defaultZoomValueIfSupported&&(r=t.config.defaultZoomValueIfSupported),r=eC(r,n.min(),n.max()),i.setValues(n.min(),n.max(),r,n.step()),i.show()}},o=rw.create(r,e),s=document.createElement(`span`),c=ZC.createElement(`button`,XC.CAMERA_START_BUTTON_ID);c.innerText=nC.scanButtonStartScanningText(),s.appendChild(c);var l=ZC.createElement(`button`,XC.CAMERA_STOP_BUTTON_ID);l.innerText=nC.scanButtonStopScanningText(),l.style.display=`none`,l.disabled=!0,s.appendChild(l);var u,d=function(e){if(!e.torchFeature().isSupported()){u&&u.hide();return}u?u.updateTorchCapability(e.torchFeature()):u=tw.create(s,e.torchFeature(),{display:`none`,marginLeft:`5px`},function(e){n.setHeaderMessage(e,aw.STATUS_WARNING)}),u.show()};r.appendChild(s);var f=function(e){e||(c.style.display=`none`),c.innerText=nC.scanButtonStartScanningText(),c.style.opacity=`1`,c.disabled=!1,e&&(c.style.display=`inline-block`)};if(c.addEventListener(`click`,function(e){c.innerText=nC.scanButtonScanningStarting(),o.disable(),c.disabled=!0,c.style.opacity=`0.5`,t.scanTypeSelector.hasMoreThanOneScanType()&&n.showHideScanTypeSwapLink(!1),n.resetHeaderMessage();var r=o.getValue();n.persistedDataManager.setLastUsedCameraId(r),n.html5Qrcode.start(r,ow(n.config),n.qrCodeSuccessCallback,n.qrCodeErrorCallback).then(function(e){l.disabled=!1,l.style.display=`inline-block`,f(!1);var r=n.html5Qrcode.getRunningTrackCameraCapabilities();t.config.showTorchButtonIfSupported===!0&&d(r),t.config.showZoomSliderIfSupported===!0&&a(r)}).catch(function(e){n.showHideScanTypeSwapLink(!0),o.enable(),f(!0),n.setHeaderMessage(e,aw.STATUS_WARNING)})}),o.hasSingleItem()&&c.click(),l.addEventListener(`click`,function(e){if(!n.html5Qrcode)throw`html5Qrcode not defined`;l.disabled=!0,n.html5Qrcode.stop().then(function(e){t.scanTypeSelector.hasMoreThanOneScanType()&&n.showHideScanTypeSwapLink(!0),o.enable(),c.disabled=!1,l.style.display=`none`,c.style.display=`inline-block`,u&&(u.reset(),u.hide()),i.removeOnCameraZoomValueChangeCallback(),i.hide(),n.insertCameraScanImageToScanRegion()}).catch(function(e){l.disabled=!1,n.setHeaderMessage(e,aw.STATUS_WARNING)})}),n.persistedDataManager.getLastUsedCameraId()){var p=n.persistedDataManager.getLastUsedCameraId();o.hasValue(p)?(o.setValue(p),c.click()):n.persistedDataManager.resetLastUsedCameraId()}},e.prototype.createSectionSwap=function(){var e=this,t=nC.textIfCameraScanSelected(),n=nC.textIfFileScanSelected(),r=document.getElementById(this.getDashboardSectionId()),i=document.createElement(`div`);i.style.textAlign=`center`;var a=ZC.createElement(`span`,this.getDashboardSectionSwapLinkId());a.style.textDecoration=`underline`,a.style.cursor=`pointer`,a.innerText=YC.isCameraScanType(this.currentScanType)?t:n,a.addEventListener(`click`,function(){if(!e.sectionSwapAllowed){e.verbose&&e.logger.logError(`Section swap called when not allowed`);return}e.resetHeaderMessage(),e.fileSelectionUi.resetValue(),e.sectionSwapAllowed=!1,YC.isCameraScanType(e.currentScanType)?(e.clearScanRegion(),e.getCameraScanRegion().style.display=`none`,e.fileSelectionUi.show(),a.innerText=n,e.currentScanType=KS.SCAN_TYPE_FILE,e.insertFileScanImageToScanRegion()):(e.clearScanRegion(),e.getCameraScanRegion().style.display=`block`,e.fileSelectionUi.hide(),a.innerText=t,e.currentScanType=KS.SCAN_TYPE_CAMERA,e.insertCameraScanImageToScanRegion(),e.startCameraScanIfPermissionExistsOnSwap()),e.sectionSwapAllowed=!0}),i.appendChild(a),r.appendChild(i)},e.prototype.startCameraScanIfPermissionExistsOnSwap=function(){var e=this,t=this;if(this.persistedDataManager.hasCameraPermissions()){JC.hasPermissions().then(function(n){if(n){var r=document.getElementById(t.getCameraPermissionButtonId());if(!r)throw e.logger.logError(`Permission button not found, fail;`),`Permission button not found`;r.click()}else t.persistedDataManager.setHasPermission(!1)}).catch(function(e){t.persistedDataManager.setHasPermission(!1)});return}},e.prototype.resetHeaderMessage=function(){var e=document.getElementById(this.getHeaderMessageContainerId());e.style.display=`none`},e.prototype.setHeaderMessage=function(e,t){t||=aw.STATUS_DEFAULT;var n=this.getHeaderMessageDiv();switch(n.innerText=e,n.style.display=`block`,t){case aw.STATUS_SUCCESS:n.style.background=`rgba(106, 175, 80, 0.26)`,n.style.color=`#477735`;break;case aw.STATUS_WARNING:n.style.background=`rgba(203, 36, 49, 0.14)`,n.style.color=`#cb2431`;break;case aw.STATUS_DEFAULT:default:n.style.background=`rgba(0, 0, 0, 0)`,n.style.color=`rgb(17, 17, 17)`;break}},e.prototype.showHideScanTypeSwapLink=function(e){this.scanTypeSelector.hasMoreThanOneScanType()&&(e!==!0&&(e=!1),this.sectionSwapAllowed=e,this.getDashboardSectionSwapLink().style.display=e?`inline-block`:`none`)},e.prototype.insertCameraScanImageToScanRegion=function(){var e=this,t=document.getElementById(this.getScanRegionId());if(this.cameraScanImage){t.innerHTML=`<br>`,t.appendChild(this.cameraScanImage);return}this.cameraScanImage=new Image,this.cameraScanImage.onload=function(n){t.innerHTML=`<br>`,t.appendChild(e.cameraScanImage)},this.cameraScanImage.width=64,this.cameraScanImage.style.opacity=`0.8`,this.cameraScanImage.src=LC,this.cameraScanImage.alt=nC.cameraScanAltText()},e.prototype.insertFileScanImageToScanRegion=function(){var e=this,t=document.getElementById(this.getScanRegionId());if(this.fileScanImage){t.innerHTML=`<br>`,t.appendChild(this.fileScanImage);return}this.fileScanImage=new Image,this.fileScanImage.onload=function(n){t.innerHTML=`<br>`,t.appendChild(e.fileScanImage)},this.fileScanImage.width=64,this.fileScanImage.style.opacity=`0.8`,this.fileScanImage.src=RC,this.fileScanImage.alt=nC.fileScanAltText()},e.prototype.clearScanRegion=function(){var e=document.getElementById(this.getScanRegionId());e.innerHTML=``},e.prototype.getDashboardSectionId=function(){return`${this.elementId}__dashboard_section`},e.prototype.getDashboardSectionCameraScanRegionId=function(){return`${this.elementId}__dashboard_section_csr`},e.prototype.getDashboardSectionSwapLinkId=function(){return XC.SCAN_TYPE_CHANGE_ANCHOR_ID},e.prototype.getScanRegionId=function(){return`${this.elementId}__scan_region`},e.prototype.getDashboardId=function(){return`${this.elementId}__dashboard`},e.prototype.getHeaderMessageContainerId=function(){return`${this.elementId}__header_message`},e.prototype.getCameraPermissionButtonId=function(){return XC.CAMERA_PERMISSION_BUTTON_ID},e.prototype.getCameraScanRegion=function(){return document.getElementById(this.getDashboardSectionCameraScanRegionId())},e.prototype.getDashboardSectionSwapLink=function(){return document.getElementById(this.getDashboardSectionSwapLinkId())},e.prototype.getHeaderMessageDiv=function(){return document.getElementById(this.getHeaderMessageContainerId())},e})();var cw;(function(e){e[e.BACK=1]=`BACK`,e[e.FRONT=2]=`FRONT`})(cw||={});var lw;(function(e){e[e.PORTRAIT=1]=`PORTRAIT`,e[e.LANDSCAPE=2]=`LANDSCAPE`,e[e.ADAPTIVE=3]=`ADAPTIVE`})(lw||={});var uw;(function(e){e[e.ALL=17]=`ALL`})(uw||={});var dw=Object.assign(Object.assign({},HS),uw),fw;(function(e){e.ZXING=`zxing`,e.MLKIT=`mlkit`})(fw||={});var pw=[{selector:`.scanner-container-display`,css:`display: block;`},{selector:`.scanner-dialog`,css:`display: none; position: fixed; z-index: 999; left: 0; top: 0; width: 100%; height: 100%; overflow: auto; background-color: rgba(0,0,0,0.4);`},{selector:`.scanner-dialog-inner`,css:`background-color: #fefefe; margin: 2% auto; padding: 20px; border: 1px solid #888; width: 96%;`},{selector:`.close-button`,css:`color: #aaa; float: right; font-size: 28px; font-weight: bold; cursor: pointer;`},{selector:`.close-button:hover`,css:`color: #222;`},{selector:`.scanner-container-full-width`,css:`width: 100%;`}];function mw(e){let t=`custom-style-os-cap-barcode`,n=document.getElementById(t);if(n||(n=document.createElement(`style`),n.type=`text/css`,n.id=t,document.head.appendChild(n)),n.sheet){for(;n.sheet.cssRules.length;)n.sheet.deleteRule(0);for(let{selector:t,css:r}of e)n.sheet.insertRule(`${t} { ${r} }`)}else{n.textContent=``;for(let{selector:t,css:r}of e)n.textContent+=`${t} { ${r} }`}}var hw=f_(`CapacitorBarcodeScanner`,{web:()=>(mw(pw),po(()=>import(`./web-DeCAC9ap.js`).then(e=>new e.CapacitorBarcodeScannerWeb),[]))}),gw=class{static async scanBarcode(e){return e.scanInstructions=e.scanInstructions||` `,e.scanButton=e.scanButton||!1,e.scanText=e.scanText||` `,e.cameraDirection=e.cameraDirection||cw.BACK,e.scanOrientation=e.scanOrientation||lw.ADAPTIVE,hw.scanBarcode(e)}};function _w(e){if(e instanceof Error){let t=e.message.toLowerCase();return t.includes(`permission`)||t.includes(`denied`)||t.includes(`not allowed`)||t.includes(`unauthorized`)}return!1}function vw(e){if(e instanceof Error){let t=e.message.toLowerCase();return t.includes(`cancel`)||t.includes(`user cancelled`)||t.includes(`scan cancelled`)}return!1}function yw(){let[e,t]=(0,Z.useState)(!1);return{scan:(0,Z.useCallback)(async()=>{if(!q())return{value:null,error:null};t(!0);try{let e=await gw.scanBarcode({hint:dw.QR_CODE,scanInstructions:`Point the camera at a Tarsk QR code`});return e?.ScanResult?{value:e.ScanResult,error:null}:{value:null,error:null}}catch(e){return vw(e)?{value:null,error:null}:_w(e)?{value:null,error:`Camera permission was denied. Please grant camera access in your device settings to scan QR codes.`}:{value:null,error:`Unable to scan QR code. Please make sure your device has a camera and try again.`}}finally{t(!1)}},[]),isScanning:e,isAvailable:q()}}function bw(){let[e,t]=(0,Z.useState)(!0),[n,r]=(0,Z.useState)(an),[i,a]=(0,Z.useState)(null),[o,s]=(0,Z.useState)(null),[c,l]=(0,Z.useState)(!1),u=yw();(0,Z.useEffect)(()=>{let e=!0;return(async()=>{try{let n=await fetch(`${qn()}/health`,{method:`GET`});e&&t(n.ok)}catch{e&&t(!1)}})(),()=>{e=!1}},[]);let d=(0,Z.useCallback)(async()=>{let e=Tr(n);if(e){a(null),l(!0);try{if(!await pn(e)){a(e);return}qt(n)}finally{l(!1)}}},[n]),f=(0,Z.useCallback)(async()=>{s(null);let e=await u.scan();if(e.error){s(e.error);return}if(e.value){r(e.value),a(null);let t=Tr(e.value);if(!t){s(`The scanned QR code did not contain a valid server address.`);return}l(!0);try{if(!await pn(t)){a(t);return}qt(e.value)}finally{l(!1)}}},[u]);return e?null:(0,$.jsx)(Mi,{open:!0,children:(0,$.jsxs)(Ci,{children:[(0,$.jsxs)(ia,{children:[(0,$.jsx)(`img`,{src:`/tarsk-color.svg`,alt:`Tarsk`,className:`mx-auto h-16 w-16 rounded-lg`}),(0,$.jsx)(ca,{children:`Connect to Tarsk`}),(0,$.jsx)(qa,{children:`Connect to the Tarsk server running on your local network by entering the IP Address or domain name below.`})]}),(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(Lt,{value:n,onChange:e=>{r(e.target.value),a(null),s(null)},onKeyDown:e=>{e.key===`Enter`&&!c&&d()},placeholder:`192.168.1.100`,autoComplete:`off`,spellCheck:!1,disabled:c,className:u.isAvailable?`pr-10`:void 0}),u.isAvailable&&(0,$.jsx)(Fe,{type:`button`,variant:`ghost`,size:`icon`,className:`absolute right-1 top-1 h-8 w-8`,"aria-label":`Scan QR code`,disabled:c||u.isScanning,onClick:()=>void f(),children:u.isScanning?(0,$.jsx)(sn,{className:`h-4 w-4 animate-spin`}):(0,$.jsx)(lt,{className:`h-4 w-4`})})]}),o&&(0,$.jsxs)(no,{variant:`error`,className:`mb-0 flex items-start gap-3`,children:[(0,$.jsx)(`p`,{className:`flex-1`,children:o}),(0,$.jsx)(Fe,{type:`button`,variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0`,"aria-label":`Dismiss error`,onClick:()=>s(null),children:(0,$.jsx)(Gt,{className:`h-4 w-4`})})]}),i&&(0,$.jsxs)(no,{variant:`error`,className:`mb-0 flex items-start gap-3`,children:[(0,$.jsxs)(`p`,{className:`flex-1`,children:[`Unable to connect to `,i,`. Please check that you are on the same network and that the Tarsk server is running and accessible on the network.`]}),(0,$.jsx)(Fe,{type:`button`,variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0`,"aria-label":`Dismiss error`,onClick:()=>a(null),children:(0,$.jsx)(Gt,{className:`h-4 w-4`})})]}),(0,$.jsx)(na,{children:(0,$.jsx)(Fe,{onClick:()=>void d(),disabled:!n.trim()||c,children:c?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(sn,{className:`mr-2 h-4 w-4 animate-spin`}),`Connecting...`]}):`Connect`})}),(0,$.jsxs)(no,{variant:`hint`,className:`mb-0`,children:[(0,$.jsx)(`p`,{className:J.bodyMuted,children:`Start the Tarsk server on your local machine by running:`}),(0,$.jsx)(`code`,{className:K(J.mono,`mt-2 block rounded bg-background/60 px-2 py-1 text-foreground`),children:`npx tarsk --server`})]})]})})}var xw=(0,Z.lazy)(()=>po(()=>import(`./dialogs-config-C2KFQf9x.js`).then(e=>e.t),__vite__mapDeps([4,1]))),Sw=(0,Z.lazy)(()=>po(()=>import(`./onboarding-CFIVEI92.js`).then(e=>e.t),__vite__mapDeps([5,1,6,4])));function Cw(e){let t=(0,Q.c)(28),{showCreateProject:n,createProjectInitialMode:r,onCreateProjectOpenChange:i,onSubmitClone:a,onSubmitWebApp:o,onSubmitFolder:s,deleteProject:c,onDeleteProjectOpenChange:l,onConfirmDeleteProject:u,pendingSetupScriptConfirmation:d,onResolveSetupScriptConfirmation:f,showOnboarding:p,onOnboardingOpenChange:m,onOnboardingComplete:h}=e,g=r??void 0,_;t[0]!==i||t[1]!==a||t[2]!==s||t[3]!==o||t[4]!==n||t[5]!==g?(_=(0,$.jsx)(Z.Suspense,{fallback:null,children:(0,$.jsx)(xw,{open:n,onOpenChange:i,initialMode:g,onSubmitClone:a,onSubmitWebApp:o,onSubmitFolder:s})}),t[0]=i,t[1]=a,t[2]=s,t[3]=o,t[4]=n,t[5]=g,t[6]=_):_=t[6];let v=c!==null,y=c?.name,b;t[7]!==u||t[8]!==l||t[9]!==v||t[10]!==y?(b=(0,$.jsx)(zS,{open:v,projectName:y,onOpenChange:l,onConfirm:u}),t[7]=u,t[8]=l,t[9]=v,t[10]=y,t[11]=b):b=t[11];let x=d!==null,S;t[12]===d?S=t[13]:(S=d?[d.command,...d.remainingScripts||[]]:[],t[12]=d,t[13]=S);let C;t[14]!==f||t[15]!==x||t[16]!==S?(C=(0,$.jsx)(BS,{open:x,setupScripts:S,onConfirm:f}),t[14]=f,t[15]=x,t[16]=S,t[17]=C):C=t[17];let w;t[18]!==h||t[19]!==m||t[20]!==p?(w=(0,$.jsx)(Z.Suspense,{fallback:null,children:(0,$.jsx)(Sw,{open:p,onOpenChange:m,onComplete:h})}),t[18]=h,t[19]=m,t[20]=p,t[21]=w):w=t[21];let T;t[22]===Symbol.for(`react.memo_cache_sentinel`)?(T=(0,$.jsx)(bw,{}),t[22]=T):T=t[22];let E;return t[23]!==_||t[24]!==b||t[25]!==C||t[26]!==w?(E=(0,$.jsxs)($.Fragment,{children:[_,b,C,w,T]}),t[23]=_,t[24]=b,t[25]=C,t[26]=w,t[27]=E):E=t[27],E}function ww(){let e=(0,Q.c)(7),{setIsSelectModeEnabled:t,setSelectedBrowserElement:n,setIsSelectionPromptOpen:r}=SS(),i;e[0]!==t||e[1]!==r||e[2]!==n?(i=e=>{n(e),r(!0),t(!1)},e[0]=t,e[1]=r,e[2]=n,e[3]=i):i=e[3];let a=i,o,s;e[4]===a?(o=e[5],s=e[6]):(o=()=>{let e=function(e){let t=e.detail;TS(t)&&a(t)},t=function(e){let t=ES(e.data);t&&a(t)};return window.addEventListener(CS,e),window.addEventListener(`message`,t),function(){window.removeEventListener(CS,e),window.removeEventListener(`message`,t)}},s=[a],e[4]=a,e[5]=o,e[6]=s),(0,Z.useEffect)(o,s)}var Tw=`__tarskBrowserCapture`,Ew=15e3,Dw=0,Ow=null,kw=new Set;function Aw(){for(let e of kw)e()}function jw(){Ow!=null&&(clearTimeout(Ow),Ow=null)}function Mw(){jw(),Dw!==0&&(Dw=0,Aw())}function Nw(){Dw+=1,jw(),Ow=setTimeout(Mw,Ew),Dw===1&&Aw()}function Pw(){Dw!==0&&(--Dw,!(Dw>0)&&(jw(),Aw()))}function Fw(){return Dw>0}function Iw(e){return kw.add(e),function(){kw.delete(e)}}function Lw(e){if(e!=null){let t=document.getElementById(`electrobun-webview-${e}`);if(t)return t}return document.querySelector(`electrobun-webview`)}function Rw(e,t){return e.width<=0||e.height<=0?null:{x:t.screenX+e.left,y:t.screenY+e.top,width:e.width,height:e.height}}function zw(e){let t=Lw(e);return t?Rw(t.getBoundingClientRect(),window):null}function Bw(){let e=window;return e[Tw]={begin:Nw,end:Pw,rect:zw},function(){delete e[Tw],Mw()}}var Vw=Pn(`app.use-browser-tool-listener.hook`);function Hw(e){let t=e.trim();return t?t.startsWith(`http://`)||t.startsWith(`https://`)?t:`http://${t}`:``}function Uw(){return document.querySelector(`electrobun-webview`)}function Ww(e=2e4){return new Promise((t,n)=>{let r=Date.now();function i(){let a=Uw();if(a&&a.webviewId!=null){t(a);return}if(Date.now()-r>e){n(Error(`Timed out waiting for preview webview to mount`));return}requestAnimationFrame(i)}requestAnimationFrame(i)})}async function Gw(e,t,n){switch(t.action){case`reload`:return e.reload(),{action:`reload`,webview_id:e.webviewId,current_url:n||e.src||null};case`go_back`:return e.goBack(),{action:`go_back`,webview_id:e.webviewId,current_url:n||e.src||null};case`go_forward`:return e.goForward(),{action:`go_forward`,webview_id:e.webviewId,current_url:n||e.src||null};case`get_state`:{let t=await e.canGoBack(),r=await e.canGoForward();return{action:`get_state`,webview_id:e.webviewId,current_url:n||e.src||null,can_go_back:t,can_go_forward:r}}default:throw Error(`Unsupported host browser action: ${String(t.action)}`)}}function Kw(e){let t=Date.now();function n(){if(Date.now()-t>2e4){Vw.error(`[browser-tool] timed out waiting for preview webview to mount (${e})`);return}let r=Uw();if(!r||r.webviewId==null){requestAnimationFrame(n);return}Iv(e,r.webviewId).catch(e=>{Vw.error(`[browser-tool] failed to report preview webview ready`,e)})}requestAnimationFrame(n)}async function qw(e,t,n){let{toolCallId:r,input:i}=e;if(!(!r||!i.action)){if(i.action===`set_viewport`){let e=i.preset??`desktop`;n(e);try{let t=await Ww();t.syncDimensions(!0),await Lv(r,{action:`set_viewport`,preset:e,webview_id:t.webviewId})}catch(t){Vw.error(`[browser-tool] failed to set viewport`,t),await Lv(r,{action:`set_viewport`,preset:e,error:t instanceof Error?t.message:String(t)})}return}if(V(i.action)){try{await Lv(r,await Gw(await Ww(),i,t))}catch(e){Vw.error(`[browser-tool] failed to execute host browser action`,e),await Lv(r,{action:i.action,error:e instanceof Error?e.message:String(e)})}return}Kw(r)}}function Jw(){let{openChatDockPanel:e}=Yc(),{expandWindow:t,hasOpenWindows:n}=vo(),{setDevServerUrl:r,devServerUrl:i}=Vh(),{setBrowserDeviceMode:a}=SS(),o=(0,Z.useRef)(null),s=X(e=>{let t=o.current;return t?e.threadStreamingStates[ja(t,`primary`)]?.isStreaming??!1:!1}),c=(0,Z.useRef)(i);c.current=i;let l=(0,Z.useRef)(e);l.current=e;let u=(0,Z.useRef)(t);u.current=t;let d=(0,Z.useRef)(n);d.current=n;let f=(0,Z.useRef)(r);f.current=r;let p=(0,Z.useRef)(a);p.current=a;let m=(0,Z.useRef)(!1);function h(){d.current&&u.current(dt)}(0,Z.useEffect)(()=>{if(!o.current){m.current=!1;return}let e=m.current;m.current=s,!(!e||s)&&(o.current=null,h())},[s]),(0,Z.useEffect)(()=>{function e(e){let t=e.detail;t?.threadId&&o.current===t.threadId&&(o.current=null,h())}return window.addEventListener(kv,e),function(){window.removeEventListener(kv,e)}},[]),(0,Z.useEffect)(()=>{if(Ln())return Bw()},[]),(0,Z.useEffect)(()=>{if(!Ln())return;function e(e){let t=e.detail;if(!t?.toolCallId||!t.input?.action)return;t.threadId&&(o.current=t.threadId,m.current=!0),l.current(`browser`,{navigateToChat:!1});let n=t.input.url?.trim()||c.current||``;if(n){let e=Hw(n);e&&f.current(e)}qw(t,c.current||``,p.current)}return window.addEventListener(Ov,e),function(){window.removeEventListener(Ov,e)}},[])}var Yw=vi,Xw=Z.forwardRef((e,t)=>{let n=(0,Q.c)(9),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=K(`fixed top-0 z-[100] flex max-h-screen w-full flex-col-reverse p-4 sm:bottom-0 sm:right-0 sm:top-auto sm:flex-col md:max-w-[420px]`,r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,$.jsx)(fi,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});Xw.displayName=fi.displayName;var Zw=W(`group pointer-events-auto relative flex w-full items-center justify-between space-x-4 overflow-hidden rounded-md border p-6 pr-8 shadow-lg transition-all data-[swipe=cancel]:translate-x-0 data-[swipe=end]:translate-x-[var(--radix-toast-swipe-end-x)] data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)] data-[swipe=move]:transition-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[swipe=end]:animate-out data-[state=closed]:fade-out-80 data-[state=closed]:slide-out-to-right-full data-[state=open]:slide-in-from-top-full data-[state=open]:sm:slide-in-from-bottom-full`,{variants:{variant:{default:`border bg-background text-foreground`,destructive:`destructive group border-destructive bg-destructive text-destructive-foreground`}},defaultVariants:{variant:`default`}}),Qw=Z.forwardRef((e,t)=>{let n=(0,Q.c)(11),r,i,a;n[0]===e?(r=n[1],i=n[2],a=n[3]):({className:r,variant:a,...i}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a);let o;n[4]!==r||n[5]!==a?(o=K(Zw({variant:a}),r),n[4]=r,n[5]=a,n[6]=o):o=n[6];let s;return n[7]!==i||n[8]!==t||n[9]!==o?(s=(0,$.jsx)(li,{ref:t,className:o,...i}),n[7]=i,n[8]=t,n[9]=o,n[10]=s):s=n[10],s});Qw.displayName=li.displayName;var $w=Z.forwardRef((e,t)=>{let n=(0,Q.c)(9),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=K(`inline-flex h-8 shrink-0 items-center justify-center rounded-md border bg-transparent px-3 font-medium ring-offset-background transition-colors hover:bg-secondary focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 group-[.destructive]:border-muted/40 group-[.destructive]:hover:border-destructive/30 group-[.destructive]:hover:bg-destructive group-[.destructive]:hover:text-destructive-foreground group-[.destructive]:focus:ring-destructive`,J.body,r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,$.jsx)(di,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});$w.displayName=di.displayName;var eT=Z.forwardRef((e,t)=>{let n=(0,Q.c)(10),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=K(`absolute right-2 top-2 rounded-md p-1 text-foreground/50 opacity-0 transition-opacity hover:text-foreground focus:opacity-100 focus:outline-none focus:ring-2 group-hover:opacity-100 group-[.destructive]:text-red-300 group-[.destructive]:hover:text-red-50 group-[.destructive]:focus:ring-red-400 group-[.destructive]:focus:ring-offset-red-600`,r),n[3]=r,n[4]=a);let o;n[5]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,$.jsx)(Gt,{className:`h-4 w-4`}),n[5]=o):o=n[5];let s;return n[6]!==i||n[7]!==t||n[8]!==a?(s=(0,$.jsx)(yi,{ref:t,className:a,"toast-close":``,...i,children:o}),n[6]=i,n[7]=t,n[8]=a,n[9]=s):s=n[9],s});eT.displayName=yi.displayName;var tT=Z.forwardRef((e,t)=>{let n=(0,Q.c)(9),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=K(J.dialogTitle,r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,$.jsx)(ui,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});tT.displayName=ui.displayName;var nT=Z.forwardRef((e,t)=>{let n=(0,Q.c)(9),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=K(J.body,`opacity-90 text-muted-foreground group-[.destructive]:text-destructive-foreground`,r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,$.jsx)(ei,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});nT.displayName=ei.displayName;function rT(){let e=(0,Q.c)(5),{toasts:t}=Ki(),n;e[0]===t?n=e[1]:(n=t.map(iT),e[0]=t,e[1]=n);let r;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(r=(0,$.jsx)(Xw,{}),e[2]=r):r=e[2];let i;return e[3]===n?i=e[4]:(i=(0,$.jsxs)(Yw,{duration:5e3,children:[n,r]}),e[3]=n,e[4]=i),i}function iT(e){let{id:t,title:n,description:r,action:i,variant:a,...o}=e,s=a===`destructive`,c=[n,r].filter(Boolean).join(`
|
|
75
|
+
`),l=s?(0,$.jsxs)($w,{altText:`Copy error`,onClick:()=>{navigator.clipboard.writeText(c)},children:[(0,$.jsx)(en,{className:`h-4 w-4`}),`Copy`]}):null;return(0,$.jsxs)(Qw,{variant:a,...o,children:[(0,$.jsxs)(`div`,{className:`grid gap-1`,children:[n&&(0,$.jsx)(tT,{children:n}),r&&(0,$.jsx)(nT,{children:r})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[i,l]}),(0,$.jsx)(eT,{})]},t)}function aT(){return new Ro({defaultOptions:{queries:{staleTime:3e4,retry:1,refetchOnWindowFocus:!0},mutations:{retry:0}}})}function oT(e){let t=(0,Q.c)(3),{children:n}=e,[r]=(0,Z.useState)(aT),i;return t[0]!==n||t[1]!==r?(i=(0,$.jsx)(Ii,{client:r,children:n}),t[0]=n,t[1]=r,t[2]=i):i=t[2],i}function sT(){let e=(0,Q.c)(4),{resolvedTheme:t,theme:n}=jo(),r,i;return e[0]!==t||e[1]!==n?(r=()=>{if(window.tarsk?.setNativeTheme){let e=n===`system`?`system`:t||`system`;window.tarsk.setNativeTheme(e)}},i=[t,n],e[0]=t,e[1]=n,e[2]=r,e[3]=i):(r=e[2],i=e[3]),(0,Z.useEffect)(r,i),null}function cT(e){let t=(0,Q.c)(7),n,r;t[0]===e?(n=t[1],r=t[2]):({children:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,$.jsx)(sT,{}),t[3]=i):i=t[3];let a;return t[4]!==n||t[5]!==r?(a=(0,$.jsxs)(Mo,{...r,children:[i,n]}),t[4]=n,t[5]=r,t[6]=a):a=t[6],a}function lT(){let e=(0,Q.c)(2),[t,n]=(0,Z.useState)(uT),r,i;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=()=>{let e=()=>n(!0),t=()=>n(!1);return window.addEventListener(`focus`,e),window.addEventListener(`blur`,t),()=>{window.removeEventListener(`focus`,e),window.removeEventListener(`blur`,t)}},i=[],e[0]=r,e[1]=i):(r=e[0],i=e[1]),(0,Z.useEffect)(r,i),t}function uT(){return document.hasFocus()}var dT=Pn(`chat.processing-threads`),fT=null;function pT(){fT??=new Audio(`/pop.wav`),fT.currentTime=0,fT.play().catch(e=>{dT.debug(`Could not play completion sound`,{err:e})})}function mT(){let e=Gi(),t=Ca(),n=X(e=>e.processingThreadIds),r=X(e=>e.completedThreadIds),i=lT(),{activeMainTab:a,setChatNotification:o}=Fi(),s=(0,Z.useRef)(null),c=(0,Z.useRef)(!1),l=(0,Z.useRef)([]),u=(0,Z.useRef)(i),d=(0,Z.useRef)(a);(0,Z.useEffect)(()=>{u.current=i},[i]),(0,Z.useEffect)(()=>{d.current=a,a===`chat`&&o(!1)},[a,o]);let f=(0,Z.useCallback)(async()=>{try{let n=o_(await yr()),r=t.getState().selectedThreadId,i=l.current.filter(e=>!n.includes(e)),a=r!==null&&i.includes(r);for(let t of i)t!==r&&e({type:Y.MarkThreadCompleted,threadId:t});return n.length>0&&d.current!==`chat`&&o(!0),(n.length===0||a)&&o(!1),i.length>0&&!u.current&&pT(),l.current=n,e({type:Y.SetProcessingThreads,threadIds:n}),n}catch(e){return dT.error(`Failed to fetch processing threads`,{err:e}),[]}},[e,t]);return(0,Z.useEffect)(()=>{let e=()=>{if(s.current||c.current)return;c.current=!0;let e=async()=>{let n=await f(),r=t.getState(),i=Object.values(r.threadStreamingStates).some(e=>e.isStreaming);n.length>0||i||r.isCreatingProject?s.current=setTimeout(e,1e3):(s.current=null,c.current=!1)};e()},n=()=>{s.current&&=(clearTimeout(s.current),null),c.current=!1};return e(),()=>{n()}},[f]),{processingThreadIds:n,completedThreadIds:r,isThreadProcessing:e=>n.includes(e),isThreadCompleted:e=>r.includes(e),clearCompleted:(0,Z.useCallback)(t=>{e({type:Y.ClearThreadCompleted,threadId:t})},[e])}}function hT(){let e=(0,Q.c)(15),t=Gi(),[r,i]=(0,Z.useState)(!1),[a,o]=(0,Z.useState)(!1),s;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(s={queryKey:ma.onboarding.status(),queryFn:Re,staleTime:1/0,retry:1},e[0]=s):s=e[0];let c=oi(s),l;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(l={queryKey:ma.app.update(),queryFn:Sr,staleTime:1/0,retry:!1},e[1]=l):l=e[1];let u=oi(l),d,f;e[2]!==c.data||e[3]!==c.isSuccess?(d=()=>{c.isSuccess&&!c.data.onboardingCompleted&&i(!0)},f=[c.isSuccess,c.data],e[2]=c.data,e[3]=c.isSuccess,e[4]=d,e[5]=f):(d=e[4],f=e[5]),(0,Z.useEffect)(d,f);let p,m;e[6]!==t||e[7]!==r?(p=()=>{r||t({type:Y.ConfigUpdated})},m=[r,t],e[6]=t,e[7]=r,e[8]=p,e[9]=m):(p=e[8],m=e[9]),(0,Z.useEffect)(p,m);let h;e[10]===Symbol.for(`react.memo_cache_sentinel`)?(h=async()=>{o(!0);try{await n()}catch{o(!1)}},e[10]=h):h=e[10];let g=h,_=u.data?.updateAvailable??!1,v;return e[11]!==r||e[12]!==_||e[13]!==a?(v={showOnboarding:r,setShowOnboarding:i,updateAvailable:_,updatingApp:a,handleUpdateApp:g},e[11]=r,e[12]=_,e[13]=a,e[14]=v):v=e[14],v}function gT(e){let t=(0,Q.c)(22),{selectedThreadId:n}=e,r=ua(),i=Oa(),{activeMainTab:a,setActiveMainTab:o}=Fi(),{openChatDockPanel:s}=Yc(),{terminalState:c}=Hi(n),l;t[0]===i.pathname?l=t[1]:(l=i.pathname.startsWith(`/settings`),t[0]=i.pathname,t[1]=l);let u=l,d=i.pathname===`/review`,f=i.pathname===`/tasks`,p=(0,Z.useRef)(null),m,h;t[2]!==f||t[3]!==r||t[4]!==s?(m=()=>{f&&(r(`/`),s(`tasks`))},h=[f,r,s],t[2]=f,t[3]=r,t[4]=s,t[5]=m,t[6]=h):(m=t[5],h=t[6]),(0,Z.useEffect)(m,h);let g,_;t[7]!==i.pathname||t[8]!==s||t[9]!==n||t[10]!==c.open?(g=()=>{c.open&&n===p.current&&!Jc(i.pathname)&&s(`terminal`),p.current=n},_=[c.open,n,i.pathname,s],t[7]=i.pathname,t[8]=s,t[9]=n,t[10]=c.open,t[11]=g,t[12]=_):(g=t[11],_=t[12]),(0,Z.useEffect)(g,_);let v,y;t[13]!==a||t[14]!==d||t[15]!==u||t[16]!==o?(v=()=>{a!==`chat`&&!u&&!d&&o(`chat`)},y=[a,d,u,o],t[13]=a,t[14]=d,t[15]=u,t[16]=o,t[17]=v,t[18]=y):(v=t[17],y=t[18]),(0,Z.useEffect)(v,y);let b;return t[19]!==d||t[20]!==u?(b={isSettingsRoute:u,isReviewRoute:d},t[19]=d,t[20]=u,t[21]=b):b=t[21],b}function _T(e,t){let n=(0,Q.c)(8),r=Gi(),i=X(vT),a=(0,Z.useRef)(null),o;n[0]!==r||n[1]!==t||n[2]!==e||n[3]!==i?(o=()=>{let n=e||t;if(n&&a.current===null)a.current=i,i&&r({type:Y.ToggleSidebar});else if(!n&&a.current!==null){let e=a.current;a.current=null,e&&!i&&r({type:Y.ToggleSidebar})}},n[0]=r,n[1]=t,n[2]=e,n[3]=i,n[4]=o):o=n[4];let s;n[5]!==t||n[6]!==e?(s=[e,t],n[5]=t,n[6]=e,n[7]=s):s=n[7],(0,Z.useEffect)(o,s)}function vT(e){return e.sidebarOpen}var yT=f_(`App`,{web:()=>po(()=>import(`./web-DsLUxLTR.js`).then(e=>new e.AppWeb),[])}),bT=1e10,xT=1e3;function ST(e,t){let n=e.map(e=>`"${e}"`).join(`, `);return Error(`This RPC instance cannot ${t} because the transport did not provide one or more of these methods: ${n}`)}function CT(e={}){let t={},n={},r;function i(e){n.unregisterHandler&&n.unregisterHandler(),n=e,n.registerHandler?.(x)}function a(e){if(typeof e==`function`){r=e;return}r=(t,n)=>{let r=e[t];if(r)return r(n);let i=e._;if(!i)throw Error(`The requested method has no handler: ${String(t)}`);return i(t,n)}}let{maxRequestTime:o=xT}=e;e.transport&&i(e.transport),e.requestHandler&&a(e.requestHandler),e._debugHooks&&(t=e._debugHooks);let s=0;function c(){return s<=bT?++s:s=0}let l=new Map,u=new Map;function d(e,...r){let i=r[0];return new Promise((r,a)=>{if(!n.send)throw ST([`send`],`make requests`);let s=c(),d={type:`request`,id:s,method:e,params:i};l.set(s,{resolve:r,reject:a}),o!==1/0&&u.set(s,setTimeout(()=>{u.delete(s),l.delete(s),a(Error(`RPC request timed out.`))},o)),t.onSend?.(d),n.send(d)})}let f=new Proxy(d,{get:(e,t,n)=>t in e?Reflect.get(e,t,n):e=>d(t,e)}),p=f;function m(e,...r){let i=r[0];if(!n.send)throw ST([`send`],`send messages`);let a={type:`message`,id:e,payload:i};t.onSend?.(a),n.send(a)}let h=new Proxy(m,{get:(e,t,n)=>t in e?Reflect.get(e,t,n):e=>m(t,e)}),g=h,_=new Map,v=new Set;function y(e,t){if(!n.registerHandler)throw ST([`registerHandler`],`register message listeners`);if(e===`*`){v.add(t);return}_.has(e)||_.set(e,new Set),_.get(e).add(t)}function b(e,t){if(e===`*`){v.delete(t);return}_.get(e)?.delete(t),_.get(e)?.size===0&&_.delete(e)}async function x(e){if(t.onReceive?.(e),!(`type`in e))throw Error(`Message does not contain a type.`);if(e.type===`request`){if(!n.send||!r)throw ST([`send`,`requestHandler`],`handle requests`);let{id:i,method:a,params:o}=e,s;try{s={type:`response`,id:i,success:!0,payload:await r(a,o)}}catch(e){if(!(e instanceof Error))throw e;s={type:`response`,id:i,success:!1,error:e.message}}t.onSend?.(s),n.send(s);return}if(e.type===`response`){let t=u.get(e.id);t!=null&&clearTimeout(t),u.delete(e.id);let{resolve:n,reject:r}=l.get(e.id)??{};l.delete(e.id),e.success?n?.(e.payload):r?.(Error(e.error));return}if(e.type===`message`){for(let t of v)t(e.id,e.payload);let t=_.get(e.id);if(!t)return;for(let n of t)n(e.payload);return}throw Error(`Unexpected RPC message type: ${e.type}`)}return{setTransport:i,setRequestHandler:a,request:f,requestProxy:p,send:h,sendProxy:g,addMessageListener:y,removeMessageListener:b,proxy:{send:g,request:p}}}function wT(e,t){let n=CT({maxRequestTime:t.maxRequestTime,requestHandler:{...t.handlers.requests,...t.extraRequestHandlers},transport:{registerHandler:()=>{}}}),r=t.handlers.messages;return r&&n.addMessageListener(`*`,((e,t)=>{let n=r[`*`];n&&n(e,t);let i=r[e];i&&i(t)})),n}var TT=window.__electrobunWebviewId,ET=window.__electrobunRpcSocketPort,DT=class{bunSocket;rpc;rpcHandler;constructor(e){this.rpc=e.rpc,this.init()}init(){this.initSocketToBun(),window.__electrobun.receiveMessageFromBun=this.receiveMessageFromBun.bind(this),this.rpc&&this.rpc.setTransport(this.createTransport())}initSocketToBun(){let e=new WebSocket(`ws://localhost:${ET}/socket?webviewId=${TT}`);this.bunSocket=e,e.addEventListener(`open`,()=>{}),e.addEventListener(`message`,async e=>{let t=e.data;if(typeof t==`string`)try{let e=JSON.parse(t),n=await window.__electrobun_decrypt(e.encryptedData,e.iv,e.tag);this.rpcHandler?.(JSON.parse(n))}catch(e){console.error(`Error parsing bun message:`,e)}else t instanceof Blob||console.error(`UNKNOWN DATA TYPE RECEIVED:`,e.data)}),e.addEventListener(`error`,e=>{console.error(`Socket error:`,e)}),e.addEventListener(`close`,e=>{})}createTransport(){let e=this;return{send(t){try{let n=JSON.stringify(t);e.bunBridge(n)}catch(e){console.error(`bun: failed to serialize message to webview`,e)}},registerHandler(t){e.rpcHandler=t}}}async bunBridge(e){if(this.bunSocket?.readyState===WebSocket.OPEN)try{let{encryptedData:t,iv:n,tag:r}=await window.__electrobun_encrypt(e),i=JSON.stringify({encryptedData:t,iv:n,tag:r});this.bunSocket.send(i);return}catch(e){console.error(`Error sending message to bun via socket:`,e)}window.__electrobunBunBridge?.postMessage(e)}receiveMessageFromBun(e){this.rpcHandler&&this.rpcHandler(e)}static defineRPC(e){return wT(`webview`,{...e,extraRequestHandlers:{evaluateJavascriptWithResponse:({script:e})=>new Promise(t=>{try{let n=Function(e)();n instanceof Promise?n.then(e=>{t(e)}).catch(e=>{console.error(`bun: async script execution failed`,e),t(String(e))}):t(n)}catch(e){console.error(`bun: failed to eval script`,e),t(String(e))}})}})}};function OT(){let e=(0,Q.c)(2),t;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=[],e[0]=t):t=e[0],(0,Z.useEffect)(MT,t);let n;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(n=[],e[1]=n):n=e[1],(0,Z.useEffect)(kT,n)}function kT(){if(!q())return;let e=yT.addListener(`backButton`,jT);return()=>{e.then(AT)}}function AT(e){return e.remove()}function jT(e){let{canGoBack:t}=e;t?window.history.back():yT.exitApp()}function MT(){window.__electrobunWebviewId&&new DT({})}var NT=Pn(`app.embed-host.hook`);function PT(e){let t=(0,Q.c)(7),n=Gi(),r=X(FT),i=(0,Z.useRef)(null),a,o;t[0]===n?(a=t[1],o=t[2]):(a=()=>{Mg()&&n({type:Y.CloseSidebar})},o=[n],t[0]=n,t[1]=a,t[2]=o),(0,Z.useEffect)(a,o);let s,c;t[3]!==e||t[4]!==r?(s=()=>{if(!Mg()||r)return;let t=jg();!t||i.current===t||(i.current=t,e(t).catch(e=>{i.current=null,NT.error(`Failed to open embed project path:`,e)}))},c=[r,e],t[3]=e,t[4]=r,t[5]=s,t[6]=c):(s=t[5],c=t[6]),(0,Z.useEffect)(s,c)}function FT(e){return e.projectsLoading}var IT=`image-background-disabled`,LT=D(),RT=new Set;function zT(){for(let e of RT)e()}function BT(e){document.documentElement.classList.toggle(IT,!e)}function VT(){return LT}function HT(e){return RT.add(e),function(){RT.delete(e)}}function UT(e){LT!==e&&(LT=e,I(e),BT(e),zT())}function WT(){let e=(0,Q.c)(2),t=(0,Z.useSyncExternalStore)(HT,VT,VT),n=KT,r=GT,i;return e[0]===t?i=e[1]:(i={isEnabled:t,updateIsEnabled:n,resetIsEnabled:r,default:!0},e[0]=t,e[1]=i),i}function GT(){UT(!0)}function KT(e){UT(e)}function qT(){LT=D(),BT(LT)}function JT(e){let t=(0,Q.c)(2),{children:n}=e,r;return t[0]===n?r=t[1]:(r=(0,$.jsx)(ha,{children:(0,$.jsx)(ki,{children:(0,$.jsx)(Bh,{children:(0,$.jsx)(Ao,{children:(0,$.jsx)(bS,{children:n})})})})}),t[0]=n,t[1]=r),r}function YT(e){let t=(0,Q.c)(5),n=Oa(),{windows:r,expandedWindowId:i}=vo();if(n.pathname===`/review`)return`Review`;if(n.pathname.startsWith(`/settings`))return`Settings`;if(!e)return`Projects`;if(i){let e;if(t[0]!==i||t[1]!==r){e=Symbol.for(`react.early_return_sentinel`);bb0:{let n;t[3]===i?n=t[4]:(n=e=>e.id===i,t[3]=i,t[4]=n);let a=r.find(n);if(a){e=rb(a.panelId);break bb0}}t[0]=i,t[1]=r,t[2]=e}else e=t[2];if(e!==Symbol.for(`react.early_return_sentinel`))return e}return`Chat`}function XT(){let e=(0,Q.c)(5),t=X(QT),n=X(ZT),r=YT(n!=null),i,a;e[0]!==t||e[1]!==n||e[2]!==r?(i=()=>{if(!n){document.title=`Tarsk - ${r}`;return}let e=t.find(e=>e.projectId===n);if(!e){document.title=`Tarsk`;return}let i=xn(e);document.title=`${i} - ${r}`},a=[t,n,r],e[0]=t,e[1]=n,e[2]=r,e[3]=i,e[4]=a):(i=e[3],a=e[4]),(0,Z.useEffect)(i,a)}function ZT(e){return e.selectedProjectId}function QT(e){return e.projects}function $T(){return Jw(),ww(),null}function eE(){let e=(0,Q.c)(1),t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t={queryKey:[`health-status`,qn()],queryFn:tE,refetchInterval:3e4,retry:!1},e[0]=t):t=e[0],oi(t)}async function tE(){let e=await fetch(`${qn()}/health`,{method:`GET`});if(!e.ok)throw Error(`Failed to load health status`);return e.json()}function nE(){let e=Gi(),t=ua(),n=Oa(),r=X(e=>e.selectedThreadId),i=X(e=>e.selectedProjectId),a=X(e=>e.sidebarOpen),o=X(e=>e.deletingProjectIds);OT();let{isEnabled:s}=WT(),c=cx()||q(),{data:l}=eE(),u=X(e=>e.projectPanelView),d=X(e=>e.projectPanelProjectId),[f,p]=(0,Z.useState)(!1),[m,h]=(0,Z.useState)(null),[g,_]=(0,Z.useState)(null),v=(0,Z.useRef)(null),y=(0,Z.useRef)(()=>{}),b=(0,Z.useCallback)(t=>{e({type:Y.OpenProjectPanel,projectId:t})},[e]),{projects:x,handleSelectThread:S,handleCreateProject:C,handleCreateWebApp:w,handleCreateFolder:T,handleOpenFolder:E,handleOpenPath:D,handleCreateThread:O,confirmDeleteProject:k,refreshProjects:A,pendingSetupScriptConfirmation:j,resolveSetupScriptConfirmation:M}=mo({onProjectCreated:b,onThreadCreateStart:b}),N=(0,Z.useCallback)(e=>{p(e),e||h(null)},[]),P=(0,Z.useCallback)(e=>{h(e),p(!0)},[]),F=(0,Z.useCallback)(()=>{E()},[E]),{clearCompleted:I}=mT(),{setActiveMainTab:L}=Fi(),{triggerBrowserReset:R}=SS(),{showOnboarding:z,setShowOnboarding:B,updateAvailable:ee,updatingApp:te,handleUpdateApp:ne}=hT();PT(D);let re=Mg(),{isSettingsRoute:ie,isReviewRoute:ae}=gT({selectedThreadId:r});_T(ie,ae),XT();let oe=(0,Z.useCallback)(e=>{let t=x.find(t=>t.projectId===e);t&&_({id:t.projectId,name:xn(t)})},[x]),se=(0,Z.useCallback)(e=>{O(e,void 0)},[O]);y.current=se;let ce=d??i;(0,Z.useEffect)(()=>{function e(e){let t=e.key.toLowerCase();!((e.metaKey||e.ctrlKey)&&e.shiftKey&&!e.altKey)||t!==`t`||!ce||(e.preventDefault(),y.current(ce))}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[ce]);let le=(0,Z.useCallback)(()=>{e({type:Y.CloseProjectPanel}),a||e({type:Y.ToggleSidebar})},[e,a]),ue=(0,Z.useCallback)((i,a)=>{I(a),n.pathname!==`/`&&t(`/`),L(`chat`),r!==a&&R(),S(i,a),c&&e({type:Y.CloseSidebar})},[S,c,r,e,I,n.pathname,t,L,R]),de=(0,Z.useCallback)(t=>{b(t);let n=x.find(e=>e.projectId===t);if(!n||n.threads.some(e=>e.threadId===r))return;let i=n.threads.find(e=>e.isSelected)??n.threads[0]??null;if(i){ue(t,i.threadId);return}r&&R(),e({type:Y.SelectProject,projectId:t})},[b,x,r,ue,R,e]),fe=uh(),pe=d==null?void 0:x.find(e=>e.projectId===d);(0,Z.useEffect)(()=>{u===`actions`&&d&&!pe&&e({type:Y.CloseProjectPanel})},[e,u,d,pe]);let V=(0,Z.useRef)(i);(0,Z.useEffect)(()=>{let e=V.current!==null;V.current=i,e&&i===null&&le()},[i,le]);let me=!ie&&!ae&&!fe,he=me&&a;return(0,Z.useEffect)(()=>{if(!fe){if(!a){v.current?.collapse();return}v.current?.expand(),me?v.current?.resize(100):c||v.current?.resize(25)}},[a,me,fe,c]),(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)($T,{}),(0,$.jsx)(Vo,{}),(0,$.jsx)(Z.Suspense,{fallback:null,children:(0,$.jsx)($a,{})}),(0,$.jsxs)(Ti,{delayDuration:200,children:[(0,$.jsxs)(`div`,{className:K(`relative h-screen overflow-hidden`,s?`bg-background`:`bg-[hsl(var(--image-off-background))]`),children:[s?(0,$.jsx)(Pi,{}):null,(0,$.jsxs)(Ex,{id:`app-shell-panels`,direction:`horizontal`,className:`relative z-10 h-full`,children:[!re&&!fe&&(0,$.jsx)(Dx,{id:`app-sidebar-panel`,order:1,ref:v,defaultSize:me||c?100:25,minSize:me||c?50:12,maxSize:me||c?100:32,collapsible:!0,collapsedSize:0,className:K(`border-r border-transparent`,c&&!a&&`hidden`),children:(0,$.jsx)(`div`,{className:`h-full overflow-hidden`,children:(0,$.jsx)(es,{projects:x,selectedThreadId:r,selectedProjectId:i,deletingProjectIds:o,onSelectProject:de,onCreateProject:P,onOpenFolder:F,onDeleteProject:oe,collapsed:!a,updateAvailable:ee,updatingApp:te,onUpdateApp:ne,isDevMode:l?.isDevMode===!0})})}),!re&&!fe&&(0,$.jsx)(Ox,{id:`app-sidebar-resize-handle`}),(0,$.jsx)(Dx,{id:`app-main-panel`,order:2,minSize:he?0:40,className:K(`overflow-hidden`,he&&`hidden`),children:(0,$.jsx)(qg,{threadId:r??void 0,children:(0,$.jsx)(Zv,{children:(0,$.jsx)(Mh,{children:(0,$.jsx)(LS,{selectedProjectId:i,isReviewRoute:ae,isSettingsRoute:ie,onCreateThread:se,onBackToProjects:le,onSelectProject:de})})})})}),(0,$.jsx)(Cw,{showCreateProject:f,createProjectInitialMode:m,onCreateProjectOpenChange:N,onSubmitClone:C,onSubmitWebApp:w,onSubmitFolder:T,deleteProject:g,onDeleteProjectOpenChange:e=>!e&&_(null),onConfirmDeleteProject:()=>{g&&(k(g.id),_(null))},pendingSetupScriptConfirmation:j,onResolveSetupScriptConfirmation:M,showOnboarding:z,onOnboardingOpenChange:B,onOnboardingComplete:()=>{A()}})]})]}),(0,$.jsx)(rT,{})]})]})}function rE(){let e=(0,Q.c)(1),t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(JT,{children:(0,$.jsx)(nE,{})}),e[0]=t):t=e[0],t}function iE(){let e=(0,Q.c)(3),[t]=(0,Z.useState)($i),n=Mg(),r;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=(0,$.jsx)(rE,{}),e[0]=r):r=e[0];let i;return e[1]===t?i=e[2]:(i=(0,$.jsx)(cT,{attribute:`class`,defaultTheme:n?`dark`:`system`,enableSystem:!0,storageKey:n?`tarsk-theme-vscode`:`tarsk-theme`,children:(0,$.jsx)(oT,{children:(0,$.jsx)(xa.Provider,{value:t,children:r})})}),e[1]=t,e[2]=i),i}var aE=75,oE=125,sE=100;function cE(){return window.matchMedia(`(max-width: 767px)`).matches}function lE(e){let t=vr(e,cE());document.documentElement.style.fontSize=`${t}%`}var uE=!1;function dE(){uE||(uE=!0,window.matchMedia(`(max-width: 767px)`).addEventListener(`change`,()=>{lE(Fr(sE))}))}function fE(){let[e,t]=(0,Z.useState)(()=>Fr(sE));(0,Z.useEffect)(()=>{dE(),lE(e)},[e]);function n(e){let n=Math.max(aE,Math.min(oE,Math.round(e)));t(n),p(n)}return{scale:e,updateScale:n,resetScale:(0,Z.useCallback)(()=>{n(sE)},[]),min:aE,max:oE,default:sE}}function pE(){dE(),lE(Fr(sE))}var mE=60,hE=100,gE=80,_E=`--frosted-panel-opacity`;function vE(e){document.documentElement.style.setProperty(_E,String(e/100))}function yE(){let[e,t]=(0,Z.useState)(()=>Xe(gE));(0,Z.useEffect)(()=>{vE(e)},[e]);function n(e){let n=Math.max(mE,Math.min(hE,Math.round(e)));t(n),at(n)}return{opacity:e,updateOpacity:n,resetOpacity:(0,Z.useCallback)(()=>{n(gE)},[]),min:mE,max:hE,default:gE}}function bE(){vE(Xe(gE))}var xE;(function(e){e.Dark=`DARK`,e.Light=`LIGHT`,e.Default=`DEFAULT`})(xE||={});var SE;(function(e){e.None=`NONE`,e.Slide=`SLIDE`,e.Fade=`FADE`})(SE||={});var CE=f_(`StatusBar`),wE=`--app-viewport-height`;function TE(){let e=window.visualViewport,t=Math.round(er()===`ios`?window.innerHeight:e?.height??window.innerHeight);document.documentElement.style.setProperty(wE,`${t}px`)}function EE(){TE(),requestAnimationFrame(TE)}function DE(){document.documentElement.dataset.nativeShell=`true`,EE(),window.addEventListener(`resize`,TE),window.addEventListener(`orientationchange`,EE);let e=window.visualViewport;e?.addEventListener(`resize`,TE),e?.addEventListener(`scroll`,TE)}async function OE(){try{await CE.setOverlaysWebView({overlay:!0}),await CE.show(),EE()}catch{}}async function kE(){try{let e=er()===`ios`?ly.None:ly.Body;await uy.setResizeMode({mode:e})}catch{}}function AE(){q()&&(DE(),OE(),kE(),document.addEventListener(`visibilitychange`,()=>{if(document.visibilityState===`visible`){EE(),OE();return}A_()}))}pE(),bE(),qT(),AE();var jE=`tarsk-chunk-reload`;function ME(e){if(!(e instanceof Error))return!1;let t=e.message;return t.includes(`valid JavaScript MIME type`)||t.includes(`Failed to fetch dynamically imported module`)||t.includes(`Importing a module script failed`)}function NE(){sessionStorage.getItem(jE)||(sessionStorage.setItem(jE,`1`),window.location.reload())}window.addEventListener(`unhandledrejection`,e=>{ME(e.reason)&&(e.preventDefault(),NE())}),window.addEventListener(`vite:preloadError`,e=>{e.preventDefault(),NE()}),sessionStorage.removeItem(jE);var PE=!1;window.addEventListener(`resize`,()=>{PE||=(window.__electrobunWebviewId&&(document.body.style.height=`calc(100%)`),!0)});var FE=q()?Qi:Yi;(0,zo.createRoot)(document.getElementById(`root`)).render((0,$.jsx)(Z.StrictMode,{children:(0,$.jsx)(FE,{children:(0,$.jsx)(iE,{})})}));export{wg as A,Ul as B,ub as C,p_ as D,Fv as E,zp as F,Zo as G,Bc as H,Ep as I,Qo as K,iu as L,Vh as M,Pm as N,Tg as O,Vp as P,ou as R,cx as S,$v as T,Vc as U,Yc as V,tc as W,Fx as _,Iw as a,Dx as b,FC as c,SS as d,sS as f,Lx as g,Px as h,Fw as i,Wh as j,Eg as k,DS as l,Bx as m,fE as n,lw as o,cS as p,WT as r,dw as s,yE as t,OS as u,Ix as v,sb as w,Ex as x,Ox as y,au as z};
|