tarsk 0.5.49 → 0.5.50
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/dist/index.js +10644 -8487
- package/dist/public/assets/{account-view-DxHV7OtO.js → account-view-orctnHTc.js} +1 -1
- package/dist/public/assets/{api-Dhzdgb40.js → api-_tZksLaY.js} +1 -1
- package/dist/public/assets/{browser-tab-qhf-xKwZ.js → browser-tab-bfjSH9LH.js} +1 -1
- package/dist/public/assets/commit-dialog-BAFsxiuw.js +1 -0
- package/dist/public/assets/{context-menu-PIC-g8wy.js → context-menu-CeBh_Q21.js} +1 -1
- package/dist/public/assets/{create-repo-dialog-CsjpTBPU.js → create-repo-dialog-D6cKAxMh.js} +1 -1
- package/dist/public/assets/{dialogs-config-BEazgV7k.js → dialogs-config-COzptu1b.js} +14 -14
- package/dist/public/assets/diff-view-CFu5DBIy.js +3 -0
- package/dist/public/assets/{explorer-tab-view--ib_BjId.js → explorer-tab-view-yR_3TyF7.js} +2 -2
- package/dist/public/assets/explorer-tree-DKrWFiee.js +1 -0
- package/dist/public/assets/explorer-view-DYbdTXTm.js +1 -0
- package/dist/public/assets/git-history-dialog-CTJwMGDA.js +1 -0
- package/dist/public/assets/git-ops-button-DM9h9L8O.js +2 -0
- package/dist/public/assets/history-view-BJ65FVAN.js +9 -0
- package/dist/public/assets/index-BMgOr4si.js +73 -0
- package/dist/public/assets/index-DzUALYN4.css +1 -0
- package/dist/public/assets/{mcp-server-card-ChdAZekt.js → mcp-server-card-7DWtYR7B.js} +1 -1
- package/dist/public/assets/{merged-pr-dialog-DAXqT4Xe.js → merged-pr-dialog-D6ReZlV4.js} +1 -1
- package/dist/public/assets/model-star-rating-DmWIerry.js +1 -0
- package/dist/public/assets/onboarding-pVfMmu_a.js +1 -0
- package/dist/public/assets/project-settings-view-CvPC_OvN.js +1 -0
- package/dist/public/assets/providers-list-view-BEBGDXvF.js +1 -0
- package/dist/public/assets/pull-request-dialog-DD9Yxl2t.js +1 -0
- package/dist/public/assets/pull-with-changes-dialog-yEIyN-rw.js +1 -0
- package/dist/public/assets/push-before-pr-dialog-09SWB4nh.js +1 -0
- package/dist/public/assets/{radio-group-n9qyUxmu.js → radio-group-DAndqwXy.js} +1 -1
- package/dist/public/assets/react-vendor-CEpXTE2b.js +16 -0
- package/dist/public/assets/settings-general-view-Crc9BTRv.js +1 -0
- package/dist/public/assets/settings-instructions-view-CB-cGPIr.js +1 -0
- package/dist/public/assets/settings-list-C5XuK_4u.js +1 -0
- package/dist/public/assets/settings-mcp-servers-view-CZR7I1h2.js +5 -0
- package/dist/public/assets/{settings-models-skeleton-Cse6L-Nd.js → settings-models-skeleton-ZtGznNlV.js} +1 -1
- package/dist/public/assets/settings-models-view-CB0rRPNa.js +1 -0
- package/dist/public/assets/settings-rules-view-BnoxoZfX.js +8 -0
- package/dist/public/assets/settings-skills-view-DKXDiK3e.js +3 -0
- package/dist/public/assets/settings-slash-commands-view-DtTuDEFe.js +1 -0
- package/dist/public/assets/settings-subagents-view-DNcPuqd5.js +2 -0
- package/dist/public/assets/{settings-system-prompt-view-B1vc2cgC.js → settings-system-prompt-view-BLkM6rN5.js} +1 -1
- package/dist/public/assets/{settings-view-DLBIkYoA.js → settings-view-BX2dUb7a.js} +2 -2
- package/dist/public/assets/{skeleton-6mGMglV0.js → skeleton-CxK1dTki.js} +1 -1
- package/dist/public/assets/slug-utils-D3-onmIf.js +1 -0
- package/dist/public/assets/{tabs-iUSYYupj.js → tabs-Tmfp1NOE.js} +1 -1
- package/dist/public/assets/{terminal-panel-DIpnKR-N.js → terminal-panel-DKkr68gm.js} +1 -1
- package/dist/public/assets/todos-view-_rD_cv7x.js +17 -0
- package/dist/public/assets/{ui-components-kSaUEA_X.js → ui-components-BhYSDqpD.js} +1 -1
- package/dist/public/assets/{use-deferred-search-DGJskNBr.js → use-deferred-search-DXiiWEeH.js} +1 -1
- package/dist/public/assets/{utils-CECQ_-6N.js → utils-DDUhUTLy.js} +1 -1
- package/dist/public/assets/{vosk-speech-CgILeNJR.js → vosk-speech-BHa2mKnm.js} +2 -2
- package/dist/public/assets/{web-BWAZk7ug.js → web-3Ems3Koj.js} +1 -1
- package/dist/public/assets/{web-BD1sqxMq.js → web-6JeYEnKU.js} +1 -1
- package/dist/public/assets/{web-DGalafxk.js → web-BYoghlKk.js} +1 -1
- package/dist/public/assets/{web-Dt5YgbhM.js → web-Dgmyivst.js} +1 -1
- package/dist/public/index.html +8 -8
- package/package.json +1 -1
- package/dist/public/assets/commit-dialog-DcVXFOBP.js +0 -1
- package/dist/public/assets/diff-view-CGEl0YbC.js +0 -3
- package/dist/public/assets/explorer-tree-CiPMm5ck.js +0 -1
- package/dist/public/assets/explorer-view-odyQutTO.js +0 -1
- package/dist/public/assets/git-history-dialog-qUZ7Qsp4.js +0 -1
- package/dist/public/assets/git-ops-button-Bced-_39.js +0 -2
- package/dist/public/assets/history-view-BMVTxWTg.js +0 -9
- package/dist/public/assets/index-C7FLshNp.css +0 -1
- package/dist/public/assets/index-_SOdLUMq.js +0 -73
- package/dist/public/assets/model-star-rating-BzpXBjSo.js +0 -1
- package/dist/public/assets/onboarding-Bi5MieW-.js +0 -1
- package/dist/public/assets/project-settings-view-CHV6lJG4.js +0 -1
- package/dist/public/assets/providers-list-view-Dgid2Wui.js +0 -1
- package/dist/public/assets/pull-request-dialog-BFgRF5AH.js +0 -1
- package/dist/public/assets/pull-with-changes-dialog-oGP-j8Yw.js +0 -1
- package/dist/public/assets/push-before-pr-dialog-BQ0QC6Qu.js +0 -1
- package/dist/public/assets/react-vendor-iDwBzcYF.js +0 -16
- package/dist/public/assets/settings-general-view-Vwi9J6Tn.js +0 -1
- package/dist/public/assets/settings-instructions-view-8YIr0PO3.js +0 -1
- package/dist/public/assets/settings-list-owWkHWxE.js +0 -1
- package/dist/public/assets/settings-mcp-servers-view-CCXW_uet.js +0 -5
- package/dist/public/assets/settings-models-view-BAxf3eJq.js +0 -1
- package/dist/public/assets/settings-rules-view-D3KLTKVZ.js +0 -8
- package/dist/public/assets/settings-skills-view-DaqOna-w.js +0 -3
- package/dist/public/assets/settings-slash-commands-view-CN8_DTYX.js +0 -1
- package/dist/public/assets/settings-subagents-view-BIejA-ck.js +0 -2
- package/dist/public/assets/slug-utils-BT1eqWhW.js +0 -1
- package/dist/public/assets/todos-view-BK6i_oPT.js +0 -17
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/dist-oojFghRi.js","assets/rolldown-runtime-aKtaBQYM.js","assets/merged-pr-dialog-DAXqT4Xe.js","assets/dialogs-config-BEazgV7k.js","assets/onboarding-Bi5MieW-.js","assets/history-view-BMVTxWTg.js","assets/git-ops-button-Bced-_39.js","assets/monaco-CZnIWXyV.js","assets/monaco-Br_kD0ds.css","assets/diff-view-CGEl0YbC.js","assets/context-menu-PIC-g8wy.js","assets/react-vendor-iDwBzcYF.js","assets/utils-CECQ_-6N.js","assets/terminal-panel-DIpnKR-N.js","assets/terminal-panel-kHJ-D0s7.css","assets/explorer-tab-view--ib_BjId.js","assets/browser-tab-qhf-xKwZ.js","assets/settings-view-DLBIkYoA.js","assets/settings-models-skeleton-Cse6L-Nd.js","assets/skeleton-6mGMglV0.js","assets/todos-view-BK6i_oPT.js","assets/tabs-iUSYYupj.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{i as e,t}from"./rolldown-runtime-aKtaBQYM.js";import{$ as n,$a as r,$i as i,$r as a,A as o,Ai as s,An as c,Ao as l,Ba as u,Bo as d,Bt as f,Cn as p,Co as m,Cr as h,D as g,Da as _,Dn as v,Dr as y,Ea as b,En as x,Eo as S,Er as C,Et as w,Fa as T,Fi as E,Fr as D,Ft as O,Gn as k,Go as A,Gr as j,Hn as M,Ho as N,Ia as P,Ii as F,In as I,Io as ee,Ir as L,J as te,Ja as R,Ji as ne,Jo as re,Jr as ie,Ka as ae,Ki as oe,Kt as se,L as ce,Mi as z,Mn as le,Mo as ue,N as de,Ni as fe,Nr as B,Oa as pe,On as V,Or as me,Ot as he,Pa as ge,Pi as _e,Pr as H,Pt as ve,Q as ye,Qa as be,Qi as xe,Qn as Se,Qo as Ce,Qr as we,Ra as U,Ri as Te,Rn as Ee,Rt as De,S as Oe,Sn as ke,T as Ae,Ta as je,Tn as Me,To as Ne,Tr as Pe,Ua as Fe,Ut as Ie,Vi as Le,Vo as Re,Vt as ze,Wa as Be,Wn as Ve,Wo as He,Xi as W,Xo as Ue,Xr as We,Ya as Ge,Yn as Ke,Yr as qe,Yt as Je,Za as Ye,Zi as Xe,Zo as Ze,Zr as Qe,_a as $e,_o as et,_r as tt,aa as nt,an as rt,ao as it,ar as at,as as ot,b as st,bt as G,c as ct,cn as lt,co as ut,cr as dt,cs as ft,d as pt,dn as mt,do as ht,dr as gt,ea as _t,ei as vt,eo as yt,er as bt,et as xt,fo as St,fr as Ct,g as wt,gn as Tt,go as Et,gr as K,hn as q,hr as Dt,ia as Ot,in as kt,io as At,ir as jt,it as Mt,j as Nt,ja as Pt,jn as Ft,jo as It,jr as Lt,kn as Rt,ko as zt,kr as Bt,kt as Vt,lo as Ht,ls as Ut,m as Wt,mn as Gt,mo as Kt,mt as qt,na as Jt,nn as Yt,nr as Xt,ns as Zt,on as Qt,oo as $t,or as en,os as tn,p as nn,pn as rn,pr as an,pt as on,qa as sn,qi as cn,qo as ln,qr as un,ra as dn,rn as fn,rr as pn,rt as mn,sn as hn,so as gn,sr as _n,ss as J,ta as vn,tn as yn,to as bn,tr as xn,ts as Sn,un as Cn,uo as wn,ut as Tn,v as En,va as Dn,vo as On,vr as kn,w as An,wa as jn,wn as Mn,wo as Nn,wr as Pn,wt as Fn,x as In,xo as Ln,xr as Rn,ya as zn,yr as Bn,z as Vn,za as Hn,zi as Un,zn as Wn,zo as Gn,zt as Kn}from"./dialogs-config-BEazgV7k.js";import{$ as qn,At as Jn,B as Yn,Ct as Xn,Dt as Zn,Et as Qn,F as $n,Ft as er,G as tr,H as nr,I as rr,J as ir,K as ar,L as or,Lt as sr,Mt as cr,Nt as lr,Ot as ur,P as dr,Pt as fr,Q as pr,R as mr,St as hr,Tt as gr,U as _r,V as vr,W as yr,X as br,Y as xr,Z as Sr,_t as Cr,at as wr,bt as Tr,ct as Er,dt as Dr,et as Or,ft as kr,gt as Ar,ht as jr,it as Mr,jt as Nr,kt as Pr,lt as Fr,mt as Ir,nt as Lr,ot as Rr,pt as zr,q as Br,rt as Vr,st as Hr,tt as Ur,ut as Wr,vt as Gr,wt as Kr,xt as qr,yt as Jr,z as Yr}from"./react-vendor-iDwBzcYF.js";import{r as Xr}from"./monaco-CZnIWXyV.js";import{A as Zr,C as Qr,F as $r,I as ei,M as ti,N as ni,O as ri,P as ii,a as ai,j as oi,k as si,l as ci,s as li,u as ui,x as di}from"./history-view-BMVTxWTg.js";import{d as fi,l as pi,o as mi,u as hi}from"./onboarding-Bi5MieW-.js";import{a as gi,i as _i,n as vi,o as yi,r as bi,t as xi}from"./vosk-speech-CgILeNJR.js";import{n as Si,t as Ci}from"./utils-CECQ_-6N.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 wi=class extends Ir{#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||Ti(),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=jr({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),Cr.batch(()=>{this.#t.forEach(t=>{t.onMutationUpdate(e)}),this.#n.notify({mutation:this,type:`updated`,action:e})})}};function Ti(){return{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:`idle`,variables:void 0,submittedAt:0}}var Ei=class extends Pr{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 wi({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=Di(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=Di(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=Di(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=Di(e);return typeof t==`string`?(this.#t.get(t)?.find(t=>t!==e&&t.state.isPaused))?.continue()??Promise.resolve():Promise.resolve()}clear(){Cr.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=>hr(t,e))}findAll(e={}){return this.getAll().filter(t=>hr(e,t))}notify(e){Cr.batch(()=>{this.listeners.forEach(t=>{t(e)})})}resumePausedMutations(){let e=this.getAll().filter(e=>e.state.isPaused);return Cr.batch(()=>Promise.all(e.map(e=>e.continue().catch(Kr))))}};function Di(e){return e.options.scope?.id}var Oi=class extends Pr{constructor(e={}){super(),this.config=e,this.#e=new Map}#e;build(e,t,n){let r=t.queryKey,i=t.queryHash??Tr(r,t),a=this.get(i);return a||(a=new zr({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(){Cr.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=>Xn(t,e))}findAll(e={}){let t=this.getAll();return Object.keys(e).length>0?t.filter(t=>Xn(e,t)):t}notify(e){Cr.batch(()=>{this.listeners.forEach(t=>{t(e)})})}onFocus(){Cr.batch(()=>{this.getAll().forEach(e=>{e.onFocus()})})}onOnline(){Cr.batch(()=>{this.getAll().forEach(e=>{e.onOnline()})})}},ki=class{#e;#t;#n;#r;#i;#a;#o;#s;constructor(e={}){this.#e=e.queryCache||new Oi,this.#t=e.mutationCache||new Ei,this.#n=e.defaultOptions||{},this.#r=new Map,this.#i=new Map,this.#a=0}mount(){this.#a++,this.#a===1&&(this.#o=ur.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#e.onFocus())}),this.#s=Ar.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(Qn(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=Gr(t,i);if(a!==void 0)return this.#e.build(this,r).setData(a,{...n,manual:!0})}setQueriesData(e,t,n){return Cr.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;Cr.batch(()=>{t.findAll(e).forEach(e=>{t.remove(e)})})}resetQueries(e,t){let n=this.#e;return Cr.batch(()=>(n.findAll(e).forEach(e=>{e.reset()}),this.refetchQueries({type:`active`,...e},t)))}cancelQueries(e,t={}){let n={revert:!0,...t},r=Cr.batch(()=>this.#e.findAll(e).map(e=>e.cancel(n)));return Promise.all(r).then(Kr).catch(Kr)}invalidateQueries(e,t={}){return Cr.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=Cr.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(Kr)),e.state.fetchStatus===`paused`?Promise.resolve():t}));return Promise.all(r).then(Kr)}fetchQuery(e){let t=this.defaultQueryOptions(e);t.retry===void 0&&(t.retry=!1);let n=this.#e.build(this,t);return n.isStaleByTime(Qn(t.staleTime,n))?n.fetch(t):Promise.resolve(n.state.data)}prefetchQuery(e){return this.fetchQuery(e).then(Kr).catch(Kr)}fetchInfiniteQuery(e){return e._type=`infinite`,this.fetchQuery(e)}prefetchInfiniteQuery(e){return this.fetchInfiniteQuery(e).then(Kr).catch(Kr)}ensureInfiniteQueryData(e){return e._type=`infinite`,this.ensureQueryData(e)}resumePausedMutations(){return Ar.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(Jr(e),{queryKey:e,defaultOptions:t})}getQueryDefaults(e){let t=[...this.#r.values()],n={};return t.forEach(t=>{gr(e,t.queryKey)&&Object.assign(n,t.defaultOptions)}),n}setMutationDefaults(e,t){this.#i.set(Jr(e),{mutationKey:e,defaultOptions:t})}getMutationDefaults(e){let t=[...this.#i.values()],n={};return t.forEach(t=>{gr(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||=Tr(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===Zn&&(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()}},Y=e(Ut(),1),Ai=sr(),X=J(),Z=function(e){return e.SetProjects=`SET_PROJECTS`,e.SetProjectsLoading=`SET_PROJECTS_LOADING`,e.SelectThread=`SELECT_THREAD`,e.SetMessages=`SET_MESSAGES`,e.AddMessage=`ADD_MESSAGE`,e.EnqueueChatMessage=`ENQUEUE_CHAT_MESSAGE`,e.RemoveQueuedChatMessage=`REMOVE_QUEUED_CHAT_MESSAGE`,e.SetStreaming=`SET_STREAMING`,e.AppendStreamContent=`APPEND_STREAM_CONTENT`,e.SetStreamContent=`SET_STREAM_CONTENT`,e.AppendStreamThinking=`APPEND_STREAM_THINKING`,e.AppendStreamChunk=`APPEND_STREAM_CHUNK`,e.SetStreamModel=`SET_STREAM_MODEL`,e.SetProjectModel=`SET_PROJECT_MODEL`,e.ResetStream=`RESET_STREAM`,e.StopStream=`STOP_STREAM`,e.ToggleSidebar=`TOGGLE_SIDEBAR`,e.CloseSidebar=`CLOSE_SIDEBAR`,e.SetCreatingProject=`SET_CREATING_PROJECT`,e.ConfigUpdated=`CONFIG_UPDATED`,e.SetProcessingThreads=`SET_PROCESSING_THREADS`,e.AddProcessingThread=`ADD_PROCESSING_THREAD`,e.RemoveProcessingThread=`REMOVE_PROCESSING_THREAD`,e.AddCreatingProject=`ADD_CREATING_PROJECT`,e.AddCreatingThread=`ADD_CREATING_THREAD`,e.RemoveCreatingProject=`REMOVE_CREATING_PROJECT`,e.RemoveCreatingThread=`REMOVE_CREATING_THREAD`,e.MarkThreadCompleted=`MARK_THREAD_COMPLETED`,e.ClearThreadCompleted=`CLEAR_THREAD_COMPLETED`,e.AddDeletingThread=`ADD_DELETING_THREAD`,e.RemoveDeletingThread=`REMOVE_DELETING_THREAD`,e.AddDeletingProject=`ADD_DELETING_PROJECT`,e.RemoveDeletingProject=`REMOVE_DELETING_PROJECT`,e.AppendCommandOutput=`APPEND_COMMAND_OUTPUT`,e.SetRunningCommand=`SET_RUNNING_COMMAND`,e.ClearCommandOutput=`CLEAR_COMMAND_OUTPUT`,e.ToggleTerminal=`TOGGLE_TERMINAL`,e.SetTerminalOpen=`SET_TERMINAL_OPEN`,e.QueueTerminalCommand=`QUEUE_TERMINAL_COMMAND`,e.ClearQueuedTerminalCommand=`CLEAR_QUEUED_TERMINAL_COMMAND`,e.AppendTerminalLine=`APPEND_TERMINAL_LINE`,e.ClearTerminalOutput=`CLEAR_TERMINAL_OUTPUT`,e.SetTerminalHeight=`SET_TERMINAL_HEIGHT`,e.SetTerminalCwd=`SET_TERMINAL_CWD`,e.SetTerminalRunning=`SET_TERMINAL_RUNNING`,e.SetTerminalHistory=`SET_TERMINAL_HISTORY`,e.SetTerminalHistoryIndex=`SET_TERMINAL_HISTORY_INDEX`,e.UpdateThreadTitle=`UPDATE_THREAD_TITLE`,e.ClearFocusChatInput=`CLEAR_FOCUS_CHAT_INPUT`,e.ClearMessages=`CLEAR_MESSAGES`,e.UpdateToolCallProgress=`UPDATE_TOOL_CALL_PROGRESS`,e.UpdateToolExecutionOutput=`UPDATE_TOOL_EXECUTION_OUTPUT`,e.AppendToolExecutionOutput=`APPEND_TOOL_EXECUTION_OUTPUT`,e.ClearToolCallProgress=`CLEAR_TOOL_CALL_PROGRESS`,e.SetPendingChatMessage=`SET_PENDING_CHAT_MESSAGE`,e.ClearPendingChatMessage=`CLEAR_PENDING_CHAT_MESSAGE`,e.IncrementStreamEventCount=`INCREMENT_STREAM_EVENT_COUNT`,e.SetDiffComments=`SET_DIFF_COMMENTS`,e.ClearSelection=`CLEAR_SELECTION`,e.SetChatInputDraft=`SET_CHAT_INPUT_DRAFT`,e.ClearChatInputDraft=`CLEAR_CHAT_INPUT_DRAFT`,e.EnableDualChat=`ENABLE_DUAL_CHAT`,e.DisableDualChat=`DISABLE_DUAL_CHAT`,e.SetFocusedPane=`SET_FOCUSED_PANE`,e.SetSecondaryMessages=`SET_SECONDARY_MESSAGES`,e.AddSecondaryMessage=`ADD_SECONDARY_MESSAGE`,e.SetActiveStreamPane=`SET_ACTIVE_STREAM_PANE`,e}({}),ji={projects:[],projectsLoading:!0,selectedThreadId:null,selectedProjectId:null,messages:[],messagesLoaded:!1,queuedChatMessages:[],isStreaming:!1,streamingContent:``,streamingThinking:``,streamingSegments:[],streamingModel:``,streamingEventCount:0,threadStreamingStates:{},threadDualChatStates:{},projectModelSelections:{},sidebarOpen:!0,isCreatingProject:!1,configUpdatedAt:0,processingThreadIds:[],completedThreadIds:[],deletingThreadIds:[],deletingProjectIds:[],commandOutput:``,isRunningCommand:!1,terminalStates:{},focusChatInput:!1,toolCallProgress:{},pendingChatMessage:null,diffComments:{},chatInputDrafts:{},dualChatEnabled:!1,focusedPane:`primary`,secondaryConversationId:null,secondaryMessages:[],secondaryMessagesLoaded:!1,activeStreamPane:null},Mi={open:!1,queuedCommand:null,queuedRelativeFolder:null,outputLines:[],height:300,history:[],historyIndex:-1,cwd:`.`,isRunning:!1};function Ni(e,t,n,r){return t.includes(e)||Ri(n,e,`primary`).isStreaming||Ri(n,e,`secondary`).isStreaming?!0:r?.threadId===e}var Pi={isStreaming:!1,streamingContent:``,streamingThinking:``,streamingSegments:[],streamingModel:``,streamingEventCount:0},Fi=Pi;function Ii(){return{...Pi,streamingSegments:[]}}function Li(e,t=`primary`){return`${e}:${t}`}function Ri(e,t,n=`primary`){return t?e[Li(t,n)]??Fi:Fi}function zi(e,t){return t.threadId??e.selectedThreadId}function Bi(e,t){return t.paneId??e.activeStreamPane??`primary`}function Vi(e,t,n){return t===e.selectedThreadId?e.activeStreamPane===null?n===`primary`:e.activeStreamPane===n:!1}function Hi(e,t,n,r,i=!1){if(!t)return{...e,...r,toolCallProgress:i?{}:e.toolCallProgress};let a=Li(t,n),o={...e.threadStreamingStates,[a]:r};return Vi(e,t,n)?{...e,...r,threadStreamingStates:o,toolCallProgress:i?{}:e.toolCallProgress}:{...e,threadStreamingStates:o}}function Ui(){return{open:!1,queuedCommand:null,queuedRelativeFolder:null,outputLines:[],height:300,history:[],historyIndex:-1,cwd:`.`,isRunning:!1}}var Wi={dualChatEnabled:!1,focusedPane:`primary`,secondaryConversationId:null,secondaryMessages:[],secondaryMessagesLoaded:!1,activeStreamPane:null};function Gi(){return{...Wi}}function Ki(e){return{dualChatEnabled:e.dualChatEnabled,focusedPane:e.focusedPane,secondaryConversationId:e.secondaryConversationId,secondaryMessages:e.secondaryMessages,secondaryMessagesLoaded:e.secondaryMessagesLoaded,activeStreamPane:e.activeStreamPane}}function qi(e,t){return t?e[t]??Wi:Wi}function Ji(e){return{...e,secondaryMessages:[...e.secondaryMessages]}}function Yi(e,t,n){let r=Ji(n),i=t===null?e.threadDualChatStates:{...e.threadDualChatStates,[t]:r};return t===e.selectedThreadId?{...e,...r,threadDualChatStates:i}:{...e,threadDualChatStates:i}}function Xi(e,t,n){let r=e.threadDualChatStates;return t&&(r={...r,[t]:Ji(Ki(e))}),{...Ji(qi(r,n)),threadDualChatStates:r}}function Zi(e,t){return Yi(e,e.selectedThreadId,{...Ki(e),...t})}function Qi(e,t){switch(t.type){case Z.EnableDualChat:{let n=e.selectedThreadId?qi(e.threadDualChatStates,e.selectedThreadId):Wi,r=n.secondaryConversationId!==null;return Zi(e,{dualChatEnabled:!0,focusedPane:`primary`,secondaryConversationId:r?n.secondaryConversationId:t.conversationId,secondaryMessages:r?n.secondaryMessages:[],secondaryMessagesLoaded:r?n.secondaryMessagesLoaded:!0})}case Z.DisableDualChat:return Zi(e,{dualChatEnabled:!1,focusedPane:`primary`,activeStreamPane:null});case Z.SetFocusedPane:return Zi(e,{focusedPane:t.paneId});case Z.SetSecondaryMessages:return Zi(e,{secondaryMessages:t.messages,secondaryMessagesLoaded:!0});case Z.AddSecondaryMessage:return Zi(e,{secondaryMessages:[...e.secondaryMessages,t.message]});case Z.SetActiveStreamPane:{if(!e.selectedThreadId||t.paneId===null)return Zi(e,{activeStreamPane:null});let n=Ri(e.threadStreamingStates,e.selectedThreadId,t.paneId);return{...Zi(e,{activeStreamPane:t.paneId}),...n}}default:return null}}function $i(e,t){switch(t.type){case Z.SetMessages:return{...e,messages:t.messages,messagesLoaded:!0};case Z.AddMessage:return t.threadId&&t.threadId!==e.selectedThreadId?e:t.paneId===`secondary`?Yi(e,e.selectedThreadId,{...Ki(e),secondaryMessages:[...e.secondaryMessages,t.message]}):{...e,messages:[...e.messages,t.message]};case Z.EnqueueChatMessage:return{...e,queuedChatMessages:[...e.queuedChatMessages,t.message]};case Z.RemoveQueuedChatMessage:return{...e,queuedChatMessages:e.queuedChatMessages.filter(e=>e.id!==t.queuedMessageId)};case Z.ClearMessages:return{...e,messages:[]};case Z.UpdateToolCallProgress:{let n=e.toolCallProgress[t.toolCallId];return{...e,toolCallProgress:{...e.toolCallProgress,[t.toolCallId]:{...n,...t.progress}}}}case Z.UpdateToolExecutionOutput:{let n=e.toolCallProgress[t.toolCallId];return{...e,toolCallProgress:{...e.toolCallProgress,[t.toolCallId]:{toolCallId:t.toolCallId,toolName:t.toolName??n?.toolName??``,delta:n?.delta??``,partial:n?.partial??{role:`tool`,content:[]},executionOutput:t.executionOutput}}}}case Z.AppendToolExecutionOutput:{let n=e.toolCallProgress[t.toolCallId],r=n?.executionOutput??``;return{...e,toolCallProgress:{...e.toolCallProgress,[t.toolCallId]:{toolCallId:t.toolCallId,toolName:t.toolName??n?.toolName??`agent`,delta:n?.delta??``,partial:n?.partial??{role:`tool`,content:[]},executionOutput:r+t.delta}}}}case Z.ClearToolCallProgress:{if(!t.toolCallId)return{...e,toolCallProgress:{}};let{[t.toolCallId]:n,...r}=e.toolCallProgress;return{...e,toolCallProgress:r}}case Z.SetPendingChatMessage:return{...e,pendingChatMessage:t.message};case Z.ClearPendingChatMessage:return{...e,pendingChatMessage:null};case Z.SetChatInputDraft:return{...e,chatInputDrafts:{...e.chatInputDrafts,[t.threadId]:t.draft}};case Z.ClearChatInputDraft:{let{[t.threadId]:n,...r}=e.chatInputDrafts;return{...e,chatInputDrafts:r}}case Z.SelectThread:{let n=Xi(e,e.selectedThreadId,t.threadId),r=Ri(e.threadStreamingStates,t.threadId,`primary`);return{...e,...r,...n,selectedThreadId:t.threadId,selectedProjectId:t.projectId,messages:t.initialMessages??[],messagesLoaded:!1,focusChatInput:t.focusInput??!1}}case Z.ClearSelection:return{...e,...Ii(),selectedThreadId:null,selectedProjectId:null,messages:[],messagesLoaded:!1,...Gi()};default:return null}}function ea(e,t){switch(t.type){case Z.SetProjects:{let n={...e.projectModelSelections};for(let e of t.projects)for(let t of e.threads){if(!t.model)continue;let e=n[t.threadId];n[t.threadId]={id:t.model,provider:t.modelProvider,name:e?.name??t.model,description:e?.description??``,context_length:e?.context_length,contextWindow:e?.contextWindow,features:e?.features,input_modalities:e?.input_modalities,max_output:e?.max_output,pricing:e?.pricing,tarsk_use:e?.tarsk_use,coding_index:e?.coding_index,supportsImages:e?.supportsImages}}return{...e,projects:t.projects,projectModelSelections:n}}case Z.SetProjectsLoading:return{...e,projectsLoading:t.projectsLoading};case Z.SetProjectModel:return console.log(`[Store] SetProjectModel action:`,{threadId:t.threadId,model:{id:t.model.id,provider:t.model.provider}}),{...e,projects:e.projects.map(e=>({...e,threads:e.threads.map(e=>e.threadId===t.threadId?{...e,model:t.model.id,modelProvider:t.model.provider}:e)})),projectModelSelections:{...e.projectModelSelections,[t.threadId]:t.model}};case Z.SetProcessingThreads:return{...e,processingThreadIds:t.threadIds,completedThreadIds:e.completedThreadIds.filter(e=>!t.threadIds.includes(e))};case Z.AddProcessingThread:return{...e,processingThreadIds:e.processingThreadIds.includes(t.threadId)?e.processingThreadIds:[...e.processingThreadIds,t.threadId],completedThreadIds:e.completedThreadIds.filter(e=>e!==t.threadId)};case Z.RemoveProcessingThread:return{...e,processingThreadIds:e.processingThreadIds.filter(e=>e!==t.threadId)};case Z.AddCreatingProject:return{...e,projects:[...e.projects,{projectId:t.projectId,name:t.projectName,gitUrl:t.gitUrl,threads:[{threadId:t.threadId,title:`thread-1`,path:``,currentBranch:``}]}]};case Z.AddCreatingThread:return{...e,projects:e.projects.map(e=>e.projectId===t.projectId?{...e,threads:[...e.threads,{threadId:t.threadId,title:t.title,path:``,currentBranch:``}]}:e)};case Z.RemoveCreatingProject:return{...e,projects:e.projects.filter(e=>e.projectId!==t.projectId)};case Z.RemoveCreatingThread:return{...e,projects:e.projects.map(e=>e.projectId===t.projectId?{...e,threads:e.threads.filter(e=>e.threadId!==t.threadId)}:e)};case Z.MarkThreadCompleted:return{...e,completedThreadIds:e.completedThreadIds.includes(t.threadId)?e.completedThreadIds:[...e.completedThreadIds,t.threadId]};case Z.ClearThreadCompleted:return{...e,completedThreadIds:e.completedThreadIds.filter(e=>e!==t.threadId)};case Z.AddDeletingThread:return{...e,deletingThreadIds:e.deletingThreadIds.includes(t.threadId)?e.deletingThreadIds:[...e.deletingThreadIds,t.threadId]};case Z.RemoveDeletingThread:return{...e,deletingThreadIds:e.deletingThreadIds.filter(e=>e!==t.threadId)};case Z.AddDeletingProject:return{...e,deletingProjectIds:e.deletingProjectIds.includes(t.projectId)?e.deletingProjectIds:[...e.deletingProjectIds,t.projectId]};case Z.RemoveDeletingProject:return{...e,deletingProjectIds:e.deletingProjectIds.filter(e=>e!==t.projectId)};case Z.UpdateThreadTitle:return{...e,projects:e.projects.map(e=>e.projectId===t.projectId?{...e,threads:e.threads.map(e=>e.threadId===t.threadId?{...e,title:t.title}:e)}:e)};default:return null}}function ta(e){return e.type===`tool_use`}function na(e){return e.type===`tool-result`}function ra(e){return typeof e==`string`?e.replace(/\\n/g,`
|
|
3
|
-
`).replace(/✅/g,`✓`):``}function ia(e){if(!e||typeof e!=`string`)return null;let t=e.trim();if(!t)return null;let n=/\[([A-Za-z]+)\]\s*/g,r,i=0;for(let e of t.matchAll(n))r=e[1],i=e.index+e[0].length;let a=r,o=a?t.slice(i):t;if(a&&o)return[{type:`reasoning`,text:o,label:a}];let s=[],c=0;for(;c<t.length;){let e=t.indexOf(`[`,c);if(e===-1){let e=t.slice(c).trim();e&&s.push({type:`reasoning`,text:e});break}let n=t.slice(c,e).trim();n&&s.push({type:`reasoning`,text:n});let r=0,i=-1;for(let n=e;n<t.length;n++)if(t[n]===`[`)r++;else if(t[n]===`]`&&(r--,r===0)){i=n;break}if(i===-1){let n=t.slice(e).trim();n&&s.push({type:`reasoning`,text:n});break}try{let n=JSON.parse(t.slice(e,i+1));if(Array.isArray(n)){for(let e of n)if(e&&typeof e==`object`&&`type`in e){let t=e.type;(t===`tool-result`||t===`tool_use`)&&s.push(e)}}}catch{let n=t.slice(e,i+1).trim();n&&s.push({type:`reasoning`,text:n})}c=i+1}return s.length>0?s:null}function aa(e,t){let n=0;for(let r=t;r<e.length;r++){let t=e[r];if(t===`[`)n++;else if(t===`]`&&(n--,n===0))return r}return-1}function oa(e,t=0){let n=[],r=t;for(;r<e.length;){for(;r<e.length&&/\s/.test(e.charAt(r));)r++;if(r>=e.length||e.charAt(r)!==`[`)break;let t=aa(e,r);if(t===-1)break;try{let i=JSON.parse(e.slice(r,t+1));if(!Array.isArray(i))break;n.push(...ca(i))}catch{break}r=t+1}return n.length===0?null:{blocks:n,nextIndex:r}}function sa(e,t){let n=[...e];for(let e of t){if(e.type===`tool_use`){let t=n.findIndex(t=>t.type===`tool_use`&&t.id===e.id);t>=0?n[t]=e:n.push(e);continue}if(e.type===`tool-result`){let t=n.findIndex(t=>t.type===`tool-result`&&t.toolCallId===e.toolCallId);t>=0?n[t]=e:n.push(e);continue}n.push(e)}return n}function ca(e){return e.map(e=>{if(typeof e==`object`&&e&&!(`type`in e)){let t=e;if(t.reasoning)return{type:`reasoning`,text:typeof t.reasoning==`string`?t.reasoning:JSON.stringify(t.reasoning)};let n=t.text??t.content??t.answer;if(n)return{type:`text`,text:typeof n==`string`?n:JSON.stringify(n)}}return e})}function la(e){let t=[];if(e.type===`long_running_confirmation`&&typeof e.prompt==`object`&&e.prompt!==null&&typeof e.prompt.question==`string`&&Array.isArray(e.prompt.options)){let n=e.prompt;return t.push({type:`long_running_confirmation`,prompt:{toolCallId:typeof n.toolCallId==`string`?n.toolCallId:void 0,question:n.question,options:n.options.filter(e=>typeof e==`string`),context:typeof n.context==`string`?n.context:void 0}}),t}if(e.type===`shell_permission`&&typeof e.shellPermission==`object`&&e.shellPermission!==null&&typeof e.shellPermission.command==`string`){let n=e.shellPermission;return t.push({type:`shell_permission`,prompt:{toolCallId:typeof n.toolCallId==`string`?n.toolCallId:`shell-permission`,command:n.command,source:n.source===`bash`||n.source===`skill_script`||n.source===`browser_js`?n.source:`bash`,wildcardOptions:Array.isArray(n.wildcardOptions)?n.wildcardOptions.filter(e=>typeof e==`object`&&!!e&&typeof e.label==`string`&&typeof e.pattern==`string`&&(e.scope===`session`||e.scope===`project`)):[]}}),t}if(e.type===`web_fetch_permission`&&typeof e.webFetchPermission==`object`&&e.webFetchPermission!==null&&typeof e.webFetchPermission.hostname==`string`){let n=e.webFetchPermission;return t.push({type:`web_fetch_permission`,prompt:{toolCallId:typeof n.toolCallId==`string`?n.toolCallId:`web-fetch-permission`,hostname:n.hostname,url:typeof n.url==`string`?n.url:``,wildcardOptions:Array.isArray(n.wildcardOptions)?n.wildcardOptions.filter(e=>typeof e==`object`&&!!e&&typeof e.label==`string`&&typeof e.pattern==`string`&&(e.scope===`session`||e.scope===`project`)):[]}}),t}e.reasoning&&typeof e.reasoning==`string`&&t.push({type:`reasoning`,text:e.reasoning});let n=(typeof e.text==`string`?e.text:null)??(typeof e.content==`string`?e.content:null)??(typeof e.answer==`string`?e.answer:null);return n&&t.push({type:`text`,text:n}),t.length===0&&Object.keys(e).length>0&&t.push({type:`text`,text:JSON.stringify(e,null,2)}),t}function ua(e){return da(e)?.some(e=>e.type===`tool_use`||e.type===`tool-result`)??!1}function da(e){if(!e)return null;let t=e.trim();if(t.startsWith(`{`)||t.startsWith(`[`))try{let e=JSON.parse(t);if(Array.isArray(e))return ca(e);if(typeof e==`object`&&e)return la(e)}catch{if(t.startsWith(`[`)){let e=oa(t);if(e){let n=t.slice(e.nextIndex).trim();return n?[...e.blocks,{type:`text`,text:n}]:e.blocks}}}let n=[],r=e.indexOf(`{`),i=e.indexOf(`[`),a=r===-1?i:i===-1?r:Math.min(r,i);if(a!==-1){let t=e.slice(0,a).trim();t&&n.push({type:`text`,text:t});let r=e.slice(a),i=oa(r);if(i){n.push(...i.blocks);let e=r.slice(i.nextIndex).trim();return e&&n.push({type:`text`,text:e}),n}let o=Math.max(r.lastIndexOf(`]`),r.lastIndexOf(`}`));if(o!==-1){let e=r.substring(0,o+1);try{let t=JSON.parse(e);Array.isArray(t)?n.push(...ca(t)):n.push(...la(t));let i=r.substring(o+1).trim();return i&&n.push({type:`text`,text:i}),n}catch{}}}return n.length>0?n:null}function fa(e,t,n){let r=e[e.length-1];return r?.type===t?[...e.slice(0,-1),{type:t,chunks:[...r.chunks,n]}]:[...e,{type:t,chunks:[n]}]}function pa(e,t){return e[e.length-1]?.type===`content`?[...e.slice(0,-1),{type:`content`,chunks:[t]}]:[...e,{type:`content`,chunks:[t]}]}function ma(e,t){let n=da(t);if(!n?.some(e=>e.type===`tool_use`||e.type===`tool-result`))return fa(e,`content`,t);let r=e[e.length-1],i=n;if(r?.type===`content`){let e=r.chunks.join(``);i=sa(da(e)??(e.trim()?[{type:`text`,text:e}]:[]),n)}let a=JSON.stringify(i);return r?.type===`content`?[...e.slice(0,-1),{type:`content`,chunks:[a]}]:[...e,{type:`content`,chunks:[a]}]}function ha(e){for(let t=e.length-1;t>=0;t--){let n=e[t];if(n.type===`content`)return n.chunks.join(``)}return``}function ga(e,t){return[...e,{type:`long_running_confirmation`,prompt:t}]}function _a(e,t){return[...e,{type:`shell_permission`,prompt:t}]}function va(e,t){return[...e,{type:`web_fetch_permission`,prompt:t}]}function ya(e){let t=[];for(let n of e){if(n.type===`long_running_confirmation`){t.push({type:`long_running_confirmation`,prompt:n.prompt});continue}if(n.type===`shell_permission`){t.push({type:`shell_permission`,prompt:n.prompt});continue}if(n.type===`web_fetch_permission`){t.push({type:`web_fetch_permission`,prompt:n.prompt});continue}let e=n.chunks.join(``);if(n.type===`thinking`){let n=ia(e)??[];t.push(...n)}else{let n=da(e)??(e.trim()?[{type:`text`,text:e}]:[]);t.push(...n)}}return t}function ba(e){return e.type===`thinking-group`}function xa(e,t=!1){let n=[],r=[],i,a=()=>{r.length>0&&(n.push({type:`thinking-group`,text:r.join(`
|
|
4
|
-
|
|
5
|
-
`),label:i,isCurrentlyStreaming:!1}),r=[],i=void 0)};for(let t of e)if(t.type===`reasoning`&&`text`in t){let e=t;r.push(e.text),e.label&&(i=e.label)}else a(),n.push(t);if(a(),t&&n.length>0){let e=n[n.length-1];if(e.type===`thinking-group`){let t=e;t.label!==`Validated`&&(t.isCurrentlyStreaming=!0)}}return n}function Sa(e){for(let t=e.length-1;t>=0;t--){let n=e[t];if(n.type===`long_running_confirmation`||n.type===`shell_permission`||n.type===`web_fetch_permission`)return t}return-1}function Ca(e){return e.type===`content`||e.type===`thinking`?e.chunks.some(e=>e.trim().length>0):!1}function wa(e){let t=ya(e),n=t.some(e=>ta(e)&&e.name===`ask_user`),r=t.some(e=>na(e)&&e.toolName===`ask_user`);if(n&&!r)return!0;let i=Sa(e);return i===-1?!1:!e.slice(i+1).some(Ca)}function Ta(e){let t=ya(e);return t.length===0?`...`:t.length===1&&t[0]?.type===`text`&&`text`in t[0]?t[0].text:JSON.stringify(t)}function Ea(e,t){switch(t.type){case Z.SetStreaming:{let n=zi(e,t),r=Bi(e,t);return Hi(e,n,r,{...Ri(e.threadStreamingStates,n,r),isStreaming:t.isStreaming})}case Z.AppendStreamContent:{let n=zi(e,t),r=Bi(e,t),i=Ri(e.threadStreamingStates,n,r);return Hi(e,n,r,{...i,streamingContent:i.streamingContent+t.content})}case Z.SetStreamContent:{let n=zi(e,t),r=Bi(e,t),i=Ri(e.threadStreamingStates,n,r),a=pa(i.streamingSegments,t.content);return Hi(e,n,r,{...i,streamingContent:t.content,streamingSegments:a})}case Z.AppendStreamThinking:{let n=zi(e,t),r=Bi(e,t),i=Ri(e.threadStreamingStates,n,r);return Hi(e,n,r,{...i,streamingThinking:i.streamingThinking+t.content})}case Z.IncrementStreamEventCount:{let n=zi(e,t),r=Bi(e,t),i=Ri(e.threadStreamingStates,n,r);return Hi(e,n,r,{...i,streamingEventCount:i.streamingEventCount+1})}case Z.AppendStreamChunk:{let n=zi(e,t),r=Bi(e,t),i=Ri(e.threadStreamingStates,n,r);return Hi(e,n,r,{...i,streamingSegments:t.segments,streamingContent:t.chunkType===`content`?i.streamingContent+t.content:i.streamingContent,streamingThinking:t.chunkType===`thinking`?i.streamingThinking+t.content:i.streamingThinking})}case Z.SetStreamModel:{let n=zi(e,t),r=Bi(e,t);return Hi(e,n,r,{...Ri(e.threadStreamingStates,n,r),streamingModel:t.model})}case Z.ResetStream:return Hi(e,zi(e,t),Bi(e,t),Ii(),!0);case Z.StopStream:{let n=zi(e,t),r=Bi(e,t);return Hi(e,n,r,{...Ri(e.threadStreamingStates,n,r),isStreaming:!1})}default:return null}}function Da(e,t){return e.terminalStates[t]??Ui()}function Oa(e,t){switch(t.type){case Z.AppendCommandOutput:return{...e,commandOutput:e.commandOutput+t.content};case Z.SetRunningCommand:return{...e,isRunningCommand:t.isRunning};case Z.ClearCommandOutput:return{...e,commandOutput:``};case Z.ToggleTerminal:{let n=Da(e,t.threadId);return{...e,terminalStates:{...e.terminalStates,[t.threadId]:{...n,open:!n.open}}}}case Z.SetTerminalOpen:{let n=t.threadId??`default`,r=Da(e,n);return{...e,terminalStates:{...e.terminalStates,[n]:{...r,open:t.open}}}}case Z.QueueTerminalCommand:{let n=Da(e,t.threadId);return{...e,terminalStates:{...e.terminalStates,[t.threadId]:{...n,queuedCommand:t.command,queuedRelativeFolder:t.relativeFolder??null,open:!0}}}}case Z.ClearQueuedTerminalCommand:{let n=Da(e,t.threadId);return{...e,terminalStates:{...e.terminalStates,[t.threadId]:{...n,queuedCommand:null}}}}case Z.AppendTerminalLine:{let n=t.threadId??`default`,r=Da(e,n);return{...e,terminalStates:{...e.terminalStates,[n]:{...r,outputLines:[...r.outputLines,t.line]}}}}case Z.ClearTerminalOutput:{let n=t.threadId??`default`,r=Da(e,n);return{...e,terminalStates:{...e.terminalStates,[n]:{...r,outputLines:[]}}}}case Z.SetTerminalHeight:{let n=Da(e,t.threadId);return{...e,terminalStates:{...e.terminalStates,[t.threadId]:{...n,height:t.height}}}}case Z.SetTerminalCwd:{let n=Da(e,t.threadId);return{...e,terminalStates:{...e.terminalStates,[t.threadId]:{...n,cwd:t.cwd}}}}case Z.SetTerminalRunning:{let n=Da(e,t.threadId);return{...e,terminalStates:{...e.terminalStates,[t.threadId]:{...n,isRunning:t.isRunning}}}}case Z.SetTerminalHistory:{let n=Da(e,t.threadId);return{...e,terminalStates:{...e.terminalStates,[t.threadId]:{...n,history:t.history}}}}case Z.SetTerminalHistoryIndex:{let n=Da(e,t.threadId);return{...e,terminalStates:{...e.terminalStates,[t.threadId]:{...n,historyIndex:t.index}}}}default:return null}}function ka(e,t){switch(t.type){case Z.ToggleSidebar:return{...e,sidebarOpen:!e.sidebarOpen};case Z.CloseSidebar:return e.sidebarOpen?{...e,sidebarOpen:!1}:e;case Z.SetCreatingProject:return{...e,isCreatingProject:t.isCreating};case Z.ConfigUpdated:return{...e,configUpdatedAt:Date.now()};case Z.ClearFocusChatInput:return{...e,focusChatInput:!1};case Z.SetDiffComments:return{...e,diffComments:{...e.diffComments,[t.threadId]:t.comments}};default:return null}}var Aa=[Ea,$i,Qi,ea,Oa,ka];function ja(e,t){for(let n of Aa){let r=n(e,t);if(r!==null)return r}return e}var Ma=new Set([Z.AppendStreamChunk,Z.IncrementStreamEventCount,Z.SetStreamModel,Z.AppendStreamContent,Z.AppendStreamThinking,Z.SetStreamContent]);function Na(e=ji){let t=e,n=new Set,r=0,i=[];function a(){return t}function o(){for(let e of n)e()}function s(e){let n=ja(t,e);n!==t&&(t=n)}function c(){if(r=0,i.length!==0){for(let e of i)s(e);i.length=0,o()}}function l(e){if(Ma.has(e.type)){i.push(e),r===0&&(r=requestAnimationFrame(c));return}s(e),o()}function u(e){return n.add(e),function(){n.delete(e)}}return{getState:a,dispatch:l,subscribe:u}}var Pa=(0,Y.createContext)(null);function Fa(){let e=(0,Y.useContext)(Pa);if(!e)throw Error(`useAppStore must be used within an AppStoreContext.Provider`);return e}function Q(e){let t=(0,X.c)(3),n=Fa(),r;t[0]!==e||t[1]!==n?(r=function(){return e(n.getState())},t[0]=e,t[1]=n,t[2]=r):r=t[2];let i=r;return(0,Y.useSyncExternalStore)(n.subscribe,i,i)}function Ia(){return Fa().dispatch}function La(e){let t=(0,X.c)(8),n=Ia(),r;t[0]===e?r=t[1]:(r=t=>(e?t.terminalStates[e]:void 0)??Mi,t[0]=e,t[1]=r);let i=Q(r),a;t[2]!==n||t[3]!==e?(a=t=>{e&&n({...t,threadId:e})},t[2]=n,t[3]=e,t[4]=a):a=t[4];let o=a,s;return t[5]!==o||t[6]!==i?(s={terminalState:i,dispatch:o},t[5]=o,t[6]=i,t[7]=s):s=t[7],s}var $=tn(),Ra=Y.forwardRef((e,t)=>{let n=(0,X.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=z(`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});Ra.displayName=`Textarea`;function za(e){let t=(0,X.c)(47),{open:n,onOpenChange:r,feedbackName:i,onFeedbackNameChange:o,feedbackEmail:c,onFeedbackEmailChange:l,feedbackText:u,onFeedbackTextChange:d,loadingFeedbackUser:f,submittingFeedback:p,onSubmit:m}=e,h;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,$.jsxs)(a,{children:[(0,$.jsx)(vt,{children:`Send Feedback`}),(0,$.jsx)(Qe,{children:`Share feedback about Tarsk.`})]}),t[0]=h):h=t[0];let g;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(g=(0,$.jsx)(j,{htmlFor:`feedback-name`,children:`Name`}),t[1]=g):g=t[1];let _;t[2]===o?_=t[3]:(_=e=>o(e.target.value),t[2]=o,t[3]=_);let v=p||f,y;t[4]!==i||t[5]!==_||t[6]!==v?(y=(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[g,(0,$.jsx)(un,{id:`feedback-name`,value:i,onChange:_,placeholder:`Your name`,disabled:v})]}),t[4]=i,t[5]=_,t[6]=v,t[7]=y):y=t[7];let b;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(b=(0,$.jsx)(j,{htmlFor:`feedback-email`,children:`Email`}),t[8]=b):b=t[8];let x;t[9]===l?x=t[10]:(x=e=>l(e.target.value),t[9]=l,t[10]=x);let S=p||f,C;t[11]!==c||t[12]!==x||t[13]!==S?(C=(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[b,(0,$.jsx)(un,{id:`feedback-email`,type:`email`,value:c,onChange:x,placeholder:`you@example.com`,disabled:S})]}),t[11]=c,t[12]=x,t[13]=S,t[14]=C):C=t[14];let w;t[15]===Symbol.for(`react.memo_cache_sentinel`)?(w=(0,$.jsx)(j,{htmlFor:`feedback-text`,children:`Feedback`}),t[15]=w):w=t[15];let T;t[16]===d?T=t[17]:(T=e=>d(e.target.value),t[16]=d,t[17]=T);let E;t[18]!==u||t[19]!==p||t[20]!==T?(E=(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[w,(0,$.jsx)(Ra,{id:`feedback-text`,value:u,onChange:T,placeholder:`Tell us what you think...`,className:`min-h-32`,disabled:p})]}),t[18]=u,t[19]=p,t[20]=T,t[21]=E):E=t[21];let D;t[22]!==E||t[23]!==y||t[24]!==C?(D=(0,$.jsxs)(`div`,{className:`grid gap-4 py-2`,children:[y,C,E]}),t[22]=E,t[23]=y,t[24]=C,t[25]=D):D=t[25];let O;t[26]===r?O=t[27]:(O=()=>r(!1),t[26]=r,t[27]=O);let k;t[28]!==p||t[29]!==O?(k=(0,$.jsx)(s,{variant:`outline`,onClick:O,disabled:p,children:`Cancel`}),t[28]=p,t[29]=O,t[30]=k):k=t[30];let A;t[31]===p?A=t[32]:(A=p?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(wn,{className:`mr-2 h-4 w-4 animate-spin`}),`Sending...`]}):`Send`,t[31]=p,t[32]=A);let M;t[33]!==m||t[34]!==p||t[35]!==A?(M=(0,$.jsx)(s,{onClick:m,disabled:p,children:A}),t[33]=m,t[34]=p,t[35]=A,t[36]=M):M=t[36];let N;t[37]!==k||t[38]!==M?(N=(0,$.jsxs)(we,{children:[k,M]}),t[37]=k,t[38]=M,t[39]=N):N=t[39];let P;t[40]!==D||t[41]!==N?(P=(0,$.jsxs)(We,{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:[h,D,N]}),t[40]=D,t[41]=N,t[42]=P):P=t[42];let F;return t[43]!==r||t[44]!==n||t[45]!==P?(F=(0,$.jsx)(ie,{open:n,onOpenChange:r,children:P}),t[43]=r,t[44]=n,t[45]=P,t[46]=F):F=t[46],F}function Ba(e){let t=(0,X.c)(30),{node:n,level:r,renderNode:i,defaultOpen:a,indent:o,childContainerClassName:s,openState:c,onToggle:l,forceOpenIds:u}=e,d=!!(n.children&&n.children.length>0),f,p,m;if(t[0]!==a||t[1]!==u||t[2]!==d||t[3]!==r||t[4]!==n||t[5]!==l||t[6]!==c||t[7]!==i){f=u?.has(n.id)||(c[n.id]??a);let e;t[11]!==n.id||t[12]!==l?(e=()=>l(n.id),t[11]=n.id,t[12]=l,t[13]=e):e=t[13];let o=e;p=`min-w-0`,m=i(n,{isOpen:f,level:r,toggle:o,hasChildren:d}),t[0]=a,t[1]=u,t[2]=d,t[3]=r,t[4]=n,t[5]=l,t[6]=c,t[7]=i,t[8]=f,t[9]=p,t[10]=m}else f=t[8],p=t[9],m=t[10];let h;t[14]!==s||t[15]!==a||t[16]!==u||t[17]!==d||t[18]!==o||t[19]!==f||t[20]!==r||t[21]!==n.children||t[22]!==l||t[23]!==c||t[24]!==i?(h=d&&f&&(0,$.jsx)(`div`,{style:{paddingLeft:o},className:s,children:n.children.map(e=>(0,$.jsx)(Ba,{node:e,level:r+1,renderNode:i,defaultOpen:a,indent:o,childContainerClassName:s,openState:c,onToggle:l,forceOpenIds:u},e.id))}),t[14]=s,t[15]=a,t[16]=u,t[17]=d,t[18]=o,t[19]=f,t[20]=r,t[21]=n.children,t[22]=l,t[23]=c,t[24]=i,t[25]=h):h=t[25];let g;return t[26]!==p||t[27]!==m||t[28]!==h?(g=(0,$.jsxs)(`div`,{className:p,children:[m,h]}),t[26]=p,t[27]=m,t[28]=h,t[29]=g):g=t[29],g}function Va(e){let t=(0,X.c)(28),{nodes:n,renderNode:r,resetKey:i,defaultOpen:a,forceOpenIds:o,initialOpenIds:s,indent:c,childContainerClassName:l,className:u}=e,d=a===void 0?!1:a,f=c===void 0?16:c,p;t[0]===s?p=t[1]:(p=()=>{let e={};if(s)for(let t of s)e[t]=!0;return e},t[0]=s,t[1]=p);let[m,h]=(0,Y.useState)(p),[g,_]=(0,Y.useState)(i);if(i!==g){_(i);let e={};if(s)for(let t of s)e[t]=!0;h(e)}let v;t[2]===o?v=t[3]:(v=o?new Set(o):void 0,t[2]=o,t[3]=v);let y=v,b;t[4]===d?b=t[5]:(b=e=>{h(t=>({...t,[e]:!(t[e]??d)}))},t[4]=d,t[5]=b);let x=b,S;t[6]===u?S=t[7]:(S=z(`min-w-0`,u),t[6]=u,t[7]=S);let C;if(t[8]!==l||t[9]!==d||t[10]!==y||t[11]!==x||t[12]!==f||t[13]!==n||t[14]!==m||t[15]!==r){let e;t[17]!==l||t[18]!==d||t[19]!==y||t[20]!==x||t[21]!==f||t[22]!==m||t[23]!==r?(e=e=>(0,$.jsx)(Ba,{node:e,level:0,renderNode:r,defaultOpen:d,indent:f,childContainerClassName:l,openState:m,onToggle:x,forceOpenIds:y},e.id),t[17]=l,t[18]=d,t[19]=y,t[20]=x,t[21]=f,t[22]=m,t[23]=r,t[24]=e):e=t[24],C=n.map(e),t[8]=l,t[9]=d,t[10]=y,t[11]=x,t[12]=f,t[13]=n,t[14]=m,t[15]=r,t[16]=C}else C=t[16];let w;return t[25]!==S||t[26]!==C?(w=(0,$.jsx)(`div`,{className:S,children:C}),t[25]=S,t[26]=C,t[27]=w):w=t[27],w}var Ha=1,Ua=1e3,Wa=0;function Ga(){return Wa=(Wa+1)%(2**53-1),Wa.toString()}var Ka=new Map,qa=e=>{if(Ka.has(e))return;let t=setTimeout(()=>{Ka.delete(e),Za({type:`REMOVE_TOAST`,toastId:e})},Ua);Ka.set(e,t)},Ja=(e,t)=>{switch(t.type){case`ADD_TOAST`:return{...e,toasts:[t.toast,...e.toasts].slice(0,Ha)};case`UPDATE_TOAST`:return{...e,toasts:e.toasts.map(e=>e.id===t.toast.id?{...e,...t.toast}:e)};case`DISMISS_TOAST`:{let{toastId:n}=t;return n?qa(n):e.toasts.forEach(e=>{qa(e.id)}),{...e,toasts:e.toasts.map(e=>e.id===n||n===void 0?{...e,open:!1}:e)}}case`REMOVE_TOAST`:return t.toastId===void 0?{...e,toasts:[]}:{...e,toasts:e.toasts.filter(e=>e.id!==t.toastId)}}},Ya=[],Xa={toasts:[]};function Za(e){Xa=Ja(Xa,e),Ya.forEach(e=>{e(Xa)})}function Qa({...e}){let t=Ga(),n=e=>Za({type:`UPDATE_TOAST`,toast:{...e,id:t}}),r=()=>Za({type:`DISMISS_TOAST`,toastId:t});return Za({type:`ADD_TOAST`,toast:{...e,id:t,open:!0,onOpenChange:e=>{e||r()}}}),{id:t,dismiss:r,update:n}}function $a(){let e=(0,X.c)(4),[t,n]=Y.useState(Xa),r,i;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=()=>(Ya.push(n),()=>{let e=Ya.indexOf(n);e>-1&&Ya.splice(e,1)}),i=[],e[0]=r,e[1]=i):(r=e[0],i=e[1]),Y.useEffect(r,i);let a;return e[2]===t?a=e[3]:(a={...t,toast:Qa,dismiss:eo},e[2]=t,e[3]=a),a}function eo(e){return Za({type:`DISMISS_TOAST`,toastId:e})}function to(){let[e,t]=(0,Y.useState)(!1),[n,r]=(0,Y.useState)(``),[i,a]=(0,Y.useState)(``),[o,s]=(0,Y.useState)(``),[c,l]=(0,Y.useState)(!1),[u,d]=(0,Y.useState)(!1);return(0,Y.useEffect)(()=>{if(!e)return;let t=!0;return l(!0),Tn().then(e=>{t&&(r(t=>t||e.name),a(t=>t||e.email))}).catch(()=>{t&&Qa({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){Qa({title:`Feedback required`,description:`Please enter your feedback before submitting.`,variant:`destructive`});return}d(!0);try{await Se(`api/feedback`,{name:n.trim(),email:i.trim(),feedback:e}),Qa({title:`Feedback sent`,description:`Thanks for sharing your feedback.`}),s(``),t(!1)}catch(e){Qa({title:`Failed to send feedback`,description:e instanceof Error?e.message:`Please try again.`,variant:`destructive`})}finally{d(!1)}}}}var no=ei(e=>(0,$.jsxs)(`div`,{className:e.v0,style:e.v1,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between border-b border-sidebar-border px-4 py-3 h-[61px]`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:e.v2,className:`flex h-7 w-7 items-center justify-center overflow-hidden rounded-md border border-sidebar-border shadow-sm cursor-pointer`,children:(0,$.jsx)(`img`,{src:`/tarsk.svg`,alt:`Tarsk`,className:`h-full w-full`})}),e.v3]}),e.v4]}),e.v5,e.v6]}),{name:`SidePanelContainer_1`,portals:[`v3`,`v4`,`v5`,`v6`]}),ro=function(e){let t=(0,X.c)(23),{children:n,collapsed:r,title:i,onTitleClose:a,subtitle:o,headerAction:c,footer:l,isDevMode:u}=e,d,f,p,m;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(f=Ve(),p=function(){kt(`https://tarsk.io/`)},d=no,m=z(`flex flex-col select-none bg-sidebar text-sidebar-foreground mx-2.5 md:mr-10 rounded-3xl shadow-2xl overflow-hidden`,f&&`mt-8`),t[0]=d,t[1]=f,t[2]=p,t[3]=m):(d=t[0],f=t[1],p=t[2],m=t[3]);let h;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(h={containerType:`inline-size`,height:f?`calc(100% - 42px)`:`calc(100% - 12px)`},t[4]=h):h=t[4];let g;t[5]!==r||t[6]!==u||t[7]!==o?(g=!r&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:p,className:z(W.sectionTitle,u&&`text-destructive dark:text-red-400`,`cursor-pointer hover:underline`),children:u?`Dev Mode`:`tarsk`}),o&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(re,{className:`h-3 w-3 text-sidebar-foreground/60`}),(0,$.jsx)(`span`,{className:z(W.label,`text-sidebar-foreground/80`),children:o})]})]}),t[5]=r,t[6]=u,t[7]=o,t[8]=g):g=t[8];let _;t[9]!==r||t[10]!==c||t[11]!==a||t[12]!==i?(_=(i??a??c)&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 ml-auto`,children:[c&&!r&&c,i&&(0,$.jsx)(`span`,{className:z(W.compact,`font-medium text-sidebar-foreground/80`),children:i}),a&&(0,$.jsxs)(s,{variant:`ghost`,size:`icon`,className:`h-7 w-7 text-sidebar-foreground`,onClick:a,children:[(0,$.jsx)(zn,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]}),t[9]=r,t[10]=c,t[11]=a,t[12]=i,t[13]=_):_=t[13];let v;t[14]===n?v=t[15]:(v=(0,$.jsx)(ct,{className:`flex-1`,children:n}),t[14]=n,t[15]=v);let y;t[16]===l?y=t[17]:(y=l&&(0,$.jsx)(`div`,{className:`border-t border-sidebar-border`,children:l}),t[16]=l,t[17]=y);let b;return t[18]!==g||t[19]!==_||t[20]!==v||t[21]!==y?(b=(0,$.jsx)(d,{v0:m,v1:h,v2:p,v3:g,v4:_,v5:v,v6:y}),t[18]=g,t[19]=_,t[20]=v,t[21]=y,t[22]=b):b=t[22],b},io=ei(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_1`,svg:!0}),ao=ei(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_2`,svg:!0}),oo=function(e){let t=(0,X.c)(9),{gitStatusDot:n,animate:r}=e,i=!!n,a=r&&`animate-thread-dot-pulse`,o=n===`changes`&&`text-brand`,s;t[0]!==i||t[1]!==n||t[2]!==a||t[3]!==o?(s=z(`h-3 w-3 shrink-0 origin-center`,a,o,Te(n)&&`text-orange-500`,!i&&`text-muted-foreground`),t[0]=i,t[1]=n,t[2]=a,t[3]=o,t[4]=s):s=t[4];let c=s;if(i){let e;return t[5]===c?e=t[6]:(e=(0,$.jsx)(io,{v0:c}),t[5]=c,t[6]=e),e}let l;return t[7]===c?l=t[8]:(l=(0,$.jsx)(ao,{v0:c}),t[7]=c,t[8]=l),l};function so(e){let t=(0,X.c)(87),{projects:n,selectedThreadId:r,selectedProjectId:i,processingThreadIds:a,completedThreadIds:o,deletingThreadIds:c,deletingProjectIds:l,onSelectThread:u,onCreateProject:d,onCreateThread:f,onDeleteThread:p,onDeleteProject:m,collapsed:h,updateAvailable:g,updatingApp:_,onUpdateApp:v,isDevMode:y,expandProjectId:b}=e,x=er(),S=Q(fo),C=Q(uo),{showFeedback:w,feedbackName:E,setFeedbackName:O,feedbackEmail:k,setFeedbackEmail:A,feedbackText:j,setFeedbackText:M,loadingFeedbackUser:N,submittingFeedback:P,handleFeedbackDialogChange:F,handleSubmitFeedback:I}=to(),te;t[0]===n?te=t[1]:(te=[...n].sort(lo),t[0]=n,t[1]=te);let R=te,ne;t[2]===R?ne=t[3]:(ne=R.map(co),t[2]=R,t[3]=ne);let re=ne,ie;bb0:{if(!i){ie=void 0;break bb0}if(n.find(e=>e.projectId===i)?.threads.length===1){ie=void 0;break bb0}let e;t[4]===i?e=t[5]:(e=[i],t[4]=i,t[5]=e),ie=e}let ae=ie,oe;t[6]===b?oe=t[7]:(oe=b?[b]:void 0,t[6]=b,t[7]=oe);let se=oe,ce;t[8]!==h||t[9]!==d?(ce=!h&&(0,$.jsxs)(s,{variant:`outline`,size:`sm`,className:`gap-2`,onClick:d,children:[(0,$.jsx)(sn,{className:`h-4 w-4 shrink-0`}),(0,$.jsx)(`span`,{className:`truncate`,children:`New Project`})]}),t[8]=h,t[9]=d,t[10]=ce):ce=t[10];let le;t[11]!==h||t[12]!==v||t[13]!==g||t[14]!==_?(le=g&&(0,$.jsxs)(s,{variant:`ghost`,size:`sm`,className:`w-full justify-start gap-2 text-emerald-600 dark:text-emerald-400`,onClick:v,disabled:_,children:[_?(0,$.jsx)(wn,{className:`h-4 w-4 animate-spin`}):(0,$.jsx)(ee,{className:`h-4 w-4`}),!h&&(0,$.jsx)(`span`,{className:`truncate`,children:_?`Updating...`:`Update to Latest`})]}),t[11]=h,t[12]=v,t[13]=g,t[14]=_,t[15]=le):le=t[15];let ue;t[16]===x?ue=t[17]:(ue=()=>void x(`/settings/general`),t[16]=x,t[17]=ue);let de;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(de=(0,$.jsx)(T,{className:`h-4 w-4`}),t[18]=de):de=t[18];let fe;t[19]===h?fe=t[20]:(fe=!h&&(0,$.jsx)(`span`,{className:`truncate`,children:`Settings`}),t[19]=h,t[20]=fe);let pe;t[21]!==ue||t[22]!==fe?(pe=(0,$.jsxs)(s,{variant:`ghost`,size:`sm`,className:`flex-1 justify-start gap-2 text-sidebar-foreground`,onClick:ue,children:[de,fe]}),t[21]=ue,t[22]=fe,t[23]=pe):pe=t[23];let V;t[24]===F?V=t[25]:(V=()=>F(!0),t[24]=F,t[25]=V);let me,he;t[26]===Symbol.for(`react.memo_cache_sentinel`)?(me=(0,$.jsx)(gn,{className:`h-4 w-4`}),he=(0,$.jsx)(`span`,{className:`sr-only`,children:`Feedback`}),t[26]=me,t[27]=he):(me=t[26],he=t[27]);let ge;t[28]===V?ge=t[29]:(ge=(0,$.jsx)(L,{asChild:!0,children:(0,$.jsxs)(s,{variant:`ghost`,size:`icon-sm`,className:`text-muted-foreground hover:text-background`,onClick:V,children:[me,he]})}),t[28]=V,t[29]=ge);let ve;t[30]===Symbol.for(`react.memo_cache_sentinel`)?(ve=(0,$.jsx)(H,{children:`Send feedback to the Tarsk team`}),t[30]=ve):ve=t[30];let ye;t[31]===ge?ye=t[32]:(ye=(0,$.jsx)(D,{children:(0,$.jsxs)(B,{children:[ge,ve]})}),t[31]=ge,t[32]=ye);let be;t[33]!==pe||t[34]!==ye?(be=(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[pe,ye]}),t[33]=pe,t[34]=ye,t[35]=be):be=t[35];let xe;t[36]!==be||t[37]!==le?(xe=(0,$.jsxs)(`div`,{className:`px-3 py-2 flex flex-col gap-1`,children:[le,be]}),t[36]=be,t[37]=le,t[38]=xe):xe=t[38];let Se;t[39]===n.length?Se=t[40]:(Se=n.length===0&&(0,$.jsx)(`p`,{className:z(W.compact,`px-3 py-6 text-center text-muted-foreground`),children:`No projects yet. Clone a repository to get started.`}),t[39]=n.length,t[40]=Se);let Ce;t[41]!==o||t[42]!==l||t[43]!==c||t[44]!==x||t[45]!==f||t[46]!==m||t[47]!==p||t[48]!==u||t[49]!==C||t[50]!==a||t[51]!==n||t[52]!==i||t[53]!==r||t[54]!==S?(Ce=(e,t)=>{let{isOpen:s,toggle:d}=t;return e.kind===`project`?(0,$.jsx)(po,{project:e.project,isOpen:s,onToggle:d,isDeletingProject:l.includes(e.project.projectId),isSelected:i?e.project.projectId===i:!1,onCreateThread:f,onDeleteProject:m,onProjectSettings:e=>void x(`/settings/project/${e}`),hasSelectedThread:e.project.threads.some(e=>e.threadId===r),onSelectThread:u}):(0,$.jsx)(mo,{thread:e.thread,projectId:e.projectId,selectedThreadId:r,isProcessing:Ni(e.thread.threadId,a,S,C),isDeleting:c.includes(e.thread.threadId),isCompleted:o.includes(e.thread.threadId),projectTitlePrefix:`${_e(n.find(t=>t.projectId===e.projectId))} - `,onSelectThread:u,onDeleteThread:p})},t[41]=o,t[42]=l,t[43]=c,t[44]=x,t[45]=f,t[46]=m,t[47]=p,t[48]=u,t[49]=C,t[50]=a,t[51]=n,t[52]=i,t[53]=r,t[54]=S,t[55]=Ce):Ce=t[55];let we;t[56]!==se||t[57]!==ae||t[58]!==re||t[59]!==Ce?(we=(0,$.jsx)(Va,{nodes:re,defaultOpen:!1,initialOpenIds:ae,forceOpenIds:se,childContainerClassName:`ml-4 border-l border-sidebar-border pl-2`,renderNode:Ce}),t[56]=se,t[57]=ae,t[58]=re,t[59]=Ce,t[60]=we):we=t[60];let U;t[61]!==Se||t[62]!==we?(U=(0,$.jsx)(`div`,{className:`flex-1 w-full`,children:(0,$.jsxs)(`div`,{className:`px-2 py-2 w-full max-w-full overflow-hidden`,children:[Se,we]})}),t[61]=Se,t[62]=we,t[63]=U):U=t[63];let Te;t[64]!==h||t[65]!==y||t[66]!==xe||t[67]!==U||t[68]!==ce?(Te=(0,$.jsx)(ro,{collapsed:h,isDevMode:y,headerAction:ce,footer:xe,children:U}),t[64]=h,t[65]=y,t[66]=xe,t[67]=U,t[68]=ce,t[69]=Te):Te=t[69];let Ee;t[70]===I?Ee=t[71]:(Ee=()=>void I(),t[70]=I,t[71]=Ee);let De;t[72]!==k||t[73]!==E||t[74]!==j||t[75]!==F||t[76]!==N||t[77]!==A||t[78]!==O||t[79]!==M||t[80]!==w||t[81]!==P||t[82]!==Ee?(De=(0,$.jsx)(za,{open:w,onOpenChange:F,feedbackName:E,onFeedbackNameChange:O,feedbackEmail:k,onFeedbackEmailChange:A,feedbackText:j,onFeedbackTextChange:M,loadingFeedbackUser:N,submittingFeedback:P,onSubmit:Ee}),t[72]=k,t[73]=E,t[74]=j,t[75]=F,t[76]=N,t[77]=A,t[78]=O,t[79]=M,t[80]=w,t[81]=P,t[82]=Ee,t[83]=De):De=t[83];let Oe;return t[84]!==Te||t[85]!==De?(Oe=(0,$.jsxs)($.Fragment,{children:[Te,De]}),t[84]=Te,t[85]=De,t[86]=Oe):Oe=t[86],Oe}function co(e,t){return{id:e.projectId||e.gitUrl||`project-${t}`,kind:`project`,project:e,children:e.threads.map((t,n)=>({id:t.threadId||`${e.projectId}-${t.title||n}`,kind:`thread`,thread:t,projectId:e.projectId}))}}function lo(e,t){return _e(e).localeCompare(_e(t))}function uo(e){return e.pendingChatMessage}function fo(e){return e.threadStreamingStates}function po(e){let t=(0,X.c)(39),{project:n,isOpen:r,onToggle:i,isDeletingProject:a,hasSelectedThread:o,isSelected:c,onCreateThread:l,onDeleteProject:u,onProjectSettings:d,onSelectThread:f}=e,p;t[0]===n?p=t[1]:(p=_e(n),t[0]=n,t[1]=p);let m=p,h=o||c,g=n.threads.length===1?n.threads[0]:null,_;t[2]!==f||t[3]!==i||t[4]!==n.projectId||t[5]!==g||t[6]!==h?(_=function(){if(!h&&g){f(n.projectId,g.threadId);return}i()},t[2]=f,t[3]=i,t[4]=n.projectId,t[5]=g,t[6]=h,t[7]=_):_=t[7];let v=_,y=o||c,x=r&&`rotate-90`,C;t[8]===x?C=t[9]:(C=z(`h-3.5 w-3.5 shrink-0 text-muted-foreground transition-transform`,x),t[8]=x,t[9]=C);let w;t[10]===C?w=t[11]:(w=(0,$.jsx)(re,{className:C}),t[10]=C,t[11]=w);let E;t[12]===n.gitUrl?E=t[13]:(E=n.gitUrl?(0,$.jsx)(S,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}):(0,$.jsx)(Nn,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),t[12]=n.gitUrl,t[13]=E);let O=(o||c)&&`font-bold text-foreground`,k;t[14]===O?k=t[15]:(k=z(`min-w-0 truncate transition-all block`,O),t[14]=O,t[15]=k);let A;t[16]!==m||t[17]!==k?(A=(0,$.jsx)(`span`,{className:k,children:m}),t[16]=m,t[17]=k,t[18]=A):A=t[18];let j;t[19]!==A||t[20]!==w||t[21]!==E?(j=(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-1.5 w-0`,children:[w,E,A]}),t[19]=A,t[20]=w,t[21]=E,t[22]=j):j=t[22];let M;t[23]!==v||t[24]!==j?(M=(0,$.jsx)(`button`,{type:`button`,className:`min-w-0`,onClick:v,children:j}),t[23]=v,t[24]=j,t[25]=M):M=t[25];let N;t[26]!==M||t[27]!==y?(N=(0,$.jsx)(fi,{selected:y,noBackground:!0,className:`h-9 min-w-0 flex-1`,asChild:!0,children:M}),t[26]=M,t[27]=y,t[28]=N):N=t[28];let P;t[29]!==a||t[30]!==l||t[31]!==u||t[32]!==d||t[33]!==n.projectId||t[34]!==n.threads.length?(P=(0,$.jsx)(`div`,{className:`flex shrink-0 items-center`,children:a?(0,$.jsx)(wn,{className:`h-3.5 w-3.5 shrink-0 animate-spin text-muted-foreground mr-1`}):(0,$.jsxs)(D,{children:[(0,$.jsxs)(B,{children:[(0,$.jsx)(L,{asChild:!0,children:(0,$.jsxs)(s,{variant:`ghost`,size:`icon`,className:`h-7 w-7 shrink-0 hidden can-hover:group-hover:flex items-center justify-center`,onClick:()=>d(n.projectId),children:[(0,$.jsx)(T,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Project settings`})]})}),(0,$.jsx)(H,{side:`right`,children:`Project settings`})]}),(0,$.jsxs)(B,{children:[(0,$.jsx)(L,{asChild:!0,children:(0,$.jsxs)(s,{variant:`action`,size:`icon-sm`,className:`shrink-0 hidden can-hover:group-hover:flex items-center justify-center`,onClick:()=>l(n.projectId),children:[(0,$.jsx)(sn,{}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Add thread`})]})}),(0,$.jsx)(H,{side:`right`,children:`Add thread`})]}),n.threads.length===0&&(0,$.jsxs)(B,{children:[(0,$.jsx)(L,{asChild:!0,children:(0,$.jsxs)(s,{variant:`ghost`,size:`icon-sm`,className:`shrink-0 hidden can-hover:group-hover:flex items-center justify-center text-muted-foreground can-hover:hover:bg-destructive can-hover:hover:text-destructive-foreground transition-colors`,onClick:()=>u(n.projectId),children:[(0,$.jsx)(b,{}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Delete project`})]})}),(0,$.jsx)(H,{side:`right`,children:`Delete project`})]})]})}),t[29]=a,t[30]=l,t[31]=u,t[32]=d,t[33]=n.projectId,t[34]=n.threads.length,t[35]=P):P=t[35];let F;return t[36]!==N||t[37]!==P?(F=(0,$.jsxs)(`div`,{className:`group mb-1 flex min-w-0 items-center`,children:[N,P]}),t[36]=N,t[37]=P,t[38]=F):F=t[38],F}function mo(e){let t=(0,X.c)(57),{thread:n,projectId:r,selectedThreadId:i,isProcessing:a,isDeleting:o,isCompleted:c,projectTitlePrefix:l,onSelectThread:u,onDeleteThread:d}=e,[f,p]=(0,Y.useState)(!1),m=(0,Y.useRef)(null),h=n.threadId===i,g,_;t[0]===a?(g=t[1],_=t[2]):(g=()=>{a&&m.current&&m.current.scrollIntoView({behavior:`smooth`,block:`nearest`})},_=[a],t[0]=a,t[1]=g,t[2]=_),(0,Y.useEffect)(g,_);let v;t[3]!==d||t[4]!==r||t[5]!==n.gitStatusDot||t[6]!==n.threadId?(v=e=>{e.stopPropagation(),n.gitStatusDot?p(!0):d(r,n.threadId)},t[3]=d,t[4]=r,t[5]=n.gitStatusDot,t[6]=n.threadId,t[7]=v):v=t[7];let y=v,x;t[8]!==l||t[9]!==n.threadId||t[10]!==n.title?(x=n.title?.startsWith(l)?n.title.slice(l.length):n.title??n.threadId,t[8]=l,t[9]=n.threadId,t[10]=n.title,t[11]=x):x=t[11];let S=x,C;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(C=(0,$.jsx)($r,{children:`Delete Thread`}),t[12]=C):C=t[12];let w;t[13]===S?w=t[14]:(w=(0,$.jsxs)(ti,{children:[`Are you sure you want to delete "`,S,`" and all its files? This action cannot be undone.`]}),t[13]=S,t[14]=w);let T;t[15]===Symbol.for(`react.memo_cache_sentinel`)?(T=(0,$.jsx)(Zr,{children:`Cancel`}),t[15]=T):T=t[15];let E;t[16]!==d||t[17]!==r||t[18]!==n.threadId?(E=(0,$.jsxs)(`div`,{className:`flex gap-3 justify-end`,children:[T,(0,$.jsx)(si,{onClick:()=>{p(!1),d(r,n.threadId)},className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:`Delete`})]}),t[16]=d,t[17]=r,t[18]=n.threadId,t[19]=E):E=t[19];let D;t[20]!==w||t[21]!==E?(D=(0,$.jsxs)(oi,{children:[C,w,E]}),t[20]=w,t[21]=E,t[22]=D):D=t[22];let O;t[23]!==f||t[24]!==D?(O=(0,$.jsx)(ri,{open:f,onOpenChange:p,children:D}),t[23]=f,t[24]=D,t[25]=O):O=t[25];let k;t[26]!==u||t[27]!==r||t[28]!==n.threadId?(k=()=>u(r,n.threadId),t[26]=u,t[27]=r,t[28]=n.threadId,t[29]=k):k=t[29];let A=a||o,j;t[30]!==A||t[31]!==n.gitStatusDot?(j=(0,$.jsx)(oo,{gitStatusDot:n.gitStatusDot,animate:A}),t[30]=A,t[31]=n.gitStatusDot,t[32]=j):j=t[32];let M;t[33]===Symbol.for(`react.memo_cache_sentinel`)?(M=z(W.body,`truncate block`),t[33]=M):M=t[33];let N;t[34]===S?N=t[35]:(N=(0,$.jsx)(`div`,{className:`flex-1 min-w-0 w-0`,children:(0,$.jsx)(`span`,{className:M,children:S})}),t[34]=S,t[35]=N);let P;t[36]===c?P=t[37]:(P=c?(0,$.jsx)(Ze,{className:`ml-auto h-3 w-3 shrink-0 text-green-500`}):null,t[36]=c,t[37]=P);let F;t[38]!==k||t[39]!==j||t[40]!==N||t[41]!==P?(F=(0,$.jsxs)(`button`,{type:`button`,className:`min-w-0 w-full`,onClick:k,children:[j,N,P]}),t[38]=k,t[39]=j,t[40]=N,t[41]=P,t[42]=F):F=t[42];let I;t[43]!==h||t[44]!==F?(I=(0,$.jsx)(fi,{selected:h,className:`min-w-0 flex-1`,asChild:!0,children:F}),t[43]=h,t[44]=F,t[45]=I):I=t[45];let ee;t[46]!==y||t[47]!==c||t[48]!==o||t[49]!==a?(ee=!a&&!o&&!c&&(0,$.jsxs)(B,{children:[(0,$.jsx)(L,{asChild:!0,children:(0,$.jsxs)(s,{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:y,children:[(0,$.jsx)(b,{}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Delete thread`})]})}),(0,$.jsx)(H,{side:`right`,children:`Delete thread and files from the repo`})]}),t[46]=y,t[47]=c,t[48]=o,t[49]=a,t[50]=ee):ee=t[50];let te;t[51]!==I||t[52]!==ee?(te=(0,$.jsxs)(`div`,{ref:m,className:`group flex min-w-0 items-center`,children:[I,ee]}),t[51]=I,t[52]=ee,t[53]=te):te=t[53];let R;return t[54]!==O||t[55]!==te?(R=(0,$.jsxs)($.Fragment,{children:[O,te]}),t[54]=O,t[55]=te,t[56]=R):R=t[56],R}var ho=e(ft(),1),go=.1,_o=10,vo=1.25,yo=.001;function bo(){let e=(0,X.c)(15),[t,n]=(0,Y.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,Y.useState)(r),[o,s]=(0,Y.useState)(!1),c=(0,Y.useRef)(null),l=xo,u;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(u=()=>n(e=>l(e*vo)),e[1]=u):u=e[1];let d=u,f;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(f=()=>n(e=>l(e/vo)),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,Y.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*yo;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,Y.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 xo(e){return Math.min(Math.max(e,go),_o)}var So=ei(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`]}),Co=ei(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`]}),wo=ei(e=>(0,$.jsxs)(`div`,{className:e.v0,children:[e.v1,(0,$.jsx)(`div`,{className:e.v2,children:`Rendering diagram…`})]}),{name:`MermaidRenderer_2`,portals:[`v1`]}),To=ei(e=>e.v0,{name:`MermaidRenderer_3`,portals:[`v0`]}),Eo=function(e){let t=(0,X.c)(47),{content:n,className:r}=e,[i,a]=(0,Y.useState)(!1),[o,c]=(0,Y.useState)(!1),{svgOutput:l,renderError:u}=Oo(n,Do()),f;t[0]===n?f=t[1]:(f=async function(){await navigator.clipboard.writeText(n),a(!0),setTimeout(()=>a(!1),2e3)},t[0]=n,t[1]=f);let p=f,m;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(m=z(W.compact,`font-mono text-muted-foreground`),t[2]=m):m=t[2];let h=u?`mermaid (render error)`:`mermaid diagram`,g;t[3]!==u||t[4]!==l?(g=l&&!u&&(0,$.jsxs)(B,{children:[(0,$.jsx)(L,{asChild:!0,children:(0,$.jsxs)(s,{variant:`action`,size:`icon-xs`,onClick:()=>c(!0),children:[(0,$.jsx)(Ht,{}),(0,$.jsx)(`span`,{className:`sr-only`,children:`View fullscreen`})]})}),(0,$.jsx)(H,{children:`View fullscreen`})]}),t[3]=u,t[4]=l,t[5]=g):g=t[5];let _;t[6]===i?_=t[7]:(_=i?(0,$.jsx)(Ze,{}):(0,$.jsx)(d,{}),t[6]=i,t[7]=_);let v;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,$.jsx)(`span`,{className:`sr-only`,children:`Copy mermaid code`}),t[8]=v):v=t[8];let y;t[9]!==p||t[10]!==_?(y=(0,$.jsxs)(s,{variant:`action`,size:`icon-xs`,onClick:p,children:[_,v]}),t[9]=p,t[10]=_,t[11]=y):y=t[11];let b;t[12]!==h||t[13]!==g||t[14]!==y?(b=(0,$.jsx)(So,{v0:m,v1:h,v2:g,v3:y}),t[12]=h,t[13]=g,t[14]=y,t[15]=b):b=t[15];let x=b;if(u){let e;t[16]===r?e=t[17]:(e=z(`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=z(W.compact,`font-mono text-foreground leading-relaxed`),t[18]=i):i=t[18];let a;return t[19]!==n||t[20]!==x||t[21]!==e?(a=(0,$.jsx)(Co,{v0:e,v1:x,v2:i,v3:n}),t[19]=n,t[20]=x,t[21]=e,t[22]=a):a=t[22],a}if(!l){let e;t[23]===r?e=t[24]:(e=z(`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=z(W.compact,`p-4 text-muted-foreground`),t[25]=n):n=t[25];let i;return t[26]!==x||t[27]!==e?(i=(0,$.jsx)(wo,{v0:e,v1:x,v2:n}),t[26]=x,t[27]=e,t[28]=i):i=t[28],i}let S;t[29]===r?S=t[30]:(S=z(`group relative overflow-hidden rounded-lg border border-border bg-muted`,r),t[29]=r,t[30]=S);let C;t[31]===Symbol.for(`react.memo_cache_sentinel`)?(C=()=>c(!0),t[31]=C):C=t[31];let w;t[32]===l?w=t[33]:(w=(0,$.jsx)(L,{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:C,dangerouslySetInnerHTML:{__html:l}})}),t[32]=l,t[33]=w);let T;t[34]===Symbol.for(`react.memo_cache_sentinel`)?(T=(0,$.jsx)(H,{children:`Click to view fullscreen`}),t[34]=T):T=t[34];let E;t[35]===w?E=t[36]:(E=(0,$.jsxs)(B,{children:[w,T]}),t[35]=w,t[36]=E);let O;t[37]!==x||t[38]!==E||t[39]!==S?(O=(0,$.jsxs)(`div`,{className:S,children:[x,E]}),t[37]=x,t[38]=E,t[39]=S,t[40]=O):O=t[40];let k;t[41]!==o||t[42]!==l?(k=o&&(0,$.jsx)(ko,{svgOutput:l,onClose:()=>c(!1)}),t[41]=o,t[42]=l,t[43]=k):k=t[43];let A;return t[44]!==O||t[45]!==k?(A=(0,$.jsx)(To,{v0:(0,$.jsxs)(D,{children:[O,k]})}),t[44]=O,t[45]=k,t[46]=A):A=t[46],A};function Do(){let e=(0,X.c)(2),[t,n]=(0,Y.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,Y.useEffect)(r,i),t}function Oo(e,t){let[n,r]=(0,Y.useState)(null),[i,a]=(0,Y.useState)(!1);return(0,Y.useEffect)(()=>{let n=!1;async function i(){try{let{renderMermaidSVG:i}=await Xr(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){console.error(`Mermaid render error:`,e),n||a(!0)}}return i(),()=>{n=!0}},[e,t]),{svgOutput:n,renderError:i}}function ko(e){let t=(0,X.c)(70),{svgOutput:n,onClose:r}=e,{scale:i,offset:a,isDragging:o,containerRef:c,zoomIn:l,zoomOut:u,reset:d,onMouseDown:f,onMouseMove:p,onMouseUp:m}=bo(),h,g;t[0]===r?(h=t[1],g=t[2]):(h=()=>{let e=function(e){e.key===`Escape`&&r()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},g=[r],t[0]=r,t[1]=h,t[2]=g),(0,Y.useEffect)(h,g);let _;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(_=[],t[3]=_):_=t[3],(0,Y.useEffect)(Ao,_);let v;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,$.jsx)(`span`,{className:z(W.compact,`font-mono text-muted-foreground`),children:`mermaid diagram`}),t[4]=v):v=t[4];let y,b;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(y=(0,$.jsx)(At,{className:`h-3.5 w-3.5`}),b=(0,$.jsx)(`span`,{className:`sr-only`,children:`Zoom out`}),t[5]=y,t[6]=b):(y=t[5],b=t[6]);let x;t[7]===u?x=t[8]:(x=(0,$.jsx)(L,{asChild:!0,children:(0,$.jsxs)(s,{variant:`ghost`,size:`icon-xs`,onClick:u,children:[y,b]})}),t[7]=u,t[8]=x);let S;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(S=(0,$.jsx)(H,{children:`Zoom out`}),t[9]=S):S=t[9];let C;t[10]===x?C=t[11]:(C=(0,$.jsxs)(B,{children:[x,S]}),t[10]=x,t[11]=C);let w;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(w=z(W.compact,`min-w-[3rem] px-2 py-1 font-mono text-muted-foreground hover:text-foreground hover:bg-muted rounded transition-colors`),t[12]=w):w=t[12];let T;t[13]===i?T=t[14]:(T=Math.round(i*100),t[13]=i,t[14]=T);let E;t[15]!==d||t[16]!==T?(E=(0,$.jsx)(L,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,onClick:d,className:w,children:[T,`%`]})}),t[15]=d,t[16]=T,t[17]=E):E=t[17];let O;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(O=(0,$.jsx)(H,{children:`Reset zoom`}),t[18]=O):O=t[18];let k;t[19]===E?k=t[20]:(k=(0,$.jsxs)(B,{children:[E,O]}),t[19]=E,t[20]=k);let A,j;t[21]===Symbol.for(`react.memo_cache_sentinel`)?(A=(0,$.jsx)(sn,{className:`h-3.5 w-3.5`}),j=(0,$.jsx)(`span`,{className:`sr-only`,children:`Zoom in`}),t[21]=A,t[22]=j):(A=t[21],j=t[22]);let M;t[23]===l?M=t[24]:(M=(0,$.jsx)(L,{asChild:!0,children:(0,$.jsxs)(s,{variant:`ghost`,size:`icon-xs`,onClick:l,children:[A,j]})}),t[23]=l,t[24]=M);let N;t[25]===Symbol.for(`react.memo_cache_sentinel`)?(N=(0,$.jsx)(H,{children:`Zoom in`}),t[25]=N):N=t[25];let P;t[26]===M?P=t[27]:(P=(0,$.jsxs)(B,{children:[M,N]}),t[26]=M,t[27]=P);let F,I;t[28]===Symbol.for(`react.memo_cache_sentinel`)?(F=(0,$.jsx)(Fe,{className:`h-3.5 w-3.5`}),I=(0,$.jsx)(`span`,{className:`sr-only`,children:`Reset view`}),t[28]=F,t[29]=I):(F=t[28],I=t[29]);let ee;t[30]===d?ee=t[31]:(ee=(0,$.jsx)(L,{asChild:!0,children:(0,$.jsxs)(s,{variant:`ghost`,size:`icon-xs`,onClick:d,children:[F,I]})}),t[30]=d,t[31]=ee);let te;t[32]===Symbol.for(`react.memo_cache_sentinel`)?(te=(0,$.jsx)(H,{children:`Reset view`}),t[32]=te):te=t[32];let R;t[33]===ee?R=t[34]:(R=(0,$.jsxs)(B,{children:[ee,te]}),t[33]=ee,t[34]=R);let ne;t[35]===Symbol.for(`react.memo_cache_sentinel`)?(ne=(0,$.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),t[35]=ne):ne=t[35];let re,ie;t[36]===Symbol.for(`react.memo_cache_sentinel`)?(re=(0,$.jsx)(zn,{className:`h-3.5 w-3.5`}),ie=(0,$.jsx)(`span`,{className:`sr-only`,children:`Close`}),t[36]=re,t[37]=ie):(re=t[36],ie=t[37]);let ae;t[38]===r?ae=t[39]:(ae=(0,$.jsx)(L,{asChild:!0,children:(0,$.jsxs)(s,{variant:`ghost`,size:`icon-xs`,onClick:r,children:[re,ie]})}),t[38]=r,t[39]=ae);let oe;t[40]===Symbol.for(`react.memo_cache_sentinel`)?(oe=(0,$.jsx)(H,{children:`Close (Esc)`}),t[40]=oe):oe=t[40];let se;t[41]===ae?se=t[42]:(se=(0,$.jsxs)(B,{children:[ae,oe]}),t[41]=ae,t[42]=se);let ce;t[43]!==k||t[44]!==P||t[45]!==R||t[46]!==se||t[47]!==C?(ce=(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 bg-background/90 border-b border-border shrink-0`,children:[v,(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[C,k,P,R,ne,se]})]}),t[43]=k,t[44]=P,t[45]=R,t[46]=se,t[47]=C,t[48]=ce):ce=t[48];let le=o?`cursor-grabbing`:`cursor-grab`,ue;t[49]===le?ue=t[50]:(ue=z(`flex-1 overflow-hidden select-none`,le),t[49]=le,t[50]=ue);let de=`translate(${a.x}px, ${a.y}px) scale(${i})`,fe=o?`none`:`transform 0.1s ease-out`,pe;t[51]!==de||t[52]!==fe?(pe={transform:de,transformOrigin:`center center`,transition:fe},t[51]=de,t[52]=fe,t[53]=pe):pe=t[53];let V;t[54]===n?V=t[55]:(V={__html:n},t[54]=n,t[55]=V);let me;t[56]!==pe||t[57]!==V?(me=(0,$.jsx)(`div`,{className:`w-full h-full flex items-center justify-center`,style:pe,dangerouslySetInnerHTML:V}),t[56]=pe,t[57]=V,t[58]=me):me=t[58];let he;t[59]!==c||t[60]!==f||t[61]!==p||t[62]!==m||t[63]!==ue||t[64]!==me?(he=(0,$.jsx)(`div`,{ref:c,className:ue,onMouseDown:f,onMouseMove:p,onMouseUp:m,onMouseLeave:m,children:me}),t[59]=c,t[60]=f,t[61]=p,t[62]=m,t[63]=ue,t[64]=me,t[65]=he):he=t[65];let ge;t[66]===Symbol.for(`react.memo_cache_sentinel`)?(ge=(0,$.jsx)(`div`,{className:z(W.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]=ge):ge=t[66];let _e;return t[67]!==ce||t[68]!==he?(_e=(0,ho.createPortal)((0,$.jsx)(D,{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:[ce,he,ge]})}),document.body),t[67]=ce,t[68]=he,t[69]=_e):_e=t[69],_e}function Ao(){return document.body.style.overflow=`hidden`,jo}function jo(){document.body.style.overflow=``}function Mo(e){let t=e.trim();if(t.startsWith(`/`)){let e=Ke().replace(/\/$/,``);return i(`${e}${t}`,e)}return i(t,Ke())}function No(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(xe(e.hostname))return!0;let n=new URL(Ke());return e.origin===n.origin&&e.pathname.startsWith(`/api/`)}catch{return!1}}function Po(e){let t=e.trim();return!t||t.startsWith(`mailto:`)||t.startsWith(`tel:`)?!1:Ve()?/^https?:\/\//i.test(t)||t.startsWith(`/api/`):No(t)}function Fo(e){let t=Mo(e);return at()&&!Ve()?(window.open(t,`_blank`,`noopener,noreferrer`),Promise.resolve()):kt(t)}function Io(e){return!!(xe(e.hostname)||typeof window<`u`&&e.origin===window.location.origin)}function Lo(e){return decodeURIComponent(e.replace(/^\/+/,``))}function Ro(e){let t=e.trim();if(!t||t.includes(`
|
|
6
|
-
`))return null;let n=Le(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 zo(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(!Io(e))return null;r=Lo(e.pathname)}else r=Lo(n);let i=Le(r);return!i||t&&i!==t?null:{path:r,kind:i}}function Bo(e,t){return Mo(`/api/threads/${encodeURIComponent(e)}/explorer/media?path=${encodeURIComponent(t)}`)}function Vo(e){if(!e.startsWith(`/`))return!1;let t=e.split(`/`)[1]??``;return[`Users`,`tmp`,`var`,`private`,`Volumes`,`home`].includes(t)}function Ho(e,t){if(!e||e.startsWith(`data:`))return e;if(t){if(Vo(e)&&Le(e))return Bo(t,e);let n=zo(e);if(n)return Bo(t,n.path)}return e.startsWith(`/`)?Mo(e):i(e,Ke())}function Uo(e,t){return Ho(e,t)}var Wo=ei(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`]}),Go=function(e){let t=(0,X.c)(32),{imageUrl:n,imageData:r,alt:i,threadId:a}=e,o=i===void 0?`Generated image`:i,[s,c]=(0,Y.useState)(!1),l;t[0]!==r||t[1]!==n||t[2]!==a?(l=r?`data:image/png;base64,${r}`:Uo(n??``,a),t[0]=r,t[1]=n,t[2]=a,t[3]=l):l=t[3];let u=l,f;t[4]===u?f=t[5]:(f=async()=>{let e=Xe(u)??`generated-image-${Date.now()}.png`,{path:t}=await Tt(u.startsWith(`data:`)?{imageData:u.replace(/^data:[^;]+;base64,/,``),filename:e}:{imageUrl:u,filename:e});Qa({title:`Saved to downloads: ${t.split(`/`).pop()}`})},t[4]=u,t[5]=f);let p=f,m;t[6]===u?m=t[7]:(m=async()=>{await st(u.startsWith(`data:`)?{imageData:u.replace(/^data:[^;]+;base64,/,``)}:{imageUrl:u}),c(!0),setTimeout(()=>c(!1),2e3)},t[6]=u,t[7]=m);let h=m;if(!u)return null;let g;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(g={maxHeight:`512px`},t[8]=g):g=t[8];let _;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(_=(0,$.jsx)(ee,{className:`h-3.5 w-3.5`}),t[9]=_):_=t[9];let v;t[10]===p?v=t[11]:(v=(0,$.jsx)(L,{asChild:!0,children:(0,$.jsx)(`button`,{onClick:p,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[10]=p,t[11]=v);let y;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(y=(0,$.jsx)(H,{children:`Save image`}),t[12]=y):y=t[12];let b;t[13]===v?b=t[14]:(b=(0,$.jsxs)(B,{children:[v,y]}),t[13]=v,t[14]=b);let x;t[15]===s?x=t[16]:(x=s?(0,$.jsx)(Ze,{className:`h-3.5 w-3.5 text-green-500`}):(0,$.jsx)(d,{className:`h-3.5 w-3.5`}),t[15]=s,t[16]=x);let S;t[17]!==h||t[18]!==x?(S=(0,$.jsx)(L,{asChild:!0,children:(0,$.jsx)(`button`,{onClick:h,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:x})}),t[17]=h,t[18]=x,t[19]=S):S=t[19];let C=s?`Copied!`:`Copy to clipboard`,w;t[20]===C?w=t[21]:(w=(0,$.jsx)(H,{children:C}),t[20]=C,t[21]=w);let T;t[22]!==S||t[23]!==w?(T=(0,$.jsxs)(B,{children:[S,w]}),t[22]=S,t[23]=w,t[24]=T):T=t[24];let E;t[25]!==T||t[26]!==b?(E=(0,$.jsxs)(D,{children:[b,T]}),t[25]=T,t[26]=b,t[27]=E):E=t[27];let O;return t[28]!==o||t[29]!==u||t[30]!==E?(O=(0,$.jsx)(Wo,{v0:u,v1:o,v2:g,v3:E}),t[28]=o,t[29]=u,t[30]=E,t[31]=O):O=t[31],O};function Ko(e){let t=_t(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 qo(e,t){let n=Ko(e)??Ko(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}}function Jo(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 Yo(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 Xo(e){console.error(`[chat-media] 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:Jo(e.mediaError)}:void 0,probeResult:e.probeResult})}function Zo(e,t,n,r){let[i,a]=(0,Y.useState)({objectUrl:null,loadError:null,loading:!1});return(0,Y.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 Yo(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 Yo(e);Xo({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 Qo(e){let t=(0,X.c)(44),{src:n,label:r}=e,[i,a]=(0,Y.useState)(!1),[o,s]=(0,Y.useState)(!1),c=(0,Y.useRef)(null),{objectUrl:l,loadError:u,loading:d}=Zo(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($o)},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;Xo({kind:`video`,src:n,label:r,mediaError:t,probeResult:await Yo(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)(R,{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=z(`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)(vt,{className:`sr-only`,children:v}),t[11]=v,t[12]=T);let E;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(E=(0,$.jsx)(Qe,{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)(it,{className:`h-4 w-4`}):(0,$.jsx)(Ht,{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)(qe,{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)(zn,{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=z(`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:z(W.compact,`text-white/80`),children:`Loading video...`}):u?(0,$.jsxs)(`p`,{className:z(W.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:z(`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)(We,{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 ee;t[38]!==i||t[39]!==I?(ee=(0,$.jsx)(ie,{open:i,onOpenChange:p,children:I}),t[38]=i,t[39]=I,t[40]=ee):ee=t[40];let L;return t[41]!==ee||t[42]!==S?(L=(0,$.jsxs)($.Fragment,{children:[S,ee]}),t[41]=ee,t[42]=S,t[43]=L):L=t[43],L}function $o(e){return!e}function es(e){let t=(0,X.c)(12),{src:n,label:r}=e,{objectUrl:i,loadError:a,loading:o}=Zo(n,!0,`audio`,r),s;t[0]!==r||t[1]!==n?(s=async function(e){let t=e.currentTarget.error;Xo({kind:`audio`,src:n,label:r,mediaError:t,probeResult:await Yo(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:z(W.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:z(W.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 ts(e){let t=(0,X.c)(13),{src:n,kind:r,label:i}=e;if(!n)return null;let a=r===`video`?l:It,o=r===`video`?`p-2`:`p-3`,s;t[0]===o?s=t[1]:(s=z(`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:z(W.compact,`truncate`),children:i})]}):null,t[2]=a,t[3]=i,t[4]=c):c=t[4];let u;t[5]!==r||t[6]!==i||t[7]!==n?(u=r===`video`?(0,$.jsx)(Qo,{src:n,label:i}):(0,$.jsx)(es,{src:n,label:i}),t[5]=r,t[6]=i,t[7]=n,t[8]=u):u=t[8];let d;return t[9]!==s||t[10]!==c||t[11]!==u?(d=(0,$.jsxs)(`div`,{className:s,children:[c,u]}),t[9]=s,t[10]=c,t[11]=u,t[12]=d):d=t[12],d}var ns=`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(`.`),rs=[/-->/,/--\./,/-\./,/==>/,/--\|/,/\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 is(e){if(!e||typeof e!=`string`)return!1;let t=e.split(`
|
|
7
|
-
`).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(ns.some(e=>n===e.toLowerCase()||n.startsWith(e.toLowerCase()+` `)))return!0;let r=0;for(let t of rs)t.test(e)&&r++;return r>=2}function as(e){if(!is(e))return null;let t=/```mermaid\s*\n([\s\S]*?)\n```/.exec(e);if(t)return t[1].trim();let n=e.split(`
|
|
8
|
-
`).map(e=>e.trim()).filter(e=>e.length>0)[0].toLowerCase();return ns.some(e=>n===e.toLowerCase()||n.startsWith(e.toLowerCase()+` `))?e.trim():null}function os(e){let t=(0,X.c)(14),{href:n,children:r}=e,i;t[0]===n?i=t[1]:(i=Mo(n),t[0]=n,t[1]=i);let a=i,o;t[2]===n?o=t[3]:(o=Po(n),t[2]=n,t[3]=o);let s=o,c;t[4]!==n||t[5]!==s?(c=function(e){s&&(e.preventDefault(),Fo(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 ss=ei(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`]}),cs=function(e){let t=(0,X.c)(19),{language:n,code:r,compact:i}=e,a=i===void 0?!1:i,[o,c]=(0,Y.useState)(!1),l;t[0]===r?l=t[1]:(l=async()=>{await navigator.clipboard.writeText(r),c(!0),setTimeout(()=>c(!1),2e3)},t[0]=r,t[1]=l);let u=l,f;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(f=z(W.compact,`text-muted-foreground font-mono`),t[2]=f):f=t[2];let p=n||`text`,m;t[3]===o?m=t[4]:(m=o?(0,$.jsx)(Ze,{}):(0,$.jsx)(d,{}),t[3]=o,t[4]=m);let h;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,$.jsx)(`span`,{className:`sr-only`,children:`Copy code`}),t[5]=h):h=t[5];let g;t[6]!==u||t[7]!==m?(g=(0,$.jsxs)(s,{variant:`action`,size:`icon-xs`,onClick:u,children:[m,h]}),t[6]=u,t[7]=m,t[8]=g):g=t[8];let _=a?`p-2`:`p-4`,v;t[9]===_?v=t[10]:(v=z(`overflow-x-auto max-w-full`,_),t[9]=_,t[10]=v);let y;t[11]===a?y=t[12]:(y=z(a?z(W.compact,`font-mono`):W.mono,`text-foreground leading-relaxed`),t[11]=a,t[12]=y);let b;return t[13]!==r||t[14]!==y||t[15]!==p||t[16]!==g||t[17]!==v?(b=(0,$.jsx)(ss,{v0:f,v1:p,v2:g,v3:v,v4:y,v5:r}),t[13]=r,t[14]=y,t[15]=p,t[16]=g,t[17]=v,t[18]=b):b=t[18],b},ls=(0,Y.memo)(function({content:e,className:t,enableMermaid:n=!1,threadId:r,compact:i=!1}){let a=(0,Y.useMemo)(()=>!e||typeof e!=`string`?[]:ms(e,n),[e,n]),o=(0,Y.useMemo)(()=>{let e=0;return a.map(t=>{if(t.type===`list`&&t.ordered){let n=e+1;return e+=t.items.length,n}else if(t.type===`list`&&!t.ordered)return 1;else return e=0,1})},[a]);return a.length===0?null:(0,$.jsx)(`div`,{className:z(`prose-custom min-w-0 break-words`,t),children:a.map((e,t)=>(0,$.jsx)(`div`,{className:ps(t,a,i),children:(0,$.jsx)(Ds,{block:e,start:o[t],threadId:r,compact:i})},t))})}),us=/^!\[([^\]]*)\]\(([^)]+)\)\s*$/;function ds(e){let t=e.match(us);return t?{alt:t[1],src:t[2]}:null}function fs(e,t){let n=e?`mt-0 space-y-0.5`:`mt-0 space-y-1`;return t?z(n,`pl-6`):z(n,`ml-[3.8rem]`,`list-outside overflow-visible list-disc`)}function ps(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 ms(e,t=!1){let n=e.split(`
|
|
9
|
-
`),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`||is(o.join(`
|
|
10
|
-
`)))?r.push({type:`mermaid`,code:o.join(`
|
|
11
|
-
`)}):r.push({type:`code`,language:a,code:o.join(`
|
|
12
|
-
`)}),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(`
|
|
13
|
-
`)});continue}if(/^\s*[-*+]\s/.test(e)){let e=[];for(;i<n.length&&/^\s*[-*+]\s/.test(n[i]);)e.push(n[i].replace(/^\s*[-*+]\s/,``)),i++;r.push({type:`list`,ordered:!1,items:e});continue}if(/^\s*\d+\.\s/.test(e)){let e=[];for(;i<n.length&&/^\s*\d+\.\s/.test(n[i]);)e.push(n[i].replace(/^\s*\d+\.\s/,``)),i++;r.push({type:`list`,ordered:!0,items:e});continue}if(e.trim()===``){i++;continue}let o=ds(e);if(o){r.push({type:`image`,...o}),i++;continue}let s=Ro(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*[-*+]\s/.test(n[i])&&!/^\s*\d+\.\s/.test(n[i]);)c.push(n[i]),i++;if(c.length>0){let e=c.join(`
|
|
14
|
-
`);if(t&&is(e)){let t=as(e);t?r.push({type:`mermaid`,code:t}):r.push({type:`paragraph`,text:e})}else r.push({type:`paragraph`,text:e})}}return r}var hs=ei(e=>e.v0,{name:`MarkdownBlock_2`,portals:[`v0`]}),gs=ei(e=>e.v0,{name:`MarkdownBlock_3`,portals:[`v0`]}),_s=ei(e=>(0,$.jsx)(`blockquote`,{className:e.v0,children:e.v1}),{name:`MarkdownBlock_4`,portals:[`v1`]}),vs=ei(e=>(0,$.jsx)(`ol`,{className:e.v0,children:e.v1}),{name:`MarkdownBlock_5`,portals:[`v1`]}),ys=ei(e=>(0,$.jsx)(`ul`,{className:e.v0,children:e.v1}),{name:`MarkdownBlock_6`,portals:[`v1`]}),bs=ei(e=>(0,$.jsx)(`p`,{className:e.v0,children:e.v1}),{name:`MarkdownBlock_7`,portals:[`v1`]}),xs=ei(()=>(0,$.jsx)(`hr`,{className:`border-border`}),{name:`MarkdownBlock_8`}),Ss=ei(e=>(0,$.jsx)(`div`,{className:`overflow-x-auto rounded-md border border-border max-w-full`,children:(0,$.jsxs)(`table`,{className:e.v0,children:[(0,$.jsx)(`thead`,{children:(0,$.jsx)(`tr`,{className:`border-b border-border bg-muted/50`,children:e.v1})}),(0,$.jsx)(`tbody`,{children:e.v2})]})}),{name:`MarkdownBlock_9`,portals:[`v1`,`v2`]}),Cs=ei(e=>e.v0,{name:`MarkdownBlock_10`,portals:[`v0`]}),ws=ei(e=>e.v0,{name:`MarkdownBlock_11`,portals:[`v0`]}),Ts=ei(e=>e.v0,{name:`MarkdownBlock_12`,portals:[`v0`]}),Es=ei(e=>e.v0,{name:`MarkdownBlock_13`,portals:[`v0`]}),Ds=(0,Y.memo)(function(e){let t=(0,X.c)(111),{block:n,start:r,threadId:i,compact:a}=e,o=r===void 0?1:r,s=a===void 0?!1:a,c=s?W.caption:W.body,l;t[0]===s?l=t[1]:(l=s?z(W.compact,`font-mono`):W.mono,t[0]=s,t[1]=l);let u=l;switch(n.type){case`heading`:{let e=`h${n.level}`,r,a,o;if(t[2]!==e||t[3]!==n.level||t[4]!==s){let i=s?{1:z(W.caption,`font-semibold`),2:z(W.caption,`font-semibold`),3:z(W.body,`font-semibold`),4:z(W.body,`font-semibold`),5:z(W.compact,`font-semibold`),6:z(W.compact,`font-semibold`)}:{1:W.sectionTitle,2:W.subSectionTitle,3:W.subSectionTitle,4:W.subSectionTitle,5:W.sectionSubtitle,6:W.sectionSubtitle};a=hs,r=e,o=z(i[n.level]),t[2]=e,t[3]=n.level,t[4]=s,t[5]=r,t[6]=a,t[7]=o}else r=t[5],a=t[6],o=t[7];let c;t[8]!==n.text||t[9]!==u||t[10]!==i?(c=(0,$.jsx)(Os,{text:n.text,threadId:i,inlineCodeClass:u}),t[8]=n.text,t[9]=u,t[10]=i,t[11]=c):c=t[11];let l;t[12]!==r||t[13]!==o||t[14]!==c?(l=(0,$.jsx)(r,{className:o,children:c}),t[12]=r,t[13]=o,t[14]=c,t[15]=l):l=t[15];let d;return t[16]!==a||t[17]!==l?(d=(0,$.jsx)(a,{v0:l}),t[16]=a,t[17]=l,t[18]=d):d=t[18],d}case`code`:{let e;return t[19]!==n.code||t[20]!==n.language||t[21]!==s?(e=(0,$.jsx)(gs,{v0:(0,$.jsx)(cs,{language:n.language,code:n.code,compact:s})}),t[19]=n.code,t[20]=n.language,t[21]=s,t[22]=e):e=t[22],e}case`blockquote`:{let e;t[23]===c?e=t[24]:(e=z(c,`border-l-2 border-border pl-4 text-muted-foreground italic`),t[23]=c,t[24]=e);let r;t[25]!==n.text||t[26]!==u||t[27]!==i?(r=(0,$.jsx)(Os,{text:n.text,threadId:i,inlineCodeClass:u}),t[25]=n.text,t[26]=u,t[27]=i,t[28]=r):r=t[28];let a;return t[29]!==e||t[30]!==r?(a=(0,$.jsx)(_s,{v0:e,v1:r}),t[29]=e,t[30]=r,t[31]=a):a=t[31],a}case`list`:{let e,r,a;if(t[32]!==n.items||t[33]!==n.ordered||t[34]!==c||t[35]!==s||t[36]!==u||t[37]!==o||t[38]!==i){a=Symbol.for(`react.early_return_sentinel`);bb0:{let l=fs(s,n.ordered);if(n.ordered){let e=z(c,l),r;if(t[42]!==n.items||t[43]!==u||t[44]!==o||t[45]!==i){let e;t[47]!==u||t[48]!==o||t[49]!==i?(e=(e,t)=>(0,$.jsxs)(`li`,{className:`flex gap-1.5`,children:[(0,$.jsxs)(`span`,{className:`shrink-0 select-none tabular-nums`,children:[o+t,`.`]}),(0,$.jsx)(`span`,{children:(0,$.jsx)(Os,{text:e,threadId:i,inlineCodeClass:u})})]},t),t[47]=u,t[48]=o,t[49]=i,t[50]=e):e=t[50],r=n.items.map(e),t[42]=n.items,t[43]=u,t[44]=o,t[45]=i,t[46]=r}else r=t[46];a=(0,$.jsx)(vs,{v0:e,v1:r});break bb0}e=ys,r=z(c,l)}t[32]=n.items,t[33]=n.ordered,t[34]=c,t[35]=s,t[36]=u,t[37]=o,t[38]=i,t[39]=e,t[40]=r,t[41]=a}else e=t[39],r=t[40],a=t[41];if(a!==Symbol.for(`react.early_return_sentinel`))return a;let l;if(t[51]!==n.items||t[52]!==u||t[53]!==i){let e;t[55]!==u||t[56]!==i?(e=(e,t)=>(0,$.jsx)(`li`,{children:(0,$.jsx)(Os,{text:e,threadId:i,inlineCodeClass:u})},t),t[55]=u,t[56]=i,t[57]=e):e=t[57],l=n.items.map(e),t[51]=n.items,t[52]=u,t[53]=i,t[54]=l}else l=t[54];let d;return t[58]!==e||t[59]!==r||t[60]!==l?(d=(0,$.jsx)(e,{v0:r,v1:l}),t[58]=e,t[59]=r,t[60]=l,t[61]=d):d=t[61],d}case`paragraph`:{let e;t[62]===c?e=t[63]:(e=z(c,`mt-0 leading-relaxed whitespace-pre-wrap break-words`),t[62]=c,t[63]=e);let r;t[64]!==n.text||t[65]!==u||t[66]!==i?(r=(0,$.jsx)(Os,{text:n.text,threadId:i,inlineCodeClass:u}),t[64]=n.text,t[65]=u,t[66]=i,t[67]=r):r=t[67];let a;return t[68]!==e||t[69]!==r?(a=(0,$.jsx)(bs,{v0:e,v1:r}),t[68]=e,t[69]=r,t[70]=a):a=t[70],a}case`hr`:{let e;return t[71]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(xs,{}),t[71]=e):e=t[71],e}case`table`:{let e;t[72]===c?e=t[73]:(e=z(c,`w-full`),t[72]=c,t[73]=e);let r;if(t[74]!==n.headers||t[75]!==u||t[76]!==i){let e;t[78]!==u||t[79]!==i?(e=(e,t)=>(0,$.jsx)(`th`,{className:`px-3 py-2 text-left font-medium`,children:(0,$.jsx)(Os,{text:e,threadId:i,inlineCodeClass:u})},t),t[78]=u,t[79]=i,t[80]=e):e=t[80],r=n.headers.map(e),t[74]=n.headers,t[75]=u,t[76]=i,t[77]=r}else r=t[77];let a;if(t[81]!==n.rows||t[82]!==u||t[83]!==i){let e;t[85]!==u||t[86]!==i?(e=(e,t)=>(0,$.jsx)(`tr`,{className:`border-b border-border last:border-0`,children:e.map((e,t)=>(0,$.jsx)(`td`,{className:`px-3 py-2`,children:(0,$.jsx)(Os,{text:e,threadId:i,inlineCodeClass:u})},t))},t),t[85]=u,t[86]=i,t[87]=e):e=t[87],a=n.rows.map(e),t[81]=n.rows,t[82]=u,t[83]=i,t[84]=a}else a=t[84];let o;return t[88]!==e||t[89]!==r||t[90]!==a?(o=(0,$.jsx)(Ss,{v0:e,v1:r,v2:a}),t[88]=e,t[89]=r,t[90]=a,t[91]=o):o=t[91],o}case`mermaid`:{let e;return t[92]===n.code?e=t[93]:(e=(0,$.jsx)(Cs,{v0:(0,$.jsx)(Eo,{content:n.code})}),t[92]=n.code,t[93]=e),e}case`image`:{let e;t[94]!==n.src||t[95]!==i?(e=Uo(n.src,i),t[94]=n.src,t[95]=i,t[96]=e):e=t[96];let r=n.alt||`Image`,a;return t[97]!==e||t[98]!==r?(a=(0,$.jsx)(ws,{v0:(0,$.jsx)(Go,{imageUrl:e,alt:r})}),t[97]=e,t[98]=r,t[99]=a):a=t[99],a}case`media`:{let e;t[100]!==n.src||t[101]!==i?(e=Ho(n.src,i),t[100]=n.src,t[101]=i,t[102]=e):e=t[102];let r=e;if(n.kind===`image`){let e;return t[103]===r?e=t[104]:(e=(0,$.jsx)(Ts,{v0:(0,$.jsx)(Go,{imageUrl:r,alt:`Image`})}),t[103]=r,t[104]=e),e}let a;t[105]===n.src?a=t[106]:(a=n.src.split(/[/\\]/).pop(),t[105]=n.src,t[106]=a);let o=a,s;return t[107]!==n.kind||t[108]!==o||t[109]!==r?(s=(0,$.jsx)(Es,{v0:(0,$.jsx)(ts,{src:r,kind:n.kind,label:o})}),t[107]=n.kind,t[108]=o,t[109]=r,t[110]=s):s=t[110],s}default:return null}}),Os=(0,Y.memo)(function(e){let t=(0,X.c)(11),{text:n,threadId:r,inlineCodeClass:i}=e,a=i===void 0?W.mono:i,o;t[0]===n?o=t[1]:(o=ks(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:z(a,`rounded bg-muted/20 py-0.5`),children:e.text},t);case`link`:return(0,$.jsx)(os,{href:e.href,children:e.text},t);case`image`:return(0,$.jsx)(Go,{imageUrl:Uo(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 ks(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(`**`))t.push({type:`bold`,text:n.slice(2,-2)});else if(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 As(e){return e.split(/[/\\]/).pop()||void 0}var js=(0,Y.memo)(function(e){let t=(0,X.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=Ro(n),t[0]=n,t[1]=s);let c=s;if(c){let e;t[2]!==c.src||t[3]!==r?(e=Ho(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)(Go,{imageUrl:n,alt:`Image`}),t[5]=n,t[6]=e),e}let i=c.kind,a;t[7]===c.src?a=t[8]:(a=As(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)(ts,{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=ra(n),t[13]=n,t[14]=l);let u=i??W.body,d;return t[15]!==o||t[16]!==l||t[17]!==u||t[18]!==r?(d=(0,$.jsx)(ls,{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 Ms(e){return`data:${e.mimeType};base64,${e.content}`}function Ns(e){return e.mimeType.startsWith(`image/`)?`image`:e.mimeType.startsWith(`video/`)?`video`:e.mimeType.startsWith(`audio/`)?`audio`:Le(e.fileName)||`file`}function Ps(e){let t=(0,X.c)(6),{icon:n,label:r}=e,i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=z(W.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 Fs(e){let t=(0,X.c)(14),{attachment:n}=e,i=Ns(n),a;t[0]===n?a=t[1]:(a=Ms(n),t[0]=n,t[1]=a);let o=a;if(i===`image`){let e;return t[2]!==n.fileName||t[3]!==o?(e=(0,$.jsx)(`div`,{className:`mt-1 max-w-full overflow-hidden rounded-lg border border-border bg-background`,children:(0,$.jsx)(`img`,{src:o,alt:n.fileName,className:`block max-h-80 max-w-full object-contain`})}),t[2]=n.fileName,t[3]=o,t[4]=e):e=t[4],e}if(i===`video`){let e;return t[5]!==n.fileName||t[6]!==o?(e=(0,$.jsx)(ts,{src:o,kind:`video`,label:n.fileName}),t[5]=n.fileName,t[6]=o,t[7]=e):e=t[7],e}if(i===`audio`){let e;return t[8]!==n.fileName||t[9]!==o?(e=(0,$.jsx)(ts,{src:o,kind:`audio`,label:n.fileName}),t[8]=n.fileName,t[9]=o,t[10]=e):e=t[10],e}let s;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(s=(0,$.jsx)(r,{className:`h-2.5 w-2.5`}),t[11]=s):s=t[11];let c;return t[12]===n.fileName?c=t[13]:(c=(0,$.jsx)(Ps,{icon:s,label:n.fileName}),t[12]=n.fileName,t[13]=c),c}function Is(e){let t=(0,X.c)(4),{attachments:n}=e,r;t[0]===n?r=t[1]:(r=n.map(Ls),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 Ls(e){let t=Ns(e),n=`${e.fileName}:${e.mimeType}`;return t===`file`?(0,$.jsx)(Fs,{attachment:e},n):(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsx)(Ps,{icon:t===`audio`?(0,$.jsx)(It,{className:`h-2.5 w-2.5`}):t===`video`?(0,$.jsx)(l,{className:`h-2.5 w-2.5`}):(0,$.jsx)(r,{className:`h-2.5 w-2.5`}),label:e.fileName}),(0,$.jsx)(Fs,{attachment:e})]},n)}function Rs(e){let[t,n]=(0,Y.useState)(!1);async function r(r){if(!(!e||t)){n(!0);try{let t=await rn(e,r);t.success?Qa({title:`Checkpoint restored`,description:`Working tree restored to before this agent run.`}):Qa({title:`Restore failed`,description:t.error??`Could not restore checkpoint.`,variant:`destructive`})}catch(e){Qa({title:`Restore failed`,description:e instanceof Error?e.message:`Unknown error`,variant:`destructive`})}finally{n(!1)}}}return{isRestoring:t,restore:r}}function zs(e){let t=(0,X.c)(7),n=e===void 0?2e3:e,[r,i]=(0,Y.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,Y.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 Bs(e){let t=(0,X.c)(39),{message:n,threadId:r,showCheckpointRestore:i,checkpointRestoreTooltip:a}=e,o=i===void 0?!1:i,s=n.sender===`user`,{isRestoring:c,restore:l}=Rs(r),{copied:u,markCopied:f}=zs(),p=s&&(o||!!a),m;t[0]===n.timestamp?m=t[1]:(m=n.timestamp?new Date(n.timestamp).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`}):``,t[0]=n.timestamp,t[1]=m);let h=m,g;t[2]!==n.checkpointRef||t[3]!==l||t[4]!==o?(g=async function(){!n.checkpointRef||!o||await l(n.checkpointRef)},t[2]=n.checkpointRef,t[3]=l,t[4]=o,t[5]=g):g=t[5];let v=g,y;t[6]!==f||t[7]!==n.content?(y=async function(){try{await navigator.clipboard.writeText(n.content),f()}catch(e){let t=e;Qa({title:`Copy failed`,description:t instanceof Error?t.message:`Could not copy prompt.`,variant:`destructive`})}},t[6]=f,t[7]=n.content,t[8]=y):y=t[8];let b=y,x=s&&`flex-row-reverse`,S;t[9]===x?S=t[10]:(S=z(`flex items-center gap-2`,x),t[9]=x,t[10]=S);let C;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(C=z(W.compact,`font-medium text-foreground`),t[11]=C):C=t[11];let w=s?`You`:`Agent`,T;t[12]===w?T=t[13]:(T=(0,$.jsx)(`span`,{className:C,children:w}),t[12]=w,t[13]=T);let E;t[14]!==a||t[15]!==b||t[16]!==v||t[17]!==u||t[18]!==c||t[19]!==s||t[20]!==p||t[21]!==o?(E=s&&(0,$.jsx)(D,{children:(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity`,children:[(0,$.jsxs)(B,{children:[(0,$.jsx)(L,{asChild:!0,children:(0,$.jsx)(`span`,{tabIndex:0,className:`inline-flex`,children:(0,$.jsx)(`button`,{onClick:b,"aria-label":u?`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:u?(0,$.jsx)(Ze,{className:`h-3 w-3 text-green-500`}):(0,$.jsx)(d,{className:`h-3 w-3`})})})}),(0,$.jsx)(H,{side:`left`,children:u?`Copied prompt`:`Copy prompt`})]}),p&&(0,$.jsxs)(B,{children:[(0,$.jsx)(L,{asChild:!0,children:(0,$.jsx)(`span`,{tabIndex:0,className:`inline-flex`,children:(0,$.jsx)(`button`,{onClick:o?v:void 0,disabled:!o||c,"aria-label":a??`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)(Fe,{className:z(`h-3 w-3`,c&&`animate-spin`)})})})}),(0,$.jsx)(H,{side:`left`,children:a??`Restore checkpoint`})]})]})}),t[14]=a,t[15]=b,t[16]=v,t[17]=u,t[18]=c,t[19]=s,t[20]=p,t[21]=o,t[22]=E):E=t[22];let O;t[23]===h?O=t[24]:(O=h&&(0,$.jsxs)(`span`,{className:z(W.compact,`flex items-center gap-1 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity`),children:[(0,$.jsx)(Re,{className:`h-2.5 w-2.5`}),h]}),t[23]=h,t[24]=O);let k;t[25]===n.model?k=t[26]:(k=n.model&&(0,$.jsxs)(`span`,{className:z(W.compact,`flex items-center gap-1 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity`),children:[(0,$.jsx)(Gn,{className:`h-2.5 w-2.5`}),hi(n.model)]}),t[25]=n.model,t[26]=k);let A;t[27]===n.metadata?A=t[28]:(A=n.metadata?.processingTimeMs&&(0,$.jsxs)(`span`,{className:z(W.compact,`flex items-center gap-1 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity`),children:[(0,$.jsx)(_,{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[27]=n.metadata,t[28]=A);let j;t[29]===n.metadata?j=t[30]:(j=(n.metadata?.tokenCount||n.metadata?.estimatedCost)&&(0,$.jsxs)(`span`,{className:z(W.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?nt(n.metadata.estimatedCost):null]}),t[29]=n.metadata,t[30]=j);let M;return t[31]!==E||t[32]!==O||t[33]!==k||t[34]!==A||t[35]!==j||t[36]!==S||t[37]!==T?(M=(0,$.jsxs)(`div`,{className:S,children:[T,E,O,k,A,j]}),t[31]=E,t[32]=O,t[33]=k,t[34]=A,t[35]=j,t[36]=S,t[37]=T,t[38]=M):M=t[38],M}function Vs(e){let t=(0,X.c)(32),{src:n,threadId:r}=e,{copied:i,markCopied:a}=zs(),o;t[0]!==n||t[1]!==r?(o=n.startsWith(`data:`)?n:Uo(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 Tt(s.startsWith(`data:`)?{imageData:s.replace(/^data:[^;]+;base64,/,``),filename:e}:{imageUrl:s,filename:e});Qa({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 st(s.startsWith(`data:`)?{imageData:s.replace(/^data:[^;]+;base64,/,``)}:{imageUrl:s}),a()},t[5]=s,t[6]=a,t[7]=u):u=t[7];let f=u,p;t[8]===s?p=t[9]:(p=(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]=p);let m;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,$.jsx)(ee,{className:`h-3.5 w-3.5`}),t[10]=m):m=t[10];let h;t[11]===l?h=t[12]:(h=(0,$.jsx)(L,{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:m})}),t[11]=l,t[12]=h);let g;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(g=(0,$.jsx)(H,{children:`Save image`}),t[13]=g):g=t[13];let _;t[14]===h?_=t[15]:(_=(0,$.jsxs)(B,{children:[h,g]}),t[14]=h,t[15]=_);let v;t[16]===i?v=t[17]:(v=i?(0,$.jsx)(Ze,{className:`h-3.5 w-3.5 text-green-500`}):(0,$.jsx)(d,{className:`h-3.5 w-3.5`}),t[16]=i,t[17]=v);let y;t[18]!==f||t[19]!==v?(y=(0,$.jsx)(L,{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:v})}),t[18]=f,t[19]=v,t[20]=y):y=t[20];let b=i?`Copied!`:`Copy to clipboard`,x;t[21]===b?x=t[22]:(x=(0,$.jsx)(H,{children:b}),t[21]=b,t[22]=x);let S;t[23]!==y||t[24]!==x?(S=(0,$.jsxs)(B,{children:[y,x]}),t[23]=y,t[24]=x,t[25]=S):S=t[25];let C;t[26]!==S||t[27]!==_?(C=(0,$.jsx)(`div`,{className:`absolute top-2 right-2 flex gap-1 opacity-0 group-hover/img:opacity-100 transition-opacity`,children:(0,$.jsxs)(D,{children:[_,S]})}),t[26]=S,t[27]=_,t[28]=C):C=t[28];let w;return t[29]!==C||t[30]!==p?(w=(0,$.jsxs)(`div`,{className:`mt-2 relative group/img inline-block max-w-full`,children:[p,C]}),t[29]=C,t[30]=p,t[31]=w):w=t[31],w}var Hs=(0,Y.createContext)(null);function Us(e){let t=(0,X.c)(10),{children:n}=e,[r,i]=(0,Y.useState)(`chat`),[a,o]=(0,Y.useState)(!1),[s,c]=(0,Y.useState)(0),[l,u]=(0,Y.useState)(0),d;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(d=()=>{c(Gs)},t[0]=d):d=t[0];let f=d,p;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(p=()=>{u(Ws)},t[1]=p):p=t[1];let m=p,h;t[2]!==r||t[3]!==s||t[4]!==l||t[5]!==a?(h={activeMainTab:r,setActiveMainTab:i,terminalNotification:a,setTerminalNotification:o,reviewRefreshTick:s,triggerReviewRefresh:f,tasksRefreshTick:l,triggerTasksRefresh:m},t[2]=r,t[3]=s,t[4]=l,t[5]=a,t[6]=h):h=t[6];let g=h,_;return t[7]!==n||t[8]!==g?(_=(0,$.jsx)(Hs.Provider,{value:g,children:n}),t[7]=n,t[8]=g,t[9]=_):_=t[9],_}function Ws(e){return e+1}function Gs(e){return e+1}function Ks(){let e=(0,Y.useContext)(Hs);if(!e)throw Error(`useMainTab must be used within a MainTabProvider`);return e}var qs=(0,Y.createContext)(null);function Js(e){let t=(0,X.c)(8),{children:n}=e,[r,i]=(0,Y.useState)(null),[a,o]=(0,Y.useState)(0),[s,c]=(0,Y.useState)(null),l;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(l=()=>{o(Ys)},t[0]=l):l=t[0];let u=l,d;t[1]!==s||t[2]!==a||t[3]!==r?(d={pendingExplorerPath:r,setPendingExplorerPath:i,explorerRefreshTick:a,triggerExplorerRefresh:u,explorerClearPath:s,setExplorerClearPath:c},t[1]=s,t[2]=a,t[3]=r,t[4]=d):d=t[4];let f=d,p;return t[5]!==n||t[6]!==f?(p=(0,$.jsx)(qs.Provider,{value:f,children:n}),t[5]=n,t[6]=f,t[7]=p):p=t[7],p}function Ys(e){return e+1}function Xs(){let e=(0,Y.useContext)(qs);if(!e)throw Error(`useExplorerTab must be used within an ExplorerTabProvider`);return e}var Zs=new RegExp(String.raw`\x1B\[[0-?]*[ -/]*[@-~]`,`g`),Qs=new RegExp(String.raw`\x1B\].*?(?:\x07|\x1B\\)`,`g`),$s=new RegExp(String.raw`\x1B[@-_]`,`g`),ec=/\r(?!\n)/g,tc=/\\n/g;function nc(e){return e.replace(Qs,``).replace(Zs,``).replace($s,``)}function rc(e){return nc(e).replace(tc,`
|
|
15
|
-
`).replace(ec,`
|
|
16
|
-
`)}function ic(e){return cn(e)}function ac(e,t){let n=e.replace(/\s+/g,` `).trim();return n.length<=t?n:`${n.slice(0,t)}...`}function oc(e){let t=e.replace(/\s+/g,` `).trim();return{fullText:t,label:ac(t,50)}}function sc(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 cc(e){return typeof e==`string`?e:typeof e==`object`&&e?JSON.stringify(e,null,2):String(e)}var lc=32;function uc(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 dc(e,t=lc,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=uc(a,t);e&&i.push(`${n}: ${e}`)}return i.length>0?i.join(`, `):null}function fc(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 pc(e){return typeof e!=`object`||!e||Array.isArray(e)?e:vn(e)}function mc(e){try{return vc(pc(JSON.parse(e)))}catch{return vc(e)}}function hc(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 gc(e){if(typeof e!=`object`||!e)return e;if(Array.isArray(e))return e.map(gc);let t={};for(let[n,r]of Object.entries(e))if(typeof r==`string`){let e=hc(r);t[n]=typeof e==`object`?gc(e):r}else t[n]=gc(r);return t}function _c(e){if(e==null||typeof e!=`string`)return``;let t=e;return t=t.replace(/\\\\n/g,`
|
|
17
|
-
`),t=t.replace(/\\\\"/g,`"`),t=t.replace(/\\n/g,`
|
|
18
|
-
`),t=t.replace(/\\"/g,`"`),t}function vc(e){if(e==null)return``;let t=typeof e==`object`&&e?gc(e):e;return rc(_c(typeof t==`string`?t:t==null?``:JSON.stringify(t,null,2)))}function yc(e,t){let n=e.name??`Unknown Tool`,r=e.id??`unknown`,i=e.input,a=i&&typeof i==`object`?i:null,o=i&&typeof i==`object`&&`description`in i,s=o?i.subagent_type:void 0,c=s==null?null:JSON.stringify(s),l=n===`agent`&&a&&typeof a.agentName==`string`?a.agentName:null,u=o?null:sc(cc(i),t),d=sc(o?String(i.prompt):null,t),f=sc(a&&typeof a.command==`string`?a.command:null,t),p=n===`fetch`&&a&&typeof a.url==`string`?a.url:null,m=a&&typeof a.pattern==`string`?a.pattern:null,h=n===`web_search`&&a&&typeof a.query==`string`?a.query:null,g=a&&typeof a.lang==`string`?a.lang:null,_=n===`code_search`,v=_&&a&&typeof a.query==`string`?a.query:null,y=_&&a&&typeof a.filePath==`string`?a.filePath:null,b=_&&a&&typeof a.fileGlob==`string`?a.fileGlob:null,x=sc(a&&typeof a.path==`string`?a.path:null,t),S=a&&typeof a.offset==`number`?a.offset:null,C=a&&typeof a.limit==`number`?a.limit:null,w=n.toLowerCase(),T=w.includes(`read`)||w.includes(`write`)||w.includes(`edit`),E=w.includes(`edit`),D=T&&a&&typeof a.path==`string`?a.path:null,O=D?D.split(`/`).pop()??D:null,k=E&&a&&typeof a.oldText==`string`?a.oldText:null,A=E&&a&&typeof a.newText==`string`?a.newText:null,j=k===null?null:k.split(`
|
|
19
|
-
`).length,M=A===null?null:A.split(`
|
|
20
|
-
`).length,N=k!==null&&A!==null,P=n===`generate_image`&&a&&typeof a.prompt==`string`?a.prompt:null,F=n===`find_images`&&a&&typeof a.query==`string`?a.query:null,I=n===`todo`&&a?a.status:void 0,ee=e.displayName??cn(n),L=e.activeDisplayName??oe(n),te=`default`;return w===`bash`||w.includes(`terminal`)||w.includes(`shell`)?te=`bash`:w===`fetch`?te=`fetch`:T?te=`file`:_||w===`find`||w===`web_search`||w.includes(`search`)||w.includes(`grep`)?te=`search`:w===`agent`||w.includes(`subagent`)||o?te=`agent`:w===`todo`?te=`todo`:w===`generate_image`?te=`imageGen`:w===`find_images`?te=`findImages`:w===`browser`&&(te=`browser`),{toolType:te,toolName:n,toolId:r,displayName:ee,activeDisplayName:L,inputObj:a,toolInput:u,command:f,fetchUrl:p,pattern:m,webSearchQuery:h,codeSearchQuery:v,codeSearchFilePath:y,codeSearchFileGlob:b,isFileTool:T,isEditTool:E,filePath:D,fileDisplayName:O,editOldText:k,editNewText:A,editDeletedLineCount:j,editAddedLineCount:M,hasEditDiff:N,path:x,offset:S,limit:C,prompt:d,agentName:l,subagentType:c,lang:g,imageGenPrompt:P,findImagesQuery:F,todoStatus:I}}var bc=new Map;function xc(e){return e.trim()}function Sc(){let e=Rn(_n.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[xc(e)]=r);return n}catch{return{}}}function Cc(e){Lt(_n.BASH_COMMAND_DURATIONS,JSON.stringify(e))}function wc(e){return Sc()[xc(e)]??null}function Tc(e,t){let n=xc(e);if(!n||!Number.isFinite(t)||t<=0)return;let r=Sc();r[n]=Math.round(t),Cc(r)}function Ec(e,t){!t?.trim()||bc.has(e)||bc.set(e,{command:xc(t),startedAt:Date.now()})}function Dc(e){let t=bc.get(e);if(!t)return;let n=Date.now()-t.startedAt;Tc(t.command,n),bc.delete(e)}function Oc(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 kc(e,t){return t!==null&&t>0?`${Math.min(99,Math.round(e/t*100))}% complete`:Oc(e)}var Ac=1e3;function jc(e,t,n){let[r,i]=(0,Y.useState)(0),[a,o]=(0,Y.useState)(null),s=(0,Y.useRef)(null),c=(0,Y.useRef)(!1),l=(0,Y.useRef)(n);return l.current=n,(0,Y.useEffect)(()=>{if(n&&!c.current){let n=e?.trim()??``;o(n?wc(n):null),Ec(t,e),s.current=Date.now(),i(0)}else !n&&c.current&&(Dc(t),s.current=null,i(0),o(null));c.current=n},[n,e,t]),(0,Y.useEffect)(()=>()=>{l.current&&Dc(t)},[t]),(0,Y.useEffect)(()=>{if(!n)return;let e=()=>{s.current===null&&(s.current=Date.now()),i(Date.now()-s.current)};e();let t=setInterval(e,Ac);return()=>clearInterval(t)},[n]),n?kc(r,a):null}function Mc(e){let{maxHeight:t=`48`,padding:n=`2`,leading:r=!1,className:i}=e??{};return z(W.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 Nc(e){let t=(0,X.c)(13),{open:n,onOpenChange:r,title:i,content:o,markdown:s,threadId:c}=e,l=s===void 0?!1:s,u;t[0]===i?u=t[1]:(u=(0,$.jsx)(a,{children:(0,$.jsx)(vt,{children:(0,$.jsx)(`code`,{className:W.mono,children:i})})}),t[0]=i,t[1]=u);let d;t[2]!==o||t[3]!==l||t[4]!==c?(d=l?(0,$.jsx)(`div`,{className:z(`flex-1 overflow-auto min-h-0`,W.body),children:(0,$.jsx)(ls,{content:ra(o),threadId:c})}):(0,$.jsx)(`pre`,{className:Mc({padding:`3`,className:`flex-1 max-h-none`}),children:o}),t[2]=o,t[3]=l,t[4]=c,t[5]=d):d=t[5];let f;t[6]!==u||t[7]!==d?(f=(0,$.jsxs)(We,{className:`max-w-3xl h-[80vh] flex flex-col`,children:[u,d]}),t[6]=u,t[7]=d,t[8]=f):f=t[8];let p;return t[9]!==r||t[10]!==n||t[11]!==f?(p=(0,$.jsx)(ie,{open:n,onOpenChange:r,children:f}),t[9]=r,t[10]=n,t[11]=f,t[12]=p):p=t[12],p}function Pc(e){let t=(0,X.c)(20),{open:n,onOpenChange:r,title:i,requestContent:o,responseContent:s}=e,c;t[0]===i?c=t[1]:(c=(0,$.jsx)(a,{children:(0,$.jsx)(vt,{children:(0,$.jsx)(`code`,{className:W.mono,children:i})})}),t[0]=i,t[1]=c);let l,u;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,$.jsx)(`div`,{className:z(W.compact,`mb-1 text-muted-foreground`),children:`Request`}),u=Mc({padding:`3`,className:`max-h-48`}),t[2]=l,t[3]=u):(l=t[2],u=t[3]);let d;t[4]===o?d=t[5]:(d=(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-col`,children:[l,(0,$.jsx)(`pre`,{className:u,children:o})]}),t[4]=o,t[5]=d);let f,p;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,$.jsx)(`div`,{className:z(W.compact,`mb-1 text-muted-foreground`),children:`Response`}),p=Mc({padding:`3`,className:`flex-1 max-h-none`}),t[6]=f,t[7]=p):(f=t[6],p=t[7]);let m;t[8]===s?m=t[9]:(m=(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[f,(0,$.jsx)(`pre`,{className:p,children:s})]}),t[8]=s,t[9]=m);let h;t[10]!==d||t[11]!==m?(h=(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-4 overflow-hidden`,children:[d,m]}),t[10]=d,t[11]=m,t[12]=h):h=t[12];let g;t[13]!==c||t[14]!==h?(g=(0,$.jsxs)(We,{className:`max-w-3xl h-[80vh] flex flex-col gap-4`,children:[c,h]}),t[13]=c,t[14]=h,t[15]=g):g=t[15];let _;return t[16]!==r||t[17]!==n||t[18]!==g?(_=(0,$.jsx)(ie,{open:n,onOpenChange:r,children:g}),t[16]=r,t[17]=n,t[18]=g,t[19]=_):_=t[19],_}function Fc(e){let t=(0,X.c)(10),{oldText:n,newText:r}=e,i,a,o;if(t[0]!==r||t[1]!==n){let e=n.split(`
|
|
21
|
-
`),s=r.split(`
|
|
22
|
-
`);t[5]===Symbol.for(`react.memo_cache_sentinel`)?(i=z(W.caption,`font-mono whitespace-pre-wrap overflow-auto`),t[5]=i):i=t[5],a=e.map(Lc),o=s.map(Ic),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 Ic(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 Lc(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 Rc(e){let t=(0,X.c)(3),{name:n}=e,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=z(W.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 zc(e){let t=(0,X.c)(3),{type:n}=e,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=z(W.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 Bc(e){let t=(0,X.c)(3),{children:n}=e,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=z(W.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 Vc(e){let t=(0,X.c)(5),{className:n,size:r}=e,i=(r===void 0?`sm`:r)===`sm`?`h-7 w-7`:`h-8 w-8`,a;t[0]!==n||t[1]!==i?(a=z(`shrink-0`,i,n),t[0]=n,t[1]=i,t[2]=a):a=t[2];let o;return t[3]===a?o=t[4]:(o=(0,$.jsx)(`img`,{src:`/busy.svg`,alt:``,className:a,"aria-hidden":!0}),t[3]=a,t[4]=o),o}function Hc(e){let t=(0,X.c)(15),{toolName:n,displayName:r,muted:i,size:a,className:o}=e,s=i===void 0?!0:i,c;t[0]===o?c=t[1]:(c=z(`inline-flex items-center gap-1`,o),t[0]=o,t[1]=c);let l=!s&&`text-foreground`,u;t[2]===l?u=t[3]:(u=z(W.caption,l),t[2]=l,t[3]=u);let d;t[4]!==r||t[5]!==u?(d=(0,$.jsx)(`span`,{className:u,children:r}),t[4]=r,t[5]=u,t[6]=d):d=t[6];let f;t[7]!==c||t[8]!==d?(f=(0,$.jsx)(L,{asChild:!0,children:(0,$.jsx)(`span`,{className:c,children:d})}),t[7]=c,t[8]=d,t[9]=f):f=t[9];let p;t[10]===n?p=t[11]:(p=(0,$.jsx)(H,{children:n}),t[10]=n,t[11]=p);let m;return t[12]!==f||t[13]!==p?(m=(0,$.jsxs)(B,{children:[f,p]}),t[12]=f,t[13]=p,t[14]=m):m=t[14],m}function Uc(e){let t=(0,X.c)(106),{data:n,inline:r,resultContent:i,isActive:a}=e,o=(0,Y.useRef)(null),[s,c]=(0,Y.useState)(!!a),[l,u]=(0,Y.useState)(!1),d=(0,Y.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=Q(f),m=a?p??i??``:i??``,h;t[2]===m?h=t[3]:(h=m?rc(m):``,t[2]=m,t[3]=h);let g=h,_=a?g:``,v=jc(n.command,n.toolId,!!a),y;t[4]===n.command?y=t[5]:(y=n.command===null?null:oc(n.command),t[4]=n.command,t[5]=y);let b=y,x,S;t[6]===a?(x=t[7],S=t[8]):(x=()=>{a&&!d.current?c(!0):!a&&d.current&&c(!1),d.current=!!a},S=[a],t[6]=a,t[7]=x,t[8]=S),(0,Y.useEffect)(x,S);let C;t[9]!==a||t[10]!==s?(C=()=>{s&&a&&o.current&&(o.current.scrollTop=o.current.scrollHeight)},t[9]=a,t[10]=s,t[11]=C):C=t[11];let w;if(t[12]!==a||t[13]!==s||t[14]!==_?(w=[s,a,_],t[12]=a,t[13]=s,t[14]=_,t[15]=w):w=t[15],(0,Y.useEffect)(C,w),r){if(a){let e;t[16]===s?e=t[17]:(e=()=>c(!s),t[16]=s,t[17]=e);let r;t[18]!==n.activeDisplayName||t[19]!==n.toolName?(r=(0,$.jsx)(Hc,{toolName:n.toolName,displayName:n.activeDisplayName,isActive:!1,className:`shrink-0`}),t[18]=n.activeDisplayName,t[19]=n.toolName,t[20]=r):r=t[20];let i;t[21]===b?i=t[22]:(i=b!==null&&(0,$.jsx)(`span`,{className:z(W.caption,`min-w-0 flex-1 truncate whitespace-nowrap`),children:b.label}),t[21]=b,t[22]=i);let a;t[23]===v?a=t[24]:(a=v&&(0,$.jsx)(`span`,{className:z(W.caption,`tabular-nums shrink-0`),children:v}),t[23]=v,t[24]=a);let l;t[25]===s?l=t[26]:(l=s?(0,$.jsx)(Ue,{className:`h-3 w-3 text-muted-foreground shrink-0`}):(0,$.jsx)(re,{className:`h-3 w-3 text-muted-foreground shrink-0`}),t[25]=s,t[26]=l);let u;t[27]!==s||t[28]!==i||t[29]!==a||t[30]!==l||t[31]!==e||t[32]!==r?(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":s,children:[r,i,a,l]}),t[27]=s,t[28]=i,t[29]=a,t[30]=l,t[31]=e,t[32]=r,t[33]=u):u=t[33];let d=s?`grid-rows-[1fr]`:`grid-rows-[0fr]`,f;t[34]===d?f=t[35]:(f=z(`grid transition-[grid-template-rows] duration-200 ease-in-out`,d),t[34]=d,t[35]=f);let p,m;t[36]===Symbol.for(`react.memo_cache_sentinel`)?(p=z(W.caption,`ml-5 text-muted-foreground/60 whitespace-pre-wrap overflow-y-auto font-mono`),m={maxHeight:`7.5em`},t[36]=p,t[37]=m):(p=t[36],m=t[37]);let h;t[38]===_?h=t[39]:(h=(0,$.jsx)(`div`,{className:`overflow-hidden`,children:(0,$.jsx)(`div`,{ref:o,className:p,style:m,children:_})}),t[38]=_,t[39]=h);let g;t[40]!==f||t[41]!==h?(g=(0,$.jsx)(`div`,{className:f,children:h}),t[40]=f,t[41]=h,t[42]=g):g=t[42];let y;return t[43]!==u||t[44]!==g?(y=(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[u,g]}),t[43]=u,t[44]=g,t[45]=y):y=t[45],y}if(b!==null&&g){let e=b.label!==b.fullText,r;t[46]!==n.displayName||t[47]!==n.toolName?(r=(0,$.jsx)(Hc,{toolName:n.toolName,displayName:n.displayName,isActive:!1}),t[46]=n.displayName,t[47]=n.toolName,t[48]=r):r=t[48];let i,a;t[49]===Symbol.for(`react.memo_cache_sentinel`)?(a=()=>u(!0),i=z(W.caption,`font-mono hover:underline truncate whitespace-nowrap min-w-0 cursor-pointer`),t[49]=i,t[50]=a):(i=t[49],a=t[50]);let o;t[51]===b.label?o=t[52]:(o=(0,$.jsx)(L,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:a,className:i,children:b.label})}),t[51]=b.label,t[52]=o);let s=e?b.fullText:`View output`,c;t[53]===s?c=t[54]:(c=(0,$.jsx)(H,{className:`max-w-md break-all font-mono`,children:s}),t[53]=s,t[54]=c);let d;t[55]!==o||t[56]!==c?(d=(0,$.jsxs)(B,{children:[o,c]}),t[55]=o,t[56]=c,t[57]=d):d=t[57];let f;t[58]!==d||t[59]!==r?(f=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 flex-wrap`,children:[r,d]}),t[58]=d,t[59]=r,t[60]=f):f=t[60];let p;t[61]!==b.fullText||t[62]!==l||t[63]!==g?(p=(0,$.jsx)(Nc,{open:l,onOpenChange:u,title:b.fullText,content:g}),t[61]=b.fullText,t[62]=l,t[63]=g,t[64]=p):p=t[64];let m;return t[65]!==f||t[66]!==p?(m=(0,$.jsxs)($.Fragment,{children:[f,p]}),t[65]=f,t[66]=p,t[67]=m):m=t[67],m}let e;t[68]!==n.displayName||t[69]!==n.toolName?(e=(0,$.jsx)(Hc,{toolName:n.toolName,displayName:n.displayName,isActive:!1}),t[68]=n.displayName,t[69]=n.toolName,t[70]=e):e=t[70];let r;t[71]===b?r=t[72]:(r=b!==null&&(0,$.jsx)(`code`,{className:z(W.caption,`font-mono truncate whitespace-nowrap rounded bg-muted/60 px-1 py-0.5 max-w-full`),children:b.label}),t[71]=b,t[72]=r);let i;return t[73]!==e||t[74]!==r?(i=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 flex-wrap`,children:[e,r]}),t[73]=e,t[74]=r,t[75]=i):i=t[75],i}let T;t[76]===s?T=t[77]:(T=()=>c(!s),t[76]=s,t[77]=T);let E;t[78]===Symbol.for(`react.memo_cache_sentinel`)?(E=z(W.body,`w-full py-2 flex items-center gap-2 font-medium text-foreground hover:bg-muted/50 transition-colors text-left`),t[78]=E):E=t[78];let D;t[79]!==n.activeDisplayName||t[80]!==n.displayName||t[81]!==a||t[82]!==v?(D=a?(0,$.jsxs)($.Fragment,{children:[n.activeDisplayName,v&&(0,$.jsx)(`span`,{className:`ml-2 text-muted-foreground tabular-nums`,children:v})]}):n.displayName,t[79]=n.activeDisplayName,t[80]=n.displayName,t[81]=a,t[82]=v,t[83]=D):D=t[83];let O;t[84]===D?O=t[85]:(O=(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:D}),t[84]=D,t[85]=O);let k;t[86]===s?k=t[87]:(k=s?(0,$.jsx)(Ue,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(re,{className:`h-4 w-4 shrink-0`}),t[86]=s,t[87]=k);let A;t[88]!==O||t[89]!==k||t[90]!==T?(A=(0,$.jsx)(L,{asChild:!0,children:(0,$.jsxs)(`button`,{onClick:T,className:E,children:[O,k]})}),t[88]=O,t[89]=k,t[90]=T,t[91]=A):A=t[91];let j;t[92]===n.toolName?j=t[93]:(j=(0,$.jsx)(H,{children:n.toolName}),t[92]=n.toolName,t[93]=j);let M;t[94]!==A||t[95]!==j?(M=(0,$.jsxs)(B,{children:[A,j]}),t[94]=A,t[95]=j,t[96]=M):M=t[96];let N;t[97]!==n.toolId||t[98]!==n.toolInput||t[99]!==a||t[100]!==s||t[101]!==_?(N=s&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border`,children:[(0,$.jsxs)(`div`,{className:z(W.compact,`text-muted-foreground mb-2 font-mono`),children:[`ID: `,n.toolId]}),a?(0,$.jsx)(`div`,{ref:o,className:z(W.caption,`text-muted-foreground/60 whitespace-pre-wrap overflow-y-auto font-mono`),style:{maxHeight:`7.5em`},children:_}):n.toolInput?(0,$.jsx)(`pre`,{className:Mc(),children:n.toolInput}):null]}),t[97]=n.toolId,t[98]=n.toolInput,t[99]=a,t[100]=s,t[101]=_,t[102]=N):N=t[102];let P;return t[103]!==M||t[104]!==N?(P=(0,$.jsxs)(`div`,{className:`overflow-hidden`,children:[M,N]}),t[103]=M,t[104]=N,t[105]=P):P=t[105],P}function Wc(e){let t=(0,X.c)(50),{data:n,inline:r,resultContent:i,isActive:a}=e,[o,s]=(0,Y.useState)(!!a),[c,l]=(0,Y.useState)(!1),u=n.fetchUrl,d;t[0]===i?d=t[1]:(d=i?Gc(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)(Hc,{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:z(W.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:z(W.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)(Ue,{className:`h-3 w-3 text-muted-foreground shrink-0`}):(0,$.jsx)(re,{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:z(W.mono,W.caption,`whitespace-pre-wrap break-all rounded bg-muted/40 p-2 max-h-48 overflow-auto`),children:Kc(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)(Hc,{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)(B,{children:[(0,$.jsx)(L,{asChild:!0,children:(0,$.jsx)(`code`,{className:z(W.mono,W.caption,`break-all`),children:u})}),(0,$.jsx)(H,{children:u})]}),t[31]=u,t[32]=_);let v;t[33]===f?v=t[34]:(v=f&&(0,$.jsxs)(`span`,{className:z(W.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:z(W.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?Kc(i):``,t[42]=i,t[43]=x);let S;t[44]!==c||t[45]!==x?(S=(0,$.jsx)(Nc,{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 Gc(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 Kc(e){try{let t=JSON.parse(e);if(typeof t.result==`string`)return t.result}catch{}return e}var qc=Hr,Jc=Er,Yc=Y.forwardRef((e,t)=>{let n=(0,X.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=z(`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)(Rr,{children:(0,$.jsx)(wr,{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});Yc.displayName=wr.displayName;function Xc(e){let t=(0,X.c)(6),{type:n,count:r}=e,i=n===`added`?`text-green-600 dark:text-green-400`:`text-red-600 dark:text-red-400`,a;t[0]===i?a=t[1]:(a=z(W.compact,`font-mono tabular-nums`,i),t[0]=i,t[1]=a);let o=n===`added`?`+`:`-`,s;return t[2]!==r||t[3]!==a||t[4]!==o?(s=(0,$.jsxs)(`span`,{className:a,children:[o,r]}),t[2]=r,t[3]=a,t[4]=o,t[5]=s):s=t[5],s}function Zc(e){let t=(0,X.c)(3),{offset:n,limit:r}=e;if(n===null&&r===null)return null;let i;i=n!==null&&r!==null?`${n}-${n+r}`:n===null?`${r}`:`${n}-`;let a;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=z(W.compact,`font-mono tabular-nums text-muted-foreground`),t[0]=a):a=t[0];let o;return t[1]===i?o=t[2]:(o=(0,$.jsx)(`span`,{className:a,children:i}),t[1]=i,t[2]=o),o}function Qc(e){let t=(0,X.c)(51),{data:n,inline:r,rootPath:i,onOpenFile:o}=e,[s,c]=(0,Y.useState)(!1),[l,u]=(0,Y.useState)(!1),d;t[0]!==n.filePath||t[1]!==o||t[2]!==i?(d=function(){!n.filePath||!o||o(i&&n.filePath.startsWith(i)?n.filePath.slice(i.length+1):n.filePath)},t[0]=n.filePath,t[1]=o,t[2]=i,t[3]=d):d=t[3];let f=d;if(r){let e=!!(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)(qc,{children:[(0,$.jsx)(Jc,{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)(Hc,{toolName:n.toolName,displayName:n.displayName,isActive:!1,muted:!1})})})}),(0,$.jsx)(Yc,{className:`w-80 max-h-80 overflow-auto`,align:`start`,children:(0,$.jsxs)(`div`,{className:z(W.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)(Hc,{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 o;t[10]!==n.editAddedLineCount||t[11]!==n.editDeletedLineCount||t[12]!==n.editNewText||t[13]!==n.editOldText||t[14]!==n.fileDisplayName||t[15]!==n.filePath||t[16]!==n.hasEditDiff||t[17]!==n.limit||t[18]!==n.offset||t[19]!==n.path||t[20]!==n.toolName||t[21]!==l||t[22]!==f||t[23]!==i?(o=n.fileDisplayName?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(B,{children:[(0,$.jsx)(L,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,onClick:n.hasEditDiff?()=>u(!0):f,className:z(`inline-flex max-w-full items-center gap-2 cursor-pointer`,W.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)(Zc,{offset:n.offset,limit:n.limit}):null,n.hasEditDiff?(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 shrink-0`,children:[n.editAddedLineCount===null?null:(0,$.jsx)(Xc,{type:`added`,count:n.editAddedLineCount}),n.editDeletedLineCount===null?null:(0,$.jsx)(Xc,{type:`deleted`,count:n.editDeletedLineCount})]}):null]})}),(0,$.jsx)(H,{children:n.hasEditDiff?`View diff`:n.filePath?sc(n.filePath,i)??n.filePath:n.fileDisplayName})]}),n.hasEditDiff&&(0,$.jsx)(ie,{open:l,onOpenChange:u,children:(0,$.jsxs)(We,{className:`max-w-2xl h-[80vh] flex flex-col`,children:[(0,$.jsx)(a,{children:(0,$.jsx)(vt,{children:(0,$.jsx)(`code`,{className:z(W.caption,`font-mono`),children:sc(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)(Fc,{oldText:n.editOldText,newText:n.editNewText})})]})})]}):n.path===null?null:(0,$.jsxs)(B,{children:[(0,$.jsx)(L,{asChild:!0,children:(0,$.jsx)(`span`,{className:z(W.caption,`font-mono truncate max-w-[200px] sm:max-w-[320px]`),children:n.path})}),(0,$.jsx)(H,{children:n.path})]}),t[10]=n.editAddedLineCount,t[11]=n.editDeletedLineCount,t[12]=n.editNewText,t[13]=n.editOldText,t[14]=n.fileDisplayName,t[15]=n.filePath,t[16]=n.hasEditDiff,t[17]=n.limit,t[18]=n.offset,t[19]=n.path,t[20]=n.toolName,t[21]=l,t[22]=f,t[23]=i,t[24]=o):o=t[24];let s;return t[25]!==r||t[26]!==o?(s=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 flex-wrap`,children:[r,o]}),t[25]=r,t[26]=o,t[27]=s):s=t[27],s}let p;t[28]===s?p=t[29]:(p=()=>c(!s),t[28]=s,t[29]=p);let m;t[30]===Symbol.for(`react.memo_cache_sentinel`)?(m=z(W.body,`w-full py-2 flex items-center gap-2 font-medium text-foreground hover:bg-muted/50 transition-colors text-left`),t[30]=m):m=t[30];let h;t[31]===n.displayName?h=t[32]:(h=(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:n.displayName}),t[31]=n.displayName,t[32]=h);let g;t[33]===s?g=t[34]:(g=s?(0,$.jsx)(Ue,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(re,{className:`h-4 w-4 shrink-0`}),t[33]=s,t[34]=g);let _;t[35]!==p||t[36]!==h||t[37]!==g?(_=(0,$.jsx)(L,{asChild:!0,children:(0,$.jsxs)(`button`,{onClick:p,className:m,children:[h,g]})}),t[35]=p,t[36]=h,t[37]=g,t[38]=_):_=t[38];let v;t[39]===n.toolName?v=t[40]:(v=(0,$.jsx)(H,{children:n.toolName}),t[39]=n.toolName,t[40]=v);let y;t[41]!==_||t[42]!==v?(y=(0,$.jsxs)(B,{children:[_,v]}),t[41]=_,t[42]=v,t[43]=y):y=t[43];let b;t[44]!==n.toolId||t[45]!==n.toolInput||t[46]!==s?(b=s&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border`,children:[(0,$.jsxs)(`div`,{className:z(W.compact,`text-muted-foreground mb-2 font-mono`),children:[`ID: `,n.toolId]}),n.toolInput?(0,$.jsx)(`pre`,{className:Mc(),children:n.toolInput}):null]}),t[44]=n.toolId,t[45]=n.toolInput,t[46]=s,t[47]=b):b=t[47];let x;return t[48]!==y||t[49]!==b?(x=(0,$.jsxs)(`div`,{className:`overflow-hidden`,children:[y,b]}),t[48]=y,t[49]=b,t[50]=x):x=t[50],x}function $c(e){let t=e.replace(/\s+/g,` `).trim();return{fullText:t,label:ac(t,50)}}function el(e){let t=(0,X.c)(11),{text:n}=e,r;t[0]===n?r=t[1]:(r=$c(n),t[0]=n,t[1]=r);let{label:i,fullText:a}=r,o;t[2]===i?o=t[3]:(o=(0,$.jsx)(Bc,{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)(L,{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)(H,{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)(B,{children:[c,l]}),t[8]=c,t[9]=l,t[10]=u):u=t[10],u}function tl(e){let t=(0,X.c)(7),{data:n}=e,r=n.toolName===`code_search`,i;return t[0]!==n.codeSearchFileGlob||t[1]!==n.codeSearchFilePath||t[2]!==n.codeSearchQuery||t[3]!==n.pattern||t[4]!==n.webSearchQuery||t[5]!==r?(i=(0,$.jsx)($.Fragment,{children:r?(0,$.jsxs)($.Fragment,{children:[n.codeSearchQuery!==null&&(0,$.jsx)(el,{text:n.codeSearchQuery}),n.pattern!==null&&(0,$.jsx)(el,{text:`/${n.pattern}/`}),n.codeSearchFilePath!==null&&(0,$.jsx)(el,{text:n.codeSearchFilePath}),n.codeSearchFileGlob!==null&&(0,$.jsx)(el,{text:n.codeSearchFileGlob})]}):(0,$.jsxs)($.Fragment,{children:[n.webSearchQuery!==null&&(0,$.jsx)(el,{text:n.webSearchQuery}),n.pattern!==null&&(0,$.jsx)(el,{text:n.pattern})]})}),t[0]=n.codeSearchFileGlob,t[1]=n.codeSearchFilePath,t[2]=n.codeSearchQuery,t[3]=n.pattern,t[4]=n.webSearchQuery,t[5]=r,t[6]=i):i=t[6],i}function nl(e){let t=(0,X.c)(72),{data:n,inline:r,resultContent:i,isActive:a}=e,[o,s]=(0,Y.useState)(!1),[c,l]=(0,Y.useState)(!1),u=n.toolName===`code_search`,d=n.webSearchQuery??n.codeSearchQuery??n.pattern??n.codeSearchFilePath??n.codeSearchFileGlob??`search`,f;t[0]===d?f=t[1]:(f=$c(d),t[0]=d,t[1]=f);let{label:p,fullText:m}=f,h=p!==m;if(r){if(i&&(u||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)(Hc,{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=z(W.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]===p?s=t[9]:(s=(0,$.jsx)(L,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:r,className:o,children:p})}),t[8]=p,t[9]=s);let u=h?m:`View results`,d;t[10]===u?d=t[11]:(d=(0,$.jsx)(H,{className:`max-w-md break-all font-mono`,children:u}),t[10]=u,t[11]=d);let f;t[12]!==s||t[13]!==d?(f=(0,$.jsxs)(B,{children:[s,d]}),t[12]=s,t[13]=d,t[14]=f):f=t[14];let g;t[15]!==e||t[16]!==f?(g=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 min-w-0`,children:[e,f]}),t[15]=e,t[16]=f,t[17]=g):g=t[17];let _;t[18]!==c||t[19]!==i||t[20]!==m?(_=(0,$.jsx)(Nc,{open:c,onOpenChange:l,title:m,content:i}),t[18]=c,t[19]=i,t[20]=m,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)(Hc,{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)(tl,{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:z(W.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 g;t[37]===o?g=t[38]:(g=()=>s(!o),t[37]=o,t[38]=g);let _;t[39]===Symbol.for(`react.memo_cache_sentinel`)?(_=z(W.body,`w-full py-2 flex items-center gap-2 font-medium text-foreground hover:bg-muted/50 transition-colors text-left`),t[39]=_):_=t[39];let v;t[40]===a?v=t[41]:(v=a&&(0,$.jsx)(Vc,{size:`md`}),t[40]=a,t[41]=v);let y;t[42]===n.displayName?y=t[43]:(y=(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:n.displayName}),t[42]=n.displayName,t[43]=y);let b;t[44]!==n.codeSearchFileGlob||t[45]!==n.codeSearchFilePath||t[46]!==n.codeSearchQuery||t[47]!==n.pattern||t[48]!==u?(b=u&&(0,$.jsxs)($.Fragment,{children:[n.codeSearchQuery!==null&&(0,$.jsx)(`code`,{className:z(W.caption,`font-mono bg-muted rounded px-1 py-0.5 truncate max-w-[150px]`),children:n.codeSearchQuery}),n.pattern!==null&&(0,$.jsxs)(`code`,{className:z(W.caption,`font-mono bg-muted rounded px-1 py-0.5 truncate max-w-[150px]`),children:[`/`,n.pattern,`/`]}),n.codeSearchFilePath!==null&&(0,$.jsx)(`code`,{className:z(W.caption,`font-mono bg-muted rounded px-1 py-0.5 truncate max-w-[150px]`),children:n.codeSearchFilePath}),n.codeSearchFileGlob!==null&&(0,$.jsx)(`code`,{className:z(W.caption,`font-mono bg-muted rounded px-1 py-0.5 truncate max-w-[150px]`),children:n.codeSearchFileGlob})]}),t[44]=n.codeSearchFileGlob,t[45]=n.codeSearchFilePath,t[46]=n.codeSearchQuery,t[47]=n.pattern,t[48]=u,t[49]=b):b=t[49];let x;t[50]===o?x=t[51]:(x=o?(0,$.jsx)(Ue,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(re,{className:`h-4 w-4 shrink-0`}),t[50]=o,t[51]=x);let S;t[52]!==g||t[53]!==v||t[54]!==y||t[55]!==b||t[56]!==x?(S=(0,$.jsx)(L,{asChild:!0,children:(0,$.jsxs)(`button`,{onClick:g,className:_,children:[v,y,b,x]})}),t[52]=g,t[53]=v,t[54]=y,t[55]=b,t[56]=x,t[57]=S):S=t[57];let C;t[58]===n.toolName?C=t[59]:(C=(0,$.jsx)(H,{children:n.toolName}),t[58]=n.toolName,t[59]=C);let w;t[60]!==S||t[61]!==C?(w=(0,$.jsxs)(B,{children:[S,C]}),t[60]=S,t[61]=C,t[62]=w):w=t[62];let T;t[63]!==n.toolId||t[64]!==n.toolInput||t[65]!==o||t[66]!==u||t[67]!==i?(T=o&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border`,children:[(0,$.jsxs)(`div`,{className:z(W.compact,`text-muted-foreground mb-2 font-mono`),children:[`ID: `,n.toolId]}),n.toolInput?(0,$.jsx)(`pre`,{className:Mc(),children:n.toolInput}):null,u&&i&&(0,$.jsx)(`pre`,{className:Mc({maxHeight:`64`,className:`mt-2`}),children:i})]}),t[63]=n.toolId,t[64]=n.toolInput,t[65]=o,t[66]=u,t[67]=i,t[68]=T):T=t[68];let E;return t[69]!==w||t[70]!==T?(E=(0,$.jsxs)(`div`,{className:`overflow-hidden`,children:[w,T]}),t[69]=w,t[70]=T,t[71]=E):E=t[71],E}function rl(e){let t=(0,X.c)(13),{output:n,scrollRef:r,placeholder:i,threadId:a,className:o,style:s}=e,c;t[0]===n?c=t[1]:(c=n?ra(rc(n)):``,t[0]=n,t[1]=c);let l=c,u;t[2]===o?u=t[3]:(u=z(W.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)(ls,{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 il(e){let t=(0,X.c)(136),{data:n,inline:r,resultContent:i,isActive:a}=e,o=(0,Y.useRef)(null),[s,c]=(0,Y.useState)(!!a),[l,u]=(0,Y.useState)(!1),d=(0,Y.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=Q(f),m=Q(al),h=a?p??i??``:i??p??``,g;t[2]===h?g=t[3]:(g=h?rc(h):``,t[2]=h,t[3]=g);let _=g,v=a?_:``,y,b;t[4]===a?(y=t[5],b=t[6]):(y=()=>{a&&!d.current?c(!0):!a&&d.current&&c(!1),d.current=!!a},b=[a],t[4]=a,t[5]=y,t[6]=b),(0,Y.useEffect)(y,b);let x;t[7]!==s||t[8]!==a?(x=()=>{s&&a&&o.current&&(o.current.scrollTop=o.current.scrollHeight)},t[7]=s,t[8]=a,t[9]=x):x=t[9];let S;if(t[10]!==s||t[11]!==a||t[12]!==v?(S=[s,a,v],t[10]=s,t[11]=a,t[12]=v,t[13]=S):S=t[13],(0,Y.useEffect)(x,S),r){if(a){let e;t[14]===s?e=t[15]:(e=()=>c(!s),t[14]=s,t[15]=e);let r;t[16]!==n.activeDisplayName||t[17]!==n.toolName?(r=(0,$.jsx)(Hc,{toolName:n.toolName,displayName:n.activeDisplayName,isActive:!0}),t[16]=n.activeDisplayName,t[17]=n.toolName,t[18]=r):r=t[18];let i;t[19]===n.agentName?i=t[20]:(i=n.agentName&&(0,$.jsx)(Rc,{name:n.agentName}),t[19]=n.agentName,t[20]=i);let a;t[21]===n.subagentType?a=t[22]:(a=n.subagentType&&(0,$.jsx)(zc,{type:n.subagentType}),t[21]=n.subagentType,t[22]=a);let l;t[23]===s?l=t[24]:(l=s?(0,$.jsx)(Ue,{className:`h-3 w-3 text-muted-foreground shrink-0`}):(0,$.jsx)(re,{className:`h-3 w-3 text-muted-foreground shrink-0`}),t[23]=s,t[24]=l);let u;t[25]!==s||t[26]!==a||t[27]!==l||t[28]!==e||t[29]!==r||t[30]!==i?(u=(0,$.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1.5 cursor-pointer select-none text-left w-full`,onClick:e,"aria-expanded":s,children:[r,i,a,l]}),t[25]=s,t[26]=a,t[27]=l,t[28]=e,t[29]=r,t[30]=i,t[31]=u):u=t[31];let d=s?`grid-rows-[1fr]`:`grid-rows-[0fr]`,f;t[32]===d?f=t[33]:(f=z(`grid transition-[grid-template-rows] duration-200 ease-in-out`,d),t[32]=d,t[33]=f);let p;t[34]===Symbol.for(`react.memo_cache_sentinel`)?(p={maxHeight:`7.5em`},t[34]=p):p=t[34];let h;t[35]!==v||t[36]!==m?(h=(0,$.jsx)(`div`,{className:`overflow-hidden`,children:(0,$.jsx)(rl,{scrollRef:o,output:v,placeholder:`Running subagent...`,threadId:m,className:`ml-5`,style:p})}),t[35]=v,t[36]=m,t[37]=h):h=t[37];let g;t[38]!==f||t[39]!==h?(g=(0,$.jsx)(`div`,{className:f,children:h}),t[38]=f,t[39]=h,t[40]=g):g=t[40];let _;return t[41]!==u||t[42]!==g?(_=(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[u,g]}),t[41]=u,t[42]=g,t[43]=_):_=t[43],_}if(_){let e;t[44]!==n.displayName||t[45]!==n.toolName?(e=(0,$.jsx)(Jc,{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)(Hc,{toolName:n.toolName,displayName:n.displayName,isActive:!1})})})}),t[44]=n.displayName,t[45]=n.toolName,t[46]=e):e=t[46];let r;t[47]===Symbol.for(`react.memo_cache_sentinel`)?(r=z(W.caption,`space-y-2`),t[47]=r):r=t[47];let i;t[48]===n.toolId?i=t[49]:(i=(0,$.jsxs)(`div`,{className:`font-mono`,children:[`ID: `,n.toolId]}),t[48]=n.toolId,t[49]=i);let a;t[50]!==n.prompt||t[51]!==n.toolInput?(a=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,t[50]=n.prompt,t[51]=n.toolInput,t[52]=a):a=t[52];let o;t[53]!==a||t[54]!==i?(o=(0,$.jsx)(Yc,{className:`w-80 max-h-80 overflow-auto`,align:`start`,children:(0,$.jsxs)(`div`,{className:r,children:[i,a]})}),t[53]=a,t[54]=i,t[55]=o):o=t[55];let s;t[56]!==o||t[57]!==e?(s=(0,$.jsxs)(qc,{children:[e,o]}),t[56]=o,t[57]=e,t[58]=s):s=t[58];let c;t[59]===n.agentName?c=t[60]:(c=n.agentName&&(0,$.jsx)(Rc,{name:n.agentName}),t[59]=n.agentName,t[60]=c);let d;t[61]===n.subagentType?d=t[62]:(d=n.subagentType&&(0,$.jsx)(zc,{type:n.subagentType}),t[61]=n.subagentType,t[62]=d);let f;t[63]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,$.jsxs)(B,{children:[(0,$.jsx)(L,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:()=>u(!0),className:z(W.caption,`text-muted-foreground hover:underline`),children:`View output`})}),(0,$.jsx)(H,{children:`View subagent output`})]}),t[63]=f):f=t[63];let p;t[64]!==s||t[65]!==c||t[66]!==d?(p=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 flex-wrap`,children:[s,c,d,f]}),t[64]=s,t[65]=c,t[66]=d,t[67]=p):p=t[67];let h;t[68]!==n.displayName||t[69]!==l||t[70]!==_||t[71]!==m?(h=(0,$.jsx)(Nc,{open:l,onOpenChange:u,title:n.displayName,content:_,markdown:!0,threadId:m}),t[68]=n.displayName,t[69]=l,t[70]=_,t[71]=m,t[72]=h):h=t[72];let g;return t[73]!==p||t[74]!==h?(g=(0,$.jsxs)($.Fragment,{children:[p,h]}),t[73]=p,t[74]=h,t[75]=g):g=t[75],g}let e;t[76]!==n.displayName||t[77]!==n.toolName?(e=(0,$.jsx)(Jc,{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)(Hc,{toolName:n.toolName,displayName:n.displayName,isActive:!1,muted:!1})})})}),t[76]=n.displayName,t[77]=n.toolName,t[78]=e):e=t[78];let r;t[79]===Symbol.for(`react.memo_cache_sentinel`)?(r=z(W.caption,`space-y-2`),t[79]=r):r=t[79];let i;t[80]===n.toolId?i=t[81]:(i=(0,$.jsxs)(`div`,{className:`font-mono`,children:[`ID: `,n.toolId]}),t[80]=n.toolId,t[81]=i);let d;t[82]!==n.prompt||t[83]!==n.toolInput?(d=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,t[82]=n.prompt,t[83]=n.toolInput,t[84]=d):d=t[84];let f;t[85]!==d||t[86]!==i?(f=(0,$.jsx)(Yc,{className:`w-80 max-h-80 overflow-auto`,align:`start`,children:(0,$.jsxs)(`div`,{className:r,children:[i,d]})}),t[85]=d,t[86]=i,t[87]=f):f=t[87];let p;t[88]!==f||t[89]!==e?(p=(0,$.jsxs)(qc,{children:[e,f]}),t[88]=f,t[89]=e,t[90]=p):p=t[90];let h;t[91]===n.agentName?h=t[92]:(h=n.agentName&&(0,$.jsx)(Rc,{name:n.agentName}),t[91]=n.agentName,t[92]=h);let g;t[93]===n.subagentType?g=t[94]:(g=n.subagentType&&(0,$.jsx)(zc,{type:n.subagentType}),t[93]=n.subagentType,t[94]=g);let y;return t[95]!==p||t[96]!==h||t[97]!==g?(y=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 flex-wrap`,children:[p,h,g]}),t[95]=p,t[96]=h,t[97]=g,t[98]=y):y=t[98],y}let C;t[99]===s?C=t[100]:(C=()=>c(!s),t[99]=s,t[100]=C);let w;t[101]===Symbol.for(`react.memo_cache_sentinel`)?(w=z(W.body,`w-full py-2 flex items-center gap-2 font-medium text-foreground hover:bg-muted/50 transition-colors text-left`),t[101]=w):w=t[101];let T;t[102]===a?T=t[103]:(T=a&&(0,$.jsx)(Vc,{size:`md`}),t[102]=a,t[103]=T);let E=a?n.activeDisplayName:n.displayName,D;t[104]===E?D=t[105]:(D=(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:E}),t[104]=E,t[105]=D);let O;t[106]===n.agentName?O=t[107]:(O=n.agentName&&(0,$.jsx)(Rc,{name:n.agentName}),t[106]=n.agentName,t[107]=O);let k;t[108]===n.subagentType?k=t[109]:(k=n.subagentType&&(0,$.jsx)(zc,{type:n.subagentType}),t[108]=n.subagentType,t[109]=k);let A;t[110]===s?A=t[111]:(A=s?(0,$.jsx)(Ue,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(re,{className:`h-4 w-4 shrink-0`}),t[110]=s,t[111]=A);let j;t[112]!==D||t[113]!==O||t[114]!==k||t[115]!==A||t[116]!==C||t[117]!==T?(j=(0,$.jsx)(L,{asChild:!0,children:(0,$.jsxs)(`button`,{onClick:C,className:w,children:[T,D,O,k,A]})}),t[112]=D,t[113]=O,t[114]=k,t[115]=A,t[116]=C,t[117]=T,t[118]=j):j=t[118];let M;t[119]===n.toolName?M=t[120]:(M=(0,$.jsx)(H,{children:n.toolName}),t[119]=n.toolName,t[120]=M);let N;t[121]!==j||t[122]!==M?(N=(0,$.jsxs)(B,{children:[j,M]}),t[121]=j,t[122]=M,t[123]=N):N=t[123];let P;t[124]!==n.prompt||t[125]!==n.toolId||t[126]!==n.toolInput||t[127]!==_||t[128]!==s||t[129]!==a||t[130]!==v||t[131]!==m?(P=s&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border`,children:[(0,$.jsxs)(`div`,{className:z(W.compact,`text-muted-foreground mb-2 font-mono`),children:[`ID: `,n.toolId]}),a?(0,$.jsx)(rl,{scrollRef:o,output:v,placeholder:`Running subagent...`,threadId:m,style:{maxHeight:`7.5em`}}):n.prompt?(0,$.jsx)(`div`,{className:Mc({maxHeight:`64`,padding:`3`,leading:!0}),children:n.prompt}):n.toolInput?(0,$.jsx)(`pre`,{className:Mc(),children:n.toolInput}):_?(0,$.jsx)(rl,{output:_,threadId:m,className:`max-h-64`}):null]}),t[124]=n.prompt,t[125]=n.toolId,t[126]=n.toolInput,t[127]=_,t[128]=s,t[129]=a,t[130]=v,t[131]=m,t[132]=P):P=t[132];let F;return t[133]!==N||t[134]!==P?(F=(0,$.jsxs)(`div`,{className:`overflow-hidden`,children:[N,P]}),t[133]=N,t[134]=P,t[135]=F):F=t[135],F}function al(e){return e.selectedThreadId}function ol(e){let t=(0,X.c)(26),{data:n,inline:r,isActive:i}=e,[a,o]=(0,Y.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]===Symbol.for(`react.memo_cache_sentinel`)?(c=z(W.label,`w-full py-2 flex items-center gap-2 hover:bg-muted/50 transition-colors text-left`),t[2]=c):c=t[2];let l;t[3]===i?l=t[4]:(l=i&&(0,$.jsx)(Vc,{size:`md`}),t[3]=i,t[4]=l);let u;t[5]===n.displayName?u=t[6]:(u=(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:n.displayName}),t[5]=n.displayName,t[6]=u);let d;t[7]===a?d=t[8]:(d=a?(0,$.jsx)(Ue,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(re,{className:`h-4 w-4 shrink-0`}),t[7]=a,t[8]=d);let f;t[9]!==s||t[10]!==l||t[11]!==u||t[12]!==d?(f=(0,$.jsx)(L,{asChild:!0,children:(0,$.jsxs)(`button`,{onClick:s,className:c,children:[l,u,d]})}),t[9]=s,t[10]=l,t[11]=u,t[12]=d,t[13]=f):f=t[13];let p;t[14]===n.toolName?p=t[15]:(p=(0,$.jsx)(H,{children:n.toolName}),t[14]=n.toolName,t[15]=p);let m;t[16]!==f||t[17]!==p?(m=(0,$.jsxs)(B,{children:[f,p]}),t[16]=f,t[17]=p,t[18]=m):m=t[18];let h;t[19]!==n.toolId||t[20]!==n.toolInput||t[21]!==a?(h=a&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border`,children:[(0,$.jsxs)(`div`,{className:z(W.compact,`text-muted-foreground mb-2 font-mono`),children:[`ID: `,n.toolId]}),n.toolInput?(0,$.jsx)(`pre`,{className:Mc(),children:n.toolInput}):null]}),t[19]=n.toolId,t[20]=n.toolInput,t[21]=a,t[22]=h):h=t[22];let g;return t[23]!==m||t[24]!==h?(g=(0,$.jsxs)(`div`,{className:`overflow-hidden`,children:[m,h]}),t[23]=m,t[24]=h,t[25]=g):g=t[25],g}function sl(e){let t=(0,X.c)(35),{data:n,inline:r,isActive:i}=e,[a,o]=(0,Y.useState)(!1);if(r){let e;t[0]!==n.displayName||t[1]!==n.toolName||t[2]!==i?(e=(0,$.jsx)(Hc,{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)(B,{children:[(0,$.jsx)(L,{asChild:!0,children:(0,$.jsx)(`span`,{className:z(W.caption,`truncate max-w-[200px] sm:max-w-[320px]`),children:n.imageGenPrompt})}),(0,$.jsx)(H,{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]===Symbol.for(`react.memo_cache_sentinel`)?(c=z(W.label,`w-full py-2 flex items-center gap-2 hover:bg-muted/50 transition-colors text-left`),t[11]=c):c=t[11];let l;t[12]===i?l=t[13]:(l=i&&(0,$.jsx)(Vc,{size:`md`}),t[12]=i,t[13]=l);let u;t[14]===n.displayName?u=t[15]:(u=(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:n.displayName}),t[14]=n.displayName,t[15]=u);let d;t[16]===a?d=t[17]:(d=a?(0,$.jsx)(Ue,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(re,{className:`h-4 w-4 shrink-0`}),t[16]=a,t[17]=d);let f;t[18]!==s||t[19]!==l||t[20]!==u||t[21]!==d?(f=(0,$.jsx)(L,{asChild:!0,children:(0,$.jsxs)(`button`,{onClick:s,className:c,children:[l,u,d]})}),t[18]=s,t[19]=l,t[20]=u,t[21]=d,t[22]=f):f=t[22];let p;t[23]===n.toolName?p=t[24]:(p=(0,$.jsx)(H,{children:n.toolName}),t[23]=n.toolName,t[24]=p);let m;t[25]!==f||t[26]!==p?(m=(0,$.jsxs)(B,{children:[f,p]}),t[25]=f,t[26]=p,t[27]=m):m=t[27];let h;t[28]!==n.toolId||t[29]!==n.toolInput||t[30]!==a?(h=a&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border`,children:[(0,$.jsxs)(`div`,{className:z(W.compact,`text-muted-foreground mb-2 font-mono`),children:[`ID: `,n.toolId]}),n.toolInput?(0,$.jsx)(`pre`,{className:Mc(),children:n.toolInput}):null]}),t[28]=n.toolId,t[29]=n.toolInput,t[30]=a,t[31]=h):h=t[31];let g;return t[32]!==m||t[33]!==h?(g=(0,$.jsxs)(`div`,{className:`overflow-hidden`,children:[m,h]}),t[32]=m,t[33]=h,t[34]=g):g=t[34],g}function cl(e){if(!e)return null;try{let t=JSON.parse(e);return qo(t,{content:e,...t})}catch{return qo(e,{content:e})}}function ll(e){return e.savedPath?e.savedPath.split(`/`).pop()??e.savedPath:`image`}function ul(e){let t=(0,X.c)(54),{data:n,inline:r,resultContent:i,isActive:o}=e,[s,c]=(0,Y.useState)(!1),[l,u]=(0,Y.useState)(!1),d=Q(dl),f,p;t[0]===i?(f=t[1],p=t[2]):(f=cl(i),p=f?ll(f):null,t[0]=i,t[1]=f,t[2]=p);let m=p;if(r){let e;t[3]!==n.displayName||t[4]!==n.toolName||t[5]!==o?(e=(0,$.jsx)(Hc,{toolName:n.toolName,displayName:n.displayName,isActive:o}),t[3]=n.displayName,t[4]=n.toolName,t[5]=o,t[6]=e):e=t[6];let r;t[7]!==n.findImagesQuery||t[8]!==f?(r=n.findImagesQuery!==null&&!f&&(0,$.jsxs)(B,{children:[(0,$.jsx)(L,{asChild:!0,children:(0,$.jsx)(`span`,{className:z(W.caption,`truncate max-w-[200px] sm:max-w-[320px]`),children:n.findImagesQuery})}),(0,$.jsx)(H,{children:n.findImagesQuery})]}),t[7]=n.findImagesQuery,t[8]=f,t[9]=r):r=t[9];let i;t[10]!==f||t[11]!==m?(i=f&&m&&(0,$.jsxs)(B,{children:[(0,$.jsx)(L,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>u(!0),className:z(W.caption,`hover:underline`),children:[`Found `,m]})}),(0,$.jsx)(H,{children:`View image`})]}),t[10]=f,t[11]=m,t[12]=i):i=t[12];let s;t[13]!==e||t[14]!==r||t[15]!==i?(s=(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]=s):s=t[16];let c;t[17]!==l||t[18]!==f||t[19]!==m||t[20]!==d?(c=f&&(0,$.jsx)(ie,{open:l,onOpenChange:u,children:(0,$.jsxs)(We,{className:`max-w-3xl max-h-[85vh] flex flex-col overflow-auto`,children:[(0,$.jsx)(a,{children:(0,$.jsxs)(vt,{children:[`Found `,m]})}),(0,$.jsx)(Go,{imageUrl:f.imageUrl,imageData:f.imageData,threadId:d,alt:m??`Found image`})]})}),t[17]=l,t[18]=f,t[19]=m,t[20]=d,t[21]=c):c=t[21];let p;return t[22]!==s||t[23]!==c?(p=(0,$.jsxs)($.Fragment,{children:[s,c]}),t[22]=s,t[23]=c,t[24]=p):p=t[24],p}let h;t[25]===s?h=t[26]:(h=()=>c(!s),t[25]=s,t[26]=h);let g;t[27]===Symbol.for(`react.memo_cache_sentinel`)?(g=z(W.body,`w-full py-2 flex items-center gap-2 font-medium text-foreground hover:bg-muted/50 transition-colors text-left`),t[27]=g):g=t[27];let _;t[28]===o?_=t[29]:(_=o&&(0,$.jsx)(Vc,{size:`md`}),t[28]=o,t[29]=_);let v=f?`Found ${m}`:n.displayName,y;t[30]===v?y=t[31]:(y=(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:v}),t[30]=v,t[31]=y);let b;t[32]===s?b=t[33]:(b=s?(0,$.jsx)(Ue,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(re,{className:`h-4 w-4 shrink-0`}),t[32]=s,t[33]=b);let x;t[34]!==h||t[35]!==_||t[36]!==y||t[37]!==b?(x=(0,$.jsx)(L,{asChild:!0,children:(0,$.jsxs)(`button`,{onClick:h,className:g,children:[_,y,b]})}),t[34]=h,t[35]=_,t[36]=y,t[37]=b,t[38]=x):x=t[38];let S;t[39]===n.toolName?S=t[40]:(S=(0,$.jsx)(H,{children:n.toolName}),t[39]=n.toolName,t[40]=S);let C;t[41]!==x||t[42]!==S?(C=(0,$.jsxs)(B,{children:[x,S]}),t[41]=x,t[42]=S,t[43]=C):C=t[43];let w;t[44]!==n.toolId||t[45]!==n.toolInput||t[46]!==s||t[47]!==f||t[48]!==m||t[49]!==d?(w=s&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border`,children:[(0,$.jsxs)(`div`,{className:z(W.compact,`text-muted-foreground mb-2 font-mono`),children:[`ID: `,n.toolId]}),n.toolInput?(0,$.jsx)(`pre`,{className:Mc(),children:n.toolInput}):null,f&&(0,$.jsx)(Go,{imageUrl:f.imageUrl,imageData:f.imageData,threadId:d,alt:m??`Found image`})]}),t[44]=n.toolId,t[45]=n.toolInput,t[46]=s,t[47]=f,t[48]=m,t[49]=d,t[50]=w):w=t[50];let T;return t[51]!==C||t[52]!==w?(T=(0,$.jsxs)(`div`,{className:`overflow-hidden`,children:[C,w]}),t[51]=C,t[52]=w,t[53]=T):T=t[53],T}function dl(e){return e.selectedThreadId}function fl(e){if(!e)return null;try{let t=JSON.parse(e);return t.action===`screenshot`?qo(t,{content:e,...t}):null}catch{return null}}function pl(e){return e.savedPath?e.savedPath.split(`/`).pop()??e.savedPath:`screenshot`}function ml(e){let t=(0,X.c)(85),{data:n,inline:r,resultContent:i,isActive:o}=e,[s,c]=(0,Y.useState)(!1),[l,u]=(0,Y.useState)(!1),d=Q(hl),f;t[0]===n.inputObj?f=t[1]:(f=fc(n.inputObj),t[0]=n.inputObj,t[1]=f);let p=f,m;t[2]===n.inputObj?m=t[3]:(m=cc(n.inputObj),t[2]=n.inputObj,t[3]=m);let h=m,g;t[4]===i?g=t[5]:(g=i?mc(i):``,t[4]=i,t[5]=g);let _=g,v,y;t[6]===i?(v=t[7],y=t[8]):(v=fl(i),y=v?pl(v):null,t[6]=i,t[7]=v,t[8]=y);let b=y;if(r){let e;t[9]!==n.displayName||t[10]!==n.toolName||t[11]!==o?(e=(0,$.jsx)(Hc,{toolName:n.toolName,displayName:n.displayName,isActive:o}),t[9]=n.displayName,t[10]=n.toolName,t[11]=o,t[12]=e):e=t[12];let r;t[13]!==p||t[14]!==i||t[15]!==b||t[16]!==v?(r=v&&b?(0,$.jsxs)(B,{children:[(0,$.jsx)(L,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>u(!0),className:z(W.caption,`hover:underline`),children:[`Screenshot `,b]})}),(0,$.jsx)(H,{children:`View screenshot`})]}):i?(0,$.jsxs)(B,{children:[(0,$.jsx)(L,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:()=>u(!0),className:z(W.caption,`font-mono hover:underline break-all cursor-pointer`),children:p})}),(0,$.jsx)(H,{children:`View results`})]}):(0,$.jsx)(`span`,{className:z(W.caption,`font-mono break-all text-muted-foreground`),children:p}),t[13]=p,t[14]=i,t[15]=b,t[16]=v,t[17]=r):r=t[17];let s;t[18]!==e||t[19]!==r?(s=(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]=s):s=t[20];let c;t[21]!==l||t[22]!==h||t[23]!==p||t[24]!==_||t[25]!==i||t[26]!==b||t[27]!==v||t[28]!==d?(c=v?(0,$.jsx)(ie,{open:l,onOpenChange:u,children:(0,$.jsxs)(We,{className:`max-w-3xl max-h-[85vh] flex flex-col overflow-auto`,children:[(0,$.jsx)(a,{children:(0,$.jsxs)(vt,{children:[`Screenshot `,b]})}),(0,$.jsx)(Go,{imageUrl:v.imageUrl,imageData:v.imageData,threadId:d,alt:b??`Browser screenshot`})]})}):i&&(0,$.jsx)(Pc,{open:l,onOpenChange:u,title:p,requestContent:h,responseContent:_}),t[21]=l,t[22]=h,t[23]=p,t[24]=_,t[25]=i,t[26]=b,t[27]=v,t[28]=d,t[29]=c):c=t[29];let f;return t[30]!==s||t[31]!==c?(f=(0,$.jsxs)($.Fragment,{children:[s,c]}),t[30]=s,t[31]=c,t[32]=f):f=t[32],f}let x;t[33]===s?x=t[34]:(x=()=>c(!s),t[33]=s,t[34]=x);let S;t[35]===Symbol.for(`react.memo_cache_sentinel`)?(S=z(W.body,`w-full py-2 flex items-center gap-2 font-medium text-foreground hover:bg-muted/50 transition-colors text-left`),t[35]=S):S=t[35];let C;t[36]===o?C=t[37]:(C=o&&(0,$.jsx)(Vc,{size:`md`}),t[36]=o,t[37]=C);let w=v&&b?`Screenshot ${b}`:n.displayName,T;t[38]===w?T=t[39]:(T=(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:w}),t[38]=w,t[39]=T);let E;t[40]===Symbol.for(`react.memo_cache_sentinel`)?(E=z(W.caption,`font-mono text-muted-foreground truncate max-w-[200px] sm:max-w-[320px]`),t[40]=E):E=t[40];let D;t[41]===p?D=t[42]:(D=(0,$.jsx)(`span`,{className:E,children:p}),t[41]=p,t[42]=D);let O;t[43]!==i||t[44]!==v?(O=i&&!v&&(0,$.jsx)(`button`,{type:`button`,className:z(W.caption,`text-brand hover:underline shrink-0`),onClick:e=>{e.stopPropagation(),u(!0)},children:`View results`}),t[43]=i,t[44]=v,t[45]=O):O=t[45];let k;t[46]===v?k=t[47]:(k=v&&(0,$.jsx)(`button`,{type:`button`,className:z(W.caption,`text-brand hover:underline shrink-0`),onClick:e=>{e.stopPropagation(),u(!0)},children:`View screenshot`}),t[46]=v,t[47]=k);let A;t[48]===s?A=t[49]:(A=s?(0,$.jsx)(Ue,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(re,{className:`h-4 w-4 shrink-0`}),t[48]=s,t[49]=A);let j;t[50]!==D||t[51]!==O||t[52]!==k||t[53]!==A||t[54]!==x||t[55]!==C||t[56]!==T?(j=(0,$.jsx)(L,{asChild:!0,children:(0,$.jsxs)(`button`,{onClick:x,className:S,children:[C,T,D,O,k,A]})}),t[50]=D,t[51]=O,t[52]=k,t[53]=A,t[54]=x,t[55]=C,t[56]=T,t[57]=j):j=t[57];let M;t[58]===n.toolName?M=t[59]:(M=(0,$.jsx)(H,{children:n.toolName}),t[58]=n.toolName,t[59]=M);let N;t[60]!==j||t[61]!==M?(N=(0,$.jsxs)(B,{children:[j,M]}),t[60]=j,t[61]=M,t[62]=N):N=t[62];let P;t[63]!==n.toolId||t[64]!==s||t[65]!==h||t[66]!==_||t[67]!==i||t[68]!==b||t[69]!==v||t[70]!==d?(P=s&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border space-y-2`,children:[(0,$.jsxs)(`div`,{className:z(W.compact,`text-muted-foreground font-mono`),children:[`ID: `,n.toolId]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:z(W.compact,`text-muted-foreground mb-1`),children:`Request`}),(0,$.jsx)(`pre`,{className:Mc(),children:h})]}),v?(0,$.jsx)(Go,{imageUrl:v.imageUrl,imageData:v.imageData,threadId:d,alt:b??`Browser screenshot`}):i&&(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:z(W.compact,`text-muted-foreground mb-1`),children:`Response`}),(0,$.jsx)(`pre`,{className:Mc({maxHeight:`64`}),children:_})]})]}),t[63]=n.toolId,t[64]=s,t[65]=h,t[66]=_,t[67]=i,t[68]=b,t[69]=v,t[70]=d,t[71]=P):P=t[71];let F;t[72]!==l||t[73]!==h||t[74]!==p||t[75]!==_||t[76]!==i||t[77]!==b||t[78]!==v||t[79]!==d?(F=v?(0,$.jsx)(ie,{open:l,onOpenChange:u,children:(0,$.jsxs)(We,{className:`max-w-3xl max-h-[85vh] flex flex-col overflow-auto`,children:[(0,$.jsx)(a,{children:(0,$.jsxs)(vt,{children:[`Screenshot `,b]})}),(0,$.jsx)(Go,{imageUrl:v.imageUrl,imageData:v.imageData,threadId:d,alt:b??`Browser screenshot`})]})}):i&&(0,$.jsx)(Pc,{open:l,onOpenChange:u,title:p,requestContent:h,responseContent:_}),t[72]=l,t[73]=h,t[74]=p,t[75]=_,t[76]=i,t[77]=b,t[78]=v,t[79]=d,t[80]=F):F=t[80];let I;return t[81]!==N||t[82]!==P||t[83]!==F?(I=(0,$.jsxs)(`div`,{className:`overflow-hidden`,children:[N,P,F]}),t[81]=N,t[82]=P,t[83]=F,t[84]=I):I=t[84],I}function hl(e){return e.selectedThreadId}function gl(e){let t=(0,X.c)(10),{summary:n,fullSummary:r}=e,i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=z(W.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)(L,{asChild:!0,children:o}),t[3]=o,t[4]=s);let c;t[5]===r?c=t[6]:(c=(0,$.jsx)(H,{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)(B,{children:[s,c]}),t[7]=s,t[8]=c,t[9]=l):l=t[9],l}function _l(e){let t=(0,X.c)(52),{data:n,inline:r,isActive:i}=e,[a,o]=(0,Y.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?dc(n.inputObj,32,e):null,c=n.prompt===null?dc(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)(qc,{children:[(0,$.jsx)(Jc,{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)(Hc,{toolName:n.toolName,displayName:n.displayName,isActive:i,muted:!1})})})}),(0,$.jsx)(Yc,{className:`w-80 max-h-80 overflow-auto`,align:`start`,children:(0,$.jsxs)(`div`,{className:z(W.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)(Hc,{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)(gl,{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)(B,{children:[(0,$.jsx)(L,{asChild:!0,children:(0,$.jsx)(`span`,{className:z(W.caption,`font-mono truncate max-w-[200px] sm:max-w-[320px]`),children:n.path})}),(0,$.jsx)(H,{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]===Symbol.for(`react.memo_cache_sentinel`)?(d=z(W.body,`w-full py-2 flex items-center gap-2 font-medium text-foreground hover:bg-muted/50 transition-colors text-left`),t[24]=d):d=t[24];let f;t[25]===i?f=t[26]:(f=i&&(0,$.jsx)(Vc,{size:`md`}),t[25]=i,t[26]=f);let p;t[27]===n.displayName?p=t[28]:(p=(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:n.displayName}),t[27]=n.displayName,t[28]=p);let m;t[29]===s?m=t[30]:(m=s&&(0,$.jsx)(`span`,{className:z(W.caption,`font-mono text-muted-foreground truncate max-w-[200px] sm:max-w-[320px]`),children:s}),t[29]=s,t[30]=m);let h;t[31]===a?h=t[32]:(h=a?(0,$.jsx)(Ue,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(re,{className:`h-4 w-4 shrink-0`}),t[31]=a,t[32]=h);let g;t[33]!==u||t[34]!==f||t[35]!==p||t[36]!==m||t[37]!==h?(g=(0,$.jsx)(L,{asChild:!0,children:(0,$.jsxs)(`button`,{onClick:u,className:d,children:[f,p,m,h]})}),t[33]=u,t[34]=f,t[35]=p,t[36]=m,t[37]=h,t[38]=g):g=t[38];let _;t[39]===n.toolName?_=t[40]:(_=(0,$.jsx)(H,{children:n.toolName}),t[39]=n.toolName,t[40]=_);let v;t[41]!==g||t[42]!==_?(v=(0,$.jsxs)(B,{children:[g,_]}),t[41]=g,t[42]=_,t[43]=v):v=t[43];let y;t[44]!==n.prompt||t[45]!==n.toolId||t[46]!==n.toolInput||t[47]!==a?(y=a&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border`,children:[(0,$.jsxs)(`div`,{className:z(W.compact,`text-muted-foreground mb-2 font-mono`),children:[`ID: `,n.toolId]}),n.prompt?(0,$.jsx)(`div`,{className:Mc({maxHeight:`64`,padding:`3`,leading:!0}),children:n.prompt}):n.toolInput?(0,$.jsx)(`pre`,{className:Mc(),children:n.toolInput}):null]}),t[44]=n.prompt,t[45]=n.toolId,t[46]=n.toolInput,t[47]=a,t[48]=y):y=t[48];let b;return t[49]!==v||t[50]!==y?(b=(0,$.jsxs)(`div`,{className:`overflow-hidden`,children:[v,y]}),t[49]=v,t[50]=y,t[51]=b):b=t[51],b}function vl(e){let t=(0,X.c)(51),{block:n,inline:r,resultContent:i,isActive:a}=e,{setActiveMainTab:o}=Ks(),{setPendingExplorerPath:s}=Xs(),c=Q(yl),l=yc(n,c),u=!!a,d;t[0]!==o||t[1]!==s?(d=function(e){s(e),o(`explorer`)},t[0]=o,t[1]=s,t[2]=d):d=t[2];let f=d;switch(l.toolType){case`bash`:{let e;return t[3]!==l||t[4]!==r||t[5]!==u||t[6]!==i?(e=(0,$.jsx)(Uc,{data:l,inline:r,resultContent:i,isActive:u}),t[3]=l,t[4]=r,t[5]=u,t[6]=i,t[7]=e):e=t[7],e}case`fetch`:{let e;return t[8]!==l||t[9]!==r||t[10]!==u||t[11]!==i?(e=(0,$.jsx)(Wc,{data:l,inline:r,resultContent:i,isActive:u}),t[8]=l,t[9]=r,t[10]=u,t[11]=i,t[12]=e):e=t[12],e}case`file`:{let e;return t[13]!==l||t[14]!==f||t[15]!==r||t[16]!==u||t[17]!==c?(e=(0,$.jsx)(Qc,{data:l,inline:r,rootPath:c,onOpenFile:f,isActive:u}),t[13]=l,t[14]=f,t[15]=r,t[16]=u,t[17]=c,t[18]=e):e=t[18],e}case`search`:{let e;return t[19]!==l||t[20]!==r||t[21]!==u||t[22]!==i?(e=(0,$.jsx)(nl,{data:l,inline:r,resultContent:i,isActive:u}),t[19]=l,t[20]=r,t[21]=u,t[22]=i,t[23]=e):e=t[23],e}case`agent`:{let e;return t[24]!==l||t[25]!==r||t[26]!==u||t[27]!==i?(e=(0,$.jsx)(il,{data:l,inline:r,resultContent:i,isActive:u}),t[24]=l,t[25]=r,t[26]=u,t[27]=i,t[28]=e):e=t[28],e}case`todo`:{let e;return t[29]!==l||t[30]!==r||t[31]!==u?(e=(0,$.jsx)(ol,{data:l,inline:r,isActive:u}),t[29]=l,t[30]=r,t[31]=u,t[32]=e):e=t[32],e}case`imageGen`:{let e;return t[33]!==l||t[34]!==r||t[35]!==u?(e=(0,$.jsx)(sl,{data:l,inline:r,isActive:u}),t[33]=l,t[34]=r,t[35]=u,t[36]=e):e=t[36],e}case`findImages`:{let e;return t[37]!==l||t[38]!==r||t[39]!==u||t[40]!==i?(e=(0,$.jsx)(ul,{data:l,inline:r,resultContent:i,isActive:u}),t[37]=l,t[38]=r,t[39]=u,t[40]=i,t[41]=e):e=t[41],e}case`browser`:{let e;return t[42]!==l||t[43]!==r||t[44]!==u||t[45]!==i?(e=(0,$.jsx)(ml,{data:l,inline:r,resultContent:i,isActive:u}),t[42]=l,t[43]=r,t[44]=u,t[45]=i,t[46]=e):e=t[46],e}default:{let e;return t[47]!==l||t[48]!==r||t[49]!==u?(e=(0,$.jsx)(_l,{data:l,inline:r,isActive:u}),t[47]=l,t[48]=r,t[49]=u,t[50]=e):e=t[50],e}}}function yl(e){return e.projects.find(t=>t.projectId===e.selectedProjectId)?.threads.find(t=>t.threadId===e.selectedThreadId)?.path}var bl=(0,Y.createContext)({todos:[],setTodos:()=>{}});function xl(e){let t=(0,X.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,Y.useState)(i),s=(0,Y.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,Y.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)(bl.Provider,{value:f,children:n}),t[7]=n,t[8]=f,t[9]=p):p=t[9],p}function Sl(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){console.error(`Failed to parse todo JSON:`,e)}}return null}function Cl(e){let t=(0,X.c)(5),{todos:n,sequence:r}=e,{setTodos:i}=(0,Y.useContext)(bl),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,Y.useEffect)(a,o),null}function wl(e){let t=(0,X.c)(79),{block:n,inline:r,sequence:i}=e,o=i===void 0?0:i,[s,c]=(0,Y.useState)(!1),[l,u]=(0,Y.useState)(!1),d=Q(El),f=Q(Tl),p=n.toolName??`Unknown Tool`,m=n.toolCallId??`unknown`,h=n,g=n.result??h.content,_;t[0]!==h||t[1]!==p?(_=p===`todo`?Sl(h):null,t[0]=h,t[1]=p,t[2]=_):_=t[2];let v=_,y,b,x,S,C,w,T;if(t[3]!==h||t[4]!==r||t[5]!==g||t[6]!==d||t[7]!==o||t[8]!==f||t[9]!==v||t[10]!==p){T=Symbol.for(`react.early_return_sentinel`);bb0:{if(b=p===`find_images`?qo(g,h):null,S=sc(vc(g),d),!(S.length>0)&&v===null&&!b){T=null;break bb0}if(y=ic(p),typeof g==`object`&&g){let e=g,n=e.returnDisplay??e.return_display;if(typeof n==`string`&&n.trim()){let e;t[18]===n?e=t[19]:(e=n.trim(),t[18]=n,t[19]=e),y=e}else if(p===`read`||p===`file_read`){let n=e.filePath??e.file_path??e.path??``;if(n){let e;t[20]===n?e=t[21]:(e=n.split(`/`).pop()??n,t[20]=n,t[21]=e),y=`Completed ${e}`}}}else if(g==null){let e;t[22]===p?e=t[23]:(e=ic(p),t[22]=p,t[23]=e),y=`${e} (no result)`}if(b){let e=b.savedPath?sc(b.savedPath.split(`/`).pop()??b.savedPath,d):null;y=e?`Found ${e}`:`Found image`}if(y=sc(y,d),v!==null){let e;t[24]!==o||t[25]!==v?(e=(0,$.jsx)(Cl,{todos:v,sequence:o}),t[24]=o,t[25]=v,t[26]=e):e=t[26],T=e;break bb0}if(r&&(b||p===`browser`)){T=null;break bb0}if(p===`generate_image`){let e;t[27]!==h||t[28]!==g?(e=Ko(g)??Ko(h),t[27]=h,t[28]=g,t[29]=e):e=t[29];let n=e;if(n&&(n.imageUrl||n.imageData)){let e;t[30]!==n.imageData||t[31]!==n.imageUrl||t[32]!==f?(e=(0,$.jsx)(Go,{imageUrl:n.imageUrl,imageData:n.imageData,threadId:f}),t[30]=n.imageData,t[31]=n.imageUrl,t[32]=f,t[33]=e):e=t[33],T=e;break bb0}}if(r){T=null;break bb0}let e;t[34]===p?e=t[35]:(e=p.toLowerCase().includes(`bash`),t[34]=p,t[35]=e),x=e,C=S?S.split(`
|
|
23
|
-
`):[],w=x?C.slice(0,3).join(`
|
|
24
|
-
`):S}t[3]=h,t[4]=r,t[5]=g,t[6]=d,t[7]=o,t[8]=f,t[9]=v,t[10]=p,t[11]=y,t[12]=b,t[13]=x,t[14]=S,t[15]=C,t[16]=w,t[17]=T}else y=t[11],b=t[12],x=t[13],S=t[14],C=t[15],w=t[16],T=t[17];if(T!==Symbol.for(`react.early_return_sentinel`))return T;let E=w,D=x&&C.length>3;if(x){let e;t[36]===Symbol.for(`react.memo_cache_sentinel`)?(e=z(W.body,`px-3 py-2 flex items-center gap-2 font-medium text-foreground`),t[36]=e):e=t[36];let n;t[37]===y?n=t[38]:(n=(0,$.jsx)(`div`,{className:e,children:(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:y})}),t[37]=y,t[38]=n);let r;t[39]!==D||t[40]!==E||t[41]!==S||t[42]!==C?(r=S&&(0,$.jsxs)(`div`,{className:`px-3 pb-2 bg-background border-t border-border`,children:[D?(0,$.jsxs)(B,{children:[(0,$.jsx)(L,{asChild:!0,children:(0,$.jsxs)(`pre`,{className:z(W.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:()=>u(!0),children:[E,(0,$.jsxs)(`span`,{className:`text-muted-foreground`,children:[`
|
|
25
|
-
`,`...`]})]})}),(0,$.jsx)(H,{children:`Click to see full output`})]}):(0,$.jsx)(`pre`,{className:z(W.caption,`bg-muted p-2 rounded font-mono whitespace-pre-wrap overflow-auto text-foreground text-left mt-2`),children:E}),D&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>u(!0),className:z(W.caption,`mt-1 text-brand hover:underline`),children:[`Show full output (`,C.length,` lines)`]})]}),t[39]=D,t[40]=E,t[41]=S,t[42]=C,t[43]=r):r=t[43];let i;t[44]!==n||t[45]!==r?(i=(0,$.jsxs)(`div`,{className:`mb-3 rounded-lg border border-border bg-muted/50 overflow-hidden`,children:[n,r]}),t[44]=n,t[45]=r,t[46]=i):i=t[46];let o;t[47]!==l||t[48]!==D||t[49]!==S?(o=D&&(0,$.jsx)(ie,{open:l,onOpenChange:u,children:(0,$.jsxs)(We,{className:`max-w-3xl max-h-[80vh] flex flex-col`,children:[(0,$.jsx)(a,{children:(0,$.jsx)(vt,{children:`Full Output`})}),(0,$.jsx)(`pre`,{className:z(W.caption,`bg-muted p-3 rounded font-mono whitespace-pre-wrap overflow-auto flex-1 text-foreground`),children:S})]})}),t[47]=l,t[48]=D,t[49]=S,t[50]=o):o=t[50];let s;return t[51]!==i||t[52]!==o?(s=(0,$.jsxs)($.Fragment,{children:[i,o]}),t[51]=i,t[52]=o,t[53]=s):s=t[53],s}let O;t[54]===s?O=t[55]:(O=()=>c(!s),t[54]=s,t[55]=O);let k;t[56]===Symbol.for(`react.memo_cache_sentinel`)?(k=z(W.body,`w-full px-3 py-2 flex items-center gap-2 font-medium text-foreground hover:bg-muted transition-colors text-left`),t[56]=k):k=t[56];let A;t[57]===y?A=t[58]:(A=(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:y}),t[57]=y,t[58]=A);let j;t[59]===s?j=t[60]:(j=s?(0,$.jsx)(Ue,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(re,{className:`h-4 w-4 shrink-0`}),t[59]=s,t[60]=j);let M;t[61]!==O||t[62]!==A||t[63]!==j?(M=(0,$.jsx)(L,{asChild:!0,children:(0,$.jsxs)(`button`,{onClick:O,className:k,children:[A,j]})}),t[61]=O,t[62]=A,t[63]=j,t[64]=M):M=t[64];let N=`${p} result`,P;t[65]===N?P=t[66]:(P=(0,$.jsx)(H,{children:N}),t[65]=N,t[66]=P);let F;t[67]!==P||t[68]!==M?(F=(0,$.jsxs)(B,{children:[M,P]}),t[67]=P,t[68]=M,t[69]=F):F=t[69];let I;t[70]!==s||t[71]!==b||t[72]!==S||t[73]!==f||t[74]!==m?(I=s&&(0,$.jsxs)(`div`,{className:`px-3 py-2 bg-background border-t border-border`,children:[(0,$.jsxs)(`div`,{className:z(W.compact,`text-muted-foreground mb-2 font-mono`),children:[`Call ID: `,m]}),b&&(0,$.jsx)(Go,{imageUrl:b.imageUrl,imageData:b.imageData,threadId:f}),S&&!b&&(0,$.jsx)(`pre`,{className:z(W.caption,`bg-muted p-2 rounded font-mono whitespace-pre-wrap overflow-auto max-h-48 text-foreground text-left`),children:S})]}),t[70]=s,t[71]=b,t[72]=S,t[73]=f,t[74]=m,t[75]=I):I=t[75];let ee;return t[76]!==F||t[77]!==I?(ee=(0,$.jsxs)(`div`,{className:`mb-3 rounded-lg border border-border bg-muted/50 overflow-hidden`,children:[F,I]}),t[76]=F,t[77]=I,t[78]=ee):ee=t[78],ee}function Tl(e){return e.selectedThreadId}function El(e){return e.projects.find(t=>t.projectId===e.selectedProjectId)?.threads.find(t=>t.threadId===e.selectedThreadId)?.path}var Dl=ei(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})]}),(0,$.jsx)(`div`,{className:e.v5,children:(0,$.jsx)(`div`,{className:`overflow-hidden`,children:e.v6})})]}),{name:`ThinkingBlock_1`,portals:[`v2`,`v4`,`v6`]}),Ol=function(e){let t=(0,X.c)(38),{text:n,isStreaming:r,label:i,threadId:a}=e,o=n===void 0?``:n,s=r===void 0?!1:r,c=(0,Y.useRef)(null),l;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(l=Date.now(),t[0]=l):l=t[0];let u=(0,Y.useRef)(l),[d,f]=(0,Y.useState)(0),[p,m]=(0,Y.useState)(!1),h=(0,Y.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,Y.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,Y.useEffect)(v,y),!o&&!s)return null;let b=!s&&i===`Validated`,x;t[11]!==d||t[12]!==s||t[13]!==i||t[14]!==o?(x=jl(s,i,d,Ot(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]===o?C=t[17]:(C=o?ra(rc(o)):``,t[16]=o,t[17]=C);let w=C,T;t[18]===p?T=t[19]:(T=()=>m(!p),t[18]=p,t[19]=T);let E;t[20]===b?E=t[21]:(E=b?(0,$.jsx)(A,{className:`h-3.5 w-3.5 shrink-0 text-green-600`}):null,t[20]=b,t[21]=E);let D=p?`grid-rows-[1fr]`:`grid-rows-[0fr]`,O;t[22]===D?O=t[23]:(O=[`grid transition-[grid-template-rows] duration-200 ease-in-out`,D],t[22]=D,t[23]=O);let k=O.join(` `),j,M;t[24]===Symbol.for(`react.memo_cache_sentinel`)?(j=z(W.caption,`ml-5 text-muted-foreground/60 overflow-y-auto scrollbar-hide`),M={maxHeight:`7.5em`},t[24]=j,t[25]=M):(j=t[24],M=t[25]);let N;t[26]!==w||t[27]!==a?(N=w?(0,$.jsx)(ls,{content:w,compact:!0,threadId:a}):null,t[26]=w,t[27]=a,t[28]=N):N=t[28];let P;t[29]===N?P=t[30]:(P=(0,$.jsx)(`div`,{ref:c,className:j,style:M,children:N}),t[29]=N,t[30]=P);let F;return t[31]!==p||t[32]!==S||t[33]!==T||t[34]!==E||t[35]!==k||t[36]!==P?(F=(0,$.jsx)(Dl,{v0:T,v1:p,v2:E,v3:W.caption,v4:S,v5:k,v6:P}),t[31]=p,t[32]=S,t[33]=T,t[34]=E,t[35]=k,t[36]=P,t[37]=F):F=t[37],F};function kl(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 Al(e){return` (${e.toLocaleString()} token${e===1?``:`s`})`}function jl(e,t,n,r){let i=e&&r>0?Al(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 ${kl(n)}.`}function Ml(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 Nl(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 Pl(e,t){let n=e.find(e=>na(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 Fl(e,t){return e.some(e=>na(e)&&e.toolCallId===t)}function Il(e,t){if(t)return Pl(e,t)}var Ll=ei(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`]}),Rl=ei(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)(`div`,{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.v5,onChange:e.v6,onKeyDown: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:`button`,onClick:e.v10,disabled:e.v11,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.v12})})]})]}),{name:`AskUserBlock_2`,portals:[`v0`,`v2`,`v3`,`v4`,`v12`]}),zl=function(e){let t=(0,X.c)(54),{toolCallId:n,question:r,options:i,context:a,answeredText:o,answeredLabel:s}=e,[c,l]=(0,Y.useState)(``),[u,d]=(0,Y.useState)(!!o),[f,p]=(0,Y.useState)(o??``),[m,h]=(0,Y.useState)(!1),[g,_]=(0,Y.useState)(null),v,y;t[0]===o?(v=t[1],y=t[2]):(v=()=>{let e=o?.trim();if(e){d(!0),p(e),h(!1),_(null);return}d(!1),p(``)},y=[o],t[0]=o,t[1]=v,t[2]=y),(0,Y.useEffect)(v,y);let b;t[3]!==m||t[4]!==n?(b=async e=>{if(!(!e.trim()||m)){h(!0);try{await V(n,e.trim()),p(e.trim()),d(!0)}catch(e){console.error(`Failed to submit answer:`,e),h(!1),_(null)}}},t[3]=m,t[4]=n,t[5]=b):b=t[5];let x=b,S;t[6]!==x||t[7]!==m||t[8]!==u?(S=e=>{u||m||(_(e),x(e))},t[6]=x,t[7]=m,t[8]=u,t[9]=S):S=t[9];let C=S,w;t[10]!==c||t[11]!==x||t[12]!==m||t[13]!==u?(w=()=>{if(u||m)return;let e=c.trim();e&&x(e)},t[10]=c,t[11]=x,t[12]=m,t[13]=u,t[14]=w):w=t[14];let T=w,E;t[15]===T?E=t[16]:(E=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),T())},t[15]=T,t[16]=E);let D=E;if(u){let e,n;t[17]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(Ze,{className:`h-5 w-5 text-brand shrink-0 mt-0.5`}),n=z(W.label,`text-foreground`),t[17]=e,t[18]=n):(e=t[17],n=t[18]);let i;t[19]===r?i=t[20]:(i=(0,$.jsx)(ls,{content:r}),t[19]=r,t[20]=i);let o;t[21]===a?o=t[22]:(o=a&&(0,$.jsx)(`p`,{className:z(W.bodyMuted,`mt-1`),children:a}),t[21]=a,t[22]=o);let c=s??`You answered`,l;return t[23]!==f||t[24]!==o||t[25]!==c||t[26]!==i?(l=(0,$.jsx)(Ll,{v0:e,v1:n,v2:i,v3:o,v4:W.bodyMuted,v5:c,v6:f}),t[23]=f,t[24]=o,t[25]=c,t[26]=i,t[27]=l):l=t[27],l}let O,k;t[28]===Symbol.for(`react.memo_cache_sentinel`)?(O=(0,$.jsx)(He,{className:`h-5 w-5 text-brand shrink-0 mt-0.5`}),k=z(W.label,`text-foreground`),t[28]=O,t[29]=k):(O=t[28],k=t[29]);let A;t[30]===r?A=t[31]:(A=(0,$.jsx)(ls,{content:r}),t[30]=r,t[31]=A);let j;t[32]===a?j=t[33]:(j=a&&(0,$.jsx)(`p`,{className:z(W.bodyMuted,`mt-1`),children:a}),t[32]=a,t[33]=j);let M;t[34]!==C||t[35]!==m||t[36]!==i||t[37]!==g?(M=i&&i.length>0&&(0,$.jsx)(`div`,{className:`flex flex-wrap gap-2 mb-3`,children:i.map(e=>{let t=g===e;return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>C(e),disabled:m,className:z(`rounded-md border px-3 py-1.5 transition-colors disabled:opacity-50 flex items-center gap-1.5`,W.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)(Ze,{className:`h-3.5 w-3.5 text-foreground`}),e]},e)})}),t[34]=C,t[35]=m,t[36]=i,t[37]=g,t[38]=M):M=t[38];let N;t[39]===Symbol.for(`react.memo_cache_sentinel`)?(N=e=>l(e.target.value),t[39]=N):N=t[39];let P=i?.length?`Or type a custom answer...`:`Type your answer...`,F;t[40]!==c||t[41]!==m?(F=m||!c.trim(),t[40]=c,t[41]=m,t[42]=F):F=t[42];let I;t[43]===Symbol.for(`react.memo_cache_sentinel`)?(I=(0,$.jsx)(Zt,{className:`h-3 w-3`}),t[43]=I):I=t[43];let ee;return t[44]!==c||t[45]!==T||t[46]!==D||t[47]!==m||t[48]!==j||t[49]!==M||t[50]!==P||t[51]!==F||t[52]!==A?(ee=(0,$.jsx)(Rl,{v0:O,v1:k,v2:A,v3:j,v4:M,v5:c,v6:N,v7:D,v8:P,v9:m,v10:T,v11:F,v12:I}),t[44]=c,t[45]=T,t[46]=D,t[47]=m,t[48]=j,t[49]=M,t[50]=P,t[51]=F,t[52]=A,t[53]=ee):ee=t[53],ee},Bl=qn,Vl=Mr,Hl=Ur,Ul=Y.forwardRef((e,t)=>{let n=(0,X.c)(14),r,i,a,o;n[0]===e?(r=n[1],i=n[2],a=n[3],o=n[4]):({className:i,inset:a,children:r,...o}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a,n[4]=o);let s;n[5]!==i||n[6]!==a?(s=z(z(W.body,`flex cursor-default gap-2 select-none items-center rounded-sm px-2 py-1.5 outline-none focus:bg-accent data-[state=open]:bg-accent [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0`),a&&`pl-8`,i),n[5]=i,n[6]=a,n[7]=s):s=n[7];let c;n[8]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,$.jsx)(re,{className:`ml-auto`}),n[8]=c):c=n[8];let l;return n[9]!==r||n[10]!==o||n[11]!==t||n[12]!==s?(l=(0,$.jsxs)(Vr,{ref:t,className:s,...o,children:[r,c]}),n[9]=r,n[10]=o,n[11]=t,n[12]=s,n[13]=l):l=n[13],l});Ul.displayName=Vr.displayName;var Wl=Y.forwardRef((e,t)=>{let n=(0,X.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=z(`z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg 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[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,$.jsx)(Lr,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});Wl.displayName=Lr.displayName;var Gl=Y.forwardRef((e,t)=>{let n=(0,X.c)(11),r,i,a;n[0]===e?(r=n[1],i=n[2],a=n[3]):({className:r,sideOffset:a,...i}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a);let o=a===void 0?4:a,s;n[4]===r?s=n[5]:(s=z(`z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md 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[4]=r,n[5]=s);let c;return n[6]!==i||n[7]!==t||n[8]!==o||n[9]!==s?(c=(0,$.jsx)(Sr,{children:(0,$.jsx)(Br,{ref:t,sideOffset:o,className:s,...i})}),n[6]=i,n[7]=t,n[8]=o,n[9]=s,n[10]=c):c=n[10],c});Gl.displayName=Br.displayName;var Kl=Y.forwardRef((e,t)=>{let n=(0,X.c)(11),r,i,a;n[0]===e?(r=n[1],i=n[2],a=n[3]):({className:r,inset:i,...a}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a);let o;n[4]!==r||n[5]!==i?(o=z(z(W.body,`relative flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0`),i&&`pl-8`,r),n[4]=r,n[5]=i,n[6]=o):o=n[6];let s;return n[7]!==a||n[8]!==t||n[9]!==o?(s=(0,$.jsx)(ir,{ref:t,className:o,...a}),n[7]=a,n[8]=t,n[9]=o,n[10]=s):s=n[10],s});Kl.displayName=ir.displayName;var ql=Y.forwardRef((e,t)=>{let n=(0,X.c)(14),r,i,a,o;n[0]===e?(r=n[1],i=n[2],a=n[3],o=n[4]):({className:a,children:i,checked:r,...o}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a,n[4]=o);let s;n[5]===a?s=n[6]:(s=z(z(W.body,`relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50`),a),n[5]=a,n[6]=s);let c;n[7]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,$.jsx)(`span`,{className:`absolute left-2 flex h-3.5 w-3.5 items-center justify-center`,children:(0,$.jsx)(xr,{children:(0,$.jsx)(Ze,{className:`h-4 w-4`})})}),n[7]=c):c=n[7];let l;return n[8]!==r||n[9]!==i||n[10]!==o||n[11]!==t||n[12]!==s?(l=(0,$.jsxs)(ar,{ref:t,className:s,checked:r,...o,children:[c,i]}),n[8]=r,n[9]=i,n[10]=o,n[11]=t,n[12]=s,n[13]=l):l=n[13],l});ql.displayName=ar.displayName;var Jl=Y.forwardRef((e,t)=>{let n=(0,X.c)(12),r,i,a;n[0]===e?(r=n[1],i=n[2],a=n[3]):({className:i,children:r,...a}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a);let o;n[4]===i?o=n[5]:(o=z(z(W.body,`relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50`),i),n[4]=i,n[5]=o);let s;n[6]===Symbol.for(`react.memo_cache_sentinel`)?(s=(0,$.jsx)(`span`,{className:`absolute left-2 flex h-3.5 w-3.5 items-center justify-center`,children:(0,$.jsx)(xr,{children:(0,$.jsx)(N,{className:`h-2 w-2 fill-current`})})}),n[6]=s):s=n[6];let c;return n[7]!==r||n[8]!==a||n[9]!==t||n[10]!==o?(c=(0,$.jsxs)(pr,{ref:t,className:o,...a,children:[s,r]}),n[7]=r,n[8]=a,n[9]=t,n[10]=o,n[11]=c):c=n[11],c});Jl.displayName=pr.displayName;var Yl=Y.forwardRef((e,t)=>{let n=(0,X.c)(11),r,i,a;n[0]===e?(r=n[1],i=n[2],a=n[3]):({className:r,inset:i,...a}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a);let o=i&&`pl-8`,s;n[4]!==r||n[5]!==o?(s=z(W.body,`px-2 py-1.5 font-semibold`,o,r),n[4]=r,n[5]=o,n[6]=s):s=n[6];let c;return n[7]!==a||n[8]!==t||n[9]!==s?(c=(0,$.jsx)(br,{ref:t,className:s,...a}),n[7]=a,n[8]=t,n[9]=s,n[10]=c):c=n[10],c});Yl.displayName=br.displayName;var Xl=Y.forwardRef((e,t)=>{let n=(0,X.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=z(`-mx-1 my-1 h-px bg-muted`,r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,$.jsx)(Or,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});Xl.displayName=Or.displayName;var Zl=e=>{let t=(0,X.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=z(W.compact,`ml-auto tracking-widest opacity-60`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,$.jsx)(`span`,{className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a};Zl.displayName=`DropdownMenuShortcut`;var Ql=ei(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:`Skipped`})]}),{name:`PermissionPromptBlock_1`,portals:[`v0`,`v2`,`v3`]}),$l=ei(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`]}),eu=function(e){let t=(0,X.c)(41),{icon:n,promptTitle:r,skippedTitle:i,detail:a,wildcardOptions:o,secondaryButtonLabel:c,resolvedDecision:l,onAllowOnce:u,onAllowWildcard:d,onSecondary:f}=e,[p,m]=(0,Y.useState)(!!l),[h,g]=(0,Y.useState)(l??null),[_,v]=(0,Y.useState)(!1),y,b;t[0]===l?(y=t[1],b=t[2]):(y=()=>{l&&(m(!0),g(l),v(!1))},b=[l],t[0]=l,t[1]=y,t[2]=b),(0,Y.useEffect)(y,b);let x;t[3]!==_||t[4]!==u||t[5]!==p?(x=async function(){if(!(_||p)){v(!0);try{await u(),m(!0),g(`allowed`)}catch(e){console.error(`Failed to submit permission response:`,e),v(!1)}}},t[3]=_,t[4]=u,t[5]=p,t[6]=x):x=t[6];let S=x,C;t[7]!==_||t[8]!==d||t[9]!==p?(C=async function(e){if(!(_||p)){v(!0);try{await d(e),m(!0),g(`allowed`)}catch(e){console.error(`Failed to submit permission response:`,e),v(!1)}}},t[7]=_,t[8]=d,t[9]=p,t[10]=C):C=t[10];let w=C,T;t[11]!==_||t[12]!==f||t[13]!==p?(T=async function(){if(!(_||p)){v(!0);try{await f(),m(!0),g(`skipped`)}catch(e){console.error(`Failed to submit permission response:`,e),v(!1)}}},t[11]=_,t[12]=f,t[13]=p,t[14]=T):T=t[14];let E=T;if(p&&h!==`skipped`)return null;if(p){let e;t[15]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(Ze,{className:`h-5 w-5 text-brand shrink-0 mt-0.5`}),t[15]=e):e=t[15];let n;return t[16]!==a||t[17]!==i?(n=(0,$.jsx)(Ql,{v0:e,v1:W.label,v2:i,v3:a,v4:W.bodyMuted}),t[16]=a,t[17]=i,t[18]=n):n=t[18],n}let D;t[19]===S?D=t[20]:(D=()=>void S(),t[19]=S,t[20]=D);let O;t[21]!==_||t[22]!==D?(O=(0,$.jsx)(s,{type:`button`,size:`sm`,disabled:_,onClick:D,className:`rounded-r-none`,children:`Allow`}),t[21]=_,t[22]=D,t[23]=O):O=t[23];let k;t[24]!==w||t[25]!==_||t[26]!==o?(k=o.length>0&&(0,$.jsxs)(Bl,{children:[(0,$.jsx)(Vl,{asChild:!0,children:(0,$.jsx)(s,{type:`button`,size:`sm`,disabled:_,className:z(`rounded-l-none border-l border-primary-foreground/20 px-2`),"aria-label":`More allow options`,children:(0,$.jsx)(Ue,{className:`h-4 w-4`})})}),(0,$.jsx)(Gl,{align:`end`,className:`max-w-md`,children:o.map(e=>(0,$.jsx)(Kl,{onClick:()=>void w(e),children:e.label},`${e.scope}-${e.pattern}`))})]}),t[24]=w,t[25]=_,t[26]=o,t[27]=k):k=t[27];let A;t[28]===E?A=t[29]:(A=()=>void E(),t[28]=E,t[29]=A);let j;t[30]!==_||t[31]!==c||t[32]!==A?(j=(0,$.jsx)(s,{type:`button`,size:`sm`,variant:`outline`,disabled:_,onClick:A,children:c}),t[30]=_,t[31]=c,t[32]=A,t[33]=j):j=t[33];let M;return t[34]!==a||t[35]!==n||t[36]!==r||t[37]!==j||t[38]!==O||t[39]!==k?(M=(0,$.jsx)($l,{v0:n,v1:W.label,v2:r,v3:a,v4:O,v5:k,v6:j}),t[34]=a,t[35]=n,t[36]=r,t[37]=j,t[38]=O,t[39]=k,t[40]=M):M=t[40],M};function tu(e){let t=(0,X.c)(3),{command:n}=e,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=z(W.mono,W.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 nu(e){let t=(0,X.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)(ge,{className:`h-5 w-5 text-brand shrink-0 mt-0.5`}),t[0]=s):s=t[0];let l;t[1]===r?l=t[2]:(l=(0,$.jsx)(tu,{command:r}),t[1]=r,t[2]=l);let u,d;t[3]!==i||t[4]!==n?(u=()=>c(n,`allow_once`,{projectId:i??void 0}),d=e=>c(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]=u,t[6]=d):(u=t[5],d=t[6]);let f;t[7]===n?f=t[8]:(f=()=>c(n,`skip`),t[7]=n,t[8]=f);let p;return t[9]!==o||t[10]!==l||t[11]!==u||t[12]!==d||t[13]!==f||t[14]!==a?(p=(0,$.jsx)(eu,{icon:s,promptTitle:`Allow the agent to run this command?`,skippedTitle:`Shell command permission`,detail:l,wildcardOptions:a,secondaryButtonLabel:`Skip`,resolvedDecision:o,onAllowOnce:u,onAllowWildcard:d,onSecondary:f}),t[9]=o,t[10]=l,t[11]=u,t[12]=d,t[13]=f,t[14]=a,t[15]=p):p=t[15],p}function ru(e){let t=(0,X.c)(9),{hostname:n,url:r}=e,i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=z(W.mono,W.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=z(W.caption,W.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 iu(e){let t=(0,X.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)(On,{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)(ru,{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=()=>Ft(n,`allow_once`),u=e=>Ft(n,e.scope===`project`?`allow_domain_project`:`allow_domain_session`),d=()=>Ft(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)(eu,{icon:s,promptTitle:`Allow the agent to fetch from this domain?`,skippedTitle:`Web fetch permission`,detail:c,wildcardOptions:a,secondaryButtonLabel:`Deny`,resolvedDecision:o,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 au=new Map,ou=new Map;function su(e){return au.get(e)}function cu(e,t){let n=ou.get(e);return n||(n=new Set,ou.set(e,n)),n.add(t),()=>{n.delete(t),n.size===0&&ou.delete(e)}}function lu(e){let t=ou.get(e);if(t)for(let e of t)e()}function uu(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 du(e,t,n){if(au.has(e))return;au.set(e,{status:`running`}),lu(e);let r=Ke();(async()=>{try{let i=uu(r,n),a=Object.getPrototypeOf(async function(){}).constructor,o=await new a(`callTool`,t)(i),s=o===void 0?null:o;au.set(e,{status:`success`,result:s}),lu(e),await Rt(e,s)}catch(t){let n=t instanceof Error?t.stack||t.message:String(t);au.set(e,{status:`error`,error:n}),lu(e);try{await Rt(e,{error:n})}catch(e){console.error(`[browser-js-executor] failed to submit error result`,e)}}})()}var fu=ei(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`]}),pu=ei(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`]}),mu=ei(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`]}),hu=function(e){let t=(0,X.c)(41),{toolCallId:n,intention:r,code:i}=e,a=Q(gu),o;t[0]===n?o=t[1]:(o=su(n),t[0]=n,t[1]=o);let s=o,[c,l]=(0,Y.useState)(s?.status??`running`),u;t[2]===s?u=t[3]:(u=()=>{if(!s||s.status!==`success`)return null;let e=s.result;return e==null?null:typeof e==`string`?e:JSON.stringify(e,null,2)},t[2]=s,t[3]=u);let[d,f]=(0,Y.useState)(u),[p,m]=(0,Y.useState)(s?.error??null),h,g;t[4]===n?(h=t[5],g=t[6]):(h=()=>cu(n,()=>{let e=su(n);if(e)if(l(e.status),e.status===`success`){let t=e.result;f(t==null?null:typeof t==`string`?t:JSON.stringify(t,null,2))}else e.status===`error`&&m(e.error??null)}),g=[n],t[4]=n,t[5]=h,t[6]=g),(0,Y.useEffect)(h,g);let _,v;t[7]!==i||t[8]!==a||t[9]!==n?(_=()=>{a&&du(n,i,a)},v=[n,i,a],t[7]=i,t[8]=a,t[9]=n,t[10]=_,t[11]=v):(_=t[10],v=t[11]),(0,Y.useEffect)(_,v);let[y,b]=(0,Y.useState)(!1),x;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(x=()=>b(_u),t[12]=x):x=t[12];let S=x;if(c===`running`){let e,n;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(e=z(W.label,`w-full py-2 flex items-center gap-2`),n=(0,$.jsx)(Gn,{className:`h-4 w-4 shrink-0 text-brand animate-pulse`}),t[13]=e,t[14]=n):(e=t[13],n=t[14]);let i=r||`Executing Browser JS...`,a;return t[15]===i?a=t[16]:(a=(0,$.jsx)(fu,{v0:e,v1:n,v2:i}),t[15]=i,t[16]=a),a}if(c===`success`){let e,n;t[17]===Symbol.for(`react.memo_cache_sentinel`)?(e=z(W.label,`w-full py-2 flex items-center gap-2 hover:bg-muted/50 transition-colors text-left`),n=(0,$.jsx)(Gn,{className:`h-4 w-4 shrink-0 text-brand`}),t[17]=e,t[18]=n):(e=t[17],n=t[18]);let a=r||`Browser JS Executed Successfully`,o;t[19]===y?o=t[20]:(o=y?(0,$.jsx)(Ue,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(re,{className:`h-4 w-4 shrink-0`}),t[19]=y,t[20]=o);let s;t[21]!==i||t[22]!==y||t[23]!==d?(s=y&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border flex flex-col gap-2`,children:[(0,$.jsx)(`pre`,{className:z(W.bodyMuted,`leading-relaxed whitespace-pre-wrap`),children:i}),d!=null&&(0,$.jsx)(`pre`,{className:z(W.body,`leading-relaxed whitespace-pre-wrap border-t border-border pt-2`),children:d})]}),t[21]=i,t[22]=y,t[23]=d,t[24]=s):s=t[24];let c;return t[25]!==a||t[26]!==o||t[27]!==s?(c=(0,$.jsx)(pu,{v0:S,v1:e,v2:n,v3:a,v4:o,v5:s}),t[25]=a,t[26]=o,t[27]=s,t[28]=c):c=t[28],c}let C,w;t[29]===Symbol.for(`react.memo_cache_sentinel`)?(C=z(W.label,`w-full py-2 flex items-center gap-2 hover:bg-muted/50 transition-colors text-left`),w=(0,$.jsx)(Gn,{className:`h-4 w-4 shrink-0 text-destructive`}),t[29]=C,t[30]=w):(C=t[29],w=t[30]);let T=r||`Browser JS Execution Failed`,E;t[31]===y?E=t[32]:(E=y?(0,$.jsx)(Ue,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(re,{className:`h-4 w-4 shrink-0`}),t[31]=y,t[32]=E);let D;t[33]!==i||t[34]!==p||t[35]!==y?(D=y&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border flex flex-col gap-2`,children:[(0,$.jsx)(`pre`,{className:z(W.bodyMuted,`leading-relaxed whitespace-pre-wrap`),children:p}),(0,$.jsx)(`pre`,{className:z(W.bodyMuted,`leading-relaxed whitespace-pre-wrap`),children:i})]}),t[33]=i,t[34]=p,t[35]=y,t[36]=D):D=t[36];let O;return t[37]!==T||t[38]!==E||t[39]!==D?(O=(0,$.jsx)(mu,{v0:S,v1:C,v2:w,v3:T,v4:E,v5:D}),t[37]=T,t[38]=E,t[39]=D,t[40]=O):O=t[40],O};function gu(e){return e.selectedThreadId}function _u(e){return!e}function vu(e){let t=(0,X.c)(69),{toolCall:n,className:r}=e,i=Ia(),[a,o]=(0,Y.useState)(!1),s;t[0]===n.id?s=t[1]:(s=e=>e.toolCallProgress[n.id],t[0]=n.id,t[1]=s);let c=Q(s),l=Q(Su),u=Q(xu),d;t[2]!==n.activeDisplayName||t[3]!==n.name?(d=n.activeDisplayName??oe(n.name),t[2]=n.activeDisplayName,t[3]=n.name,t[4]=d):d=t[4];let f=d;if(!l)return null;let p;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(p=()=>{o(bu)},t[5]=p):p=t[5];let m=p,h;t[6]!==i||t[7]!==u||t[8]!==n.id||t[9]!==n.name?(h=()=>{i({type:Z.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:Z.AppendStreamChunk,chunkType:`content`,content:JSON.stringify([e]),segments:u})},t[6]=i,t[7]=u,t[8]=n.id,t[9]=n.name,t[10]=h):h=t[10];let g=h,_=yu,v=n.name===`bash`&&typeof n.input?.command==`string`?n.input.command:null,y;t[11]===v?y=t[12]:(y=v===null?null:oc(v),t[11]=v,t[12]=y);let b=y,x=n.name===`fetch`&&typeof n.input?.url==`string`?n.input.url:null,S=n.name===`web_search`&&typeof n.input?.query==`string`?n.input.query:null,C=!v&&typeof n.input?.description==`string`?n.input.description:null,w;t[13]===r?w=t[14]:(w=z(`overflow-hidden mb-2`,r),t[13]=r,t[14]=w);let T;t[15]===Symbol.for(`react.memo_cache_sentinel`)?(T=(0,$.jsx)(Vc,{}),t[15]=T):T=t[15];let E;t[16]===f?E=t[17]:(E=(0,$.jsx)(L,{asChild:!0,children:(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[T,(0,$.jsx)(`span`,{className:W.bodyMuted,children:f})]})}),t[16]=f,t[17]=E);let D;t[18]===n.name?D=t[19]:(D=(0,$.jsx)(H,{children:n.name}),t[18]=n.name,t[19]=D);let O;t[20]!==E||t[21]!==D?(O=(0,$.jsxs)(B,{children:[E,D]}),t[20]=E,t[21]=D,t[22]=O):O=t[22];let k;t[23]===b?k=t[24]:(k=b!==null&&(0,$.jsx)(`code`,{className:z(W.mono,W.bodyMuted,`truncate whitespace-nowrap rounded bg-muted/60 px-1 py-0.5 max-w-full`),children:b.label}),t[23]=b,t[24]=k);let A;t[25]===x?A=t[26]:(A=x!==null&&(0,$.jsx)(`code`,{className:z(W.mono,W.bodyMuted,`break-all rounded bg-muted/60 px-1 py-0.5`),children:x.length>60?`${x.slice(0,59)}…`:x}),t[25]=x,t[26]=A);let j;t[27]===S?j=t[28]:(j=S!==null&&(0,$.jsx)(`code`,{className:z(W.mono,W.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]=j);let M;t[29]===C?M=t[30]:(M=C!==null&&(0,$.jsx)(`span`,{className:W.bodyMuted,children:C}),t[29]=C,t[30]=M);let N;t[31]!==v||t[32]!==C||t[33]!==x||t[34]!==S?(N=!v&&!x&&!S&&!C&&(0,$.jsx)(`span`,{className:W.bodyMuted,children:`running`}),t[31]=v,t[32]=C,t[33]=x,t[34]=S,t[35]=N):N=t[35];let P;t[36]===a?P=t[37]:(P=(0,$.jsx)(L,{asChild:!0,children:(0,$.jsx)(`button`,{onClick:m,className:`p-1 hover:bg-muted/50 rounded transition-colors`,children:a?(0,$.jsx)(ln,{className:`h-3 w-3`}):(0,$.jsx)(Ue,{className:`h-3 w-3`})})}),t[36]=a,t[37]=P);let F=a?`Collapse`:`Expand`,I;t[38]===F?I=t[39]:(I=(0,$.jsx)(H,{children:F}),t[38]=F,t[39]=I);let ee;t[40]!==P||t[41]!==I?(ee=(0,$.jsxs)(B,{children:[P,I]}),t[40]=P,t[41]=I,t[42]=ee):ee=t[42];let te;t[43]===Symbol.for(`react.memo_cache_sentinel`)?(te=(0,$.jsx)(zn,{className:`h-3 w-3`}),t[43]=te):te=t[43];let R;t[44]===g?R=t[45]:(R=(0,$.jsx)(L,{asChild:!0,children:(0,$.jsx)(`button`,{onClick:g,className:`p-1 hover:bg-red-200 dark:hover:bg-red-800 rounded transition-colors text-red-600 dark:text-red-400`,children:te})}),t[44]=g,t[45]=R);let ne;t[46]===Symbol.for(`react.memo_cache_sentinel`)?(ne=(0,$.jsx)(H,{className:`bg-red-600 text-white border-red-600`,children:`Stop this process`}),t[46]=ne):ne=t[46];let re;t[47]===R?re=t[48]:(re=(0,$.jsxs)(B,{children:[R,ne]}),t[47]=R,t[48]=re);let ie;t[49]!==ee||t[50]!==re?(ie=(0,$.jsxs)(`div`,{className:`flex items-center gap-1 ml-auto shrink-0`,children:[ee,re]}),t[49]=ee,t[50]=re,t[51]=ie):ie=t[51];let ae;t[52]!==O||t[53]!==k||t[54]!==A||t[55]!==j||t[56]!==M||t[57]!==N||t[58]!==ie?(ae=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 flex-wrap`,children:[O,k,A,j,M,N,ie]}),t[52]=O,t[53]=k,t[54]=A,t[55]=j,t[56]=M,t[57]=N,t[58]=ie,t[59]=ae):ae=t[59];let se;t[60]!==a||t[61]!==n.id||t[62]!==n.input||t[63]!==c?(se=a&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border min-h-[8rem] overflow-auto`,children:[(0,$.jsxs)(`div`,{className:z(W.compact,W.bodyMuted,`mb-2 font-mono`),children:[`ID: `,n.id]}),(0,$.jsxs)(`div`,{className:`mb-2`,children:[(0,$.jsx)(`div`,{className:z(W.compact,W.label,`text-muted-foreground mb-1`),children:`Input:`}),(0,$.jsx)(`pre`,{className:Mc({className:`border border-border`}),children:_(n.input)})]}),c&&(0,$.jsxs)(`div`,{className:`mb-2`,children:[(0,$.jsx)(`div`,{className:z(W.compact,W.label,`text-muted-foreground mb-1`),children:`Progress:`}),(0,$.jsxs)(`div`,{className:z(W.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:z(W.mono,`text-green-700 dark:text-green-300`),children:c.delta}),c.partial?.content?.[0]?.arguments&&typeof c.partial.content[0].arguments==`object`&&`content`in c.partial.content[0].arguments&&typeof c.partial.content[0].arguments.content==`string`&&(0,$.jsxs)(`div`,{className:z(W.mono,`mt-1 text-green-600 dark:text-green-400`),children:[`Building: `,c.partial.content[0].arguments.content.slice(-50),c.partial.content[0].arguments.content.length>50&&`...`]})]})]}),(0,$.jsxs)(`div`,{className:z(W.compact,`flex items-center gap-1.5 text-muted-foreground`),children:[(0,$.jsx)(Vc,{}),`Executing`,c&&` with progress`,`...`]})]}),t[60]=a,t[61]=n.id,t[62]=n.input,t[63]=c,t[64]=se):se=t[64];let ce;return t[65]!==ae||t[66]!==se||t[67]!==w?(ce=(0,$.jsxs)(`div`,{className:w,children:[ae,se]}),t[65]=ae,t[66]=se,t[67]=w,t[68]=ce):ce=t[68],ce}function yu(e){return JSON.stringify(e,null,2)}function bu(e){return!e}function xu(e){return e.streamingSegments}function Su(e){return e.isStreaming}function Cu(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 wu(e){return e.type!==`subagent_event`||!e.subagentEvent?null:Tu(e.subagentEvent)}function Tu(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?Eu(e.content):null;case`shell_permission`:{let t=e.shellPermission?.command?.trim();return t?`\n⏳ Waiting for shell approval: ${t}\n`:`
|
|
26
|
-
⏳ Waiting for shell approval…
|
|
27
|
-
`}case`web_fetch_permission`:{let t=e.webFetchPermission?.hostname?.trim();return t?`\n⏳ Waiting for approval to fetch ${t}\n`:`
|
|
28
|
-
⏳ Waiting for web fetch approval…
|
|
29
|
-
`}case`error`:return e.content?`\n${e.content}`:null;default:return null}}function Eu(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(`✓\n\n\`\`\`\n${r}${e}\n\`\`\`\n`)}}return n.length>0?n.join(``):null}catch{return null}}function Du(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 Ou(e){return{intention:typeof e.intention==`string`?e.intention:``,code:typeof e.code==`string`?e.code:``}}function ku(e){let t=(0,X.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)(zl,{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 Au(e){let t=(0,X.c)(5),{prompt:n,projectId:r}=e,i;return t[0]!==r||t[1]!==n.command||t[2]!==n.toolCallId||t[3]!==n.wildcardOptions?(i=(0,$.jsx)(nu,{toolCallId:n.toolCallId,command:n.command,projectId:r,wildcardOptions:n.wildcardOptions}),t[0]=r,t[1]=n.command,t[2]=n.toolCallId,t[3]=n.wildcardOptions,t[4]=i):i=t[4],i}function ju(e){let t=(0,X.c)(6),{prompt:n,projectId:r}=e,i;return t[0]!==r||t[1]!==n.hostname||t[2]!==n.toolCallId||t[3]!==n.url||t[4]!==n.wildcardOptions?(i=(0,$.jsx)(iu,{toolCallId:n.toolCallId,hostname:n.hostname,url:n.url,projectId:r,wildcardOptions:n.wildcardOptions}),t[0]=r,t[1]=n.hostname,t[2]=n.toolCallId,t[3]=n.url,t[4]=n.wildcardOptions,t[5]=i):i=t[5],i}function Mu(e,t){if(e.name!==`ask_user`)return null;let n=Du(e.input);return(0,$.jsx)(zl,{toolCallId:e.id,question:n.question,options:n.options,context:n.context,answeredText:t})}function Nu(e){if(e.name!==`run_js`&&e.name!==`run_web_worker`)return null;let t=Ou(e.input);return(0,$.jsx)(hu,{toolCallId:e.id,intention:t.intention,code:t.code})}function Pu(e){let t=(0,X.c)(12),{block:n,resultContent:r}=e,i;t[0]===n.id?i=t[1]:(i=e=>e.toolCallProgress[n.id],t[0]=n.id,t[1]=i);let a=Q(i),o;t[2]===a?o=t[3]:(o=a??{},t[2]=a,t[3]=o);let s;t[4]===o?s=t[5]:(s=Nl(o),t[4]=o,t[5]=s);let c=s,l=r===void 0,u=n.name===`bash`||n.name===`read`||n.name===`file_read`||Cu(n.name,n.input);if(l&&!u){let e;return t[6]===n?e=t[7]:(e=(0,$.jsx)(vu,{toolCall:n}),t[6]=n,t[7]=e),e}let d=l?c:r,f;return t[8]!==n||t[9]!==l||t[10]!==d?(f=(0,$.jsx)(vl,{inline:!0,block:n,resultContent:d,isActive:l}),t[8]=n,t[9]=l,t[10]=d,t[11]=f):f=t[11],f}function Fu(e){let t=(0,X.c)(11),{block:n,showActive:r,resultContent:i}=e,a;t[0]!==n||t[1]!==i?(a=Mu(n,i),t[0]=n,t[1]=i,t[2]=a):a=t[2];let o=a;if(o)return o;let s;t[3]===n?s=t[4]:(s=Nu(n),t[3]=n,t[4]=s);let c=s;if(c)return c;if(r){let e;return t[5]!==n||t[6]!==i?(e=(0,$.jsx)(Pu,{block:n,resultContent:i}),t[5]=n,t[6]=i,t[7]=e):e=t[7],e}let l;return t[8]!==n||t[9]!==i?(l=(0,$.jsx)(vl,{inline:!0,block:n,resultContent:i,isActive:!1}),t[8]=n,t[9]=i,t[10]=l):l=t[10],l}function Iu(e){let t=(0,X.c)(3),{block:n,sequence:r}=e,i;return t[0]!==n||t[1]!==r?(i=(0,$.jsx)(wl,{inline:!0,sequence:r,block:n}),t[0]=n,t[1]=r,t[2]=i):i=t[2],i}function Lu(e){if(ba(e)){let t=e.text.slice(0,128);return`thinking-${e.label??`none`}-${Ml(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??Ml(e.prompt.question)}`;case`shell_permission`:return`shell-${e.prompt.toolCallId}`;case`web_fetch_permission`:return`fetch-${e.prompt.toolCallId}`;case`text`:return`text-${Ml(e.text.slice(0,128))}`}}function Ru(e,t,n){let{lookupBlocks:r,isStreaming:i,threadId:a,projectId:o,messageIndex:s}=n;if(ta(e)&&e.name===`todo`)return null;if(na(e)){if(e.toolName===`todo`)return(0,$.jsx)(Iu,{sequence:s,block:e},t);if(e.toolName===`ask_user`)return null}switch(e.type){case`long_running_confirmation`:return(0,$.jsx)(ku,{prompt:e.prompt,answeredText:Il(r,e.prompt.toolCallId)},t);case`shell_permission`:return(0,$.jsx)(Au,{prompt:e.prompt,projectId:o},t);case`web_fetch_permission`:return(0,$.jsx)(ju,{prompt:e.prompt,projectId:o},t);case`text`:return(0,$.jsx)(js,{content:e.text,threadId:a},t);case`tool_use`:{let n=Pl(r,e.id);return(0,$.jsx)(Fu,{block:e,showActive:i&&!Fl(r,e.id),resultContent:n},t)}case`tool-result`:return(0,$.jsx)(Iu,{block:e},t)}}function zu(e){let t=(0,X.c)(8),{blocks:n,isStreaming:r,threadId:i,projectId:a,messageIndex:o}=e,s=r===void 0?!1:r,c=o===void 0?0:o,l;t[0]!==n||t[1]!==s||t[2]!==c||t[3]!==a||t[4]!==i?(l=xa(n,s).map(e=>{let t=Lu(e);return ba(e)?(0,$.jsx)(Ol,{text:e.text,label:e.label,isStreaming:e.isCurrentlyStreaming,threadId:i},t):Ru(e,t,{lookupBlocks:n,isStreaming:s,threadId:i,projectId:a,messageIndex:c})}),t[0]=n,t[1]=s,t[2]=c,t[3]=a,t[4]=i,t[5]=l):l=t[5];let u;return t[6]===l?u=t[7]:(u=(0,$.jsx)($.Fragment,{children:l}),t[6]=l,t[7]=u),u}var Bu=ei(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`]}),Vu=function(e){let t=(0,X.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:da(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?ia(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=z(`group px-4 py-4`,m),t[6]=m,t[7]=h);let g=l&&`items-end`,_;t[8]===g?_=t[9]:(_=z(`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)(Bs,{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=z(`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)(Hu,{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)(Vs,{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)(Is,{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)(Bu,{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 Hu(e){let t=(0,X.c)(14),{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)(zu,{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=z(W.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)(js,{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]!==i||t[8]!==a||t[9]!==r?(e=(0,$.jsx)(zu,{blocks:a,threadId:r,messageIndex:i}),t[7]=i,t[8]=a,t[9]=r,t[10]=e):e=t[10],e}let s;return t[11]!==n.content||t[12]!==r?(s=(0,$.jsx)(js,{content:n.content,threadId:r,className:W.body}),t[11]=n.content,t[12]=r,t[13]=s):s=t[13],s}function Uu(e){let t=(0,Y.useRef)(new Map);return(0,Y.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`?ia(a)??[]:da(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 Wu=ei(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:`Agent`}),e.v2]}),e.v3]})}),{name:`StreamingMessage_1`,portals:[`v2`,`v3`]}),Gu=function(e){let t=(0,X.c)(16),{segments:n,model:r,threadId:i,projectId:a,isCreatingProject:o,isProcessingThread:s,totalMessages:c,showProcessingLine:l}=e,u=c===void 0?0:c,d=l===void 0?!1:l,f=Uu(n),p=d?`pb-0`:`pb-4`,m;t[0]===p?m=t[1]:(m=z(`group px-4 pt-4`,p),t[0]=p,t[1]=m);let h;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(h=z(W.compact,`font-medium text-foreground`),t[2]=h):h=t[2];let g;t[3]===r?g=t[4]:(g=r&&(0,$.jsxs)(`span`,{className:z(W.compact,`flex items-center gap-1 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity`),children:[(0,$.jsx)(Gn,{className:`h-2.5 w-2.5`}),hi(r)]}),t[3]=r,t[4]=g);let _;t[5]!==o||t[6]!==s||t[7]!==f||t[8]!==a||t[9]!==i||t[10]!==u?(_=f.length>0?(0,$.jsx)(`div`,{className:`flex flex-col gap-0.5 min-w-0 text-base`,children:(0,$.jsx)(zu,{blocks:f,isStreaming:!0,threadId:i,projectId:a,messageIndex:u})}):o||s?(0,$.jsx)(`div`,{className:`min-w-0`,children:(0,$.jsx)(Ol,{isStreaming:!0})}):null,t[5]=o,t[6]=s,t[7]=f,t[8]=a,t[9]=i,t[10]=u,t[11]=_):_=t[11];let v;return t[12]!==m||t[13]!==g||t[14]!==_?(v=(0,$.jsx)(Wu,{v0:m,v1:h,v2:g,v3:_}),t[12]=m,t[13]=g,t[14]=_,t[15]=v):v=t[15],v},Ku=3e3;function qu(e){let t=[...dn],n=e?t.filter(t=>t!==e):t;return n[Math.floor(Math.random()*n.length)]}function Ju(e){let t=(0,X.c)(3),[n,r]=(0,Y.useState)(Jt),i=(0,Y.useRef)(Jt),a,o;return t[0]===e?(a=t[1],o=t[2]):(a=()=>{if(!e){r(Jt),i.current=Jt;return}let t=setInterval(()=>{let e=i.current===`Processing...`?qu():qu(i.current);i.current=e,r(e)},Ku);return()=>clearInterval(t)},o=[e],t[0]=e,t[1]=a,t[2]=o),(0,Y.useEffect)(a,o),n}function Yu(e){let t=(0,X.c)(8),{active:n,className:r}=e,i=n===void 0?!0:n,a=Ju(i),o=i?`animate-shimmer`:void 0,s;t[0]===o?s=t[1]:(s=z(W.caption,o),t[0]=o,t[1]=s);let c;t[2]!==a||t[3]!==s?(c=(0,$.jsx)(`span`,{className:s,children:a}),t[2]=a,t[3]=s,t[4]=c):c=t[4];let l;return t[5]!==r||t[6]!==c?(l=(0,$.jsx)(`div`,{className:r,"aria-live":`polite`,"aria-busy":`true`,children:c}),t[5]=r,t[6]=c,t[7]=l):l=t[7],l}var Xu=ei(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`]}),Zu=function(e){let t=(0,X.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=z(W.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)(S,{className:`h-5 w-5 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`${W.body} text-foreground leading-snug font-medium`,children:e.name}),(0,$.jsxs)(`span`,{className:W.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 d;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,$.jsx)(m,{className:`h-5 w-5 text-muted-foreground`}),t[8]=d):d=t[8];let f;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,$.jsx)(be,{className:`h-5 w-5 text-muted-foreground`}),t[9]=f):f=t[9];let p;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,$.jsx)(Ne,{className:`h-5 w-5 text-muted-foreground`}),t[10]=p):p=t[10];let h;return t[11]!==a||t[12]!==o||t[13]!==s||t[14]!==l||t[15]!==u?(h=(0,$.jsx)(Xu,{v0:c,v1:`mt-1 ${W.pageSubtitle}`,v2:l,v3:u,v4:a,v5:d,v6:`${W.body} text-foreground leading-snug font-medium`,v7:W.caption,v8:o,v9:f,v10:`${W.body} text-foreground leading-snug font-medium`,v11:W.caption,v12:s,v13:p,v14:`${W.body} text-foreground leading-snug font-medium`,v15:W.caption}),t[11]=a,t[12]=o,t[13]=s,t[14]=l,t[15]=u,t[16]=h):h=t[16],h},Qu=(0,Y.createContext)(null);function $u(e){let t=(0,X.c)(7),{children:n}=e,[r,i]=(0,Y.useState)(null),[a,o]=(0,Y.useState)(!1),[s,c]=(0,Y.useState)(!1),l;t[0]!==s||t[1]!==a||t[2]!==r?(l={devServerUrl:r,setDevServerUrl:i,devServerRunning:a,setDevServerRunning:o,devServerLoading:s,setDevServerLoading:c},t[0]=s,t[1]=a,t[2]=r,t[3]=l):l=t[3];let u=l,d;return t[4]!==n||t[5]!==u?(d=(0,$.jsx)(Qu.Provider,{value:u,children:n}),t[4]=n,t[5]=u,t[6]=d):d=t[6],d}function ed(){let e=(0,Y.useContext)(Qu);if(!e)throw Error(`useDevServer must be used within a DevServerProvider`);return e}function td(e){e.onTerminalMessage?.(`✓ Server running at: ${e.url}`),e.setDevServerUrl(e.url),e.setActiveMainTab(`browser`)}function nd(e){return typeof e==`object`&&!!e&&e.type===`url`&&typeof e.url==`string`}function rd(){let e=Q(e=>e.selectedThreadId),{dispatch:t}=La(e),{setActiveMainTab:n}=Ks(),{setDevServerUrl:r,setDevServerRunning:i,setDevServerLoading:a}=ed();return{startServer:async o=>{if(!o?.runCommand||!o?.projectId)return;a(!0),t({type:Z.ClearTerminalOutput}),t({type:Z.SetTerminalOpen,open:!1}),t({type:Z.AppendTerminalLine,line:{type:`system`,content:`Starting dev server: ${o.runCommand}`}});let s=!1,c=setTimeout(()=>{s=!0,t({type:Z.SetTerminalOpen,open:!0})},3e3);try{let l=await Mn(o.projectId,e??void 0);if(!l){clearTimeout(c),t({type:Z.AppendTerminalLine,line:{type:`error`,content:`Failed to start dev server`}}),a(!1);return}let u=l.getReader(),d=new TextDecoder;i(!0),a(!1);let f=!1,p=!1;for(;;){let{done:e,value:i}=await u.read();if(e)break;let o=d.decode(i,{stream:!0});try{let e=o.split(`
|
|
30
|
-
`).filter(e=>e.trim());for(let i of e)try{let e=JSON.parse(i);p||(p=!0,a(!1)),nd(e)&&e.url&&(clearTimeout(c),td({url:e.url,setDevServerUrl:r,setActiveMainTab:n,onTerminalMessage:e=>{t({type:Z.AppendTerminalLine,line:{type:`system`,content:e}})}}),s&&setTimeout(()=>{t({type:Z.SetTerminalOpen,open:!1})},100),f=!0)}catch{}}catch{}}f||t({type:Z.AppendTerminalLine,line:{type:`system`,content:`Server is running but URL could not be detected`}})}catch(e){console.error(`Failed to start dev server:`,e),a(!1),t({type:Z.AppendTerminalLine,line:{type:`error`,content:`Failed to start dev server`}})}},setServerUrl:r}}var id=3e4,ad=2e3;function od(e){let{devServerRunning:t,setDevServerRunning:n,devServerLoading:r}=ed(),i=(0,Y.useRef)(!1);return(0,Y.useEffect)(()=>{e&&(i.current=!1,(async()=>{try{n((await Yt(e)).isRunning)}catch{n(!1)}finally{i.current=!0}})())},[e,n]),(0,Y.useEffect)(()=>{if(!e||!r)return;let t=Date.now(),i=setInterval(()=>{if(Date.now()-t>id){clearInterval(i);return}Yt(e).then(e=>{e.isRunning&&(n(!0),clearInterval(i))}).catch(()=>{})},ad);return()=>clearInterval(i)},[e,r,n]),{isRunning:t,isLoading:r,recheck:(0,Y.useCallback)(async()=>{if(e)try{n((await Yt(e)).isRunning)}catch{n(!1)}},[e,n])}}var sd=ei(e=>(0,$.jsx)(`div`,{className:`flex-1 flex flex-col items-center justify-center`,children:(0,$.jsxs)(`div`,{className:`flex 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]})}),{name:`ChatMessagesPlaceholder_1`,portals:[`v1`,`v3`,`v4`]}),cd=function(e){let t=(0,X.c)(14),{project:n}=e,{isRunning:r}=od(n?.projectId),{startServer:i}=rd();n?.name;let a=n?.name??`your project`,o;t[0]===a?o=t[1]:(o=ld(a),t[0]=a,t[1]=o);let s=o,c=!r&&n?.runCommand,l;t[2]!==n||t[3]!==i?(l=()=>{n&&i(n)},t[2]=n,t[3]=i,t[4]=l):l=t[4];let u=l,d;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(d=z(W.pageTitle,`tracking-tight text-foreground text-balance`),t[5]=d):d=t[5];let f=n?.name??`Project`,p;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(p=z(W.pageSubtitle,`mt-2`),t[6]=p):p=t[6];let m;t[7]!==u||t[8]!==c?(m=c&&(0,$.jsx)(`button`,{type:`button`,onClick:u,className:z(W.label,`inline-flex items-center gap-2 rounded-full bg-primary px-4 py-2 text-primary-foreground hover:bg-primary/90 transition-colors`),children:`Start App`}),t[7]=u,t[8]=c,t[9]=m):m=t[9];let h;return t[10]!==s||t[11]!==f||t[12]!==m?(h=(0,$.jsx)(sd,{v0:d,v1:f,v2:p,v3:s,v4:m}),t[10]=s,t[11]=f,t[12]=m,t[13]=h):h=t[13],h};function ld(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 ud({virtuosoRef:e,selectedThreadId:t,messagesLoaded:n,messageCount:r,isStreaming:i,hasPendingMessage:a,streamingSegmentCount:o}){let s=(0,Y.useRef)(0),c=(0,Y.useRef)(!1),l=(0,Y.useRef)(!1),u=(0,Y.useRef)(!1),d=(0,Y.useRef)(0),f=(0,Y.useRef)(null),p=(0,Y.useCallback)(()=>{t&&e.current?.getState(e=>{Bt(t,e.scrollTop)})},[t,e]),m=(0,Y.useRef)(p);m.current=p;function h(){u.current&&m.current()}(0,Y.useEffect)(()=>{function e(){h()}return window.addEventListener(`beforeunload`,e),()=>{window.removeEventListener(`beforeunload`,e)}},[t]),(0,Y.useEffect)(()=>{let e=setInterval(()=>{h()},5e3);return()=>clearInterval(e)},[t]),(0,Y.useEffect)(()=>()=>{f.current&&clearTimeout(f.current)},[]),(0,Y.useEffect)(()=>{l.current=!1,u.current=!1,s.current=0},[t]),(0,Y.useEffect)(()=>{if(!t||!n||r===0||l.current)return;l.current=!0,s.current=r;let i=Bn(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,Y.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:_}}var dd=(0,Y.createContext)(void 0);function fd(e){let t=(0,X.c)(12),{paneId:n,conversationId:r,fillPane:i,children:a}=e,o=i===void 0?!1:i,s=Ia(),c=Q(pd),l;t[0]!==s||t[1]!==n?(l=()=>{s({type:Z.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)(dd.Provider,{value:p,children:a}),t[9]=a,t[10]=p,t[11]=m):m=t[11],m}function pd(e){return e.focusedPane}function md(){let e=(0,X.c)(1),t=(0,Y.useContext)(dd);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:hd},e[0]=t):t=e[0],t}return t}function hd(){}var gd=`md:mr-4`;function _d(e){return e?`w-full min-w-0 px-4`:`mx-auto max-w-3xl w-full min-w-0`}function vd(e,t){return e?z(`relative w-full min-w-0 pl-4`,gd):z(`relative mx-auto max-w-3xl`,t?`w-full min-w-0`:`w-[90vw] min-w-[400px]`)}function yd(e,t){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`:e?`relative w-full min-w-0 pb-2 md:pb-4`:z(`relative mx-auto w-full max-w-3xl max-md:px-0 pb-2 md:pl-4 md:pb-4 md:-ml-[6px]`,gd)}function bd(e){return e.isCreatingProject||e.streamingSegmentCount>0?!0:e.lastMessageSender===`user`}function xd(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 Sd(e){return{bottomInset:e.bottomInset,columnClassName:e.columnClassName,isStreaming:e.isStreaming,isCreatingProject:e.isCreatingProject,isProcessingThread:e.isProcessingThread,hasPendingMessage:e.hasPendingMessage,hasActiveBlockingPrompt:wa(e.streamingSegments),selectedProjectId:e.selectedProjectId,selectedThreadId:e.selectedThreadId,streamingSegments:e.streamingSegments,streamingModel:e.streamingModel,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=>xd({isUser:t.sender===`user`,hasCheckpointRef:!!t.checkpointRef,isStreaming:e.isStreaming,hasPendingMessage:e.hasPendingMessage,isCreatingProject:e.isCreatingProject,isProcessingThread:e.isProcessingThread})}}function Cd(e){let t=(0,Y.forwardRef)((t,n)=>{let r=(0,X.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}function wd(e){let t=(0,X.c)(28),{context:n}=e;if(!n)return null;let{bottomInset:r,isStreaming:i,isCreatingProject:a,isProcessingThread:o,hasPendingMessage:s,hasActiveBlockingPrompt:c,selectedProjectId:l,selectedThreadId:u,streamingSegments:d,streamingModel:f,totalMessages:p,lastMessageSender:m,error:h,onClearError:g}=n,_=d.length>0||a||o&&(i||s),v;t[0]!==a||t[1]!==m||t[2]!==d.length?(v=bd({isCreatingProject:a,streamingSegmentCount:d.length,lastMessageSender:m}),t[0]=a,t[1]=m,t[2]=d.length,t[3]=v):v=t[3];let y=v,b=_&&(i||a||o)&&y,x=(i||s)&&!c&&y,S;t[4]===r?S=t[5]:(S={paddingBottom:r},t[4]=r,t[5]=S);let C;t[6]!==a||t[7]!==o||t[8]!==l||t[9]!==u||t[10]!==b||t[11]!==x||t[12]!==f||t[13]!==d||t[14]!==p?(C=b&&(0,$.jsx)(Gu,{segments:d,model:f,threadId:u,projectId:l,isCreatingProject:a,isProcessingThread:o,totalMessages:p,showProcessingLine:x}),t[6]=a,t[7]=o,t[8]=l,t[9]=u,t[10]=b,t[11]=x,t[12]=f,t[13]=d,t[14]=p,t[15]=C):C=t[15];let w;t[16]!==b||t[17]!==x?(w=x&&(0,$.jsx)(`div`,{className:z(`px-4 pb-4`,b?`pt-0`:`pt-2`),children:(0,$.jsx)(Yu,{active:x})}),t[16]=b,t[17]=x,t[18]=w):w=t[18];let T;t[19]!==h||t[20]!==g?(T=h&&(0,$.jsxs)(`div`,{className:`mx-4 my-2`,children:[(0,$.jsx)(di,{variant:`error`,className:`mb-0`,children:h}),(0,$.jsx)(`button`,{type:`button`,className:z(W.compact,`mt-1 text-destructive underline underline-offset-2 hover:text-destructive/80`),onClick:g,children:`Dismiss`})]}),t[19]=h,t[20]=g,t[21]=T):T=t[21];let E;return t[22]!==n.columnClassName||t[23]!==S||t[24]!==C||t[25]!==w||t[26]!==T?(E=(0,$.jsxs)(`div`,{className:n.columnClassName,style:S,children:[C,w,T]}),t[22]=n.columnClassName,t[23]=S,t[24]=C,t[25]=w,t[26]=T,t[27]=E):E=t[27],E}function Td(e,t,n){return(0,$.jsx)(Vu,{message:t,threadId:n.selectedThreadId,messageIndex:e,showCheckpointRestore:n.showCheckpointRestore(t),checkpointRestoreTooltip:n.getCheckpointTooltip(t)})}var Ed=(0,Y.forwardRef)(function(e,t){let n=(0,X.c)(56),{bottomInset:r,messages:i,isStreaming:a,streamingSegments:o,streamingModel:s,isCreatingProject:c,isProcessingThread:l,hasPendingMessage:u,selectedThreadId:d,selectedProjectId:f,projects:p,projectsLoading:m,messagesLoaded:h,onSelectThread:g,onCreateThread:_,onConnectRepo:v,onNewApp:y,onOpenFolder:b,error:x,onClearError:S,onAtBottomChange:C,hideEmptyState:w}=e,T=r===void 0?0:r,E=w===void 0?!1:w,{fillPane:D}=md(),O;n[0]===D?O=n[1]:(O=_d(D),n[0]=D,n[1]=O);let k=O,A=(0,Y.useRef)(null),j;n[2]===k?j=n[3]:(j=Cd(k),n[2]=k,n[3]=j);let M;n[4]===j?M=n[5]:(M={List:j,Footer:wd},n[4]=j,n[5]=M);let N=M,P;n[6]===Symbol.for(`react.memo_cache_sentinel`)?(P=()=>({scrollToBottom:()=>{A.current?.scrollTo({top:2**53-1,behavior:`smooth`})}}),n[6]=P):P=n[6],(0,Y.useImperativeHandle)(t,P);let F;n[7]!==u||n[8]!==a||n[9]!==i.length||n[10]!==h||n[11]!==d||n[12]!==o.length?(F={virtuosoRef:A,selectedThreadId:d,messagesLoaded:h,messageCount:i.length,isStreaming:a,hasPendingMessage:u,streamingSegmentCount:o.length},n[7]=u,n[8]=a,n[9]=i.length,n[10]=h,n[11]=d,n[12]=o.length,n[13]=F):F=n[13];let{onRangeChanged:I,onScrollingStateChange:ee}=ud(F),L=!E&&i.length===0&&!a&&!c&&!d,te=!E&&h&&i.length===0&&!a&&!c&&!l&&!u&&d,R;if(n[14]!==p||n[15]!==f){let e;n[17]===f?e=n[18]:(e=e=>e.projectId===f,n[17]=f,n[18]=e),R=p.find(e),n[14]=p,n[15]=f,n[16]=R}else R=n[16];let ne=R,re=i.length>0?i[i.length-1].sender:null,ie;n[19]!==T||n[20]!==k||n[21]!==x||n[22]!==u||n[23]!==c||n[24]!==l||n[25]!==a||n[26]!==re||n[27]!==i.length||n[28]!==S||n[29]!==f||n[30]!==d||n[31]!==s||n[32]!==o?(ie=Sd({bottomInset:T,columnClassName:k,isStreaming:a,isCreatingProject:c,isProcessingThread:l,hasPendingMessage:u,streamingSegments:o,selectedProjectId:f,selectedThreadId:d,streamingModel:s,totalMessages:i.length,lastMessageSender:re,error:x,onClearError:S}),n[19]=T,n[20]=k,n[21]=x,n[22]=u,n[23]=c,n[24]=l,n[25]=a,n[26]=re,n[27]=i.length,n[28]=S,n[29]=f,n[30]=d,n[31]=s,n[32]=o,n[33]=ie):ie=n[33];let ae=ie;if(L){let e=`flex-1 transition-opacity duration-500 ease-in-out ${m?`opacity-0`:`opacity-100`}`,t;n[34]!==v||n[35]!==_||n[36]!==y||n[37]!==b||n[38]!==g||n[39]!==p?(t=(0,$.jsx)(Zu,{projects:p,onSelectProject:g,onCreateThread:_,onConnectRepo:v,onNewApp:y,onOpenFolder:b}),n[34]=v,n[35]=_,n[36]=y,n[37]=b,n[38]=g,n[39]=p,n[40]=t):t=n[40];let r;return n[41]!==e||n[42]!==t?(r=(0,$.jsx)(`div`,{className:`flex-1 flex flex-col items-center overflow-hidden`,children:(0,$.jsx)(`div`,{className:e,children:t})}),n[41]=e,n[42]=t,n[43]=r):r=n[43],r}if(te){let e;return n[44]===ne?e=n[45]:(e=(0,$.jsx)(cd,{project:ne}),n[44]=ne,n[45]=e),e}let oe;n[46]===Symbol.for(`react.memo_cache_sentinel`)?(oe=z(`h-full overflow-hidden`),n[46]=oe):oe=n[46];let se=d??void 0,ce;n[47]===Symbol.for(`react.memo_cache_sentinel`)?(ce={height:`100%`},n[47]=ce):ce=n[47];let le;return n[48]!==i||n[49]!==C||n[50]!==I||n[51]!==ee||n[52]!==se||n[53]!==N||n[54]!==ae?(le=(0,$.jsx)(`div`,{className:oe,children:(0,$.jsx)(Fr,{ref:A,style:ce,data:i,computeItemKey:Dd,context:ae,itemContent:Td,overscan:500,components:N,atBottomStateChange:C,rangeChanged:I,isScrolling:ee},se)}),n[48]=i,n[49]=C,n[50]=I,n[51]=ee,n[52]=se,n[53]=N,n[54]=ae,n[55]=le):le=n[55],le});function Dd(e,t){return t.messageId}var Od={onboarding:{status:()=>[`onboarding`,`status`]},app:{update:()=>[`app`,`update`]},models:{enabled:e=>[`models`,`enabled`,e]},userTasks:e=>[`user-tasks`,e]};function kd(e){let t=(0,X.c)(10),r;t[0]===e?r=t[1]:(r=Od.models.enabled(e),t[0]=e,t[1]=r);let i;t[2]===r?i=t[3]:(i={queryKey:r,queryFn:n,placeholderData:qr},t[2]=r,t[3]=i);let a=Wr(i),o;bb0:{if(!a.data){let e;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(e=[],t[4]=e):e=t[4],o=e;break bb0}let e;t[5]===a.data?e=t[6]:(e=Object.values(a.data).flat(),t[5]=a.data,t[6]=e),o=e}let s=o,c;return t[7]!==s||t[8]!==a?(c={...a,models:s},t[7]=s,t[8]=a,t[9]=c):c=t[9],c}function Ad(e,t){return t===`secondary`?`${e}:secondary`:e}function jd(e){let t=(0,X.c)(113),n;t[0]===e?n=t[1]:(n=e===void 0?{}:e,t[0]=e,t[1]=n);let{initialValue:r}=n,i=Ia(),{paneId:a}=md(),o=Q(Bd),s=Q(zd),c=Q(Rd),l=Q(Ld),u=Q(Id),d=Q(Fd),f=Q(Pd),p=Q(Nd),{models:m,isFetched:h}=kd(d),g;t[2]!==u||t[3]!==r||t[4]!==a||t[5]!==o?(g=()=>{if(o){let e=Ad(o,a);if(u[e])return u[e]}return r??``},t[2]=u,t[3]=r,t[4]=a,t[5]=o,t[6]=g):g=t[6];let[_,v]=(0,Y.useState)(g),[y,b]=(0,Y.useState)(-1),[x,S]=(0,Y.useState)(``),[C,w]=(0,Y.useState)(0),T=(0,Y.useRef)(_),E,D;t[7]===_?(E=t[8],D=t[9]):(E=()=>{T.current=_},D=[_],t[7]=_,t[8]=E,t[9]=D),(0,Y.useEffect)(E,D);let O=(0,Y.useRef)(u),k,A;t[10]===u?(k=t[11],A=t[12]):(k=()=>{O.current=u},A=[u],t[10]=u,t[11]=k,t[12]=A),(0,Y.useEffect)(k,A);let j=(0,Y.useRef)(!0),N,P;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(N=()=>(j.current=!0,()=>{j.current=!1}),P=[],t[13]=N,t[14]=P):(N=t[13],P=t[14]),(0,Y.useEffect)(N,P);let F;t[15]===Symbol.for(`react.memo_cache_sentinel`)?(F=[],t[15]=F):F=t[15];let[I,ee]=(0,Y.useState)(F),L;t[16]!==l||t[17]!==o?(L=()=>(o?l[o]:void 0)??null,t[16]=l,t[17]=o,t[18]=L):L=t[18];let[te,R]=(0,Y.useState)(L),ne=(0,Y.useRef)(te?.id??``),re=(0,Y.useRef)(te?.provider??``),ie=(0,Y.useRef)(null),[ae,oe]=(0,Y.useState)(!1),[se,ce]=(0,Y.useState)(!1),z;t[19]===Symbol.for(`react.memo_cache_sentinel`)?(z=[],t[19]=z):z=t[19];let[le,ue]=(0,Y.useState)(z),[de,fe]=(0,Y.useState)(!1),[B,pe]=(0,Y.useState)(!1),[V,me]=(0,Y.useState)(!1),he;t[20]===Symbol.for(`react.memo_cache_sentinel`)?(he=[],t[20]=he):he=t[20];let[ge,_e]=(0,Y.useState)(he),[H,be]=(0,Y.useState)(null),xe;t[21]===Symbol.for(`react.memo_cache_sentinel`)?(xe=[],t[21]=xe):xe=t[21];let[Se,Ce]=(0,Y.useState)(xe),[we,U]=(0,Y.useState)(!1),[Te,Ee]=(0,Y.useState)(``),[De,Oe]=(0,Y.useState)(0),ke;t[22]===Symbol.for(`react.memo_cache_sentinel`)?(ke=[],t[22]=ke):ke=t[22];let[Ae,je]=(0,Y.useState)(ke),Me;t[23]===Symbol.for(`react.memo_cache_sentinel`)?(Me=[],t[23]=Me):Me=t[23];let[Ne,Pe]=(0,Y.useState)(Me),Fe;t[24]===Symbol.for(`react.memo_cache_sentinel`)?(Fe=[],t[24]=Fe):Fe=t[24];let[Ie,Le]=(0,Y.useState)(Fe),[Re,ze]=(0,Y.useState)(!1),[Be,Ve]=(0,Y.useState)(!1),[He,W]=(0,Y.useState)(``),Ue=(0,Y.useRef)(null),We=(0,Y.useRef)(null),Ge=(0,Y.useRef)(null),Ke=(0,Y.useRef)(null),qe=(0,Y.useRef)(null),Je=(0,Y.useRef)(null),Ye;t[25]!==te?.id||t[26]!==te?.provider?(Ye=()=>{ne.current=te?.id??``,re.current=te?.provider??``},t[25]=te?.id,t[26]=te?.provider,t[27]=Ye):Ye=t[27];let Xe=te?.id,Ze=te?.provider,Qe;t[28]!==Xe||t[29]!==Ze?(Qe=[Xe,Ze],t[28]=Xe,t[29]=Ze,t[30]=Qe):Qe=t[30],(0,Y.useEffect)(Ye,Qe);let $e;t[31]!==i||t[32]!==o?($e=(e,t)=>{R(e);let n=o;if(!n||(i({type:Z.SetProjectModel,threadId:n,model:e}),t?.persist===!1))return;let r=`${n}:${e.provider??``}:${e.id}`;ie.current!==r&&(ie.current=r,console.log(`[useChatInputState] Persisting model to thread:`,{threadId:n,model:{id:e.id,provider:e.provider}}),M(n,{model:e.id,modelProvider:e.provider}).then(()=>{ie.current===r&&(ie.current=null),console.log(`[useChatInputState] Model persisted successfully`)}).catch(e=>{ie.current===r&&(ie.current=null),console.error(`Failed to save model to thread:`,e)}))},t[31]=i,t[32]=o,t[33]=$e):$e=t[33];let et=$e,tt,nt;t[34]!==m||t[35]!==h||t[36]!==l||t[37]!==c||t[38]!==et||t[39]!==s||t[40]!==o?(tt=()=>{let e=s?c.find(e=>e.projectId===s)?.threads.find(e=>e.threadId===o):void 0,t=o?l[o]:void 0,n=e?.model??t?.id??null,r=e?.modelProvider??t?.provider??null;if(m.length===0){h&&(ee([]),R(null));return}ee(m);let i=n&&r?m.find(e=>e.id===n&&e.provider===r)??null:null,a=m[0],u=i??a,d=!i&&!!(n||r),f=ne.current===u.id&&re.current===u.provider;if(!m.some(e=>e.id===ne.current&&e.provider===re.current)&&ne.current){et(a,{persist:!0});return}f||et(u,{persist:d})},nt=[o,s,c,l,m,h,et],t[34]=m,t[35]=h,t[36]=l,t[37]=c,t[38]=et,t[39]=s,t[40]=o,t[41]=tt,t[42]=nt):(tt=t[41],nt=t[42]),(0,Y.useEffect)(tt,nt);let rt,it;t[43]!==ge.length||t[44]!==V?(rt=()=>{!V||ge.length>0||(async()=>{try{let e=await ye(),t=Object.values(e).flat();t.length>0&&(_e(t),be(e=>e??t[0]))}catch(e){console.error(`Failed to load image models:`,e)}})()},it=[V,ge.length],t[43]=ge.length,t[44]=V,t[45]=rt,t[46]=it):(rt=t[45],it=t[46]),(0,Y.useEffect)(rt,it);let[at,ot]=(0,Y.useState)(o),st,G;t[47]!==i||t[48]!==a||t[49]!==at||t[50]!==o?(st=()=>{if(o!==at){at&&T.current.trim()&&O.current[Ad(at,a)]!==T.current&&i({type:Z.SetChatInputDraft,threadId:Ad(at,a),draft:T.current});let e=!1;return queueMicrotask(()=>{e||!j.current||(ot(o),v(o?O.current[Ad(o,a)]??``:``),Ce([]),U(!1),je([]),Pe([]),Le([]),ze(!1),Ve(!1),fe(!1),me(!1),pe(!1))}),()=>{e=!0}}},G=[o,at,a,i],t[47]=i,t[48]=a,t[49]=at,t[50]=o,t[51]=st,t[52]=G):(st=t[51],G=t[52]),(0,Y.useEffect)(st,G);let ct,lt;t[53]===o?(ct=t[54],lt=t[55]):(ct=()=>{o&&ve(o).then(e=>{let{commands:t,skills:n,bundledSkills:r}=e;console.log(`Loaded slash commands:`,t,`skills:`,n,`bundled:`,r),je(t),Pe(n),Le(r)}).catch(Md)},lt=[o],t[53]=o,t[54]=ct,t[55]=lt),(0,Y.useEffect)(ct,lt);let ut;t[56]!==u||t[57]!==a||t[58]!==o?(ut=o?u[Ad(o,a)]??``:``,t[56]=u,t[57]=a,t[58]=o,t[59]=ut):ut=t[59];let dt=ut,ft;t[60]!==o||t[61]!==dt?(ft=()=>{o&&v(dt)},t[60]=o,t[61]=dt,t[62]=ft):ft=t[62];let pt;t[63]!==a||t[64]!==o||t[65]!==dt?(pt=[o,dt,a],t[63]=a,t[64]=o,t[65]=dt,t[66]=pt):pt=t[66],(0,Y.useEffect)(ft,pt);let mt;t[67]===Symbol.for(`react.memo_cache_sentinel`)?(mt=()=>{let e=We.current;if(!e)return;e.style.height=`auto`;let t=Math.max(e.scrollHeight,e.offsetHeight);e.style.height=`${Math.min(t,160)}px`},t[67]=mt):mt=t[67];let ht;t[68]===_?ht=t[69]:(ht=[_],t[68]=_,t[69]=ht),(0,Y.useLayoutEffect)(mt,ht);let gt,_t;t[70]!==i||t[71]!==f||t[72]!==p||t[73]!==o?(gt=()=>{f&&o&&!p&&(We.current?.focus(),i({type:Z.ClearFocusChatInput}))},_t=[f,o,p,i],t[70]=i,t[71]=f,t[72]=p,t[73]=o,t[74]=gt,t[75]=_t):(gt=t[74],_t=t[75]),(0,Y.useEffect)(gt,_t);let vt,yt;t[76]!==i||t[77]!==a||t[78]!==o?(vt=()=>{let e=o,t=e?Ad(e,a):null;return()=>{t&&T.current.trim()&&O.current[t]!==T.current&&i({type:Z.SetChatInputDraft,threadId:t,draft:T.current})}},yt=[o,a,i],t[76]=i,t[77]=a,t[78]=o,t[79]=vt,t[80]=yt):(vt=t[79],yt=t[80]),(0,Y.useEffect)(vt,yt);let bt,xt;t[81]!==ae||t[82]!==se?(bt=()=>{let e=e=>{Ge.current&&!Ge.current.contains(e.target)&&oe(!1),Ke.current&&!Ke.current.contains(e.target)&&ce(!1)};if(ae||se)return document.addEventListener(`mousedown`,e),()=>{document.removeEventListener(`mousedown`,e)}},xt=[ae,se],t[81]=ae,t[82]=se,t[83]=bt,t[84]=xt):(bt=t[83],xt=t[84]),(0,Y.useEffect)(bt,xt);let St;return t[85]!==Se||t[86]!==le||t[87]!==ge||t[88]!==I||t[89]!==Re||t[90]!==Ie||t[91]!==He||t[92]!==C||t[93]!==i||t[94]!==x||t[95]!==y||t[96]!==V||t[97]!==_||t[98]!==de||t[99]!==B||t[100]!==et||t[101]!==H||t[102]!==De||t[103]!==te||t[104]!==o||t[105]!==Be||t[106]!==ae||t[107]!==se||t[108]!==we||t[109]!==Ne||t[110]!==Ae||t[111]!==Te?(St={message:_,setMessage:v,historyIndex:y,setHistoryIndex:b,draftMessage:x,setDraftMessage:S,cursorPosition:C,setCursorPosition:w,availableModels:I,setAvailableModels:ee,selectedModel:te,setSelectedModel:et,selectedModelIdRef:ne,showModelMenu:ae,setShowModelMenu:oe,showPlusMenu:se,setShowPlusMenu:ce,attachments:le,setAttachments:ue,planMode:de,setPlanMode:fe,ralphMode:B,setRalphMode:pe,imageMode:V,setImageMode:me,availableImageModels:ge,setAvailableImageModels:_e,selectedImageModel:H,setSelectedImageModel:be,allFiles:Se,setAllFiles:Ce,showSuggestions:we,setShowSuggestions:U,suggestionQuery:Te,setSuggestionQuery:Ee,selectedIndex:De,setSelectedIndex:Oe,slashCommands:Ae,setSlashCommands:je,skills:Ne,setSkills:Pe,bundledSkills:Ie,setBundledSkills:Le,bundledSkillMode:Re,setBundledSkillMode:ze,showCommandSuggestions:Be,setShowCommandSuggestions:Ve,commandQuery:He,setCommandQuery:W,fileInputRef:Ue,textareaRef:We,modelMenuRef:Ge,plusMenuRef:Ke,suggestionsRef:qe,commandSuggestionsRef:Je,selectedThreadId:o,dispatch:i},t[85]=Se,t[86]=le,t[87]=ge,t[88]=I,t[89]=Re,t[90]=Ie,t[91]=He,t[92]=C,t[93]=i,t[94]=x,t[95]=y,t[96]=V,t[97]=_,t[98]=de,t[99]=B,t[100]=et,t[101]=H,t[102]=De,t[103]=te,t[104]=o,t[105]=Be,t[106]=ae,t[107]=se,t[108]=we,t[109]=Ne,t[110]=Ae,t[111]=Te,t[112]=St):St=t[112],St}function Md(e){return console.error(`Failed to load slash commands and skills:`,e)}function Nd(e){return e.isStreaming}function Pd(e){return e.focusChatInput}function Fd(e){return e.configUpdatedAt}function Id(e){return e.chatInputDrafts}function Ld(e){return e.projectModelSelections}function Rd(e){return e.projects}function zd(e){return e.selectedProjectId}function Bd(e){return e.selectedThreadId}var Vd=e=>{dt(e)};function Hd(e,t){return t===`secondary`?`${e}:secondary`:e}function Ud(e){let t=(0,X.c)(116),{message:n,setMessage:r,userTasks:i,onMatchedUserTaskSend:a,attachments:o,selectedModel:s,onSend:c,isStreaming:l,selectedThreadId:u,isListening:d,stopListening:f,resetTranscript:p,dispatch:m,historyIndex:h,setHistoryIndex:g,draftMessage:_,setDraftMessage:v,cursorPosition:y,setCursorPosition:b,showSuggestions:x,setShowSuggestions:S,suggestionQuery:C,setSuggestionQuery:w,allFiles:T,setAllFiles:E,selectedIndex:D,setSelectedIndex:O,showCommandSuggestions:k,setShowCommandSuggestions:A,commandQuery:j,setCommandQuery:M,slashCommands:N,skills:P,bundledSkills:F,bundledSkillMode:I,setBundledSkillMode:ee,textareaRef:L,setAttachments:te,planMode:R,setPlanMode:ne,ralphMode:re,setRalphMode:ie,imageMode:ae,setImageMode:oe,selectedImageModel:se,hasConversationMessages:ce}=e,{paneId:z}=md(),le;t[0]!==o||t[1]!==m||t[2]!==ae||t[3]!==d||t[4]!==l||t[5]!==n||t[6]!==a||t[7]!==c||t[8]!==z||t[9]!==R||t[10]!==re||t[11]!==p||t[12]!==se||t[13]!==s||t[14]!==u||t[15]!==te||t[16]!==v||t[17]!==g||t[18]!==r||t[19]!==f||t[20]!==L||t[21]!==i?(le=()=>{if(!n.trim()&&o.length===0||!u)return;let e=ae?se:s;if(!e)return;d&&(f(),p()),l?m({type:Z.EnqueueChatMessage,message:{id:`queued-${Date.now()}`,threadId:u,paneId:z,message:n,model:e.id,attachments:o,provider:e.provider,planMode:R,imageMode:ae,ralphMode:re}}):c(n,e.id,o,e.provider,R,ae,re);let t=n,h=i.find(e=>e.content===t);Vd(n),r(``),te([]),h&&a?.(h),g(-1),v(``),u&&m({type:Z.ClearChatInputDraft,threadId:Hd(u,z)}),L.current&&(L.current.style.height=`auto`)},t[0]=o,t[1]=m,t[2]=ae,t[3]=d,t[4]=l,t[5]=n,t[6]=a,t[7]=c,t[8]=z,t[9]=R,t[10]=re,t[11]=p,t[12]=se,t[13]=s,t[14]=u,t[15]=te,t[16]=v,t[17]=g,t[18]=r,t[19]=f,t[20]=L,t[21]=i,t[22]=le):le=t[22];let ue=le,de;t[23]!==y||t[24]!==n||t[25]!==r||t[26]!==S||t[27]!==C||t[28]!==L?(de=e=>{let t=n.substring(0,y-C.length-1);r(`${t}${e} ${n.substring(y)}`),S(!1),setTimeout(()=>{if(L.current){L.current.focus();let n=t.length+e.length+1;L.current.setSelectionRange(n,n)}},0)},t[23]=y,t[24]=n,t[25]=r,t[26]=S,t[27]=C,t[28]=L,t[29]=de):de=t[29];let fe=de,B;t[30]!==j||t[31]!==y||t[32]!==n||t[33]!==oe||t[34]!==r||t[35]!==ne||t[36]!==ie||t[37]!==A||t[38]!==L?(B=e=>{let t=e.metadata.action===`compact`?`/compact`:e.content,i=n.substring(0,y-j.length-1);r(`${i}${t}${n.substring(y)}`),A(!1),setTimeout(()=>{if(L.current){L.current.focus();let e=i.length+t.length;L.current.setSelectionRange(e,e)}},0),e.metadata.mode===`plan`?(ne(!0),ie(!1),oe(!1)):e.metadata.mode===`ralph`&&(ie(!0),ne(!1),oe(!1))},t[30]=j,t[31]=y,t[32]=n,t[33]=oe,t[34]=r,t[35]=ne,t[36]=ie,t[37]=A,t[38]=L,t[39]=B):B=t[39];let pe=B,V;t[40]!==I||t[41]!==j||t[42]!==y||t[43]!==n||t[44]!==ee||t[45]!==r||t[46]!==A||t[47]!==L?(V=e=>{let t=I?j.length+2:j.length+1,i=n.substring(0,y-t),a=n.substring(y),o=e.scope===`bundled`?`//${e.name}`:e.name.includes(` `)?`/"${e.name}"`:`/${e.name}`;r(`${i}${o}${a}`),A(!1),ee(!1),setTimeout(()=>{if(L.current){L.current.focus();let e=i.length+o.length;L.current.setSelectionRange(e,e)}},0)},t[40]=I,t[41]=j,t[42]=y,t[43]=n,t[44]=ee,t[45]=r,t[46]=A,t[47]=L,t[48]=V):V=t[48];let me=V,he,ge,_e,H;if(t[49]!==T||t[50]!==I||t[51]!==F||t[52]!==j||t[53]!==_||t[54]!==ue||t[55]!==ce||t[56]!==h||t[57]!==pe||t[58]!==fe||t[59]!==me||t[60]!==n||t[61]!==D||t[62]!==u||t[63]!==E||t[64]!==ee||t[65]!==M||t[66]!==b||t[67]!==v||t[68]!==g||t[69]!==r||t[70]!==O||t[71]!==A||t[72]!==S||t[73]!==w||t[74]!==k||t[75]!==x||t[76]!==P||t[77]!==N||t[78]!==C){_e=e=>{if(k){if(e.key===`ArrowDown`){e.preventDefault(),O((D+1)%he.length);return}if(e.key===`ArrowUp`){e.preventDefault(),O((D-1+he.length)%he.length);return}if(e.key===`Enter`||e.key===`Tab`){e.preventDefault();let t=he[D];t&&(t.type===`command`?pe(t.data):me(t.data));return}if(e.key===`Escape`){A(!1);return}}if(x){let t=ge.length>0;if(e.key===`ArrowDown`&&t){e.preventDefault(),O((D+1)%ge.length);return}if(e.key===`ArrowUp`&&t){e.preventDefault(),O((D-1+ge.length)%ge.length);return}if(e.key===`Enter`||e.key===`Tab`){e.preventDefault(),ge[D]&&fe(ge[D]);return}if(e.key===`Escape`){S(!1);return}}if(e.key===`Enter`&&!e.shiftKey){e.preventDefault(),ue();return}let t=Dt();t.length!==0&&(e.key===`ArrowUp`?(e.preventDefault(),h===-1?(v(n),g(t.length-1),r(t[t.length-1])):h>0&&(g(h-1),r(t[h-1]))):e.key===`ArrowDown`&&(e.preventDefault(),h>0?(g(h-1),r(t[h-1])):h===0&&(g(-1),r(_))))};let e;t[83]!==T||t[84]!==u||t[85]!==E||t[86]!==ee||t[87]!==M||t[88]!==b||t[89]!==r||t[90]!==O||t[91]!==A||t[92]!==S||t[93]!==w?(e=e=>{let t=e.target.value,n=e.target.selectionStart;r(t),b(n);let i=t.substring(0,n),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(` `)){M(t),ee(!0),A(!0),S(!1),O(0);let n=e.target;n.style.height=`auto`,n.style.height=`${Math.min(n.scrollHeight,160)}px`;return}}}ee(!1);let o=i.lastIndexOf(`/`);if(o!==-1){let e=o>0?i[o-1]:``;if(o===0||/\s/.test(e)){let e=i.substring(o+1);e.includes(` `)?A(!1):(M(e),A(!0),S(!1),O(0))}else A(!1)}else{A(!1);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(` `)?S(!1):(w(t),S(!0),O(0),T.length===0&&u&&De(u).then(e=>{E(e)}).catch(Kd))}else S(!1)}else S(!1)}let s=e.target;s.style.height=`auto`,s.style.height=`${Math.min(s.scrollHeight,160)}px`},t[83]=T,t[84]=u,t[85]=E,t[86]=ee,t[87]=M,t[88]=b,t[89]=r,t[90]=O,t[91]=A,t[92]=S,t[93]=w,t[94]=e):e=t[94],H=e;let i;if(t[95]!==I||t[96]!==F||t[97]!==j||t[98]!==ce||t[99]!==P||t[100]!==N){let e;t[102]!==j||t[103]!==ce?(e=e=>e.metadata.action===`compact`&&!ce?!1:e.name.toLowerCase().includes(j.toLowerCase()),t[102]=j,t[103]=ce,t[104]=e):e=t[104];let n=N.filter(e),r=I?F:P,a;t[105]===j?a=t[106]:(a=e=>e.name.toLowerCase().includes(j.toLowerCase()),t[105]=j,t[106]=a);let o=r.filter(a);i=[...I?[]:n.map(Gd),...o.map(Wd)],t[95]=I,t[96]=F,t[97]=j,t[98]=ce,t[99]=P,t[100]=N,t[101]=i}else i=t[101];he=i.slice(0,10),ge=x?T.filter(e=>e.toLowerCase().includes(C.toLowerCase())).slice(0,10):[],t[49]=T,t[50]=I,t[51]=F,t[52]=j,t[53]=_,t[54]=ue,t[55]=ce,t[56]=h,t[57]=pe,t[58]=fe,t[59]=me,t[60]=n,t[61]=D,t[62]=u,t[63]=E,t[64]=ee,t[65]=M,t[66]=b,t[67]=v,t[68]=g,t[69]=r,t[70]=O,t[71]=A,t[72]=S,t[73]=w,t[74]=k,t[75]=x,t[76]=P,t[77]=N,t[78]=C,t[79]=he,t[80]=ge,t[81]=_e,t[82]=H}else he=t[79],ge=t[80],_e=t[81],H=t[82];let ve;return t[107]!==he||t[108]!==ge||t[109]!==_e||t[110]!==ue||t[111]!==H||t[112]!==pe||t[113]!==fe||t[114]!==me?(ve={handleSend:ue,handleKeyDown:_e,handleTextareaInput:H,insertFileReference:fe,insertCommand:pe,insertSkill:me,allSuggestions:he,fileSuggestions:ge},t[107]=he,t[108]=ge,t[109]=_e,t[110]=ue,t[111]=H,t[112]=pe,t[113]=fe,t[114]=me,t[115]=ve):ve=t[115],ve}function Wd(e){return{type:`skill`,data:e}}function Gd(e){return{type:`command`,data:e}}function Kd(e){return console.error(`Failed to fetch files:`,e)}var qd=768;function Jd(){let e=(0,X.c)(2),[t,n]=Y.useState(Yd),r,i;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=()=>{let e=window.matchMedia(`(max-width: ${qd-1}px)`),t=()=>{n(window.innerWidth<qd)};return e.addEventListener(`change`,t),n(window.innerWidth<qd),()=>e.removeEventListener(`change`,t)},i=[],e[0]=r,e[1]=i):(r=e[0],i=e[1]),Y.useEffect(r,i),t}function Yd(){return typeof window>`u`?!1:window.innerWidth<qd}function Xd(){let e=(0,X.c)(18),t=Ia(),n=Q($d),r=Q(Qd),i=Q(Zd),a=Jd(),o,s;e[0]!==t||e[1]!==n||e[2]!==a?(o=()=>{a&&n&&t({type:Z.DisableDualChat})},s=[t,n,a],e[0]=t,e[1]=n,e[2]=a,e[3]=o,e[4]=s):(o=e[3],s=e[4]),(0,Y.useEffect)(o,s);let c;e[5]!==t||e[6]!==a||e[7]!==i?(c=()=>{if(!i||a)return;let e=crypto.randomUUID();t({type:Z.EnableDualChat,conversationId:e})},e[5]=t,e[6]=a,e[7]=i,e[8]=c):c=e[8];let l=c,u;e[9]===t?u=e[10]:(u=()=>{t({type:Z.DisableDualChat})},e[9]=t,e[10]=u);let d=u,f=!a&&!!i,p=n&&f,m=r!==`secondary`,h;return e[11]!==d||e[12]!==l||e[13]!==r||e[14]!==p||e[15]!==f||e[16]!==m?(h={isDualChatActive:p,showDualChatControls:f,focusedPane:r,canCloseSecondary:m,enableDualChat:l,disableDualChat:d},e[11]=d,e[12]=l,e[13]=r,e[14]=p,e[15]=f,e[16]=m,e[17]=h):h=e[17],h}function Zd(e){return e.selectedThreadId}function Qd(e){return e.focusedPane}function $d(e){return e.dualChatEnabled}function ef(e){let t=(0,X.c)(26),{visible:n,commands:r,skills:i,skillReferencePrefix:a,query:o,selectedIndex:s,onSelectCommand:c,onSelectSkill:l,onMouseEnterSuggestion:u,containerRef:d}=e,f=a===void 0?`/`:a;if(!n)return null;let p=f===`//`,m;if(t[0]!==r||t[1]!==p||t[2]!==o||t[3]!==i){let e;t[5]===o?e=t[6]:(e=e=>e.name.toLowerCase().includes(o.toLowerCase()),t[5]=o,t[6]=e);let n=r.filter(e),a;t[7]===o?a=t[8]:(a=e=>e.name.toLowerCase().includes(o.toLowerCase()),t[7]=o,t[8]=a);let s=i.filter(a);m=[...p?[]:n.map(nf),...s.map(tf)].slice(0,10),t[0]=r,t[1]=p,t[2]=o,t[3]=i,t[4]=m}else m=t[4];let h=m,g,_;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(g=z(W.dropdownGroupHeading,`px-2 py-1.5 border-b border-border/50 mb-1 flex items-center gap-2`),_=(0,$.jsx)(pe,{className:`h-3 w-3`}),t[9]=g,t[10]=_):(g=t[9],_=t[10]);let v=p?`Bundled Skills`:`Commands & Skills`,y=o&&` matching "${o}"`,b;t[11]!==v||t[12]!==y?(b=(0,$.jsxs)(`div`,{className:g,children:[_,v,y]}),t[11]=v,t[12]=y,t[13]=b):b=t[13];let x;t[14]!==h||t[15]!==p||t[16]!==u||t[17]!==c||t[18]!==l||t[19]!==s||t[20]!==f?(x=h.length>0?h.map((e,t)=>{let n=t===s;if(e.type===`command`){let r=e.data;return(0,$.jsxs)(`button`,{type:`button`,className:z(`flex w-full flex-col gap-1 rounded-lg px-3 py-2 text-left transition-colors`,n?`bg-accent text-accent-foreground`:`text-popover-foreground hover:bg-accent/50`),onClick:()=>c(r),onMouseEnter:()=>u(t),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(pe,{className:`h-3 w-3 text-muted-foreground`}),(0,$.jsxs)(`span`,{className:`font-medium`,children:[`/`,r.name]}),r.metadata.argumentHint&&(0,$.jsx)(`span`,{className:W.compact,children:r.metadata.argumentHint}),r.scope===`project`&&(0,$.jsx)(`span`,{className:z(W.compact,`ml-auto rounded-full bg-primary/10 px-1.5 py-0.5 text-primary`),children:`project`})]}),r.metadata.description&&(0,$.jsx)(`span`,{className:W.compact,children:r.metadata.description})]},`cmd-${r.name}`)}else{let r=e.data;return(0,$.jsxs)(`button`,{type:`button`,className:z(`flex w-full flex-col gap-1 rounded-lg px-3 py-2 text-left transition-colors`,n?`bg-accent text-accent-foreground`:`text-popover-foreground hover:bg-accent/50`),onClick:()=>l(r),onMouseEnter:()=>u(t),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(Dn,{className:`h-3 w-3 text-amber-500`}),(0,$.jsxs)(`span`,{className:`font-medium`,children:[f,r.name]}),(0,$.jsx)(`span`,{className:z(W.compact,`ml-auto rounded-full bg-amber-500/10 px-1.5 py-0.5 text-amber-700 dark:text-amber-400`),children:r.scope===`bundled`?`bundled`:`skill`}),r.scope===`project`&&(0,$.jsx)(`span`,{className:z(W.compact,`rounded-full bg-primary/10 px-1.5 py-0.5 text-primary`),children:`project`})]}),(0,$.jsx)(`span`,{className:W.compact,children:r.description})]},`skill-${r.name}`)}}):(0,$.jsxs)(`div`,{className:z(W.compact,`px-3 py-4 text-center text-muted-foreground`),children:[p?`No bundled skills found.`:`No commands or skills found.`,(0,$.jsx)(`br`,{}),(0,$.jsxs)(`span`,{className:W.compact,children:[p?(0,$.jsx)($.Fragment,{children:`Use bundled skills with syntax like `}):(0,$.jsx)($.Fragment,{children:`Create commands in `}),p?(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[14]=h,t[15]=p,t[16]=u,t[17]=c,t[18]=l,t[19]=s,t[20]=f,t[21]=x):x=t[21];let S;return t[22]!==d||t[23]!==b||t[24]!==x?(S=(0,$.jsxs)(`div`,{ref:d,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:[b,x]}),t[22]=d,t[23]=b,t[24]=x,t[25]=S):S=t[25],S}function tf(e){return{type:`skill`,data:e}}function nf(e){return{type:`command`,data:e}}function rf(e){return e.startsWith(`image/`)}function af(e){return e.startsWith(`video/`)}function of(e){return e.startsWith(`audio/`)}function sf(e){let t=(0,X.c)(7),{attachments:n,onRemove:i}=e;if(n.length===0)return null;let a;if(t[0]!==n||t[1]!==i){let e;t[3]===i?e=t[4]:(e=(e,t)=>(0,$.jsx)(`div`,{className:z(W.compact,`group relative flex items-center gap-1 rounded-md bg-muted text-muted-foreground`),children:rf(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:()=>i(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)(zn,{className:`h-2.5 w-2.5`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Remove attachment`})]})]}):af(e.mimeType)?(0,$.jsxs)(`span`,{className:`flex items-center gap-1 px-2 py-1`,children:[(0,$.jsx)(l,{className:`h-3 w-3`}),e.fileName,(0,$.jsxs)(`button`,{type:`button`,onClick:()=>i(t),className:`ml-1 hover:text-foreground`,children:[(0,$.jsx)(zn,{className:`h-3 w-3`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Remove attachment`})]})]}):of(e.mimeType)?(0,$.jsxs)(`span`,{className:`flex items-center gap-1 px-2 py-1`,children:[(0,$.jsx)(It,{className:`h-3 w-3`}),e.fileName,(0,$.jsxs)(`button`,{type:`button`,onClick:()=>i(t),className:`ml-1 hover:text-foreground`,children:[(0,$.jsx)(zn,{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)(r,{className:`h-3 w-3`}),e.fileName,(0,$.jsxs)(`button`,{type:`button`,onClick:()=>i(t),className:`ml-1 hover:text-foreground`,children:[(0,$.jsx)(zn,{className:`h-3 w-3`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Remove attachment`})]})]})},t),t[3]=i,t[4]=e),a=n.map(e),t[0]=n,t[1]=i,t[2]=a}else a=t[2];let o;return t[5]===a?o=t[6]:(o=(0,$.jsx)(`div`,{className:`mb-2 flex flex-wrap gap-1.5`,children:a}),t[5]=a,t[6]=o),o}var cf=ei(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,` 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.v6})}),(0,$.jsx)(`div`,{className:`space-y-1.5`,children:e.v7})]}),{name:`ContextUsagePanel_1`,portals:[`v1`,`v3`,`v4`,`v5`,`v6`,`v7`]}),lf=function(e){let t=(0,X.c)(37),{breakdown:n,onClose:r}=e,{categories:i,totalTokens:a,contextWindow:o,percentageFull:c}=n,l,u,d,f,p,m,h,g;if(t[0]!==i||t[1]!==o||t[2]!==r||t[3]!==c||t[4]!==a){let e;t[13]===i?e=t[14]:(e=e=>i[e.key]>0,t[13]=i,t[14]=e);let n=uf.filter(e);l=cf,u=W.label,t[15]===r?d=t[16]:(d=r&&(0,$.jsxs)(s,{variant:`ghost`,size:`icon-sm`,className:`text-muted-foreground hover:text-background`,onClick:r,children:[(0,$.jsx)(zn,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Close`})]}),t[15]=r,t[16]=d),t[17]===Symbol.for(`react.memo_cache_sentinel`)?(f=z(W.compact,`flex items-center justify-between text-muted-foreground`),t[17]=f):f=t[17],p=c,t[18]===a?m=t[19]:(m=df(a),t[18]=a,t[19]=m),t[20]===o?h=t[21]:(h=ff(o),t[20]=o,t[21]=h);let _;t[22]!==i||t[23]!==o?(_=e=>{let t=i[e.key],n=o>0?t/o*100:0;return(0,$.jsx)(`div`,{style:{width:`${Math.max(n,t>0?.5:0)}%`,backgroundColor:e.color}},e.key)},t[22]=i,t[23]=o,t[24]=_):_=t[24],g=n.map(_),t[0]=i,t[1]=o,t[2]=r,t[3]=c,t[4]=a,t[5]=l,t[6]=u,t[7]=d,t[8]=f,t[9]=p,t[10]=m,t[11]=h,t[12]=g}else l=t[5],u=t[6],d=t[7],f=t[8],p=t[9],m=t[10],h=t[11],g=t[12];let _;t[25]===i?_=t[26]:(_=uf.map(e=>(0,$.jsxs)(`div`,{className:z(W.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:df(i[e.key])})]},e.key)),t[25]=i,t[26]=_);let v;return t[27]!==l||t[28]!==u||t[29]!==d||t[30]!==f||t[31]!==p||t[32]!==m||t[33]!==h||t[34]!==g||t[35]!==_?(v=(0,$.jsx)(l,{v0:u,v1:d,v2:f,v3:p,v4:m,v5:h,v6:g,v7:_}),t[27]=l,t[28]=u,t[29]=d,t[30]=f,t[31]=p,t[32]=m,t[33]=h,t[34]=g,t[35]=_,t[36]=v):v=t[36],v},uf=[{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 df(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toString()}function ff(e){return e>=1e6?`${Math.round(e/1e6)}M`:e>=1e3?`${Math.round(e/1e3)}K`:e.toString()}function pf({threadId:e,currentConversationId:t,initialBreakdown:n,refreshKey:r,children:i}){let[a,o]=(0,Y.useState)(n??null),[s,c]=(0,Y.useState)(!1),[l,u]=(0,Y.useState)(null),[d,f]=(0,Y.useState)(!1),[p,m]=(0,Y.useState)(n?t:void 0);return(0,Y.useEffect)(()=>{if(n){o(n),m(t),u(null);return}t!==p&&(o(null),m(void 0),u(null))},[n,t,p,r]),(0,Y.useEffect)(()=>{if(!d||!e||!t||p===t)return;let n=!1;async function r(){let r=t;if(r){c(!0),u(null);try{let t=await Mt(e,r);if(n)return;o(t),m(r)}catch(e){if(console.error(`[TokenUsageTooltip] Failed to load context data:`,e),n)return;o(e=>(e||u(`Failed to load context data`),e))}finally{n||c(!1)}}}return r(),()=>{n=!0}},[d,e,t,p]),!e||e===``?(0,$.jsx)($.Fragment,{children:i}):(0,$.jsxs)(qc,{open:d,onOpenChange:f,children:[(0,$.jsxs)(B,{children:[(0,$.jsx)(L,{asChild:!0,children:(0,$.jsx)(Jc,{asChild:!0,children:i})}),(0,$.jsx)(H,{side:`top`,className:`bg-popover text-popover-foreground`,children:`Show context usage`})]}),(0,$.jsxs)(Yc,{side:`top`,align:`end`,className:`w-auto p-4`,children:[s&&(0,$.jsxs)(`div`,{className:z(W.compact,`flex w-72 items-center gap-2 text-muted-foreground`),children:[(0,$.jsx)(Ce,{className:`h-3 w-3 animate-pulse`}),(0,$.jsx)(`span`,{children:`Loading context...`})]}),l&&!s&&(0,$.jsxs)(`div`,{className:z(W.compact,`flex w-72 items-center gap-2 text-muted-foreground`),children:[(0,$.jsx)(Ce,{className:`h-3 w-3`}),(0,$.jsx)(`span`,{children:l})]}),!s&&!l&&a&&(0,$.jsx)(lf,{breakdown:a,onClose:()=>f(!1)})]})]})}var mf=ei(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}),hf=function(e){let t=(0,X.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=_f(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)(mf,{v0:o,v1:7,v2:7,v3:r,v4:i}),t[2]=i,t[3]=o,t[4]=s):s=t[4],s};function gf(e){return e.filter(e=>e.sender===`agent`).length}function _f(e){return e>75?`text-red-500`:e>50?`text-orange-500`:`text-muted-foreground`}var vf=500;function yf(e){let t=(0,X.c)(39),{threadId:n,conversationId:r,messages:i}=e,a;t[0]===i?a=t[1]:(a=i===void 0?[]:i,t[0]=i,t[1]=a);let o=a,[c,l]=(0,Y.useState)(r),[u,d]=(0,Y.useState)(),f;t[2]===o?f=t[3]:(f=gf(o),t[2]=o,t[3]=f);let p=f,[m,h]=(0,Y.useState)(p),g=(0,Y.useRef)(null),_=(0,Y.useRef)(n),v,y;t[4]===p?(v=t[5],y=t[6]):(v=()=>(g.current&&clearTimeout(g.current),g.current=setTimeout(()=>{h(p)},vf),()=>{g.current&&clearTimeout(g.current)}),y=[p],t[4]=p,t[5]=v,t[6]=y),(0,Y.useEffect)(v,y);let b,x;t[7]===n?(b=t[8],x=t[9]):(b=()=>{_.current!==n&&(_.current&&(k.invalidate(`thread-${_.current}`),k.invalidatePattern(RegExp(`^context-breakdown-${_.current}-`))),_.current=n,l(void 0),d(void 0))},x=[n],t[7]=n,t[8]=b,t[9]=x),(0,Y.useEffect)(b,x);let S,C;t[10]===r?(S=t[11],C=t[12]):(S=()=>{if(r){l(r);return}},C=[r],t[10]=r,t[11]=S,t[12]=C),(0,Y.useEffect)(S,C);let w;t[13]!==r||t[14]!==n?(w=()=>{let e=!1;return(async function(){if(!n){l(void 0),d(void 0);return}if(r){l(r);return}try{let t=await O(n);if(e)return;l(t.currentConversationId)}catch(e){console.error(`Failed to fetch thread data:`,e)}})(),()=>{e=!0}},t[13]=r,t[14]=n,t[15]=w):w=t[15];let T;t[16]!==r||t[17]!==m||t[18]!==n?(T=[r,n,m],t[16]=r,t[17]=m,t[18]=n,t[19]=T):T=t[19],(0,Y.useEffect)(w,T);let E;t[20]!==c||t[21]!==n?(E=()=>{let e=!1;return(async function(){if(!n||!c){d(void 0);return}try{let t=await Mt(n,c);if(e)return;d(t)}catch(e){let t=e;if(t instanceof Error&&t.message===`Conversation not found`){d(void 0);return}console.error(`Failed to fetch context breakdown:`,t)}})(),()=>{e=!0}},t[20]=c,t[21]=n,t[22]=E):E=t[22];let D;if(t[23]!==m||t[24]!==c||t[25]!==n?(D=[n,c,m],t[23]=m,t[24]=c,t[25]=n,t[26]=D):D=t[26],(0,Y.useEffect)(E,D),!n||n===``)return null;let A=u?.percentageFull,j=typeof A==`number`&&A>25,M=String(m),N;t[27]!==A||t[28]!==j?(N=j?(0,$.jsx)(hf,{percentage:A}):(0,$.jsx)(je,{className:`h-4 w-4`}),t[27]=A,t[28]=j,t[29]=N):N=t[29];let P;t[30]===Symbol.for(`react.memo_cache_sentinel`)?(P=(0,$.jsx)(`span`,{className:`sr-only`,children:`Show context usage`}),t[30]=P):P=t[30];let F;t[31]===N?F=t[32]:(F=(0,$.jsxs)(s,{variant:`ghost`,size:`icon-sm`,className:`text-muted-foreground hover:text-background`,children:[N,P]}),t[31]=N,t[32]=F);let I;return t[33]!==u||t[34]!==c||t[35]!==M||t[36]!==F||t[37]!==n?(I=(0,$.jsx)(pf,{threadId:n,currentConversationId:c,initialBreakdown:u,refreshKey:M,children:F}),t[33]=u,t[34]=c,t[35]=M,t[36]=F,t[37]=n,t[38]=I):I=t[38],I}function bf(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 xf(e){let t=(0,X.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=z(W.dropdownGroupHeading,`px-2 py-1.5 border-b border-border/50 mb-1 flex items-center gap-2`),u=(0,$.jsx)(Hn,{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:z(W.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:[e.endsWith(`.ts`)||e.endsWith(`.tsx`)||e.endsWith(`.js`)||e.endsWith(`.jsx`)?(0,$.jsx)(ue,{className:`h-4 w-4 text-blue-500`}):(0,$.jsx)(zt,{className:`h-4 w-4 text-muted-foreground`}),(0,$.jsxs)(`div`,{className:`flex flex-col overflow-hidden`,children:[(0,$.jsx)(`span`,{className:`truncate font-medium`,children:n}),(0,$.jsx)(`span`,{className:z(W.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 Sf(e){let t=(0,X.c)(5),{providerSlug:n}=e;if(!n)return null;let r;t[0]===n?r=t[1]:(r=he(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:Cf}),t[2]=r,t[3]=i,t[4]=a):a=t[4],a}function Cf(e){e.currentTarget.style.visibility=`hidden`}function wf(e){let t=(0,X.c)(9),{providerSlug:n,providerData:r}=e,i=r?.name??n,a;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=z(W.dropdownGroupHeading,`flex items-center gap-1.5 px-3 py-1.5 uppercase tracking-wide`),t[0]=a):a=t[0];let o;t[1]===n?o=t[2]:(o=(0,$.jsx)(Sf,{providerSlug:n}),t[1]=n,t[2]=o);let s;t[3]!==i||t[4]!==r?(s=r?.url?(0,$.jsx)(mi,{url:r.url,showIcon:!1,variant:`inline`,children:i}):i,t[3]=i,t[4]=r,t[5]=s):s=t[5];let c;return t[6]!==o||t[7]!==s?(c=(0,$.jsxs)(`div`,{className:a,children:[o,s]}),t[6]=o,t[7]=s,t[8]=c):c=t[8],c}function Tf(e){let t=e.pricing?.prompt;return t==null?null:Math.ceil(t*3)}function Ef(e){return`$${fe(e)}`}function Df(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:`${Ef(e.pricing.prompt??0)} input per million tokens`}),(0,$.jsx)(`div`,{children:`${Ef(e.pricing.completion??0)} output per million tokens`}),(0,$.jsx)(`div`,{children:`Displayed value of ${t} is a relative price.`})]}):null}function Of(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=(Tf(e)??2**53-1)-(Tf(n)??2**53-1);if(t!==0)return t}return hi(e.id).localeCompare(hi(n.id))})}function kf(e){let t=(0,X.c)(34),{availableModels:n,selectedModel:r,onModelSelect:i}=e,[a,o]=Y.useState(!1),[c,l]=Y.useState(`relative-price`),u;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(u=new Map,t[0]=u):u=t[0];let[d,f]=Y.useState(u),p=Y.useRef(null),m,h;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(m=()=>{Vt().then(function(e){f(new Map(e.map(jf)))})},h=[],t[1]=m,t[2]=h):(m=t[1],h=t[2]),Y.useEffect(m,h);let g,_;t[3]===a?(g=t[4],_=t[5]):(g=()=>{let e=e=>{p.current&&!p.current.contains(e.target)&&o(!1)};if(a)return document.addEventListener(`mousedown`,e),()=>{document.removeEventListener(`mousedown`,e)}},_=[a],t[3]=a,t[4]=g,t[5]=_),Y.useEffect(g,_);let v;t[6]===i?v=t[7]:(v=e=>{i(e),o(!1)},t[6]=i,t[7]=v);let y=v,b;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(b=()=>{l(function(e){return e===`relative-price`?`alphabetical`:`relative-price`})},t[8]=b):b=t[8];let x=b,S;t[9]!==n||t[10]!==c?(S=Of(n,c),t[9]=n,t[10]=c,t[11]=S):S=t[11];let C=S,w=c===`relative-price`?Sn:ot,T=c===`relative-price`?`Sort by relative price`:`Sort alphabetically`,E;t[12]===a?E=t[13]:(E=()=>o(!a),t[12]=a,t[13]=E);let O;t[14]===Symbol.for(`react.memo_cache_sentinel`)?(O=z(W.body,`font-normal`),t[14]=O):O=t[14];let k;t[15]===r?k=t[16]:(k=r?hi(r.id):`No model`,t[15]=r,t[16]=k);let A;t[17]===k?A=t[18]:(A=(0,$.jsx)(`span`,{className:O,children:k}),t[17]=k,t[18]=A);let j;t[19]===Symbol.for(`react.memo_cache_sentinel`)?(j=(0,$.jsx)(ln,{className:`h-3 w-3`}),t[19]=j):j=t[19];let M;t[20]!==A||t[21]!==E?(M=(0,$.jsxs)(s,{variant:`action`,size:`icon-sm`,className:`gap-1 w-auto px-2`,onClick:E,children:[A,j]}),t[20]=A,t[21]=E,t[22]=M):M=t[22];let N;t[23]!==w||t[24]!==y||t[25]!==d||t[26]!==r?.id||t[27]!==a||t[28]!==T||t[29]!==C?(N=a&&(0,$.jsx)(`div`,{className:`absolute bottom-full left-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)(D,{children:[(0,$.jsx)(`div`,{className:`-mb-3 flex justify-end px-1 pb-1`,children:(0,$.jsxs)(B,{children:[(0,$.jsx)(L,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,"aria-label":T,className:`rounded-md p-1 text-muted-foreground transition-colors hover:bg-accent hover:text-accent-foreground`,onClick:x,children:(0,$.jsx)(w,{className:`h-3.5 w-3.5`})})}),(0,$.jsx)(H,{side:`left`,align:`start`,sideOffset:8,children:T})]})}),Object.entries(C.reduce(Af,{})).map((e,t)=>{let[n,i]=e;return(0,$.jsxs)(`div`,{children:[t>0&&(0,$.jsx)(pi,{className:`my-1`}),(0,$.jsx)(wf,{providerSlug:n,providerData:d.get(n)}),i.map(e=>{let t=Tf(e),n=t==null?null:Df(e,t);return(0,$.jsx)(`div`,{children:(0,$.jsx)(`div`,{children:(0,$.jsxs)(`button`,{type:`button`,className:z(W.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:()=>y(e),children:[(0,$.jsx)(`span`,{className:`min-w-0 truncate`,children:hi(e.id)}),t!=null&&n&&(0,$.jsxs)(B,{children:[(0,$.jsx)(L,{asChild:!0,children:(0,$.jsx)(`span`,{className:`shrink-0 text-xs text-muted-foreground`,children:t})}),(0,$.jsx)(H,{side:`left`,align:`end`,sideOffset:8,className:`max-w-64`,children:n})]})]})})},e.id)})]},n)})]})}),t[23]=w,t[24]=y,t[25]=d,t[26]=r?.id,t[27]=a,t[28]=T,t[29]=C,t[30]=N):N=t[30];let P;return t[31]!==M||t[32]!==N?(P=(0,$.jsxs)(`div`,{className:`relative`,ref:p,children:[M,N]}),t[31]=M,t[32]=N,t[33]=P):P=t[33],P}function Af(e,t){let n=t.provider??`Other`;return e[n]||(e[n]=[]),e[n].push(t),e}function jf(e){return[e.slug,e]}var Mf=[{value:`build`,label:`Build`,icon:Et,description:`Executes code changes and implements features`},{value:`plan`,label:`Plan`,icon:St,description:`Creates implementation plans without making changes`},{value:`image`,label:`Image`,icon:Kt,description:`Generates and edits images`},{value:`ralph`,label:`Ralph`,icon:Be,description:`Runs rapid iterative test-fix cycles`}];function Nf(e,t,n){return n?`ralph`:e?`plan`:t?`image`:`build`}function Pf({planMode:e,imageMode:t,ralphMode:n,setPlanMode:r,setImageMode:i,setRalphMode:a,projectId:o}){let s=Ia(),c=Q(function(e){if(o)return e.projects.find(e=>e.projectId===o)}),[l,u]=Y.useState(!0),[d,f]=Y.useState(!1),p=Nf(e,t,n),m=Mf.find(e=>e.value===p);Y.useEffect(()=>{c&&u(c.allowAllCommands===!1)},[c]);async function h(){if(!o||d)return;let e=!l;u(e),f(!0);try{await I(o,{allowAllCommands:!e}),yn(o);let t=await w();s({type:Z.SetProjects,projects:t.projects})}catch(t){u(!e),console.error(`Failed to update command confirmation setting:`,t)}finally{f(!1)}}function g(e){r(e===`plan`),i(e===`image`),a(e===`ralph`)}return{chatModes:Mf,confirmCommands:l,currentConfig:m,currentMode:p,isUpdatingConfirmCommands:d,selectMode:g,toggleConfirmCommands:h}}function Ff(e){let t=(0,X.c)(38),{planMode:n,imageMode:r,ralphMode:i,setPlanMode:a,setImageMode:o,setRalphMode:c,projectId:l}=e,[u,d]=Y.useState(!1),f=Y.useRef(null),p;t[0]!==r||t[1]!==n||t[2]!==l||t[3]!==i||t[4]!==o||t[5]!==a||t[6]!==c?(p={planMode:n,imageMode:r,ralphMode:i,setPlanMode:a,setImageMode:o,setRalphMode:c,projectId:l},t[0]=r,t[1]=n,t[2]=l,t[3]=i,t[4]=o,t[5]=a,t[6]=c,t[7]=p):p=t[7];let{chatModes:m,confirmCommands:h,currentConfig:g,currentMode:_,isUpdatingConfirmCommands:v,selectMode:y,toggleConfirmCommands:b}=Pf(p),x,S;t[8]===u?(x=t[9],S=t[10]):(x=()=>{let e=function(e){f.current&&!f.current.contains(e.target)&&d(!1)};if(u)return document.addEventListener(`mousedown`,e),()=>{document.removeEventListener(`mousedown`,e)}},S=[u],t[8]=u,t[9]=x,t[10]=S),Y.useEffect(x,S);let C;t[11]===y?C=t[12]:(C=function(e){y(e),d(!1)},t[11]=y,t[12]=C);let w=C,T;t[13]===u?T=t[14]:(T=()=>d(!u),t[13]=u,t[14]=T);let E;t[15]===g.icon?E=t[16]:(E=(0,$.jsx)(g.icon,{className:`h-4 w-4`}),t[15]=g.icon,t[16]=E);let O;t[17]!==T||t[18]!==E?(O=(0,$.jsx)(L,{asChild:!0,children:(0,$.jsx)(s,{variant:`action`,size:`icon-sm`,onClick:T,children:E})}),t[17]=T,t[18]=E,t[19]=O):O=t[19];let k;t[20]!==g.description||t[21]!==g.label?(k=(0,$.jsx)(H,{children:(0,$.jsxs)(`p`,{children:[g.label,` - `,g.description]})}),t[20]=g.description,t[21]=g.label,t[22]=k):k=t[22];let A;t[23]!==O||t[24]!==k?(A=(0,$.jsx)(D,{children:(0,$.jsxs)(B,{children:[O,k]})}),t[23]=O,t[24]=k,t[25]=A):A=t[25];let j;t[26]!==m||t[27]!==h||t[28]!==_||t[29]!==w||t[30]!==v||t[31]!==u||t[32]!==l||t[33]!==b?(j=u&&(0,$.jsxs)(`div`,{className:`absolute bottom-full right-0 z-50 mb-1 w-56 rounded-lg border border-border bg-popover p-1 shadow-md`,children:[l&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`button`,{type:`button`,className:z(W.body,`flex w-full items-center gap-2 rounded-md px-3 py-2 text-popover-foreground hover:bg-accent disabled:opacity-50`),onClick:()=>{b()},disabled:v,children:[`Confirm Commands`,h&&(0,$.jsx)(Ze,{className:`ml-auto h-3.5 w-3.5`})]}),(0,$.jsx)(`div`,{className:`my-1 h-px bg-border`})]}),m.map(e=>{let t=e.icon,n=e.value===_;return(0,$.jsxs)(`button`,{type:`button`,className:z(W.body,`flex w-full items-center gap-2 rounded-md px-3 py-2 text-popover-foreground hover:bg-accent`),onClick:()=>w(e.value),children:[(0,$.jsx)(t,{className:`h-3.5 w-3.5`}),e.label,n&&(0,$.jsx)(Ze,{className:`ml-auto h-3.5 w-3.5`})]},e.value)})]}),t[26]=m,t[27]=h,t[28]=_,t[29]=w,t[30]=v,t[31]=u,t[32]=l,t[33]=b,t[34]=j):j=t[34];let M;return t[35]!==j||t[36]!==A?(M=(0,$.jsxs)(`div`,{className:`relative hidden md:block`,ref:f,children:[A,j]}),t[35]=j,t[36]=A,t[37]=M):M=t[37],M}function If(e){let t=(0,X.c)(32),{disabled:n,canAddTask:i,onFileAttach:a,onAddTask:o,showModes:c,planMode:l,imageMode:u,ralphMode:d,setPlanMode:f,setImageMode:p,setRalphMode:m,projectId:h}=e,g=n===void 0?!1:n,_=c===void 0?!1:c,v=l===void 0?!1:l,y=u===void 0?!1:u,b=d===void 0?!1:d,x=f??zf,S=p??Rf,C=m??Lf,w;t[0]!==y||t[1]!==v||t[2]!==h||t[3]!==b||t[4]!==x||t[5]!==S||t[6]!==C?(w={planMode:v,imageMode:y,ralphMode:b,setPlanMode:x,setImageMode:S,setRalphMode:C,projectId:h},t[0]=y,t[1]=v,t[2]=h,t[3]=b,t[4]=x,t[5]=S,t[6]=C,t[7]=w):w=t[7];let T=Pf(w),E;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(E=function(e){e()},t[8]=E):E=t[8];let D=E,O,k;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(O=(0,$.jsx)(sn,{}),k=(0,$.jsx)(`span`,{className:`sr-only`,children:`More options`}),t[9]=O,t[10]=k):(O=t[9],k=t[10]);let A;t[11]===g?A=t[12]:(A=(0,$.jsx)(Vl,{asChild:!0,children:(0,$.jsxs)(s,{variant:`action`,size:`icon-sm`,disabled:g,children:[O,k]})}),t[11]=g,t[12]=A);let j;t[13]===a?j=t[14]:(j=()=>D(a),t[13]=a,t[14]=j);let M;t[15]===Symbol.for(`react.memo_cache_sentinel`)?(M=(0,$.jsx)(r,{className:`mr-2 h-3.5 w-3.5`}),t[15]=M):M=t[15];let N;t[16]===j?N=t[17]:(N=(0,$.jsxs)(Kl,{onClick:j,children:[M,`Attach File`]}),t[16]=j,t[17]=N);let P;t[18]!==i||t[19]!==o?(P=i&&(0,$.jsxs)(Kl,{onClick:()=>D(o),children:[(0,$.jsx)(ht,{className:`mr-2 h-3.5 w-3.5`}),`Add Task`]}),t[18]=i,t[19]=o,t[20]=P):P=t[20];let F;t[21]!==T||t[22]!==h||t[23]!==_?(F=_&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Xl,{}),h&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(Kl,{onClick:()=>{T.toggleConfirmCommands()},disabled:T.isUpdatingConfirmCommands,children:[`Confirm Commands`,T.confirmCommands&&(0,$.jsx)(Ze,{className:`ml-auto h-3.5 w-3.5`})]}),(0,$.jsx)(Xl,{})]}),T.chatModes.map(e=>{let t=e.icon,n=e.value===T.currentMode;return(0,$.jsxs)(Kl,{onClick:()=>T.selectMode(e.value),className:z(n&&`bg-accent`),children:[(0,$.jsx)(t,{className:`mr-2 h-3.5 w-3.5`}),e.label,n&&(0,$.jsx)(Ze,{className:`ml-auto h-3.5 w-3.5`})]},e.value)})]}),t[21]=T,t[22]=h,t[23]=_,t[24]=F):F=t[24];let I;t[25]!==N||t[26]!==P||t[27]!==F?(I=(0,$.jsxs)(Gl,{align:`start`,side:`top`,className:`w-56`,children:[N,P,F]}),t[25]=N,t[26]=P,t[27]=F,t[28]=I):I=t[28];let ee;return t[29]!==A||t[30]!==I?(ee=(0,$.jsxs)(Bl,{children:[A,I]}),t[29]=A,t[30]=I,t[31]=ee):ee=t[31],ee}function Lf(){}function Rf(){}function zf(){}var Bf=_i(`useWebSpeech`);function Vf(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 Hf(e){let t=``;for(let n=0;n<e.results.length;n+=1)t+=e.results[n][0]?.transcript??``;return t}function Uf(){let[e,t]=(0,Y.useState)(`idle`),[n,r]=(0,Y.useState)(null),[i,a]=(0,Y.useState)(``),[o,s]=(0,Y.useState)(null),c=(0,Y.useRef)(null),l=(0,Y.useRef)(!1);(0,Y.useEffect)(()=>()=>{l.current=!1,c.current?.abort(),c.current=null},[]);let u=(0,Y.useCallback)(()=>{let e=gi();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=Hf(e).trim();t&&a(t)},e.onerror=e=>{let t=Vf(e.error);Bf.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}Bf.info(`Web Speech recognition ended — restarting`),u()},c.current=e;try{e.start(),t(`recording`),Bf.info(`Web Speech recognition started`)}catch(e){c.current=null,l.current=!1;let n=e instanceof Error?e.message:`Unknown error`;Bf.error(`Failed to start Web Speech recognition`,{error:n}),t(`ready`),s(`Failed to start speech recognition: ${n}`)}},[]),d=(0,Y.useCallback)(async()=>{if(e===`ready`||e===`error`)return e;t(`checking-support`),s(null),Bf.info(`Checking Web Speech API support`,{userAgent:navigator.userAgent,platform:navigator.platform});let n=yi();return r(n),n?(Bf.info(`Web Speech API available — ready`),t(`ready`),`ready`):(Bf.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,Y.useCallback)(async()=>{l.current=!0,s(null),a(``),Bf.info(`Starting Web Speech recognition`),u()},[u]),stopListening:(0,Y.useCallback)(async()=>{l.current=!1,c.current?.stop(),c.current=null,t(`ready`),Bf.info(`Web Speech recognition stopped`)},[]),requestModelDownload:(0,Y.useCallback)(async()=>{},[]),ensureReady:d,resetTranscript:(0,Y.useCallback)(()=>{a(``),s(null)},[])}}var Wf=_i(`useVoskSpeech`);function Gf(e,t){let n=e.trim(),r=t.trim();return n&&r?`${n} ${r}`:n||r}function Kf(){let[e,t]=(0,Y.useState)(`idle`),[n,r]=(0,Y.useState)(null),[i,a]=(0,Y.useState)(``),[o,s]=(0,Y.useState)(null),[c,l]=(0,Y.useState)(0),u=(0,Y.useRef)(null),d=(0,Y.useRef)(null),f=(0,Y.useRef)(null),p=(0,Y.useRef)(null),m=(0,Y.useRef)(!1),h=(0,Y.useRef)(``),g=(0,Y.useRef)(``),_=(0,Y.useCallback)(e=>{m.current=e},[]);(0,Y.useEffect)(()=>()=>{f.current?.stop(),f.current=null,u.current?.terminate(),u.current=null},[]);let v=(0,Y.useCallback)(()=>{a(Gf(h.current,g.current))},[]),y=(0,Y.useCallback)(async()=>{if(e===`ready`||e===`needs-model`||e===`error`)return e;if(p.current)return p.current;let n=xi();async function i(){t(`checking-support`),_(!1),l(0),s(null),Wf.separator(`VOICE SESSION START`),Wf.info(`Checking Vosk support`,{userAgent:navigator.userAgent,platform:navigator.platform,url:n});try{let e=new vi;u.current=e;let i=e.checkSupport();if(r(i),!i)return Wf.error(`Vosk not supported in this environment`),t(`error`),s(`Local speech recognition is not supported in this environment.`),`error`;let a=new bi;d.current=a,Wf.info(`Checking IndexedDB model cache`,{url:n});let o=await a.getCachedModelByUrl(n);return o?(Wf.info(`Cached model found — initializing Vosk`,{sizeBytes:o.byteLength,sizeMB:(o.byteLength/1024/1024).toFixed(2)}),_(!0),t(`initializing`),await e.initModelFromBytes(o),Wf.info(`Vosk model initialized from cache — ready`),t(`ready`),`ready`):(Wf.info(`Model not in cache — download required`),t(`needs-model`),`needs-model`)}catch(e){let n=e instanceof Error?e.message:`Unknown error`;return Wf.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,Y.useCallback)(async()=>{if(!u.current||!d.current)return;let e=xi();t(`downloading-model`),l(0),s(null),Wf.info(`Model download requested`,{url:e});try{let n=await d.current.loadModelByUrl(e,e=>{l(e),e%10==0&&Wf.debug(`Model download progress`,{progress:e})});Wf.info(`Model download complete — initializing Vosk`,{sizeBytes:n.byteLength,sizeMB:(n.byteLength/1024/1024).toFixed(2)}),t(`initializing`),await u.current.initModelFromBytes(n),Wf.info(`Vosk model initialized after download — ready`),_(!0),t(`ready`)}catch(e){let n=e instanceof Error?e.message:`An unknown error occurred.`;Wf.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,Y.useCallback)(async()=>{if(!(!u.current||!m.current)){if(t(`requesting-mic`),s(null),h.current=``,g.current=``,a(``),Wf.separator(`RECORDING START`),!navigator.mediaDevices?.getUserMedia){Wf.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`),Wf.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,Y.useCallback)(async()=>{if(!f.current){Wf.info(`stopListening called but no active recording`),m.current&&t(`ready`);return}t(`transcribing`),Wf.info(`Stopping recording`);try{await f.current.stop(),g.current=``,v(),t(`ready`),Wf.info(`Recording stopped`)}catch(e){let n=e instanceof Error?e.message:`Unknown error`;Wf.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,Y.useCallback)(()=>{h.current=``,g.current=``,a(``),s(null)},[])}}function qf(){let e=(0,X.c)(22),t=Kf(),n=Uf();if(Ve()){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 Jf=Y.forwardRef((e,t)=>{let n=(0,X.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=z(`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)(yr,{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)(tr,{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});Jf.displayName=tr.displayName;function Yf(e,t,n){return t?`Preparing voice input…`:n<100?`Downloading voice model… ${n}%`:e?`Finishing download…`:`Downloading voice model…`}function Xf(e){let t=(0,X.c)(24),{open:n,onOpenChange:r,onRetry:i,isDownloading:o,isInitializing:c,progress:l,error:u}=e,d=o||c,f;t[0]!==d||t[1]!==r?(f=function(e){d&&!e||r(e)},t[0]=d,t[1]=r,t[2]=f):f=t[2];let p=f,m=u?`Voice model download failed`:`Setting up voice input`,h;t[3]===m?h=t[4]:(h=(0,$.jsx)(vt,{children:m}),t[3]=m,t[4]=h);let g=u?`The English voice model could not be downloaded or prepared.`:`First-time setup downloads a ~40 MB English speech model to your device.`,_;t[5]===g?_=t[6]:(_=(0,$.jsx)(Qe,{children:g}),t[5]=g,t[6]=_);let v;t[7]!==h||t[8]!==_?(v=(0,$.jsxs)(a,{children:[h,_]}),t[7]=h,t[8]=_,t[9]=v):v=t[9];let y;t[10]!==u||t[11]!==o||t[12]!==c||t[13]!==r||t[14]!==i||t[15]!==l?(y=u?(0,$.jsxs)(`div`,{className:`space-y-4 py-2`,children:[(0,$.jsx)(di,{variant:`error`,className:`mb-0`,children:u}),(0,$.jsxs)(we,{children:[(0,$.jsx)(s,{variant:`outline`,onClick:()=>r(!1),children:`Cancel`}),(0,$.jsx)(s,{onClick:i,children:`Try again`})]})]}):(0,$.jsxs)(`div`,{className:`space-y-4 py-2`,children:[(0,$.jsx)(di,{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)(Qr,{title:Yf(o,c,l)}),(0,$.jsx)(Jf,{value:c?100:l,className:`w-full`}),(0,$.jsx)(`p`,{className:z(W.bodyMuted,`text-center`),children:c?`Loading the model into memory. This usually takes a few seconds.`:l<100?`About 40 MB — kept on this device for future use.`:`Saving the model locally…`})]})]}),t[10]=u,t[11]=o,t[12]=c,t[13]=r,t[14]=i,t[15]=l,t[16]=y):y=t[16];let b;t[17]!==v||t[18]!==y?(b=(0,$.jsxs)(We,{children:[v,y]}),t[17]=v,t[18]=y,t[19]=b):b=t[19];let x;return t[20]!==p||t[21]!==n||t[22]!==b?(x=(0,$.jsx)(ie,{open:n,onOpenChange:p,children:b}),t[20]=p,t[21]=n,t[22]=b,t[23]=x):x=t[23],x}var Zf=ei(e=>(0,$.jsxs)(`slot`,{children:[(0,$.jsx)(`style`,{children:`
|
|
31
|
-
.recording-waveform {
|
|
32
|
-
display: flex;
|
|
33
|
-
align-items: center;
|
|
34
|
-
gap: 2px;
|
|
35
|
-
height: 16px;
|
|
36
|
-
}
|
|
37
|
-
.recording-waveform-bar {
|
|
38
|
-
display: block;
|
|
39
|
-
width: 3px;
|
|
40
|
-
height: 4px;
|
|
41
|
-
border-radius: 2px;
|
|
42
|
-
background: currentColor;
|
|
43
|
-
animation: waveform-bounce 0.7s ease-in-out infinite alternate;
|
|
44
|
-
}
|
|
45
|
-
@keyframes waveform-bounce {
|
|
46
|
-
from { height: 3px; }
|
|
47
|
-
to { height: 14px; }
|
|
48
|
-
}
|
|
49
|
-
`}),e.v0,e.v1]}),{name:`SpeechInput_1`,portals:[`v0`,`v1`]}),Qf=function({onTranscript:e,children:t}){let{state:n,isSupported:r,usesLocalModel:i,transcript:a,error:o,downloadProgress:s,startListening:c,stopListening:l,requestModelDownload:u,ensureReady:d,resetTranscript:f}=qf(),{toast:p}=$a(),[m,h]=(0,Y.useState)(!1),g=(0,Y.useRef)(``),_=(0,Y.useRef)(null),v=n===`recording`,y=n===`transcribing`,b=v||y,x=n===`needs-model`,S=n===`downloading-model`,C=n===`initializing`,w=S||C,T=n===`checking-support`;(0,Y.useEffect)(()=>{o&&o!==_.current&&!m&&p({title:`Voice Input Error`,description:o,variant:`destructive`}),_.current=o},[o,m,p]),(0,Y.useEffect)(()=>{if(a&&a!==g.current){let t=a.substring(g.current.length);g.current=a,e(t)}},[a,e]),(0,Y.useEffect)(()=>{a||(g.current=``)},[a]);function E(){h(!0),u()}let D=(0,Y.useCallback)(async()=>{if(b){l();return}if(x){E();return}if(n===`ready`){f(),c();return}if(n===`idle`){let e=await d();e===`needs-model`?E():e===`ready`&&(f(),c())}},[x,b,n,d,l,c,f,u]),O=(0,Y.useCallback)(()=>{u()},[u]);(0,Y.useEffect)(()=>{n===`ready`&&m&&h(!1)},[n,m]);let k=(0,Y.useCallback)(()=>T?`Checking voice input support...`:r===!1?`Voice input not supported in this browser`:o||(w?`Downloading speech model...`:y?`Transcribing...`:v?`Stop listening`:x?`Click to download speech model`:`Start listening`),[o,T,w,v,y,r,x]),A=(0,Y.useCallback)(()=>w||y?(0,$.jsx)(wn,{className:`h-3 w-3 animate-spin`}):v?(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)($t,{className:`h-3 w-3`}),[w,v,y]),j=k(),M=b?j:`Voice input`;return(0,$.jsx)(Zf,{v0:(0,$.jsxs)(B,{children:[(0,$.jsx)(L,{asChild:!0,children:t({onClick:D,disabled:T||w||y||r===!1,icon:A(),label:j,isRecording:v,isTranscribing:y,isDownloading:w,needsModel:x,isSupported:r!==!1})}),(0,$.jsx)(H,{side:`top`,className:`bg-popover text-popover-foreground max-w-64`,children:M})]}),v1:i?(0,$.jsx)(Xf,{open:m,onOpenChange:h,onRetry:O,isDownloading:S,isInitializing:C,progress:s,error:m?o:null}):null})};function $f(e){let t=(0,X.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:z(W.compact,W.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:z(W.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)(zn,{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)(di,{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}function ep(e){let t=(0,X.c)(27),{onSpeechClick:n,speechDisabled:r,icon:i,label:a,isRecording:o,isTranscribing:c,isDownloading:l,isSupported:u,hasMessageText:d,setIsVoiceActive:f,isStreaming:p,disabled:m,canSubmitMessage:h,attachmentsLength:g,effectiveModel:_,onStop:v,onSend:y}=e,b=o||c||l,x,S;t[0]!==b||t[1]!==f?(x=()=>{f(b)},S=[b,f],t[0]=b,t[1]=f,t[2]=x,t[3]=S):(x=t[2],S=t[3]),(0,Y.useEffect)(x,S);let C=!p&&!b&&((m??!1)||!h&&r||!d&&g>0&&!_||d&&!_),w;t[4]!==h||t[5]!==p||t[6]!==b||t[7]!==y||t[8]!==n||t[9]!==v?(w=function(){if(p){v?.();return}if(b){n();return}if(h){y();return}n()},t[4]=h,t[5]=p,t[6]=b,t[7]=y,t[8]=n,t[9]=v,t[10]=w):w=t[10];let T=w,E=p?`Stop generation`:b?a:h?`Send message`:a,D=`relative h-7 w-7 rounded-full ${o?`bg-primary text-primary-foreground hover:bg-primary/90`:``} ${p?`before:absolute before:inset-[-1px] before:rounded-full before:border before:border-primary/60 before:animate-ping-subtle before:content-['']`:``}`,O;t[11]!==h||t[12]!==i||t[13]!==p||t[14]!==b?(O=p?(0,$.jsx)(`span`,{className:`block h-3 w-3 shrink-0 rounded-[2px] bg-current`,"aria-hidden":`true`}):b||!h?i:(0,$.jsx)(Zt,{className:`h-3 w-3`}),t[11]=h,t[12]=i,t[13]=p,t[14]=b,t[15]=O):O=t[15];let k;t[16]===E?k=t[17]:(k=(0,$.jsx)(`span`,{className:`sr-only`,children:E}),t[16]=E,t[17]=k);let A;t[18]===u?A=t[19]:(A=!u&&(0,$.jsx)(`span`,{className:`sr-only`,children:`Voice input not supported`}),t[18]=u,t[19]=A);let j;return t[20]!==T||t[21]!==C||t[22]!==D||t[23]!==O||t[24]!==k||t[25]!==A?(j=(0,$.jsxs)(s,{size:`icon`,className:D,onClick:T,disabled:C,children:[O,k,A]}),t[20]=T,t[21]=C,t[22]=D,t[23]=O,t[24]=k,t[25]=A,t[26]=j):j=t[26],j}function tp(e){let t=(0,X.c)(197),{planMode:n,setPlanMode:r,onSend:i,onStop:a,isStreaming:c,disabled:l,initialValue:u,queuedMessages:d,onRemoveQueuedMessage:f,isOverlay:p,userTasks:m,onMatchedUserTaskSend:h,onUserTaskCreated:g}=e,_=c===void 0?!1:c,v=p===void 0?!1:p,y;t[0]===m?y=t[1]:(y=m===void 0?[]:m,t[0]=m,t[1]=y);let b=y,x;t[2]===u?x=t[3]:(x={initialValue:u},t[2]=u,t[3]=x);let{message:S,setMessage:C,historyIndex:w,setHistoryIndex:T,draftMessage:E,setDraftMessage:D,cursorPosition:O,setCursorPosition:k,availableModels:A,selectedModel:j,setSelectedModel:M,attachments:N,setAttachments:P,planMode:F,setPlanMode:I,ralphMode:ee,setRalphMode:te,imageMode:R,setImageMode:ne,availableImageModels:ie,selectedImageModel:ae,setSelectedImageModel:oe,allFiles:se,setAllFiles:ce,showSuggestions:le,setShowSuggestions:ue,suggestionQuery:de,setSuggestionQuery:fe,selectedIndex:pe,setSelectedIndex:V,slashCommands:me,skills:he,bundledSkills:ge,bundledSkillMode:_e,setBundledSkillMode:ve,showCommandSuggestions:ye,setShowCommandSuggestions:be,commandQuery:xe,setCommandQuery:Se,fileInputRef:Ce,textareaRef:we,suggestionsRef:U,commandSuggestionsRef:Te,selectedThreadId:Ee,dispatch:De}=jd(x),{paneId:Oe,conversationId:ke,setFocused:Ae,fillPane:je}=md(),Me=Q(up),Ne=Q(lp),Pe=Oe===`secondary`?Ne:Me,Fe=Q(cp),{isDualChatActive:Ie,showDualChatControls:Le,canCloseSecondary:Re,enableDualChat:ze,disableDualChat:Be}=Xd(),Ve;t[4]===Pe?Ve=t[5]:(Ve=Pe.some(sp),t[4]=Pe,t[5]=Ve);let He=Ve,Ue=R?ae:j,We=R?ie:A,Ge;t[6]===S?Ge=t[7]:(Ge=S.trim(),t[6]=S,t[7]=Ge);let Ke=Ge.length>0,qe=Ke||N.length>0,[Je,Ye]=Y.useState(!1),Xe=Jd(),Ze=n??F,Qe=r??I,$e=Ee??void 0,et;t[8]!==se||t[9]!==N||t[10]!==_e||t[11]!==ge||t[12]!==xe||t[13]!==O||t[14]!==De||t[15]!==E||t[16]!==Ze||t[17]!==Qe||t[18]!==He||t[19]!==w||t[20]!==R||t[21]!==_||t[22]!==S||t[23]!==h||t[24]!==i||t[25]!==ee||t[26]!==ae||t[27]!==pe||t[28]!==j||t[29]!==ce||t[30]!==P||t[31]!==ve||t[32]!==Se||t[33]!==k||t[34]!==D||t[35]!==T||t[36]!==ne||t[37]!==C||t[38]!==te||t[39]!==V||t[40]!==be||t[41]!==ue||t[42]!==fe||t[43]!==ye||t[44]!==le||t[45]!==he||t[46]!==me||t[47]!==de||t[48]!==$e||t[49]!==we||t[50]!==b?(et={message:S,setMessage:C,userTasks:b,onMatchedUserTaskSend:h,attachments:N,selectedModel:j,onSend:i,isStreaming:_,selectedThreadId:$e,isListening:!1,stopListening:op,resetTranscript:ap,dispatch:De,historyIndex:w,setHistoryIndex:T,draftMessage:E,setDraftMessage:D,cursorPosition:O,setCursorPosition:k,showSuggestions:le,setShowSuggestions:ue,suggestionQuery:de,setSuggestionQuery:fe,allFiles:se,setAllFiles:ce,selectedIndex:pe,setSelectedIndex:V,showCommandSuggestions:ye,setShowCommandSuggestions:be,commandQuery:xe,setCommandQuery:Se,slashCommands:me,skills:he,bundledSkills:ge,bundledSkillMode:_e,setBundledSkillMode:ve,textareaRef:we,setAttachments:P,planMode:Ze,setPlanMode:Qe,ralphMode:ee,setRalphMode:te,imageMode:R,setImageMode:ne,selectedImageModel:ae,hasConversationMessages:He},t[8]=se,t[9]=N,t[10]=_e,t[11]=ge,t[12]=xe,t[13]=O,t[14]=De,t[15]=E,t[16]=Ze,t[17]=Qe,t[18]=He,t[19]=w,t[20]=R,t[21]=_,t[22]=S,t[23]=h,t[24]=i,t[25]=ee,t[26]=ae,t[27]=pe,t[28]=j,t[29]=ce,t[30]=P,t[31]=ve,t[32]=Se,t[33]=k,t[34]=D,t[35]=T,t[36]=ne,t[37]=C,t[38]=te,t[39]=V,t[40]=be,t[41]=ue,t[42]=fe,t[43]=ye,t[44]=le,t[45]=he,t[46]=me,t[47]=de,t[48]=$e,t[49]=we,t[50]=b,t[51]=et):et=t[51];let{handleSend:tt,handleKeyDown:nt,handleTextareaInput:rt,insertFileReference:it,insertCommand:at,insertSkill:ot,fileSuggestions:st}=Ud(et),G;t[52]===C?G=t[53]:(G=e=>{C(t=>(t.endsWith(` `),t+e))},t[52]=C,t[53]=G);let ct=G,lt;t[54]===P?lt=t[55]:(lt=e=>{let t=e.clipboardData?.items;if(!t)return;let n=Array.from(t).filter(ip);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];P(n=>[...n,{fileName:t.name||`pasted-image.${t.type.split(`/`)[1]||`png`}`,content:e,mimeType:t.type}])},n.readAsDataURL(t)}}},t[54]=P,t[55]=lt);let ut=lt,dt;t[56]!==je||t[57]!==v?(dt=yd(je,v),t[56]=je,t[57]=v,t[58]=dt):dt=t[58];let ft=v?`border-border/50 bg-background/80 shadow-lg backdrop-blur-sm`:`border-border bg-background shadow-2xl`,pt;t[59]===ft?pt=t[60]:(pt=z(`relative flex min-w-0 flex-1 flex-col rounded-2xl border focus-within:ring-2 focus-within:ring-brand pointer-events-auto`,ft),t[59]=ft,t[60]=pt);let mt;t[61]!==Re||t[62]!==Be||t[63]!==l||t[64]!==Ie||t[65]!==Oe||t[66]!==Le?(mt=Le&&Oe===`secondary`&&Ie&&(0,$.jsx)(`div`,{className:`absolute top-2 right-2 z-10 hidden md:block`,children:(0,$.jsxs)(B,{children:[(0,$.jsx)(L,{asChild:!0,children:(0,$.jsxs)(s,{type:`button`,size:`icon`,variant:`ghost`,className:`h-7 w-7 text-muted-foreground hover:text-foreground`,onClick:Be,disabled:!Re||l,children:[(0,$.jsx)(zn,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Close dual chat`})]})}),(0,$.jsx)(H,{children:`Close dual chat`})]})}),t[61]=Re,t[62]=Be,t[63]=l,t[64]=Ie,t[65]=Oe,t[66]=Le,t[67]=mt):mt=t[67];let ht;t[68]!==f||t[69]!==d?(ht=(0,$.jsx)($f,{queuedMessages:d,onRemoveQueuedMessage:f}),t[68]=f,t[69]=d,t[70]=ht):ht=t[70];let gt=ee?`Describe stories for Ralph to implement autonomously...`:Ze?`Describe what you want Tarsk to plan...`:R?`Describe the image you want to generate...`:Je?`Dictate your message...`:`Ask Tarsk anything, # for files, / for commands & skills`,_t=Le&&Oe===`secondary`&&Ie&&`md:pr-12`,vt;t[71]===_t?vt=t[72]:(vt=z(W.body,`min-h-[4.5rem] w-full resize-none bg-transparent px-6 pt-4 pb-4 text-foreground placeholder:text-muted-foreground focus:outline-none`,_t),t[71]=_t,t[72]=vt);let yt;t[73]!==l||t[74]!==nt||t[75]!==ut||t[76]!==rt||t[77]!==S||t[78]!==Ae||t[79]!==gt||t[80]!==vt||t[81]!==we?(yt=(0,$.jsx)(`textarea`,{ref:we,value:S,onChange:rt,onKeyDown:nt,onPaste:ut,onFocus:Ae,placeholder:gt,rows:1,className:vt,disabled:l}),t[73]=l,t[74]=nt,t[75]=ut,t[76]=rt,t[77]=S,t[78]=Ae,t[79]=gt,t[80]=vt,t[81]=we,t[82]=yt):yt=t[82];let bt=_e?ge:he,xt=_e?`//`:`/`,St;t[83]!==xe||t[84]!==Te||t[85]!==at||t[86]!==ot||t[87]!==pe||t[88]!==V||t[89]!==ye||t[90]!==me||t[91]!==bt||t[92]!==xt?(St=(0,$.jsx)(ef,{visible:ye,commands:me,skills:bt,skillReferencePrefix:xt,query:xe,selectedIndex:pe,onSelectCommand:at,onSelectSkill:ot,onMouseEnterSuggestion:V,containerRef:Te}),t[83]=xe,t[84]=Te,t[85]=at,t[86]=ot,t[87]=pe,t[88]=V,t[89]=ye,t[90]=me,t[91]=bt,t[92]=xt,t[93]=St):St=t[93];let Ct;t[94]!==st||t[95]!==it||t[96]!==pe||t[97]!==V||t[98]!==le||t[99]!==de||t[100]!==U?(Ct=(0,$.jsx)(xf,{showSuggestions:le,fileSuggestions:st,suggestionQuery:de,selectedIndex:pe,onSelectFile:it,onMouseEnterSuggestion:V,containerRef:U}),t[94]=st,t[95]=it,t[96]=pe,t[97]=V,t[98]=le,t[99]=de,t[100]=U,t[101]=Ct):Ct=t[101];let wt;t[102]!==N||t[103]!==j?.id||t[104]!==j?.name||t[105]!==j?.supportsImages||t[106]!==P?(wt=N.length>0&&(0,$.jsxs)(`div`,{className:`px-4`,children:[(0,$.jsx)(sf,{attachments:N,onRemove:e=>P(t=>t.filter((t,n)=>n!==e))}),N.some(rp)&&j?.supportsImages===!1&&(0,$.jsxs)(`div`,{className:z(W.compact,`mb-2 flex items-center gap-1.5 text-amber-500`),children:[(0,$.jsx)(jn,{className:`h-3 w-3 shrink-0`}),(0,$.jsxs)(`span`,{children:[`Images are not supported by `,j?.name||j?.id]})]})]}),t[102]=N,t[103]=j?.id,t[104]=j?.name,t[105]=j?.supportsImages,t[106]=P,t[107]=wt):wt=t[107];let Tt;t[108]===Ce?Tt=t[109]:(Tt=()=>Ce.current?.click(),t[108]=Ce,t[109]=Tt);let Et;t[110]!==De||t[111]!==S||t[112]!==g||t[113]!==Oe||t[114]!==P||t[115]!==C||t[116]!==Ee||t[117]!==we?(Et=()=>{let e=Ee;if(!e)return;let t=S.trim();t&&o(e,t).then(t=>{g?.(t),C(``),P([]),De({type:Z.ClearChatInputDraft,threadId:Oe===`secondary`?`${e}:secondary`:e}),we.current&&(we.current.style.height=`auto`)}).catch(np)},t[110]=De,t[111]=S,t[112]=g,t[113]=Oe,t[114]=P,t[115]=C,t[116]=Ee,t[117]=we,t[118]=Et):Et=t[118];let K;t[119]!==l||t[120]!==Ze||t[121]!==Qe||t[122]!==Ke||t[123]!==R||t[124]!==Xe||t[125]!==ee||t[126]!==Fe||t[127]!==ne||t[128]!==te||t[129]!==Tt||t[130]!==Et?(K=(0,$.jsx)(If,{disabled:l,canAddTask:Ke,showModes:Xe,planMode:Ze,imageMode:R,ralphMode:ee,setPlanMode:Qe,setImageMode:ne,setRalphMode:te,projectId:Fe,onFileAttach:Tt,onAddTask:Et}),t[119]=l,t[120]=Ze,t[121]=Qe,t[122]=Ke,t[123]=R,t[124]=Xe,t[125]=ee,t[126]=Fe,t[127]=ne,t[128]=te,t[129]=Tt,t[130]=Et,t[131]=K):K=t[131];let q=R?oe:M,Dt;t[132]!==We||t[133]!==Ue||t[134]!==q?(Dt=(0,$.jsx)(kf,{availableModels:We,selectedModel:Ue,onModelSelect:q}),t[132]=We,t[133]=Ue,t[134]=q,t[135]=Dt):Dt=t[135];let Ot;t[136]!==K||t[137]!==Dt?(Ot=(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[K,Dt]}),t[136]=K,t[137]=Dt,t[138]=Ot):Ot=t[138];let kt;t[139]!==Ze||t[140]!==Qe||t[141]!==R||t[142]!==ee||t[143]!==Fe||t[144]!==ne||t[145]!==te?(kt=(0,$.jsx)(Ff,{planMode:Ze,imageMode:R,ralphMode:ee,setPlanMode:Qe,setImageMode:ne,setRalphMode:te,projectId:Fe}),t[139]=Ze,t[140]=Qe,t[141]=R,t[142]=ee,t[143]=Fe,t[144]=ne,t[145]=te,t[146]=kt):kt=t[146];let At=Ee??void 0,jt;t[147]!==ke||t[148]!==Pe||t[149]!==At?(jt=(0,$.jsx)(yf,{threadId:At,conversationId:ke,messages:Pe}),t[147]=ke,t[148]=Pe,t[149]=At,t[150]=jt):jt=t[150];let Mt;t[151]!==N.length||t[152]!==qe||t[153]!==l||t[154]!==Ue||t[155]!==tt||t[156]!==Ke||t[157]!==_||t[158]!==a?(Mt=e=>{let{onClick:t,disabled:n,icon:r,label:i,isRecording:o,isTranscribing:s,isDownloading:c,isSupported:u}=e;return(0,$.jsx)(ep,{onSpeechClick:t,speechDisabled:n,icon:r,label:i,isRecording:o,isTranscribing:s,isDownloading:c,isSupported:u,hasMessageText:Ke,setIsVoiceActive:Ye,isStreaming:_,disabled:l,canSubmitMessage:qe,attachmentsLength:N.length,effectiveModel:Ue,onStop:a,onSend:tt})},t[151]=N.length,t[152]=qe,t[153]=l,t[154]=Ue,t[155]=tt,t[156]=Ke,t[157]=_,t[158]=a,t[159]=Mt):Mt=t[159];let Nt;t[160]!==ct||t[161]!==Mt?(Nt=(0,$.jsx)(Qf,{onTranscript:ct,children:Mt}),t[160]=ct,t[161]=Mt,t[162]=Nt):Nt=t[162];let Pt;t[163]!==kt||t[164]!==jt||t[165]!==Nt?(Pt=(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[kt,jt,Nt]}),t[163]=kt,t[164]=jt,t[165]=Nt,t[166]=Pt):Pt=t[166];let Ft;t[167]!==Ot||t[168]!==Pt?(Ft=(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-3 pb-2`,children:[Ot,Pt]}),t[167]=Ot,t[168]=Pt,t[169]=Ft):Ft=t[169];let It;t[170]!==pt||t[171]!==mt||t[172]!==ht||t[173]!==yt||t[174]!==St||t[175]!==Ct||t[176]!==wt||t[177]!==Ft?(It=(0,$.jsxs)(`div`,{className:pt,children:[mt,ht,yt,St,Ct,wt,Ft]}),t[170]=pt,t[171]=mt,t[172]=ht,t[173]=yt,t[174]=St,t[175]=Ct,t[176]=wt,t[177]=Ft,t[178]=It):It=t[178];let Lt;t[179]!==l||t[180]!==ze||t[181]!==Ie||t[182]!==Oe||t[183]!==Le?(Lt=Le&&Oe===`primary`&&!Ie&&(0,$.jsxs)(B,{children:[(0,$.jsx)(L,{asChild:!0,children:(0,$.jsxs)(s,{type:`button`,size:`icon`,variant:`ghost`,className:`hidden h-7 w-7 shrink-0 pointer-events-auto md:inline-flex`,onClick:ze,disabled:l,children:[(0,$.jsx)(re,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Open dual chat`})]})}),(0,$.jsx)(H,{children:`Open dual chat`})]}),t[179]=l,t[180]=ze,t[181]=Ie,t[182]=Oe,t[183]=Le,t[184]=Lt):Lt=t[184];let Rt;t[185]!==It||t[186]!==Lt?(Rt=(0,$.jsxs)(`div`,{className:`relative flex min-w-0 items-center gap-1`,children:[It,Lt]}),t[185]=It,t[186]=Lt,t[187]=Rt):Rt=t[187];let zt;t[188]===P?zt=t[189]:(zt=e=>bf(e,e=>P(t=>[...t,...e])),t[188]=P,t[189]=zt);let Bt;t[190]!==Ce||t[191]!==zt?(Bt=(0,$.jsx)(`input`,{ref:Ce,type:`file`,multiple:!0,className:`hidden`,onChange:zt}),t[190]=Ce,t[191]=zt,t[192]=Bt):Bt=t[192];let Vt;return t[193]!==dt||t[194]!==Rt||t[195]!==Bt?(Vt=(0,$.jsxs)(`div`,{className:dt,children:[Rt,Bt]}),t[193]=dt,t[194]=Rt,t[195]=Bt,t[196]=Vt):Vt=t[196],Vt}function np(e){console.error(`Failed to create user task:`,e)}function rp(e){return e.mimeType.startsWith(`image/`)}function ip(e){return e.type.startsWith(`image/`)}function ap(){}function op(){}function sp(e){return e.sender===`agent`}function cp(e){return e.selectedProjectId}function lp(e){return e.secondaryMessages}function up(e){return e.messages}var dp=`[gitops-timing]`;function fp(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,ms:r}),console.log(`${dp} ${e} step=${n} ${r}ms`)}}function i(n,r,i){t.push({step:n,ms:r}),console.log(`${dp} ${e} step=${n} ${r}ms${i?` ${i}`:``}`)}function a(r){let i=Math.round(performance.now()-n),a=t.reduce((e,t)=>t.ms>=e.ms?t:e,{step:`none`,ms:0}),o=t.map(e=>`${e.step}:${e.ms}`).join(` `);console.log(`${dp} ${e} summary total=${i}ms slowest=${a.step}@${a.ms}ms breakdown=[${o}]${r?` ${r}`:``}`)}return{step:r,record:i,summary:a}}var pp=3e4,mp={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},hp=new Map,gp=new Map;function _p(e,t){let n=hp.get(e);if(n)for(let e of n)e(t)}function vp(e,t){let n=hp.get(e);return n||(n=new Set,hp.set(e,n)),n.add(t),()=>{n.delete(t),n.size===0&&hp.delete(e)}}function yp(e){return`unified-git-status-${e}`}function bp(e){return k.getSync(yp(e))}function xp(e){let[t,n]=(0,Y.useState)(mp),[r,i]=(0,Y.useState)(!1),a=(0,Y.useRef)(void 0),o=(0,Y.useRef)(0),s=(0,Y.useCallback)(e=>{(0,Y.startTransition)(()=>{n(e)})},[]),c=(0,Y.useRef)(s);c.current=s;let l=(0,Y.useCallback)(async(t=!1)=>{if(!e)return;let n=++o.current,r=fp(`hook fetch thread=${e} force=${t}`),a=setTimeout(()=>{o.current===n&&i(!0)},100);try{let i=yp(e),a=performance.now(),c=bp(e);r.record(`local-cache-check`,Math.round(performance.now()-a),`result=${c?`hit`:`miss`}`),t&&(k.invalidate(i),r.record(`invalidate-local-cache`,0));let l=await r.step(`ttl-cache-get`,()=>k.get(i,()=>Kn(e,t,!1),pp));if(o.current!==n){r.summary(`stale-request`);return}await r.step(`update-state`,async()=>{s(l),_p(e,l)}),r.summary(`branch=${l.currentBranch} changes=${l.changedFilesCount} prExists=${l.prExists}`)}catch(e){if(o.current!==n)return;console.error(`Failed to fetch unified git status:`,e),r.summary(`error`)}finally{clearTimeout(a),o.current===n&&i(!1)}},[e,s]),u=(0,Y.useRef)(l);return u.current=l,(0,Y.useEffect)(()=>{if(e)return vp(e,e=>{c.current(e)})},[e]),(0,Y.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,Y.useEffect)(()=>{if(o.current+=1,i(!1),!e){a.current=void 0,(0,Y.startTransition)(()=>{n(mp)});return}let t=a.current!==e,r=bp(e);t&&(console.log(`[gitops-timing] hook thread changed ${a.current??`none`} -> ${e}`),a.current=e),(0,Y.startTransition)(()=>{n(r??mp)}),console.log(r?`[gitops-timing] hook load thread=${e} local cache=hit`:`[gitops-timing] hook load thread=${e} local cache=miss`);let s=e,l=!1;function d(){if(l)return;let e=gp.get(s);if(e){console.log(`[gitops-timing] hook initial fetch already in flight thread=${s}`),e.then(()=>{if(l)return;let e=bp(s);e&&c.current(e)});return}console.log(`[gitops-timing] hook starting initial fetch thread=${s}`);let t=u.current(!1).finally(()=>{console.log(`[gitops-timing] hook initial fetch settled thread=${s}`),gp.delete(s)});gp.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 Sp=(0,Y.createContext)(void 0);function Cp(e){let t=(0,X.c)(7),{threadId:n,fetchUnifiedStatus:r}=e,i=Q(Ep),a=Q(Tp),o=Q(wp),s,c;return t[0]!==a||t[1]!==r||t[2]!==i||t[3]!==o||t[4]!==n?(s=()=>{if(!(!n||n!==o)&&!i&&a.includes(n)){let e=setTimeout(()=>{r(!1)},1e3);return()=>clearTimeout(e)}},c=[n,o,i,a,r],t[0]=a,t[1]=r,t[2]=i,t[3]=o,t[4]=n,t[5]=s,t[6]=c):(s=t[5],c=t[6]),(0,Y.useEffect)(s,c),null}function wp(e){return e.selectedThreadId}function Tp(e){return e.completedThreadIds}function Ep(e){return e.isStreaming}function Dp(e){let t=(0,X.c)(7),{threadId:n,children:r}=e,i=xp(n),a;t[0]!==n||t[1]!==i.fetchUnifiedStatus?(a=(0,$.jsx)(Cp,{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)(Sp.Provider,{value:i,children:[a,r]}),t[3]=r,t[4]=a,t[5]=i,t[6]=o):o=t[6],o}function Op(){let e=(0,Y.useContext)(Sp);if(e===void 0)throw Error(`useGitStatus must be used within a GitStatusProvider`);return e}var kp=ei(e=>(0,$.jsxs)(`svg`,{"aria-hidden":`true`,width:e.v0,height:e.v1,viewBox:e.v2,className:`size-10 shrink-0`,children:[(0,$.jsx)(`circle`,{cx:e.v3,cy:e.v4,r:e.v5,fill:`none`,stroke:`currentColor`,strokeOpacity:`0.2`,strokeWidth:e.v6}),(0,$.jsx)(`circle`,{cx:e.v7,cy:e.v8,r:e.v9,fill:`none`,stroke:`currentColor`,strokeWidth:e.v10,strokeDasharray:e.v11,strokeDashoffset:e.v12,strokeLinecap:`round`,transform:e.v13,className:`transition-[stroke-dashoffset] duration-300 ease-out`})]}),{name:`TodoProgressRing_1`,svg:!0}),Ap=function(e){let t=(0,X.c)(2),{completedCount:n,totalCount:r}=e,i=Pp*(1-(r>0?n/r:0)),a=jp/2,o;return t[0]===i?o=t[1]:(o=(0,$.jsx)(kp,{v0:jp,v1:jp,v2:`0 0 ${jp} ${jp}`,v3:a,v4:a,v5:Np,v6:Mp,v7:a,v8:a,v9:Np,v10:Mp,v11:Pp,v12:i,v13:`rotate(-90 ${a} ${a})`}),t[0]=i,t[1]=o),o},jp=40,Mp=4,Np=10,Pp=2*Math.PI*Np;function Fp(e){let t=(0,X.c)(13),{todos:n}=e,r;t[0]===n?r=t[1]:(r=n.filter(Lp),t[0]=n,t[1]=r);let i=r.length,a;t[2]===n.length?a=t[3]:(a=n.length===0&&(0,$.jsx)(`p`,{className:W.compact,children:`No todo items.`}),t[2]=n.length,t[3]=a);let o;t[4]===n?o=t[5]:(o=n.map(Ip),t[4]=n,t[5]=o);let s;t[6]!==i||t[7]!==n.length?(s=n.length>0&&(0,$.jsxs)(`p`,{className:z(W.compact,`pt-1`),children:[i,`/`,n.length,` completed`]}),t[6]=i,t[7]=n.length,t[8]=s):s=t[8];let c;return t[9]!==a||t[10]!==o||t[11]!==s?(c=(0,$.jsxs)(`div`,{className:`space-y-1`,children:[a,o,s]}),t[9]=a,t[10]=o,t[11]=s,t[12]=c):c=t[12],c}function Ip(e){return(0,$.jsxs)(`div`,{className:z(W.caption,`flex items-start gap-2`),children:[e.status===`done`?(0,$.jsx)(A,{className:`h-4 w-4 shrink-0 mt-0.5 text-brand`}):e.status===`working`?(0,$.jsx)(Re,{className:`h-4 w-4 shrink-0 mt-0.5 text-yellow-500`}):(0,$.jsx)(N,{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 Lp(e){return e.status===`done`}function Rp(e){let t=(0,X.c)(43),{layout:n}=e,r=n===void 0?`bar`:n,{todos:i}=(0,Y.useContext)(bl),[o,c]=(0,Y.useState)(!1),l;t[0]===i?l=t[1]:(l=i.filter(zp),t[0]=i,t[1]=l);let u=l.length,d=i.length-u,f=`${u} of ${i.length} complete`;if(d<=0)return null;if(r===`menu`){let e;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(e=()=>c(!0),t[2]=e):e=t[2];let n;t[3]!==u||t[4]!==i.length?(n=(0,$.jsx)(Ap,{completedCount:u,totalCount:i.length}),t[3]=u,t[4]=i.length,t[5]=n):n=t[5];let r;t[6]===f?r=t[7]:(r=(0,$.jsx)(`span`,{children:f}),t[6]=f,t[7]=r);let l;t[8]!==n||t[9]!==r?(l=(0,$.jsxs)(s,{variant:`ghost`,size:`sm`,className:`w-full justify-start gap-2`,onClick:e,children:[n,r]}),t[8]=n,t[9]=r,t[10]=l):l=t[10];let d;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,$.jsx)(a,{children:(0,$.jsx)(vt,{children:`Agent Todos`})}),t[11]=d):d=t[11];let p;t[12]===i?p=t[13]:(p=(0,$.jsxs)(We,{className:`max-w-md`,children:[d,(0,$.jsx)(Fp,{todos:i})]}),t[12]=i,t[13]=p);let m;t[14]!==o||t[15]!==p?(m=(0,$.jsx)(ie,{open:o,onOpenChange:c,children:p}),t[14]=o,t[15]=p,t[16]=m):m=t[16];let h;return t[17]!==l||t[18]!==m?(h=(0,$.jsxs)($.Fragment,{children:[l,m]}),t[17]=l,t[18]=m,t[19]=h):h=t[19],h}let p;t[20]===Symbol.for(`react.memo_cache_sentinel`)?(p=()=>c(!0),t[20]=p):p=t[20];let m;t[21]!==u||t[22]!==i.length?(m=(0,$.jsx)(Ap,{completedCount:u,totalCount:i.length}),t[21]=u,t[22]=i.length,t[23]=m):m=t[23];let h;t[24]===f?h=t[25]:(h=(0,$.jsx)(`span`,{className:`sr-only`,children:f}),t[24]=f,t[25]=h);let g;t[26]!==m||t[27]!==h?(g=(0,$.jsx)(L,{asChild:!0,children:(0,$.jsxs)(s,{variant:`ghost`,size:`icon`,className:`ml-2 rounded-full [&_svg]:!size-10`,onClick:p,children:[m,h]})}),t[26]=m,t[27]=h,t[28]=g):g=t[28];let _;t[29]===f?_=t[30]:(_=(0,$.jsx)(H,{children:f}),t[29]=f,t[30]=_);let v;t[31]!==g||t[32]!==_?(v=(0,$.jsx)(D,{children:(0,$.jsxs)(B,{children:[g,_]})}),t[31]=g,t[32]=_,t[33]=v):v=t[33];let y;t[34]===Symbol.for(`react.memo_cache_sentinel`)?(y=(0,$.jsx)(a,{children:(0,$.jsx)(vt,{children:`Agent Todos`})}),t[34]=y):y=t[34];let b;t[35]===i?b=t[36]:(b=(0,$.jsxs)(We,{className:`max-w-md`,children:[y,(0,$.jsx)(Fp,{todos:i})]}),t[35]=i,t[36]=b);let x;t[37]!==o||t[38]!==b?(x=(0,$.jsx)(ie,{open:o,onOpenChange:c,children:b}),t[37]=o,t[38]=b,t[39]=x):x=t[39];let S;return t[40]!==x||t[41]!==v?(S=(0,$.jsxs)($.Fragment,{children:[v,x]}),t[40]=x,t[41]=v,t[42]=S):S=t[42],S}function zp(e){return e.status===`done`}function Bp(e){let t=(0,X.c)(34),{tasks:n,disabled:r,onSelectTask:i,onTogglePinned:a,onRemoveTask:o,layout:c}=e,l=r===void 0?!1:r,u=c===void 0?`bar`:c,[d,f]=(0,Y.useState)(!1),p=n.length,m=`${p} ${p===1?`Task`:`Tasks`}`;if(p===0)return null;let h;t[0]===i?h=t[1]:(h=function(e){i(e),f(!1)},t[0]=i,t[1]=h);let g=h,_;t[2]!==o||t[3]!==p?(_=function(e){o(e),p===1&&f(!1)},t[2]=o,t[3]=p,t[4]=_):_=t[4];let v=_,y;t[5]===a?y=t[6]:(y=function(e){a(e)},t[5]=a,t[6]=y);let b=y,x=u===`menu`?`ghost`:`outline`,S=u===`bar`&&`bg-background`,C=u===`menu`&&`w-full justify-start`,w;t[7]!==S||t[8]!==C?(w=z(`gap-2`,S,C),t[7]=S,t[8]=C,t[9]=w):w=t[9];let T;t[10]===m?T=t[11]:(T=(0,$.jsx)(`span`,{children:m}),t[10]=m,t[11]=T);let E;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(E=(0,$.jsx)(ln,{className:`h-4 w-4 shrink-0`}),t[12]=E):E=t[12];let O;t[13]!==l||t[14]!==T||t[15]!==x||t[16]!==w?(O=(0,$.jsx)(Jc,{asChild:!0,children:(0,$.jsxs)(s,{variant:x,size:`sm`,className:w,disabled:l,children:[T,E]})}),t[13]=l,t[14]=T,t[15]=x,t[16]=w,t[17]=O):O=t[17];let k;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(k=(0,$.jsx)(`div`,{className:z(W.compact,W.label,`px-2 pb-1 pt-1 text-muted-foreground`),children:`Tasks`}),t[18]=k):k=t[18];let A;if(t[19]!==v||t[20]!==g||t[21]!==b||t[22]!==n){let e;t[24]!==v||t[25]!==g||t[26]!==b?(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:()=>g(e),children:[(0,$.jsx)(U,{className:`mt-0.5 h-4 w-4 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{className:z(W.body,`line-clamp-3 text-foreground`),children:e.content})]}),(0,$.jsxs)(B,{children:[(0,$.jsx)(L,{asChild:!0,children:(0,$.jsxs)(s,{type:`button`,variant:`ghost`,size:`icon`,className:z(`h-7 w-7 shrink-0`,e.pinned&&`text-primary hover:text-primary`),onClick:()=>b(e.id),children:[(0,$.jsx)(Ge,{className:z(`h-4 w-4`,e.pinned&&`fill-current`)}),(0,$.jsx)(`span`,{className:`sr-only`,children:e.pinned?`Unpin task`:`Pin task`})]})}),(0,$.jsx)(H,{children:e.pinned?`Unpin task`:`Pin task`})]}),(0,$.jsxs)(s,{type:`button`,variant:`ghost`,size:`icon`,className:`h-7 w-7 shrink-0`,onClick:()=>v(e.id),children:[(0,$.jsx)(zn,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Remove task`})]})]},e.id),t[24]=v,t[25]=g,t[26]=b,t[27]=e):e=t[27],A=n.map(e),t[19]=v,t[20]=g,t[21]=b,t[22]=n,t[23]=A}else A=t[23];let j;t[28]===A?j=t[29]:(j=(0,$.jsx)(Yc,{align:`start`,className:`w-96 p-2`,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[k,A]})}),t[28]=A,t[29]=j);let M;return t[30]!==d||t[31]!==O||t[32]!==j?(M=(0,$.jsx)(D,{children:(0,$.jsxs)(qc,{open:d,onOpenChange:f,children:[O,j]})}),t[30]=d,t[31]=O,t[32]=j,t[33]=M):M=t[33],M}function Vp(e){let t=(0,X.c)(23),n=kr(),r;t[0]===e?r=t[1]:(r=Od.userTasks(e),t[0]=e,t[1]=r);let i;t[2]===e?i=t[3]:(i=()=>f(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=Wr(o),c;t[8]!==n||t[9]!==e?(c=t=>{e&&n.setQueryData(Od.userTasks(e),e=>typeof t==`function`?t(e??[]):t)},t[8]=n,t[9]=e,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]!==n||t[14]!==e?(d=()=>n.invalidateQueries({queryKey:Od.userTasks(e)}),t[13]=n,t[14]=e,t[15]=d):d=t[15];let p;return t[16]!==s.error||t[17]!==s.isError||t[18]!==s.isLoading||t[19]!==l||t[20]!==u||t[21]!==d?(p={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]=p):p=t[22],p}function Hp(e,t){let n=e.find(e=>e.threads.some(e=>e.threadId===t));if(!n)return`New Chat`;let r=new Set(n.threads.filter(e=>e.threadId!==t).map(e=>e.title.trim()).filter(e=>e.length>0)),i=1,a=`New Chat`;for(;r.has(a);)i+=1,a=`New Chat ${i}`;return a}var Up=(0,Y.createContext)(void 0);function Wp(e){let t=(0,X.c)(33),{children:n}=e,r=Ia(),{paneId:i}=md(),a=Q(Jp),o=Q(qp),s=Q(Kp),c=Q(Gp),{toast:l}=$a(),{userTasks:u,setUserTasks:d,isError:f}=Vp(i===`primary`?a:null),p;t[0]===i?p=t[1]:(p=e=>{let t=i===`primary`&&e.pendingChatMessage?.threadId===e.selectedThreadId;return e.selectedThreadId?Ri(e.threadStreamingStates,e.selectedThreadId,i).isStreaming||t:!1},t[0]=i,t[1]=p);let m=Q(p),h,g;t[2]!==f||t[3]!==l?(h=()=>{f&&l({title:`Could not load tasks`,description:`Failed to load UserTasks for this thread.`,variant:`destructive`})},g=[f,l],t[2]=f,t[3]=l,t[4]=h,t[5]=g):(h=t[4],g=t[5]),(0,Y.useEffect)(h,g);let _;t[6]!==r||t[7]!==i||t[8]!==o||t[9]!==s||t[10]!==a?(_=async()=>{if(a){if(i===`secondary`){r({type:Z.SetSecondaryMessages,messages:[]});return}try{let e=Hp(o,a);await M(a,{title:e}),s&&r({type:Z.UpdateThreadTitle,projectId:s,threadId:a,title:e});let t=await wt(a);r({type:Z.ClearMessages}),console.log(`New conversation started:`,t),setTimeout(()=>{(async()=>{try{let e=await mn(a);r({type:Z.SetMessages,messages:e.messages})}catch(e){console.error(`Failed to refresh chat history after starting new chat:`,e)}})()},0)}catch(e){console.error(`Failed to start new chat:`,e)}}},t[6]=r,t[7]=i,t[8]=o,t[9]=s,t[10]=a,t[11]=_):_=t[11];let v=_,y;t[12]!==a||t[13]!==d||t[14]!==l?(y=async e=>{if(a)try{await Vn(a,e),d(t=>t.filter(t=>t.id!==e))}catch(e){console.error(`Failed to delete user task:`,e),l({title:`Could not remove task`,description:`Failed to delete the selected task.`,variant:`destructive`})}},t[12]=a,t[13]=d,t[14]=l,t[15]=y):y=t[15];let b=y,x;t[16]===d?x=t[17]:(x=e=>{d(t=>t.map(t=>t.id===e?{...t,pinned:!t.pinned}:t))},t[16]=d,t[17]=x);let S=x,C;t[18]!==r||t[19]!==a?(C=e=>{a&&r({type:Z.SetChatInputDraft,threadId:a,draft:e.content})},t[18]=r,t[19]=a,t[20]=C):C=t[20];let w=C,T;t[21]!==m||t[22]!==v||t[23]!==b||t[24]!==w||t[25]!==c||t[26]!==d||t[27]!==S||t[28]!==u?(T={userTasks:u,setUserTasks:d,handleNewChat:v,handleSelectUserTask:w,handleRemoveUserTask:b,toggleUserTaskPinned:S,effectiveIsStreaming:m,isCreatingProject:c},t[21]=m,t[22]=v,t[23]=b,t[24]=w,t[25]=c,t[26]=d,t[27]=S,t[28]=u,t[29]=T):T=t[29];let E=T,D;return t[30]!==n||t[31]!==E?(D=(0,$.jsx)(Up.Provider,{value:E,children:n}),t[30]=n,t[31]=E,t[32]=D):D=t[32],D}function Gp(e){return e.isCreatingProject}function Kp(e){return e.selectedProjectId}function qp(e){return e.projects}function Jp(e){return e.selectedThreadId}function Yp(){let e=(0,Y.useContext)(Up);if(e===void 0)throw Error(`useChatInputToolbar must be used within a ChatInputToolbarProvider`);return e}var Xp=function({workspaceEntries:e,hasMultipleWorkspaces:t,runningScripts:n,onScriptClick:r}){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)(`button`,{type:`button`,className:`flex items-center gap-2 rounded-sm px-2 py-1.5 text-sm hover:bg-accent`,onClick:()=>{r(e)},children:[n.has(e.name)?(0,$.jsx)(wn,{className:`h-3 w-3 animate-spin shrink-0`}):(0,$.jsx)(`div`,{className:`h-3 w-3 shrink-0`}),e.friendlyName]},e.name))]},e)):e[0]?.[1].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`,onClick:()=>{r(e)},children:[n.has(e.name)?(0,$.jsx)(wn,{className:`h-3 w-3 animate-spin shrink-0`}):(0,$.jsx)(`div`,{className:`h-3 w-3 shrink-0`}),e.friendlyName]},e.name))};function Zp({workspaceEntries:e,hasMultipleWorkspaces:t,runningScripts:n,onScriptClick:r}){return t?e.map(([e,t])=>(0,$.jsxs)(Hl,{children:[(0,$.jsx)(Ul,{children:e}),(0,$.jsx)(Wl,{className:`max-h-[min(400px,80vh)] overflow-y-auto`,children:t.map(e=>(0,$.jsxs)(Kl,{onClick:()=>{r(e)},className:`gap-2`,children:[n.has(e.name)?(0,$.jsx)(wn,{className:`h-3 w-3 animate-spin shrink-0`}):(0,$.jsx)(`div`,{className:`h-3 w-3 shrink-0`}),e.friendlyName]},e.name))})]},e)):e[0]?.[1].map(e=>(0,$.jsxs)(Kl,{onClick:()=>{r(e)},className:`gap-2`,children:[n.has(e.name)?(0,$.jsx)(wn,{className:`h-3 w-3 animate-spin shrink-0`}):(0,$.jsx)(`div`,{className:`h-3 w-3 shrink-0`}),e.friendlyName]},e.name))}function Qp({threadId:e,layout:t=`bar`}){let n=Ia(),{setTerminalNotification:r,setActiveMainTab:i}=Ks(),{setDevServerUrl:a}=ed(),[o,c]=(0,Y.useState)(null),[l,d]=(0,Y.useState)(new Set),f=(0,Y.useRef)(new Map);(0,Y.useEffect)(()=>((async()=>{try{let t=await Fn(e);if(t.length===0){c(null);return}c(t),d(new Set(t.filter(e=>e.isRunning).map(e=>e.name)))}catch{c(null)}})(),()=>{for(let e of f.current.values())e.abort();f.current.clear()}),[e]);function p(t){if(typeof t==`string`){n({type:Z.AppendTerminalLine,threadId:e,line:{type:`output`,content:t}});return}if(!(!t||typeof t!=`object`)){if(nd(t)){td({url:t.url,setDevServerUrl:a,setActiveMainTab:i,onTerminalMessage:t=>{n({type:Z.AppendTerminalLine,threadId:e,line:{type:`system`,content:t}})}});return}`type`in t&&t.type===`error`&&`message`in t&&n({type:Z.AppendTerminalLine,threadId:e,line:{type:`error`,content:String(t.message)}})}}let m=async t=>{if(l.has(t.name)){let r=f.current.get(t.name);r&&(r.abort(),f.current.delete(t.name));try{await v(e,t.name)}catch{}n({type:Z.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 i=new AbortController;f.current.set(t.name,i),d(e=>new Set([...e,t.name])),r(!0),n({type:Z.AppendTerminalLine,threadId:e,line:{type:`system`,content:`▶ ${t.friendlyName}`}});try{let r=await Gt(e,t.name,t.command,{signal:i.signal});if(r){let t=r.getReader(),i=new TextDecoder,a=``;try{for(;;){let{done:r,value:o}=await t.read();if(r)break;a+=i.decode(o,{stream:!0});let s=a.split(`
|
|
50
|
-
`);a=s.pop()??``;for(let t of s)if(t.trim())try{p(JSON.parse(t))}catch{n({type:Z.AppendTerminalLine,threadId:e,line:{type:`output`,content:t}})}}if(a.trim())try{p(JSON.parse(a))}catch{n({type:Z.AppendTerminalLine,threadId:e,line:{type:`output`,content:a}})}}finally{t.releaseLock()}}n({type:Z.AppendTerminalLine,threadId:e,line:{type:`system`,content:`✓ ${t.friendlyName} done`}})}catch{}finally{f.current.delete(t.name),d(e=>{let n=new Set(e);return n.delete(t.name),n})}}};if(!o)return null;let h=o.reduce((e,t)=>(e[t.workspace]||(e[t.workspace]=[]),e[t.workspace].push(t),e),{}),g=Object.entries(h).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>[e,[...t].sort((e,t)=>e.friendlyName.localeCompare(t.friendlyName))]),_=g.length>1;function y(e){m(e)}return t===`menu`?(0,$.jsxs)(qc,{children:[(0,$.jsx)(Jc,{asChild:!0,children:(0,$.jsxs)(s,{variant:`ghost`,size:`sm`,className:`w-full justify-start gap-2`,children:[(0,$.jsx)(u,{className:`h-4 w-4 shrink-0`}),`Project Scripts`]})}),(0,$.jsx)(Yc,{align:`start`,className:`w-56 p-1`,children:(0,$.jsx)(Xp,{workspaceEntries:g,hasMultipleWorkspaces:_,runningScripts:l,onScriptClick:y})})]}):(0,$.jsxs)(Bl,{children:[(0,$.jsx)(D,{children:(0,$.jsxs)(B,{children:[(0,$.jsx)(L,{asChild:!0,children:(0,$.jsx)(Vl,{asChild:!0,children:(0,$.jsx)(s,{variant:`action`,size:`icon-md`,children:(0,$.jsx)(u,{})})})}),(0,$.jsx)(H,{children:`Project Scripts`})]})}),(0,$.jsx)(Gl,{align:`end`,className:`min-w-[180px]`,children:(0,$.jsx)(Zp,{workspaceEntries:g,hasMultipleWorkspaces:_,runningScripts:l,onScriptClick:y})})]})}var $p=`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 em({open:e,onOpenChange:t,projectId:n,commands:r,onRefresh:i}){let[o,c]=(0,Y.useState)(null),[l,u]=(0,Y.useState)(!1),[d,f]=(0,Y.useState)(!1),[p,m]=(0,Y.useState)([]),[h,g]=(0,Y.useState)(0),[_,v]=(0,Y.useState)(!1),y=(0,Y.useRef)(null),x=(0,Y.useRef)(null),S=()=>{c({id:crypto.randomUUID(),name:``,icon:`Play`,commandLine:``}),f(!1),m([])},C=e=>{c({...e}),f(!1),m([])},w=async()=>{try{v(!0);let e=await qt(n);m(e.scripts),g(0),f(e.scripts.length>0)}catch(e){console.error(`Failed to load package scripts:`,e),Qa({title:`Error`,description:`Failed to load package scripts`,variant:`destructive`})}finally{v(!1)}},T=e=>{c(t=>t?{...t,name:e.name,commandLine:e.commandLine,relativeFolder:e.relativePath||``}:null),f(!1),m([]),y.current?.focus()},E=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&&T(p[h])):e.key===`Escape`&&(e.preventDefault(),f(!1),m([])))};(0,Y.useEffect)(()=>{let e=e=>{x.current&&!x.current.contains(e.target)&&(f(!1),m([]))};return d&&document.addEventListener(`mousedown`,e),()=>{document.removeEventListener(`mousedown`,e)}},[d]);let O=async e=>{try{await Nt(n,e),Qa({title:`Success`,description:`Command deleted`}),i()}catch{Qa({title:`Error`,description:`Failed to delete command`,variant:`destructive`})}};return(0,$.jsx)(ie,{open:e,onOpenChange:t,children:(0,$.jsxs)(We,{className:`sm:max-w-[500px]`,children:[(0,$.jsxs)(a,{children:[(0,$.jsx)(vt,{children:`Project Commands`}),(0,$.jsx)(Qe,{children:`Manage custom commands for this project.`})]}),(0,$.jsx)(`div`,{className:`py-4 flex flex-col gap-4`,children:o?(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)(j,{htmlFor:`name`,children:`Command Name`}),(0,$.jsx)(un,{id:`name`,value:o.name,onChange:e=>c({...o,name:e.target.value}),placeholder:`e.g. Run Tests`,autoComplete:`off`})]}),(0,$.jsxs)(`div`,{className:`grid gap-2 relative`,children:[(0,$.jsx)(j,{htmlFor:`commandLine`,children:`Command Line`}),(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(Ra,{ref:y,id:`commandLine`,value:o.commandLine,onChange:e=>c({...o,commandLine:e.target.value}),onKeyDown:E,placeholder:`e.g. npm test`,className:`font-mono text-base min-h-[100px] resize-none pr-10`}),(0,$.jsx)(D,{children:(0,$.jsxs)(B,{children:[(0,$.jsx)(L,{asChild:!0,children:(0,$.jsx)(s,{type:`button`,variant:`ghost`,size:`icon`,className:`absolute right-2 top-2 h-6 w-6 text-muted-foreground transition-colors`,onClick:()=>void w(),disabled:_,children:(0,$.jsx)(Ue,{className:`h-4 w-4`})})}),(0,$.jsx)(H,{children:(0,$.jsx)(`p`,{children:`Discover package scripts`})})]})})]}),d&&(0,$.jsx)(`div`,{ref:x,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:z(W.dropdownGroupHeading,`px-2 py-1.5 border-b border-border/50 mb-1 flex items-center gap-2`),children:[(0,$.jsx)(Ue,{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:z(W.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:z(`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:()=>T(e),onMouseEnter:()=>g(n-1),children:[(0,$.jsx)(`span`,{className:`font-medium`,children:e.name}),(0,$.jsx)(`span`,{className:z(W.caption,`font-mono`),children:e.commandLine})]},e.commandLine)})]},t)})})():(0,$.jsx)(`div`,{className:z(W.caption,`px-3 py-4 text-center`),children:_?`Loading scripts...`:`No package scripts found`})]})})]}),(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[(0,$.jsx)(j,{htmlFor:`relativeFolder`,children:`Relative Folder`}),(0,$.jsx)(un,{id:`relativeFolder`,value:o.relativeFolder??``,onChange:e=>c({...o,relativeFolder:e.target.value}),placeholder:`e.g. frontend, packages/api (optional)`,autoComplete:`off`}),(0,$.jsx)(`p`,{className:W.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)(j,{children:`Icon`}),(0,$.jsx)(D,{children:(0,$.jsx)(`div`,{className:`grid grid-cols-10 gap-1 p-2 bg-background rounded-md border border-border`,children:$p.map(e=>{let t=$e[e]||He;return(0,$.jsxs)(B,{children:[(0,$.jsx)(L,{asChild:!0,children:(0,$.jsx)(s,{variant:o.icon===e?`default`:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:()=>c({...o,icon:e}),children:(0,$.jsx)(t,{className:`h-4 w-4`})})}),(0,$.jsx)(H,{children:e})]},e)})})})]}),(0,$.jsxs)(`div`,{className:`flex justify-end gap-2 mt-2`,children:[(0,$.jsxs)(s,{variant:`ghost`,size:`sm`,onClick:()=>c(null),children:[(0,$.jsx)(zn,{className:`h-4 w-4 mr-2`}),` Cancel`]}),(0,$.jsxs)(s,{size:`sm`,onClick:async()=>{if(!o?.name||!o?.commandLine){Qa({title:`Error`,description:`Name and Command Line are required`,variant:`destructive`});return}try{u(!0),await q(n,o),Qa({title:`Success`,description:`Command saved`}),c(null),i()}catch{Qa({title:`Error`,description:`Failed to save command`,variant:`destructive`})}finally{u(!1)}},disabled:l,children:[(0,$.jsx)(Ze,{className:`h-4 w-4 mr-2`}),` `,l?`Saving...`:`Save Command`]})]})]}):(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:()=>C(e),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(`div`,{className:`p-2 bg-muted rounded`,children:(0,$.jsx)($e[e.icon]||R,{className:`h-4 w-4`})}),(0,$.jsxs)(`div`,{className:`flex flex-col`,children:[(0,$.jsx)(`span`,{className:W.label,children:e.name}),(0,$.jsx)(`span`,{className:z(W.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)(s,{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(),O(e.id)},children:(0,$.jsx)(b,{className:`h-4 w-4`})})})]},e.id))]}),(0,$.jsxs)(s,{variant:`outline`,className:`w-full border-dashed`,onClick:S,children:[(0,$.jsx)(sn,{className:`h-4 w-4 mr-2`}),` Add New Command`]})]})})]})})}function tm(e){let t=(0,X.c)(37),{layout:n}=e,r=n===void 0?`bar`:n,i=Q(im),a=Q(rm),o=Q(nm),c=Ia(),{terminalState:l,dispatch:u}=La(a),[d,f]=(0,Y.useState)(!1),p=l.isRunning||l.queuedCommand!==null,m,h,g,_,v;if(t[0]!==c||t[1]!==u||t[2]!==p||t[3]!==r||t[4]!==o||t[5]!==i||t[6]!==a||t[7]!==d){v=Symbol.for(`react.early_return_sentinel`);bb0:{let e;t[13]===i?e=t[14]:(e=e=>e.projectId===i,t[13]=i,t[14]=e),m=o.find(e)?.commands??[];let n;t[15]!==u||t[16]!==i||t[17]!==a?(n=e=>{!i||!a||u({type:Z.QueueTerminalCommand,command:e.commandLine,relativeFolder:e.relativeFolder})},t[15]=u,t[16]=i,t[17]=a,t[18]=n):n=t[18];let l=n,y;if(t[19]===c?y=t[20]:(y=async()=>{c({type:Z.ConfigUpdated})},t[19]=c,t[20]=y),h=y,!i){v=null;break bb0}if(r===`menu`){let e;t[21]!==l||t[22]!==p?(e=e=>{let t=$e[e.icon]||R;return(0,$.jsxs)(s,{variant:`ghost`,size:`sm`,className:z(`relative w-full justify-start gap-2`,p&&`text-primary`,p&&`before:absolute before:inset-[-1px] before:rounded-md before:border before:border-primary/60 before:animate-ping-subtle before:content-['']`),onClick:()=>l({commandLine:e.commandLine,relativeFolder:e.relativeFolder}),disabled:p,children:[(0,$.jsx)(t,{className:`h-4 w-4 shrink-0`}),e.name]},e.id)},t[21]=l,t[22]=p,t[23]=e):e=t[23];let n,r;t[24]===Symbol.for(`react.memo_cache_sentinel`)?(r=()=>f(!0),n=(0,$.jsx)(P,{className:`h-4 w-4 shrink-0`}),t[24]=n,t[25]=r):(n=t[24],r=t[25]);let a=m.length===0?`Project Commands`:`Manage commands`,o;t[26]===a?o=t[27]:(o=(0,$.jsxs)(s,{variant:`ghost`,size:`sm`,className:`w-full justify-start gap-2`,onClick:r,children:[n,a]}),t[26]=a,t[27]=o),v=(0,$.jsxs)($.Fragment,{children:[m.map(e),o,(0,$.jsx)(em,{open:d,onOpenChange:f,projectId:i,commands:m,onRefresh:h})]});break bb0}g=`flex items-center gap-1`,_=m.length===0?(0,$.jsx)(D,{children:(0,$.jsxs)(B,{children:[(0,$.jsx)(L,{asChild:!0,children:(0,$.jsx)(s,{variant:`action`,size:`icon-md`,onClick:()=>f(!0),children:(0,$.jsx)(P,{})})}),(0,$.jsx)(H,{children:`Manage commands`})]})}):(0,$.jsx)($.Fragment,{children:(0,$.jsxs)(D,{children:[m.map(e=>{let t=$e[e.icon]||R;return(0,$.jsxs)(B,{children:[(0,$.jsx)(L,{asChild:!0,children:(0,$.jsx)(s,{variant:`action`,size:`icon-md`,className:z(`relative`,p&&`bg-primary/10 text-primary`,p&&`before:absolute before:inset-[-1px] before:rounded-full before:border before:border-primary/60 before:animate-ping-subtle before:content-['']`),onClick:()=>l({commandLine:e.commandLine,relativeFolder:e.relativeFolder}),disabled:p,children:(0,$.jsx)(t,{})})}),(0,$.jsx)(H,{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})]})})]},e.id)}),(0,$.jsxs)(B,{children:[(0,$.jsx)(L,{asChild:!0,children:(0,$.jsx)(s,{variant:`action`,size:`icon-md`,className:`ml-1`,onClick:()=>f(!0),children:(0,$.jsx)(P,{})})}),(0,$.jsx)(H,{children:`Manage commands`})]})]})})}t[0]=c,t[1]=u,t[2]=p,t[3]=r,t[4]=o,t[5]=i,t[6]=a,t[7]=d,t[8]=m,t[9]=h,t[10]=g,t[11]=_,t[12]=v}else m=t[8],h=t[9],g=t[10],_=t[11],v=t[12];if(v!==Symbol.for(`react.early_return_sentinel`))return v;let y;t[28]!==m||t[29]!==h||t[30]!==i||t[31]!==d?(y=(0,$.jsx)(em,{open:d,onOpenChange:f,projectId:i,commands:m,onRefresh:h}),t[28]=m,t[29]=h,t[30]=i,t[31]=d,t[32]=y):y=t[32];let b;return t[33]!==g||t[34]!==_||t[35]!==y?(b=(0,$.jsxs)(`div`,{className:g,children:[_,y]}),t[33]=g,t[34]=_,t[35]=y,t[36]=b):b=t[36],b}function nm(e){return e.projects}function rm(e){return e.selectedThreadId}function im(e){return e.selectedProjectId}var am=`VS Code`;function om(e){return e||tt(am)}var sm={"VS Code":`vscode`,Antigravity:`antigravity`,Cursor:`cursor`,"Devin Desktop":`devin`,Windsurf:`windsurf`,Xcode:`xcode`,"Android Studio":`android-studio`,Kiro:`kiro`,Terminal:`terminal`};function cm({projectId:e,threadId:t,openWith:n,layout:r=`bar`}){let[i,a]=(0,Y.useState)(!1),[o,c]=(0,Y.useState)([]),[l,u]=(0,Y.useState)(()=>om(n)),[d,f]=(0,Y.useState)(!0);(0,Y.useEffect)(()=>{(async()=>{try{let e=await xt();c(e);let t=om(n);e.includes(t)?u(t):e.length>0&&u(e[0])}catch(e){console.error(`Failed to fetch available programs:`,e),c([am])}finally{f(!1)}})()},[]),(0,Y.useEffect)(()=>{if(n&&o.includes(n)){u(n);return}let e=tt(am);!n&&o.includes(e)&&u(e)},[n,o]);async function p(t){u(t),y(t),await Ee(e,t)}let m=async n=>{try{a(!0),await p(n),t?await hn(t,n):await Qt(e,n),Qa({title:`Success`,description:`Opened project in ${n}`})}catch(e){console.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}Qa({title:`Error`,description:t,variant:`destructive`})}finally{a(!1)}};async function h(e){try{await p(e)}catch(t){console.error(`Failed to save preferred IDE (${e}):`,t),Qa({title:`Error`,description:`Failed to save IDE preference`,variant:`destructive`})}}let g=async()=>{await m(l)};return d?(0,$.jsx)(s,{variant:`outline`,size:`sm`,className:`h-8`,disabled:!0,children:(0,$.jsx)(`div`,{className:`h-4 w-4 animate-pulse bg-muted rounded`})}):r===`menu`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(s,{variant:`ghost`,size:`sm`,className:`w-full justify-start gap-2`,disabled:i,onClick:()=>{g()},children:[(0,$.jsx)(`img`,{src:`/ide/${sm[l]||sm[am]}.svg`,alt:l,className:`h-4 w-4 shrink-0`}),`Open in `,l]}),(0,$.jsxs)(qc,{children:[(0,$.jsx)(Jc,{asChild:!0,children:(0,$.jsxs)(s,{variant:`ghost`,size:`sm`,className:`w-full justify-start gap-2`,children:[(0,$.jsx)(Ue,{className:`h-4 w-4 shrink-0`}),`Change IDE`]})}),(0,$.jsx)(Yc,{align:`start`,className:`w-56 p-1`,children:o.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:()=>{h(e)},disabled:i,children:[(0,$.jsx)(`img`,{src:`/ide/${sm[e]||sm[am]}.svg`,alt:e,className:`h-4 w-4 shrink-0`}),e]},e))})]})]}):(0,$.jsxs)(`div`,{className:`flex items-center gap-0`,children:[(0,$.jsxs)(B,{children:[(0,$.jsx)(L,{asChild:!0,children:(0,$.jsx)(s,{variant:`outline`,size:`sm`,className:`h-8 rounded-r-none border-r-0 border-transparent`,disabled:i,onClick:g,children:(0,$.jsx)(`img`,{src:`/ide/${sm[l]||sm[am]}.svg`,alt:l,className:`h-4 w-4`})})}),(0,$.jsx)(H,{children:`Open in ${l}`})]}),(0,$.jsxs)(Bl,{children:[(0,$.jsx)(Vl,{asChild:!0,children:(0,$.jsx)(s,{variant:`outline`,size:`sm`,className:`h-8 w-8 rounded-l-none px-1 border-transparent`,disabled:i,children:(0,$.jsx)(Ue,{className:`h-3.5 w-3.5`})})}),(0,$.jsx)(Gl,{align:`end`,children:o.map(e=>(0,$.jsxs)(Kl,{onClick:()=>void h(e),disabled:i,className:`flex items-center gap-2`,children:[(0,$.jsx)(`img`,{src:`/ide/${sm[e]||sm[am]}.svg`,alt:e,className:`h-4 w-4`}),e]},e))})]})]})}var lm=ei(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`]}),um=ei(e=>e.v0,{name:`RunStopButton_2`,portals:[`v0`]}),dm=ei(e=>(0,$.jsx)(`slot`,{children:e.v0}),{name:`RunStopButton_3`,portals:[`v0`]}),fm=function({projectId:e,runCommand:t,large:n,layout:r=`bar`}){let{dispatch:i}=La(Q(e=>e.selectedThreadId)),{setDevServerUrl:a,setDevServerRunning:o,setDevServerLoading:c}=ed(),{startServer:l}=rd(),{isRunning:u,isLoading:d}=od(e),f=(0,Y.useRef)(!1),p=()=>{l({projectId:e,runCommand:t||``})},m=async()=>{f.current=!0,c(!0);try{await x(e),o(!1),a(null),i({type:Z.AppendTerminalLine,line:{type:`system`,content:`Server stopped`}})}catch(e){let t=e instanceof Error?e.message:`Failed to stop dev server`;i({type:Z.AppendTerminalLine,line:{type:`error`,content:t}}),Qa({title:`Error`,description:t,variant:`destructive`})}finally{c(!1)}},h=!!t,g=d?`Starting...`:u?`Stop dev server`:`Start dev server`;return n?(0,$.jsx)(lm,{v0:u?m:p,v1:d||!u&&!h,v2:`flex flex-col items-center gap-3 group disabled:opacity-40 disabled:cursor-not-allowed ${u?`text-orange-500`:`text-muted-foreground`}`,v3:d?(0,$.jsx)(wn,{className:`h-10 w-10 animate-spin`}):u?(0,$.jsx)(Pt,{className:`h-10 w-10 fill-current`}):(0,$.jsx)(R,{className:`h-10 w-10 fill-current group-hover:text-foreground transition-colors`}),v4:z(W.body,`group-hover:text-foreground transition-colors`),v5:g}):r===`menu`?(0,$.jsx)(um,{v0:(0,$.jsxs)(s,{variant:`ghost`,size:`sm`,className:z(`w-full justify-start gap-2`,u&&`text-orange-500`),onClick:u?m:p,disabled:d||!u&&!h,children:[d?(0,$.jsx)(wn,{className:`h-4 w-4 shrink-0 animate-spin`}):u?(0,$.jsx)(Pt,{className:`h-4 w-4 shrink-0 fill-current`}):(0,$.jsx)(R,{className:`h-4 w-4 shrink-0`}),g]})}):(0,$.jsx)(dm,{v0:(0,$.jsx)(D,{children:(0,$.jsxs)(B,{children:[(0,$.jsx)(L,{asChild:!0,children:(0,$.jsxs)(s,{variant:`ghost`,size:`icon`,className:z(`relative h-8 w-8`,u&&`text-orange-500 bg-orange-500/10`,u&&`before:absolute before:inset-[-1px] before:rounded-full before:border before:border-orange-500/60 before:animate-ping-subtle before:content-['']`,!u&&`text-muted-foreground`),onClick:u?m:p,disabled:d||!u&&!h,children:[d?(0,$.jsx)(wn,{className:`h-4 w-4 animate-spin`}):u?(0,$.jsx)(Pt,{className:`h-4 w-4 fill-current`}):(0,$.jsx)(R,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:u?`Stop dev server`:`Start dev server`})]})}),(0,$.jsx)(H,{children:u?`Stop dev server`:h?`Start dev server: ${t}`:`Set run command in project settings`})]})})})};function pm(e){let t=(0,X.c)(31),{currentBranch:n,availableBranches:r,isLoadingBranches:i,isCheckingOut:a,onLoadBranches:o,onCheckoutBranch:c,onCreateBranch:l,onRenameBranch:u}=e,d;t[0]===o?d=t[1]:(d=e=>{e&&o()},t[0]=o,t[1]=d);let f,p;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(f=z(W.compact,`h-7 px-2 bg-background gap-1.5 border-none text-muted-foreground hover:bg-accent hover:text-accent-foreground`),p=(0,$.jsx)(m,{className:`h-3.5 w-3.5 shrink-0`}),t[2]=f,t[3]=p):(f=t[2],p=t[3]);let h=n||`Unknown`,g;t[4]===h?g=t[5]:(g=(0,$.jsx)(Vl,{asChild:!0,children:(0,$.jsxs)(s,{variant:`outline`,size:`sm`,className:f,children:[p,h]})}),t[4]=h,t[5]=g);let _,v;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(_=(0,$.jsx)(sn,{className:`h-3.5 w-3.5 mr-2 shrink-0`}),v=(0,$.jsx)(`span`,{children:`Create branch`}),t[6]=_,t[7]=v):(_=t[6],v=t[7]);let y;t[8]!==a||t[9]!==l?(y=(0,$.jsxs)(Kl,{onClick:l,disabled:a,children:[_,v]}),t[8]=a,t[9]=l,t[10]=y):y=t[10];let b,x;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(x=(0,$.jsx)(Ye,{className:`h-3.5 w-3.5 mr-2 shrink-0`}),b=(0,$.jsx)(`span`,{children:`Rename branch`}),t[11]=b,t[12]=x):(b=t[11],x=t[12]);let S;t[13]!==a||t[14]!==u?(S=(0,$.jsxs)(Kl,{onClick:u,disabled:a,children:[x,b]}),t[13]=a,t[14]=u,t[15]=S):S=t[15];let C;t[16]===Symbol.for(`react.memo_cache_sentinel`)?(C=(0,$.jsx)(Xl,{}),t[16]=C):C=t[16];let w;t[17]!==r||t[18]!==n||t[19]!==a||t[20]!==i||t[21]!==c?(w=i?(0,$.jsxs)(`div`,{className:z(W.compact,`px-2 py-1.5 text-muted-foreground flex items-center gap-2`),children:[(0,$.jsx)(wn,{className:`h-3 w-3 animate-spin`}),`Loading branches...`]}):r.length===0?(0,$.jsx)(`div`,{className:z(W.compact,`px-2 py-1.5 text-muted-foreground`),children:`No branches found`}):(0,$.jsx)(`div`,{className:`max-h-[300px] overflow-y-auto`,children:r.map(e=>(0,$.jsxs)(Kl,{disabled:e===n||a,onClick:()=>c(e),children:[(0,$.jsx)(m,{className:`h-3.5 w-3.5 mr-2 shrink-0`}),(0,$.jsx)(`span`,{className:e===n?`font-semibold text-foreground`:``,children:e}),e===n&&(0,$.jsx)(`span`,{className:z(W.compact,`ml-auto text-muted-foreground`),children:`current`})]},e))}),t[17]=r,t[18]=n,t[19]=a,t[20]=i,t[21]=c,t[22]=w):w=t[22];let T;t[23]!==S||t[24]!==w||t[25]!==y?(T=(0,$.jsxs)(Gl,{align:`start`,children:[y,S,C,w]}),t[23]=S,t[24]=w,t[25]=y,t[26]=T):T=t[26];let E;return t[27]!==d||t[28]!==T||t[29]!==g?(E=(0,$.jsxs)(Bl,{onOpenChange:d,children:[g,T]}),t[27]=d,t[28]=T,t[29]=g,t[30]=E):E=t[30],E}function mm(){return{autoGenerateCommitMessage:gt(),autoGeneratePRInfo:Ct(),privateRepositoryDefault:kn(),newChatOnNewBranch:K()}}function hm(e){e.autoGenerateCommitMessage!==void 0&&h(e.autoGenerateCommitMessage),e.autoGeneratePRInfo!==void 0&&Pn(e.autoGeneratePRInfo),e.privateRepositoryDefault!==void 0&&me(e.privateRepositoryDefault),e.newChatOnNewBranch!==void 0&&C(e.newChatOnNewBranch)}var gm=(0,Y.lazy)(()=>Xr(()=>import(`./merged-pr-dialog-DAXqT4Xe.js`).then(e=>({default:e.MergedPRDialog})),__vite__mapDeps([2,3,1,4,5])));function _m({threadId:e,projectId:t}){let n=Ia(),r=Q(e=>e.projects.find(e=>e.projectId===t)),i=Op(),[a,o]=(0,Y.useState)(!1),[s,c]=(0,Y.useState)(!1),l=(0,Y.useRef)(null),[u,d]=(0,Y.useState)(()=>mm());(0,Y.useEffect)(()=>{hm(u)},[u]),(0,Y.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 Ie(e);if(u.newChatOnNewBranch){let r=`New Chat`;await M(e,{title:r}),n({type:Z.UpdateThreadTitle,projectId:t,threadId:e,title:r}),await wt(e),n({type:Z.ClearMessages}),setTimeout(()=>{(async()=>{try{let t=await mn(e);n({type:Z.SetMessages,messages:t.messages})}catch(e){console.error(`Failed to refresh chat history after starting new chat:`,e)}})()},0)}yn();let a=await w();n({type:Z.SetProjects,projects:a.projects}),Qa({title:`New branch created`,description:`Created new branch "${r.branchName}" on current thread`}),o(!1),await i.fetchUnifiedStatus(!0),setTimeout(()=>void i.fetchUnifiedStatus(!0),1500)}catch(e){console.error(`Failed to create new branch:`,e),Qa({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)(Y.Suspense,{fallback:null,children:(0,$.jsx)(gm,{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 vm(e){let t=(0,X.c)(35),{open:n,onOpenChange:r,branchName:i,onBranchNameChange:o,isLoading:c,onCreateBranch:l}=e,u;t[0]!==i||t[1]!==c||t[2]!==l?(u=e=>{e.key===`Enter`&&i.trim()&&!c&&l()},t[0]=i,t[1]=c,t[2]=l,t[3]=u):u=t[3];let d=u,f;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,$.jsxs)(a,{children:[(0,$.jsx)(vt,{children:`New Branch`}),(0,$.jsx)(Qe,{children:`Enter a name for the new branch. It will be created from the default branch.`})]}),t[4]=f):f=t[4];let p;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,$.jsx)(j,{htmlFor:`branch-name`,children:`Branch Name`}),t[5]=p):p=t[5];let m;t[6]===o?m=t[7]:(m=e=>o(e.target.value),t[6]=o,t[7]=m);let h;t[8]!==i||t[9]!==d||t[10]!==c||t[11]!==m?(h=(0,$.jsx)(`div`,{className:`grid gap-4 py-4`,children:(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[p,(0,$.jsx)(un,{id:`branch-name`,placeholder:`e.g. feature/my-feature`,value:i,onChange:m,onKeyDown:d,disabled:c,autoFocus:!0})]})}),t[8]=i,t[9]=d,t[10]=c,t[11]=m,t[12]=h):h=t[12];let g;t[13]===r?g=t[14]:(g=()=>r(!1),t[13]=r,t[14]=g);let _;t[15]!==c||t[16]!==g?(_=(0,$.jsx)(s,{variant:`outline`,onClick:g,disabled:c,children:`Cancel`}),t[15]=c,t[16]=g,t[17]=_):_=t[17];let v;t[18]!==i||t[19]!==c?(v=c||!i.trim(),t[18]=i,t[19]=c,t[20]=v):v=t[20];let y=c?`Creating...`:`Create Branch`,b;t[21]!==l||t[22]!==v||t[23]!==y?(b=(0,$.jsx)(s,{onClick:l,disabled:v,children:y}),t[21]=l,t[22]=v,t[23]=y,t[24]=b):b=t[24];let x;t[25]!==b||t[26]!==_?(x=(0,$.jsxs)(we,{children:[_,b]}),t[25]=b,t[26]=_,t[27]=x):x=t[27];let S;t[28]!==x||t[29]!==h?(S=(0,$.jsxs)(We,{children:[f,h,x]}),t[28]=x,t[29]=h,t[30]=S):S=t[30];let C;return t[31]!==r||t[32]!==n||t[33]!==S?(C=(0,$.jsx)(ie,{open:n,onOpenChange:r,children:S}),t[31]=r,t[32]=n,t[33]=S,t[34]=C):C=t[34],C}function ym(e,t,n){return e?e===t?`New name is the same as the current branch`:n.has(e)?`Branch "${e}" already exists`:null:`Branch name cannot be blank`}function bm(e){let t=(0,X.c)(47),{open:n,onOpenChange:r,currentBranch:i,availableBranches:o,branchName:c,onBranchNameChange:l,isLoading:u,onRenameBranch:d}=e,f;t[0]===o?f=t[1]:(f=new Set(o),t[0]=o,t[1]=f);let p=f,m,h;t[2]!==c||t[3]!==i||t[4]!==p?(h=c.trim(),m=ym(h,i,p),t[2]=c,t[3]=i,t[4]=p,t[5]=m,t[6]=h):(m=t[5],h=t[6]);let g=m,_=u||g!==null,v;t[7]!==_||t[8]!==d?(v=e=>{e.key===`Enter`&&!_&&d()},t[7]=_,t[8]=d,t[9]=v):v=t[9];let y=v,b;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(b=(0,$.jsx)(vt,{children:`Rename Branch`}),t[10]=b):b=t[10];let x;t[11]===i?x=t[12]:(x=(0,$.jsxs)(a,{children:[b,(0,$.jsxs)(Qe,{children:[`Rename the current branch `,(0,$.jsx)(`span`,{className:`font-semibold`,children:i}),` to a new name.`]})]}),t[11]=i,t[12]=x);let S;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(S=(0,$.jsx)(j,{htmlFor:`rename-branch-name`,children:`New Branch Name`}),t[13]=S):S=t[13];let C;t[14]===l?C=t[15]:(C=e=>l(e.target.value),t[14]=l,t[15]=C);let w;t[16]!==c||t[17]!==y||t[18]!==u||t[19]!==C?(w=(0,$.jsx)(un,{id:`rename-branch-name`,placeholder:`e.g. feature/my-feature`,value:c,onChange:C,onKeyDown:y,disabled:u,autoFocus:!0,autoComplete:`off`,autoCorrect:`off`,autoCapitalize:`off`,spellCheck:!1}),t[16]=c,t[17]=y,t[18]=u,t[19]=C,t[20]=w):w=t[20];let T;t[21]!==h||t[22]!==g?(T=g&&h.length>0&&(0,$.jsx)(`p`,{className:`text-sm text-destructive`,children:g}),t[21]=h,t[22]=g,t[23]=T):T=t[23];let E;t[24]!==w||t[25]!==T?(E=(0,$.jsx)(`div`,{className:`grid gap-4 py-4`,children:(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[S,w,T]})}),t[24]=w,t[25]=T,t[26]=E):E=t[26];let D;t[27]===r?D=t[28]:(D=()=>r(!1),t[27]=r,t[28]=D);let O;t[29]!==u||t[30]!==D?(O=(0,$.jsx)(s,{variant:`outline`,onClick:D,disabled:u,children:`Cancel`}),t[29]=u,t[30]=D,t[31]=O):O=t[31];let k=u?`Renaming...`:`Rename Branch`,A;t[32]!==_||t[33]!==d||t[34]!==k?(A=(0,$.jsx)(s,{onClick:d,disabled:_,children:k}),t[32]=_,t[33]=d,t[34]=k,t[35]=A):A=t[35];let M;t[36]!==O||t[37]!==A?(M=(0,$.jsxs)(we,{children:[O,A]}),t[36]=O,t[37]=A,t[38]=M):M=t[38];let N;t[39]!==E||t[40]!==M||t[41]!==x?(N=(0,$.jsxs)(We,{children:[x,E,M]}),t[39]=E,t[40]=M,t[41]=x,t[42]=N):N=t[42];let P;return t[43]!==r||t[44]!==n||t[45]!==N?(P=(0,$.jsx)(ie,{open:n,onOpenChange:r,children:N}),t[43]=r,t[44]=n,t[45]=N,t[46]=P):P=t[46],P}var xm=`panda.koala.penguin.bunny.kitten.puppy.hamster.otter.hedgehog.sloth.dolphin.owl.fox.deer.koala.walrus.bouncy.sparkly.fluffy.jolly.zesty.peppy.snappy.perky.breezy.chirpy.dizzy.fizzy.glossy.groggy.loopy.quirky.umbrella.taco.pickle.waffle.bubble.puzzle.rocket.tornado.volcano.rainbow.diamond.crystal.lantern.treasure.whisper.echo.boing.splat.whoosh.crunch.splash.jingle.wiggle.giggle.scramble.tumble.fumble.jumble.rumble.mumble.stumble.hustle.castle.island.mountain.forest.meadow.lagoon.canyon.geyser.oasis.glacier.waterfall.volcano.tundra.savanna.jungle.desert.magic.dream.wonder.spark.glow.shimmer.twinkle.radiance.harmony.melody.rhythm.symphony.adventure.journey.quest.odyssey`.split(`.`);function Sm(){return xm[Math.floor(Math.random()*xm.length)]??`branch`}function Cm(){let e=Sm(),t=Sm();for(;t===e;)t=Sm();return`${e}-${t}`}function wm(e){let[t,n]=(0,Y.useState)([]),[r,i]=(0,Y.useState)(!1),[a,o]=(0,Y.useState)(!1),[s,c]=(0,Y.useState)(!1),[l,u]=(0,Y.useState)(``),[d,f]=(0,Y.useState)(!1),[p,m]=(0,Y.useState)(!1),[h,g]=(0,Y.useState)(``),[_,v]=(0,Y.useState)(!1),[y,b]=(0,Y.useState)(`main`),x=Op();(0,Y.useEffect)(()=>{if(!s){u(``);return}u(Cm())},[s]),(0,Y.useEffect)(()=>{if(!p){g(``);return}g(x.currentBranch)},[p,x.currentBranch]),(0,Y.useEffect)(()=>{x.defaultBranch&&b(x.defaultBranch)},[x.defaultBranch]);async function S(){if(!(!e||r)){i(!0);try{n((await se(e)).branches)}catch{n([])}finally{i(!1)}}}async function C(t){if(!(!e||t===x.currentBranch)){o(!0);try{await ze(e,t),await x.fetchUnifiedStatus(!0),Qa({title:`Switched to branch "${t}"`})}catch(e){Qa({title:`Failed to switch branch`,description:e instanceof Error?e.message:String(e),variant:`destructive`})}finally{o(!1)}}}function w(){c(!0)}function T(){m(!0)}async function E(){if(!(!e||!l.trim()||d)){f(!0);try{let t=await Ie(e,y,l);c(!1),await S(),await x.fetchUnifiedStatus(!0),Qa({title:`Branch created`,description:`Created branch "${t.branchName}" from ${y}`})}catch(e){Qa({title:`Failed to create branch`,description:e instanceof Error?e.message:String(e),variant:`destructive`})}finally{f(!1)}}}async function D(){if(!(!e||!h.trim()||_)){v(!0);try{let t=await Je(e,h);m(!1),await S(),await x.fetchUnifiedStatus(!0),Qa({title:`Branch renamed`,description:`Renamed branch to "${t.branchName}"`})}catch(e){Qa({title:`Failed to rename branch`,description:e instanceof Error?e.message:String(e),variant:`destructive`})}finally{v(!1)}}}return{currentBranch:x.currentBranch,availableBranches:t,isLoadingBranches:r,isCheckingOut:a,loadBranches:S,checkoutBranch:C,fetchUnifiedStatus:x.fetchUnifiedStatus,isCreateDialogOpen:s,setIsCreateDialogOpen:c,newBranchName:l,setNewBranchName:u,isCreatingBranch:d,createBranch:E,openCreateBranchDialog:w,defaultBranch:y,isRenameDialogOpen:p,setIsRenameDialogOpen:m,renameBranchName:h,setRenameBranchName:g,isRenamingBranch:_,renameBranch:D,openRenameBranchDialog:T}}var Tm=(0,Y.lazy)(()=>Xr(()=>import(`./git-ops-button-Bced-_39.js`).then(e=>({default:e.GitOpsButton})),__vite__mapDeps([6,1,7,8,3])));function Em(e){return e===`menu`?`w-full justify-start gap-2`:`gap-2`}function Dm(e){let t=(0,X.c)(4),{threadId:n,projectId:r,messages:i,userTasks:a}=e,{hasChanges:o}=Op(),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 Om(e){let t=(0,X.c)(92),{threadId:n,projectId:r,messages:i,userTasks:a,effectiveIsStreaming:o,isCreatingProject:c,onNewChat:l,onSelectUserTask:u,onToggleUserTaskPinned:d,onRemoveUserTask:f,layout:p}=e,m=p===void 0?`bar`:p,{setActiveMainTab:h}=Ks(),g;t[0]!==i||t[1]!==r||t[2]!==n||t[3]!==a?(g={threadId:n,projectId:r,messages:i,userTasks:a},t[0]=i,t[1]=r,t[2]=n,t[3]=a,t[4]=g):g=t[4];let{hasMessages:_,hasChanges:v,isVisible:y}=Dm(g),{changedFilesCount:b}=Op(),x;t[5]===m?x=t[6]:(x=Em(m),t[5]=m,t[6]=x);let S=x,{currentBranch:C,availableBranches:w,isLoadingBranches:T,isCheckingOut:E,loadBranches:D,checkoutBranch:O,isRenameDialogOpen:k,setIsRenameDialogOpen:A,renameBranchName:j,setRenameBranchName:M,isRenamingBranch:N,renameBranch:P,openRenameBranchDialog:F,isCreateDialogOpen:I,setIsCreateDialogOpen:ee,newBranchName:L,setNewBranchName:te,isCreatingBranch:R,createBranch:ne}=wm(n),re=Q(km),ie;if(t[7]!==r||t[8]!==re){let e;t[10]===r?e=t[11]:(e=e=>e.projectId===r,t[10]=r,t[11]=e),ie=re.find(e),t[7]=r,t[8]=re,t[9]=ie}else ie=t[9];let ae=ie,oe=m===`menu`&&!!n&&!!r,se=_||v||a.length>0||!!(n&&r);if(!y)return null;let ce=m===`bar`&&`absolute -top-12 left-0 z-10 ml-8 flex flex-wrap items-center gap-2`,le=m===`menu`&&`flex flex-col items-stretch gap-1 p-1 min-w-[220px]`,ue;t[12]!==ce||t[13]!==le?(ue=z(ce,le),t[12]=ce,t[13]=le,t[14]=ue):ue=t[14];let de=m===`bar`?!0:void 0,fe;t[15]!==_||t[16]!==m||t[17]!==l||t[18]!==S?(fe=_&&(0,$.jsxs)(s,{variant:m===`menu`?`ghost`:`outline`,size:`sm`,className:S,onClick:l,children:[(0,$.jsx)(sn,{className:`h-4 w-4 shrink-0`}),`New Chat`]}),t[15]=_,t[16]=m,t[17]=l,t[18]=S,t[19]=fe):fe=t[19];let B;t[20]!==b||t[21]!==v||t[22]!==m||t[23]!==h||t[24]!==S?(B=v&&(0,$.jsxs)(s,{variant:m===`menu`?`ghost`:`outline`,size:`sm`,className:S,onClick:()=>h(`review`),children:[(0,$.jsx)(Ln,{className:`h-4 w-4 shrink-0`}),b,` `,b===1?`Change`:`Changes`]}),t[20]=b,t[21]=v,t[22]=m,t[23]=h,t[24]=S,t[25]=B):B=t[25];let pe;t[26]!==o||t[27]!==c||t[28]!==m||t[29]!==f||t[30]!==u||t[31]!==d||t[32]!==n||t[33]!==a?(pe=a.length>0&&(0,$.jsx)(Bp,{tasks:a,disabled:o||!n&&!c,onSelectTask:u,onTogglePinned:d,onRemoveTask:f,layout:m}),t[26]=o,t[27]=c,t[28]=m,t[29]=f,t[30]=u,t[31]=d,t[32]=n,t[33]=a,t[34]=pe):pe=t[34];let V;t[35]!==m||t[36]!==r||t[37]!==n?(V=n&&r&&(0,$.jsx)(Y.Suspense,{fallback:null,children:(0,$.jsx)(Tm,{projectId:r,threadId:n,layout:m},n)}),t[35]=m,t[36]=r,t[37]=n,t[38]=V):V=t[38];let me;t[39]!==_||t[40]!==m?(me=_&&(0,$.jsx)(Rp,{layout:m}),t[39]=_,t[40]=m,t[41]=me):me=t[41];let he;t[42]!==w||t[43]!==O||t[44]!==C||t[45]!==E||t[46]!==T||t[47]!==m||t[48]!==D||t[49]!==F||t[50]!==ee?(he=m===`bar`&&(0,$.jsx)(pm,{currentBranch:C,availableBranches:w,isLoadingBranches:T,isCheckingOut:E,onLoadBranches:D,onCheckoutBranch:O,onCreateBranch:()=>ee(!0),onRenameBranch:F}),t[42]=w,t[43]=O,t[44]=C,t[45]=E,t[46]=T,t[47]=m,t[48]=D,t[49]=F,t[50]=ee,t[51]=he):he=t[51];let ge;t[52]!==se||t[53]!==oe?(ge=oe&&se&&(0,$.jsx)(Xl,{className:`my-1`}),t[52]=se,t[53]=oe,t[54]=ge):ge=t[54];let _e;t[55]!==r||t[56]!==ae?.openWith||t[57]!==ae?.runCommand||t[58]!==oe||t[59]!==n?(_e=oe&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(fm,{projectId:r,runCommand:ae?.runCommand,layout:`menu`}),(0,$.jsx)(Qp,{threadId:n,layout:`menu`}),(0,$.jsx)(tm,{layout:`menu`}),(0,$.jsx)(cm,{projectId:r,threadId:n,openWith:ae?.openWith,layout:`menu`})]}),t[55]=r,t[56]=ae?.openWith,t[57]=ae?.runCommand,t[58]=oe,t[59]=n,t[60]=_e):_e=t[60];let H;t[61]!==B||t[62]!==pe||t[63]!==V||t[64]!==me||t[65]!==he||t[66]!==ge||t[67]!==_e||t[68]!==ue||t[69]!==de||t[70]!==fe?(H=(0,$.jsxs)(`div`,{className:ue,"data-chat-toolbar":de,children:[fe,B,pe,V,me,he,ge,_e]}),t[61]=B,t[62]=pe,t[63]=V,t[64]=me,t[65]=he,t[66]=ge,t[67]=_e,t[68]=ue,t[69]=de,t[70]=fe,t[71]=H):H=t[71];let ve;t[72]!==ne||t[73]!==I||t[74]!==R||t[75]!==L||t[76]!==ee||t[77]!==te?(ve=(0,$.jsx)(vm,{open:I,onOpenChange:ee,branchName:L,onBranchNameChange:te,isLoading:R,onCreateBranch:ne}),t[72]=ne,t[73]=I,t[74]=R,t[75]=L,t[76]=ee,t[77]=te,t[78]=ve):ve=t[78];let ye;t[79]!==w||t[80]!==C||t[81]!==k||t[82]!==N||t[83]!==P||t[84]!==j||t[85]!==A||t[86]!==M?(ye=(0,$.jsx)(bm,{open:k,onOpenChange:A,currentBranch:C,availableBranches:w,branchName:j,onBranchNameChange:M,isLoading:N,onRenameBranch:P}),t[79]=w,t[80]=C,t[81]=k,t[82]=N,t[83]=P,t[84]=j,t[85]=A,t[86]=M,t[87]=ye):ye=t[87];let be;return t[88]!==H||t[89]!==ve||t[90]!==ye?(be=(0,$.jsxs)($.Fragment,{children:[H,ve,ye]}),t[88]=H,t[89]=ve,t[90]=ye,t[91]=be):be=t[91],be}function km(e){return e.projects}function Am(e){let t=(0,X.c)(2),n;return t[0]===e?n=t[1]:(n=(0,$.jsx)(Om,{...e}),t[0]=e,t[1]=n),n}function jm(){let e=(0,X.c)(21),t=Q(Pm),n=Q(Nm),r=Q(Mm),{userTasks:i,handleNewChat:a,handleSelectUserTask:o,handleRemoveUserTask:c,toggleUserTaskPinned:l,effectiveIsStreaming:u,isCreatingProject:d}=Yp(),f;e[0]!==r||e[1]!==n||e[2]!==t||e[3]!==i?(f={threadId:t,projectId:n,messages:r,userTasks:i},e[0]=r,e[1]=n,e[2]=t,e[3]=i,e[4]=f):f=e[4];let{isVisible:p}=Dm(f);if(!t||!p)return null;let m;e[5]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,$.jsx)(Vl,{asChild:!0,children:(0,$.jsxs)(s,{variant:`ghost`,size:`icon`,className:`h-8 w-8 text-muted-foreground shrink-0 md:hidden electrobun-webkit-app-region-no-drag`,children:[(0,$.jsx)(ut,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Chat actions`})]})}),e[5]=m):m=e[5];let h=n??``,g;e[6]===a?g=e[7]:(g=()=>{a()},e[6]=a,e[7]=g);let _;e[8]===c?_=e[9]:(_=e=>{c(e)},e[8]=c,e[9]=_);let v;return e[10]!==u||e[11]!==o||e[12]!==d||e[13]!==r||e[14]!==t||e[15]!==h||e[16]!==g||e[17]!==_||e[18]!==l||e[19]!==i?(v=(0,$.jsxs)(Bl,{children:[m,(0,$.jsx)(Gl,{align:`end`,className:`electrobun-webkit-app-region-no-drag`,children:(0,$.jsx)(Om,{threadId:t,projectId:h,messages:r,userTasks:i,effectiveIsStreaming:u,isCreatingProject:d,onNewChat:g,onSelectUserTask:o,onToggleUserTaskPinned:l,onRemoveUserTask:_,layout:`menu`})})]}),e[10]=u,e[11]=o,e[12]=d,e[13]=r,e[14]=t,e[15]=h,e[16]=g,e[17]=_,e[18]=l,e[19]=i,e[20]=v):v=e[20],v}function Mm(e){return e.messages}function Nm(e){return e.selectedProjectId}function Pm(e){return e.selectedThreadId}function Fm(e){let t=(0,X.c)(6),{threadId:n,children:r}=e,i=Q(Im),a;t[0]!==i||t[1]!==n?(a=n&&i?(0,$.jsx)(_m,{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 Im(e){return e.selectedProjectId}function Lm(e){let t=(0,X.c)(6),{threadId:n,children:r}=e,i;t[0]!==r||t[1]!==n?(i=(0,$.jsx)(Fm,{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)(Dp,{threadId:n,children:i}),t[3]=i,t[4]=n,t[5]=a):a=t[5],a}function Rm(e){let t=(0,X.c)(10),{open:n,onClose:r}=e,i=er(),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)(ii,{children:[(0,$.jsx)($r,{children:`Balance empty`}),(0,$.jsx)(ti,{children:`You have no prompts remaining. Purchase additional prompts to continue.`})]}),t[2]=o):o=t[2];let c;t[3]!==i||t[4]!==r?(c=(0,$.jsxs)(oi,{children:[o,(0,$.jsx)(ni,{children:(0,$.jsx)(s,{onClick:()=>{r(),i(`/settings/account`)},children:`Go to Account`})})]}),t[3]=i,t[4]=r,t[5]=c):c=t[5];let l;return t[6]!==n||t[7]!==a||t[8]!==c?(l=(0,$.jsx)(ri,{open:n,onOpenChange:a,children:c}),t[6]=n,t[7]=a,t[8]=c,t[9]=l):l=t[9],l}var zm=`tarsk-browser-tool-request`,Bm=`tarsk-ask-user-prompt`,Vm=new Set,Hm=new Set;function Um(e){Ve()&&window.dispatchEvent(new CustomEvent(zm,{detail:e}))}function Wm(e,t,n){!Ve()||Vm.has(e)||t.action&&(Vm.add(e),Um({toolCallId:e,input:t,threadId:n}))}function Gm(e,t){Hm.has(e)||(Hm.add(e),window.dispatchEvent(new CustomEvent(Bm,{detail:{toolCallId:e,threadId:t}})))}function Km(){return Ve()?`views://public/browser-preview-rpc.js`:`${Ke()}/browser-preview-rpc.js`}async function qm(e,t){await mt(e,t)}async function Jm(e,t){await Cn(e,t)}var Ym=new Set,Xm=new Map,Zm=5e3;function Qm(e){Ym.add(e);let t=Xm.get(e);t&&clearTimeout(t),Xm.set(e,setTimeout(()=>{Ym.delete(e),Xm.delete(e)},Zm))}function $m(e){return Ym.has(e)}function eh(e){return e.filter(e=>!Ym.has(e))}var th;(function(e){e.Unimplemented=`UNIMPLEMENTED`,e.Unavailable=`UNAVAILABLE`})(th||={});var nh=class extends Error{constructor(e,t,n){super(e),this.message=e,this.code=t,this.data=n}},rh=e=>e?.androidBridge?`android`:e?.webkit?.messageHandlers?.bridge?`ios`:`web`,ih=e=>{let t=e.CapacitorCustomPlatform||null,n=e.Capacitor||{},r=n.Plugins=n.Plugins||{},i=()=>t===null?rh(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 nh(`"${e}" plugin is not implemented on ${c}`,th.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 nh(`"${e}.${t}()" is not implemented on ${c}`,th.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=nh,n.DEBUG=!!n.DEBUG,n.isLoggingEnabled=!!n.isLoggingEnabled,n},ah=(e=>e.Capacitor=ih(e))(typeof globalThis<`u`?globalThis:typeof self<`u`?self:typeof window<`u`?window:typeof global<`u`?global:{}),oh=ah.registerPlugin,sh=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 ah.Exception(e,th.Unimplemented)}unavailable(e=`not available`){return new ah.Exception(e,th.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)}))}},ch=e=>encodeURIComponent(e).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape),lh=e=>e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent),uh=class extends sh{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=lh(n).trim(),r=lh(r).trim(),t[n]=r}),t}async setCookie(e){try{let t=ch(e.key),n=ch(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)}}};oh(`CapacitorCookies`,{web:()=>new uh});var dh=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)}),fh=(e={})=>{let t=Object.keys(e);return Object.keys(e).map(e=>e.toLocaleLowerCase()).reduce((n,r,i)=>(n[r]=e[t[i]],n),{})},ph=(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,mh=(e,t={})=>{let n=Object.assign({method:e.method||`GET`,headers:e.headers},t),r=fh(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},hh=class extends sh{async request(e){let t=mh(e,e.webFetchExtra),n=ph(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 dh(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`}))}};oh(`CapacitorHttp`,{web:()=>new hh});var gh;(function(e){e.Dark=`DARK`,e.Light=`LIGHT`,e.Default=`DEFAULT`})(gh||={});var _h;(function(e){e.StatusBar=`StatusBar`,e.NavigationBar=`NavigationBar`})(_h||={});var vh=class extends sh{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`)}};oh(`SystemBars`,{web:()=>new vh});var yh=oh(`KeepAwake`,{web:()=>Xr(()=>import(`./web-BD1sqxMq.js`).then(e=>new e.KeepAwakeWeb),[])}),bh=0;function xh(){return typeof window<`u`&&at()}async function Sh(){if(xh()&&(bh+=1,!(bh>1)))try{await yh.keepAwake()}catch{bh=0}}async function Ch(){if(xh()&&bh!==0&&(--bh,!(bh>0)))try{await yh.allowSleep()}catch{bh=0}}async function wh(){if(bh=0,xh())try{await yh.allowSleep()}catch{}}function Th(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&&du(e.id,e.input.code,t)}catch{}}function Eh(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&&Wm(e.id,e.input,t)}catch{}}function Dh(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&&Gm(e.id,t)}catch{}}function Oh(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`&&Ec(e.id,e.input.command)}catch{}}function kh(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`&&Dc(e.toolCallId)}catch{}}async function Ah(e,t,n,r,i){let a=await mn(t,r);if(t===i.current){if(n===`secondary`){e({type:Z.SetSecondaryMessages,messages:a.messages});return}e({type:Z.SetMessages,messages:a.messages})}}var jh=/^\/compact(?:\s+(.*))?$/i,Mh=`[Compact] Compaction in progress...`;function Nh(e,t,n){return{...e,threadId:t,paneId:n}}function Ph(e,t,n){let r={type:`thinking`,content:Mh,model:n};e(Nh({type:Z.SetStreaming,isStreaming:!0},t,`primary`)),e(Nh({type:Z.SetStreamModel,model:n},t,`primary`)),e(Nh({type:Z.AppendStreamChunk,chunkType:`thinking`,content:r.content??``,segments:fa([],`thinking`,r.content??``)},t,`primary`))}function Fh(e){let t=Ia(),{toast:n}=$a(),r=Fa(),[i,a]=(0,Y.useState)(null),[o,s]=(0,Y.useState)(!1),[c,l]=(0,Y.useState)(null),u=(0,Y.useRef)(null),d=(0,Y.useRef)(new Map),f=(0,Y.useRef)(null),m=(0,Y.useRef)({primary:!1,secondary:!1}),h=Q(e=>e.selectedThreadId),g=Q(e=>e.selectedProjectId),_=Q(e=>e.queuedChatMessages),v=Q(e=>e.pendingChatMessage),y=Q(e=>e.processingThreadIds);u.current=h;function b(e){let t=r.getState();return e===`secondary`?t.secondaryMessages:t.messages}function x(e,t){return Ri(r.getState().threadStreamingStates,e,t).isStreaming}function S(e,t){return Ri(r.getState().threadStreamingStates,e,t).streamingModel||`default`}let C=(0,Y.useCallback)(e=>h?_.filter(t=>t.threadId===h&&t.paneId===e):[],[_,h]),w=(0,Y.useCallback)((e,n,r)=>{let i=Li(e,r.paneId);if(r.pendingTransientRecovery){r.pendingTransientRecovery=!1,(async()=>{try{if((await G()).includes(e)){f.current?.(e,t=>le(e,t),n,r.paneId,r.conversationId);return}}catch(e){console.error(`Failed to recover chat stream after disconnect:`,e)}w(e,n,r)})();return}if(d.current.get(i)!==r){d.current.has(i)||(Qm(e),t(Nh({type:Z.ResetStream},e,r.paneId)),t({type:Z.RemoveProcessingThread,threadId:e}));return}if(d.current.delete(i),t({type:Z.ClearToolCallProgress}),r.keepsDeviceAwake&&(r.keepsDeviceAwake=!1,Ch()),r.stopHandled)return;if(Qm(e),r.error){let i={messageId:`msg-${Date.now()}-error`,sender:`agent`,content:`Error: ${r.error}`,contentType:`text`,timestamp:new Date().toISOString(),model:n||`default`,isThinking:!1};t({type:Z.AddMessage,message:i,threadId:e,paneId:r.paneId}),t(Nh({type:Z.ResetStream},e,r.paneId)),t({type:Z.RemoveProcessingThread,threadId:e});return}let a=Ta(r.segments)||`...`,o={messageId:`msg-${Date.now()}-agent`,sender:`agent`,content:a,contentType:`markdown`,timestamp:new Date().toISOString(),model:n||`default`,isThinking:!1};async function s(){for(let n=0;n<4;n++){n>0&&await new Promise(e=>setTimeout(e,150*n));try{await Ah(t,e,r.paneId,r.conversationId,u);return}catch(e){console.error(`Failed to reload chat history after stream:`,e);break}}t({type:Z.AddMessage,message:o,threadId:e,paneId:r.paneId})}s(),t(Nh({type:Z.ResetStream},e,r.paneId)),t({type:Z.SetActiveStreamPane,paneId:null}),t({type:Z.MarkThreadCompleted,threadId:e}),t({type:Z.RemoveProcessingThread,threadId:e})},[t]),T=(0,Y.useCallback)(e=>{if(!h)return;l(h);let n=Li(h,e),r=d.current.get(n);r&&(r.stopHandled=!0,r.controller.abort(),r.cancel?.(),d.current.delete(n),r.keepsDeviceAwake&&(r.keepsDeviceAwake=!1,Ch())),Me(h);let i={messageId:`msg-${Date.now()}-stopped`,sender:`agent`,content:`I've stopped working on your request.`,contentType:`text`,timestamp:new Date().toISOString(),model:S(h,e),isThinking:!1};t({type:Z.AddMessage,message:i,threadId:h,paneId:e}),t({type:Z.ClearToolCallProgress}),t(Nh({type:Z.ResetStream},h,e)),t({type:Z.SetActiveStreamPane,paneId:null}),t({type:Z.MarkThreadCompleted,threadId:h}),t({type:Z.RemoveProcessingThread,threadId:h}),Qm(h)},[h,t,r]);(0,Y.useEffect)(()=>()=>{for(let[e,n]of d.current.entries()){n.controller.abort(),n.cancel?.(),n.keepsDeviceAwake&&(n.keepsDeviceAwake=!1,Ch());let[r,i]=e.split(`:`);t(Nh({type:Z.ResetStream},r,i))}d.current.clear()},[t]);let E=(0,Y.useCallback)((e,n,r,i,o)=>{let c=Li(e,i),l=d.current.get(c);l&&(l.controller.abort(),l.cancel?.());let f=new AbortController,p={controller:f,cancel:null,segments:[],assistantMessage:``,assistantThinking:``,hasStructuredContent:!1,error:null,stopHandled:!1,pendingTransientRecovery:!1,activeSubagentToolCallId:null,paneId:i,conversationId:o,keepsDeviceAwake:!1};return d.current.set(c,p),t(Nh({type:Z.ResetStream},e,i)),t({type:Z.AddProcessingThread,threadId:e}),t(Nh({type:Z.SetStreaming,isStreaming:!0},e,i)),t({type:Z.SetActiveStreamPane,paneId:i}),Sh().then(()=>{p.keepsDeviceAwake=!0}),n(f.signal).then(n=>{if(!n||f.signal.aborted){w(e,r,p);return}p.cancel=lt(n,n=>{if(t(Nh({type:Z.IncrementStreamEventCount},e,i)),n.type===`error`){let t=n.content?.trim()||n.error?.message?.trim()||n.message?.trim()||`Unknown error occurred`;p.error=t,e===u.current&&a(t);return}if(n.type!==`message`){if(n.type===`long_running_confirmation`){let r=n.prompt;if(!r)return;p.segments=ga(p.segments,r),t(Nh({type:Z.AppendStreamChunk,chunkType:`content`,content:``,segments:p.segments},e,i));return}if(n.type===`shell_permission`){let r=n.shellPermission;if(!r)return;p.activeSubagentToolCallId&&t({type:Z.AppendToolExecutionOutput,toolCallId:p.activeSubagentToolCallId,toolName:`agent`,delta:`\n⏳ Waiting for shell approval: ${r.command}\n`}),p.segments=_a(p.segments,r),t(Nh({type:Z.AppendStreamChunk,chunkType:`content`,content:``,segments:p.segments},e,i));return}if(n.type===`web_fetch_permission`){let r=n.webFetchPermission;if(!r)return;p.activeSubagentToolCallId&&t({type:Z.AppendToolExecutionOutput,toolCallId:p.activeSubagentToolCallId,toolName:`agent`,delta:`\n⏳ Waiting for approval to fetch ${r.hostname}\n`}),p.segments=va(p.segments,r),t(Nh({type:Z.AppendStreamChunk,chunkType:`content`,content:``,segments:p.segments},e,i));return}if(n.type===`toolcall_delta`){n.partial?.content?.[0]?.id&&n.delta&&t({type:Z.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:Z.UpdateToolExecutionOutput,toolCallId:n.toolCallId,toolName:n.toolName,executionOutput:n.executionOutput});return}if(n.type===`subagent_start`){if(n.toolCallId){p.activeSubagentToolCallId=n.toolCallId;let e=n.subagentName?.trim()||`subagent`;t({type:Z.UpdateToolExecutionOutput,toolCallId:n.toolCallId,toolName:`agent`,executionOutput:`Running ${e}…\n`})}return}if(n.type===`subagent_event`){if(n.toolCallId){let e=wu(n);e&&t({type:Z.AppendToolExecutionOutput,toolCallId:n.toolCallId,toolName:`agent`,delta:e})}return}if(n.type===`subagent_complete`){n.toolCallId&&(p.activeSubagentToolCallId=null,n.subagentResult&&t({type:Z.UpdateToolExecutionOutput,toolCallId:n.toolCallId,toolName:`agent`,executionOutput:n.subagentResult}));return}if(n.model&&t(Nh({type:Z.SetStreamModel,model:n.model},e,i)),n.type===`thinking`||n.isThinking){let r=n.content??``;Th(r,e),Eh(r,e),Dh(r,e),p.assistantThinking+=r,p.segments=fa(p.segments,`thinking`,r),t(Nh({type:Z.AppendStreamChunk,chunkType:`thinking`,content:r,segments:p.segments},e,i))}else if(n.type===`result`){p.hasStructuredContent=!0;let r=n.content??``;p.assistantMessage=r,p.segments=pa(p.segments,r),t(Nh({type:Z.SetStreamContent,content:r},e,i)),typeof r==`string`&&(Th(r,e),Eh(r,e),Dh(r,e))}else{if(p.hasStructuredContent)return;let r=n.content??``;p.assistantMessage+=r,p.segments=fa(p.segments,`content`,r),t(Nh({type:Z.AppendStreamChunk,chunkType:`content`,content:r,segments:p.segments},e,i))}}},()=>{w(e,r,p)},t=>{if(t.includes(`AbortError`)||t.includes(`canceled`)||t.includes(`BodyStreamBuffer was aborted`)){w(e,r,p);return}if(fn(t)){p.pendingTransientRecovery=!0;return}p.error=t,e===u.current&&a(t)},n=>{if(t(Nh({type:Z.IncrementStreamEventCount},e,i)),n.role===`assistant`){let r=n.content??``,a=typeof r==`string`?r:JSON.stringify(r);if(n.isThinking??!1){p.assistantThinking+=a,p.segments=fa(p.segments,`thinking`,a),t(Nh({type:Z.AppendStreamChunk,chunkType:`thinking`,content:a,segments:p.segments},e,i));return}let o=!1;if(typeof r==`object`&&Array.isArray(r)&&r.length>0)o=!0;else if(typeof a==`string`&&a.trim().startsWith(`[`))try{let e=JSON.parse(a);o=Array.isArray(e)&&e.length>0}catch{}o?(p.hasStructuredContent=!0,p.assistantMessage=a,p.segments=pa(p.segments,a),t(Nh({type:Z.SetStreamContent,content:a},e,i)),Th(a,e),Eh(a,e),Dh(a,e)):(p.assistantMessage+=a,p.segments=fa(p.segments,`content`,a),t(Nh({type:Z.AppendStreamChunk,chunkType:`content`,content:a,segments:p.segments},e,i)))}else if(n.role===`tool`){let r=n.content??``,a=typeof r==`string`?r:JSON.stringify(r);a&&(Oh(a),kh(a),ua(a)?(p.hasStructuredContent=!0,p.segments=ma(p.segments,a),p.assistantMessage=ha(p.segments),t(Nh({type:Z.SetStreamContent,content:p.assistantMessage},e,i))):a.trim().startsWith(`[`)||(p.assistantMessage+=a,p.segments=fa(p.segments,`content`,a),t(Nh({type:Z.AppendStreamChunk,chunkType:`content`,content:a,segments:p.segments},e,i))))}})}).catch(n=>{if(n instanceof Error&&n.name===`AbortError`){d.current.delete(c),t(Nh({type:Z.ResetStream},e,i));return}if(n instanceof pt){d.current.delete(c),t(Nh({type:Z.ResetStream},e,i)),s(!0);return}if(n instanceof Error&&n.message.includes(`not currently processing`)){d.current.delete(c),t(Nh({type:Z.ResetStream},e,i));return}if(n instanceof Error&&fn(n.message)){p.pendingTransientRecovery=!0,w(e,r,p);return}d.current.delete(c);let o=n instanceof Error?n.message:`Failed to send message. Please ensure the CLI server is running on localhost:641`;e===u.current&&a(o),console.error(`Failed to subscribe to chat stream:`,n),t(Nh({type:Z.ResetStream},e,i))}),f},[t,w]);f.current=E,(0,Y.useEffect)(()=>{for(let e of y){let t=Li(e,`primary`);d.current.has(t)||r.getState().threadStreamingStates[t]?.isStreaming||$m(e)||E(e,t=>le(e,t),`default`,`primary`)}},[E,y,r]);let D=(0,Y.useCallback)(async(r,i,o,s,c,u,d,f,m)=>{if(!h)return;let _=h,v=b(r);a(null),l(null);let S=o.trim().match(jh);if(S){if(r!==`primary`)return;if(v.filter(e=>e.sender===`agent`).length<2){n({title:`Nothing to compact`,description:`Start a conversation with at least two exchanges first.`});return}if(y.includes(_)||x(_,r)){n({title:`Agent is busy`,description:`Wait for the agent to finish before compacting.`});return}let e=S[1]?.trim();Ph(t,_,s);try{let i=await En(_,{model:s,provider:u,instructions:e});t({type:Z.SetMessages,messages:i.messages}),t(Nh({type:Z.ResetStream},_,r)),n({title:`Conversation compacted`,description:`${i.messagesBefore} messages → ${i.messagesAfter} summary`})}catch(e){t(Nh({type:Z.ResetStream},_,r)),n({title:`Compaction failed`,description:e instanceof Error?e.message:`Failed to compact conversation`,variant:`destructive`})}return}let C=`msg-${Date.now()}`,w={messageId:C,sender:`user`,content:o,contentType:`text`,timestamp:new Date().toISOString(),model:s,attachments:c.map(e=>({fileName:e.fileName,content:e.content,mimeType:e.mimeType}))};t({type:Z.AddMessage,message:w,threadId:_,paneId:r});let T;try{let e=await Oe(_,C);e.success&&e.stashed&&e.checkpointRef&&(T=e.checkpointRef)}catch{}if(r===`primary`){let e=o.trim().replace(/\n/g,` `).slice(0,100);g&&(M(_,{title:e}).catch(e=>{console.error(`Failed to update thread title:`,e)}),t({type:Z.UpdateThreadTitle,projectId:g,threadId:_,title:e}))}if(f){let e=u??void 0;if(!e&&typeof s==`string`){let t=s.split(/[:/]/)[0]?.trim();t&&(e=t)}if(!e){let e={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:s,isThinking:!1};t({type:Z.AddMessage,message:e,threadId:_,paneId:r}),t(Nh({type:Z.ResetStream},_,r)),t({type:Z.SetActiveStreamPane,paneId:null});return}t(Nh({type:Z.SetStreaming,isStreaming:!0},_,r)),t({type:Z.SetActiveStreamPane,paneId:r});try{let n=await te(o,s,e,_),i={messageId:`msg-${Date.now()}-agent`,sender:`agent`,content:o,contentType:`text`,timestamp:new Date().toISOString(),model:s,isThinking:!1,generatedImageUrl:n.imageUrl,generatedImageData:n.imageData};t({type:Z.AddMessage,message:i,threadId:_,paneId:r})}catch(e){let n=e instanceof Error?e.message:`Image generation failed`,i={messageId:`msg-${Date.now()}-error`,sender:`agent`,content:`Error: ${n}`,contentType:`text`,timestamp:new Date().toISOString(),model:s,isThinking:!1};t({type:Z.AddMessage,message:i,threadId:_,paneId:r})}finally{t(Nh({type:Z.ResetStream},_,r)),t({type:Z.SetActiveStreamPane,paneId:null})}return}E(_,e=>p(_,o,s,c,e,u,d,m,T,i),s,r,i),d&&e?.()},[h,g,t,E,y,n,e,r]);return(0,Y.useEffect)(()=>{let e=v;if(!e||e.threadId!==h||x(h??``,`primary`))return;let n=setTimeout(()=>{t({type:Z.ClearPendingChatMessage}),D(`primary`,void 0,e.message,e.model,[],e.provider)},100);return()=>clearTimeout(n)},[v,h,t,D,r]),(0,Y.useEffect)(()=>{if(!h)return;let e,n=null;for(let i of[`primary`,`secondary`]){let a=C(i);if(a.length===0||x(h,i)||m.current[i])continue;let[o]=a;m.current[i]=!0,n=i,e=setTimeout(()=>{t({type:Z.RemoveQueuedChatMessage,queuedMessageId:o.id}),D(i,i===`secondary`?r.getState().secondaryConversationId??void 0:void 0,o.message,o.model,o.attachments,o.provider,o.planMode,o.imageMode,o.ralphMode),m.current[i]=!1},0);break}return()=>{e&&clearTimeout(e),n&&(m.current[n]=!1)}},[t,C,D,_,h,r]),{error:i,setError:a,handleSend:D,handleStop:T,getQueuedMessagesForPane:C,handleRemoveQueuedMessage:(0,Y.useCallback)((e,n)=>{let i=C(e).find(e=>e.id===n);t({type:Z.RemoveQueuedChatMessage,queuedMessageId:n}),!(!i||x(h??``,e)||b(e).length>0||!h)&&D(e,e===`secondary`?r.getState().secondaryConversationId??void 0:void 0,i.message,i.model,i.attachments,i.provider,i.planMode,i.imageMode,i.ralphMode)},[t,C,D,h,r]),showEmptyBalanceDialog:o,setShowEmptyBalanceDialog:s}}var Ih=(0,Y.createContext)(void 0);function Lh(e){let t=(0,X.c)(3),{children:n}=e,r=Fh(),i;return t[0]!==n||t[1]!==r?(i=(0,$.jsx)(Ih.Provider,{value:r,children:n}),t[0]=n,t[1]=r,t[2]=i):i=t[2],i}function Rh(){let e=(0,Y.useContext)(Ih);if(e===void 0)throw Error(`useChatHandlersContext must be used within a ChatHandlersProvider`);return e}function zh(e){let t=(0,X.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)(Bh,{messages:i}),t[2]=i,t[3]=a),a}function Bh(e){let t=(0,X.c)(59),{messages:n}=e,{paneId:r,conversationId:i,fillPane:a}=md(),o=Q(Uh),s=Q(Hh),c=Q(Vh),[l,u]=Y.useState(!1),{handleSend:d,handleStop:f,getQueuedMessagesForPane:p,handleRemoveQueuedMessage:m,showEmptyBalanceDialog:h,setShowEmptyBalanceDialog:g}=Rh(),{userTasks:_,setUserTasks:v,handleNewChat:y,handleSelectUserTask:b,handleRemoveUserTask:x,toggleUserTaskPinned:S,effectiveIsStreaming:C}=Yp(),w=Jd(),T;t[0]===w?T=t[1]:(T=w||at(),t[0]=w,t[1]=T);let E=T,D;t[2]!==i||t[3]!==d||t[4]!==r?(D=(e,t,n,a,o,s,c)=>d(r,i,e,t,n,a,o,s,c),t[2]=i,t[3]=d,t[4]=r,t[5]=D):D=t[5];let O=D,k;t[6]!==f||t[7]!==r?(k=()=>{f(r)},t[6]=f,t[7]=r,t[8]=k):k=t[8];let A=k,j;t[9]!==m||t[10]!==r?(j=e=>{m(r,e)},t[9]=m,t[10]=r,t[11]=j):j=t[11];let M=j,N;t[12]===g?N=t[13]:(N=()=>g(!1),t[12]=g,t[13]=N);let P;t[14]!==h||t[15]!==N?(P=(0,$.jsx)(Rm,{open:h,onClose:N}),t[14]=h,t[15]=N,t[16]=P):P=t[16];let F;t[17]!==a||t[18]!==E?(F=vd(a,E),t[17]=a,t[18]=E,t[19]=F):F=t[19];let I;t[20]!==C||t[21]!==y||t[22]!==x||t[23]!==b||t[24]!==o||t[25]!==n||t[26]!==r||t[27]!==c||t[28]!==s||t[29]!==S||t[30]!==_?(I=r===`primary`&&s&&(c||n.length>0||_.length>0)&&(0,$.jsx)(`div`,{className:`max-md:hidden`,children:(0,$.jsx)(Am,{threadId:s,projectId:c??``,messages:n,userTasks:_,effectiveIsStreaming:C,isCreatingProject:o,onNewChat:()=>{y()},onSelectUserTask:b,onToggleUserTaskPinned:S,onRemoveUserTask:e=>{x(e)}})}),t[20]=C,t[21]=y,t[22]=x,t[23]=b,t[24]=o,t[25]=n,t[26]=r,t[27]=c,t[28]=s,t[29]=S,t[30]=_,t[31]=I):I=t[31];let ee=!s&&!o,L;t[32]!==p||t[33]!==r?(L=p(r),t[32]=p,t[33]=r,t[34]=L):L=t[34];let te;t[35]===x?te=t[36]:(te=e=>{e.pinned||x(e.id)},t[35]=x,t[36]=te);let R;t[37]===v?R=t[38]:(R=e=>{v(t=>[...t,e])},t[37]=v,t[38]=R);let ne;t[39]!==C||t[40]!==M||t[41]!==O||t[42]!==A||t[43]!==l||t[44]!==L||t[45]!==te||t[46]!==R||t[47]!==ee||t[48]!==_?(ne=(0,$.jsx)(tp,{planMode:l,setPlanMode:u,onSend:O,onStop:A,isStreaming:C,disabled:ee,initialValue:``,queuedMessages:L,onRemoveQueuedMessage:M,isOverlay:!1,userTasks:_,onMatchedUserTaskSend:te,onUserTaskCreated:R}),t[39]=C,t[40]=M,t[41]=O,t[42]=A,t[43]=l,t[44]=L,t[45]=te,t[46]=R,t[47]=ee,t[48]=_,t[49]=ne):ne=t[49];let re;t[50]!==ne||t[51]!==I?(re=(0,$.jsxs)(`div`,{className:`relative`,children:[I,ne]}),t[50]=ne,t[51]=I,t[52]=re):re=t[52];let ie;t[53]!==re||t[54]!==F?(ie=(0,$.jsx)(`div`,{className:F,children:re}),t[53]=re,t[54]=F,t[55]=ie):ie=t[55];let ae;return t[56]!==ie||t[57]!==P?(ae=(0,$.jsxs)($.Fragment,{children:[P,ie]}),t[56]=ie,t[57]=P,t[58]=ae):ae=t[58],ae}function Vh(e){return e.selectedProjectId}function Hh(e){return e.selectedThreadId}function Uh(e){return e.isCreatingProject}var Wh=768;function Gh(){let e=(0,X.c)(2),[t,n]=Y.useState(void 0),r,i;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=()=>{let e=window.matchMedia(`(max-width: ${Wh-1}px)`),t=()=>{n(window.innerWidth<Wh)};return e.addEventListener(`change`,t),n(window.innerWidth<Wh),()=>e.removeEventListener(`change`,t)},i=[],e[0]=r,e[1]=i):(r=e[0],i=e[1]),Y.useEffect(r,i),!!t}function Kh(e){let t=(0,X.c)(7),{paneId:n,conversationId:r}=e,i=Ia(),a=Q(Jh),o=Q(qh),s,c;t[0]!==r||t[1]!==i||t[2]!==o||t[3]!==n||t[4]!==a?(s=()=>{if(n!==`secondary`||!o||!a||!r)return;let e=a,t=r,s=!1;return(async function(){try{let n=await mn(e,t);if(s)return;i({type:Z.SetSecondaryMessages,messages:n.messages})}catch(e){console.error(`Failed to load secondary chat history:`,e),s||i({type:Z.SetSecondaryMessages,messages:[]})}})(),()=>{s=!0}},c=[r,i,o,n,a],t[0]=r,t[1]=i,t[2]=o,t[3]=n,t[4]=a,t[5]=s,t[6]=c):(s=t[5],c=t[6]),(0,Y.useEffect)(s,c)}function qh(e){return e.dualChatEnabled}function Jh(e){return e.selectedThreadId}var Yh=4,Xh=8,Zh=`(max-width: 767px)`;function Qh(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(Zh).matches?Yh:0,s=window.matchMedia(Zh).matches?0:Xh;return a+o+s}function $h(e,t,n){let r=(0,X.c)(5),[i,a]=(0,Y.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(0);return}let o=function(){let n=e.current,r=t.current;!n||!r||a(Qh(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,Y.useEffect)(o,s),i}var eg;(function(e){e.Dark=`DARK`,e.Light=`LIGHT`,e.Default=`DEFAULT`})(eg||={});var tg;(function(e){e.Body=`body`,e.Ionic=`ionic`,e.Native=`native`,e.None=`none`})(tg||={});var ng=oh(`Keyboard`);function rg(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 ig(e,t){return jt()?t:e>0?e:t}function ag(e,t){let n=(0,X.c)(6),[r,i]=(0,Y.useState)(0),[a,o]=(0,Y.useState)(0),s=t?.onlyWhenOverlapping??!1,c,l;if(n[0]===e?(c=n[1],l=n[2]):(c=()=>{let t=function(){i(rg(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 at()&&a.push(ng.addListener(`keyboardWillShow`,e=>{o(e.keyboardHeight)}),ng.addListener(`keyboardDidShow`,e=>{o(e.keyboardHeight)}),ng.addListener(`keyboardWillHide`,()=>{o(0)}),ng.addListener(`keyboardDidHide`,()=>{o(0)})),()=>{r?.removeEventListener(`resize`,n),r?.removeEventListener(`scroll`,n),window.removeEventListener(`resize`,n);for(let e of a)e.then(og)}},l=[e],n[0]=e,n[1]=c,n[2]=l),(0,Y.useEffect)(c,l),s&&r<=0)return 0;let u;return n[3]!==r||n[4]!==a?(u=ig(r,a),n[3]=r,n[4]=a,n[5]=u):u=n[5],u}function og(e){e.remove()}function sg({paneId:e,conversationId:t,onCreateThread:n,showEmptyState:r=e===`primary`,fillPane:i=!1,onConnectRepo:a=()=>{},onNewApp:o=()=>{},onOpenFolder:s=()=>{}}){let c=Ia(),l=Q(e=>e.selectedThreadId),u=Q(e=>e.selectedProjectId),d=Q(e=>e.projects),f=Q(e=>e.projectsLoading),p=Q(e=>e.isCreatingProject),m=Q(e=>e.processingThreadIds),h=Q(e=>e.pendingChatMessage),g=Q(t=>l?Ri(t.threadStreamingStates,l,e):null),_=Q(e=>e.messages),v=Q(e=>e.secondaryMessages),y=Q(e=>e.messagesLoaded),b=Q(e=>e.secondaryMessagesLoaded),x=e===`primary`?_:v,S=e===`primary`?y:b,C=!!(l&&m.includes(l)),w=e===`primary`&&h?.threadId===l,T=g?.isStreaming??!1;Kh({paneId:e,conversationId:t});let E=(0,Y.useRef)(null),D=(0,Y.useRef)(null),O=(0,Y.useRef)(null),k=Gh(),[A,j]=(0,Y.useState)(!0),M=!!l,N=k&&M&&!A,P=$h(E,D,M),F=ag(D);function I(){c({type:Z.CloseSidebar})}return(0,$.jsx)(fd,{paneId:e,conversationId:t,fillPane:i,children:(0,$.jsx)(Wp,{children:(0,$.jsxs)(`div`,{ref:E,className:`relative flex h-full min-w-0 flex-col`,children:[(0,$.jsx)(Ed,{ref:O,bottomInset:P,messages:x,isStreaming:T,streamingSegments:T?g?.streamingSegments??[]:[],streamingModel:T?g?.streamingModel??``:``,isCreatingProject:r?p:!1,isProcessingThread:C,hasPendingMessage:w,selectedThreadId:l,selectedProjectId:u,projects:d,projectsLoading:f,messagesLoaded:S,onSelectThread:(e,t)=>{I(),c({type:Z.SelectThread,projectId:e,threadId:t})},onCreateThread:n,onConnectRepo:a,onNewApp:o,onOpenFolder:s,error:null,onClearError:()=>{},onAtBottomChange:j,hideEmptyState:!r}),M&&(0,$.jsxs)(`div`,{ref:D,className:`absolute inset-x-0 z-20 max-md:px-2`,style:{bottom:F},children:[(0,$.jsx)(`div`,{className:z(`h-0 bg-gradient-to-t from-background to-transparent md:h-6`,`md:mr-4`)}),(0,$.jsx)(`div`,{className:z(`h-0 bg-background md:h-8`,`md:mr-4`)}),N&&(0,$.jsx)(`div`,{className:`mb-1 flex justify-center`,children:(0,$.jsx)(`button`,{type:`button`,onClick:()=>O.current?.scrollToBottom(),className:`flex h-8 w-8 items-center justify-center rounded-full border border-border bg-background shadow-md transition-colors hover:bg-accent active:bg-accent`,"aria-label":`Scroll to bottom`,children:(0,$.jsx)(Ue,{className:`h-4 w-4`})})}),(0,$.jsx)(`div`,{className:z(`bg-background`,`md:mr-4`),children:(0,$.jsx)(zh,{messages:x})})]})]})})})}function cg(){let e=Ia(),t=Q(e=>e.selectedThreadId),n=Q(e=>e.selectedProjectId),r=Q(e=>e.processingThreadIds),i=Q(e=>e.threadStreamingStates);(0,Y.useEffect)(()=>{if(!t)return;let n=t,a=r.includes(n),o=i[Li(n,`primary`)],s=!1;async function c(){try{let t=await mn(n);if(s||(e({type:Z.SetMessages,messages:t.messages}),!a||o?.isStreaming))return;e({type:Z.ResetStream,threadId:n,paneId:`primary`}),e({type:Z.SetStreaming,isStreaming:!0,threadId:n,paneId:`primary`});let r=await le(n);if(s){await r?.cancel().catch(()=>{});return}if(!r){e({type:Z.ResetStream,threadId:n,paneId:`primary`});return}let i=r.getReader(),c=new TextDecoder,l=``;try{for(;!s;){let{done:t,value:r}=await i.read();if(t)break;l+=c.decode(r,{stream:!0});let a=l.split(`
|
|
51
|
-
`);l=a.pop()??``;for(let t of a){let r=t.trim();if(r)try{let t=JSON.parse(r);if(t.model&&e({type:Z.SetStreamModel,model:t.model,threadId:n,paneId:`primary`}),t.type===`thinking`)e({type:Z.AppendStreamThinking,content:t.content??``,threadId:n,paneId:`primary`});else if(t.type===`result`)e({type:Z.SetStreamContent,content:t.content??``,threadId:n,paneId:`primary`});else if(t.type===`complete`){e({type:Z.ResetStream,threadId:n,paneId:`primary`});return}else t.type&&t.type!==`message`&&e({type:Z.AppendStreamContent,content:t.content??``,threadId:n,paneId:`primary`})}catch{}}}}catch(e){s||console.error(`Failed to replay selected thread stream:`,e)}finally{await i.cancel().catch(()=>{})}s||e({type:Z.ResetStream,threadId:n,paneId:`primary`})}catch(t){console.error(`Failed to load chat history:`,t),s||(e({type:Z.SetMessages,messages:[]}),e({type:Z.ResetStream,threadId:n,paneId:`primary`}))}}return c(),()=>{s=!0}},[t,n,e])}var lg=e=>{let t=(0,X.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=z(`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)(nr,{className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a},ug=vr,dg=e=>{let t=(0,X.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=z(`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)(et,{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)(_r,{className:a,...r,children:o}),t[8]=r,t[9]=a,t[10]=o,t[11]=s):s=t[11],s},fg=(0,Y.lazy)(()=>Xr(()=>import(`./diff-view-CGEl0YbC.js`),__vite__mapDeps([9,1,7,8,5,3,4,10,11,12]))),pg=(0,Y.lazy)(()=>Xr(()=>import(`./dialogs-config-BEazgV7k.js`).then(e=>e.t),__vite__mapDeps([3,1])));function mg(e){let t=(0,X.c)(35),{onCreateThread:n}=e,r=Ia(),i=er(),a=fr(),[o,s]=(0,Y.useState)(!1),[c,l]=(0,Y.useState)(null),u=Q(gg),d=Q(hg),{isDualChatActive:f}=Xd(),p=Gh(),m;t[0]===r?m=t[1]:(m=()=>{r({type:Z.CloseSidebar})},t[0]=r,t[1]=m);let h=m,g;t[2]===h?g=t[3]:(g=()=>{h(),l(`clone`),s(!0)},t[2]=h,t[3]=g);let _=g,v;t[4]===h?v=t[5]:(v=()=>{h(),l(`webapp`),s(!0)},t[4]=h,t[5]=v);let y=v,b;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(b=async(e,t)=>{try{await An(e,t),s(!1),l(null)}catch(e){console.error(`Failed to clone repository:`,e)}},t[6]=b):b=t[6];let x=b,S;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(S=async(e,t,n)=>{try{await Ae(e,t,n),s(!1),l(null)}catch(e){console.error(`Failed to create project:`,e)}},t[7]=S):S=t[7];let C=S,w;t[8]===h?w=t[9]:(w=async()=>{h();try{await rt(),s(!1),l(null)}catch(e){console.error(`Failed to open folder:`,e)}},t[8]=h,t[9]=w);let T=w,E;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(E=async e=>{try{await In(e),s(!1),l(null)}catch(e){console.error(`Failed to create folder:`,e)}},t[10]=E):E=t[10];let D=E,O=a.pathname===`/review`,k;t[11]===i?k=t[12]:(k=()=>{i(`/`)},t[11]=i,t[12]=k);let A=k;cg();let j=!O,M;t[13]!==_||t[14]!==A||t[15]!==y||t[16]!==T||t[17]!==f||t[18]!==p||t[19]!==n||t[20]!==O||t[21]!==d||t[22]!==u||t[23]!==j?(M=O&&u?(0,$.jsx)(Y.Suspense,{fallback:(0,$.jsx)(ci,{}),children:(0,$.jsx)(fg,{threadId:u,onExit:A})}):j&&f&&!p?(0,$.jsxs)(lg,{direction:`horizontal`,className:`h-full`,children:[(0,$.jsx)(ug,{defaultSize:50,minSize:30,children:(0,$.jsx)(sg,{paneId:`primary`,fillPane:!0,onCreateThread:n,showEmptyState:!0,onConnectRepo:_,onNewApp:y,onOpenFolder:T})}),(0,$.jsx)(dg,{withHandle:!0}),(0,$.jsx)(ug,{defaultSize:50,minSize:30,className:`border-l border-border`,children:(0,$.jsx)(sg,{paneId:`secondary`,fillPane:!0,conversationId:d??void 0,onCreateThread:n,showEmptyState:!1})})]}):j?(0,$.jsx)(sg,{paneId:`primary`,onCreateThread:n,showEmptyState:!0,onConnectRepo:_,onNewApp:y,onOpenFolder:T}):null,t[13]=_,t[14]=A,t[15]=y,t[16]=T,t[17]=f,t[18]=p,t[19]=n,t[20]=O,t[21]=d,t[22]=u,t[23]=j,t[24]=M):M=t[24];let N=c??void 0,P;t[25]!==o||t[26]!==T||t[27]!==N?(P=(0,$.jsx)(Y.Suspense,{fallback:null,children:(0,$.jsx)(pg,{open:o,onOpenChange:s,initialMode:N,onSubmitClone:x,onSubmitWebApp:C,onSubmitFolder:D,onOpenFolder:T})}),t[25]=o,t[26]=T,t[27]=N,t[28]=P):P=t[28];let F;t[29]!==P||t[30]!==M?(F=(0,$.jsx)(Lh,{children:(0,$.jsxs)(`div`,{className:`relative flex h-full flex-col`,children:[M,P]})}),t[29]=P,t[30]=M,t[31]=F):F=t[31];let I;return t[32]!==u||t[33]!==F?(I=(0,$.jsx)(xl,{threadId:u,children:F}),t[32]=u,t[33]=F,t[34]=I):I=t[34],I}function hg(e){return e.secondaryConversationId}function gg(e){return e.selectedThreadId}function _g(e){let t=(0,X.c)(5),{children:n,className:r}=e,i;t[0]===r?i=t[1]:(i=z(`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 vg(e){let t=(0,X.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 yg;(function(e){e.Heavy=`HEAVY`,e.Medium=`MEDIUM`,e.Light=`LIGHT`})(yg||={});var bg;(function(e){e.Success=`SUCCESS`,e.Warning=`WARNING`,e.Error=`ERROR`})(bg||={});var xg=oh(`Haptics`,{web:()=>Xr(()=>import(`./web-Dt5YgbhM.js`).then(e=>new e.HapticsWeb),[])});function Sg(){return typeof window<`u`&&at()}function Cg(e=yg.Medium){Sg()&&xg.impact({style:e}).catch(()=>{})}function wg(){let e=(0,X.c)(49),t=Ia(),n=Q(kg),r=Q(Og),i=Q(Dg),a=Q(Eg),o=Q(Tg),{handleNewChat:c}=Yp(),l=o.length>0,u;if(e[0]!==i||e[1]!==r){let t;e[3]===r?t=e[4]:(t=e=>e.projectId===r,e[3]=r,e[4]=t),u=i.find(t),e[0]=i,e[1]=r,e[2]=u}else u=e[2];let d=u,f=!a,p,m;if(e[5]!==f){let t=Ve();p=_g,m=z(t&&`pt-8 md:min-h-[103px]`,f&&t&&`max-md:pb-2 md:h-auto md:pb-3 md:h-[103px] md:pb-0`),e[5]=f,e[6]=p,e[7]=m}else p=e[6],m=e[7];let h;e[8]===t?h=e[9]:(h=()=>t({type:Z.ToggleSidebar}),e[8]=t,e[9]=h);let g;e[10]===a?g=e[11]:(g=a?(0,$.jsx)(bn,{className:`h-4 w-4`}):(0,$.jsx)(yt,{className:`h-4 w-4`}),e[10]=a,e[11]=g);let _;e[12]===Symbol.for(`react.memo_cache_sentinel`)?(_=(0,$.jsx)(`span`,{className:`sr-only`,children:`Toggle sidebar`}),e[12]=_):_=e[12];let v;e[13]!==h||e[14]!==g?(v=(0,$.jsxs)(s,{variant:`ghost`,size:`icon`,className:`h-8 w-8 text-muted-foreground shrink-0 electrobun-webkit-app-region-no-drag`,onClick:h,children:[g,_]}),e[13]=h,e[14]=g,e[15]=v):v=e[15];let y;e[16]!==i||e[17]!==r||e[18]!==n?(y=n&&(0,$.jsx)(`span`,{className:z(W.sectionTitle,`text-foreground truncate min-w-0`),children:E(i,r)}),e[16]=i,e[17]=r,e[18]=n,e[19]=y):y=e[19];let b;e[20]!==v||e[21]!==y?(b=(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-2`,children:[v,y]}),e[20]=v,e[21]=y,e[22]=b):b=e[22];let x;e[23]!==c||e[24]!==l||e[25]!==n?(x=n&&l&&(0,$.jsxs)(s,{size:`icon`,className:`h-7 w-7 rounded-full md:hidden electrobun-webkit-app-region-no-drag`,onClick:()=>{Cg(),c()},children:[(0,$.jsx)(sn,{className:`h-3 w-3`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`New Chat`})]}),e[23]=c,e[24]=l,e[25]=n,e[26]=x):x=e[26];let S;e[27]===n?S=e[28]:(S=n&&(0,$.jsx)(jm,{}),e[27]=n,e[28]=S);let C;e[29]!==d?.runCommand||e[30]!==r||e[31]!==n?(C=r&&(0,$.jsxs)(vg,{className:`electrobun-webkit-app-region-no-drag`,children:[(0,$.jsx)(fm,{projectId:r,runCommand:d?.runCommand}),n&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Qp,{threadId:n}),(0,$.jsx)(tm,{})]})]}),e[29]=d?.runCommand,e[30]=r,e[31]=n,e[32]=C):C=e[32];let w;e[33]!==d?.openWith||e[34]!==r||e[35]!==n?(w=n&&r&&(0,$.jsx)(vg,{className:`electrobun-webkit-app-region-no-drag`,children:(0,$.jsx)(cm,{projectId:r,threadId:n,openWith:d?.openWith})}),e[33]=d?.openWith,e[34]=r,e[35]=n,e[36]=w):w=e[36];let T;e[37]!==C||e[38]!==w?(T=(0,$.jsxs)(`div`,{className:`hidden md:flex flex-wrap items-center justify-end gap-2`,children:[C,w]}),e[37]=C,e[38]=w,e[39]=T):T=e[39];let D;e[40]!==T||e[41]!==x||e[42]!==S?(D=(0,$.jsxs)(`div`,{className:`ml-auto flex shrink-0 items-center gap-2`,children:[x,S,T]}),e[40]=T,e[41]=x,e[42]=S,e[43]=D):D=e[43];let O;return e[44]!==p||e[45]!==m||e[46]!==D||e[47]!==b?(O=(0,$.jsxs)(p,{className:m,children:[b,D]}),e[44]=p,e[45]=m,e[46]=D,e[47]=b,e[48]=O):O=e[48],O}function Tg(e){return e.messages}function Eg(e){return e.sidebarOpen}function Dg(e){return e.projects}function Og(e){return e.selectedProjectId}function kg(e){return e.selectedThreadId}function Ag(){let e=(0,X.c)(1),t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center bg-background`,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 jg=[`Chat`,`Explorer`,`Review`,`Browser`,`Terminal`,`Tasks`];function Mg(e){let t=(0,X.c)(14),{mainTabBarRef:n,explorerTabClickedRef:r,reviewTabClickedRef:i,tasksTabClickedRef:a}=e,{activeMainTab:o,setActiveMainTab:s,terminalNotification:c,setTerminalNotification:l,triggerReviewRefresh:u,triggerTasksRefresh:d}=Ks(),{triggerExplorerRefresh:f}=Xs(),p;t[0]!==o||t[1]!==r||t[2]!==i||t[3]!==s||t[4]!==l||t[5]!==a||t[6]!==c||t[7]!==f||t[8]!==u||t[9]!==d?(p=jg.map(e=>{let t=e.toLowerCase();return(0,$.jsxs)(`button`,{"data-tab":t,onClick:()=>{s(t),t===`terminal`&&l(!1),t===`explorer`&&(r.current=!0,f()),t===`review`&&(i.current=!0,u()),t===`tasks`&&(a.current=!0,d())},className:`relative shrink-0 px-4 py-2 text-base font-medium transition-colors ${o===t?`border-b-2 border-primary text-foreground -mb-px`:`text-muted-foreground hover:text-foreground`}`,children:[e,t===`terminal`&&c&&o!==`terminal`&&(0,$.jsx)(`span`,{className:`absolute top-1.5 right-1 h-1.5 w-1.5 rounded-full bg-brand`})]},t)}),t[0]=o,t[1]=r,t[2]=i,t[3]=s,t[4]=l,t[5]=a,t[6]=c,t[7]=f,t[8]=u,t[9]=d,t[10]=p):p=t[10];let m;return t[11]!==n||t[12]!==p?(m=(0,$.jsx)(`div`,{ref:n,className:`flex shrink-0 select-none overflow-x-auto overflow-y-hidden border-b border-border`,children:p}),t[11]=n,t[12]=p,t[13]=m):m=t[13],m}var Ng=(0,Y.lazy)(()=>Xr(()=>import(`./terminal-panel-DIpnKR-N.js`).then(e=>({default:e.TerminalPanel})),__vite__mapDeps([13,1,3,14]))),Pg=(0,Y.lazy)(()=>Xr(()=>import(`./diff-view-CGEl0YbC.js`),__vite__mapDeps([9,1,7,8,5,3,4,10,11,12]))),Fg=(0,Y.lazy)(()=>Xr(()=>import(`./explorer-tab-view--ib_BjId.js`),__vite__mapDeps([15,1,7,8,5,3]))),Ig=(0,Y.lazy)(()=>Xr(()=>import(`./browser-tab-qhf-xKwZ.js`).then(e=>({default:e.BrowserTab})),__vite__mapDeps([16,1,3]))),Lg=(0,Y.lazy)(()=>Xr(()=>import(`./settings-view-DLBIkYoA.js`),__vite__mapDeps([17,1,7,8,5,3,4,18,19,11]))),Rg=(0,Y.lazy)(()=>Xr(()=>import(`./todos-view-BK6i_oPT.js`).then(e=>({default:e.TodosView})),__vite__mapDeps([20,1,7,8,5,3,21,11])));function zg(e){let t=(0,X.c)(47),{selectedThreadId:n,selectedProjectId:r,isReviewRoute:i,isSettingsRoute:a,onCreateThread:o,mainTabBarRef:s,explorerTabClickedRef:c,reviewTabClickedRef:l,tasksTabClickedRef:u}=e,{activeMainTab:d,setActiveMainTab:f,reviewRefreshTick:p,tasksRefreshTick:m}=Ks(),h=!i&&!a,g;t[0]===h?g=t[1]:(g=h&&(0,$.jsx)(wg,{}),t[0]=h,t[1]=g);let _;t[2]!==c||t[3]!==s||t[4]!==l||t[5]!==r||t[6]!==h||t[7]!==u?(_=h&&r&&(0,$.jsx)(Mg,{mainTabBarRef:s,explorerTabClickedRef:c,reviewTabClickedRef:l,tasksTabClickedRef:u}),t[2]=c,t[3]=s,t[4]=l,t[5]=r,t[6]=h,t[7]=u,t[8]=_):_=t[8];let v=`flex-1 overflow-hidden${h&&d!==`chat`?` hidden`:``}`,y;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(y=(0,$.jsx)(cr,{path:`/settings/providers/:providerSlug`,element:(0,$.jsx)(Y.Suspense,{fallback:(0,$.jsx)(Ag,{}),children:(0,$.jsx)(Lg,{})})}),t[9]=y):y=t[9];let b;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(b=(0,$.jsx)(cr,{path:`/settings/project/:projectId`,element:(0,$.jsx)(Y.Suspense,{fallback:(0,$.jsx)(Ag,{}),children:(0,$.jsx)(Lg,{})})}),t[10]=b):b=t[10];let x;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(x=(0,$.jsx)(cr,{path:`/settings/:tab?`,element:(0,$.jsx)(Y.Suspense,{fallback:(0,$.jsx)(Ag,{}),children:(0,$.jsx)(Lg,{})})}),t[11]=x):x=t[11];let S;t[12]===o?S=t[13]:(S=(0,$.jsxs)(lr,{children:[y,b,x,(0,$.jsx)(cr,{path:`*`,element:(0,$.jsx)(mg,{onCreateThread:o})})]}),t[12]=o,t[13]=S);let C;t[14]!==v||t[15]!==S?(C=(0,$.jsx)(`main`,{className:v,children:S}),t[14]=v,t[15]=S,t[16]=C):C=t[16];let w=`flex-1 overflow-hidden${d===`terminal`&&h?``:` hidden`}`,T;t[17]===Symbol.for(`react.memo_cache_sentinel`)?(T=(0,$.jsx)(Y.Suspense,{fallback:null,children:(0,$.jsx)(Ng,{})}),t[17]=T):T=t[17];let E;t[18]===w?E=t[19]:(E=(0,$.jsx)(`div`,{className:w,children:T}),t[18]=w,t[19]=E);let D=`flex-1 overflow-hidden${d===`browser`&&h?``:` hidden`}`,O;t[20]===Symbol.for(`react.memo_cache_sentinel`)?(O=(0,$.jsx)(Y.Suspense,{fallback:null,children:(0,$.jsx)(Ig,{})}),t[20]=O):O=t[20];let k;t[21]===D?k=t[22]:(k=(0,$.jsx)(`div`,{className:D,children:O}),t[21]=D,t[22]=k);let A;t[23]!==d||t[24]!==n||t[25]!==h?(A=n&&h&&d===`explorer`&&(0,$.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:(0,$.jsx)(Y.Suspense,{fallback:(0,$.jsx)(ui,{}),children:(0,$.jsx)(Fg,{})})}),t[23]=d,t[24]=n,t[25]=h,t[26]=A):A=t[26];let j;t[27]!==d||t[28]!==r||t[29]!==h||t[30]!==m?(j=h&&d===`tasks`&&r&&(0,$.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:(0,$.jsx)(Y.Suspense,{fallback:(0,$.jsx)(ui,{}),children:(0,$.jsx)(Rg,{projectId:r,refreshTrigger:m})})}),t[27]=d,t[28]=r,t[29]=h,t[30]=m,t[31]=j):j=t[31];let M;t[32]!==d||t[33]!==p||t[34]!==n||t[35]!==f||t[36]!==h?(M=h&&d===`review`&&n&&(0,$.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:(0,$.jsx)(Y.Suspense,{fallback:null,children:(0,$.jsx)(Pg,{threadId:n,onExit:()=>f(`chat`),refreshTrigger:p})})}),t[32]=d,t[33]=p,t[34]=n,t[35]=f,t[36]=h,t[37]=M):M=t[37];let N;return t[38]!==g||t[39]!==E||t[40]!==k||t[41]!==A||t[42]!==j||t[43]!==M||t[44]!==_||t[45]!==C?(N=(0,$.jsxs)(`div`,{className:`flex h-full flex-col overflow-hidden`,children:[g,_,C,E,k,A,j,M]}),t[38]=g,t[39]=E,t[40]=k,t[41]=A,t[42]=j,t[43]=M,t[44]=_,t[45]=C,t[46]=N):N=t[46],N}function Bg(e){let t=(0,X.c)(14),{open:n,projectName:r,onOpenChange:i,onConfirm:a}=e,o;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,$.jsx)($r,{children:`Delete Project`}),t[0]=o):o=t[0];let s;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(s=z(W.body,`font-semibold text-foreground`),t[1]=s):s=t[1];let c;t[2]===r?c=t[3]:(c=(0,$.jsxs)(ii,{children:[o,(0,$.jsxs)(ti,{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)(Zr,{children:`Cancel`}),t[4]=l):l=t[4];let u;t[5]===a?u=t[6]:(u=(0,$.jsxs)(ni,{children:[l,(0,$.jsx)(si,{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)(oi,{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)(ri,{open:n,onOpenChange:i,children:d}),t[10]=i,t[11]=n,t[12]=d,t[13]=f):f=t[13],f}function Vg(e){let t=(0,X.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)($r,{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)(ii,{children:[o,(0,$.jsxs)(ti,{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(Hg),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)(Zr,{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)(si,{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)(ni,{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)(oi,{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)(ri,{open:n,onOpenChange:a,children:h}),t[24]=n,t[25]=a,t[26]=h,t[27]=g):g=t[27],g}function Hg(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:W.label,children:r||`root`}),(0,$.jsx)(`div`,{className:W.bodyMuted,children:i})]})]})},t)}var Ug;(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`})(Ug||={});var Wg=new Map([[Ug.QR_CODE,`QR_CODE`],[Ug.AZTEC,`AZTEC`],[Ug.CODABAR,`CODABAR`],[Ug.CODE_39,`CODE_39`],[Ug.CODE_93,`CODE_93`],[Ug.CODE_128,`CODE_128`],[Ug.DATA_MATRIX,`DATA_MATRIX`],[Ug.MAXICODE,`MAXICODE`],[Ug.ITF,`ITF`],[Ug.EAN_13,`EAN_13`],[Ug.EAN_8,`EAN_8`],[Ug.PDF_417,`PDF_417`],[Ug.RSS_14,`RSS_14`],[Ug.RSS_EXPANDED,`RSS_EXPANDED`],[Ug.UPC_A,`UPC_A`],[Ug.UPC_E,`UPC_E`],[Ug.UPC_EAN_EXTENSION,`UPC_EAN_EXTENSION`]]),Gg;(function(e){e[e.UNKNOWN=0]=`UNKNOWN`,e[e.URL=1]=`URL`})(Gg||={});function Kg(e){return Object.values(Ug).includes(e)}var qg;(function(e){e[e.SCAN_TYPE_CAMERA=0]=`SCAN_TYPE_CAMERA`,e[e.SCAN_TYPE_FILE=1]=`SCAN_TYPE_FILE`})(qg||={});var Jg=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=[qg.SCAN_TYPE_CAMERA,qg.SCAN_TYPE_FILE],e}(),Yg=function(){function e(e,t){this.format=e,this.formatName=t}return e.prototype.toString=function(){return this.formatName},e.create=function(t){if(!Wg.has(t))throw`${t} not in html5QrcodeSupportedFormatsTextMap`;return new e(t,Wg.get(t))},e}(),Xg=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}(),Zg;(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`})(Zg||={});var Qg=function(){function e(){}return e.createFrom=function(e){return{errorMessage:e,type:Zg.UNKWOWN_ERROR}},e}(),$g=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 e_(e){return e==null}function t_(e,t,n){return e>n?n:e<t?t:e}var n_=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}(),r_=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}(),i_=function(){function e(){}return e.poweredBy=function(){return`Powered by `},e.reportIssues=function(){return`Report issues`},e}(),a_=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}(),o_=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)===`
|
|
52
|
-
`||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=`
|
|
53
|
-
`){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(`
|
|
54
|
-
`)}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 ee{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 L{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 te;(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`})(te||={});var R=te,ne;(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`})(ne||={});var re=ne;class ie{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 ae{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 oe{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=ae.addOrSubtract(n,r)}return n}n=t[0];let r=t.length,i=this.field;for(let a=1;a<r;a++)n=ae.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]=ae.addOrSubtract(t[e-i],n[e]);return new oe(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]=ae.addOrSubtract(a[e+t],o.multiply(n,r[t]))}return new oe(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 oe(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 oe(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 se extends s{}se.kind=`ArithmeticException`;class ce extends ae{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 oe(this,Int32Array.from([0])),this.one=new oe(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 oe(this,n)}inverse(e){if(e===0)throw new se;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}}ce.AZTEC_DATA_12=new ce(4201,4096,1),ce.AZTEC_DATA_10=new ce(1033,1024,1),ce.AZTEC_DATA_6=new ce(67,64,1),ce.AZTEC_PARAM=new ce(19,16,1),ce.QR_CODE_FIELD_256=new ce(285,256,0),ce.DATA_MATRIX_FIELD_256=new ce(301,256,1),ce.AZTEC_DATA_8=ce.DATA_MATRIX_FIELD_256,ce.MAXICODE_FIELD_64=ce.AZTEC_DATA_6;class z extends s{}z.kind=`ReedSolomonException`;class le extends s{}le.kind=`IllegalStateException`;class ue{constructor(e){this.field=e}decode(e,t){let n=this.field,r=new oe(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 oe(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 z(`Bad error location`);e[r]=ce.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 z(`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 le(`Division algorithm failed to reduce polynomial?`)}let c=s.getCoefficient(0);if(c===0)throw new z(`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 z(`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 de;(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`})(de||={});class fe{decode(e){this.ddata=e;let t=e.getBits(),n=this.extractBits(t),r=this.correctBits(n),i=new ie(fe.convertBoolArrayToByteArray(r),fe.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=de.UPPER,r=de.UPPER,i=``,a=0;for(;a<t;)if(r===de.BINARY){if(t-a<5)break;let o=fe.readCode(e,a,5);if(a+=5,o===0){if(t-a<11)break;o=fe.readCode(e,a,11)+31,a+=11}for(let n=0;n<o;n++){if(t-a<8){a=t;break}let n=fe.readCode(e,a,8);i+=E.castAsNonUtf8Char(n),a+=8}r=n}else{let o=r===de.DIGIT?4:5;if(t-a<o)break;let s=fe.readCode(e,a,o);a+=o;let c=fe.getCharacter(r,s);c.startsWith(`CTRL_`)?(n=r,r=fe.getTable(c.charAt(5)),c.charAt(6)===`L`&&(n=r)):(i+=c,r=n)}return i}static getTable(e){switch(e){case`L`:return de.LOWER;case`P`:return de.PUNCT;case`M`:return de.MIXED;case`D`:return de.DIGIT;case`B`:return de.BINARY;default:return de.UPPER}}static getCharacter(e,t){switch(e){case de.UPPER:return fe.UPPER_TABLE[t];case de.LOWER:return fe.LOWER_TABLE[t];case de.MIXED:return fe.MIXED_TABLE[t];case de.PUNCT:return fe.PUNCT_TABLE[t];case de.DIGIT:return fe.DIGIT_TABLE[t];default:throw new le(`Bad table`)}}correctBits(e){let t,n;this.ddata.getNbLayers()<=2?(n=6,t=ce.AZTEC_DATA_6):this.ddata.getNbLayers()<=8?(n=8,t=ce.AZTEC_DATA_8):this.ddata.getNbLayers()<=22?(n=10,t=ce.AZTEC_DATA_10):(n=12,t=ce.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]=fe.readCode(e,a,n);try{new ue(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?fe.readCode(e,t,8):fe.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]=fe.readByte(e,8*n);return t}totalBitsInLayer(e,t){return((t?88:112)+16*e)*e}}fe.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(`.`),fe.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(`.`),fe.MIXED_TABLE=`CTRL_PS. .\\1.\\2.\\3.\\4.\\5.\\6.\\7.\b. .
|
|
55
|
-
.\\13.\f.\r.\\33.\\34.\\35.\\36.\\37.@.\\.^._.\`.|.~.\\177.CTRL_LL.CTRL_UL.CTRL_PL.CTRL_BS`.split(`.`),fe.PUNCT_TABLE=[``,`\r`,`\r
|
|
56
|
-
`,`. `,`, `,`: `,`!`,`"`,`#`,`$`,`%`,`&`,`'`,`(`,`)`,`*`,`+`,`,`,`-`,`.`,`/`,`:`,`;`,`<`,`=`,`>`,`?`,`[`,`]`,`{`,`}`,`CTRL_UL`],fe.DIGIT_TABLE=[`CTRL_PS`,` `,`0`,`1`,`2`,`3`,`4`,`5`,`6`,`7`,`8`,`9`,`,`,`.`,`CTRL_UL`,`CTRL_US`];class B{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 B.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=B.round(B.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=B.round(e+n*a),i=B.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 H{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=H.quadrilateralToSquare(e,t,n,r,i,a,o,s);return H.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 H(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 H(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 H.squareToQuadrilateral(e,t,n,r,i,a,o,s).buildAdjoint()}buildAdjoint(){return new H(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 H(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 ve extends _e{sampleGrid(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h,g,_,v){let y=H.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 ye{static setGridSampler(e){ye.gridSampler=e}static getInstance(){return ye.gridSampler}}ye.gridSampler=new ve;class be{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 xe{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 ue(ce.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 be(i+7,a-7),!1,1,-1).toResultPoint(),t=this.getFirstDifferent(new be(i+7,a+7),!1,1,1).toResultPoint(),n=this.getFirstDifferent(new be(i-7,a+7),!1,-1,1).toResultPoint(),r=this.getFirstDifferent(new be(i-7,a-7),!1,-1,-1).toResultPoint()}let i=B.round((e.getX()+r.getX()+t.getX()+n.getX())/4),a=B.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 be(i+7,a-7),!1,1,-1).toResultPoint(),t=this.getFirstDifferent(new be(i+7,a+7),!1,1,1).toResultPoint(),n=this.getFirstDifferent(new be(i-7,a+7),!1,-1,1).toResultPoint(),r=this.getFirstDifferent(new be(i-7,a-7),!1,-1,-1).toResultPoint()}return i=B.round((e.getX()+r.getX()+t.getX()+n.getX())/4),a=B.round((e.getY()+r.getY()+t.getY()+n.getY())/4),new be(i,a)}getMatrixCornerPoints(e){return this.expandSquare(e,2*this.nbCenterLayers,this.getDimension())}sampleGrid(e,t,n,r,i){let a=ye.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(B.round(o+e*c),B.round(s+e*l))&&(r|=1<<n-e-1);return r}isWhiteOrBlackRectangle(e,t,n,r){e=new be(e.getX()-3,e.getY()+3),t=new be(t.getX()-3,t.getY()-3),n=new be(n.getX()+3,n.getY()-3),r=new be(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(B.round(o),B.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 be(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=B.round(e.getX()),n=B.round(e.getY());return this.isValid(t,n)}distancePoint(e,t){return B.distance(e.getX(),e.getY(),t.getX(),t.getY())}distanceResultPoint(e,t){return B.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 Se{decode(e,t=null){let n=null,r=new xe(e.getBlackMatrix()),i=null,a=null;try{let e=r.detectMirror(!1);i=e.getPoints(),this.reportFoundResultPoints(t,i),a=new fe().decode(e)}catch(e){n=e}if(a==null)try{let e=r.detectMirror(!0);i=e.getPoints(),this.reportFoundResultPoints(t,i),a=new fe().decode(e)}catch(e){throw n??e}let o=new L(a.getText(),a.getRawBytes(),a.getNumBits(),i,R.AZTEC,p.currentTimeMillis()),s=a.getByteSegments();s!=null&&o.putMetadata(re.BYTE_SEGMENTS,s);let c=a.getECLevel();return c!=null&&o.putMetadata(re.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 Ce extends ee{constructor(e=500){super(new Se,e)}}class we{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(re.ORIENTATION)===!0&&(a+=i.get(re.ORIENTATION)%360),r.putMetadata(re.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(re.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;we.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 U extends we{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=U.MAX_AVG_VARIANCE,n=-1;for(let e=U.CODE_START_A;e<=U.CODE_START_C;e++){let r=we.patternMatchVariance(i,U.CODE_PATTERNS[e],U.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){we.recordPattern(e,n,t);let r=U.MAX_AVG_VARIANCE,i=-1;for(let e=0;e<U.CODE_PATTERNS.length;e++){let n=U.CODE_PATTERNS[e],a=this.patternMatchVariance(t,n,U.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=U.findStartPattern(t),a=i[2],o=0,s=new Uint8Array(20);s[o++]=a;let c;switch(a){case U.CODE_START_A:c=U.CODE_CODE_A;break;case U.CODE_START_B:c=U.CODE_CODE_B;break;case U.CODE_START_C:c=U.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=_,_=U.decodeCode(t,h,m),s[o++]=_,_!==U.CODE_STOP&&(S=!0),_!==U.CODE_STOP&&(y++,v+=y*_),p=m,m+=h.reduce((e,t)=>e+t,0),_){case U.CODE_START_A:case U.CODE_START_B:case U.CODE_START_C:throw new x}switch(c){case U.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(_!==U.CODE_STOP&&(S=!1),_){case U.CODE_FNC_1:r&&(f.length===0?f+=`]C1`:f+=``);break;case U.CODE_FNC_2:case U.CODE_FNC_3:break;case U.CODE_FNC_4_A:!C&&w?(C=!0,w=!1):C&&w?(C=!1,w=!1):w=!0;break;case U.CODE_SHIFT:u=!0,c=U.CODE_CODE_B;break;case U.CODE_CODE_B:c=U.CODE_CODE_B;break;case U.CODE_CODE_C:c=U.CODE_CODE_C;break;case U.CODE_STOP:l=!0;break}break;case U.CODE_CODE_B:if(_<96)w===C?f+=String.fromCharCode(32+_):f+=String.fromCharCode(32+_+128),w=!1;else switch(_!==U.CODE_STOP&&(S=!1),_){case U.CODE_FNC_1:r&&(f.length===0?f+=`]C1`:f+=``);break;case U.CODE_FNC_2:case U.CODE_FNC_3:break;case U.CODE_FNC_4_B:!C&&w?(C=!0,w=!1):C&&w?(C=!1,w=!1):w=!0;break;case U.CODE_SHIFT:u=!0,c=U.CODE_CODE_A;break;case U.CODE_CODE_A:c=U.CODE_CODE_A;break;case U.CODE_CODE_C:c=U.CODE_CODE_C;break;case U.CODE_STOP:l=!0;break}break;case U.CODE_CODE_C:if(_<100)_<10&&(f+=`0`),f+=_;else switch(_!==U.CODE_STOP&&(S=!1),_){case U.CODE_FNC_1:r&&(f.length===0?f+=`]C1`:f+=``);break;case U.CODE_CODE_A:c=U.CODE_CODE_A;break;case U.CODE_CODE_B:c=U.CODE_CODE_B;break;case U.CODE_STOP:l=!0;break}break}e&&(c=c===U.CODE_CODE_A?U.CODE_CODE_B:U.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===U.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 L(f,j,0,M,R.CODE_128,new Date().getTime())}}U.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])],U.MAX_AVG_VARIANCE=.25,U.MAX_INDIVIDUAL_VARIANCE=.7,U.CODE_SHIFT=98,U.CODE_CODE_C=99,U.CODE_CODE_B=100,U.CODE_CODE_A=101,U.CODE_FNC_1=102,U.CODE_FNC_2=97,U.CODE_FNC_3=96,U.CODE_FNC_4_A=101,U.CODE_FNC_4_B=100,U.CODE_START_A=103,U.CODE_START_B=104,U.CODE_START_C=105,U.CODE_STOP=106;class Te extends we{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=Te.findAsteriskPattern(t,r),a=t.getNextSet(i[1]),o=t.getSize(),s,c;do{Te.recordPattern(t,a,r);let e=Te.toNarrowWidePattern(r);if(e<0)throw new k;s=Te.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+=Te.ALPHABET_STRING.indexOf(this.decodeRowResult.charAt(n));if(this.decodeRowResult.charAt(e)!==Te.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?Te.decodeExtended(this.decodeRowResult):this.decodeRowResult;let p=(i[1]+i[0])/2,m=c+l/2;return new L(f,null,0,[new V(p,e),new V(m,e)],R.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)===Te.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<Te.CHARACTER_ENCODINGS.length;t++)if(Te.CHARACTER_ENCODINGS[t]===e)return Te.ALPHABET_STRING.charAt(t);if(e===Te.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}}Te.ALPHABET_STRING=`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%`,Te.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],Te.ASTERISK_ENCODING=148;class Ee extends we{constructor(){super(...arguments),this.narrowLineWidth=-1}decodeRow(e,t,n){let r=this.decodeStart(t),i=this.decodeEnd(t),a=new D;Ee.decodeMiddle(t,r[1],i[0],a);let o=a.toString(),s=null;n!=null&&(s=n.get(b.ALLOWED_LENGTHS)),s??=Ee.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 L(o,null,0,[new V(r[1],e),new V(i[0],e)],R.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;){we.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=Ee.decodeDigit(a);r.append(n.toString()),n=this.decodeDigit(o),r.append(n.toString()),i.forEach(function(e){t+=e})}}decodeStart(e){let t=Ee.skipWhiteSpace(e),n=Ee.findGuardPattern(e,t,Ee.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=Ee.skipWhiteSpace(e),n;try{n=Ee.findGuardPattern(e,t,Ee.END_PATTERN_REVERSED[0])}catch(r){r instanceof k&&(n=Ee.findGuardPattern(e,t,Ee.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(we.patternMatchVariance(i,n,Ee.MAX_INDIVIDUAL_VARIANCE)<Ee.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=Ee.MAX_AVG_VARIANCE,n=-1,r=Ee.PATTERNS.length;for(let i=0;i<r;i++){let r=Ee.PATTERNS[i],a=we.patternMatchVariance(e,r,Ee.MAX_INDIVIDUAL_VARIANCE);a<t?(t=a,n=i):a===t&&(n=-1)}if(n>=0)return n%10;throw new k}}Ee.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])],Ee.MAX_AVG_VARIANCE=.38,Ee.MAX_INDIVIDUAL_VARIANCE=.5,Ee.DEFAULT_ALLOWED_LENGTHS=[6,8,10,12,14],Ee.START_PATTERN=Int32Array.from([1,1,1,1]),Ee.END_PATTERN_REVERSED=[Int32Array.from([1,1,2]),Int32Array.from([1,1,3])];class De extends we{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=De.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 De.checkStandardUPCEANChecksum(e)}static checkStandardUPCEANChecksum(e){let t=e.length;if(t===0)return!1;let n=parseInt(e.charAt(t-1),10);return De.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 De.findGuardPattern(e,t,!1,De.START_END_PATTERN,new Int32Array(De.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(we.patternMatchVariance(i,r,De.MAX_INDIVIDUAL_VARIANCE)<De.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=we.patternMatchVariance(t,n,De.MAX_INDIVIDUAL_VARIANCE);o<i&&(i=o,a=e)}if(a>=0)return a;throw new k}}De.MAX_AVG_VARIANCE=.48,De.MAX_INDIVIDUAL_VARIANCE=.7,De.START_END_PATTERN=Int32Array.from([1,1,1]),De.MIDDLE_PATTERN=Int32Array.from([1,1,1,1,1]),De.END_PATTERN=Int32Array.from([1,1,1,1,1,1]),De.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 Oe{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=Oe.parseExtensionString(a),s=new L(a,null,0,[new V((n[0]+n[1])/2,e),new V(i,e)],R.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=De.decodeDigit(e,r,a,De.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(Oe.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=Oe.parseExtension5String(e);return t==null?null:new Map([[re.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 ke{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=ke.parseExtensionString(a),s=new L(a,null,0,[new V((n[0]+n[1])/2,e),new V(i,e)],R.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=De.decodeDigit(e,r,a,De.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([[re.ISSUE_NUMBER,parseInt(e)]]):null}}class Ae{static decodeRow(e,t,n){let r=De.findGuardPattern(t,n,!1,this.EXTENSION_START_PATTERN,new Int32Array(this.EXTENSION_START_PATTERN.length).fill(0));try{return new Oe().decodeRow(e,t,r)}catch{return new ke().decodeRow(e,t,r)}}}Ae.EXTENSION_START_PATTERN=Int32Array.from([1,1,2]);class je extends De{constructor(){super(),this.decodeRowStringBuffer=``,je.L_AND_G_PATTERNS=je.L_PATTERNS.map(e=>Int32Array.from(e));for(let e=10;e<20;e++){let t=je.L_PATTERNS[e-10],n=new Int32Array(t.length);for(let e=0;e<t.length;e++)n[e]=t[t.length-e-1];je.L_AND_G_PATTERNS[e]=n}}decodeRow(e,t,n){let r=je.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(!je.checkChecksum(f))throw new d;let p=(r[1]+r[0])/2,m=(c[1]+c[0])/2,h=this.getBarcodeFormat(),g=new L(f,null,0,[new V(p,e),new V(m,e)],h,new Date().getTime()),_=0;try{let n=Ae.decodeRow(e,t,c[1]);g.putMetadata(re.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 je.findGuardPattern(e,t,!1,je.START_END_PATTERN,new Int32Array(je.START_END_PATTERN.length).fill(0))}static checkChecksum(e){return je.checkStandardUPCEANChecksum(e)}static checkStandardUPCEANChecksum(e){let t=e.length;if(t===0)return!1;let n=parseInt(e.charAt(t-1),10);return je.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 Me extends je{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=je.decodeDigit(e,r,a,je.L_AND_G_PATTERNS);n+=String.fromCharCode(48+i%10);for(let e of r)a+=e;i>=10&&(o|=1<<5-t)}n=Me.determineFirstDigit(n,o),a=je.findGuardPattern(e,a,!0,je.MIDDLE_PATTERN,new Int32Array(je.MIDDLE_PATTERN.length).fill(0))[1];for(let t=0;t<6&&a<i;t++){let t=je.decodeDigit(e,r,a,je.L_PATTERNS);n+=String.fromCharCode(48+t);for(let e of r)a+=e}return{rowOffset:a,resultString:n}}getBarcodeFormat(){return R.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}}Me.FIRST_DIGIT_ENCODINGS=[0,11,13,14,19,25,28,21,22,26];class Ne extends je{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=je.decodeDigit(e,r,a,je.L_PATTERNS);n+=String.fromCharCode(48+t);for(let e of r)a+=e}a=je.findGuardPattern(e,a,!0,je.MIDDLE_PATTERN,new Int32Array(je.MIDDLE_PATTERN.length).fill(0))[1];for(let t=0;t<4&&a<i;t++){let t=je.decodeDigit(e,r,a,je.L_PATTERNS);n+=String.fromCharCode(48+t);for(let e of r)a+=e}return{rowOffset:a,resultString:n}}getBarcodeFormat(){return R.EAN_8}}class Pe extends je{constructor(){super(...arguments),this.ean13Reader=new Me}getBarcodeFormat(){return R.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 L(t.substring(1),null,null,e.getResultPoints(),R.UPC_A);return e.getResultMetadata()!=null&&n.putAllMetadata(e.getResultMetadata()),n}else throw new k}reset(){this.ean13Reader.reset()}}class Fe extends je{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=Fe.decodeDigit(e,r,a,Fe.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=Fe.determineNumSysAndCheckDigit(n,o);return{rowOffset:a,resultString:s}}decodeEnd(e,t){return Fe.findGuardPatternWithoutCounters(e,t,!0,Fe.MIDDLE_END_PATTERN)}checkChecksum(e){return je.checkChecksum(Fe.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 R.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()}}Fe.MIDDLE_END_PATTERN=Int32Array.from([1,1,1,1,1,1]),Fe.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 Ie extends we{constructor(e){super();let n=e==null?null:e.get(b.POSSIBLE_FORMATS),r=[];t(n)?(r.push(new Me),r.push(new Pe),r.push(new Ne),r.push(new Fe)):(n.indexOf(R.EAN_13)>-1&&r.push(new Me),n.indexOf(R.UPC_A)>-1&&r.push(new Pe),n.indexOf(R.EAN_8)>-1&&r.push(new Ne),n.indexOf(R.UPC_E)>-1&&r.push(new Fe)),this.readers=r}decodeRow(e,t,n){for(let r of this.readers)try{let i=r.decodeRow(e,t,n),a=i.getBarcodeFormat()===R.EAN_13&&i.getText().charAt(0)===`0`,o=n==null?null:n.get(b.POSSIBLE_FORMATS),s=o==null||o.includes(R.UPC_A);if(a&&s){let e=i.getRawBytes(),t=new L(i.getText().substring(1),e,e?e.length:null,i.getResultPoints(),R.UPC_A);return t.putAllMetadata(i.getResultMetadata()),t}return i}catch{}throw new k}reset(){for(let e of this.readers)e.reset()}}class Le extends we{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(we.patternMatchVariance(e,t[n],Le.MAX_INDIVIDUAL_VARIANCE)<Le.MAX_AVG_VARIANCE)return n;throw new k}static count(e){return B.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>=Le.MIN_FINDER_PATTERN_RATIO&&n<=Le.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}}Le.MAX_AVG_VARIANCE=.2,Le.MAX_INDIVIDUAL_VARIANCE=.45,Le.MIN_FINDER_PATTERN_RATIO=9.5/12,Le.MAX_FINDER_PATTERN_RATIO=12.5/14;class Re{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 Re))return!1;let t=e;return this.value===t.value&&this.checksumPortion===t.checksumPortion}hashCode(){return this.value^this.checksumPortion}}class ze{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 ze))return!1;let t=e;return this.value===t.value}hashCode(){return this.value}}class Be{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=Be.combins(r-c-1,o-s-2);if(n&&a===0&&r-c-(o-s-1)>=o-s-1&&(e-=Be.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+=Be.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 Ve{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 He{constructor(e,t){t?this.decodedInformation=null:(this.finished=e,this.decodedInformation=t)}getDecodedInformation(){return this.decodedInformation}isFinished(){return this.finished}}class W{constructor(e){this.newPosition=e}getNewPosition(){return this.newPosition}}class Ue extends W{constructor(e,t){super(e),this.value=t}getValue(){return this.value}isFNC1(){return this.value===Ue.FNC1}}Ue.FNC1=`$`;class We extends W{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 Ge extends W{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===Ge.FNC1}isSecondDigitFNC1(){return this.secondDigit===Ge.FNC1}isAnyFNC1(){return this.firstDigit===Ge.FNC1||this.secondDigit===Ge.FNC1}}Ge.FNC1=10;class Ke{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 Ke.TWO_DIGIT_DATA_LENGTH)if(n[0]===t)return n[1]===Ke.VARIABLE_LENGTH?Ke.processVariableAI(2,n[2],e):Ke.processFixedAI(2,n[1],e);if(e.length<3)throw new k;let n=e.substring(0,3);for(let t of Ke.THREE_DIGIT_DATA_LENGTH)if(t[0]===n)return t[1]===Ke.VARIABLE_LENGTH?Ke.processVariableAI(3,t[2],e):Ke.processFixedAI(3,t[1],e);for(let t of Ke.THREE_DIGIT_PLUS_DIGIT_DATA_LENGTH)if(t[0]===n)return t[1]===Ke.VARIABLE_LENGTH?Ke.processVariableAI(4,t[2],e):Ke.processFixedAI(4,t[1],e);if(e.length<4)throw new k;let r=e.substring(0,4);for(let t of Ke.FOUR_DIGIT_DATA_LENGTH)if(t[0]===r)return t[1]===Ke.VARIABLE_LENGTH?Ke.processVariableAI(4,t[2],e):Ke.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=Ke.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=Ke.parseFieldsInGeneralPurpose(o);return c==null?s:s+c}}Ke.VARIABLE_LENGTH=[],Ke.TWO_DIGIT_DATA_LENGTH=[[`00`,18],[`01`,14],[`02`,14],[`10`,Ke.VARIABLE_LENGTH,20],[`11`,6],[`12`,6],[`13`,6],[`15`,6],[`17`,6],[`20`,2],[`21`,Ke.VARIABLE_LENGTH,20],[`22`,Ke.VARIABLE_LENGTH,29],[`30`,Ke.VARIABLE_LENGTH,8],[`37`,Ke.VARIABLE_LENGTH,8],[`90`,Ke.VARIABLE_LENGTH,30],[`91`,Ke.VARIABLE_LENGTH,30],[`92`,Ke.VARIABLE_LENGTH,30],[`93`,Ke.VARIABLE_LENGTH,30],[`94`,Ke.VARIABLE_LENGTH,30],[`95`,Ke.VARIABLE_LENGTH,30],[`96`,Ke.VARIABLE_LENGTH,30],[`97`,Ke.VARIABLE_LENGTH,3],[`98`,Ke.VARIABLE_LENGTH,30],[`99`,Ke.VARIABLE_LENGTH,30]],Ke.THREE_DIGIT_DATA_LENGTH=[[`240`,Ke.VARIABLE_LENGTH,30],[`241`,Ke.VARIABLE_LENGTH,30],[`242`,Ke.VARIABLE_LENGTH,6],[`250`,Ke.VARIABLE_LENGTH,30],[`251`,Ke.VARIABLE_LENGTH,30],[`253`,Ke.VARIABLE_LENGTH,17],[`254`,Ke.VARIABLE_LENGTH,20],[`400`,Ke.VARIABLE_LENGTH,30],[`401`,Ke.VARIABLE_LENGTH,30],[`402`,17],[`403`,Ke.VARIABLE_LENGTH,30],[`410`,13],[`411`,13],[`412`,13],[`413`,13],[`414`,13],[`420`,Ke.VARIABLE_LENGTH,20],[`421`,Ke.VARIABLE_LENGTH,15],[`422`,3],[`423`,Ke.VARIABLE_LENGTH,15],[`424`,3],[`425`,3],[`426`,3]],Ke.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`,Ke.VARIABLE_LENGTH,15],[`391`,Ke.VARIABLE_LENGTH,18],[`392`,Ke.VARIABLE_LENGTH,15],[`393`,Ke.VARIABLE_LENGTH,18],[`703`,Ke.VARIABLE_LENGTH,30]],Ke.FOUR_DIGIT_DATA_LENGTH=[[`7001`,13],[`7002`,Ke.VARIABLE_LENGTH,30],[`7003`,10],[`8001`,14],[`8002`,Ke.VARIABLE_LENGTH,20],[`8003`,Ke.VARIABLE_LENGTH,30],[`8004`,Ke.VARIABLE_LENGTH,30],[`8005`,6],[`8006`,18],[`8007`,Ke.VARIABLE_LENGTH,30],[`8008`,Ke.VARIABLE_LENGTH,12],[`8018`,18],[`8020`,Ke.VARIABLE_LENGTH,25],[`8100`,6],[`8101`,10],[`8102`,2],[`8110`,Ke.VARIABLE_LENGTH,70],[`8200`,Ke.VARIABLE_LENGTH,70]];class qe{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=Ke.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 Ge(this.information.getSize(),Ge.FNC1,Ge.FNC1):new Ge(this.information.getSize(),t-1,Ge.FNC1)}let t=this.extractNumericValueFromBitArray(e,7),n=(t-8)/11,r=(t-8)%11;return new Ge(e+7,n,r)}extractNumericValueFromBitArray(e,t){return qe.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 We(this.current.getPosition(),this.buffer.toString(),n.getRemainingValue()):new We(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 We(this.current.getPosition(),this.buffer.toString()):new We(this.current.getPosition(),this.buffer.toString(),e.getSecondDigit()),new He(!0,t)}if(this.buffer.append(e.getFirstDigit()),e.isSecondDigitFNC1())return new He(!0,new We(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 He(!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 He(!0,new We(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 He(!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 He(!0,new We(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 He(!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 Ue(e+5,Ue.FNC1);if(t>=5&&t<15)return new Ue(e+5,`0`+(t-5));let n=this.extractNumericValueFromBitArray(e,7);if(n>=64&&n<90)return new Ue(e+7,``+(n+1));if(n>=90&&n<116)return new Ue(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 Ue(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 Ue(e+5,Ue.FNC1);if(t>=5&&t<15)return new Ue(e+5,`0`+(t-5));let n=this.extractNumericValueFromBitArray(e,6);if(n>=32&&n<58)return new Ue(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 le(`Decoding invalid alphanumeric value: `+n)}return new Ue(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 Je{constructor(e){this.information=e,this.generalDecoder=new qe(e)}getInformation(){return this.information}getGeneralDecoder(){return this.generalDecoder}}class Ye extends Je{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)}Ye.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)}}Ye.GTIN_SIZE=40;class Xe extends Ye{constructor(e){super(e)}parseInformation(){let e=new D;e.append(`(01)`);let t=e.length(),n=this.getGeneralDecoder().extractNumericValueFromBitArray(Xe.HEADER_SIZE,4);return e.append(n),this.encodeCompressedGtinWithoutAI(e,Xe.HEADER_SIZE+4,t),this.getGeneralDecoder().decodeAllCodes(e,Xe.HEADER_SIZE+44)}}Xe.HEADER_SIZE=4;class Ze extends Je{constructor(e){super(e)}parseInformation(){let e=new D;return this.getGeneralDecoder().decodeAllCodes(e,Ze.HEADER_SIZE)}}Ze.HEADER_SIZE=5;class Qe extends Ye{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 $e extends Qe{constructor(e){super(e)}parseInformation(){if(this.getInformation().getSize()!=$e.HEADER_SIZE+Qe.GTIN_SIZE+$e.WEIGHT_SIZE)throw new k;let e=new D;return this.encodeCompressedGtin(e,$e.HEADER_SIZE),this.encodeCompressedWeight(e,$e.HEADER_SIZE+Qe.GTIN_SIZE,$e.WEIGHT_SIZE),e.toString()}}$e.HEADER_SIZE=5,$e.WEIGHT_SIZE=15;class et extends $e{constructor(e){super(e)}addWeightCode(e,t){e.append(`(3103)`)}checkWeight(e){return e}}class tt extends $e{constructor(e){super(e)}addWeightCode(e,t){t<1e4?e.append(`(3202)`):e.append(`(3203)`)}checkWeight(e){return e<1e4?e:e-1e4}}class nt extends Ye{constructor(e){super(e)}parseInformation(){if(this.getInformation().getSize()<nt.HEADER_SIZE+Ye.GTIN_SIZE)throw new k;let e=new D;this.encodeCompressedGtin(e,nt.HEADER_SIZE);let t=this.getGeneralDecoder().extractNumericValueFromBitArray(nt.HEADER_SIZE+Ye.GTIN_SIZE,nt.LAST_DIGIT_SIZE);e.append(`(392`),e.append(t),e.append(`)`);let n=this.getGeneralDecoder().decodeGeneralPurposeField(nt.HEADER_SIZE+Ye.GTIN_SIZE+nt.LAST_DIGIT_SIZE,null);return e.append(n.getNewString()),e.toString()}}nt.HEADER_SIZE=8,nt.LAST_DIGIT_SIZE=2;class rt extends Ye{constructor(e){super(e)}parseInformation(){if(this.getInformation().getSize()<rt.HEADER_SIZE+Ye.GTIN_SIZE)throw new k;let e=new D;this.encodeCompressedGtin(e,rt.HEADER_SIZE);let t=this.getGeneralDecoder().extractNumericValueFromBitArray(rt.HEADER_SIZE+Ye.GTIN_SIZE,rt.LAST_DIGIT_SIZE);e.append(`(393`),e.append(t),e.append(`)`);let n=this.getGeneralDecoder().extractNumericValueFromBitArray(rt.HEADER_SIZE+Ye.GTIN_SIZE+rt.LAST_DIGIT_SIZE,rt.FIRST_THREE_DIGITS_SIZE);n/100==0&&e.append(`0`),n/10==0&&e.append(`0`),e.append(n);let r=this.getGeneralDecoder().decodeGeneralPurposeField(rt.HEADER_SIZE+Ye.GTIN_SIZE+rt.LAST_DIGIT_SIZE+rt.FIRST_THREE_DIGITS_SIZE,null);return e.append(r.getNewString()),e.toString()}}rt.HEADER_SIZE=8,rt.LAST_DIGIT_SIZE=2,rt.FIRST_THREE_DIGITS_SIZE=10;class it extends Qe{constructor(e,t,n){super(e),this.dateCode=n,this.firstAIdigits=t}parseInformation(){if(this.getInformation().getSize()!=it.HEADER_SIZE+it.GTIN_SIZE+it.WEIGHT_SIZE+it.DATE_SIZE)throw new k;let e=new D;return this.encodeCompressedGtin(e,it.HEADER_SIZE),this.encodeCompressedWeight(e,it.HEADER_SIZE+it.GTIN_SIZE,it.WEIGHT_SIZE),this.encodeCompressedDate(e,it.HEADER_SIZE+it.GTIN_SIZE+it.WEIGHT_SIZE),e.toString()}encodeCompressedDate(e,t){let n=this.getGeneralDecoder().extractNumericValueFromBitArray(t,it.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}}it.HEADER_SIZE=8,it.WEIGHT_SIZE=20,it.DATE_SIZE=16;function at(e){try{if(e.get(1))return new Xe(e);if(!e.get(2))return new Ze(e);switch(qe.extractNumericValueFromBitArray(e,1,4)){case 4:return new et(e);case 5:return new tt(e)}switch(qe.extractNumericValueFromBitArray(e,1,5)){case 12:return new nt(e);case 13:return new rt(e)}switch(qe.extractNumericValueFromBitArray(e,1,7)){case 56:return new it(e,`310`,`11`);case 57:return new it(e,`320`,`11`);case 58:return new it(e,`310`,`13`);case 59:return new it(e,`320`,`13`);case 60:return new it(e,`310`,`15`);case 61:return new it(e,`320`,`15`);case 62:return new it(e,`310`,`17`);case 63:return new it(e,`320`,`17`)}}catch(t){throw console.log(t),new le(`unknown decoder: `+e)}}class ot{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 ot?ot.equalsOrNull(e.leftchar,t.leftchar)&&ot.equalsOrNull(e.rightchar,t.rightchar)&&ot.equalsOrNull(e.finderpattern,t.finderpattern):!1}static equalsOrNull(e,t){return e===null?t===null:ot.equals(e,t)}hashCode(){return this.leftchar.getValue()^this.rightchar.getValue()^this.finderpattern.getValue()}}class st{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 st?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 G extends Le{constructor(e){super(...arguments),this.pairs=Array(G.MAX_PAIRS),this.rows=[],this.startEnd=[2],this.verbose=e===!0}decodeRow(e,t,n){this.pairs.length=0,this.startFromEven=!1;try{return G.constructResult(this.decodeRow2pairs(e,t))}catch(e){this.verbose&&console.log(e)}return this.pairs.length=0,this.startFromEven=!0,G.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()),!G.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 G.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||G.isPartialRow(this.pairs,this.rows)||(this.rows.push(n,new st(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(ot.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=at(Ve.buildBitArray(e)).parseInformation(),n=e[0].getFinderPattern().getResultPoints(),r=e[e.length-1].getFinderPattern().getResultPoints();return new L(t,null,null,[n[0],n[1],r[0],r[1]],R.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=G.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 ot(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&&G.reverseCounters(r),G.isFinderPattern(r)){this.startEnd[0]=l,this.startEnd[1]=t;return}o&&G.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,G.FINDER_PATTERNS)}catch{return null}return new ze(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)G.recordPatternInReverse(e,t.getStartEnd()[0],i);else{G.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=B.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(G.isNotA1left(t,n,r)){let t=G.WEIGHTS[d][2*e];p+=s[e]*t}f+=s[e]}let m=0;for(let e=c.length-1;e>=0;e--)if(G.isNotA1left(t,n,r)){let t=G.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,_=G.SYMBOL_WIDEST[g],v=9-_,y=Be.getRSSvalue(s,_,!0),b=Be.getRSSvalue(c,v,!1),x=G.EVEN_TOTAL_SUBSET[g],S=G.GSUM[g];return new Re(y*x+b+S,h)}static isNotA1left(e,t,n){return!(e.getValue()==0&&t&&n)}adjustOddEvenCounts(e){let t=B.sum(new Int32Array(this.getOddCounts())),n=B.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;G.increment(this.getOddCounts(),this.getOddRoundingErrors())}if(i&&G.decrement(this.getOddCounts(),this.getOddRoundingErrors()),a){if(o)throw new k;G.increment(this.getEvenCounts(),this.getOddRoundingErrors())}o&&G.decrement(this.getEvenCounts(),this.getEvenRoundingErrors())}}G.SYMBOL_WIDEST=[7,5,4,3,1],G.EVEN_TOTAL_SUBSET=[4,20,52,104,204],G.GSUM=[0,348,1388,2948,3988],G.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])],G.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]],G.FINDER_PAT_A=0,G.FINDER_PAT_B=1,G.FINDER_PAT_C=2,G.FINDER_PAT_D=3,G.FINDER_PAT_E=4,G.FINDER_PAT_F=5,G.FINDER_PATTERN_SEQUENCES=[[G.FINDER_PAT_A,G.FINDER_PAT_A],[G.FINDER_PAT_A,G.FINDER_PAT_B,G.FINDER_PAT_B],[G.FINDER_PAT_A,G.FINDER_PAT_C,G.FINDER_PAT_B,G.FINDER_PAT_D],[G.FINDER_PAT_A,G.FINDER_PAT_E,G.FINDER_PAT_B,G.FINDER_PAT_D,G.FINDER_PAT_C],[G.FINDER_PAT_A,G.FINDER_PAT_E,G.FINDER_PAT_B,G.FINDER_PAT_D,G.FINDER_PAT_D,G.FINDER_PAT_F],[G.FINDER_PAT_A,G.FINDER_PAT_E,G.FINDER_PAT_B,G.FINDER_PAT_D,G.FINDER_PAT_E,G.FINDER_PAT_F,G.FINDER_PAT_F],[G.FINDER_PAT_A,G.FINDER_PAT_A,G.FINDER_PAT_B,G.FINDER_PAT_B,G.FINDER_PAT_C,G.FINDER_PAT_C,G.FINDER_PAT_D,G.FINDER_PAT_D],[G.FINDER_PAT_A,G.FINDER_PAT_A,G.FINDER_PAT_B,G.FINDER_PAT_B,G.FINDER_PAT_C,G.FINDER_PAT_C,G.FINDER_PAT_D,G.FINDER_PAT_E,G.FINDER_PAT_E],[G.FINDER_PAT_A,G.FINDER_PAT_A,G.FINDER_PAT_B,G.FINDER_PAT_B,G.FINDER_PAT_C,G.FINDER_PAT_C,G.FINDER_PAT_D,G.FINDER_PAT_E,G.FINDER_PAT_F,G.FINDER_PAT_F],[G.FINDER_PAT_A,G.FINDER_PAT_A,G.FINDER_PAT_B,G.FINDER_PAT_B,G.FINDER_PAT_C,G.FINDER_PAT_D,G.FINDER_PAT_D,G.FINDER_PAT_E,G.FINDER_PAT_E,G.FINDER_PAT_F,G.FINDER_PAT_F]],G.MAX_PAIRS=11;class ct extends Re{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 lt extends Le{constructor(){super(...arguments),this.possibleLeftPairs=[],this.possibleRightPairs=[]}decodeRow(e,t,n){let r=this.decodePair(t,!1,e,n);lt.addOrTally(this.possibleLeftPairs,r),t.reverse();let i=this.decodePair(t,!0,e,n);lt.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&<.checkChecksum(e,t))return lt.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 L(i.toString(),null,0,[o[0],o[1],s[0],s[1]],R.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 ct(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)we.recordPatternInReverse(e,t.getStartEnd()[0],r);else{we.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=B.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=lt.OUTSIDE_ODD_WIDEST[e],n=9-t,r=Be.getRSSvalue(o,t,!1),i=Be.getRSSvalue(s,n,!0),a=lt.OUTSIDE_EVEN_TOTAL_SUBSET[e],c=lt.OUTSIDE_GSUM[e];return new Re(r*a+i+c,m)}else{if(p&1||p>10||p<4)throw new k;let e=(10-p)/2,t=lt.INSIDE_ODD_WIDEST[e],n=9-t,r=Be.getRSSvalue(o,t,!0),i=Be.getRSSvalue(s,n,!1),a=lt.INSIDE_ODD_TOTAL_SUBSET[e],c=lt.INSIDE_GSUM[e];return new Re(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(Le.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,lt.FINDER_PATTERNS),u=a,d=r[1];return n&&(u=e.getSize()-1-u,d=e.getSize()-1-d),new ze(l,[a,r[1]],u,d,t)}adjustOddEvenCounts(e,t){let n=B.sum(new Int32Array(this.getOddCounts())),r=B.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;Le.increment(this.getOddCounts(),this.getOddRoundingErrors())}if(a&&Le.decrement(this.getOddCounts(),this.getOddRoundingErrors()),o){if(s)throw new k;Le.increment(this.getEvenCounts(),this.getOddRoundingErrors())}s&&Le.decrement(this.getEvenCounts(),this.getEvenRoundingErrors())}}lt.OUTSIDE_EVEN_TOTAL_SUBSET=[1,10,34,70,126],lt.INSIDE_ODD_TOTAL_SUBSET=[4,20,48,81],lt.OUTSIDE_GSUM=[0,161,961,2015,2715],lt.INSIDE_GSUM=[0,336,1036,1516],lt.OUTSIDE_ODD_WIDEST=[8,6,4,3,1],lt.INSIDE_ODD_WIDEST=[2,4,6,8],lt.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 ut extends we{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(R.EAN_13)||n.includes(R.UPC_A)||n.includes(R.EAN_8)||n.includes(R.UPC_E))&&this.readers.push(new Ie(e)),n.includes(R.CODE_39)&&this.readers.push(new Te(r)),n.includes(R.CODE_128)&&this.readers.push(new U),n.includes(R.ITF)&&this.readers.push(new Ee),n.includes(R.RSS_14)&&this.readers.push(new lt),n.includes(R.RSS_EXPANDED)&&this.readers.push(new G(this.verbose))):(this.readers.push(new Ie(e)),this.readers.push(new Te),this.readers.push(new Ie(e)),this.readers.push(new U),this.readers.push(new Ee),this.readers.push(new lt),this.readers.push(new G(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 dt extends ee{constructor(e=500,t){super(new ut(t),e,t)}}class ft{constructor(e,t,n){this.ecCodewords=e,this.ecBlocks=[t],n&&this.ecBlocks.push(n)}getECCodewords(){return this.ecCodewords}getECBlocks(){return this.ecBlocks}}class pt{constructor(e,t){this.count=e,this.dataCodewords=t}getCount(){return this.count}getDataCodewords(){return this.dataCodewords}}class mt{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 mt.VERSIONS)if(n.symbolSizeRows===e&&n.symbolSizeColumns===t)return n;throw new x}toString(){return``+this.versionNumber}static buildVersions(){return[new mt(1,10,10,8,8,new ft(5,new pt(1,3))),new mt(2,12,12,10,10,new ft(7,new pt(1,5))),new mt(3,14,14,12,12,new ft(10,new pt(1,8))),new mt(4,16,16,14,14,new ft(12,new pt(1,12))),new mt(5,18,18,16,16,new ft(14,new pt(1,18))),new mt(6,20,20,18,18,new ft(18,new pt(1,22))),new mt(7,22,22,20,20,new ft(20,new pt(1,30))),new mt(8,24,24,22,22,new ft(24,new pt(1,36))),new mt(9,26,26,24,24,new ft(28,new pt(1,44))),new mt(10,32,32,14,14,new ft(36,new pt(1,62))),new mt(11,36,36,16,16,new ft(42,new pt(1,86))),new mt(12,40,40,18,18,new ft(48,new pt(1,114))),new mt(13,44,44,20,20,new ft(56,new pt(1,144))),new mt(14,48,48,22,22,new ft(68,new pt(1,174))),new mt(15,52,52,24,24,new ft(42,new pt(2,102))),new mt(16,64,64,14,14,new ft(56,new pt(2,140))),new mt(17,72,72,16,16,new ft(36,new pt(4,92))),new mt(18,80,80,18,18,new ft(48,new pt(4,114))),new mt(19,88,88,20,20,new ft(56,new pt(4,144))),new mt(20,96,96,22,22,new ft(68,new pt(4,174))),new mt(21,104,104,24,24,new ft(56,new pt(6,136))),new mt(22,120,120,18,18,new ft(68,new pt(6,175))),new mt(23,132,132,20,20,new ft(62,new pt(8,163))),new mt(24,144,144,22,22,new ft(62,new pt(8,156),new pt(2,155))),new mt(25,8,18,6,16,new ft(7,new pt(1,5))),new mt(26,8,32,6,14,new ft(11,new pt(1,10))),new mt(27,12,26,10,24,new ft(14,new pt(1,16))),new mt(28,12,36,10,16,new ft(18,new pt(1,22))),new mt(29,16,36,14,16,new ft(24,new pt(1,32))),new mt(30,16,48,14,22,new ft(28,new pt(1,49)))]}}mt.VERSIONS=mt.buildVersions();class ht{constructor(e){let t=e.getHeight();if(t<8||t>144||t&1)throw new x;this.version=ht.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 mt.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 gt{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 gt(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 _t{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 vt;(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`})(vt||={});class yt{static decode(e){let t=new _t(e),n=new D,r=new D,i=[],a=vt.ASCII_ENCODE;do if(a===vt.ASCII_ENCODE)a=this.decodeAsciiSegment(t,n,r);else{switch(a){case vt.C40_ENCODE:this.decodeC40Segment(t,n);break;case vt.TEXT_ENCODE:this.decodeTextSegment(t,n);break;case vt.ANSIX12_ENCODE:this.decodeAnsiX12Segment(t,n);break;case vt.EDIFACT_ENCODE:this.decodeEdifactSegment(t,n);break;case vt.BASE256_ENCODE:this.decodeBase256Segment(t,n,i);break;default:throw new x}a=vt.ASCII_ENCODE}while(a!==vt.PAD_ENCODE&&t.available()>0);return r.length()>0&&n.append(r.toString()),new ie(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)),vt.ASCII_ENCODE;if(i===129)return vt.PAD_ENCODE;if(i<=229){let e=i-130;e<10&&t.append(`0`),t.append(``+e)}else switch(i){case 230:return vt.C40_ENCODE;case 231:return vt.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 vt.ANSIX12_ENCODE;case 239:return vt.TEXT_ENCODE;case 240:return vt.EDIFACT_ENCODE;case 241:break;default:if(i!==254||e.available()!==0)throw new x;break}}while(e.available()>0);return vt.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 le(`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}}yt.C40_BASIC_SET_CHARS=`*** 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ`.split(``),yt.C40_SHIFT2_SET_CHARS=`!"#$%&'()*+,-./:;<=>?@[\\]^_`.split(``),yt.TEXT_BASIC_SET_CHARS=`*** 0123456789abcdefghijklmnopqrstuvwxyz`.split(``),yt.TEXT_SHIFT2_SET_CHARS=yt.C40_SHIFT2_SET_CHARS,yt.TEXT_SHIFT3_SET_CHARS="`ABCDEFGHIJKLMNOPQRSTUVWXYZ{|}~".split(``);class bt{constructor(){this.rsDecoder=new ue(ce.DATA_MATRIX_FIELD_256)}decode(e){let t=new ht(e),n=t.getVersion(),r=t.readCodewords(),i=gt.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 yt.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 xt{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(xt.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=xt.shiftPoint(n,r,(a+1)*4),s=xt.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=xt.shiftPoint(t,n,(o+1)*4),c=xt.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=xt.shiftPoint(t,n,o*4),c=xt.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=xt.moveAway(t,l,u),n=xt.moveAway(n,l,u),r=xt.moveAway(r,l,u),i=xt.moveAway(i,l,u);let d,f;return s=xt.shiftPoint(t,n,o*4),s=xt.shiftPoint(s,i,a*4),d=xt.shiftPoint(n,t,o*4),d=xt.shiftPoint(d,r,a*4),c=xt.shiftPoint(r,i,o*4),c=xt.shiftPoint(c,n,a*4),f=xt.shiftPoint(i,r,o*4),f=xt.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 ye.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 St{constructor(){this.decoder=new bt}decode(e,t=null){let n,r;if(t!=null&&t.has(b.PURE_BARCODE)){let t=St.extractPureBits(e.getBlackMatrix());n=this.decoder.decode(t),r=St.NO_POINTS}else{let t=new xt(e.getBlackMatrix()).detect();n=this.decoder.decode(t.getBits()),r=t.getPoints()}let i=n.getRawBytes(),a=new L(n.getText(),i,8*i.length,r,R.DATA_MATRIX,p.currentTimeMillis()),o=n.getByteSegments();o!=null&&a.putMetadata(re.BYTE_SEGMENTS,o);let s=n.getECLevel();return s!=null&&a.putMetadata(re.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}}St.NO_POINTS=[];class Ct extends ee{constructor(e=500){super(new St,e)}}var wt;(function(e){e[e.L=0]=`L`,e[e.M=1]=`M`,e[e.Q=2]=`Q`,e[e.H=3]=`H`})(wt||={});class Tt{constructor(e,t,n){this.value=e,this.stringValue=t,this.bits=n,Tt.FOR_BITS.set(n,this),Tt.FOR_VALUE.set(e,this)}getValue(){return this.value}getBits(){return this.bits}static fromString(e){switch(e){case`L`:return Tt.L;case`M`:return Tt.M;case`Q`:return Tt.Q;case`H`:return Tt.H;default:throw new c(e+`not available`)}}toString(){return this.stringValue}equals(e){if(!(e instanceof Tt))return!1;let t=e;return this.value===t.value}static forBits(e){if(e<0||e>=Tt.FOR_BITS.size)throw new l;return Tt.FOR_BITS.get(e)}}Tt.FOR_BITS=new Map,Tt.FOR_VALUE=new Map,Tt.L=new Tt(wt.L,`L`,1),Tt.M=new Tt(wt.M,`M`,0),Tt.Q=new Tt(wt.Q,`Q`,3),Tt.H=new Tt(wt.H,`H`,2);class Et{constructor(e){this.errorCorrectionLevel=Tt.forBits(e>>3&3),this.dataMask=e&7}static numBitsDiffering(e,t){return _.bitCount(e^t)}static decodeFormatInformation(e,t){let n=Et.doDecodeFormatInformation(e,t);return n===null?Et.doDecodeFormatInformation(e^Et.FORMAT_INFO_MASK_QR,t^Et.FORMAT_INFO_MASK_QR):n}static doDecodeFormatInformation(e,t){let n=2**53-1,r=0;for(let i of Et.FORMAT_INFO_DECODE_LOOKUP){let a=i[0];if(a===e||a===t)return new Et(i[1]);let o=Et.numBitsDiffering(e,a);o<n&&(r=i[1],n=o),e!==t&&(o=Et.numBitsDiffering(t,a),o<n&&(r=i[1],n=o))}return n<=3?new Et(r):null}getErrorCorrectionLevel(){return this.errorCorrectionLevel}getDataMask(){return this.dataMask}hashCode(){return this.errorCorrectionLevel.getBits()<<3|this.dataMask}equals(e){if(!(e instanceof Et))return!1;let t=e;return this.errorCorrectionLevel===t.errorCorrectionLevel&&this.dataMask===t.dataMask}}Et.FORMAT_INFO_MASK_QR=21522,Et.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 K{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 q{constructor(e,t){this.count=e,this.dataCodewords=t}getCount(){return this.count}getDataCodewords(){return this.dataCodewords}}class Dt{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 Dt.VERSIONS[e-1]}static decodeVersionInformation(e){let t=2**53-1,n=0;for(let r=0;r<Dt.VERSION_DECODE_INFO.length;r++){let i=Dt.VERSION_DECODE_INFO[r];if(i===e)return Dt.getVersionForNumber(r+7);let a=Et.numBitsDiffering(e,i);a<t&&(n=r+7,t=a)}return t<=3?Dt.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}}Dt.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]),Dt.VERSIONS=[new Dt(1,new Int32Array,new K(7,new q(1,19)),new K(10,new q(1,16)),new K(13,new q(1,13)),new K(17,new q(1,9))),new Dt(2,Int32Array.from([6,18]),new K(10,new q(1,34)),new K(16,new q(1,28)),new K(22,new q(1,22)),new K(28,new q(1,16))),new Dt(3,Int32Array.from([6,22]),new K(15,new q(1,55)),new K(26,new q(1,44)),new K(18,new q(2,17)),new K(22,new q(2,13))),new Dt(4,Int32Array.from([6,26]),new K(20,new q(1,80)),new K(18,new q(2,32)),new K(26,new q(2,24)),new K(16,new q(4,9))),new Dt(5,Int32Array.from([6,30]),new K(26,new q(1,108)),new K(24,new q(2,43)),new K(18,new q(2,15),new q(2,16)),new K(22,new q(2,11),new q(2,12))),new Dt(6,Int32Array.from([6,34]),new K(18,new q(2,68)),new K(16,new q(4,27)),new K(24,new q(4,19)),new K(28,new q(4,15))),new Dt(7,Int32Array.from([6,22,38]),new K(20,new q(2,78)),new K(18,new q(4,31)),new K(18,new q(2,14),new q(4,15)),new K(26,new q(4,13),new q(1,14))),new Dt(8,Int32Array.from([6,24,42]),new K(24,new q(2,97)),new K(22,new q(2,38),new q(2,39)),new K(22,new q(4,18),new q(2,19)),new K(26,new q(4,14),new q(2,15))),new Dt(9,Int32Array.from([6,26,46]),new K(30,new q(2,116)),new K(22,new q(3,36),new q(2,37)),new K(20,new q(4,16),new q(4,17)),new K(24,new q(4,12),new q(4,13))),new Dt(10,Int32Array.from([6,28,50]),new K(18,new q(2,68),new q(2,69)),new K(26,new q(4,43),new q(1,44)),new K(24,new q(6,19),new q(2,20)),new K(28,new q(6,15),new q(2,16))),new Dt(11,Int32Array.from([6,30,54]),new K(20,new q(4,81)),new K(30,new q(1,50),new q(4,51)),new K(28,new q(4,22),new q(4,23)),new K(24,new q(3,12),new q(8,13))),new Dt(12,Int32Array.from([6,32,58]),new K(24,new q(2,92),new q(2,93)),new K(22,new q(6,36),new q(2,37)),new K(26,new q(4,20),new q(6,21)),new K(28,new q(7,14),new q(4,15))),new Dt(13,Int32Array.from([6,34,62]),new K(26,new q(4,107)),new K(22,new q(8,37),new q(1,38)),new K(24,new q(8,20),new q(4,21)),new K(22,new q(12,11),new q(4,12))),new Dt(14,Int32Array.from([6,26,46,66]),new K(30,new q(3,115),new q(1,116)),new K(24,new q(4,40),new q(5,41)),new K(20,new q(11,16),new q(5,17)),new K(24,new q(11,12),new q(5,13))),new Dt(15,Int32Array.from([6,26,48,70]),new K(22,new q(5,87),new q(1,88)),new K(24,new q(5,41),new q(5,42)),new K(30,new q(5,24),new q(7,25)),new K(24,new q(11,12),new q(7,13))),new Dt(16,Int32Array.from([6,26,50,74]),new K(24,new q(5,98),new q(1,99)),new K(28,new q(7,45),new q(3,46)),new K(24,new q(15,19),new q(2,20)),new K(30,new q(3,15),new q(13,16))),new Dt(17,Int32Array.from([6,30,54,78]),new K(28,new q(1,107),new q(5,108)),new K(28,new q(10,46),new q(1,47)),new K(28,new q(1,22),new q(15,23)),new K(28,new q(2,14),new q(17,15))),new Dt(18,Int32Array.from([6,30,56,82]),new K(30,new q(5,120),new q(1,121)),new K(26,new q(9,43),new q(4,44)),new K(28,new q(17,22),new q(1,23)),new K(28,new q(2,14),new q(19,15))),new Dt(19,Int32Array.from([6,30,58,86]),new K(28,new q(3,113),new q(4,114)),new K(26,new q(3,44),new q(11,45)),new K(26,new q(17,21),new q(4,22)),new K(26,new q(9,13),new q(16,14))),new Dt(20,Int32Array.from([6,34,62,90]),new K(28,new q(3,107),new q(5,108)),new K(26,new q(3,41),new q(13,42)),new K(30,new q(15,24),new q(5,25)),new K(28,new q(15,15),new q(10,16))),new Dt(21,Int32Array.from([6,28,50,72,94]),new K(28,new q(4,116),new q(4,117)),new K(26,new q(17,42)),new K(28,new q(17,22),new q(6,23)),new K(30,new q(19,16),new q(6,17))),new Dt(22,Int32Array.from([6,26,50,74,98]),new K(28,new q(2,111),new q(7,112)),new K(28,new q(17,46)),new K(30,new q(7,24),new q(16,25)),new K(24,new q(34,13))),new Dt(23,Int32Array.from([6,30,54,78,102]),new K(30,new q(4,121),new q(5,122)),new K(28,new q(4,47),new q(14,48)),new K(30,new q(11,24),new q(14,25)),new K(30,new q(16,15),new q(14,16))),new Dt(24,Int32Array.from([6,28,54,80,106]),new K(30,new q(6,117),new q(4,118)),new K(28,new q(6,45),new q(14,46)),new K(30,new q(11,24),new q(16,25)),new K(30,new q(30,16),new q(2,17))),new Dt(25,Int32Array.from([6,32,58,84,110]),new K(26,new q(8,106),new q(4,107)),new K(28,new q(8,47),new q(13,48)),new K(30,new q(7,24),new q(22,25)),new K(30,new q(22,15),new q(13,16))),new Dt(26,Int32Array.from([6,30,58,86,114]),new K(28,new q(10,114),new q(2,115)),new K(28,new q(19,46),new q(4,47)),new K(28,new q(28,22),new q(6,23)),new K(30,new q(33,16),new q(4,17))),new Dt(27,Int32Array.from([6,34,62,90,118]),new K(30,new q(8,122),new q(4,123)),new K(28,new q(22,45),new q(3,46)),new K(30,new q(8,23),new q(26,24)),new K(30,new q(12,15),new q(28,16))),new Dt(28,Int32Array.from([6,26,50,74,98,122]),new K(30,new q(3,117),new q(10,118)),new K(28,new q(3,45),new q(23,46)),new K(30,new q(4,24),new q(31,25)),new K(30,new q(11,15),new q(31,16))),new Dt(29,Int32Array.from([6,30,54,78,102,126]),new K(30,new q(7,116),new q(7,117)),new K(28,new q(21,45),new q(7,46)),new K(30,new q(1,23),new q(37,24)),new K(30,new q(19,15),new q(26,16))),new Dt(30,Int32Array.from([6,26,52,78,104,130]),new K(30,new q(5,115),new q(10,116)),new K(28,new q(19,47),new q(10,48)),new K(30,new q(15,24),new q(25,25)),new K(30,new q(23,15),new q(25,16))),new Dt(31,Int32Array.from([6,30,56,82,108,134]),new K(30,new q(13,115),new q(3,116)),new K(28,new q(2,46),new q(29,47)),new K(30,new q(42,24),new q(1,25)),new K(30,new q(23,15),new q(28,16))),new Dt(32,Int32Array.from([6,34,60,86,112,138]),new K(30,new q(17,115)),new K(28,new q(10,46),new q(23,47)),new K(30,new q(10,24),new q(35,25)),new K(30,new q(19,15),new q(35,16))),new Dt(33,Int32Array.from([6,30,58,86,114,142]),new K(30,new q(17,115),new q(1,116)),new K(28,new q(14,46),new q(21,47)),new K(30,new q(29,24),new q(19,25)),new K(30,new q(11,15),new q(46,16))),new Dt(34,Int32Array.from([6,34,62,90,118,146]),new K(30,new q(13,115),new q(6,116)),new K(28,new q(14,46),new q(23,47)),new K(30,new q(44,24),new q(7,25)),new K(30,new q(59,16),new q(1,17))),new Dt(35,Int32Array.from([6,30,54,78,102,126,150]),new K(30,new q(12,121),new q(7,122)),new K(28,new q(12,47),new q(26,48)),new K(30,new q(39,24),new q(14,25)),new K(30,new q(22,15),new q(41,16))),new Dt(36,Int32Array.from([6,24,50,76,102,128,154]),new K(30,new q(6,121),new q(14,122)),new K(28,new q(6,47),new q(34,48)),new K(30,new q(46,24),new q(10,25)),new K(30,new q(2,15),new q(64,16))),new Dt(37,Int32Array.from([6,28,54,80,106,132,158]),new K(30,new q(17,122),new q(4,123)),new K(28,new q(29,46),new q(14,47)),new K(30,new q(49,24),new q(10,25)),new K(30,new q(24,15),new q(46,16))),new Dt(38,Int32Array.from([6,32,58,84,110,136,162]),new K(30,new q(4,122),new q(18,123)),new K(28,new q(13,46),new q(32,47)),new K(30,new q(48,24),new q(14,25)),new K(30,new q(42,15),new q(32,16))),new Dt(39,Int32Array.from([6,26,54,82,110,138,166]),new K(30,new q(20,117),new q(4,118)),new K(28,new q(40,47),new q(7,48)),new K(30,new q(43,24),new q(22,25)),new K(30,new q(10,15),new q(67,16))),new Dt(40,Int32Array.from([6,30,58,86,114,142,170]),new K(30,new q(19,118),new q(6,119)),new K(28,new q(18,47),new q(31,48)),new K(30,new q(34,24),new q(34,25)),new K(30,new q(20,15),new q(61,16)))];var Ot;(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`})(Ot||={});class kt{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)}}kt.values=new Map([[Ot.DATA_MASK_000,new kt(Ot.DATA_MASK_000,(e,t)=>(e+t&1)==0)],[Ot.DATA_MASK_001,new kt(Ot.DATA_MASK_001,(e,t)=>(e&1)==0)],[Ot.DATA_MASK_010,new kt(Ot.DATA_MASK_010,(e,t)=>t%3==0)],[Ot.DATA_MASK_011,new kt(Ot.DATA_MASK_011,(e,t)=>(e+t)%3==0)],[Ot.DATA_MASK_100,new kt(Ot.DATA_MASK_100,(e,t)=>(Math.floor(e/2)+Math.floor(t/3)&1)==0)],[Ot.DATA_MASK_101,new kt(Ot.DATA_MASK_101,(e,t)=>e*t%6==0)],[Ot.DATA_MASK_110,new kt(Ot.DATA_MASK_110,(e,t)=>e*t%6<3)],[Ot.DATA_MASK_111,new kt(Ot.DATA_MASK_111,(e,t)=>(e+t+e*t%3&1)==0)]]);class At{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=Et.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 Dt.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=Dt.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=Dt.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=kt.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=kt.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 jt{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 jt(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 Mt;(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`})(Mt||={});class Nt{constructor(e,t,n,r){this.value=e,this.stringValue=t,this.characterCountBitsForVersions=n,this.bits=r,Nt.FOR_BITS.set(r,this),Nt.FOR_VALUE.set(e,this)}static forBits(e){let t=Nt.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 Nt))return!1;let t=e;return this.value===t.value}toString(){return this.stringValue}}Nt.FOR_BITS=new Map,Nt.FOR_VALUE=new Map,Nt.TERMINATOR=new Nt(Mt.TERMINATOR,`TERMINATOR`,Int32Array.from([0,0,0]),0),Nt.NUMERIC=new Nt(Mt.NUMERIC,`NUMERIC`,Int32Array.from([10,12,14]),1),Nt.ALPHANUMERIC=new Nt(Mt.ALPHANUMERIC,`ALPHANUMERIC`,Int32Array.from([9,11,13]),2),Nt.STRUCTURED_APPEND=new Nt(Mt.STRUCTURED_APPEND,`STRUCTURED_APPEND`,Int32Array.from([0,0,0]),3),Nt.BYTE=new Nt(Mt.BYTE,`BYTE`,Int32Array.from([8,16,16]),4),Nt.ECI=new Nt(Mt.ECI,`ECI`,Int32Array.from([0,0,0]),7),Nt.KANJI=new Nt(Mt.KANJI,`KANJI`,Int32Array.from([8,10,12]),8),Nt.FNC1_FIRST_POSITION=new Nt(Mt.FNC1_FIRST_POSITION,`FNC1_FIRST_POSITION`,Int32Array.from([0,0,0]),5),Nt.FNC1_SECOND_POSITION=new Nt(Mt.FNC1_SECOND_POSITION,`FNC1_SECOND_POSITION`,Int32Array.from([0,0,0]),9),Nt.HANZI=new Nt(Mt.HANZI,`HANZI`,Int32Array.from([8,10,12]),13);class Pt{static decode(e,t,n,r){let i=new _t(e),a=new D,o=[],s=-1,c=-1;try{let e=null,n=!1,l;do{if(i.available()<4)l=Nt.TERMINATOR;else{let e=i.readBits(4);l=Nt.forBits(e)}switch(l){case Nt.TERMINATOR:break;case Nt.FNC1_FIRST_POSITION:case Nt.FNC1_SECOND_POSITION:n=!0;break;case Nt.STRUCTURED_APPEND:if(i.available()<16)throw new x;s=i.readBits(8),c=i.readBits(8);break;case Nt.ECI:let u=Pt.parseECIValue(i);if(e=C.getCharacterSetECIByValue(u),e===null)throw new x;break;case Nt.HANZI:let d=i.readBits(4),f=i.readBits(l.getCharacterCountBits(t));d===Pt.GB2312_SUBSET&&Pt.decodeHanziSegment(i,a,f);break;default:let p=i.readBits(l.getCharacterCountBits(t));switch(l){case Nt.NUMERIC:Pt.decodeNumericSegment(i,a,p);break;case Nt.ALPHANUMERIC:Pt.decodeAlphanumericSegment(i,a,p,n);break;case Nt.BYTE:Pt.decodeByteSegment(i,a,p,e,o,r);break;case Nt.KANJI:Pt.decodeKanjiSegment(i,a,p);break;default:throw new x}break}}while(l!==Nt.TERMINATOR)}catch{throw new x}return new ie(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>=Pt.ALPHANUMERIC_CHARS.length)throw new x;return Pt.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(Pt.toAlphaNumericChar(Math.floor(r/45))),t.append(Pt.toAlphaNumericChar(r%45)),n-=2}if(n===1){if(e.available()<6)throw new x;t.append(Pt.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(Pt.toAlphaNumericChar(Math.floor(r/100))),t.append(Pt.toAlphaNumericChar(Math.floor(r/10)%10)),t.append(Pt.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(Pt.toAlphaNumericChar(Math.floor(n/10))),t.append(Pt.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(Pt.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}}Pt.ALPHANUMERIC_CHARS=`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:`,Pt.GB2312_SUBSET=1;class Ft{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 It{constructor(){this.rsDecoder=new ue(ce.QR_CODE_FIELD_256)}decodeBooleanArray(e,t){return this.decodeBitMatrix(O.parseFromBooleanArray(e),t)}decodeBitMatrix(e,t){let n=new At(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 Ft(!0)),e}catch(e){throw r===null?e:r}}decodeBitMatrixParser(e,t){let n=e.readVersion(),r=e.readFormatInformation().getErrorCorrectionLevel(),i=e.readCodewords(),a=jt.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 Pt.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 Lt 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 Lt((this.getX()+t)/2,(this.getY()+e)/2,(this.estimatedModuleSize+n)/2)}}class Rt{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)?Rt.centerFromEnd(o,s):NaN}handlePossibleCenter(e,t,n){let r=e[0]+e[1]+e[2],i=Rt.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 Lt(i,a,t);this.possibleCenters.push(n),this.resultPointCallback!==null&&this.resultPointCallback!==void 0&&this.resultPointCallback.foundPossibleResultPoint(n)}return null}}class zt 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 zt((this.count*this.getX()+t)/r,(this.count*this.getY()+e)/r,(this.count*this.estimatedModuleSize+n)/r,r)}}class Bt{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 Vt{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*Vt.MAX_MODULES));(o<Vt.MIN_SKIP||t)&&(o=Vt.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(Vt.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]++;Vt.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 Bt(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&&Vt.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:Vt.foundPatternCross(o)?Vt.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:Vt.foundPatternCross(o)?Vt.centerFromEnd(o,s):NaN}handlePossibleCenter(e,t,n,r){let i=e[0]+e[1]+e[2]+e[3]+e[4],a=Vt.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 zt(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()>=Vt.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()>=Vt.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]]}}Vt.CENTER_QUORUM=2,Vt.MIN_SKIP=3,Vt.MAX_MODULES=57;class Ht{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 Vt(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=Ht.computeDimension(t,n,r,i),o=Dt.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=Ht.createTransform(t,n,r,c,a),u=Ht.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),H.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 ye.getInstance().sampleGridWithTransform(e,n,n,t)}static computeDimension(e,t,n,r){let i=B.round(V.distance(e,t)/r),a=B.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 B.distance(n,f,e,t);u++}if(s+=o,s>0){if(f===r)break;f+=l,s-=a}}return u===2?B.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 Rt(this.image,a,s,o-a,c-s,e,this.resultPointCallback).find()}}class Ut{constructor(){this.decoder=new It}getDecoder(){return this.decoder}decode(e,t){let n,r;if(t!=null&&t.get(b.PURE_BARCODE)!==void 0){let i=Ut.extractPureBits(e.getBlackMatrix());n=this.decoder.decodeBitMatrix(i,t),r=Ut.NO_POINTS}else{let i=new Ht(e.getBlackMatrix()).detect(t);n=this.decoder.decodeBitMatrix(i.getBits(),t),r=i.getPoints()}n.getOther()instanceof Ft&&n.getOther().applyMirroredCorrection(r);let i=new L(n.getText(),n.getRawBytes(),void 0,r,R.QR_CODE,void 0),a=n.getByteSegments();a!==null&&i.putMetadata(re.BYTE_SEGMENTS,a);let o=n.getECLevel();return o!==null&&i.putMetadata(re.ERROR_CORRECTION_LEVEL,o),n.hasStructuredAppend()&&(i.putMetadata(re.STRUCTURED_APPEND_SEQUENCE,n.getStructuredAppendSequenceNumber()),i.putMetadata(re.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}}Ut.NO_POINTS=[];class Wt{PDF417Common(){}static getBitCountSum(e){return B.sum(e)}static toIntArray(e){if(e==null||!e.length)return Wt.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(Wt.SYMBOL_TABLE,e&262143);return t<0?-1:(Wt.CODEWORD_TABLE[t]-1)%Wt.NUMBER_OF_CODEWORDS}}Wt.NUMBER_OF_CODEWORDS=929,Wt.MAX_CODEWORDS_IN_BARCODE=Wt.NUMBER_OF_CODEWORDS-1,Wt.MIN_ROWS_IN_BARCODE=3,Wt.MAX_ROWS_IN_BARCODE=90,Wt.MODULES_IN_CODEWORD=17,Wt.MODULES_IN_STOP_PATTERN=18,Wt.BARS_IN_MODULE=8,Wt.EMPTY_INT_ARRAY=new Int32Array([]),Wt.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]),Wt.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 Gt{constructor(e,t){this.bits=e,this.points=t}getBits(){return this.bits}getPoints(){return this.points}}class Kt{static detectMultiple(e,t,n){let r=e.getBlackMatrix(),i=Kt.detect(n,r);return i.length||(r=r.clone(),r.rotate180(),i=Kt.detect(n,r)),new Gt(r,i)}static detect(e,t){let n=[],r=0,i=0,a=!1;for(;r<t.getHeight();){let o=Kt.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+=Kt.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 Kt.copyToResult(a,Kt.findRowsWithPattern(e,r,i,t,n,Kt.START_PATTERN),Kt.INDEXES_START_PATTERN),a[4]!=null&&(n=Math.trunc(a[4].getX()),t=Math.trunc(a[4].getY())),Kt.copyToResult(a,Kt.findRowsWithPattern(e,r,i,t,n,Kt.STOP_PATTERN),Kt.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+=Kt.ROW_STEP){let t=Kt.findGuardPattern(e,i,r,n,!1,a,c);if(t!=null){for(;r>0;){let o=Kt.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=Kt.findGuardPattern(e,i[0],l,n,!1,a,c);if(t!=null&&Math.abs(i[0]-t[0])<Kt.MAX_PATTERN_DRIFT&&Math.abs(i[1]-t[1])<Kt.MAX_PATTERN_DRIFT)i=t,r=0;else if(r>Kt.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<Kt.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++<Kt.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(Kt.patternMatchVariance(o,a,Kt.MAX_INDIVIDUAL_VARIANCE)<Kt.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&&Kt.patternMatchVariance(o,a,Kt.MAX_INDIVIDUAL_VARIANCE)<Kt.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}}Kt.INDEXES_START_PATTERN=Int32Array.from([0,4,1,5]),Kt.INDEXES_STOP_PATTERN=Int32Array.from([6,2,7,3]),Kt.MAX_AVG_VARIANCE=.42,Kt.MAX_INDIVIDUAL_VARIANCE=.8,Kt.START_PATTERN=Int32Array.from([8,1,1,1,1,1,1,3]),Kt.STOP_PATTERN=Int32Array.from([7,1,1,3,1,1,1,2,1]),Kt.MAX_PIXEL_DRIFT=3,Kt.MAX_PATTERN_DRIFT=5,Kt.SKIPPED_ROW_COUNT_MAX=25,Kt.ROW_STEP=5,Kt.BARCODE_MIN_HEIGHT=10;class qt{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 qt(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 qt?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 qt(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 qt(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 qt(this.field,t)}multiplyScalar(e){if(e===0)return new qt(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 qt(this.field,n)}multiplyByMonomial(e,t){if(e<0)throw new l;if(t===0)return new qt(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 qt(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 Jt{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 se;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 Yt extends Jt{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 qt(this,new Int32Array([0])),this.one=new qt(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 qt(this,n)}}Yt.PDF417_GF=new Yt(Wt.NUMBER_OF_CODEWORDS,3);class Xt{constructor(){this.field=Yt.PDF417_GF}decode(e,t,n){let r=new qt(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 qt(this.field,new Int32Array([this.field.subtract(0,n),1]));o=o.multiply(r)}let s=new qt(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 qt(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 Zt{constructor(e,t,n,r,i){e instanceof Zt?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 Zt(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 Zt(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 Qt{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 $t{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+=$t.form(e,t)}toString(){return this.buffer}}class en{constructor(e){this.boundingBox=new Zt(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<en.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 $t,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()}}en.MAX_NEARBY_DISTANCE=5;class tn{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 Wt.toIntArray(t)}getConfidence(e){return this.values.get(e)}}class nn extends en{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 tn,n=new tn,r=new tn,i=new tn;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]<Wt.MIN_ROWS_IN_BARCODE||n.getValue()[0]+r.getValue()[0]>Wt.MAX_ROWS_IN_BARCODE)return null;let a=new Qt(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+`
|
|
57
|
-
`+super.toString()}}class rn{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=Wt.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=rn.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=rn.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(rn.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 $t;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 an{constructor(e,t,n,r){this.rowNumber=an.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!==an.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}}an.BARCODE_ROW_UNKNOWN=-1;class on{static initialize(){for(let e=0;e<Wt.SYMBOL_TABLE.length;e++){let t=Wt.SYMBOL_TABLE[e],n=t&1;for(let r=0;r<Wt.BARS_IN_MODULE;r++){let i=0;for(;(t&1)===n;)i+=1,t>>=1;n=t&1,on.RATIOS_TABLE[e]||(on.RATIOS_TABLE[e]=Array(Wt.BARS_IN_MODULE)),on.RATIOS_TABLE[e][Wt.BARS_IN_MODULE-r-1]=Math.fround(i/Wt.MODULES_IN_CODEWORD)}}this.bSymbolTableReady=!0}static getDecodedValue(e){let t=on.getDecodedCodewordValue(on.sampleBitCounts(e));return t===-1?on.getClosestDecodedValue(e):t}static sampleBitCounts(e){let t=B.sum(e),n=new Int32Array(Wt.BARS_IN_MODULE),r=0,i=0;for(let a=0;a<Wt.MODULES_IN_CODEWORD;a++){let o=t/(2*Wt.MODULES_IN_CODEWORD)+a*t/Wt.MODULES_IN_CODEWORD;i+e[r]<=o&&(i+=e[r],r++),n[r]++}return n}static getDecodedCodewordValue(e){let t=on.getBitValue(e);return Wt.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=B.sum(e),n=Array(Wt.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||on.initialize();for(let e=0;e<on.RATIOS_TABLE.length;e++){let t=0,a=on.RATIOS_TABLE[e];for(let e=0;e<Wt.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=Wt.SYMBOL_TABLE[e])}return i}}on.bSymbolTableReady=!1,on.RATIOS_TABLE=Array(Wt.SYMBOL_TABLE.length).map(e=>e=Array(Wt.BARS_IN_MODULE));class sn{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 cn{static parseLong(e,t=void 0){return parseInt(e,t)}}class ln extends s{}ln.kind=`NullPointerException`;class un{writeBytes(e){this.writeBytesOffset(e,0,e.length)}writeBytesOffset(e,t,n){if(e==null)throw new ln;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 dn extends s{}class fn extends un{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 dn;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 pn;(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`})(pn||={});function mn(){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 hn;function gn(e){if(hn===void 0&&(hn=mn()),hn===null)throw Error(`BigInt is not supported!`);return hn(e)}function _n(){let e=[];e[0]=gn(1);let t=gn(900);e[1]=t;for(let n=2;n<16;n++)e[n]=e[n-1]*t;return e}class J{static decode(e,t){let n=new D(``),r=C.ISO8859_1;n.enableDecoding(r);let i=1,a=e[i++],o=new sn;for(;i<e[0];){switch(a){case J.TEXT_COMPACTION_MODE_LATCH:i=J.textCompaction(e,i,n);break;case J.BYTE_COMPACTION_MODE_LATCH:case J.BYTE_COMPACTION_MODE_LATCH_6:i=J.byteCompaction(a,e,r,i,n);break;case J.MODE_SHIFT_TO_BYTE_COMPACTION_MODE:n.append(e[i++]);break;case J.NUMERIC_COMPACTION_MODE_LATCH:i=J.numericCompaction(e,i,n);break;case J.ECI_CHARSET:C.getCharacterSetECIByValue(e[i++]);break;case J.ECI_GENERAL_PURPOSE:i+=2;break;case J.ECI_USER_DEFINED:i++;break;case J.BEGIN_MACRO_PDF417_CONTROL_BLOCK:i=J.decodeMacroBlock(e,i,o);break;case J.BEGIN_MACRO_PDF417_OPTIONAL_FIELD:case J.MACRO_PDF417_TERMINATOR:throw new x;default:i--,i=J.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 ie(null,n.toString(),null,t);return s.setOther(o),s}static decodeMacroBlock(e,t,n){if(t+J.NUMBER_OF_SEQUENCE_CODEWORDS>e[0])throw x.getFormatInstance();let r=new Int32Array(J.NUMBER_OF_SEQUENCE_CODEWORDS);for(let n=0;n<J.NUMBER_OF_SEQUENCE_CODEWORDS;n++,t++)r[n]=e[t];n.setSegmentIndex(_.parseInt(J.decodeBase900toBase10(r,J.NUMBER_OF_SEQUENCE_CODEWORDS)));let i=new D;t=J.textCompaction(e,t,i),n.setFileId(i.toString());let a=-1;for(e[t]===J.BEGIN_MACRO_PDF417_OPTIONAL_FIELD&&(a=t+1);t<e[0];)switch(e[t]){case J.BEGIN_MACRO_PDF417_OPTIONAL_FIELD:switch(t++,e[t]){case J.MACRO_PDF417_OPTIONAL_FIELD_FILE_NAME:let r=new D;t=J.textCompaction(e,t+1,r),n.setFileName(r.toString());break;case J.MACRO_PDF417_OPTIONAL_FIELD_SENDER:let i=new D;t=J.textCompaction(e,t+1,i),n.setSender(i.toString());break;case J.MACRO_PDF417_OPTIONAL_FIELD_ADDRESSEE:let a=new D;t=J.textCompaction(e,t+1,a),n.setAddressee(a.toString());break;case J.MACRO_PDF417_OPTIONAL_FIELD_SEGMENT_COUNT:let o=new D;t=J.numericCompaction(e,t+1,o),n.setSegmentCount(_.parseInt(o.toString()));break;case J.MACRO_PDF417_OPTIONAL_FIELD_TIME_STAMP:let s=new D;t=J.numericCompaction(e,t+1,s),n.setTimestamp(cn.parseLong(s.toString()));break;case J.MACRO_PDF417_OPTIONAL_FIELD_CHECKSUM:let c=new D;t=J.numericCompaction(e,t+1,c),n.setChecksum(_.parseInt(c.toString()));break;case J.MACRO_PDF417_OPTIONAL_FIELD_FILE_SIZE:let l=new D;t=J.numericCompaction(e,t+1,l),n.setFileSize(cn.parseLong(l.toString()));break;default:throw x.getFormatInstance()}break;case J.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<J.TEXT_COMPACTION_MODE_LATCH)r[a]=n/30,r[a+1]=n%30,a+=2;else switch(n){case J.TEXT_COMPACTION_MODE_LATCH:r[a++]=J.TEXT_COMPACTION_MODE_LATCH;break;case J.BYTE_COMPACTION_MODE_LATCH:case J.BYTE_COMPACTION_MODE_LATCH_6:case J.NUMERIC_COMPACTION_MODE_LATCH:case J.BEGIN_MACRO_PDF417_CONTROL_BLOCK:case J.BEGIN_MACRO_PDF417_OPTIONAL_FIELD:case J.MACRO_PDF417_TERMINATOR:t--,o=!0;break;case J.MODE_SHIFT_TO_BYTE_COMPACTION_MODE:r[a]=J.MODE_SHIFT_TO_BYTE_COMPACTION_MODE,n=e[t++],i[a]=n,a++;break}}return J.decodeTextCompaction(r,i,a,n),t}static decodeTextCompaction(e,t,n,r){let i=pn.ALPHA,a=pn.ALPHA,o=0;for(;o<n;){let n=e[o],s=``;switch(i){case pn.ALPHA:if(n<26)s=String.fromCharCode(65+n);else switch(n){case 26:s=` `;break;case J.LL:i=pn.LOWER;break;case J.ML:i=pn.MIXED;break;case J.PS:a=i,i=pn.PUNCT_SHIFT;break;case J.MODE_SHIFT_TO_BYTE_COMPACTION_MODE:r.append(t[o]);break;case J.TEXT_COMPACTION_MODE_LATCH:i=pn.ALPHA;break}break;case pn.LOWER:if(n<26)s=String.fromCharCode(97+n);else switch(n){case 26:s=` `;break;case J.AS:a=i,i=pn.ALPHA_SHIFT;break;case J.ML:i=pn.MIXED;break;case J.PS:a=i,i=pn.PUNCT_SHIFT;break;case J.MODE_SHIFT_TO_BYTE_COMPACTION_MODE:r.append(t[o]);break;case J.TEXT_COMPACTION_MODE_LATCH:i=pn.ALPHA;break}break;case pn.MIXED:if(n<J.PL)s=J.MIXED_CHARS[n];else switch(n){case J.PL:i=pn.PUNCT;break;case 26:s=` `;break;case J.LL:i=pn.LOWER;break;case J.AL:i=pn.ALPHA;break;case J.PS:a=i,i=pn.PUNCT_SHIFT;break;case J.MODE_SHIFT_TO_BYTE_COMPACTION_MODE:r.append(t[o]);break;case J.TEXT_COMPACTION_MODE_LATCH:i=pn.ALPHA;break}break;case pn.PUNCT:if(n<J.PAL)s=J.PUNCT_CHARS[n];else switch(n){case J.PAL:i=pn.ALPHA;break;case J.MODE_SHIFT_TO_BYTE_COMPACTION_MODE:r.append(t[o]);break;case J.TEXT_COMPACTION_MODE_LATCH:i=pn.ALPHA;break}break;case pn.ALPHA_SHIFT:if(i=a,n<26)s=String.fromCharCode(65+n);else switch(n){case 26:s=` `;break;case J.TEXT_COMPACTION_MODE_LATCH:i=pn.ALPHA;break}break;case pn.PUNCT_SHIFT:if(i=a,n<J.PAL)s=J.PUNCT_CHARS[n];else switch(n){case J.PAL:i=pn.ALPHA;break;case J.MODE_SHIFT_TO_BYTE_COMPACTION_MODE:r.append(t[o]);break;case J.TEXT_COMPACTION_MODE_LATCH:i=pn.ALPHA;break}break}s!==``&&r.append(s),o++}}static byteCompaction(e,t,n,r,i){let a=new fn,o=0,s=0,c=!1;switch(e){case J.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 J.TEXT_COMPACTION_MODE_LATCH:case J.BYTE_COMPACTION_MODE_LATCH:case J.NUMERIC_COMPACTION_MODE_LATCH:case J.BYTE_COMPACTION_MODE_LATCH_6:case J.BEGIN_MACRO_PDF417_CONTROL_BLOCK:case J.BEGIN_MACRO_PDF417_OPTIONAL_FIELD:case J.MACRO_PDF417_TERMINATOR:r--,c=!0;break;default:if(o%5==0&&o>0){for(let e=0;e<6;++e)a.write(Number(gn(s)>>gn(8*(5-e))));s=0,o=0}break}r===t[0]&&n<J.TEXT_COMPACTION_MODE_LATCH&&(e[o++]=n);for(let t=0;t<o;t++)a.write(e[t]);break;case J.BYTE_COMPACTION_MODE_LATCH_6:for(;r<t[0]&&!c;){let e=t[r++];if(e<J.TEXT_COMPACTION_MODE_LATCH)o++,s=900*s+e;else switch(e){case J.TEXT_COMPACTION_MODE_LATCH:case J.BYTE_COMPACTION_MODE_LATCH:case J.NUMERIC_COMPACTION_MODE_LATCH:case J.BYTE_COMPACTION_MODE_LATCH_6:case J.BEGIN_MACRO_PDF417_CONTROL_BLOCK:case J.BEGIN_MACRO_PDF417_OPTIONAL_FIELD:case J.MACRO_PDF417_TERMINATOR:r--,c=!0;break}if(o%5==0&&o>0){for(let e=0;e<6;++e)a.write(Number(gn(s)>>gn(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(J.MAX_NUMERIC_CODEWORDS);for(;t<e[0]&&!i;){let o=e[t++];if(t===e[0]&&(i=!0),o<J.TEXT_COMPACTION_MODE_LATCH)a[r]=o,r++;else switch(o){case J.TEXT_COMPACTION_MODE_LATCH:case J.BYTE_COMPACTION_MODE_LATCH:case J.BYTE_COMPACTION_MODE_LATCH_6:case J.BEGIN_MACRO_PDF417_CONTROL_BLOCK:case J.BEGIN_MACRO_PDF417_OPTIONAL_FIELD:case J.MACRO_PDF417_TERMINATOR:t--,i=!0;break}(r%J.MAX_NUMERIC_CODEWORDS===0||o===J.NUMERIC_COMPACTION_MODE_LATCH||i)&&r>0&&(n.append(J.decodeBase900toBase10(a,r)),r=0)}return t}static decodeBase900toBase10(e,t){let n=gn(0);for(let r=0;r<t;r++)n+=J.EXP900[t-r-1]*gn(e[r]);let r=n.toString();if(r.charAt(0)!==`1`)throw new x;return r.substring(1)}}J.TEXT_COMPACTION_MODE_LATCH=900,J.BYTE_COMPACTION_MODE_LATCH=901,J.NUMERIC_COMPACTION_MODE_LATCH=902,J.BYTE_COMPACTION_MODE_LATCH_6=924,J.ECI_USER_DEFINED=925,J.ECI_GENERAL_PURPOSE=926,J.ECI_CHARSET=927,J.BEGIN_MACRO_PDF417_CONTROL_BLOCK=928,J.BEGIN_MACRO_PDF417_OPTIONAL_FIELD=923,J.MACRO_PDF417_TERMINATOR=922,J.MODE_SHIFT_TO_BYTE_COMPACTION_MODE=913,J.MAX_NUMERIC_CODEWORDS=15,J.MACRO_PDF417_OPTIONAL_FIELD_FILE_NAME=0,J.MACRO_PDF417_OPTIONAL_FIELD_SEGMENT_COUNT=1,J.MACRO_PDF417_OPTIONAL_FIELD_TIME_STAMP=2,J.MACRO_PDF417_OPTIONAL_FIELD_SENDER=3,J.MACRO_PDF417_OPTIONAL_FIELD_ADDRESSEE=4,J.MACRO_PDF417_OPTIONAL_FIELD_FILE_SIZE=5,J.MACRO_PDF417_OPTIONAL_FIELD_CHECKSUM=6,J.PL=25,J.LL=27,J.AS=27,J.ML=28,J.AL=28,J.PS=29,J.PAL=29,J.PUNCT_CHARS=`;<>@[\\]_\`~!\r ,:
|
|
58
|
-
-.$/"|*()?{}'`,J.MIXED_CHARS=`0123456789&\r ,:#-.$/+%*=^`,J.EXP900=mn()?_n():[],J.NUMBER_OF_SEQUENCE_CODEWORDS=2;class vn{constructor(){}static decode(e,t,n,r,i,a,o){let s=new Zt(e,t,n,r,i),c=null,l=null,u;for(let n=!0;;n=!1){if(t!=null&&(c=vn.getRowIndicatorColumn(e,s,t,!0,a,o)),r!=null&&(l=vn.getRowIndicatorColumn(e,s,r,!1,a,o)),u=vn.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 nn(s,n===0):new en(s),u.setDetectionResultColumn(n,r);let i=-1,c=i;for(let t=s.getMinY();t<=s.getMaxY();t++){if(i=vn.getStartColumn(u,n,t,f),i<0||i>s.getMaxX()){if(c===-1)continue;i=c}let l=vn.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 vn.createDecoderResult(u)}static merge(e,t){if(e==null&&t==null)return null;let n=vn.getBarcodeMetadata(e,t);return n==null?null:new rn(n,Zt.merge(vn.adjustBoundingBox(e),vn.adjustBoundingBox(t)))}static adjustBoundingBox(e){if(e==null)return null;let t=e.getRowHeights();if(t==null)return null;let n=vn.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 nn(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=vn.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()-vn.getNumberOfECCodeWords(e.getBarcodeECLevel());if(r.length===0){if(i<1||i>Wt.MAX_CODEWORDS_IN_BARCODE)throw k.getNotFoundInstance();n.setValue(i)}else r[0]!==i&&n.setValue(i)}static createDecoderResult(e){let t=vn.createBarcodeMatrix(e);vn.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 vn.createDecoderResultFromAmbiguousValues(e.getBarcodeECLevel(),r,Wt.toIntArray(n),Wt.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 vn.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 tn;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(vn.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(vn.isValidBarcodeColumn(e,t-i)&&(a=e.getDetectionResultColumn(t-i).getCodewordNearby(n)),a!=null)return r?a.getEndX():a.getStartX();let o=0;for(;vn.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=vn.adjustCodewordStartColumn(e,t,n,r,i,a);let c=vn.getModuleBitCount(e,t,n,r,i,a);if(c==null)return null;let l,u=B.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(!vn.checkCodewordSkew(u,o,s))return null;let d=on.getDecodedValue(c),f=Wt.getCodeword(d);return f===-1?null:new an(i,l,vn.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)>vn.CODEWORD_SKEW_SIZE)return i;o+=s}s=-s,r=!r}return o}static checkCodewordSkew(e,t,n){return t-vn.CODEWORD_SKEW_SIZE<=e&&e<=n+vn.CODEWORD_SKEW_SIZE}static decodeCodewords(e,t,n){if(e.length===0)throw x.getFormatInstance();let r=1<<t+1,i=vn.correctErrors(e,n,r);vn.verifyCodewordCount(e,r);let a=J.decode(e,``+t);return a.setErrorsCorrected(i),a.setErasures(n.length),a}static correctErrors(e,t,n){if(t!=null&&t.length>n/2+vn.MAX_ERRORS||n<0||n>vn.MAX_EC_CODEWORDS)throw d.getChecksumInstance();return vn.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 vn.getCodewordBucketNumber(vn.getBitCountForCodeword(e))}static getCodewordBucketNumber_Int32Array(e){return(e[0]-e[2]+e[4]-e[6]+9)%9}static toString(e){let t=new $t;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()}}vn.CODEWORD_SKEW_SIZE=2,vn.MAX_ERRORS=3,vn.MAX_EC_CODEWORDS=512,vn.errorCorrection=new Xt;class yn{decode(e,t=null){let n=yn.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 yn.decode(e,t,!0)}catch(e){throw e instanceof x||e instanceof d?k.getNotFoundInstance():e}}static decode(e,t,n){let r=[],i=Kt.detectMultiple(e,t,n);for(let e of i.getPoints()){let t=vn.decode(i.getBits(),e[4],e[5],e[6],e[7],yn.getMinCodewordWidth(e),yn.getMaxCodewordWidth(e)),n=new L(t.getText(),t.getRawBytes(),void 0,e,R.PDF_417);n.putMetadata(re.ERROR_CORRECTION_LEVEL,t.getECLevel());let a=t.getOther();a!=null&&n.putMetadata(re.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(yn.getMaxWidth(e[0],e[4]),yn.getMaxWidth(e[6],e[2])*Wt.MODULES_IN_CODEWORD/Wt.MODULES_IN_STOP_PATTERN),Math.max(yn.getMaxWidth(e[1],e[5]),yn.getMaxWidth(e[7],e[3])*Wt.MODULES_IN_CODEWORD/Wt.MODULES_IN_STOP_PATTERN)))}static getMinCodewordWidth(e){return Math.floor(Math.min(Math.min(yn.getMinWidth(e[0],e[4]),yn.getMinWidth(e[6],e[2])*Wt.MODULES_IN_CODEWORD/Wt.MODULES_IN_STOP_PATTERN),Math.min(yn.getMinWidth(e[1],e[5]),yn.getMinWidth(e[7],e[3])*Wt.MODULES_IN_CODEWORD/Wt.MODULES_IN_STOP_PATTERN)))}reset(){}}class bn extends s{}bn.kind=`ReaderException`;class xn{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===R.UPC_A||e===R.UPC_E||e===R.EAN_13||e===R.EAN_8||e===R.CODABAR||e===R.CODE_39||e===R.CODE_93||e===R.CODE_128||e===R.ITF||e===R.RSS_14||e===R.RSS_EXPANDED);t&&!n&&i.push(new ut(e,this.verbose)),r.includes(R.QR_CODE)&&i.push(new Ut),r.includes(R.DATA_MATRIX)&&i.push(new St),r.includes(R.AZTEC)&&i.push(new Se),r.includes(R.PDF_417)&&i.push(new yn),t&&n&&i.push(new ut(e,this.verbose))}i.length===0&&(n||i.push(new ut(e,this.verbose)),i.push(new Ut),i.push(new St),i.push(new Se),i.push(new yn),n&&i.push(new ut(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 bn(`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 bn)continue}throw new k(`No MultiFormat Readers were able to detect the code.`)}}class Sn extends ee{constructor(e=null,t=500){let n=new xn;n.setHints(e),super(n,t)}decodeBitmap(e){return this.reader.decodeWithState(e)}}class Cn extends ee{constructor(e=500){super(new yn,e)}}class wn extends ee{constructor(e=500){super(new Ut,e)}}var Tn;(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`})(Tn||={});var En=Tn;class Dn{constructor(e){this.field=e,this.cachedGenerators=[],this.cachedGenerators.push(new oe(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 oe(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 oe(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 On{constructor(){}static applyMaskPenaltyRule1(e){return On.applyMaskPenaltyRule1Internal(e,!0)+On.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 On.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&&(On.isWhiteHorizontal(o,a-4,a)||On.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&&(On.isWhiteVertical(n,a,e-4,e)||On.isWhiteVertical(n,a,e+7,e+11))&&t++}return t*On.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)*On.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+=On.N1+(r-5)),r=1,o=i)}r>=5&&(n+=On.N1+(r-5))}return n}}On.N1=3,On.N2=3,On.N3=40,On.N4=10;class kn{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 kn))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(`
|
|
59
|
-
`)}return e.toString()}}class An{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(`<<
|
|
60
|
-
`),e.append(` mode: `),e.append(this.mode?this.mode.toString():`null`),e.append(`
|
|
61
|
-
ecLevel: `),e.append(this.ecLevel?this.ecLevel.toString():`null`),e.append(`
|
|
62
|
-
version: `),e.append(this.version?this.version.toString():`null`),e.append(`
|
|
63
|
-
maskPattern: `),e.append(this.maskPattern.toString()),this.matrix?(e.append(`
|
|
64
|
-
matrix:
|
|
65
|
-
`),e.append(this.matrix.toString())):e.append(`
|
|
66
|
-
matrix: null
|
|
67
|
-
`),e.append(`>>
|
|
68
|
-
`),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<An.NUM_MASK_PATTERNS}}An.NUM_MASK_PATTERNS=8;class jn extends s{}jn.kind=`WriterException`;class Mn{constructor(){}static clearMatrix(e){e.clear(255)}static buildMatrix(e,t,n,r,i){Mn.clearMatrix(i),Mn.embedBasicPatterns(n,i),Mn.embedTypeInfo(t,r,i),Mn.maybeEmbedVersionInfo(n,i),Mn.embedDataBits(e,r,i)}static embedBasicPatterns(e,t){Mn.embedPositionDetectionPatternsAndSeparators(t),Mn.embedDarkDotAtLeftBottomCorner(t),Mn.maybeEmbedPositionAdjustmentPatterns(e,t),Mn.embedTimingPatterns(t)}static embedTypeInfo(e,t,n){let r=new v;Mn.makeTypeInfoBits(e,t,r);for(let e=0,t=r.getSize();e<t;++e){let t=r.get(r.getSize()-1-e),i=Mn.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;Mn.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(!Mn.isEmpty(n.get(s,o)))continue;let c;r<e.getSize()?(c=e.get(r),++r):c=!1,t!==255&&On.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 jn(`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=Mn.findMSBSet(t);for(e<<=n-1;Mn.findMSBSet(e)>=n;)e^=t<<Mn.findMSBSet(e)-n;return e}static makeTypeInfoBits(e,t,n){if(!An.isValidMaskPattern(t))throw new jn(`Invalid mask pattern`);let r=e.getBits()<<3|t;n.appendBits(r,5);let i=Mn.calculateBCHCode(r,Mn.TYPE_INFO_POLY);n.appendBits(i,10);let a=new v;if(a.appendBits(Mn.TYPE_INFO_MASK_PATTERN,15),n.xor(a),n.getSize()!==15)throw new jn(`should not happen but we got: `+n.getSize())}static makeVersionInfoBits(e,t){t.appendBits(e.getVersionNumber(),6);let n=Mn.calculateBCHCode(e.getVersionNumber(),Mn.VERSION_INFO_POLY);if(t.appendBits(n,12),t.getSize()!==18)throw new jn(`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;Mn.isEmpty(e.get(t,6))&&e.setNumber(t,6,n),Mn.isEmpty(e.get(6,t))&&e.setNumber(6,t,n)}}static embedDarkDotAtLeftBottomCorner(e){if(e.get(8,e.getHeight()-8)===0)throw new jn;e.setNumber(8,e.getHeight()-8,1)}static embedHorizontalSeparationPattern(e,t,n){for(let r=0;r<8;++r){if(!Mn.isEmpty(n.get(e+r,t)))throw new jn;n.setNumber(e+r,t,0)}}static embedVerticalSeparationPattern(e,t,n){for(let r=0;r<7;++r){if(!Mn.isEmpty(n.get(e,t+r)))throw new jn;n.setNumber(e,t+r,0)}}static embedPositionAdjustmentPattern(e,t,n){for(let r=0;r<5;++r){let i=Mn.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=Mn.POSITION_DETECTION_PATTERN[r];for(let a=0;a<7;++a)n.setNumber(e+a,t+r,i[a])}}static embedPositionDetectionPatternsAndSeparators(e){let t=Mn.POSITION_DETECTION_PATTERN[0].length;Mn.embedPositionDetectionPattern(0,0,e),Mn.embedPositionDetectionPattern(e.getWidth()-t,0,e),Mn.embedPositionDetectionPattern(0,e.getWidth()-t,e),Mn.embedHorizontalSeparationPattern(0,7,e),Mn.embedHorizontalSeparationPattern(e.getWidth()-8,7,e),Mn.embedHorizontalSeparationPattern(0,e.getWidth()-8,e),Mn.embedVerticalSeparationPattern(7,0,e),Mn.embedVerticalSeparationPattern(e.getHeight()-7-1,0,e),Mn.embedVerticalSeparationPattern(7,e.getHeight()-7,e)}static maybeEmbedPositionAdjustmentPatterns(e,t){if(e.getVersionNumber()<2)return;let n=e.getVersionNumber()-1,r=Mn.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&&Mn.isEmpty(t.get(n,i))&&Mn.embedPositionAdjustmentPattern(n-2,i-2,t)}}}}Mn.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])]),Mn.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])]),Mn.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])]),Mn.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])]),Mn.VERSION_INFO_POLY=7973,Mn.TYPE_INFO_POLY=1335,Mn.TYPE_INFO_MASK_PATTERN=21522;class Nn{constructor(e,t){this.dataBytes=e,this.errorCorrectionBytes=t}getDataBytes(){return this.dataBytes}getErrorCorrectionBytes(){return this.errorCorrectionBytes}}class Pn{constructor(){}static calculateMaskPenalty(e){return On.applyMaskPenaltyRule1(e)+On.applyMaskPenaltyRule2(e)+On.applyMaskPenaltyRule3(e)+On.applyMaskPenaltyRule4(e)}static encode(e,t,n=null){let r=Pn.DEFAULT_BYTE_MODE_ENCODING,i=n!==null&&n.get(En.CHARACTER_SET)!==void 0;i&&(r=n.get(En.CHARACTER_SET).toString());let a=this.chooseMode(e,r),o=new v;if(a===Nt.BYTE&&(i||Pn.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(En.QR_VERSION)!==void 0){let e=Number.parseInt(n.get(En.QR_VERSION).toString(),10);c=Dt.getVersionForNumber(e);let r=this.calculateBitsNeeded(a,o,s,c);if(!this.willFit(r,c,t))throw new jn(`Data too big for requested version`)}else c=this.recommendVersion(t,a,o,s);let l=new v;l.appendBitArray(o);let u=a===Nt.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 An;m.setECLevel(t),m.setMode(a),m.setVersion(c);let h=c.getDimensionForVersion(),g=new kn(h,h),_=this.chooseMaskPattern(p,t,c,g);return m.setMaskPattern(_),Mn.buildMatrix(p,t,c,_,g),m.setMatrix(g),m}static recommendVersion(e,t,n,r){let i=this.calculateBitsNeeded(t,n,r,Dt.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<Pn.ALPHANUMERIC_TABLE.length?Pn.ALPHANUMERIC_TABLE[e]:-1}static chooseMode(e,t=null){if(C.SJIS.getName()===t&&this.isOnlyDoubleByteKanji(e))return Nt.KANJI;let n=!1,r=!1;for(let t=0,i=e.length;t<i;++t){let i=e.charAt(t);if(Pn.isDigit(i))n=!0;else if(this.getAlphanumericCode(i.charCodeAt(0))!==-1)r=!0;else return Nt.BYTE}return r?Nt.ALPHANUMERIC:n?Nt.NUMERIC:Nt.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<An.NUM_MASK_PATTERNS;o++){Mn.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=Dt.getVersionForNumber(n);if(Pn.willFit(e,r,t))return r}throw new jn(`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 jn(`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 jn(`Bits size does not equal capacity`)}static getNumDataBytesAndNumECBytesForBlockID(e,t,n,r,i,a){if(r>=n)throw new jn(`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 jn(`EC bytes mismatch`);if(n!==s+o)throw new jn(`RS blocks mismatch`);if(e!==(u+f)*s+(d+p)*o)throw new jn(`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 jn(`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);Pn.getNumDataBytesAndNumECBytesForBlockID(t,n,r,c,l,u);let d=l[0],f=new Uint8Array(d);e.toBytes(8*i,f,0,d);let p=Pn.generateECBytes(f,u[0]);s.push(new Nn(f,p)),a=Math.max(a,d),o=Math.max(o,p.length),i+=l[0]}if(n!==i)throw new jn(`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 jn(`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 Dn(ce.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 jn(e+` is bigger than `+((1<<i)-1));r.appendBits(e,i)}static appendBytes(e,t,n,r){switch(t){case Nt.NUMERIC:Pn.appendNumericBytes(e,n);break;case Nt.ALPHANUMERIC:Pn.appendAlphanumericBytes(e,n);break;case Nt.BYTE:Pn.append8BitBytes(e,n,r);break;case Nt.KANJI:Pn.appendKanjiBytes(e,n);break;default:throw new jn(`Invalid mode: `+t)}}static getDigit(e){return e.charCodeAt(0)-48}static isDigit(e){let t=Pn.getDigit(e);return t>=0&&t<=9}static appendNumericBytes(e,t){let n=e.length,r=0;for(;r<n;){let i=Pn.getDigit(e.charAt(r));if(r+2<n){let n=Pn.getDigit(e.charAt(r+1)),a=Pn.getDigit(e.charAt(r+2));t.appendBits(i*100+n*10+a,10),r+=3}else if(r+1<n){let n=Pn.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=Pn.getAlphanumericCode(e.charCodeAt(r));if(i===-1)throw new jn;if(r+1<n){let n=Pn.getAlphanumericCode(e.charCodeAt(r+1));if(n===-1)throw new jn;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 jn(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 jn(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 jn(`Invalid byte sequence`);let s=(o>>8)*192+(o&255);t.appendBits(s,13)}}static appendECI(e,t){t.appendBits(Nt.ECI.getBits(),4),t.appendBits(e.getValue(),8)}}Pn.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]),Pn.DEFAULT_BYTE_MODE_ENCODING=C.UTF8.getName();class Fn{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=Tt.L,a=Fn.QUIET_ZONE_SIZE;r!==null&&(r.get(En.ERROR_CORRECTION)!==void 0&&(i=Tt.fromString(r.get(En.ERROR_CORRECTION).toString())),r.get(En.MARGIN)!==void 0&&(a=Number.parseInt(r.get(En.MARGIN).toString(),10)));let o=Pn.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 le;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(Fn.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(Fn.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}}Fn.QUIET_ZONE_SIZE=4,Fn.SVG_NS=`http://www.w3.org/2000/svg`;class In{encode(e,t,n,r,i){if(e.length===0)throw new l(`Found empty contents`);if(t!==R.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=Tt.L,o=In.QUIET_ZONE_SIZE;i!==null&&(i.get(En.ERROR_CORRECTION)!==void 0&&(a=Tt.fromString(i.get(En.ERROR_CORRECTION).toString())),i.get(En.MARGIN)!==void 0&&(o=Number.parseInt(i.get(En.MARGIN).toString(),10)));let s=Pn.encode(e,a,i);return In.renderResult(s,n,r,o)}static renderResult(e,t,n,r){let i=e.getMatrix();if(i===null)throw new le;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}}In.QUIET_ZONE_SIZE=4;class Ln{encode(e,t,n,r,i){let a;switch(t){case R.QR_CODE:a=new In;break;default:throw new l(`No encoder available for format `+t)}return a.encode(e,t,n,r,i)}}class Rn 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 Rn(this.yuvData,this.dataWidth,this.dataHeight,this.left+e,this.top+t,n,r,!1)}renderThumbnail(){let e=this.getWidth()/Rn.THUMBNAIL_SCALE_FACTOR,t=this.getHeight()/Rn.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*Rn.THUMBNAIL_SCALE_FACTOR]&255;n[t+a]=4278190080|e*65793}i+=this.dataWidth*Rn.THUMBNAIL_SCALE_FACTOR}return n}getThumbnailWidth(){return this.getWidth()/Rn.THUMBNAIL_SCALE_FACTOR}getThumbnailHeight(){return this.getHeight()/Rn.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)}}Rn.THUMBNAIL_SCALE_FACTOR=2;class zn 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 zn(this.luminances,n,r,this.dataWidth,this.dataHeight,this.left+e,this.top+t)}invert(){return new N(this)}}class Bn extends C{static forName(e){return this.getCharacterSetECIByName(e)}}class Vn{}Vn.ISO_8859_1=C.ISO8859_1;class Hn{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 Un{static singletonList(e){return[e]}static min(e,t){return e.sort(t)[0]}}class Wn{constructor(e){this.previous=e}getPrevious(){return this.previous}}class Gn extends Wn{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 Gn(this,e,t)}addBinaryShift(e,t){return console.warn(`addBinaryShift on SimpleToken, this simply returns a copy of this token`),new Gn(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 Kn extends Gn{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 Kn(this,e,t)}toString(){return`<`+this.binaryShiftStart+`::`+(this.binaryShiftStart+this.binaryShiftByteCount-1)+`>`}}function qn(e,t,n){return new Kn(e,t,n)}function Jn(e,t,n){return new Gn(e,t,n)}let Yn=[`UPPER`,`LOWER`,`DIGIT`,`MIXED`,`PUNCT`],Xn=new Gn(null,0,0),Zn=[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 Qn(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 $n=Qn(g.createInt32Array(6,6));class er{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=Zn[this.mode][e];r=Jn(r,t&65535,t>>16),n+=t>>16}let i=e===2?4:5;return r=Jn(r,t,i),new er(r,e,0,n+i)}shiftAndAppend(e,t){let n=this.token,r=this.mode===2?4:5;return n=Jn(n,$n[this.mode][e],r),n=Jn(n,t,5),new er(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=Zn[n][0];t=Jn(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 er(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=qn(t,e-this.binaryShiftByteCount,this.binaryShiftByteCount),new er(t,this.mode,0,this.bitCount)}isBetterThanOrEqualTo(e){let t=this.bitCount+(Zn[this.mode][e.mode]>>16);return this.binaryShiftByteCount<e.binaryShiftByteCount?t+=er.calculateBinaryShiftCost(e)-er.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`,Yn[this.mode],this.bitCount,this.binaryShiftByteCount)}static calculateBinaryShiftCost(e){return e.binaryShiftByteCount>62?21:e.binaryShiftByteCount>31?20:e.binaryShiftByteCount>0?10:0}}er.INITIAL_STATE=new er(Xn,0,0,0);function tr(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
|
|
69
|
-
\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 nr=tr(g.createInt32Array(5,256));class rr{constructor(e){this.text=e}encode(){let e=E.getCharCode(` `),t=E.getCharCode(`
|
|
70
|
-
`),n=Un.singletonList(er.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=rr.updateStateListForPair(n,r,i),r++):n=this.updateStateListForChar(n,r)}return Un.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 rr.simplifyStates(n)}updateStateForChar(e,t,n){let r=this.text[t]&255,i=nr[e.getMode()][r]>0,a=null;for(let o=0;o<=4;o++){let s=nr[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&&$n[e.getMode()][o]>=0){let e=a.shiftAndAppend(o,s);n.push(e)}}}if(e.getBinaryShiftByteCount()>0||nr[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 ir{constructor(){}static encodeBytes(e){return ir.encode(e,ir.DEFAULT_EC_PERCENT,ir.DEFAULT_AZTEC_LAYERS)}static encode(e,t,n){let r=new rr(e).encode(),i=_.truncDivision(r.getSize()*t,100)+11,a=r.getSize()+i,o,s,c,u,d;if(n!==ir.DEFAULT_AZTEC_LAYERS){if(o=n<0,s=Math.abs(n),s>(o?ir.MAX_NB_BITS_COMPACT:ir.MAX_NB_BITS))throw new l(E.format(`Illegal value %s for layers`,n));c=ir.totalBitsInLayer(s,o),u=ir.WORD_SIZE[s];let e=c-c%u;if(d=ir.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>ir.MAX_NB_BITS)throw new l(`Data too large for an Aztec code`);if(o=e<=3,s=o?e+1:e,c=ir.totalBitsInLayer(s,o),a>c)continue;(d==null||u!==ir.WORD_SIZE[s])&&(u=ir.WORD_SIZE[s],d=ir.stuffBits(r,u));let t=c-c%u;if(!(o&&d.getSize()>u*64)&&d.getSize()+i<=t)break}}let f=ir.generateCheckWords(d,c,u),p=d.getSize()/u,m=ir.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(ir.drawModeMessage(y,o,v,m),o)ir.drawBullsEye(y,_.truncDivision(v,2),5);else{ir.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 Hn;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=ir.generateCheckWords(r,28,4)):(r.appendBits(t-1,5),r.appendBits(n-1,11),r=ir.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 Dn(ir.getGF(n)),a=_.truncDivision(t,n),o=ir.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 ce.AZTEC_PARAM;case 6:return ce.AZTEC_DATA_6;case 8:return ce.AZTEC_DATA_8;case 10:return ce.AZTEC_DATA_10;case 12:return ce.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}}ir.DEFAULT_EC_PERCENT=33,ir.DEFAULT_AZTEC_LAYERS=0,ir.MAX_NB_BITS=32,ir.MAX_NB_BITS_COMPACT=4,ir.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 ar{encode(e,t,n,r){return this.encodeWithHints(e,t,n,r,null)}encodeWithHints(e,t,n,r,i){let a=Vn.ISO_8859_1,o=ir.DEFAULT_EC_PERCENT,s=ir.DEFAULT_AZTEC_LAYERS;return i!=null&&(i.has(En.CHARACTER_SET)&&(a=Bn.forName(i.get(En.CHARACTER_SET).toString())),i.has(En.ERROR_CORRECTION)&&(o=_.parseInt(i.get(En.ERROR_CORRECTION).toString())),i.has(En.AZTEC_LAYERS)&&(s=_.parseInt(i.get(En.AZTEC_LAYERS).toString()))),ar.encodeLayers(e,t,n,r,a,o,s)}static encodeLayers(e,t,n,r,i,a,o){if(t!==R.AZTEC)throw new l(`Can only encode AZTEC, but got `+t);let s=ir.encode(E.getBytes(e,i),a,o);return ar.renderResult(s,n,r)}static renderResult(e,t,n){let r=e.getMatrix();if(r==null)throw new le;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=Je,e.ArgumentException=c,e.ArithmeticException=se,e.AztecCode=Hn,e.AztecCodeReader=Se,e.AztecCodeWriter=ar,e.AztecDecoder=fe,e.AztecDetector=xe,e.AztecDetectorResult=he,e.AztecEncoder=ir,e.AztecHighLevelEncoder=rr,e.AztecPoint=be,e.BarcodeFormat=R,e.Binarizer=f,e.BinaryBitmap=u,e.BitArray=v,e.BitMatrix=O,e.BitSource=_t,e.BrowserAztecCodeReader=Ce,e.BrowserBarcodeReader=dt,e.BrowserCodeReader=ee,e.BrowserDatamatrixCodeReader=Ct,e.BrowserMultiFormatReader=Sn,e.BrowserPDF417Reader=Cn,e.BrowserQRCodeReader=wn,e.BrowserQRCodeSvgWriter=Fn,e.CharacterSetECI=C,e.ChecksumException=d,e.Code128Reader=U,e.Code39Reader=Te,e.DataMatrixDecodedBitStreamParser=yt,e.DataMatrixReader=St,e.DecodeHintType=b,e.DecoderResult=ie,e.DefaultGridSampler=ve,e.DetectorResult=me,e.EAN13Reader=Me,e.EncodeHintType=En,e.Exception=s,e.FormatException=x,e.GenericGF=ce,e.GenericGFPoly=oe,e.GlobalHistogramBinarizer=A,e.GridSampler=_e,e.GridSamplerInstance=ye,e.HTMLCanvasElementLuminanceSource=P,e.HybridBinarizer=j,e.ITFReader=Ee,e.IllegalArgumentException=l,e.IllegalStateException=le,e.InvertedLuminanceSource=N,e.LuminanceSource=M,e.MathUtils=B,e.MultiFormatOneDReader=ut,e.MultiFormatReader=xn,e.MultiFormatWriter=Ln,e.NotFoundException=k,e.OneDReader=we,e.PDF417DecodedBitStreamParser=J,e.PDF417DecoderErrorCorrection=Xt,e.PDF417Reader=yn,e.PDF417ResultMetadata=sn,e.PerspectiveTransform=H,e.PlanarYUVLuminanceSource=Rn,e.QRCodeByteMatrix=kn,e.QRCodeDataMask=kt,e.QRCodeDecodedBitStreamParser=Pt,e.QRCodeDecoderErrorCorrectionLevel=Tt,e.QRCodeDecoderFormatInformation=Et,e.QRCodeEncoder=Pn,e.QRCodeEncoderQRCode=An,e.QRCodeMaskUtil=On,e.QRCodeMatrixUtil=Mn,e.QRCodeMode=Nt,e.QRCodeReader=Ut,e.QRCodeVersion=Dt,e.QRCodeWriter=In,e.RGBLuminanceSource=zn,e.RSS14Reader=lt,e.RSSExpandedReader=G,e.ReaderException=bn,e.ReedSolomonDecoder=ue,e.ReedSolomonEncoder=Dn,e.ReedSolomonException=z,e.Result=L,e.ResultMetadataType=re,e.ResultPoint=V,e.StringUtils=E,e.UnsupportedOperationException=w,e.VideoInputDevice=F,e.WhiteRectangleDetector=ge,e.WriterException=jn,e.ZXingArrays=g,e.ZXingCharset=Bn,e.ZXingInteger=_,e.ZXingStandardCharsets=Vn,e.ZXingStringBuilder=D,e.ZXingStringEncoding=T,e.ZXingSystem=p,e.createAbstractExpandedDecoder=at,Object.defineProperty(e,"__esModule",{value:!0})}))}))()),s_=function(){function e(e,t,n){if(this.formatMap=new Map([[Ug.QR_CODE,o_.BarcodeFormat.QR_CODE],[Ug.AZTEC,o_.BarcodeFormat.AZTEC],[Ug.CODABAR,o_.BarcodeFormat.CODABAR],[Ug.CODE_39,o_.BarcodeFormat.CODE_39],[Ug.CODE_93,o_.BarcodeFormat.CODE_93],[Ug.CODE_128,o_.BarcodeFormat.CODE_128],[Ug.DATA_MATRIX,o_.BarcodeFormat.DATA_MATRIX],[Ug.MAXICODE,o_.BarcodeFormat.MAXICODE],[Ug.ITF,o_.BarcodeFormat.ITF],[Ug.EAN_13,o_.BarcodeFormat.EAN_13],[Ug.EAN_8,o_.BarcodeFormat.EAN_8],[Ug.PDF_417,o_.BarcodeFormat.PDF_417],[Ug.RSS_14,o_.BarcodeFormat.RSS_14],[Ug.RSS_EXPANDED,o_.BarcodeFormat.RSS_EXPANDED],[Ug.UPC_A,o_.BarcodeFormat.UPC_A],[Ug.UPC_E,o_.BarcodeFormat.UPC_E],[Ug.UPC_EAN_EXTENSION,o_.BarcodeFormat.UPC_EAN_EXTENSION]]),this.reverseFormatMap=this.createReverseFormatMap(),!o_)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(o_.DecodeHintType.POSSIBLE_FORMATS,r),i.set(o_.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 o_.MultiFormatReader(this.verbose,this.hints),n=new o_.HTMLCanvasElementLuminanceSource(e),r=new o_.BinaryBitmap(new o_.HybridBinarizer(n)),i=t.decode(r);return{text:i.text,format:Yg.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}(),c_=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())})},l_=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}}},u_=function(){function e(t,n,r){if(this.formatMap=new Map([[Ug.QR_CODE,`qr_code`],[Ug.AZTEC,`aztec`],[Ug.CODABAR,`codabar`],[Ug.CODE_39,`code_39`],[Ug.CODE_93,`code_93`],[Ug.CODE_128,`code_128`],[Ug.DATA_MATRIX,`data_matrix`],[Ug.ITF,`itf`],[Ug.EAN_13,`ean_13`],[Ug.EAN_8,`ean_8`],[Ug.PDF_417,`pdf417`],[Ug.UPC_A,`upc_a`],[Ug.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 c_(this,void 0,void 0,function(){var t,n;return l_(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:Yg.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}(),d_=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())})},f_=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}}},p_=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&&u_.isSupported()?(this.primaryDecoder=new u_(e,n,r),this.secondaryDecoder=new s_(e,n,r)):this.primaryDecoder=new s_(e,n,r)}return e.prototype.decodeAsync=function(e){return d_(this,void 0,void 0,function(){var t;return f_(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 d_(this,void 0,void 0,function(){var t,n;return f_(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}(),m_=(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)}})(),h_=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())})},g_=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}}},__=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}(),v_=function(e){m_(t,e);function t(t){return e.call(this,`zoom`,t)||this}return t}(function(e){m_(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}(__)),y_=function(e){m_(t,e);function t(t){return e.call(this,`torch`,t)||this}return t}(__),b_=function(){function e(e){this.track=e}return e.prototype.zoomFeature=function(){return new v_(this.track)},e.prototype.torchFeature=function(){return new y_(this.track)},e}(),x_=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 h_(this,void 0,void 0,function(){var a,o;return g_(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 h_(this,void 0,void 0,function(){return g_(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 b_(this.getFirstTrackOrFail())},e}(),S_=function(){function e(e){this.mediaStream=e}return e.prototype.render=function(e,t,n){return h_(this,void 0,void 0,function(){return g_(this,function(r){return[2,x_.create(e,this.mediaStream,t,n)]})})},e.create=function(t){return h_(this,void 0,void 0,function(){var n,r;return g_(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}(),C_=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())})},w_=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}}},T_=function(){function e(){}return e.failIfNotSupported=function(){return C_(this,void 0,void 0,function(){return w_(this,function(t){if(!navigator.mediaDevices)throw`navigator.mediaDevices not supported`;return[2,new e]})})},e.prototype.create=function(e){return C_(this,void 0,void 0,function(){return w_(this,function(t){return[2,S_.create(e)]})})},e}(),E_=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())})},D_=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}}},O_=function(){function e(){}return e.retrieve=function(){return navigator.mediaDevices?e.getCamerasFromMediaDevices():MediaStreamTrack&&MediaStreamTrack.getSources?e.getCamerasFromMediaStreamTrack():e.rejectWithError()},e.rejectWithError=function(){var t=n_.unableToQuerySupportedDevices();return e.isHttpsOrLocalhost()||(t=n_.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 E_(this,void 0,void 0,function(){var e,t,n,r,i,a,o;return D_(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}(),k_;(function(e){e[e.UNKNOWN=0]=`UNKNOWN`,e[e.NOT_STARTED=1]=`NOT_STARTED`,e[e.SCANNING=2]=`SCANNING`,e[e.PAUSED=3]=`PAUSED`})(k_||={});var A_=function(){function e(){this.state=k_.NOT_STARTED,this.onGoingTransactionNewState=k_.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===k_.UNKNOWN)throw`Transaction is already cancelled, cannot execute().`;var e=this.onGoingTransactionNewState;this.onGoingTransactionNewState=k_.UNKNOWN,this.directTransition(e)},e.prototype.cancel=function(){if(this.onGoingTransactionNewState===k_.UNKNOWN)throw`Transaction is already cancelled, cannot cancel().`;this.onGoingTransactionNewState=k_.UNKNOWN},e.prototype.getState=function(){return this.state},e.prototype.failIfTransitionOngoing=function(){if(this.onGoingTransactionNewState!==k_.UNKNOWN)throw`Cannot transition to a new state, already under transition`},e.prototype.validateTransition=function(e){switch(this.state){case k_.UNKNOWN:throw`Transition from unknown is not allowed`;case k_.NOT_STARTED:this.failIfNewStateIs(e,[k_.PAUSED]);break;case k_.SCANNING:break;case k_.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}(),j_=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()===k_.NOT_STARTED},e.prototype.isScanning=function(){return this.stateManager.getState()!==k_.NOT_STARTED},e.prototype.isStrictlyScanning=function(){return this.stateManager.getState()===k_.SCANNING},e.prototype.isPaused=function(){return this.stateManager.getState()===k_.PAUSED},e}(),M_=function(){function e(){}return e.create=function(){return new j_(new A_)},e}(),N_=(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)}})(),P_=function(e){N_(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}(Jg),F_=function(){function e(e,t){this.logger=t,this.fps=P_.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=P_.DEFAULT_DISABLE_FLIP}return e.prototype.isMediaStreamConstraintsValid=function(){return this.videoConstraints?a_.isMediaStreamConstraintsValid(this.videoConstraints,this.logger):(this.logger.logError(`Empty videoConstraints`,!0),!1)},e.prototype.isShadedBoxEnabled=function(){return!e_(this.qrbox)},e.create=function(t,n){return new e(t,n)},e}(),I_=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 $g(this.verbose),this.qrcode=new p_(this.getSupportedFormats(t),this.getUseBarCodeDetectorIfSupported(n),this.verbose,this.logger),this.foreverScanTimeout,this.shouldScan=!0,this.stateManagerProxy=M_.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=F_.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:P_.DEFAULT_WIDTH,l.style.position=`relative`,this.shouldScan=!0,this.element=l;var u=this,d=this.stateManagerProxy.startTransition(k_.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)}};T_.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(n_.errorGettingUserMedia(e))})}).catch(function(e){d.cancel(),r(n_.cameraStreamingNotSupported())})})},e.prototype.pause=function(e){if(!this.stateManagerProxy.isStrictlyScanning())throw`Cannot pause, scanner is not scanning.`;this.stateManagerProxy.directTransition(k_.PAUSED),this.showPausedState(),(e_(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(k_.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(k_.NOT_STARTED);this.shouldScan=!1,this.foreverScanTimeout&&clearTimeout(this.foreverScanTimeout);var n=function(){if(e.element){var t=document.getElementById(P_.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(e_(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:P_.DEFAULT_WIDTH,l=Math.max(s.clientHeight?s.clientHeight:o,P_.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=P_.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(Xg.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 O_.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(!a_.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=[Ug.QR_CODE,Ug.AZTEC,Ug.CODABAR,Ug.CODE_39,Ug.CODE_93,Ug.CODE_128,Ug.DATA_MATRIX,Ug.MAXICODE,Ug.ITF,Ug.EAN_13,Ug.EAN_8,Ug.PDF_417,Ug.RSS_14,Ug.RSS_EXPANDED,Ug.UPC_A,Ug.UPC_E,Ug.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];Kg(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(e_(e))return!0;if(!e_(e.useBarCodeDetectorIfSupported))return e.useBarCodeDetectorIfSupported!==!1;if(e_(e.experimentalFeatures))return!0;var t=e.experimentalFeatures;return e_(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<P_.MIN_QR_BOX_SIZE)throw`minimum size of 'config.qrbox' dimension value is ${P_.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=e_(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=n_.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,Xg.createFromQrcodeResult(t)),n.possiblyUpdateShaders(!0),!0}).catch(function(e){n.possiblyUpdateShaders(!1);var r=n_.codeParseError(e);return t(r,Qg.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?P_.BORDER_SHADER_MATCH_COLOR:P_.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=e_(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=`${P_.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=P_.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}(),L_=`data:image/svg+xml;base64,`,R_=L_+`PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAzNzEuNjQzIDM3MS42NDMiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDM3MS42NDMgMzcxLjY0MyIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+PHBhdGggZD0iTTEwNS4wODQgMzguMjcxaDE2My43Njh2MjBIMTA1LjA4NHoiLz48cGF0aCBkPSJNMzExLjU5NiAxOTAuMTg5Yy03LjQ0MS05LjM0Ny0xOC40MDMtMTYuMjA2LTMyLjc0My0yMC41MjJWMzBjMC0xNi41NDItMTMuNDU4LTMwLTMwLTMwSDEyNS4wODRjLTE2LjU0MiAwLTMwIDEzLjQ1OC0zMCAzMHYxMjAuMTQzaC04LjI5NmMtMTYuNTQyIDAtMzAgMTMuNDU4LTMwIDMwdjEuMzMzYTI5LjgwNCAyOS44MDQgMCAwIDAgNC42MDMgMTUuOTM5Yy03LjM0IDUuNDc0LTEyLjEwMyAxNC4yMjEtMTIuMTAzIDI0LjA2MXYxLjMzM2MwIDkuODQgNC43NjMgMTguNTg3IDEyLjEwMyAyNC4wNjJhMjkuODEgMjkuODEgMCAwIDAtNC42MDMgMTUuOTM4djEuMzMzYzAgMTYuNTQyIDEzLjQ1OCAzMCAzMCAzMGg4LjMyNGMuNDI3IDExLjYzMSA3LjUwMyAyMS41ODcgMTcuNTM0IDI2LjE3Ny45MzEgMTAuNTAzIDQuMDg0IDMwLjE4NyAxNC43NjggNDUuNTM3YTkuOTg4IDkuOTg4IDAgMCAwIDguMjE2IDQuMjg4IDkuOTU4IDkuOTU4IDAgMCAwIDUuNzA0LTEuNzkzYzQuNTMzLTMuMTU1IDUuNjUtOS4zODggMi40OTUtMTMuOTIxLTYuNzk4LTkuNzY3LTkuNjAyLTIyLjYwOC0xMC43Ni0zMS40aDgyLjY4NWMuMjcyLjQxNC41NDUuODE4LjgxNSAxLjIxIDMuMTQyIDQuNTQxIDkuMzcyIDUuNjc5IDEzLjkxMyAyLjUzNCA0LjU0Mi0zLjE0MiA1LjY3Ny05LjM3MSAyLjUzNS0xMy45MTMtMTEuOTE5LTE3LjIyOS04Ljc4Ny0zNS44ODQgOS41ODEtNTcuMDEyIDMuMDY3LTIuNjUyIDEyLjMwNy0xMS43MzIgMTEuMjE3LTI0LjAzMy0uODI4LTkuMzQzLTcuMTA5LTE3LjE5NC0xOC42NjktMjMuMzM3YTkuODU3IDkuODU3IDAgMCAwLTEuMDYxLS40ODZjLS40NjYtLjE4Mi0xMS40MDMtNC41NzktOS43NDEtMTUuNzA2IDEuMDA3LTYuNzM3IDE0Ljc2OC04LjI3MyAyMy43NjYtNy42NjYgMjMuMTU2IDEuNTY5IDM5LjY5OCA3LjgwMyA0Ny44MzYgMTguMDI2IDUuNzUyIDcuMjI1IDcuNjA3IDE2LjYyMyA1LjY3MyAyOC43MzMtLjQxMyAyLjU4NS0uODI0IDUuMjQxLTEuMjQ1IDcuOTU5LTUuNzU2IDM3LjE5NC0xMi45MTkgODMuNDgzLTQ5Ljg3IDExNC42NjEtNC4yMjEgMy41NjEtNC43NTYgOS44Ny0xLjE5NCAxNC4wOTJhOS45OCA5Ljk4IDAgMCAwIDcuNjQ4IDMuNTUxIDkuOTU1IDkuOTU1IDAgMCAwIDYuNDQ0LTIuMzU4YzQyLjY3Mi0zNi4wMDUgNTAuODAyLTg4LjUzMyA1Ni43MzctMTI2Ljg4OC40MTUtMi42ODQuODIxLTUuMzA5IDEuMjI5LTcuODYzIDIuODM0LTE3LjcyMS0uNDU1LTMyLjY0MS05Ljc3Mi00NC4zNDV6bS0yMzIuMzA4IDQyLjYyYy01LjUxNCAwLTEwLTQuNDg2LTEwLTEwdi0xLjMzM2MwLTUuNTE0IDQuNDg2LTEwIDEwLTEwaDE1djIxLjMzM2gtMTV6bS0yLjUtNTIuNjY2YzAtNS41MTQgNC40ODYtMTAgMTAtMTBoNy41djIxLjMzM2gtNy41Yy01LjUxNCAwLTEwLTQuNDg2LTEwLTEwdi0xLjMzM3ptMTcuNSA5My45OTloLTcuNWMtNS41MTQgMC0xMC00LjQ4Ni0xMC0xMHYtMS4zMzNjMC01LjUxNCA0LjQ4Ni0xMCAxMC0xMGg3LjV2MjEuMzMzem0zMC43OTYgMjguODg3Yy01LjUxNCAwLTEwLTQuNDg2LTEwLTEwdi04LjI3MWg5MS40NTdjLS44NTEgNi42NjgtLjQzNyAxMi43ODcuNzMxIDE4LjI3MWgtODIuMTg4em03OS40ODItMTEzLjY5OGMtMy4xMjQgMjAuOTA2IDEyLjQyNyAzMy4xODQgMjEuNjI1IDM3LjA0IDUuNDQxIDIuOTY4IDcuNTUxIDUuNjQ3IDcuNzAxIDcuMTg4LjIxIDIuMTUtMi41NTMgNS42ODQtNC40NzcgNy4yNTEtLjQ4Mi4zNzgtLjkyOS44LTEuMzM1IDEuMjYxLTYuOTg3IDcuOTM2LTExLjk4MiAxNS41Mi0xNS40MzIgMjIuNjg4aC05Ny41NjRWMzBjMC01LjUxNCA0LjQ4Ni0xMCAxMC0xMGgxMjMuNzY5YzUuNTE0IDAgMTAgNC40ODYgMTAgMTB2MTM1LjU3OWMtMy4wMzItLjM4MS02LjE1LS42OTQtOS4zODktLjkxNC0yNS4xNTktMS42OTQtNDIuMzcgNy43NDgtNDQuODk4IDI0LjY2NnoiLz48cGF0aCBkPSJNMTc5LjEyOSA4My4xNjdoLTI0LjA2YTUgNSAwIDAgMC01IDV2MjQuMDYxYTUgNSAwIDAgMCA1IDVoMjQuMDZhNSA1IDAgMCAwIDUtNVY4OC4xNjdhNSA1IDAgMCAwLTUtNXpNMTcyLjYyOSAxNDIuODZoLTEyLjU2VjEzMC44YTUgNSAwIDEgMC0xMCAwdjE3LjA2MWE1IDUgMCAwIDAgNSA1aDE3LjU2YTUgNSAwIDEgMCAwLTEwLjAwMXpNMjE2LjU2OCA4My4xNjdoLTI0LjA2YTUgNSAwIDAgMC01IDV2MjQuMDYxYTUgNSAwIDAgMCA1IDVoMjQuMDZhNSA1IDAgMCAwIDUtNVY4OC4xNjdhNSA1IDAgMCAwLTUtNXptLTUgMjQuMDYxaC0xNC4wNlY5My4xNjdoMTQuMDZ2MTQuMDYxek0yMTEuNjY5IDEyNS45MzZIMTk3LjQxYTUgNSAwIDAgMC01IDV2MTQuMjU3YTUgNSAwIDAgMCA1IDVoMTQuMjU5YTUgNSAwIDAgMCA1LTV2LTE0LjI1N2E1IDUgMCAwIDAtNS01eiIvPjwvc3ZnPg==`,z_=L_+`PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA1OS4wMTggNTkuMDE4IiBzdHlsZT0iZW5hYmxlLWJhY2tncm91bmQ6bmV3IDAgMCA1OS4wMTggNTkuMDE4IiB4bWw6c3BhY2U9InByZXNlcnZlIj48cGF0aCBkPSJtNTguNzQxIDU0LjgwOS01Ljk2OS02LjI0NGExMC43NCAxMC43NCAwIDAgMCAyLjgyLTcuMjVjMC01Ljk1My00Ljg0My0xMC43OTYtMTAuNzk2LTEwLjc5NlMzNCAzNS4zNjEgMzQgNDEuMzE0IDM4Ljg0MyA1Mi4xMSA0NC43OTYgNTIuMTFjMi40NDEgMCA0LjY4OC0uODI0IDYuNDk5LTIuMTk2bDYuMDAxIDYuMjc3YS45OTguOTk4IDAgMCAwIDEuNDE0LjAzMiAxIDEgMCAwIDAgLjAzMS0xLjQxNHpNMzYgNDEuMzE0YzAtNC44NSAzLjk0Ni04Ljc5NiA4Ljc5Ni04Ljc5NnM4Ljc5NiAzLjk0NiA4Ljc5NiA4Ljc5Ni0zLjk0NiA4Ljc5Ni04Ljc5NiA4Ljc5NlMzNiA0Ni4xNjQgMzYgNDEuMzE0ek0xMC40MzEgMTYuMDg4YzAgMy4wNyAyLjQ5OCA1LjU2OCA1LjU2OSA1LjU2OHM1LjU2OS0yLjQ5OCA1LjU2OS01LjU2OGMwLTMuMDcxLTIuNDk4LTUuNTY5LTUuNTY5LTUuNTY5cy01LjU2OSAyLjQ5OC01LjU2OSA1LjU2OXptOS4xMzggMGMwIDEuOTY4LTEuNjAyIDMuNTY4LTMuNTY5IDMuNTY4cy0zLjU2OS0xLjYwMS0zLjU2OS0zLjU2OCAxLjYwMi0zLjU2OSAzLjU2OS0zLjU2OSAzLjU2OSAxLjYwMSAzLjU2OSAzLjU2OXoiLz48cGF0aCBkPSJtMzAuODgyIDI4Ljk4NyA5LjE4LTEwLjA1NCAxMS4yNjIgMTAuMzIzYTEgMSAwIDAgMCAxLjM1MS0xLjQ3NWwtMTItMTFhMSAxIDAgMCAwLTEuNDE0LjA2M2wtOS43OTQgMTAuNzI3LTQuNzQzLTQuNzQzYTEuMDAzIDEuMDAzIDAgMCAwLTEuMzY4LS4wNDRMNi4zMzkgMzcuNzY4YTEgMSAwIDEgMCAxLjMyMiAxLjUwMWwxNi4zMTMtMTQuMzYyIDcuMzE5IDcuMzE4YS45OTkuOTk5IDAgMSAwIDEuNDE0LTEuNDE0bC0xLjgyNS0xLjgyNHoiLz48cGF0aCBkPSJNMzAgNDYuNTE4SDJ2LTQyaDU0djI4YTEgMSAwIDEgMCAyIDB2LTI5YTEgMSAwIDAgMC0xLTFIMWExIDEgMCAwIDAtMSAxdjQ0YTEgMSAwIDAgMCAxIDFoMjlhMSAxIDAgMSAwIDAtMnoiLz48L3N2Zz4=`,B_=L_+`PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0NjAgNDYwIiBzdHlsZT0iZW5hYmxlLWJhY2tncm91bmQ6bmV3IDAgMCA0NjAgNDYwIiB4bWw6c3BhY2U9InByZXNlcnZlIj48cGF0aCBkPSJNMjMwIDBDMTAyLjk3NSAwIDAgMTAyLjk3NSAwIDIzMHMxMDIuOTc1IDIzMCAyMzAgMjMwIDIzMC0xMDIuOTc0IDIzMC0yMzBTMzU3LjAyNSAwIDIzMCAwem0zOC4zMzMgMzc3LjM2YzAgOC42NzYtNy4wMzQgMTUuNzEtMTUuNzEgMTUuNzFoLTQzLjEwMWMtOC42NzYgMC0xNS43MS03LjAzNC0xNS43MS0xNS43MVYyMDIuNDc3YzAtOC42NzYgNy4wMzMtMTUuNzEgMTUuNzEtMTUuNzFoNDMuMTAxYzguNjc2IDAgMTUuNzEgNy4wMzMgMTUuNzEgMTUuNzFWMzc3LjM2ek0yMzAgMTU3Yy0yMS41MzkgMC0zOS0xNy40NjEtMzktMzlzMTcuNDYxLTM5IDM5LTM5IDM5IDE3LjQ2MSAzOSAzOS0xNy40NjEgMzktMzkgMzl6Ii8+PC9zdmc+`,V_=`data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAAQgAAAEIBarqQRAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAE1SURBVDiNfdI7S0NBEAXgLya1otFgpbYSbISAgpXYi6CmiH9KCAiChaVga6OiWPgfRDQ+0itaGVNosXtluWwcuMzePfM4M3sq8lbHBubwg1dc4m1E/J/N4ghDPOIsfk/4xiEao5KX0McFljN4C9d4QTPXuY99jP3DsIoDPGM6BY5i5yI5R7O4q+ImFkJY2DCh3cAH2klyB+9J1xUMMAG7eCh1a+Mr+k48b5diXrFVwwLuS+BJ9MfR7+G0FHOHhTHhnXNWS87VDF4pcnfQK4Ep7XScNLmPTZgURNKKYENYWDpzW1BhscS1WHS8CDgURFJQrWcoF3c13KKbgg1BYQfy8xZWEzTTw1QZbAoKu8FqJnktdu5hcVSHmchiILzzuaDQvjBzV2m8yohCE1jHfPx/xhU+y4G/D75ELlRJsSYAAAAASUVORK5CYII=`,H_=function(){function e(){}return e.createDefault=function(){return{hasPermission:!1,lastUsedCameraId:null}},e}(),U_=function(){function e(){this.data=H_.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=H_.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}(),W_=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=i_.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=i_.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}(),G_=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=B_,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=V_,this.infoIcon.style.opacity=`1`):(this.isShowingInfoIcon=!0,this.onTapOut(),this.infoIcon.src=B_,this.infoIcon.style.opacity=`0.6`)},e}(),K_=function(){function e(){var e=this;this.infoDiv=new W_,this.infoIcon=new G_(function(){e.infoDiv.show()},function(){e.infoDiv.hide()})}return e.prototype.renderInto=function(e){this.infoDiv.renderInto(e),this.infoIcon.renderInto(e)},e}(),q_=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())})},J_=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}}},Y_=function(){function e(){}return e.hasPermissions=function(){return q_(this,void 0,void 0,function(){var e,t,n,r;return J_(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}(),X_=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===qg.SCAN_TYPE_CAMERA},e.isFileScanType=function(e){return e===qg.SCAN_TYPE_FILE},e.prototype.validateAndReturnScanTypes=function(e){if(!e||e.length===0)return Jg.DEFAULT_SUPPORTED_SCAN_TYPE;var t=Jg.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(!Jg.DEFAULT_SUPPORTED_SCAN_TYPE.includes(i))throw`Unsupported scan type ${i}`}return e},e}(),Z_=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}(),Q_=function(){function e(){}return e.createElement=function(e,t){var n=document.createElement(e);return n.id=t,n.classList.add(Z_.ALL_ELEMENT_CLASS),e===`button`&&n.setAttribute(`type`,`button`),n},e}(),$_=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())})},ev=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}}},tv=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 $_(this,void 0,void 0,function(){var e,t;return ev(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?r_.torchOffButton():r_.torchOnButton()),this.isTorchOn=t):this.propagateFailure(t),this.buttonController.enable()},e.prototype.propagateFailure=function(e,t){var n=e?r_.torchOnFailedMessage():r_.torchOffFailedMessage();t&&(n+=`; Error = `+t),this.onTorchActionFailureCallback(n)},e.prototype.reset=function(){this.isTorchOn=!1},e}(),nv=function(){function e(e,t){this.onTorchActionFailureCallback=t,this.torchButton=Q_.createElement(`button`,Z_.TORCH_BUTTON_ID),this.torchController=new tv(e,this,t)}return e.prototype.render=function(e,t){var n=this;this.torchButton.innerText=r_.torchOnButton(),this.torchButton.style.display=t.display,this.torchButton.style.marginLeft=t.marginLeft;var r=this;this.torchButton.addEventListener(`click`,function(e){return $_(n,void 0,void 0,function(){return ev(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(Z_.TORCH_BUTTON_CLASS_TORCH_OFF),r.torchButton.classList.add(Z_.TORCH_BUTTON_CLASS_TORCH_ON)):(r.torchButton.classList.remove(Z_.TORCH_BUTTON_CLASS_TORCH_ON),r.torchButton.classList.add(Z_.TORCH_BUTTON_CLASS_TORCH_OFF)),[2]}})})}),e.appendChild(this.torchButton)},e.prototype.updateTorchCapability=function(e){this.torchController=new tv(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=r_.torchOnButton(),this.torchController.reset()},e.create=function(t,n,r,i){var a=new e(n,i);return a.render(t,r),a},e}(),rv=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=Q_.createElement(`button`,Z_.FILE_SELECTION_BUTTON_ID),this.setInitialValueToButton(),this.fileSelectionButton.addEventListener(`click`,function(e){r.click()}),r.append(this.fileSelectionButton),this.fileScanInput=Q_.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=r_.dragAndDropMessage();break}}o||(a.innerText=r_.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=r_.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=r_.fileSelectionChooseAnother()+` - `+e;this.fileSelectionButton.innerText=r},e.prototype.setInitialValueToButton=function(){var e=r_.fileSelectionChooseImage()+` - `+r_.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}(),iv=function(){function e(e){this.selectElement=Q_.createElement(`select`,Z_.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=`${r_.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=[r_.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}(),av=function(){function e(){this.onChangeCallback=null,this.zoomElementContainer=document.createElement(`div`),this.rangeInput=Q_.createElement(`input`,Z_.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=r_.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=r_.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}(),ov;(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`})(ov||={});function sv(e){return{fps:e.fps,qrbox:e.qrbox,aspectRatio:e.aspectRatio,disableFlip:e.disableFlip,videoConstraints:e.videoConstraints}}function cv(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 X_(this.config.supportedScanTypes),this.currentScanType=this.scanTypeSelector.getDefaultScanType(),this.sectionSwapAllowed=!0,this.logger=new $g(this.verbose),this.persistedDataManager=new U_,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(r_.lastMatch(t),ov.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 I_(this.getScanRegionId(),cv(this.config,this.verbose))},e.prototype.pause=function(e){(e_(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||=Jg.SCAN_DEFAULT_FPS,e.rememberLastUsedCamera!==!Jg.DEFAULT_REMEMBER_LAST_CAMERA_USED&&(e.rememberLastUsedCamera=Jg.DEFAULT_REMEMBER_LAST_CAMERA_USED),e.supportedScanTypes||=Jg.DEFAULT_SUPPORTED_SCAN_TYPE,e):{fps:Jg.SCAN_DEFAULT_FPS,rememberLastUsedCamera:Jg.DEFAULT_REMEMBER_LAST_CAMERA_USED,supportedScanTypes:Jg.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),X_.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 K_().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(r_.cameraPermissionRequesting());var i=function(){n||r.createPermissionButton(e,t)};I_.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(r_.noCameraFound(),ov.STATUS_WARNING),i())}).catch(function(e){r.persistedDataManager.setHasPermission(!1),n?n.disabled=!1:i(),r.setHeaderMessage(e,ov.STATUS_WARNING),r.showHideScanTypeSwapLink(!0)})},e.prototype.createPermissionButton=function(e,t){var n=this,r=Q_.createElement(`button`,this.getCameraPermissionButtonId());r.innerText=r_.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(X_.isCameraScanType(this.currentScanType)&&this.persistedDataManager.hasCameraPermissions()){Y_.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=X_.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=X_.isFileScanType(this.currentScanType),n=this,r=function(e){if(!n.html5Qrcode)throw`html5Qrcode not defined`;X_.isFileScanType(n.currentScanType)&&(n.setHeaderMessage(r_.loadingImage()),n.html5Qrcode.scanFileV2(e,!0).then(function(e){n.resetHeaderMessage(),n.qrCodeSuccessCallback(e.decodedText,e)}).catch(function(e){n.setHeaderMessage(e,ov.STATUS_WARNING),n.qrCodeErrorCallback(e,Qg.createFrom(e))}))};this.fileSelectionUi=rv.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=av.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=t_(r,n.min(),n.max()),i.setValues(n.min(),n.max(),r,n.step()),i.show()}},o=iv.create(r,e),s=document.createElement(`span`),c=Q_.createElement(`button`,Z_.CAMERA_START_BUTTON_ID);c.innerText=r_.scanButtonStartScanningText(),s.appendChild(c);var l=Q_.createElement(`button`,Z_.CAMERA_STOP_BUTTON_ID);l.innerText=r_.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=nv.create(s,e.torchFeature(),{display:`none`,marginLeft:`5px`},function(e){n.setHeaderMessage(e,ov.STATUS_WARNING)}),u.show()};r.appendChild(s);var f=function(e){e||(c.style.display=`none`),c.innerText=r_.scanButtonStartScanningText(),c.style.opacity=`1`,c.disabled=!1,e&&(c.style.display=`inline-block`)};if(c.addEventListener(`click`,function(e){c.innerText=r_.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,sv(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,ov.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,ov.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=r_.textIfCameraScanSelected(),n=r_.textIfFileScanSelected(),r=document.getElementById(this.getDashboardSectionId()),i=document.createElement(`div`);i.style.textAlign=`center`;var a=Q_.createElement(`span`,this.getDashboardSectionSwapLinkId());a.style.textDecoration=`underline`,a.style.cursor=`pointer`,a.innerText=X_.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,X_.isCameraScanType(e.currentScanType)?(e.clearScanRegion(),e.getCameraScanRegion().style.display=`none`,e.fileSelectionUi.show(),a.innerText=n,e.currentScanType=qg.SCAN_TYPE_FILE,e.insertFileScanImageToScanRegion()):(e.clearScanRegion(),e.getCameraScanRegion().style.display=`block`,e.fileSelectionUi.hide(),a.innerText=t,e.currentScanType=qg.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()){Y_.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||=ov.STATUS_DEFAULT;var n=this.getHeaderMessageDiv();switch(n.innerText=e,n.style.display=`block`,t){case ov.STATUS_SUCCESS:n.style.background=`rgba(106, 175, 80, 0.26)`,n.style.color=`#477735`;break;case ov.STATUS_WARNING:n.style.background=`rgba(203, 36, 49, 0.14)`,n.style.color=`#cb2431`;break;case ov.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=R_,this.cameraScanImage.alt=r_.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=z_,this.fileScanImage.alt=r_.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 Z_.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 Z_.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 lv;(function(e){e[e.BACK=1]=`BACK`,e[e.FRONT=2]=`FRONT`})(lv||={});var uv;(function(e){e[e.PORTRAIT=1]=`PORTRAIT`,e[e.LANDSCAPE=2]=`LANDSCAPE`,e[e.ADAPTIVE=3]=`ADAPTIVE`})(uv||={});var dv;(function(e){e[e.ALL=17]=`ALL`})(dv||={});var fv=Object.assign(Object.assign({},Ug),dv),pv;(function(e){e.ZXING=`zxing`,e.MLKIT=`mlkit`})(pv||={});var mv=[{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 hv(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 gv=oh(`CapacitorBarcodeScanner`,{web:()=>(hv(mv),Xr(()=>import(`./web-BWAZk7ug.js`).then(e=>new e.CapacitorBarcodeScannerWeb),[]))}),_v=class{static async scanBarcode(e){return e.scanInstructions=e.scanInstructions||` `,e.scanButton=e.scanButton||!1,e.scanText=e.scanText||` `,e.cameraDirection=e.cameraDirection||lv.BACK,e.scanOrientation=e.scanOrientation||uv.ADAPTIVE,gv.scanBarcode(e)}};function vv(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 yv(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 bv(){let[e,t]=(0,Y.useState)(!1);return{scan:(0,Y.useCallback)(async()=>{if(!at())return{value:null,error:null};t(!0);try{let e=await _v.scanBarcode({hint:fv.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 yv(e)?{value:null,error:null}:vv(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:at()}}function xv(){let[e,t]=(0,Y.useState)(!0),[n,r]=(0,Y.useState)(Xt),[i,a]=(0,Y.useState)(null),[o,c]=(0,Y.useState)(null),[l,u]=(0,Y.useState)(!1),d=bv();(0,Y.useEffect)(()=>{let e=!0;return(async()=>{try{let n=await fetch(`${Ke()}/health`,{method:`GET`});e&&t(n.ok)}catch{e&&t(!1)}})(),()=>{e=!1}},[]);let f=(0,Y.useCallback)(async()=>{let e=bt(n);if(e){a(null),u(!0);try{if(!await en(e)){a(e);return}xn(n)}finally{u(!1)}}},[n]),p=(0,Y.useCallback)(async()=>{c(null);let e=await d.scan();if(e.error){c(e.error);return}if(e.value){r(e.value),a(null);let t=bt(e.value);if(!t){c(`The scanned QR code did not contain a valid server address.`);return}u(!0);try{if(!await en(t)){a(t);return}xn(e.value)}finally{u(!1)}}},[d]);return e?null:(0,$.jsx)(ri,{open:!0,children:(0,$.jsxs)(oi,{children:[(0,$.jsxs)(ii,{children:[(0,$.jsx)(`img`,{src:`/tarsk-color.svg`,alt:`Tarsk`,className:`mx-auto h-16 w-16 rounded-lg`}),(0,$.jsx)($r,{children:`Connect to Tarsk`}),(0,$.jsx)(ti,{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)(un,{value:n,onChange:e=>{r(e.target.value),a(null),c(null)},onKeyDown:e=>{e.key===`Enter`&&!l&&f()},placeholder:`192.168.1.100`,autoComplete:`off`,spellCheck:!1,disabled:l,className:d.isAvailable?`pr-10`:void 0}),d.isAvailable&&(0,$.jsx)(s,{type:`button`,variant:`ghost`,size:`icon`,className:`absolute right-1 top-1 h-8 w-8`,"aria-label":`Scan QR code`,disabled:l||d.isScanning,onClick:()=>void p(),children:d.isScanning?(0,$.jsx)(wn,{className:`h-4 w-4 animate-spin`}):(0,$.jsx)(ae,{className:`h-4 w-4`})})]}),o&&(0,$.jsxs)(di,{variant:`error`,className:`mb-0 flex items-start gap-3`,children:[(0,$.jsx)(`p`,{className:`flex-1`,children:o}),(0,$.jsx)(s,{type:`button`,variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0`,"aria-label":`Dismiss error`,onClick:()=>c(null),children:(0,$.jsx)(zn,{className:`h-4 w-4`})})]}),i&&(0,$.jsxs)(di,{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)(s,{type:`button`,variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0`,"aria-label":`Dismiss error`,onClick:()=>a(null),children:(0,$.jsx)(zn,{className:`h-4 w-4`})})]}),(0,$.jsx)(ni,{children:(0,$.jsx)(s,{onClick:()=>void f(),disabled:!n.trim()||l,children:l?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(wn,{className:`mr-2 h-4 w-4 animate-spin`}),`Connecting...`]}):`Connect`})}),(0,$.jsxs)(di,{variant:`hint`,className:`mb-0`,children:[(0,$.jsx)(`p`,{className:W.bodyMuted,children:`Start the Tarsk server on your local machine by running:`}),(0,$.jsx)(`code`,{className:z(W.mono,`mt-2 block rounded bg-background/60 px-2 py-1 text-foreground`),children:`npx tarsk --server`})]})]})})}var Sv=(0,Y.lazy)(()=>Xr(()=>import(`./dialogs-config-BEazgV7k.js`).then(e=>e.t),__vite__mapDeps([3,1]))),Cv=(0,Y.lazy)(()=>Xr(()=>import(`./onboarding-Bi5MieW-.js`).then(e=>e.t),__vite__mapDeps([4,1,5,3])));function wv(e){let t=(0,X.c)(28),{showCreateProject:n,onCreateProjectOpenChange:r,onSubmitClone:i,onSubmitWebApp:a,onSubmitFolder:o,onOpenFolder:s,deleteProject:c,onDeleteProjectOpenChange:l,onConfirmDeleteProject:u,pendingSetupScriptConfirmation:d,onResolveSetupScriptConfirmation:f,showOnboarding:p,onOnboardingOpenChange:m,onOnboardingComplete:h}=e,g;t[0]!==r||t[1]!==s||t[2]!==i||t[3]!==o||t[4]!==a||t[5]!==n?(g=(0,$.jsx)(Y.Suspense,{fallback:null,children:(0,$.jsx)(Sv,{open:n,onOpenChange:r,onSubmitClone:i,onSubmitWebApp:a,onSubmitFolder:o,onOpenFolder:s})}),t[0]=r,t[1]=s,t[2]=i,t[3]=o,t[4]=a,t[5]=n,t[6]=g):g=t[6];let _=c!==null,v=c?.name,y;t[7]!==u||t[8]!==l||t[9]!==_||t[10]!==v?(y=(0,$.jsx)(Bg,{open:_,projectName:v,onOpenChange:l,onConfirm:u}),t[7]=u,t[8]=l,t[9]=_,t[10]=v,t[11]=y):y=t[11];let b=d!==null,x;t[12]===d?x=t[13]:(x=d?[d.command,...d.remainingScripts||[]]:[],t[12]=d,t[13]=x);let S;t[14]!==f||t[15]!==b||t[16]!==x?(S=(0,$.jsx)(Vg,{open:b,setupScripts:x,onConfirm:f}),t[14]=f,t[15]=b,t[16]=x,t[17]=S):S=t[17];let C;t[18]!==h||t[19]!==m||t[20]!==p?(C=(0,$.jsx)(Y.Suspense,{fallback:null,children:(0,$.jsx)(Cv,{open:p,onOpenChange:m,onComplete:h})}),t[18]=h,t[19]=m,t[20]=p,t[21]=C):C=t[21];let w;t[22]===Symbol.for(`react.memo_cache_sentinel`)?(w=(0,$.jsx)(xv,{}),t[22]=w):w=t[22];let T;return t[23]!==g||t[24]!==y||t[25]!==S||t[26]!==C?(T=(0,$.jsxs)($.Fragment,{children:[g,y,S,C,w]}),t[23]=g,t[24]=y,t[25]=S,t[26]=C,t[27]=T):T=t[27],T}var Tv=(0,Y.createContext)(null);function Ev(e){let t=(0,X.c)(7),{children:n}=e,[r,i]=(0,Y.useState)(0),[a,o]=(0,Y.useState)(`desktop`),s;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(s=()=>{i(Dv)},t[0]=s):s=t[0];let c=s,l;t[1]!==a||t[2]!==r?(l={browserResetTrigger:r,triggerBrowserReset:c,browserDeviceMode:a,setBrowserDeviceMode:o},t[1]=a,t[2]=r,t[3]=l):l=t[3];let u=l,d;return t[4]!==n||t[5]!==u?(d=(0,$.jsx)(Tv.Provider,{value:u,children:n}),t[4]=n,t[5]=u,t[6]=d):d=t[6],d}function Dv(e){return e+1}function Ov(){let e=(0,Y.useContext)(Tv);if(!e)throw Error(`useBrowserTab must be used within a BrowserTabProvider`);return e}function kv(e){let t=e.trim();return t?t.startsWith(`http://`)||t.startsWith(`https://`)?t:`http://${t}`:``}function Av(){return document.querySelector(`electrobun-webview`)}function jv(e=2e4){return new Promise((t,n)=>{let r=Date.now();function i(){let a=Av();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 Mv(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 Nv(e){let t=Date.now();function n(){if(Date.now()-t>2e4){console.error(`[browser-tool] timed out waiting for preview webview to mount (${e})`);return}let r=Av();if(!r||r.webviewId==null){requestAnimationFrame(n);return}qm(e,r.webviewId).catch(e=>{console.error(`[browser-tool] failed to report preview webview ready`,e)})}requestAnimationFrame(n)}async function Pv(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 jv();t.syncDimensions(!0),await Jm(r,{action:`set_viewport`,preset:e,webview_id:t.webviewId})}catch(t){console.error(`[browser-tool] failed to set viewport`,t),await Jm(r,{action:`set_viewport`,preset:e,error:t instanceof Error?t.message:String(t)})}return}if(Un(i.action)){try{await Jm(r,await Mv(await jv(),i,t))}catch(e){console.error(`[browser-tool] failed to execute host browser action`,e),await Jm(r,{action:i.action,error:e instanceof Error?e.message:String(e)})}return}Nv(r)}}function Fv(){let{activeMainTab:e,setActiveMainTab:t}=Ks(),{setDevServerUrl:n,devServerUrl:r}=ed(),{setBrowserDeviceMode:i}=Ov(),a=(0,Y.useRef)(null),o=Q(e=>{let t=a.current;return t?e.threadStreamingStates[Li(t,`primary`)]?.isStreaming??!1:!1}),s=(0,Y.useRef)(r);s.current=r;let c=(0,Y.useRef)(e);c.current=e;let l=(0,Y.useRef)(t);l.current=t;let u=(0,Y.useRef)(n);u.current=n;let d=(0,Y.useRef)(i);d.current=i;let f=(0,Y.useRef)(!1),p=(0,Y.useRef)(!1);(0,Y.useEffect)(()=>{if(f.current){f.current=!1;return}a.current&&e!==`browser`&&(a.current=null)},[e]),(0,Y.useEffect)(()=>{if(!a.current){p.current=!1;return}let e=p.current;p.current=o,!(!e||o)&&(a.current=null,f.current=!0,l.current(`chat`))},[o]),(0,Y.useEffect)(()=>{function e(e){let t=e.detail;t?.threadId&&a.current===t.threadId&&(a.current=null,f.current=!0,l.current(`chat`))}return window.addEventListener(Bm,e),function(){window.removeEventListener(Bm,e)}},[]),(0,Y.useEffect)(()=>{if(!Ve())return;function e(e){let t=e.detail;if(!t?.toolCallId||!t.input?.action)return;c.current===`chat`&&t.threadId&&(a.current=t.threadId,p.current=!0),f.current=!0,l.current(`browser`);let n=t.input.url?.trim()||s.current||``;if(n){let e=kv(n);e&&u.current(e)}Pv(t,s.current||``,d.current)}return window.addEventListener(zm,e),function(){window.removeEventListener(zm,e)}},[])}var Iv=or,Lv=Y.forwardRef((e,t)=>{let n=(0,X.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=z(`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)(Yn,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});Lv.displayName=Yn.displayName;var Rv=F(`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`}}),zv=Y.forwardRef((e,t)=>{let n=(0,X.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=z(Rv({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)(mr,{ref:t,className:o,...i}),n[7]=i,n[8]=t,n[9]=o,n[10]=s):s=n[10],s});zv.displayName=mr.displayName;var Bv=Y.forwardRef((e,t)=>{let n=(0,X.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=z(`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`,W.body,r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,$.jsx)(dr,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});Bv.displayName=dr.displayName;var Vv=Y.forwardRef((e,t)=>{let n=(0,X.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=z(`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)(zn,{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)($n,{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});Vv.displayName=$n.displayName;var Hv=Y.forwardRef((e,t)=>{let n=(0,X.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=z(W.dialogTitle,r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,$.jsx)(Yr,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});Hv.displayName=Yr.displayName;var Uv=Y.forwardRef((e,t)=>{let n=(0,X.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=z(W.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)(rr,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});Uv.displayName=rr.displayName;function Wv(){let e=(0,X.c)(5),{toasts:t}=$a(),n;e[0]===t?n=e[1]:(n=t.map(Gv),e[0]=t,e[1]=n);let r;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(r=(0,$.jsx)(Lv,{}),e[2]=r):r=e[2];let i;return e[3]===n?i=e[4]:(i=(0,$.jsxs)(Iv,{duration:1e4,children:[n,r]}),e[3]=n,e[4]=i),i}function Gv(e){let{id:t,title:n,description:r,action:i,...a}=e;return(0,$.jsxs)(zv,{...a,children:[(0,$.jsxs)(`div`,{className:`grid gap-1`,children:[n&&(0,$.jsx)(Hv,{children:n}),r&&(0,$.jsx)(Uv,{children:r})]}),i,(0,$.jsx)(Vv,{})]},t)}function Kv(){return new ki({defaultOptions:{queries:{staleTime:3e4,retry:1,refetchOnWindowFocus:!0},mutations:{retry:0}}})}function qv(e){let t=(0,X.c)(3),{children:n}=e,[r]=(0,Y.useState)(Kv),i;return t[0]!==n||t[1]!==r?(i=(0,$.jsx)(Dr,{client:r,children:n}),t[0]=n,t[1]=r,t[2]=i):i=t[2],i}function Jv(){let e=(0,X.c)(4),{resolvedTheme:t,theme:n}=Si(),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,Y.useEffect)(r,i),null}function Yv(e){let t=(0,X.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)(Jv,{}),t[3]=i):i=t[3];let a;return t[4]!==n||t[5]!==r?(a=(0,$.jsxs)(Ci,{...r,children:[i,n]}),t[4]=n,t[5]=r,t[6]=a):a=t[6],a}async function Xv(e,t){let n=e.getReader(),r=new TextDecoder,i=``;try{for(;;){let{done:e,value:a}=await n.read();if(e)break;i+=r.decode(a,{stream:!0});let o=i.split(`
|
|
71
|
-
`);i=o.pop()??``;for(let e of o){let n=e.trim();if(n)try{await t(JSON.parse(n),n)}catch{await t(n,n)}}}if(i.trim())try{await t(JSON.parse(i),i)}catch{await t(i,i)}}finally{n.releaseLock()}}async function Zv(e,t){await Xv(e,e=>{if(typeof e==`string`){t.onOutput(e);return}if(!e||typeof e!=`object`)return;let n=e;n.type===`error`&&typeof n.message==`string`&&t.onError(n.message)})}function Qv(){let e=(0,X.c)(14),t=Ia(),n=Q(ty),r=ai(`projects:bootstrap:${Q(ey)}`,w),i;e[0]!==r.projects||e[1]!==t?(i=()=>{t({type:Z.SetProjects,projects:r.projects}),t({type:Z.SetProjectsLoading,projectsLoading:!1})},e[0]=r.projects,e[1]=t,e[2]=i):i=e[2];let a;e[3]!==r||e[4]!==t?(a=[r,t],e[3]=r,e[4]=t,e[5]=a):a=e[5],(0,Y.useLayoutEffect)(i,a);let o;e[6]!==r.projects||e[7]!==t||e[8]!==n?(o=()=>{if(!n)for(let e of r.projects){let n=e.threads.find($v);if(n){t({type:Z.SelectThread,threadId:n.threadId,projectId:e.projectId});break}}},e[6]=r.projects,e[7]=t,e[8]=n,e[9]=o):o=e[9];let s;return e[10]!==r||e[11]!==t||e[12]!==n?(s=[r,t,n],e[10]=r,e[11]=t,e[12]=n,e[13]=s):s=e[13],(0,Y.useLayoutEffect)(o,s),null}function $v(e){return e.isSelected}function ey(e){return e.configUpdatedAt}function ty(e){return e.selectedThreadId}function ny(e){let t=Ia(),n=Q(e=>e.projects),r=Q(e=>e.selectedProjectId),i=Q(e=>e.selectedThreadId),{toast:a}=$a(),o=La(`project-creation`).dispatch,[s,c]=(0,Y.useState)(null),l=(0,Y.useCallback)(async()=>{try{t({type:Z.SetProjectsLoading,projectsLoading:!0}),yn(),li(`projects:bootstrap:`);let e=await w();t({type:Z.SetProjects,projects:e.projects})}catch(e){console.error(`Failed to refresh projects:`,e)}finally{t({type:Z.SetProjectsLoading,projectsLoading:!1})}},[t]),u=(0,Y.useCallback)((e,n)=>{(i!==n||r!==e)&&t({type:Z.SelectThread,threadId:n,projectId:e}),ke(e,n).catch(e=>{console.error(`Failed to select thread:`,e)})},[t,i,r]),d=(0,Y.useCallback)(async n=>{t({type:Z.SetCreatingProject,isCreating:!0});try{let r=await n.apiCall();if(!r){t({type:Z.SetCreatingProject,isCreating:!1}),await l();return}let i=n.useTerminalDispatch?o:t;i({type:Z.ClearTerminalOutput}),i({type:Z.SetTerminalOpen,open:!0}),i({type:Z.AppendTerminalLine,line:{type:`system`,content:n.initialMessage}});let a=r.getReader(),s=new TextDecoder,u=``,d=null,f=!1,p=null,m=null;for(;;){let{done:e,value:r}=await a.read();if(e)break;u+=s.decode(r,{stream:!0});let o=u.split(`
|
|
72
|
-
`);u=o.pop()??``;for(let e of o){let r=e.trim();if(r)try{let e=JSON.parse(r);if(e.type===`progress`)!f&&e.threadId&&e.projectId&&(f=!0,p=e.projectId,m=e.threadId,t({type:Z.AddCreatingProject,projectId:e.projectId,threadId:e.threadId,projectName:n.optimisticProjectName,gitUrl:n.gitUrl??``}),t({type:Z.AddProcessingThread,threadId:e.threadId})),t({type:Z.AppendTerminalLine,...n.useTerminalDispatch?{threadId:m??`project-creation`}:{},line:{type:`output`,content:e.message}});else if(e.type===`complete`){if(e.project){d=e.project.id;let r=n.includeThreadPath&&e.project.threads?.length>0?`${e.project.path}/${e.project.threads[0]}`:e.project.path;i({type:Z.AppendTerminalLine,line:{type:`system`,content:`Project created successfully at: ${r}`}}),t({type:Z.SetTerminalOpen,open:!1}),n.handleSetupScript&&e.suggestedSetupScript&&c({projectId:e.project.id,command:e.suggestedSetupScript,remainingScripts:e.project.pendingSetupScripts??[]})}}else e.type===`error`&&(f&&p&&(t({type:Z.RemoveCreatingProject,projectId:p}),m&&t({type:Z.RemoveProcessingThread,threadId:m})),t({type:Z.AppendTerminalLine,...n.useTerminalDispatch?{threadId:m??`project-creation`}:{},line:{type:`error`,content:`Error: ${e.message}`}}))}catch(e){console.error(`Failed to parse ${n.logTag} event`,e)}}}t({type:Z.SetCreatingProject,isCreating:!1}),f&&m&&t({type:Z.RemoveProcessingThread,threadId:m}),yn();let h=await w();if(t({type:Z.SetProjects,projects:h.projects}),t({type:Z.SetProjectsLoading,projectsLoading:!1}),d){let n=h.projects.find(e=>e.projectId===d);if(n&&n.threads.length>0){let e=n.threads[0].threadId;t({type:Z.SelectThread,threadId:e,projectId:d,focusInput:!0})}e?.onProjectCreated?.(d)}}catch(e){console.error(`Failed to ${n.logTag}:`,e),t({type:Z.SetCreatingProject,isCreating:!1}),(n.useTerminalDispatch?o:t)({type:Z.AppendTerminalLine,line:{type:`error`,content:`${n.catchErrorPrefix}: ${e instanceof Error?e.message:`Unknown error`}`}})}},[t,l,o,e?.onProjectCreated]),f=(0,Y.useCallback)(async(e,t)=>{let n=e.split(`/`).pop()?.replace(`.git`,``)??`project`;await d({apiCall:()=>An(e,t),initialMessage:`Cloning repository: ${e}...`,optimisticProjectName:n,gitUrl:e,useTerminalDispatch:!0,includeThreadPath:!0,handleSetupScript:!0,logTag:`create project`,catchErrorPrefix:`Failed to create project`})},[d]),p=(0,Y.useCallback)(async(e,t,n)=>{await d({apiCall:()=>Ae(e,t,n),initialMessage:`Creating app "${e}"...`,optimisticProjectName:e,useTerminalDispatch:!0,handleSetupScript:!1,logTag:`create web app`,catchErrorPrefix:`Failed to create web app`})},[d]),m=(0,Y.useCallback)(async e=>{await d({apiCall:()=>In(e),initialMessage:`Creating folder "${e}"...`,optimisticProjectName:e,useTerminalDispatch:!0,handleSetupScript:!1,logTag:`create folder`,catchErrorPrefix:`Failed to create folder`})},[d]),h=(0,Y.useCallback)(async(e,r)=>{try{let i=r??(()=>{let t=n.find(t=>t.projectId===e)?.threads.map(e=>e.title)??[],r=/^thread-(\d+)$/i,i=0;for(let e of t){let t=e.match(r);t&&(i=Math.max(i,parseInt(t[1],10)))}return`thread-${i+1}`})(),o=await g(e,r);if(!o){await l();return}let s=o.getReader(),c=new TextDecoder,u=``,d=!1,f=null,p=!0,m=[{type:`system`,content:`Creating thread "${i}"...`}];try{for(;;){let{done:n,value:r}=await s.read();if(n)break;u+=c.decode(r,{stream:!0});let o=u.split(`
|
|
73
|
-
`);u=o.pop()??``;for(let n of o){let r=n.trim();if(r)try{let n=JSON.parse(r);if(n.type===`progress`){if(!d&&n.threadId){d=!0,f=n.threadId,t({type:Z.AddCreatingThread,projectId:e,threadId:n.threadId,title:i}),t({type:Z.AddProcessingThread,threadId:n.threadId}),t({type:Z.ClearTerminalOutput,threadId:f});for(let e of m)t({type:Z.AppendTerminalLine,threadId:f,line:e});m.length=0}let r={type:`output`,content:n.message};f?t({type:Z.AppendTerminalLine,threadId:f,line:r}):m.push(r)}else if(n.type===`error`){d&&f&&(t({type:Z.RemoveCreatingThread,projectId:e,threadId:f}),t({type:Z.RemoveProcessingThread,threadId:f}));let r={type:`error`,content:`Error: ${n.message}`};f?t({type:Z.AppendTerminalLine,threadId:f,line:r}):m.push(r),console.error(`Thread creation error:`,n.message),a({title:`Thread Creation Failed`,description:n.message,variant:`destructive`}),p=!1}}catch(e){console.error(`Failed to parse thread event`,e)}}}d&&f&&t({type:Z.RemoveProcessingThread,threadId:f}),yn(),await l(),f&&p&&t({type:Z.SelectThread,threadId:f,projectId:e,focusInput:!0})}catch(n){throw d&&f&&(t({type:Z.RemoveCreatingThread,projectId:e,threadId:f}),t({type:Z.RemoveProcessingThread,threadId:f})),a({title:`Thread Creation Failed`,description:n instanceof Error?n.message:String(n),variant:`destructive`}),n}}catch(e){console.error(`Failed to create thread:`,e);let n=`Failed to create thread: ${e instanceof Error?e.message:`Unknown error`}`;throw t({type:Z.AppendTerminalLine,line:{type:`error`,content:n}}),a({variant:`destructive`,title:`Thread Creation Failed`,description:n}),e}},[l,t,n,a]),_=(0,Y.useCallback)(async(e,n)=>{t({type:Z.AddDeletingThread,threadId:n}),t({type:Z.ClearChatInputDraft,threadId:n});try{await ce(e,n),i===n&&t({type:Z.SelectThread,threadId:``,projectId:``}),await l(),t({type:Z.ConfigUpdated})}catch(e){console.error(`Failed to delete thread:`,e),a({variant:`destructive`,title:`Failed to delete thread`,description:e instanceof Error?e.message:`Unknown error`})}finally{t({type:Z.RemoveDeletingThread,threadId:n})}},[l,i,t,a]),v=(0,Y.useCallback)(async e=>{t({type:Z.AddDeletingProject,projectId:e});let i=n.find(t=>t.projectId===e)?.threads.map(e=>e.threadId)??[];for(let e of i)t({type:Z.AddDeletingThread,threadId:e}),t({type:Z.ClearChatInputDraft,threadId:e});try{await de(e),r===e&&t({type:Z.SelectThread,threadId:``,projectId:``}),await l(),t({type:Z.ConfigUpdated})}catch(e){console.error(`Failed to delete project:`,e)}finally{t({type:Z.RemoveDeletingProject,projectId:e});for(let e of i)t({type:Z.RemoveDeletingThread,threadId:e})}},[l,r,n,t]),y=(0,Y.useCallback)(async e=>{let n=s;if(c(null),!n||!e)return;let{projectId:r,command:i,remainingScripts:a}=n,o=[i,...a||[]];try{t({type:Z.SetCreatingProject,isCreating:!0}),t({type:Z.SetTerminalOpen,open:!0}),t({type:Z.AppendTerminalLine,line:{type:`system`,content:`Installing dependencies for ${o.length} package${o.length===1?``:`s`}...`}});for(let e=0;e<o.length;e++){let n=o[e],i=n.match(/^cd "([^"]+)" && (.+)$/),a=i?i[1]:`root`;t({type:Z.AppendTerminalLine,line:{type:`system`,content:`Installing package ${e+1}/${o.length} in ${a}...`}}),t({type:Z.AppendTerminalLine,line:{type:`output`,content:`📦 Installing dependencies in ${a}: ${n}`}});let s=await Wn(r,n,!0);s&&await Zv(s,{onOutput:e=>{t({type:Z.AppendTerminalLine,line:{type:`output`,content:e}})},onError:e=>{t({type:Z.AppendTerminalLine,line:{type:`error`,content:e}})}}),e<o.length-1&&(t({type:Z.AppendTerminalLine,line:{type:`system`,content:``}}),t({type:Z.AppendTerminalLine,line:{type:`system`,content:`---`}}),t({type:Z.AppendTerminalLine,line:{type:`system`,content:``}}))}t({type:Z.AppendTerminalLine,line:{type:`system`,content:`All dependencies installed successfully!`}}),t({type:Z.SetCreatingProject,isCreating:!1}),await l()}catch(e){t({type:Z.SetCreatingProject,isCreating:!1}),console.error(`Failed to run setup script:`,e),t({type:Z.AppendTerminalLine,line:{type:`error`,content:`Failed to run setup script: ${e instanceof Error?e.message:`Unknown error`}`}})}},[s,t,l]);return{projects:n,selectedProjectId:r,selectedThreadId:i,refreshProjects:l,handleSelectThread:u,handleCreateProject:f,handleCreateWebApp:p,handleCreateFolder:m,handleOpenFolder:(0,Y.useCallback)(async()=>{await d({apiCall:rt,initialMessage:`Opening folder...`,optimisticProjectName:`Opening folder...`,useTerminalDispatch:!0,handleSetupScript:!0,logTag:`open folder`,catchErrorPrefix:`Failed to open folder`})},[d]),handleCreateThread:h,handleDeleteThread:_,confirmDeleteProject:v,pendingSetupScriptConfirmation:s,resolveSetupScriptConfirmation:y}}function ry(){let e=(0,X.c)(2),[t,n]=(0,Y.useState)(iy),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,Y.useEffect)(r,i),t}function iy(){return document.hasFocus()}var ay=null;function oy(){ay??=new Audio(`/pop.wav`),ay.currentTime=0,ay.play().catch(e=>{console.debug(`Could not play completion sound:`,e)})}function sy(){let e=Ia(),t=Fa(),n=Q(e=>e.processingThreadIds),r=Q(e=>e.completedThreadIds),i=ry(),a=(0,Y.useRef)(null),o=(0,Y.useRef)(!1),s=(0,Y.useRef)([]),c=(0,Y.useRef)(i);(0,Y.useEffect)(()=>{c.current=i},[i]);let l=(0,Y.useCallback)(async()=>{try{let n=eh(await G()),r=s.current.filter(e=>!n.includes(e));for(let n of r)n!==t.getState().selectedThreadId&&e({type:Z.MarkThreadCompleted,threadId:n});return r.length>0&&!c.current&&oy(),s.current=n,e({type:Z.SetProcessingThreads,threadIds:n}),n}catch(e){return console.error(`Failed to fetch processing threads:`,e),[]}},[e,t]);return(0,Y.useEffect)(()=>{let e=()=>{if(a.current||o.current)return;o.current=!0;let e=async()=>{let n=await l(),r=t.getState(),i=Object.values(r.threadStreamingStates).some(e=>e.isStreaming);n.length>0||i||r.isCreatingProject?a.current=setTimeout(e,1e3):(a.current=null,o.current=!1)};e()},n=()=>{a.current&&=(clearTimeout(a.current),null),o.current=!1};return e(),()=>{n()}},[l]),{processingThreadIds:n,completedThreadIds:r,isThreadProcessing:e=>n.includes(e),isThreadCompleted:e=>r.includes(e),clearCompleted:(0,Y.useCallback)(t=>{e({type:Z.ClearThreadCompleted,threadId:t})},[e])}}function cy(){let e=(0,X.c)(15),t=Ia(),[n,r]=(0,Y.useState)(!1),[i,a]=(0,Y.useState)(!1),o;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(o={queryKey:Od.onboarding.status(),queryFn:on,staleTime:1/0,retry:1},e[0]=o):o=e[0];let s=Wr(o),c;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(c={queryKey:Od.app.update(),queryFn:Wt,staleTime:1/0,retry:!1},e[1]=c):c=e[1];let l=Wr(c),u,d;e[2]!==s.data||e[3]!==s.isSuccess?(u=()=>{s.isSuccess&&!s.data.onboardingCompleted&&r(!0)},d=[s.isSuccess,s.data],e[2]=s.data,e[3]=s.isSuccess,e[4]=u,e[5]=d):(u=e[4],d=e[5]),(0,Y.useEffect)(u,d);let f,p;e[6]!==t||e[7]!==n?(f=()=>{n||t({type:Z.ConfigUpdated})},p=[n,t],e[6]=t,e[7]=n,e[8]=f,e[9]=p):(f=e[8],p=e[9]),(0,Y.useEffect)(f,p);let m;e[10]===Symbol.for(`react.memo_cache_sentinel`)?(m=async()=>{a(!0);try{await nn()}catch{a(!1)}},e[10]=m):m=e[10];let h=m,g=l.data?.updateAvailable??!1,_;return e[11]!==n||e[12]!==g||e[13]!==i?(_={showOnboarding:n,setShowOnboarding:r,updateAvailable:g,updatingApp:i,handleUpdateApp:h},e[11]=n,e[12]=g,e[13]=i,e[14]=_):_=e[14],_}function ly(e){return e.startsWith(`/settings`)||e===`/review`}function uy(e){let t=(0,X.c)(45),{selectedThreadId:n,selectedProjectId:r,isMobile:i,mainTabBarRef:a}=e,o=er(),s=fr(),{activeMainTab:c,setActiveMainTab:l,triggerReviewRefresh:u,triggerTasksRefresh:d}=Ks(),{triggerExplorerRefresh:f}=Xs(),{terminalState:p}=La(n),m;t[0]===s.pathname?m=t[1]:(m=s.pathname.startsWith(`/settings`),t[0]=s.pathname,t[1]=m);let h=m,g=s.pathname===`/review`,_=s.pathname===`/todos`,v=(0,Y.useRef)(null),y=(0,Y.useRef)(c),b=(0,Y.useRef)(c),x=(0,Y.useRef)(!1),S=(0,Y.useRef)(c),C=(0,Y.useRef)(!1),w=(0,Y.useRef)(c),T=(0,Y.useRef)(!1),E=(0,Y.useRef)(null),D,O;t[2]!==_||t[3]!==o||t[4]!==l?(D=()=>{_&&(o(`/`),l(`tasks`))},O=[_,o,l],t[2]=_,t[3]=o,t[4]=l,t[5]=D,t[6]=O):(D=t[5],O=t[6]),(0,Y.useEffect)(D,O);let k,A;t[7]!==s.pathname||t[8]!==n||t[9]!==l||t[10]!==p.open?(k=()=>{p.open&&n===v.current&&!ly(s.pathname)&&l(`terminal`),v.current=n},A=[p.open,n,s.pathname,l],t[7]=s.pathname,t[8]=n,t[9]=l,t[10]=p.open,t[11]=k,t[12]=A):(k=t[11],A=t[12]),(0,Y.useEffect)(k,A);let j,M;t[13]!==c||t[14]!==i||t[15]!==a?(j=()=>{i&&(a.current?.querySelector(`[data-tab="${c}"]`))?.scrollIntoView({inline:`nearest`,block:`nearest`})},M=[c,i,a],t[13]=c,t[14]=i,t[15]=a,t[16]=j,t[17]=M):(j=t[16],M=t[17]),(0,Y.useEffect)(j,M);let N,P;t[18]!==c||t[19]!==h||t[20]!==o?(N=()=>{if(h){if(E.current===null){E.current=Date.now(),y.current=c;return}y.current!==c&&o(`/`)}else E.current=null;y.current=c},P=[c,h,o],t[18]=c,t[19]=h,t[20]=o,t[21]=N,t[22]=P):(N=t[21],P=t[22]),(0,Y.useEffect)(N,P);let F,I;t[23]!==c||t[24]!==g||t[25]!==h||t[26]!==n||t[27]!==f?(F=()=>{let e=b.current===`explorer`;b.current=c,c===`explorer`&&!e&&!x.current&&n&&!g&&!h&&f(),x.current=!1},I=[c,n,g,h,f],t[23]=c,t[24]=g,t[25]=h,t[26]=n,t[27]=f,t[28]=F,t[29]=I):(F=t[28],I=t[29]),(0,Y.useEffect)(F,I);let ee,L;t[30]!==c||t[31]!==n||t[32]!==u?(ee=()=>{let e=S.current===`review`;S.current=c,c===`review`&&!e&&!C.current&&n&&u(),C.current=!1},L=[c,n,u],t[30]=c,t[31]=n,t[32]=u,t[33]=ee,t[34]=L):(ee=t[33],L=t[34]),(0,Y.useEffect)(ee,L);let te,R;t[35]!==c||t[36]!==g||t[37]!==h||t[38]!==r||t[39]!==d?(te=()=>{let e=w.current===`tasks`;w.current=c,c===`tasks`&&!e&&!T.current&&r&&!g&&!h&&d(),T.current=!1},R=[c,r,g,h,d],t[35]=c,t[36]=g,t[37]=h,t[38]=r,t[39]=d,t[40]=te,t[41]=R):(te=t[40],R=t[41]),(0,Y.useEffect)(te,R);let ne;return t[42]!==g||t[43]!==h?(ne={isSettingsRoute:h,isReviewRoute:g,explorerTabClickedRef:x,reviewTabClickedRef:C,tasksTabClickedRef:T},t[42]=g,t[43]=h,t[44]=ne):ne=t[44],ne}function dy(e,t){let n=(0,X.c)(8),r=Ia(),i=Q(fy),a=(0,Y.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:Z.ToggleSidebar});else if(!n&&a.current!==null){let e=a.current;a.current=null,e&&!i&&r({type:Z.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,Y.useEffect)(o,s)}function fy(e){return e.sidebarOpen}var py=oh(`App`,{web:()=>Xr(()=>import(`./web-DGalafxk.js`).then(e=>new e.AppWeb),[])}),my=1e10,hy=1e3;function gy(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 _y(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=hy}=e;e.transport&&i(e.transport),e.requestHandler&&a(e.requestHandler),e._debugHooks&&(t=e._debugHooks);let s=0;function c(){return s<=my?++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 gy([`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 gy([`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 gy([`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 gy([`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 vy(e,t){let n=_y({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 yy=window.__electrobunWebviewId,by=window.__electrobunRpcSocketPort,xy=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:${by}/socket?webviewId=${yy}`);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 vy(`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 Sy(){let e=(0,X.c)(2),t;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=[],e[0]=t):t=e[0],(0,Y.useEffect)(Ey,t);let n;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(n=[],e[1]=n):n=e[1],(0,Y.useEffect)(Cy,n)}function Cy(){if(!at())return;let e=py.addListener(`backButton`,Ty);return()=>{e.then(wy)}}function wy(e){return e.remove()}function Ty(e){let{canGoBack:t}=e;t?window.history.back():py.exitApp()}function Ey(){window.__electrobunWebviewId&&new xy({})}function Dy(e){let t=(0,X.c)(2),{children:n}=e,r;return t[0]===n?r=t[1]:(r=(0,$.jsx)(Us,{children:(0,$.jsx)($u,{children:(0,$.jsx)(Js,{children:(0,$.jsx)(Ev,{children:n})})})}),t[0]=n,t[1]=r),r}function Oy(){return Fv(),null}function ky(){let e=(0,X.c)(1),t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t={queryKey:[`health-status`,Ke()],queryFn:Ay,refetchInterval:3e4,retry:!1},e[0]=t):t=e[0],Wr(t)}async function Ay(){let e=await fetch(`${Ke()}/health`,{method:`GET`});if(!e.ok)throw Error(`Failed to load health status`);return e.json()}function jy(){let e=(0,X.c)(105),t=Ia(),n=er(),r=fr(),i=Q(Iy),a=Q(Fy),o=Q(Py),s=Q(Ny),c=Q(My);Sy();let l=Jd(),u;e[0]===l?u=e[1]:(u=l||at(),e[0]=l,e[1]=u);let d=u,{data:f}=ky(),[p,m]=(0,Y.useState)(null),[h,g]=(0,Y.useState)(!1),[_,v]=(0,Y.useState)(null),y=(0,Y.useRef)(null),b=(0,Y.useRef)(null),x;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(x={onProjectCreated:m},e[2]=x):x=e[2];let{projects:S,handleSelectThread:C,handleCreateProject:w,handleCreateWebApp:T,handleCreateFolder:E,handleOpenFolder:O,handleCreateThread:k,handleDeleteThread:A,confirmDeleteProject:j,refreshProjects:M,pendingSetupScriptConfirmation:N,resolveSetupScriptConfirmation:P}=ny(x),{processingThreadIds:F,completedThreadIds:I,clearCompleted:ee}=sy(),{setActiveMainTab:L}=Ks(),{triggerBrowserReset:te}=Ov(),{showOnboarding:R,setShowOnboarding:ne,updateAvailable:re,updatingApp:ie,handleUpdateApp:ae}=cy(),oe;e[3]!==l||e[4]!==a||e[5]!==i?(oe={selectedThreadId:i,selectedProjectId:a,isMobile:l,mainTabBarRef:b},e[3]=l,e[4]=a,e[5]=i,e[6]=oe):oe=e[6];let{isSettingsRoute:se,isReviewRoute:ce,explorerTabClickedRef:le,reviewTabClickedRef:ue,tasksTabClickedRef:de}=uy(oe);dy(se,ce);let fe;e[7]===S?fe=e[8]:(fe=e=>{let t=S.find(t=>t.projectId===e);t&&v({id:t.projectId,name:_e(t)})},e[7]=S,e[8]=fe);let B=fe,pe;e[9]===k?pe=e[10]:(pe=e=>{m(e),k(e,void 0)},e[9]=k,e[10]=pe);let V=pe,me,he;e[11]!==p||e[12]!==a||e[13]!==i?(me=()=>{p&&a===p&&i&&m(null)},he=[p,a,i],e[11]=p,e[12]=a,e[13]=i,e[14]=me,e[15]=he):(me=e[14],he=e[15]),(0,Y.useEffect)(me,he);let ge;e[16]!==ee||e[17]!==t||e[18]!==C||e[19]!==r.pathname||e[20]!==n||e[21]!==i||e[22]!==L||e[23]!==te||e[24]!==d?(ge=(e,a)=>{m(null),ee(a),r.pathname!==`/`&&n(`/`),L(`chat`),i!==a&&te(),C(e,a),d&&t({type:Z.CloseSidebar})},e[16]=ee,e[17]=t,e[18]=C,e[19]=r.pathname,e[20]=n,e[21]=i,e[22]=L,e[23]=te,e[24]=d,e[25]=ge):ge=e[25];let H=ge,ve,ye;e[26]===o?(ve=e[27],ye=e[28]):(ve=()=>{o?y.current?.expand():y.current?.collapse()},ye=[o],e[26]=o,e[27]=ve,e[28]=ye),(0,Y.useEffect)(ve,ye);let be;e[29]===Symbol.for(`react.memo_cache_sentinel`)?(be=(0,$.jsx)(Oy,{}),e[29]=be):be=e[29];let xe;e[30]===Symbol.for(`react.memo_cache_sentinel`)?(xe=(0,$.jsx)(Y.Suspense,{fallback:null,children:(0,$.jsx)(Qv,{})}),e[30]=xe):xe=e[30];let Se=d?100:25,Ce=d?50:12,we=d?100:32,U=d&&!o&&`hidden`,Te;e[31]===U?Te=e[32]:(Te=z(`border-r border-transparent`,U),e[31]=U,e[32]=Te);let Ee;e[33]===Symbol.for(`react.memo_cache_sentinel`)?(Ee=()=>g(!0),e[33]=Ee):Ee=e[33];let De=!o,Oe=f?.isDevMode===!0,ke;e[34]!==I||e[35]!==c||e[36]!==s||e[37]!==p||e[38]!==V||e[39]!==B||e[40]!==A||e[41]!==H||e[42]!==ae||e[43]!==F||e[44]!==S||e[45]!==a||e[46]!==i||e[47]!==De||e[48]!==Oe||e[49]!==re||e[50]!==ie?(ke=(0,$.jsx)(`div`,{className:`h-full overflow-hidden`,children:(0,$.jsx)(so,{projects:S,selectedThreadId:i,selectedProjectId:a,processingThreadIds:F,completedThreadIds:I,deletingThreadIds:s,deletingProjectIds:c,onSelectThread:H,onCreateProject:Ee,onCreateThread:V,onDeleteThread:A,onDeleteProject:B,collapsed:De,updateAvailable:re,updatingApp:ie,onUpdateApp:ae,isDevMode:Oe,expandProjectId:p})}),e[34]=I,e[35]=c,e[36]=s,e[37]=p,e[38]=V,e[39]=B,e[40]=A,e[41]=H,e[42]=ae,e[43]=F,e[44]=S,e[45]=a,e[46]=i,e[47]=De,e[48]=Oe,e[49]=re,e[50]=ie,e[51]=ke):ke=e[51];let Ae;e[52]!==Se||e[53]!==Ce||e[54]!==we||e[55]!==Te||e[56]!==ke?(Ae=(0,$.jsx)(ug,{ref:y,defaultSize:Se,minSize:Ce,maxSize:we,collapsible:!0,collapsedSize:0,className:Te,children:ke}),e[52]=Se,e[53]=Ce,e[54]=we,e[55]=Te,e[56]=ke,e[57]=Ae):Ae=e[57];let je;e[58]!==o||e[59]!==d?(je=!d&&(0,$.jsx)(dg,{withHandle:!0,className:o?`ml-[-40px]`:``}),e[58]=o,e[59]=d,e[60]=je):je=e[60];let Me=d&&o&&`hidden`,Ne;e[61]===Me?Ne=e[62]:(Ne=z(`overflow-hidden`,Me),e[61]=Me,e[62]=Ne);let Pe=i??void 0,Fe;e[63]!==le||e[64]!==V||e[65]!==ce||e[66]!==se||e[67]!==ue||e[68]!==a||e[69]!==i||e[70]!==de?(Fe=(0,$.jsx)(Wp,{children:(0,$.jsx)(zg,{selectedThreadId:i,selectedProjectId:a,isReviewRoute:ce,isSettingsRoute:se,onCreateThread:V,mainTabBarRef:b,explorerTabClickedRef:le,reviewTabClickedRef:ue,tasksTabClickedRef:de})}),e[63]=le,e[64]=V,e[65]=ce,e[66]=se,e[67]=ue,e[68]=a,e[69]=i,e[70]=de,e[71]=Fe):Fe=e[71];let Ie;e[72]!==Pe||e[73]!==Fe?(Ie=(0,$.jsx)(Lm,{threadId:Pe,children:Fe}),e[72]=Pe,e[73]=Fe,e[74]=Ie):Ie=e[74];let Le;e[75]!==Ne||e[76]!==Ie?(Le=(0,$.jsx)(ug,{minSize:40,className:Ne,children:Ie}),e[75]=Ne,e[76]=Ie,e[77]=Le):Le=e[77];let Re;e[78]===Symbol.for(`react.memo_cache_sentinel`)?(Re=e=>!e&&v(null),e[78]=Re):Re=e[78];let ze;e[79]!==j||e[80]!==_?(ze=()=>{_&&(j(_.id),v(null))},e[79]=j,e[80]=_,e[81]=ze):ze=e[81];let Be;e[82]===M?Be=e[83]:(Be=()=>{M()},e[82]=M,e[83]=Be);let Ve;e[84]!==_||e[85]!==E||e[86]!==w||e[87]!==T||e[88]!==O||e[89]!==N||e[90]!==P||e[91]!==ne||e[92]!==h||e[93]!==R||e[94]!==ze||e[95]!==Be?(Ve=(0,$.jsx)(wv,{showCreateProject:h,onCreateProjectOpenChange:g,onSubmitClone:w,onSubmitWebApp:T,onSubmitFolder:E,onOpenFolder:O,deleteProject:_,onDeleteProjectOpenChange:Re,onConfirmDeleteProject:ze,pendingSetupScriptConfirmation:N,onResolveSetupScriptConfirmation:P,showOnboarding:R,onOnboardingOpenChange:ne,onOnboardingComplete:Be}),e[84]=_,e[85]=E,e[86]=w,e[87]=T,e[88]=O,e[89]=N,e[90]=P,e[91]=ne,e[92]=h,e[93]=R,e[94]=ze,e[95]=Be,e[96]=Ve):Ve=e[96];let He;e[97]!==Ae||e[98]!==je||e[99]!==Le||e[100]!==Ve?(He=(0,$.jsxs)(lg,{direction:`horizontal`,className:`h-screen bg-background`,children:[Ae,je,Le,Ve]}),e[97]=Ae,e[98]=je,e[99]=Le,e[100]=Ve,e[101]=He):He=e[101];let W;e[102]===Symbol.for(`react.memo_cache_sentinel`)?(W=(0,$.jsx)(Wv,{}),e[102]=W):W=e[102];let Ue;return e[103]===He?Ue=e[104]:(Ue=(0,$.jsxs)($.Fragment,{children:[be,xe,(0,$.jsxs)(D,{delayDuration:200,children:[He,W]})]}),e[103]=He,e[104]=Ue),Ue}function My(e){return e.deletingProjectIds}function Ny(e){return e.deletingThreadIds}function Py(e){return e.sidebarOpen}function Fy(e){return e.selectedProjectId}function Iy(e){return e.selectedThreadId}function Ly(){let e=(0,X.c)(1),t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(Dy,{children:(0,$.jsx)(jy,{})}),e[0]=t):t=e[0],t}function Ry(){let e=(0,X.c)(3),[t]=(0,Y.useState)(Na),n;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,$.jsx)(Ly,{}),e[0]=n):n=e[0];let r;return e[1]===t?r=e[2]:(r=(0,$.jsx)(Yv,{attribute:`class`,defaultTheme:`system`,enableSystem:!0,storageKey:`tarsk-theme`,children:(0,$.jsx)(qv,{children:(0,$.jsx)(Pa.Provider,{value:t,children:n})})}),e[1]=t,e[2]=r),r}var zy=75,By=125,Vy=100;function Hy(){return window.matchMedia(`(max-width: 767px)`).matches}function Uy(e){let t=ne(e,Hy());document.documentElement.style.fontSize=`${t}%`}var Wy=!1;function Gy(){Wy||(Wy=!0,window.matchMedia(`(max-width: 767px)`).addEventListener(`change`,()=>{Uy(an(Vy))}))}function Ky(){let[e,t]=(0,Y.useState)(()=>an(Vy));(0,Y.useEffect)(()=>{Gy(),Uy(e)},[e]);function n(e){let n=Math.max(zy,Math.min(By,Math.round(e)));t(n),Pe(n)}return{scale:e,updateScale:n,resetScale:(0,Y.useCallback)(()=>{n(Vy)},[]),min:zy,max:By,default:Vy}}function qy(){Gy(),Uy(an(Vy))}var Jy;(function(e){e.Dark=`DARK`,e.Light=`LIGHT`,e.Default=`DEFAULT`})(Jy||={});var Yy;(function(e){e.None=`NONE`,e.Slide=`SLIDE`,e.Fade=`FADE`})(Yy||={});var Xy=oh(`StatusBar`),Zy=`--app-viewport-height`;function Qy(){let e=window.visualViewport,t=Math.round(pn()===`ios`?window.innerHeight:e?.height??window.innerHeight);document.documentElement.style.setProperty(Zy,`${t}px`)}function $y(){Qy(),requestAnimationFrame(Qy)}function eb(){document.documentElement.dataset.nativeShell=`true`,$y(),window.addEventListener(`resize`,Qy),window.addEventListener(`orientationchange`,$y);let e=window.visualViewport;e?.addEventListener(`resize`,Qy),e?.addEventListener(`scroll`,Qy)}async function tb(){try{await Xy.setOverlaysWebView({overlay:!0}),await Xy.show(),$y()}catch{}}async function nb(){try{let e=pn()===`ios`?tg.None:tg.Body;await ng.setResizeMode({mode:e})}catch{}}function rb(){at()&&(eb(),tb(),nb(),document.addEventListener(`visibilitychange`,()=>{if(document.visibilityState===`visible`){$y(),tb();return}wh()}))}qy(),rb();var ib=`tarsk-chunk-reload`;function ab(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 ob(){sessionStorage.getItem(ib)||(sessionStorage.setItem(ib,`1`),window.location.reload())}window.addEventListener(`unhandledrejection`,e=>{ab(e.reason)&&(e.preventDefault(),ob())}),window.addEventListener(`vite:preloadError`,e=>{e.preventDefault(),ob()}),sessionStorage.removeItem(ib);var sb=!1;window.addEventListener(`resize`,()=>{sb||=(window.__electrobunWebviewId&&(document.body.style.height=`calc(100%)`),!0)});var cb=at()?Jn:Nr;(0,Ai.createRoot)(document.getElementById(`root`)).render((0,$.jsx)(Y.StrictMode,{children:(0,$.jsx)(cb,{children:(0,$.jsx)(Ry,{})})}));export{Xs as A,Z as B,Kl as C,qc as D,Vl as E,Va as F,Ra as I,Ia as L,ls as M,ro as N,Yc as O,Qa as P,Q as R,Gl as S,Zl as T,fm as _,I_ as a,ed as b,_g as c,lg as d,zh as f,hm as g,mm as h,fv as i,Ks as j,Jc as k,dg as l,Km as m,Ov as n,yg as o,sh as p,uv as r,bg as s,Ky as t,ug as u,Op as v,Xl as w,Bl as x,Jd as y,La as z};
|