tarsk 0.5.48 → 0.5.49

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/dist/public/assets/{account-view-Bbdb8T18.js → account-view-DxHV7OtO.js} +1 -1
  2. package/dist/public/assets/{browser-tab-3DUg6V0M.js → browser-tab-qhf-xKwZ.js} +1 -1
  3. package/dist/public/assets/{commit-dialog-CgHm8yd5.js → commit-dialog-DcVXFOBP.js} +1 -1
  4. package/dist/public/assets/{create-repo-dialog-BlvNaVRv.js → create-repo-dialog-CsjpTBPU.js} +1 -1
  5. package/dist/public/assets/{diff-view-BTMJ68_E.js → diff-view-CGEl0YbC.js} +1 -1
  6. package/dist/public/assets/{explorer-tab-view-BBkCWKSi.js → explorer-tab-view--ib_BjId.js} +2 -2
  7. package/dist/public/assets/{explorer-tree-CboAGH2h.js → explorer-tree-CiPMm5ck.js} +1 -1
  8. package/dist/public/assets/{explorer-view-CBxsEzQT.js → explorer-view-odyQutTO.js} +1 -1
  9. package/dist/public/assets/git-ops-button-Bced-_39.js +2 -0
  10. package/dist/public/assets/{index-r-MGLt04.js → index-_SOdLUMq.js} +5 -5
  11. package/dist/public/assets/{project-settings-view-DuZuSAP6.js → project-settings-view-CHV6lJG4.js} +1 -1
  12. package/dist/public/assets/{pull-request-dialog-DUFq4dcj.js → pull-request-dialog-BFgRF5AH.js} +1 -1
  13. package/dist/public/assets/{settings-general-view-DRoJpfeq.js → settings-general-view-Vwi9J6Tn.js} +1 -1
  14. package/dist/public/assets/{settings-instructions-view-DMiTyhgF.js → settings-instructions-view-8YIr0PO3.js} +1 -1
  15. package/dist/public/assets/{settings-mcp-servers-view-D-ZPqbhw.js → settings-mcp-servers-view-CCXW_uet.js} +1 -1
  16. package/dist/public/assets/{settings-rules-view-CpGhrZ4c.js → settings-rules-view-D3KLTKVZ.js} +1 -1
  17. package/dist/public/assets/{settings-skills-view-Bbo2EUTs.js → settings-skills-view-DaqOna-w.js} +1 -1
  18. package/dist/public/assets/{settings-slash-commands-view-B9knfs3R.js → settings-slash-commands-view-CN8_DTYX.js} +1 -1
  19. package/dist/public/assets/{settings-subagents-view-CmSR8G5x.js → settings-subagents-view-BIejA-ck.js} +1 -1
  20. package/dist/public/assets/{settings-system-prompt-view-N-H35C8O.js → settings-system-prompt-view-B1vc2cgC.js} +1 -1
  21. package/dist/public/assets/{settings-view-CjN-sUwG.js → settings-view-DLBIkYoA.js} +2 -2
  22. package/dist/public/assets/{terminal-panel-0S4qt1S4.js → terminal-panel-DIpnKR-N.js} +1 -1
  23. package/dist/public/assets/{todos-view-CMguWUyv.js → todos-view-BK6i_oPT.js} +1 -1
  24. package/dist/public/assets/{web-CBt5zrp2.js → web-BD1sqxMq.js} +1 -1
  25. package/dist/public/assets/{web-DltYtNVf.js → web-BWAZk7ug.js} +1 -1
  26. package/dist/public/assets/{web-Ca4UIlTP.js → web-DGalafxk.js} +1 -1
  27. package/dist/public/assets/{web-oCvIBpv0.js → web-Dt5YgbhM.js} +1 -1
  28. package/dist/public/index.html +1 -1
  29. package/package.json +1 -1
  30. package/dist/public/assets/git-ops-button-qjbfOO7Y.js +0 -2
@@ -1,4 +1,4 @@
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-qjbfOO7Y.js","assets/monaco-CZnIWXyV.js","assets/monaco-Br_kD0ds.css","assets/diff-view-BTMJ68_E.js","assets/context-menu-PIC-g8wy.js","assets/react-vendor-iDwBzcYF.js","assets/utils-CECQ_-6N.js","assets/terminal-panel-0S4qt1S4.js","assets/terminal-panel-kHJ-D0s7.css","assets/explorer-tab-view-BBkCWKSi.js","assets/browser-tab-3DUg6V0M.js","assets/settings-view-CjN-sUwG.js","assets/settings-models-skeleton-Cse6L-Nd.js","assets/skeleton-6mGMglV0.js","assets/todos-view-CMguWUyv.js","assets/tabs-iUSYYupj.js"])))=>i.map(i=>d[i]);
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
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
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
4
 
@@ -47,8 +47,8 @@ import{i as e,t}from"./rolldown-runtime-aKtaBQYM.js";import{$ as n,$a as r,$i as
47
47
  to { height: 14px; }
48
48
  }
49
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-qjbfOO7Y.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-CBt5zrp2.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-BTMJ68_E.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-oCvIBpv0.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-0S4qt1S4.js`).then(e=>({default:e.TerminalPanel})),__vite__mapDeps([13,1,3,14]))),Pg=(0,Y.lazy)(()=>Xr(()=>import(`./diff-view-BTMJ68_E.js`),__vite__mapDeps([9,1,7,8,5,3,4,10,11,12]))),Fg=(0,Y.lazy)(()=>Xr(()=>import(`./explorer-tab-view-BBkCWKSi.js`),__vite__mapDeps([15,1,7,8,5,3]))),Ig=(0,Y.lazy)(()=>Xr(()=>import(`./browser-tab-3DUg6V0M.js`).then(e=>({default:e.BrowserTab})),__vite__mapDeps([16,1,3]))),Lg=(0,Y.lazy)(()=>Xr(()=>import(`./settings-view-CjN-sUwG.js`),__vite__mapDeps([17,1,7,8,5,3,4,18,19,11]))),Rg=(0,Y.lazy)(()=>Xr(()=>import(`./todos-view-CMguWUyv.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)===`
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
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
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
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. .
@@ -67,7 +67,7 @@ import{i as e,t}from"./rolldown-runtime-aKtaBQYM.js";import{$ as n,$a as r,$i as
67
67
  `),e.append(`>>
68
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
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-DltYtNVf.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(`
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
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
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-Ca4UIlTP.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};
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};